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.
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
+ forceTimeoutMs: z.number().int().nonnegative().default(5000),
1413
+ retryAfterSeconds: z.number().int().nonnegative().default(5),
1414
+ signal: z.custom((value) => typeof value === "object" && value !== null && ("aborted" in value) && ("addEventListener" in value), "Expected an AbortSignal").optional()
1415
+ });
1416
+ var ShutdownStatusSchema = z.object({
1417
+ state: ShutdownStateSchema,
1418
+ acceptedRequests: z.number().int().nonnegative(),
1419
+ completedRequests: z.number().int().nonnegative(),
1420
+ pendingRequests: z.number().int().nonnegative(),
1421
+ pendingWebSockets: z.number().int().nonnegative()
1422
+ });
1423
+ var ShutdownResultSchema = z.object({
1424
+ outcome: z.enum(["clean", "forced"]),
1425
+ reason: z.enum(["deadline", "signal"]).optional(),
1426
+ acceptedRequests: z.number().int().nonnegative(),
1427
+ completedRequests: z.number().int().nonnegative(),
1428
+ pendingRequests: z.number().int().nonnegative(),
1429
+ pendingWebSockets: z.number().int().nonnegative(),
1430
+ pendingRequestsAtForce: z.number().int().nonnegative(),
1431
+ pendingWebSocketsAtForce: z.number().int().nonnegative(),
1432
+ abortedRequests: z.number().int().nonnegative(),
1433
+ forcedWebSockets: z.number().int().nonnegative(),
1434
+ durationMs: z.number().nonnegative()
1435
+ });
1436
+ function rejectedResponse(retryAfterSeconds) {
1437
+ return Response.json({ error: { code: "SERVER_SHUTTING_DOWN", message: "Server is shutting down" } }, {
1438
+ status: 503,
1439
+ headers: {
1440
+ Connection: "close",
1441
+ "Retry-After": String(retryAfterSeconds)
1442
+ }
1443
+ });
1444
+ }
1445
+ function waitForZero(read, signal) {
1446
+ if (read() === 0)
1447
+ return Promise.resolve();
1448
+ return new Promise((resolve) => {
1449
+ const check = () => {
1450
+ if (read() === 0 || signal.aborted) {
1451
+ clearInterval(timer);
1452
+ signal.removeEventListener("abort", check);
1453
+ resolve();
1454
+ }
1455
+ };
1456
+ const timer = setInterval(check, 5);
1457
+ signal.addEventListener("abort", check, { once: true });
1458
+ });
1459
+ }
1460
+ function untilAbort(signal) {
1461
+ if (signal.aborted)
1462
+ return Promise.resolve();
1463
+ return new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
1464
+ }
1465
+ function withTimeout(promise, timeoutMs, message) {
1466
+ return new Promise((resolve, reject) => {
1467
+ const timer = setTimeout(() => reject(new Error(message)), timeoutMs);
1468
+ promise.then((value) => {
1469
+ clearTimeout(timer);
1470
+ resolve(value);
1471
+ }, (error) => {
1472
+ clearTimeout(timer);
1473
+ reject(error);
1474
+ });
1475
+ });
1476
+ }
1477
+ function createServerLifecycle(getAdapter) {
1478
+ let state = "running";
1479
+ let acceptedRequests = 0;
1480
+ let completedRequests = 0;
1481
+ let pendingApplicationRequests = 0;
1482
+ let retryAfterSeconds = 5;
1483
+ let shutdownPromise;
1484
+ const status = () => {
1485
+ const adapter = getAdapter();
1486
+ return ShutdownStatusSchema.parse({
1487
+ state,
1488
+ acceptedRequests,
1489
+ completedRequests,
1490
+ pendingRequests: adapter.pendingRequests(),
1491
+ pendingWebSockets: adapter.pendingWebSockets()
1492
+ });
1493
+ };
1494
+ const wrapFetch = (handler) => {
1495
+ return async (request, server) => {
1496
+ if (state !== "running")
1497
+ return rejectedResponse(retryAfterSeconds);
1498
+ acceptedRequests += 1;
1499
+ pendingApplicationRequests += 1;
1500
+ try {
1501
+ return await handler(request, server);
1502
+ } finally {
1503
+ pendingApplicationRequests -= 1;
1504
+ completedRequests += 1;
1505
+ }
1506
+ };
1507
+ };
1508
+ const shutdown = (options) => {
1509
+ if (shutdownPromise)
1510
+ return shutdownPromise;
1511
+ const parsed = ShutdownOptionsSchema.parse(options ?? {});
1512
+ retryAfterSeconds = parsed.retryAfterSeconds;
1513
+ const startedAt = performance.now();
1514
+ const adapter = getAdapter();
1515
+ state = "draining-http";
1516
+ adapter.beginShutdown(retryAfterSeconds);
1517
+ shutdownPromise = new Promise((resolve, reject) => {
1518
+ const phaseAbort = new AbortController;
1519
+ let forcedReason;
1520
+ let phaseError;
1521
+ const force = (reason) => {
1522
+ if (forcedReason)
1523
+ return;
1524
+ forcedReason = reason;
1525
+ phaseAbort.abort();
1526
+ };
1527
+ const timer = setTimeout(() => force("deadline"), parsed.gracePeriodMs);
1528
+ const onExternalAbort = () => force("signal");
1529
+ parsed.signal?.addEventListener("abort", onExternalAbort, { once: true });
1530
+ if (parsed.signal?.aborted)
1531
+ force("signal");
1532
+ const cleanup = () => {
1533
+ clearTimeout(timer);
1534
+ parsed.signal?.removeEventListener("abort", onExternalAbort);
1535
+ };
1536
+ (async () => {
1537
+ try {
1538
+ await waitForZero(() => pendingApplicationRequests, phaseAbort.signal);
1539
+ if (!forcedReason) {
1540
+ state = "closing-realtime";
1541
+ await Promise.race([adapter.closeRealtime(), untilAbort(phaseAbort.signal)]);
1542
+ }
1543
+ if (!forcedReason) {
1544
+ state = "stopping-runtime";
1545
+ await Promise.race([adapter.stopGracefully(), untilAbort(phaseAbort.signal)]);
1546
+ }
1547
+ } catch (error) {
1548
+ if (!forcedReason) {
1549
+ phaseError = error;
1550
+ force("error");
1551
+ }
1552
+ }
1553
+ let pendingRequestsAtForce = 0;
1554
+ let pendingWebSocketsAtForce = 0;
1555
+ if (forcedReason) {
1556
+ state = "stopping-runtime";
1557
+ pendingRequestsAtForce = adapter.pendingRequests();
1558
+ pendingWebSocketsAtForce = adapter.pendingWebSockets();
1559
+ let forceError;
1560
+ let forceFailed = false;
1561
+ try {
1562
+ await withTimeout(adapter.forceStop(), parsed.forceTimeoutMs, `[stitchkit] forced shutdown did not complete within ${parsed.forceTimeoutMs}ms`);
1563
+ } catch (error) {
1564
+ forceFailed = true;
1565
+ forceError = error;
1566
+ } finally {
1567
+ state = "forced";
1568
+ }
1569
+ if (forcedReason === "error") {
1570
+ if (forceFailed) {
1571
+ throw new AggregateError([phaseError, forceError], "[stitchkit] graceful shutdown failed and forced cleanup also failed", { cause: phaseError });
1572
+ }
1573
+ throw phaseError;
1574
+ }
1575
+ if (forceFailed)
1576
+ throw forceError;
1577
+ } else {
1578
+ state = "clean";
1579
+ }
1580
+ cleanup();
1581
+ resolve(ShutdownResultSchema.parse({
1582
+ outcome: forcedReason ? "forced" : "clean",
1583
+ ...forcedReason && { reason: forcedReason },
1584
+ acceptedRequests,
1585
+ completedRequests,
1586
+ pendingRequests: adapter.pendingRequests(),
1587
+ pendingWebSockets: adapter.pendingWebSockets(),
1588
+ pendingRequestsAtForce,
1589
+ pendingWebSocketsAtForce,
1590
+ abortedRequests: pendingRequestsAtForce,
1591
+ forcedWebSockets: pendingWebSocketsAtForce,
1592
+ durationMs: performance.now() - startedAt
1593
+ }));
1594
+ })().catch((error) => {
1595
+ cleanup();
1596
+ reject(error);
1597
+ });
1598
+ });
1599
+ return shutdownPromise;
1600
+ };
1601
+ return {
1602
+ wrapFetch,
1603
+ get status() {
1604
+ return status();
1605
+ },
1606
+ shutdown
1607
+ };
1608
+ }
1609
+
1400
1610
  // src/server/implement.ts
