bson 4.7.0 → 5.0.0-alpha.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 (98) hide show
  1. package/bson.d.ts +207 -259
  2. package/lib/bson.bundle.js +4033 -0
  3. package/lib/bson.bundle.js.map +1 -0
  4. package/lib/bson.cjs +4028 -0
  5. package/lib/bson.cjs.map +1 -0
  6. package/lib/bson.mjs +4002 -0
  7. package/lib/bson.mjs.map +1 -0
  8. package/package.json +49 -62
  9. package/src/binary.ts +63 -52
  10. package/src/bson.ts +27 -108
  11. package/src/code.ts +24 -14
  12. package/src/constants.ts +28 -0
  13. package/src/db_ref.ts +13 -8
  14. package/src/decimal128.ts +31 -25
  15. package/src/double.ts +7 -5
  16. package/src/error.ts +0 -2
  17. package/src/extended_json.ts +148 -148
  18. package/src/index.ts +19 -0
  19. package/src/int_32.ts +7 -5
  20. package/src/long.ts +16 -16
  21. package/src/max_key.ts +6 -6
  22. package/src/min_key.ts +6 -6
  23. package/src/objectid.ts +41 -74
  24. package/src/parser/calculate_size.ts +39 -63
  25. package/src/parser/deserializer.ts +41 -112
  26. package/src/parser/serializer.ts +234 -341
  27. package/src/parser/utils.ts +1 -99
  28. package/src/regexp.ts +16 -5
  29. package/src/symbol.ts +7 -5
  30. package/src/timestamp.ts +62 -27
  31. package/src/utils/byte_utils.ts +61 -0
  32. package/src/utils/node_byte_utils.ts +141 -0
  33. package/src/utils/web_byte_utils.ts +190 -0
  34. package/src/uuid_utils.ts +15 -15
  35. package/bower.json +0 -26
  36. package/dist/bson.browser.esm.js +0 -7470
  37. package/dist/bson.browser.esm.js.map +0 -1
  38. package/dist/bson.browser.umd.js +0 -7537
  39. package/dist/bson.browser.umd.js.map +0 -1
  40. package/dist/bson.bundle.js +0 -7536
  41. package/dist/bson.bundle.js.map +0 -1
  42. package/dist/bson.esm.js +0 -5436
  43. package/dist/bson.esm.js.map +0 -1
  44. package/lib/binary.js +0 -426
  45. package/lib/binary.js.map +0 -1
  46. package/lib/bson.js +0 -251
  47. package/lib/bson.js.map +0 -1
  48. package/lib/code.js +0 -46
  49. package/lib/code.js.map +0 -1
  50. package/lib/constants.js +0 -82
  51. package/lib/constants.js.map +0 -1
  52. package/lib/db_ref.js +0 -97
  53. package/lib/db_ref.js.map +0 -1
  54. package/lib/decimal128.js +0 -669
  55. package/lib/decimal128.js.map +0 -1
  56. package/lib/double.js +0 -76
  57. package/lib/double.js.map +0 -1
  58. package/lib/ensure_buffer.js +0 -25
  59. package/lib/ensure_buffer.js.map +0 -1
  60. package/lib/error.js +0 -55
  61. package/lib/error.js.map +0 -1
  62. package/lib/extended_json.js +0 -390
  63. package/lib/extended_json.js.map +0 -1
  64. package/lib/int_32.js +0 -58
  65. package/lib/int_32.js.map +0 -1
  66. package/lib/long.js +0 -900
  67. package/lib/long.js.map +0 -1
  68. package/lib/map.js +0 -123
  69. package/lib/map.js.map +0 -1
  70. package/lib/max_key.js +0 -33
  71. package/lib/max_key.js.map +0 -1
  72. package/lib/min_key.js +0 -33
  73. package/lib/min_key.js.map +0 -1
  74. package/lib/objectid.js +0 -299
  75. package/lib/objectid.js.map +0 -1
  76. package/lib/parser/calculate_size.js +0 -194
  77. package/lib/parser/calculate_size.js.map +0 -1
  78. package/lib/parser/deserializer.js +0 -665
  79. package/lib/parser/deserializer.js.map +0 -1
  80. package/lib/parser/serializer.js +0 -867
  81. package/lib/parser/serializer.js.map +0 -1
  82. package/lib/parser/utils.js +0 -115
  83. package/lib/parser/utils.js.map +0 -1
  84. package/lib/regexp.js +0 -74
  85. package/lib/regexp.js.map +0 -1
  86. package/lib/symbol.js +0 -48
  87. package/lib/symbol.js.map +0 -1
  88. package/lib/timestamp.js +0 -102
  89. package/lib/timestamp.js.map +0 -1
  90. package/lib/utils/global.js +0 -18
  91. package/lib/utils/global.js.map +0 -1
  92. package/lib/uuid_utils.js +0 -35
  93. package/lib/uuid_utils.js.map +0 -1
  94. package/lib/validate_utf8.js +0 -47
  95. package/lib/validate_utf8.js.map +0 -1
  96. package/src/ensure_buffer.ts +0 -27
  97. package/src/map.ts +0 -119
  98. package/src/utils/global.ts +0 -22
