mongodb 6.5.0 → 6.6.0-dev.20240504.sha.2609953

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 (207) hide show
  1. package/README.md +9 -9
  2. package/lib/admin.js +9 -9
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bson.js +33 -22
  5. package/lib/bson.js.map +1 -1
  6. package/lib/bulk/common.js +13 -12
  7. package/lib/bulk/common.js.map +1 -1
  8. package/lib/change_stream.js +28 -18
  9. package/lib/change_stream.js.map +1 -1
  10. package/lib/client-side-encryption/auto_encrypter.js +2 -2
  11. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  12. package/lib/client-side-encryption/client_encryption.js +6 -6
  13. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  14. package/lib/client-side-encryption/providers/aws.js +13 -10
  15. package/lib/client-side-encryption/providers/aws.js.map +1 -1
  16. package/lib/client-side-encryption/providers/azure.js +6 -3
  17. package/lib/client-side-encryption/providers/azure.js.map +1 -1
  18. package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
  19. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
  20. package/lib/cmap/auth/gssapi.js +7 -6
  21. package/lib/cmap/auth/gssapi.js.map +1 -1
  22. package/lib/cmap/auth/mongodb_aws.js +8 -101
  23. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  24. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
  25. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
  26. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
  27. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
  28. package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
  29. package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
  30. package/lib/cmap/auth/scram.js +2 -2
  31. package/lib/cmap/auth/scram.js.map +1 -1
  32. package/lib/cmap/commands.js +24 -111
  33. package/lib/cmap/commands.js.map +1 -1
  34. package/lib/cmap/connect.js +4 -4
  35. package/lib/cmap/connect.js.map +1 -1
  36. package/lib/cmap/connection.js +61 -36
  37. package/lib/cmap/connection.js.map +1 -1
  38. package/lib/cmap/connection_pool.js +22 -13
  39. package/lib/cmap/connection_pool.js.map +1 -1
  40. package/lib/cmap/handshake/client_metadata.js +2 -2
  41. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  42. package/lib/cmap/wire_protocol/compression.js +8 -8
  43. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  44. package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
  45. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
  46. package/lib/cmap/wire_protocol/responses.js +184 -0
  47. package/lib/cmap/wire_protocol/responses.js.map +1 -0
  48. package/lib/collection.js +42 -38
  49. package/lib/collection.js.map +1 -1
  50. package/lib/connection_string.js +4 -6
  51. package/lib/connection_string.js.map +1 -1
  52. package/lib/cursor/abstract_cursor.js +76 -43
  53. package/lib/cursor/abstract_cursor.js.map +1 -1
  54. package/lib/cursor/aggregation_cursor.js +16 -33
  55. package/lib/cursor/aggregation_cursor.js.map +1 -1
  56. package/lib/cursor/find_cursor.js +36 -18
  57. package/lib/cursor/find_cursor.js.map +1 -1
  58. package/lib/cursor/run_command_cursor.js +3 -2
  59. package/lib/cursor/run_command_cursor.js.map +1 -1
  60. package/lib/db.js +15 -19
  61. package/lib/db.js.map +1 -1
  62. package/lib/deps.js +31 -26
  63. package/lib/deps.js.map +1 -1
  64. package/lib/encrypter.js +14 -5
  65. package/lib/encrypter.js.map +1 -1
  66. package/lib/error.js +4 -3
  67. package/lib/error.js.map +1 -1
  68. package/lib/gridfs/download.js +19 -14
  69. package/lib/gridfs/download.js.map +1 -1
  70. package/lib/gridfs/index.js.map +1 -1
  71. package/lib/gridfs/upload.js +6 -1
  72. package/lib/gridfs/upload.js.map +1 -1
  73. package/lib/index.js.map +1 -1
  74. package/lib/mongo_client.js +11 -7
  75. package/lib/mongo_client.js.map +1 -1
  76. package/lib/mongo_logger.js +3 -0
  77. package/lib/mongo_logger.js.map +1 -1
  78. package/lib/operations/aggregate.js +2 -1
  79. package/lib/operations/aggregate.js.map +1 -1
  80. package/lib/operations/command.js +1 -1
  81. package/lib/operations/command.js.map +1 -1
  82. package/lib/operations/create_collection.js +1 -1
  83. package/lib/operations/create_collection.js.map +1 -1
  84. package/lib/operations/delete.js +4 -3
  85. package/lib/operations/delete.js.map +1 -1
  86. package/lib/operations/drop.js +1 -1
  87. package/lib/operations/drop.js.map +1 -1
  88. package/lib/operations/execute_operation.js +23 -8
  89. package/lib/operations/execute_operation.js.map +1 -1
  90. package/lib/operations/find.js +4 -4
  91. package/lib/operations/find.js.map +1 -1
  92. package/lib/operations/get_more.js +2 -1
  93. package/lib/operations/get_more.js.map +1 -1
  94. package/lib/operations/indexes.js +29 -121
  95. package/lib/operations/indexes.js.map +1 -1
  96. package/lib/operations/insert.js +3 -3
  97. package/lib/operations/insert.js.map +1 -1
  98. package/lib/operations/kill_cursors.js +3 -1
  99. package/lib/operations/kill_cursors.js.map +1 -1
  100. package/lib/operations/list_collections.js +1 -1
  101. package/lib/operations/list_collections.js.map +1 -1
  102. package/lib/operations/list_databases.js +1 -1
  103. package/lib/operations/list_databases.js.map +1 -1
  104. package/lib/operations/operation.js.map +1 -1
  105. package/lib/operations/run_command.js +4 -2
  106. package/lib/operations/run_command.js.map +1 -1
  107. package/lib/operations/search_indexes/create.js.map +1 -1
  108. package/lib/operations/stats.js +1 -1
  109. package/lib/operations/stats.js.map +1 -1
  110. package/lib/operations/update.js +1 -1
  111. package/lib/operations/update.js.map +1 -1
  112. package/lib/sdam/common.js.map +1 -1
  113. package/lib/sdam/monitor.js +139 -42
  114. package/lib/sdam/monitor.js.map +1 -1
  115. package/lib/sdam/server.js +5 -15
  116. package/lib/sdam/server.js.map +1 -1
  117. package/lib/sdam/server_description.js +1 -0
  118. package/lib/sdam/server_description.js.map +1 -1
  119. package/lib/sdam/server_selection.js +1 -1
  120. package/lib/sdam/server_selection.js.map +1 -1
  121. package/lib/sdam/srv_polling.js +2 -1
  122. package/lib/sdam/srv_polling.js.map +1 -1
  123. package/lib/sdam/topology.js +67 -54
  124. package/lib/sdam/topology.js.map +1 -1
  125. package/lib/sdam/topology_description.js +10 -0
  126. package/lib/sdam/topology_description.js.map +1 -1
  127. package/lib/sessions.js +133 -93
  128. package/lib/sessions.js.map +1 -1
  129. package/lib/timeout.js +77 -0
  130. package/lib/timeout.js.map +1 -0
  131. package/lib/utils.js +61 -28
  132. package/lib/utils.js.map +1 -1
  133. package/mongodb.d.ts +150 -38
  134. package/package.json +17 -14
  135. package/src/admin.ts +9 -9
  136. package/src/bson.ts +14 -0
  137. package/src/bulk/common.ts +3 -2
  138. package/src/change_stream.ts +39 -30
  139. package/src/client-side-encryption/auto_encrypter.ts +2 -2
  140. package/src/client-side-encryption/client_encryption.ts +6 -6
  141. package/src/client-side-encryption/providers/aws.ts +17 -10
  142. package/src/client-side-encryption/providers/azure.ts +5 -3
  143. package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
  144. package/src/cmap/auth/gssapi.ts +9 -11
  145. package/src/cmap/auth/mongodb_aws.ts +19 -126
  146. package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
  147. package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
  148. package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
  149. package/src/cmap/auth/scram.ts +2 -2
  150. package/src/cmap/commands.ts +28 -132
  151. package/src/cmap/connect.ts +4 -4
  152. package/src/cmap/connection.ts +107 -43
  153. package/src/cmap/connection_pool.ts +32 -29
  154. package/src/cmap/handshake/client_metadata.ts +2 -5
  155. package/src/cmap/wire_protocol/compression.ts +11 -13
  156. package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
  157. package/src/cmap/wire_protocol/responses.ts +237 -0
  158. package/src/collection.ts +87 -58
  159. package/src/connection_string.ts +9 -7
  160. package/src/cursor/abstract_cursor.ts +102 -38
  161. package/src/cursor/aggregation_cursor.ts +32 -34
  162. package/src/cursor/find_cursor.ts +33 -21
  163. package/src/cursor/list_search_indexes_cursor.ts +1 -1
  164. package/src/cursor/run_command_cursor.ts +3 -2
  165. package/src/db.ts +42 -21
  166. package/src/deps.ts +52 -40
  167. package/src/encrypter.ts +14 -5
  168. package/src/error.ts +9 -3
  169. package/src/gridfs/download.ts +19 -31
  170. package/src/gridfs/index.ts +2 -0
  171. package/src/gridfs/upload.ts +11 -8
  172. package/src/index.ts +13 -5
  173. package/src/mongo_client.ts +21 -15
  174. package/src/mongo_logger.ts +3 -0
  175. package/src/mongo_types.ts +1 -1
  176. package/src/operations/aggregate.ts +2 -1
  177. package/src/operations/command.ts +1 -1
  178. package/src/operations/create_collection.ts +7 -2
  179. package/src/operations/delete.ts +4 -3
  180. package/src/operations/drop.ts +1 -1
  181. package/src/operations/execute_operation.ts +29 -10
  182. package/src/operations/find.ts +13 -14
  183. package/src/operations/get_more.ts +9 -1
  184. package/src/operations/indexes.ts +103 -176
  185. package/src/operations/insert.ts +2 -2
  186. package/src/operations/kill_cursors.ts +3 -2
  187. package/src/operations/list_collections.ts +5 -1
  188. package/src/operations/list_databases.ts +1 -1
  189. package/src/operations/operation.ts +3 -0
  190. package/src/operations/run_command.ts +6 -4
  191. package/src/operations/search_indexes/create.ts +4 -1
  192. package/src/operations/stats.ts +1 -1
  193. package/src/operations/update.ts +7 -7
  194. package/src/sdam/common.ts +8 -2
  195. package/src/sdam/monitor.ts +178 -61
  196. package/src/sdam/server.ts +27 -20
  197. package/src/sdam/server_description.ts +8 -3
  198. package/src/sdam/server_selection.ts +2 -3
  199. package/src/sdam/srv_polling.ts +3 -2
  200. package/src/sdam/topology.ts +114 -117
  201. package/src/sdam/topology_description.ts +14 -4
  202. package/src/sessions.ts +168 -148
  203. package/src/timeout.ts +96 -0
  204. package/src/utils.ts +85 -32
  205. package/lib/operations/common_functions.js +0 -38
  206. package/lib/operations/common_functions.js.map +0 -1
  207. package/src/operations/common_functions.ts +0 -79
