bson 4.2.2 → 4.4.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.
Files changed (84) hide show
  1. package/HISTORY.md +44 -0
  2. package/bower.json +1 -1
  3. package/bson.d.ts +77 -6
  4. package/dist/bson.browser.esm.js +2116 -1292
  5. package/dist/bson.browser.esm.js.map +1 -1
  6. package/dist/bson.browser.umd.js +2172 -1347
  7. package/dist/bson.browser.umd.js.map +1 -1
  8. package/dist/bson.bundle.js +2174 -1347
  9. package/dist/bson.bundle.js.map +1 -1
  10. package/dist/bson.esm.js +2061 -1241
  11. package/dist/bson.esm.js.map +1 -1
  12. package/lib/binary.js +71 -60
  13. package/lib/binary.js.map +1 -1
  14. package/lib/bson.js +60 -52
  15. package/lib/bson.js.map +1 -1
  16. package/lib/code.js +18 -15
  17. package/lib/code.js.map +1 -1
  18. package/lib/db_ref.js +40 -30
  19. package/lib/db_ref.js.map +1 -1
  20. package/lib/decimal128.js +135 -124
  21. package/lib/decimal128.js.map +1 -1
  22. package/lib/double.js +24 -21
  23. package/lib/double.js.map +1 -1
  24. package/lib/ensure_buffer.js +4 -7
  25. package/lib/ensure_buffer.js.map +1 -1
  26. package/lib/extended_json.js +113 -71
  27. package/lib/extended_json.js.map +1 -1
  28. package/lib/float_parser.js +21 -21
  29. package/lib/float_parser.js.map +1 -1
  30. package/lib/int_32.js +19 -16
  31. package/lib/int_32.js.map +1 -1
  32. package/lib/long.js +248 -230
  33. package/lib/long.js.map +1 -1
  34. package/lib/map.js +54 -45
  35. package/lib/map.js.map +1 -1
  36. package/lib/max_key.js +16 -11
  37. package/lib/max_key.js.map +1 -1
  38. package/lib/min_key.js +16 -11
  39. package/lib/min_key.js.map +1 -1
  40. package/lib/objectid.js +96 -93
  41. package/lib/objectid.js.map +1 -1
  42. package/lib/parser/calculate_size.js +17 -15
  43. package/lib/parser/calculate_size.js.map +1 -1
  44. package/lib/parser/deserializer.js +135 -123
  45. package/lib/parser/deserializer.js.map +1 -1
  46. package/lib/parser/serializer.js +108 -88
  47. package/lib/parser/serializer.js.map +1 -1
  48. package/lib/parser/utils.js +47 -25
  49. package/lib/parser/utils.js.map +1 -1
  50. package/lib/regexp.js +16 -15
  51. package/lib/regexp.js.map +1 -1
  52. package/lib/symbol.js +21 -18
  53. package/lib/symbol.js.map +1 -1
  54. package/lib/timestamp.js +50 -27
  55. package/lib/timestamp.js.map +1 -1
  56. package/lib/uuid.js +173 -42
  57. package/lib/uuid.js.map +1 -1
  58. package/lib/uuid_utils.js +34 -0
  59. package/lib/uuid_utils.js.map +1 -0
  60. package/lib/validate_utf8.js +12 -12
  61. package/lib/validate_utf8.js.map +1 -1
  62. package/package.json +5 -4
  63. package/src/binary.ts +20 -6
  64. package/src/bson.ts +3 -0
  65. package/src/code.ts +6 -2
  66. package/src/db_ref.ts +14 -5
  67. package/src/decimal128.ts +14 -5
  68. package/src/double.ts +4 -2
  69. package/src/ensure_buffer.ts +7 -7
  70. package/src/extended_json.ts +64 -16
  71. package/src/int_32.ts +4 -2
  72. package/src/long.ts +22 -8
  73. package/src/max_key.ts +5 -1
  74. package/src/min_key.ts +5 -1
  75. package/src/objectid.ts +15 -20
  76. package/src/parser/calculate_size.ts +8 -11
  77. package/src/parser/deserializer.ts +46 -36
  78. package/src/parser/serializer.ts +13 -12
  79. package/src/parser/utils.ts +49 -17
  80. package/src/regexp.ts +5 -5
  81. package/src/symbol.ts +4 -2
  82. package/src/timestamp.ts +6 -1
  83. package/src/uuid.ts +192 -40
  84. package/src/uuid_utils.ts +31 -0
