bson 5.1.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +3 -126
  2. package/bson.d.ts +79 -22
  3. package/lib/binary.d.ts +182 -0
  4. package/lib/binary.d.ts.map +1 -0
  5. package/lib/bson.bundle.js +87 -89
  6. package/lib/bson.bundle.js.map +1 -1
  7. package/lib/bson.cjs +87 -89
  8. package/lib/bson.cjs.map +1 -1
  9. package/lib/bson.d.ts +97 -0
  10. package/lib/bson.d.ts.map +1 -0
  11. package/lib/bson.mjs +87 -89
  12. package/lib/bson.mjs.map +1 -1
  13. package/lib/bson_value.d.ts +10 -0
  14. package/lib/bson_value.d.ts.map +1 -0
  15. package/lib/code.d.ts +32 -0
  16. package/lib/code.d.ts.map +1 -0
  17. package/lib/constants.d.ts +107 -0
  18. package/lib/constants.d.ts.map +1 -0
  19. package/lib/db_ref.d.ts +40 -0
  20. package/lib/db_ref.d.ts.map +1 -0
  21. package/lib/decimal128.d.ts +34 -0
  22. package/lib/decimal128.d.ts.map +1 -0
  23. package/lib/double.d.ts +35 -0
  24. package/lib/double.d.ts.map +1 -0
  25. package/lib/error.d.ts +50 -0
  26. package/lib/error.d.ts.map +1 -0
  27. package/lib/extended_json.d.ts +82 -0
  28. package/lib/extended_json.d.ts.map +1 -0
  29. package/lib/index.d.ts +4 -0
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/int_32.d.ts +35 -0
  32. package/lib/int_32.d.ts.map +1 -0
  33. package/lib/long.d.ts +323 -0
  34. package/lib/long.d.ts.map +1 -0
  35. package/lib/max_key.d.ts +19 -0
  36. package/lib/max_key.d.ts.map +1 -0
  37. package/lib/min_key.d.ts +19 -0
  38. package/lib/min_key.d.ts.map +1 -0
  39. package/lib/objectid.d.ts +96 -0
  40. package/lib/objectid.d.ts.map +1 -0
  41. package/lib/regexp.d.ts +36 -0
  42. package/lib/regexp.d.ts.map +1 -0
  43. package/lib/symbol.d.ts +28 -0
  44. package/lib/symbol.d.ts.map +1 -0
  45. package/lib/timestamp.d.ts +66 -0
  46. package/lib/timestamp.d.ts.map +1 -0
  47. package/lib/validate_utf8.d.ts +10 -0
  48. package/lib/validate_utf8.d.ts.map +1 -0
  49. package/package.json +20 -20
  50. package/src/binary.ts +67 -43
  51. package/src/bson.ts +1 -1
  52. package/src/constants.ts +1 -1
  53. package/src/extended_json.ts +11 -3
  54. package/src/objectid.ts +11 -5
  55. package/src/parser/deserializer.ts +37 -12
  56. package/src/parser/serializer.ts +17 -4
  57. package/src/timestamp.ts +1 -1
  58. package/src/uuid_utils.ts +0 -33
