mongodb 5.2.0 → 5.4.0
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 +18 -0
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +28 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +29 -2
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +5 -3
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/cache.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +83 -0
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +138 -112
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +4 -2
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +12 -56
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc.js +17 -13
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +6 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/connect.js +1 -0
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +12 -12
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +7 -3
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +28 -3
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +173 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +2 -2
- package/lib/cmap/wire_protocol/shared.js +2 -2
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +3 -0
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +48 -53
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +11 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +1 -0
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/db.js +18 -0
- package/lib/db.js.map +1 -1
- package/lib/mongo_client.js +16 -0
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +258 -27
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/find.js +0 -7
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -15
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/utils.js +48 -35
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +247 -47
- package/package.json +3 -3
- package/src/admin.ts +18 -0
- package/src/bulk/common.ts +28 -7
- package/src/change_stream.ts +1 -1
- package/src/cmap/auth/mongo_credentials.ts +35 -2
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +6 -3
- package/src/cmap/auth/mongodb_oidc/cache.ts +27 -0
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +107 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +208 -171
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +5 -3
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +17 -96
- package/src/cmap/auth/mongodb_oidc.ts +61 -37
- package/src/cmap/command_monitoring_events.ts +13 -1
- package/src/cmap/connect.ts +3 -1
- package/src/cmap/connection.ts +16 -13
- package/src/cmap/connection_pool.ts +14 -4
- package/src/cmap/connection_pool_events.ts +68 -6
- package/src/cmap/handshake/client_metadata.ts +272 -0
- package/src/cmap/wire_protocol/constants.ts +2 -2
- package/src/cmap/wire_protocol/shared.ts +2 -3
- package/src/collection.ts +6 -3
- package/src/connection_string.ts +55 -55
- package/src/constants.ts +11 -0
- package/src/cursor/abstract_cursor.ts +1 -0
- package/src/db.ts +18 -0
- package/src/index.ts +24 -6
- package/src/mongo_client.ts +50 -6
- package/src/mongo_logger.ts +363 -44
- package/src/operations/add_user.ts +8 -2
- package/src/operations/find.ts +0 -10
- package/src/operations/run_command.ts +40 -3
- package/src/operations/stats.ts +11 -2
- package/src/operations/update.ts +8 -4
- package/src/sdam/srv_polling.ts +1 -16
- package/src/sdam/topology.ts +1 -3
- package/src/utils.ts +54 -73
- package/lib/cmap/auth/mongodb_oidc/workflow.js +0 -3
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +0 -1
- package/src/cmap/auth/mongodb_oidc/workflow.ts +0 -21
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import type { Document } from 'bson';
|
|
2
|
+
|
|
1
3
|
import { MongoInvalidArgumentError, MongoMissingCredentialsError } from '../../error';
|
|
2
4
|
import type { HandshakeDocument } from '../connect';
|
|
3
|
-
import
|
|
5
|
+
import type { Connection } from '../connection';
|
|
6
|
+
import { AuthContext, AuthProvider } from './auth_provider';
|
|
4
7
|
import type { MongoCredentials } from './mongo_credentials';
|
|
5
8
|
import { AwsServiceWorkflow } from './mongodb_oidc/aws_service_workflow';
|
|
6
9
|
import { CallbackWorkflow } from './mongodb_oidc/callback_workflow';
|
|
7
|
-
|
|
10
|
+
|
|
11
|
+
/** Error when credentials are missing. */
|
|
12
|
+
const MISSING_CREDENTIALS_ERROR = 'AuthContext must provide credentials.';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* @public
|
|
11
16
|
* @experimental
|
|
12
17
|
*/
|
|
13
|
-
export interface
|
|
14
|
-
|
|
15
|
-
tokenEndpoint?: string;
|
|
16
|
-
deviceAuthorizationEndpoint?: string;
|
|
18
|
+
export interface IdPServerInfo {
|
|
19
|
+
issuer: string;
|
|
17
20
|
clientId: string;
|
|
18
|
-
clientSecret?: string;
|
|
19
21
|
requestScopes?: string[];
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -23,35 +25,61 @@ export interface OIDCMechanismServerStep1 {
|
|
|
23
25
|
* @public
|
|
24
26
|
* @experimental
|
|
25
27
|
*/
|
|
26
|
-
export interface
|
|
28
|
+
export interface IdPServerResponse {
|
|
27
29
|
accessToken: string;
|
|
28
30
|
expiresInSeconds?: number;
|
|
29
31
|
refreshToken?: string;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
* @experimental
|
|
37
|
+
*/
|
|
38
|
+
export interface OIDCCallbackContext {
|
|
39
|
+
refreshToken?: string;
|
|
40
|
+
timeoutSeconds?: number;
|
|
41
|
+
timeoutContext?: AbortSignal;
|
|
42
|
+
version: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
/**
|
|
33
46
|
* @public
|
|
34
47
|
* @experimental
|
|
35
48
|
*/
|
|
36
49
|
export type OIDCRequestFunction = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
) => Promise<OIDCRequestTokenResult>;
|
|
50
|
+
info: IdPServerInfo,
|
|
51
|
+
context: OIDCCallbackContext
|
|
52
|
+
) => Promise<IdPServerResponse>;
|
|
41
53
|
|
|
42
54
|
/**
|
|
43
55
|
* @public
|
|
44
56
|
* @experimental
|
|
45
57
|
*/
|
|
46
58
|
export type OIDCRefreshFunction = (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
timeout: AbortSignal | number
|
|
51
|
-
) => Promise<OIDCRequestTokenResult>;
|
|
59
|
+
info: IdPServerInfo,
|
|
60
|
+
context: OIDCCallbackContext
|
|
61
|
+
) => Promise<IdPServerResponse>;
|
|
52
62
|
|
|
53
63
|
type ProviderName = 'aws' | 'callback';
|
|
54
64
|
|
|
65
|
+
export interface Workflow {
|
|
66
|
+
/**
|
|
67
|
+
* All device workflows must implement this method in order to get the access
|
|
68
|
+
* token and then call authenticate with it.
|
|
69
|
+
*/
|
|
70
|
+
execute(
|
|
71
|
+
connection: Connection,
|
|
72
|
+
credentials: MongoCredentials,
|
|
73
|
+
reauthenticating: boolean,
|
|
74
|
+
response?: Document
|
|
75
|
+
): Promise<Document>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get the document to add for speculative authentication.
|
|
79
|
+
*/
|
|
80
|
+
speculativeAuth(credentials: MongoCredentials): Promise<Document>;
|
|
81
|
+
}
|
|
82
|
+
|
|
55
83
|
/** @internal */
|
|
56
84
|
export const OIDC_WORKFLOWS: Map<ProviderName, Workflow> = new Map();
|
|
57
85
|
OIDC_WORKFLOWS.set('callback', new CallbackWorkflow());
|
|
@@ -73,19 +101,10 @@ export class MongoDBOIDC extends AuthProvider {
|
|
|
73
101
|
* Authenticate using OIDC
|
|
74
102
|
*/
|
|
75
103
|
override async auth(authContext: AuthContext): Promise<void> {
|
|
76
|
-
const { connection,
|
|
77
|
-
|
|
78
|
-
if (response?.speculativeAuthenticate) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!credentials) {
|
|
83
|
-
throw new MongoMissingCredentialsError('AuthContext must provide credentials.');
|
|
84
|
-
}
|
|
85
|
-
|
|
104
|
+
const { connection, reauthenticating, response } = authContext;
|
|
105
|
+
const credentials = getCredentials(authContext);
|
|
86
106
|
const workflow = getWorkflow(credentials);
|
|
87
|
-
|
|
88
|
-
await workflow.execute(connection, credentials, reauthenticating);
|
|
107
|
+
await workflow.execute(connection, credentials, reauthenticating, response);
|
|
89
108
|
}
|
|
90
109
|
|
|
91
110
|
/**
|
|
@@ -95,19 +114,24 @@ export class MongoDBOIDC extends AuthProvider {
|
|
|
95
114
|
handshakeDoc: HandshakeDocument,
|
|
96
115
|
authContext: AuthContext
|
|
97
116
|
): Promise<HandshakeDocument> {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
if (!credentials) {
|
|
101
|
-
throw new MongoMissingCredentialsError('AuthContext must provide credentials.');
|
|
102
|
-
}
|
|
103
|
-
|
|
117
|
+
const credentials = getCredentials(authContext);
|
|
104
118
|
const workflow = getWorkflow(credentials);
|
|
105
|
-
|
|
106
|
-
const result = await workflow.speculativeAuth();
|
|
119
|
+
const result = await workflow.speculativeAuth(credentials);
|
|
107
120
|
return { ...handshakeDoc, ...result };
|
|
108
121
|
}
|
|
109
122
|
}
|
|
110
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Get credentials from the auth context, throwing if they do not exist.
|
|
126
|
+
*/
|
|
127
|
+
function getCredentials(authContext: AuthContext): MongoCredentials {
|
|
128
|
+
const { credentials } = authContext;
|
|
129
|
+
if (!credentials) {
|
|
130
|
+
throw new MongoMissingCredentialsError(MISSING_CREDENTIALS_ERROR);
|
|
131
|
+
}
|
|
132
|
+
return credentials;
|
|
133
|
+
}
|
|
134
|
+
|
|
111
135
|
/**
|
|
112
136
|
* Gets either a device workflow or callback workflow.
|
|
113
137
|
*/
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Document, ObjectId } from '../bson';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
COMMAND_FAILED,
|
|
4
|
+
COMMAND_STARTED,
|
|
5
|
+
COMMAND_SUCCEEDED,
|
|
6
|
+
LEGACY_HELLO_COMMAND,
|
|
7
|
+
LEGACY_HELLO_COMMAND_CAMEL_CASE
|
|
8
|
+
} from '../constants';
|
|
3
9
|
import { calculateDurationInMs, deepCopy } from '../utils';
|
|
4
10
|
import { Msg, WriteProtocolMessageType } from './commands';
|
|
5
11
|
import type { Connection } from './connection';
|
|
@@ -18,6 +24,8 @@ export class CommandStartedEvent {
|
|
|
18
24
|
address: string;
|
|
19
25
|
connectionId?: string | number;
|
|
20
26
|
serviceId?: ObjectId;
|
|
27
|
+
/** @internal */
|
|
28
|
+
name = COMMAND_STARTED;
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* Create a started event
|
|
@@ -65,6 +73,8 @@ export class CommandSucceededEvent {
|
|
|
65
73
|
commandName: string;
|
|
66
74
|
reply: unknown;
|
|
67
75
|
serviceId?: ObjectId;
|
|
76
|
+
/** @internal */
|
|
77
|
+
name = COMMAND_SUCCEEDED;
|
|
68
78
|
|
|
69
79
|
/**
|
|
70
80
|
* Create a succeeded event
|
|
@@ -113,6 +123,8 @@ export class CommandFailedEvent {
|
|
|
113
123
|
commandName: string;
|
|
114
124
|
failure: Error;
|
|
115
125
|
serviceId?: ObjectId;
|
|
126
|
+
/** @internal */
|
|
127
|
+
name = COMMAND_FAILED;
|
|
116
128
|
|
|
117
129
|
/**
|
|
118
130
|
* Create a failure event
|
package/src/cmap/connect.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
MongoRuntimeError,
|
|
18
18
|
needsRetryableWriteLabel
|
|
19
19
|
} from '../error';
|
|
20
|
-
import { Callback,
|
|
20
|
+
import { Callback, HostAddress, ns } from '../utils';
|
|
21
21
|
import { AuthContext, AuthProvider } from './auth/auth_provider';
|
|
22
22
|
import { GSSAPI } from './auth/gssapi';
|
|
23
23
|
import { MongoCR } from './auth/mongocr';
|
|
@@ -28,6 +28,7 @@ import { AuthMechanism } from './auth/providers';
|
|
|
28
28
|
import { ScramSHA1, ScramSHA256 } from './auth/scram';
|
|
29
29
|
import { X509 } from './auth/x509';
|
|
30
30
|
import { CommandOptions, Connection, ConnectionOptions, CryptoConnection } from './connection';
|
|
31
|
+
import type { ClientMetadata } from './handshake/client_metadata';
|
|
31
32
|
import {
|
|
32
33
|
MAX_SUPPORTED_SERVER_VERSION,
|
|
33
34
|
MAX_SUPPORTED_WIRE_VERSION,
|
|
@@ -400,6 +401,7 @@ function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stre
|
|
|
400
401
|
|
|
401
402
|
if ('authorizationError' in socket) {
|
|
402
403
|
if (socket.authorizationError && rejectUnauthorized) {
|
|
404
|
+
// TODO(NODE-5192): wrap this with a MongoError subclass
|
|
403
405
|
return callback(socket.authorizationError);
|
|
404
406
|
}
|
|
405
407
|
}
|
package/src/cmap/connection.ts
CHANGED
|
@@ -29,7 +29,6 @@ import { applySession, ClientSession, updateSessionFromResponse } from '../sessi
|
|
|
29
29
|
import {
|
|
30
30
|
calculateDurationInMs,
|
|
31
31
|
Callback,
|
|
32
|
-
ClientMetadata,
|
|
33
32
|
HostAddress,
|
|
34
33
|
maxWireVersion,
|
|
35
34
|
MongoDBNamespace,
|
|
@@ -46,6 +45,7 @@ import {
|
|
|
46
45
|
} from './command_monitoring_events';
|
|
47
46
|
import { BinMsg, Msg, Query, Response, WriteProtocolMessageType } from './commands';
|
|
48
47
|
import type { Stream } from './connect';
|
|
48
|
+
import type { ClientMetadata } from './handshake/client_metadata';
|
|
49
49
|
import { MessageStream, OperationDescription } from './message_stream';
|
|
50
50
|
import { StreamDescription, StreamDescriptionOptions } from './stream_description';
|
|
51
51
|
import { getReadPreference, isSharded } from './wire_protocol/shared';
|
|
@@ -122,7 +122,9 @@ export interface ConnectionOptions
|
|
|
122
122
|
credentials?: MongoCredentials;
|
|
123
123
|
connectTimeoutMS?: number;
|
|
124
124
|
tls: boolean;
|
|
125
|
+
/** @deprecated - Will not be able to turn off in the future. */
|
|
125
126
|
keepAlive?: boolean;
|
|
127
|
+
/** @deprecated - Will not be configurable in the future. */
|
|
126
128
|
keepAliveInitialDelay?: number;
|
|
127
129
|
noDelay?: boolean;
|
|
128
130
|
socketTimeoutMS?: number;
|
|
@@ -482,22 +484,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
482
484
|
|
|
483
485
|
command(
|
|
484
486
|
ns: MongoDBNamespace,
|
|
485
|
-
|
|
487
|
+
command: Document,
|
|
486
488
|
options: CommandOptions | undefined,
|
|
487
489
|
callback: Callback
|
|
488
490
|
): void {
|
|
489
|
-
|
|
491
|
+
let cmd = { ...command };
|
|
492
|
+
|
|
493
|
+
const readPreference = getReadPreference(options);
|
|
490
494
|
const shouldUseOpMsg = supportsOpMsg(this);
|
|
491
495
|
const session = options?.session;
|
|
492
496
|
|
|
493
497
|
let clusterTime = this.clusterTime;
|
|
494
|
-
let finalCmd = Object.assign({}, cmd);
|
|
495
498
|
|
|
496
499
|
if (this.serverApi) {
|
|
497
500
|
const { version, strict, deprecationErrors } = this.serverApi;
|
|
498
|
-
|
|
499
|
-
if (strict != null)
|
|
500
|
-
if (deprecationErrors != null)
|
|
501
|
+
cmd.apiVersion = version;
|
|
502
|
+
if (strict != null) cmd.apiStrict = strict;
|
|
503
|
+
if (deprecationErrors != null) cmd.apiDeprecationErrors = deprecationErrors;
|
|
501
504
|
}
|
|
502
505
|
|
|
503
506
|
if (hasSessionSupport(this) && session) {
|
|
@@ -509,7 +512,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
509
512
|
clusterTime = session.clusterTime;
|
|
510
513
|
}
|
|
511
514
|
|
|
512
|
-
const err = applySession(session,
|
|
515
|
+
const err = applySession(session, cmd, options);
|
|
513
516
|
if (err) {
|
|
514
517
|
return callback(err);
|
|
515
518
|
}
|
|
@@ -519,12 +522,12 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
519
522
|
|
|
520
523
|
// if we have a known cluster time, gossip it
|
|
521
524
|
if (clusterTime) {
|
|
522
|
-
|
|
525
|
+
cmd.$clusterTime = clusterTime;
|
|
523
526
|
}
|
|
524
527
|
|
|
525
528
|
if (isSharded(this) && !shouldUseOpMsg && readPreference && readPreference.mode !== 'primary') {
|
|
526
|
-
|
|
527
|
-
$query:
|
|
529
|
+
cmd = {
|
|
530
|
+
$query: cmd,
|
|
528
531
|
$readPreference: readPreference.toJSON()
|
|
529
532
|
};
|
|
530
533
|
}
|
|
@@ -542,8 +545,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
542
545
|
|
|
543
546
|
const cmdNs = `${ns.db}.$cmd`;
|
|
544
547
|
const message = shouldUseOpMsg
|
|
545
|
-
? new Msg(cmdNs,
|
|
546
|
-
: new Query(cmdNs,
|
|
548
|
+
? new Msg(cmdNs, cmd, commandOptions)
|
|
549
|
+
: new Query(cmdNs, cmd, commandOptions);
|
|
547
550
|
|
|
548
551
|
try {
|
|
549
552
|
write(this, message, commandOptions, callback);
|
|
@@ -641,7 +641,10 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
643
|
|
|
644
|
-
private destroyConnection(
|
|
644
|
+
private destroyConnection(
|
|
645
|
+
connection: Connection,
|
|
646
|
+
reason: 'error' | 'idle' | 'stale' | 'poolClosed'
|
|
647
|
+
) {
|
|
645
648
|
this.emit(
|
|
646
649
|
ConnectionPool.CONNECTION_CLOSED,
|
|
647
650
|
new ConnectionClosedEvent(this, connection, reason)
|
|
@@ -701,7 +704,13 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
701
704
|
this[kPending]--;
|
|
702
705
|
this.emit(
|
|
703
706
|
ConnectionPool.CONNECTION_CLOSED,
|
|
704
|
-
new ConnectionClosedEvent(
|
|
707
|
+
new ConnectionClosedEvent(
|
|
708
|
+
this,
|
|
709
|
+
{ id: connectOptions.id, serviceId: undefined },
|
|
710
|
+
'error',
|
|
711
|
+
// TODO(NODE-5192): Remove this cast
|
|
712
|
+
err as MongoError
|
|
713
|
+
)
|
|
705
714
|
);
|
|
706
715
|
if (err instanceof MongoNetworkError || err instanceof MongoServerError) {
|
|
707
716
|
err.connectionGeneration = connectOptions.generation;
|
|
@@ -812,7 +821,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
812
821
|
const error = this.closed ? new PoolClosedError(this) : new PoolClearedError(this);
|
|
813
822
|
this.emit(
|
|
814
823
|
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
|
|
815
|
-
new ConnectionCheckOutFailedEvent(this, reason)
|
|
824
|
+
new ConnectionCheckOutFailedEvent(this, reason, error)
|
|
816
825
|
);
|
|
817
826
|
if (waitQueueMember.timer) {
|
|
818
827
|
clearTimeout(waitQueueMember.timer);
|
|
@@ -865,7 +874,8 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
865
874
|
if (err) {
|
|
866
875
|
this.emit(
|
|
867
876
|
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
|
|
868
|
-
|
|
877
|
+
// TODO(NODE-5192): Remove this cast
|
|
878
|
+
new ConnectionCheckOutFailedEvent(this, 'connectionError', err as MongoError)
|
|
869
879
|
);
|
|
870
880
|
} else if (connection) {
|
|
871
881
|
this[kCheckedOut].add(connection);
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { ObjectId } from '../bson';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CONNECTION_CHECK_OUT_FAILED,
|
|
4
|
+
CONNECTION_CHECK_OUT_STARTED,
|
|
5
|
+
CONNECTION_CHECKED_IN,
|
|
6
|
+
CONNECTION_CHECKED_OUT,
|
|
7
|
+
CONNECTION_CLOSED,
|
|
8
|
+
CONNECTION_CREATED,
|
|
9
|
+
CONNECTION_POOL_CLEARED,
|
|
10
|
+
CONNECTION_POOL_CLOSED,
|
|
11
|
+
CONNECTION_POOL_CREATED,
|
|
12
|
+
CONNECTION_POOL_READY,
|
|
13
|
+
CONNECTION_READY
|
|
14
|
+
} from '../constants';
|
|
15
|
+
import type { MongoError } from '../error';
|
|
3
16
|
import type { Connection } from './connection';
|
|
4
17
|
import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
|
|
5
18
|
|
|
@@ -8,11 +21,24 @@ import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
|
|
|
8
21
|
* @public
|
|
9
22
|
* @category Event
|
|
10
23
|
*/
|
|
11
|
-
export class ConnectionPoolMonitoringEvent {
|
|
24
|
+
export abstract class ConnectionPoolMonitoringEvent {
|
|
12
25
|
/** A timestamp when the event was created */
|
|
13
26
|
time: Date;
|
|
14
27
|
/** The address (host/port pair) of the pool */
|
|
15
28
|
address: string;
|
|
29
|
+
/** @internal */
|
|
30
|
+
abstract name:
|
|
31
|
+
| typeof CONNECTION_CHECK_OUT_FAILED
|
|
32
|
+
| typeof CONNECTION_CHECK_OUT_STARTED
|
|
33
|
+
| typeof CONNECTION_CHECKED_IN
|
|
34
|
+
| typeof CONNECTION_CHECKED_OUT
|
|
35
|
+
| typeof CONNECTION_CLOSED
|
|
36
|
+
| typeof CONNECTION_CREATED
|
|
37
|
+
| typeof CONNECTION_POOL_CLEARED
|
|
38
|
+
| typeof CONNECTION_POOL_CLOSED
|
|
39
|
+
| typeof CONNECTION_POOL_CREATED
|
|
40
|
+
| typeof CONNECTION_POOL_READY
|
|
41
|
+
| typeof CONNECTION_READY;
|
|
16
42
|
|
|
17
43
|
/** @internal */
|
|
18
44
|
constructor(pool: ConnectionPool) {
|
|
@@ -29,6 +55,8 @@ export class ConnectionPoolMonitoringEvent {
|
|
|
29
55
|
export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
30
56
|
/** The options used to create this connection pool */
|
|
31
57
|
options?: ConnectionPoolOptions;
|
|
58
|
+
/** @internal */
|
|
59
|
+
name = CONNECTION_POOL_CREATED;
|
|
32
60
|
|
|
33
61
|
/** @internal */
|
|
34
62
|
constructor(pool: ConnectionPool) {
|
|
@@ -43,6 +71,9 @@ export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
43
71
|
* @category Event
|
|
44
72
|
*/
|
|
45
73
|
export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
74
|
+
/** @internal */
|
|
75
|
+
name = CONNECTION_POOL_READY;
|
|
76
|
+
|
|
46
77
|
/** @internal */
|
|
47
78
|
constructor(pool: ConnectionPool) {
|
|
48
79
|
super(pool);
|
|
@@ -55,6 +86,9 @@ export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
|
55
86
|
* @category Event
|
|
56
87
|
*/
|
|
57
88
|
export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
89
|
+
/** @internal */
|
|
90
|
+
name = CONNECTION_POOL_CLOSED;
|
|
91
|
+
|
|
58
92
|
/** @internal */
|
|
59
93
|
constructor(pool: ConnectionPool) {
|
|
60
94
|
super(pool);
|
|
@@ -69,6 +103,8 @@ export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
69
103
|
export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
70
104
|
/** A monotonically increasing, per-pool id for the newly created connection */
|
|
71
105
|
connectionId: number | '<monitor>';
|
|
106
|
+
/** @internal */
|
|
107
|
+
name = CONNECTION_CREATED;
|
|
72
108
|
|
|
73
109
|
/** @internal */
|
|
74
110
|
constructor(pool: ConnectionPool, connection: { id: number | '<monitor>' }) {
|
|
@@ -85,6 +121,8 @@ export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
85
121
|
export class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
86
122
|
/** The id of the connection */
|
|
87
123
|
connectionId: number | '<monitor>';
|
|
124
|
+
/** @internal */
|
|
125
|
+
name = CONNECTION_READY;
|
|
88
126
|
|
|
89
127
|
/** @internal */
|
|
90
128
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -104,17 +142,23 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
104
142
|
/** The reason the connection was closed */
|
|
105
143
|
reason: string;
|
|
106
144
|
serviceId?: ObjectId;
|
|
145
|
+
/** @internal */
|
|
146
|
+
name = CONNECTION_CLOSED;
|
|
147
|
+
/** @internal */
|
|
148
|
+
error: MongoError | null;
|
|
107
149
|
|
|
108
150
|
/** @internal */
|
|
109
151
|
constructor(
|
|
110
152
|
pool: ConnectionPool,
|
|
111
153
|
connection: Pick<Connection, 'id' | 'serviceId'>,
|
|
112
|
-
reason:
|
|
154
|
+
reason: 'idle' | 'stale' | 'poolClosed' | 'error',
|
|
155
|
+
error?: MongoError
|
|
113
156
|
) {
|
|
114
157
|
super(pool);
|
|
115
158
|
this.connectionId = connection.id;
|
|
116
|
-
this.reason = reason
|
|
159
|
+
this.reason = reason;
|
|
117
160
|
this.serviceId = connection.serviceId;
|
|
161
|
+
this.error = error ?? null;
|
|
118
162
|
}
|
|
119
163
|
}
|
|
120
164
|
|
|
@@ -124,6 +168,9 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
124
168
|
* @category Event
|
|
125
169
|
*/
|
|
126
170
|
export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
|
|
171
|
+
/** @internal */
|
|
172
|
+
name = CONNECTION_CHECK_OUT_STARTED;
|
|
173
|
+
|
|
127
174
|
/** @internal */
|
|
128
175
|
constructor(pool: ConnectionPool) {
|
|
129
176
|
super(pool);
|
|
@@ -137,12 +184,21 @@ export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEven
|
|
|
137
184
|
*/
|
|
138
185
|
export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
|
|
139
186
|
/** The reason the attempt to check out failed */
|
|
140
|
-
reason:
|
|
187
|
+
reason: string;
|
|
188
|
+
/** @internal */
|
|
189
|
+
error?: MongoError;
|
|
190
|
+
/** @internal */
|
|
191
|
+
name = CONNECTION_CHECK_OUT_FAILED;
|
|
141
192
|
|
|
142
193
|
/** @internal */
|
|
143
|
-
constructor(
|
|
194
|
+
constructor(
|
|
195
|
+
pool: ConnectionPool,
|
|
196
|
+
reason: 'poolClosed' | 'timeout' | 'connectionError',
|
|
197
|
+
error?: MongoError
|
|
198
|
+
) {
|
|
144
199
|
super(pool);
|
|
145
200
|
this.reason = reason;
|
|
201
|
+
this.error = error;
|
|
146
202
|
}
|
|
147
203
|
}
|
|
148
204
|
|
|
@@ -154,6 +210,8 @@ export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent
|
|
|
154
210
|
export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
|
|
155
211
|
/** The id of the connection */
|
|
156
212
|
connectionId: number | '<monitor>';
|
|
213
|
+
/** @internal */
|
|
214
|
+
name = CONNECTION_CHECKED_OUT;
|
|
157
215
|
|
|
158
216
|
/** @internal */
|
|
159
217
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -170,6 +228,8 @@ export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
|
|
|
170
228
|
export class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
|
|
171
229
|
/** The id of the connection */
|
|
172
230
|
connectionId: number | '<monitor>';
|
|
231
|
+
/** @internal */
|
|
232
|
+
name = CONNECTION_CHECKED_IN;
|
|
173
233
|
|
|
174
234
|
/** @internal */
|
|
175
235
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -188,6 +248,8 @@ export class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
188
248
|
serviceId?: ObjectId;
|
|
189
249
|
|
|
190
250
|
interruptInUseConnections?: boolean;
|
|
251
|
+
/** @internal */
|
|
252
|
+
name = CONNECTION_POOL_CLEARED;
|
|
191
253
|
|
|
192
254
|
/** @internal */
|
|
193
255
|
constructor(
|