mongodb 6.5.0-dev.20240326.sha.918fe69 → 6.5.0-dev.20240403.sha.cb5903f

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 (155) hide show
  1. package/lib/admin.js +9 -9
  2. package/lib/admin.js.map +1 -1
  3. package/lib/bson.js +33 -22
  4. package/lib/bson.js.map +1 -1
  5. package/lib/bulk/common.js +2 -1
  6. package/lib/bulk/common.js.map +1 -1
  7. package/lib/change_stream.js +21 -13
  8. package/lib/change_stream.js.map +1 -1
  9. package/lib/client-side-encryption/auto_encrypter.js +2 -2
  10. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  11. package/lib/client-side-encryption/client_encryption.js +6 -6
  12. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  13. package/lib/client-side-encryption/providers/azure.js +6 -3
  14. package/lib/client-side-encryption/providers/azure.js.map +1 -1
  15. package/lib/cmap/auth/aws_temporary_credentials.js +1 -1
  16. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
  17. package/lib/cmap/auth/gssapi.js +6 -6
  18. package/lib/cmap/auth/gssapi.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
  20. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
  22. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
  23. package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
  24. package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
  25. package/lib/cmap/auth/scram.js +2 -2
  26. package/lib/cmap/auth/scram.js.map +1 -1
  27. package/lib/cmap/connect.js +3 -3
  28. package/lib/cmap/connect.js.map +1 -1
  29. package/lib/cmap/connection.js +7 -5
  30. package/lib/cmap/connection.js.map +1 -1
  31. package/lib/cmap/connection_pool.js +2 -1
  32. package/lib/cmap/connection_pool.js.map +1 -1
  33. package/lib/cmap/handshake/client_metadata.js +2 -2
  34. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  35. package/lib/cmap/wire_protocol/compression.js +6 -6
  36. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  37. package/lib/cmap/wire_protocol/on_demand/document.js +207 -0
  38. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
  39. package/lib/collection.js +25 -25
  40. package/lib/collection.js.map +1 -1
  41. package/lib/connection_string.js +4 -6
  42. package/lib/connection_string.js.map +1 -1
  43. package/lib/cursor/abstract_cursor.js +44 -18
  44. package/lib/cursor/abstract_cursor.js.map +1 -1
  45. package/lib/cursor/aggregation_cursor.js +1 -1
  46. package/lib/cursor/aggregation_cursor.js.map +1 -1
  47. package/lib/cursor/find_cursor.js +16 -11
  48. package/lib/cursor/find_cursor.js.map +1 -1
  49. package/lib/cursor/run_command_cursor.js +1 -1
  50. package/lib/cursor/run_command_cursor.js.map +1 -1
  51. package/lib/db.js +11 -11
  52. package/lib/db.js.map +1 -1
  53. package/lib/encrypter.js +10 -4
  54. package/lib/encrypter.js.map +1 -1
  55. package/lib/gridfs/download.js +19 -14
  56. package/lib/gridfs/download.js.map +1 -1
  57. package/lib/gridfs/upload.js +6 -1
  58. package/lib/gridfs/upload.js.map +1 -1
  59. package/lib/mongo_client.js +10 -5
  60. package/lib/mongo_client.js.map +1 -1
  61. package/lib/mongo_logger.js +3 -0
  62. package/lib/mongo_logger.js.map +1 -1
  63. package/lib/operations/aggregate.js +2 -1
  64. package/lib/operations/aggregate.js.map +1 -1
  65. package/lib/operations/command.js +1 -1
  66. package/lib/operations/command.js.map +1 -1
  67. package/lib/operations/delete.js +4 -3
  68. package/lib/operations/delete.js.map +1 -1
  69. package/lib/operations/drop.js +1 -1
  70. package/lib/operations/drop.js.map +1 -1
  71. package/lib/operations/execute_operation.js +13 -3
  72. package/lib/operations/execute_operation.js.map +1 -1
  73. package/lib/operations/find.js +1 -1
  74. package/lib/operations/find.js.map +1 -1
  75. package/lib/operations/get_more.js +1 -1
  76. package/lib/operations/get_more.js.map +1 -1
  77. package/lib/operations/indexes.js +2 -2
  78. package/lib/operations/indexes.js.map +1 -1
  79. package/lib/operations/insert.js +1 -1
  80. package/lib/operations/insert.js.map +1 -1
  81. package/lib/operations/kill_cursors.js +3 -1
  82. package/lib/operations/kill_cursors.js.map +1 -1
  83. package/lib/operations/list_collections.js +1 -1
  84. package/lib/operations/list_collections.js.map +1 -1
  85. package/lib/operations/list_databases.js +1 -1
  86. package/lib/operations/list_databases.js.map +1 -1
  87. package/lib/operations/run_command.js +4 -2
  88. package/lib/operations/run_command.js.map +1 -1
  89. package/lib/operations/stats.js +1 -1
  90. package/lib/operations/stats.js.map +1 -1
  91. package/lib/operations/update.js +1 -1
  92. package/lib/operations/update.js.map +1 -1
  93. package/lib/sdam/monitor.js +4 -0
  94. package/lib/sdam/monitor.js.map +1 -1
  95. package/lib/sdam/srv_polling.js +2 -1
  96. package/lib/sdam/srv_polling.js.map +1 -1
  97. package/lib/sdam/topology.js +1 -1
  98. package/lib/sdam/topology.js.map +1 -1
  99. package/lib/sessions.js +6 -4
  100. package/lib/sessions.js.map +1 -1
  101. package/lib/utils.js +28 -2
  102. package/lib/utils.js.map +1 -1
  103. package/mongodb.d.ts +7 -7
  104. package/package.json +3 -2
  105. package/src/admin.ts +9 -9
  106. package/src/bson.ts +13 -0
  107. package/src/bulk/common.ts +2 -1
  108. package/src/change_stream.ts +28 -21
  109. package/src/client-side-encryption/auto_encrypter.ts +2 -2
  110. package/src/client-side-encryption/client_encryption.ts +6 -6
  111. package/src/client-side-encryption/providers/azure.ts +5 -3
  112. package/src/cmap/auth/aws_temporary_credentials.ts +3 -1
  113. package/src/cmap/auth/gssapi.ts +7 -7
  114. package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
  115. package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
  116. package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
  117. package/src/cmap/auth/scram.ts +2 -2
  118. package/src/cmap/connect.ts +3 -3
  119. package/src/cmap/connection.ts +8 -5
  120. package/src/cmap/connection_pool.ts +2 -1
  121. package/src/cmap/handshake/client_metadata.ts +2 -5
  122. package/src/cmap/wire_protocol/compression.ts +6 -6
  123. package/src/cmap/wire_protocol/on_demand/document.ts +322 -0
  124. package/src/collection.ts +25 -25
  125. package/src/connection_string.ts +9 -7
  126. package/src/cursor/abstract_cursor.ts +40 -19
  127. package/src/cursor/aggregation_cursor.ts +1 -1
  128. package/src/cursor/find_cursor.ts +16 -12
  129. package/src/cursor/run_command_cursor.ts +1 -1
  130. package/src/db.ts +14 -11
  131. package/src/encrypter.ts +9 -4
  132. package/src/gridfs/download.ts +17 -31
  133. package/src/gridfs/upload.ts +9 -8
  134. package/src/mongo_client.ts +17 -12
  135. package/src/mongo_logger.ts +3 -0
  136. package/src/operations/aggregate.ts +2 -1
  137. package/src/operations/command.ts +1 -1
  138. package/src/operations/delete.ts +4 -3
  139. package/src/operations/drop.ts +1 -1
  140. package/src/operations/execute_operation.ts +12 -4
  141. package/src/operations/find.ts +1 -1
  142. package/src/operations/get_more.ts +1 -1
  143. package/src/operations/indexes.ts +2 -2
  144. package/src/operations/insert.ts +1 -1
  145. package/src/operations/kill_cursors.ts +3 -2
  146. package/src/operations/list_collections.ts +5 -1
  147. package/src/operations/list_databases.ts +1 -1
  148. package/src/operations/run_command.ts +6 -4
  149. package/src/operations/stats.ts +1 -1
  150. package/src/operations/update.ts +7 -7
  151. package/src/sdam/monitor.ts +4 -0
  152. package/src/sdam/srv_polling.ts +3 -2
  153. package/src/sdam/topology.ts +1 -1
  154. package/src/sessions.ts +7 -4
  155. package/src/utils.ts +26 -1
