Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bson

Package Overview
Dependencies
Maintainers
8
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bson - npm Package Compare versions

Comparing version 5.4.0 to 6.0.0-alpha

33

bson.d.ts

@@ -34,12 +34,6 @@ /**

* Create a new Binary instance.
*
* This constructor can accept a string as its first argument. In this case,
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
* instead to convert the string to a Buffer using UTF-8 first.
*
* @param buffer - a buffer object containing the binary data.
* @param subType - the option binary type.
*/
constructor(buffer?: string | BinarySequence, subType?: number);
constructor(buffer?: BinarySequence, subType?: number);
/**

@@ -52,3 +46,3 @@ * Updates this binary with byte_value.

/**
* Writes a buffer or string to the binary.
* Writes a buffer to the binary.
*

@@ -58,3 +52,3 @@ * @param sequence - a string or buffer to be written to the Binary BSON object.

*/
write(sequence: string | BinarySequence, offset: number): void;
write(sequence: BinarySequence, offset: number): void;
/**

@@ -67,9 +61,4 @@ * Reads **length** bytes starting at **position**.

read(position: number, length: number): BinarySequence;
/**
* Returns the value of this binary as a string.
* @param asRaw - Will skip converting to a string
* @remarks
* This is handy when calling this function conditionally for some key value pairs and not others
*/
value(asRaw?: boolean): string | BinarySequence;
/** returns a view of the binary value as a Uint8Array */
value(): Uint8Array;
/** the length of the binary sequence */

@@ -997,3 +986,3 @@ length(): number;

set id(value: Uint8Array);
/** Returns the ObjectId id as a 24 character hex string representation */
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
toHexString(): string;

@@ -1014,2 +1003,3 @@ /* Excluded from this release type: getInc */

toJSON(): string;
/* Excluded from this release type: is */
/**

@@ -1020,3 +1010,3 @@ * Compares the equality of this ObjectId with `otherID`.

*/
equals(otherId: string | ObjectId | ObjectIdLike): boolean;
equals(otherId: string | ObjectId | ObjectIdLike | undefined | null): boolean;
/** Returns the generation date (accurate up to the second) that this ID was generated. */

@@ -1040,5 +1030,4 @@ getTimestamp(): Date;

/**
* Checks if a value is a valid bson ObjectId
*
* @param id - ObjectId instance to validate.
* Checks if a value can be used to create a valid bson ObjectId
* @param id - any JS value
*/

@@ -1224,4 +1213,2 @@ static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;

