bson 5.3.0 → 5.4.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.
Files changed (67) hide show
  1. package/README.md +4 -11
  2. package/lib/bson.bundle.js +20 -18
  3. package/lib/bson.bundle.js.map +1 -1
  4. package/lib/bson.cjs +20 -18
  5. package/lib/bson.cjs.map +1 -1
  6. package/lib/bson.mjs +20 -18
  7. package/lib/bson.mjs.map +1 -1
  8. package/lib/bson.rn.cjs +4110 -0
  9. package/lib/bson.rn.cjs.map +1 -0
  10. package/package.json +8 -7
  11. package/src/binary.ts +3 -2
  12. package/src/bson.ts +2 -2
  13. package/src/parser/deserializer.ts +8 -8
  14. package/src/timestamp.ts +7 -5
  15. package/src/utils/byte_utils.ts +1 -1
  16. package/src/utils/node_byte_utils.ts +3 -3
  17. package/src/utils/web_byte_utils.ts +2 -2
  18. package/vendor/base64/LICENSE-MIT.txt +20 -0
  19. package/vendor/base64/README.md +112 -0
  20. package/vendor/base64/base64.js +157 -0
  21. package/vendor/base64/package.json +43 -0
  22. package/vendor/text-encoding/LICENSE.md +237 -0
  23. package/vendor/text-encoding/README.md +111 -0
  24. package/vendor/text-encoding/index.js +9 -0
  25. package/vendor/text-encoding/lib/encoding-indexes.js +47 -0
  26. package/vendor/text-encoding/lib/encoding.js +3301 -0
  27. package/vendor/text-encoding/package.json +37 -0
  28. package/lib/binary.d.ts +0 -182
  29. package/lib/binary.d.ts.map +0 -1
  30. package/lib/bson.d.ts +0 -97
  31. package/lib/bson.d.ts.map +0 -1
  32. package/lib/bson_value.d.ts +0 -10
  33. package/lib/bson_value.d.ts.map +0 -1
  34. package/lib/code.d.ts +0 -32
  35. package/lib/code.d.ts.map +0 -1
  36. package/lib/constants.d.ts +0 -107
  37. package/lib/constants.d.ts.map +0 -1
  38. package/lib/db_ref.d.ts +0 -40
  39. package/lib/db_ref.d.ts.map +0 -1
  40. package/lib/decimal128.d.ts +0 -34
  41. package/lib/decimal128.d.ts.map +0 -1
  42. package/lib/double.d.ts +0 -35
  43. package/lib/double.d.ts.map +0 -1
  44. package/lib/error.d.ts +0 -50
  45. package/lib/error.d.ts.map +0 -1
  46. package/lib/extended_json.d.ts +0 -82
  47. package/lib/extended_json.d.ts.map +0 -1
  48. package/lib/index.d.ts +0 -4
  49. package/lib/index.d.ts.map +0 -1
  50. package/lib/int_32.d.ts +0 -35
  51. package/lib/int_32.d.ts.map +0 -1
  52. package/lib/long.d.ts +0 -323
  53. package/lib/long.d.ts.map +0 -1
  54. package/lib/max_key.d.ts +0 -19
  55. package/lib/max_key.d.ts.map +0 -1
  56. package/lib/min_key.d.ts +0 -19
  57. package/lib/min_key.d.ts.map +0 -1
  58. package/lib/objectid.d.ts +0 -96
  59. package/lib/objectid.d.ts.map +0 -1
  60. package/lib/regexp.d.ts +0 -36
  61. package/lib/regexp.d.ts.map +0 -1
  62. package/lib/symbol.d.ts +0 -28
  63. package/lib/symbol.d.ts.map +0 -1
  64. package/lib/timestamp.d.ts +0 -66
  65. package/lib/timestamp.d.ts.map +0 -1
  66. package/lib/validate_utf8.d.ts +0 -10
  67. package/lib/validate_utf8.d.ts.map +0 -1