package/HISTORY.md CHANGED
@@ -2,6 +2,50 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [4.4.1](https://github.com/mongodb/js-bson/compare/v4.4.0...v4.4.1) (2021-07-06)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **NODE-3247:** DBRef special handling ([#443](https://github.com/mongodb/js-bson/issues/443)) ([f5d984d](https://github.com/mongodb/js-bson/commit/f5d984d88b2e20310ec5cc3a39b91b0fd1e0b3c9))
11
+ * **NODE-3282:** BSONRegExp options not alphabetized ([#441](https://github.com/mongodb/js-bson/issues/441)) ([18c3512](https://github.com/mongodb/js-bson/commit/18c3512befe54908e4b816056dbde0d1b998d81b))
12
+ * **NODE-3376:** use standard JS methods for copying Buffers ([#444](https://github.com/mongodb/js-bson/issues/444)) ([804050d](https://github.com/mongodb/js-bson/commit/804050d40b03a02116995e63671e05ffa033dc45))
13
+ * **NODE-3390:** serialize non-finite doubles correctly in EJSON ([#445](https://github.com/mongodb/js-bson/issues/445)) ([7eb7998](https://github.com/mongodb/js-bson/commit/7eb79981e16d73a391c567b7f9748943997a424d))
14
+
15
+ ## [4.4.0](https://github.com/mongodb/js-bson/compare/v4.3.0...v4.4.0) (2021-05-18)
16
+
17
+
18
+ ### Features
19
+
20
+ * **NODE-3264:** allow Decimal128(string), Long(string), Long(bigint) ([#437](https://github.com/mongodb/js-bson/issues/437)) ([392c1bc](https://github.com/mongodb/js-bson/commit/392c1bcbe003b185f38d64a8a24bc21a6661cb26))
21
+ * make circular input errors for EJSON expressive ([#433](https://github.com/mongodb/js-bson/issues/433)) ([7b351cc](https://github.com/mongodb/js-bson/commit/7b351cc217786e5ee992f0fb64588f9c3fddd828))
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * make Long inspect result evaluable ([3a2eff1](https://github.com/mongodb/js-bson/commit/3a2eff127175c7f94c9ccc940074537b7ad972f1))
27
+ * **NODE-3153:** correctly deserialize `__proto__` properties ([#431](https://github.com/mongodb/js-bson/issues/431)) ([f34cabc](https://github.com/mongodb/js-bson/commit/f34cabc31e66bc809d8e3cc6b0d203739f40aa41))
28
+ * accept Uint8Array where Buffer is accepted ([#432](https://github.com/mongodb/js-bson/issues/432)) ([4613763](https://github.com/mongodb/js-bson/commit/46137636ac8e59010ba3bfdd317d5d13d9d3066d))
29
+ * clean up instanceof usage ([9b6d52a](https://github.com/mongodb/js-bson/commit/9b6d52a84a20641b22732355e56c3bae3fe857f1))
30
+ * improve ArrayBuffer brand check in ensureBuffer ([#429](https://github.com/mongodb/js-bson/issues/429)) ([99722f6](https://github.com/mongodb/js-bson/commit/99722f66d9f5eeb0ab57e74bab26049a425fa3e8))
31
+
32
+ ## [4.3.0](https://github.com/mongodb/js-bson/compare/v4.2.3...v4.3.0) (2021-04-06)
33
+
34
+
35
+ ### Features
36
+
37
+ * UUID convenience class ([#425](https://github.com/mongodb/js-bson/issues/425)) ([76e1826](https://github.com/mongodb/js-bson/commit/76e1826eed852d4cca9fafabbcf826af1367c9af))
38
+
39
+ ### [4.2.3](https://github.com/mongodb/js-bson/compare/v4.2.2...v4.2.3) (2021-03-02)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * allow library to be loaded in web workeds ([#423](https://github.com/mongodb/js-bson/issues/423)) ([023f57e](https://github.com/mongodb/js-bson/commit/5ae057d3c6dd87e1407dcdc7b8d9da668023f57e))
45
+
46
+ * make inspection result of BSON types evaluable ([#416](https://github.com/mongodb/js-bson/issues/416)) ([616665f](https://github.com/mongodb/js-bson/commit/616665f5e6f7dd06a88de450aaccaa203fa6c652))
47
+ * permit BSON types to be created without new ([#424](https://github.com/mongodb/js-bson/issues/424)) ([d2bc284](https://github.com/mongodb/js-bson/commit/d2bc284943649ac27116701a4ed91ff731a4bdf7))
48
+
5
49
  ### [4.2.2](https://github.com/mongodb/js-bson/compare/v4.2.1...v4.2.2) (2020-12-01)
6
50
 
7
51
 
package/bower.json CHANGED
@@ -22,5 +22,5 @@
22
22
  "test",
23
23
  "tools"
24
24
  ],
25
- "version": "4.2.2"
25
+ "version": "4.4.1"
26
26
  }
package/bson.d.ts CHANGED
@@ -62,6 +62,7 @@ export declare class Binary {
62
62
  /* Excluded from this release type: toJSON */
63
63
  /* Excluded from this release type: toString */
64
64
  /* Excluded from this release type: toExtendedJSON */
65
+ /* Excluded from this release type: toUUID */
65
66
  /* Excluded from this release type: fromExtendedJSON */
66
67
  inspect(): string;
67
68
  }
@@ -95,6 +96,7 @@ declare const BSON: {
95
96
  Double: typeof Double;
96
97
  Int32: typeof Int32;
97
98
  Long: typeof Long;
99
+ UUID: typeof UUID;
98
100
  Map: MapConstructor;
99
101
  MaxKey: typeof MaxKey;
100
102
  MinKey: typeof MinKey;
@@ -258,8 +260,11 @@ export declare interface DBRefLike {
258
260
  export declare class Decimal128 {
259
261
  _bsontype: 'Decimal128';
260
262
  readonly bytes: Buffer;
261
- /** @param bytes - a buffer containing the raw Decimal128 bytes in little endian order */
262
- constructor(bytes: Buffer);
263
+ /**
264
+ * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
265
+ * or a string representation as returned by .toString()
266
+ */
267
+ constructor(bytes: Buffer | string);
263
268
  /**
264
269
  * Create a Decimal128 instance from a string representation
265
270
  *
@@ -463,6 +468,7 @@ export declare interface Int32Extended {
463
468
  $numberInt: string;
464
469
  }
465
470
  declare const kId: unique symbol;
471
+ declare const kId_2: unique symbol;
466
472
  /**
467
473
  * A class representing a 64-bit integer
468
474
  * @public
@@ -500,11 +506,17 @@ export declare class Long {
500
506
  /**
501
507
  * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
502
508
  * See the from* functions below for more convenient ways of constructing Longs.
509
+ *
510
+ * Acceptable signatures are:
511
+ * - Long(low, high, unsigned?)
512
+ * - Long(bigint, unsigned?)
513
+ * - Long(string, unsigned?)
514
+ *
503
515
  * @param low - The low (signed) 32 bits of the long
504
516
  * @param high - The high (signed) 32 bits of the long
505
517
  * @param unsigned - Whether unsigned or not, defaults to signed
506
518
  */
507
- constructor(low?: number, high?: number, unsigned?: boolean);
519
+ constructor(low?: number | bigint | string, high?: number | boolean, unsigned?: boolean);
508
520
  static TWO_PWR_24: Long;
509
521
  /** Maximum unsigned value. */
510
522
  static MAX_UNSIGNED_VALUE: Long;
@@ -790,6 +802,7 @@ export { Map_2 as Map };
790
802
  */
791
803
  export declare class MaxKey {
792
804
  _bsontype: 'MaxKey';
805
+ constructor();
793
806
  /* Excluded from this release type: toExtendedJSON */
794
807
  /* Excluded from this release type: fromExtendedJSON */
795
808
  inspect(): string;
@@ -804,6 +817,7 @@ export declare interface MaxKeyExtended {
804
817
  */
805
818
  export declare class MinKey {
806
819
  _bsontype: 'MinKey';
820
+ constructor();
807
821
  /* Excluded from this release type: toExtendedJSON */
808
822
  /* Excluded from this release type: fromExtendedJSON */
809
823
  inspect(): string;
@@ -875,7 +889,7 @@ declare class ObjectId {
875
889
  *
876
890
  * @param id - ObjectId instance to validate.
877
891
  */
878
- static isValid(id: number | string | ObjectId | Buffer | ObjectIdLike): boolean;
892
+ static isValid(id: number | string | ObjectId | Uint8Array | ObjectIdLike): boolean;
879
893
  /* Excluded from this release type: toExtendedJSON */
880
894
  /* Excluded from this release type: fromExtendedJSON */
881
895
  inspect(): string;
@@ -941,6 +955,7 @@ export declare class Timestamp extends LongWithoutOverridesClass {
941
955
  * @param low - the low (signed) 32 bits of the Timestamp.
942
956
  * @param high - the high (signed) 32 bits of the Timestamp.
943
957
  */
958
+ constructor(low: Long);
944
959
  constructor(low: number, high: number);
945
960
  toJSON(): {
946
961
  $timestamp: string;
@@ -976,8 +991,64 @@ export declare interface TimestampExtended {
976
991
  }
977
992
  /** @public */
978
993
  export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect';
994
+ /**
995
+ * A class representation of the BSON UUID type.
996
+ * @public
997
+ */
998
+ export declare class UUID {
999
+ _bsontype: 'UUID';
1000
+ static cacheHexString: boolean;
1001
+ /* Excluded from this release type: [kId] */
1002
+ /* Excluded from this release type: __id */
1003
+ /**
1004
+ * Create an UUID type
1005
+ *
1006
+ * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
1007
+ */
1008
+ constructor(input?: string | Buffer | UUID);
1009
+ /*
1010
+ * The UUID bytes
1011
+ * @readonly
1012
+ */
1013
+ id: Buffer;
1014
+ /**
1015
+ * Generate a 16 byte uuid v4 buffer used in UUIDs
1016
+ */
1017
+ /**
1018
+ * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
1019
+ * @param includeDashes - should the string exclude dash-separators.
1020
+ * */
1021
+ toHexString(includeDashes?: boolean): string;
1022
+ /* Excluded from this release type: toString */
1023
+ /* Excluded from this release type: toJSON */
1024
+ /**
1025
+ * Compares the equality of this UUID with `otherID`.
1026
+ *
1027
+ * @param otherId - UUID instance to compare against.
1028
+ */
1029
+ equals(otherId: string | Buffer | UUID): boolean;
1030
+ /**
1031
+ * Creates a Binary instance from the current UUID.
1032
+ */
1033
+ toBinary(): Binary;
1034
+ /**
1035
+ * Generates a populated buffer containing a v4 uuid
1036
+ */
1037
+ static generate(): Buffer;
1038
+ /**
1039
+ * Checks if a value is a valid bson UUID
1040
+ * @param input - UUID, string or Buffer to validate.
1041
+ */
1042
+ static isValid(input: string | Buffer | UUID): boolean;
1043
+ /**
1044
+ * Creates an UUID from a hex string representation of an UUID.
1045
+ * @param hexString - 32 or 36 character hex string (dashes excluded/included).
1046
+ */
1047
+ static createFromHexString(hexString: string): UUID;
1048
+ inspect(): string;
1049
+ }
979
1050
  /** @public */
980
- export declare interface UUIDExtended {
1051
+ export declare type UUIDExtended = {
981
1052
  $uuid: string;
982
- }
1053
+ };
983
1054
  export {};