mongodb 6.5.0-dev.20240426.sha.6d8ad33 → 6.5.0-dev.20240503.sha.7f191cf

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 (36) hide show
  1. package/lib/cmap/connection.js +8 -4
  2. package/lib/cmap/connection.js.map +1 -1
  3. package/lib/cmap/wire_protocol/on_demand/document.js +27 -16
  4. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  5. package/lib/cmap/wire_protocol/responses.js +106 -10
  6. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  7. package/lib/cursor/abstract_cursor.js +33 -27
  8. package/lib/cursor/abstract_cursor.js.map +1 -1
  9. package/lib/cursor/find_cursor.js +21 -8
  10. package/lib/cursor/find_cursor.js.map +1 -1
  11. package/lib/cursor/run_command_cursor.js +2 -1
  12. package/lib/cursor/run_command_cursor.js.map +1 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/operations/execute_operation.js.map +1 -1
  15. package/lib/operations/find.js +3 -3
  16. package/lib/operations/find.js.map +1 -1
  17. package/lib/operations/get_more.js +2 -1
  18. package/lib/operations/get_more.js.map +1 -1
  19. package/lib/sdam/server.js +3 -7
  20. package/lib/sdam/server.js.map +1 -1
  21. package/lib/utils.js +13 -2
  22. package/lib/utils.js.map +1 -1
  23. package/mongodb.d.ts +2 -0
  24. package/package.json +2 -2
  25. package/src/cmap/connection.ts +14 -5
  26. package/src/cmap/wire_protocol/on_demand/document.ts +36 -21
  27. package/src/cmap/wire_protocol/responses.ts +139 -11
  28. package/src/cursor/abstract_cursor.ts +61 -21
  29. package/src/cursor/find_cursor.ts +17 -9
  30. package/src/cursor/run_command_cursor.ts +2 -1
  31. package/src/index.ts +5 -1
  32. package/src/operations/execute_operation.ts +2 -1
  33. package/src/operations/find.ts +13 -14
  34. package/src/operations/get_more.ts +9 -1
  35. package/src/sdam/server.ts +22 -7
  36. package/src/utils.ts +13 -0
@@ -7,6 +7,7 @@ import {
7
7
  type ConnectionPoolOptions
8
8
  } from '../cmap/connection_pool';
9
9
  import { PoolClearedError } from '../cmap/errors';
10
+ import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses';
10
11
  import {
11
12
  APM_EVENTS,
12
13
  CLOSED,
@@ -262,11 +263,25 @@ export class Server extends TypedEventEmitter<ServerEvents> {
262
263
  }
263
264
  }
264
265
 
265
- /**
266
- * Execute a command
267
- * @internal
268
- */
269
- async command(ns: MongoDBNamespace, cmd: Document, options: CommandOptions): Promise<Document> {
266
+ public async command<T extends MongoDBResponseConstructor>(
267
+ ns: MongoDBNamespace,
268
+ command: Document,
269
+ options: CommandOptions | undefined,
270
+ responseType: T | undefined
271
+ ): Promise<typeof responseType extends undefined ? Document : InstanceType<T>>;
272
+
273
+ public async command(
274
+ ns: MongoDBNamespace,
275
+ command: Document,
276
+ options?: CommandOptions
277
+ ): Promise<Document>;
278
+
279
+ public async command(
280
+ ns: MongoDBNamespace,
281
+ cmd: Document,
282
+ options: CommandOptions,
283
+ responseType?: MongoDBResponseConstructor
284
+ ): Promise<Document> {
270
285
  if (ns.db == null || typeof ns === 'string') {
271
286
  throw new MongoInvalidArgumentError('Namespace must not be a string');
272
287
  }
@@ -308,7 +323,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
308
323
 
309
324
  try {
310
325
  try {
311
- return await conn.command(ns, cmd, finalOptions);
326
+ return await conn.command(ns, cmd, finalOptions, responseType);
312
327
  } catch (commandError) {
313
328
  throw this.decorateCommandError(conn, cmd, finalOptions, commandError);
314
329
  }
@@ -319,7 +334,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
319
334
  ) {
320
335
  await this.pool.reauthenticate(conn);
321
336
  try {
322
- return await conn.command(ns, cmd, finalOptions);
337
+ return await conn.command(ns, cmd, finalOptions, responseType);
323
338
  } catch (commandError) {
324
339
  throw this.decorateCommandError(conn, cmd, finalOptions, commandError);
325
340
  }
package/src/utils.ts CHANGED
@@ -64,6 +64,19 @@ export const ByteUtils = {
64
64
  }
65
65
  };
66
66
 
67
+ /**
68
+ * Returns true if value is a Uint8Array or a Buffer
69
+ * @param value - any value that may be a Uint8Array
70
+ */
71
+ export function isUint8Array(value: unknown): value is Uint8Array {
72
+ return (
73
+ value != null &&
74
+ typeof value === 'object' &&
75
+ Symbol.toStringTag in value &&
76
+ value[Symbol.toStringTag] === 'Uint8Array'
77
+ );
78
+ }
79
+
67
80
  /**
68
81
  * Determines if a connection's address matches a user provided list
69
82
  * of domain wildcards.