bson 6.10.3 → 7.0.0-alpha
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/README.md +11 -1
- package/bson.d.ts +21 -14
- package/lib/bson.bundle.js +147 -78
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +147 -78
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +148 -80
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +4636 -0
- package/lib/bson.node.mjs.map +1 -0
- package/lib/bson.rn.cjs +146 -80
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +32 -32
- package/src/binary.ts +27 -4
- package/src/bson.ts +1 -1
- package/src/bson_value.ts +24 -1
- package/src/extended_json.ts +0 -3
- package/src/long.ts +4 -9
- package/src/objectid.ts +25 -25
- package/src/parser/on_demand/parse_to_elements.ts +25 -23
- package/src/timestamp.ts +10 -1
- package/src/utils/node_byte_utils.ts +15 -22
- package/src/utils/number_utils.ts +4 -13
- package/vendor/base64/LICENSE-MIT.txt +0 -20
- package/vendor/base64/README.md +0 -112
- package/vendor/base64/base64.js +0 -157
- package/vendor/base64/package.json +0 -43
- package/vendor/text-encoding/LICENSE.md +0 -237
- package/vendor/text-encoding/README.md +0 -111
- package/vendor/text-encoding/index.js +0 -9
- package/vendor/text-encoding/lib/encoding-indexes.js +0 -47
- package/vendor/text-encoding/lib/encoding.js +0 -3301
- package/vendor/text-encoding/package.json +0 -37
package/lib/bson.mjs
CHANGED
|
@@ -140,6 +140,7 @@ class BSONOffsetError extends BSONError {
|
|
|
140
140
|
get name() {
|
|
141
141
|
return 'BSONOffsetError';
|
|
142
142
|
}
|
|
143
|
+
offset;
|
|
143
144
|
constructor(message, offset, options) {
|
|
144
145
|
super(`${message}. offset: ${offset}`, options);
|
|
145
146
|
this.offset = offset;
|
|
@@ -216,11 +217,15 @@ function tryWriteBasicLatin(destination, source, offset) {
|
|
|
216
217
|
function nodejsMathRandomBytes(byteLength) {
|
|
217
218
|
return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
218
219
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
function nodejsSecureRandomBytes(byteLength) {
|
|
221
|
+
return crypto.getRandomValues(nodeJsByteUtils.allocate(byteLength));
|
|
222
|
+
}
|
|
223
|
+
const nodejsRandomBytes = (() => {
|
|
224
|
+
const { crypto } = globalThis;
|
|
225
|
+
if (crypto != null && typeof crypto.getRandomValues === 'function') {
|
|
226
|
+
return nodejsSecureRandomBytes;
|
|
222
227
|
}
|
|
223
|
-
|
|
228
|
+
else {
|
|
224
229
|
return nodejsMathRandomBytes;
|
|
225
230
|
}
|
|
226
231
|
})();
|
|
@@ -439,7 +444,11 @@ const webByteUtils = {
|
|
|
439
444
|
const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
|
|
440
445
|
const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
|
441
446
|
|
|
447
|
+
const bsonType = Symbol.for('@@mdb.bson.type');
|
|
442
448
|
class BSONValue {
|
|
449
|
+
get [bsonType]() {
|
|
450
|
+
return this._bsontype;
|
|
451
|
+
}
|
|
443
452
|
get [BSON_VERSION_SYMBOL]() {
|
|
444
453
|
return BSON_MAJOR_VERSION;
|
|
445
454
|
}
|
|
@@ -490,7 +499,7 @@ const NumberUtils = {
|
|
|
490
499
|
source[offset + 1] * 256 +
|
|
491
500
|
source[offset + 2] * 65536 +
|
|
492
501
|
source[offset + 3] * 16777216);
|
|
493
|
-
return (hi <<
|
|
502
|
+
return (hi << 32n) + lo;
|
|
494
503
|
},
|
|
495
504
|
getFloat64LE: isBigEndian
|
|
496
505
|
? (source, offset) => {
|
|
@@ -536,7 +545,7 @@ const NumberUtils = {
|
|
|
536
545
|
return 4;
|
|
537
546
|
},
|
|
538
547
|
setBigInt64LE(destination, offset, value) {
|
|
539
|
-
const mask32bits =
|
|
548
|
+
const mask32bits = 0xffffffffn;
|
|
540
549
|
let lo = Number(value & mask32bits);
|
|
541
550
|
destination[offset] = lo;
|
|
542
551
|
lo >>= 8;
|
|
@@ -545,7 +554,7 @@ const NumberUtils = {
|
|
|
545
554
|
destination[offset + 2] = lo;
|
|
546
555
|
lo >>= 8;
|
|
547
556
|
destination[offset + 3] = lo;
|
|
548
|
-
let hi = Number((value >>
|
|
557
|
+
let hi = Number((value >> 32n) & mask32bits);
|
|
549
558
|
destination[offset + 4] = hi;
|
|
550
559
|
hi >>= 8;
|
|
551
560
|
destination[offset + 5] = hi;
|
|
@@ -586,6 +595,27 @@ class Binary extends BSONValue {
|
|
|
586
595
|
get _bsontype() {
|
|
587
596
|
return 'Binary';
|
|
588
597
|
}
|
|
598
|
+
static BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
599
|
+
static BUFFER_SIZE = 256;
|
|
600
|
+
static SUBTYPE_DEFAULT = 0;
|
|
601
|
+
static SUBTYPE_FUNCTION = 1;
|
|
602
|
+
static SUBTYPE_BYTE_ARRAY = 2;
|
|
603
|
+
static SUBTYPE_UUID_OLD = 3;
|
|
604
|
+
static SUBTYPE_UUID = 4;
|
|
605
|
+
static SUBTYPE_MD5 = 5;
|
|
606
|
+
static SUBTYPE_ENCRYPTED = 6;
|
|
607
|
+
static SUBTYPE_COLUMN = 7;
|
|
608
|
+
static SUBTYPE_SENSITIVE = 8;
|
|
609
|
+
static SUBTYPE_VECTOR = 9;
|
|
610
|
+
static SUBTYPE_USER_DEFINED = 128;
|
|
611
|
+
static VECTOR_TYPE = Object.freeze({
|
|
612
|
+
Int8: 0x03,
|
|
613
|
+
Float32: 0x27,
|
|
614
|
+
PackedBit: 0x10
|
|
615
|
+
});
|
|
616
|
+
buffer;
|
|
617
|
+
sub_type;
|
|
618
|
+
position;
|
|
589
619
|
constructor(buffer, subType) {
|
|
590
620
|
super();
|
|
591
621
|
if (!(buffer == null) &&
|
|
@@ -748,6 +778,7 @@ class Binary extends BSONValue {
|
|
|
748
778
|
if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
|
|
749
779
|
throw new BSONError('Binary datatype field is not Int8');
|
|
750
780
|
}
|
|
781
|
+
validateBinaryVector(this);
|
|
751
782
|
return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
752
783
|
}
|
|
753
784
|
toFloat32Array() {
|
|
@@ -757,6 +788,7 @@ class Binary extends BSONValue {
|
|
|
757
788
|
if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
|
|
758
789
|
throw new BSONError('Binary datatype field is not Float32');
|
|
759
790
|
}
|
|
791
|
+
validateBinaryVector(this);
|
|
760
792
|
const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
761
793
|
if (NumberUtils.isBigEndian)
|
|
762
794
|
ByteUtils.swap32(floatBytes);
|
|
@@ -769,6 +801,7 @@ class Binary extends BSONValue {
|
|
|
769
801
|
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
770
802
|
throw new BSONError('Binary datatype field is not packed bit');
|
|
771
803
|
}
|
|
804
|
+
validateBinaryVector(this);
|
|
772
805
|
return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
773
806
|
}
|
|
774
807
|
toBits() {
|
|
@@ -778,6 +811,7 @@ class Binary extends BSONValue {
|
|
|
778
811
|
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
779
812
|
throw new BSONError('Binary datatype field is not packed bit');
|
|
780
813
|
}
|
|
814
|
+
validateBinaryVector(this);
|
|
781
815
|
const byteCount = this.length() - 2;
|
|
782
816
|
const bitCount = byteCount * 8 - this.buffer[1];
|
|
783
817
|
const bits = new Int8Array(bitCount);
|
|
@@ -796,7 +830,9 @@ class Binary extends BSONValue {
|
|
|
796
830
|
buffer[1] = 0;
|
|
797
831
|
const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
798
832
|
buffer.set(intBytes, 2);
|
|
799
|
-
|
|
833
|
+
const bin = new this(buffer, this.SUBTYPE_VECTOR);
|
|
834
|
+
validateBinaryVector(bin);
|
|
835
|
+
return bin;
|
|
800
836
|
}
|
|
801
837
|
static fromFloat32Array(array) {
|
|
802
838
|
const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
|
|
@@ -806,14 +842,18 @@ class Binary extends BSONValue {
|
|
|
806
842
|
binaryBytes.set(floatBytes, 2);
|
|
807
843
|
if (NumberUtils.isBigEndian)
|
|
808
844
|
ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
|
|
809
|
-
|
|
845
|
+
const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
|
|
846
|
+
validateBinaryVector(bin);
|
|
847
|
+
return bin;
|
|
810
848
|
}
|
|
811
849
|
static fromPackedBits(array, padding = 0) {
|
|
812
850
|
const buffer = ByteUtils.allocate(array.byteLength + 2);
|
|
813
851
|
buffer[0] = Binary.VECTOR_TYPE.PackedBit;
|
|
814
852
|
buffer[1] = padding;
|
|
815
853
|
buffer.set(array, 2);
|
|
816
|
-
|
|
854
|
+
const bin = new this(buffer, this.SUBTYPE_VECTOR);
|
|
855
|
+
validateBinaryVector(bin);
|
|
856
|
+
return bin;
|
|
817
857
|
}
|
|
818
858
|
static fromBits(bits) {
|
|
819
859
|
const byteLength = (bits.length + 7) >>> 3;
|
|
@@ -835,24 +875,6 @@ class Binary extends BSONValue {
|
|
|
835
875
|
return new this(bytes, Binary.SUBTYPE_VECTOR);
|
|
836
876
|
}
|
|
837
877
|
}
|
|
838
|
-
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
839
|
-
Binary.BUFFER_SIZE = 256;
|
|
840
|
-
Binary.SUBTYPE_DEFAULT = 0;
|
|
841
|
-
Binary.SUBTYPE_FUNCTION = 1;
|
|
842
|
-
Binary.SUBTYPE_BYTE_ARRAY = 2;
|
|
843
|
-
Binary.SUBTYPE_UUID_OLD = 3;
|
|
844
|
-
Binary.SUBTYPE_UUID = 4;
|
|
845
|
-
Binary.SUBTYPE_MD5 = 5;
|
|
846
|
-
Binary.SUBTYPE_ENCRYPTED = 6;
|
|
847
|
-
Binary.SUBTYPE_COLUMN = 7;
|
|
848
|
-
Binary.SUBTYPE_SENSITIVE = 8;
|
|
849
|
-
Binary.SUBTYPE_VECTOR = 9;
|
|
850
|
-
Binary.SUBTYPE_USER_DEFINED = 128;
|
|
851
|
-
Binary.VECTOR_TYPE = Object.freeze({
|
|
852
|
-
Int8: 0x03,
|
|
853
|
-
Float32: 0x27,
|
|
854
|
-
PackedBit: 0x10
|
|
855
|
-
});
|
|
856
878
|
function validateBinaryVector(vector) {
|
|
857
879
|
if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
|
|
858
880
|
return;
|
|
@@ -863,6 +885,11 @@ function validateBinaryVector(vector) {
|
|
|
863
885
|
padding !== 0) {
|
|
864
886
|
throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
|
|
865
887
|
}
|
|
888
|
+
if (datatype === Binary.VECTOR_TYPE.Float32) {
|
|
889
|
+
if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
|
|
890
|
+
throw new BSONError('Invalid Vector: Float32 vector must contain a multiple of 4 bytes');
|
|
891
|
+
}
|
|
892
|
+
}
|
|
866
893
|
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
|
|
867
894
|
throw new BSONError('Invalid Vector: padding must be zero for packed bit vectors that are empty');
|
|
868
895
|
}
|
|
@@ -984,6 +1011,8 @@ class Code extends BSONValue {
|
|
|
984
1011
|
get _bsontype() {
|
|
985
1012
|
return 'Code';
|
|
986
1013
|
}
|
|
1014
|
+
code;
|
|
1015
|
+
scope;
|
|
987
1016
|
constructor(code, scope) {
|
|
988
1017
|
super();
|
|
989
1018
|
this.code = code.toString();
|
|
@@ -1029,6 +1058,10 @@ class DBRef extends BSONValue {
|
|
|
1029
1058
|
get _bsontype() {
|
|
1030
1059
|
return 'DBRef';
|
|
1031
1060
|
}
|
|
1061
|
+
collection;
|
|
1062
|
+
oid;
|
|
1063
|
+
db;
|
|
1064
|
+
fields;
|
|
1032
1065
|
constructor(collection, oid, db, fields) {
|
|
1033
1066
|
super();
|
|
1034
1067
|
const parts = collection.split('.');
|
|
@@ -1138,6 +1171,9 @@ class Long extends BSONValue {
|
|
|
1138
1171
|
get __isLong__() {
|
|
1139
1172
|
return true;
|
|
1140
1173
|
}
|
|
1174
|
+
high;
|
|
1175
|
+
low;
|
|
1176
|
+
unsigned;
|
|
1141
1177
|
constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
|
|
1142
1178
|
super();
|
|
1143
1179
|
const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
|
|
@@ -1151,6 +1187,15 @@ class Long extends BSONValue {
|
|
|
1151
1187
|
this.high = res.high;
|
|
1152
1188
|
this.unsigned = res.unsigned;
|
|
1153
1189
|
}
|
|
1190
|
+
static TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
1191
|
+
static MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
1192
|
+
static ZERO = Long.fromInt(0);
|
|
1193
|
+
static UZERO = Long.fromInt(0, true);
|
|
1194
|
+
static ONE = Long.fromInt(1);
|
|
1195
|
+
static UONE = Long.fromInt(1, true);
|
|
1196
|
+
static NEG_ONE = Long.fromInt(-1);
|
|
1197
|
+
static MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
1198
|
+
static MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
1154
1199
|
static fromBits(lowBits, highBits, unsigned) {
|
|
1155
1200
|
return new Long(lowBits, highBits, unsigned);
|
|
1156
1201
|
}
|
|
@@ -1191,7 +1236,7 @@ class Long extends BSONValue {
|
|
|
1191
1236
|
return Long.MAX_UNSIGNED_VALUE;
|
|
1192
1237
|
}
|
|
1193
1238
|
else {
|
|
1194
|
-
if (value <= -
|
|
1239
|
+
if (value <= -TWO_PWR_63_DBL)
|
|
1195
1240
|
return Long.MIN_VALUE;
|
|
1196
1241
|
if (value + 1 >= TWO_PWR_63_DBL)
|
|
1197
1242
|
return Long.MAX_VALUE;
|
|
@@ -1201,8 +1246,8 @@ class Long extends BSONValue {
|
|
|
1201
1246
|
return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
|
1202
1247
|
}
|
|
1203
1248
|
static fromBigInt(value, unsigned) {
|
|
1204
|
-
const FROM_BIGINT_BIT_MASK =
|
|
1205
|
-
const FROM_BIGINT_BIT_SHIFT =
|
|
1249
|
+
const FROM_BIGINT_BIT_MASK = 0xffffffffn;
|
|
1250
|
+
const FROM_BIGINT_BIT_SHIFT = 32n;
|
|
1206
1251
|
return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
|
|
1207
1252
|
}
|
|
1208
1253
|
static _fromString(str, unsigned, radix) {
|
|
@@ -1235,7 +1280,7 @@ class Long extends BSONValue {
|
|
|
1235
1280
|
static fromStringStrict(str, unsignedOrRadix, radix) {
|
|
1236
1281
|
let unsigned = false;
|
|
1237
1282
|
if (typeof unsignedOrRadix === 'number') {
|
|
1238
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
1283
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
1239
1284
|
}
|
|
1240
1285
|
else {
|
|
1241
1286
|
unsigned = !!unsignedOrRadix;
|
|
@@ -1257,7 +1302,7 @@ class Long extends BSONValue {
|
|
|
1257
1302
|
static fromString(str, unsignedOrRadix, radix) {
|
|
1258
1303
|
let unsigned = false;
|
|
1259
1304
|
if (typeof unsignedOrRadix === 'number') {
|
|
1260
|
-
(radix = unsignedOrRadix), (unsignedOrRadix = false);
|
|
1305
|
+
((radix = unsignedOrRadix), (unsignedOrRadix = false));
|
|
1261
1306
|
}
|
|
1262
1307
|
else {
|
|
1263
1308
|
unsigned = !!unsignedOrRadix;
|
|
@@ -1777,15 +1822,6 @@ class Long extends BSONValue {
|
|
|
1777
1822
|
return `new Long(${longVal}${unsignedVal})`;
|
|
1778
1823
|
}
|
|
1779
1824
|
}
|
|
1780
|
-
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
1781
|
-
Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
|
|
1782
|
-
Long.ZERO = Long.fromInt(0);
|
|
1783
|
-
Long.UZERO = Long.fromInt(0, true);
|
|
1784
|
-
Long.ONE = Long.fromInt(1);
|
|
1785
|
-
Long.UONE = Long.fromInt(1, true);
|
|
1786
|
-
Long.NEG_ONE = Long.fromInt(-1);
|
|
1787
|
-
Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
|
|
1788
|
-
Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
|
|
1789
1825
|
|
|
1790
1826
|
const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
|
|
1791
1827
|
const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
|
|
@@ -1866,6 +1902,7 @@ class Decimal128 extends BSONValue {
|
|
|
1866
1902
|
get _bsontype() {
|
|
1867
1903
|
return 'Decimal128';
|
|
1868
1904
|
}
|
|
1905
|
+
bytes;
|
|
1869
1906
|
constructor(bytes) {
|
|
1870
1907
|
super();
|
|
1871
1908
|
if (typeof bytes === 'string') {
|
|
@@ -2341,6 +2378,7 @@ class Double extends BSONValue {
|
|
|
2341
2378
|
get _bsontype() {
|
|
2342
2379
|
return 'Double';
|
|
2343
2380
|
}
|
|
2381
|
+
value;
|
|
2344
2382
|
constructor(value) {
|
|
2345
2383
|
super();
|
|
2346
2384
|
if (value instanceof Number) {
|
|
@@ -2404,6 +2442,7 @@ class Int32 extends BSONValue {
|
|
|
2404
2442
|
get _bsontype() {
|
|
2405
2443
|
return 'Int32';
|
|
2406
2444
|
}
|
|
2445
|
+
value;
|
|
2407
2446
|
constructor(value) {
|
|
2408
2447
|
super();
|
|
2409
2448
|
if (value instanceof Number) {
|
|
@@ -2482,11 +2521,14 @@ class MinKey extends BSONValue {
|
|
|
2482
2521
|
}
|
|
2483
2522
|
|
|
2484
2523
|
let PROCESS_UNIQUE = null;
|
|
2485
|
-
const __idCache = new WeakMap();
|
|
2486
2524
|
class ObjectId extends BSONValue {
|
|
2487
2525
|
get _bsontype() {
|
|
2488
2526
|
return 'ObjectId';
|
|
2489
2527
|
}
|
|
2528
|
+
static index = Math.floor(Math.random() * 0xffffff);
|
|
2529
|
+
static cacheHexString = false;
|
|
2530
|
+
buffer;
|
|
2531
|
+
#cachedHexString = null;
|
|
2490
2532
|
constructor(inputId) {
|
|
2491
2533
|
super();
|
|
2492
2534
|
let workingId;
|
|
@@ -2504,8 +2546,8 @@ class ObjectId extends BSONValue {
|
|
|
2504
2546
|
else {
|
|
2505
2547
|
workingId = inputId;
|
|
2506
2548
|
}
|
|
2507
|
-
if (workingId == null
|
|
2508
|
-
this.buffer = ObjectId.generate(
|
|
2549
|
+
if (workingId == null) {
|
|
2550
|
+
this.buffer = ObjectId.generate();
|
|
2509
2551
|
}
|
|
2510
2552
|
else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
|
2511
2553
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
@@ -2514,7 +2556,7 @@ class ObjectId extends BSONValue {
|
|
|
2514
2556
|
if (ObjectId.validateHexString(workingId)) {
|
|
2515
2557
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
2516
2558
|
if (ObjectId.cacheHexString) {
|
|
2517
|
-
|
|
2559
|
+
this.#cachedHexString = workingId;
|
|
2518
2560
|
}
|
|
2519
2561
|
}
|
|
2520
2562
|
else {
|
|
@@ -2531,7 +2573,7 @@ class ObjectId extends BSONValue {
|
|
|
2531
2573
|
set id(value) {
|
|
2532
2574
|
this.buffer = value;
|
|
2533
2575
|
if (ObjectId.cacheHexString) {
|
|
2534
|
-
|
|
2576
|
+
this.#cachedHexString = ByteUtils.toHex(value);
|
|
2535
2577
|
}
|
|
2536
2578
|
}
|
|
2537
2579
|
static validateHexString(string) {
|
|
@@ -2549,14 +2591,11 @@ class ObjectId extends BSONValue {
|
|
|
2549
2591
|
return true;
|
|
2550
2592
|
}
|
|
2551
2593
|
toHexString() {
|
|
2552
|
-
if (
|
|
2553
|
-
|
|
2554
|
-
if (__id)
|
|
2555
|
-
return __id;
|
|
2556
|
-
}
|
|
2594
|
+
if (this.#cachedHexString)
|
|
2595
|
+
return this.#cachedHexString.toLowerCase();
|
|
2557
2596
|
const hexString = ByteUtils.toHex(this.id);
|
|
2558
2597
|
if (ObjectId.cacheHexString) {
|
|
2559
|
-
|
|
2598
|
+
this.#cachedHexString = hexString;
|
|
2560
2599
|
}
|
|
2561
2600
|
return hexString;
|
|
2562
2601
|
}
|
|
@@ -2681,14 +2720,13 @@ class ObjectId extends BSONValue {
|
|
|
2681
2720
|
return new ObjectId(doc.$oid);
|
|
2682
2721
|
}
|
|
2683
2722
|
isCached() {
|
|
2684
|
-
return ObjectId.cacheHexString &&
|
|
2723
|
+
return ObjectId.cacheHexString && this.#cachedHexString != null;
|
|
2685
2724
|
}
|
|
2686
2725
|
inspect(depth, options, inspect) {
|
|
2687
2726
|
inspect ??= defaultInspect;
|
|
2688
2727
|
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
|
2689
2728
|
}
|
|
2690
2729
|
}
|
|
2691
|
-
ObjectId.index = Math.floor(Math.random() * 0xffffff);
|
|
2692
2730
|
|
|
2693
2731
|
function internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined) {
|
|
2694
2732
|
let totalLength = 4 + 1;
|
|
@@ -2857,6 +2895,8 @@ class BSONRegExp extends BSONValue {
|
|
|
2857
2895
|
get _bsontype() {
|
|
2858
2896
|
return 'BSONRegExp';
|
|
2859
2897
|
}
|
|
2898
|
+
pattern;
|
|
2899
|
+
options;
|
|
2860
2900
|
constructor(pattern, options) {
|
|
2861
2901
|
super();
|
|
2862
2902
|
this.pattern = pattern;
|
|
@@ -2917,6 +2957,7 @@ class BSONSymbol extends BSONValue {
|
|
|
2917
2957
|
get _bsontype() {
|
|
2918
2958
|
return 'BSONSymbol';
|
|
2919
2959
|
}
|
|
2960
|
+
value;
|
|
2920
2961
|
constructor(value) {
|
|
2921
2962
|
super();
|
|
2922
2963
|
this.value = value;
|
|
@@ -2947,6 +2988,10 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2947
2988
|
get _bsontype() {
|
|
2948
2989
|
return 'Timestamp';
|
|
2949
2990
|
}
|
|
2991
|
+
get [bsonType]() {
|
|
2992
|
+
return 'Timestamp';
|
|
2993
|
+
}
|
|
2994
|
+
static MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
2950
2995
|
get i() {
|
|
2951
2996
|
return this.low >>> 0;
|
|
2952
2997
|
}
|
|
@@ -3026,7 +3071,6 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
3026
3071
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
3027
3072
|
}
|
|
3028
3073
|
}
|
|
3029
|
-
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
3030
3074
|
|
|
3031
3075
|
const JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
|
|
3032
3076
|
const JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
|
|
@@ -4374,6 +4418,29 @@ EJSON.serialize = EJSONserialize;
|
|
|
4374
4418
|
EJSON.deserialize = EJSONdeserialize;
|
|
4375
4419
|
Object.freeze(EJSON);
|
|
4376
4420
|
|
|
4421
|
+
const BSONElementType = {
|
|
4422
|
+
double: 1,
|
|
4423
|
+
string: 2,
|
|
4424
|
+
object: 3,
|
|
4425
|
+
array: 4,
|
|
4426
|
+
binData: 5,
|
|
4427
|
+
undefined: 6,
|
|
4428
|
+
objectId: 7,
|
|
4429
|
+
bool: 8,
|
|
4430
|
+
date: 9,
|
|
4431
|
+
null: 10,
|
|
4432
|
+
regex: 11,
|
|
4433
|
+
dbPointer: 12,
|
|
4434
|
+
javascript: 13,
|
|
4435
|
+
symbol: 14,
|
|
4436
|
+
javascriptWithScope: 15,
|
|
4437
|
+
int: 16,
|
|
4438
|
+
timestamp: 17,
|
|
4439
|
+
long: 18,
|
|
4440
|
+
decimal: 19,
|
|
4441
|
+
minKey: 255,
|
|
4442
|
+
maxKey: 127
|
|
4443
|
+
};
|
|
4377
4444
|
function getSize(source, offset) {
|
|
4378
4445
|
try {
|
|
4379
4446
|
return NumberUtils.getNonnegativeInt32LE(source, offset);
|
|
@@ -4418,48 +4485,48 @@ function parseToElements(bytes, startOffset = 0) {
|
|
|
4418
4485
|
const nameLength = findNull(bytes, offset) - nameOffset;
|
|
4419
4486
|
offset += nameLength + 1;
|
|
4420
4487
|
let length;
|
|
4421
|
-
if (type ===
|
|
4422
|
-
type ===
|
|
4423
|
-
type ===
|
|
4424
|
-
type ===
|
|
4488
|
+
if (type === BSONElementType.double ||
|
|
4489
|
+
type === BSONElementType.long ||
|
|
4490
|
+
type === BSONElementType.date ||
|
|
4491
|
+
type === BSONElementType.timestamp) {
|
|
4425
4492
|
length = 8;
|
|
4426
4493
|
}
|
|
4427
|
-
else if (type ===
|
|
4494
|
+
else if (type === BSONElementType.int) {
|
|
4428
4495
|
length = 4;
|
|
4429
4496
|
}
|
|
4430
|
-
else if (type ===
|
|
4497
|
+
else if (type === BSONElementType.objectId) {
|
|
4431
4498
|
length = 12;
|
|
4432
4499
|
}
|
|
4433
|
-
else if (type ===
|
|
4500
|
+
else if (type === BSONElementType.decimal) {
|
|
4434
4501
|
length = 16;
|
|
4435
4502
|
}
|
|
4436
|
-
else if (type ===
|
|
4503
|
+
else if (type === BSONElementType.bool) {
|
|
4437
4504
|
length = 1;
|
|
4438
4505
|
}
|
|
4439
|
-
else if (type ===
|
|
4440
|
-
type ===
|
|
4441
|
-
type ===
|
|
4442
|
-
type ===
|
|
4506
|
+
else if (type === BSONElementType.null ||
|
|
4507
|
+
type === BSONElementType.undefined ||
|
|
4508
|
+
type === BSONElementType.maxKey ||
|
|
4509
|
+
type === BSONElementType.minKey) {
|
|
4443
4510
|
length = 0;
|
|
4444
4511
|
}
|
|
4445
|
-
else if (type ===
|
|
4512
|
+
else if (type === BSONElementType.regex) {
|
|
4446
4513
|
length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
|
|
4447
4514
|
}
|
|
4448
|
-
else if (type ===
|
|
4449
|
-
type ===
|
|
4450
|
-
type ===
|
|
4515
|
+
else if (type === BSONElementType.object ||
|
|
4516
|
+
type === BSONElementType.array ||
|
|
4517
|
+
type === BSONElementType.javascriptWithScope) {
|
|
4451
4518
|
length = getSize(bytes, offset);
|
|
4452
4519
|
}
|
|
4453
|
-
else if (type ===
|
|
4454
|
-
type ===
|
|
4455
|
-
type ===
|
|
4456
|
-
type ===
|
|
4457
|
-
type ===
|
|
4520
|
+
else if (type === BSONElementType.string ||
|
|
4521
|
+
type === BSONElementType.binData ||
|
|
4522
|
+
type === BSONElementType.dbPointer ||
|
|
4523
|
+
type === BSONElementType.javascript ||
|
|
4524
|
+
type === BSONElementType.symbol) {
|
|
4458
4525
|
length = getSize(bytes, offset) + 4;
|
|
4459
|
-
if (type ===
|
|
4526
|
+
if (type === BSONElementType.binData) {
|
|
4460
4527
|
length += 1;
|
|
4461
4528
|
}
|
|
4462
|
-
if (type ===
|
|
4529
|
+
if (type === BSONElementType.dbPointer) {
|
|
4463
4530
|
length += 12;
|
|
4464
4531
|
}
|
|
4465
4532
|
}
|
|
@@ -4555,6 +4622,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4555
4622
|
ObjectId: ObjectId,
|
|
4556
4623
|
Timestamp: Timestamp,
|
|
4557
4624
|
UUID: UUID,
|
|
4625
|
+
bsonType: bsonType,
|
|
4558
4626
|
calculateObjectSize: calculateObjectSize,
|
|
4559
4627
|
deserialize: deserialize,
|
|
4560
4628
|
deserializeStream: deserializeStream,
|
|
@@ -4564,5 +4632,5 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4564
4632
|
setInternalBufferSize: setInternalBufferSize
|
|
4565
4633
|
});
|
|
4566
4634
|
|
|
4567
|
-
export { bson as BSON, BSONError, BSONOffsetError, BSONRegExp, BSONRuntimeError, BSONSymbol, BSONType, BSONValue, BSONVersionError, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, MaxKey, MinKey, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, onDemand, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
4635
|
+
export { bson as BSON, BSONError, BSONOffsetError, BSONRegExp, BSONRuntimeError, BSONSymbol, BSONType, BSONValue, BSONVersionError, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, MaxKey, MinKey, ObjectId, Timestamp, UUID, bsonType, calculateObjectSize, deserialize, deserializeStream, onDemand, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
4568
4636
|
//# sourceMappingURL=bson.mjs.map
|