stitchkit 0.52.0 → 0.53.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/http.d.ts +7 -0
  3. package/dist/browser/http.d.ts.map +1 -1
  4. package/dist/browser/socket-io.d.ts +38 -2
  5. package/dist/browser/socket-io.d.ts.map +1 -1
  6. package/dist/cli.js +2 -2
  7. package/dist/contract/errors.d.ts +13 -1
  8. package/dist/contract/errors.d.ts.map +1 -1
  9. package/dist/contract/index.js +1 -1
  10. package/dist/{index-8qghvg18.js → index-173tvqcp.js} +3 -1
  11. package/dist/{index-h55e1wyq.js → index-6j4j5wf9.js} +1 -1
  12. package/dist/{index-gff2mxzk.js → index-e1es808r.js} +4 -1
  13. package/dist/{index-psrxjvbw.js → index-gvha32jh.js} +1 -1
  14. package/dist/{index-d6jj3cp5.js → index-pdv1mjjr.js} +44 -4
  15. package/dist/{index-trz4ate5.js → index-pfqjb5xy.js} +3 -1
  16. package/dist/{index-tw7mhqgy.js → index-yez419px.js} +1 -1
  17. package/dist/{index-drsnz8gw.js → index-yydqk4fh.js} +1 -1
  18. package/dist/index.js +28 -10
  19. package/dist/node.d.ts +1 -1
  20. package/dist/node.d.ts.map +1 -1
  21. package/dist/node.js +3 -3
  22. package/dist/observability/index.js +2 -2
  23. package/dist/realtime/socket.d.ts +8 -1
  24. package/dist/realtime/socket.d.ts.map +1 -1
  25. package/dist/server/bun.d.ts +19 -0
  26. package/dist/server/bun.d.ts.map +1 -1
  27. package/dist/server/index.d.ts +2 -2
  28. package/dist/server/index.d.ts.map +1 -1
  29. package/dist/server/index.js +84 -19
  30. package/dist/server/realtime.d.ts +14 -10
  31. package/dist/server/realtime.d.ts.map +1 -1
  32. package/dist/server/socket-io-config.d.ts +45 -2
  33. package/dist/server/socket-io-config.d.ts.map +1 -1
  34. package/dist/server/socket-io-node.d.ts +5 -5
  35. package/dist/server/socket-io-node.d.ts.map +1 -1
  36. package/dist/server/socket-io.d.ts +5 -5
  37. package/dist/server/socket-io.d.ts.map +1 -1
  38. package/dist/testing.js +1 -1
  39. package/dist/tools/remote.d.ts.map +1 -1
  40. package/dist/tools.js +8 -8
  41. package/llms-full.txt +184 -28
  42. package/package.json +1 -1
@@ -12,7 +12,7 @@ import {
12
12
  parseMultipart,
13
13
  socketIoLane,
14
14
  webSocketLane
15
- } from "../index-d6jj3cp5.js";
15
+ } from "../index-pdv1mjjr.js";
16
16
  import {
17
17
  createAuthHook,
18
18
  createBearerResolver,
@@ -24,7 +24,7 @@ import {
24
24
  signJwt,
25
25
  verifyJwt,
26
26
  verifyPkce
27
- } from "../index-tw7mhqgy.js";
27
+ } from "../index-yez419px.js";
28
28
  import {
29
29
  DEFAULT_CORS_ALLOW_HEADERS,
30
30
  DEFAULT_CORS_EXPOSE_HEADERS,
@@ -38,7 +38,7 @@ import {
38
38
  defineMultipartStream,
39
39
  implement,
40
40
  implementRegistry
41
- } from "../index-drsnz8gw.js";
41
+ } from "../index-yydqk4fh.js";
42
42
  import {
43
43
  isWithinDir,
44
44
  jsonSchemaFields,
@@ -69,12 +69,45 @@ import {
69
69
  resolveTraceId,
70
70
  unauthorized,
71
71
  zodIssues
72
- } from "../index-8qghvg18.js";
72
+ } from "../index-173tvqcp.js";
73
73
  import {
74
74
  isRecord,
75
75
  parseTrailingWildcard
76
76
  } from "../index-bmnhqtya.js";
77
77
  // src/server/bun.ts
