UNPKG

42.4 kBTypeScriptView Raw
1import { Buffer } from 'buffer';
2/**
3 * A class representation of the BSON Binary type.
4 * @public
5 */
6export declare class Binary {
7 _bsontype: 'Binary';
8 /* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
9 /** Initial buffer default size */
10 static readonly BUFFER_SIZE = 256;
11 /** Default BSON type */
12 static readonly SUBTYPE_DEFAULT = 0;
13 /** Function BSON type */
14 static readonly SUBTYPE_FUNCTION = 1;
15 /** Byte Array BSON type */
16 static readonly SUBTYPE_BYTE_ARRAY = 2;
17 /** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
18 static readonly SUBTYPE_UUID_OLD = 3;
19 /** UUID BSON type */
20 static readonly SUBTYPE_UUID = 4;
21 /** MD5 BSON type */
22 static readonly SUBTYPE_MD5 = 5;
23 /** Encrypted BSON type */
24 static readonly SUBTYPE_ENCRYPTED = 6;
25 /** Column BSON type */
26 static readonly SUBTYPE_COLUMN = 7;
27 /** User BSON type */
28 static readonly SUBTYPE_USER_DEFINED = 128;
29 buffer: Buffer;
30 sub_type: number;
31 position: number;
32 /**
33 * @param buffer - a buffer object containing the binary data.
34 * @param subType - the option binary type.
35 */
36 constructor(buffer?: string | BinarySequence, subType?: number);
37 /**
38 * Updates this binary with byte_value.
39 *
40 * @param byteValue - a single byte we wish to write.
41 */
42 put(byteValue: string | number | Uint8Array | Buffer | number[]): void;
43 /**
44 * Writes a buffer or string to the binary.
45 *
46 * @param sequence - a string or buffer to be written to the Binary BSON object.
47 * @param offset - specify the binary of where to write the content.
48 */
49 write(sequence: string | BinarySequence, offset: number): void;
50 /**
51 * Reads **length** bytes starting at **position**.
52 *
53 * @param position - read from the given position in the Binary.
54 * @param length - the number of bytes to read.
55 */
56 read(position: number, length: number): BinarySequence;
57 /**
58 * Returns the value of this binary as a string.
59 * @param asRaw - Will skip converting to a string
60 * @remarks
61 * This is handy when calling this function conditionally for some key value pairs and not others
62 */
63 value(asRaw?: boolean): string | BinarySequence;
64 /** the length of the binary sequence */
65 length(): number;
66 toJSON(): string;
67 toString(format?: string): string;
68 /* Excluded from this release type: toExtendedJSON */
69 toUUID(): UUID;
70 /* Excluded from this release type: fromExtendedJSON */
71 inspect(): string;
72}
73/** @public */
74export declare interface BinaryExtended {
75 $binary: {
76 subType: string;
77 base64: string;
78 };
79}
80/** @public */
81export declare interface BinaryExtendedLegacy {
82 $type: string;
83 $binary: string;
84}
85/** @public */
86export declare type BinarySequence = Uint8Array | Buffer | number[];
87/**
88 * BSON default export
89 * @deprecated Please use named exports
90 * @privateRemarks
91 * We want to someday deprecate the default export,
92 * so none of the new TS types are being exported on the default
93 * @public
94 */
95declare const BSON: {
96 Binary: typeof Binary;
97 Code: typeof Code;
98 DBRef: typeof DBRef;
99 Decimal128: typeof Decimal128;
100 Double: typeof Double;
101 Int32: typeof Int32;
102 Long: typeof Long;
103 UUID: typeof UUID;
104 Map: MapConstructor;
105 MaxKey: typeof MaxKey;
106 MinKey: typeof MinKey;
107 ObjectId: typeof ObjectId;
108 ObjectID: typeof ObjectId;
109 BSONRegExp: typeof BSONRegExp;
110 BSONSymbol: typeof BSONSymbol;
111 Timestamp: typeof Timestamp;
112 EJSON: typeof EJSON;
113 setInternalBufferSize: typeof setInternalBufferSize;
114 serialize: typeof serialize;
115 serializeWithBufferAndIndex: typeof serializeWithBufferAndIndex;
116 deserialize: typeof deserialize;
117 calculateObjectSize: typeof calculateObjectSize;
118 deserializeStream: typeof deserializeStream;
119 BSONError: typeof BSONError;
120 BSONTypeError: typeof BSONTypeError;
121};
122export default BSON;
123/* Excluded from this release type: BSON_BINARY_SUBTYPE_BYTE_ARRAY */
124/* Excluded from this release type: BSON_BINARY_SUBTYPE_COLUMN */
125/* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
126/* Excluded from this release type: BSON_BINARY_SUBTYPE_ENCRYPTED */
127/* Excluded from this release type: BSON_BINARY_SUBTYPE_FUNCTION */
128/* Excluded from this release type: BSON_BINARY_SUBTYPE_MD5 */
129/* Excluded from this release type: BSON_BINARY_SUBTYPE_USER_DEFINED */
130/* Excluded from this release type: BSON_BINARY_SUBTYPE_UUID */
131/* Excluded from this release type: BSON_BINARY_SUBTYPE_UUID_NEW */
132/* Excluded from this release type: BSON_DATA_ARRAY */
133/* Excluded from this release type: BSON_DATA_BINARY */
134/* Excluded from this release type: BSON_DATA_BOOLEAN */
135/* Excluded from this release type: BSON_DATA_CODE */
136/* Excluded from this release type: BSON_DATA_CODE_W_SCOPE */
137/* Excluded from this release type: BSON_DATA_DATE */
138/* Excluded from this release type: BSON_DATA_DBPOINTER */
139/* Excluded from this release type: BSON_DATA_DECIMAL128 */
140/* Excluded from this release type: BSON_DATA_INT */
141/* Excluded from this release type: BSON_DATA_LONG */
142/* Excluded from this release type: BSON_DATA_MAX_KEY */
143/* Excluded from this release type: BSON_DATA_MIN_KEY */
144/* Excluded from this release type: BSON_DATA_NULL */
145/* Excluded from this release type: BSON_DATA_NUMBER */
146/* Excluded from this release type: BSON_DATA_OBJECT */
147/* Excluded from this release type: BSON_DATA_OID */
148/* Excluded from this release type: BSON_DATA_REGEXP */
149/* Excluded from this release type: BSON_DATA_STRING */
150/* Excluded from this release type: BSON_DATA_SYMBOL */
151/* Excluded from this release type: BSON_DATA_TIMESTAMP */
152/* Excluded from this release type: BSON_DATA_UNDEFINED */
153/* Excluded from this release type: BSON_INT32_MAX */
154/* Excluded from this release type: BSON_INT32_MIN */
155/* Excluded from this release type: BSON_INT64_MAX */
156/* Excluded from this release type: BSON_INT64_MIN */
157/** @public */
158export declare class BSONError extends Error {
159 readonly name: string;
160}
161/**
162 * A class representation of the BSON RegExp type.
163 * @public
164 */
165export declare class BSONRegExp {
166 _bsontype: 'BSONRegExp';
167 pattern: string;
168 options: string;
169 /**
170 * @param pattern - The regular expression pattern to match
171 * @param options - The regular expression options
172 */
173 constructor(pattern: string, options?: string);
174 static parseOptions(options?: string): string;
175}
176/** @public */
177export declare interface BSONRegExpExtended {
178 $regularExpression: {
179 pattern: string;
180 options: string;
181 };
182}
183/** @public */
184export declare interface BSONRegExpExtendedLegacy {
185 $regex: string | BSONRegExp;
186 $options: string;
187}
188/**
189 * A class representation of the BSON Symbol type.
190 * @public
191 */
192export declare class BSONSymbol {
193 _bsontype: 'Symbol';
194 value: string;
195 /**
196 * @param value - the string representing the symbol.
197 */
198 constructor(value: string);
199 /** Access the wrapped string value. */
200 valueOf(): string;
201 toString(): string;
202 /* Excluded from this release type: inspect */
203 toJSON(): string;
204}
205/** @public */
206export declare interface BSONSymbolExtended {
207 $symbol: string;
208}
209/** @public */
210export declare class BSONTypeError extends TypeError {
211 readonly name: string;
212}
213/**
214 * Calculate the bson size for a passed in Javascript object.
215 *
216 * @param object - the Javascript object to calculate the BSON byte size for
217 * @returns size of BSON object in bytes
218 * @public
219 */
220export declare function calculateObjectSize(object: Document, options?: CalculateObjectSizeOptions): number;
221/** @public */
222export declare type CalculateObjectSizeOptions = Pick<SerializeOptions, 'serializeFunctions' | 'ignoreUndefined'>;
223/**
224 * A class representation of the BSON Code type.
225 * @public
226 */
227export declare class Code {
228 _bsontype: 'Code';
229 code: string | Function;
230 scope?: Document;
231 /**
232 * @param code - a string or function.
233 * @param scope - an optional scope for the function.
234 */
235 constructor(code: string | Function, scope?: Document);
236 toJSON(): {
237 code: string | Function;
238 scope?: Document;
239 };
240 /* Excluded from this release type: toExtendedJSON */
241 /* Excluded from this release type: fromExtendedJSON */
242 inspect(): string;
243}
244/** @public */
245export declare interface CodeExtended {
246 $code: string | Function;
247 $scope?: Document;
248}
249/**
250 * A class representation of the BSON DBRef type.
251 * @public
252 */
253export declare class DBRef {
254 _bsontype: 'DBRef';
255 collection: string;
256 oid: ObjectId;
257 db?: string;
258 fields: Document;
259 /**
260 * @param collection - the collection name.
261 * @param oid - the reference ObjectId.
262 * @param db - optional db name, if omitted the reference is local to the current db.
263 */
264 constructor(collection: string, oid: ObjectId, db?: string, fields?: Document);
265 /* Excluded from this release type: namespace */
266 /* Excluded from this release type: namespace */
267 toJSON(): DBRefLike & Document;
268 /* Excluded from this release type: toExtendedJSON */
269 /* Excluded from this release type: fromExtendedJSON */
270 inspect(): string;
271}
272/** @public */
273export declare interface DBRefLike {
274 $ref: string;
275 $id: ObjectId;
276 $db?: string;
277}
278/**
279 * A class representation of the BSON Decimal128 type.
280 * @public
281 */
282export declare class Decimal128 {
283 _bsontype: 'Decimal128';
284 readonly bytes: Buffer;
285 /**
286 * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
287 * or a string representation as returned by .toString()
288 */
289 constructor(bytes: Buffer | string);
290 /**
291 * Create a Decimal128 instance from a string representation
292 *
293 * @param representation - a numeric string representation.
294 */
295 static fromString(representation: string): Decimal128;
296 /** Create a string representation of the raw Decimal128 value */
297 toString(): string;
298 toJSON(): Decimal128Extended;
299 /* Excluded from this release type: toExtendedJSON */
300 /* Excluded from this release type: fromExtendedJSON */
301 inspect(): string;
302}
303/** @public */
304export declare interface Decimal128Extended {
305 $numberDecimal: string;
306}
307/**
308 * Deserialize data as BSON.
309 *
310 * @param buffer - the buffer containing the serialized set of BSON documents.
311 * @returns returns the deserialized Javascript Object.
312 * @public
313 */
314export declare function deserialize(buffer: Buffer | ArrayBufferView | ArrayBuffer, options?: DeserializeOptions): Document;
315/** @public */
316export declare interface DeserializeOptions {
317 /** evaluate functions in the BSON document scoped to the object deserialized. */
318 evalFunctions?: boolean;
319 /** cache evaluated functions for reuse. */
320 cacheFunctions?: boolean;
321 /**
322 * use a crc32 code for caching, otherwise use the string of the function.
323 * @deprecated this option to use the crc32 function never worked as intended
324 * due to the fact that the crc32 function itself was never implemented.
325 * */
326 cacheFunctionsCrc32?: boolean;
327 /** when deserializing a Long will fit it into a Number if it's smaller than 53 bits */
328 promoteLongs?: boolean;
329 /** when deserializing a Binary will return it as a node.js Buffer instance. */
330 promoteBuffers?: boolean;
331 /** when deserializing will promote BSON values to their Node.js closest equivalent types. */
332 promoteValues?: boolean;
333 /** allow to specify if there what fields we wish to return as unserialized raw buffer. */
334 fieldsAsRaw?: Document;
335 /** return BSON regular expressions as BSONRegExp instances. */
336 bsonRegExp?: boolean;
337 /** allows the buffer to be larger than the parsed BSON object */
338 allowObjectSmallerThanBufferSize?: boolean;
339 /** Offset into buffer to begin reading document from */
340 index?: number;
341 raw?: boolean;
342}
343/**
344 * Deserialize stream data as BSON documents.
345 *
346 * @param data - the buffer containing the serialized set of BSON documents.
347 * @param startIndex - the start index in the data Buffer where the deserialization is to start.
348 * @param numberOfDocuments - number of documents to deserialize.
349 * @param documents - an array where to store the deserialized documents.
350 * @param docStartIndex - the index in the documents array from where to start inserting documents.
351 * @param options - additional options used for the deserialization.
352 * @returns next index in the buffer after deserialization **x** numbers of documents.
353 * @public
354 */
355export declare function deserializeStream(data: Buffer | ArrayBufferView | ArrayBuffer, startIndex: number, numberOfDocuments: number, documents: Document[], docStartIndex: number, options: DeserializeOptions): number;
356/** @public */
357export declare interface Document {
358 [key: string]: any;
359}
360/**
361 * A class representation of the BSON Double type.
362 * @public
363 */
364export declare class Double {
365 _bsontype: 'Double';
366 value: number;
367 /**
368 * Create a Double type
369 *
370 * @param value - the number we want to represent as a double.
371 */
372 constructor(value: number);
373 /**
374 * Access the number value.
375 *
376 * @returns returns the wrapped double number.
377 */
378 valueOf(): number;
379 toJSON(): number;
380 toString(radix?: number): string;
381 /* Excluded from this release type: toExtendedJSON */
382 /* Excluded from this release type: fromExtendedJSON */
383 inspect(): string;
384}
385/** @public */
386export declare interface DoubleExtended {
387 $numberDouble: string;
388}
389/**
390 * EJSON parse / stringify API
391 * @public
392 */
393export declare namespace EJSON {
394 export interface Options {
395 /** Output using the Extended JSON v1 spec */
396 legacy?: boolean;
397 /** Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types */
398 relaxed?: boolean;
399 /**
400 * Disable Extended JSON's `relaxed` mode, which attempts to return BSON types where possible, rather than native JS types
401 * @deprecated Please use the relaxed property instead
402 */
403 strict?: boolean;
404 }
405 /**
406 * Parse an Extended JSON string, constructing the JavaScript value or object described by that
407 * string.
408 *
409 * @example
410 * ```js
411 * const { EJSON } = require('bson');
412 * const text = '{ "int32": { "$numberInt": "10" } }';
413 *
414 * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
415 * console.log(EJSON.parse(text, { relaxed: false }));
416 *
417 * // prints { int32: 10 }
418 * console.log(EJSON.parse(text));
419 * ```
420 */
421 export function parse(text: string, options?: EJSON.Options): SerializableTypes;
422 export type JSONPrimitive = string | number | boolean | null;
423 export type SerializableTypes = Document | Array<JSONPrimitive | Document> | JSONPrimitive;
424 /**
425 * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
426 * function is specified or optionally including only the specified properties if a replacer array
427 * is specified.
428 *
429 * @param value - The value to convert to extended JSON
430 * @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
431 * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
432 * @param options - Optional settings
433 *
434 * @example
435 * ```js
436 * const { EJSON } = require('bson');
437 * const Int32 = require('mongodb').Int32;
438 * const doc = { int32: new Int32(10) };
439 *
440 * // prints '{"int32":{"$numberInt":"10"}}'
441 * console.log(EJSON.stringify(doc, { relaxed: false }));
442 *
443 * // prints '{"int32":10}'
444 * console.log(EJSON.stringify(doc));
445 * ```
446 */
447 export function stringify(value: SerializableTypes, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSON.Options, space?: string | number, options?: EJSON.Options): string;
448 /**
449 * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
450 *
451 * @param value - The object to serialize
452 * @param options - Optional settings passed to the `stringify` function
453 */
454 export function serialize(value: SerializableTypes, options?: EJSON.Options): Document;
455 /**
456 * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
457 *
458 * @param ejson - The Extended JSON object to deserialize
459 * @param options - Optional settings passed to the parse method
460 */
461 export function deserialize(ejson: Document, options?: EJSON.Options): SerializableTypes;
462}
463/** @public */
464export declare type EJSONOptions = EJSON.Options;
465/**
466 * A class representation of a BSON Int32 type.
467 * @public
468 */
469export declare class Int32 {
470 _bsontype: 'Int32';
471 value: number;
472 /**
473 * Create an Int32 type
474 *
475 * @param value - the number we want to represent as an int32.
476 */
477 constructor(value: number | string);
478 /**
479 * Access the number value.
480 *
481 * @returns returns the wrapped int32 number.
482 */
483 valueOf(): number;
484 toString(radix?: number): string;
485 toJSON(): number;
486 /* Excluded from this release type: toExtendedJSON */
487 /* Excluded from this release type: fromExtendedJSON */
488 inspect(): string;
489}
490/** @public */
491export declare interface Int32Extended {
492 $numberInt: string;
493}
494declare const kId: unique symbol;
495declare const kId_2: unique symbol;
496/**
497 * A class representing a 64-bit integer
498 * @public
499 * @remarks
500 * The internal representation of a long is the two given signed, 32-bit values.
501 * We use 32-bit pieces because these are the size of integers on which
502 * Javascript performs bit-operations. For operations like addition and
503 * multiplication, we split each number into 16 bit pieces, which can easily be
504 * multiplied within Javascript's floating-point representation without overflow
505 * or change in sign.
506 * In the algorithms below, we frequently reduce the negative case to the
507 * positive case by negating the input(s) and then post-processing the result.
508 * Note that we must ALWAYS check specially whether those values are MIN_VALUE
509 * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
510 * a positive number, it overflows back into a negative). Not handling this
511 * case would often result in infinite recursion.
512 * Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
513 */
514export declare class Long {
515 _bsontype: 'Long';
516 /** An indicator used to reliably determine if an object is a Long or not. */
517 __isLong__: true;
518 /**
519 * The high 32 bits as a signed value.
520 */
521 high: number;
522 /**
523 * The low 32 bits as a signed value.
524 */
525 low: number;
526 /**
527 * Whether unsigned or not.
528 */
529 unsigned: boolean;
530 /**
531 * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
532 * See the from* functions below for more convenient ways of constructing Longs.
533 *
534 * Acceptable signatures are:
535 * - Long(low, high, unsigned?)
536 * - Long(bigint, unsigned?)
537 * - Long(string, unsigned?)
538 *
539 * @param low - The low (signed) 32 bits of the long
540 * @param high - The high (signed) 32 bits of the long
541 * @param unsigned - Whether unsigned or not, defaults to signed
542 */
543 constructor(low?: number | bigint | string, high?: number | boolean, unsigned?: boolean);
544 static TWO_PWR_24: Long;
545 /** Maximum unsigned value. */
546 static MAX_UNSIGNED_VALUE: Long;
547 /** Signed zero */
548 static ZERO: Long;
549 /** Unsigned zero. */
550 static UZERO: Long;
551 /** Signed one. */
552 static ONE: Long;
553 /** Unsigned one. */
554 static UONE: Long;
555 /** Signed negative one. */
556 static NEG_ONE: Long;
557 /** Maximum signed value. */
558 static MAX_VALUE: Long;
559 /** Minimum signed value. */
560 static MIN_VALUE: Long;
561 /**
562 * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits.
563 * Each is assumed to use 32 bits.
564 * @param lowBits - The low 32 bits
565 * @param highBits - The high 32 bits
566 * @param unsigned - Whether unsigned or not, defaults to signed
567 * @returns The corresponding Long value
568 */
569 static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
570 /**
571 * Returns a Long representing the given 32 bit integer value.
572 * @param value - The 32 bit integer in question
573 * @param unsigned - Whether unsigned or not, defaults to signed
574 * @returns The corresponding Long value
575 */
576 static fromInt(value: number, unsigned?: boolean): Long;
577 /**
578 * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
579 * @param value - The number in question
580 * @param unsigned - Whether unsigned or not, defaults to signed
581 * @returns The corresponding Long value
582 */
583 static fromNumber(value: number, unsigned?: boolean): Long;
584 /**
585 * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
586 * @param value - The number in question
587 * @param unsigned - Whether unsigned or not, defaults to signed
588 * @returns The corresponding Long value
589 */
590 static fromBigInt(value: bigint, unsigned?: boolean): Long;
591 /**
592 * Returns a Long representation of the given string, written using the specified radix.
593 * @param str - The textual representation of the Long
594 * @param unsigned - Whether unsigned or not, defaults to signed
595 * @param radix - The radix in which the text is written (2-36), defaults to 10
596 * @returns The corresponding Long value
597 */
598 static fromString(str: string, unsigned?: boolean, radix?: number): Long;
599 /**
600 * Creates a Long from its byte representation.
601 * @param bytes - Byte representation
602 * @param unsigned - Whether unsigned or not, defaults to signed
603 * @param le - Whether little or big endian, defaults to big endian
604 * @returns The corresponding Long value
605 */
606 static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
607 /**
608 * Creates a Long from its little endian byte representation.
609 * @param bytes - Little endian byte representation
610 * @param unsigned - Whether unsigned or not, defaults to signed
611 * @returns The corresponding Long value
612 */
613 static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
614 /**
615 * Creates a Long from its big endian byte representation.
616 * @param bytes - Big endian byte representation
617 * @param unsigned - Whether unsigned or not, defaults to signed
618 * @returns The corresponding Long value
619 */
620 static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
621 /**
622 * Tests if the specified object is a Long.
623 */
624 static isLong(value: any): value is Long;
625 /**
626 * Converts the specified value to a Long.
627 * @param unsigned - Whether unsigned or not, defaults to signed
628 */
629 static fromValue(val: number | string | {
630 low: number;
631 high: number;
632 unsigned?: boolean;
633 }, unsigned?: boolean): Long;
634 /** Returns the sum of this and the specified Long. */
635 add(addend: string | number | Long | Timestamp): Long;
636 /**
637 * Returns the sum of this and the specified Long.
638 * @returns Sum
639 */
640 and(other: string | number | Long | Timestamp): Long;
641 /**
642 * Compares this Long's value with the specified's.
643 * @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
644 */
645 compare(other: string | number | Long | Timestamp): 0 | 1 | -1;
646 /** This is an alias of {@link Long.compare} */
647 comp(other: string | number | Long | Timestamp): 0 | 1 | -1;
648 /**
649 * Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
650 * @returns Quotient
651 */
652 divide(divisor: string | number | Long | Timestamp): Long;
653 /**This is an alias of {@link Long.divide} */
654 div(divisor: string | number | Long | Timestamp): Long;
655 /**
656 * Tests if this Long's value equals the specified's.
657 * @param other - Other value
658 */
659 equals(other: string | number | Long | Timestamp): boolean;
660 /** This is an alias of {@link Long.equals} */
661 eq(other: string | number | Long | Timestamp): boolean;
662 /** Gets the high 32 bits as a signed integer. */
663 getHighBits(): number;
664 /** Gets the high 32 bits as an unsigned integer. */
665 getHighBitsUnsigned(): number;
666 /** Gets the low 32 bits as a signed integer. */
667 getLowBits(): number;
668 /** Gets the low 32 bits as an unsigned integer. */
669 getLowBitsUnsigned(): number;
670 /** Gets the number of bits needed to represent the absolute value of this Long. */
671 getNumBitsAbs(): number;
672 /** Tests if this Long's value is greater than the specified's. */
673 greaterThan(other: string | number | Long | Timestamp): boolean;
674 /** This is an alias of {@link Long.greaterThan} */
675 gt(other: string | number | Long | Timestamp): boolean;
676 /** Tests if this Long's value is greater than or equal the specified's. */
677 greaterThanOrEqual(other: string | number | Long | Timestamp): boolean;
678 /** This is an alias of {@link Long.greaterThanOrEqual} */
679 gte(other: string | number | Long | Timestamp): boolean;
680 /** This is an alias of {@link Long.greaterThanOrEqual} */
681 ge(other: string | number | Long | Timestamp): boolean;
682 /** Tests if this Long's value is even. */
683 isEven(): boolean;
684 /** Tests if this Long's value is negative. */
685 isNegative(): boolean;
686 /** Tests if this Long's value is odd. */
687 isOdd(): boolean;
688 /** Tests if this Long's value is positive. */
689 isPositive(): boolean;
690 /** Tests if this Long's value equals zero. */
691 isZero(): boolean;
692 /** Tests if this Long's value is less than the specified's. */
693 lessThan(other: string | number | Long | Timestamp): boolean;
694 /** This is an alias of {@link Long#lessThan}. */
695 lt(other: string | number | Long | Timestamp): boolean;
696 /** Tests if this Long's value is less than or equal the specified's. */
697 lessThanOrEqual(other: string | number | Long | Timestamp): boolean;
698 /** This is an alias of {@link Long.lessThanOrEqual} */
699 lte(other: string | number | Long | Timestamp): boolean;
700 /** Returns this Long modulo the specified. */
701 modulo(divisor: string | number | Long | Timestamp): Long;
702 /** This is an alias of {@link Long.modulo} */
703 mod(divisor: string | number | Long | Timestamp): Long;
704 /** This is an alias of {@link Long.modulo} */
705 rem(divisor: string | number | Long | Timestamp): Long;
706 /**
707 * Returns the product of this and the specified Long.
708 * @param multiplier - Multiplier
709 * @returns Product
710 */
711 multiply(multiplier: string | number | Long | Timestamp): Long;
712 /** This is an alias of {@link Long.multiply} */
713 mul(multiplier: string | number | Long | Timestamp): Long;
714 /** Returns the Negation of this Long's value. */
715 negate(): Long;
716 /** This is an alias of {@link Long.negate} */
717 neg(): Long;
718 /** Returns the bitwise NOT of this Long. */
719 not(): Long;
720 /** Tests if this Long's value differs from the specified's. */
721 notEquals(other: string | number | Long | Timestamp): boolean;
722 /** This is an alias of {@link Long.notEquals} */
723 neq(other: string | number | Long | Timestamp): boolean;
724 /** This is an alias of {@link Long.notEquals} */
725 ne(other: string | number | Long | Timestamp): boolean;
726 /**
727 * Returns the bitwise OR of this Long and the specified.
728 */
729 or(other: number | string | Long): Long;
730 /**
731 * Returns this Long with bits shifted to the left by the given amount.
732 * @param numBits - Number of bits
733 * @returns Shifted Long
734 */
735 shiftLeft(numBits: number | Long): Long;
736 /** This is an alias of {@link Long.shiftLeft} */
737 shl(numBits: number | Long): Long;
738 /**
739 * Returns this Long with bits arithmetically shifted to the right by the given amount.
740 * @param numBits - Number of bits
741 * @returns Shifted Long
742 */
743 shiftRight(numBits: number | Long): Long;
744 /** This is an alias of {@link Long.shiftRight} */
745 shr(numBits: number | Long): Long;
746 /**
747 * Returns this Long with bits logically shifted to the right by the given amount.
748 * @param numBits - Number of bits
749 * @returns Shifted Long
750 */
751 shiftRightUnsigned(numBits: Long | number): Long;
752 /** This is an alias of {@link Long.shiftRightUnsigned} */
753 shr_u(numBits: number | Long): Long;
754 /** This is an alias of {@link Long.shiftRightUnsigned} */
755 shru(numBits: number | Long): Long;
756 /**
757 * Returns the difference of this and the specified Long.
758 * @param subtrahend - Subtrahend
759 * @returns Difference
760 */
761 subtract(subtrahend: string | number | Long | Timestamp): Long;
762 /** This is an alias of {@link Long.subtract} */
763 sub(subtrahend: string | number | Long | Timestamp): Long;
764 /** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
765 toInt(): number;
766 /** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */
767 toNumber(): number;
768 /** Converts the Long to a BigInt (arbitrary precision). */
769 toBigInt(): bigint;
770 /**
771 * Converts this Long to its byte representation.
772 * @param le - Whether little or big endian, defaults to big endian
773 * @returns Byte representation
774 */
775 toBytes(le?: boolean): number[];
776 /**
777 * Converts this Long to its little endian byte representation.
778 * @returns Little endian byte representation
779 */
780 toBytesLE(): number[];
781 /**
782 * Converts this Long to its big endian byte representation.
783 * @returns Big endian byte representation
784 */
785 toBytesBE(): number[];
786 /**
787 * Converts this Long to signed.
788 */
789 toSigned(): Long;
790 /**
791 * Converts the Long to a string written in the specified radix.
792 * @param radix - Radix (2-36), defaults to 10
793 * @throws RangeError If `radix` is out of range
794 */
795 toString(radix?: number): string;
796 /** Converts this Long to unsigned. */
797 toUnsigned(): Long;
798 /** Returns the bitwise XOR of this Long and the given one. */
799 xor(other: Long | number | string): Long;
800 /** This is an alias of {@link Long.isZero} */
801 eqz(): boolean;
802 /** This is an alias of {@link Long.lessThanOrEqual} */
803 le(other: string | number | Long | Timestamp): boolean;
804 toExtendedJSON(options?: EJSONOptions): number | LongExtended;
805 static fromExtendedJSON(doc: {
806 $numberLong: string;
807 }, options?: EJSONOptions): number | Long;
808 inspect(): string;
809}
810/** @public */
811export declare interface LongExtended {
812 $numberLong: string;
813}
814/** @public */
815export declare type LongWithoutOverrides = new (low: unknown, high?: number, unsigned?: boolean) => {
816 [P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
817};
818/** @public */
819export declare const LongWithoutOverridesClass: LongWithoutOverrides;
820/** @public */
821declare let Map_2: MapConstructor;
822export { Map_2 as Map };
823/**
824 * A class representation of the BSON MaxKey type.
825 * @public
826 */
827export declare class MaxKey {
828 _bsontype: 'MaxKey';
829 constructor();
830 /* Excluded from this release type: toExtendedJSON */
831 /* Excluded from this release type: fromExtendedJSON */
832 inspect(): string;
833}
834/** @public */
835export declare interface MaxKeyExtended {
836 $maxKey: 1;
837}
838/**
839 * A class representation of the BSON MinKey type.
840 * @public
841 */
842export declare class MinKey {
843 _bsontype: 'MinKey';
844 constructor();
845 /* Excluded from this release type: toExtendedJSON */
846 /* Excluded from this release type: fromExtendedJSON */
847 inspect(): string;
848}
849/** @public */
850export declare interface MinKeyExtended {
851 $minKey: 1;
852}
853/**
854 * A class representation of the BSON ObjectId type.
855 * @public
856 */
857declare class ObjectId {
858 _bsontype: 'ObjectId';
859 /* Excluded from this release type: index */
860 static cacheHexString: boolean;
861 /* Excluded from this release type: [kId] */
862 /* Excluded from this release type: __id */
863 /**
864 * Create an ObjectId type
865 *
866 * @param id - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
867 */
868 constructor(id?: string | Buffer | number | ObjectIdLike | ObjectId);
869 /*
870 * The ObjectId bytes
871 * @readonly
872 */
873 id: Buffer;
874 /*
875 * The generation time of this ObjectId instance
876 * @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch
877 */
878 generationTime: number;
879 /** Returns the ObjectId id as a 24 character hex string representation */
880 toHexString(): string;
881 /* Excluded from this release type: getInc */
882 /**
883 * Generate a 12 byte id buffer used in ObjectId's
884 *
885 * @param time - pass in a second based timestamp.
886 */
887 static generate(time?: number): Buffer;
888 /**
889 * Converts the id into a 24 character hex string for printing
890 *
891 * @param format - The Buffer toString format parameter.
892 */
893 toString(format?: string): string;
894 /** Converts to its JSON the 24 character hex string representation. */
895 toJSON(): string;
896 /**
897 * Compares the equality of this ObjectId with `otherID`.
898 *
899 * @param otherId - ObjectId instance to compare against.
900 */
901 equals(otherId: string | ObjectId | ObjectIdLike): boolean;
902 /** Returns the generation date (accurate up to the second) that this ID was generated. */
903 getTimestamp(): Date;
904 /* Excluded from this release type: createPk */
905 /**
906 * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
907 *
908 * @param time - an integer number representing a number of seconds.
909 */
910 static createFromTime(time: number): ObjectId;
911 /**
912 * Creates an ObjectId from a hex string representation of an ObjectId.
913 *
914 * @param hexString - create a ObjectId from a passed in 24 character hexstring.
915 */
916 static createFromHexString(hexString: string): ObjectId;
917 /**
918 * Checks if a value is a valid bson ObjectId
919 *
920 * @param id - ObjectId instance to validate.
921 */
922 static isValid(id: number | string | ObjectId | Uint8Array | ObjectIdLike): boolean;
923 /* Excluded from this release type: toExtendedJSON */
924 /* Excluded from this release type: fromExtendedJSON */
925 inspect(): string;
926}
927export { ObjectId as ObjectID };
928export { ObjectId };
929/** @public */
930export declare interface ObjectIdExtended {
931 $oid: string;
932}
933/** @public */
934export declare interface ObjectIdLike {
935 id: string | Buffer;
936 __id?: string;
937 toHexString(): string;
938}
939/**
940 * Serialize a Javascript object.
941 *
942 * @param object - the Javascript object to serialize.
943 * @returns Buffer object containing the serialized object.
944 * @public
945 */
946export declare function serialize(object: Document, options?: SerializeOptions): Buffer;
947/** @public */
948export declare interface SerializeOptions {
949 /** the serializer will check if keys are valid. */
950 checkKeys?: boolean;
951 /** serialize the javascript functions **(default:false)**. */
952 serializeFunctions?: boolean;
953 /** serialize will not emit undefined fields **(default:true)** */
954 ignoreUndefined?: boolean;
955 /* Excluded from this release type: minInternalBufferSize */
956 /** the index in the buffer where we wish to start serializing into */
957 index?: number;
958}
959/**
960 * Serialize a Javascript object using a predefined Buffer and index into the buffer,
961 * useful when pre-allocating the space for serialization.
962 *
963 * @param object - the Javascript object to serialize.
964 * @param finalBuffer - the Buffer you pre-allocated to store the serialized BSON object.
965 * @returns the index pointing to the last written byte in the buffer.
966 * @public
967 */
968export declare function serializeWithBufferAndIndex(object: Document, finalBuffer: Buffer, options?: SerializeOptions): number;
969/**
970 * Sets the size of the internal serialization buffer.
971 *
972 * @param size - The desired size for the internal serialization buffer
973 * @public
974 */
975export declare function setInternalBufferSize(size: number): void;
976/** @public */
977export declare class Timestamp extends LongWithoutOverridesClass {
978 _bsontype: 'Timestamp';
979 static readonly MAX_VALUE: Long;
980 /**
981 * @param low - A 64-bit Long representing the Timestamp.
982 */
983 constructor(long: Long);
984 /**
985 * @param value - A pair of two values indicating timestamp and increment.
986 */
987 constructor(value: {
988 t: number;
989 i: number;
990 });
991 /**
992 * @param low - the low (signed) 32 bits of the Timestamp.
993 * @param high - the high (signed) 32 bits of the Timestamp.
994 * @deprecated Please use `Timestamp({ t: high, i: low })` or `Timestamp(Long(low, high))` instead.
995 */
996 constructor(low: number, high: number);
997 toJSON(): {
998 $timestamp: string;
999 };
1000 /** Returns a Timestamp represented by the given (32-bit) integer value. */
1001 static fromInt(value: number): Timestamp;
1002 /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
1003 static fromNumber(value: number): Timestamp;
1004 /**
1005 * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
1006 *
1007 * @param lowBits - the low 32-bits.
1008 * @param highBits - the high 32-bits.
1009 */
1010 static fromBits(lowBits: number, highBits: number): Timestamp;
1011 /**
1012 * Returns a Timestamp from the given string, optionally using the given radix.
1013 *
1014 * @param str - the textual representation of the Timestamp.
1015 * @param optRadix - the radix in which the text is written.
1016 */
1017 static fromString(str: string, optRadix: number): Timestamp;
1018 /* Excluded from this release type: toExtendedJSON */
1019 /* Excluded from this release type: fromExtendedJSON */
1020 inspect(): string;
1021}
1022/** @public */
1023export declare interface TimestampExtended {
1024 $timestamp: {
1025 t: number;
1026 i: number;
1027 };
1028}
1029/** @public */
1030export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect';
1031/**
1032 * A class representation of the BSON UUID type.
1033 * @public
1034 */
1035export declare class UUID {
1036 _bsontype: 'UUID';
1037 static cacheHexString: boolean;
1038 /* Excluded from this release type: [kId] */
1039 /* Excluded from this release type: __id */
1040 /**
1041 * Create an UUID type
1042 *
1043 * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
1044 */
1045 constructor(input?: string | Buffer | UUID);
1046 /*
1047 * The UUID bytes
1048 * @readonly
1049 */
1050 id: Buffer;
1051 /**
1052 * Generate a 16 byte uuid v4 buffer used in UUIDs
1053 */
1054 /**
1055 * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
1056 * @param includeDashes - should the string exclude dash-separators.
1057 * */
1058 toHexString(includeDashes?: boolean): string;
1059 /**
1060 * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
1061 */
1062 toString(encoding?: string): string;
1063 /**
1064 * Converts the id into its JSON string representation.
1065 * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1066 */
1067 toJSON(): string;
1068 /**
1069 * Compares the equality of this UUID with `otherID`.
1070 *
1071 * @param otherId - UUID instance to compare against.
1072 */
1073 equals(otherId: string | Buffer | UUID): boolean;
1074 /**
1075 * Creates a Binary instance from the current UUID.
1076 */
1077 toBinary(): Binary;
1078 /**
1079 * Generates a populated buffer containing a v4 uuid
1080 */
1081 static generate(): Buffer;
1082 /**
1083 * Checks if a value is a valid bson UUID
1084 * @param input - UUID, string or Buffer to validate.
1085 */
1086 static isValid(input: string | Buffer | UUID): boolean;
1087 /**
1088 * Creates an UUID from a hex string representation of an UUID.
1089 * @param hexString - 32 or 36 character hex string (dashes excluded/included).
1090 */
1091 static createFromHexString(hexString: string): UUID;
1092 inspect(): string;
1093}
1094/** @public */
1095export declare type UUIDExtended = {
1096 $uuid: string;
1097};
1098export {};