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.
- package/bson.d.ts +207 -259
- package/lib/bson.bundle.js +4033 -0
- package/lib/bson.bundle.js.map +1 -0
- package/lib/bson.cjs +4028 -0
- package/lib/bson.cjs.map +1 -0
- package/lib/bson.mjs +4002 -0
- package/lib/bson.mjs.map +1 -0
- package/package.json +49 -62
- package/src/binary.ts +63 -52
- package/src/bson.ts +27 -108
- package/src/code.ts +24 -14
- package/src/constants.ts +28 -0
- package/src/db_ref.ts +13 -8
- package/src/decimal128.ts +31 -25
- package/src/double.ts +7 -5
- package/src/error.ts +0 -2
- package/src/extended_json.ts +148 -148
- package/src/index.ts +19 -0
- package/src/int_32.ts +7 -5
- package/src/long.ts +16 -16
- package/src/max_key.ts +6 -6
- package/src/min_key.ts +6 -6
- package/src/objectid.ts +41 -74
- package/src/parser/calculate_size.ts +39 -63
- package/src/parser/deserializer.ts +41 -112
- package/src/parser/serializer.ts +234 -341
- package/src/parser/utils.ts +1 -99
- package/src/regexp.ts +16 -5
- package/src/symbol.ts +7 -5
- package/src/timestamp.ts +62 -27
- package/src/utils/byte_utils.ts +61 -0
- package/src/utils/node_byte_utils.ts +141 -0
- package/src/utils/web_byte_utils.ts +190 -0
- package/src/uuid_utils.ts +15 -15
- package/bower.json +0 -26
- package/dist/bson.browser.esm.js +0 -7470
- package/dist/bson.browser.esm.js.map +0 -1
- package/dist/bson.browser.umd.js +0 -7537
- package/dist/bson.browser.umd.js.map +0 -1
- package/dist/bson.bundle.js +0 -7536
- package/dist/bson.bundle.js.map +0 -1
- package/dist/bson.esm.js +0 -5436
- package/dist/bson.esm.js.map +0 -1
- package/lib/binary.js +0 -426
- package/lib/binary.js.map +0 -1
- package/lib/bson.js +0 -251
- package/lib/bson.js.map +0 -1
- package/lib/code.js +0 -46
- package/lib/code.js.map +0 -1
- package/lib/constants.js +0 -82
- package/lib/constants.js.map +0 -1
- package/lib/db_ref.js +0 -97
- package/lib/db_ref.js.map +0 -1
- package/lib/decimal128.js +0 -669
- package/lib/decimal128.js.map +0 -1
- package/lib/double.js +0 -76
- package/lib/double.js.map +0 -1
- package/lib/ensure_buffer.js +0 -25
- package/lib/ensure_buffer.js.map +0 -1
- package/lib/error.js +0 -55
- package/lib/error.js.map +0 -1
- package/lib/extended_json.js +0 -390
- package/lib/extended_json.js.map +0 -1
- package/lib/int_32.js +0 -58
- package/lib/int_32.js.map +0 -1
- package/lib/long.js +0 -900
- package/lib/long.js.map +0 -1
- package/lib/map.js +0 -123
- package/lib/map.js.map +0 -1
- package/lib/max_key.js +0 -33
- package/lib/max_key.js.map +0 -1
- package/lib/min_key.js +0 -33
- package/lib/min_key.js.map +0 -1
- package/lib/objectid.js +0 -299
- package/lib/objectid.js.map +0 -1
- package/lib/parser/calculate_size.js +0 -194
- package/lib/parser/calculate_size.js.map +0 -1
- package/lib/parser/deserializer.js +0 -665
- package/lib/parser/deserializer.js.map +0 -1
- package/lib/parser/serializer.js +0 -867
- package/lib/parser/serializer.js.map +0 -1
- package/lib/parser/utils.js +0 -115
- package/lib/parser/utils.js.map +0 -1
- package/lib/regexp.js +0 -74
- package/lib/regexp.js.map +0 -1
- package/lib/symbol.js +0 -48
- package/lib/symbol.js.map +0 -1
- package/lib/timestamp.js +0 -102
- package/lib/timestamp.js.map +0 -1
- package/lib/utils/global.js +0 -18
- package/lib/utils/global.js.map +0 -1
- package/lib/uuid_utils.js +0 -35
- package/lib/uuid_utils.js.map +0 -1
- package/lib/validate_utf8.js +0 -47
- package/lib/validate_utf8.js.map +0 -1
- package/src/ensure_buffer.ts +0 -27
- package/src/map.ts +0 -119
- 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:
|
|
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 |
|
|
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(
|
|
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 |
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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: '
|
|
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
|
|
296
|
-
scope
|
|
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
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
*
|
|
490
|
-
*
|
|
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
|
-
|
|
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 =
|
|
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__:
|
|
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: '
|
|
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 |
|
|
901
|
+
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
|
|
986
902
|
/**
|
|
987
903
|
* The ObjectId bytes
|
|
988
904
|
* @readonly
|
|
989
905
|
*/
|
|
990
|
-
get id():
|
|
991
|
-
set id(value:
|
|
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):
|
|
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(
|
|
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 |
|
|
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 |
|
|
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):
|
|
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:
|
|
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
|
|
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 |
|
|
1123
|
+
constructor(input?: string | Uint8Array | UUID);
|
|
1176
1124
|
/**
|
|
1177
1125
|
* The UUID bytes
|
|
1178
1126
|
* @readonly
|
|
1179
1127
|
*/
|
|
1180
|
-
get id():
|
|
1181
|
-
set id(value:
|
|
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?:
|
|
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 |
|
|
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():
|
|
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 |
|
|
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).
|