Skip to content

Commit 53ef8ad

Browse files
committed
chore: fix linting errors
1 parent f4b16d9 commit 53ef8ad

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

lib/db_ref.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,12 @@ Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' });
7171
// the 1.x parser used a "namespace" property, while 4.x uses "collection". To ensure backwards
7272
// compatibility, let's expose "namespace"
7373
Object.defineProperty(DBRef.prototype, 'namespace', {
74-
get() { return this.collection; },
75-
set(val) { this.collection = val; },
74+
get() {
75+
return this.collection;
76+
},
77+
set(val) {
78+
this.collection = val;
79+
},
7680
configurable: false
7781
});
7882
module.exports = DBRef;

lib/extended_json.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,15 @@ const BSON_TYPE_MAPPINGS = {
272272
Decimal128: o => new Decimal128(o.bytes),
273273
Double: o => new Double(o.value),
274274
Int32: o => new Int32(o.value),
275-
Long: o => Long.fromBits( // underscore variants for 1.x backwards compatibility
276-
o.low != null ? o.low : o.low_,
277-
o.low != null ? o.high : o.high_,
278-
o.low != null ? o.unsigned : o.unsigned_
279-
),
280-
MaxKey: o => new MaxKey(),
281-
MinKey: o => new MinKey(),
275+
Long: o =>
276+
Long.fromBits(
277+
// underscore variants for 1.x backwards compatibility
278+
o.low != null ? o.low : o.low_,
279+
o.low != null ? o.high : o.high_,
280+
o.low != null ? o.unsigned : o.unsigned_
281+
),
282+
MaxKey: () => new MaxKey(),
283+
MinKey: () => new MinKey(),
282284
ObjectID: o => new ObjectId(o),
283285
ObjectId: o => new ObjectId(o), // support 4.0.0/4.0.1 before _bsontype was reverted back to ObjectID
284286
BSONRegExp: o => new BSONRegExp(o.pattern, o.options),
@@ -291,16 +293,13 @@ function serializeDocument(doc, options) {
291293

292294
const bsontype = doc._bsontype;
293295
if (typeof bsontype === 'undefined') {
294-
295296
// It's a regular object. Recursively serialize its property values.
296297
const _doc = {};
297298
for (let name in doc) {
298299
_doc[name] = serializeValue(doc[name], options);
299300
}
300301
return _doc;
301-
302302
} else if (typeof bsontype === 'string') {
303-
304303
// the "document" is really just a BSON type object
305304
let _doc = doc;
306305
if (typeof _doc.toExtendedJSON !== 'function') {
@@ -315,15 +314,14 @@ function serializeDocument(doc, options) {
315314
_doc = mapper(_doc);
316315
}
317316

318-
// Two BSON types may have nested objects that may need to be serialized too
317+
// Two BSON types may have nested objects that may need to be serialized too
319318
if (bsontype === 'Code' && _doc.scope) {
320319
_doc = new Code(_doc.code, serializeValue(_doc.scope, options));
321320
} else if (bsontype === 'DBRef' && _doc.oid) {
322321
_doc = new DBRef(_doc.collection, serializeValue(_doc.oid, options), _doc.db, _doc.fields);
323322
}
324323

325324
return _doc.toExtendedJSON(options);
326-
327325
} else {
328326
throw new Error('_bsontype must be a string, but was: ' + typeof bsontype);
329327
}

test/node/bson_test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,11 @@ describe('BSON', function() {
23512351
});
23522352

23532353
// Object
2354-
const record = { oldBsonType: new ObjectIdv400(), reallyOldBsonType: new OldObjectID, newBsonType: new ObjectId() };
2354+
const record = {
2355+
oldBsonType: new ObjectIdv400(),
2356+
reallyOldBsonType: new OldObjectID(),
2357+
newBsonType: new ObjectId()
2358+
};
23552359
const deserializedObject = BSON.deserialize(BSON.serialize(record));
23562360
expect(deserializedObject).to.have.keys(['oldBsonType', 'reallyOldBsonType', 'newBsonType']);
23572361
expect(record.oldBsonType.toString()).to.equal(deserializedObject.oldBsonType.toString());

test/node/extended_json_tests.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ describe('Extended JSON', function() {
331331
it.skip('skipping 4.x/1.x interop tests', () => {});
332332
} else {
333333
it('should interoperate 4.x with 1.x versions of this library', function() {
334-
335334
const buffer = Buffer.alloc(64);
336335
for (var i = 0; i < buffer.length; i++) {
337336
buffer[i] = i;
@@ -363,10 +362,11 @@ describe('Extended JSON', function() {
363362
oldObjectOldSerializer: OldBSON.serialize(oldBsonObject, serializationOptions),
364363
oldObjectNewSerializer: BSON.serialize(oldBsonObject, serializationOptions),
365364
newObjectOldSerializer: OldBSON.serialize(newBsonObject, serializationOptions),
366-
newObjectNewSerializer: BSON.serialize(newBsonObject, serializationOptions),
365+
newObjectNewSerializer: BSON.serialize(newBsonObject, serializationOptions)
367366
};
368367

369-
const expectedBufferBase64 = 'VgEAAAViaW5hcnkAQAAAAAAAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/DWNvZGUADgAAAGZ1bmN0aW9uKCkge30AA2RiUmVmACwAAAACJHJlZgAGAAAAdGVzdHMAECRpZAABAAAAAiRkYgAFAAAAdGVzdAAAE2RlY2ltYWwxMjgA//837RjxE6AdAgAAAABAMAFkb3VibGUAMzMzMzMzJEAQaW50MzIACgAAABJsb25nAP//38RiSvoQf21heEtleQAHb2JqZWN0SWQAERERERERERERERERB29iamVjdElEABEREREREREREREREQtic29uUmVnRXhwAGhlbGxvIHdvcmxkAGkADnN5bWJvbAAHAAAAc3ltYm9sABF0aW1lc3RhbXAAAAAAAAAAAAAA';
368+
const expectedBufferBase64 =
369+
'VgEAAAViaW5hcnkAQAAAAAAAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/DWNvZGUADgAAAGZ1bmN0aW9uKCkge30AA2RiUmVmACwAAAACJHJlZgAGAAAAdGVzdHMAECRpZAABAAAAAiRkYgAFAAAAdGVzdAAAE2RlY2ltYWwxMjgA//837RjxE6AdAgAAAABAMAFkb3VibGUAMzMzMzMzJEAQaW50MzIACgAAABJsb25nAP//38RiSvoQf21heEtleQAHb2JqZWN0SWQAERERERERERERERERB29iamVjdElEABEREREREREREREREQtic29uUmVnRXhwAGhlbGxvIHdvcmxkAGkADnN5bWJvbAAHAAAAc3ltYm9sABF0aW1lc3RhbXAAAAAAAAAAAAAA';
370370
const expectedBuffer = Buffer.from(expectedBufferBase64, 'base64');
371371

372372
// Regardless of which library version created the objects, and which library version
@@ -383,20 +383,28 @@ describe('Extended JSON', function() {
383383
const deserializationOptions = { promoteValues: false };
384384
const deserialized = {
385385
usingOldDeserializer: OldBSON.deserialize(expectedBuffer, deserializationOptions),
386-
usingNewDeserializer: BSON.deserialize(expectedBuffer, deserializationOptions),
386+
usingNewDeserializer: BSON.deserialize(expectedBuffer, deserializationOptions)
387387
};
388388
// Apparently the Symbol BSON type was deprecated in V4. Symbols in BSON are deserialized as strings in V4
389389
// Therefore, for this type we know there will be a difference between the V1 library and the V4 library,
390390
// so remove Symbol from the list of BSON types that are being compared.
391391
// Browser tests currently don't handle BSON Symbol correctly, so only test this under Node where OldBSON !=== BSON module.
392392
if (BSON !== OldBSON) {
393-
expect(deserialized.usingOldDeserializer['symbol'].value).to.equal(deserialized.usingNewDeserializer['symbol']);
393+
expect(deserialized.usingOldDeserializer['symbol'].value).to.equal(
394+
deserialized.usingNewDeserializer['symbol']
395+
);
394396
}
395397
delete deserialized.usingOldDeserializer['symbol'];
396398
delete deserialized.usingNewDeserializer['symbol'];
397399

398400
const ejsonExpected = {
399-
binary: { $binary: { base64: 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+Pw==', subType: '00' } },
401+
binary: {
402+
$binary: {
403+
base64:
404+
'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+Pw==',
405+
subType: '00'
406+
}
407+
},
400408
code: { $code: 'function() {}' },
401409
dbRef: { $ref: 'tests', $id: { $numberInt: '1' }, $db: 'test' },
402410
decimal128: { $numberDecimal: '9991223372036854775807' },
@@ -412,9 +420,15 @@ describe('Extended JSON', function() {
412420
timestamp: { $timestamp: { t: 0, i: 0 } }
413421
};
414422
const ejsonSerializationOptions = { relaxed: false };
415-
const resultOld = EJSON.serialize(deserialized.usingOldDeserializer, ejsonSerializationOptions);
423+
const resultOld = EJSON.serialize(
424+
deserialized.usingOldDeserializer,
425+
ejsonSerializationOptions
426+
);
416427
expect(resultOld).to.deep.equal(ejsonExpected);
417-
const resultNew = EJSON.serialize(deserialized.usingNewDeserializer, ejsonSerializationOptions);
428+
const resultNew = EJSON.serialize(
429+
deserialized.usingNewDeserializer,
430+
ejsonSerializationOptions
431+
);
418432
expect(resultNew).to.deep.equal(ejsonExpected);
419433
});
420434

@@ -444,7 +458,7 @@ describe('Extended JSON', function() {
444458
oldObjectOldSerializer: OldBSON.serialize(oldMinKey, serializationOptions),
445459
oldObjectNewSerializer: BSON.serialize(oldMinKey, serializationOptions),
446460
newObjectOldSerializer: OldBSON.serialize(newMinKey, serializationOptions),
447-
newObjectNewSerializer: BSON.serialize(newMinKey, serializationOptions),
461+
newObjectNewSerializer: BSON.serialize(newMinKey, serializationOptions)
448462
};
449463

450464
expect(expectedBufferMinKey).to.deep.equal(bsonBuffersMinKey.newObjectNewSerializer);
@@ -453,17 +467,23 @@ describe('Extended JSON', function() {
453467
expect(expectedBufferMinKey).to.deep.equal(bsonBuffersMinKey.oldObjectOldSerializer);
454468

455469
const ejsonExpected = {
456-
minKey: { $minKey: 1 },
470+
minKey: { $minKey: 1 }
457471
};
458472

459473
const deserialized = {
460474
usingOldDeserializer: OldBSON.deserialize(expectedBufferMinKey, deserializationOptions),
461-
usingNewDeserializer: BSON.deserialize(expectedBufferMinKey, deserializationOptions),
475+
usingNewDeserializer: BSON.deserialize(expectedBufferMinKey, deserializationOptions)
462476
};
463477
const ejsonSerializationOptions = { relaxed: false };
464-
const resultOld = EJSON.serialize(deserialized.usingOldDeserializer, ejsonSerializationOptions);
478+
const resultOld = EJSON.serialize(
479+
deserialized.usingOldDeserializer,
480+
ejsonSerializationOptions
481+
);
465482
expect(resultOld).to.deep.equal(ejsonExpected);
466-
const resultNew = EJSON.serialize(deserialized.usingNewDeserializer, ejsonSerializationOptions);
483+
const resultNew = EJSON.serialize(
484+
deserialized.usingNewDeserializer,
485+
ejsonSerializationOptions
486+
);
467487
expect(resultNew).to.deep.equal(ejsonExpected);
468488
});
469489
}

0 commit comments

Comments
 (0)