Comparing version 5.2.0 to 5.3.0
@@ -283,3 +283,3 @@ /** | ||
/** @public */ | ||
export declare type BSONType = typeof BSONType[keyof typeof BSONType]; | ||
export declare type BSONType = (typeof BSONType)[keyof typeof BSONType]; | ||
@@ -420,17 +420,41 @@ /** @public */ | ||
export declare interface DeserializeOptions { | ||
/** when deserializing a Long will return as a BigInt. */ | ||
/** | ||
* when deserializing a Long return as a BigInt. | ||
* @defaultValue `false` | ||
*/ | ||
useBigInt64?: boolean; | ||
/** when deserializing a Long will fit it into a Number if it's smaller than 53 bits. */ | ||
/** | ||
* when deserializing a Long will fit it into a Number if it's smaller than 53 bits. | ||
* @defaultValue `true` | ||
*/ | ||
promoteLongs?: boolean; | ||
/** when deserializing a Binary will return it as a node.js Buffer instance. */ | ||
/** | ||
* when deserializing a Binary will return it as a node.js Buffer instance. | ||
* @defaultValue `false` | ||
*/ | ||
promoteBuffers?: boolean; | ||
/** when deserializing will promote BSON values to their Node.js closest equivalent types. */ | ||
/** | ||
* when deserializing will promote BSON values to their Node.js closest equivalent types. | ||
* @defaultValue `true` | ||
*/ | ||
promoteValues?: boolean; | ||
/** allow to specify if there what fields we wish to return as unserialized raw buffer. */ | ||
/** | ||
* allow to specify if there what fields we wish to return as unserialized raw buffer. | ||
* @defaultValue `null` | ||
*/ | ||
fieldsAsRaw?: Document; | ||
/** return BSON regular expressions as BSONRegExp instances. */ | ||
/** | ||
* return BSON regular expressions as BSONRegExp instances. | ||
* @defaultValue `false` | ||
*/ | ||
bsonRegExp?: boolean; | ||
/** allows the buffer to be larger than the parsed BSON object. */ | ||
/** | ||
* allows the buffer to be larger than the parsed BSON object. | ||
* @defaultValue `false` | ||
*/ | ||
allowObjectSmallerThanBufferSize?: boolean; | ||
/** Offset into buffer to begin reading document from */ | ||
/** | ||
* Offset into buffer to begin reading document from | ||
* @defaultValue `0` | ||
*/ | ||
index?: number; | ||
@@ -527,7 +551,15 @@ raw?: boolean; | ||
export declare type EJSONOptions = { | ||
/** Output using the Extended JSON v1 spec */ | ||
/** | ||
* Output using the Extended JSON v1 spec | ||
* @defaultValue `false` | ||
*/ | ||
legacy?: boolean; | ||
/** Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types */ | ||
/** | ||
* Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types | ||
* @defaultValue `false` */ | ||
relaxed?: boolean; | ||
/** Enable native bigint support */ | ||
/** | ||
* Enable native bigint support | ||
* @defaultValue `false` | ||
*/ | ||
useBigInt64?: boolean; | ||
@@ -1055,10 +1087,23 @@ }; | ||
export declare interface SerializeOptions { | ||
/** the serializer will check if keys are valid. */ | ||
/** | ||
* the serializer will check if keys are valid. | ||
* @defaultValue `false` | ||
*/ | ||
checkKeys?: boolean; | ||
/** serialize the javascript functions **(default:false)**. */ | ||
/** | ||
* serialize the javascript functions | ||
* @defaultValue `false` | ||
*/ | ||
serializeFunctions?: boolean; | ||
/** serialize will not emit undefined fields **(default:true)** */ | ||
/** | ||
* serialize will not emit undefined fields | ||
* note that the driver sets this to `false` | ||
* @defaultValue `true` | ||
*/ | ||
ignoreUndefined?: boolean; | ||
/* Excluded from this release type: minInternalBufferSize */ | ||
/** the index in the buffer where we wish to start serializing into */ | ||
/** | ||
* the index in the buffer where we wish to start serializing into | ||
* @defaultValue `0` | ||
*/ | ||
index?: number; | ||
@@ -1081,3 +1126,3 @@ } | ||
* | ||
* @param size - The desired size for the internal serialization buffer | ||
* @param size - The desired size for the internal serialization buffer in bytes | ||
* @public | ||
@@ -1115,3 +1160,3 @@ */ | ||
* @category BSONType | ||
* */ | ||
*/ | ||
export declare class Timestamp extends LongWithoutOverridesClass { | ||
@@ -1177,7 +1222,9 @@ get _bsontype(): 'Timestamp'; | ||
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; | ||
/* Excluded from this release type: __id */ | ||
/** | ||
* Create an UUID type | ||
* Create a UUID type | ||
* | ||
* When the argument to the constructor is omitted a random v4 UUID will be generated. | ||
* | ||
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer. | ||
@@ -1195,3 +1242,3 @@ */ | ||
* @param includeDashes - should the string exclude dash-separators. | ||
* */ | ||
*/ | ||
toHexString(includeDashes?: boolean): string; | ||
@@ -1225,3 +1272,3 @@ /** | ||
*/ | ||
static isValid(input: string | Uint8Array | UUID): boolean; | ||
static isValid(input: string | Uint8Array | UUID | Binary): boolean; | ||
/** | ||
@@ -1234,2 +1281,4 @@ * Creates an UUID from a hex string representation of an UUID. | ||
static createFromBase64(base64: string): UUID; | ||
/* Excluded from this release type: bytesFromString */ | ||
/* Excluded from this release type: isValidUUIDString */ | ||
inspect(): string; | ||
@@ -1236,0 +1285,0 @@ } |
@@ -16,3 +16,3 @@ { | ||
"types": "bson.d.ts", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"author": { | ||
@@ -30,28 +30,28 @@ "name": "The MongoDB NodeJS Team", | ||
"@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"@microsoft/api-extractor": "^7.33.7", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@rollup/plugin-typescript": "^10.0.1", | ||
"@types/chai": "^4.3.4", | ||
"@microsoft/api-extractor": "^7.34.7", | ||
"@rollup/plugin-node-resolve": "^15.0.2", | ||
"@rollup/plugin-typescript": "^11.1.0", | ||
"@types/chai": "^4.3.5", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^18.11.12", | ||
"@types/sinon": "^10.0.13", | ||
"@types/node": "^18.16.3", | ||
"@types/sinon": "^10.0.14", | ||
"@types/sinon-chai": "^3.2.9", | ||
"@typescript-eslint/eslint-plugin": "^5.46.0", | ||
"@typescript-eslint/parser": "^5.46.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.2", | ||
"@typescript-eslint/parser": "^5.59.2", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.3.7", | ||
"chalk": "^5.1.2", | ||
"eslint": "^8.29.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"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", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-tsdoc": "^0.2.17", | ||
"magic-string": "^0.27.0", | ||
"mocha": "10.1.0", | ||
"node-fetch": "^3.2.10", | ||
"magic-string": "^0.30.0", | ||
"mocha": "10.2.0", | ||
"node-fetch": "^3.3.1", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.8.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^3.7.1", | ||
"sinon": "^15.0.0", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^5.0.0", | ||
"rollup": "^3.21.4", | ||
"sinon": "^15.0.4", | ||
"sinon-chai": "^3.7.0", | ||
@@ -61,3 +61,3 @@ "source-map-support": "^0.5.21", | ||
"ts-node": "^10.9.1", | ||
"tsd": "^0.25.0", | ||
"tsd": "^0.28.1", | ||
"typescript": "^4.9.4", | ||
@@ -64,0 +64,0 @@ "typescript-cached-transpile": "0.0.6", |
127
README.md
@@ -72,32 +72,6 @@ # BSON parser | ||
### Objects | ||
### BSON | ||
<dl> | ||
<dt><a href="#EJSON">EJSON</a> : <code>object</code></dt> | ||
<dd></dd> | ||
</dl> | ||
[API documentation](https://mongodb.github.io/node-mongodb-native/Next/modules/BSON.html) | ||
### Functions | ||
<dl> | ||
<dt><a href="#setInternalBufferSize">setInternalBufferSize(size)</a></dt> | ||
<dd><p>Sets the size of the internal serialization buffer.</p> | ||
</dd> | ||
<dt><a href="#serialize">serialize(object)</a> ⇒ <code>Buffer</code></dt> | ||
<dd><p>Serialize a Javascript object.</p> | ||
</dd> | ||
<dt><a href="#serializeWithBufferAndIndex">serializeWithBufferAndIndex(object, buffer)</a> ⇒ <code>Number</code></dt> | ||
<dd><p>Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.</p> | ||
</dd> | ||
<dt><a href="#deserialize">deserialize(buffer)</a> ⇒ <code>Object</code></dt> | ||
<dd><p>Deserialize data as BSON.</p> | ||
</dd> | ||
<dt><a href="#calculateObjectSize">calculateObjectSize(object)</a> ⇒ <code>Number</code></dt> | ||
<dd><p>Calculate the bson size for a passed in Javascript object.</p> | ||
</dd> | ||
<dt><a href="#deserializeStream">deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, [options])</a> ⇒ <code>Number</code></dt> | ||
<dd><p>Deserialize stream data as BSON documents.</p> | ||
</dd> | ||
</dl> | ||
<a name="EJSON"></a> | ||
@@ -193,99 +167,2 @@ | ||
<a name="setInternalBufferSize"></a> | ||
### setInternalBufferSize(size) | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| size | <code>number</code> | The desired size for the internal serialization buffer | | ||
Sets the size of the internal serialization buffer. | ||
<a name="serialize"></a> | ||
### serialize(object) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| object | <code>Object</code> | | the Javascript object to serialize. | | ||
| [options.checkKeys] | <code>Boolean</code> | | the serializer will check if keys are valid. | | ||
| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. | | ||
| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. | | ||
Serialize a Javascript object. | ||
**Returns**: <code>Buffer</code> - returns the Buffer object containing the serialized object. | ||
<a name="serializeWithBufferAndIndex"></a> | ||
### serializeWithBufferAndIndex(object, buffer) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| object | <code>Object</code> | | the Javascript object to serialize. | | ||
| buffer | <code>Buffer</code> | | the Buffer you pre-allocated to store the serialized BSON object. | | ||
| [options.checkKeys] | <code>Boolean</code> | | the serializer will check if keys are valid. | | ||
| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. | | ||
| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. | | ||
| [options.index] | <code>Number</code> | | the index in the buffer where we wish to start serializing into. | | ||
Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization. | ||
**Returns**: <code>Number</code> - returns the index pointing to the last written byte in the buffer. | ||
<a name="deserialize"></a> | ||
### deserialize(buffer) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| buffer | <code>Buffer</code> | | the buffer containing the serialized set of BSON documents. | | ||
| [options.evalFunctions] | <code>Object</code> | <code>false</code> | evaluate functions in the BSON document scoped to the object deserialized. | | ||
| [options.cacheFunctions] | <code>Object</code> | <code>false</code> | cache evaluated functions for reuse. | | ||
| [options.useBigInt64] | <code>Object</code> | <code>false</code> | when deserializing a Long will return a BigInt. | | ||
| [options.promoteLongs] | <code>Object</code> | <code>true</code> | when deserializing a Long will fit it into a Number if it's smaller than 53 bits | | ||
| [options.promoteBuffers] | <code>Object</code> | <code>false</code> | when deserializing a Binary will return it as a node.js Buffer instance. | | ||
| [options.promoteValues] | <code>Object</code> | <code>false</code> | when deserializing will promote BSON values to their Node.js closest equivalent types. | | ||
| [options.fieldsAsRaw] | <code>Object</code> | <code></code> | allow to specify if there what fields we wish to return as unserialized raw buffer. | | ||
| [options.bsonRegExp] | <code>Object</code> | <code>false</code> | return BSON regular expressions as BSONRegExp instances. | | ||
| [options.allowObjectSmallerThanBufferSize] | <code>boolean</code> | <code>false</code> | allows the buffer to be larger than the parsed BSON object. | | ||
Deserialize data as BSON. | ||
**Returns**: <code>Object</code> - returns the deserialized Javascript Object. | ||
<a name="calculateObjectSize"></a> | ||
### calculateObjectSize(object) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| object | <code>Object</code> | | the Javascript object to calculate the BSON byte size for. | | ||
| [options.serializeFunctions] | <code>Boolean</code> | <code>false</code> | serialize the javascript functions **(default:false)**. | | ||
| [options.ignoreUndefined] | <code>Boolean</code> | <code>true</code> | ignore undefined fields **(default:true)**. | | ||
Calculate the bson size for a passed in Javascript object. | ||
**Returns**: <code>Number</code> - returns the number of bytes the BSON object will take up. | ||
<a name="deserializeStream"></a> | ||
### deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, [options]) | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| data | <code>Buffer</code> | | the buffer containing the serialized set of BSON documents. | | ||
| startIndex | <code>Number</code> | | the start index in the data Buffer where the deserialization is to start. | | ||
| numberOfDocuments | <code>Number</code> | | number of documents to deserialize. | | ||
| documents | <code>Array</code> | | an array where to store the deserialized documents. | | ||
| docStartIndex | <code>Number</code> | | the index in the documents array from where to start inserting documents. | | ||
| [options] | <code>Object</code> | | additional options used for the deserialization. | | ||
| [options.evalFunctions] | <code>Object</code> | <code>false</code> | evaluate functions in the BSON document scoped to the object deserialized. | | ||
| [options.cacheFunctions] | <code>Object</code> | <code>false</code> | cache evaluated functions for reuse. | | ||
| [options.promoteLongs] | <code>Object</code> | <code>true</code> | when deserializing a Long will fit it into a Number if it's smaller than 53 bits | | ||
| [options.promoteBuffers] | <code>Object</code> | <code>false</code> | when deserializing a Binary will return it as a node.js Buffer instance. | | ||
| [options.promoteValues] | <code>Object</code> | <code>false</code> | when deserializing will promote BSON values to their Node.js closest equivalent types. | | ||
| [options.fieldsAsRaw] | <code>Object</code> | <code></code> | allow to specify if there what fields we wish to return as unserialized raw buffer. | | ||
| [options.bsonRegExp] | <code>Object</code> | <code>false</code> | return BSON regular expressions as BSONRegExp instances. | | ||
Deserialize stream data as BSON documents. | ||
**Returns**: <code>Number</code> - returns the next index in the buffer after deserialization **x** numbers of documents. | ||
## Error Handling | ||
@@ -292,0 +169,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { bufferToUuidHexString, uuidHexStringToBuffer, uuidValidateString } from './uuid_utils'; | ||
import { isUint8Array } from './parser/utils'; | ||
@@ -291,3 +290,3 @@ import type { EJSONOptions } from './extended_json'; | ||
type = 4; | ||
data = uuidHexStringToBuffer(doc.$uuid); | ||
data = UUID.bytesFromString(doc.$uuid); | ||
} | ||
@@ -315,3 +314,6 @@ if (!data) { | ||
}; | ||
const UUID_BYTE_LENGTH = 16; | ||
const UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i; | ||
const UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i; | ||
@@ -323,10 +325,9 @@ /** | ||
export class UUID extends Binary { | ||
static cacheHexString: boolean; | ||
/** UUID hexString cache @internal */ | ||
private __id?: string; | ||
/** @deprecated Hex string is no longer cached, this control will be removed in a future major release */ | ||
static cacheHexString = false; | ||
/** | ||
* Create an UUID type | ||
* Create a UUID type | ||
* | ||
* When the argument to the constructor is omitted a random v4 UUID will be generated. | ||
* | ||
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer. | ||
@@ -336,3 +337,2 @@ */ | ||
let bytes: Uint8Array; | ||
let hexStr; | ||
if (input == null) { | ||
@@ -342,7 +342,6 @@ bytes = UUID.generate(); | ||
bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer)); | ||
hexStr = input.__id; | ||
} else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) { | ||
bytes = ByteUtils.toLocalBufferType(input); | ||
} else if (typeof input === 'string') { | ||
bytes = uuidHexStringToBuffer(input); | ||
bytes = UUID.bytesFromString(input); | ||
} else { | ||
@@ -354,3 +353,2 @@ throw new BSONError( | ||
super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW); | ||
this.__id = hexStr; | ||
} | ||
@@ -368,6 +366,2 @@ | ||
this.buffer = value; | ||
if (UUID.cacheHexString) { | ||
this.__id = bufferToUuidHexString(value); | ||
} | ||
} | ||
@@ -378,15 +372,14 @@ | ||
* @param includeDashes - should the string exclude dash-separators. | ||
* */ | ||
*/ | ||
toHexString(includeDashes = true): string { | ||
if (UUID.cacheHexString && this.__id) { | ||
return this.__id; | ||
if (includeDashes) { | ||
return [ | ||
ByteUtils.toHex(this.buffer.subarray(0, 4)), | ||
ByteUtils.toHex(this.buffer.subarray(4, 6)), | ||
ByteUtils.toHex(this.buffer.subarray(6, 8)), | ||
ByteUtils.toHex(this.buffer.subarray(8, 10)), | ||
ByteUtils.toHex(this.buffer.subarray(10, 16)) | ||
].join('-'); | ||
} | ||
const uuidHexString = bufferToUuidHexString(this.id, includeDashes); | ||
if (UUID.cacheHexString) { | ||
this.__id = uuidHexString; | ||
} | ||
return uuidHexString; | ||
return ByteUtils.toHex(this.buffer); | ||
} | ||
@@ -457,3 +450,3 @@ | ||
*/ | ||
static isValid(input: string | Uint8Array | UUID): boolean { | ||
static isValid(input: string | Uint8Array | UUID | Binary): boolean { | ||
if (!input) { | ||
@@ -463,20 +456,15 @@ return false; | ||
if (input instanceof UUID) { | ||
return true; | ||
} | ||
if (typeof input === 'string') { | ||
return uuidValidateString(input); | ||
return UUID.isValidUUIDString(input); | ||
} | ||
if (isUint8Array(input)) { | ||
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3) | ||
if (input.byteLength !== UUID_BYTE_LENGTH) { | ||
return false; | ||
} | ||
return (input[6] & 0xf0) === 0x40 && (input[8] & 0x80) === 0x80; | ||
return input.byteLength === UUID_BYTE_LENGTH; | ||
} | ||
return false; | ||
return ( | ||
input._bsontype === 'Binary' && | ||
input.sub_type === this.SUBTYPE_UUID && | ||
input.buffer.byteLength === 16 | ||
); | ||
} | ||
@@ -489,3 +477,3 @@ | ||
static override createFromHexString(hexString: string): UUID { | ||
const buffer = uuidHexStringToBuffer(hexString); | ||
const buffer = UUID.bytesFromString(hexString); | ||
return new UUID(buffer); | ||
@@ -499,3 +487,23 @@ } | ||
/** @internal */ | ||
static bytesFromString(representation: string) { | ||
if (!UUID.isValidUUIDString(representation)) { | ||
throw new BSONError( | ||
'UUID string representation must be 32 hex digits or canonical hyphenated representation' | ||
); | ||
} | ||
return ByteUtils.fromHex(representation.replace(/-/g, '')); | ||
} | ||
/** | ||
* @internal | ||
* | ||
* Validates a string to be a hex digit sequence with or without dashes. | ||
* The canonical hyphenated representation of a uuid is hex in 8-4-4-4-12 groups. | ||
*/ | ||
static isValidUUIDString(representation: string) { | ||
return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation); | ||
} | ||
/** | ||
* Converts to a string representation of this Id. | ||
@@ -502,0 +510,0 @@ * |
@@ -73,3 +73,3 @@ import { Binary, UUID } from './binary'; | ||
* | ||
* @param size - The desired size for the internal serialization buffer | ||
* @param size - The desired size for the internal serialization buffer in bytes | ||
* @public | ||
@@ -76,0 +76,0 @@ */ |
@@ -141,2 +141,2 @@ /** @internal */ | ||
/** @public */ | ||
export type BSONType = typeof BSONType[keyof typeof BSONType]; | ||
export type BSONType = (typeof BSONType)[keyof typeof BSONType]; |
@@ -27,7 +27,15 @@ import { Binary } from './binary'; | ||
export type EJSONOptions = { | ||
/** Output using the Extended JSON v1 spec */ | ||
/** | ||
* Output using the Extended JSON v1 spec | ||
* @defaultValue `false` | ||
*/ | ||
legacy?: boolean; | ||
/** Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types */ | ||
/** | ||
* Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types | ||
* @defaultValue `false` */ | ||
relaxed?: boolean; | ||
/** Enable native bigint support */ | ||
/** | ||
* Enable native bigint support | ||
* @defaultValue `false` | ||
*/ | ||
useBigInt64?: boolean; | ||
@@ -34,0 +42,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import { Binary } from '../binary'; | ||
import { Binary, UUID } from '../binary'; | ||
import type { Document } from '../bson'; | ||
@@ -22,17 +22,41 @@ import { Code } from '../code'; | ||
export interface DeserializeOptions { | ||
/** when deserializing a Long will return as a BigInt. */ | ||
/** | ||
* when deserializing a Long return as a BigInt. | ||
* @defaultValue `false` | ||
*/ | ||
useBigInt64?: boolean; | ||
/** when deserializing a Long will fit it into a Number if it's smaller than 53 bits. */ | ||
/** | ||
* when deserializing a Long will fit it into a Number if it's smaller than 53 bits. | ||
* @defaultValue `true` | ||
*/ | ||
promoteLongs?: boolean; | ||
/** when deserializing a Binary will return it as a node.js Buffer instance. */ | ||
/** | ||
* when deserializing a Binary will return it as a node.js Buffer instance. | ||
* @defaultValue `false` | ||
*/ | ||
promoteBuffers?: boolean; | ||
/** when deserializing will promote BSON values to their Node.js closest equivalent types. */ | ||
/** | ||
* when deserializing will promote BSON values to their Node.js closest equivalent types. | ||
* @defaultValue `true` | ||
*/ | ||
promoteValues?: boolean; | ||
/** allow to specify if there what fields we wish to return as unserialized raw buffer. */ | ||
/** | ||
* allow to specify if there what fields we wish to return as unserialized raw buffer. | ||
* @defaultValue `null` | ||
*/ | ||
fieldsAsRaw?: Document; | ||
/** return BSON regular expressions as BSONRegExp instances. */ | ||
/** | ||
* return BSON regular expressions as BSONRegExp instances. | ||
* @defaultValue `false` | ||
*/ | ||
bsonRegExp?: boolean; | ||
/** allows the buffer to be larger than the parsed BSON object. */ | ||
/** | ||
* allows the buffer to be larger than the parsed BSON object. | ||
* @defaultValue `false` | ||
*/ | ||
allowObjectSmallerThanBufferSize?: boolean; | ||
/** Offset into buffer to begin reading document from */ | ||
/** | ||
* Offset into buffer to begin reading document from | ||
* @defaultValue `0` | ||
*/ | ||
index?: number; | ||
@@ -408,3 +432,3 @@ | ||
value = new Binary(buffer.slice(index, index + binarySize), subType); | ||
if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW) { | ||
if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) { | ||
value = value.toUUID(); | ||
@@ -437,6 +461,7 @@ } | ||
value = _buffer; | ||
} else if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW) { | ||
value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID(); | ||
} else { | ||
value = new Binary(buffer.slice(index, index + binarySize), subType); | ||
if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) { | ||
value = value.toUUID(); | ||
} | ||
} | ||
@@ -443,0 +468,0 @@ } |
@@ -19,11 +19,24 @@ import { Binary } from '../binary'; | ||
export interface SerializeOptions { | ||
/** the serializer will check if keys are valid. */ | ||
/** | ||
* the serializer will check if keys are valid. | ||
* @defaultValue `false` | ||
*/ | ||
checkKeys?: boolean; | ||
/** serialize the javascript functions **(default:false)**. */ | ||
/** | ||
* serialize the javascript functions | ||
* @defaultValue `false` | ||
*/ | ||
serializeFunctions?: boolean; | ||
/** serialize will not emit undefined fields **(default:true)** */ | ||
/** | ||
* serialize will not emit undefined fields | ||
* note that the driver sets this to `false` | ||
* @defaultValue `true` | ||
*/ | ||
ignoreUndefined?: boolean; | ||
/** @internal Resize internal buffer */ | ||
minInternalBufferSize?: number; | ||
/** the index in the buffer where we wish to start serializing into */ | ||
/** | ||
* the index in the buffer where we wish to start serializing into | ||
* @defaultValue `0` | ||
*/ | ||
index?: number; | ||
@@ -30,0 +43,0 @@ } |
@@ -30,3 +30,3 @@ import { BSONError } from './error'; | ||
* @category BSONType | ||
* */ | ||
*/ | ||
export class Timestamp extends LongWithoutOverridesClass { | ||
@@ -33,0 +33,0 @@ get _bsontype(): 'Timestamp' { |
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
1345769
78
20779
246