@ -12,8 +12,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- The JSDoc is now much more exhaustive.
- An auto-generated JSDoc file is generated: [API.md](./API.md).
- Added `Datastore#dropDatabaseAsync` and its callback equivalent.
- The Error given when there the `Datastore#corruptAlertThreshold` is reached now has three properties: `dataLength` which is the amount of lines in the database file (excluding empty lines), `corruptItems` which is the amount of corrupted lines, `corruptionRate` which the rate of corruption between 0 and 1.
### Changed
- The `corrpuptionAlertThreshold` now doesn't take into account empty lines.
- The `Datastore#update`'s callback has its signature slightly changed. The
`upsert` flag is always defined either at `true` or `false` but not `null` nor
`undefined`, and `affectedDocuments` is `null` when none is given rather than
)thrownewError(`More than ${Math.floor(100*this.corruptAlertThreshold)}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`)
if(dataLength>0){
constcorruptionRate=corruptItems/dataLength
if(corruptionRate>this.corruptAlertThreshold){
consterror=newError(`${Math.floor(100*corruptionRate)}% of the data file is corrupt, more than given corruptAlertThreshold (${Math.floor(100*this.corruptAlertThreshold)}%). Cautiously refusing to start NeDB to prevent dataloss.`)
error.corruptionRate=corruptionRate
error.corruptItems=corruptItems
error.dataLength=dataLength
throwerror
}
}
consttdata=Object.values(dataById)
@ -225,13 +233,13 @@ class Persistence {
constindexes={}
// Last line of every data file is usually blank so not really corrupt
consterr=newError(`More than ${Math.floor(100*this.corruptAlertThreshold)}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`)
reject(err,null)
if(dataLength>0){
constcorruptionRate=corruptItems/dataLength
if(corruptionRate>this.corruptAlertThreshold){
consterror=newError(`${Math.floor(100*corruptionRate)}% of the data file is corrupt, more than given corruptAlertThreshold (${Math.floor(100*this.corruptAlertThreshold)}%). Cautiously refusing to start NeDB to prevent dataloss.`)