mongodb 6.8.0-dev.20240905.sha.65e0e15c → 6.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +1 -14
  2. package/lib/bson.js +13 -4
  3. package/lib/bson.js.map +1 -1
  4. package/lib/bulk/common.js +21 -16
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/ordered.js.map +1 -1
  7. package/lib/bulk/unordered.js.map +1 -1
  8. package/lib/change_stream.js +8 -10
  9. package/lib/change_stream.js.map +1 -1
  10. package/lib/client-side-encryption/auto_encrypter.js +3 -14
  11. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  12. package/lib/client-side-encryption/client_encryption.js +7 -25
  13. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  14. package/lib/client-side-encryption/crypto_callbacks.js +6 -6
  15. package/lib/client-side-encryption/crypto_callbacks.js.map +1 -1
  16. package/lib/client-side-encryption/mongocryptd_manager.js +5 -9
  17. package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -1
  18. package/lib/client-side-encryption/providers/aws.js +2 -1
  19. package/lib/client-side-encryption/providers/aws.js.map +1 -1
  20. package/lib/client-side-encryption/providers/azure.js +5 -5
  21. package/lib/client-side-encryption/providers/azure.js.map +1 -1
  22. package/lib/client-side-encryption/providers/gcp.js +2 -1
  23. package/lib/client-side-encryption/providers/gcp.js.map +1 -1
  24. package/lib/client-side-encryption/providers/index.js +3 -2
  25. package/lib/client-side-encryption/providers/index.js.map +1 -1
  26. package/lib/client-side-encryption/state_machine.js +4 -9
  27. package/lib/client-side-encryption/state_machine.js.map +1 -1
  28. package/lib/cmap/auth/auth_provider.js.map +1 -1
  29. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
  30. package/lib/cmap/auth/gssapi.js +4 -4
  31. package/lib/cmap/auth/gssapi.js.map +1 -1
  32. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  33. package/lib/cmap/auth/mongocr.js.map +1 -1
  34. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  35. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -1
  36. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
  37. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +2 -0
  38. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
  39. package/lib/cmap/auth/mongodb_oidc/command_builders.js +3 -2
  40. package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
  41. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
  42. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
  43. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +2 -0
  44. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
  45. package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -1
  46. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
  47. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  48. package/lib/cmap/auth/plain.js.map +1 -1
  49. package/lib/cmap/auth/scram.js.map +1 -1
  50. package/lib/cmap/auth/x509.js.map +1 -1
  51. package/lib/cmap/command_monitoring_events.js.map +1 -1
  52. package/lib/cmap/commands.js +5 -62
  53. package/lib/cmap/commands.js.map +1 -1
  54. package/lib/cmap/connect.js +7 -9
  55. package/lib/cmap/connect.js.map +1 -1
  56. package/lib/cmap/connection.js +5 -3
  57. package/lib/cmap/connection.js.map +1 -1
  58. package/lib/cmap/connection_pool.js +9 -11
  59. package/lib/cmap/connection_pool.js.map +1 -1
  60. package/lib/cmap/connection_pool_events.js +3 -7
  61. package/lib/cmap/connection_pool_events.js.map +1 -1
  62. package/lib/cmap/handshake/client_metadata.js +5 -5
  63. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  64. package/lib/cmap/metrics.js +1 -1
  65. package/lib/cmap/metrics.js.map +1 -1
  66. package/lib/cmap/stream_description.js.map +1 -1
  67. package/lib/cmap/wire_protocol/compression.js +5 -5
  68. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  69. package/lib/cmap/wire_protocol/constants.js +2 -2
  70. package/lib/cmap/wire_protocol/on_data.js +2 -1
  71. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  72. package/lib/cmap/wire_protocol/on_demand/document.js +3 -12
  73. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  74. package/lib/cmap/wire_protocol/responses.js +15 -6
  75. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  76. package/lib/cmap/wire_protocol/shared.js +3 -2
  77. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  78. package/lib/collection.js.map +1 -1
  79. package/lib/connection_string.js +5 -10
  80. package/lib/connection_string.js.map +1 -1
  81. package/lib/constants.js +0 -1
  82. package/lib/constants.js.map +1 -1
  83. package/lib/cursor/abstract_cursor.js +16 -25
  84. package/lib/cursor/abstract_cursor.js.map +1 -1
  85. package/lib/cursor/aggregation_cursor.js +2 -2
  86. package/lib/cursor/aggregation_cursor.js.map +1 -1
  87. package/lib/cursor/change_stream_cursor.js.map +1 -1
  88. package/lib/cursor/find_cursor.js +4 -4
  89. package/lib/cursor/find_cursor.js.map +1 -1
  90. package/lib/db.js +1 -1
  91. package/lib/db.js.map +1 -1
  92. package/lib/deps.js +8 -16
  93. package/lib/deps.js.map +1 -1
  94. package/lib/encrypter.js.map +1 -1
  95. package/lib/error.js +14 -19
  96. package/lib/error.js.map +1 -1
  97. package/lib/explain.js.map +1 -1
  98. package/lib/gridfs/download.js +4 -1
  99. package/lib/gridfs/download.js.map +1 -1
  100. package/lib/gridfs/index.js +1 -1
  101. package/lib/gridfs/index.js.map +1 -1
  102. package/lib/gridfs/upload.js +4 -0
  103. package/lib/gridfs/upload.js.map +1 -1
  104. package/lib/index.js +2 -4
  105. package/lib/index.js.map +1 -1
  106. package/lib/mongo_client.js +1 -15
  107. package/lib/mongo_client.js.map +1 -1
  108. package/lib/mongo_client_auth_providers.js.map +1 -1
  109. package/lib/mongo_logger.js +8 -8
  110. package/lib/mongo_logger.js.map +1 -1
  111. package/lib/mongo_types.js +0 -1
  112. package/lib/mongo_types.js.map +1 -1
  113. package/lib/operations/aggregate.js +0 -1
  114. package/lib/operations/aggregate.js.map +1 -1
  115. package/lib/operations/bulk_write.js.map +1 -1
  116. package/lib/operations/collections.js.map +1 -1
  117. package/lib/operations/command.js +1 -1
  118. package/lib/operations/command.js.map +1 -1
  119. package/lib/operations/count.js.map +1 -1
  120. package/lib/operations/create_collection.js.map +1 -1
  121. package/lib/operations/delete.js +2 -2
  122. package/lib/operations/delete.js.map +1 -1
  123. package/lib/operations/distinct.js.map +1 -1
  124. package/lib/operations/drop.js.map +1 -1
  125. package/lib/operations/estimated_document_count.js.map +1 -1
  126. package/lib/operations/execute_operation.js +109 -111
  127. package/lib/operations/execute_operation.js.map +1 -1
  128. package/lib/operations/find.js.map +1 -1
  129. package/lib/operations/find_and_modify.js +8 -2
  130. package/lib/operations/find_and_modify.js.map +1 -1
  131. package/lib/operations/get_more.js.map +1 -1
  132. package/lib/operations/indexes.js.map +1 -1
  133. package/lib/operations/insert.js.map +1 -1
  134. package/lib/operations/is_capped.js.map +1 -1
  135. package/lib/operations/kill_cursors.js.map +1 -1
  136. package/lib/operations/list_collections.js.map +1 -1
  137. package/lib/operations/list_databases.js.map +1 -1
  138. package/lib/operations/operation.js +5 -5
  139. package/lib/operations/operation.js.map +1 -1
  140. package/lib/operations/options_operation.js.map +1 -1
  141. package/lib/operations/profiling_level.js.map +1 -1
  142. package/lib/operations/search_indexes/drop.js.map +1 -1
  143. package/lib/operations/set_profiling_level.js.map +1 -1
  144. package/lib/operations/stats.js.map +1 -1
  145. package/lib/operations/update.js +2 -2
  146. package/lib/operations/update.js.map +1 -1
  147. package/lib/operations/validate_collection.js.map +1 -1
  148. package/lib/read_concern.js.map +1 -1
  149. package/lib/read_preference.js +1 -1
  150. package/lib/read_preference.js.map +1 -1
  151. package/lib/sdam/common.js +3 -3
  152. package/lib/sdam/common.js.map +1 -1
  153. package/lib/sdam/monitor.js +5 -1
  154. package/lib/sdam/monitor.js.map +1 -1
  155. package/lib/sdam/server.js +2 -2
  156. package/lib/sdam/server.js.map +1 -1
  157. package/lib/sdam/server_description.js +3 -3
  158. package/lib/sdam/server_description.js.map +1 -1
  159. package/lib/sdam/server_selection.js +5 -5
  160. package/lib/sdam/server_selection.js.map +1 -1
  161. package/lib/sdam/srv_polling.js +3 -2
  162. package/lib/sdam/srv_polling.js.map +1 -1
  163. package/lib/sdam/topology.js +1 -1
  164. package/lib/sdam/topology.js.map +1 -1
  165. package/lib/sdam/topology_description.js.map +1 -1
  166. package/lib/sessions.js +218 -221
  167. package/lib/sessions.js.map +1 -1
  168. package/lib/sort.js +3 -2
  169. package/lib/sort.js.map +1 -1
  170. package/lib/timeout.js +1 -0
  171. package/lib/timeout.js.map +1 -1
  172. package/lib/transactions.js +2 -2
  173. package/lib/transactions.js.map +1 -1
  174. package/lib/utils.js +51 -49
  175. package/lib/utils.js.map +1 -1
  176. package/lib/write_concern.js +2 -2
  177. package/lib/write_concern.js.map +1 -1
  178. package/mongodb.d.ts +143 -146
  179. package/package.json +28 -27
  180. package/src/bson.ts +13 -1
  181. package/src/bulk/common.ts +18 -18
  182. package/src/change_stream.ts +15 -33
  183. package/src/client-side-encryption/auto_encrypter.ts +82 -18
  184. package/src/client-side-encryption/client_encryption.ts +54 -51
  185. package/src/client-side-encryption/mongocryptd_manager.ts +6 -10
  186. package/src/client-side-encryption/state_machine.ts +6 -28
  187. package/src/cmap/auth/gssapi.ts +1 -1
  188. package/src/cmap/auth/mongodb_aws.ts +2 -2
  189. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +2 -2
  190. package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +2 -2
  191. package/src/cmap/commands.ts +5 -70
  192. package/src/cmap/connect.ts +1 -3
  193. package/src/cmap/connection.ts +4 -3
  194. package/src/cmap/connection_pool.ts +9 -17
  195. package/src/cmap/connection_pool_events.ts +2 -34
  196. package/src/cmap/handshake/client_metadata.ts +1 -1
  197. package/src/cmap/wire_protocol/constants.ts +2 -2
  198. package/src/cmap/wire_protocol/on_demand/document.ts +14 -18
  199. package/src/cmap/wire_protocol/responses.ts +23 -5
  200. package/src/cmap/wire_protocol/shared.ts +2 -1
  201. package/src/collection.ts +15 -16
  202. package/src/connection_string.ts +2 -8
  203. package/src/constants.ts +0 -1
  204. package/src/cursor/abstract_cursor.ts +28 -42
  205. package/src/cursor/aggregation_cursor.ts +5 -7
  206. package/src/cursor/find_cursor.ts +1 -1
  207. package/src/deps.ts +1 -8
  208. package/src/error.ts +14 -33
  209. package/src/gridfs/download.ts +4 -28
  210. package/src/gridfs/upload.ts +6 -1
  211. package/src/index.ts +6 -6
  212. package/src/mongo_client.ts +3 -25
  213. package/src/mongo_logger.ts +3 -5
  214. package/src/mongo_types.ts +68 -69
  215. package/src/operations/aggregate.ts +1 -2
  216. package/src/operations/bulk_write.ts +2 -2
  217. package/src/operations/command.ts +1 -1
  218. package/src/operations/execute_operation.ts +131 -137
  219. package/src/operations/find_and_modify.ts +7 -2
  220. package/src/operations/insert.ts +4 -3
  221. package/src/operations/operation.ts +10 -7
  222. package/src/operations/search_indexes/drop.ts +1 -4
  223. package/src/sdam/monitor.ts +5 -3
  224. package/src/sdam/server.ts +1 -1
  225. package/src/sdam/server_description.ts +6 -5
  226. package/src/sdam/srv_polling.ts +2 -1
  227. package/src/sessions.ts +277 -291
  228. package/src/sort.ts +1 -1
  229. package/src/timeout.ts +1 -0
  230. package/src/transactions.ts +2 -1
  231. package/src/utils.ts +4 -9
  232. package/src/write_concern.ts +2 -2
  233. package/tsconfig.json +1 -2
  234. package/lib/beta.d.ts +0 -7900
  235. package/lib/beta.js +0 -21
  236. package/lib/beta.js.map +0 -1
  237. package/lib/operations/client_bulk_write/command_builder.js +0 -198
  238. package/lib/operations/client_bulk_write/command_builder.js.map +0 -1
  239. package/lib/operations/client_bulk_write/common.js +0 -3
  240. package/lib/operations/client_bulk_write/common.js.map +0 -1
  241. package/lib/resource_management.js +0 -58
  242. package/lib/resource_management.js.map +0 -1
  243. package/src/beta.ts +0 -22
  244. package/src/operations/client_bulk_write/command_builder.ts +0 -283
  245. package/src/operations/client_bulk_write/common.ts +0 -146
  246. package/src/resource_management.ts +0 -74
