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/README.md
CHANGED
|
@@ -14,7 +14,7 @@ You can learn more about it in [the specification](http://bsonspec.org).
|
|
|
14
14
|
|
|
15
15
|
### Release Integrity
|
|
16
16
|
|
|
17
|
-
Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc).
|
|
17
|
+
Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc). All release packages provided as part of a GitHub release are signed. To verify the provided packages, download the key and import it using gpg:
|
|
18
18
|
|
|
19
19
|
```shell
|
|
20
20
|
gpg --import node-driver.asc
|
|
@@ -36,7 +36,13 @@ gpg --verify bson-X.Y.Z.tgz.sig bson-X.Y.Z.tgz
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
>[!Note]
|
|
39
|
-
No verification is done when using npm to install the package. The contents of the
|
|
39
|
+
No GPG verification is done when using npm to install the package. The contents of the GitHub tarball and npm's tarball are identical.
|
|
40
|
+
|
|
41
|
+
Releases published to the npm registry also include a [provenance attestation](https://docs.npmjs.com/generating-provenance-statements), which cryptographically links the package to its source repository and build workflow. To verify provenance:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
npm audit signatures
|
|
45
|
+
```
|
|
40
46
|
|
|
41
47
|
## Bugs / Feature Requests
|
|
42
48
|
|
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
|
|
|
@@ -1294,7 +1316,7 @@ export declare interface LongExtended {
|
|
|
1294
1316
|
|
|
1295
1317
|
/** @public */
|
|
1296
1318
|
export declare type LongWithoutOverrides = new (low: unknown, high?: number | boolean, unsigned?: boolean) => {
|
|
1297
|
-
[P in
|
|
1319
|
+
[P in TimestampKept]: Long[P];
|
|
1298
1320
|
};
|
|
1299
1321
|
|
|
1300
1322
|
/** @public */
|
|
@@ -1374,6 +1396,8 @@ export declare const NumberUtils: NumberUtils;
|
|
|
1374
1396
|
export declare class ObjectId extends BSONValue {
|
|
1375
1397
|
get _bsontype(): 'ObjectId';
|
|
1376
1398
|
/* Excluded from this release type: index */
|
|
1399
|
+
/* Excluded from this release type: PROCESS_UNIQUE */
|
|
1400
|
+
/* Excluded from this release type: resetState */
|
|
1377
1401
|
static cacheHexString: boolean;
|
|
1378
1402
|
/* Excluded from this release type: buffer */
|
|
1379
1403
|
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
|
@@ -1519,7 +1543,7 @@ export declare const onDemand: OnDemand;
|
|
|
1519
1543
|
* console.log(EJSON.parse(text));
|
|
1520
1544
|
* ```
|
|
1521
1545
|
*/
|
|
1522
|
-
declare function parse(text: string, options?:
|
|
1546
|
+
declare function parse(text: string, options?: EJSONParseOptions): any;
|
|
1523
1547
|
|
|
1524
1548
|
/**
|
|
1525
1549
|
* Serialize a Javascript object.
|
|
@@ -1596,9 +1620,16 @@ export declare function setInternalBufferSize(size: number): void;
|
|
|
1596
1620
|
*
|
|
1597
1621
|
* // prints '{"int32":10}'
|
|
1598
1622
|
* console.log(EJSON.stringify(doc));
|
|
1623
|
+
*
|
|
1624
|
+
* // prints '{"int32":{"$numberInt":"10"}}' with 2 space indentation
|
|
1625
|
+
* console.log(EJSON.stringify(doc, { relaxed: false }, 2));
|
|
1599
1626
|
* ```
|
|
1600
1627
|
*/
|
|
1601
|
-
declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) |
|
|
1628
|
+
declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | null, space?: string | number, options?: EJSONSerializeOptions): string;
|
|
1629
|
+
|
|
1630
|
+
declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | null, options?: EJSONSerializeOptions): string;
|
|
1631
|
+
|
|
1632
|
+
declare function stringify(value: any, options?: EJSONSerializeOptions, space?: string | number): string;
|
|
1602
1633
|
|
|
1603
1634
|
/**
|
|
1604
1635
|
* @public
|
|
@@ -1609,6 +1640,9 @@ declare function stringify(value: any, replacer?: (number | string)[] | ((this:
|
|
|
1609
1640
|
export declare class Timestamp extends LongWithoutOverridesClass {
|
|
1610
1641
|
get _bsontype(): 'Timestamp';
|
|
1611
1642
|
get [bsonType](): 'Timestamp';
|
|
1643
|
+
/**
|
|
1644
|
+
* @deprecated Use `Long.MAX_UNSIGNED_VALUE` instead.
|
|
1645
|
+
*/
|
|
1612
1646
|
static readonly MAX_VALUE: Long;
|
|
1613
1647
|
/**
|
|
1614
1648
|
* An incrementing ordinal for operations within a given second.
|
|
@@ -1636,9 +1670,15 @@ export declare class Timestamp extends LongWithoutOverridesClass {
|
|
|
1636
1670
|
toJSON(): {
|
|
1637
1671
|
$timestamp: string;
|
|
1638
1672
|
};
|
|
1639
|
-
/**
|
|
1673
|
+
/**
|
|
1674
|
+
* Returns a Timestamp represented by the given (32-bit) integer value.
|
|
1675
|
+
* @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.
|
|
1676
|
+
*/
|
|
1640
1677
|
static fromInt(value: number): Timestamp;
|
|
1641
|
-
/**
|
|
1678
|
+
/**
|
|
1679
|
+
* Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned.
|
|
1680
|
+
* @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.
|
|
1681
|
+
*/
|
|
1642
1682
|
static fromNumber(value: number): Timestamp;
|
|
1643
1683
|
/**
|
|
1644
1684
|
* Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
|
|
@@ -1657,6 +1697,98 @@ export declare class Timestamp extends LongWithoutOverridesClass {
|
|
|
1657
1697
|
/* Excluded from this release type: toExtendedJSON */
|
|
1658
1698
|
/* Excluded from this release type: fromExtendedJSON */
|
|
1659
1699
|
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
|
1700
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1701
|
+
add: Long['add'];
|
|
1702
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1703
|
+
subtract: Long['subtract'];
|
|
1704
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1705
|
+
sub: Long['sub'];
|
|
1706
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1707
|
+
multiply: Long['multiply'];
|
|
1708
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1709
|
+
mul: Long['mul'];
|
|
1710
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1711
|
+
divide: Long['divide'];
|
|
1712
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1713
|
+
div: Long['div'];
|
|
1714
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1715
|
+
modulo: Long['modulo'];
|
|
1716
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1717
|
+
mod: Long['mod'];
|
|
1718
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1719
|
+
rem: Long['rem'];
|
|
1720
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
1721
|
+
negate: Long['negate'];
|
|
1722
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
1723
|
+
neg: Long['neg'];
|
|
1724
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1725
|
+
and: Long['and'];
|
|
1726
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1727
|
+
or: Long['or'];
|
|
1728
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1729
|
+
xor: Long['xor'];
|
|
1730
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1731
|
+
not: Long['not'];
|
|
1732
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1733
|
+
shiftLeft: Long['shiftLeft'];
|
|
1734
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1735
|
+
shl: Long['shl'];
|
|
1736
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1737
|
+
shiftRight: Long['shiftRight'];
|
|
1738
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1739
|
+
shr: Long['shr'];
|
|
1740
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1741
|
+
shiftRightUnsigned: Long['shiftRightUnsigned'];
|
|
1742
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1743
|
+
shr_u: Long['shr_u'];
|
|
1744
|
+
/** @deprecated Not applicable to Timestamp; Timestamp is not intended to be used as a Long. */
|
|
1745
|
+
shru: Long['shru'];
|
|
1746
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned. */
|
|
1747
|
+
toSigned: Long['toSigned'];
|
|
1748
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (this is a no-op). */
|
|
1749
|
+
toUnsigned: Long['toUnsigned'];
|
|
1750
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always false). */
|
|
1751
|
+
isNegative: Long['isNegative'];
|
|
1752
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
|
|
1753
|
+
isPositive: Long['isPositive'];
|
|
1754
|
+
/** @deprecated Not applicable to Timestamp as the underlying Long is always unsigned (is always true). */
|
|
1755
|
+
unsigned: Long['unsigned'];
|
|
1756
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
1757
|
+
toInt: Long['toInt'];
|
|
1758
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
1759
|
+
toNumber: Long['toNumber'];
|
|
1760
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
1761
|
+
toBytes: Long['toBytes'];
|
|
1762
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
1763
|
+
toBytesLE: Long['toBytesLE'];
|
|
1764
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch, or `.i` for the increment ordinal. */
|
|
1765
|
+
toBytesBE: Long['toBytesBE'];
|
|
1766
|
+
/** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.t` for seconds since the Unix epoch. */
|
|
1767
|
+
getHighBits: Long['getHighBits'];
|
|
1768
|
+
/** @deprecated Not applicable to Timestamp; use `.t` for seconds since the Unix epoch. */
|
|
1769
|
+
getHighBitsUnsigned: Long['getHighBitsUnsigned'];
|
|
1770
|
+
/** @deprecated Incompatible with Timestamp: returns a signed integer, but Timestamp is always unsigned. Use `.i` for the increment ordinal. */
|
|
1771
|
+
getLowBits: Long['getLowBits'];
|
|
1772
|
+
/** @deprecated Not applicable to Timestamp; use `.i` for the increment ordinal. */
|
|
1773
|
+
getLowBitsUnsigned: Long['getLowBitsUnsigned'];
|
|
1774
|
+
/** @deprecated Not applicable to Timestamp; use `.i` instead. */
|
|
1775
|
+
low: Long['low'];
|
|
1776
|
+
/** @deprecated Not applicable to Timestamp; use `.t` instead. */
|
|
1777
|
+
high: Long['high'];
|
|
1778
|
+
/** @deprecated Use .compare() for general comparison, or .equals(), .lessThan(), .greaterThan() for specific cases. */
|
|
1779
|
+
comp: Long['comp'];
|
|
1780
|
+
/** @deprecated Compare `.t` and `.i` against `0` explicitly. */
|
|
1781
|
+
isZero: Long['isZero'];
|
|
1782
|
+
/** @deprecated Compare `.t` and `.i` against `0` explicitly. */
|
|
1783
|
+
eqz: Long['eqz'];
|
|
1784
|
+
/** @deprecated Not applicable to Timestamp. Use the bsonType symbol or _bsontype === 'Timestamp' to identify a Timestamp. */
|
|
1785
|
+
__isLong__: Long['__isLong__'];
|
|
1786
|
+
/** @deprecated Not applicable to Timestamp. */
|
|
1787
|
+
getNumBitsAbs: Long['getNumBitsAbs'];
|
|
1788
|
+
/** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
|
|
1789
|
+
isEven: Long['isEven'];
|
|
1790
|
+
/** @deprecated Not applicable to Timestamp; tests parity of the increment only. */
|
|
1791
|
+
isOdd: Long['isOdd'];
|
|
1660
1792
|
}
|
|
1661
1793
|
|
|
1662
1794
|
/** @public */
|
|
@@ -1667,7 +1799,21 @@ export declare interface TimestampExtended {
|
|
|
1667
1799
|
};
|
|
1668
1800
|
}
|
|
1669
1801
|
|
|
1670
|
-
/**
|
|
1802
|
+
/**
|
|
1803
|
+
* @public
|
|
1804
|
+
*
|
|
1805
|
+
* Inherited `Long` members surfaced on `Timestamp`.
|
|
1806
|
+
* When `Long` gains a new member: add it here if it should pass through, or
|
|
1807
|
+
* add a `@deprecated declare` line on the `Timestamp` class if it should be
|
|
1808
|
+
* surfaced as deprecated. Anything left unclassified is silently dropped from
|
|
1809
|
+
* the public type — preventing accidental behavioral bleed-through.
|
|
1810
|
+
*/
|
|
1811
|
+
declare type TimestampKept = 'toBigInt' | 'toString' | 'compare' | 'equals' | 'eq' | 'notEquals' | 'neq' | 'ne' | 'lessThan' | 'lt' | 'lessThanOrEqual' | 'lte' | 'le' | 'greaterThan' | 'gt' | 'greaterThanOrEqual' | 'gte' | 'ge';
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* @public
|
|
1815
|
+
* @deprecated This type is no longer used internally and will be removed in a future version.
|
|
1816
|
+
*/
|
|
1671
1817
|
export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect' | typeof bsonType;
|
|
1672
1818
|
|
|
1673
1819
|
/**
|