Skip to content

Commit ebfdc40

Browse files
committed
feat: add support for shutdownAfterInactiveSeconds parameter
1 parent ed28903 commit ebfdc40

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/connection.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,37 @@ describe("Connection.connect, when passed connection options", () => {
213213
sessionType: "multi",
214214
});
215215
});
216+
217+
test("can be set with shutdownAfterInactiveSeconds", async () => {
218+
simulateImmediatelyReadySession(fetchMock);
219+
simulateImmediatelyOpenSocket(MockWebSocket);
220+
Connection.connect(
221+
{
222+
apiKey: testApiKey,
223+
runtime: Runtime.TINY,
224+
shutdownAfterInactiveSeconds: 3600,
225+
},
226+
testHarness,
227+
);
228+
vi.runAllTimersAsync();
229+
expectMatchingSessionCreateBody(fetchMock, {
230+
shutdownAfterInactiveSeconds: 3600,
231+
});
232+
});
233+
234+
test("rejects if shutdownAfterInactiveSeconds is invalid", async () => {
235+
const connection = Connection.connect(
236+
{
237+
apiKey: testApiKey,
238+
runtime: Runtime.TINY,
239+
shutdownAfterInactiveSeconds: -100,
240+
},
241+
testHarness,
242+
);
243+
vi.runAllTimersAsync();
244+
await expect(connection).rejects.toBeInstanceOf(Error);
245+
expect(fetchMock).not.toHaveBeenCalled();
246+
});
216247
});
217248

218249
describe("Connection.connect, when establishing SQL session", () => {

src/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export class Connection {
137137
runtimeId: this.options.runtime,
138138
version: this.options.version,
139139
sessionType: this.options.sessionType,
140+
shutdownAfterInactiveSeconds:
141+
this.options.shutdownAfterInactiveSeconds,
140142
}),
141143
...this.fetchOptions,
142144
signal: combineAbortSignals(signal, this.fetchOptions.signal),

src/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ConnectionOptionsSchema = z.object({
2626
dataCompression: z.literal(DataCompression.BROTLI).optional(),
2727
geometryRepresentation: z.nativeEnum(GeometryRepresentation).optional(),
2828
sessionType: z.nativeEnum(SessionType).optional(),
29+
shutdownAfterInactiveSeconds: z.number().int().positive().optional(),
2930
});
3031

3132
export type ConnectionOptions = z.infer<typeof ConnectionOptionsSchema>;

0 commit comments

Comments
 (0)