1401
1611
  function isStreamingImplementation(value) {
1402
1612
  return typeof value === "object" && value !== null && "kind" in value && value.kind === "stitchkit.multipart.stream";
@@ -1525,9 +1735,9 @@ function createImplementRegistry() {
1525
1735
  }
1526
1736
 
1527
1737
  // src/realtime/rejection.ts
1528
- import { z } from "zod";
1738
+ import { z as z2 } from "zod";
1529
1739
  function realtimeContractViolation(options) {
1530
- const issues = options.cause instanceof z.ZodError ? zodIssues(options.cause) : undefined;
1740
+ const issues = options.cause instanceof z2.ZodError ? zodIssues(options.cause) : undefined;
1531
1741
  const reason = options.reason.replaceAll("-", " ");
1532
1742
  const error = new AppError("REALTIME_CONTRACT_VIOLATION", `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`, 500, {
1533
1743
  event: options.event,
@@ -1832,6 +2042,34 @@ async function createSocketIOServer(config) {
1832
2042
  credentials: config.cors.credentials ?? true,
1833
2043
  methods: ["GET", "POST"]
1834
2044
  };
2045
+ let accepting = true;
2046
+ let attached = false;
2047
+ let closePromise;
2048
+ const consumerAllowRequest = config.allowRequest;
2049
+ const checkRequest = async (request) => {
2050
+ if (consumerAllowRequest && !await consumerAllowRequest(request)) {
2051
+ throw new Error("Request rejected by the configured Socket.IO policy");
2052
+ }
2053
+ if (!accepting)
2054
+ throw new Error("Server is shutting down");
2055
+ };
2056
+ const allowRequest = (request, done) => {
2057
+ const headers = new Headers;
2058
+ for (const [name, value] of Object.entries(request.headers)) {
2059
+ if (Array.isArray(value)) {
2060
+ for (const item of value)
2061
+ headers.append(name, item);
2062
+ } else if (value !== undefined) {
2063
+ headers.set(name, value);
2064
+ }
2065
+ }
2066
+ const host = headers.get("host") ?? "localhost";
2067
+ const webRequest = new Request(new URL(request.url ?? "/", `http://${host}`), {
2068
+ method: request.method,
2069
+ headers
2070
+ });
2071
+ checkRequest(webRequest).then(() => done(null, true), (error) => done(error instanceof Error ? error.message : "Request rejected", false));
2072
+ };
1835
2073
  const { Server } = await importPeer(() => import("socket.io"), "socket.io");
1836
2074
  const io = new Server({
1837
2075
  ...config.serverOptions,
@@ -1839,15 +2077,31 @@ async function createSocketIOServer(config) {
1839
2077
  cors,
1840
2078
  transports,
1841
2079
  pingTimeout,
1842
- pingInterval
2080
+ pingInterval,
2081
+ allowRequest
1843
2082
  });
2083
+ const lifecycle = {
2084
+ beginShutdown() {
2085
+ accepting = false;
2086
+ },
2087
+ close() {
2088
+ if (closePromise)
2089
+ return closePromise;
2090
+ closePromise = onBun || attached ? io.close() : Promise.resolve();
2091
+ return closePromise;
2092
+ },
2093
+ connections() {
2094
+ return io.engine?.clientsCount ?? 0;
2095
+ }
2096
+ };
1844
2097
  if (onBun) {
1845
2098
  const { Server: Engine } = await importPeer(() => import("@socket.io/bun-engine"), "@socket.io/bun-engine");
1846
2099
  const engineOpts = {
1847
2100
  path,
1848
2101
  cors,
1849
2102
  pingTimeout,
1850
- pingInterval
2103
+ pingInterval,
2104
+ allowRequest: checkRequest
1851
2105
  };
1852
2106
  if (config.serverOptions?.maxHttpBufferSize !== undefined) {
1853
2107
  engineOpts.maxHttpBufferSize = config.serverOptions.maxHttpBufferSize;
@@ -1868,11 +2122,14 @@ async function createSocketIOServer(config) {
1868
2122
  return engine.handleRequest(req, ctx.server);
1869
2123
  }
1870
2124
  };
1871
- return { io, websocket, route, attach: noop };
2125
+ return { io, websocket, route, attach: noop, ...lifecycle };
1872
2126
  }
1873
2127
  return {
1874
2128
  io,
1875
- attach: (server) => io.attach(server),
2129
+ attach: (server) => {
2130
+ io.attach(server);
2131
+ attached = true;
2132
+ },
1876
2133
  websocket: { open: noop, message: noop, close: noop, maxPayloadLength: 0 },
1877
2134
  route: {
1878
2135
  method: "ALL",
@@ -1880,7 +2137,8 @@ async function createSocketIOServer(config) {
1880
2137
  handler: () => {
1881
2138
  throw new Error("[stitchkit] On Node, Socket.IO attaches via serveNode({ socket }) — this route is not mounted.");
1882
2139
  }
1883
- }
2140
+ },
2141
+ ...lifecycle
1884
2142
  };
1885
2143
  }
1886
2144
  function socketIoLane(websocket) {
@@ -1890,4 +2148,4 @@ function socketIoLane(websocket) {
1890
2148
  });
1891
2149
  }
1892
2150
 
1893
- export { parseMultipart, createHandler, defineMultipartStream, implement, createImplement, implementRegistry, createImplementRegistry, bindRealtimeServer, webSocketLane, composeWebSocketHandlers, createSocketIOServer, socketIoLane };
2151
+ 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":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,SAAS,EACT,iBAAiB,EACjB,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,wBAAwB,IAAI,oBAAoB,EAChD,KAAK,wBAAwB,IAAI,oBAAoB,EACrD,KAAK,oBAAoB,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,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-z992nfbx.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,CAA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,SAAS,CAAC,CAAC;AAE7D,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAyIrE"}
@@ -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,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,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,GAClB,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AO,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,eAAe,EACpB,SAAS,EACT,eAAe,EACf,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,KAAK,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,QAAQ,EACR,cAAc,EACd,aAAa,EACb,UAAU,EACV,SAAS,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,KAA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