Comparing version 5.0.0 to 5.0.1
@@ -147,2 +147,3 @@ /** | ||
BSONVersionError, | ||
BSONRuntimeError, | ||
BSONType, | ||
@@ -158,3 +159,7 @@ EJSON, | ||
* @public | ||
* `BSONError` objects are thrown when runtime errors occur. | ||
* @category Error | ||
* | ||
* `BSONError` objects are thrown when BSON ecounters an error. | ||
* | ||
* This is the parent class for all the other errors thrown by this library. | ||
*/ | ||
@@ -212,2 +217,15 @@ export declare class BSONError extends Error { | ||
/** | ||
* @public | ||
* @category Error | ||
* | ||
* An error generated when BSON functions encounter an unexpected input | ||
* or reaches an unexpected/invalid internal state | ||
* | ||
*/ | ||
export declare class BSONRuntimeError extends BSONError { | ||
get name(): 'BSONRuntimeError'; | ||
constructor(message: string); | ||
} | ||
/** | ||
* A class representation of the BSON Symbol type. | ||
@@ -275,3 +293,6 @@ * @public | ||
/** @public */ | ||
/** | ||
* @public | ||
* @category Error | ||
*/ | ||
export declare class BSONVersionError extends BSONError { | ||
@@ -278,0 +299,0 @@ get name(): 'BSONVersionError'; |
@@ -16,3 +16,3 @@ { | ||
"types": "bson.d.ts", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"author": { | ||
@@ -45,2 +45,3 @@ "name": "The MongoDB NodeJS Team", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-no-bigint-usage": "file:./etc/eslint/no-bigint-usage", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
@@ -81,7 +82,17 @@ "eslint-plugin-tsdoc": "^0.2.17", | ||
"exports": { | ||
"import": "./lib/bson.mjs", | ||
"require": "./lib/bson.cjs", | ||
"import": { | ||
"types": "./bson.d.ts", | ||
"default": "./lib/bson.mjs" | ||
}, | ||
"require": { | ||
"types": "./bson.d.ts", | ||
"default": "./lib/bson.cjs" | ||
}, | ||
"react-native": "./lib/bson.cjs", | ||
"browser": "./lib/bson.mjs" | ||
}, | ||
"compass:exports": { | ||
"import": "./lib/bson.cjs", | ||
"require": "./lib/bson.cjs" | ||
}, | ||
"engines": { | ||
@@ -92,6 +103,7 @@ "node": ">=14.20.1" | ||
"pretest": "npm run build", | ||
"test": "npm run check:node && npm run check:web", | ||
"test": "npm run check:node && npm run check:web && npm run check:web-no-bigint", | ||
"check:node": "WEB=false mocha test/node", | ||
"check:tsd": "npm run build:dts && tsd", | ||
"check:web": "WEB=true mocha test/node", | ||
"check:web-no-bigint": "WEB=true NO_BIGINT=true mocha test/node", | ||
"build:ts": "node ./node_modules/typescript/bin/tsc", | ||
@@ -98,0 +110,0 @@ "build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && rimraf 'lib/**/*.d.ts*' lib/parser lib/utils", |
@@ -53,3 +53,3 @@ import { Binary, UUID } from './binary'; | ||
export { BSONValue } from './bson_value'; | ||
export { BSONError, BSONVersionError } from './error'; | ||
export { BSONError, BSONVersionError, BSONRuntimeError } from './error'; | ||
export { BSONType } from './constants'; | ||
@@ -56,0 +56,0 @@ export { EJSON } from './extended_json'; |
@@ -5,3 +5,7 @@ import { BSON_MAJOR_VERSION } from './constants'; | ||
* @public | ||
* `BSONError` objects are thrown when runtime errors occur. | ||
* @category Error | ||
* | ||
* `BSONError` objects are thrown when BSON ecounters an error. | ||
* | ||
* This is the parent class for all the other errors thrown by this library. | ||
*/ | ||
@@ -50,3 +54,6 @@ export class BSONError extends Error { | ||
/** @public */ | ||
/** | ||
* @public | ||
* @category Error | ||
*/ | ||
export class BSONVersionError extends BSONError { | ||
@@ -63,1 +70,19 @@ get name(): 'BSONVersionError' { | ||
} | ||
/** | ||
* @public | ||
* @category Error | ||
* | ||
* An error generated when BSON functions encounter an unexpected input | ||
* or reaches an unexpected/invalid internal state | ||
* | ||
*/ | ||
export class BSONRuntimeError extends BSONError { | ||
get name(): 'BSONRuntimeError' { | ||
return 'BSONRuntimeError'; | ||
} | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
} |
@@ -14,3 +14,3 @@ import { Binary } from './binary'; | ||
import { Double } from './double'; | ||
import { BSONError, BSONVersionError } from './error'; | ||
import { BSONError, BSONRuntimeError, BSONVersionError } from './error'; | ||
import { Int32 } from './int_32'; | ||
@@ -97,2 +97,3 @@ import { Long } from './long'; | ||
if (options.useBigInt64) { | ||
// eslint-disable-next-line no-restricted-globals -- This is allowed here as useBigInt64=true | ||
return BigInt(value); | ||
@@ -129,2 +130,4 @@ } | ||
else if (typeof d === 'string') date.setTime(Date.parse(d)); | ||
else if (typeof d === 'bigint') date.setTime(Number(d)); | ||
else throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`); | ||
} else { | ||
@@ -134,2 +137,4 @@ if (typeof d === 'string') date.setTime(Date.parse(d)); | ||
else if (typeof d === 'number' && options.relaxed) date.setTime(d); | ||
else if (typeof d === 'bigint') date.setTime(Number(d)); | ||
else throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`); | ||
} | ||
@@ -256,2 +261,3 @@ return date; | ||
if (typeof value === 'bigint') { | ||
/* eslint-disable no-restricted-globals -- This is allowed as we are accepting a bigint as input */ | ||
if (!options.relaxed) { | ||
@@ -261,2 +267,3 @@ return { $numberLong: BigInt.asIntN(64, value).toString() }; | ||
return Number(BigInt.asIntN(64, value)); | ||
/* eslint-enable */ | ||
} | ||
@@ -263,0 +270,0 @@ |
@@ -899,2 +899,3 @@ import { BSONValue } from './bson_value'; | ||
toBigInt(): bigint { | ||
// eslint-disable-next-line no-restricted-globals -- This is allowed here as it is explicitly requesting a bigint | ||
return BigInt(this.toString()); | ||
@@ -1046,4 +1047,6 @@ } | ||
if (useBigInt64) { | ||
/* eslint-disable no-restricted-globals -- Can use BigInt here as useBigInt64=true */ | ||
const bigIntResult = BigInt(doc.$numberLong); | ||
return BigInt.asIntN(64, bigIntResult); | ||
/* eslint-enable */ | ||
} | ||
@@ -1050,0 +1053,0 @@ |
@@ -25,3 +25,3 @@ import { BSONError } from '../error'; | ||
declare const Buffer: NodeJsBufferConstructor; | ||
declare const require: (mod: 'node:crypto') => { randomBytes: (byteLength: number) => Uint8Array }; | ||
declare const require: (mod: 'crypto') => { randomBytes: (byteLength: number) => Uint8Array }; | ||
@@ -52,3 +52,3 @@ /** @internal */ | ||
try { | ||
return require('node:crypto').randomBytes; | ||
return require('crypto').randomBytes; | ||
} catch { | ||
@@ -55,0 +55,0 @@ return nodejsMathRandomBytes; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1275790
19351
36