bson
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -13,6 +13,7 @@ { | ||
"bson.d.ts", | ||
"etc/prepare.js" | ||
"etc/prepare.js", | ||
"vendor" | ||
], | ||
"types": "bson.d.ts", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"author": { | ||
@@ -30,3 +31,4 @@ "name": "The MongoDB NodeJS Team", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"@microsoft/api-extractor": "^7.34.7", | ||
"@microsoft/api-extractor": "^7.35.1", | ||
"@octokit/core": "^4.2.4", | ||
"@rollup/plugin-node-resolve": "^15.0.2", | ||
@@ -54,3 +56,2 @@ "@rollup/plugin-typescript": "^11.1.0", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.0", | ||
"rollup": "^3.21.4", | ||
@@ -63,3 +64,3 @@ "sinon": "^15.0.4", | ||
"tsd": "^0.28.1", | ||
"typescript": "^4.9.4", | ||
"typescript": "^5.0.4", | ||
"typescript-cached-transpile": "0.0.6", | ||
@@ -92,3 +93,3 @@ "uuid": "^9.0.0", | ||
}, | ||
"react-native": "./lib/bson.cjs", | ||
"react-native": "./lib/bson.rn.cjs", | ||
"browser": "./lib/bson.mjs" | ||
@@ -111,3 +112,3 @@ }, | ||
"build:ts": "node ./node_modules/typescript/bin/tsc", | ||
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && rimraf 'lib/**/*.d.ts*' lib/parser lib/utils", | ||
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && node etc/clean_definition_files.cjs", | ||
"build:bundle": "rollup -c rollup.config.mjs", | ||
@@ -114,0 +115,0 @@ "build": "npm run build:dts && npm run build:bundle", |
@@ -191,5 +191,6 @@ # BSON parser | ||
BSON requires that `TextEncoder`, `TextDecoder`, `atob`, `btoa`, and `crypto.getRandomValues` are available globally. These are present in most Javascript runtimes but require polyfilling in React Native. Polyfills for the missing functionality can be installed with the following command: | ||
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` imported from React Native and therefore doesn't expect users to polyfill these. One additional polyfill, `crypto.getRandomValues` is recommended and can be installed with the following command: | ||
```sh | ||
npm install --save react-native-get-random-values text-encoding-polyfill base-64 | ||
npm install --save react-native-get-random-values | ||
``` | ||
@@ -201,10 +202,2 @@ | ||
// Required Polyfills For ReactNative | ||
import {encode, decode} from 'base-64'; | ||
if (global.btoa == null) { | ||
global.btoa = encode; | ||
} | ||
if (global.atob == null) { | ||
global.atob = decode; | ||
} | ||
import 'text-encoding-polyfill'; | ||
import 'react-native-get-random-values'; | ||
@@ -219,3 +212,3 @@ ``` | ||
This will cause React Native to import the `node_modules/bson/lib/bson.cjs` bundle (see the `"react-native"` setting we have in the `"exports"` section of our [package.json](./package.json).) | ||
This will cause React Native to import the `node_modules/bson/lib/bson.rn.cjs` bundle (see the `"react-native"` setting we have in the `"exports"` section of our [package.json](./package.json).) | ||
@@ -222,0 +215,0 @@ ### Technical Note about React Native module import |
@@ -226,4 +226,5 @@ import { isUint8Array } from './parser/utils'; | ||
if (encoding === 'base64') return ByteUtils.toBase64(this.buffer); | ||
if (encoding === 'utf8' || encoding === 'utf-8') return ByteUtils.toUTF8(this.buffer); | ||
return ByteUtils.toUTF8(this.buffer); | ||
if (encoding === 'utf8' || encoding === 'utf-8') | ||
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength); | ||
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength); | ||
} | ||
@@ -230,0 +231,0 @@ |
@@ -13,4 +13,4 @@ import { Binary, UUID } from './binary'; | ||
// Parts of the parser | ||
import { internalDeserialize, DeserializeOptions } from './parser/deserializer'; | ||
import { serializeInto, SerializeOptions } from './parser/serializer'; | ||
import { internalDeserialize, type DeserializeOptions } from './parser/deserializer'; | ||
import { serializeInto, type SerializeOptions } from './parser/serializer'; | ||
import { BSONRegExp } from './regexp'; | ||
@@ -17,0 +17,0 @@ import { BSONSymbol } from './symbol'; |
@@ -5,3 +5,3 @@ import { Binary, UUID } from '../binary'; | ||
import * as constants from '../constants'; | ||
import { DBRef, DBRefLike, isDBRefLike } from '../db_ref'; | ||
import { DBRef, type DBRefLike, isDBRefLike } from '../db_ref'; | ||
import { Decimal128 } from '../decimal128'; | ||
@@ -240,3 +240,3 @@ import { Double } from '../double'; | ||
// Represents the key | ||
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer.subarray(index, i)); | ||
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i); | ||
@@ -481,3 +481,3 @@ // shouldValidateKey is true if the key should be validated, false otherwise | ||
// Return the C string | ||
const source = ByteUtils.toUTF8(buffer.subarray(index, i)); | ||
const source = ByteUtils.toUTF8(buffer, index, i); | ||
// Create the regexp | ||
@@ -495,3 +495,3 @@ index = i + 1; | ||
// Return the C string | ||
const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i)); | ||
const regExpOptions = ByteUtils.toUTF8(buffer, index, i); | ||
index = i + 1; | ||
@@ -528,3 +528,3 @@ | ||
// Return the C string | ||
const source = ByteUtils.toUTF8(buffer.subarray(index, i)); | ||
const source = ByteUtils.toUTF8(buffer, index, i); | ||
index = i + 1; | ||
@@ -541,3 +541,3 @@ | ||
// Return the C string | ||
const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i)); | ||
const regExpOptions = ByteUtils.toUTF8(buffer, index, i); | ||
index = i + 1; | ||
@@ -687,3 +687,3 @@ | ||
} | ||
const namespace = ByteUtils.toUTF8(buffer.subarray(index, index + stringSize - 1)); | ||
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1); | ||
// Update parse index position | ||
@@ -745,3 +745,3 @@ index = index + stringSize; | ||
) { | ||
const value = ByteUtils.toUTF8(buffer.subarray(start, end)); | ||
const value = ByteUtils.toUTF8(buffer, start, end); | ||
// if utf8 validation is on, do the check | ||
@@ -748,0 +748,0 @@ if (shouldValidateUtf8) { |
@@ -64,9 +64,11 @@ import { BSONError } from './error'; | ||
} | ||
if (low.t < 0) { | ||
const t = Number(low.t); | ||
const i = Number(low.i); | ||
if (t < 0 || Number.isNaN(t)) { | ||
throw new BSONError('Timestamp constructed from { t, i } must provide a positive t'); | ||
} | ||
if (low.i < 0) { | ||
if (i < 0 || Number.isNaN(i)) { | ||
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i'); | ||
} | ||
if (low.t > 0xffff_ffff) { | ||
if (t > 0xffff_ffff) { | ||
throw new BSONError( | ||
@@ -76,3 +78,3 @@ 'Timestamp constructed from { t, i } must provide t equal or less than uint32 max' | ||
} | ||
if (low.i > 0xffff_ffff) { | ||
if (i > 0xffff_ffff) { | ||
throw new BSONError( | ||
@@ -83,3 +85,3 @@ 'Timestamp constructed from { t, i } must provide i equal or less than uint32 max' | ||
super(low.i.valueOf(), low.t.valueOf(), true); | ||
super(i, t, true); | ||
} else { | ||
@@ -86,0 +88,0 @@ throw new BSONError( |
@@ -29,3 +29,3 @@ import { nodeJsByteUtils } from './node_byte_utils'; | ||
/** Create a string from utf8 code units */ | ||
toUTF8: (buffer: Uint8Array) => string; | ||
toUTF8: (buffer: Uint8Array, start: number, end: number) => string; | ||
/** Get the utf8 code unit count from a string if it were to be transformed to utf8 */ | ||
@@ -32,0 +32,0 @@ utf8ByteLength: (input: string) => number; |
@@ -8,3 +8,3 @@ import { BSONError } from '../error'; | ||
copy(target: Uint8Array, targetStart: number, sourceStart: number, sourceEnd: number): number; | ||
toString: (this: Uint8Array, encoding: NodeJsEncoding) => string; | ||
toString: (this: Uint8Array, encoding: NodeJsEncoding, start?: number, end?: number) => string; | ||
equals: (this: Uint8Array, other: Uint8Array) => boolean; | ||
@@ -129,4 +129,4 @@ }; | ||
toUTF8(buffer: Uint8Array): string { | ||
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8'); | ||
toUTF8(buffer: Uint8Array, start: number, end: number): string { | ||
return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end); | ||
}, | ||
@@ -133,0 +133,0 @@ |
@@ -175,4 +175,4 @@ import { BSONError } from '../error'; | ||
toUTF8(uint8array: Uint8Array): string { | ||
return new TextDecoder('utf8', { fatal: false }).decode(uint8array); | ||
toUTF8(uint8array: Uint8Array, start: number, end: number): string { | ||
return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end)); | ||
}, | ||
@@ -179,0 +179,0 @@ |
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
2264298
28715
50
1
239