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.cjs
CHANGED
|
@@ -232,6 +232,7 @@ const nodejsRandomBytes = (() => {
|
|
|
232
232
|
}
|
|
233
233
|
})();
|
|
234
234
|
const nodeJsByteUtils = {
|
|
235
|
+
isUint8Array: isUint8Array,
|
|
235
236
|
toLocalBufferType(potentialBuffer) {
|
|
236
237
|
if (Buffer.isBuffer(potentialBuffer)) {
|
|
237
238
|
return potentialBuffer;
|
|
@@ -254,6 +255,12 @@ const nodeJsByteUtils = {
|
|
|
254
255
|
allocateUnsafe(size) {
|
|
255
256
|
return Buffer.allocUnsafe(size);
|
|
256
257
|
},
|
|
258
|
+
compare(a, b) {
|
|
259
|
+
return nodeJsByteUtils.toLocalBufferType(a).compare(b);
|
|
260
|
+
},
|
|
261
|
+
concat(list) {
|
|
262
|
+
return Buffer.concat(list);
|
|
263
|
+
},
|
|
257
264
|
equals(a, b) {
|
|
258
265
|
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
259
266
|
},
|
|
@@ -263,6 +270,9 @@ const nodeJsByteUtils = {
|
|
|
263
270
|
fromBase64(base64) {
|
|
264
271
|
return Buffer.from(base64, 'base64');
|
|
265
272
|
},
|
|
273
|
+
fromUTF8(utf8) {
|
|
274
|
+
return Buffer.from(utf8, 'utf8');
|
|
275
|
+
},
|
|
266
276
|
toBase64(buffer) {
|
|
267
277
|
return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
|
|
268
278
|
},
|
|
@@ -337,6 +347,7 @@ const webRandomBytes = (() => {
|
|
|
337
347
|
})();
|
|
338
348
|
const HEX_DIGIT = /(\d|[a-f])/i;
|
|
339
349
|
const webByteUtils = {
|
|
350
|
+
isUint8Array: isUint8Array,
|
|
340
351
|
toLocalBufferType(potentialUint8array) {
|
|
341
352
|
const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
|
|
342
353
|
Object.prototype.toString.call(potentialUint8array);
|
|
@@ -363,12 +374,43 @@ const webByteUtils = {
|
|
|
363
374
|
allocateUnsafe(size) {
|
|
364
375
|
return webByteUtils.allocate(size);
|
|
365
376
|
},
|
|
366
|
-
|
|
367
|
-
if (
|
|
377
|
+
compare(uint8Array, otherUint8Array) {
|
|
378
|
+
if (uint8Array === otherUint8Array)
|
|
379
|
+
return 0;
|
|
380
|
+
const len = Math.min(uint8Array.length, otherUint8Array.length);
|
|
381
|
+
for (let i = 0; i < len; i++) {
|
|
382
|
+
if (uint8Array[i] < otherUint8Array[i])
|
|
383
|
+
return -1;
|
|
384
|
+
if (uint8Array[i] > otherUint8Array[i])
|
|
385
|
+
return 1;
|
|
386
|
+
}
|
|
387
|
+
if (uint8Array.length < otherUint8Array.length)
|
|
388
|
+
return -1;
|
|
389
|
+
if (uint8Array.length > otherUint8Array.length)
|
|
390
|
+
return 1;
|
|
391
|
+
return 0;
|
|
392
|
+
},
|
|
393
|
+
concat(uint8Arrays) {
|
|
394
|
+
if (uint8Arrays.length === 0)
|
|
395
|
+
return webByteUtils.allocate(0);
|
|
396
|
+
let totalLength = 0;
|
|
397
|
+
for (const uint8Array of uint8Arrays) {
|
|
398
|
+
totalLength += uint8Array.length;
|
|
399
|
+
}
|
|
400
|
+
const result = webByteUtils.allocate(totalLength);
|
|
401
|
+
let offset = 0;
|
|
402
|
+
for (const uint8Array of uint8Arrays) {
|
|
403
|
+
result.set(uint8Array, offset);
|
|
404
|
+
offset += uint8Array.length;
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
},
|
|
408
|
+
equals(uint8Array, otherUint8Array) {
|
|
409
|
+
if (uint8Array.byteLength !== otherUint8Array.byteLength) {
|
|
368
410
|
return false;
|
|
369
411
|
}
|
|
370
|
-
for (let i = 0; i <
|
|
371
|
-
if (
|
|
412
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
413
|
+
if (uint8Array[i] !== otherUint8Array[i]) {
|
|
372
414
|
return false;
|
|
373
415
|
}
|
|
374
416
|
}
|
|
@@ -380,6 +422,9 @@ const webByteUtils = {
|
|
|
380
422
|
fromBase64(base64) {
|
|
381
423
|
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
|
382
424
|
},
|
|
425
|
+
fromUTF8(utf8) {
|
|
426
|
+
return new TextEncoder().encode(utf8);
|
|
427
|
+
},
|
|
383
428
|
toBase64(uint8array) {
|
|
384
429
|
return btoa(webByteUtils.toISO88591(uint8array));
|
|
385
430
|
},
|
|
@@ -4549,8 +4594,6 @@ function parseToElements(bytes, startOffset = 0) {
|
|
|
4549
4594
|
|
|
4550
4595
|
const onDemand = Object.create(null);
|
|
4551
4596
|
onDemand.parseToElements = parseToElements;
|
|
4552
|
-
onDemand.ByteUtils = ByteUtils;
|
|
4553
|
-
onDemand.NumberUtils = NumberUtils;
|
|
4554
4597
|
Object.freeze(onDemand);
|
|
4555
4598
|
|
|
4556
4599
|
const MAXSIZE = 1024 * 1024 * 17;
|
|
@@ -4615,6 +4658,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4615
4658
|
BSONValue: BSONValue,
|
|
4616
4659
|
BSONVersionError: BSONVersionError,
|
|
4617
4660
|
Binary: Binary,
|
|
4661
|
+
ByteUtils: ByteUtils,
|
|
4618
4662
|
Code: Code,
|
|
4619
4663
|
DBRef: DBRef,
|
|
4620
4664
|
Decimal128: Decimal128,
|
|
@@ -4624,6 +4668,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4624
4668
|
Long: Long,
|
|
4625
4669
|
MaxKey: MaxKey,
|
|
4626
4670
|
MinKey: MinKey,
|
|
4671
|
+
NumberUtils: NumberUtils,
|
|
4627
4672
|
ObjectId: ObjectId,
|
|
4628
4673
|
Timestamp: Timestamp,
|
|
4629
4674
|
UUID: UUID,
|
|
@@ -4647,6 +4692,7 @@ exports.BSONType = BSONType;
|
|
|
4647
4692
|
exports.BSONValue = BSONValue;
|
|
4648
4693
|
exports.BSONVersionError = BSONVersionError;
|
|
4649
4694
|
exports.Binary = Binary;
|
|
4695
|
+
exports.ByteUtils = ByteUtils;
|
|
4650
4696
|
exports.Code = Code;
|
|
4651
4697
|
exports.DBRef = DBRef;
|
|
4652
4698
|
exports.Decimal128 = Decimal128;
|
|
@@ -4656,6 +4702,7 @@ exports.Int32 = Int32;
|
|
|
4656
4702
|
exports.Long = Long;
|
|
4657
4703
|
exports.MaxKey = MaxKey;
|
|
4658
4704
|
exports.MinKey = MinKey;
|
|
4705
|
+
exports.NumberUtils = NumberUtils;
|
|
4659
4706
|
exports.ObjectId = ObjectId;
|
|
4660
4707
|
exports.Timestamp = Timestamp;
|
|
4661
4708
|
exports.UUID = UUID;
|