package/src/bson.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { DeserializeOptions, SerializeOptions } from 'bson';
2
+ import { BSON } from 'bson';
2
3
 
3
4
  export {
4
5
  Binary,
5
6
  BSON,
7
+ BSONError,
6
8
  BSONRegExp,
7
9
  BSONSymbol,
8
10
  BSONType,
@@ -25,6 +27,17 @@ export {
25
27
  UUID
26
28
  } from 'bson';
27
29
 
30
+ export type BSONElement = BSON.OnDemand['BSONElement'];
31
+
32
+ export function parseToElementsToArray(bytes: Uint8Array, offset?: number): BSONElement[] {
33
+ const res = BSON.onDemand.parseToElements(bytes, offset);
34
+ return Array.isArray(res) ? res : [...res];
35
+ }
36
+ export const getInt32LE = BSON.onDemand.NumberUtils.getInt32LE;
37
+ export const getFloat64LE = BSON.onDemand.NumberUtils.getFloat64LE;
38
+ export const getBigInt64LE = BSON.onDemand.NumberUtils.getBigInt64LE;
39
+ export const toUTF8 = BSON.onDemand.ByteUtils.toUTF8;
40
+
28
41
  /**
29
42
  * BSON Serialization options.
30
43
  * @public
@@ -589,6 +589,7 @@ function executeCommands(
589
589
  : null;
590
590
 
591
591
  if (operation != null) {
592
+ // eslint-disable-next-line github/no-then
592
593
  executeOperation(bulkOperation.s.collection.client, operation).then(
593
594
  result => resultHandler(undefined, result),
594
595
  error => resultHandler(error)
@@ -1224,7 +1225,7 @@ export abstract class BulkOperationBase {
1224
1225
  const finalOptions = { ...this.s.options, ...options };
1225
1226
  const operation = new BulkWriteShimOperation(this, finalOptions);
1226
1227
 
1227
- return executeOperation(this.s.collection.client, operation);
1228
+ return await executeOperation(this.s.collection.client, operation);
1228
1229
  }
1229
1230
 
1230
1231
  /**
@@ -19,7 +19,7 @@ import type { AggregateOptions } from './operations/aggregate';
19
19
  import type { CollationOptions, OperationParent } from './operations/command';
20
20
  import type { ReadPreference } from './read_preference';
21
21
  import type { ServerSessionId } from './sessions';
22
- import { filterOptions, getTopology, type MongoDBNamespace } from './utils';
22
+ import { filterOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
23
23
 
24
24
  /** @internal */
25
25
  const kCursorStream = Symbol('cursorStream');
@@ -379,7 +379,7 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
379
379
  /**
380
380
  * Only present when the `showExpandedEvents` flag is enabled.
381
381
  * @public
382
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
382
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/createIndexes/#mongodb-data-createIndexes
383
383
  */
384
384
  export interface ChangeStreamCreateIndexDocument
385
385
  extends ChangeStreamDocumentCommon,
@@ -392,7 +392,7 @@ export interface ChangeStreamCreateIndexDocument
392
392
  /**
393
393
  * Only present when the `showExpandedEvents` flag is enabled.
394
394
  * @public
395
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
395
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/dropIndexes/#mongodb-data-dropIndexes
396
396
  */
397
397
  export interface ChangeStreamDropIndexDocument
398
398
  extends ChangeStreamDocumentCommon,
@@ -405,7 +405,7 @@ export interface ChangeStreamDropIndexDocument
405
405
  /**
406
406
  * Only present when the `showExpandedEvents` flag is enabled.
407
407
  * @public
408
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
408
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/modify/#mongodb-data-modify
409
409
  */
410
410
  export interface ChangeStreamCollModDocument
411
411
  extends ChangeStreamDocumentCommon,
@@ -416,7 +416,7 @@ export interface ChangeStreamCollModDocument
416
416
 
417
417
  /**
418
418
  * @public
419
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
419
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/create/#mongodb-data-create
420
420
  */
421
421
  export interface ChangeStreamCreateDocument
422
422
  extends ChangeStreamDocumentCommon,
@@ -427,7 +427,7 @@ export interface ChangeStreamCreateDocument
427
427
 
428
428
  /**
429
429
  * @public
430
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
430
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/shardCollection/#mongodb-data-shardCollection
431
431
  */
432
432
  export interface ChangeStreamShardCollectionDocument
433
433
  extends ChangeStreamDocumentCommon,
@@ -439,7 +439,7 @@ export interface ChangeStreamShardCollectionDocument
439
439
 
440
440
  /**
441
441
  * @public
442
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
442
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/reshardCollection/#mongodb-data-reshardCollection
443
443
  */
444
444
  export interface ChangeStreamReshardCollectionDocument
445
445
  extends ChangeStreamDocumentCommon,
@@ -451,7 +451,7 @@ export interface ChangeStreamReshardCollectionDocument
451
451
 
452
452
  /**
453
453
  * @public
454
- * @see https://www.mongodb.com/docs/manual/reference/change-events/
454
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/refineCollectionShardKey/#mongodb-data-refineCollectionShardKey
455
455
  */
456
456
  export interface ChangeStreamRefineCollectionShardKeyDocument
457
457
  extends ChangeStreamDocumentCommon,
@@ -676,8 +676,8 @@ export class ChangeStream<
676
676
  } catch (error) {
677
677
  try {
678
678
  await this.close();
679
- } catch {
680
- // We are not concerned with errors from close()
679
+ } catch (error) {
680
+ squashError(error);
681
681
  }
682
682
  throw error;
683
683
  }
