Lint: Formatting

pull/5/head
eliot-akira 3 years ago
parent f3f625276b
commit 842f3e9f2b
  1. 2
      browser-version/lib/byline.js
  2. 12
      lib/persistence.js
  3. 16
      test/persistence.test.js

@ -1 +1 @@
module.exports = {} module.exports = {}

@ -198,8 +198,7 @@ class Persistence {
const that = this const that = this
let length = 0 let length = 0
lineStream.on('data', function(line) { lineStream.on('data', function (line) {
try { try {
const doc = model.deserialize(that.beforeDeserialization(line)) const doc = model.deserialize(that.beforeDeserialization(line))
if (doc._id) { if (doc._id) {
@ -214,11 +213,11 @@ class Persistence {
length++ length++
}) })
lineStream.on('end', function() { lineStream.on('end', function () {
// A bit lenient on corruption // A bit lenient on corruption
let err let err
if (length > 0 && corruptItems / length > that.corruptAlertThreshold) { 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) { Object.keys(dataById).forEach(function (k) {
@ -228,7 +227,7 @@ class Persistence {
cb(err, { data: tdata, indexes: indexes }) cb(err, { data: tdata, indexes: indexes })
}) })
lineStream.on('error', function(err) { lineStream.on('error', function (err) {
cb(err) cb(err)
}) })
} }
@ -258,7 +257,6 @@ class Persistence {
storage.ensureDatafileIntegrity(this.filename, err => { storage.ensureDatafileIntegrity(this.filename, err => {
// TODO: handle error // TODO: handle error
const treatedDataCallback = (err, treatedData) => { const treatedDataCallback = (err, treatedData) => {
if (err) return cb(err) if (err) return cb(err)
// Recreate all indexes in the datafile // Recreate all indexes in the datafile
@ -279,7 +277,7 @@ class Persistence {
if (storage.readFileStream) { if (storage.readFileStream) {
// Server side // Server side
const fileStream = storage.readFileStream(this.filename, { encoding : 'utf8' }) const fileStream = storage.readFileStream(this.filename, { encoding: 'utf8' })
this.treatRawStream(fileStream, treatedDataCallback) this.treatRawStream(fileStream, treatedDataCallback)
return return
} }

@ -102,7 +102,7 @@ describe('Persistence', function () {
d.persistence.treatRawStream(stream, function (err, result) { d.persistence.treatRawStream(stream, function (err, result) {
console.log(err) console.log(err)
var treatedData = result.data const treatedData = result.data
treatedData.sort(function (a, b) { return a._id - b._id }) treatedData.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] })
@ -135,7 +135,7 @@ describe('Persistence', function () {
stream.push(null) stream.push(null)
d.persistence.treatRawStream(stream, function (err, result) { 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.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] })
@ -168,7 +168,7 @@ describe('Persistence', function () {
stream.push(null) stream.push(null)
d.persistence.treatRawStream(stream, function (err, result) { 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.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)
assert.deepStrictEqual(treatedData[0], { _id: '1', nested: { today: now } }) assert.deepStrictEqual(treatedData[0], { _id: '1', nested: { today: now } })
@ -203,7 +203,7 @@ describe('Persistence', function () {
stream.push(null) stream.push(null)
d.persistence.treatRawStream(stream, function (err, result) { 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.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)
assert.deepStrictEqual(treatedData[0], { _id: '2', hello: 'world' }) assert.deepStrictEqual(treatedData[0], { _id: '2', hello: 'world' })
@ -236,7 +236,7 @@ describe('Persistence', function () {
stream.push(null) stream.push(null)
d.persistence.treatRawStream(stream, function (err, result) { 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.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)
assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] }) assert.deepStrictEqual(treatedData[0], { _id: '1', a: 2, ages: [1, 5, 12] })
@ -273,10 +273,10 @@ describe('Persistence', function () {
stream.push(null) stream.push(null)
d.persistence.treatRawStream(stream, function (err, result) { d.persistence.treatRawStream(stream, function (err, result) {
var treatedData = result.data const treatedData = result.data
var indexes = result.indexes const indexes = result.indexes
Object.keys(indexes).length.should.equal(1) 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.sort(function (a, b) { return a._id - b._id })
treatedData.length.should.equal(2) treatedData.length.should.equal(2)

Loading…
Cancel
Save