diff --git a/browser-version/lib/byline.js b/browser-version/lib/byline.js index 7c6d6c7..4ba52ba 100644 --- a/browser-version/lib/byline.js +++ b/browser-version/lib/byline.js @@ -1 +1 @@ -module.exports = {} \ No newline at end of file +module.exports = {} diff --git a/lib/persistence.js b/lib/persistence.js index 1e65bed..126c75a 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -198,8 +198,7 @@ class Persistence { const that = this let length = 0 - lineStream.on('data', function(line) { - + lineStream.on('data', function (line) { try { const doc = model.deserialize(that.beforeDeserialization(line)) if (doc._id) { @@ -214,11 +213,11 @@ class Persistence { length++ }) - lineStream.on('end', function() { + lineStream.on('end', function () { // A bit lenient on corruption let err if (length > 0 && corruptItems / length > that.corruptAlertThreshold) { - err = new Error("More than " + Math.floor(100 * that.corruptAlertThreshold) + "% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss") + err = new Error('More than ' + Math.floor(100 * that.corruptAlertThreshold) + '% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss') } Object.keys(dataById).forEach(function (k) { @@ -228,7 +227,7 @@ class Persistence { cb(err, { data: tdata, indexes: indexes }) }) - lineStream.on('error', function(err) { + lineStream.on('error', function (err) { cb(err) }) } @@ -258,7 +257,6 @@ class Persistence { storage.ensureDatafileIntegrity(this.filename, err => { // TODO: handle error const treatedDataCallback = (err, treatedData) => { - if (err) return cb(err) // Recreate all indexes in the datafile @@ -279,7 +277,7 @@ class Persistence { if (storage.readFileStream) { // Server side - const fileStream = storage.readFileStream(this.filename, { encoding : 'utf8' }) + const fileStream = storage.readFileStream(this.filename, { encoding: 'utf8' }) this.treatRawStream(fileStream, treatedDataCallback) return } diff --git a/test/persistence.test.js b/test/persistence.test.js index df0dcda..ecbc4dd 100755 --- a/test/persistence.test.js +++ b/test/persistence.test.js @@ -102,7 +102,7 @@ describe('Persistence', function () { d.persistence.treatRawStream(stream, function (err, result) { console.log(err) - var treatedData = result.data + const treatedData = result.data treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) @@ -135,7 +135,7 @@ describe('Persistence', function () { stream.push(null) d.persistence.treatRawStream(stream, function (err, result) { - var treatedData = result.data + const treatedData = result.data treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) @@ -168,7 +168,7 @@ describe('Persistence', function () { stream.push(null) d.persistence.treatRawStream(stream, function (err, result) { - var treatedData = result.data + const treatedData = result.data treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2) assert.deepStrictEqual(treatedData[0], { _id: '1', nested: { today: now } }) @@ -203,7 +203,7 @@ describe('Persistence', function () { stream.push(null) d.persistence.treatRawStream(stream, function (err, result) { - var treatedData = result.data + const treatedData = result.data treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2) assert.deepStrictEqual(treatedData[0], { _id: '2', hello: 'world' }) @@ -236,7 +236,7 @@ describe('Persistence', function () { stream.push(null) d.persistence.treatRawStream(stream, function (err, result) { - var treatedData = result.data + const treatedData = result.data treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) @@ -273,10 +273,10 @@ describe('Persistence', function () { stream.push(null) d.persistence.treatRawStream(stream, function (err, result) { - var treatedData = result.data - var indexes = result.indexes + const treatedData = result.data + const indexes = result.indexes Object.keys(indexes).length.should.equal(1) - assert.deepEqual(indexes.test, { fieldName: "test", unique: true }) + assert.deepEqual(indexes.test, { fieldName: 'test', unique: true }) treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.length.should.equal(2)