bson 6.8.0 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bson.d.ts CHANGED
@@ -26,10 +26,57 @@ export declare class Binary extends BSONValue {
26
26
  static readonly SUBTYPE_COLUMN = 7;
27
27
  /** Sensitive BSON type */
28
28
  static readonly SUBTYPE_SENSITIVE = 8;
29
+ /** Vector BSON type */
30
+ static readonly SUBTYPE_VECTOR = 9;
29
31
  /** User BSON type */
30
32
  static readonly SUBTYPE_USER_DEFINED = 128;
33
+ /** datatype of a Binary Vector (subtype: 9) */
34
+ static readonly VECTOR_TYPE: Readonly<{
35
+ readonly Int8: 3;
36
+ readonly Float32: 39;
37
+ readonly PackedBit: 16;
38
+ }>;
39
+ /**
40
+ * The bytes of the Binary value.
41
+ *
42
+ * The format of a Binary value in BSON is defined as:
43
+ * ```txt
44
+ * binary ::= int32 subtype (byte*)
45
+ * ```
46
+ *
47
+ * This `buffer` is the "(byte*)" segment.
48
+ *
49
+ * Unless the value is subtype 2, then deserialize will read the first 4 bytes as an int32 and set this to the remaining bytes.
50
+ *
51
+ * ```txt
52
+ * binary ::= int32 unsigned_byte(2) int32 (byte*)
53
+ * ```
54
+ *
55
+ * @see https://bsonspec.org/spec.html
56
+ */
31
57
  buffer: Uint8Array;
58
+ /**
59
+ * The binary subtype.
60
+ *
61
+ * Current defined values are:
62
+ *
63
+ * - `unsigned_byte(0)` Generic binary subtype
64
+ * - `unsigned_byte(1)` Function
65
+ * - `unsigned_byte(2)` Binary (Deprecated)
66
+ * - `unsigned_byte(3)` UUID (Deprecated)
67
+ * - `unsigned_byte(4)` UUID
68
+ * - `unsigned_byte(5)` MD5
69
+ * - `unsigned_byte(6)` Encrypted BSON value
70
+ * - `unsigned_byte(7)` Compressed BSON column
71
+ * - `unsigned_byte(8)` Sensitive
72
+ * - `unsigned_byte(9)` Vector
73
+ * - `unsigned_byte(128)` - `unsigned_byte(255)` User defined
74
+ */
32
75
  sub_type: number;
76
+ /**
77
+ * The Binary's `buffer` can be larger than the Binary's content.
78
+ * This property is used to determine where the content ends in the buffer.
79
+ */
33
80
  position: number;
34
81
  /**
35
82
  * Create a new Binary instance.
@@ -51,12 +98,12 @@ export declare class Binary extends BSONValue {
51
98
  */
52
99
  write(sequence: BinarySequence, offset: number): void;
53
100
  /**
54
- * Reads **length** bytes starting at **position**.
101
+ * Returns a view of **length** bytes starting at **position**.
55
102
  *
56
103
  * @param position - read from the given position in the Binary.
57
104
  * @param length - the number of bytes to read.
58
105
  */
59
- read(position: number, length: number): BinarySequence;
106
+ read(position: number, length: number): Uint8Array;
60
107
  /** returns a view of the binary value as a Uint8Array */
61
108
  value(): Uint8Array;
62
109
  /** the length of the binary sequence */
@@ -71,6 +118,56 @@ export declare class Binary extends BSONValue {
71
118
  static createFromBase64(base64: string, subType?: number): Binary;
72
119
  /* Excluded from this release type: fromExtendedJSON */
73
120
  inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
121
+ /**
122
+ * If this Binary represents a Int8 Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.Int8`),
123
+ * returns a copy of the bytes in a new Int8Array.
124
+ *
125
+ * If the Binary is not a Vector, or the datatype is not Int8, an error is thrown.
126
+ */
127
+ toInt8Array(): Int8Array;
128
+ /**
129
+ * If this Binary represents a Float32 Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.Float32`),
130
+ * returns a copy of the bytes in a new Float32Array.
131
+ *
132
+ * If the Binary is not a Vector, or the datatype is not Float32, an error is thrown.
133
+ */
134
+ toFloat32Array(): Float32Array;
135
+ /**
136
+ * If this Binary represents packed bit Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit`),
137
+ * returns a copy of the bytes that are packed bits.
138
+ *
139
+ * Use `toBits` to get the unpacked bits.
140
+ *
141
+ * If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.
142
+ */
143
+ toPackedBits(): Uint8Array;
144
+ /**
145
+ * If this Binary represents a Packed bit Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit`),
146
+ * returns a copy of the bit unpacked into a new Int8Array.
147
+ *
148
+ * Use `toPackedBits` to get the bits still in packed form.
149
+ *
150
+ * If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.
151
+ */
152
+ toBits(): Int8Array;
153
+ /**
154
+ * Constructs a Binary representing an Int8 Vector.
155
+ * @param array - The array to store as a view on the Binary class
156
+ */
157
+ static fromInt8Array(array: Int8Array): Binary;
158
+ /** Constructs a Binary representing an Float32 Vector. */
159
+ static fromFloat32Array(array: Float32Array): Binary;
160
+ /**
161
+ * Constructs a Binary representing a packed bit Vector.
162
+ *
163
+ * Use `fromBits` to pack an array of 1s and 0s.
164
+ */
165
+ static fromPackedBits(array: Uint8Array, padding?: number): Binary;
166
+ /**
167
+ * Constructs a Binary representing an Packed Bit Vector.
168
+ * @param array - The array of 1s and 0s to pack into the Binary instance
169
+ */
170
+ static fromBits(bits: ArrayLike<number>): Binary;
74
171
  }
75
172
 
76
173
  /** @public */
@@ -151,6 +248,10 @@ declare namespace BSON {
151
248
  }
152
249
  export { BSON }
153
250
 
251
+ /* Excluded from this release type: BSON_MAJOR_VERSION */
252
+
253
+ /* Excluded from this release type: BSON_VERSION_SYMBOL */
254
+
154
255
  /**
155
256
  * @public
156
257
  * @experimental
@@ -311,6 +412,7 @@ export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
311
412
  export declare abstract class BSONValue {
312
413
  /** @public */
313
414
  abstract get _bsontype(): string;
415
+ /* Excluded from this release type: [BSON_VERSION_SYMBOL] */
314
416
  /**
315
417
  * @public
316
418
  * Prints a human-readable string of BSON value information
@@ -367,6 +469,8 @@ declare type ByteUtils = {
367
469
  encodeUTF8Into: (destination: Uint8Array, source: string, byteOffset: number) => number;
368
470
  /** Generate a Uint8Array filled with random bytes with byteLength */
369
471
  randomBytes: (byteLength: number) => Uint8Array;
472
+ /** Interprets `buffer` as an array of 32-bit values and swaps the byte order in-place. */
473
+ swap32: (buffer: Uint8Array) => Uint8Array;
370
474
  };
