Socket
Socket
Sign inDemoInstall

bson

Package Overview
Dependencies
0
Maintainers
8
Versions
161
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.4.0 to 6.5.0

src/parser/on_demand/index.ts

50

bson.d.ts

@@ -27,2 +27,4 @@ /**

static readonly SUBTYPE_COLUMN = 7;
/** Sensitive BSON type */
static readonly SUBTYPE_SENSITIVE = 8;
/** User BSON type */

@@ -144,2 +146,3 @@ static readonly SUBTYPE_USER_DEFINED = 128;

EJSON,
onDemand,
Document,

@@ -153,2 +156,14 @@ CalculateObjectSizeOptions

* @public
* @experimental
*/
declare type BSONElement = [
type: number,
nameOffset: number,
nameLength: number,
offset: number,
length: number
];
/**
* @public
* @category Error

@@ -179,2 +194,17 @@ *

/**
* @public
* @category Error
*
* @experimental
*
* An error generated when BSON bytes are invalid.
* Reports the offset the parser was able to reach before encountering the error.
*/
declare class BSONOffsetError extends BSONError {
get name(): 'BSONOffsetError';
offset: number;
constructor(message: string, offset: number);
}
/**
* A class representation of the BSON RegExp type.

@@ -1114,2 +1144,22 @@ * @public

/**
* @experimental
* @public
*
* A new set of BSON APIs that are currently experimental and not intended for production use.
*/
declare type OnDemand = {
BSONOffsetError: {
new (message: string, offset: number): BSONOffsetError;
isBSONError(value: unknown): value is BSONError;
};
parseToElements: (this: void, bytes: Uint8Array, startOffset?: number) => Iterable<BSONElement>;
};
/**
* @experimental
* @public
*/
export declare const onDemand: OnDemand;
/**
* Parse an Extended JSON string, constructing the JavaScript value or object described by that

@@ -1116,0 +1166,0 @@ * string.

2

package.json

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

"types": "bson.d.ts",
"version": "6.4.0",
"version": "6.5.0",
"author": {

@@ -20,0 +20,0 @@ "name": "The MongoDB NodeJS Team",

@@ -59,2 +59,4 @@ import { type InspectFn, defaultInspect, isAnyArrayBuffer, isUint8Array } from './parser/utils';

static readonly SUBTYPE_COLUMN = 7;
/** Sensitive BSON type */
static readonly SUBTYPE_SENSITIVE = 8;
/** User BSON type */

@@ -61,0 +63,0 @@ static readonly SUBTYPE_USER_DEFINED = 128;

@@ -57,2 +57,3 @@ import { Binary, UUID } from './binary';

export { EJSON } from './extended_json';
export { onDemand } from './parser/on_demand/index';

@@ -59,0 +60,0 @@ /** @public */

@@ -112,2 +112,5 @@ /** @internal */

/** Sensitive BSON type @internal */
export const BSON_BINARY_SUBTYPE_SENSITIVE = 8;
/** Binary User Defined Type @internal */

@@ -114,0 +117,0 @@ export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;

@@ -84,1 +84,23 @@ import { BSON_MAJOR_VERSION } from './constants';

}
/**
* @public
* @category Error
*
* @experimental
*
* An error generated when BSON bytes are invalid.
* Reports the offset the parser was able to reach before encountering the error.
*/
export class BSONOffsetError extends BSONError {
public get name(): 'BSONOffsetError' {
return 'BSONOffsetError';
}
public offset: number;
constructor(message: string, offset: number) {
super(`${message}. offset: ${offset}`);
this.offset = offset;
}
}
const FLOAT = new Float64Array(1);
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
FLOAT[0] = -1;
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
const isBigEndian = FLOAT_BYTES[7] === 0;
/**

@@ -53,13 +58,25 @@ * Number parsing and serializing utilities.

/** Reads a little-endian 64-bit float from source */
getFloat64LE(source: Uint8Array, offset: number): number {
FLOAT_BYTES[0] = source[offset];
FLOAT_BYTES[1] = source[offset + 1];
FLOAT_BYTES[2] = source[offset + 2];
FLOAT_BYTES[3] = source[offset + 3];
FLOAT_BYTES[4] = source[offset + 4];
FLOAT_BYTES[5] = source[offset + 5];
FLOAT_BYTES[6] = source[offset + 6];
FLOAT_BYTES[7] = source[offset + 7];
return FLOAT[0];
},
getFloat64LE: isBigEndian
? (source: Uint8Array, offset: number) => {
FLOAT_BYTES[7] = source[offset];
FLOAT_BYTES[6] = source[offset + 1];
FLOAT_BYTES[5] = source[offset + 2];
FLOAT_BYTES[4] = source[offset + 3];
FLOAT_BYTES[3] = source[offset + 4];
FLOAT_BYTES[2] = source[offset + 5];
FLOAT_BYTES[1] = source[offset + 6];
FLOAT_BYTES[0] = source[offset + 7];
return FLOAT[0];
}
: (source: Uint8Array, offset: number) => {
FLOAT_BYTES[0] = source[offset];
FLOAT_BYTES[1] = source[offset + 1];
FLOAT_BYTES[2] = source[offset + 2];
FLOAT_BYTES[3] = source[offset + 3];
FLOAT_BYTES[4] = source[offset + 4];
FLOAT_BYTES[5] = source[offset + 5];
FLOAT_BYTES[6] = source[offset + 6];
FLOAT_BYTES[7] = source[offset + 7];
return FLOAT[0];
},

@@ -124,14 +141,27 @@ /** Writes a big-endian 32-bit integer to destination, can be signed or unsigned */

/** Writes a little-endian 64-bit float to destination */
setFloat64LE(destination: Uint8Array, offset: number, value: number): 8 {
FLOAT[0] = value;
destination[offset] = FLOAT_BYTES[0];
destination[offset + 1] = FLOAT_BYTES[1];
destination[offset + 2] = FLOAT_BYTES[2];
destination[offset + 3] = FLOAT_BYTES[3];
destination[offset + 4] = FLOAT_BYTES[4];
destination[offset + 5] = FLOAT_BYTES[5];
destination[offset + 6] = FLOAT_BYTES[6];
destination[offset + 7] = FLOAT_BYTES[7];
return 8;
}
setFloat64LE: isBigEndian
? (destination: Uint8Array, offset: number, value: number) => {
FLOAT[0] = value;
destination[offset] = FLOAT_BYTES[7];
destination[offset + 1] = FLOAT_BYTES[6];
destination[offset + 2] = FLOAT_BYTES[5];
destination[offset + 3] = FLOAT_BYTES[4];
destination[offset + 4] = FLOAT_BYTES[3];
destination[offset + 5] = FLOAT_BYTES[2];
destination[offset + 6] = FLOAT_BYTES[1];
destination[offset + 7] = FLOAT_BYTES[0];
return 8;
}
: (destination: Uint8Array, offset: number, value: number) => {
FLOAT[0] = value;
destination[offset] = FLOAT_BYTES[0];
destination[offset + 1] = FLOAT_BYTES[1];
destination[offset + 2] = FLOAT_BYTES[2];
destination[offset + 3] = FLOAT_BYTES[3];
destination[offset + 4] = FLOAT_BYTES[4];
destination[offset + 5] = FLOAT_BYTES[5];
destination[offset + 6] = FLOAT_BYTES[6];
destination[offset + 7] = FLOAT_BYTES[7];
return 8;
}
};

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc