stitchkit 0.48.1 → 0.49.1

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.
@@ -1,9 +1,14 @@
1
1
  import {
2
+ ShutdownOptionsSchema,
3
+ ShutdownResultSchema,
4
+ ShutdownStateSchema,
5
+ ShutdownStatusSchema,
2
6
  bindRealtimeServer,
3
7
  composeWebSocketHandlers,
4
8
  createHandler,
5
9
  createImplement,
6
10
  createImplementRegistry,
11
+ createServerLifecycle,
7
12
  createSocketIOServer,
8
13
  defineMultipartStream,
9
14
  implement,
@@ -11,7 +16,7 @@ import {
11
16
  parseMultipart,
12
17
  socketIoLane,
13
18
  webSocketLane
14
- } from "../index-ts21eyz4.js";
19
+ } from "../index-z992nfbx.js";
15
20
  import {
16
21
  createAuthHook,
17
22
  createBearerResolver,
@@ -67,16 +72,112 @@ import {
67
72
  } from "../index-h05ygjqx.js";
68
73
  // src/server/bun.ts
69
74
  function createServer(config) {
70
- const { routes, websocket, development, bun: bunExtra, port = 3000, hostname } = config;
75
+ const {
76
+ websocket: configuredWebSocket,
77
+ socket,
78
+ development,
79
+ bun: bunExtra,
80
+ port = 3000,
81
+ hostname
82
+ } = config;
83
+ const socketRoutePrefix = socket?.route.path.replace(/\*socketPath$/, "");
84
+ const websocket = configuredWebSocket ?? socket?.websocket;
85
+ const openSockets = new Set;
86
+ const socketDrainWaiters = new Set;
87
+ let hadWebSockets = false;
88
+ const resolveSocketDrain = () => {
89
+ if (openSockets.size !== 0)
90
+ return;
91
+ for (const resolve of socketDrainWaiters)
92
+ resolve();
93
+ socketDrainWaiters.clear();
94
+ };
95
+ const waitForSocketDrain = () => {
96
+ if (openSockets.size === 0)
97
+ return Promise.resolve();
98
+ return new Promise((resolve) => socketDrainWaiters.add(resolve));
99
+ };
100
+ const trackedWebSocket = websocket ? {
101
+ ...websocket,
102
+ open(ws) {
103
+ hadWebSockets = true;
104
+ openSockets.add(ws);
105
+ websocket.open?.(ws);
106
+ },
107
+ close(ws, code, reason) {
108
+ openSockets.delete(ws);
109
+ resolveSocketDrain();
110
+ websocket.close?.(ws, code, reason);
111
+ }
112
+ } : undefined;
113
+ let runtime;
114
+ const requireRuntime = () => {
115
+ if (!runtime)
116
+ throw new Error("[stitchkit] Bun server lifecycle started before Bun.serve");
117
+ return runtime;
118
+ };
119
+ const adapter = {
120
+ beginShutdown: () => socket?.beginShutdown(),
121
+ pendingRequests: () => runtime?.pendingRequests ?? 0,
122
+ pendingWebSockets: () => openSockets.size,
123
+ async closeRealtime() {
124
+ const logicalClose = socket?.close();
125
+ for (const ws of openSockets)
126
+ ws.close(1001, "Server shutting down");
127
+ await Promise.all([logicalClose, waitForSocketDrain()]);
128
+ },
129
+ async stopGracefully() {
130
+ await new Promise((resolve) => setTimeout(resolve, 0));
131
+ const server2 = requireRuntime();
132
+ if (server2.pendingRequests === 0 && openSockets.size === 0) {
133
+ const stopping = server2.stop(true);
134
+ if (!hadWebSockets)
135
+ await stopping;
136
+ else
137
+ stopping.catch(() => {
138
+ return;
139
+ });
140
+ return;
141
+ }
142
+ await server2.stop(false);
143
+ },
144
+ async forceStop() {
145
+ const logicalClose = socket?.close();
146
+ const physicalClose = waitForSocketDrain();
147
+ for (const ws of [...openSockets])
148
+ ws.terminate();
149
+ const stopping = requireRuntime().stop(true);
150
+ if (!hadWebSockets)
151
+ await stopping;
152
+ else
153
+ stopping.catch(() => {
154
+ return;
155
+ });
156
+ await Promise.all([logicalClose, physicalClose]);
157
+ }
158
+ };
159
+ const lifecycle = createServerLifecycle(() => adapter);
71
160
  const handler = createHandler(config);
72
- const fetch = config.wrapFetch ? config.wrapFetch(handler) : handler;
73
- return websocket ? Bun.serve({
161
+ const consumerFetch = config.wrapFetch ? config.wrapFetch(handler) : handler;
162
+ const admittedFetch = lifecycle.wrapFetch(consumerFetch);
163
+ const fetch = async (request, server2) => {
164
+ if (socket && socketRoutePrefix) {
165
+ const pathname = new URL(request.url).pathname;
166
+ if (pathname.startsWith(socketRoutePrefix)) {
167
+ return await socket.route.handler(request, {
168
+ params: { socketPath: pathname.slice(socketRoutePrefix.length) },
169
+ server: server2
170
+ });
171
+ }
172
+ }
173
+ return admittedFetch(request, server2);
174
+ };
175
+ runtime = trackedWebSocket ? Bun.serve({
74
176
  ...bunExtra,
75
- ...routes && { routes },
76
177
  ...development && { development },
77
178
  port,
78
179
  hostname,
79
- websocket,
180
+ websocket: trackedWebSocket,
80
181
  fetch
81
182
  }) : Bun.serve({
82
183
  ...bunExtra,
@@ -85,6 +186,16 @@ function createServer(config) {
85
186
  hostname,
86
187
  fetch
87
188
  });
189
+ const server = runtime;
190
+ return {
191
+ url: server.url.toString().replace(/\/$/, ""),
192
+ port: server.port ?? port,
193
+ runtime: server,
194
+ get status() {
195
+ return lifecycle.status;
196
+ },
197
+ shutdown: lifecycle.shutdown
198
+ };
88
199
  }
89
200
  // src/server/swept-map.ts
90
201
  function createSweptMap(options) {
@@ -849,6 +960,10 @@ export {
849
960
  bindRealtimeServer,
850
961
  badRequest,
851
962
  appError,
963
+ ShutdownStatusSchema,
964
+ ShutdownStateSchema,
965
+ ShutdownResultSchema,
966
+ ShutdownOptionsSchema,
852
967
  STITCH_ERROR_STATUS,
853
968
  DEFAULT_CORS_EXPOSE_HEADERS,
854
969
  DEFAULT_CORS_ALLOW_HEADERS,
@@ -1,21 +1,20 @@
1
1
  import type { Server as HttpServer } from 'node:http';
2
+ import { serve } from 'srvx/node';
3
+ import { type ManagedServerHandle } from './shutdown';
2
4
  import type { FetchComposition, HandlerConfig } from './types';
5
+ export interface NodeSocketLifecycle {
6
+ attach(server: HttpServer): void;
7
+ beginShutdown(): void;
8
+ close(): Promise<void>;
9
+ connections(): number;
10
+ }
3
11
  export interface NodeServerConfig extends HandlerConfig, FetchComposition {
4
12
  port?: number;
5
13
  hostname?: string;
6
- /**
7
- * A Socket.IO handle from `createSocketIOServer` — attached to the underlying
8
- * `node:http.Server` (srvx `server.node.server`) once it is listening, so
9
- * Socket.IO owns the HTTP `upgrade` event on the same port.
10
- */
11
- socket?: {
12
- attach(server: HttpServer): void;
13
- };
14
- }
15
- export interface NodeServerHandle {
16
- url: string;
17
- port: number;
18
- close(closeActive?: boolean): Promise<void>;
14
+ /** A full Socket.IO lifecycle from `createSocketIOServer`. */
15
+ socket?: NodeSocketLifecycle;
19
16
  }
17
+ export type NodeRuntimeServer = ReturnType<typeof serve>;
18
+ export type NodeServerHandle = ManagedServerHandle<NodeRuntimeServer>;
20
19
  export declare function serveNode(config: NodeServerConfig): Promise<NodeServerHandle>;
21
20
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/server/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,WAAW,gBAAiB,SAAQ,aAAa,EAAE,gBAAgB;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;KAAE,CAAC;CAC/C;AAED,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA8BnF"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/server/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAkB,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACjC,aAAa,IAAI,IAAI,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,WAAW,IAAI,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,aAAa,EAAE,gBAAgB;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACzD,MAAM,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;AAEtE,wBAAsB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAoHnF"}
@@ -0,0 +1,77 @@
1
+ import { z } from 'zod';
2
+ import type { FetchHandler } from './types';
3
+ export declare const ShutdownStateSchema: z.ZodEnum<{
4
+ clean: "clean";
5
+ "closing-realtime": "closing-realtime";
6
+ "draining-http": "draining-http";
7
+ forced: "forced";
8
+ running: "running";
9
+ "stopping-runtime": "stopping-runtime";
10
+ }>;
11
+ export type ShutdownState = z.infer<typeof ShutdownStateSchema>;
12
+ export declare const ShutdownOptionsSchema: z.ZodObject<{
13
+ gracePeriodMs: z.ZodDefault<z.ZodNumber>;
14
+ forceTimeoutMs: z.ZodDefault<z.ZodNumber>;
15
+ retryAfterSeconds: z.ZodDefault<z.ZodNumber>;
16
+ signal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
17
+ }, z.core.$strip>;
18
+ export type ShutdownOptions = z.input<typeof ShutdownOptionsSchema>;
19
+ export declare const ShutdownStatusSchema: z.ZodObject<{
20
+ state: z.ZodEnum<{
21
+ clean: "clean";
22
+ "closing-realtime": "closing-realtime";
23
+ "draining-http": "draining-http";
24
+ forced: "forced";
25
+ running: "running";
26
+ "stopping-runtime": "stopping-runtime";
27
+ }>;
28
+ acceptedRequests: z.ZodNumber;
29
+ completedRequests: z.ZodNumber;
30
+ pendingRequests: z.ZodNumber;
31
+ pendingWebSockets: z.ZodNumber;
32
+ }, z.core.$strip>;
33
+ export type ShutdownStatus = z.infer<typeof ShutdownStatusSchema>;
34
+ export declare const ShutdownResultSchema: z.ZodObject<{
35
+ outcome: z.ZodEnum<{
36
+ clean: "clean";
37
+ forced: "forced";
38
+ }>;
39
+ reason: z.ZodOptional<z.ZodEnum<{
40
+ deadline: "deadline";
41
+ signal: "signal";
42
+ }>>;
43
+ acceptedRequests: z.ZodNumber;
44
+ completedRequests: z.ZodNumber;
45
+ pendingRequests: z.ZodNumber;
46
+ pendingWebSockets: z.ZodNumber;
47
+ pendingRequestsAtForce: z.ZodNumber;
48
+ pendingWebSocketsAtForce: z.ZodNumber;
49
+ abortedRequests: z.ZodNumber;
50
+ forcedWebSockets: z.ZodNumber;
51
+ durationMs: z.ZodNumber;
52
+ }, z.core.$strip>;
53
+ export type ShutdownResult = z.infer<typeof ShutdownResultSchema>;
54
+ /** Shared lifecycle shape; only the explicit runtime escape hatch varies. */
55
+ export interface ManagedServerHandle<TRuntime> {
56
+ readonly url: string;
57
+ readonly port: number;
58
+ readonly runtime: TRuntime;
59
+ readonly status: ShutdownStatus;
60
+ shutdown(options?: ShutdownOptions): Promise<ShutdownResult>;
61
+ }
62
+ export interface ShutdownAdapter {
63
+ beginShutdown(retryAfterSeconds: number): void;
64
+ pendingRequests(): number;
65
+ pendingWebSockets(): number;
66
+ closeRealtime(): Promise<void>;
67
+ stopGracefully(): Promise<void>;
68
+ forceStop(): Promise<void>;
69
+ }
70
+ interface ServerLifecycle {
71
+ wrapFetch<TServer>(handler: FetchHandler<TServer>): FetchHandler<TServer>;
72
+ readonly status: ShutdownStatus;
73
+ shutdown(options?: ShutdownOptions): Promise<ShutdownResult>;
74
+ }
75
+ export declare function createServerLifecycle(getAdapter: () => ShutdownAdapter): ServerLifecycle;
76
+ export {};
77
+ //# sourceMappingURL=shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../src/server/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,eAAO,MAAM,mBAAmB;;;;;;;EAO9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,qBAAqB;;;;;iBAchC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;iBAM/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;iBAY/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE,6EAA6E;AAC7E,MAAM,WAAW,mBAAmB,CAAC,QAAQ;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/C,eAAe,IAAI,MAAM,CAAC;IAC1B,iBAAiB,IAAI,MAAM,CAAC;IAC5B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,UAAU,eAAe;IACvB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAC1E,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC9D;AAqDD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,eAAe,GAAG,eAAe,CAiJxF"}
@@ -1,5 +1,7 @@
1
1
  /** Runtime-neutral Socket.IO configuration shared by Bun and Node adapters. */
2
2
  import type { ServerOptions } from 'socket.io';
3
+ /** Runtime-neutral Engine.IO handshake policy, evaluated before shutdown admission. */
4
+ export type SocketIORequestPolicy = (request: Request) => boolean | Promise<boolean>;
3
5
  export interface SocketIOServerConfig {
4
6
  /** CORS — the browser origin(s) allowed to open a socket. */
5
7
  cors: {
@@ -14,7 +16,9 @@ export interface SocketIOServerConfig {
14
16
  pingTimeout?: number;
15
17
  /** Heartbeat: ms between pings. */
16
18
  pingInterval?: number;
19
+ /** Runtime-neutral policy for accepting a new Engine.IO handshake. */
20
+ allowRequest?: SocketIORequestPolicy;
17
21
  /** Typed Socket.IO options not owned by this wrapper. */
18
- serverOptions?: Partial<ServerOptions>;
22
+ serverOptions?: Omit<Partial<ServerOptions>, 'allowRequest'>;
19
23
  }
20
24
  //# sourceMappingURL=socket-io-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-io-config.d.ts","sourceRoot":"","sources":["../../src/server/socket-io-config.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC,6DAA6D;IAC7D,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3D,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC5C,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,aAAa,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CACxC"}
1
+ {"version":3,"file":"socket-io-config.d.ts","sourceRoot":"","sources":["../../src/server/socket-io-config.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,uFAAuF;AACvF,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAErF,MAAM,WAAW,oBAAoB;IACnC,6DAA6D;IAC7D,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3D,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,UAAU,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC5C,qEAAqE;IACrE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,yDAAyD;IACzD,aAAa,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC,CAAC;CAC9D"}
@@ -3,11 +3,14 @@ import type { Server as HttpServer } from 'node:http';
3
3
  import type { Server as SocketIOServer } from 'socket.io';
4
4
  import type { SocketEventMap } from '../browser/socket-io';
5
5
  import type { SocketIOServerConfig } from './socket-io-config';
6
- export type { SocketIOServerConfig } from './socket-io-config';
6
+ export type { SocketIORequestPolicy, SocketIOServerConfig } from './socket-io-config';
7
7
  /** The runtime-neutral part of a Socket.IO handle used by `serveNode`. */
8
8
  export interface NodeSocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> {
9
9
  io: SocketIOServer<TClientEvents, TServerEvents>;
10
10
  attach(server: HttpServer): void;
11
+ beginShutdown(): void;
12
+ close(): Promise<void>;
13
+ connections(): number;
11
14
  }
12
15
  /** Create a Socket.IO handle typed only for the Node capabilities it exposes. */
13
16
  export declare function createNodeSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): Promise<NodeSocketIOServerHandle<TServerEvents, TClientEvents>>;
@@ -1 +1 @@
1
- {"version":3,"file":"socket-io-node.d.ts","sourceRoot":"","sources":["../../src/server/socket-io-node.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EA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iFAAiF;AACjF,wBAAsB,wBAAwB,CAC5C,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EAEpC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,wBAAwB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAEjE"}
@@ -23,10 +23,8 @@ import type { BunServer } from './bun';
23
23
  import type { SocketIOServerConfig } from './socket-io-config';
24
24
  import type { RawRoute } from './types';
25
25
  import { type ComposedLane } from './websocket';
26
- export type { SocketIOServerConfig } from './socket-io-config';
27
- export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> {
28
- /** The typed Socket.IO server — attach `io.on('connection', ...)` handlers. */
29
- io: SocketIOServer<TClientEvents, TServerEvents>;
26
+ export type { SocketIORequestPolicy, SocketIOServerConfig } from './socket-io-config';
27
+ export interface SocketIOServerLifecycle {
30
28
  /**
31
29
  * WebSocket handler for `Bun.serve({ websocket })`. Real on Bun; on Node it is
32
30
  * an inert no-op — sockets there are driven by the `node:http.Server`
@@ -47,6 +45,16 @@ export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TCli
47
45
  * `serveNode({ socket })` calls this for you.
48
46
  */
49
47
  attach(server: HttpServer): void;
48
+ /** Stop admitting new Engine.IO handshakes. Called by the managed server. */
49
+ beginShutdown(): void;
50
+ /** Idempotently close namespaces, adapters and the bound transport engine. */
51
+ close(): Promise<void>;
52
+ /** Current Engine.IO client count, when the engine has been bound. */
53
+ connections(): number;
54
+ }
55
+ export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> extends SocketIOServerLifecycle {
56
+ /** The typed Socket.IO server — attach `io.on('connection', ...)` handlers. */
57
+ io: SocketIOServer<TClientEvents, TServerEvents>;
50
58
  }
51
59
  export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): Promise<SocketIOServerHandle<TServerEvents, TClientEvents>>;
52
60
  /**
@@ -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AoB,CACnC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,CACpC,SAAQ,uBAAuB;IAC/B,+EAA+E;IAC/E,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;CAClD;AAuCD,wBAAsB,oBAAoB,CACxC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAyI3F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,oBAAoB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,WAAW,CAAC,GAC3E,YAAY,CAMd"}
@@ -66,7 +66,7 @@ export declare function webSocketLane<TData>(lane: WebSocketLane<TData>): Compos
66
66
  * [webSocketLane({ match: isPcmSocket, handlers: pcmHandlers }), socketIoLane(socket.websocket)],
67
67
  * { maxPayloadLength: 16 * 1024 * 1024 },
68
68
  * )
69
- * createServer({ websocket: ws, rawRoutes: [socket.route, pcmUpgradeRoute] })
69
+ * createServer({ socket, websocket: ws, rawRoutes: [pcmUpgradeRoute] })
70
70
  * ```
71
71
  */
72
72
  export declare function composeWebSocketHandlers(lanes: ComposedLane[], config?: WebSocketComposeConfig): WebSocketHandler<unknown>;