bson 6.8.1 → 6.9.1
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 +16 -0
- package/lib/bson.bundle.js +251 -189
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +251 -189
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +251 -189
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +255 -191
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +22 -21
- package/src/bson_value.ts +2 -1
- package/src/constants.ts +3 -0
- package/src/decimal128.ts +1 -1
- package/src/extended_json.ts +3 -2
- package/src/long.ts +0 -1
- package/src/objectid.ts +25 -4
- package/src/parser/calculate_size.ts +1 -1
- package/src/parser/serializer.ts +196 -188
- package/src/parser/utils.ts +43 -9
- package/src/timestamp.ts +19 -3
package/src/parser/utils.ts
CHANGED
|
@@ -1,31 +1,65 @@
|
|
|
1
|
+
const map = new WeakMap<object, string>();
|
|
2
|
+
|
|
3
|
+
const TYPES = {
|
|
4
|
+
ArrayBuffer: '[object ArrayBuffer]',
|
|
5
|
+
SharedArrayBuffer: '[object SharedArrayBuffer]',
|
|
6
|
+
Uint8Array: '[object Uint8Array]',
|
|
7
|
+
BigInt64Array: '[object BigInt64Array]',
|
|
8
|
+
BigUint64Array: '[object BigUint64Array]',
|
|
9
|
+
RegExp: '[object RegExp]',
|
|
10
|
+
Map: '[object Map]',
|
|
11
|
+
Date: '[object Date]'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the prototype.toString() of a value.
|
|
16
|
+
* If the value is an object, it will cache the result in a WeakMap for future use.
|
|
17
|
+
*/
|
|
18
|
+
function getPrototypeString(value: unknown): string {
|
|
19
|
+
let str = map.get(value as object);
|
|
20
|
+
|
|
21
|
+
if (!str) {
|
|
22
|
+
str = Object.prototype.toString.call(value);
|
|
23
|
+
if (value !== null && typeof value === 'object') {
|
|
24
|
+
map.set(value, str);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
|
|
1
30
|
export function isAnyArrayBuffer(value: unknown): value is ArrayBuffer {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
);
|
|
31
|
+
const type = getPrototypeString(value);
|
|
32
|
+
return type === TYPES.ArrayBuffer || type === TYPES.SharedArrayBuffer;
|
|
5
33
|
}
|
|
6
34
|
|
|
7
35
|
export function isUint8Array(value: unknown): value is Uint8Array {
|
|
8
|
-
|
|
36
|
+
const type = getPrototypeString(value);
|
|
37
|
+
return type === TYPES.Uint8Array;
|
|
9
38
|
}
|
|
10
39
|
|
|
11
40
|
export function isBigInt64Array(value: unknown): value is BigInt64Array {
|
|
12
|
-
|
|
41
|
+
const type = getPrototypeString(value);
|
|
42
|
+
return type === TYPES.BigInt64Array;
|
|
13
43
|
}
|
|
14
44
|
|
|
15
45
|
export function isBigUInt64Array(value: unknown): value is BigUint64Array {
|
|
16
|
-
|
|
46
|
+
const type = getPrototypeString(value);
|
|
47
|
+
return type === TYPES.BigUint64Array;
|
|
17
48
|
}
|
|
18
49
|
|
|
19
50
|
export function isRegExp(d: unknown): d is RegExp {
|
|
20
|
-
|
|
51
|
+
const type = getPrototypeString(d);
|
|
52
|
+
return type === TYPES.RegExp;
|
|
21
53
|
}
|
|
22
54
|
|
|
23
55
|
export function isMap(d: unknown): d is Map<unknown, unknown> {
|
|
24
|
-
|
|
56
|
+
const type = getPrototypeString(d);
|
|
57
|
+
return type === TYPES.Map;
|
|
25
58
|
}
|
|
26
59
|
|
|
27
60
|
export function isDate(d: unknown): d is Date {
|
|
28
|
-
|
|
61
|
+
const type = getPrototypeString(d);
|
|
62
|
+
return type === TYPES.Date;
|
|
29
63
|
}
|
|
30
64
|
|
|
31
65
|
export type InspectFn = (x: unknown, options?: unknown) => string;
|
package/src/timestamp.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface TimestampExtended {
|
|
|
28
28
|
/**
|
|
29
29
|
* @public
|
|
30
30
|
* @category BSONType
|
|
31
|
+
*
|
|
32
|
+
* A special type for _internal_ MongoDB use and is **not** associated with the regular Date type.
|
|
31
33
|
*/
|
|
32
34
|
export class Timestamp extends LongWithoutOverridesClass {
|
|
33
35
|
get _bsontype(): 'Timestamp' {
|
|
@@ -36,6 +38,20 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
36
38
|
|
|
37
39
|
static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* An incrementing ordinal for operations within a given second.
|
|
43
|
+
*/
|
|
44
|
+
get i(): number {
|
|
45
|
+
return this.low >>> 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A `time_t` value measuring seconds since the Unix epoch
|
|
50
|
+
*/
|
|
51
|
+
get t(): number {
|
|
52
|
+
return this.high >>> 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
/**
|
|
40
56
|
* @param int - A 64-bit bigint representing the Timestamp.
|
|
41
57
|
*/
|
|
@@ -127,7 +143,7 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
127
143
|
|
|
128
144
|
/** @internal */
|
|
129
145
|
toExtendedJSON(): TimestampExtended {
|
|
130
|
-
return { $timestamp: { t: this.
|
|
146
|
+
return { $timestamp: { t: this.t, i: this.i } };
|
|
131
147
|
}
|
|
132
148
|
|
|
133
149
|
/** @internal */
|
|
@@ -144,8 +160,8 @@ export class Timestamp extends LongWithoutOverridesClass {
|
|
|
144
160
|
|
|
145
161
|
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
|
146
162
|
inspect ??= defaultInspect;
|
|
147
|
-
const t = inspect(this.
|
|
148
|
-
const i = inspect(this.
|
|
163
|
+
const t = inspect(this.t, options);
|
|
164
|
+
const i = inspect(this.i, options);
|
|
149
165
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
150
166
|
}
|
|
151
167
|
}
|