@@ -1,9 +1,8 @@
1
1
  import type { Document } from '../bson';
2
2
  import type { Collection } from '../collection';
3
- import type { Db } from '../db';
4
- import { MongoCompatibilityError, MONGODB_ERROR_CODES, MongoError } from '../error';
3
+ import { type AbstractCursorOptions } from '../cursor/abstract_cursor';
4
+ import { MongoCompatibilityError } from '../error';
5
5
  import { type OneOrMore } from '../mongo_types';
6
- import { ReadPreference } from '../read_preference';
7
6
  import type { Server } from '../sdam/server';
8
7
  import type { ClientSession } from '../sessions';
9
8
  import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
@@ -13,8 +12,7 @@ import {
13
12
  type CommandOperationOptions,
14
13
  type OperationParent
15
14
  } from './command';
16
- import { indexInformation, type IndexInformationOptions } from './common_functions';
17
- import { AbstractOperation, Aspect, defineAspects } from './operation';
15
+ import { Aspect, defineAspects } from './operation';
18
16
 
19
17
  const VALID_INDEX_OPTIONS = new Set([
20
18
  'background',
@@ -73,6 +71,29 @@ export type IndexSpecification = OneOrMore<
73
71
  | Map<string, IndexDirection>
74
72
  >;
75
73
 
74
+ /** @public */
75
+ export interface IndexInformationOptions extends ListIndexesOptions {
76
+ /**
77
+ * When `true`, an array of index descriptions is returned.
78
+ * When `false`, the driver returns an object that with keys corresponding to index names with values
79
+ * corresponding to the entries of the indexes' key.
80
+ *
81
+ * For example, the given the following indexes:
82
+ * ```
83
+ * [ { name: 'a_1', key: { a: 1 } }, { name: 'b_1_c_1' , key: { b: 1, c: 1 } }]
84
+ * ```
85
+ *
86
+ * When `full` is `true`, the above array is returned. When `full` is `false`, the following is returned:
87
+ * ```
88
+ * {
89
+ * 'a_1': [['a', 1]],
90
+ * 'b_1_c_1': [['b', 1], ['c', 1]],
91
+ * }
92
+ * ```
93
+ */
94
+ full?: boolean;
95
+ }
96
+
76
97
  /** @public */
77
98
  export interface IndexDescription
78
99
  extends Pick<
@@ -146,10 +167,11 @@ function isSingleIndexTuple(t: unknown): t is [string, IndexDirection] {
146
167
  return Array.isArray(t) && t.length === 2 && isIndexDirection(t[1]);
147
168
  }
148
169
 
149
- function makeIndexSpec(
150
- indexSpec: IndexSpecification,
151
- options?: CreateIndexesOptions
152
- ): IndexDescription {
170
+ /**
171
+ * Converts an `IndexSpecification`, which can be specified in multiple formats, into a
172
+ * valid `key` for the createIndexes command.
173
+ */
174
+ function constructIndexDescriptionMap(indexSpec: IndexSpecification): Map<string, IndexDirection> {
153
175
  const key: Map<string, IndexDirection> = new Map();
154
176
 
155
177
  const indexSpecs =
@@ -172,46 +194,60 @@ function makeIndexSpec(
172
194
  }
173
195
  }
174
196
 
175
- return { ...options, key };
197
+ return key;
176
198
  }
177
199
 
178
- /** @internal */
179
- export class IndexesOperation extends AbstractOperation<Document[]> {
180
- override options: IndexInformationOptions;
181
- collection: Collection;
182
-
183
- constructor(collection: Collection, options: IndexInformationOptions) {
184
- super(options);
185
- this.options = options;
186
- this.collection = collection;
187
- }
200
+ /**
201
+ * Receives an index description and returns a modified index description which has had invalid options removed
202
+ * from the description and has mapped the `version` option to the `v` option.
203
+ */
204
+ function resolveIndexDescription(
205
+ description: IndexDescription
206
+ ): Omit<ResolvedIndexDescription, 'key'> {
207
+ const validProvidedOptions = Object.entries(description).filter(([optionName]) =>
208
+ VALID_INDEX_OPTIONS.has(optionName)
209
+ );
188
210
 
189
- override get commandName() {
190
- return 'listIndexes' as const;
191
- }
211
+ return Object.fromEntries(
212
+ // we support the `version` option, but the `createIndexes` command expects it to be the `v`
213
+ validProvidedOptions.map(([name, value]) => (name === 'version' ? ['v', value] : [name, value]))
214
+ );
215
+ }
192
216
 
193
- override async execute(_server: Server, session: ClientSession | undefined): Promise<Document[]> {
194
- const coll = this.collection;
195
- const options = this.options;
217
+ /**
218
+ * @public
219
+ * The index information returned by the listIndexes command. https://www.mongodb.com/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes
220
+ */
221
+ export type IndexDescriptionInfo = Omit<IndexDescription, 'key' | 'version'> & {
222
+ key: { [key: string]: IndexDirection };
223
+ v?: IndexDescription['version'];
224
+ } & Document;
196
225
 
197
- return indexInformation(coll.s.db, coll.collectionName, {
198
- full: true,
199
- ...options,
200
- readPreference: this.readPreference,
201
- session
202
- });
203
- }
204
- }
226
+ /** @public */
227
+ export type IndexDescriptionCompact = Record<string, [name: string, direction: IndexDirection][]>;
228
+
229
+ /**
230
+ * @internal
231
+ *
232
+ * Internally, the driver represents index description keys with `Map`s to preserve key ordering.
233
+ * We don't require users to specify maps, so we transform user provided descriptions into
234
+ * "resolved" by converting the `key` into a JS `Map`, if it isn't already a map.
235
+ *
236
+ * Additionally, we support the `version` option, but the `createIndexes` command uses the field `v`
237
+ * to specify the index version so we map the value of `version` to `v`, if provided.
238
+ */
239
+ type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
240
+ key: Map<string, IndexDirection>;
241
+ v?: IndexDescription['version'];
242
+ };
205
243
 
206
244
  /** @internal */
207
- export class CreateIndexesOperation<
208
- T extends string | string[] = string[]
209
- > extends CommandOperation<T> {
245
+ export class CreateIndexesOperation extends CommandOperation<string[]> {
210
246
  override options: CreateIndexesOptions;
211
247
  collectionName: string;
212
- indexes: ReadonlyArray<Omit<IndexDescription, 'key'> & { key: Map<string, IndexDirection> }>;
248
+ indexes: ReadonlyArray<ResolvedIndexDescription>;
213
249
 
214
- constructor(
250
+ private constructor(
215
251
  parent: OperationParent,
216
252
  collectionName: string,
217
253
  indexes: IndexDescription[],
@@ -221,16 +257,12 @@ export class CreateIndexesOperation<
221
257
 
222
258
  this.options = options ?? {};
223
259
  this.collectionName = collectionName;
224
- this.indexes = indexes.map(userIndex => {
260
+ this.indexes = indexes.map((userIndex: IndexDescription): ResolvedIndexDescription => {
225
261
  // Ensure the key is a Map to preserve index key ordering
226
262
  const key =
227
263
  userIndex.key instanceof Map ? userIndex.key : new Map(Object.entries(userIndex.key));
228
- const name = userIndex.name != null ? userIndex.name : Array.from(key).flat().join('_');
229
- const validIndexOptions = Object.fromEntries(
230
- Object.entries({ ...userIndex }).filter(([optionName]) =>
231
- VALID_INDEX_OPTIONS.has(optionName)
232
- )
233
- );
264
+ const name = userIndex.name ?? Array.from(key).flat().join('_');
265
+ const validIndexOptions = resolveIndexDescription(userIndex);
234
266
  return {
235
267
  ...validIndexOptions,
236
268
  name,
@@ -239,11 +271,31 @@ export class CreateIndexesOperation<
239
271
  });
240
272
  }
241
273
 
274
+ static fromIndexDescriptionArray(
275
+ parent: OperationParent,
276
+ collectionName: string,
277
+ indexes: IndexDescription[],
278
+ options?: CreateIndexesOptions
279
+ ): CreateIndexesOperation {
280
+ return new CreateIndexesOperation(parent, collectionName, indexes, options);
281
+ }
282
+
283
+ static fromIndexSpecification(
284
+ parent: OperationParent,
285
+ collectionName: string,
286
+ indexSpec: IndexSpecification,
287
+ options: CreateIndexesOptions = {}
288
+ ): CreateIndexesOperation {
289
+ const key = constructIndexDescriptionMap(indexSpec);
290
+ const description: IndexDescription = { ...options, key };
291
+ return new CreateIndexesOperation(parent, collectionName, [description], options);
292
+ }
293
+
242
294
  override get commandName() {
243
295
  return 'createIndexes';
244
296
  }
245
297
 
246
- override async execute(server: Server, session: ClientSession | undefined): Promise<T> {
298
+ override async execute(server: Server, session: ClientSession | undefined): Promise<string[]> {
247
299
  const options = this.options;
248
300
  const indexes = this.indexes;
249
301
 
@@ -266,61 +318,7 @@ export class CreateIndexesOperation<
266
318
  await super.executeCommand(server, session, cmd);
267
319
 
268
320
  const indexNames = indexes.map(index => index.name || '');
269
- return indexNames as T;
270
- }
271
- }
272
-
273
- /** @internal */
274
- export class CreateIndexOperation extends CreateIndexesOperation<string> {
275
- constructor(
276
- parent: OperationParent,
277
- collectionName: string,
278
- indexSpec: IndexSpecification,
279
- options?: CreateIndexesOptions
280
- ) {
281
- super(parent, collectionName, [makeIndexSpec(indexSpec, options)], options);
282
- }
283
-
284
- override async execute(server: Server, session: ClientSession | undefined): Promise<string> {
285
- const indexNames = await super.execute(server, session);
286
- return indexNames[0];
287
- }
288
- }
289
-
290
- /** @internal */
291
- export class EnsureIndexOperation extends CreateIndexOperation {
292
- db: Db;
293
-
294
- constructor(
295
- db: Db,
296
- collectionName: string,
297
- indexSpec: IndexSpecification,
298
- options?: CreateIndexesOptions
299
- ) {
300
- super(db, collectionName, indexSpec, options);
301
-
302
- this.readPreference = ReadPreference.primary;
303
- this.db = db;
304
- this.collectionName = collectionName;
305
- }
306
-
307
- override get commandName() {
308
- return 'listIndexes';
309
- }
310
-
311
- override async execute(server: Server, session: ClientSession | undefined): Promise<string> {
312
- const indexName = this.indexes[0].name;
313
- const indexes = await this.db
314
- .collection(this.collectionName)
315
- .listIndexes({ session })
316
- .toArray()
317
- .catch(error => {
318
- if (error instanceof MongoError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound)
319
- return [];
320
- throw error;
321
- });
322
- if (indexName && indexes.some(index => index.name === indexName)) return indexName;
323
- return super.execute(server, session);
321
+ return indexNames;
324
322
  }
325
323
  }
326
324
 
@@ -347,15 +345,12 @@ export class DropIndexOperation extends CommandOperation<Document> {
347
345
 
348
346
  override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
349
347
  const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
350
- return super.executeCommand(server, session, cmd);
348
+ return await super.executeCommand(server, session, cmd);
351
349
  }
352
350
  }
353
351
 
354
352
  /** @public */
355
- export interface ListIndexesOptions extends Omit<CommandOperationOptions, 'writeConcern'> {
356
- /** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
357
- batchSize?: number;
358
- }
353
+ export type ListIndexesOptions = AbstractCursorOptions;
359
354
 
360
355
  /** @internal */
361
356
  export class ListIndexesOperation extends CommandOperation<Document> {
@@ -394,73 +389,7 @@ export class ListIndexesOperation extends CommandOperation<Document> {
394
389
  command.comment = this.options.comment;
395
390
  }
396
391
 
397
- return super.executeCommand(server, session, command);
398
- }
399
- }
400
-
401
- /** @internal */
402
- export class IndexExistsOperation extends AbstractOperation<boolean> {
403
- override options: IndexInformationOptions;
404
- collection: Collection;
405
- indexes: string | string[];
406
-
407
- constructor(
408
- collection: Collection,
409
- indexes: string | string[],
410
- options: IndexInformationOptions
411
- ) {
412
- super(options);
413
- this.options = options;
414
- this.collection = collection;
415
- this.indexes = indexes;
416
- }
417
-
418
- override get commandName() {
419
- return 'listIndexes' as const;
420
- }
421
-
422
- override async execute(server: Server, session: ClientSession | undefined): Promise<boolean> {
423
- const coll = this.collection;
424
- const indexes = this.indexes;
425
-
426
- const info = await indexInformation(coll.s.db, coll.collectionName, {
427
- ...this.options,
428
- readPreference: this.readPreference,
429
- session
430
- });
431
- // Let's check for the index names
432
- if (!Array.isArray(indexes)) return info[indexes] != null;
433
- // All keys found return true
434
- return indexes.every(indexName => info[indexName] != null);
435
- }
436
- }
437
-
438
- /** @internal */
439
- export class IndexInformationOperation extends AbstractOperation<Document> {
440
- override options: IndexInformationOptions;
441
- db: Db;
442
- name: string;
443
-
444
- constructor(db: Db, name: string, options?: IndexInformationOptions) {
445
- super(options);
446
- this.options = options ?? {};
447
- this.db = db;
448
- this.name = name;
449
- }
450
-
451
- override get commandName() {
452
- return 'listIndexes' as const;
453
- }
454
-
455
- override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
456
- const db = this.db;
457
- const name = this.name;
458
-
459
- return indexInformation(db, name, {
460
- ...this.options,
461
- readPreference: this.readPreference,
462
- session
463
- });
392
+ return await super.executeCommand(server, session, command);
464
393
  }
465
394
  }
466
395
 
@@ -470,6 +399,4 @@ defineAspects(ListIndexesOperation, [
470
399
  Aspect.CURSOR_CREATING
471
400
  ]);
472
401
  defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION]);
473
- defineAspects(CreateIndexOperation, [Aspect.WRITE_OPERATION]);
474
- defineAspects(EnsureIndexOperation, [Aspect.WRITE_OPERATION]);
475
402
  defineAspects(DropIndexOperation, [Aspect.WRITE_OPERATION]);
@@ -6,10 +6,10 @@ import type { InferIdType } from '../mongo_types';
6
6
  import type { Server } from '../sdam/server';
7
7
  import type { ClientSession } from '../sessions';
8
8
  import type { MongoDBNamespace } from '../utils';
9
+ import { maybeAddIdToDocuments } from '../utils';
9
10
  import { WriteConcern } from '../write_concern';
10
11
  import { BulkWriteOperation } from './bulk_write';
11
12
  import { CommandOperation, type CommandOperationOptions } from './command';
12
- import { maybeAddIdToDocuments } from './common_functions';
13
13
  import { AbstractOperation, Aspect, defineAspects } from './operation';
14
14
 
15
15
  /** @internal */
@@ -47,7 +47,7 @@ export class InsertOperation extends CommandOperation<Document> {
47
47
  command.comment = options.comment;
48
48
  }
49
49
 
50
- return super.executeCommand(server, session, command);
50
+ return await super.executeCommand(server, session, command);
51
51
  }
52
52
  }
53
53
 
@@ -2,7 +2,7 @@ import type { Long } from '../bson';
2
2
  import { MongoRuntimeError } from '../error';
3
3
  import type { Server } from '../sdam/server';
4
4
  import type { ClientSession } from '../sessions';
5
- import type { MongoDBNamespace } from '../utils';
5
+ import { type MongoDBNamespace, squashError } from '../utils';
6
6
  import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
7
7
 
8
8
  /**
@@ -47,8 +47,9 @@ export class KillCursorsOperation extends AbstractOperation {
47
47
  };
48
48
  try {
49
49
  await server.command(this.ns, killCursorsCommand, { session });
50
- } catch {
50
+ } catch (error) {
51
51
  // The driver should never emit errors from killCursors, this is spec-ed behavior
52
+ squashError(error);
52
53
  }
53
54
  }
54
55
  }
@@ -52,7 +52,11 @@ export class ListCollectionsOperation extends CommandOperation<Document> {
52
52
  }
53
53
 
54
54
  override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
55
- return super.executeCommand(server, session, this.generateCommand(maxWireVersion(server)));
55
+ return await super.executeCommand(
56
+ server,
57
+ session,
58
+ this.generateCommand(maxWireVersion(server))
59
+ );
56
60
  }
57
61
 
58
62
  /* This is here for the purpose of unit testing the final command that gets sent. */
@@ -63,7 +63,7 @@ export class ListDatabasesOperation extends CommandOperation<ListDatabasesResult
63
63
  cmd.comment = this.options.comment;
64
64
  }