@@ -160,9 +160,9 @@ export abstract class CallbackWorkflow implements Workflow {
160
160
  // previous lock, only the current callback's value would get returned.
161
161
  await lock;
162
162
  lock = lock
163
-
163
+ // eslint-disable-next-line github/no-then
164
164
  .catch(() => null)
165
-
165
+ // eslint-disable-next-line github/no-then
166
166
  .then(async () => {
167
167
  const difference = Date.now() - this.lastExecutionTime;
168
168
  if (difference <= THROTTLE_MS) {
@@ -115,9 +115,9 @@ export abstract class MachineWorkflow implements Workflow {
115
115
  // previous lock, only the current callback's value would get returned.
116
116
  await lock;
117
117
  lock = lock
118
-
118
+ // eslint-disable-next-line github/no-then
119
119
  .catch(() => null)
120
-
120
+ // eslint-disable-next-line github/no-then
121
121
  .then(async () => {
122
122
  const difference = Date.now() - this.lastExecutionTime;
123
123
  if (difference <= THROTTLE_MS) {
@@ -30,8 +30,6 @@ const QUERY_FAILURE = 2;
30
30
  const SHARD_CONFIG_STALE = 4;
31
31
  const AWAIT_CAPABLE = 8;
32
32
 
33
- const encodeUTF8Into = BSON.BSON.onDemand.ByteUtils.encodeUTF8Into;
34
-
35
33
  /** @internal */
36
34
  export type WriteProtocolMessageType = OpQueryRequest | OpMsgRequest;
37
35
 
@@ -75,11 +73,7 @@ export class OpQueryRequest {
75
73
  exhaust: boolean;
76
74
  partial: boolean;
77
75
 
78
- constructor(
79
- public databaseName: string,
80
- public query: Document,
81
- options: OpQueryOptions
82
- ) {
76
+ constructor(public databaseName: string, public query: Document, options: OpQueryOptions) {
83
77
  // Basic options needed to be passed in
84
78
  // TODO(NODE-3483): Replace with MongoCommandError
85
79
  const ns = `${databaseName}.$cmd`;
@@ -417,15 +411,6 @@ export interface OpMsgOptions {
417
411
  readPreference: ReadPreference;
418
412
  }
419
413
 
420
- /** @internal */
421
- export class DocumentSequence {
422
- documents: Document[];
423
-
424
- constructor(documents: Document[]) {
425
- this.documents = documents;
426
- }
427
- }
428
-
429
414
  /** @internal */
430
415
  export class OpMsgRequest {
431
416
  requestId: number;
@@ -495,7 +480,7 @@ export class OpMsgRequest {
495
480
 
496
481
  let totalLength = header.length;
497
482
  const command = this.command;
498
- totalLength += this.makeSections(buffers, command);
483
+ totalLength += this.makeDocumentSegment(buffers, command);
499
484
 
500
485
  header.writeInt32LE(totalLength, 0); // messageLength
501
486
  header.writeInt32LE(this.requestId, 4); // requestID
@@ -505,65 +490,15 @@ export class OpMsgRequest {
505
490
  return buffers;
506
491
  }
507
492
 
508
- /**
509
- * Add the sections to the OP_MSG request's buffers and returns the length.
510
- */
511
- makeSections(buffers: Uint8Array[], document: Document): number {
512
- const sequencesBuffer = this.extractDocumentSequences(document);
513
- const payloadTypeBuffer = Buffer.allocUnsafe(1);
493
+ makeDocumentSegment(buffers: Uint8Array[], document: Document): number {
494
+ const payloadTypeBuffer = Buffer.alloc(1);
514
495
  payloadTypeBuffer[0] = 0;
515
496
 
516
497
  const documentBuffer = this.serializeBson(document);
517
- // First section, type 0
518
498
  buffers.push(payloadTypeBuffer);
519
499
  buffers.push(documentBuffer);
520
- // Subsequent sections, type 1
521
- buffers.push(sequencesBuffer);
522
-
523
- return payloadTypeBuffer.length + documentBuffer.length + sequencesBuffer.length;
524
- }
525
500
 
526
- /**
527
- * Extracts the document sequences from the command document and returns
528
- * a buffer to be added as multiple sections after the initial type 0
529
- * section in the message.
530
- */
531
- extractDocumentSequences(document: Document): Uint8Array {
532
- // Pull out any field in the command document that's value is a document sequence.
533
- const chunks = [];
534
- for (const [key, value] of Object.entries(document)) {
535
- if (value instanceof DocumentSequence) {
536
- // Document sequences starts with type 1 at the first byte.
537
- const buffer = Buffer.allocUnsafe(1 + 4 + key.length);
538
- buffer[0] = 1;
539
- // Third part is the field name at offset 5.
540
- encodeUTF8Into(buffer, key, 5);
541
- chunks.push(buffer);
542
- // Fourth part are the documents' bytes.
543
- let docsLength = 0;
544
- for (const doc of value.documents) {
545
- const docBson = this.serializeBson(doc);
546
- docsLength += docBson.length;
547
- chunks.push(docBson);
548
- }
549
- // Second part of the sequence is the length at offset 1;
550
- buffer.writeInt32LE(key.length + docsLength, 1);
551
- // Why are we removing the field from the command? This is because it needs to be
552
- // removed in the OP_MSG request first section, and DocumentSequence is not a
553
- // BSON type and is specific to the MongoDB wire protocol so there's nothing
554
- // our BSON serializer can do about this. Since DocumentSequence is not exposed
555
- // in the public API and only used internally, we are never mutating an original
556
- // command provided by the user, just our own, and it's cheaper to delete from
557
- // our own command than copying it.
558
- delete document[key];
559
- }
560
- }
561
- if (chunks.length > 0) {
562
- return Buffer.concat(chunks);
563
- }
564
- // If we have no document sequences we return an empty buffer for nothing to add
565
- // to the payload.
566
- return Buffer.alloc(0);
501
+ return payloadTypeBuffer.length + documentBuffer.length;
567
502
  }
568
503
 
569
504
  serializeBson(document: Document): Uint8Array {
@@ -164,7 +164,7 @@ export async function performInitialHandshake(
164
164
  } catch (error) {
165
165
  if (error instanceof MongoError) {
166
166
  error.addErrorLabel(MongoErrorLabel.HandshakeError);
167
- if (needsRetryableWriteLabel(error, response.maxWireVersion, conn.description.type)) {
167
+ if (needsRetryableWriteLabel(error, response.maxWireVersion)) {
168
168
  error.addErrorLabel(MongoErrorLabel.RetryableWriteError);
169
169
  }
170
170
  }
@@ -269,8 +269,6 @@ export const LEGAL_TLS_SOCKET_OPTIONS = [
269
269
 
270
270
  /** @public */
271
271
  export const LEGAL_TCP_SOCKET_OPTIONS = [
272
- 'autoSelectFamily',
273
- 'autoSelectFamilyAttemptTimeout',
274
272
  'family',
275
273
  'hints',
276
274
  'localAddress',
@@ -1,3 +1,4 @@
1
+ import { type DeserializeOptions } from 'bson';
1
2
  import { type Readable, Transform, type TransformCallback } from 'stream';
2
3
  import { clearTimeout, setTimeout } from 'timers';
3
4
 
@@ -332,7 +333,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
332
333
 
333
334
  this.socket.destroy();
334
335
  this.error = error;
335
-
336
+ // eslint-disable-next-line github/no-then
336
337
  this.dataEvents?.throw(error).then(undefined, squashError);
337
338
  this.closed = true;
338
339
  this.emit(Connection.CLOSE);
@@ -487,7 +488,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
487
488
 
488
489
  // If `documentsReturnedIn` not set or raw is not enabled, use input bson options
489
490
  // Otherwise, support raw flag. Raw only works for cursors that hardcode firstBatch/nextBatch fields
490
- const bsonOptions =
491
+ const bsonOptions: DeserializeOptions =
491
492
  options.documentsReturnedIn == null || !options.raw
492
493
  ? options
493
494
  : {
@@ -602,7 +603,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
602
603
  }
603
604
  throw new MongoUnexpectedServerResponseError('Server ended moreToCome unexpectedly');
604
605
  };
605
-
606
+ // eslint-disable-next-line github/no-then
606
607
  exhaustLoop().then(undefined, replyListener);
607
608
  }
608
609
 
@@ -27,7 +27,7 @@ import {
27
27
  import { CancellationToken, TypedEventEmitter } from '../mongo_types';
28
28
  import type { Server } from '../sdam/server';
29
29
  import { Timeout, TimeoutError } from '../timeout';
30
- import { type Callback, List, makeCounter, now, promiseWithResolvers } from '../utils';
30
+ import { type Callback, List, makeCounter, promiseWithResolvers } from '../utils';
31
31
  import { connect } from './connect';
32
32
  import { Connection, type ConnectionEvents, type ConnectionOptions } from './connection';
33
33
  import {
@@ -104,7 +104,6 @@ export interface WaitQueueMember {
104
104
  reject: (err: AnyError) => void;
105
105
  timeout: Timeout;
106
106
  [kCancelled]?: boolean;
107
- checkoutTime: number;
108
107
  }
109
108
 
110
109
  /** @internal */
@@ -356,7 +355,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
356
355
  * explicitly destroyed by the new owner.
357
356
  */
358
357
  async checkOut(): Promise<Connection> {
359
- const checkoutTime = now();
360
358
  this.emitAndLog(
361
359
  ConnectionPool.CONNECTION_CHECK_OUT_STARTED,
362
360
  new ConnectionCheckOutStartedEvent(this)
@@ -371,8 +369,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
371
369
  const waitQueueMember: WaitQueueMember = {
372
370
  resolve,
373
371
  reject,
374
- timeout,
375
- checkoutTime
372
+ timeout
376
373
  };
377
374
 
378
375
  this[kWaitQueue].push(waitQueueMember);
@@ -388,7 +385,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
388
385
 
389
386
  this.emitAndLog(
390
387
  ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
391
- new ConnectionCheckOutFailedEvent(this, 'timeout', waitQueueMember.checkoutTime)
388
+ new ConnectionCheckOutFailedEvent(this, 'timeout')
392
389
  );
393
390
  const timeoutError = new WaitQueueTimeoutError(
394
391
  this.loadBalanced
@@ -632,12 +629,12 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
632
629
 
633
630
  this[kPending]++;
634
631
  // This is our version of a "virtual" no-I/O connection as the spec requires
635
- const connectionCreatedTime = now();
636
632
  this.emitAndLog(
637
633
  ConnectionPool.CONNECTION_CREATED,
638
634
  new ConnectionCreatedEvent(this, { id: connectOptions.id })
639
635
  );
640
636
 
637
+ // eslint-disable-next-line github/no-then
641
638
  connect(connectOptions).then(
642
639
  connection => {
643
640
  // The pool might have closed since we started trying to create a connection
@@ -673,7 +670,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
673
670
  connection.markAvailable();
674
671
  this.emitAndLog(
675
672
  ConnectionPool.CONNECTION_READY,
676
- new ConnectionReadyEvent(this, connection, connectionCreatedTime)
673
+ new ConnectionReadyEvent(this, connection)
677
674
  );
678
675
 
679
676
  this[kPending]--;
@@ -762,7 +759,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
762
759
  const error = this.closed ? new PoolClosedError(this) : new PoolClearedError(this);
763
760
  this.emitAndLog(
764
761
  ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
765
- new ConnectionCheckOutFailedEvent(this, reason, waitQueueMember.checkoutTime, error)
762
+ new ConnectionCheckOutFailedEvent(this, reason, error)
766
763
  );
767
764
  waitQueueMember.timeout.clear();
768
765
  this[kWaitQueue].shift();
@@ -783,7 +780,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
783
780
  this[kCheckedOut].add(connection);
784
781
  this.emitAndLog(
785
782
  ConnectionPool.CONNECTION_CHECKED_OUT,
786
- new ConnectionCheckedOutEvent(this, connection, waitQueueMember.checkoutTime)
783
+ new ConnectionCheckedOutEvent(this, connection)
787
784
  );
788
785
  waitQueueMember.timeout.clear();
789
786
 
@@ -812,19 +809,14 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
812
809
  this.emitAndLog(
813
810
  ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
814
811
  // TODO(NODE-5192): Remove this cast
815
- new ConnectionCheckOutFailedEvent(
816
- this,
817
- 'connectionError',
818
- waitQueueMember.checkoutTime,
819
- err as MongoError
820
- )
812
+ new ConnectionCheckOutFailedEvent(this, 'connectionError', err as MongoError)
821
813
  );
822
814
  waitQueueMember.reject(err);
823
815
  } else if (connection) {
824
816
  this[kCheckedOut].add(connection);
825
817
  this.emitAndLog(
826
818
  ConnectionPool.CONNECTION_CHECKED_OUT,
827
- new ConnectionCheckedOutEvent(this, connection, waitQueueMember.checkoutTime)
819
+ new ConnectionCheckedOutEvent(this, connection)
828
820
  );
829
821
  waitQueueMember.resolve(connection);
830
822
  }
@@ -13,7 +13,6 @@ import {
13
13
  CONNECTION_READY
14
14
  } from '../constants';
15
15
  import type { MongoError } from '../error';
16
- import { now } from '../utils';
17
16
  import type { Connection } from './connection';
18
17
  import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
19
18
 
@@ -127,25 +126,12 @@ export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
127
126
  export class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
128
127
  /** The id of the connection */
129
128
  connectionId: number | '<monitor>';
130
- /**
131
- * The time it took to establish the connection.
132
- * In accordance with the definition of establishment of a connection
133
- * specified by `ConnectionPoolOptions.maxConnecting`,
134
- * it is the time elapsed between emitting a `ConnectionCreatedEvent`
135
- * and emitting this event as part of the same checking out.
136
- *
137
- * Naturally, when establishing a connection is part of checking out,
138
- * this duration is not greater than
139
- * `ConnectionCheckedOutEvent.duration`.
140
- */
141
- durationMS: number;
142
129
  /** @internal */
143
130
  name = CONNECTION_READY;
144
131
 
145
132
  /** @internal */
146
- constructor(pool: ConnectionPool, connection: Connection, connectionCreatedEventTime: number) {
133
+ constructor(pool: ConnectionPool, connection: Connection) {
147
134
  super(pool);
148
- this.durationMS = now() - connectionCreatedEventTime;
149
135
  this.connectionId = connection.id;
150
136
  }
151
137
  }
@@ -208,23 +194,14 @@ export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent
208
194
  error?: MongoError;
209
195
  /** @internal */
210
196
  name = CONNECTION_CHECK_OUT_FAILED;
211
- /**
212
- * The time it took to check out the connection.
213
- * More specifically, the time elapsed between
214
- * emitting a `ConnectionCheckOutStartedEvent`
215
- * and emitting this event as part of the same check out.
216
- */
217
- durationMS: number;
218
197
 
219
198
  /** @internal */
220
199
  constructor(
221
200
  pool: ConnectionPool,
222
201
  reason: 'poolClosed' | 'timeout' | 'connectionError',
223
- checkoutTime: number,
224
202
  error?: MongoError
225
203
  ) {
226
204
  super(pool);
227
- this.durationMS = now() - checkoutTime;
228
205
  this.reason = reason;
229
206
  this.error = error;
230
207
  }
@@ -240,19 +217,10 @@ export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
240
217
  connectionId: number | '<monitor>';
241
218
  /** @internal */
242
219
  name = CONNECTION_CHECKED_OUT;
243
- /**
244
- * The time it took to check out the connection.
245
- * More specifically, the time elapsed between
246
- * emitting a `ConnectionCheckOutStartedEvent`
247
- * and emitting this event as part of the same checking out.
248
- *
249
- */
250
- durationMS: number;
251
220
 
252
221
  /** @internal */
253
- constructor(pool: ConnectionPool, connection: Connection, checkoutTime: number) {
222
+ constructor(pool: ConnectionPool, connection: Connection) {
254
223
  super(pool);
255
- this.durationMS = now() - checkoutTime;
256
224
  this.connectionId = connection.id;
257
225
  }
258
226
  }
@@ -6,7 +6,7 @@ import { MongoInvalidArgumentError } from '../../error';
6
6
  import type { MongoOptions } from '../../mongo_client';
7
7
  import { fileIsAccessible } from '../../utils';
8
8
 
9
- // eslint-disable-next-line @typescript-eslint/no-require-imports
9
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
10
10
  const NODE_DRIVER_VERSION = require('../../../package.json').version;
11
11
 
12
12
  /**
@@ -1,7 +1,7 @@
1
1
  export const MIN_SUPPORTED_SERVER_VERSION = '3.6';
2
- export const MAX_SUPPORTED_SERVER_VERSION = '8.0';
2
+ export const MAX_SUPPORTED_SERVER_VERSION = '7.0';
3
3
  export const MIN_SUPPORTED_WIRE_VERSION = 6;
4
- export const MAX_SUPPORTED_WIRE_VERSION = 25;
4
+ export const MAX_SUPPORTED_WIRE_VERSION = 21;
5
5
  export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
6
6
  export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
7
7
  export const OP_REPLY = 1;
@@ -1,8 +1,9 @@
1
+ import { type DeserializeOptions } from 'bson';
2
+
1
3
  import {
2
4
  Binary,
3
5
  type BSONElement,
4
6
  BSONError,
5
- type BSONSerializeOptions,
6
7
  BSONType,
7
8
  deserialize,
8
9
  getBigInt64LE,
@@ -10,7 +11,6 @@ import {
10
11
  getInt32LE,
11
12
  ObjectId,
12
13
  parseToElementsToArray,
13
- pluckBSONSerializeOptions,
14
14
  Timestamp,
15
15
  toUTF8
16
16
  } from '../../../bson';
@@ -44,6 +44,14 @@ export type JSTypeOf = {
44
44
  /** @internal */
45
45
  type CachedBSONElement = { element: BSONElement; value: any | undefined };
46
46
 
47
+ /**
48
+ * @internal
49
+ *
50
+ * Options for `OnDemandDocument.toObject()`. Validation is required to ensure
51
+ * that callers provide utf8 validation options. */
52
+ export type OnDemandDocumentDeserializeOptions = Omit<DeserializeOptions, 'validation'> &
53
+ Required<Pick<DeserializeOptions, 'validation'>>;
54
+
47
55
  /** @internal */
48
56
  export class OnDemandDocument {
49
57
  /**
@@ -330,24 +338,12 @@ export class OnDemandDocument {
330
338
  * Deserialize this object, DOES NOT cache result so avoid multiple invocations
331
339
  * @param options - BSON deserialization options
332
340
  */
333
- public toObject(options?: BSONSerializeOptions): Record<string, any> {
334
- const exactBSONOptions = {
335
- ...pluckBSONSerializeOptions(options ?? {}),
336
- validation: this.parseBsonSerializationOptions(options),
341
+ public toObject(options?: OnDemandDocumentDeserializeOptions): Record<string, any> {
342
+ return deserialize(this.bson, {
343
+ ...options,
337
344
  index: this.offset,
338
345
  allowObjectSmallerThanBufferSize: true
339
- };
340
- return deserialize(this.bson, exactBSONOptions);
341
- }
342
-
343
- private parseBsonSerializationOptions(options?: { enableUtf8Validation?: boolean }): {
344
- utf8: { writeErrors: false } | false;
345
- } {
346
- const enableUtf8Validation = options?.enableUtf8Validation;
347
- if (enableUtf8Validation === false) {
348
- return { utf8: false };
349
- }
350
- return { utf8: { writeErrors: false } };
346
+ });
351
347
  }
352
348
 
353
349
  /** Returns this document's bytes only */
@@ -1,3 +1,5 @@
1
+ import { type DeserializeOptions } from 'bson';
2
+
1
3
  import {
2
4
  type BSONElement,
3
5
  type BSONSerializeOptions,
@@ -5,12 +7,18 @@ import {
5
7
  type Document,
6
8
  Long,
7
9
  parseToElementsToArray,
10
+ parseUtf8ValidationOption,
11
+ pluckBSONSerializeOptions,
8
12
  type Timestamp
9
13
  } from '../../bson';
10
14
  import { MongoUnexpectedServerResponseError } from '../../error';
11
15
  import { type ClusterTime } from '../../sdam/common';
12
16
  import { decorateDecryptionResult, ns } from '../../utils';
13
- import { type JSTypeOf, OnDemandDocument } from './on_demand/document';
17
+ import {
18
+ type JSTypeOf,
19
+ OnDemandDocument,
20
+ type OnDemandDocumentDeserializeOptions
21
+ } from './on_demand/document';
14
22
 
15
23
  // eslint-disable-next-line no-restricted-syntax
16
24
  const enum BSONElementOffset {
@@ -112,7 +120,8 @@ export class MongoDBResponse extends OnDemandDocument {
112
120
  this.get('recoveryToken', BSONType.object)?.toObject({
113
121
  promoteValues: false,
114
122
  promoteLongs: false,
115
- promoteBuffers: false
123
+ promoteBuffers: false,
124
+ validation: { utf8: true }
116
125
  }) ?? null
117
126
  );
118
127
  }
@@ -165,6 +174,14 @@ export class MongoDBResponse extends OnDemandDocument {
165
174
  }
166
175
  return this.clusterTime ?? null;
167
176
  }
177
+
178
+ public override toObject(options?: BSONSerializeOptions): Record<string, any> {
179
+ const exactBSONOptions = {
180
+ ...pluckBSONSerializeOptions(options ?? {}),
181
+ validation: parseUtf8ValidationOption(options)
182
+ };
183
+ return super.toObject(exactBSONOptions);
184
+ }
168
185
  }
169
186
 
170
187
  /** @internal */
@@ -248,12 +265,13 @@ export class CursorResponse extends MongoDBResponse {
248
265
  this.cursor.get('postBatchResumeToken', BSONType.object)?.toObject({
249
266
  promoteValues: false,
250
267
  promoteLongs: false,
251
- promoteBuffers: false
268
+ promoteBuffers: false,
269
+ validation: { utf8: true }
252
270
  }) ?? null
253
271
  );
254
272
  }
255
273
 
256
- public shift(options?: BSONSerializeOptions): any {
274
+ public shift(options: OnDemandDocumentDeserializeOptions): any {
257
275
  if (this.iterated >= this.batchSize) {
258
276
  return null;
259
277
  }
@@ -305,7 +323,7 @@ export class ExplainedCursorResponse extends CursorResponse {
305
323
  return this._length;
306
324
  }
307
325
 
308
- override shift(options?: BSONSerializeOptions | undefined) {
326
+ override shift(options?: DeserializeOptions) {
309
327
  if (this._length === 0) return null;
310
328
  this._length -= 1;
311
329
  return this.toObject(options);
@@ -1,5 +1,6 @@
1
1
  import { MongoInvalidArgumentError } from '../../error';
2
- import { ReadPreference, type ReadPreferenceLike } from '../../read_preference';
2
+ import type { ReadPreferenceLike } from '../../read_preference';
3
+ import { ReadPreference } from '../../read_preference';
3
4
  import { ServerType } from '../../sdam/common';
4
5
  import type { Server } from '../../sdam/server';
5
6
  import type { ServerDescription } from '../../sdam/server_description';
package/src/collection.ts CHANGED
@@ -47,18 +47,17 @@ import {
47
47
  FindOneAndUpdateOperation,
48
48
  type FindOneAndUpdateOptions
49
49
  } from './operations/find_and_modify';
50
- import {
51
- CreateIndexesOperation,
52
- type CreateIndexesOptions,
53
- type DropIndexesOptions,
54
- DropIndexOperation,
55
- type IndexDescription,
56
- type IndexDescriptionCompact,
57
- type IndexDescriptionInfo,
58
- type IndexInformationOptions,
59
- type IndexSpecification,
60
- type ListIndexesOptions
50
+ import type {
51
+ CreateIndexesOptions,
52
+ DropIndexesOptions,
53
+ IndexDescription,
54
+ IndexDescriptionCompact,
55
+ IndexDescriptionInfo,
56
+ IndexInformationOptions,
57
+ IndexSpecification,
58
+ ListIndexesOptions
61
59
  } from './operations/indexes';
60
+ import { CreateIndexesOperation, DropIndexOperation } from './operations/indexes';
62
61
  import {
63
62
  InsertManyOperation,
64
63
  type InsertManyResult,
@@ -293,7 +292,7 @@ export class Collection<TSchema extends Document = Document> {
293
292
  * @param options - Optional settings for the command
294
293
  */
295
294
  async insertMany(
296
- docs: ReadonlyArray<OptionalUnlessRequiredId<TSchema>>,
295
+ docs: OptionalUnlessRequiredId<TSchema>[],
297
296
  options?: BulkWriteOptions
298
297
  ): Promise<InsertManyResult<TSchema>> {
299
298
  return await executeOperation(
@@ -326,7 +325,7 @@ export class Collection<TSchema extends Document = Document> {
326
325
  * @throws MongoDriverError if operations is not an array
327
326
  */
328
327
  async bulkWrite(
329
- operations: ReadonlyArray<AnyBulkWriteOperation<TSchema>>,
328
+ operations: AnyBulkWriteOperation<TSchema>[],
330
329
  options?: BulkWriteOptions
331
330
  ): Promise<BulkWriteResult> {
332
331
  if (!Array.isArray(operations)) {
@@ -337,7 +336,7 @@ export class Collection<TSchema extends Document = Document> {
337
336
  this.client,
338
337
  new BulkWriteOperation(
339
338
  this as TODO_NODE_3286,
340
- operations,
339
+ operations as TODO_NODE_3286,
341
340
  resolveOptions(this, options ?? { ordered: true })
342
341
  )
343
342
  );
@@ -1122,8 +1121,8 @@ export class Collection<TSchema extends Document = Document> {
1122
1121
  indexNameOrOptions == null
1123
1122
  ? null
1124
1123
  : typeof indexNameOrOptions === 'object'
1125
- ? null
1126
- : indexNameOrOptions;
1124
+ ? null
1125
+ : indexNameOrOptions;
1127
1126
 
1128
1127
  return new ListSearchIndexesCursor(this as TODO_NODE_3286, indexName, options);
1129
1128
  }
@@ -73,7 +73,7 @@ export async function resolveSRVRecord(options: MongoOptions): Promise<HostAddre
73
73
  // the SRV record is resolved before starting a second DNS query.
74
74
  const lookupAddress = options.srvHost;
75
75
  const txtResolutionPromise = dns.promises.resolveTxt(lookupAddress);
76
-
76
+ // eslint-disable-next-line github/no-then
77
77
  txtResolutionPromise.then(undefined, squashError); // rejections will be handled later
78
78
 
79
79
  // Resolve the SRV record and use the result as the list of hosts to connect to.
@@ -552,6 +552,7 @@ export function parseOptions(
552
552
 
553
553
  mongoOptions.metadata = makeClientMetadata(mongoOptions);
554
554
 
555
+ // eslint-disable-next-line github/no-then
555
556
  mongoOptions.extendedMetadata = addContainerMetadata(mongoOptions.metadata).then(
556
557
  undefined,
557
558
  squashError
@@ -739,13 +740,6 @@ export const OPTIONS = {
739
740
  autoEncryption: {
740
741
  type: 'record'
741
742
  },
742
- autoSelectFamily: {
743
- type: 'boolean',
744
- default: true
745
- },
746
- autoSelectFamilyAttemptTimeout: {
747
- type: 'uint'
748
- },
749
743
  bsonRegExp: {
750
744
  type: 'boolean'
751
745
  },
package/src/constants.ts CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
2
1
  export const SYSTEM_NAMESPACE_COLLECTION = 'system.namespaces';
3
2
  export const SYSTEM_INDEX_COLLECTION = 'system.indexes';
4
3
  export const SYSTEM_PROFILE_COLLECTION = 'system.profile';