bson 7.1.0 → 7.2.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 +30 -6
- package/lib/bson.bundle.js +29 -1
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +29 -1
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +29 -1
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.node.mjs +29 -1
- package/lib/bson.node.mjs.map +1 -1
- package/lib/bson.rn.cjs +29 -1
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +1 -1
- package/src/bson.ts +6 -1
- package/src/extended_json.ts +33 -13
- package/src/parser/on_demand/index.ts +8 -0
- 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/bson.d.ts
CHANGED
|
@@ -207,6 +207,9 @@ declare namespace BSON {
|
|
|
207
207
|
Decimal128Extended,
|
|
208
208
|
DoubleExtended,
|
|
209
209
|
EJSONOptions,
|
|
210
|
+
EJSONOptionsBase,
|
|
211
|
+
EJSONSerializeOptions,
|
|
212
|
+
EJSONParseOptions,
|
|
210
213
|
Int32Extended,
|
|
211
214
|
LongExtended,
|
|
212
215
|
MaxKeyExtended,
|
|
@@ -465,6 +468,8 @@ export declare type ByteUtils = {
|
|
|
465
468
|
compare: (buffer1: Uint8Array, buffer2: Uint8Array) => -1 | 0 | 1;
|
|
466
469
|
/** Concatenating all the Uint8Arrays in new Uint8Array. */
|
|
467
470
|
concat: (list: Uint8Array[]) => Uint8Array;
|
|
471
|
+
/** Copy bytes from source Uint8Array to target Uint8Array */
|
|
472
|
+
copy: (source: Uint8Array, target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number) => number;
|
|
468
473
|
/** Check if two Uint8Arrays are deep equal */
|
|
469
474
|
equals: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
470
475
|
/** Create a Uint8Array from an array of numbers */
|
|
@@ -782,10 +787,13 @@ export declare const EJSON: {
|
|
|
782
787
|
* @param ejson - The Extended JSON object to deserialize
|
|
783
788
|
* @param options - Optional settings passed to the parse method
|
|
784
789
|
*/
|
|
785
|
-
declare function EJSONdeserialize(ejson: Document, options?:
|
|
790
|
+
declare function EJSONdeserialize(ejson: Document, options?: EJSONParseOptions): any;
|
|
786
791
|
|
|
787
792
|
/** @public */
|
|
788
|
-
export declare type EJSONOptions =
|
|
793
|
+
export declare type EJSONOptions = EJSONSerializeOptions & EJSONParseOptions;
|
|
794
|
+
|
|
795
|
+
/** @public */
|
|
796
|
+
export declare type EJSONOptionsBase = {
|
|
789
797
|
/**
|
|
790
798
|
* Output using the Extended JSON v1 spec
|
|
791
799
|
* @defaultValue `false`
|
|
@@ -793,8 +801,13 @@ export declare type EJSONOptions = {
|
|
|
793
801
|
legacy?: boolean;
|
|
794
802
|
/**
|
|
795
803
|
* Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types
|
|
796
|
-
* @defaultValue `false`
|
|
804
|
+
* @defaultValue `false`
|
|
805
|
+
*/
|
|
797
806
|
relaxed?: boolean;
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
/** @public */
|
|
810
|
+
export declare type EJSONParseOptions = EJSONOptionsBase & {
|
|
798
811
|
/**
|
|
799
812
|
* Enable native bigint support
|
|
800
813
|
* @defaultValue `false`
|
|
@@ -808,7 +821,16 @@ export declare type EJSONOptions = {
|
|
|
808
821
|
* @param value - The object to serialize
|
|
809
822
|
* @param options - Optional settings passed to the `stringify` function
|
|
810
823
|
*/
|
|
811
|
-
declare function EJSONserialize(value: any, options?:
|
|
824
|
+
declare function EJSONserialize(value: any, options?: EJSONSerializeOptions): Document;
|
|
825
|
+
|
|
826
|
+
/** @public */
|
|
827
|
+
export declare type EJSONSerializeOptions = EJSONOptionsBase & {
|
|
828
|
+
/**
|
|
829
|
+
* Omits undefined values from the output instead of converting them to null
|
|
830
|
+
* @defaultValue `false`
|
|
831
|
+
*/
|
|
832
|
+
ignoreUndefined?: boolean;
|
|
833
|
+
};
|
|
812
834
|
|
|
813
835
|
declare type InspectFn = (x: unknown, options?: unknown) => string;
|
|
814
836
|
|
|
@@ -1493,6 +1515,8 @@ export declare interface ObjectIdLike {
|
|
|
1493
1515
|
export declare type OnDemand = {
|
|
1494
1516
|
parseToElements: (this: void, bytes: Uint8Array, startOffset?: number) => Iterable<BSONElement>;
|
|
1495
1517
|
BSONElement: BSONElement;
|
|
1518
|
+
ByteUtils: ByteUtils;
|
|
1519
|
+
NumberUtils: NumberUtils;
|
|
1496
1520
|
};
|
|
1497
1521
|
|
|
1498
1522
|
/**
|
|
@@ -1517,7 +1541,7 @@ export declare const onDemand: OnDemand;
|
|
|
1517
1541
|
* console.log(EJSON.parse(text));
|
|
1518
1542
|
* ```
|
|
1519
1543
|
*/
|
|
1520
|
-
declare function parse(text: string, options?:
|
|
1544
|
+
declare function parse(text: string, options?: EJSONParseOptions): any;
|
|
1521
1545
|
|
|
1522
1546
|
/**
|
|
1523
1547
|
* Serialize a Javascript object.
|
|
@@ -1596,7 +1620,7 @@ export declare function setInternalBufferSize(size: number): void;
|
|
|
1596
1620
|
* console.log(EJSON.stringify(doc));
|
|
1597
1621
|
* ```
|
|
1598
1622
|
*/
|
|
1599
|
-
declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) |
|
|
1623
|
+
declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONSerializeOptions, space?: string | number, options?: EJSONSerializeOptions): string;
|
|
1600
1624
|
|
|
1601
1625
|
/**
|
|
1602
1626
|
* @public
|
package/lib/bson.bundle.js
CHANGED
|
@@ -262,6 +262,11 @@ const nodeJsByteUtils = {
|
|
|
262
262
|
concat(list) {
|
|
263
263
|
return Buffer.concat(list);
|
|
264
264
|
},
|
|
265
|
+
copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|
266
|
+
return nodeJsByteUtils
|
|
267
|
+
.toLocalBufferType(source)
|
|
268
|
+
.copy(target, targetStart ?? 0, sourceStart ?? 0, sourceEnd ?? source.length);
|
|
269
|
+
},
|
|
265
270
|
equals(a, b) {
|
|
266
271
|
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
267
272
|
},
|
|
@@ -406,6 +411,27 @@ const webByteUtils = {
|
|
|
406
411
|
}
|
|
407
412
|
return result;
|
|
408
413
|
},
|
|
414
|
+
copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|
415
|
+
if (sourceEnd !== undefined && sourceEnd < 0) {
|
|
416
|
+
throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${sourceEnd}`);
|
|
417
|
+
}
|
|
418
|
+
sourceEnd = sourceEnd ?? source.length;
|
|
419
|
+
if (sourceStart !== undefined && (sourceStart < 0 || sourceStart > sourceEnd)) {
|
|
420
|
+
throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${sourceEnd}. Received ${sourceStart}`);
|
|
421
|
+
}
|
|
422
|
+
sourceStart = sourceStart ?? 0;
|
|
423
|
+
if (targetStart !== undefined && targetStart < 0) {
|
|
424
|
+
throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${targetStart}`);
|
|
425
|
+
}
|
|
426
|
+
targetStart = targetStart ?? 0;
|
|
427
|
+
const srcSlice = source.subarray(sourceStart, sourceEnd);
|
|
428
|
+
const maxLen = Math.min(srcSlice.length, target.length - targetStart);
|
|
429
|
+
if (maxLen <= 0) {
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
target.set(srcSlice.subarray(0, maxLen), targetStart);
|
|
433
|
+
return maxLen;
|
|
434
|
+
},
|
|
409
435
|
equals(uint8Array, otherUint8Array) {
|
|
410
436
|
if (uint8Array.byteLength !== otherUint8Array.byteLength) {
|
|
411
437
|
return false;
|
|
@@ -4311,7 +4337,7 @@ function serializeValue(value, options) {
|
|
|
4311
4337
|
if (Array.isArray(value))
|
|
4312
4338
|
return serializeArray(value, options);
|
|
4313
4339
|
if (value === undefined)
|
|
4314
|
-
return null;
|
|
4340
|
+
return options.ignoreUndefined ? undefined : null;
|
|
4315
4341
|
if (value instanceof Date || isDate(value)) {
|
|
4316
4342
|
const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 253402318800000;
|
|
4317
4343
|
if (options.legacy) {
|
|
@@ -4595,6 +4621,8 @@ function parseToElements(bytes, startOffset = 0) {
|
|
|
4595
4621
|
|
|
4596
4622
|
const onDemand = Object.create(null);
|
|
4597
4623
|
onDemand.parseToElements = parseToElements;
|
|
4624
|
+
onDemand.ByteUtils = ByteUtils;
|
|
4625
|
+
onDemand.NumberUtils = NumberUtils;
|
|
4598
4626
|
Object.freeze(onDemand);
|
|
4599
4627
|
|
|
4600
4628
|
const MAXSIZE = 1024 * 1024 * 17;
|