65
65
 
66
- return super.executeCommand(server, session, cmd) as TODO_NODE_3286;
66
+ return await (super.executeCommand(server, session, cmd) as Promise<TODO_NODE_3286>);
67
67
  }
68
68
  }
69
69
 
@@ -34,6 +34,9 @@ export interface OperationOptions extends BSONSerializeOptions {
34
34
  /** @internal Hints to `executeOperation` that this operation should not unpin on an ended transaction */
35
35
  bypassPinningCheck?: boolean;
36
36
  omitReadPreference?: boolean;
37
+
38
+ /** @internal TODO(NODE-5688): make this public */
39
+ timeoutMS?: number;
37
40
  }
38
41
 
39
42
  /** @internal */
@@ -28,11 +28,12 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
28
28
 
29
29
  override async execute(server: Server, session: ClientSession | undefined): Promise<T> {
30
30
  this.server = server;
31
- return server.command(this.ns, this.command, {
31
+ const res: TODO_NODE_3286 = await server.command(this.ns, this.command, {
32
32
  ...this.options,
33
33
  readPreference: this.readPreference,
34
34
  session
35
- }) as TODO_NODE_3286;
35
+ });
36
+ return res;
36
37
  }
37
38
  }
38
39
 
@@ -54,10 +55,11 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
54
55
 