export declare class UUID extends Binary {
/** @deprecated Hex string is no longer cached, this control will be removed in a future major release */
static cacheHexString: boolean;
/**

@@ -1228,0 +1215,0 @@ * Create a UUID type

@@ -17,3 +17,3 @@ {

"types": "bson.d.ts",
"version": "5.4.0",
"version": "6.0.0-alpha",
"author": {

@@ -31,31 +31,32 @@ "name": "The MongoDB NodeJS Team",

"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@microsoft/api-extractor": "^7.35.1",
"@microsoft/api-extractor": "^7.36.4",
"@octokit/core": "^4.2.4",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.16.3",
"@types/sinon": "^10.0.14",
"@types/node": "^18.17.3",
"@types/sinon": "^10.0.16",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"chalk": "^5.2.0",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-no-bigint-usage": "file:./etc/eslint/no-bigint-usage",
"chalk": "^5.3.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-no-bigint-usage": "file:etc/eslint/no-bigint-usage",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-tsdoc": "^0.2.17",
"magic-string": "^0.30.0",
"magic-string": "^0.30.2",
"mocha": "10.2.0",
"node-fetch": "^3.3.1",
"node-fetch": "^3.3.2",
"nyc": "^15.1.0",
"prettier": "^2.8.8",
"rollup": "^3.21.4",
"sinon": "^15.0.4",
"rollup": "^3.27.2",
"sinon": "^15.2.0",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"standard-version": "^9.5.0",
"tar": "^6.1.15",
"ts-node": "^10.9.1",

@@ -65,4 +66,3 @@ "tsd": "^0.28.1",

"typescript-cached-transpile": "0.0.6",
"uuid": "^9.0.0",
"v8-profiler-next": "^1.9.0"
"uuid": "^9.0.0"
},

@@ -100,3 +100,3 @@ "tsd": {

"engines": {
"node": ">=14.20.1"
"node": ">=16.20.1"
},

@@ -110,2 +110,3 @@ "scripts": {

"check:web-no-bigint": "WEB=true NO_BIGINT=true mocha test/node",
"check:bench": "cd test/bench && npx tsc && node ./lib/index.js && mv benchmarks.json ../../.",
"build:ts": "node ./node_modules/typescript/bin/tsc",

@@ -112,0 +113,0 @@ "build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && node etc/clean_definition_files.cjs",

@@ -7,2 +7,3 @@ # BSON parser

### Table of Contents
- [Usage](#usage)

@@ -22,3 +23,3 @@ - [Bugs/Feature Requests](#bugs--feature-requests)

Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are **public**.
Bug reports in JIRA for the NODE driver project are **public**.

@@ -72,5 +73,16 @@ ## Usage

### MongoDB Node.js Driver Version Compatibility
Only the following version combinations with the [MongoDB Node.js Driver](https://github.com/mongodb/node-mongodb-native) are considered stable.
| | `bson@1.x` | `bson@4.x` | `bson@5.x` | `bson@6.x` |
| ------------- | ---------- | ---------- | ---------- | ---------- |
| `mongodb@6.x` | N/A | N/A | N/A | ✓ |
| `mongodb@5.x` | N/A | N/A | ✓ | N/A |
| `mongodb@4.x` | N/A | ✓ | N/A | N/A |
| `mongodb@3.x` | ✓ | N/A | N/A | N/A |
## Documentation
### BSON
### BSON

@@ -83,21 +95,20 @@ [API documentation](https://mongodb.github.io/node-mongodb-native/Next/modules/BSON.html)

* [EJSON](#EJSON)
- [EJSON](#EJSON)
* [.parse(text, [options])](#EJSON.parse)
- [.parse(text, [options])](#EJSON.parse)
* [.stringify(value, [replacer], [space], [options])](#EJSON.stringify)
- [.stringify(value, [replacer], [space], [options])](#EJSON.stringify)
* [.serialize(bson, [options])](#EJSON.serialize)
- [.serialize(bson, [options])](#EJSON.serialize)
* [.deserialize(ejson, [options])](#EJSON.deserialize)
- [.deserialize(ejson, [options])](#EJSON.deserialize)
<a name="EJSON.parse"></a>
#### *EJSON*.parse(text, [options])
#### _EJSON_.parse(text, [options])
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| text | <code>string</code> | | |
| [options] | <code>object</code> | | Optional settings |
| Param | Type | Default | Description |
| ----------------- | -------------------- | ----------------- | ---------------------------------------------------------------------------------- |
| text | <code>string</code> | | |
| [options] | <code>object</code> | | Optional settings |
| [options.relaxed] | <code>boolean</code> | <code>true</code> | Attempt to return native JS types where possible, rather than BSON types (if true) |

@@ -109,2 +120,3 @@

**Example**
```js

@@ -120,14 +132,15 @@ const { EJSON } = require('bson');

```
<a name="EJSON.stringify"></a>
#### *EJSON*.stringify(value, [replacer], [space], [options])
#### _EJSON_.stringify(value, [replacer], [space], [options])
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| value | <code>object</code> | | The value to convert to extended JSON |
| [replacer] | <code>function</code> \| <code>array</code> | | A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string |
| [space] | <code>string</code> \| <code>number</code> | | A String or Number object that's used to insert white space into the output JSON string for readability purposes. |
| [options] | <code>object</code> | | Optional settings |
| [options.relaxed] | <code>boolean</code> | <code>true</code> | Enabled Extended JSON's `relaxed` mode |
| [options.legacy] | <code>boolean</code> | <code>true</code> | Output in Extended JSON v1 |
| Param | Type | Default | Description |
| ----------------- | ------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| value | <code>object</code> | | The value to convert to extended JSON |
| [replacer] | <code>function</code> \| <code>array</code> | | A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string |
| [space] | <code>string</code> \| <code>number</code> | | A String or Number object that's used to insert white space into the output JSON string for readability purposes. |
| [options] | <code>object</code> | | Optional settings |
| [options.relaxed] | <code>boolean</code> | <code>true</code> | Enabled Extended JSON's `relaxed` mode |
| [options.legacy] | <code>boolean</code> | <code>true</code> | Output in Extended JSON v1 |

@@ -139,2 +152,3 @@ Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer

**Example**
```js

@@ -151,9 +165,10 @@ const { EJSON } = require('bson');

```
<a name="EJSON.serialize"></a>
#### *EJSON*.serialize(bson, [options])
#### _EJSON_.serialize(bson, [options])
| Param | Type | Description |
| --- | --- | --- |
| bson | <code>object</code> | The object to serialize |
| Param | Type | Description |
| --------- | ------------------- | ---------------------------------------------------- |
| bson | <code>object</code> | The object to serialize |
| [options] | <code>object</code> | Optional settings passed to the `stringify` function |

@@ -165,7 +180,7 @@

#### *EJSON*.deserialize(ejson, [options])
#### _EJSON_.deserialize(ejson, [options])
| Param | Type | Description |
| --- | --- | --- |
| ejson | <code>object</code> | The Extended JSON object to deserialize |
| Param | Type | Description |
| --------- | ------------------- | -------------------------------------------- |
| ejson | <code>object</code> | The Extended JSON object to deserialize |
| [options] | <code>object</code> | Optional settings passed to the parse method |

@@ -206,3 +221,3 @@

The following snippet should be placed at the top of the entrypoint (by default this is the root `index.js` file) for React Native projects using the BSON library. These lines must be placed for any code that imports `BSON`.
The following snippet should be placed at the top of the entrypoint (by default this is the root `index.js` file) for React Native projects using the BSON library. These lines must be placed for any code that imports `BSON`.

@@ -224,3 +239,3 @@ ```typescript

The `"exports"` definition in our `package.json` will result in BSON's CommonJS bundle being imported in a React Native project instead of the ES module bundle. Importing the CommonJS bundle is necessary because BSON's ES module bundle of BSON uses top-level await, which is not supported syntax in [React Native's runtime hermes](https://hermesengine.dev/).
The `"exports"` definition in our `package.json` will result in BSON's CommonJS bundle being imported in a React Native project instead of the ES module bundle. Importing the CommonJS bundle is necessary because BSON's ES module bundle of BSON uses top-level await, which is not supported syntax in [React Native's runtime hermes](https://hermesengine.dev/).

@@ -227,0 +242,0 @@ ## FAQ

@@ -1,2 +0,2 @@

import { isUint8Array } from './parser/utils';
import { isAnyArrayBuffer, isUint8Array } from './parser/utils';
import type { EJSONOptions } from './extended_json';

@@ -68,23 +68,15 @@ import { BSONError } from './error';

* Create a new Binary instance.
*
* This constructor can accept a string as its first argument. In this case,
* this string will be encoded using ISO-8859-1, **not** using UTF-8.
* This is almost certainly not what you want. Use `new Binary(Buffer.from(string))`
* instead to convert the string to a Buffer using UTF-8 first.
*
* @param buffer - a buffer object containing the binary data.
* @param subType - the option binary type.
*/
constructor(buffer?: string | BinarySequence, subType?: number) {
constructor(buffer?: BinarySequence, subType?: number) {
super();
if (
!(buffer == null) &&
!(typeof buffer === 'string') &&
typeof buffer === 'string' &&
!ArrayBuffer.isView(buffer) &&
!(buffer instanceof ArrayBuffer) &&
!isAnyArrayBuffer(buffer) &&
!Array.isArray(buffer)
) {
throw new BSONError(
'Binary can only be constructed from string, Buffer, TypedArray, or Array<number>'
);
throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
}

@@ -99,13 +91,5 @@

} else {
if (typeof buffer === 'string') {
// string
this.buffer = ByteUtils.fromISO88591(buffer);
} else if (Array.isArray(buffer)) {
// number[]
this.buffer = ByteUtils.fromNumberArray(buffer);
} else {
// Buffer | TypedArray | ArrayBuffer
this.buffer = ByteUtils.toLocalBufferType(buffer);
}
this.buffer = Array.isArray(buffer)
? ByteUtils.fromNumberArray(buffer)
: ByteUtils.toLocalBufferType(buffer);
this.position = this.buffer.byteLength;

@@ -152,3 +136,3 @@ }

/**
* Writes a buffer or string to the binary.
* Writes a buffer to the binary.
*

@@ -158,3 +142,3 @@ * @param sequence - a string or buffer to be written to the Binary BSON object.

*/
write(sequence: string | BinarySequence, offset: number): void {
write(sequence: BinarySequence, offset: number): void {
offset = typeof offset === 'number' ? offset : this.position;

@@ -176,6 +160,3 @@

} else if (typeof sequence === 'string') {
const bytes = ByteUtils.fromISO88591(sequence);
this.buffer.set(bytes, offset);
this.position =
offset + sequence.length > this.position ? offset + sequence.length : this.position;
throw new BSONError('input cannot be string');
}

@@ -197,22 +178,8 @@ }

/**
* Returns the value of this binary as a string.
* @param asRaw - Will skip converting to a string
* @remarks
* This is handy when calling this function conditionally for some key value pairs and not others
*/
value(asRaw?: boolean): string | BinarySequence {
asRaw = !!asRaw;
/** returns a view of the binary value as a Uint8Array */
value(): Uint8Array {
// Optimize to serialize for the situation where the data == size of buffer
if (asRaw && this.buffer.length === this.position) {
return this.buffer;
}
// If it's a node.js buffer object
if (asRaw) {
return this.buffer.slice(0, this.position);
}
// TODO(NODE-4361): remove binary string support, value(true) should be the default / only option here.
return ByteUtils.toISO88591(this.buffer.subarray(0, this.position));
return this.buffer.length === this.position
? this.buffer
: this.buffer.subarray(0, this.position);
}

@@ -330,4 +297,2 @@

export class UUID extends Binary {
/** @deprecated Hex string is no longer cached, this control will be removed in a future major release */
static cacheHexString = false;
/**

@@ -334,0 +299,0 @@ * Create a UUID type

@@ -65,3 +65,3 @@ import type { Document } from './bson';

const codeJson = this.toJSON();
return `new Code("${String(codeJson.code)}"${
return `new Code(${JSON.stringify(String(codeJson.code))}${
codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ''

@@ -68,0 +68,0 @@ })`;

/** @internal */
export const BSON_MAJOR_VERSION = 5 as const;
export const BSON_MAJOR_VERSION = 6 as const;

@@ -4,0 +4,0 @@ /** @internal */

@@ -163,2 +163,3 @@ import { BSONValue } from './bson_value';

let isNegative = false;
let sawSign = false;
let sawRadix = false;

@@ -184,4 +185,2 @@ let foundNonZero = false;

let digitsInsert = 0;
// The index of the first non-zero digit
let firstDigit = 0;
// The index of the last digit

@@ -192,4 +191,2 @@ let lastDigit = 0;

let exponent = 0;
// loop index over array
let i = 0;
// The high 17 digits of the significand

@@ -247,2 +244,3 @@ let significandHigh = new Long(0, 0);

if (representation[index] === '+' || representation[index] === '-') {
sawSign = true;
isNegative = representation[index++] === '-';

@@ -270,3 +268,3 @@ }

if (nDigitsStored < 34) {
if (nDigitsStored < MAX_DIGITS) {
if (representation[index] !== '0' || foundNonZero) {

@@ -315,7 +313,3 @@ if (!foundNonZero) {

// Find first non-zero digit in digits
firstDigit = 0;
if (!nDigitsStored) {
firstDigit = 0;
lastDigit = 0;
digits[0] = 0;

@@ -329,3 +323,7 @@ nDigits = 1;

if (significantDigits !== 1) {
while (digits[firstNonZero + significantDigits - 1] === 0) {
while (
representation[
firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)
] === '0'
) {
significantDigits = significantDigits - 1;

@@ -341,3 +339,3 @@ }

// Overflow prevention
if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) {
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
exponent = EXPONENT_MIN;

@@ -352,7 +350,5 @@ } else {

lastDigit = lastDigit + 1;
if (lastDigit - firstDigit > MAX_DIGITS) {
if (lastDigit >= MAX_DIGITS) {
// Check if we have a zero then just hard clamp, otherwise fail
const digitsString = digits.join('');
if (digitsString.match(/^0+$/)) {
if (significantDigits === 0) {
exponent = EXPONENT_MAX;

@@ -369,12 +365,24 @@ break;

// Shift last digit. can only do this if < significant digits than # stored.
if (lastDigit === 0 && significantDigits < nDigitsStored) {
exponent = EXPONENT_MIN;
significantDigits = 0;
break;
if (lastDigit === 0) {
if (significantDigits === 0) {
exponent = EXPONENT_MIN;
break;
}
invalidErr(representation, 'exponent underflow');
}
if (nDigitsStored < nDigits) {
if (
representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
significantDigits !== 0
) {
invalidErr(representation, 'inexact rounding');
}
// adjust to match digits not stored
nDigits = nDigits - 1;
} else {
if (digits[lastDigit] !== 0) {
invalidErr(representation, 'inexact rounding');
}
// adjust to round

@@ -387,8 +395,2 @@ lastDigit = lastDigit - 1;

} else {
// Check if we have a zero then just hard clamp, otherwise fail
const digitsString = digits.join('');
if (digitsString.match(/^0+$/)) {
exponent = EXPONENT_MAX;
break;
}
invalidErr(representation, 'overflow');

@@ -400,5 +402,3 @@ }

// We've normalized the exponent, but might still need to round.
if (lastDigit - firstDigit + 1 < significantDigits) {
let endOfString = nDigitsRead;
if (lastDigit + 1 < significantDigits) {
// If we have seen a radix point, 'string' is 1 longer than we have

@@ -409,45 +409,13 @@ // documented with ndigits_read, so inc the position of the first nonzero

firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
// if negative, we need to increment again to account for - sign at start.
if (isNegative) {
// if saw sign, we need to increment again to account for - or + sign at start.
if (sawSign) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
let roundBit = 0;
if (roundDigit >= 5) {
roundBit = 1;
if (roundDigit === 5) {
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
if (parseInt(representation[i], 10)) {
roundBit = 1;
break;
}
}
}
if (roundDigit !== 0) {
invalidErr(representation, 'inexact rounding');
}
if (roundBit) {
let dIdx = lastDigit;
for (; dIdx >= 0; dIdx--) {
if (++digits[dIdx] > 9) {
digits[dIdx] = 0;
// overflowed most significant digit
if (dIdx === 0) {
if (exponent < EXPONENT_MAX) {
exponent = exponent + 1;
digits[dIdx] = 1;
} else {
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
}
}
}
}
}
}

@@ -465,4 +433,4 @@

significandLow = Long.fromNumber(0);
} else if (lastDigit - firstDigit < 17) {
let dIdx = firstDigit;
} else if (lastDigit < 17) {
let dIdx = 0;
significandLow = Long.fromNumber(digits[dIdx++]);

@@ -476,3 +444,3 @@ significandHigh = new Long(0, 0);

} else {
let dIdx = firstDigit;
let dIdx = 0;
significandHigh = Long.fromNumber(digits[dIdx++]);

@@ -479,0 +447,0 @@

import { BSONValue } from './bson_value';
import { BSONError } from './error';
import { isUint8Array } from './parser/utils';
import { BSONDataView, ByteUtils } from './utils/byte_utils';

@@ -77,15 +76,7 @@

} else if (typeof workingId === 'string') {
if (workingId.length === 12) {
// TODO(NODE-4361): Remove string of length 12 support
const bytes = ByteUtils.fromUTF8(workingId);
if (bytes.byteLength === 12) {
this[kId] = bytes;
} else {
throw new BSONError('Argument passed in must be a string of 12 bytes');
}
} else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
this[kId] = ByteUtils.fromHex(workingId);
} else {
throw new BSONError(
'Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer'
'input must be a 24 character hex string, 12 byte Uint8Array, or an integer'
);

@@ -117,3 +108,3 @@ }

/** Returns the ObjectId id as a 24 character hex string representation */
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
toHexString(): string {

@@ -193,2 +184,12 @@ if (ObjectId.cacheHexString && this.__id) {

/** @internal */
private static is(variable: unknown): variable is ObjectId {
return (
variable != null &&
typeof variable === 'object' &&
'_bsontype' in variable &&
variable._bsontype === 'ObjectId'
);
}
/**

@@ -199,3 +200,3 @@ * Compares the equality of this ObjectId with `otherID`.

*/
equals(otherId: string | ObjectId | ObjectIdLike): boolean {
equals(otherId: string | ObjectId | ObjectIdLike | undefined | null): boolean {
if (otherId === undefined || otherId === null) {

@@ -205,30 +206,13 @@ return false;

if (otherId instanceof ObjectId) {
if (ObjectId.is(otherId)) {
return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
}
if (
typeof otherId === 'string' &&
ObjectId.isValid(otherId) &&
otherId.length === 12 &&
isUint8Array(this.id)
) {
return ByteUtils.equals(this.id, ByteUtils.fromISO88591(otherId));
}
if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
if (typeof otherId === 'string') {
return otherId.toLowerCase() === this.toHexString();
}
if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
return ByteUtils.equals(ByteUtils.fromUTF8(otherId), this.id);
}
if (
typeof otherId === 'object' &&
'toHexString' in otherId &&
typeof otherId.toHexString === 'function'
) {
if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
const otherIdString = otherId.toHexString();
const thisIdString = this.toHexString().toLowerCase();
const thisIdString = this.toHexString();
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;

@@ -289,5 +273,4 @@ }

/**
* Checks if a value is a valid bson ObjectId
*
* @param id - ObjectId instance to validate.
* Checks if a value can be used to create a valid bson ObjectId
* @param id - any JS value
*/

@@ -294,0 +277,0 @@ static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean {

@@ -37,3 +37,3 @@ import { BSONValue } from './bson_value';

inspect(): string {
return `new BSONSymbol("${this.value}")`;
return `new BSONSymbol(${JSON.stringify(this.value)})`;
}

@@ -40,0 +40,0 @@

@@ -24,3 +24,3 @@ import { nodeJsByteUtils } from './node_byte_utils';

fromHex: (hex: string) => Uint8Array;
/** Create a hex string from bytes */
/** Create a lowercase hex string from bytes */
toHex: (buffer: Uint8Array) => string;

@@ -27,0 +27,0 @@ /** Create a Uint8Array containing utf8 code units from a string */

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc