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/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
- equals(a, b) {
367
- if (a.byteLength !== b.byteLength) {
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 < a.byteLength; i++) {
371
- if (a[i] !== b[i]) {
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
  },
@@ -4615,6 +4660,7 @@ var bson = /*#__PURE__*/Object.freeze({
4615
4660
  BSONValue: BSONValue,
4616
4661
  BSONVersionError: BSONVersionError,
4617
4662
  Binary: Binary,
4663
+ ByteUtils: ByteUtils,
4618
4664
  Code: Code,
4619
4665
  DBRef: DBRef,
4620
4666
  Decimal128: Decimal128,
@@ -4624,6 +4670,7 @@ var bson = /*#__PURE__*/Object.freeze({
4624
4670
  Long: Long,
4625
4671
  MaxKey: MaxKey,
4626
4672
  MinKey: MinKey,
4673
+ NumberUtils: NumberUtils,
4627
4674
  ObjectId: ObjectId,
4628
4675
  Timestamp: Timestamp,
4629
4676
  UUID: UUID,
@@ -4647,6 +4694,7 @@ exports.BSONType = BSONType;
4647
4694
  exports.BSONValue = BSONValue;
4648
4695
  exports.BSONVersionError = BSONVersionError;
4649
4696
  exports.Binary = Binary;
4697
+ exports.ByteUtils = ByteUtils;
4650
4698
  exports.Code = Code;
4651
4699
  exports.DBRef = DBRef;
4652
4700
  exports.Decimal128 = Decimal128;
@@ -4656,6 +4704,7 @@ exports.Int32 = Int32;
4656
4704
  exports.Long = Long;
4657
4705
  exports.MaxKey = MaxKey;
4658
4706
  exports.MinKey = MinKey;
4707
+ exports.NumberUtils = NumberUtils;
4659
4708
  exports.ObjectId = ObjectId;
4660
4709
  exports.Timestamp = Timestamp;
4661
4710
  exports.UUID = UUID;