55
56
  override async execute(server: Server, session: ClientSession | undefined): Promise<T> {
56
57
  this.server = server;
57
- return server.command(this.ns, this.command, {
58
+ const res: TODO_NODE_3286 = await server.command(this.ns, this.command, {
58
59
  ...this.options,
59
60
  readPreference: this.readPreference,
60
61
  session
61
- }) as TODO_NODE_3286;
62
+ });
63
+ return res;
62
64
  }
63
65
  }
@@ -8,12 +8,15 @@ import { AbstractOperation } from '../operation';
8
8
  /**
9
9
  * @public
10
10
  */
11
- export interface SearchIndexDescription {
11
+ export interface SearchIndexDescription extends Document {
12
12
  /** The name of the index. */
13
13
  name?: string;
14
14
 
15
15
  /** The index definition. */
16
16
  definition: Document;
17
+
18
+ /** The type of the index. Currently `search` or `vectorSearch` are supported. */
19
+ type?: string;
17
20
  }
18
21
 
19
22
  /** @internal */
@@ -30,7 +30,7 @@ export class DbStatsOperation extends CommandOperation<Document> {
30
30
  command.scale = this.options.scale;
31
31
  }
32
32
 
33
- return super.executeCommand(server, session, command);
33
+ return await super.executeCommand(server, session, command);
34
34
  }