@@ -703,8 +703,8 @@ export class ChangeStream<
703
703
  } catch (error) {
704
704
  try {
705
705
  await this.close();
706
- } catch {
707
- // We are not concerned with errors from close()
706
+ } catch (error) {
707
+ squashError(error);
708
708
  }
709
709
  throw error;
710
710
  }
@@ -731,8 +731,8 @@ export class ChangeStream<
731
731
  } catch (error) {
732
732
  try {
733
733
  await this.close();
734
- } catch {
735
- // We are not concerned with errors from close()
734
+ } catch (error) {
735
+ squashError(error);
736
736
  }
737
737
  throw error;
738
738
  }
@@ -754,8 +754,8 @@ export class ChangeStream<
754
754
  } finally {
755
755
  try {
756
756
  await this.close();
757
- } catch {
758
- // we're not concerned with errors from close()
757
+ } catch (error) {
758
+ squashError(error);
759
759
  }
760
760
  }
761
761
  }
@@ -867,7 +867,8 @@ export class ChangeStream<
867
867
  private _closeEmitterModeWithError(error: AnyError): void {
868
868
  this.emit(ChangeStream.ERROR, error);
869
869
 
870
- this.close().catch(() => null);
870
+ // eslint-disable-next-line github/no-then
871
+ this.close().then(undefined, squashError);
871
872
  }
