Skip to content

Commit 667b05e

Browse files
committed
chore: make event names consistent (present tense)
1 parent 73a09e6 commit 667b05e

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/common/connectionManager.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ export type AnyConnectionState =
6464
| ConnectionStateErrored;
6565

6666
export interface ConnectionManagerEvents {
67-
"connection-requested": [AnyConnectionState];
68-
"connection-succeeded": [ConnectionStateConnected];
69-
"connection-timed-out": [ConnectionStateErrored];
70-
"connection-closed": [ConnectionStateDisconnected];
71-
"connection-errored": [ConnectionStateErrored];
67+
"connection-request": [AnyConnectionState];
68+
"connection-success": [ConnectionStateConnected];
69+
"connection-time-out": [ConnectionStateErrored];
70+
"connection-close": [ConnectionStateDisconnected];
71+
"connection-error": [ConnectionStateErrored];
7272
}
7373

7474
export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
@@ -101,7 +101,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
101101
}
102102

103103
async connect(settings: ConnectionSettings): Promise<AnyConnectionState> {
104-
this.emit("connection-requested", this.state);
104+
this.emit("connection-request", this.state);
105105

106106
if (this.state.tag === "connected" || this.state.tag === "connecting") {
107107
await this.disconnect();
@@ -155,7 +155,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
155155
);
156156
} catch (error: unknown) {
157157
const errorReason = error instanceof Error ? error.message : `${error as string}`;
158-
this.changeState("connection-errored", {
158+
this.changeState("connection-error", {
159159
tag: "errored",
160160
errorReason,
161161
connectionStringAuthType,
@@ -169,7 +169,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
169169
if (connectionType.startsWith("oidc")) {
170170
void this.pingAndForget(serviceProvider);
171171

172-
return this.changeState("connection-requested", {
172+
return this.changeState("connection-request", {
173173
tag: "connecting",
174174
connectedAtlasCluster: settings.atlas,
175175
serviceProvider,
@@ -180,15 +180,15 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
180180

181181
await serviceProvider?.runCommand?.("admin", { hello: 1 });
182182

183-
return this.changeState("connection-succeeded", {
183+
return this.changeState("connection-success", {
184184
tag: "connected",
185185
connectedAtlasCluster: settings.atlas,
186186
serviceProvider,
187187
connectionStringAuthType: connectionType,
188188
});
189189
} catch (error: unknown) {
190190
const errorReason = error instanceof Error ? error.message : `${error as string}`;
191-
this.changeState("connection-errored", {
191+
this.changeState("connection-error", {
192192
tag: "errored",
193193
errorReason,
194194
connectionStringAuthType,
@@ -207,7 +207,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
207207
try {
208208
await this.state.serviceProvider?.close(true);
209209
} finally {
210-
this.changeState("connection-closed", {
210+
this.changeState("connection-close", {
211211
tag: "disconnected",
212212
});
213213
}
@@ -239,7 +239,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
239239

240240
private onOidcAuthSucceeded(): void {
241241
if (this.state.tag === "connecting" && this.state.connectionStringAuthType?.startsWith("oidc")) {
242-
this.changeState("connection-succeeded", { ...this.state, tag: "connected" });
242+
this.changeState("connection-success", { ...this.state, tag: "connected" });
243243
}
244244

245245
this.logger.info({
@@ -251,7 +251,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
251251

252252
private onOidcNotifyDeviceFlow(flowInfo: { verificationUrl: string; userCode: string }): void {
253253
if (this.state.tag === "connecting" && this.state.connectionStringAuthType?.startsWith("oidc")) {
254-
this.changeState("connection-requested", {
254+
this.changeState("connection-request", {
255255
...this.state,
256256
tag: "connecting",
257257
connectionStringAuthType: "oidc-device-flow",
@@ -325,7 +325,7 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
325325
message: String(error),
326326
});
327327
} finally {
328-
this.changeState("connection-errored", { tag: "errored", errorReason: String(error) });
328+
this.changeState("connection-error", { tag: "errored", errorReason: String(error) });
329329
}
330330
}
331331
}

src/common/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export class Session extends EventEmitter<SessionEvents> {
6767
this.apiClient = new ApiClient({ baseUrl: apiBaseUrl, credentials }, logger);
6868
this.exportsManager = exportsManager;
6969
this.connectionManager = connectionManager;
70-
this.connectionManager.on("connection-succeeded", () => this.emit("connect"));
71-
this.connectionManager.on("connection-timed-out", (error) => this.emit("connection-error", error));
72-
this.connectionManager.on("connection-closed", () => this.emit("disconnect"));
73-
this.connectionManager.on("connection-errored", (error) => this.emit("connection-error", error));
70+
this.connectionManager.on("connection-success", () => this.emit("connect"));
71+
this.connectionManager.on("connection-time-out", (error) => this.emit("connection-error", error));
72+
this.connectionManager.on("connection-close", () => this.emit("disconnect"));
73+
this.connectionManager.on("connection-error", (error) => this.emit("connection-error", error));
7474
}
7575

7676
setMcpClient(mcpClient: Implementation | undefined): void {

tests/integration/common/connectionManager.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ describeWithMongoDB("Connection Manager", (integration) => {
1919
await connectionManager().disconnect();
2020
// for testing, force disconnecting AND setting the connection to closed to reset the
2121
// state of the connection manager
22-
connectionManager().changeState("connection-closed", { tag: "disconnected" });
22+
connectionManager().changeState("connection-close", { tag: "disconnected" });
2323
});
2424

2525
describe("when successfully connected", () => {
2626
type ConnectionManagerSpies = {
27-
"connection-requested": (event: ConnectionManagerEvents["connection-requested"][0]) => void;
28-
"connection-succeeded": (event: ConnectionManagerEvents["connection-succeeded"][0]) => void;
29-
"connection-timed-out": (event: ConnectionManagerEvents["connection-timed-out"][0]) => void;
30-
"connection-closed": (event: ConnectionManagerEvents["connection-closed"][0]) => void;
31-
"connection-errored": (event: ConnectionManagerEvents["connection-errored"][0]) => void;
27+
"connection-request": (event: ConnectionManagerEvents["connection-request"][0]) => void;
28+
"connection-success": (event: ConnectionManagerEvents["connection-succeess"][0]) => void;
29+
"connection-time-out": (event: ConnectionManagerEvents["connection-time-out"][0]) => void;
30+
"connection-close": (event: ConnectionManagerEvents["connection-close"][0]) => void;
31+
"connection-error": (event: ConnectionManagerEvents["connection-error"][0]) => void;
3232
};
3333

3434
let connectionManagerSpies: ConnectionManagerSpies;
3535

3636
beforeEach(async () => {
3737
connectionManagerSpies = {
38-
"connection-requested": vi.fn(),
39-
"connection-succeeded": vi.fn(),
40-
"connection-timed-out": vi.fn(),
41-
"connection-closed": vi.fn(),
42-
"connection-errored": vi.fn(),
38+
"connection-request": vi.fn(),
39+
"connection-success": vi.fn(),
40+
"connection-time-out": vi.fn(),
41+
"connection-close": vi.fn(),
42+
"connection-error": vi.fn(),
4343
};
4444

4545
for (const [event, spy] of Object.entries(connectionManagerSpies)) {
@@ -62,11 +62,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
6262
});
6363

6464
it("should notify that the connection was requested", () => {
65-
expect(connectionManagerSpies["connection-requested"]).toHaveBeenCalledOnce();
65+
expect(connectionManagerSpies["connection-request"]).toHaveBeenCalledOnce();
6666
});
6767

6868
it("should notify that the connection was successful", () => {
69-
expect(connectionManagerSpies["connection-succeeded"]).toHaveBeenCalledOnce();
69+
expect(connectionManagerSpies["connection-success"]).toHaveBeenCalledOnce();
7070
});
7171

7272
describe("when disconnects", () => {
@@ -75,7 +75,7 @@ describeWithMongoDB("Connection Manager", (integration) => {
7575
});
7676

7777
it("should notify that it was disconnected before connecting", () => {
78-
expect(connectionManagerSpies["connection-closed"]).toHaveBeenCalled();
78+
expect(connectionManagerSpies["connection-close"]).toHaveBeenCalled();
7979
});
8080

8181
it("should be marked explicitly as disconnected", () => {
@@ -91,11 +91,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
9191
});
9292

9393
it("should notify that it was disconnected before connecting", () => {
94-
expect(connectionManagerSpies["connection-closed"]).toHaveBeenCalled();
94+
expect(connectionManagerSpies["connection-close"]).toHaveBeenCalled();
9595
});
9696

9797
it("should notify that it was connected again", () => {
98-
expect(connectionManagerSpies["connection-succeeded"]).toHaveBeenCalled();
98+
expect(connectionManagerSpies["connection-success"]).toHaveBeenCalled();
9999
});
100100

101101
it("should be marked explicitly as connected", () => {
@@ -115,11 +115,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
115115
});
116116

117117
it("should notify that it was disconnected before connecting", () => {
118-
expect(connectionManagerSpies["connection-closed"]).toHaveBeenCalled();
118+
expect(connectionManagerSpies["connection-close"]).toHaveBeenCalled();
119119
});
120120

121121
it("should notify that it failed connecting", () => {
122-
expect(connectionManagerSpies["connection-errored"]).toHaveBeenCalledWith({
122+
expect(connectionManagerSpies["connection-error"]).toHaveBeenCalledWith({
123123
tag: "errored",
124124
connectedAtlasCluster: undefined,
125125
connectionStringAuthType: "scram",
@@ -152,11 +152,11 @@ describeWithMongoDB("Connection Manager", (integration) => {
152152
});
153153

154154
it("should notify that it was disconnected before connecting", () => {
155-
expect(connectionManagerSpies["connection-closed"]).toHaveBeenCalled();
155+
expect(connectionManagerSpies["connection-close"]).toHaveBeenCalled();
156156
});
157157

158158
it("should notify that it failed connecting", () => {
159-
expect(connectionManagerSpies["connection-errored"]).toHaveBeenCalledWith({
159+
expect(connectionManagerSpies["connection-error"]).toHaveBeenCalledWith({
160160
tag: "errored",
161161
connectedAtlasCluster: atlas,
162162
connectionStringAuthType: "scram",

0 commit comments

Comments
 (0)