35
35
  }
36
36
 
@@ -122,7 +122,7 @@ export class UpdateOperation extends CommandOperation<Document> {
122
122
  }
123
123
  }
124
124
 
125
- return super.executeCommand(server, session, command);
125
+ return await super.executeCommand(server, session, command);
126
126
  }
127
127
  }
128
128
 
@@ -144,8 +144,8 @@ export class UpdateOneOperation extends UpdateOperation {
144
144
  server: Server,
145
145
  session: ClientSession | undefined
146
146
  ): Promise<UpdateResult> {
147
- const res = await super.execute(server, session);
148
- if (this.explain != null) return res as TODO_NODE_3286;
147
+ const res: TODO_NODE_3286 = await super.execute(server, session);
148
+ if (this.explain != null) return res;
149
149
  if (res.code) throw new MongoServerError(res);
150
150
  if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
151
151
 
@@ -178,8 +178,8 @@ export class UpdateManyOperation extends UpdateOperation {
178
178
  server: Server,
179
179
  session: ClientSession | undefined
180
180
  ): Promise<UpdateResult> {
181
- const res = await super.execute(server, session);
182
- if (this.explain != null) return res as TODO_NODE_3286;
181
+ const res: TODO_NODE_3286 = await super.execute(server, session);
182
+ if (this.explain != null) return res;
183
183
  if (res.code) throw new MongoServerError(res);
184
184
  if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
185
185
 
@@ -231,8 +231,8 @@ export class ReplaceOneOperation extends UpdateOperation {
231
231
  server: Server,
232
232
  session: ClientSession | undefined
233
233
  ): Promise<UpdateResult> {
234
- const res = await super.execute(server, session);
235
- if (this.explain != null) return res as TODO_NODE_3286;
234
+ const res: TODO_NODE_3286 = await super.execute(server, session);
235
+ if (this.explain != null) return res;
236
236
  if (res.code) throw new MongoServerError(res);
237
237
  if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
238
238
 
@@ -55,10 +55,16 @@ export function drainTimerQueue(queue: TimerQueue): void {
55
55
  queue.clear();
56
56
  }
57
57
 
58
- /** @public */
58
+ /**
59
+ * @public
60
+ * Gossiped in component for the cluster time tracking the state of user databases
61
+ * across the cluster. It may optionally include a signature identifying the process that
62
+ * generated such a value.
63
+ */
59
64
  export interface ClusterTime {
60
65
  clusterTime: Timestamp;
61
- signature: {
66
+ /** Used to validate the identity of a request or response's ClusterTime. */
67
+ signature?: {
62
68
  hash: Binary;
63
69
  keyId: Long;
64
70
  };