stitchkit 0.48.1 → 0.49.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/README.md CHANGED
@@ -225,8 +225,7 @@ socket.io.on('connection', (s) => { /* rooms, handshake auth — your domain log
225
225
 
226
226
  createServer({
227
227
  services: [service],
228
- websocket: socket.websocket, // Bun.serve
229
- rawRoutes: [socket.route], // ready /socket.io/*socketPath route
228
+ socket, // route + websocket + managed shutdown
230
229
  })
231
230
  ```
232
231
 
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/browser/http.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,MAAM,MAAM,QAAQ,GAChB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAEzD,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAEhE,qBAAa,QAAS,SAAQ,KAAK;aAEf,IAAI,EAAE,MAAM;aACZ,MAAM,EAAE,MAAM;aACd,OAAO,CAAC,EAAE,OAAO;aAEjB,IAAI,CAAC,EAAE,MAAM;aACb,OAAO,CAAC,EAAE,MAAM;IANlC,YACkB,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAU,EAClB,OAAO,CAAC,EAAE,OAAO,EACjC,OAAO,CAAC,EAAE,MAAM,EACA,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,OAAO,CAAC,EAAE,MAAM,YAAA,EAIjC;IAED,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE3C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aders2(cors, req) });
1398
1398
  }
1399
1399
 
1400
+ // src/server/shutdown.ts
1401
+ import { z } from "zod";
1402
+ var ShutdownStateSchema = z.enum([
1403
+ "running",
1404
+ "draining-http",
1405
+ "closing-realtime",
1406
+ "stopping-runtime",
1407
+ "clean",
1408
+ "forced"
1409
+ ]);
1410
+ var ShutdownOptionsSchema = z.object({
1411
+ gracePeriodMs: z.number().int().nonnegative().default(30000),
1412
+ retryAfterSeconds: z.number().int().nonnegative().default(5),
1413
+ signal: z.custom((value) => typeof value === "object" && value !== null && ("aborted" in value) && ("addEventListener" in value), "Expected an AbortSignal").optional()
1414
+ });
1415
+ var ShutdownStatusSchema = z.object({
1416
+ state: ShutdownStateSchema,
1417
+ acceptedRequests: z.number().int().nonnegative(),
1418
+ completedRequests: z.number().int().nonnegative(),
1419
+ pendingRequests: z.number().int().nonnegative(),
1420
+ pendingWebSockets: z.number().int().nonnegative()
1421
+ });
1422
+ var ShutdownResultSchema = z.object({
1423
+ outcome: z.enum(["clean", "forced"]),
1424
+ reason: z.enum(["deadline", "signal"]).optional(),
1425
+ acceptedRequests: z.number().int().nonnegative(),
1426
+ completedRequests: z.number().int().nonnegative(),
1427
+ pendingRequests: z.number().int().nonnegative(),
1428
+ pendingWebSockets: z.number().int().nonnegative(),
1429
+ pendingRequestsAtForce: z.number().int().nonnegative(),
1430
+ pendingWebSocketsAtForce: z.number().int().nonnegative(),
1431
+ abortedRequests: z.number().int().nonnegative(),
1432
+ forcedWebSockets: z.number().int().nonnegative(),
1433
+ durationMs: z.number().nonnegative()
1434
+ });
1435
+ function rejectedResponse(retryAfterSeconds) {
1436
+ return Response.json({ error: { code: "SERVER_SHUTTING_DOWN", message: "Server is shutting down" } }, {
1437
+ status: 503,
1438
+ headers: {
1439
+ Connection: "close",
1440
+ "Retry-After": String(retryAfterSeconds)
1441
+ }
1442
+ });
1443
+ }
1444
+ function waitForZero(read, signal) {
1445
+ if (read() === 0)
1446
+ return Promise.resolve();
1447
+ return new Promise((resolve) => {
1448
+ const check = () => {
1449
+ if (read() === 0 || signal.aborted) {
1450
+ clearInterval(timer);
1451
+ signal.removeEventListener("abort", check);
1452
+ resolve();
1453
+ }
1454
+ };
1455
+ const timer = setInterval(check, 5);
1456
+ signal.addEventListener("abort", check, { once: true });
1457
+ });
1458
+ }
1459
+ function untilAbort(signal) {
1460
+ if (signal.aborted)
1461
+ return Promise.resolve();
1462
+ return new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
1463
+ }
1464
+ function createServerLifecycle(getAdapter) {
1465
+ let state = "running";
1466
+ let acceptedRequests = 0;
1467
+ let completedRequests = 0;
1468
+ let pendingApplicationRequests = 0;
1469
+ let retryAfterSeconds = 5;
1470
+ let shutdownPromise;
1471
+ const status = () => {
1472
+ const adapter = getAdapter();
1473
+ return ShutdownStatusSchema.parse({
1474
+ state,
1475
+ acceptedRequests,
1476
+ completedRequests,
1477
+ pendingRequests: adapter.pendingRequests(),
1478
+ pendingWebSockets: adapter.pendingWebSockets()
1479
+ });
1480
+ };
1481
+ const wrapFetch = (handler) => {
1482
+ return async (request, server) => {
1483
+ if (state !== "running")
1484
+ return rejectedResponse(retryAfterSeconds);
1485
+ acceptedRequests += 1;
1486
+ pendingApplicationRequests += 1;
1487
+ try {
1488
+ return await handler(request, server);
1489
+ } finally {
1490
+ pendingApplicationRequests -= 1;
1491
+ completedRequests += 1;
1492
+ }
1493
+ };
1494
+ };
1495
+ const shutdown = (options) => {
1496
+ if (shutdownPromise)
1497
+ return shutdownPromise;
1498
+ const parsed = ShutdownOptionsSchema.parse(options ?? {});
1499
+ retryAfterSeconds = parsed.retryAfterSeconds;
1500
+ const startedAt = performance.now();
1501
+ const adapter = getAdapter();
1502
+ state = "draining-http";
1503
+ adapter.beginShutdown(retryAfterSeconds);
1504
+ shutdownPromise = new Promise((resolve, reject) => {
1505
+ const phaseAbort = new AbortController;
1506
+ let forcedReason;
1507
+ const force = (reason) => {
1508
+ if (forcedReason)
1509
+ return;
1510
+ forcedReason = reason;
1511
+ phaseAbort.abort();
1512
+ };
1513
+ const timer = setTimeout(() => force("deadline"), parsed.gracePeriodMs);
1514
+ const onExternalAbort = () => force("signal");
1515
+ parsed.signal?.addEventListener("abort", onExternalAbort, { once: true });
1516
+ if (parsed.signal?.aborted)
1517
+ force("signal");
1518
+ const cleanup = () => {
1519
+ clearTimeout(timer);
1520
+ parsed.signal?.removeEventListener("abort", onExternalAbort);
1521
+ };
1522
+ (async () => {
1523
+ await waitForZero(() => pendingApplicationRequests, phaseAbort.signal);
1524
+ if (!forcedReason) {
1525
+ state = "closing-realtime";
1526
+ const closeRealtime = adapter.closeRealtime();
1527
+ await Promise.race([
1528
+ closeRealtime.catch((error) => {
1529
+ if (!forcedReason)
1530
+ throw error;
1531
+ }),
1532
+ untilAbort(phaseAbort.signal)
1533
+ ]);
1534
+ }
1535
+ if (!forcedReason) {
1536
+ state = "stopping-runtime";
1537
+ const stopGracefully = adapter.stopGracefully();
1538
+ await Promise.race([
1539
+ stopGracefully.catch((error) => {
1540
+ if (!forcedReason)
1541
+ throw error;
1542
+ }),
1543
+ untilAbort(phaseAbort.signal)
1544
+ ]);
1545
+ }
1546
+ let pendingRequestsAtForce = 0;
1547
+ let pendingWebSocketsAtForce = 0;
1548
+ if (forcedReason) {
1549
+ state = "stopping-runtime";
1550
+ pendingRequestsAtForce = adapter.pendingRequests();
1551
+ pendingWebSocketsAtForce = adapter.pendingWebSockets();
1552
+ await adapter.forceStop();
1553
+ state = "forced";
1554
+ } else {
1555
+ state = "clean";
1556
+ }
1557
+ cleanup();
1558
+ resolve(ShutdownResultSchema.parse({
1559
+ outcome: forcedReason ? "forced" : "clean",
1560
+ ...forcedReason && { reason: forcedReason },
1561
+ acceptedRequests,
1562
+ completedRequests,
1563
+ pendingRequests: adapter.pendingRequests(),
1564
+ pendingWebSockets: adapter.pendingWebSockets(),
1565
+ pendingRequestsAtForce,
1566
+ pendingWebSocketsAtForce,
1567
+ abortedRequests: pendingRequestsAtForce,
1568
+ forcedWebSockets: pendingWebSocketsAtForce,
1569
+ durationMs: performance.now() - startedAt
1570
+ }));
1571
+ })().catch((error) => {
1572
+ cleanup();
1573
+ reject(error);
1574
+ });
1575
+ });
1576
+ return shutdownPromise;
1577
+ };
1578
+ return {
1579
+ wrapFetch,
1580
+ get status() {
1581
+ return status();
1582
+ },
1583
+ shutdown
1584
+ };
1585
+ }
1586
+
1400
1587
  // src/server/implement.ts
1401
1588
  function isStreamingImplementation(value) {
1402
1589
  return typeof value === "object" && value !== null && "kind" in value && value.kind === "stitchkit.multipart.stream";
@@ -1525,9 +1712,9 @@ function createImplementRegistry() {
1525
1712
  }
1526
1713
 
1527
1714
  // src/realtime/rejection.ts
1528
- import { z } from "zod";
1715
+ import { z as z2 } from "zod";
1529
1716
  function realtimeContractViolation(options) {
1530
- const issues = options.cause instanceof z.ZodError ? zodIssues(options.cause) : undefined;
1717
+ const issues = options.cause instanceof z2.ZodError ? zodIssues(options.cause) : undefined;
1531
1718
  const reason = options.reason.replaceAll("-", " ");
1532
1719
  const error = new AppError("REALTIME_CONTRACT_VIOLATION", `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`, 500, {
1533
1720
  event: options.event,
@@ -1832,6 +2019,34 @@ async function createSocketIOServer(config) {
1832
2019
  credentials: config.cors.credentials ?? true,
1833
2020
  methods: ["GET", "POST"]
1834
2021
  };
2022
+ let accepting = true;
2023
+ let attached = false;
2024
+ let closePromise;
2025
+ const consumerAllowRequest = config.allowRequest;
2026
+ const checkRequest = async (request) => {
2027
+ if (consumerAllowRequest && !await consumerAllowRequest(request)) {
2028
+ throw new Error("Request rejected by the configured Socket.IO policy");
2029
+ }
2030
+ if (!accepting)
2031
+ throw new Error("Server is shutting down");
2032
+ };
2033
+ const allowRequest = (request, done) => {
2034
+ const headers = new Headers;
2035
+ for (const [name, value] of Object.entries(request.headers)) {
2036
+ if (Array.isArray(value)) {
2037
+ for (const item of value)
2038
+ headers.append(name, item);
2039
+ } else if (value !== undefined) {
2040
+ headers.set(name, value);
2041
+ }
2042
+ }
2043
+ const host = headers.get("host") ?? "localhost";
2044
+ const webRequest = new Request(new URL(request.url ?? "/", `http://${host}`), {
2045
+ method: request.method,
2046
+ headers
2047
+ });
2048
+ checkRequest(webRequest).then(() => done(null, true), (error) => done(error instanceof Error ? error.message : "Request rejected", false));
2049
+ };
1835
2050
  const { Server } = await importPeer(() => import("socket.io"), "socket.io");
1836
2051
  const io = new Server({
1837
2052
  ...config.serverOptions,
@@ -1839,15 +2054,31 @@ async function createSocketIOServer(config) {
1839
2054
  cors,
1840
2055
  transports,
1841
2056
  pingTimeout,
1842
- pingInterval
2057
+ pingInterval,
2058
+ allowRequest
1843
2059
  });
2060
+ const lifecycle = {
2061
+ beginShutdown() {
2062
+ accepting = false;
2063
+ },
2064
+ close() {
2065
+ if (closePromise)
2066
+ return closePromise;
2067
+ closePromise = onBun || attached ? io.close() : Promise.resolve();
2068
+ return closePromise;
2069
+ },
2070
+ connections() {
2071
+ return io.engine?.clientsCount ?? 0;
2072
+ }
2073
+ };
1844
2074
  if (onBun) {
1845
2075
  const { Server: Engine } = await importPeer(() => import("@socket.io/bun-engine"), "@socket.io/bun-engine");
1846
2076
  const engineOpts = {
1847
2077
  path,
1848
2078
  cors,
1849
2079
  pingTimeout,
1850
- pingInterval
2080
+ pingInterval,
2081
+ allowRequest: checkRequest
1851
2082
  };
1852
2083
  if (config.serverOptions?.maxHttpBufferSize !== undefined) {
1853
2084
  engineOpts.maxHttpBufferSize = config.serverOptions.maxHttpBufferSize;
@@ -1868,11 +2099,14 @@ async function createSocketIOServer(config) {
1868
2099
  return engine.handleRequest(req, ctx.server);
1869
2100
  }
1870
2101
  };
1871
- return { io, websocket, route, attach: noop };
2102
+ return { io, websocket, route, attach: noop, ...lifecycle };
1872
2103
  }
1873
2104
  return {
1874
2105
  io,
1875
- attach: (server) => io.attach(server),
2106
+ attach: (server) => {
2107
+ io.attach(server);
2108
+ attached = true;
2109
+ },
1876
2110
  websocket: { open: noop, message: noop, close: noop, maxPayloadLength: 0 },
1877
2111
  route: {
1878
2112
  method: "ALL",
@@ -1880,7 +2114,8 @@ async function createSocketIOServer(config) {
1880
2114
  handler: () => {
1881
2115
  throw new Error("[stitchkit] On Node, Socket.IO attaches via serveNode({ socket }) — this route is not mounted.");
1882
2116
  }
1883
- }
2117
+ },
2118
+ ...lifecycle
1884
2119
  };
1885
2120
  }
1886
2121
  function socketIoLane(websocket) {
@@ -1890,4 +2125,4 @@ function socketIoLane(websocket) {
1890
2125
  });
1891
2126
  }
1892
2127
 
1893
- export { parseMultipart, createHandler, defineMultipartStream, implement, createImplement, implementRegistry, createImplementRegistry, bindRealtimeServer, webSocketLane, composeWebSocketHandlers, createSocketIOServer, socketIoLane };
2128
+ export { parseMultipart, createHandler, ShutdownStateSchema, ShutdownOptionsSchema, ShutdownStatusSchema, ShutdownResultSchema, createServerLifecycle, defineMultipartStream, implement, createImplement, implementRegistry, createImplementRegistry, bindRealtimeServer, webSocketLane, composeWebSocketHandlers, createSocketIOServer, socketIoLane };
package/dist/index.js CHANGED
@@ -397,6 +397,34 @@ function parseApiErrorBody(body) {
397
397
  hint: typeof error.hint === "string" ? error.hint : undefined
398
398
  };
399
399
  }
400
+ function createRetryAwareFetch() {
401
+ const runtimeFetch = globalThis.fetch.bind(globalThis);
402
+ let attempt = 0;
403
+ return (input, init) => {
404
+ attempt += 1;
405
+ if (attempt === 1) {
406
+ return runtimeFetch(input, init);
407
+ }
408
+ if (!(input instanceof Request))
409
+ return runtimeFetch(input, init);
410
+ const streamedBody = input.body ? { body: input.body, duplex: "half" } : {};
411
+ return runtimeFetch(input.url, {
412
+ ...init,
413
+ method: input.method,
414
+ headers: input.headers,
415
+ ...streamedBody,
416
+ cache: input.cache,
417
+ credentials: input.credentials,
418
+ integrity: input.integrity,
419
+ keepalive: input.keepalive,
420
+ mode: input.mode,
421
+ redirect: input.redirect,
422
+ referrer: input.referrer,
423
+ referrerPolicy: input.referrerPolicy,
424
+ signal: input.signal
425
+ });
426
+ };
427
+ }
400
428
  function createHttpClient(config) {
401
429
  let ssrCookies = null;
402
430
  let isLoggedOut = false;
@@ -462,6 +490,7 @@ function createHttpClient(config) {
462
490
  async function request(method, url, data, options = {}) {
463
491
  const cancellation = createRequestCancellation(options.signal, options.timeout ?? config.timeout ?? 30000);
464
492
  const kyOptions = {
493
+ fetch: createRetryAwareFetch(),
465
494
  timeout: false,
466
495
  signal: cancellation.signal
467
496
  };
package/dist/node.d.ts CHANGED
@@ -8,8 +8,9 @@ export { AppError, appError, badRequest, conflict, forbidden, notFound, rateLimi
8
8
  export { createHandler } from './server/create';
9
9
  export { createImplement, createImplementRegistry, type ExactRegistryHandlers, type ImplementationRegistry, implement, implementRegistry, type RegistryHandlers, } from './server/implement';
10
10
  export type { LogFormat } from './server/logger';
11
- export { type NodeServerConfig, type NodeServerHandle, serveNode } from './server/node';
11
+ export { type NodeRuntimeServer, type NodeServerConfig, type NodeServerHandle, type NodeSocketLifecycle, serveNode, } from './server/node';
12
12
  export { bindRealtimeServer, type RealtimeServer, type RealtimeServerConnection, type RealtimeServerHandle, } from './server/realtime';
13
- export { createNodeSocketIOServer as createSocketIOServer, type NodeSocketIOServerHandle as SocketIOServerHandle, type SocketIOServerConfig, } from './server/socket-io-node';
13
+ export { type ManagedServerHandle, type ShutdownOptions, ShutdownOptionsSchema, type ShutdownResult, ShutdownResultSchema, type ShutdownState, ShutdownStateSchema, type ShutdownStatus, ShutdownStatusSchema, } from './server/shutdown';
14
+ export { createNodeSocketIOServer as createSocketIOServer, type NodeSocketIOServerHandle as SocketIOServerHandle, type SocketIORequestPolicy, type SocketIOServerConfig, } from './server/socket-io-node';
14
15
  export type { FetchComposition, FetchHandler, HandlerConfig, LoggingConfig, LogOutcome, RawRoute, RawRouteContext, ServiceDef, } from './server/types';
15
16
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mapp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gBAAgB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,oBAAoB,EACpB,KAAK,aAAa,EAClB,mBAAmB,EACnB,KAAK,cAAc,EACnB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,IAAI,oBAAoB,EAChD,KAAK,wBAAwB,IAAI,oBAAoB,EACrD,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,gBAAgB,CAAC"}
package/dist/node.js CHANGED
@@ -1,12 +1,17 @@
1
1
  import {
2
+ ShutdownOptionsSchema,
3
+ ShutdownResultSchema,
4
+ ShutdownStateSchema,
5
+ ShutdownStatusSchema,
2
6
  bindRealtimeServer,
3
7
  createHandler,
4
8
  createImplement,
5
9
  createImplementRegistry,
10
+ createServerLifecycle,
6
11
  createSocketIOServer,
7
12
  implement,
8
13
  implementRegistry
9
- } from "./index-ts21eyz4.js";
14
+ } from "./index-fjfzsq6y.js";
10
15
  import"./index-r1qp4rve.js";
11
16
  import {
12
17
  AppError,
@@ -20,27 +25,108 @@ import {
20
25
  } from "./index-jewp9r0a.js";
21
26
  import"./index-h05ygjqx.js";
22
27
  // src/server/node.ts
23
- import { serve } from "srvx";
28
+ import { serve } from "srvx/node";
24
29
  async function serveNode(config) {
25
30
  const { port = 3000, hostname, socket, wrapFetch, ...handlerConfig } = config;
26
31
  const handler = createHandler(handlerConfig);
27
- const fetch = wrapFetch ? wrapFetch(handler) : handler;
28
- const server = serve({ port, hostname, fetch });
29
- await server.ready();
30
- if (socket) {
31
- const nodeServer = server.node?.server;
32
- if (!nodeServer || !("maxRequestsPerSocket" in nodeServer)) {
33
- throw new Error("[stitchkit] serveNode: expected a node:http.Server for Socket.IO (none / http2).");
32
+ let runtime;
33
+ let nodeServer;
34
+ const sockets = new Set;
35
+ const upgradedSockets = new Set;
36
+ const responses = new Set;
37
+ const socketDrainWaiters = new Set;
38
+ const resolveSocketDrain = () => {
39
+ if (sockets.size !== 0)
40
+ return;
41
+ for (const resolve of socketDrainWaiters)
42
+ resolve();
43
+ socketDrainWaiters.clear();
44
+ };
45
+ const waitForSocketDrain = () => {
46
+ if (sockets.size === 0)
47
+ return Promise.resolve();
48
+ return new Promise((resolve) => socketDrainWaiters.add(resolve));
49
+ };
50
+ const requireRuntime = () => {
51
+ if (!runtime)
52
+ throw new Error("[stitchkit] Node server lifecycle started before srvx");
53
+ return runtime;
54
+ };
55
+ const requireNodeServer = () => {
56
+ if (!nodeServer)
57
+ throw new Error("[stitchkit] Node HTTP server is unavailable");
58
+ return nodeServer;
59
+ };
60
+ const adapter = {
61
+ beginShutdown: () => socket?.beginShutdown(),
62
+ pendingRequests: () => responses.size,
63
+ pendingWebSockets: () => upgradedSockets.size,
64
+ closeRealtime: () => socket?.close() ?? Promise.resolve(),
65
+ async stopGracefully() {
66
+ const runtimeClose = socket ? Promise.resolve() : requireRuntime().close(false);
67
+ requireNodeServer().closeIdleConnections?.();
68
+ await runtimeClose;
69
+ await waitForSocketDrain();
70
+ },
71
+ async forceStop() {
72
+ const activeServer = requireNodeServer();
73
+ const logicalClose = socket?.close();
74
+ const physicalClosures = [...sockets].map((activeSocket) => new Promise((resolve) => {
75
+ if (activeSocket.closed)
76
+ resolve();
77
+ else
78
+ activeSocket.once("close", () => resolve());
79
+ }));
80
+ activeServer.closeAllConnections?.();
81
+ for (const activeSocket of sockets)
82
+ activeSocket.destroy();
83
+ if (logicalClose)
84
+ await logicalClose;
85
+ else
86
+ await requireRuntime().close(true);
87
+ await Promise.all(physicalClosures);
88
+ responses.clear();
34
89
  }
35
- socket.attach(nodeServer);
90
+ };
91
+ const lifecycle = createServerLifecycle(() => adapter);
92
+ const consumerFetch = wrapFetch ? wrapFetch(handler) : handler;
93
+ const fetch = lifecycle.wrapFetch(consumerFetch);
94
+ runtime = serve({ port, hostname, fetch, gracefulShutdown: false });
95
+ await runtime.ready();
96
+ const candidate = runtime.node?.server;
97
+ if (!candidate || !("maxRequestsPerSocket" in candidate)) {
98
+ await runtime.close(true);
99
+ throw new Error("[stitchkit] serveNode: expected a node:http.Server for the managed lifecycle.");
36
100
  }
37
- const listenUrl = server.url ?? `http://${hostname ?? "localhost"}:${port}`;
101
+ nodeServer = candidate;
102
+ nodeServer.on("connection", (activeSocket) => {
103
+ sockets.add(activeSocket);
104
+ activeSocket.once("close", () => {
105
+ sockets.delete(activeSocket);
106
+ upgradedSockets.delete(activeSocket);
107
+ resolveSocketDrain();
108
+ });
109
+ });
110
+ nodeServer.on("upgrade", (request) => upgradedSockets.add(request.socket));
111
+ nodeServer.prependListener("request", (_request, response) => {
112
+ responses.add(response);
113
+ const complete = () => responses.delete(response);
114
+ response.once("finish", complete);
115
+ response.once("close", complete);
116
+ });
117
+ socket?.attach(nodeServer);
118
+ const listenUrl = runtime.url ?? `http://${hostname ?? "localhost"}:${port}`;
38
119
  const resolvedPort = Number(new URL(listenUrl).port) || port;
39
120
  const resolvedHost = hostname ?? "localhost";
121
+ const server = runtime;
40
122
  return {
41
123
  url: `http://${resolvedHost}:${resolvedPort}`,
42
124
  port: resolvedPort,
43
- close: (closeActive) => server.close(closeActive)
125
+ runtime: server,
126
+ get status() {
127
+ return lifecycle.status;
128
+ },
129
+ shutdown: lifecycle.shutdown
44
130
  };
45
131
  }
46
132
  // src/server/socket-io-node.ts
@@ -63,5 +149,9 @@ export {
63
149
  bindRealtimeServer,
64
150
  badRequest,
65
151
  appError,
152
+ ShutdownStatusSchema,
153
+ ShutdownStateSchema,
154
+ ShutdownResultSchema,
155
+ ShutdownOptionsSchema,
66
156
  AppError
67
157
  };
@@ -1,3 +1,5 @@
1
+ import { type ManagedServerHandle } from './shutdown';
2
+ import type { SocketIOServerLifecycle } from './socket-io';
1
3
  import type { FetchComposition, FetchHandler, HandlerConfig, RawRoute, RawRouteContext } from './types';
2
4
  /** The concrete `Bun.serve` server instance passed to Bun raw routes. */
3
5
  export type BunServer = ReturnType<typeof Bun.serve>;
@@ -7,12 +9,7 @@ export type BunFetchHandler = FetchHandler<BunServer>;
7
9
  export type BunFetchComposition = FetchComposition<BunServer>;
8
10
  export type BunHandlerConfig = HandlerConfig<BunServer>;
9
11
  type BunServeOptions = Parameters<typeof Bun.serve>[0];
10
- type BunWebSocketHandlers = BunServeOptions extends {
11
- websocket?: infer T;
12
- } ? T : never;
13
- type BunRoutes = BunServeOptions extends {
14
- routes?: infer T;
15
- } ? T : never;
12
+ type BunWebSocketHandlers = Bun.WebSocketHandler<unknown>;
16
13
  type BunDevelopmentOptions = BunServeOptions extends {
17
14
  development?: infer T;
18
15
  } ? T : never;
@@ -21,12 +18,14 @@ export type ServerPassthrough = Omit<BunServeOptions, 'fetch' | 'port' | 'hostna
21
18
  export interface BunServerConfig extends BunHandlerConfig, BunFetchComposition {
22
19
  port?: number;
23
20
  hostname?: string;
24
- routes?: BunRoutes;
25
21
  websocket?: BunWebSocketHandlers;
22
+ /** Full Stitchkit Socket.IO lifecycle; route and default websocket are mounted automatically. */
23
+ socket?: SocketIOServerLifecycle;
26
24
  development?: BunDevelopmentOptions;
27
25
  bun?: ServerPassthrough;
28
26
  }
27
+ export type BunServerHandle = ManagedServerHandle<BunServer>;
29
28
  /** Start the contract router through `Bun.serve`. */
30
- export declare function createServer(config: BunServerConfig): BunServer;
29
+ export declare function createServer(config: BunServerConfig): BunServerHandle;
31
30
  export {};
32
31
  //# sourceMappingURL=bun.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../../src/server/bun.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC9C,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAExD,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,KAAK,oBAAoB,GAAG,eAAe,SAAS;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AACxF,KAAK,SAAS,GAAG,eAAe,SAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAC1E,KAAK,qBAAqB,GAAG,eAAe,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3F,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,eAAe,EACf,OAAO,GAAG,MAAM,GAAG,UAA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C;AACvD,KAAK,oBAAoB,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AAC1D,KAAK,qBAAqB,GAAG,eAAe,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAE3F,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,eAAe,EACf,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAChF,CAAC;AAEF,8EAA8E;AAC9E,MAAM,WAAW,eAAgB,SAAQ,gBAAgB,EAAE,mBAAmB;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,iGAAiG;IACjG,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAE7D,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAqIrE"}
@@ -1,7 +1,7 @@
1
1
  export { AppError, appError, badRequest, conflict, forbidden, isStitchErrorCode, notFound, rateLimited, STITCH_ERROR_STATUS, type StitchErrorCode, unauthorized, } from '../contract';
2
2
  export { errorCode, formatZodError, normalizeError, type ZodIssueSummary, zodIssues, } from '../internal/errors';
3
3
  export { isWithinDir } from '../internal/within-dir';
4
- export { type BunFetchComposition as FetchComposition, type BunFetchHandler as FetchHandler, type BunHandlerConfig as HandlerConfig, type BunRawRoute as RawRoute, type BunRawRouteContext as RawRouteContext, type BunServer, type BunServerConfig, createServer, type ServerPassthrough, } from './bun';
4
+ export { type BunFetchComposition as FetchComposition, type BunFetchHandler as FetchHandler, type BunHandlerConfig as HandlerConfig, type BunRawRoute as RawRoute, type BunRawRouteContext as RawRouteContext, type BunServer, type BunServerConfig, type BunServerHandle, createServer, type ServerPassthrough, } from './bun';
5
5
  export { type CacheOptions, cacheHeaders, createCache } from './cache';
6
6
  export { createHandler } from './create';
7
7
  export { createErrorHook, type ErrorHookConfig, type ResolvedError, } from './error-hook';
@@ -19,7 +19,8 @@ export { createRateLimiter, type RateLimitConfig } from './rate-limit';
19
19
  export { errorResponse, parseBody, respondJson } from './raw';
20
20
  export { bindRealtimeServer, type RealtimeServer, type RealtimeServerConnection, type RealtimeServerHandle, } from './realtime';
21
21
  export { type ClientIpOptions, extractIp, generateTraceId, getClientInfo, resolveSocketIp, resolveTraceId, } from './request';
22
- export type { SocketIOServerConfig, SocketIOServerHandle } from './socket-io';
22
+ export { type ManagedServerHandle, type ShutdownOptions, ShutdownOptionsSchema, type ShutdownResult, ShutdownResultSchema, type ShutdownState, ShutdownStateSchema, type ShutdownStatus, ShutdownStatusSchema, } from './shutdown';
23
+ export type { SocketIORequestPolicy, SocketIOServerConfig, SocketIOServerHandle, SocketIOServerLifecycle, } from './socket-io';
23
24
  export { createSocketIOServer, socketIoLane } from './socket-io';
24
25
  export { type ParseSSEOptions, parseSSE, streamSSE } from './stream';
25
26
  export type { AuthorizationContext, EndpointHandlerContext, Handlers, LifecycleHooks, LoggingConfig, LogOutcome, MethodDef, MultipartFileMetadata, MultipartReceiver, MultipartReceiverResult, OperationIdentity, RouteGroup, ServiceDef, StitchLogger, StreamingMultipartImplementation, } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,KAAK,eAAe,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,SAAS,E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,EACT,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,gCAAgC,GACjC,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,YAAY,EACjB,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,aAAa,GACd,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,KAAK,eAAe,EACpB,YAAY,GACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,EACd,KAAK,eAAe,EACpB,SAAS,GACV,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EACL,KAAK,mBAAmB,IAAI,gBAAgB,EAC5C,KAAK,eAAe,IAAI,YAAY,EACpC,KAAK,gBAAgB,IAAI,aAAa,EACtC,KAAK,WAAW,IAAI,QAAQ,EAC5B,KAAK,kBAAkB,IAAI,eAAe,EAC1C,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,YAAY,GA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