bson 7.0.0-alpha.2 → 7.1.0
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 +7 -6
- package/bson.d.ts +24 -7
- package/lib/bson.bundle.js +53 -6
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +53 -6
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +52 -7
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +52 -7
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +53 -6
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +3 -3
- package/src/bson.ts +3 -1
- package/src/parser/on_demand/index.ts +0 -8
- 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
|
},
|
|
@@ -4559,8 +4604,6 @@ function parseToElements(bytes, startOffset = 0) {
|
|
|
4559
4604
|
|
|
4560
4605
|
const onDemand = Object.create(null);
|
|
4561
4606
|
onDemand.parseToElements = parseToElements;
|
|
4562
|
-
onDemand.ByteUtils = ByteUtils;
|
|
4563
|
-
onDemand.NumberUtils = NumberUtils;
|
|
4564
4607
|
Object.freeze(onDemand);
|
|
4565
4608
|
|
|
4566
4609
|
const MAXSIZE = 1024 * 1024 * 17;
|
|
@@ -4625,6 +4668,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4625
4668
|
BSONValue: BSONValue,
|
|
4626
4669
|
BSONVersionError: BSONVersionError,
|
|
4627
4670
|
Binary: Binary,
|
|
4671
|
+
ByteUtils: ByteUtils,
|
|
4628
4672
|
Code: Code,
|
|
4629
4673
|
DBRef: DBRef,
|
|
4630
4674
|
Decimal128: Decimal128,
|
|
@@ -4634,6 +4678,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4634
4678
|
Long: Long,
|
|
4635
4679
|
MaxKey: MaxKey,
|
|
4636
4680
|
MinKey: MinKey,
|
|
4681
|
+
NumberUtils: NumberUtils,
|
|
4637
4682
|
ObjectId: ObjectId,
|
|
4638
4683
|
Timestamp: Timestamp,
|
|
4639
4684
|
UUID: UUID,
|
|
@@ -4657,6 +4702,7 @@ exports.BSONType = BSONType;
|
|
|
4657
4702
|
exports.BSONValue = BSONValue;
|
|
4658
4703
|
exports.BSONVersionError = BSONVersionError;
|
|
4659
4704
|
exports.Binary = Binary;
|
|
4705
|
+
exports.ByteUtils = ByteUtils;
|
|
4660
4706
|
exports.Code = Code;
|
|
4661
4707
|
exports.DBRef = DBRef;
|
|
4662
4708
|
exports.Decimal128 = Decimal128;
|
|
@@ -4666,6 +4712,7 @@ exports.Int32 = Int32;
|
|
|
4666
4712
|
exports.Long = Long;
|
|
4667
4713
|
exports.MaxKey = MaxKey;
|
|
4668
4714
|
exports.MinKey = MinKey;
|
|
4715
|
+
exports.NumberUtils = NumberUtils;
|
|
4669
4716
|
exports.ObjectId = ObjectId;
|
|
4670
4717
|
exports.Timestamp = Timestamp;
|
|
4671
4718
|
exports.UUID = UUID;
|