bson 4.6.5 → 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 +208 -267
- 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 -61
- package/src/binary.ts +235 -37
- package/src/bson.ts +43 -129
- 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 +47 -113
- 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 -7471
- package/dist/bson.browser.esm.js.map +0 -1
- package/dist/bson.browser.umd.js +0 -7538
- package/dist/bson.browser.umd.js.map +0 -1
- package/dist/bson.bundle.js +0 -7537
- package/dist/bson.bundle.js.map +0 -1
- package/dist/bson.esm.js +0 -5437
- package/dist/bson.esm.js.map +0 -1
- package/lib/binary.js +0 -247
- package/lib/binary.js.map +0 -1
- package/lib/bson.js +0 -265
- 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 -659
- 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.js +0 -179
- package/lib/uuid.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/src/uuid.ts +0 -209
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
|
|
@@ -597,8 +519,6 @@ export declare interface Int32Extended {
|
|
|
597
519
|
|
|
598
520
|
declare const kId: unique symbol;
|
|
599
521
|
|
|
600
|
-
declare const kId_2: unique symbol;
|
|
601
|
-
|
|
602
522
|
/**
|
|
603
523
|
* A class representing a 64-bit integer
|
|
604
524
|
* @public
|
|
@@ -619,9 +539,9 @@ declare const kId_2: unique symbol;
|
|
|
619
539
|
* Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
|
|
620
540
|
*/
|
|
621
541
|
export declare class Long {
|
|
622
|
-
_bsontype: 'Long';
|
|
542
|
+
get _bsontype(): 'Long';
|
|
623
543
|
/** An indicator used to reliably determine if an object is a Long or not. */
|
|
624
|
-
__isLong__:
|
|
544
|
+
get __isLong__(): boolean;
|
|
625
545
|
/**
|
|
626
546
|
* The high 32 bits as a signed value.
|
|
627
547
|
*/
|
|
@@ -921,25 +841,20 @@ export declare interface LongExtended {
|
|
|
921
841
|
}
|
|
922
842
|
|
|
923
843
|
/** @public */
|
|
924
|
-
export declare type LongWithoutOverrides = new (low: unknown, high?: number, unsigned?: boolean) => {
|
|
844
|
+
export declare type LongWithoutOverrides = new (low: unknown, high?: number | boolean, unsigned?: boolean) => {
|
|
925
845
|
[P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
|
|
926
846
|
};
|
|
927
847
|
|
|
928
848
|
/** @public */
|
|
929
849
|
export declare const LongWithoutOverridesClass: LongWithoutOverrides;
|
|
930
850
|
|
|
931
|
-
/** @public */
|
|
932
|
-
declare let Map_2: MapConstructor;
|
|
933
|
-
export { Map_2 as Map }
|
|
934
|
-
|
|
935
851
|
/**
|
|
936
852
|
* A class representation of the BSON MaxKey type.
|
|
937
853
|
* @public
|
|
938
854
|
* @category BSONType
|
|
939
855
|
*/
|
|
940
856
|
export declare class MaxKey {
|
|
941
|
-
_bsontype: 'MaxKey';
|
|
942
|
-
constructor();
|
|
857
|
+
get _bsontype(): 'MaxKey';
|
|
943
858
|
/* Excluded from this release type: toExtendedJSON */
|
|
944
859
|
/* Excluded from this release type: fromExtendedJSON */
|
|
945
860
|
inspect(): string;
|
|
@@ -956,8 +871,7 @@ export declare interface MaxKeyExtended {
|
|
|
956
871
|
* @category BSONType
|
|
957
872
|
*/
|
|
958
873
|
export declare class MinKey {
|
|
959
|
-
_bsontype: 'MinKey';
|
|
960
|
-
constructor();
|
|
874
|
+
get _bsontype(): 'MinKey';
|
|
961
875
|
/* Excluded from this release type: toExtendedJSON */
|
|
962
876
|
/* Excluded from this release type: fromExtendedJSON */
|
|
963
877
|
inspect(): string;
|
|
@@ -973,8 +887,8 @@ export declare interface MinKeyExtended {
|
|
|
973
887
|
* @public
|
|
974
888
|
* @category BSONType
|
|
975
889
|
*/
|
|
976
|
-
declare class ObjectId {
|
|
977
|
-
_bsontype: '
|
|
890
|
+
export declare class ObjectId {
|
|
891
|
+
get _bsontype(): 'ObjectId';
|
|
978
892
|
/* Excluded from this release type: index */
|
|
979
893
|
static cacheHexString: boolean;
|
|
980
894
|
/* Excluded from this release type: [kId] */
|
|
@@ -984,19 +898,13 @@ declare class ObjectId {
|
|
|
984
898
|
*
|
|
985
899
|
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
|
|
986
900
|
*/
|
|
987
|
-
constructor(inputId?: string | number | ObjectId | ObjectIdLike |
|
|
901
|
+
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
|
|
988
902
|
/**
|
|
989
903
|
* The ObjectId bytes
|
|
990
904
|
* @readonly
|
|
991
905
|
*/
|
|
992
|
-
get id():
|
|
993
|
-
set id(value:
|
|
994
|
-
/**
|
|
995
|
-
* The generation time of this ObjectId instance
|
|
996
|
-
* @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch
|
|
997
|
-
*/
|
|
998
|
-
get generationTime(): number;
|
|
999
|
-
set generationTime(value: number);
|
|
906
|
+
get id(): Uint8Array;
|
|
907
|
+
set id(value: Uint8Array);
|
|
1000
908
|
/** Returns the ObjectId id as a 24 character hex string representation */
|
|
1001
909
|
toHexString(): string;
|
|
1002
910
|
/* Excluded from this release type: getInc */
|
|
@@ -1005,13 +913,12 @@ declare class ObjectId {
|
|
|
1005
913
|
*
|
|
1006
914
|
* @param time - pass in a second based timestamp.
|
|
1007
915
|
*/
|
|
1008
|
-
static generate(time?: number):
|
|
916
|
+
static generate(time?: number): Uint8Array;
|
|
1009
917
|
/**
|
|
1010
|
-
* Converts the id into a 24 character hex string for printing
|
|
1011
|
-
*
|
|
1012
|
-
* @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
|
|
1013
920
|
*/
|
|
1014
|
-
toString(
|
|
921
|
+
toString(encoding?: 'hex' | 'base64'): string;
|
|
1015
922
|
/** Converts to its JSON the 24 character hex string representation. */
|
|
1016
923
|
toJSON(): string;
|
|
1017
924
|
/**
|
|
@@ -1040,13 +947,11 @@ declare class ObjectId {
|
|
|
1040
947
|
*
|
|
1041
948
|
* @param id - ObjectId instance to validate.
|
|
1042
949
|
*/
|
|
1043
|
-
static isValid(id: string | number | ObjectId | ObjectIdLike |
|
|
950
|
+
static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
|
|
1044
951
|
/* Excluded from this release type: toExtendedJSON */
|
|
1045
952
|
/* Excluded from this release type: fromExtendedJSON */
|
|
1046
953
|
inspect(): string;
|
|
1047
954
|
}
|
|
1048
|
-
export { ObjectId as ObjectID }
|
|
1049
|
-
export { ObjectId }
|
|
1050
955
|
|
|
1051
956
|
/** @public */
|
|
1052
957
|
export declare interface ObjectIdExtended {
|
|
@@ -1055,11 +960,29 @@ export declare interface ObjectIdExtended {
|
|
|
1055
960
|
|
|
1056
961
|
/** @public */
|
|
1057
962
|
export declare interface ObjectIdLike {
|
|
1058
|
-
id: string |
|
|
963
|
+
id: string | Uint8Array;
|
|
1059
964
|
__id?: string;
|
|
1060
965
|
toHexString(): string;
|
|
1061
966
|
}
|
|
1062
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
|
+
|
|
1063
986
|
/**
|
|
1064
987
|
* Serialize a Javascript object.
|
|
1065
988
|
*
|
|
@@ -1067,7 +990,7 @@ export declare interface ObjectIdLike {
|
|
|
1067
990
|
* @returns Buffer object containing the serialized object.
|
|
1068
991
|
* @public
|
|
1069
992
|
*/
|
|
1070
|
-
export declare function serialize(object: Document, options?: SerializeOptions):
|
|
993
|
+
export declare function serialize(object: Document, options?: SerializeOptions): Uint8Array;
|
|
1071
994
|
|
|
1072
995
|
/** @public */
|
|
1073
996
|
export declare interface SerializeOptions {
|
|
@@ -1091,7 +1014,7 @@ export declare interface SerializeOptions {
|
|
|
1091
1014
|
* @returns the index pointing to the last written byte in the buffer.
|
|
1092
1015
|
* @public
|
|
1093
1016
|
*/
|
|
1094
|
-
export declare function serializeWithBufferAndIndex(object: Document, finalBuffer:
|
|
1017
|
+
export declare function serializeWithBufferAndIndex(object: Document, finalBuffer: Uint8Array, options?: SerializeOptions): number;
|
|
1095
1018
|
|
|
1096
1019
|
/**
|
|
1097
1020
|
* Sets the size of the internal serialization buffer.
|
|
@@ -1101,15 +1024,44 @@ export declare function serializeWithBufferAndIndex(object: Document, finalBuffe
|
|
|
1101
1024
|
*/
|
|
1102
1025
|
export declare function setInternalBufferSize(size: number): void;
|
|
1103
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
|
+
|
|
1104
1052
|
/**
|
|
1105
1053
|
* @public
|
|
1106
1054
|
* @category BSONType
|
|
1107
1055
|
* */
|
|
1108
1056
|
export declare class Timestamp extends LongWithoutOverridesClass {
|
|
1109
|
-
_bsontype: 'Timestamp';
|
|
1057
|
+
get _bsontype(): 'Timestamp';
|
|
1110
1058
|
static readonly MAX_VALUE: Long;
|
|
1111
1059
|
/**
|
|
1112
|
-
* @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.
|
|
1113
1065
|
*/
|
|
1114
1066
|
constructor(long: Long);
|
|
1115
1067
|
/**
|
|
@@ -1119,12 +1071,6 @@ export declare class Timestamp extends LongWithoutOverridesClass {
|
|
|
1119
1071
|
t: number;
|
|
1120
1072
|
i: number;
|
|
1121
1073
|
});
|
|
1122
|
-
/**
|
|
1123
|
-
* @param low - the low (signed) 32 bits of the Timestamp.
|
|
1124
|
-
* @param high - the high (signed) 32 bits of the Timestamp.
|
|
1125
|
-
* @deprecated Please use `Timestamp({ t: high, i: low })` or `Timestamp(Long(low, high))` instead.
|
|
1126
|
-
*/
|
|
1127
|
-
constructor(low: number, high: number);
|
|
1128
1074
|
toJSON(): {
|
|
1129
1075
|
$timestamp: string;
|
|
1130
1076
|
};
|
|
@@ -1166,26 +1112,21 @@ export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromE
|
|
|
1166
1112
|
* A class representation of the BSON UUID type.
|
|
1167
1113
|
* @public
|
|
1168
1114
|
*/
|
|
1169
|
-
export declare class UUID {
|
|
1170
|
-
_bsontype: 'UUID';
|
|
1115
|
+
export declare class UUID extends Binary {
|
|
1171
1116
|
static cacheHexString: boolean;
|
|
1172
|
-
/* Excluded from this release type: [kId] */
|
|
1173
1117
|
/* Excluded from this release type: __id */
|
|
1174
1118
|
/**
|
|
1175
1119
|
* Create an UUID type
|
|
1176
1120
|
*
|
|
1177
1121
|
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
|
|
1178
1122
|
*/
|
|
1179
|
-
constructor(input?: string |
|
|
1123
|
+
constructor(input?: string | Uint8Array | UUID);
|
|
1180
1124
|
/**
|
|
1181
1125
|
* The UUID bytes
|
|
1182
1126
|
* @readonly
|
|
1183
1127
|
*/
|
|
1184
|
-
get id():
|
|
1185
|
-
set id(value:
|
|
1186
|
-
/**
|
|
1187
|
-
* Generate a 16 byte uuid v4 buffer used in UUIDs
|
|
1188
|
-
*/
|
|
1128
|
+
get id(): Uint8Array;
|
|
1129
|
+
set id(value: Uint8Array);
|
|
1189
1130
|
/**
|
|
1190
1131
|
* Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
|
|
1191
1132
|
* @param includeDashes - should the string exclude dash-separators.
|
|
@@ -1194,7 +1135,7 @@ export declare class UUID {
|
|
|
1194
1135
|
/**
|
|
1195
1136
|
* Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
|
|
1196
1137
|
*/
|
|
1197
|
-
toString(encoding?:
|
|
1138
|
+
toString(encoding?: 'hex' | 'base64'): string;
|
|
1198
1139
|
/**
|
|
1199
1140
|
* Converts the id into its JSON string representation.
|
|
1200
1141
|
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
@@ -1205,7 +1146,7 @@ export declare class UUID {
|
|
|
1205
1146
|
*
|
|
1206
1147
|
* @param otherId - UUID instance to compare against.
|
|
1207
1148
|
*/
|
|
1208
|
-
equals(otherId: string |
|
|
1149
|
+
equals(otherId: string | Uint8Array | UUID): boolean;
|
|
1209
1150
|
/**
|
|
1210
1151
|
* Creates a Binary instance from the current UUID.
|
|
1211
1152
|
*/
|
|
@@ -1213,12 +1154,12 @@ export declare class UUID {
|
|
|
1213
1154
|
/**
|
|
1214
1155
|
* Generates a populated buffer containing a v4 uuid
|
|
1215
1156
|
*/
|
|
1216
|
-
static generate():
|
|
1157
|
+
static generate(): Uint8Array;
|
|
1217
1158
|
/**
|
|
1218
1159
|
* Checks if a value is a valid bson UUID
|
|
1219
1160
|
* @param input - UUID, string or Buffer to validate.
|
|
1220
1161
|
*/
|
|
1221
|
-
static isValid(input: string |
|
|
1162
|
+
static isValid(input: string | Uint8Array | UUID): boolean;
|
|
1222
1163
|
/**
|
|
1223
1164
|
* Creates an UUID from a hex string representation of an UUID.
|
|
1224
1165
|
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|