bson 6.9.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 */
@@ -372,6 +469,8 @@ declare type ByteUtils = {
372
469
  encodeUTF8Into: (destination: Uint8Array, source: string, byteOffset: number) => number;
373
470
  /** Generate a Uint8Array filled with random bytes with byteLength */
374
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;
375
474
  };
376
475
 
377
476
  /* Excluded declaration from this release type: ByteUtils */
@@ -1211,6 +1310,8 @@ export declare interface MinKeyExtended {
1211
1310
  * A collection of functions that get or set various numeric types and bit widths from a Uint8Array.
1212
1311
  */
1213
1312
  declare type NumberUtils = {
1313
+ /** Is true if the current system is big endian. */
1314
+ isBigEndian: boolean;
1214
1315
  /**
1215
1316
  * Parses a signed int32 at offset. Throws a `RangeError` if value is negative.
1216
1317
  */