bson 4.6.4 → 4.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bower.json +1 -1
- package/bson.d.ts +8 -1
- package/dist/bson.browser.esm.js +95 -143
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +95 -143
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +95 -143
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +92 -143
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +13 -6
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +19 -6
- package/lib/bson.js.map +1 -1
- package/lib/code.js +1 -1
- package/lib/code.js.map +1 -1
- package/lib/db_ref.js +2 -2
- package/lib/db_ref.js.map +1 -1
- package/lib/decimal128.js +13 -13
- package/lib/decimal128.js.map +1 -1
- package/lib/double.js +2 -2
- package/lib/double.js.map +1 -1
- package/lib/ensure_buffer.js +1 -1
- package/lib/ensure_buffer.js.map +1 -1
- package/lib/extended_json.js +24 -12
- package/lib/extended_json.js.map +1 -1
- package/lib/int_32.js +1 -1
- package/lib/int_32.js.map +1 -1
- package/lib/long.js +3 -3
- package/lib/long.js.map +1 -1
- package/lib/map.js +1 -1
- package/lib/map.js.map +1 -1
- package/lib/objectid.js +8 -8
- package/lib/objectid.js.map +1 -1
- package/lib/parser/calculate_size.js +10 -9
- package/lib/parser/calculate_size.js.map +1 -1
- package/lib/parser/deserializer.js +13 -10
- package/lib/parser/deserializer.js.map +1 -1
- package/lib/parser/serializer.js +25 -22
- package/lib/parser/serializer.js.map +1 -1
- package/lib/parser/utils.js +23 -19
- package/lib/parser/utils.js.map +1 -1
- package/lib/regexp.js +4 -4
- package/lib/regexp.js.map +1 -1
- package/lib/symbol.js +1 -1
- package/lib/symbol.js.map +1 -1
- package/lib/timestamp.js +3 -3
- package/lib/timestamp.js.map +1 -1
- package/lib/utils/global.js +1 -1
- package/lib/utils/global.js.map +1 -1
- package/lib/uuid.js +9 -9
- package/lib/uuid.js.map +1 -1
- package/lib/uuid_utils.js +1 -1
- package/lib/uuid_utils.js.map +1 -1
- package/package.json +16 -24
- package/src/binary.ts +7 -0
- package/src/code.ts +1 -1
- package/src/db_ref.ts +1 -1
- package/src/decimal128.ts +3 -3
- package/src/extended_json.ts +13 -2
- package/src/long.ts +32 -7
- package/src/objectid.ts +1 -1
- package/src/parser/calculate_size.ts +4 -3
- package/src/parser/deserializer.ts +6 -3
- package/src/parser/serializer.ts +14 -7
- package/src/parser/utils.ts +24 -20
- package/src/timestamp.ts +1 -1
- package/src/utils/global.ts +1 -1
- package/src/uuid.ts +1 -1
- package/bson-ts34.d.ts +0 -1133
- package/lib/float_parser.js +0 -137
- package/lib/float_parser.js.map +0 -1
- package/src/float_parser.ts +0 -152
package/lib/timestamp.js
CHANGED
|
@@ -29,13 +29,13 @@ var Timestamp = /** @class */ (function (_super) {
|
|
|
29
29
|
function Timestamp(low, high) {
|
|
30
30
|
var _this = this;
|
|
31
31
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
32
|
-
|
|
32
|
+
// @ts-expect-error
|
|
33
33
|
if (!(_this instanceof Timestamp))
|
|
34
34
|
return new Timestamp(low, high);
|
|
35
35
|
if (long_1.Long.isLong(low)) {
|
|
36
36
|
_this = _super.call(this, low.low, low.high, true) || this;
|
|
37
37
|
}
|
|
38
|
-
else if (utils_1.isObjectLike(low) && typeof low.t !== 'undefined' && typeof low.i !== 'undefined') {
|
|
38
|
+
else if ((0, utils_1.isObjectLike)(low) && typeof low.t !== 'undefined' && typeof low.i !== 'undefined') {
|
|
39
39
|
_this = _super.call(this, low.i, low.t, true) || this;
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
@@ -93,7 +93,7 @@ var Timestamp = /** @class */ (function (_super) {
|
|
|
93
93
|
return this.inspect();
|
|
94
94
|
};
|
|
95
95
|
Timestamp.prototype.inspect = function () {
|
|
96
|
-
return "new Timestamp({ t: "
|
|
96
|
+
return "new Timestamp({ t: ".concat(this.getHighBits(), ", i: ").concat(this.getLowBits(), " })");
|
|
97
97
|
};
|
|
98
98
|
Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE;
|
|
99
99
|
return Timestamp;
|
package/lib/timestamp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../src/timestamp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAC9B,wCAA8C;AAQ9C,cAAc;AACD,QAAA,yBAAyB,GACpC,WAAuC,CAAC;AAU1C;;;KAGK;AACL;IAA+B,6BAAyB;IAmBtD,mBAAY,GAA6C,EAAE,IAAa;QAAxE,iBAkBC;QAjBC,6DAA6D;QAC7D,mBAAmB;QACnB,IAAI,CAAC,CAAC,KAAI,YAAY,SAAS,CAAC;YAAE,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAElE,IAAI,WAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACpB,QAAA,kBAAM,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAC;SAChC;aAAM,IAAI,oBAAY,
|
|
1
|
+
{"version":3,"file":"timestamp.js","sourceRoot":"","sources":["../src/timestamp.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAC9B,wCAA8C;AAQ9C,cAAc;AACD,QAAA,yBAAyB,GACpC,WAAuC,CAAC;AAU1C;;;KAGK;AACL;IAA+B,6BAAyB;IAmBtD,mBAAY,GAA6C,EAAE,IAAa;QAAxE,iBAkBC;QAjBC,6DAA6D;QAC7D,mBAAmB;QACnB,IAAI,CAAC,CAAC,KAAI,YAAY,SAAS,CAAC;YAAE,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAElE,IAAI,WAAI,CAAC,MAAM,CAAC,GA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AC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,gBAAgB;IAChB,kCAAc,GAAd;QACE,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE,EAAE,CAAC;IACnE,CAAC;IAED,gBAAgB;IACT,0BAAgB,GAAvB,UAAwB,GAAsB;QAC5C,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB;IAChB,oBAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,GAA1C;QACE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,2BAAO,GAAP;QACE,OAAO,6BAAsB,IAAI,CAAC,WAAW,EAAE,kBAAQ,IAAI,CAAC,UAAU,EAAE,QAAK,CAAC;IAChF,CAAC;IAzFe,mBAAS,GAAG,WAAI,CAAC,kBAAkB,CAAC;IA0FtD,gBAAC;CAAA,AA7FD,CAA+B,iCAAyB,GA6FvD;AA7FY,8BAAS"}
|
package/lib/utils/global.js
CHANGED
|
@@ -7,11 +7,11 @@ function checkForMath(potentialGlobal) {
|
|
|
7
7
|
}
|
|
8
8
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
9
9
|
function getGlobal() {
|
|
10
|
-
// eslint-disable-next-line no-undef
|
|
11
10
|
return (checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
12
11
|
checkForMath(typeof window === 'object' && window) ||
|
|
13
12
|
checkForMath(typeof self === 'object' && self) ||
|
|
14
13
|
checkForMath(typeof global === 'object' && global) ||
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
15
15
|
Function('return this')());
|
|
16
16
|
}
|
|
17
17
|
exports.getGlobal = getGlobal;
|
package/lib/utils/global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/utils/global.ts"],"names":[],"mappings":";;;AAMA,SAAS,YAAY,CAAC,eAAoB;IACxC,kCAAkC;IAClC,OAAO,eAAe,IAAI,eAAe,CAAC,IAAI,IAAI,IAAI,IAAI,eAAe,CAAC;AAC5E,CAAC;AAED,uEAAuE;AACvE,SAAgB,SAAS;IACvB,
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../src/utils/global.ts"],"names":[],"mappings":";;;AAMA,SAAS,YAAY,CAAC,eAAoB;IACxC,kCAAkC;IAClC,OAAO,eAAe,IAAI,eAAe,CAAC,IAAI,IAAI,IAAI,IAAI,eAAe,CAAC;AAC5E,CAAC;AAED,uEAAuE;AACvE,SAAgB,SAAS;IACvB,OAAO,CACL,YAAY,CAAC,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC;QAC1D,YAAY,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC;QAClD,YAAY,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC;QAC9C,YAAY,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC;QAClD,8DAA8D;QAC9D,QAAQ,CAAC,aAAa,CAAC,EAAE,CAC1B,CAAC;AACJ,CAAC;AATD,8BASC"}
|
package/lib/uuid.js
CHANGED
|
@@ -29,10 +29,10 @@ var UUID = /** @class */ (function () {
|
|
|
29
29
|
this.__id = input.__id;
|
|
30
30
|
}
|
|
31
31
|
else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
|
|
32
|
-
this.id = ensure_buffer_1.ensureBuffer(input);
|
|
32
|
+
this.id = (0, ensure_buffer_1.ensureBuffer)(input);
|
|
33
33
|
}
|
|
34
34
|
else if (typeof input === 'string') {
|
|
35
|
-
this.id = uuid_utils_1.uuidHexStringToBuffer(input);
|
|
35
|
+
this.id = (0, uuid_utils_1.uuidHexStringToBuffer)(input);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
throw new error_1.BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
|
|
@@ -49,7 +49,7 @@ var UUID = /** @class */ (function () {
|
|
|
49
49
|
set: function (value) {
|
|
50
50
|
this[kId] = value;
|
|
51
51
|
if (UUID.cacheHexString) {
|
|
52
|
-
this.__id = uuid_utils_1.bufferToUuidHexString(value);
|
|
52
|
+
this.__id = (0, uuid_utils_1.bufferToUuidHexString)(value);
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
enumerable: false,
|
|
@@ -67,7 +67,7 @@ var UUID = /** @class */ (function () {
|
|
|
67
67
|
if (UUID.cacheHexString && this.__id) {
|
|
68
68
|
return this.__id;
|
|
69
69
|
}
|
|
70
|
-
var uuidHexString = uuid_utils_1.bufferToUuidHexString(this.id, includeDashes);
|
|
70
|
+
var uuidHexString = (0, uuid_utils_1.bufferToUuidHexString)(this.id, includeDashes);
|
|
71
71
|
if (UUID.cacheHexString) {
|
|
72
72
|
this.__id = uuidHexString;
|
|
73
73
|
}
|
|
@@ -115,7 +115,7 @@ var UUID = /** @class */ (function () {
|
|
|
115
115
|
* Generates a populated buffer containing a v4 uuid
|
|
116
116
|
*/
|
|
117
117
|
UUID.generate = function () {
|
|
118
|
-
var bytes = utils_1.randomBytes(BYTE_LENGTH);
|
|
118
|
+
var bytes = (0, utils_1.randomBytes)(BYTE_LENGTH);
|
|
119
119
|
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
120
120
|
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
|
121
121
|
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
@@ -134,9 +134,9 @@ var UUID = /** @class */ (function () {
|
|
|
134
134
|
return true;
|
|
135
135
|
}
|
|
136
136
|
if (typeof input === 'string') {
|
|
137
|
-
return uuid_utils_1.uuidValidateString(input);
|
|
137
|
+
return (0, uuid_utils_1.uuidValidateString)(input);
|
|
138
138
|
}
|
|
139
|
-
if (utils_1.isUint8Array(input)) {
|
|
139
|
+
if ((0, utils_1.isUint8Array)(input)) {
|
|
140
140
|
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
|
|
141
141
|
if (input.length !== BYTE_LENGTH) {
|
|
142
142
|
return false;
|
|
@@ -157,7 +157,7 @@ var UUID = /** @class */ (function () {
|
|
|
157
157
|
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
158
158
|
*/
|
|
159
159
|
UUID.createFromHexString = function (hexString) {
|
|
160
|
-
var buffer = uuid_utils_1.uuidHexStringToBuffer(hexString);
|
|
160
|
+
var buffer = (0, uuid_utils_1.uuidHexStringToBuffer)(hexString);
|
|
161
161
|
return new UUID(buffer);
|
|
162
162
|
};
|
|
163
163
|
/**
|
|
@@ -170,7 +170,7 @@ var UUID = /** @class */ (function () {
|
|
|
170
170
|
return this.inspect();
|
|
171
171
|
};
|
|
172
172
|
UUID.prototype.inspect = function () {
|
|
173
|
-
return "new UUID(\""
|
|
173
|
+
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
174
174
|
};
|
|
175
175
|
return UUID;
|
|
176
176
|
}());
|
package/lib/uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,iDAA+C;AAC/C,mCAAkC;AAClC,2CAAgG;AAChG,wCAA2D;AAC3D,iCAAwC;AAOxC,IAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,IAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAEzB;;;GAGG;AACH;IAWE;;;;OAIG;IACH,cAAY,KAA8B;QACxC,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,2DAA2D;Y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,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,eAAM,CAAC,YAAY,CAAC;aACvE;YAAC,WAAM;gBACN,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,wBAAmB,GAA1B,UAA2B,SAAiB;QAC1C,IAAM,MAAM,GAAG,IAAA,kCAAqB,EAAC,SAAS,CAAC,CAAC;QAChD,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,eAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,GAA1C;QACE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,sBAAO,GAAP;QACE,OAAO,qBAAa,IAAI,CAAC,WAAW,EAAE,QAAI,CAAC;IAC7C,CAAC;IACH,WAAC;AAAD,CAAC,AA1LD,IA0LC;AA1LY,oBAAI;AA4LjB,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC"}
|
package/lib/uuid_utils.js
CHANGED
|
@@ -10,7 +10,7 @@ var uuidValidateString = function (str) {
|
|
|
10
10
|
};
|
|
11
11
|
exports.uuidValidateString = uuidValidateString;
|
|
12
12
|
var uuidHexStringToBuffer = function (hexString) {
|
|
13
|
-
if (!exports.uuidValidateString(hexString)) {
|
|
13
|
+
if (!(0, exports.uuidValidateString)(hexString)) {
|
|
14
14
|
throw new error_1.BSONTypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
|
|
15
15
|
}
|
|
16
16
|
var sanitizedHexString = hexString.replace(/-/g, '');
|
package/lib/uuid_utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid_utils.js","sourceRoot":"","sources":["../src/uuid_utils.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,iCAAwC;AAExC,kEAAkE;AAClE,IAAM,gBAAgB,GACpB,uHAAuH,CAAC;AAEnH,IAAM,kBAAkB,GAAG,UAAC,GAAW;IAC5C,OAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;AAArD,CAAqD,CAAC;AAD3C,QAAA,kBAAkB,sBACyB;AAEjD,IAAM,qBAAqB,GAAG,UAAC,SAAiB;IACrD,IAAI,CAAC,0BAAkB,
|
|
1
|
+
{"version":3,"file":"uuid_utils.js","sourceRoot":"","sources":["../src/uuid_utils.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,iCAAwC;AAExC,kEAAkE;AAClE,IAAM,gBAAgB,GACpB,uHAAuH,CAAC;AAEnH,IAAM,kBAAkB,GAAG,UAAC,GAAW;IAC5C,OAAA,OAAO,GAAG,KAAK,QAAQ,IAAI,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;AAArD,CAAqD,CAAC;AAD3C,QAAA,kBAAkB,sBACyB;AAEjD,IAAM,qBAAqB,GAAG,UAAC,SAAiB;IACrD,IAAI,CAAC,IAAA,0BAAkB,EAAC,SAAS,CAAC,EAAE;QAClC,MAAM,IAAI,qBAAa,CACrB,uLAAuL,CACxL,CAAC;KACH;IAED,IAAM,kBAAkB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,eAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC;AAEK,IAAM,qBAAqB,GAAG,UAAC,MAAc,EAAE,aAAoB;IAApB,8BAAA,EAAA,oBAAoB;IACxE,OAAA,aAAa;QACX,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,GAAG;YACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,GAAG;YACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5B,GAAG;YACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,GAAG;YACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;AAV1B,CAU0B,CAAC;AAXhB,QAAA,qBAAqB,yBAWL"}
|
package/package.json
CHANGED
|
@@ -11,19 +11,11 @@
|
|
|
11
11
|
"src",
|
|
12
12
|
"dist",
|
|
13
13
|
"bson.d.ts",
|
|
14
|
-
"bson-ts34.d.ts",
|
|
15
14
|
"etc/prepare.js",
|
|
16
15
|
"bower.json"
|
|
17
16
|
],
|
|
18
17
|
"types": "bson.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"<=4.0.2": {
|
|
21
|
-
"bson.d.ts": [
|
|
22
|
-
"bson.ts34.d.ts"
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"version": "4.6.4",
|
|
18
|
+
"version": "4.6.5",
|
|
27
19
|
"author": {
|
|
28
20
|
"name": "The MongoDB NodeJS Team",
|
|
29
21
|
"email": "dbx-node@mongodb.com"
|
|
@@ -38,22 +30,23 @@
|
|
|
38
30
|
"@babel/plugin-external-helpers": "^7.10.4",
|
|
39
31
|
"@babel/preset-env": "^7.11.0",
|
|
40
32
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
41
|
-
"@microsoft/api-extractor": "^7.
|
|
33
|
+
"@microsoft/api-extractor": "^7.28.0",
|
|
42
34
|
"@rollup/plugin-babel": "^5.2.0",
|
|
43
35
|
"@rollup/plugin-commonjs": "^15.0.0",
|
|
44
36
|
"@rollup/plugin-json": "^4.1.0",
|
|
45
37
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
38
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
46
39
|
"@rollup/plugin-typescript": "^6.0.0",
|
|
47
|
-
"@
|
|
48
|
-
"@typescript-eslint/
|
|
40
|
+
"@types/node": "^18.0.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
|
42
|
+
"@typescript-eslint/parser": "^5.30.0",
|
|
49
43
|
"array-includes": "^3.1.3",
|
|
50
44
|
"benchmark": "^2.1.4",
|
|
51
45
|
"chai": "^4.2.0",
|
|
52
|
-
"
|
|
53
|
-
"eslint": "^
|
|
54
|
-
"eslint-
|
|
55
|
-
"eslint-plugin-
|
|
56
|
-
"eslint-plugin-tsdoc": "^0.2.6",
|
|
46
|
+
"eslint": "^8.18.0",
|
|
47
|
+
"eslint-config-prettier": "^8.5.0",
|
|
48
|
+
"eslint-plugin-prettier": "^4.1.0",
|
|
49
|
+
"eslint-plugin-tsdoc": "^0.2.16",
|
|
57
50
|
"karma": "^6.3.4",
|
|
58
51
|
"karma-chai": "^0.1.0",
|
|
59
52
|
"karma-chrome-launcher": "^3.1.0",
|
|
@@ -63,19 +56,18 @@
|
|
|
63
56
|
"mocha": "5.2.0",
|
|
64
57
|
"node-fetch": "^2.6.1",
|
|
65
58
|
"nyc": "^15.1.0",
|
|
66
|
-
"object.entries": "^1.1.
|
|
67
|
-
"prettier": "^2.
|
|
59
|
+
"object.entries": "^1.1.5",
|
|
60
|
+
"prettier": "^2.7.1",
|
|
68
61
|
"rimraf": "^3.0.2",
|
|
69
62
|
"rollup": "^2.26.5",
|
|
70
63
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
71
64
|
"rollup-plugin-node-globals": "^1.4.0",
|
|
72
65
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
73
66
|
"rollup-plugin-polyfill-node": "^0.7.0",
|
|
74
|
-
"standard-version": "^9.
|
|
67
|
+
"standard-version": "^9.5.0",
|
|
75
68
|
"ts-node": "^9.0.0",
|
|
76
|
-
"tsd": "^0.
|
|
77
|
-
"
|
|
78
|
-
"typescript": "^4.0.2",
|
|
69
|
+
"tsd": "^0.21.0",
|
|
70
|
+
"typescript": "^4.7.4",
|
|
79
71
|
"typescript-cached-transpile": "0.0.6",
|
|
80
72
|
"uuid": "^8.3.2"
|
|
81
73
|
},
|
|
@@ -107,7 +99,7 @@
|
|
|
107
99
|
"test-tsd": "npm run build:dts && tsd",
|
|
108
100
|
"test-browser": "node --max-old-space-size=4096 ./node_modules/.bin/karma start karma.conf.js",
|
|
109
101
|
"build:ts": "tsc",
|
|
110
|
-
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && rimraf 'lib/**/*.d.ts*'
|
|
102
|
+
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && rimraf 'lib/**/*.d.ts*'",
|
|
111
103
|
"build:bundle": "rollup -c rollup.config.js",
|
|
112
104
|
"build": "npm run build:dts && npm run build:bundle",
|
|
113
105
|
"lint": "eslint -v && eslint --ext '.js,.ts' --max-warnings=0 src test && tsc -v && tsc --noEmit && npm run test-tsd",
|
package/src/binary.ts
CHANGED
|
@@ -62,6 +62,13 @@ export class Binary {
|
|
|
62
62
|
position!: number;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
+
* Create a new Binary instance.
|
|
66
|
+
*
|
|
67
|
+
* This constructor can accept a string as its first argument. In this case,
|
|
68
|
+
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
|
|
69
|
+
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
|
|
70
|
+
* instead to convert the string to a Buffer using UTF-8 first.
|
|
71
|
+
*
|
|
65
72
|
* @param buffer - a buffer object containing the binary data.
|
|
66
73
|
* @param subType - the option binary type.
|
|
67
74
|
*/
|
package/src/code.ts
CHANGED
package/src/db_ref.ts
CHANGED
|
@@ -115,7 +115,7 @@ export class DBRef {
|
|
|
115
115
|
// NOTE: if OID is an ObjectId class it will just print the oid string.
|
|
116
116
|
const oid =
|
|
117
117
|
this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
|
|
118
|
-
return `new DBRef("${this.namespace}", new ObjectId("${oid}")${
|
|
118
|
+
return `new DBRef("${this.namespace}", new ObjectId("${String(oid)}")${
|
|
119
119
|
this.db ? `, "${this.db}"` : ''
|
|
120
120
|
})`;
|
|
121
121
|
}
|
package/src/decimal128.ts
CHANGED
|
@@ -690,8 +690,8 @@ export class Decimal128 {
|
|
|
690
690
|
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
|
|
691
691
|
if (significand_digits > 34) {
|
|
692
692
|
string.push(`${0}`);
|
|
693
|
-
if (exponent > 0) string.push(
|
|
694
|
-
else if (exponent < 0) string.push(
|
|
693
|
+
if (exponent > 0) string.push(`E+${exponent}`);
|
|
694
|
+
else if (exponent < 0) string.push(`E${exponent}`);
|
|
695
695
|
return string.join('');
|
|
696
696
|
}
|
|
697
697
|
|
|
@@ -709,7 +709,7 @@ export class Decimal128 {
|
|
|
709
709
|
// Exponent
|
|
710
710
|
string.push('E');
|
|
711
711
|
if (scientific_exponent > 0) {
|
|
712
|
-
string.push(
|
|
712
|
+
string.push(`+${scientific_exponent}`);
|
|
713
713
|
} else {
|
|
714
714
|
string.push(`${scientific_exponent}`);
|
|
715
715
|
}
|
package/src/extended_json.ts
CHANGED
|
@@ -44,7 +44,8 @@ export function isBSONType(value: unknown): value is BSONType {
|
|
|
44
44
|
const BSON_INT32_MAX = 0x7fffffff;
|
|
45
45
|
const BSON_INT32_MIN = -0x80000000;
|
|
46
46
|
// INT64 boundaries
|
|
47
|
-
const BSON_INT64_MAX = 0x7fffffffffffffff;
|
|
47
|
+
// const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
|
|
48
|
+
const BSON_INT64_MAX = 0x8000000000000000;
|
|
48
49
|
const BSON_INT64_MIN = -0x8000000000000000;
|
|
49
50
|
|
|
50
51
|
// all the types where we don't need to do any special processing and can just pass the EJSON
|
|
@@ -284,7 +285,17 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
|
|
|
284
285
|
for (const name in doc) {
|
|
285
286
|
options.seenObjects.push({ propertyName: name, obj: null });
|
|
286
287
|
try {
|
|
287
|
-
|
|
288
|
+
const value = serializeValue(doc[name], options);
|
|
289
|
+
if (name === '__proto__') {
|
|
290
|
+
Object.defineProperty(_doc, name, {
|
|
291
|
+
value,
|
|
292
|
+
writable: true,
|
|
293
|
+
enumerable: true,
|
|
294
|
+
configurable: true
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
_doc[name] = value;
|
|
298
|
+
}
|
|
288
299
|
} finally {
|
|
289
300
|
options.seenObjects.pop();
|
|
290
301
|
}
|
package/src/long.ts
CHANGED
|
@@ -4,12 +4,37 @@ import type { Timestamp } from './timestamp';
|
|
|
4
4
|
|
|
5
5
|
interface LongWASMHelpers {
|
|
6
6
|
/** Gets the high bits of the last operation performed */
|
|
7
|
-
get_high(): number;
|
|
8
|
-
div_u(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
get_high(this: void): number;
|
|
8
|
+
div_u(
|
|
9
|
+
this: void,
|
|
10
|
+
lowBits: number,
|
|
11
|
+
highBits: number,
|
|
12
|
+
lowBitsDivisor: number,
|
|
13
|
+
highBitsDivisor: number
|
|
14
|
+
): number;
|
|
15
|
+
div_s(
|
|
16
|
+
this: void,
|
|
17
|
+
lowBits: number,
|
|
18
|
+
highBits: number,
|
|
19
|
+
lowBitsDivisor: number,
|
|
20
|
+
highBitsDivisor: number
|
|
21
|
+
): number;
|
|
22
|
+
rem_u(
|
|
23
|
+
this: void,
|
|
24
|
+
lowBits: number,
|
|
25
|
+
highBits: number,
|
|
26
|
+
lowBitsDivisor: number,
|
|
27
|
+
highBitsDivisor: number
|
|
28
|
+
): number;
|
|
29
|
+
rem_s(
|
|
30
|
+
this: void,
|
|
31
|
+
lowBits: number,
|
|
32
|
+
highBits: number,
|
|
33
|
+
lowBitsDivisor: number,
|
|
34
|
+
highBitsDivisor: number
|
|
35
|
+
): number;
|
|
12
36
|
mul(
|
|
37
|
+
this: void,
|
|
13
38
|
lowBits: number,
|
|
14
39
|
highBits: number,
|
|
15
40
|
lowBitsMultiplier: number,
|
|
@@ -306,8 +331,7 @@ export class Long {
|
|
|
306
331
|
/**
|
|
307
332
|
* Tests if the specified object is a Long.
|
|
308
333
|
*/
|
|
309
|
-
|
|
310
|
-
static isLong(value: any): value is Long {
|
|
334
|
+
static isLong(value: unknown): value is Long {
|
|
311
335
|
return isObjectLike(value) && value['__isLong__'] === true;
|
|
312
336
|
}
|
|
313
337
|
|
|
@@ -471,6 +495,7 @@ export class Long {
|
|
|
471
495
|
// into the result, and subtract it from the remainder. It is critical that
|
|
472
496
|
// the approximate value is less than or equal to the real value so that the
|
|
473
497
|
// remainder never becomes negative.
|
|
498
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
474
499
|
rem = this;
|
|
475
500
|
while (rem.gte(divisor)) {
|
|
476
501
|
// Approximate the result of division. This may be a little greater or
|
package/src/objectid.ts
CHANGED
|
@@ -121,15 +121,16 @@ function calculateElement(
|
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
} else if (value['_bsontype'] === 'Binary') {
|
|
124
|
+
const binary: Binary = value;
|
|
124
125
|
// Check what kind of subtype we have
|
|
125
|
-
if (
|
|
126
|
+
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
126
127
|
return (
|
|
127
128
|
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +
|
|
128
|
-
(
|
|
129
|
+
(binary.position + 1 + 4 + 1 + 4)
|
|
129
130
|
);
|
|
130
131
|
} else {
|
|
131
132
|
return (
|
|
132
|
-
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (
|
|
133
|
+
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1)
|
|
133
134
|
);
|
|
134
135
|
}
|
|
135
136
|
} else if (value['_bsontype'] === 'Symbol') {
|
|
@@ -197,6 +197,7 @@ function deserializeObject(
|
|
|
197
197
|
let isPossibleDBRef = isArray ? false : null;
|
|
198
198
|
|
|
199
199
|
// While we have more left data left keep parsing
|
|
200
|
+
const dataview = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
200
201
|
while (!done) {
|
|
201
202
|
// Read the type
|
|
202
203
|
const elementType = buffer[index++];
|
|
@@ -263,10 +264,10 @@ function deserializeObject(
|
|
|
263
264
|
(buffer[index++] << 16) |
|
|
264
265
|
(buffer[index++] << 24);
|
|
265
266
|
} else if (elementType === constants.BSON_DATA_NUMBER && promoteValues === false) {
|
|
266
|
-
value = new Double(
|
|
267
|
+
value = new Double(dataview.getFloat64(index, true));
|
|
267
268
|
index = index + 8;
|
|
268
269
|
} else if (elementType === constants.BSON_DATA_NUMBER) {
|
|
269
|
-
value =
|
|
270
|
+
value = dataview.getFloat64(index, true);
|
|
270
271
|
index = index + 8;
|
|
271
272
|
} else if (elementType === constants.BSON_DATA_DATE) {
|
|
272
273
|
const lowBits =
|
|
@@ -697,7 +698,7 @@ function deserializeObject(
|
|
|
697
698
|
value = new DBRef(namespace, oid);
|
|
698
699
|
} else {
|
|
699
700
|
throw new BSONError(
|
|
700
|
-
|
|
701
|
+
`Detected unknown BSON type ${elementType.toString(16)} for fieldname "${name}"`
|
|
701
702
|
);
|
|
702
703
|
}
|
|
703
704
|
if (name === '__proto__') {
|
|
@@ -742,9 +743,11 @@ function isolateEval(
|
|
|
742
743
|
functionCache?: { [hash: string]: Function },
|
|
743
744
|
object?: Document
|
|
744
745
|
) {
|
|
746
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
745
747
|
if (!functionCache) return new Function(functionString);
|
|
746
748
|
// Check for cache hit, eval if missing and return cached function
|
|
747
749
|
if (functionCache[functionString] == null) {
|
|
750
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
748
751
|
functionCache[functionString] = new Function(functionString);
|
|
749
752
|
}
|
|
750
753
|
|
package/src/parser/serializer.ts
CHANGED
|
@@ -9,7 +9,6 @@ import type { Double } from '../double';
|
|
|
9
9
|
import { ensureBuffer } from '../ensure_buffer';
|
|
10
10
|
import { BSONError, BSONTypeError } from '../error';
|
|
11
11
|
import { isBSONType } from '../extended_json';
|
|
12
|
-
import { writeIEEE754 } from '../float_parser';
|
|
13
12
|
import type { Int32 } from '../int_32';
|
|
14
13
|
import { Long } from '../long';
|
|
15
14
|
import { Map } from '../map';
|
|
@@ -79,6 +78,12 @@ function serializeString(
|
|
|
79
78
|
return index;
|
|
80
79
|
}
|
|
81
80
|
|
|
81
|
+
const SPACE_FOR_FLOAT64 = new Uint8Array(8);
|
|
82
|
+
const DV_FOR_FLOAT64 = new DataView(
|
|
83
|
+
SPACE_FOR_FLOAT64.buffer,
|
|
84
|
+
SPACE_FOR_FLOAT64.byteOffset,
|
|
85
|
+
SPACE_FOR_FLOAT64.byteLength
|
|
86
|
+
);
|
|
82
87
|
function serializeNumber(
|
|
83
88
|
buffer: Buffer,
|
|
84
89
|
key: string,
|
|
@@ -119,7 +124,8 @@ function serializeNumber(
|
|
|
119
124
|
index = index + numberOfWrittenBytes;
|
|
120
125
|
buffer[index++] = 0;
|
|
121
126
|
// Write float
|
|
122
|
-
|
|
127
|
+
DV_FOR_FLOAT64.setFloat64(0, value, true);
|
|
128
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
123
129
|
// Adjust index
|
|
124
130
|
index = index + 8;
|
|
125
131
|
}
|
|
@@ -487,7 +493,8 @@ function serializeDouble(
|
|
|
487
493
|
buffer[index++] = 0;
|
|
488
494
|
|
|
489
495
|
// Write float
|
|
490
|
-
|
|
496
|
+
DV_FOR_FLOAT64.setFloat64(0, value.value, true);
|
|
497
|
+
buffer.set(SPACE_FOR_FLOAT64, index);
|
|
491
498
|
|
|
492
499
|
// Adjust index
|
|
493
500
|
index = index + 8;
|
|
@@ -763,7 +770,7 @@ export function serializeInto(
|
|
|
763
770
|
if (Array.isArray(object)) {
|
|
764
771
|
// Get object keys
|
|
765
772
|
for (let i = 0; i < object.length; i++) {
|
|
766
|
-
const key =
|
|
773
|
+
const key = `${i}`;
|
|
767
774
|
let value = object[i];
|
|
768
775
|
|
|
769
776
|
// Is there an override value
|
|
@@ -841,7 +848,7 @@ export function serializeInto(
|
|
|
841
848
|
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
|
|
842
849
|
index = serializeMinMax(buffer, key, value, index, true);
|
|
843
850
|
} else if (typeof value['_bsontype'] !== 'undefined') {
|
|
844
|
-
throw new BSONTypeError(
|
|
851
|
+
throw new BSONTypeError(`Unrecognized or invalid _bsontype: ${String(value['_bsontype'])}`);
|
|
845
852
|
}
|
|
846
853
|
}
|
|
847
854
|
} else if (object instanceof Map || isMap(object)) {
|
|
@@ -942,7 +949,7 @@ export function serializeInto(
|
|
|
942
949
|
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
|
|
943
950
|
index = serializeMinMax(buffer, key, value, index);
|
|
944
951
|
} else if (typeof value['_bsontype'] !== 'undefined') {
|
|
945
|
-
throw new BSONTypeError(
|
|
952
|
+
throw new BSONTypeError(`Unrecognized or invalid _bsontype: ${String(value['_bsontype'])}`);
|
|
946
953
|
}
|
|
947
954
|
}
|
|
948
955
|
} else {
|
|
@@ -1047,7 +1054,7 @@ export function serializeInto(
|
|
|
1047
1054
|
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
|
|
1048
1055
|
index = serializeMinMax(buffer, key, value, index);
|
|
1049
1056
|
} else if (typeof value['_bsontype'] !== 'undefined') {
|
|
1050
|
-
throw new BSONTypeError(
|
|
1057
|
+
throw new BSONTypeError(`Unrecognized or invalid _bsontype: ${String(value['_bsontype'])}`);
|
|
1051
1058
|
}
|
|
1052
1059
|
}
|
|
1053
1060
|
}
|
package/src/parser/utils.ts
CHANGED
|
@@ -33,33 +33,37 @@ declare let window: any;
|
|
|
33
33
|
declare let require: Function;
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
35
|
declare let global: any;
|
|
36
|
-
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
declare let process: any; // Used by @rollup/plugin-replace
|
|
37
38
|
|
|
38
39
|
const detectRandomBytes = (): RandomBytesFunction => {
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (process.browser) {
|
|
41
|
+
if (typeof window !== 'undefined') {
|
|
42
|
+
// browser crypto implementation(s)
|
|
43
|
+
const target = window.crypto || window.msCrypto; // allow for IE11
|
|
44
|
+
if (target && target.getRandomValues) {
|
|
45
|
+
return size => target.getRandomValues(Buffer.alloc(size));
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
|
-
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (typeof global !== 'undefined' && global.crypto && global.crypto.getRandomValues) {
|
|
50
|
+
// allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
|
|
51
|
+
return size => global.crypto.getRandomValues(Buffer.alloc(size));
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
return insecureRandomBytes;
|
|
55
|
+
} else {
|
|
56
|
+
let requiredRandomBytes: RandomBytesFunction | null | undefined;
|
|
57
|
+
try {
|
|
58
|
+
requiredRandomBytes = require('crypto').randomBytes;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
// keep the fallback
|
|
61
|
+
}
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
// NOTE: in transpiled cases the above require might return null/undefined
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
return requiredRandomBytes || insecureRandomBytes;
|
|
66
|
+
}
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
export const randomBytes = detectRandomBytes();
|
package/src/timestamp.ts
CHANGED
|
@@ -44,7 +44,7 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
44
44
|
constructor(low: number, high: number);
|
|
45
45
|
constructor(low: number | Long | { t: number; i: number }, high?: number) {
|
|
46
46
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
47
|
-
|
|
47
|
+
// @ts-expect-error
|
|
48
48
|
if (!(this instanceof Timestamp)) return new Timestamp(low, high);
|
|
49
49
|
|
|
50
50
|
if (Long.isLong(low)) {
|
package/src/utils/global.ts
CHANGED
|
@@ -11,12 +11,12 @@ function checkForMath(potentialGlobal: any) {
|
|
|
11
11
|
|
|
12
12
|
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
|
|
13
13
|
export function getGlobal<T = Record<string, unknown>>(): T {
|
|
14
|
-
// eslint-disable-next-line no-undef
|
|
15
14
|
return (
|
|
16
15
|
checkForMath(typeof globalThis === 'object' && globalThis) ||
|
|
17
16
|
checkForMath(typeof window === 'object' && window) ||
|
|
18
17
|
checkForMath(typeof self === 'object' && self) ||
|
|
19
18
|
checkForMath(typeof global === 'object' && global) ||
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
20
20
|
Function('return this')()
|
|
21
21
|
);
|
|
22
22
|
}
|