package/lib/bson.cjs CHANGED
@@ -165,8 +165,8 @@ const nodeJsByteUtils = {
165
165
  fromUTF8(text) {
166
166
  return Buffer.from(text, 'utf8');
167
167
  },
168
- toUTF8(buffer) {
169
- return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8');
168
+ toUTF8(buffer, start, end) {
169
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
170
170
  },
171
171
  utf8ByteLength(input) {
172
172
  return Buffer.byteLength(input, 'utf8');
@@ -276,8 +276,8 @@ const webByteUtils = {
276
276
  fromUTF8(text) {
277
277
  return new TextEncoder().encode(text);
278
278
  },
279
- toUTF8(uint8array) {
280
- return new TextDecoder('utf8', { fatal: false }).decode(uint8array);
279
+ toUTF8(uint8array, start, end) {
280
+ return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
281
281
  },
282
282
  utf8ByteLength(input) {
283
283
  return webByteUtils.fromUTF8(input).byteLength;
@@ -409,8 +409,8 @@ class Binary extends BSONValue {
409
409
  if (encoding === 'base64')
410
410
  return ByteUtils.toBase64(this.buffer);
411
411
  if (encoding === 'utf8' || encoding === 'utf-8')
412
- return ByteUtils.toUTF8(this.buffer);
413
- return ByteUtils.toUTF8(this.buffer);
412
+ return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
413
+ return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
414
414
  }
415
415
  toExtendedJSON(options) {
416
416
  options = options || {};
@@ -2416,19 +2416,21 @@ class Timestamp extends LongWithoutOverridesClass {
2416
2416
  if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
2417
2417
  throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
2418
2418
  }
2419
- if (low.t < 0) {
2419
+ const t = Number(low.t);
2420
+ const i = Number(low.i);
2421
+ if (t < 0 || Number.isNaN(t)) {
2420
2422
  throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
2421
2423
  }
2422
- if (low.i < 0) {
2424
+ if (i < 0 || Number.isNaN(i)) {
2423
2425
  throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
2424
2426
  }
2425
- if (low.t > 4294967295) {
2427
+ if (t > 4294967295) {
2426
2428
  throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
2427
2429
  }
2428
- if (low.i > 4294967295) {
2430
+ if (i > 4294967295) {
2429
2431
  throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
2430
2432
  }
2431
- super(low.i.valueOf(), low.t.valueOf(), true);
2433
+ super(i, t, true);
2432
2434
  }
2433
2435
  else {
2434
2436
  throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
@@ -2600,7 +2602,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2600
2602
  }
2601
2603
  if (i >= buffer.byteLength)
2602
2604
  throw new BSONError('Bad BSON Document: illegal CString');
2603
- const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer.subarray(index, i));
2605
+ const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
2604
2606
  let shouldValidateKey = true;
2605
2607
  if (globalUTFValidation || utf8KeysSet.has(name)) {
2606
2608
  shouldValidateKey = validationSetting;
@@ -2815,7 +2817,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2815
2817
  }
2816
2818
  if (i >= buffer.length)
2817
2819
  throw new BSONError('Bad BSON Document: illegal CString');
2818
- const source = ByteUtils.toUTF8(buffer.subarray(index, i));
2820
+ const source = ByteUtils.toUTF8(buffer, index, i);
2819
2821
  index = i + 1;
2820
2822
  i = index;
2821
2823
  while (buffer[i] !== 0x00 && i < buffer.length) {
@@ -2823,7 +2825,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2823
2825
  }
2824
2826
  if (i >= buffer.length)
2825
2827
  throw new BSONError('Bad BSON Document: illegal CString');
2826
- const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i));
2828
+ const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
2827
2829
  index = i + 1;
2828
2830
  const optionsArray = new Array(regExpOptions.length);
2829
2831
  for (i = 0; i < regExpOptions.length; i++) {
@@ -2848,7 +2850,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2848
2850
  }
2849
2851
  if (i >= buffer.length)
2850
2852
  throw new BSONError('Bad BSON Document: illegal CString');
2851
- const source = ByteUtils.toUTF8(buffer.subarray(index, i));
2853
+ const source = ByteUtils.toUTF8(buffer, index, i);
2852
2854
  index = i + 1;
2853
2855
  i = index;
2854
2856
  while (buffer[i] !== 0x00 && i < buffer.length) {
@@ -2856,7 +2858,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2856
2858
  }
2857
2859
  if (i >= buffer.length)
2858
2860
  throw new BSONError('Bad BSON Document: illegal CString');
2859
- const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i));
2861
+ const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
2860
2862
  index = i + 1;
2861
2863
  value = new BSONRegExp(source, regExpOptions);
2862
2864
  }
@@ -2953,7 +2955,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2953
2955
  throw new BSONError('Invalid UTF-8 string in BSON document');
2954
2956
  }
2955
2957
  }
2956
- const namespace = ByteUtils.toUTF8(buffer.subarray(index, index + stringSize - 1));
2958
+ const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
2957
2959
  index = index + stringSize;
2958
2960
  const oidBuffer = ByteUtils.allocate(12);
2959
2961
  oidBuffer.set(buffer.subarray(index, index + 12), 0);
@@ -2993,7 +2995,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2993
2995
  return object;
2994
2996
  }
2995
2997
  function getValidatedString(buffer, start, end, shouldValidateUtf8) {
2996
- const value = ByteUtils.toUTF8(buffer.subarray(start, end));
2998
+ const value = ByteUtils.toUTF8(buffer, start, end);
2997
2999
  if (shouldValidateUtf8) {
2998
3000
  for (let i = 0; i < value.length; i++) {
2999
3001
  if (value.charCodeAt(i) === 0xfffd) {