|
| 1 | +import { type DeserializeOptions } from 'bson'; |
| 2 | + |
1 | 3 | import { |
2 | 4 | type BSONElement, |
3 | 5 | type BSONSerializeOptions, |
4 | 6 | BSONType, |
5 | 7 | type Document, |
6 | 8 | Long, |
7 | 9 | parseToElementsToArray, |
| 10 | + parseUtf8ValidationOption, |
8 | 11 | pluckBSONSerializeOptions, |
9 | 12 | type Timestamp |
10 | 13 | } from '../../bson'; |
11 | 14 | import { MongoUnexpectedServerResponseError } from '../../error'; |
12 | 15 | import { type ClusterTime } from '../../sdam/common'; |
13 | 16 | import { decorateDecryptionResult, ns } from '../../utils'; |
14 | | -import { type JSTypeOf, OnDemandDocument } from './on_demand/document'; |
| 17 | +import { |
| 18 | + type JSTypeOf, |
| 19 | + OnDemandDocument, |
| 20 | + type OnDemandDocumentDeserializeOptions |
| 21 | +} from './on_demand/document'; |
15 | 22 |
|
16 | 23 | // eslint-disable-next-line no-restricted-syntax |
17 | 24 | const enum BSONElementOffset { |
@@ -113,7 +120,8 @@ export class MongoDBResponse extends OnDemandDocument { |
113 | 120 | this.get('recoveryToken', BSONType.object)?.toObject({ |
114 | 121 | promoteValues: false, |
115 | 122 | promoteLongs: false, |
116 | | - promoteBuffers: false |
| 123 | + promoteBuffers: false, |
| 124 | + validation: { utf8: true } |
117 | 125 | }) ?? null |
118 | 126 | ); |
119 | 127 | } |
@@ -170,20 +178,10 @@ export class MongoDBResponse extends OnDemandDocument { |
170 | 178 | public override toObject(options?: BSONSerializeOptions): Record<string, any> { |
171 | 179 | const exactBSONOptions = { |
172 | 180 | ...pluckBSONSerializeOptions(options ?? {}), |
173 | | - validation: this.parseBsonSerializationOptions(options) |
| 181 | + validation: parseUtf8ValidationOption(options) |
174 | 182 | }; |
175 | 183 | return super.toObject(exactBSONOptions); |
176 | 184 | } |
177 | | - |
178 | | - private parseBsonSerializationOptions(options?: { enableUtf8Validation?: boolean }): { |
179 | | - utf8: { writeErrors: false } | false; |
180 | | - } { |
181 | | - const enableUtf8Validation = options?.enableUtf8Validation; |
182 | | - if (enableUtf8Validation === false) { |
183 | | - return { utf8: false }; |
184 | | - } |
185 | | - return { utf8: { writeErrors: false } }; |
186 | | - } |
187 | 185 | } |
188 | 186 |
|
189 | 187 | /** @internal */ |
@@ -267,12 +265,13 @@ export class CursorResponse extends MongoDBResponse { |
267 | 265 | this.cursor.get('postBatchResumeToken', BSONType.object)?.toObject({ |
268 | 266 | promoteValues: false, |
269 | 267 | promoteLongs: false, |
270 | | - promoteBuffers: false |
| 268 | + promoteBuffers: false, |
| 269 | + validation: { utf8: true } |
271 | 270 | }) ?? null |
272 | 271 | ); |
273 | 272 | } |
274 | 273 |
|
275 | | - public shift(options?: BSONSerializeOptions): any { |
| 274 | + public shift(options: OnDemandDocumentDeserializeOptions): any { |
276 | 275 | if (this.iterated >= this.batchSize) { |
277 | 276 | return null; |
278 | 277 | } |
@@ -324,7 +323,7 @@ export class ExplainedCursorResponse extends CursorResponse { |
324 | 323 | return this._length; |
325 | 324 | } |
326 | 325 |
|
327 | | - override shift(options?: BSONSerializeOptions | undefined) { |
| 326 | + override shift(options?: DeserializeOptions) { |
328 | 327 | if (this._length === 0) return null; |
329 | 328 | this._length -= 1; |
330 | 329 | return this.toObject(options); |
|
0 commit comments