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.
- package/lib/admin.js +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +2 -1
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +21 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +6 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/connect.js +3 -3
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +7 -5
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +2 -1
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +6 -6
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +207 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/collection.js +25 -25
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +44 -18
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +16 -11
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +1 -1
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +11 -11
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +10 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/mongo_client.js +10 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +13 -3
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +2 -2
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/monitor.js +4 -0
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +6 -4
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +28 -2
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +7 -7
- package/package.json +3 -2
- package/src/admin.ts +9 -9
- package/src/bson.ts +13 -0
- package/src/bulk/common.ts +2 -1
- package/src/change_stream.ts +28 -21
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +3 -1
- package/src/cmap/auth/gssapi.ts +7 -7
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/connect.ts +3 -3
- package/src/cmap/connection.ts +8 -5
- package/src/cmap/connection_pool.ts +2 -1
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +6 -6
- package/src/cmap/wire_protocol/on_demand/document.ts +322 -0
- package/src/collection.ts +25 -25
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +40 -19
- package/src/cursor/aggregation_cursor.ts +1 -1
- package/src/cursor/find_cursor.ts +16 -12
- package/src/cursor/run_command_cursor.ts +1 -1
- package/src/db.ts +14 -11
- package/src/encrypter.ts +9 -4
- package/src/gridfs/download.ts +17 -31
- package/src/gridfs/upload.ts +9 -8
- package/src/mongo_client.ts +17 -12
- package/src/mongo_logger.ts +3 -0
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +12 -4
- package/src/operations/find.ts +1 -1
- package/src/operations/get_more.ts +1 -1
- package/src/operations/indexes.ts +2 -2
- package/src/operations/insert.ts +1 -1
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/run_command.ts +6 -4
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/monitor.ts +4 -0
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +1 -1
- package/src/sessions.ts +7 -4
- package/src/utils.ts +26 -1
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from '../sdam/server_selection';
|
|
27
27
|
import type { Topology } from '../sdam/topology';
|
|
28
28
|
import type { ClientSession } from '../sessions';
|
|
29
|
-
import { supportsRetryableWrites } from '../utils';
|
|
29
|
+
import { squashError, supportsRetryableWrites } from '../utils';
|
|
30
30
|
import { AbstractOperation, Aspect } from './operation';
|
|
31
31
|
|
|
32
32
|
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
|
|
@@ -146,7 +146,7 @@ export async function executeOperation<
|
|
|
146
146
|
|
|
147
147
|
if (session == null) {
|
|
148
148
|
// No session also means it is not retryable, early exit
|
|
149
|
-
return operation.execute(server, undefined);
|
|
149
|
+
return await operation.execute(server, undefined);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
if (!operation.hasAspect(Aspect.RETRYABLE)) {
|
|
@@ -155,7 +155,11 @@ export async function executeOperation<
|
|
|
155
155
|
return await operation.execute(server, session);
|
|
156
156
|
} finally {
|
|
157
157
|
if (session?.owner != null && session.owner === owner) {
|
|
158
|
-
|
|
158
|
+
try {
|
|
159
|
+
await session.endSession();
|
|
160
|
+
} catch (error) {
|
|
161
|
+
squashError(error);
|
|
162
|
+
}
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
165
|
}
|
|
@@ -191,7 +195,11 @@ export async function executeOperation<
|
|
|
191
195
|
throw operationError;
|
|
192
196
|
} finally {
|
|
193
197
|
if (session?.owner != null && session.owner === owner) {
|
|
194
|
-
|
|
198
|
+
try {
|
|
199
|
+
await session.endSession();
|
|
200
|
+
} catch (error) {
|
|
201
|
+
squashError(error);
|
|
202
|
+
}
|
|
195
203
|
}
|
|
196
204
|
}
|
|
197
205
|
}
|
package/src/operations/find.ts
CHANGED
|
@@ -111,7 +111,7 @@ export class FindOperation extends CommandOperation<Document> {
|
|
|
111
111
|
findCommand = decorateWithExplain(findCommand, this.explain);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
return server.command(this.ns, findCommand, {
|
|
114
|
+
return await server.command(this.ns, findCommand, {
|
|
115
115
|
...this.options,
|
|
116
116
|
...this.bsonOptions,
|
|
117
117
|
documentsReturnedIn: 'firstBatch',
|
|
@@ -333,7 +333,7 @@ export class DropIndexOperation extends CommandOperation<Document> {
|
|
|
333
333
|
|
|
334
334
|
override async execute(server: Server, session: ClientSession | undefined): Promise<Document> {
|
|
335
335
|
const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
|
|
336
|
-
return super.executeCommand(server, session, cmd);
|
|
336
|
+
return await super.executeCommand(server, session, cmd);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -377,7 +377,7 @@ export class ListIndexesOperation extends CommandOperation<Document> {
|
|
|
377
377
|
command.comment = this.options.comment;
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
return super.executeCommand(server, session, command);
|
|
380
|
+
return await super.executeCommand(server, session, command);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
package/src/operations/insert.ts
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
|
|
@@ -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
|
-
|
|
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
|
-
})
|
|
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
|
-
|
|
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
|
-
})
|
|
62
|
+
});
|
|
63
|
+
return res;
|
|
62
64
|
}
|
|
63
65
|
}
|
package/src/operations/stats.ts
CHANGED
package/src/operations/update.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
package/src/sdam/monitor.ts
CHANGED
|
@@ -351,6 +351,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
|
|
|
351
351
|
awaited = false;
|
|
352
352
|
connection
|
|
353
353
|
.command(ns('admin.$cmd'), cmd, options)
|
|
354
|
+
// eslint-disable-next-line github/no-then
|
|
354
355
|
.then(onHeartbeatSucceeded, onHeartbeatFailed);
|
|
355
356
|
|
|
356
357
|
return;
|
|
@@ -369,6 +370,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
|
|
|
369
370
|
connection.destroy();
|
|
370
371
|
throw error;
|
|
371
372
|
}
|
|
373
|
+
// eslint-disable-next-line github/no-then
|
|
372
374
|
})().then(
|
|
373
375
|
connection => {
|
|
374
376
|
if (isInCloseState(monitor)) {
|
|
@@ -512,6 +514,7 @@ function measureRoundTripTime(rttPinger: RTTPinger, options: RTTPingerOptions) {
|
|
|
512
514
|
|
|
513
515
|
const connection = rttPinger.connection;
|
|
514
516
|
if (connection == null) {
|
|
517
|
+
// eslint-disable-next-line github/no-then
|
|
515
518
|
connect(options).then(
|
|
516
519
|
connection => {
|
|
517
520
|
measureAndReschedule(connection);
|
|
@@ -526,6 +529,7 @@ function measureRoundTripTime(rttPinger: RTTPinger, options: RTTPingerOptions) {
|
|
|
526
529
|
|
|
527
530
|
const commandName =
|
|
528
531
|
connection.serverApi?.version || connection.helloOk ? 'hello' : LEGACY_HELLO_COMMAND;
|
|
532
|
+
// eslint-disable-next-line github/no-then
|
|
529
533
|
connection.command(ns('admin.$cmd'), { [commandName]: 1 }, undefined).then(
|
|
530
534
|
() => measureAndReschedule(),
|
|
531
535
|
() => {
|
package/src/sdam/srv_polling.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { clearTimeout, setTimeout } from 'timers';
|
|
|
3
3
|
|
|
4
4
|
import { MongoRuntimeError } from '../error';
|
|
5
5
|
import { TypedEventEmitter } from '../mongo_types';
|
|
6
|
-
import { HostAddress, matchesParentDomain } from '../utils';
|
|
6
|
+
import { HostAddress, matchesParentDomain, squashError } from '../utils';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
@@ -95,7 +95,8 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
this._timeout = setTimeout(() => {
|
|
98
|
-
|
|
98
|
+
// eslint-disable-next-line github/no-then
|
|
99
|
+
this._poll().then(undefined, squashError);
|
|
99
100
|
}, this.intervalMS);
|
|
100
101
|
}
|
|
101
102
|
|
package/src/sdam/topology.ts
CHANGED
|
@@ -623,7 +623,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
623
623
|
this[kWaitQueue].push(waitQueueMember);
|
|
624
624
|
processWaitQueue(this);
|
|
625
625
|
|
|
626
|
-
return serverPromise;
|
|
626
|
+
return await serverPromise;
|
|
627
627
|
}
|
|
628
628
|
/**
|
|
629
629
|
* Update the internal TopologyDescription with a ServerDescription
|
package/src/sessions.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable github/no-then */
|
|
1
2
|
import { promisify } from 'util';
|
|
2
3
|
|
|
3
4
|
import { Binary, type Document, Long, type Timestamp } from './bson';
|
|
@@ -44,6 +45,7 @@ import {
|
|
|
44
45
|
List,
|
|
45
46
|
maxWireVersion,
|
|
46
47
|
now,
|
|
48
|
+
squashError,
|
|
47
49
|
uuidV4
|
|
48
50
|
} from './utils';
|
|
49
51
|
import { WriteConcern } from './write_concern';
|
|
@@ -274,8 +276,9 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
274
276
|
this.hasEnded = true;
|
|
275
277
|
this.emit('ended', this);
|
|
276
278
|
}
|
|
277
|
-
} catch {
|
|
279
|
+
} catch (error) {
|
|
278
280
|
// spec indicates that we should ignore all errors for `endSessions`
|
|
281
|
+
squashError(error);
|
|
279
282
|
} finally {
|
|
280
283
|
maybeClearPinnedConnection(this, { force: true, ...options });
|
|
281
284
|
}
|
|
@@ -415,14 +418,14 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
415
418
|
* Commits the currently active transaction in this session.
|
|
416
419
|
*/
|
|
417
420
|
async commitTransaction(): Promise<void> {
|
|
418
|
-
return endTransactionAsync(this, 'commitTransaction');
|
|
421
|
+
return await endTransactionAsync(this, 'commitTransaction');
|
|
419
422
|
}
|
|
420
423
|
|
|
421
424
|
/**
|
|
422
425
|
* Aborts the currently active transaction in this session.
|
|
423
426
|
*/
|
|
424
427
|
async abortTransaction(): Promise<void> {
|
|
425
|
-
return endTransactionAsync(this, 'abortTransaction');
|
|
428
|
+
return await endTransactionAsync(this, 'abortTransaction');
|
|
426
429
|
}
|
|
427
430
|
|
|
428
431
|
/**
|
|
@@ -464,7 +467,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
464
467
|
options?: TransactionOptions
|
|
465
468
|
): Promise<T> {
|
|
466
469
|
const startTime = now();
|
|
467
|
-
return attemptTransaction(this, startTime, fn, options);
|
|
470
|
+
return await attemptTransaction(this, startTime, fn, options);
|
|
468
471
|
}
|
|
469
472
|
}
|
|
470
473
|
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as crypto from 'crypto';
|
|
2
2
|
import type { SrvRecord } from 'dns';
|
|
3
3
|
import { type EventEmitter } from 'events';
|
|
4
|
+
import { promises as fs } from 'fs';
|
|
4
5
|
import * as http from 'http';
|
|
5
6
|
import { clearTimeout, setTimeout } from 'timers';
|
|
6
7
|
import * as url from 'url';
|
|
@@ -178,6 +179,7 @@ export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLik
|
|
|
178
179
|
value != null &&
|
|
179
180
|
typeof value === 'object' &&
|
|
180
181
|
'then' in value &&
|
|
182
|
+
// eslint-disable-next-line github/no-then
|
|
181
183
|
typeof value.then === 'function'
|
|
182
184
|
);
|
|
183
185
|
}
|
|
@@ -1156,7 +1158,7 @@ export async function request(
|
|
|
1156
1158
|
uri: string,
|
|
1157
1159
|
options: RequestOptions = {}
|
|
1158
1160
|
): Promise<string | Record<string, any>> {
|
|
1159
|
-
return new Promise<string | Record<string, any>>((resolve, reject) => {
|
|
1161
|
+
return await new Promise<string | Record<string, any>>((resolve, reject) => {
|
|
1160
1162
|
const requestOptions = {
|
|
1161
1163
|
method: 'GET',
|
|
1162
1164
|
timeout: 10000,
|
|
@@ -1259,6 +1261,20 @@ export function promiseWithResolvers<T>(): {
|
|
|
1259
1261
|
return { promise, resolve, reject } as const;
|
|
1260
1262
|
}
|
|
1261
1263
|
|
|
1264
|
+
/**
|
|
1265
|
+
* A noop function intended for use in preventing unhandled rejections.
|
|
1266
|
+
*
|
|
1267
|
+
* @example
|
|
1268
|
+
* ```js
|
|
1269
|
+
* const promise = myAsyncTask();
|
|
1270
|
+
* // eslint-disable-next-line github/no-then
|
|
1271
|
+
* promise.then(undefined, squashError);
|
|
1272
|
+
* ```
|
|
1273
|
+
*/
|
|
1274
|
+
export function squashError(_error: unknown) {
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1262
1278
|
export const randomBytes = promisify(crypto.randomBytes);
|
|
1263
1279
|
|
|
1264
1280
|
/**
|
|
@@ -1319,3 +1335,12 @@ export function maybeAddIdToDocuments(
|
|
|
1319
1335
|
};
|
|
1320
1336
|
return Array.isArray(docOrDocs) ? docOrDocs.map(transform) : transform(docOrDocs);
|
|
1321
1337
|
}
|
|
1338
|
+
|
|
1339
|
+
export async function fileIsAccessible(fileName: string, mode?: number) {
|
|
1340
|
+
try {
|
|
1341
|
+
await fs.access(fileName, mode);
|
|
1342
|
+
return true;
|
|
1343
|
+
} catch {
|
|
1344
|
+
return false;
|
|
1345
|
+
}
|
|
1346
|
+
}
|