Skip to content

Commit

Permalink
feat(bsontype): move all _bsontypes to non-enumerable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Aug 2, 2018
1 parent 545900d commit 16f5bf6
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 21 deletions.
6 changes: 1 addition & 5 deletions lib/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class Binary {
throw new Error('only String, Buffer, Uint8Array or Array accepted');
}

this._bsontype = 'Binary';

if (buffer instanceof Number) {
this.sub_type = buffer;
this.position = 0;
Expand Down Expand Up @@ -375,7 +373,5 @@ Binary.SUBTYPE_MD5 = 5;
**/
Binary.SUBTYPE_USER_DEFINED = 128;

/**
* Expose.
*/
Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
module.exports = Binary;
2 changes: 1 addition & 1 deletion lib/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Code {
* @return {Code}
*/
constructor(code, scope) {
this._bsontype = 'Code';
this.code = code;
this.scope = scope;
}
Expand All @@ -25,4 +24,5 @@ class Code {
}
}

Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
module.exports = Code;
3 changes: 2 additions & 1 deletion lib/db_ref.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';

/**
* A class representation of the BSON DBRef type.
*/
Expand All @@ -19,7 +20,6 @@ class DBRef {
collection = parts.shift();
}

this._bsontype = 'DBRef';
this.collection = collection;
this.oid = oid;
this.db = db;
Expand All @@ -44,4 +44,5 @@ class DBRef {
}
}

Object.defineProperty(DBRef.prototype, '_bsontype', { value: 'DBRef' });
module.exports = DBRef;
2 changes: 1 addition & 1 deletion lib/double.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Double {
* @return {Double}
*/
constructor(value) {
this._bsontype = 'Double';
this.value = value;
}

Expand All @@ -32,4 +31,5 @@ class Double {
}
}

Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
module.exports = Double;
2 changes: 1 addition & 1 deletion lib/int_32.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Int32 {
* @return {Int32}
*/
constructor(value) {
this._bsontype = 'Int32';
this.value = value;
}

Expand All @@ -32,4 +31,5 @@ class Int32 {
}
}

Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
module.exports = Int32;
5 changes: 2 additions & 3 deletions lib/max_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class MaxKey {
*
* @return {MaxKey} A MaxKey instance
*/
constructor() {
this._bsontype = 'MaxKey';
}
constructor() {}
}

Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
module.exports = MaxKey;
5 changes: 2 additions & 3 deletions lib/min_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ class MinKey {
*
* @return {MinKey} A MinKey instance
*/
constructor() {
this._bsontype = 'MinKey';
}
constructor() {}
}

Object.defineProperty(MinKey.prototype, '_bsontype', { value: 'MinKey' });
module.exports = MinKey;
5 changes: 1 addition & 4 deletions lib/objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ObjectID {
constructor(id) {
// Duck-typing to support ObjectId from different npm packages
if (id instanceof ObjectID) return id;
this._bsontype = 'ObjectID';

// The most common usecase (blank id, new objectId instance)
if (id == null || typeof id === 'number') {
Expand Down Expand Up @@ -381,7 +380,5 @@ ObjectID.prototype.inspect = ObjectID.prototype.toString;
*/
ObjectID.index = ~~(Math.random() * 0xffffff);

/**
* Expose.
*/
Object.defineProperty(ObjectID.prototype, '_bsontype', { value: 'ObjectID' });
module.exports = ObjectID;
2 changes: 1 addition & 1 deletion lib/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class BSONRegExp {
*/
constructor(pattern, options) {
// Execute
this._bsontype = 'BSONRegExp';
this.pattern = pattern || '';
this.options = options ? alphabetize(options) : '';

Expand All @@ -41,4 +40,5 @@ class BSONRegExp {
}
}

Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' });
module.exports = BSONRegExp;
2 changes: 1 addition & 1 deletion lib/symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Symbol {
* @param {string} value the string representing the symbol.
*/
constructor(value) {
this._bsontype = 'Symbol';
this.value = value;
}

Expand Down Expand Up @@ -45,4 +44,5 @@ class Symbol {
}
}

Object.defineProperty(Symbol.prototype, '_bsontype', { value: 'Symbol' });
module.exports = Symbol;

0 comments on commit 16f5bf6

Please sign in to comment.