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.node.mjs
CHANGED
|
@@ -230,6 +230,7 @@ const nodejsRandomBytes = (() => {
|
|
|
230
230
|
}
|
|
231
231
|
})();
|
|
232
232
|
const nodeJsByteUtils = {
|
|
233
|
+
isUint8Array: isUint8Array,
|
|
233
234
|
toLocalBufferType(potentialBuffer) {
|
|
234
235
|
if (Buffer.isBuffer(potentialBuffer)) {
|
|
235
236
|
return potentialBuffer;
|
|
@@ -252,6 +253,12 @@ const nodeJsByteUtils = {
|
|
|
252
253
|
allocateUnsafe(size) {
|
|
253
254
|
return Buffer.allocUnsafe(size);
|
|
254
255
|
},
|
|
256
|
+
compare(a, b) {
|
|
257
|
+
return nodeJsByteUtils.toLocalBufferType(a).compare(b);
|
|
258
|
+
},
|
|
259
|
+
concat(list) {
|
|
260
|
+
return Buffer.concat(list);
|
|
261
|
+
},
|
|
255
262
|
equals(a, b) {
|
|
256
263
|
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
257
264
|
},
|
|
@@ -261,6 +268,9 @@ const nodeJsByteUtils = {
|
|
|
261
268
|
fromBase64(base64) {
|
|
262
269
|
return Buffer.from(base64, 'base64');
|
|
263
270
|
},
|
|
271
|
+
fromUTF8(utf8) {
|
|
272
|
+
return Buffer.from(utf8, 'utf8');
|
|
273
|
+
},
|
|
264
274
|
toBase64(buffer) {
|
|
265
275
|
return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
|
|
266
276
|
},
|
|
@@ -335,6 +345,7 @@ const webRandomBytes = (() => {
|
|
|
335
345
|
})();
|
|
336
346
|
const HEX_DIGIT = /(\d|[a-f])/i;
|
|
337
347
|
const webByteUtils = {
|
|
348
|
+
isUint8Array: isUint8Array,
|
|
338
349
|
toLocalBufferType(potentialUint8array) {
|
|
339
350
|
const stringTag = potentialUint8array?.[Symbol.toStringTag] ??
|
|
340
351
|
Object.prototype.toString.call(potentialUint8array);
|
|
@@ -361,12 +372,43 @@ const webByteUtils = {
|
|
|
361
372
|
allocateUnsafe(size) {
|
|
362
373
|
return webByteUtils.allocate(size);
|
|
363
374
|
},
|
|
364
|
-
|
|
365
|
-
if (
|
|
375
|
+
compare(uint8Array, otherUint8Array) {
|
|
376
|
+
if (uint8Array === otherUint8Array)
|
|
377
|
+
return 0;
|
|
378
|
+
const len = Math.min(uint8Array.length, otherUint8Array.length);
|
|
379
|
+
for (let i = 0; i < len; i++) {
|
|
380
|
+
if (uint8Array[i] < otherUint8Array[i])
|
|
381
|
+
return -1;
|
|
382
|
+
if (uint8Array[i] > otherUint8Array[i])
|
|
383
|
+
return 1;
|
|
384
|
+
}
|
|
385
|
+
if (uint8Array.length < otherUint8Array.length)
|
|
386
|
+
return -1;
|
|
387
|
+
if (uint8Array.length > otherUint8Array.length)
|
|
388
|
+
return 1;
|
|
389
|
+
return 0;
|
|
390
|
+
},
|
|
391
|
+
concat(uint8Arrays) {
|
|
392
|
+
if (uint8Arrays.length === 0)
|
|
393
|
+
return webByteUtils.allocate(0);
|
|
394
|
+
let totalLength = 0;
|
|
395
|
+
for (const uint8Array of uint8Arrays) {
|
|
396
|
+
totalLength += uint8Array.length;
|
|
397
|
+
}
|
|
398
|
+
const result = webByteUtils.allocate(totalLength);
|
|
399
|
+
let offset = 0;
|
|
400
|
+
for (const uint8Array of uint8Arrays) {
|
|
401
|
+
result.set(uint8Array, offset);
|
|
402
|
+
offset += uint8Array.length;
|
|
403
|
+
}
|
|
404
|
+
return result;
|
|
405
|
+
},
|
|
406
|
+
equals(uint8Array, otherUint8Array) {
|
|
407
|
+
if (uint8Array.byteLength !== otherUint8Array.byteLength) {
|
|
366
408
|
return false;
|
|
367
409
|
}
|
|
368
|
-
for (let i = 0; i <
|
|
369
|
-
if (
|
|
410
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
411
|
+
if (uint8Array[i] !== otherUint8Array[i]) {
|
|
370
412
|
return false;
|
|
371
413
|
}
|
|
372
414
|
}
|
|
@@ -378,6 +420,9 @@ const webByteUtils = {
|
|
|
378
420
|
fromBase64(base64) {
|
|
379
421
|
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
|
|
380
422
|
},
|
|
423
|
+
fromUTF8(utf8) {
|
|
424
|
+
return new TextEncoder().encode(utf8);
|
|
425
|
+
},
|
|
381
426
|
toBase64(uint8array) {
|
|
382
427
|
return btoa(webByteUtils.toISO88591(uint8array));
|
|
383
428
|
},
|
|
@@ -4613,6 +4658,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4613
4658
|
BSONValue: BSONValue,
|
|
4614
4659
|
BSONVersionError: BSONVersionError,
|
|
4615
4660
|
Binary: Binary,
|
|
4661
|
+
ByteUtils: ByteUtils,
|
|
4616
4662
|
Code: Code,
|
|
4617
4663
|
DBRef: DBRef,
|
|
4618
4664
|
Decimal128: Decimal128,
|
|
@@ -4622,6 +4668,7 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4622
4668
|
Long: Long,
|
|
4623
4669
|
MaxKey: MaxKey,
|
|
4624
4670
|
MinKey: MinKey,
|
|
4671
|
+
NumberUtils: NumberUtils,
|
|
4625
4672
|
ObjectId: ObjectId,
|
|
4626
4673
|
Timestamp: Timestamp,
|
|
4627
4674
|
UUID: UUID,
|
|
@@ -4635,5 +4682,5 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4635
4682
|
setInternalBufferSize: setInternalBufferSize
|
|
4636
4683
|
});
|
|
4637
4684
|
|
|
4638
|
-
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 };
|
|
4685
|
+
export { bson as BSON, BSONError, BSONOffsetError, BSONRegExp, BSONRuntimeError, BSONSymbol, BSONType, BSONValue, BSONVersionError, Binary, ByteUtils, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, MaxKey, MinKey, NumberUtils, ObjectId, Timestamp, UUID, bsonType, calculateObjectSize, deserialize, deserializeStream, onDemand, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
4639
4686
|
//# sourceMappingURL=bson.node.mjs.map
|