78
+ import { chmodSync, statSync, unlinkSync } from "node:fs";
79
+ function reclaimStaleUnixSocket(path) {
80
+ const stats = statSync(path, { throwIfNoEntry: false });
81
+ if (stats === undefined)
82
+ return;
83
+ if (!stats.isSocket()) {
84
+ throw new Error(`[stitchkit] createServer: "${path}" exists and is not a socket — refusing to remove it`);
85
+ }
86
+ if (typeof process.getuid === "function" && stats.uid !== process.getuid()) {
87
+ throw new Error(`[stitchkit] createServer: unix socket "${path}" is owned by another user — refusing to reclaim it`);
88
+ }
89
+ const standalone = Bun.main.startsWith("/$bunfs/");
90
+ const interpreter = standalone ? Bun.which("bun") : process.execPath;
91
+ if (!interpreter) {
92
+ throw new Error(`[stitchkit] createServer: unix socket "${path}" already exists and no \`bun\` binary is on PATH to probe it from this compiled executable — remove the file manually if the previous process is dead`);
93
+ }
94
+ const probe = Bun.spawnSync({
95
+ cmd: [
96
+ interpreter,
97
+ "-e",
98
+ 'try { const socket = await Bun.connect({ unix: Bun.env.STITCHKIT_UNIX_PROBE ?? "", socket: { data() { return undefined; } } }); socket.end(); process.exit(0); } catch (error) { process.exit(error && typeof error === "object" && "code" in error && error.code === "EACCES" ? 2 : 1); }'
99
+ ],
100
+ env: { ...process.env, STITCHKIT_UNIX_PROBE: path },
101
+ timeout: 2000
102
+ });
103
+ if (probe.exitedDueToTimeout) {
104
+ throw new Error(`[stitchkit] createServer: liveness probe for unix socket "${path}" timed out — refusing to reclaim; remove the file manually if the previous process is dead`);
105
+ }
106
+ if (probe.exitCode === 0 || probe.exitCode === 2) {
107
+ throw new Error(`[stitchkit] createServer: unix socket "${path}" is already in use${probe.exitCode === 2 ? " (connect permission denied)" : " by a live listener"}`);
108
+ }
109
+ unlinkSync(path);
110
+ }
78
111
  function createServer(config) {
79
112
  const {
80
113
  websocket: configuredWebSocket,
@@ -84,6 +117,19 @@ function createServer(config) {
84
117
  port = 3000,
85
118
  hostname
86
119
  } = config;
120
+ const unixPath = typeof config.unix === "string" ? config.unix : config.unix?.path;
121
+ const unixMode = typeof config.unix === "string" ? undefined : config.unix?.mode;
122
+ if (unixPath !== undefined) {
123
+ if (unixPath.length === 0) {
124
+ throw new Error("[stitchkit] createServer: `unix` must be a non-empty socket path");
125
+ }
126
+ if (config.port !== undefined || config.hostname !== undefined) {
127
+ throw new Error("[stitchkit] createServer: `unix` is mutually exclusive with `port`/`hostname`");
128
+ }
129
+ if (socket) {
130
+ throw new Error("[stitchkit] createServer: the Socket.IO lifecycle cannot listen on a unix socket — socket.io clients dial TCP only");
131
+ }
132
+ }
87
133
  const socketRoutePrefix = socket?.route.path.replace(/\*socketPath$/, "");
88
134
  const websocket = configuredWebSocket ?? socket?.websocket;
89
135
  const openSockets = new Set;
@@ -176,24 +222,43 @@ function createServer(config) {
176
222
  }
177
223
  return admittedFetch(request, server2);
178
224
  };
179
- runtime = trackedWebSocket ? Bun.serve({
180
- ...bunExtra,
181
- ...development && { development },
182
- port,
183
- hostname,
184
- websocket: trackedWebSocket,
185
- fetch
186
- }) : Bun.serve({
187
- ...bunExtra,
188
- ...development && { development },
189
- port,
190
- hostname,
191
- fetch
192
- });
225
+ if (unixPath !== undefined) {
226
+ reclaimStaleUnixSocket(unixPath);
227
+ const { reusePort, ipv6Only, http3, http1, idleTimeout, ...unixExtra } = bunExtra ?? {};
228
+ runtime = trackedWebSocket ? Bun.serve({
229
+ ...unixExtra,
230
+ ...development && { development },
231
+ unix: unixPath,
232
+ websocket: trackedWebSocket,
233
+ fetch
234
+ }) : Bun.serve({
235
+ ...unixExtra,
236
+ ...development && { development },
237
+ unix: unixPath,
238
+ fetch
239
+ });
240
+ if (unixMode !== undefined)
241
+ chmodSync(unixPath, unixMode);
242
+ } else {
243
+ runtime = trackedWebSocket ? Bun.serve({
244
+ ...bunExtra,
245
+ ...development && { development },
246
+ port,
247
+ hostname,
248
+ websocket: trackedWebSocket,
249
+ fetch
250
+ }) : Bun.serve({
251
+ ...bunExtra,
252
+ ...development && { development },
253
+ port,
254
+ hostname,
255
+ fetch
256
+ });
257
+ }
193
258
  const server = runtime;
194
259
  return {
195
260
  url: server.url.toString().replace(/\/$/, ""),
196
- port: server.port ?? port,
261
+ port: server.port ?? (unixPath !== undefined ? 0 : port),
197
262
  runtime: server,
198
263
  get status() {
199
264
  return lifecycle.status;
@@ -1,24 +1,28 @@
1
- import type { Socket, Server as SocketIOServer } from 'socket.io';
1
+ import type { DefaultEventsMap, Socket, Server as SocketIOServer } from 'socket.io';
2
2
  import type { SocketEventMap } from '../browser/socket-io';
3
3
  import type { StitchLogger } from '../logger';
4
4
  import type { RealtimeContract, RealtimeEventRegistry, RealtimeRejectedEventHook } from '../realtime/contract';
5
5
  import { type ValidatedRealtimeSocket } from '../realtime/socket';
6
- export interface RealtimeServerConnection<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry> {
7
- /** Raw Socket.IO socket for handshake auth, rooms and application-owned delivery policy. */
8
- raw: Socket;
6
+ export interface RealtimeServerConnection<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry, TData = any> {
7
+ /**
8
+ * Raw Socket.IO socket for rooms and application-owned delivery policy.
9
+ * `raw.data` carries the typed handshake identity when the server was
10
+ * created with a `handshake` gate.
11
+ */
12
+ raw: Socket<SocketEventMap, SocketEventMap, DefaultEventsMap, TData>;
9
13
  events: ValidatedRealtimeSocket<TClientToServer, TServerToClient>;
10
14
  to(room: string): Pick<ValidatedRealtimeSocket<RealtimeEventRegistry, TServerToClient>, 'emit'>;
11
15
  }
12
- export interface RealtimeServer<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry> {
13
- onConnection(handler: (connection: RealtimeServerConnection<TServerToClient, TClientToServer>) => void | Promise<void>): () => void;
16
+ export interface RealtimeServer<TServerToClient extends RealtimeEventRegistry, TClientToServer extends RealtimeEventRegistry, TData = any> {
17
+ onConnection(handler: (connection: RealtimeServerConnection<TServerToClient, TClientToServer, TData>) => void | Promise<void>): () => void;
14
18
  emit: ValidatedRealtimeSocket<RealtimeEventRegistry, TServerToClient>['emit'];
15
19
  to(room: string): Pick<ValidatedRealtimeSocket<RealtimeEventRegistry, TServerToClient>, 'emit'>;
16
20
  }
17
- export interface RealtimeServerHandle {
18
- io: SocketIOServer<SocketEventMap, SocketEventMap>;
21
+ export interface RealtimeServerHandle<TData = any> {
22
+ io: SocketIOServer<SocketEventMap, SocketEventMap, DefaultEventsMap, TData>;
19
23
  }
20
- export declare function bindRealtimeServer<const TServerToClient extends RealtimeEventRegistry, const TClientToServer extends RealtimeEventRegistry>(contract: RealtimeContract<TServerToClient, TClientToServer>, handle: RealtimeServerHandle, options?: {
24
+ export declare function bindRealtimeServer<const TServerToClient extends RealtimeEventRegistry, const TClientToServer extends RealtimeEventRegistry, TData = any>(contract: RealtimeContract<TServerToClient, TClientToServer>, handle: RealtimeServerHandle<TData>, options?: {
21
25
  onRejected?: RealtimeRejectedEventHook;
22
26
  logger?: StitchLogger;
23
- }): RealtimeServer<TServerToClient, TClientToServer>;
27
+ }): RealtimeServer<TServerToClient, TClientToServer, TData>;
24
28
  //# sourceMappingURL=realtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/server/realtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,wBAAwB,CACvC,eAAe,SAAS,qBAAqB,EAC7C,eAAe,SAAS,qBAAqB;IAE7C,4FAA4F;IAC5F,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,uBAAuB,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;IAClE,EAAE,CACA,IAAI,EAAE,MAAM,GACX,IAAI,CAAC,uBAAuB,CAAC,qBAAqB,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CAAC;CAClF;AAED,MAAM,WAAW,cAAc,CAC7B,eAAe,SAAS,qBAAqB,EAC7C,eAAe,SAAS,qBAAqB;IAE7C,YAAY,CACV,OAAO,EAAE,CACP,UAAU,EAAE,wBAAwB,CAAC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C,EAAE,YAAY,CAAA;CAAO,GAC9E,cAAc,CAAC,eAAe,EAAE,eAAe,EAAE,KAAK,CAAC,CAwCzD"}
@@ -1,8 +1,42 @@
1
1
  /** Runtime-neutral Socket.IO configuration shared by Bun and Node adapters. */
2
- import type { ServerOptions } from 'socket.io';
2
+ import type { ServerOptions, Socket } from 'socket.io';
3
+ import type { z } from 'zod';
3
4
  /** Runtime-neutral Engine.IO handshake policy, evaluated before shutdown admission. */
4
5
  export type SocketIORequestPolicy = (request: Request) => boolean | Promise<boolean>;
5
- export interface SocketIOServerConfig {
6
+ /**
7
+ * Typed identity gate for the Socket.IO handshake. `schema` validates
8
+ * `socket.handshake.auth` (the structured channel — `query` values are strings
9
+ * on the wire); an optional `verify` turns the parsed payload into the
10
+ * connection identity. Returning `null` or throwing rejects the handshake
11
+ * **before** the connection handler and before any event validation; the
12
+ * accepted identity is written to `socket.data`, typed end-to-end through
13
+ * `createSocketIOServer` and `bindRealtimeServer`.
14
+ *
15
+ * A rejected handshake is terminal for socket.io-client — it does **not**
16
+ * retry (unlike a transport-level denial). The stitchkit client surfaces it
17
+ * via `onConnectError` with `terminal: true`; recovery is an explicit
18
+ * `connect()`, which re-reads a function-form `auth`.
19
+ */
20
+ export interface SocketIOHandshakeConfig<TParsed, TData = TParsed> {
21
+ /** Zod schema for `socket.handshake.auth`. */
22
+ schema: z.ZodType<TParsed>;
23
+ /**
24
+ * Turn the schema-validated payload into the connection identity (may be
25
+ * async — the wrapper awaits it safely; socket.io itself would leak an
26
+ * unhandled rejection from a raw async middleware). Return `null` or throw
27
+ * to reject; a thrown error is logged server-side and the peer sees only
28
+ * the generic `handshake rejected` — raw error text never crosses to an
29
+ * unauthenticated client. When omitted, the parsed payload itself is the
30
+ * identity (when passing `TData` explicitly with `TData ≠ TParsed`,
31
+ * `verify` is therefore mandatory — without it the runtime stores the
32
+ * schema output). The `schema` must be synchronous (no async
33
+ * refine/transform).
34
+ */
35
+ verify?: (parsed: TParsed, context: {
36
+ handshake: Socket['handshake'];
37
+ }) => TData | null | Promise<TData | null>;
38
+ }
39
+ export interface SocketIOServerConfig<TParsed = any, TData = TParsed> {
6
40
  /** CORS — the browser origin(s) allowed to open a socket. */
7
41
  cors: {
8
42
  origin: string | string[];
@@ -18,6 +52,15 @@ export interface SocketIOServerConfig {
18
52
  pingInterval?: number;
19
53
  /** Runtime-neutral policy for accepting a new Engine.IO handshake. */
20
54
  allowRequest?: SocketIORequestPolicy;
55
+ /**
56
+ * Typed identity gate — Zod-validate the handshake and put the result into
57
+ * `socket.data`. Registered as the **first** `io.use()` middleware, so app
58
+ * middlewares added later see the typed identity already in place. Type
59
+ * inference works on calls without explicit event generics (the
60
+ * `bindRealtimeServer` lane); with explicit generics, pass the identity
61
+ * types explicitly: `createSocketIOServer<S, C, Parsed, Data>`.
62
+ */
63
+ handshake?: SocketIOHandshakeConfig<TParsed, TData>;
21
64
  /** Typed Socket.IO options not owned by this wrapper. */
22
65
  serverOptions?: Omit<Partial<ServerOptions>, 'allowRequest'>;
23
66
  }
@@ -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,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;IAC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A2E;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;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,yDAAyD;IACzD,aAAa,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC,CAAC;CAC9D"}
@@ -1,17 +1,17 @@
1
1
  /** Node-facing Socket.IO surface without Bun engine declarations. */
2
2
  import type { Server as HttpServer } from 'node:http';
3
- import type { Server as SocketIOServer } from 'socket.io';
3
+ import type { DefaultEventsMap, 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 { SocketIORequestPolicy, SocketIOServerConfig } from './socket-io-config';
6
+ export type { SocketIOHandshakeConfig, SocketIORequestPolicy, SocketIOServerConfig, } from './socket-io-config';
7
7
  /** The runtime-neutral part of a Socket.IO handle used by `serveNode`. */
8
- export interface NodeSocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> {
9
- io: SocketIOServer<TClientEvents, TServerEvents>;
8
+ export interface NodeSocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap, TData = any> {
9
+ io: SocketIOServer<TClientEvents, TServerEvents, DefaultEventsMap, TData>;
10
10
  attach(server: HttpServer): void;
11
11
  beginShutdown(): void;
12
12
  close(): Promise<void>;
13
13
  connections(): number;
14
14
  }
15
15
  /** Create a Socket.IO handle typed only for the Node capabilities it exposes. */
16
- export declare function createNodeSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): Promise<NodeSocketIOServerHandle<TServerEvents, TClientEvents>>;
16
+ export declare function createNodeSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap, TParsed = any, TData = TParsed>(config: SocketIOServerConfig<TParsed, TData>): Promise<NodeSocketIOServerHandle<TServerEvents, TClientEvents, TData>>;
17
17
  //# sourceMappingURL=socket-io-node.d.ts.map
@@ -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,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEtF,0EAA0E;AAC1E,MAAM,WAAW,wBAAwB,CACvC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc;IAEpC,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACjD,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,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"}
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,gBAAgB,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,YAAY,EACV,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,0EAA0E;AAC1E,MAAM,WAAW,wBAAwB,CACvC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,KAAK,GAAG,GAAG;IAEX,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAC1E,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,iFAAiF;AACjF,wBAAsB,wBAAwB,CAC5C,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EAGpC,OAAO,GAAG,GAAG,EACb,KAAK,GAAG,OAAO,EAEf,MAAM,EAAE,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,GAC3C,OAAO,CAAC,wBAAwB,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CAExE"}
@@ -17,13 +17,13 @@
17
17
  */
18
18
  import type { Server as HttpServer } from 'node:http';
19
19
  import type { Server as BunEngine } from '@socket.io/bun-engine';
20
- import type { Server as SocketIOServer } from 'socket.io';
20
+ import type { DefaultEventsMap, Server as SocketIOServer } from 'socket.io';
21
21
  import type { SocketEventMap } from '../browser/socket-io';
22
22
  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 { SocketIORequestPolicy, SocketIOServerConfig } from './socket-io-config';
26
+ export type { SocketIOHandshakeConfig, SocketIORequestPolicy, SocketIOServerConfig, } from './socket-io-config';
27
27
  export interface SocketIOServerLifecycle {
28
28
  /**
29
29
  * WebSocket handler for `Bun.serve({ websocket })`. Real on Bun; on Node it is
@@ -52,11 +52,11 @@ export interface SocketIOServerLifecycle {
52
52
  /** Current Engine.IO client count, when the engine has been bound. */
53
53
  connections(): number;
54
54
  }
55
- export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap> extends SocketIOServerLifecycle {
55
+ export interface SocketIOServerHandle<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap, TData = any> extends SocketIOServerLifecycle {
56
56
  /** The typed Socket.IO server — attach `io.on('connection', ...)` handlers. */
57
- io: SocketIOServer<TClientEvents, TServerEvents>;
57
+ io: SocketIOServer<TClientEvents, TServerEvents, DefaultEventsMap, TData>;
58
58
  }
59
- export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOServerConfig): Promise<SocketIOServerHandle<TServerEvents, TClientEvents>>;
59
+ export declare function createSocketIOServer<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap, TParsed = any, TData = TParsed>(config: SocketIOServerConfig<TParsed, TData>): Promise<SocketIOServerHandle<TServerEvents, TClientEvents, TData>>;
60
60
  /**
61
61
  * Wrap a Socket.IO handle's `websocket` as a catch-all {@link ComposedLane} for
62
62
  * {@link composeWebSocketHandlers} — when a second, raw WebSocket lane shares
@@ -1 +1 @@
1
- {"version":3,"file":"socket-io.d.ts","sourceRoot":"","sources":["../../src/server/socket-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,MAAM,I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,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,sEAAsE;IACtE,WAAW,IAAI,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB,CACnC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,KAAK,GAAG,GAAG,CACX,SAAQ,uBAAuB;IAC/B,+EAA+E;IAC/E,EAAE,EAAE,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;CAC3E;AA8GD,wBAAsB,oBAAoB,CACxC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EAKpC,OAAO,GAAG,GAAG,EACb,KAAK,GAAG,OAAO,EAEf,MAAM,EAAE,oBAAoB,CAAC,OAAO,EAAE,KAAK,CAAC,GAC3C,OAAO,CAAC,oBAAoB,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,CA6IpE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,oBAAoB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,WAAW,CAAC,GAC3E,YAAY,CAMd"}
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createClient,
3
3
  createClients
4
- } from "./index-gff2mxzk.js";
4
+ } from "./index-e1es808r.js";
5
5
  import"./index-48ffdxgk.js";
6
6
  import"./index-bmnhqtya.js";
7
7
 
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/tools/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAiB7D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,C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
  verifyPkce
4
- } from "./index-tw7mhqgy.js";
4
+ } from "./index-yez419px.js";
5
5
  import {
6
6
  DEFAULT_CORS_ALLOW_HEADERS,
7
7
  contractOnlyService
8
- } from "./index-drsnz8gw.js";
8
+ } from "./index-yydqk4fh.js";
9
9
  import {
10
10
  assertToolName,
11
11
  assertUniqueToolName,
@@ -26,7 +26,7 @@ import {
26
26
  toolErrorFromResult,
27
27
  toolResultFromError,
28
28
  writeDownload
29
- } from "./index-h55e1wyq.js";
29
+ } from "./index-6j4j5wf9.js";
30
30
  import {
31
31
  isWithinDir,
32
32
  realPathWithinDir,
@@ -35,18 +35,18 @@ import {
35
35
  import {
36
36
  ApiError,
37
37
  createClient
38
- } from "./index-gff2mxzk.js";
38
+ } from "./index-e1es808r.js";
39
39
  import"./index-48ffdxgk.js";
40
40
  import {
41
41
  redact
42
- } from "./index-psrxjvbw.js";
42
+ } from "./index-gvha32jh.js";
43
43
  import {
44
44
  AppError,
45
45
  getRequestContext,
46
46
  getTraceId,
47
47
  mergeMeta,
48
48
  runWithRequestContext
49
- } from "./index-8qghvg18.js";
49
+ } from "./index-173tvqcp.js";
50
50
  import {
51
51
  isRecord,
52
52
  resolvePropagationContext
@@ -2214,12 +2214,12 @@ function implementRemote(contract, http, options) {
2214
2214
  throw new Error(`implementRemote: endpoint "${key}" is not exposed over HTTP`);
2215
2215
  }
2216
2216
  const args = toArgs(ctx);
2217
- const finalArgs = options?.transformArgs ? await options.transformArgs(key, args) : args;
2218
2217
  try {
2218
+ const finalArgs = options?.transformArgs ? await options.transformArgs(key, args) : args;
2219
2219
  return await call(finalArgs);
2220
2220
  } catch (err) {
2221
2221
  if (ApiError.is(err)) {
2222
- throw new AppError(err.code, err.message, err.status, isRecord(err.details) ? err.details : undefined, err.hint);
2222
+ throw new AppError(err.code, err.message, err.status, isRecord(err.details) ? err.details : undefined, err.hint, err.traceId);
2223
2223
  }
2224
2224
  throw err;
2225
2225
  }