|
|
@ -49,6 +49,7 @@ class Persistence { |
|
|
|
* @param {object} [options.modes] Modes to use for FS permissions. Will not work on Windows. |
|
|
|
* @param {object} [options.modes] Modes to use for FS permissions. Will not work on Windows. |
|
|
|
* @param {number} [options.modes.fileMode=0o644] Mode to use for files. |
|
|
|
* @param {number} [options.modes.fileMode=0o644] Mode to use for files. |
|
|
|
* @param {number} [options.modes.dirMode=0o755] Mode to use for directories. |
|
|
|
* @param {number} [options.modes.dirMode=0o755] Mode to use for directories. |
|
|
|
|
|
|
|
* @param {boolean} [options.testSerializationHooks=true] Whether to test the serialization hooks or not, might be CPU-intensive |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
constructor (options) { |
|
|
|
constructor (options) { |
|
|
|
this.db = options.db |
|
|
|
this.db = options.db |
|
|
@ -77,11 +78,13 @@ class Persistence { |
|
|
|
this.afterSerialization = options.afterSerialization || (s => s) |
|
|
|
this.afterSerialization = options.afterSerialization || (s => s) |
|
|
|
this.beforeDeserialization = options.beforeDeserialization || (s => s) |
|
|
|
this.beforeDeserialization = options.beforeDeserialization || (s => s) |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 1; i < 30; i += 1) { |
|
|
|
if (options.testSerializationHooks === undefined || options.testSerializationHooks) { |
|
|
|
for (let j = 0; j < 10; j += 1) { |
|
|
|
for (let i = 1; i < 30; i += 1) { |
|
|
|
const randomString = customUtils.uid(i) |
|
|
|
for (let j = 0; j < 10; j += 1) { |
|
|
|
if (this.beforeDeserialization(this.afterSerialization(randomString)) !== randomString) { |
|
|
|
const randomString = customUtils.uid(i) |
|
|
|
throw new Error('beforeDeserialization is not the reverse of afterSerialization, cautiously refusing to start NeDB to prevent dataloss') |
|
|
|
if (this.beforeDeserialization(this.afterSerialization(randomString)) !== randomString) { |
|
|
|
|
|
|
|
throw new Error('beforeDeserialization is not the reverse of afterSerialization, cautiously refusing to start NeDB to prevent dataloss') |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|