package/bson.d.ts CHANGED
@@ -1,12 +1,10 @@
1
- import { Buffer } from 'buffer';
2
-
3
1
  /**
4
2
  * A class representation of the BSON Binary type.
5
3
  * @public
6
4
  * @category BSONType
7
5
  */
8
6
  export declare class Binary {
9
- _bsontype: 'Binary';
7
+ get _bsontype(): 'Binary';
10
8
  /* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
11
9
  /** Initial buffer default size */
12
10
  static readonly BUFFER_SIZE = 256;
@@ -28,7 +26,7 @@ export declare class Binary {
28
26
  static readonly SUBTYPE_COLUMN = 7;
29
27
  /** User BSON type */
30
28
  static readonly SUBTYPE_USER_DEFINED = 128;
31
- buffer: Buffer;
29
+ buffer: Uint8Array;
32
30
  sub_type: number;
33
31
  position: number;
34
32
  /**
@@ -48,7 +46,7 @@ export declare class Binary {
48
46
  *
49
47
  * @param byteValue - a single byte we wish to write.
50
48
  */
51
- put(byteValue: string | number | Uint8Array | Buffer | number[]): void;
49
+ put(byteValue: string | number | Uint8Array | number[]): void;
52
50
  /**
53
51
  * Writes a buffer or string to the binary.
54
52
  *
@@ -73,7 +71,7 @@ export declare class Binary {
73
71
  /** the length of the binary sequence */
74
72
  length(): number;
75
73
  toJSON(): string;
76
- toString(format?: string): string;
74
+ toString(encoding?: 'hex' | 'base64' | 'utf8' | 'utf-8'): string;
77
75
  /* Excluded from this release type: toExtendedJSON */
78
76
  toUUID(): UUID;
79
77
  /* Excluded from this release type: fromExtendedJSON */
@@ -95,112 +93,63 @@ export declare interface BinaryExtendedLegacy {
95
93
  }
96
94
 
97
95
  /** @public */
98
- export declare type BinarySequence = Uint8Array | Buffer | number[];
99
-
100
- /**
101
- * BSON default export
102
- * @deprecated Please use named exports
103
- * @privateRemarks
104
- * We want to someday deprecate the default export,
105
- * so none of the new TS types are being exported on the default
106
- * @public
107
- */
108
- declare const BSON: {
109
- Binary: typeof Binary;
110
- Code: typeof Code;
111
- DBRef: typeof DBRef;
112
- Decimal128: typeof Decimal128;
113
- Double: typeof Double;
114
- Int32: typeof Int32;
115
- Long: typeof Long;
116
- UUID: typeof UUID;
117
- Map: MapConstructor;
118
- MaxKey: typeof MaxKey;
119
- MinKey: typeof MinKey;
120
- ObjectId: typeof ObjectId;
121
- ObjectID: typeof ObjectId;
122
- BSONRegExp: typeof BSONRegExp;
123
- BSONSymbol: typeof BSONSymbol;
124
- Timestamp: typeof Timestamp;
125
- EJSON: typeof EJSON;
126
- setInternalBufferSize: typeof setInternalBufferSize;
127
- serialize: typeof serialize;
128
- serializeWithBufferAndIndex: typeof serializeWithBufferAndIndex;
129
- deserialize: typeof deserialize;
130
- calculateObjectSize: typeof calculateObjectSize;
131
- deserializeStream: typeof deserializeStream;
132
- BSONError: typeof BSONError;
133
- BSONTypeError: typeof BSONTypeError;
134
- };
135
- export default BSON;
136
-
137
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_BYTE_ARRAY */
138
-
139
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_COLUMN */
140
-
141
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
142
-
143
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_ENCRYPTED */
144
-
145
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_FUNCTION */
146
-
147
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_MD5 */
148
-
149
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_USER_DEFINED */
150
-
151
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_UUID */
152
-
153
- /* Excluded from this release type: BSON_BINARY_SUBTYPE_UUID_NEW */
154
-
155
- /* Excluded from this release type: BSON_DATA_ARRAY */
156
-
157
- /* Excluded from this release type: BSON_DATA_BINARY */
158
-
159
- /* Excluded from this release type: BSON_DATA_BOOLEAN */
160
-
161
- /* Excluded from this release type: BSON_DATA_CODE */
162
-
163
- /* Excluded from this release type: BSON_DATA_CODE_W_SCOPE */
164
-
165
- /* Excluded from this release type: BSON_DATA_DATE */
166
-
167
- /* Excluded from this release type: BSON_DATA_DBPOINTER */
168
-
169
- /* Excluded from this release type: BSON_DATA_DECIMAL128 */
170
-
171
- /* Excluded from this release type: BSON_DATA_INT */
172
-
173
- /* Excluded from this release type: BSON_DATA_LONG */
174
-
175
- /* Excluded from this release type: BSON_DATA_MAX_KEY */
176
-
177
- /* Excluded from this release type: BSON_DATA_MIN_KEY */
178
-
179
- /* Excluded from this release type: BSON_DATA_NULL */
180
-
181
- /* Excluded from this release type: BSON_DATA_NUMBER */
182
-
183
- /* Excluded from this release type: BSON_DATA_OBJECT */
184
-
185
- /* Excluded from this release type: BSON_DATA_OID */
186
-
187
- /* Excluded from this release type: BSON_DATA_REGEXP */
188
-
189
- /* Excluded from this release type: BSON_DATA_STRING */
190
-
191
- /* Excluded from this release type: BSON_DATA_SYMBOL */
192
-
193
- /* Excluded from this release type: BSON_DATA_TIMESTAMP */
194
-
195
- /* Excluded from this release type: BSON_DATA_UNDEFINED */
196
-
197
- /* Excluded from this release type: BSON_INT32_MAX */
198
-
199
- /* Excluded from this release type: BSON_INT32_MIN */
200
-
201
- /* Excluded from this release type: BSON_INT64_MAX */
202
-
203
- /* Excluded from this release type: BSON_INT64_MIN */
96
+ export declare type BinarySequence = Uint8Array | number[];
97
+
98
+ declare namespace BSON {
99
+ export {
100
+ setInternalBufferSize,
101
+ serialize,
102
+ serializeWithBufferAndIndex,
103
+ deserialize,
104
+ calculateObjectSize,
105
+ deserializeStream,
106
+ UUIDExtended,
107
+ BinaryExtended,
108
+ BinaryExtendedLegacy,
109
+ BinarySequence,
110
+ CodeExtended,
111
+ DBRefLike,
112
+ Decimal128Extended,
113
+ DoubleExtended,
114
+ EJSONOptions,
115
+ Int32Extended,
116
+ LongExtended,
117
+ MaxKeyExtended,
118
+ MinKeyExtended,
119
+ ObjectIdExtended,
120
+ ObjectIdLike,
121
+ BSONRegExpExtended,
122
+ BSONRegExpExtendedLegacy,
123
+ BSONSymbolExtended,
124
+ LongWithoutOverrides,
125
+ TimestampExtended,
126
+ TimestampOverrides,
127
+ LongWithoutOverridesClass,
128
+ SerializeOptions,
129
+ DeserializeOptions,
130
+ Code,
131
+ BSONSymbol,
132
+ DBRef,
133
+ Binary,
134
+ ObjectId,
135
+ UUID,
136
+ Long,
137
+ Timestamp,
138
+ Double,
139
+ Int32,
140
+ MinKey,
141
+ MaxKey,
142
+ BSONRegExp,
143
+ Decimal128,
144
+ BSONError,
145
+ BSONTypeError,
146
+ BSONType,
147
+ EJSON,
148
+ Document,
149
+ CalculateObjectSizeOptions
150
+ }
151
+ }
152
+ export { BSON }
204
153
 
205
154
  /** @public */
206
155
  export declare class BSONError extends Error {
@@ -214,7 +163,7 @@ export declare class BSONError extends Error {
214
163
  * @category BSONType
215
164
  */
216
165
  export declare class BSONRegExp {
217
- _bsontype: 'BSONRegExp';
166
+ get _bsontype(): 'BSONRegExp';
218
167
  pattern: string;
219
168
  options: string;
220
169
  /**
@@ -225,6 +174,7 @@ export declare class BSONRegExp {
225
174
  static parseOptions(options?: string): string;
226
175
  /* Excluded from this release type: toExtendedJSON */
227
176
  /* Excluded from this release type: fromExtendedJSON */
177
+ inspect(): string;
228
178
  }
229
179
 
230
180
  /** @public */
@@ -247,7 +197,7 @@ export declare interface BSONRegExpExtendedLegacy {
247
197
  * @category BSONType
248
198
  */
249
199
  export declare class BSONSymbol {
250
- _bsontype: 'Symbol';
200
+ get _bsontype(): 'BSONSymbol';
251
201
  value: string;
252
202
  /**
253
203
  * @param value - the string representing the symbol.
@@ -267,6 +217,34 @@ export declare interface BSONSymbolExtended {
267
217
  $symbol: string;
268
218
  }
269
219
 
220
+ /** @public */
221
+ export declare const BSONType: Readonly<{
222
+ readonly double: 1;
223
+ readonly string: 2;
224
+ readonly object: 3;
225
+ readonly array: 4;
226
+ readonly binData: 5;
227
+ readonly undefined: 6;
228
+ readonly objectId: 7;
229
+ readonly bool: 8;
230
+ readonly date: 9;
231
+ readonly null: 10;
232
+ readonly regex: 11;
233
+ readonly dbPointer: 12;
234
+ readonly javascript: 13;
235
+ readonly symbol: 14;
236
+ readonly javascriptWithScope: 15;
237
+ readonly int: 16;
238
+ readonly timestamp: 17;
239
+ readonly long: 18;
240
+ readonly decimal: 19;
241
+ readonly minKey: -1;
242
+ readonly maxKey: 127;
243
+ }>;
244
+
245
+ /** @public */
246
+ export declare type BSONType = typeof BSONType[keyof typeof BSONType];
247
+
270
248
  /** @public */
271
249
  export declare class BSONTypeError extends TypeError {
272
250
  constructor(message: string);
@@ -291,16 +269,16 @@ export declare type CalculateObjectSizeOptions = Pick<SerializeOptions, 'seriali
291
269
  * @category BSONType
292
270
  */
293
271
  export declare class Code {
294
- _bsontype: 'Code';
295
- code: string | Function;
296
- scope?: Document;
272
+ get _bsontype(): 'Code';
273
+ code: string;
274
+ scope: Document | null;
297
275
  /**
298
276
  * @param code - a string or function.
299
277
  * @param scope - an optional scope for the function.
300
278
  */
301
- constructor(code: string | Function, scope?: Document);
279
+ constructor(code: string | Function, scope?: Document | null);
302
280
  toJSON(): {
303
- code: string | Function;
281
+ code: string;
304
282
  scope?: Document;
305
283
  };
306
284
  /* Excluded from this release type: toExtendedJSON */
@@ -310,7 +288,7 @@ export declare class Code {
310
288
 
311
289
  /** @public */
312
290
  export declare interface CodeExtended {
313
- $code: string | Function;
291
+ $code: string;
314
292
  $scope?: Document;
315
293
  }
316
294
 
@@ -320,7 +298,7 @@ export declare interface CodeExtended {
320
298
  * @category BSONType
321
299
  */
322
300
  export declare class DBRef {
323
- _bsontype: 'DBRef';
301
+ get _bsontype(): 'DBRef';
324
302
  collection: string;
325
303
  oid: ObjectId;
326
304
  db?: string;
@@ -352,13 +330,13 @@ export declare interface DBRefLike {
352
330
  * @category BSONType
353
331
  */
354
332
  export declare class Decimal128 {
355
- _bsontype: 'Decimal128';
356
- readonly bytes: Buffer;
333
+ get _bsontype(): 'Decimal128';
334
+ readonly bytes: Uint8Array;
357
335
  /**
358
336
  * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
359
337
  * or a string representation as returned by .toString()
360
338
  */
361
- constructor(bytes: Buffer | string);
339
+ constructor(bytes: Uint8Array | string);
362
340
  /**
363
341
  * Create a Decimal128 instance from a string representation
364
342
  *
@@ -385,20 +363,10 @@ export declare interface Decimal128Extended {
385
363
  * @returns returns the deserialized Javascript Object.
386
364
  * @public
387
365
  */
388
- export declare function deserialize(buffer: Buffer | ArrayBufferView | ArrayBuffer, options?: DeserializeOptions): Document;
366
+ export declare function deserialize(buffer: Uint8Array, options?: DeserializeOptions): Document;
389
367
 
390
368
  /** @public */
391
369
  export declare interface DeserializeOptions {
392
- /** evaluate functions in the BSON document scoped to the object deserialized. */
393
- evalFunctions?: boolean;
394
- /** cache evaluated functions for reuse. */
395
- cacheFunctions?: boolean;
396
- /**
397
- * use a crc32 code for caching, otherwise use the string of the function.
398
- * @deprecated this option to use the crc32 function never worked as intended
399
- * due to the fact that the crc32 function itself was never implemented.
400
- * */
401
- cacheFunctionsCrc32?: boolean;
402
370
  /** when deserializing a Long will fit it into a Number if it's smaller than 53 bits */
403
371
  promoteLongs?: boolean;
404
372
  /** when deserializing a Binary will return it as a node.js Buffer instance. */
@@ -446,7 +414,7 @@ export declare interface DeserializeOptions {
446
414
  * @returns next index in the buffer after deserialization **x** numbers of documents.
447
415
  * @public
448
416
  */
449
- export declare function deserializeStream(data: Buffer | ArrayBufferView | ArrayBuffer, startIndex: number, numberOfDocuments: number, documents: Document[], docStartIndex: number, options: DeserializeOptions): number;
417
+ export declare function deserializeStream(data: Uint8Array | ArrayBuffer, startIndex: number, numberOfDocuments: number, documents: Document[], docStartIndex: number, options: DeserializeOptions): number;
450
418
 
451
419
  /** @public */
452
420
  export declare interface Document {
@@ -459,7 +427,7 @@ export declare interface Document {
459
427
  * @category BSONType
460
428
  */
461
429
  export declare class Double {
462
- _bsontype: 'Double';
430
+ get _bsontype(): 'Double';
463
431
  value: number;
464
432
  /**
465
433
  * Create a Double type
@@ -485,83 +453,37 @@ export declare interface DoubleExtended {
485
453
  $numberDouble: string;
486
454
  }
487
455
 
456
+ /** @public */
457
+ export declare const EJSON: {
458
+ parse: typeof parse;
459
+ stringify: typeof stringify;
460
+ serialize: typeof EJSONserialize;
461
+ deserialize: typeof EJSONdeserialize;
462
+ };
463
+
488
464
  /**
489
- * EJSON parse / stringify API
490
- * @public
465
+ * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
466
+ *
467
+ * @param ejson - The Extended JSON object to deserialize
468
+ * @param options - Optional settings passed to the parse method
491
469
  */
492
- export declare namespace EJSON {
493
- export interface Options {
494
- /** Output using the Extended JSON v1 spec */
495
- legacy?: boolean;
496
- /** Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types */
497
- relaxed?: boolean;
498
- /**
499
- * Disable Extended JSON's `relaxed` mode, which attempts to return BSON types where possible, rather than native JS types
500
- * @deprecated Please use the relaxed property instead
501
- */
502
- strict?: boolean;
503
- }
504
- /**
505
- * Parse an Extended JSON string, constructing the JavaScript value or object described by that
506
- * string.
507
- *
508
- * @example
509
- * ```js
510
- * const { EJSON } = require('bson');
511
- * const text = '{ "int32": { "$numberInt": "10" } }';
512
- *
513
- * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
514
- * console.log(EJSON.parse(text, { relaxed: false }));
515
- *
516
- * // prints { int32: 10 }
517
- * console.log(EJSON.parse(text));
518
- * ```
519
- */
520
- export function parse(text: string, options?: EJSON.Options): SerializableTypes;
521
- export type JSONPrimitive = string | number | boolean | null;
522
- export type SerializableTypes = Document | Array<JSONPrimitive | Document> | JSONPrimitive;
523
- /**
524
- * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
525
- * function is specified or optionally including only the specified properties if a replacer array
526
- * is specified.
527
- *
528
- * @param value - The value to convert to extended JSON
529
- * @param replacer - A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
530
- * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
531
- * @param options - Optional settings
532
- *
533
- * @example
534
- * ```js
535
- * const { EJSON } = require('bson');
536
- * const Int32 = require('mongodb').Int32;
537
- * const doc = { int32: new Int32(10) };
538
- *
539
- * // prints '{"int32":{"$numberInt":"10"}}'
540
- * console.log(EJSON.stringify(doc, { relaxed: false }));
541
- *
542
- * // prints '{"int32":10}'
543
- * console.log(EJSON.stringify(doc));
544
- * ```
545
- */
546
- export function stringify(value: SerializableTypes, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSON.Options, space?: string | number, options?: EJSON.Options): string;
547
- /**
548
- * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
549
- *
550
- * @param value - The object to serialize
551
- * @param options - Optional settings passed to the `stringify` function
552
- */
553
- export function serialize(value: SerializableTypes, options?: EJSON.Options): Document;
554
- /**
555
- * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
556
- *
557
- * @param ejson - The Extended JSON object to deserialize
558
- * @param options - Optional settings passed to the parse method
559
- */
560
- export function deserialize(ejson: Document, options?: EJSON.Options): SerializableTypes;
561
- }
470
+ declare function EJSONdeserialize(ejson: Document, options?: EJSONOptions): any;
562
471
 
563
472
  /** @public */
564
- export declare type EJSONOptions = EJSON.Options;
473
+ export declare type EJSONOptions = {
474
+ /** Output using the Extended JSON v1 spec */
475
+ legacy?: boolean;
476
+ /** Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types */
477
+ relaxed?: boolean;
478
+ };
479
+
480
+ /**
481
+ * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
482
+ *
483
+ * @param value - The object to serialize
484
+ * @param options - Optional settings passed to the `stringify` function
485
+ */
486
+ declare function EJSONserialize(value: any, options?: EJSONOptions): Document;
565
487
 
566
488
  /**
567
489
  * A class representation of a BSON Int32 type.
@@ -569,7 +491,7 @@ export declare type EJSONOptions = EJSON.Options;
569
491
  * @category BSONType
570
492
  */
571
493
  export declare class Int32 {
572
- _bsontype: 'Int32';
494
+ get _bsontype(): 'Int32';
573
495
  value: number;
574
496
  /**
575
497
  * Create an Int32 type
@@ -617,9 +539,9 @@ declare const kId: unique symbol;
617
539
  * Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
618
540
  */
619
541
  export declare class Long {
620
- _bsontype: 'Long';
542
+ get _bsontype(): 'Long';
621
543
  /** An indicator used to reliably determine if an object is a Long or not. */
622
- __isLong__: true;
544
+ get __isLong__(): boolean;
623
545
  /**
624
546
  * The high 32 bits as a signed value.
625
547
  */
@@ -919,25 +841,20 @@ export declare interface LongExtended {
919
841
  }
920
842
 
921
843
  /** @public */
922
- export declare type LongWithoutOverrides = new (low: unknown, high?: number, unsigned?: boolean) => {
844
+ export declare type LongWithoutOverrides = new (low: unknown, high?: number | boolean, unsigned?: boolean) => {
923
845
  [P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
924
846
  };
925
847
 
926
848
  /** @public */
927
849
  export declare const LongWithoutOverridesClass: LongWithoutOverrides;
928
850
 
929
- /** @public */
930
- declare let Map_2: MapConstructor;
931
- export { Map_2 as Map }
932
-
933
851
  /**
934
852
  * A class representation of the BSON MaxKey type.
935
853
  * @public
936
854
  * @category BSONType
937
855
  */
938
856
  export declare class MaxKey {
939
- _bsontype: 'MaxKey';
940
- constructor();
857
+ get _bsontype(): 'MaxKey';
941
858
  /* Excluded from this release type: toExtendedJSON */
942
859
  /* Excluded from this release type: fromExtendedJSON */
943
860
  inspect(): string;
@@ -954,8 +871,7 @@ export declare interface MaxKeyExtended {
954
871
  * @category BSONType
955
872
  */
956
873
  export declare class MinKey {
957
- _bsontype: 'MinKey';
958
- constructor();
874
+ get _bsontype(): 'MinKey';
959
875
  /* Excluded from this release type: toExtendedJSON */
960
876
  /* Excluded from this release type: fromExtendedJSON */
961
877
  inspect(): string;
@@ -971,8 +887,8 @@ export declare interface MinKeyExtended {
971
887
  * @public
972
888
  * @category BSONType
973
889
  */
974
- declare class ObjectId {
975
- _bsontype: 'ObjectID';
890
+ export declare class ObjectId {
891
+ get _bsontype(): 'ObjectId';
976
892
  /* Excluded from this release type: index */
977
893
  static cacheHexString: boolean;
978
894
  /* Excluded from this release type: [kId] */
@@ -982,19 +898,13 @@ declare class ObjectId {
982
898
  *
983
899
  * @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
984
900
  */
985
- constructor(inputId?: string | number | ObjectId | ObjectIdLike | Buffer | Uint8Array);
901
+ constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
986
902
  /**
987
903
  * The ObjectId bytes
988
904
  * @readonly
989
905
  */
990
- get id(): Buffer;
991
- set id(value: Buffer);
992
- /**
993
- * The generation time of this ObjectId instance
994
- * @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch
995
- */
996
- get generationTime(): number;
997
- set generationTime(value: number);
906
+ get id(): Uint8Array;
907
+ set id(value: Uint8Array);
998
908
  /** Returns the ObjectId id as a 24 character hex string representation */
999
909
  toHexString(): string;
1000
910
  /* Excluded from this release type: getInc */
@@ -1003,13 +913,12 @@ declare class ObjectId {
1003
913
  *
1004
914
  * @param time - pass in a second based timestamp.
1005
915
  */
1006
- static generate(time?: number): Buffer;
916
+ static generate(time?: number): Uint8Array;
1007
917
  /**
1008
- * Converts the id into a 24 character hex string for printing
1009
- *
1010
- * @param format - The Buffer toString format parameter.
918
+ * Converts the id into a 24 character hex string for printing, unless encoding is provided.
919
+ * @param encoding - hex or base64
1011
920
  */
1012
- toString(format?: string): string;
921
+ toString(encoding?: 'hex' | 'base64'): string;
1013
922
  /** Converts to its JSON the 24 character hex string representation. */
1014
923
  toJSON(): string;
1015
924
  /**
@@ -1038,13 +947,11 @@ declare class ObjectId {
1038
947
  *
1039
948
  * @param id - ObjectId instance to validate.
1040
949
  */
1041
- static isValid(id: string | number | ObjectId | ObjectIdLike | Buffer | Uint8Array): boolean;
950
+ static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
1042
951
  /* Excluded from this release type: toExtendedJSON */
1043
952
  /* Excluded from this release type: fromExtendedJSON */
1044
953
  inspect(): string;
1045
954
  }
1046
- export { ObjectId as ObjectID }
1047
- export { ObjectId }
1048
955
 
1049
956
  /** @public */
1050
957
  export declare interface ObjectIdExtended {
@@ -1053,11 +960,29 @@ export declare interface ObjectIdExtended {
1053
960
 
1054
961
  /** @public */
1055
962
  export declare interface ObjectIdLike {
1056
- id: string | Buffer;
963
+ id: string | Uint8Array;
1057
964
  __id?: string;
1058
965
  toHexString(): string;
1059
966
  }
1060
967
 
968
+ /**
969
+ * Parse an Extended JSON string, constructing the JavaScript value or object described by that
970
+ * string.
971
+ *
972
+ * @example
973
+ * ```js
974
+ * const { EJSON } = require('bson');
975
+ * const text = '{ "int32": { "$numberInt": "10" } }';
976
+ *
977
+ * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
978
+ * console.log(EJSON.parse(text, { relaxed: false }));
979
+ *
980
+ * // prints { int32: 10 }
981
+ * console.log(EJSON.parse(text));
982
+ * ```
983
+ */
984
+ declare function parse(text: string, options?: EJSONOptions): any;
985
+
1061
986
  /**
1062
987
  * Serialize a Javascript object.
1063
988
  *
@@ -1065,7 +990,7 @@ export declare interface ObjectIdLike {
1065
990
  * @returns Buffer object containing the serialized object.
1066
991
  * @public
1067
992
  */
1068
- export declare function serialize(object: Document, options?: SerializeOptions): Buffer;
993
+ export declare function serialize(object: Document, options?: SerializeOptions): Uint8Array;
1069
994
 
1070
995
  /** @public */
1071
996
  export declare interface SerializeOptions {
@@ -1089,7 +1014,7 @@ export declare interface SerializeOptions {
1089
1014
  * @returns the index pointing to the last written byte in the buffer.
1090
1015
  * @public
1091
1016
  */
1092
- export declare function serializeWithBufferAndIndex(object: Document, finalBuffer: Buffer, options?: SerializeOptions): number;
1017
+ export declare function serializeWithBufferAndIndex(object: Document, finalBuffer: Uint8Array, options?: SerializeOptions): number;
1093
1018
 
1094
1019
  /**
1095
1020
  * Sets the size of the internal serialization buffer.
@@ -1099,15 +1024,44 @@ export declare function serializeWithBufferAndIndex(object: Document, finalBuffe
1099
1024
  */
1100
1025
  export declare function setInternalBufferSize(size: number): void;
1101
1026
 
1027
+ /**
1028
+ * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
1029
+ * function is specified or optionally including only the specified properties if a replacer array
1030
+ * is specified.
1031
+ *
1032
+ * @param value - The value to convert to extended JSON
1033
+ * @param replacer - A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
1034
+ * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
1035
+ * @param options - Optional settings
1036
+ *
1037
+ * @example
1038
+ * ```js
1039
+ * const { EJSON } = require('bson');
1040
+ * const Int32 = require('mongodb').Int32;
1041
+ * const doc = { int32: new Int32(10) };
1042
+ *
1043
+ * // prints '{"int32":{"$numberInt":"10"}}'
1044
+ * console.log(EJSON.stringify(doc, { relaxed: false }));
1045
+ *
1046
+ * // prints '{"int32":10}'
1047
+ * console.log(EJSON.stringify(doc));
1048
+ * ```
1049
+ */
1050
+ declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONOptions, space?: string | number, options?: EJSONOptions): string;
1051
+
1102
1052
  /**
1103
1053
  * @public
1104
1054
  * @category BSONType
1105
1055
  * */
1106
1056
  export declare class Timestamp extends LongWithoutOverridesClass {
1107
- _bsontype: 'Timestamp';
1057
+ get _bsontype(): 'Timestamp';
1108
1058
  static readonly MAX_VALUE: Long;
1109
1059
  /**
1110
- * @param low - A 64-bit Long representing the Timestamp.
1060
+ * @param int - A 64-bit bigint representing the Timestamp.
1061
+ */
1062
+ constructor(int: bigint);
1063
+ /**
1064
+ * @param long - A 64-bit Long representing the Timestamp.
1111
1065
  */
1112
1066
  constructor(long: Long);
1113
1067
  /**
@@ -1117,12 +1071,6 @@ export declare class Timestamp extends LongWithoutOverridesClass {
1117
1071
  t: number;
1118
1072
  i: number;
1119
1073
  });
1120
- /**
1121
- * @param low - the low (signed) 32 bits of the Timestamp.
1122
- * @param high - the high (signed) 32 bits of the Timestamp.
1123
- * @deprecated Please use `Timestamp({ t: high, i: low })` or `Timestamp(Long(low, high))` instead.
1124
- */
1125
- constructor(low: number, high: number);
1126
1074
  toJSON(): {
1127
1075
  $timestamp: string;
1128
1076
  };
@@ -1172,13 +1120,13 @@ export declare class UUID extends Binary {
1172
1120
  *
1173
1121
  * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
1174
1122
  */
1175
- constructor(input?: string | Buffer | UUID);
1123
+ constructor(input?: string | Uint8Array | UUID);
1176
1124
  /**
1177
1125
  * The UUID bytes
1178
1126
  * @readonly
1179
1127
  */
1180
- get id(): Buffer;
1181
- set id(value: Buffer);
1128
+ get id(): Uint8Array;
1129
+ set id(value: Uint8Array);
1182
1130
  /**
1183
1131
  * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
1184
1132
  * @param includeDashes - should the string exclude dash-separators.
@@ -1187,7 +1135,7 @@ export declare class UUID extends Binary {
1187
1135
  /**
1188
1136
  * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
1189
1137
  */
1190
- toString(encoding?: string): string;
1138
+ toString(encoding?: 'hex' | 'base64'): string;
1191
1139
  /**
1192
1140
  * Converts the id into its JSON string representation.
1193
1141
  * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
@@ -1198,7 +1146,7 @@ export declare class UUID extends Binary {
1198
1146
  *
1199
1147
  * @param otherId - UUID instance to compare against.
1200
1148
  */
1201
- equals(otherId: string | Buffer | UUID): boolean;
1149
+ equals(otherId: string | Uint8Array | UUID): boolean;
1202
1150
  /**
1203
1151
  * Creates a Binary instance from the current UUID.
1204
1152
  */
@@ -1206,12 +1154,12 @@ export declare class UUID extends Binary {
1206
1154
  /**
1207
1155
  * Generates a populated buffer containing a v4 uuid
1208
1156
  */
1209
- static generate(): Buffer;
1157
+ static generate(): Uint8Array;
1210
1158
  /**
1211
1159
  * Checks if a value is a valid bson UUID
1212
1160
  * @param input - UUID, string or Buffer to validate.
1213
1161
  */
1214
- static isValid(input: string | Buffer | UUID): boolean;
1162
+ static isValid(input: string | Uint8Array | UUID): boolean;
1215
1163
  /**
1216
1164
  * Creates an UUID from a hex string representation of an UUID.
1217
1165
  * @param hexString - 32 or 36 character hex string (dashes excluded/included).