Comparing version 6.8.0-dev.20240907.sha.91ceaf05 to 6.8.0-dev.20240910.sha.833eaa41
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.resolveBSONOptions = resolveBSONOptions; | ||
exports.parseUtf8ValidationOption = parseUtf8ValidationOption; | ||
const bson_1 = require("bson"); | ||
@@ -75,2 +76,10 @@ var bson_2 = require("bson"); | ||
} | ||
/** @internal */ | ||
function parseUtf8ValidationOption(options) { | ||
const enableUtf8Validation = options?.enableUtf8Validation; | ||
if (enableUtf8Validation === false) { | ||
return { utf8: false }; | ||
} | ||
return { utf8: { writeErrors: false } }; | ||
} | ||
//# sourceMappingURL=bson.js.map |
@@ -160,2 +160,3 @@ "use strict"; | ||
exports.LEGAL_TLS_SOCKET_OPTIONS = [ | ||
'allowPartialTrustChain', | ||
'ALPNProtocols', | ||
@@ -162,0 +163,0 @@ 'ca', |
@@ -208,17 +208,8 @@ "use strict"; | ||
toObject(options) { | ||
const exactBSONOptions = { | ||
...(0, bson_1.pluckBSONSerializeOptions)(options ?? {}), | ||
validation: this.parseBsonSerializationOptions(options), | ||
return (0, bson_1.deserialize)(this.bson, { | ||
...options, | ||
index: this.offset, | ||
allowObjectSmallerThanBufferSize: true | ||
}; | ||
return (0, bson_1.deserialize)(this.bson, exactBSONOptions); | ||
}); | ||
} | ||
parseBsonSerializationOptions(options) { | ||
const enableUtf8Validation = options?.enableUtf8Validation; | ||
if (enableUtf8Validation === false) { | ||
return { utf8: false }; | ||
} | ||
return { utf8: { writeErrors: false } }; | ||
} | ||
/** Returns this document's bytes only */ | ||
@@ -225,0 +216,0 @@ toBytes() { |
@@ -69,3 +69,4 @@ "use strict"; | ||
promoteLongs: false, | ||
promoteBuffers: false | ||
promoteBuffers: false, | ||
validation: { utf8: true } | ||
}) ?? null); | ||
@@ -112,2 +113,9 @@ } | ||
} | ||
toObject(options) { | ||
const exactBSONOptions = { | ||
...(0, bson_1.pluckBSONSerializeOptions)(options ?? {}), | ||
validation: (0, bson_1.parseUtf8ValidationOption)(options) | ||
}; | ||
return super.toObject(exactBSONOptions); | ||
} | ||
} | ||
@@ -181,3 +189,4 @@ exports.MongoDBResponse = MongoDBResponse; | ||
promoteLongs: false, | ||
promoteBuffers: false | ||
promoteBuffers: false, | ||
validation: { utf8: true } | ||
}) ?? null); | ||
@@ -184,0 +193,0 @@ } |
@@ -1023,3 +1023,4 @@ "use strict"; | ||
srvPoller: { type: 'any' }, | ||
// Accepted NodeJS Options | ||
// Accepted Node.js Options | ||
allowPartialTrustChain: { type: 'any' }, | ||
minDHSize: { type: 'any' }, | ||
@@ -1026,0 +1027,0 @@ pskCallback: { type: 'any' }, |
@@ -74,2 +74,8 @@ "use strict"; | ||
} | ||
this.deserializationOptions = { | ||
...this.cursorOptions, | ||
validation: { | ||
utf8: options?.enableUtf8Validation === false ? false : true | ||
} | ||
}; | ||
} | ||
@@ -143,3 +149,3 @@ /** | ||
for (let count = 0; count < documentsToRead; count++) { | ||
const document = this.documents?.shift(this.cursorOptions); | ||
const document = this.documents?.shift(this.deserializationOptions); | ||
if (document != null) { | ||
@@ -229,3 +235,3 @@ bufferedDocs.push(document); | ||
do { | ||
const doc = this.documents?.shift(this.cursorOptions); | ||
const doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -247,3 +253,3 @@ if (this.transform != null) | ||
} | ||
let doc = this.documents?.shift(this.cursorOptions); | ||
let doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -255,3 +261,3 @@ if (this.transform != null) | ||
await this.fetchBatch(); | ||
doc = this.documents?.shift(this.cursorOptions); | ||
doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -258,0 +264,0 @@ if (this.transform != null) |
@@ -48,3 +48,3 @@ "use strict"; | ||
explain: verbosity ?? true | ||
}))).shift(this.aggregateOptions); | ||
}))).shift(this.deserializationOptions); | ||
} | ||
@@ -51,0 +51,0 @@ addStage(stage) { |
@@ -108,3 +108,3 @@ "use strict"; | ||
explain: verbosity ?? true | ||
}))).shift(this.findOptions); | ||
}))).shift(this.deserializationOptions); | ||
} | ||
@@ -111,0 +111,0 @@ /** Set the cursor query */ |
{ | ||
"name": "mongodb", | ||
"version": "6.8.0-dev.20240907.sha.91ceaf05", | ||
"version": "6.8.0-dev.20240910.sha.833eaa41", | ||
"description": "The official MongoDB driver for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -135,1 +135,12 @@ import { BSON, type DeserializeOptions, type SerializeOptions } from 'bson'; | ||
} | ||
/** @internal */ | ||
export function parseUtf8ValidationOption(options?: { enableUtf8Validation?: boolean }): { | ||
utf8: { writeErrors: false } | false; | ||
} { | ||
const enableUtf8Validation = options?.enableUtf8Validation; | ||
if (enableUtf8Validation === false) { | ||
return { utf8: false }; | ||
} | ||
return { utf8: { writeErrors: false } }; | ||
} |
@@ -252,2 +252,3 @@ import type { Socket, SocketConnectOpts } from 'net'; | ||
export const LEGAL_TLS_SOCKET_OPTIONS = [ | ||
'allowPartialTrustChain', | ||
'ALPNProtocols', | ||
@@ -254,0 +255,0 @@ 'ca', |
@@ -0,1 +1,2 @@ | ||
import { type DeserializeOptions } from 'bson'; | ||
import { type Readable, Transform, type TransformCallback } from 'stream'; | ||
@@ -490,3 +491,3 @@ import { clearTimeout, setTimeout } from 'timers'; | ||
// Otherwise, support raw flag. Raw only works for cursors that hardcode firstBatch/nextBatch fields | ||
const bsonOptions = | ||
const bsonOptions: DeserializeOptions = | ||
options.documentsReturnedIn == null || !options.raw | ||
@@ -493,0 +494,0 @@ ? options |
@@ -0,1 +1,3 @@ | ||
import { type DeserializeOptions } from 'bson'; | ||
import { | ||
@@ -5,3 +7,2 @@ Binary, | ||
BSONError, | ||
type BSONSerializeOptions, | ||
BSONType, | ||
@@ -14,3 +15,2 @@ deserialize, | ||
parseToElementsToArray, | ||
pluckBSONSerializeOptions, | ||
Timestamp, | ||
@@ -49,2 +49,10 @@ toUTF8 | ||
/** | ||
* @internal | ||
* | ||
* Options for `OnDemandDocument.toObject()`. Validation is required to ensure | ||
* that callers provide utf8 validation options. */ | ||
export type OnDemandDocumentDeserializeOptions = Omit<DeserializeOptions, 'validation'> & | ||
Required<Pick<DeserializeOptions, 'validation'>>; | ||
/** @internal */ | ||
@@ -336,22 +344,10 @@ export class OnDemandDocument { | ||
*/ | ||
public toObject(options?: BSONSerializeOptions): Record<string, any> { | ||
const exactBSONOptions = { | ||
...pluckBSONSerializeOptions(options ?? {}), | ||
validation: this.parseBsonSerializationOptions(options), | ||
public toObject(options?: OnDemandDocumentDeserializeOptions): Record<string, any> { | ||
return deserialize(this.bson, { | ||
...options, | ||
index: this.offset, | ||
allowObjectSmallerThanBufferSize: true | ||
}; | ||
return deserialize(this.bson, exactBSONOptions); | ||
}); | ||
} | ||
private parseBsonSerializationOptions(options?: { enableUtf8Validation?: boolean }): { | ||
utf8: { writeErrors: false } | false; | ||
} { | ||
const enableUtf8Validation = options?.enableUtf8Validation; | ||
if (enableUtf8Validation === false) { | ||
return { utf8: false }; | ||
} | ||
return { utf8: { writeErrors: false } }; | ||
} | ||
/** Returns this document's bytes only */ | ||
@@ -358,0 +354,0 @@ toBytes() { |
@@ -0,1 +1,3 @@ | ||
import { type DeserializeOptions } from 'bson'; | ||
import { | ||
@@ -8,2 +10,4 @@ type BSONElement, | ||
parseToElementsToArray, | ||
parseUtf8ValidationOption, | ||
pluckBSONSerializeOptions, | ||
type Timestamp | ||
@@ -14,3 +18,7 @@ } from '../../bson'; | ||
import { decorateDecryptionResult, ns } from '../../utils'; | ||
import { type JSTypeOf, OnDemandDocument } from './on_demand/document'; | ||
import { | ||
type JSTypeOf, | ||
OnDemandDocument, | ||
type OnDemandDocumentDeserializeOptions | ||
} from './on_demand/document'; | ||
@@ -117,3 +125,4 @@ // eslint-disable-next-line no-restricted-syntax | ||
promoteLongs: false, | ||
promoteBuffers: false | ||
promoteBuffers: false, | ||
validation: { utf8: true } | ||
}) ?? null | ||
@@ -171,2 +180,10 @@ ); | ||
} | ||
public override toObject(options?: BSONSerializeOptions): Record<string, any> { | ||
const exactBSONOptions = { | ||
...pluckBSONSerializeOptions(options ?? {}), | ||
validation: parseUtf8ValidationOption(options) | ||
}; | ||
return super.toObject(exactBSONOptions); | ||
} | ||
} | ||
@@ -255,3 +272,4 @@ | ||
promoteLongs: false, | ||
promoteBuffers: false | ||
promoteBuffers: false, | ||
validation: { utf8: true } | ||
}) ?? null | ||
@@ -261,3 +279,3 @@ ); | ||
public shift(options?: BSONSerializeOptions): any { | ||
public shift(options: OnDemandDocumentDeserializeOptions): any { | ||
if (this.iterated >= this.batchSize) { | ||
@@ -314,3 +332,3 @@ return null; | ||
override shift(options?: BSONSerializeOptions | undefined) { | ||
override shift(options?: DeserializeOptions) { | ||
if (this._length === 0) return null; | ||
@@ -317,0 +335,0 @@ this._length -= 1; |
@@ -1231,3 +1231,4 @@ import * as dns from 'dns'; | ||
srvPoller: { type: 'any' }, | ||
// Accepted NodeJS Options | ||
// Accepted Node.js Options | ||
allowPartialTrustChain: { type: 'any' }, | ||
minDHSize: { type: 'any' }, | ||
@@ -1234,0 +1235,0 @@ pskCallback: { type: 'any' }, |
import { Readable, Transform } from 'stream'; | ||
import { type BSONSerializeOptions, type Document, Long, pluckBSONSerializeOptions } from '../bson'; | ||
import { type OnDemandDocumentDeserializeOptions } from '../cmap/wire_protocol/on_demand/document'; | ||
import { type CursorResponse } from '../cmap/wire_protocol/responses'; | ||
@@ -161,2 +162,5 @@ import { | ||
/** @internal */ | ||
protected deserializationOptions: OnDemandDocumentDeserializeOptions; | ||
/** @internal */ | ||
protected constructor( | ||
@@ -215,2 +219,9 @@ client: MongoClient, | ||
} | ||
this.deserializationOptions = { | ||
...this.cursorOptions, | ||
validation: { | ||
utf8: options?.enableUtf8Validation === false ? false : true | ||
} | ||
}; | ||
} | ||
@@ -309,3 +320,3 @@ | ||
for (let count = 0; count < documentsToRead; count++) { | ||
const document = this.documents?.shift(this.cursorOptions); | ||
const document = this.documents?.shift(this.deserializationOptions); | ||
if (document != null) { | ||
@@ -412,3 +423,3 @@ bufferedDocs.push(document); | ||
do { | ||
const doc = this.documents?.shift(this.cursorOptions); | ||
const doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -432,3 +443,3 @@ if (this.transform != null) return await this.transformDocument(doc); | ||
let doc = this.documents?.shift(this.cursorOptions); | ||
let doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -441,3 +452,3 @@ if (this.transform != null) return await this.transformDocument(doc); | ||
doc = this.documents?.shift(this.cursorOptions); | ||
doc = this.documents?.shift(this.deserializationOptions); | ||
if (doc != null) { | ||
@@ -444,0 +455,0 @@ if (this.transform != null) return await this.transformDocument(doc); |
@@ -79,3 +79,3 @@ import type { Document } from '../bson'; | ||
) | ||
).shift(this.aggregateOptions); | ||
).shift(this.deserializationOptions); | ||
} | ||
@@ -82,0 +82,0 @@ |
@@ -146,3 +146,3 @@ import { type Document } from '../bson'; | ||
) | ||
).shift(this.findOptions); | ||
).shift(this.deserializationOptions); | ||
} | ||
@@ -149,0 +149,0 @@ |
@@ -305,4 +305,8 @@ import { Admin } from './admin'; | ||
export type { CompressorName } from './cmap/wire_protocol/compression'; | ||
export type { JSTypeOf, OnDemandDocument } from './cmap/wire_protocol/on_demand/document'; | ||
export type { | ||
JSTypeOf, | ||
OnDemandDocument, | ||
OnDemandDocumentDeserializeOptions | ||
} from './cmap/wire_protocol/on_demand/document'; | ||
export type { | ||
CursorResponse, | ||
@@ -309,0 +313,0 @@ MongoDBResponse, |
@@ -96,4 +96,6 @@ import { promises as fs } from 'fs'; | ||
export type SupportedTLSConnectionOptions = Pick< | ||
TLSConnectionOptions, | ||
Extract<keyof TLSConnectionOptions, (typeof LEGAL_TLS_SOCKET_OPTIONS)[number]> | ||
TLSConnectionOptions & { | ||
allowPartialTrustChain?: boolean; | ||
}, | ||
(typeof LEGAL_TLS_SOCKET_OPTIONS)[number] | ||
>; | ||
@@ -100,0 +102,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
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 too big to display
3410271
71151