bson 7.1.1 → 7.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.
- package/README.md +8 -2
- package/bson.d.ts +156 -10
- package/lib/bson.bundle.js +479 -453
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +479 -453
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +479 -453
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +479 -453
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +480 -456
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -1
- package/src/binary.ts +2 -2
- package/src/bson.ts +6 -3
- package/src/extended_json.ts +63 -22
- package/src/objectid.ts +24 -10
- package/src/parser/calculate_size.ts +75 -68
- package/src/parser/deserializer.ts +227 -61
- package/src/parser/serializer.ts +272 -478
- package/src/timestamp.ts +157 -4
- package/src/utils/byte_utils.ts +8 -0
- package/src/utils/node_byte_utils.ts +12 -0
- package/src/utils/web_byte_utils.ts +43 -0
package/src/timestamp.ts
CHANGED
|
@@ -4,20 +4,53 @@ import type { Int32 } from './int_32';
|
|
|
4
4
|
import { Long } from './long';
|
|
5
5
|
import { type InspectFn, defaultInspect } from './parser/utils';
|
|
6
6
|
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
* @deprecated This type is no longer used internally and will be removed in a future version.
|
|
10
|
+
*/
|
|
8
11
|
export type TimestampOverrides =
|
|
9
12
|
| '_bsontype'
|
|
10
13
|
| 'toExtendedJSON'
|
|
11
14
|
| 'fromExtendedJSON'
|
|
12
15
|
| 'inspect'
|
|
13
16
|
| typeof bsonType;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*
|
|
21
|
+
* Inherited `Long` members surfaced on `Timestamp`.
|
|
22
|
+
* When `Long` gains a new member: add it here if it should pass through, or
|
|
23
|
+
* add a `@deprecated declare` line on the `Timestamp` class if it should be
|
|
24
|
+
* surfaced as deprecated. Anything left unclassified is silently dropped from
|
|
25
|
+
* the public type — preventing accidental behavioral bleed-through.
|
|
26
|
+
*/
|
|
27
|
+
type TimestampKept =
|
|
28
|
+
| 'toBigInt'
|
|
29
|
+
| 'toString'
|
|
30
|
+
| 'compare'
|
|
31
|
+
| 'equals'
|
|
32
|
+
| 'eq'
|
|
33
|
+
| 'notEquals'
|
|
34
|
+
| 'neq'
|
|
35
|
+
| 'ne'
|
|
36
|
+
| 'lessThan'
|
|
37
|
+
| 'lt'
|
|
38
|
+
| 'lessThanOrEqual'
|
|
39
|
+
| 'lte'
|
|
40
|
+
| 'le'
|
|
41
|
+
| 'greaterThan'
|
|
42
|
+
| 'gt'
|
|
43
|
+
| 'greaterThanOrEqual'
|
|
44
|
+
| 'gte'
|
|
45
|
+
| 'ge';
|
|
46
|
+
|
|
14
47
|
/** @public */
|
|
15
48
|
export type LongWithoutOverrides = new (
|
|
16
49
|
low: unknown,
|
|
17
50
|
high?: number | boolean,
|
|
18
51
|
unsigned?: boolean
|
|
19
52
|
) => {
|
|
20
|
-
[P in
|
|
53
|
+
[P in TimestampKept]: Long[P];
|
|
21
54
|
};
|
|
22
55
|
/** @public */
|
|
23
56
|
export const LongWithoutOverridesClass: LongWithoutOverrides =
|
|
@@ -45,6 +78,9 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
45
78
|
return 'Timestamp';
|
|
46
79
|
}
|
|
47
80
|
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use `Long.MAX_UNSIGNED_VALUE` instead.
|
|
83
|
+
*/
|
|
48
84
|
static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
49
85
|
|
|
50
86
|
/**
|
|
@@ -120,12 +156,18 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
120
156
|
};
|
|
121
157
|
}
|
|
122
158
|
|
|
123
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Returns a Timestamp represented by the given (32-bit) integer value.
|
|
161
|
+
* @deprecated Stores `value` in the low 32 bits (increment), leaving t = 0. Use `new Timestamp({ t, i })` or `Timestamp.fromBits(lowBits, highBits)` for explicit construction.
|
|
162
|
+
*/
|
|
124
163
|
static fromInt(value: number): Timestamp {
|
|
125
164
|
return new Timestamp(Long.fromInt(value, true));
|
|
126
165
|
}
|
|
127
166
|
|
|
128
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned.
|
|
169
|
+
* @deprecated Splits `value` across (t, i) as a uint64; the result rarely matches user intent. Use `new Timestamp({ t, i })` or `Timestamp.fromBits(lowBits, highBits)` for explicit construction.
|
|
170
|
+
*/
|
|
129
171
|
static fromNumber(value: number): Timestamp {
|
|
130
172
|
return new Timestamp(Long.fromNumber(value, true));
|
|
131
173
|
}
|
|
@@ -173,4 +215,115 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
173
215
|
const i = inspect(this.i, options);
|
|
174
216
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
175
217
|
}
|
|
218
|
+
|
|
219
|
+
// ********************
|
|
220
|
+
// **** DEPRECATED ****
|
|
221
|
+
// ********************
|
|
222
|
+
// Declare used to avoid runtime effects for field declaration.
|
|
223
|
+
// See: https://www.typescriptlang.org/docs/handbook/2/classes.html#type-only-field-declarations
|
|
224
|
+
|
|
225
|
+
// Arithmetic
|
|
226
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
227
|
+
declare add: Long['add'];
|
|
228
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
229
|
+
declare subtract: Long['subtract'];
|
|
230
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
231
|
+
declare sub: Long['sub'];
|
|
232
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
233
|
+
declare multiply: Long['multiply'];
|
|
234
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
235
|
+
declare mul: Long['mul'];
|
|
236
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
237
|
+
declare divide: Long['divide'];
|
|
238
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
239
|
+
declare div: Long['div'];
|
|
240
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
241
|
+
declare modulo: Long['modulo'];
|
|
242
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
243
|
+
declare mod: Long['mod'];
|
|
244
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
245
|
+
declare rem: Long['rem'];
|
|
246
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
247
|
+
declare negate: Long['negate'];
|
|
248
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
249
|
+
declare neg: Long['neg'];
|
|
250
|
+
|
|
251
|
+
// Bitwise / shifts
|
|
252
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
253
|
+
declare and: Long['and'];
|
|
254
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
255
|
+
declare or: Long['or'];
|
|
256
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
257
|
+
declare xor: Long['xor'];
|
|
258
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
259
|
+
declare not: Long['not'];
|
|
260
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
261
|
+
declare shiftLeft: Long['shiftLeft'];
|
|
262
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
263
|
+
declare shl: Long['shl'];
|
|
264
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
265
|
+
declare shiftRight: Long['shiftRight'];
|
|
266
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
267
|
+
declare shr: Long['shr'];
|
|
268
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
269
|
+
declare shiftRightUnsigned: Long['shiftRightUnsigned'];
|
|
270
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
271
|
+
declare shr_u: Long['shr_u'];
|
|
272
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
273
|
+
declare shru: Long['shru'];
|
|
274
|
+
|
|
275
|
+
// Signing
|
|
276
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
277
|
+
declare toSigned: Long['toSigned'];
|
|
278
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (this is a no-op). */
|
|
279
|
+
declare toUnsigned: Long['toUnsigned'];
|
|
280
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always false). */
|
|
281
|
+
declare isNegative: Long['isNegative'];
|
|
282
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
|
|
283
|
+
declare isPositive: Long['isPositive'];
|
|
284
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
|
|
285
|
+
declare unsigned: Long['unsigned'];
|
|
286
|
+
|
|
287
|
+
// Conversion
|
|
288
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
289
|
+
declare toInt: Long['toInt'];
|
|
290
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
291
|
+
declare toNumber: Long['toNumber'];
|
|
292
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
293
|
+
declare toBytes: Long['toBytes'];
|
|
294
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
295
|
+
declare toBytesLE: Long['toBytesLE'];
|
|
296
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
297
|
+
declare toBytesBE: Long['toBytesBE'];
|
|
298
|
+
|
|
299
|
+
// Other
|
|
300
|
+
/** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.t` for seconds since the Unix epoch. */
|
|
301
|
+
declare getHighBits: Long['getHighBits'];
|
|
302
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch. */
|
|
303
|
+
declare getHighBitsUnsigned: Long['getHighBitsUnsigned'];
|
|
304
|
+
/** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.i` for the increment ordinal. */
|
|
305
|
+
declare getLowBits: Long['getLowBits'];
|
|
306
|
+
/** @deprecated Not applicable to Timestamp; use `.i` for the increment ordinal. */
|
|
307
|
+
declare getLowBitsUnsigned: Long['getLowBitsUnsigned'];
|
|
308
|
+
|
|
309
|
+
/** @deprecated Not applicable to Timestamp; use `.i` instead. */
|
|
310
|
+
declare low: Long['low'];
|
|
311
|
+
/** @deprecated Not applicable to Timestamp; use `.t` instead. */
|
|
312
|
+
declare high: Long['high'];
|
|
313
|
+
|
|
314
|
+
/** @deprecated Use .compare() for general comparison, or .equals(), .lessThan(), .greaterThan() for specific cases. */
|
|
315
|
+
declare comp: Long['comp'];
|
|
316
|
+
/** @deprecated Compare `.t` and `.i` against `0` explicitly. */
|
|
317
|
+
declare isZero: Long['isZero'];
|
|
318
|
+
/** @deprecated Compare `.t` and `.i` against `0` explicitly. */
|
|
319
|
+
declare eqz: Long['eqz'];
|
|
320
|
+
|
|
321
|
+
/** @deprecated Not applicable to Timestamp. Use the bsonType symbol or _bsontype === 'Timestamp' to identify a Timestamp. */
|
|
322
|
+
declare __isLong__: Long['__isLong__'];
|
|
323
|
+
/** @deprecated Not applicable to Timestamp. */
|
|
324
|
+
declare getNumBitsAbs: Long['getNumBitsAbs'];
|
|
325
|
+
/** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
|
|
326
|
+
declare isEven: Long['isEven'];
|
|
327
|
+
/** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
|
|
328
|
+
declare isOdd: Long['isOdd'];
|
|
176
329
|
}
|
package/src/utils/byte_utils.ts
CHANGED
|
@@ -21,6 +21,14 @@ export type ByteUtils = {
|
|
|
21
21
|
compare: (buffer1: Uint8Array, buffer2: Uint8Array) => -1 | 0 | 1;
|
|
22
22
|
/** Concatenating all the Uint8Arrays in new Uint8Array. */
|
|
23
23
|
concat: (list: Uint8Array[]) => Uint8Array;
|
|
24
|
+
/** Copy bytes from source Uint8Array to target Uint8Array */
|
|
25
|
+
copy: (
|
|
26
|
+
source: Uint8Array,
|
|
27
|
+
target: Uint8Array,
|
|
28
|
+
targetStart?: number,
|
|
29
|
+
sourceStart?: number,
|
|
30
|
+
sourceEnd?: number
|
|
31
|
+
) => number;
|
|
24
32
|
/** Check if two Uint8Arrays are deep equal */
|
|
25
33
|
equals: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
26
34
|
/** Create a Uint8Array from an array of numbers */
|
|
@@ -104,6 +104,18 @@ export const nodeJsByteUtils = {
|
|
|
104
104
|
return Buffer.concat(list);
|
|
105
105
|
},
|
|
106
106
|
|
|
107
|
+
copy(
|
|
108
|
+
source: Uint8Array,
|
|
109
|
+
target: Uint8Array,
|
|
110
|
+
targetStart?: number,
|
|
111
|
+
sourceStart?: number,
|
|
112
|
+
sourceEnd?: number
|
|
113
|
+
): number {
|
|
114
|
+
return nodeJsByteUtils
|
|
115
|
+
.toLocalBufferType(source)
|
|
116
|
+
.copy(target, targetStart ?? 0, sourceStart ?? 0, sourceEnd ?? source.length);
|
|
117
|
+
},
|
|
118
|
+
|
|
107
119
|
equals(a: Uint8Array, b: Uint8Array): boolean {
|
|
108
120
|
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
109
121
|
},
|
|
@@ -155,6 +155,49 @@ export const webByteUtils = {
|
|
|
155
155
|
return result;
|
|
156
156
|
},
|
|
157
157
|
|
|
158
|
+
copy(
|
|
159
|
+
source: Uint8Array,
|
|
160
|
+
target: Uint8Array,
|
|
161
|
+
targetStart?: number,
|
|
162
|
+
sourceStart?: number,
|
|
163
|
+
sourceEnd?: number
|
|
164
|
+
): number {
|
|
165
|
+
// validate and standardize passed-in sourceEnd
|
|
166
|
+
if (sourceEnd !== undefined && sourceEnd < 0) {
|
|
167
|
+
throw new RangeError(
|
|
168
|
+
`The value of "sourceEnd" is out of range. It must be >= 0. Received ${sourceEnd}`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
sourceEnd = sourceEnd ?? source.length;
|
|
172
|
+
|
|
173
|
+
// validate and standardize passed-in sourceStart
|
|
174
|
+
if (sourceStart !== undefined && (sourceStart < 0 || sourceStart > sourceEnd)) {
|
|
175
|
+
throw new RangeError(
|
|
176
|
+
`The value of "sourceStart" is out of range. It must be >= 0 and <= ${sourceEnd}. Received ${sourceStart}`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
sourceStart = sourceStart ?? 0;
|
|
180
|
+
|
|
181
|
+
// validate and standardize passed-in targetStart
|
|
182
|
+
if (targetStart !== undefined && targetStart < 0) {
|
|
183
|
+
throw new RangeError(
|
|
184
|
+
`The value of "targetStart" is out of range. It must be >= 0. Received ${targetStart}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
targetStart = targetStart ?? 0;
|
|
188
|
+
|
|
189
|
+
// figure out how many bytes we can copy
|
|
190
|
+
const srcSlice = source.subarray(sourceStart, sourceEnd);
|
|
191
|
+
const maxLen = Math.min(srcSlice.length, target.length - targetStart);
|
|
192
|
+
if (maxLen <= 0) {
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// perform the copy
|
|
197
|
+
target.set(srcSlice.subarray(0, maxLen), targetStart);
|
|
198
|
+
return maxLen;
|
|
199
|
+
},
|
|
200
|
+
|
|
158
201
|
equals(uint8Array: Uint8Array, otherUint8Array: Uint8Array): boolean {
|
|
159
202
|
if (uint8Array.byteLength !== otherUint8Array.byteLength) {
|
|
160
203
|
return false;
|