-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmod.d.ts
1622 lines (1553 loc) · 57.6 KB
/
mod.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* A class representation of the BSON Binary type.
* @public
* @category BSONType
*/
export declare class Binary extends BSONValue {
get _bsontype(): 'Binary';
/* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
/** Initial buffer default size */
static readonly BUFFER_SIZE = 256;
/** Default BSON type */
static readonly SUBTYPE_DEFAULT = 0;
/** Function BSON type */
static readonly SUBTYPE_FUNCTION = 1;
/** Byte Array BSON type */
static readonly SUBTYPE_BYTE_ARRAY = 2;
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
static readonly SUBTYPE_UUID_OLD = 3;
/** UUID BSON type */
static readonly SUBTYPE_UUID = 4;
/** MD5 BSON type */
static readonly SUBTYPE_MD5 = 5;
/** Encrypted BSON type */
static readonly SUBTYPE_ENCRYPTED = 6;
/** Column BSON type */
static readonly SUBTYPE_COLUMN = 7;
/** Sensitive BSON type */
static readonly SUBTYPE_SENSITIVE = 8;
/** User BSON type */
static readonly SUBTYPE_USER_DEFINED = 128;
buffer: Uint8Array;
sub_type: number;
position: number;
/**
* Create a new Binary instance.
* @param buffer - a buffer object containing the binary data.
* @param subType - the option binary type.
*/
constructor(buffer?: BinarySequence, subType?: number);
/**
* Updates this binary with byte_value.
*
* @param byteValue - a single byte we wish to write.
*/
put(byteValue: string | number | Uint8Array | number[]): void;
/**
* Writes a buffer to the binary.
*
* @param sequence - a string or buffer to be written to the Binary BSON object.
* @param offset - specify the binary of where to write the content.
*/
write(sequence: BinarySequence, offset: number): void;
/**
* Reads **length** bytes starting at **position**.
*
* @param position - read from the given position in the Binary.
* @param length - the number of bytes to read.
*/
read(position: number, length: number): BinarySequence;
/** returns a view of the binary value as a Uint8Array */
value(): Uint8Array;
/** the length of the binary sequence */
length(): number;
toJSON(): string;
toString(encoding?: 'hex' | 'base64' | 'utf8' | 'utf-8'): string;
/* Excluded from this release type: toExtendedJSON */
toUUID(): UUID;
/** Creates an Binary instance from a hex digit string */
static createFromHexString(hex: string, subType?: number): Binary;
/** Creates an Binary instance from a base64 string */
static createFromBase64(base64: string, subType?: number): Binary;
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface BinaryExtended {
$binary: {
subType: string;
base64: string;
};
}
/** @public */
export declare interface BinaryExtendedLegacy {
$type: string;
$binary: string;
}
/** @public */
export declare type BinarySequence = Uint8Array | number[];
declare namespace BSON {
export {
setInternalBufferSize,
serialize,
serializeWithBufferAndIndex,
deserialize,
calculateObjectSize,
deserializeStream,
UUIDExtended,
BinaryExtended,
BinaryExtendedLegacy,
BinarySequence,
CodeExtended,
DBRefLike,
Decimal128Extended,
DoubleExtended,
EJSONOptions,
Int32Extended,
LongExtended,
MaxKeyExtended,
MinKeyExtended,
ObjectIdExtended,
ObjectIdLike,
BSONRegExpExtended,
BSONRegExpExtendedLegacy,
BSONSymbolExtended,
LongWithoutOverrides,
TimestampExtended,
TimestampOverrides,
LongWithoutOverridesClass,
SerializeOptions,
DeserializeOptions,
Code,
BSONSymbol,
DBRef,
Binary,
ObjectId,
UUID,
Long,
Timestamp,
Double,
Int32,
MinKey,
MaxKey,
BSONRegExp,
Decimal128,
BSONValue,
BSONError,
BSONVersionError,
BSONRuntimeError,
BSONOffsetError,
BSONType,
EJSON,
onDemand,
OnDemand,
Document,
CalculateObjectSizeOptions
}
}
export { BSON }
/* Excluded from this release type: BSON_MAJOR_VERSION */
/* Excluded from this release type: BSON_VERSION_SYMBOL */
/**
* @public
* @experimental
*/
declare type BSONElement = [
type: number,
nameOffset: number,
nameLength: number,
offset: number,
length: number
];
/**
* @public
* @category Error
*
* `BSONError` objects are thrown when BSON encounters an error.
*
* This is the parent class for all the other errors thrown by this library.
*/
export declare class BSONError extends Error {
/* Excluded from this release type: bsonError */
get name(): string;
constructor(message: string, options?: {
cause?: unknown;
});
/**
* @public
*
* All errors thrown from the BSON library inherit from `BSONError`.
* This method can assist with determining if an error originates from the BSON library
* even if it does not pass an `instanceof` check against this class' constructor.
*
* @param value - any javascript value that needs type checking
*/
static isBSONError(value: unknown): value is BSONError;
}
/**
* @public
* @category Error
*
* @experimental
*
* An error generated when BSON bytes are invalid.
* Reports the offset the parser was able to reach before encountering the error.
*/
export declare class BSONOffsetError extends BSONError {
get name(): 'BSONOffsetError';
offset: number;
constructor(message: string, offset: number, options?: {
cause?: unknown;
});
}
/**
* A class representation of the BSON RegExp type.
* @public
* @category BSONType
*/
export declare class BSONRegExp extends BSONValue {
get _bsontype(): 'BSONRegExp';
pattern: string;
options: string;
/**
* @param pattern - The regular expression pattern to match
* @param options - The regular expression options
*/
constructor(pattern: string, options?: string);
static parseOptions(options?: string): string;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface BSONRegExpExtended {
$regularExpression: {
pattern: string;
options: string;
};
}
/** @public */
export declare interface BSONRegExpExtendedLegacy {
$regex: string | BSONRegExp;
$options: string;
}
/**
* @public
* @category Error
*
* An error generated when BSON functions encounter an unexpected input
* or reaches an unexpected/invalid internal state
*
*/
export declare class BSONRuntimeError extends BSONError {
get name(): 'BSONRuntimeError';
constructor(message: string);
}
/**
* A class representation of the BSON Symbol type.
* @public
* @category BSONType
*/
export declare class BSONSymbol extends BSONValue {
get _bsontype(): 'BSONSymbol';
value: string;
/**
* @param value - the string representing the symbol.
*/
constructor(value: string);
/** Access the wrapped string value. */
valueOf(): string;
toString(): string;
toJSON(): string;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface BSONSymbolExtended {
$symbol: string;
}
/** @public */
export declare const BSONType: Readonly<{
readonly double: 1;
readonly string: 2;
readonly object: 3;
readonly array: 4;
readonly binData: 5;
readonly undefined: 6;
readonly objectId: 7;
readonly bool: 8;
readonly date: 9;
readonly null: 10;
readonly regex: 11;
readonly dbPointer: 12;
readonly javascript: 13;
readonly symbol: 14;
readonly javascriptWithScope: 15;
readonly int: 16;
readonly timestamp: 17;
readonly long: 18;
readonly decimal: 19;
readonly minKey: -1;
readonly maxKey: 127;
}>;
/** @public */
export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
/** @public */
export declare abstract class BSONValue {
/** @public */
abstract get _bsontype(): string;
/* Excluded from this release type: [BSON_VERSION_SYMBOL] */
/**
* @public
* Prints a human-readable string of BSON value information
* If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify
*/
abstract inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
/* Excluded from this release type: toExtendedJSON */
}
/**
* @public
* @category Error
*/
export declare class BSONVersionError extends BSONError {
get name(): 'BSONVersionError';
constructor();
}
/**
* @public
* @experimental
*
* A collection of functions that help work with data in a Uint8Array.
* ByteUtils is configured at load time to use Node.js or Web based APIs for the internal implementations.
*/
declare type ByteUtils = {
/** Transforms the input to an instance of Buffer if running on node, otherwise Uint8Array */
toLocalBufferType: (buffer: Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array;
/** Create empty space of size */
allocate: (size: number) => Uint8Array;
/** Create empty space of size, use pooled memory when available */
allocateUnsafe: (size: number) => Uint8Array;
/** Check if two Uint8Arrays are deep equal */
equals: (a: Uint8Array, b: Uint8Array) => boolean;
/** Check if two Uint8Arrays are deep equal */
fromNumberArray: (array: number[]) => Uint8Array;
/** Create a Uint8Array from a base64 string */
fromBase64: (base64: string) => Uint8Array;
/** Create a base64 string from bytes */
toBase64: (buffer: Uint8Array) => string;
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
fromISO88591: (codePoints: string) => Uint8Array;
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
toISO88591: (buffer: Uint8Array) => string;
/** Create a Uint8Array from a hex string */
fromHex: (hex: string) => Uint8Array;
/** Create a lowercase hex string from bytes */
toHex: (buffer: Uint8Array) => string;
/** Create a string from utf8 code units, fatal=true will throw an error if UTF-8 bytes are invalid, fatal=false will insert replacement characters */
toUTF8: (buffer: Uint8Array, start: number, end: number, fatal: boolean) => string;
/** Get the utf8 code unit count from a string if it were to be transformed to utf8 */
utf8ByteLength: (input: string) => number;
/** Encode UTF8 bytes generated from `source` string into `destination` at byteOffset. Returns the number of bytes encoded. */
encodeUTF8Into: (destination: Uint8Array, source: string, byteOffset: number) => number;
/** Generate a Uint8Array filled with random bytes with byteLength */
randomBytes: (byteLength: number) => Uint8Array;
};
/* Excluded declaration from this release type: ByteUtils */
/**
* Calculate the bson size for a passed in Javascript object.
*
* @param object - the Javascript object to calculate the BSON byte size for
* @returns size of BSON object in bytes
* @public
*/
export declare function calculateObjectSize(object: Document, options?: CalculateObjectSizeOptions): number;
/** @public */
export declare type CalculateObjectSizeOptions = Pick<SerializeOptions, 'serializeFunctions' | 'ignoreUndefined'>;
/**
* A class representation of the BSON Code type.
* @public
* @category BSONType
*/
export declare class Code extends BSONValue {
get _bsontype(): 'Code';
code: string;
scope: Document | null;
/**
* @param code - a string or function.
* @param scope - an optional scope for the function.
*/
constructor(code: string | Function, scope?: Document | null);
toJSON(): {
code: string;
scope?: Document;
};
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface CodeExtended {
$code: string;
$scope?: Document;
}
/**
* A class representation of the BSON DBRef type.
* @public
* @category BSONType
*/
export declare class DBRef extends BSONValue {
get _bsontype(): 'DBRef';
collection: string;
oid: ObjectId;
db?: string;
fields: Document;
/**
* @param collection - the collection name.
* @param oid - the reference ObjectId.
* @param db - optional db name, if omitted the reference is local to the current db.
*/
constructor(collection: string, oid: ObjectId, db?: string, fields?: Document);
/* Excluded from this release type: namespace */
/* Excluded from this release type: namespace */
toJSON(): DBRefLike & Document;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface DBRefLike {
$ref: string;
$id: ObjectId;
$db?: string;
}
/**
* A class representation of the BSON Decimal128 type.
* @public
* @category BSONType
*/
export declare class Decimal128 extends BSONValue {
get _bsontype(): 'Decimal128';
readonly bytes: Uint8Array;
/**
* @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
* or a string representation as returned by .toString()
*/
constructor(bytes: Uint8Array | string);
/**
* Create a Decimal128 instance from a string representation
*
* @param representation - a numeric string representation.
*/
static fromString(representation: string): Decimal128;
/**
* Create a Decimal128 instance from a string representation, allowing for rounding to 34
* significant digits
*
* @example Example of a number that will be rounded
* ```ts
* > let d = Decimal128.fromString('37.499999999999999196428571428571375')
* Uncaught:
* BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
* at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
* at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
* at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)
*
* > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
* new Decimal128("37.49999999999999919642857142857138")
* ```
* @param representation - a numeric string representation.
*/
static fromStringWithRounding(representation: string): Decimal128;
private static _fromString;
/** Create a string representation of the raw Decimal128 value */
toString(): string;
toJSON(): Decimal128Extended;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface Decimal128Extended {
$numberDecimal: string;
}
/**
* Deserialize data as BSON.
*
* @param buffer - the buffer containing the serialized set of BSON documents.
* @returns returns the deserialized Javascript Object.
* @public
*/
export declare function deserialize(buffer: Uint8Array, options?: DeserializeOptions): Document;
/** @public */
export declare interface DeserializeOptions {
/**
* when deserializing a Long return as a BigInt.
* @defaultValue `false`
*/
useBigInt64?: boolean;
/**
* when deserializing a Long will fit it into a Number if it's smaller than 53 bits.
* @defaultValue `true`
*/
promoteLongs?: boolean;
/**
* when deserializing a Binary will return it as a node.js Buffer instance.
* @defaultValue `false`
*/
promoteBuffers?: boolean;
/**
* when deserializing will promote BSON values to their Node.js closest equivalent types.
* @defaultValue `true`
*/
promoteValues?: boolean;
/**
* allow to specify if there what fields we wish to return as unserialized raw buffer.
* @defaultValue `null`
*/
fieldsAsRaw?: Document;
/**
* return BSON regular expressions as BSONRegExp instances.
* @defaultValue `false`
*/
bsonRegExp?: boolean;
/**
* allows the buffer to be larger than the parsed BSON object.
* @defaultValue `false`
*/
allowObjectSmallerThanBufferSize?: boolean;
/**
* Offset into buffer to begin reading document from
* @defaultValue `0`
*/
index?: number;
raw?: boolean;
/** Allows for opt-out utf-8 validation for all keys or
* specified keys. Must be all true or all false.
*
* @example
* ```js
* // disables validation on all keys
* validation: { utf8: false }
*
* // enables validation only on specified keys a, b, and c
* validation: { utf8: { a: true, b: true, c: true } }
*
* // disables validation only on specified keys a, b
* validation: { utf8: { a: false, b: false } }
* ```
*/
validation?: {
utf8: boolean | Record<string, true> | Record<string, false>;
};
}
/**
* Deserialize stream data as BSON documents.
*
* @param data - the buffer containing the serialized set of BSON documents.
* @param startIndex - the start index in the data Buffer where the deserialization is to start.
* @param numberOfDocuments - number of documents to deserialize.
* @param documents - an array where to store the deserialized documents.
* @param docStartIndex - the index in the documents array from where to start inserting documents.
* @param options - additional options used for the deserialization.
* @returns next index in the buffer after deserialization **x** numbers of documents.
* @public
*/
export declare function deserializeStream(data: Uint8Array | ArrayBuffer, startIndex: number, numberOfDocuments: number, documents: Document[], docStartIndex: number, options: DeserializeOptions): number;
/** @public */
export declare interface Document {
[key: string]: any;
}
/**
* A class representation of the BSON Double type.
* @public
* @category BSONType
*/
export declare class Double extends BSONValue {
get _bsontype(): 'Double';
value: number;
/**
* Create a Double type
*
* @param value - the number we want to represent as a double.
*/
constructor(value: number);
/**
* Attempt to create an double type from string.
*
* This method will throw a BSONError on any string input that is not representable as a IEEE-754 64-bit double.
* Notably, this method will also throw on the following string formats:
* - Strings in non-decimal and non-exponential formats (binary, hex, or octal digits)
* - Strings with characters other than numeric, floating point, or leading sign characters (Note: 'Infinity', '-Infinity', and 'NaN' input strings are still allowed)
* - Strings with leading and/or trailing whitespace
*
* Strings with leading zeros, however, are also allowed
*
* @param value - the string we want to represent as a double.
*/
static fromString(value: string): Double;
/**
* Access the number value.
*
* @returns returns the wrapped double number.
*/
valueOf(): number;
toJSON(): number;
toString(radix?: number): string;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface DoubleExtended {
$numberDouble: string;
}
/** @public */
export declare const EJSON: {
parse: typeof parse;
stringify: typeof stringify;
serialize: typeof EJSONserialize;
deserialize: typeof EJSONdeserialize;
};
/**
* Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
*
* @param ejson - The Extended JSON object to deserialize
* @param options - Optional settings passed to the parse method
*/
declare function EJSONdeserialize(ejson: Document, options?: EJSONOptions): any;
/** @public */
export declare type EJSONOptions = {
/**
* Output using the Extended JSON v1 spec
* @defaultValue `false`
*/
legacy?: boolean;
/**
* Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types
* @defaultValue `false` */
relaxed?: boolean;
/**
* Enable native bigint support
* @defaultValue `false`
*/
useBigInt64?: boolean;
};
/**
* Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
*
* @param value - The object to serialize
* @param options - Optional settings passed to the `stringify` function
*/
declare function EJSONserialize(value: any, options?: EJSONOptions): Document;
declare type InspectFn = (x: unknown, options?: unknown) => string;
/**
* A class representation of a BSON Int32 type.
* @public
* @category BSONType
*/
export declare class Int32 extends BSONValue {
get _bsontype(): 'Int32';
value: number;
/**
* Create an Int32 type
*
* @param value - the number we want to represent as an int32.
*/
constructor(value: number | string);
/**
* Attempt to create an Int32 type from string.
*
* This method will throw a BSONError on any string input that is not representable as an Int32.
* Notably, this method will also throw on the following string formats:
* - Strings in non-decimal formats (exponent notation, binary, hex, or octal digits)
* - Strings non-numeric and non-leading sign characters (ex: '2.0', '24,000')
* - Strings with leading and/or trailing whitespace
*
* Strings with leading zeros, however, are allowed.
*
* @param value - the string we want to represent as an int32.
*/
static fromString(value: string): Int32;
/**
* Access the number value.
*
* @returns returns the wrapped int32 number.
*/
valueOf(): number;
toString(radix?: number): string;
toJSON(): number;
/* Excluded from this release type: toExtendedJSON */
/* Excluded from this release type: fromExtendedJSON */
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
}
/** @public */
export declare interface Int32Extended {
$numberInt: string;
}
/**
* A class representing a 64-bit integer
* @public
* @category BSONType
* @remarks
* The internal representation of a long is the two given signed, 32-bit values.
* We use 32-bit pieces because these are the size of integers on which
* Javascript performs bit-operations. For operations like addition and
* multiplication, we split each number into 16 bit pieces, which can easily be
* multiplied within Javascript's floating-point representation without overflow
* or change in sign.
* In the algorithms below, we frequently reduce the negative case to the
* positive case by negating the input(s) and then post-processing the result.
* Note that we must ALWAYS check specially whether those values are MIN_VALUE
* (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
* a positive number, it overflows back into a negative). Not handling this
* case would often result in infinite recursion.
* Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
*/
export declare class Long extends BSONValue {
get _bsontype(): 'Long';
/** An indicator used to reliably determine if an object is a Long or not. */
get __isLong__(): boolean;
/**
* The high 32 bits as a signed value.
*/
high: number;
/**
* The low 32 bits as a signed value.
*/
low: number;
/**
* Whether unsigned or not.
*/
unsigned: boolean;
/**
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
*
* @param low - The low (signed) 32 bits of the long
* @param high - The high (signed) 32 bits of the long
* @param unsigned - Whether unsigned or not, defaults to signed
*/
constructor(low: number, high?: number, unsigned?: boolean);
/**
* Constructs a 64 bit two's-complement integer, given a bigint representation.
*
* @param value - BigInt representation of the long value
* @param unsigned - Whether unsigned or not, defaults to signed
*/
constructor(value: bigint, unsigned?: boolean);
/**
* Constructs a 64 bit two's-complement integer, given a string representation.
*
* @param value - String representation of the long value
* @param unsigned - Whether unsigned or not, defaults to signed
*/
constructor(value: string, unsigned?: boolean);
static TWO_PWR_24: Long;
/** Maximum unsigned value. */
static MAX_UNSIGNED_VALUE: Long;
/** Signed zero */
static ZERO: Long;
/** Unsigned zero. */
static UZERO: Long;
/** Signed one. */
static ONE: Long;
/** Unsigned one. */
static UONE: Long;
/** Signed negative one. */
static NEG_ONE: Long;
/** Maximum signed value. */
static MAX_VALUE: Long;
/** Minimum signed value. */
static MIN_VALUE: Long;
/**
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits.
* Each is assumed to use 32 bits.
* @param lowBits - The low 32 bits
* @param highBits - The high 32 bits
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
/**
* Returns a Long representing the given 32 bit integer value.
* @param value - The 32 bit integer in question
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromInt(value: number, unsigned?: boolean): Long;
/**
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
* @param value - The number in question
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromNumber(value: number, unsigned?: boolean): Long;
/**
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
* @param value - The number in question
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromBigInt(value: bigint, unsigned?: boolean): Long;
/* Excluded from this release type: _fromString */
/**
* Returns a signed Long representation of the given string, written using radix 10.
* Will throw an error if the given text is not exactly representable as a Long.
* Throws an error if any of the following conditions are true:
* - the string contains invalid characters for the radix 10
* - the string contains whitespace
* - the value the string represents is too large or too small to be a Long
* Unlike Long.fromString, this method does not coerce '+/-Infinity' and 'NaN' to Long.Zero
* @param str - The textual representation of the Long
* @returns The corresponding Long value
*/
static fromStringStrict(str: string): Long;
/**
* Returns a Long representation of the given string, written using the radix 10.
* Will throw an error if the given parameters are not exactly representable as a Long.
* Throws an error if any of the following conditions are true:
* - the string contains invalid characters for the given radix
* - the string contains whitespace
* - the value the string represents is too large or too small to be a Long
* Unlike Long.fromString, this method does not coerce '+/-Infinity' and 'NaN' to Long.Zero
* @param str - The textual representation of the Long
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromStringStrict(str: string, unsigned?: boolean): Long;
/**
* Returns a signed Long representation of the given string, written using the specified radix.
* Will throw an error if the given parameters are not exactly representable as a Long.
* Throws an error if any of the following conditions are true:
* - the string contains invalid characters for the given radix
* - the string contains whitespace
* - the value the string represents is too large or too small to be a Long
* Unlike Long.fromString, this method does not coerce '+/-Infinity' and 'NaN' to Long.Zero
* @param str - The textual representation of the Long
* @param radix - The radix in which the text is written (2-36), defaults to 10
* @returns The corresponding Long value
*/
static fromStringStrict(str: string, radix?: boolean): Long;
/**
* Returns a Long representation of the given string, written using the specified radix.
* Will throw an error if the given parameters are not exactly representable as a Long.
* Throws an error if any of the following conditions are true:
* - the string contains invalid characters for the given radix
* - the string contains whitespace
* - the value the string represents is too large or too small to be a Long
* Unlike Long.fromString, this method does not coerce '+/-Infinity' and 'NaN' to Long.Zero
* @param str - The textual representation of the Long
* @param unsigned - Whether unsigned or not, defaults to signed
* @param radix - The radix in which the text is written (2-36), defaults to 10
* @returns The corresponding Long value
*/
static fromStringStrict(str: string, unsigned?: boolean, radix?: number): Long;
/**
* Returns a signed Long representation of the given string, written using radix 10.
*
* If the input string is empty, this function will throw a BSONError.
*
* If input string does not have valid signed 64-bit Long representation, this method will return a coerced value:
* - inputs that overflow 64-bit signed long will be coerced to Long.MAX_VALUE and Long.MIN_VALUE respectively
* - 'NaN' or '+/-Infinity' are coerced to Long.ZERO
* - other invalid characters sequences have variable behavior
*
* @param str - The textual representation of the Long
* @returns The corresponding Long value
*/
static fromString(str: string): Long;
/**
* Returns a signed Long representation of the given string, written using the provided radix.
*
* If the input string is empty or a provided radix is not within (2-36), this function will throw a BSONError.
*
* If input parameters do not have valid signed 64-bit Long representation, this method will return a coerced value:
* - inputs that overflow 64-bit signed long will be coerced to Long.MAX_VALUE and Long.MIN_VALUE respectively
* - if the radix is less than 24, 'NaN' is coerced to Long.ZERO
* - if the radix is less than 35, '+/-Infinity' inputs are coerced to Long.ZERO
* - other invalid characters sequences have variable behavior
* @param str - The textual representation of the Long
* @param radix - The radix in which the text is written (2-36), defaults to 10
* @returns The corresponding Long value
*/
static fromString(str: string, radix?: number): Long;
/**
* Returns a Long representation of the given string, written using radix 10.
*
* If the input string is empty, this function will throw a BSONError.
*
* If input parameters do not have a valid 64-bit Long representation, this method will return a coerced value:
* - inputs that overflow 64-bit long will be coerced to max or min (if signed) values
* - if the radix is less than 24, 'NaN' is coerced to Long.ZERO
* - if the radix is less than 35, '+/-Infinity' inputs are coerced to Long.ZERO
* - other invalid characters sequences have variable behavior
* @param str - The textual representation of the Long
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromString(str: string, unsigned?: boolean): Long;
/**
* Returns a Long representation of the given string, written using the specified radix.
*
* If the input string is empty or a provided radix is not within (2-36), this function will throw a BSONError.
*
* If input parameters do not have a valid 64-bit Long representation, this method will return a coerced value:
* - inputs that overflow 64-bit long will be coerced to max or min (if signed) values
* - if the radix is less than 24, 'NaN' is coerced to Long.ZERO
* - if the radix is less than 35, '+/-Infinity' inputs are coerced to Long.ZERO
* - other invalid characters sequences have variable behavior
* @param str - The textual representation of the Long
* @param unsigned - Whether unsigned or not, defaults to signed
* @param radix - The radix in which the text is written (2-36), defaults to 10
* @returns The corresponding Long value
*/
static fromString(str: string, unsigned?: boolean, radix?: number): Long;
/**
* Creates a Long from its byte representation.
* @param bytes - Byte representation
* @param unsigned - Whether unsigned or not, defaults to signed
* @param le - Whether little or big endian, defaults to big endian
* @returns The corresponding Long value
*/
static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
/**
* Creates a Long from its little endian byte representation.
* @param bytes - Little endian byte representation
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
/**
* Creates a Long from its big endian byte representation.
* @param bytes - Big endian byte representation
* @param unsigned - Whether unsigned or not, defaults to signed
* @returns The corresponding Long value
*/
static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
/**
* Tests if the specified object is a Long.
*/
static isLong(value: unknown): value is Long;
/**
* Converts the specified value to a Long.
* @param unsigned - Whether unsigned or not, defaults to signed
*/
static fromValue(val: number | string | {
low: number;
high: number;
unsigned?: boolean;
}, unsigned?: boolean): Long;
/** Returns the sum of this and the specified Long. */
add(addend: string | number | Long | Timestamp): Long;
/**
* Returns the sum of this and the specified Long.
* @returns Sum
*/
and(other: string | number | Long | Timestamp): Long;
/**
* Compares this Long's value with the specified's.
* @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
*/
compare(other: string | number | Long | Timestamp): 0 | 1 | -1;
/** This is an alias of {@link Long.compare} */
comp(other: string | number | Long | Timestamp): 0 | 1 | -1;
/**
* Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
* @returns Quotient
*/