371
475
 
372
476
  /* Excluded declaration from this release type: ByteUtils */
@@ -1206,6 +1310,8 @@ export declare interface MinKeyExtended {
1206
1310
  * A collection of functions that get or set various numeric types and bit widths from a Uint8Array.
1207
1311
  */
1208
1312
  declare type NumberUtils = {
1313
+ /** Is true if the current system is big endian. */
1314
+ isBigEndian: boolean;
1209
1315
  /**
1210
1316
  * Parses a signed int32 at offset. Throws a `RangeError` if value is negative.
1211
1317
  */
@@ -1285,6 +1391,7 @@ export declare class ObjectId extends BSONValue {
1285
1391
  */
1286
1392
  get id(): Uint8Array;
1287
1393
  set id(value: Uint8Array);
1394
+ /* Excluded from this release type: validateHexString */
1288
1395
  /** Returns the ObjectId id as a 24 lowercase character hex string representation */
1289
1396
  toHexString(): string;
1290
1397
  /* Excluded from this release type: getInc */
@@ -1472,10 +1579,20 @@ declare function stringify(value: any, replacer?: (number | string)[] | ((this:
1472
1579
  /**
1473
1580
  * @public
1474
1581
  * @category BSONType
1582
+ *
1583
+ * A special type for _internal_ MongoDB use and is **not** associated with the regular Date type.
1475
1584
  */
1476
1585
  export declare class Timestamp extends LongWithoutOverridesClass {
1477
1586
  get _bsontype(): 'Timestamp';
1478
1587
  static readonly MAX_VALUE: Long;
1588
+ /**
1589
+ * An incrementing ordinal for operations within a given second.
1590
+ */
1591
+ get i(): number;
1592
+ /**
1593
+ * A `time_t` value measuring seconds since the Unix epoch
1594
+ */
1595
+ get t(): number;
1479
1596
  /**
1480
1597
  * @param int - A 64-bit bigint representing the Timestamp.
1481
1598
  */