bson 7.0.0 → 7.1.1
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/bson.d.ts +24 -5
- package/lib/bson.bundle.js +53 -4
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +53 -4
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +52 -5
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +52 -5
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +53 -4
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +2 -2
- package/src/bson.ts +3 -1
- package/src/utils/byte_utils.ts +11 -2
- package/src/utils/node_byte_utils.ts +21 -1
- package/src/utils/web_byte_utils.ts +50 -5
package/lib/bson.rn.cjs
CHANGED
|
@@ -240,6 +240,7 @@ const nodejsRandomBytes = (() => {
|
|
|
240
240
|
}
|
|
241
241
|
})();
|
|
242
242
|
const nodeJsByteUtils = {
|
|
243
|
+
isUint8Array: isUint8Array,
|
|
243
244
|
toLocalBufferType(potentialBuffer) {
|
|
244
245
|
if (Buffer.isBuffer(potentialBuffer)) {
|
|
245
246
|
return potentialBuffer;
|
|
@@ -262,6 +263,12 @@ const nodeJsByteUtils = {
|
|
|
262
263
|
allocateUnsafe(size) {
|
|
263
264
|
return Buffer.allocUnsafe(size);
|
|
264
265
|
},
|
|
266
|
+
compare(a, b) {
|
|
267
|
+
return nodeJsByteUtils.toLocalBufferType(a).compare(b);
|
|
268
|
+
},
|
|
269
|
+
concat(list) {
|
|
270
|
+
return Buffer.concat(list);
|
|
271
|
+
},
|
|
265
272
|
equals(a, b) {
|
|
266
273
|
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
267
274
|
},
|
|
@@ -271,6 +278,9 @@ const nodeJsByteUtils = {
|
|
|
271
278
|
fromBase64(base64) {
|
|
272
279
|
return Buffer.from(base64, 'base64');
|
|
273
280
|
},
|
|
281
|
+
fromUTF8(utf8) {
|
|
282
|
+
return Buffer.from(utf8, 'utf8');
|
|
283
|
+
},
|
|
274
284
|
toBase64(buffer) {
|
|
275
285
|
return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
|
|
276
286
|
},
|
|
@@ -345,6 +355,7 @@ const webRandomBytes = (() => {
|
|
|
345
355
|
})();
|
|
346
356
|
const HEX_DIGIT = /(\d|[a-f])/i;
|
|
347
357
|
const webByteUtils = {
|
|
358
|
+
isUint8Array: isUint8Array,
|
|
348
359
|
toLocalBufferType(potentialUint8array) {
|
|
349
360
|
const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
|
|
350
361
|
Object.prototype.toString.call(potentialUint8array);
|
|
@@ -371,12 +382,43 @@ const webByteUtils = {
|
|
|
371
382
|
allocateUnsafe(size) {
|
|
372
383
|
return webByteUtils.allocate(size);
|
|
373
384
|
},
|
|
374
|
-
|
|
375
|
-
if (
|
|
385
|
+
compare(uint8Array, otherUint8Array) {
|
|
386
|
+
if (uint8Array === otherUint8Array)
|
|
387
|
+
return 0;
|
|
388
|
+
const len = Math.min(uint8Array.length, otherUint8Array.length);
|
|
389
|
+
for (let i = 0; i < len; i++) {
|
|
390
|
+
if (uint8Array[i] < otherUint8Array[i])
|
|
391
|
+
return -1;
|
|
392
|
+
if (uint8Array[i] > otherUint8Array[i])
|
|
393
|
+
return 1;
|
|
394
|
+
}
|
|
395
|
+
if (uint8Array.length < otherUint8Array.length)
|
|
396
|
+
return -1;
|
|
397
|
+
if (uint8Array.length > otherUint8Array.length)
|
|
398
|
+
return 1;
|
|
399
|
+
return 0;
|
|
400
|
+
},
|
|
401
|
+
concat(uint8Arrays) {
|
|
402
|
+
if (uint8Arrays.length === 0)
|
|
403
|
+
return webByteUtils.allocate(0);
|
|
404
|
+
let totalLength = 0;
|
|
405
|
+
for (const uint8Array of uint8Arrays) {
|
|
406
|
+
totalLength += uint8Array.length;
|
|
407
|
+
}
|
|
408
|
+
const result = webByteUtils.allocate(totalLength);
|
|
409
|
+
let offset = 0;
|
|
410
|
+
for (const uint8Array of uint8Arrays) {
|
|
411
|
+
result.set(uint8Array, offset);
|
|
412
|
+
offset += uint8Array.length;
|
|
413
|
+
}
|
|
414
|
+
return result;
|
|
415
|
+
},
|
|
416
|
+
equals(uint8Array, otherUint8Array) {
|
|
417
|
+
if (uint8Array.byteLength !== otherUint8Array.byteLength) {
|
|
376
418
|
return false;
|
|
377
419
|
}
|
|
378
|
-
for (let i = 0; i <
|
|
379
|
-
if (
|
|
420
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
421
|
+
if (uint8Array[i] !== otherUint8Array[i]) {
|
|
380
422
|
return false;
|
|
381
423
|
}
|
|
382
424
|
}
|
|
@@ -388,6 +430,9 @@ const webByteUtils = {
|
|
|
388
430
|
fromBase64(base64) {
|
|
389
431
|
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
|
390
432
|
},
|
|
433
|
+
fromUTF8(utf8) {
|
|
434
|
+
return new TextEncoder().encode(utf8);
|
|
435
|
+
},
|
|
391
436
|
toBase64(uint8array) {
|
|
392
437
|
return btoa(webByteUtils.toISO88591(uint8array));
|
|
393
438
|
},
|
|
@@ -4625,6 +4670,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4625
4670
|
BSONValue: BSONValue,
|
|
4626
4671
|
BSONVersionError: BSONVersionError,
|
|
4627
4672
|
Binary: Binary,
|
|
4673
|
+
ByteUtils: ByteUtils,
|
|
4628
4674
|
Code: Code,
|
|
4629
4675
|
DBRef: DBRef,
|
|
4630
4676
|
Decimal128: Decimal128,
|
|
@@ -4634,6 +4680,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4634
4680
|
Long: Long,
|
|
4635
4681
|
MaxKey: MaxKey,
|
|
4636
4682
|
MinKey: MinKey,
|
|
4683
|
+
NumberUtils: NumberUtils,
|
|
4637
4684
|
ObjectId: ObjectId,
|
|
4638
4685
|
Timestamp: Timestamp,
|
|
4639
4686
|
UUID: UUID,
|
|
@@ -4657,6 +4704,7 @@ exports.BSONType = BSONType;
|
|
|
4657
4704
|
exports.BSONValue = BSONValue;
|
|
4658
4705
|
exports.BSONVersionError = BSONVersionError;
|
|
4659
4706
|
exports.Binary = Binary;
|
|
4707
|
+
exports.ByteUtils = ByteUtils;
|
|
4660
4708
|
exports.Code = Code;
|
|
4661
4709
|
exports.DBRef = DBRef;
|
|
4662
4710
|
exports.Decimal128 = Decimal128;
|
|
@@ -4666,6 +4714,7 @@ exports.Int32 = Int32;
|
|
|
4666
4714
|
exports.Long = Long;
|
|
4667
4715
|
exports.MaxKey = MaxKey;
|
|
4668
4716
|
exports.MinKey = MinKey;
|
|
4717
|
+
exports.NumberUtils = NumberUtils;
|
|
4669
4718
|
exports.ObjectId = ObjectId;
|
|
4670
4719
|
exports.Timestamp = Timestamp;
|
|
4671
4720
|
exports.UUID = UUID;
|