@@ -0,0 +1,10 @@
1
+ /** @public */
2
+ export declare abstract class BSONValue {
3
+ /** @public */
4
+ abstract get _bsontype(): string;
5
+ /** @public */
6
+ abstract inspect(): string;
7
+ /** @internal */
8
+ abstract toExtendedJSON(): unknown;
9
+ }
10
+ //# sourceMappingURL=bson_value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bson_value.d.ts","sourceRoot":"","sources":["../src/bson_value.ts"],"names":[],"mappings":"AAEA,cAAc;AACd,8BAAsB,SAAS;IAC7B,cAAc;IACd,aAAoB,SAAS,IAAI,MAAM,CAAC;IAOxC,cAAc;aACE,OAAO,IAAI,MAAM;IAEjC,gBAAgB;IAChB,QAAQ,CAAC,cAAc,IAAI,OAAO;CACnC"}
package/lib/code.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { Document } from './bson';
2
+ import { BSONValue } from './bson_value';
3
+ /** @public */
4
+ export interface CodeExtended {
5
+ $code: string;
6
+ $scope?: Document;
7
+ }
8
+ /**
9
+ * A class representation of the BSON Code type.
10
+ * @public
11
+ * @category BSONType
12
+ */
13
+ export declare class Code extends BSONValue {
14
+ get _bsontype(): 'Code';
15
+ code: string;
16
+ scope: Document | null;
17
+ /**
18
+ * @param code - a string or function.
19
+ * @param scope - an optional scope for the function.
20
+ */
21
+ constructor(code: string | Function, scope?: Document | null);
22
+ toJSON(): {
23
+ code: string;
24
+ scope?: Document;
25
+ };
26
+ /** @internal */
27
+ toExtendedJSON(): CodeExtended;
28
+ /** @internal */
29
+ static fromExtendedJSON(doc: CodeExtended): Code;
30
+ inspect(): string;
31
+ }
32
+ //# sourceMappingURL=code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../src/code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,cAAc;AACd,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,IAAK,SAAQ,SAAS;IACjC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,EAAE,MAAM,CAAC;IAIb,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEvB;;;OAGG;gBACS,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,IAAI;IAM5D,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;KAAE;IAQ5C,gBAAgB;IAChB,cAAc,IAAI,YAAY;IAQ9B,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAShD,OAAO,IAAI,MAAM;CAMlB"}
@@ -0,0 +1,107 @@
1
+ /** @internal */
2
+ export declare const BSON_MAJOR_VERSION: 5;
3
+ /** @internal */
4
+ export declare const BSON_INT32_MAX = 2147483647;
5
+ /** @internal */
6
+ export declare const BSON_INT32_MIN = -2147483648;
7
+ /** @internal */
8
+ export declare const BSON_INT64_MAX: number;
9
+ /** @internal */
10
+ export declare const BSON_INT64_MIN: number;
11
+ /**
12
+ * Any integer up to 2^53 can be precisely represented by a double.
13
+ * @internal
14
+ */
15
+ export declare const JS_INT_MAX: number;
16
+ /**
17
+ * Any integer down to -2^53 can be precisely represented by a double.
18
+ * @internal
19
+ */
20
+ export declare const JS_INT_MIN: number;
21
+ /** Number BSON Type @internal */
22
+ export declare const BSON_DATA_NUMBER = 1;
23
+ /** String BSON Type @internal */
24
+ export declare const BSON_DATA_STRING = 2;
25
+ /** Object BSON Type @internal */
26
+ export declare const BSON_DATA_OBJECT = 3;
27
+ /** Array BSON Type @internal */
28
+ export declare const BSON_DATA_ARRAY = 4;
29
+ /** Binary BSON Type @internal */
30
+ export declare const BSON_DATA_BINARY = 5;
31
+ /** Binary BSON Type @internal */
32
+ export declare const BSON_DATA_UNDEFINED = 6;
33
+ /** ObjectId BSON Type @internal */
34
+ export declare const BSON_DATA_OID = 7;
35
+ /** Boolean BSON Type @internal */
36
+ export declare const BSON_DATA_BOOLEAN = 8;
37
+ /** Date BSON Type @internal */
38
+ export declare const BSON_DATA_DATE = 9;
39
+ /** null BSON Type @internal */
40
+ export declare const BSON_DATA_NULL = 10;
41
+ /** RegExp BSON Type @internal */
42
+ export declare const BSON_DATA_REGEXP = 11;
43
+ /** Code BSON Type @internal */
44
+ export declare const BSON_DATA_DBPOINTER = 12;
45
+ /** Code BSON Type @internal */
46
+ export declare const BSON_DATA_CODE = 13;
47
+ /** Symbol BSON Type @internal */
48
+ export declare const BSON_DATA_SYMBOL = 14;
49
+ /** Code with Scope BSON Type @internal */
50
+ export declare const BSON_DATA_CODE_W_SCOPE = 15;
51
+ /** 32 bit Integer BSON Type @internal */
52
+ export declare const BSON_DATA_INT = 16;
53
+ /** Timestamp BSON Type @internal */
54
+ export declare const BSON_DATA_TIMESTAMP = 17;
55
+ /** Long BSON Type @internal */
56
+ export declare const BSON_DATA_LONG = 18;
57
+ /** Decimal128 BSON Type @internal */
58
+ export declare const BSON_DATA_DECIMAL128 = 19;
59
+ /** MinKey BSON Type @internal */
60
+ export declare const BSON_DATA_MIN_KEY = 255;
61
+ /** MaxKey BSON Type @internal */
62
+ export declare const BSON_DATA_MAX_KEY = 127;
63
+ /** Binary Default Type @internal */
64
+ export declare const BSON_BINARY_SUBTYPE_DEFAULT = 0;
65
+ /** Binary Function Type @internal */
66
+ export declare const BSON_BINARY_SUBTYPE_FUNCTION = 1;
67
+ /** Binary Byte Array Type @internal */
68
+ export declare const BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
69
+ /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
70
+ export declare const BSON_BINARY_SUBTYPE_UUID = 3;
71
+ /** Binary UUID Type @internal */
72
+ export declare const BSON_BINARY_SUBTYPE_UUID_NEW = 4;
73
+ /** Binary MD5 Type @internal */
74
+ export declare const BSON_BINARY_SUBTYPE_MD5 = 5;
75
+ /** Encrypted BSON type @internal */
76
+ export declare const BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
77
+ /** Column BSON type @internal */
78
+ export declare const BSON_BINARY_SUBTYPE_COLUMN = 7;
79
+ /** Binary User Defined Type @internal */
80
+ export declare const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
81
+ /** @public */
82
+ export declare const BSONType: Readonly<{
83
+ readonly double: 1;
84
+ readonly string: 2;
85
+ readonly object: 3;
86
+ readonly array: 4;
87
+ readonly binData: 5;
88
+ readonly undefined: 6;
89
+ readonly objectId: 7;
90
+ readonly bool: 8;
91
+ readonly date: 9;
92
+ readonly null: 10;
93
+ readonly regex: 11;
94
+ readonly dbPointer: 12;
95
+ readonly javascript: 13;
96
+ readonly symbol: 14;
97
+ readonly javascriptWithScope: 15;
98
+ readonly int: 16;
99
+ readonly timestamp: 17;
100
+ readonly long: 18;
101
+ readonly decimal: 19;
102
+ readonly minKey: -1;
103
+ readonly maxKey: 127;
104
+ }>;
105
+ /** @public */
106
+ export type BSONType = (typeof BSONType)[keyof typeof BSONType];
107
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,GAAa,CAAC;AAE7C,gBAAgB;AAChB,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,gBAAgB;AAChB,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,gBAAgB;AAChB,eAAO,MAAM,cAAc,QAAsB,CAAC;AAClD,gBAAgB;AAChB,eAAO,MAAM,cAAc,QAAmB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAkB,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAmB,CAAC;AAE3C,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,gCAAgC;AAChC,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,iCAAiC;AACjC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,mCAAmC;AACnC,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,kCAAkC;AAClC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,+BAA+B;AAC/B,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,+BAA+B;AAC/B,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,+BAA+B;AAC/B,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,+BAA+B;AAC/B,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,yCAAyC;AACzC,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,oCAAoC;AACpC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,+BAA+B;AAC/B,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,qCAAqC;AACrC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,iCAAiC;AACjC,eAAO,MAAM,iBAAiB,MAAO,CAAC;AAEtC,iCAAiC;AACjC,eAAO,MAAM,iBAAiB,MAAO,CAAC;AAEtC,oCAAoC;AACpC,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,qCAAqC;AACrC,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,uCAAuC;AACvC,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,gGAAgG;AAChG,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,iCAAiC;AACjC,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,gCAAgC;AAChC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,oCAAoC;AACpC,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C,iCAAiC;AACjC,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,yCAAyC;AACzC,eAAO,MAAM,gCAAgC,MAAM,CAAC;AAEpD,cAAc;AACd,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;EAsBV,CAAC;AAEZ,cAAc;AACd,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { Document } from './bson';
2
+ import { BSONValue } from './bson_value';
3
+ import type { EJSONOptions } from './extended_json';
4
+ import type { ObjectId } from './objectid';
5
+ /** @public */
6
+ export interface DBRefLike {
7
+ $ref: string;
8
+ $id: ObjectId;
9
+ $db?: string;
10
+ }
11
+ /** @internal */
12
+ export declare function isDBRefLike(value: unknown): value is DBRefLike;
13
+ /**
14
+ * A class representation of the BSON DBRef type.
15
+ * @public
16
+ * @category BSONType
17
+ */
18
+ export declare class DBRef extends BSONValue {
19
+ get _bsontype(): 'DBRef';
20
+ collection: string;
21
+ oid: ObjectId;
22
+ db?: string;
23
+ fields: Document;
24
+ /**
25
+ * @param collection - the collection name.
26
+ * @param oid - the reference ObjectId.
27
+ * @param db - optional db name, if omitted the reference is local to the current db.
28
+ */
29
+ constructor(collection: string, oid: ObjectId, db?: string, fields?: Document);
30
+ /** @internal */
31
+ get namespace(): string;
32
+ set namespace(value: string);
33
+ toJSON(): DBRefLike & Document;
34
+ /** @internal */
35
+ toExtendedJSON(options?: EJSONOptions): DBRefLike;
36
+ /** @internal */
37
+ static fromExtendedJSON(doc: DBRefLike): DBRef;
38
+ inspect(): string;
39
+ }
40
+ //# sourceMappingURL=db_ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db_ref.d.ts","sourceRoot":"","sources":["../src/db_ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,cAAc;AACd,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAW9D;AAED;;;;GAIG;AACH,qBAAa,KAAM,SAAQ,SAAS;IAClC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,UAAU,EAAG,MAAM,CAAC;IACpB,GAAG,EAAG,QAAQ,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAG,QAAQ,CAAC;IAElB;;;;OAIG;gBACS,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ;IAmB7E,gBAAgB;IAChB,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,EAE1B;IAED,MAAM,IAAI,SAAS,GAAG,QAAQ;IAa9B,gBAAgB;IAChB,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS;IAgBjD,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,SAAS,GAAG,KAAK;IAa9C,OAAO,IAAI,MAAM;CAQlB"}
@@ -0,0 +1,34 @@
1
+ import { BSONValue } from './bson_value';
2
+ /** @public */
3
+ export interface Decimal128Extended {
4
+ $numberDecimal: string;
5
+ }
6
+ /**
7
+ * A class representation of the BSON Decimal128 type.
8
+ * @public
9
+ * @category BSONType
10
+ */
11
+ export declare class Decimal128 extends BSONValue {
12
+ get _bsontype(): 'Decimal128';
13
+ readonly bytes: Uint8Array;
14
+ /**
15
+ * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
16
+ * or a string representation as returned by .toString()
17
+ */
18
+ constructor(bytes: Uint8Array | string);
19
+ /**
20
+ * Create a Decimal128 instance from a string representation
21
+ *
22
+ * @param representation - a numeric string representation.
23
+ */
24
+ static fromString(representation: string): Decimal128;
25
+ /** Create a string representation of the raw Decimal128 value */
26
+ toString(): string;
27
+ toJSON(): Decimal128Extended;
28
+ /** @internal */
29
+ toExtendedJSON(): Decimal128Extended;
30
+ /** @internal */
31
+ static fromExtendedJSON(doc: Decimal128Extended): Decimal128;
32
+ inspect(): string;
33
+ }
34
+ //# sourceMappingURL=decimal128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal128.d.ts","sourceRoot":"","sources":["../src/decimal128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAuHzC,cAAc;AACd,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,SAAS;IACvC,IAAI,SAAS,IAAI,YAAY,CAE5B;IAED,QAAQ,CAAC,KAAK,EAAG,UAAU,CAAC;IAE5B;;;OAGG;gBACS,KAAK,EAAE,UAAU,GAAG,MAAM;IActC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU;IA+XrD,iEAAiE;IACjE,QAAQ,IAAI,MAAM;IAmNlB,MAAM,IAAI,kBAAkB;IAI5B,gBAAgB;IAChB,cAAc,IAAI,kBAAkB;IAIpC,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,GAAG,UAAU;IAS5D,OAAO,IAAI,MAAM;CAGlB"}
@@ -0,0 +1,35 @@
1
+ import { BSONValue } from './bson_value';
2
+ import type { EJSONOptions } from './extended_json';
3
+ /** @public */
4
+ export interface DoubleExtended {
5
+ $numberDouble: string;
6
+ }
7
+ /**
8
+ * A class representation of the BSON Double type.
9
+ * @public
10
+ * @category BSONType
11
+ */
12
+ export declare class Double extends BSONValue {
13
+ get _bsontype(): 'Double';
14
+ value: number;
15
+ /**
16
+ * Create a Double type
17
+ *
18
+ * @param value - the number we want to represent as a double.
19
+ */
20
+ constructor(value: number);
21
+ /**
22
+ * Access the number value.
23
+ *
24
+ * @returns returns the wrapped double number.
25
+ */
26
+ valueOf(): number;
27
+ toJSON(): number;
28
+ toString(radix?: number): string;
29
+ /** @internal */
30
+ toExtendedJSON(options?: EJSONOptions): number | DoubleExtended;
31
+ /** @internal */
32
+ static fromExtendedJSON(doc: DoubleExtended, options?: EJSONOptions): number | Double;
33
+ inspect(): string;
34
+ }
35
+ //# sourceMappingURL=double.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"double.d.ts","sourceRoot":"","sources":["../src/double.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,cAAc;AACd,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,SAAS;IACnC,IAAI,SAAS,IAAI,QAAQ,CAExB;IAED,KAAK,EAAG,MAAM,CAAC;IACf;;;;OAIG;gBACS,KAAK,EAAE,MAAM;IASzB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB,MAAM,IAAI,MAAM;IAIhB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhC,gBAAgB;IAChB,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,cAAc;IAgB/D,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,MAAM;IAUrF,OAAO,IAAI,MAAM;CAIlB"}
package/lib/error.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @public
3
+ * @category Error
4
+ *
5
+ * `BSONError` objects are thrown when BSON ecounters an error.
6
+ *
7
+ * This is the parent class for all the other errors thrown by this library.
8
+ */
9
+ export declare class BSONError extends Error {
10
+ /**
11
+ * @internal
12
+ * The underlying algorithm for isBSONError may change to improve how strict it is
13
+ * about determining if an input is a BSONError. But it must remain backwards compatible
14
+ * with previous minors & patches of the current major version.
15
+ */
16
+ protected get bsonError(): true;
17
+ get name(): string;
18
+ constructor(message: string);
19
+ /**
20
+ * @public
21
+ *
22
+ * All errors thrown from the BSON library inherit from `BSONError`.
23
+ * This method can assist with determining if an error originates from the BSON library
24
+ * even if it does not pass an `instanceof` check against this class' constructor.
25
+ *
26
+ * @param value - any javascript value that needs type checking
27
+ */
28
+ static isBSONError(value: unknown): value is BSONError;
29
+ }
30
+ /**
31
+ * @public
32
+ * @category Error
33
+ */
34
+ export declare class BSONVersionError extends BSONError {
35
+ get name(): 'BSONVersionError';
36
+ constructor();
37
+ }
38
+ /**
39
+ * @public
40
+ * @category Error
41
+ *
42
+ * An error generated when BSON functions encounter an unexpected input
43
+ * or reaches an unexpected/invalid internal state
44
+ *
45
+ */
46
+ export declare class BSONRuntimeError extends BSONError {
47
+ get name(): 'BSONRuntimeError';
48
+ constructor(message: string);
49
+ }
50
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;;;OAKG;IACH,SAAS,KAAK,SAAS,IAAI,IAAI,CAE9B;IAED,IAAa,IAAI,IAAI,MAAM,CAE1B;gBAEW,OAAO,EAAE,MAAM;IAI3B;;;;;;;;OAQG;WACW,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS;CAY9D;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,IAAI,IAAI,IAAI,kBAAkB,CAE7B;;CAOF;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,IAAI,IAAI,IAAI,kBAAkB,CAE7B;gBAEW,OAAO,EAAE,MAAM;CAG5B"}
@@ -0,0 +1,82 @@
1
+ import type { Document } from './bson';
2
+ /** @public */
3
+ export type EJSONOptions = {
4
+ /**
5
+ * Output using the Extended JSON v1 spec
6
+ * @defaultValue `false`
7
+ */
8
+ legacy?: boolean;
9
+ /**
10
+ * Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types
11
+ * @defaultValue `false` */
12
+ relaxed?: boolean;
13
+ /**
14
+ * Enable native bigint support
15
+ * @defaultValue `false`
16
+ */
17
+ useBigInt64?: boolean;
18
+ };
19
+ /**
20
+ * Parse an Extended JSON string, constructing the JavaScript value or object described by that
21
+ * string.
22
+ *
23
+ * @example
24
+ * ```js
25
+ * const { EJSON } = require('bson');
26
+ * const text = '{ "int32": { "$numberInt": "10" } }';
27
+ *
28
+ * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
29
+ * console.log(EJSON.parse(text, { relaxed: false }));
30
+ *
31
+ * // prints { int32: 10 }
32
+ * console.log(EJSON.parse(text));
33
+ * ```
34
+ */
35
+ declare function parse(text: string, options?: EJSONOptions): any;
36
+ /**
37
+ * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
38
+ * function is specified or optionally including only the specified properties if a replacer array
39
+ * is specified.
40
+ *
41
+ * @param value - The value to convert to extended JSON
42
+ * @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
43
+ * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
44
+ * @param options - Optional settings
45
+ *
46
+ * @example
47
+ * ```js
48
+ * const { EJSON } = require('bson');
49
+ * const Int32 = require('mongodb').Int32;
50
+ * const doc = { int32: new Int32(10) };
51
+ *
52
+ * // prints '{"int32":{"$numberInt":"10"}}'
53
+ * console.log(EJSON.stringify(doc, { relaxed: false }));
54
+ *
55
+ * // prints '{"int32":10}'
56
+ * console.log(EJSON.stringify(doc));
57
+ * ```
58
+ */
59
+ declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONOptions, space?: string | number, options?: EJSONOptions): string;
60
+ /**
61
+ * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
62
+ *
63
+ * @param value - The object to serialize
64
+ * @param options - Optional settings passed to the `stringify` function
65
+ */
66
+ declare function EJSONserialize(value: any, options?: EJSONOptions): Document;
67
+ /**
68
+ * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
69
+ *
70
+ * @param ejson - The Extended JSON object to deserialize
71
+ * @param options - Optional settings passed to the parse method
72
+ */
73
+ declare function EJSONdeserialize(ejson: Document, options?: EJSONOptions): any;
74
+ /** @public */
75
+ declare const EJSON: {
76
+ parse: typeof parse;
77
+ stringify: typeof stringify;
78
+ serialize: typeof EJSONserialize;
79
+ deserialize: typeof EJSONdeserialize;
80
+ };
81
+ export { EJSON };
82
+ //# sourceMappingURL=extended_json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extended_json.d.ts","sourceRoot":"","sources":["../src/extended_json.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAuBvC,cAAc;AACd,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;+BAE2B;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAqWF;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,GAAG,CAcxD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,SAAS,CAEhB,KAAK,EAAE,GAAG,EAEV,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,YAAY,EAC7F,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,YAAY,GACrB,MAAM,CAgBR;AAED;;;;;GAKG;AAEH,iBAAS,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,QAAQ,CAGpE;AAED;;;;;GAKG;AAEH,iBAAS,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,GAAG,CAGtE;AAED,cAAc;AACd,QAAA,MAAM,KAAK,EAAE;IACX,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,SAAS,EAAE,OAAO,cAAc,CAAC;IACjC,WAAW,EAAE,OAAO,gBAAgB,CAAC;CAChB,CAAC;AAMxB,OAAO,EAAE,KAAK,EAAE,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import * as BSON from './bson';
2
+ export * from './bson';
3
+ export { BSON };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAK/B,cAAc,QAAQ,CAAC;AAKvB,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { BSONValue } from './bson_value';
2
+ import type { EJSONOptions } from './extended_json';
3
+ /** @public */
4
+ export interface Int32Extended {
5
+ $numberInt: string;
6
+ }
7
+ /**
8
+ * A class representation of a BSON Int32 type.
9
+ * @public
10
+ * @category BSONType
11
+ */
12
+ export declare class Int32 extends BSONValue {
13
+ get _bsontype(): 'Int32';
14
+ value: number;
15
+ /**
16
+ * Create an Int32 type
17
+ *
18
+ * @param value - the number we want to represent as an int32.
19
+ */
20
+ constructor(value: number | string);
21
+ /**
22
+ * Access the number value.
23
+ *
24
+ * @returns returns the wrapped int32 number.
25
+ */
26
+ valueOf(): number;
27
+ toString(radix?: number): string;
28
+ toJSON(): number;
29
+ /** @internal */
30
+ toExtendedJSON(options?: EJSONOptions): number | Int32Extended;
31
+ /** @internal */
32
+ static fromExtendedJSON(doc: Int32Extended, options?: EJSONOptions): number | Int32;
33
+ inspect(): string;
34
+ }
35
+ //# sourceMappingURL=int_32.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int_32.d.ts","sourceRoot":"","sources":["../src/int_32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,cAAc;AACd,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,KAAM,SAAQ,SAAS;IAClC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,KAAK,EAAG,MAAM,CAAC;IACf;;;;OAIG;gBACS,KAAK,EAAE,MAAM,GAAG,MAAM;IASlC;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhC,MAAM,IAAI,MAAM;IAIhB,gBAAgB;IAChB,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,aAAa;IAK9D,gBAAgB;IAChB,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,KAAK;IASnF,OAAO,IAAI,MAAM;CAGlB"}