872
873
 
873
874
  /** @internal */
@@ -931,13 +932,15 @@ export class ChangeStream<
931
932
 
932
933
  if (isResumableError(changeStreamError, this.cursor.maxWireVersion)) {
933
934
  this._endStream();
934
- this.cursor.close().catch(() => null);
935
+ // eslint-disable-next-line github/no-then
936
+ this.cursor.close().then(undefined, squashError);
935
937
 
936
938
  const topology = getTopology(this.parent);
937
939
  topology
938
940
  .selectServer(this.cursor.readPreference, {
939
941
  operationName: 'reconnect topology in change stream'
940
942
  })
943
+ // eslint-disable-next-line github/no-then
941
944
  .then(
942
945
  () => {
943
946
  this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
@@ -959,13 +962,17 @@ export class ChangeStream<
959
962
  if (!isResumableError(changeStreamError, this.cursor.maxWireVersion)) {
960
963
  try {
961
964
  await this.close();
962
- } catch {
963
- // ignore errors from close
965
+ } catch (error) {
966
+ squashError(error);
964
967
  }
965
968
  throw changeStreamError;
966
969
  }
967
970
 
968
- await this.cursor.close().catch(() => null);
971
+ try {
972
+ await this.cursor.close();
973
+ } catch (error) {
974
+ squashError(error);
975
+ }
969
976
  const topology = getTopology(this.parent);
970
977
  try {
971
978
  await topology.selectServer(this.cursor.readPreference, {
@@ -467,7 +467,7 @@ export class AutoEncrypter {
467
467
  proxyOptions: this._proxyOptions,
468
468
  tlsOptions: this._tlsOptions
469
469
  });
470
- return stateMachine.execute<Document>(this, context);
470
+ return await stateMachine.execute<Document>(this, context);
471
471
  }
472
472
 
473
473
  /**
@@ -502,7 +502,7 @@ export class AutoEncrypter {
502
502
  * the original ones.
503
503
  */
504
504
  async askForKMSCredentials(): Promise<KMSProviders> {
505
- return refreshKMSCredentials(this._kmsProviders);
505
+ return await refreshKMSCredentials(this._kmsProviders);
506
506
  }
507
507
 
508
508
  /**
@@ -315,7 +315,7 @@ export class ClientEncryption {
315
315
  this._keyVaultNamespace
316
316
  );
317
317
 
318
- return this._keyVaultClient
318
+ return await this._keyVaultClient
319
319
  .db(dbName)
320
320
  .collection<DataKey>(collectionName)
321
321
  .deleteOne({ _id }, { writeConcern: { w: 'majority' } });
@@ -364,7 +364,7 @@ export class ClientEncryption {
364
364
  this._keyVaultNamespace
365
365
  );
366
366
 
367
- return this._keyVaultClient
367
+ return await this._keyVaultClient
368
368
  .db(dbName)
369
369
  .collection<DataKey>(collectionName)
370
370
  .findOne({ _id }, { readConcern: { level: 'majority' } });
@@ -391,7 +391,7 @@ export class ClientEncryption {
391
391
  this._keyVaultNamespace
392
392
  );
393
393
 
394
- return this._keyVaultClient
394
+ return await this._keyVaultClient
395
395
  .db(dbName)
396
396
  .collection<DataKey>(collectionName)
397
397
  .findOne({ keyAltNames: keyAltName }, { readConcern: { level: 'majority' } });
@@ -589,7 +589,7 @@ export class ClientEncryption {
589
589
  * ```
590
590
  */
591
591
  async encrypt(value: unknown, options: ClientEncryptionEncryptOptions): Promise<Binary> {
592
- return this._encrypt(value, false, options);
592
+ return await this._encrypt(value, false, options);
593
593
  }
594
594
 
595
595
  /**
@@ -614,7 +614,7 @@ export class ClientEncryption {
614
614
  expression: Document,
615
615
  options: ClientEncryptionEncryptOptions
616
616
  ): Promise<Binary> {
617
- return this._encrypt(expression, true, options);
617
+ return await this._encrypt(expression, true, options);
618
618
  }
619
619
 
620
620
  /**
@@ -654,7 +654,7 @@ export class ClientEncryption {
654
654
  * the original ones.
655
655
  */
656
656
  async askForKMSCredentials(): Promise<KMSProviders> {
657
- return refreshKMSCredentials(this._kmsProviders);
657
+ return await refreshKMSCredentials(this._kmsProviders);
658
658
  }
659
659
 
660
660
  static get libmongocryptVersion() {
@@ -148,13 +148,15 @@ export async function fetchAzureKMSToken(
148
148
  options: AzureKMSRequestOptions = {}
149
149
  ): Promise<AzureTokenCacheEntry> {
150
150
  const { headers, url } = prepareRequest(options);
151
- const response = await get(url, { headers }).catch(error => {
151
+ try {
152
+ const response = await get(url, { headers });
153
+ return await parseResponse(response);
154
+ } catch (error) {
152
155
  if (error instanceof MongoCryptKMSRequestNetworkTimeoutError) {
153
156
  throw new MongoCryptAzureKMSRequestError(`[Azure KMS] ${error.message}`);
154
157
  }
155
158
  throw error;
156
- });
157
- return parseResponse(response);
159
+ }
158
160
  }
159
161
 
160
162
  /**
@@ -139,7 +139,9 @@ export class LegacyAWSTemporaryCredentialProvider extends AWSTemporaryCredential
139
139
  // If the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
140
140
  // is set then drivers MUST assume that it was set by an AWS ECS agent
141
141
  if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
142
- return request(`${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`);
142
+ return await request(
143
+ `${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`
144
+ );
143
145
  }
144
146
 
145
147
  // Otherwise assume we are on an EC2 instance
@@ -30,10 +30,10 @@ async function externalCommand(
30
30
  connection: Connection,
31
31
  command: ReturnType<typeof saslStart> | ReturnType<typeof saslContinue>
32
32
  ): Promise<{ payload: string; conversationId: any }> {
33
- return connection.command(ns('$external.$cmd'), command, undefined) as Promise<{
33
+ return await (connection.command(ns('$external.$cmd'), command, undefined) as Promise<{
34
34
  payload: string;
35
35
  conversationId: any;
36
- }>;
36
+ }>);
37
37
  }
38
38
 
39
39
  let krb: typeof Kerberos;
@@ -104,7 +104,7 @@ async function makeKerberosClient(authContext: AuthContext): Promise<KerberosCli
104
104
  spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
105
105
  }
106
106
 
107
- return initializeClient(spn, initOptions);
107
+ return await initializeClient(spn, initOptions);
108
108
  }
109
109
 
110
110
  function saslStart(payload: string) {
@@ -138,14 +138,14 @@ async function negotiate(
138
138
  throw error;
139
139
  }
140
140
  // Adjust number of retries and call step again
141
- return negotiate(client, retries - 1, payload);
141
+ return await negotiate(client, retries - 1, payload);
142
142
  }
143
143
  }
144
144
 
145
145
  async function finalize(client: KerberosClient, user: string, payload: string): Promise<string> {
146
146
  // GSS Client Unwrap
147
147
  const response = await client.unwrap(payload);
148
- return client.wrap(response || '', { user });
148
+ return await client.wrap(response || '', { user });
149
149
  }
150
150
 
151
151
  export async function performGSSAPICanonicalizeHostName(
@@ -174,12 +174,12 @@ export async function performGSSAPICanonicalizeHostName(
174
174
  // This can error as ptr records may not exist for all ips. In this case
175
175
  // fallback to a cname lookup as dns.lookup() does not return the
176
176
  // cname.
177
- return resolveCname(host);
177
+ return await resolveCname(host);
178
178
  }
179
179
  } else {
180
180
  // The case for forward is just to resolve the cname as dns.lookup()
181
181
  // will not return it.
182
- return resolveCname(host);
182
+ return await resolveCname(host);
183
183
  }
184
184
  }
185
185
 
@@ -24,6 +24,6 @@ export class AwsServiceWorkflow extends ServiceWorkflow {
24
24
  if (!tokenFile) {
25
25
  throw new MongoAWSError(TOKEN_MISSING_ERROR);
26
26
  }
27
- return fs.promises.readFile(tokenFile, 'utf8');
27
+ return await fs.promises.readFile(tokenFile, 'utf8');
28
28
  }
29
29
  }
@@ -87,8 +87,9 @@ function withLock(callback: OIDCRequestFunction | OIDCRefreshFunction) {
87
87
  let lock: Promise<any> = Promise.resolve();
88
88
  return async (info: IdPServerInfo, context: OIDCCallbackContext): Promise<IdPServerResponse> => {
89
89
  await lock;
90
+ // eslint-disable-next-line github/no-then
90
91
  lock = lock.then(() => callback(info, context));
91
- return lock;
92
+ return await lock;
92
93
  };
93
94
  }
94
95
 
@@ -18,7 +18,7 @@ export abstract class ServiceWorkflow implements Workflow {
18
18
  async execute(connection: Connection, credentials: MongoCredentials): Promise<Document> {
19
19
  const token = await this.getToken(credentials);
20
20
  const command = commandDocument(token);
21
- return connection.command(ns(credentials.source), command, undefined);
21
+ return await connection.command(ns(credentials.source), command, undefined);
22
22
  }
23
23
 
24
24
  /**
@@ -51,13 +51,13 @@ class ScramSHA extends AuthProvider {
51
51
  override async auth(authContext: AuthContext) {
52
52
  const { reauthenticating, response } = authContext;
53
53
  if (response?.speculativeAuthenticate && !reauthenticating) {
54
- return continueScramConversation(
54
+ return await continueScramConversation(
55
55
  this.cryptoMethod,
56
56
  response.speculativeAuthenticate,
57
57
  authContext
58
58
  );
59
59
  }
60
- return executeScram(this.cryptoMethod, authContext);
60
+ return await executeScram(this.cryptoMethod, authContext);
61
61
  }
62
62
  }
63
63
 
@@ -226,13 +226,13 @@ export async function prepareHandshakeDocument(
226
226
  `No AuthProvider for ${AuthMechanism.MONGODB_SCRAM_SHA256} defined.`
227
227
  );
228
228
  }
229
- return provider.prepare(handshakeDoc, authContext);
229
+ return await provider.prepare(handshakeDoc, authContext);
230
230
  }
231
231
  const provider = authContext.options.authProviders.getOrCreateProvider(credentials.mechanism);
232
232
  if (!provider) {
233
233
  throw new MongoInvalidArgumentError(`No AuthProvider for ${credentials.mechanism} defined.`);
234
234
  }
235
- return provider.prepare(handshakeDoc, authContext);
235
+ return await provider.prepare(handshakeDoc, authContext);
236
236
  }
237
237
  return handshakeDoc;
238
238
  }
@@ -325,7 +325,7 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
325
325
 
326
326
  if (options.proxyHost != null) {
327
327
  // Currently, only Socks5 is supported.
328
- return makeSocks5Connection({
328
+ return await makeSocks5Connection({
329
329
  ...options,
330
330
  connectTimeoutMS // Should always be present for Socks5
331
331
  });
@@ -38,6 +38,7 @@ import {
38
38
  type MongoDBNamespace,
39
39
  now,
40
40
  once,
41
+ squashError,
41
42
  uuidV4
42
43
  } from '../utils';
43
44
  import type { WriteConcern } from '../write_concern';
@@ -324,7 +325,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
324
325
 
325
326
  this.socket.destroy();
326
327
  this.error = error;
327
- this.dataEvents?.throw(error).then(undefined, () => null); // squash unhandled rejection
328
+ // eslint-disable-next-line github/no-then
329
+ this.dataEvents?.throw(error).then(undefined, squashError);
328
330
  this.closed = true;
329
331
  this.emit(Connection.CLOSE);
330
332
  }
@@ -579,7 +581,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
579
581
  }
580
582
  throw new MongoUnexpectedServerResponseError('Server ended moreToCome unexpectedly');
581
583
  };
582
- exhaustLoop().catch(replyListener);
584
+ // eslint-disable-next-line github/no-then
585
+ exhaustLoop().then(undefined, replyListener);
583
586
  }
584
587
 
585
588
  private throwIfAborted() {
@@ -607,7 +610,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
607
610
  const buffer = Buffer.concat(await finalCommand.toBin());
608
611
 
609
612
  if (this.socket.write(buffer)) return;
610
- return once(this.socket, 'drain');
613
+ return await once(this.socket, 'drain');
611
614
  }
612
615
 
613
616
  /**
@@ -698,7 +701,7 @@ export class CryptoConnection extends Connection {
698
701
  const serverWireVersion = maxWireVersion(this);
699
702
  if (serverWireVersion === 0) {
700
703
  // This means the initial handshake hasn't happened yet
701
- return super.command(ns, cmd, options);
704
+ return await super.command(ns, cmd, options);
702
705
  }
703
706
 
704
707
  if (serverWireVersion < 8) {
@@ -734,6 +737,6 @@ export class CryptoConnection extends Connection {
734
737
 
735
738
  const response = await super.command(ns, encrypted, options);
736
739
 
737
- return autoEncrypter.decrypt(response, options);
740
+ return await autoEncrypter.decrypt(response, options);
738
741
  }
739
742
  }
@@ -394,7 +394,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
394
394
  this[kWaitQueue].push(waitQueueMember);
395
395
  process.nextTick(() => this.processWaitQueue());
396
396
 
397
- return promise;
397
+ return await promise;
398
398
  }
399
399
 
400
400
  /**
@@ -631,6 +631,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
631
631
  new ConnectionCreatedEvent(this, { id: connectOptions.id })
632
632
  );
633
633
 
634
+ // eslint-disable-next-line github/no-then
634
635
  connect(connectOptions).then(
635
636
  connection => {
636
637
  // The pool might have closed since we started trying to create a connection
@@ -1,10 +1,10 @@
1
- import { promises as fs } from 'fs';
2
1
  import * as os from 'os';
3
2
  import * as process from 'process';
4
3
 
5
4
  import { BSON, type Document, Int32 } from '../../bson';
6
5
  import { MongoInvalidArgumentError } from '../../error';
7
6
  import type { MongoOptions } from '../../mongo_client';
7
+ import { fileIsAccessible } from '../../utils';
8
8
 
9
9
  // eslint-disable-next-line @typescript-eslint/no-var-requires
10
10
  const NODE_DRIVER_VERSION = require('../../../package.json').version;
@@ -160,10 +160,7 @@ let dockerPromise: Promise<boolean>;
160
160
  /** @internal */
161
161
  async function getContainerMetadata() {
162
162
  const containerMetadata: Record<string, any> = {};
163
- dockerPromise ??= fs.access('/.dockerenv').then(
164
- () => true,
165
- () => false
166
- );
163
+ dockerPromise ??= fileIsAccessible('/.dockerenv');
167
164
  const isDocker = await dockerPromise;
168
165
 
169
166
  const { KUBERNETES_SERVICE_HOST = '' } = process.env;
@@ -67,20 +67,20 @@ export async function compress(
67
67
  switch (options.agreedCompressor) {
68
68
  case 'snappy': {
69
69
  Snappy ??= loadSnappy();
70
- return Snappy.compress(dataToBeCompressed);
70
+ return await Snappy.compress(dataToBeCompressed);
71
71
  }
72
72
  case 'zstd': {
73
73
  loadZstd();
74
74
  if ('kModuleError' in zstd) {
75
75
  throw zstd['kModuleError'];
76
76
  }
77
- return zstd.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL);
77
+ return await zstd.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL);
78
78
  }
79
79
  case 'zlib': {
80
80
  if (options.zlibCompressionLevel) {
81
81
  zlibOptions.level = options.zlibCompressionLevel;
82
82
  }
83
- return zlibDeflate(dataToBeCompressed, zlibOptions);
83
+ return await zlibDeflate(dataToBeCompressed, zlibOptions);
84
84
  }
85
85
  default: {
86
86
  throw new MongoInvalidArgumentError(
@@ -106,17 +106,17 @@ export async function decompress(compressorID: number, compressedData: Buffer):
106
106
  switch (compressorID) {
107
107
  case Compressor.snappy: {
108
108
  Snappy ??= loadSnappy();
109
- return Snappy.uncompress(compressedData, { asBuffer: true });
109
+ return await Snappy.uncompress(compressedData, { asBuffer: true });
110
110
  }
111
111
  case Compressor.zstd: {
112
112
  loadZstd();
113
113
  if ('kModuleError' in zstd) {
114
114
  throw zstd['kModuleError'];
115
115
  }
116
- return zstd.decompress(compressedData);
116
+ return await zstd.decompress(compressedData);
117
117
  }
118
118
  case Compressor.zlib: {
119
- return zlibInflate(compressedData);
119
+ return await zlibInflate(compressedData);
120
120
  }
121
121
  default: {
122
122
  return compressedData;