@solidjs/web 2.0.0-rc.1 → 2.0.0-rc.3

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 (84) hide show
  1. package/dist/dev.cjs +116 -66
  2. package/dist/dev.js +109 -65
  3. package/dist/server.cjs +386 -109
  4. package/dist/server.js +378 -113
  5. package/dist/web.cjs +113 -64
  6. package/dist/web.js +106 -63
  7. package/frames/dist/client.cjs +100 -14
  8. package/frames/dist/client.dev.cjs +103 -14
  9. package/frames/dist/client.dev.js +104 -15
  10. package/frames/dist/client.js +101 -15
  11. package/frames/dist/server.cjs +285 -154
  12. package/frames/dist/server.js +287 -156
  13. package/package.json +20 -22
  14. package/serialization/dist/decode.cjs +22 -5
  15. package/serialization/dist/decode.js +23 -6
  16. package/serialization/dist/serialization.cjs +26 -13
  17. package/serialization/dist/serialization.js +26 -8
  18. package/serialization/types/index.d.ts +69 -157
  19. package/serialization/types/serializer-decode.d.ts +89 -112
  20. package/serialization/types/serializer.d.ts +94 -0
  21. package/serialization/types-cjs/index.d.cts +69 -157
  22. package/serialization/types-cjs/serializer-decode.d.cts +89 -112
  23. package/serialization/types-cjs/serializer.d.cts +94 -0
  24. package/server-functions/dist/client.cjs +48 -7
  25. package/server-functions/dist/client.js +48 -8
  26. package/server-functions/dist/server.cjs +76 -5
  27. package/server-functions/dist/server.dev.cjs +76 -5
  28. package/server-functions/dist/server.dev.js +76 -6
  29. package/server-functions/dist/server.js +76 -6
  30. package/types/client.d.ts +150 -290
  31. package/types/constants.d.ts +18 -0
  32. package/types/cookies.d.ts +31 -75
  33. package/types/frames/frame-client.d.ts +287 -259
  34. package/types/frames/frame-container-plugin.d.ts +71 -0
  35. package/types/frames/frame-sink.d.ts +58 -160
  36. package/types/frames/frame-transport.d.ts +161 -194
  37. package/types/frames/serializer-decode.d.ts +159 -0
  38. package/types/frames/serializer.d.ts +69 -157
  39. package/types/head.d.ts +16 -0
  40. package/types/index.d.ts +0 -65
  41. package/types/index.server.d.ts +125 -0
  42. package/types/jsx.d.ts +5 -13
  43. package/types/reconcile.d.ts +1 -0
  44. package/types/render.d.ts +4 -0
  45. package/types/response.d.ts +41 -153
  46. package/types/serializer-decode.d.ts +89 -112
  47. package/types/serializer.d.ts +69 -157
  48. package/types/server-functions/client.d.ts +101 -199
  49. package/types/server-functions/flash.d.ts +10 -30
  50. package/types/server-functions/registry.d.ts +63 -0
  51. package/types/server-functions/rich-args.d.ts +1 -10
  52. package/types/server-functions/server.d.ts +301 -518
  53. package/types/server-functions/shared.d.ts +112 -458
  54. package/types/server-mock.d.ts +13 -4
  55. package/types/server.d.ts +256 -427
  56. package/types-cjs/client.d.cts +150 -290
  57. package/types-cjs/constants.d.cts +18 -0
  58. package/types-cjs/cookies.d.cts +31 -75
  59. package/types-cjs/frames/frame-client.d.cts +287 -259
  60. package/types-cjs/frames/frame-container-plugin.d.cts +71 -0
  61. package/types-cjs/frames/frame-sink.d.cts +58 -160
  62. package/types-cjs/frames/frame-transport.d.cts +161 -194
  63. package/types-cjs/frames/serializer-decode.d.cts +159 -0
  64. package/types-cjs/frames/serializer.d.cts +69 -157
  65. package/types-cjs/head.d.cts +16 -0
  66. package/types-cjs/index.d.cts +0 -65
  67. package/types-cjs/index.server.d.cts +125 -0
  68. package/types-cjs/jsx.d.cts +5 -13
  69. package/types-cjs/reconcile.d.cts +1 -0
  70. package/types-cjs/render.d.cts +4 -0
  71. package/types-cjs/response.d.cts +41 -153
  72. package/types-cjs/serializer-decode.d.cts +89 -112
  73. package/types-cjs/serializer.d.cts +69 -157
  74. package/types-cjs/server-functions/client.d.cts +101 -199
  75. package/types-cjs/server-functions/flash.d.cts +10 -30
  76. package/types-cjs/server-functions/registry.d.cts +63 -0
  77. package/types-cjs/server-functions/rich-args.d.cts +1 -10
  78. package/types-cjs/server-functions/server.d.cts +301 -518
  79. package/types-cjs/server-functions/shared.d.cts +112 -458
  80. package/types-cjs/server-mock.d.cts +13 -4
  81. package/types-cjs/server.d.cts +256 -427
  82. package/LICENSE +0 -21
  83. package/types/core.d.ts +0 -6
  84. package/types-cjs/core.d.cts +0 -6
@@ -1,35 +1,10 @@
1
+ export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, isServerFunction, subscribeFlightData, withMeta } from "./shared.cjs";
2
+ export { decodeFlashCookie, encodeFlashCookie } from "./flash.cjs";
1
3
  import { ResponseEnvelope } from "../response.cjs";
2
4
  import { JSONCodecOptions } from "../serializer-decode.cjs";
3
5
  import { RequestEvent } from "../server.cjs";
4
-
5
- export {
6
- ERROR_HEADER,
7
- FLASH_COOKIE,
8
- FUNCTION_HEADER,
9
- INSTANCE_HEADER,
10
- SINGLE_FLIGHT_HEADER,
11
- clearFlashCookie,
12
- decodeErrorHeaderValue,
13
- decodeResponse,
14
- decodeResponsePayload,
15
- encodeErrorHeaderValue,
16
- getServerFunctionMetadata,
17
- hasFlashCookie,
18
- isServerFunction,
19
- subscribeFlightData,
20
- withMeta
21
- } from "./shared.cjs";
22
- export type {
23
- FlightDataConsumer,
24
- FlightDataContext,
25
- ServerFunction,
26
- ServerFunctionMetadata,
27
- SingleFlightPayload
28
- } from "./shared.cjs";
29
- export { decodeFlashCookie, encodeFlashCookie } from "./flash.cjs";
6
+ export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
30
7
  export type { FlashSubmission } from "./flash.cjs";
31
- import { ServerFunction } from "./shared.cjs";
32
-
33
8
  /**
34
9
  * The request event a server function call runs under: the base
35
10
  * `RequestEvent` (request + locals) with `serverOnly` added, set when the
@@ -37,64 +12,62 @@ import { ServerFunction } from "./shared.cjs";
37
12
  * client.
38
13
  */
39
14
  export interface ServerFunctionEvent extends RequestEvent {
40
- serverOnly?: boolean;
15
+ serverOnly?: boolean;
41
16
  }
42
-
43
17
  /**
44
18
  * What a server function call resolved to, as seen by the single-flight
45
19
  * hook — enough context for any data-production strategy without core
46
20
  * assuming one.
47
21
  */
48
22
  export interface ServerFunctionOutcome {
49
- /** The build-stable id of the function that ran. */
50
- id: string;
51
- /**
52
- * The value the caller will receive: the raw return for plain results,
53
- * the unwrapped `value` for `ResponseEnvelope`s, `null` for body-less
54
- * control-flow `Response`s (redirect/reload).
55
- */
56
- value: unknown;
57
- /**
58
- * The `Response` carrying the result's HTTP metadata, when there is one
59
- * (from a returned/thrown `Response` or a `ResponseEnvelope`). Read
60
- * `Location` here for redirect-with-data — the data should describe the
61
- * destination route — and `X-Revalidate` for the invalidated keys.
62
- * Undefined for plain values.
63
- */
64
- response: Response | undefined;
65
- /**
66
- * The original HTTP request, untouched: headers the client integration
67
- * sent (referrer, custom route context) ride here for the hook to read —
68
- * core assigns them no meaning.
69
- */
70
- request: Request;
71
- /** Whether the result was thrown rather than returned. */
72
- thrown: boolean;
73
- /**
74
- * The URL the client will show after the mutation — the redirect
75
- * `Location` when the outcome carries one (resolved against the request
76
- * URL, as a browser would), the referring page otherwise. Undefined
77
- * without a usable referer (a non-browser caller has no page to produce
78
- * data for) and for redirects leaving the app's origin: produce no data
79
- * when this is undefined.
80
- */
81
- targetUrl: string | undefined;
82
- /**
83
- * The outcome's `X-Revalidate` keys, split — the invalidation scope the
84
- * mutation declared. Undefined when the outcome carries none (integrations
85
- * typically collect everything for the target in that case).
86
- */
87
- revalidateKeys: string[] | undefined;
88
- /**
89
- * The request headers with the mutation's cookie effects applied: the
90
- * event response's `Set-Cookie`s (set during the call), then the
91
- * outcome's own (e.g. `redirect(to, { headers })`), later winning on
92
- * conflict, deletions honored. Build the data-collection request from
93
- * these so re-run reads observe post-mutation cookie state.
94
- */
95
- foldedHeaders: Headers;
23
+ /** The build-stable id of the function that ran. */
24
+ id: string;
25
+ /**
26
+ * The value the caller will receive: the raw return for plain results,
27
+ * the unwrapped `value` for `ResponseEnvelope`s, `null` for body-less
28
+ * control-flow `Response`s (redirect/reload).
29
+ */
30
+ value: unknown;
31
+ /**
32
+ * The `Response` carrying the result's HTTP metadata, when there is one
33
+ * (from a returned/thrown `Response` or a `ResponseEnvelope`). Read
34
+ * `Location` here for redirect-with-data — the data should describe the
35
+ * destination route — and `X-Revalidate` for the invalidated keys.
36
+ * Undefined for plain values.
37
+ */
38
+ response: Response | undefined;
39
+ /**
40
+ * The original HTTP request, untouched: headers the client integration
41
+ * sent (referrer, custom route context) ride here for the hook to read —
42
+ * core assigns them no meaning.
43
+ */
44
+ request: Request;
45
+ /** Whether the result was thrown rather than returned. */
46
+ thrown: boolean;
47
+ /**
48
+ * The URL the client will show after the mutation — the redirect
49
+ * `Location` when the outcome carries one (resolved against the request
50
+ * URL, as a browser would), the referring page otherwise. Undefined
51
+ * without a usable referer (a non-browser caller has no page to produce
52
+ * data for) and for redirects leaving the app's origin: produce no data
53
+ * when this is undefined.
54
+ */
55
+ targetUrl: string | undefined;
56
+ /**
57
+ * The outcome's `X-Revalidate` keys, split — the invalidation scope the
58
+ * mutation declared. Undefined when the outcome carries none (integrations
59
+ * typically collect everything for the target in that case).
60
+ */
61
+ revalidateKeys: string[] | undefined;
62
+ /**
63
+ * The request headers with the mutation's cookie effects applied: the
64
+ * event response's `Set-Cookie`s (set during the call), then the
65
+ * outcome's own (e.g. `redirect(to, { headers })`), later winning on
66
+ * conflict, deletions honored. Build the data-collection request from
67
+ * these so re-run reads observe post-mutation cookie state.
68
+ */
69
+ foldedHeaders: Headers;
96
70
  }
97
-
98
71
  /**
99
72
  * The single-flight server hook: given the request event and the function's
100
73
  * outcome, optionally produce a data payload (possibly async) to fold into
@@ -114,11 +87,7 @@ export interface ServerFunctionOutcome {
114
87
  * pre-digested on the outcome (`targetUrl`, `revalidateKeys`,
115
88
  * `foldedHeaders`); the hook supplies only the data strategy.
116
89
  */
117
- export type CollectFlightDataHook = (
118
- event: ServerFunctionEvent,
119
- outcome: ServerFunctionOutcome
120
- ) => unknown | Promise<unknown>;
121
-
90
+ export type CollectFlightDataHook = (event: ServerFunctionEvent, outcome: ServerFunctionOutcome) => unknown | Promise<unknown>;
122
91
  /**
123
92
  * Wraps a server function execution — the per-invocation seam for
124
93
  * framework policies (per-function middleware, auth, logging, error
@@ -135,174 +104,130 @@ export type CollectFlightDataHook = (
135
104
  * return `run()`'s value, not an unconditional promise, unless it needs to
136
105
  * be async.
137
106
  */
138
- export type WrapInvocationHook = (
139
- run: () => unknown,
140
- context: {
107
+ export type WrapInvocationHook = (run: () => unknown, context: {
141
108
  id: string;
142
109
  args: unknown[];
143
110
  event: ServerFunctionEvent;
144
111
  request?: Request;
145
112
  direct: boolean;
146
- }
147
- ) => unknown;
148
-
149
- /**
150
- * Request headers with `setCookies` folded into the `Cookie` header, as the
151
- * browser would have applied them before its next request. Later entries
152
- * win on conflict, and deletions are honored (`Max-Age` at or below zero,
153
- * `Expires` in the past). The input headers are not modified.
154
- *
155
- * For work re-run on the server after a mutation — a
156
- * `CollectFlightDataHook` gathering fresh data, typically. That pass starts
157
- * from the request that triggered the mutation, whose cookies are
158
- * pre-mutation by definition, so a read depending on a session the mutation
159
- * just established would otherwise see the old state. Which responses
160
- * contribute their `Set-Cookie`s, and in what order, is the caller's
161
- * decision.
162
- *
163
- * @example
164
- * ```ts
165
- * const headers = foldSetCookies(event.request.headers, [
166
- * ...(event.response?.headers?.getSetCookie() ?? []),
167
- * ...(outcome.response?.headers?.getSetCookie() ?? [])
168
- * ]);
169
- * ```
170
- */
171
- export function foldSetCookies(headers: Headers, setCookies: readonly string[]): Headers;
172
-
113
+ }) => unknown;
173
114
  /** Options for `createNoJSHandler`. */
174
115
  export interface NoJSHandlerOptions {
175
- /** The app's mount path, for resolving a relative redirect `Location`. */
176
- base?: string;
116
+ /** The app's mount path, for resolving a relative redirect `Location`. */
117
+ base?: string;
118
+ }
119
+ export type ServerFunctionOriginMatcher = string | readonly string[] | ((origin: string, request: Request) => boolean | Promise<boolean>);
120
+ /** Same-origin validation options for server function requests. */
121
+ export interface ServerFunctionCSRFOptions {
122
+ /**
123
+ * Expected public origin. Defaults to the incoming request URL's origin.
124
+ * A function can validate origins dynamically for multi-tenant hosts.
125
+ */
126
+ origin?: ServerFunctionOriginMatcher;
127
+ /**
128
+ * Allows requests without `Sec-Fetch-Site`, `Origin`, or `Referer`.
129
+ * Cross-origin metadata is still rejected.
130
+ * @default false
131
+ */
132
+ allowRequestsWithoutOriginCheck?: boolean;
177
133
  }
178
-
179
- /**
180
- * Builds the `handleNoJS` implementation for the no-JS form convention: a
181
- * form posted without the client runtime has no way to receive a value, so
182
- * the call redirects back to the referring page (or to the result's own
183
- * `Location`, resolved against `base`) with the outcome riding a one-shot
184
- * flash cookie. `303 See Other` turns the POST into a GET unless the result
185
- * names a redirect status of its own. A result that is already a `Response`
186
- * carries its meaning in its metadata and is not flashed.
187
- *
188
- * The render that follows reads the cookie with `decodeFlashCookie` and
189
- * surfaces the outcome however it likes — that half is the integration's.
190
- *
191
- * The handler applies to every call it receives. `handleServerFunctionRequest`
192
- * already uses it for browser form posts, so wire it explicitly only to set
193
- * a `base`, or to extend the convention to direct HTTP calls by registering
194
- * it through `configureServerFunctionsServer`.
195
- */
196
- export function createNoJSHandler(
197
- options?: NoJSHandlerOptions
198
- ): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
199
-
200
134
  /** Options for `configureServerFunctionsServer`. */
201
135
  export interface ServerFunctionsServerConfig {
202
- /**
203
- * Establishes the request-event scope for a call — the function passed
204
- * runs with `event` visible to `getRequestEvent()`. Wire it to
205
- * `provideRequestEvent` from `@solidjs/web/storage` (or the framework's
206
- * equivalent). When omitted, falls back to the AsyncLocalStorage instance
207
- * an established request scope parks on the global.
208
- */
209
- provideEvent?: <T>(event: ServerFunctionEvent, fn: () => T) => T;
210
- /**
211
- * Wraps every server function execution — HTTP dispatch and direct SSR
212
- * calls alike — with the invocation identity already established (see
213
- * `WrapInvocationHook`). The per-invocation seam for framework policies:
214
- * per-function middleware, auth, logging, error mapping. A per-request
215
- * option overrides it for HTTP dispatch.
216
- */
217
- wrapInvocation?: WrapInvocationHook;
218
- /**
219
- * The single-flight hook: produces the data payload folded into
220
- * responses of calls that opted in (see `CollectFlightDataHook`).
221
- * Registered once by the integration that owns data production (a
222
- * router); per-handler `collectFlightData` options override it.
223
- */
224
- collectFlightData?: CollectFlightDataHook;
225
- /**
226
- * Server-wide default for the handler's `transformResult` (same contract
227
- * — see `HandleServerFunctionRequestOptions`); a per-request option
228
- * overrides it. Registering it here makes result policies (e.g. frames'
229
- * `frameTransformResult`) work through generic dispatchers that call
230
- * `handleServerFunctionRequest(request)` with no options.
231
- */
232
- transformResult?(
233
- event: ServerFunctionEvent,
234
- result: unknown,
235
- context: {
236
- id: string;
237
- args: unknown[];
238
- instance: string | null;
239
- request: Request;
240
- thrown?: boolean;
241
- }
242
- ): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
243
- /**
244
- * `transformResult`'s counterpart for the single-flight fold: when a
245
- * call's flight payload needs a body only a policy knows how to build
246
- * (frames' `frameTransformFlightResult` an invalidated entry is
247
- * markup), this gets first refusal on the `{ value, data }` outcome.
248
- * Return a `Response` to carry the outcome (call headers and cookies are
249
- * copied onto it), or `undefined` to decline and keep the plain
250
- * serialized envelope. A per-request option overrides it.
251
- */
252
- transformFlightResult?(
253
- event: ServerFunctionEvent,
254
- outcome: { value: unknown; data: unknown },
255
- context: { id: string; args: unknown[]; instance: string | null; request: Request }
256
- ): Response | undefined | Promise<Response | undefined>;
257
- /**
258
- * The in-process mirror of `transformResult` for direct (same-server)
259
- * calls during document SSR — e.g. frames' `frameTransformDirectResult`.
260
- */
261
- transformDirectResult?(
262
- value: unknown,
263
- options: { id: string; args: unknown[]; event: ServerFunctionEvent }
264
- ): unknown;
265
- /**
266
- * Server-wide response builder for calls made without the client runtime
267
- * (see `handleNoJS` in `HandleServerFunctionRequestOptions`); a
268
- * per-request option overrides it. Set it to `createNoJSHandler({ base })`
269
- * to apply the convention to every non-scripted call rather than only to
270
- * browser form posts, to a handler of your own to replace it, or to
271
- * `null` to disable the built-in convention and answer form posts with
272
- * the plain serialized response.
273
- */
274
- handleNoJS?:
275
- | ((
276
- result: unknown,
277
- request: Request,
278
- args: unknown[],
279
- thrown?: boolean
280
- ) => Response | Promise<Response>)
281
- | null;
282
- /**
283
- * Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
284
- * references (e.g. form actions) — must match the client configuration.
285
- * Prefix it when the app serves from a base path (e.g.
286
- * `` `${BASE_URL}_server` ``).
287
- * @default "/_server"
288
- */
289
- endpoint?: string;
290
- /**
291
- * Codec options (extra plugins etc.) for decoding arguments and encoding
292
- * results — must match the client's. Stored in the shared layer, so
293
- * `decodeResponse` sees them too.
294
- */
295
- codec?: JSONCodecOptions;
136
+ /**
137
+ * Establishes the request-event scope for a call — the function passed
138
+ * runs with `event` visible to `getRequestEvent()`. Wire it to
139
+ * `provideRequestEvent` from `@solidjs/web/storage` (or the framework's
140
+ * equivalent). When omitted, falls back to the AsyncLocalStorage instance
141
+ * an established request scope parks on the global.
142
+ */
143
+ provideEvent?: <T>(event: ServerFunctionEvent, fn: () => T) => T;
144
+ /**
145
+ * Wraps every server function execution — HTTP dispatch and direct SSR
146
+ * calls alike — with the invocation identity already established (see
147
+ * `WrapInvocationHook`). The per-invocation seam for framework policies:
148
+ * per-function middleware, auth, logging, error mapping. A per-request
149
+ * option overrides it for HTTP dispatch.
150
+ */
151
+ wrapInvocation?: WrapInvocationHook;
152
+ /**
153
+ * The single-flight hook: produces the data payload folded into
154
+ * responses of calls that opted in (see `CollectFlightDataHook`).
155
+ * Registered once by the integration that owns data production (a
156
+ * router); per-handler `collectFlightData` options override it.
157
+ */
158
+ collectFlightData?: CollectFlightDataHook;
159
+ /**
160
+ * Server-wide default for the handler's `transformResult` (same contract
161
+ * — see `HandleServerFunctionRequestOptions`); a per-request option
162
+ * overrides it. Registering it here makes result policies (e.g. frames'
163
+ * `frameTransformResult`) work through generic dispatchers that call
164
+ * `handleServerFunctionRequest(request)` with no options.
165
+ */
166
+ transformResult?(event: ServerFunctionEvent, result: unknown, context: {
167
+ id: string;
168
+ args: unknown[];
169
+ instance: string | null;
170
+ request: Request;
171
+ thrown?: boolean;
172
+ }): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
173
+ /**
174
+ * `transformResult`'s counterpart for the single-flight fold: when a
175
+ * call's flight payload needs a body only a policy knows how to build
176
+ * (frames' `frameTransformFlightResult` an invalidated entry is
177
+ * markup), this gets first refusal on the `{ value, data }` outcome.
178
+ * Return a `Response` to carry the outcome (call headers and cookies are
179
+ * copied onto it), or `undefined` to decline and keep the plain
180
+ * serialized envelope. A per-request option overrides it.
181
+ */
182
+ transformFlightResult?(event: ServerFunctionEvent, outcome: {
183
+ value: unknown;
184
+ data: unknown;
185
+ }, context: {
186
+ id: string;
187
+ args: unknown[];
188
+ instance: string | null;
189
+ request: Request;
190
+ }): Response | undefined | Promise<Response | undefined>;
191
+ /**
192
+ * The in-process mirror of `transformResult` for direct (same-server)
193
+ * calls during document SSR — e.g. frames' `frameTransformDirectResult`.
194
+ */
195
+ transformDirectResult?(value: unknown, options: {
196
+ id: string;
197
+ args: unknown[];
198
+ event: ServerFunctionEvent;
199
+ }): unknown;
200
+ /**
201
+ * Server-wide response builder for calls made without the client runtime
202
+ * (see `handleNoJS` in `HandleServerFunctionRequestOptions`); a
203
+ * per-request option overrides it. Set it to `createNoJSHandler({ base })`
204
+ * to apply the convention to every non-scripted call rather than only to
205
+ * browser form posts, to a handler of your own to replace it, or to
206
+ * `null` to disable the built-in convention and answer form posts with
207
+ * the plain serialized response.
208
+ */
209
+ handleNoJS?: ((result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response | Promise<Response>) | null;
210
+ /**
211
+ * Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
212
+ * references (e.g. form actions) — must match the client configuration.
213
+ * Prefix it when the app serves from a base path (e.g.
214
+ * `` `${BASE_URL}_server` ``).
215
+ * @default "/_server"
216
+ */
217
+ endpoint?: string;
218
+ /**
219
+ * Same-origin protection for HTTP server function calls. Enabled by
220
+ * default. Set to `false` only when another trusted layer protects the
221
+ * endpoint.
222
+ */
223
+ csrf?: boolean | ServerFunctionCSRFOptions;
224
+ /**
225
+ * Codec options (extra plugins etc.) for decoding arguments and encoding
226
+ * results — must match the client's. Stored in the shared layer, so
227
+ * `decodeResponse` sees them too.
228
+ */
229
+ codec?: JSONCodecOptions;
296
230
  }
297
-
298
- /**
299
- * Configures the server runtime. Call once at server startup, before
300
- * handling requests. Only needed when deviating from the defaults (custom
301
- * endpoint, codec plugins, an explicit event provider, or a single-flight
302
- * hook).
303
- */
304
- export function configureServerFunctionsServer(config?: ServerFunctionsServerConfig): void;
305
-
306
231
  /**
307
232
  * A registered server function: its build-stable id paired with the
308
233
  * original implementation. Returned by `registerServerReference` and
@@ -312,89 +237,19 @@ export function configureServerFunctionsServer(config?: ServerFunctionsServerCon
312
237
  * @internal
313
238
  */
314
239
  export interface ServerFunctionReference<T extends any[] = any[], R = any> {
315
- id: string;
316
- fn: (...args: T) => R;
317
- /**
318
- * The function's source name, emitted by development builds only —
319
- * `createServerReference` seeds the metadata channel with it.
320
- * @internal
321
- */
322
- name?: string;
240
+ id: string;
241
+ fn: (...args: T) => R;
242
+ /**
243
+ * The function's source name, emitted by development builds only —
244
+ * `createServerReference` seeds the metadata channel with it.
245
+ * @internal
246
+ */
247
+ name?: string;
323
248
  }
324
-
325
- /**
326
- * Adds a function to the dispatch registry under an id and returns it
327
- * unchanged. The low-level registry write for integrations registering
328
- * functions outside the compiler (e.g. a router registering its own
329
- * endpoints); compiled output goes through `registerServerReference`
330
- * instead. Ids must be stable across the client and server builds.
331
- */
332
- export function registerServerFunction<T extends any[], R>(
333
- id: string,
334
- callback: (...args: T) => R
335
- ): (...args: T) => R;
336
-
337
- /**
338
- * Looks up a registered server function by id; throws for unknown ids.
339
- * The HTTP handler uses this for dispatch — integrations building custom
340
- * dispatch (or introspection) can too.
341
- */
342
- export function getServerFunction<T extends any[], R>(id: string): (...args: T) => R;
343
-
344
- /**
345
- * Compiler ABI — emitted by compiled `"use server"` server output for
346
- * every server function: registers `fn` for HTTP dispatch under its
347
- * build-stable id and returns the reference the server-side
348
- * `createServerReference` consumes. Development builds pass the function's
349
- * source name as the trailing argument (dev-only metadata; never emitted in
350
- * production). Not meant for hand-written code.
351
- * @internal
352
- */
353
- export function registerServerReference<T extends any[], R>(
354
- id: string,
355
- fn: (...args: T) => R,
356
- name?: string
357
- ): ServerFunctionReference<T, R>;
358
-
359
- /**
360
- * Compiler ABI — emitted by compiled `"use server"` server output where
361
- * the function was referenced; produces the server-side callable. Calling
362
- * it during SSR runs the original function in-process (no HTTP), under a
363
- * request event derived from the current one — marked `serverOnly` and
364
- * carrying the function's meta. Not meant for hand-written code.
365
- * @internal
366
- */
367
- export function createServerReference<T extends any[], R>(
368
- reference: ServerFunctionReference<T, R>
369
- ): (...args: T) => R;
370
-
371
- /**
372
- * Declares a server function callable over HTTP GET. The server half is
373
- * identity-flavored — SSR calls stay in-process — but it brands the
374
- * declaration on the reference's metadata channel
375
- * (`getServerFunctionMetadata(fn)?.method === "GET"`) and records the
376
- * declared method for the function's id so `handleServerFunctionRequest`
377
- * honors it: GET-declared functions accept GET requests in addition to the
378
- * default POST transport (declaring GET grants, it does not revoke);
379
- * functions that never declared GET answer GET requests with 405.
380
- *
381
- * Wrap the reference at its declaration; the compiler round-trips the call
382
- * in both builds:
383
- *
384
- * ```ts
385
- * export const getUser = GET(async (id: string) => {
386
- * "use server";
387
- * return db.users.find(id);
388
- * });
389
- * ```
390
- */
391
- export function GET<A extends readonly any[], R>(
392
- fn: (...args: A) => R
393
- ): ServerFunction<A, Awaited<R>>;
394
-
395
- /** Wire-state transitions a live call's iterable can report (client side). */
249
+ /** Wire-state transitions a live call's iterable can report (client side).
250
+ * `"closed"` carries the error when a definite rejection (4xx) ended the
251
+ * call instead of the retry loop. */
396
252
  export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
397
-
398
253
  /**
399
254
  * Type-level mirror of the client's live answer shape so isomorphic code
400
255
  * assigning `onstatus` typechecks against either build's declarations. On
@@ -402,215 +257,143 @@ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
402
257
  * own iterable — there is no connection to report on.
403
258
  */
404
259
  export type LiveSource<R> = R & {
405
- onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
260
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
406
261
  };
407
-
408
- /**
409
- * Declares a value-shaped live source: a server function returning an async
410
- * iterable whose yields are successive VALUES of one logical query, with
411
- * the contract that the source re-yields current state on every invocation.
412
- * Writes `live: true` on the metadata channel and brands the resolved
413
- * iterable (registered symbol `solid.LiveSource`) so SSR faces meeting the
414
- * value in-process can apply live policy (document face: first value, then
415
- * client takeover). Dispatch is untouched — over-the-wire calls stream the
416
- * raw registered function's result. Declare live outermost:
417
- * `live(GET(fn))`.
418
- */
419
- export function live<A extends readonly any[], R>(
420
- fn: (...args: A) => R
421
- ): ServerFunction<A, LiveSource<Awaited<R>>>;
422
-
423
262
  /** Identity of the currently executing server function call. */
424
263
  export interface ServerFunctionInvocation {
425
- id: string;
264
+ id: string;
426
265
  }
427
-
428
- /**
429
- * Reads the in-flight server function invocation (its id) for the current
430
- * request event — usable inside a server function body, e.g. to key caches
431
- * or logs by function. Returns undefined outside a server function call.
432
- * The state lives in a module-private WeakMap keyed by the per-call request
433
- * event (never in `event.locals`, which derived events share with their
434
- * outer event). Distinct from `getServerFunctionMetadata(fn)`, which reads
435
- * a reference's static declaration metadata; this describes the call
436
- * currently executing.
437
- */
438
- export function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
439
-
440
- /**
441
- * The event-keyed half of `getServerFunctionInvocation`, for callers handed
442
- * an event outside its provideEvent scope (the handler's result transforms
443
- * run after the scope has exited). Integration plumbing — application code
444
- * reads the ambient accessor instead.
445
- * @internal
446
- */
447
- export function getEventServerFunctionInvocation(
448
- event: RequestEvent | undefined
449
- ): ServerFunctionInvocation | undefined;
450
-
451
266
  /**
452
267
  * Hooks layering framework policy onto `handleServerFunctionRequest`.
453
268
  * All are optional — the bare handler dispatches, scopes events, and
454
269
  * encodes results on its own.
455
270
  */
456
271
  export interface HandleServerFunctionOptions {
457
- /**
458
- * Builds the request event a call runs under (default: bare
459
- * `{ request, locals: {} }`). Integrations supply their richer event
460
- * (cookies, response helpers, platform handles).
461
- */
462
- createEvent?(request: Request): ServerFunctionEvent;
463
- /**
464
- * Overrides the configured event provider for this handler — same
465
- * contract as the `provideEvent` config option.
466
- */
467
- provideEvent?<T>(event: ServerFunctionEvent, fn: () => T): T;
468
- /**
469
- * Overrides the configured per-invocation wrap for this handler — same
470
- * contract as the `wrapInvocation` config option (see
471
- * `WrapInvocationHook`), except it only applies to HTTP dispatch (a
472
- * per-request option can't see direct SSR calls).
473
- */
474
- wrapInvocation?: WrapInvocationHook;
475
- /**
476
- * Observes or replaces the function's result before encoding — the
477
- * extension point for response metadata policies (headers, statuses,
478
- * substituted results). Runs for returned and thrown results alike
479
- * (`context.thrown` distinguishes); `context.instance` is null for no-JS
480
- * calls. The context carries the call's identity — the function `id` and
481
- * the parsed `args` the implementation was invoked with — matching the
482
- * direct-call mirror (`transformDirectResult`), so a policy keying state
483
- * by the call works over either dispatch path. Return the result
484
- * unchanged to pass through, or a `ResponseEnvelope` (exposed through
485
- * the core entry) to send HTTP metadata plus a structured payload. Runs
486
- * before `collectFlightData`, so the flight hook sees the transformed
487
- * outcome — use `collectFlightData`, not this, to fold data into the
488
- * response.
489
- */
490
- transformResult?(
491
- event: ServerFunctionEvent,
492
- result: unknown,
493
- context: {
494
- id: string;
495
- args: unknown[];
496
- instance: string | null;
497
- request: Request;
498
- thrown?: boolean;
499
- }
500
- ): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
501
- /**
502
- * Overrides the configured single-flight hook for this handler — same
503
- * contract as the `collectFlightData` config option (see
504
- * `CollectFlightDataHook`).
505
- */
506
- collectFlightData?: CollectFlightDataHook;
507
- /**
508
- * Overrides the configured single-flight fold policy for this handler —
509
- * same contract as the `transformFlightResult` config option.
510
- */
511
- transformFlightResult?(
512
- event: ServerFunctionEvent,
513
- outcome: { value: unknown; data: unknown },
514
- context: { id: string; args: unknown[]; instance: string | null; request: Request }
515
- ): Response | undefined | Promise<Response | undefined>;
516
- /**
517
- * Builds the response for calls made without the client runtime (no
518
- * instance header — no-JS form posts, direct HTTP). Receives the
519
- * (transformed) result, the request, and the decoded arguments; `thrown`
520
- * is set when the result was thrown rather than returned.
521
- *
522
- * Overrides the configured hook, which in turn overrides the built-in
523
- * `createNoJSHandler()` applied to browser form posts. Other
524
- * no-instance callers get the normal serialized response.
525
- */
526
- handleNoJS?(
527
- result: unknown,
528
- request: Request,
529
- args: unknown[],
530
- thrown?: boolean
531
- ): Response | Promise<Response>;
532
- /** Overrides the configured codec options for this handler. */
533
- codec?: JSONCodecOptions;
272
+ /**
273
+ * Builds the request event a call runs under (default: bare
274
+ * `{ request, locals: {} }`). Integrations supply their richer event
275
+ * (cookies, response helpers, platform handles).
276
+ */
277
+ createEvent?(request: Request): ServerFunctionEvent;
278
+ /**
279
+ * Overrides the configured event provider for this handler — same
280
+ * contract as the `provideEvent` config option.
281
+ */
282
+ provideEvent?<T>(event: ServerFunctionEvent, fn: () => T): T;
283
+ /**
284
+ * Overrides the configured per-invocation wrap for this handler — same
285
+ * contract as the `wrapInvocation` config option (see
286
+ * `WrapInvocationHook`), except it only applies to HTTP dispatch (a
287
+ * per-request option can't see direct SSR calls).
288
+ */
289
+ wrapInvocation?: WrapInvocationHook;
290
+ /**
291
+ * Observes or replaces the function's result before encoding — the
292
+ * extension point for response metadata policies (headers, statuses,
293
+ * substituted results). Runs for returned and thrown results alike
294
+ * (`context.thrown` distinguishes); `context.instance` is null for no-JS
295
+ * calls. The context carries the call's identity — the function `id` and
296
+ * the parsed `args` the implementation was invoked with — matching the
297
+ * direct-call mirror (`transformDirectResult`), so a policy keying state
298
+ * by the call works over either dispatch path. Return the result
299
+ * unchanged to pass through, or a `ResponseEnvelope` (exposed through
300
+ * the core entry) to send HTTP metadata plus a structured payload. Runs
301
+ * before `collectFlightData`, so the flight hook sees the transformed
302
+ * outcome — use `collectFlightData`, not this, to fold data into the
303
+ * response.
304
+ */
305
+ transformResult?(event: ServerFunctionEvent, result: unknown, context: {
306
+ id: string;
307
+ args: unknown[];
308
+ instance: string | null;
309
+ request: Request;
310
+ thrown?: boolean;
311
+ }): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
312
+ /**
313
+ * Overrides the configured single-flight hook for this handler — same
314
+ * contract as the `collectFlightData` config option (see
315
+ * `CollectFlightDataHook`).
316
+ */
317
+ collectFlightData?: CollectFlightDataHook;
318
+ /**
319
+ * Overrides the configured single-flight fold policy for this handler —
320
+ * same contract as the `transformFlightResult` config option.
321
+ */
322
+ transformFlightResult?(event: ServerFunctionEvent, outcome: {
323
+ value: unknown;
324
+ data: unknown;
325
+ }, context: {
326
+ id: string;
327
+ args: unknown[];
328
+ instance: string | null;
329
+ request: Request;
330
+ }): Response | undefined | Promise<Response | undefined>;
331
+ /**
332
+ * Builds the response for calls made without the client runtime (no
333
+ * instance header — no-JS form posts, direct HTTP). Receives the
334
+ * (transformed) result, the request, and the decoded arguments; `thrown`
335
+ * is set when the result was thrown rather than returned.
336
+ *
337
+ * Overrides the configured hook, which in turn overrides the built-in
338
+ * `createNoJSHandler()` applied to browser form posts. Other
339
+ * no-instance callers get the normal serialized response.
340
+ */
341
+ handleNoJS?(result: unknown, request: Request, args: unknown[], thrown?: boolean): Response | Promise<Response>;
342
+ /**
343
+ * Overrides same-origin protection for this handler. Set to `false` only
344
+ * when another trusted layer protects the endpoint.
345
+ */
346
+ csrf?: boolean | ServerFunctionCSRFOptions;
347
+ /** Overrides the configured codec options for this handler. */
348
+ codec?: JSONCodecOptions;
349
+ }
350
+ export interface ServerFunctionRequestCall {
351
+ type: "request";
352
+ id: string;
353
+ instance: string;
354
+ request: Request;
355
+ meta: ServerFunctionMetadata | undefined;
356
+ time: number;
534
357
  }
535
-
358
+ export interface ServerFunctionResponseCall {
359
+ type: "response";
360
+ id: string;
361
+ instance: string;
362
+ response: Response;
363
+ meta: ServerFunctionMetadata | undefined;
364
+ time: number;
365
+ }
366
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
367
+ export declare function configureServerFunctionsServer(config?: ServerFunctionsServerConfig): void;
368
+ export declare function registerServerFunction<T extends any[], R>(id: string, callback: (...args: T) => R): (...args: T) => R;
369
+ export declare function getServerFunction<T extends any[], R>(id: string): (...args: T) => R;
370
+ export declare function registerServerReference<T extends any[], R>(id: string, fn: (...args: T) => R, name?: string): ServerFunctionReference<T, R>;
371
+ export declare function createServerReference<T extends any[], R>(reference: ServerFunctionReference<T, R>): (...args: T) => R;
372
+ export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
373
+ export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, LiveSource<Awaited<R>>>;
374
+ export declare function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
375
+ export declare function getEventServerFunctionInvocation(event: RequestEvent | undefined): ServerFunctionInvocation | undefined;
376
+ export declare function foldSetCookies(headers: Headers, setCookies: readonly string[]): Headers;
377
+ export declare function createNoJSHandler(options?: NoJSHandlerOptions): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
536
378
  /**
537
- * Web-standard HTTP handler for server function calls: resolves the
538
- * function id from the request, gates GET dispatch on the declaration (405
539
- * for a GET request to a function that never declared `GET`; POST is always
540
- * accepted), decodes arguments, runs the function under a request-event scope,
541
- * and encodes the result (forwarding redirect/revalidation metadata
542
- * through headers). Mount it on the endpoint the client transport targets
543
- * (default `/_server`); platform adapters (h3, express, ...) convert their
544
- * request shape to a web `Request` around it.
545
- *
546
- * When the event carries a `response` head stub (`event.response`, see the
547
- * server entry's `ResponseStub`), the handler folds it onto every outgoing
548
- * response as the head freezes — its `Set-Cookie` values (cookies appended
549
- * during the call) append cookie-by-cookie alongside the result's own,
550
- * other stub headers fill gaps (the call's response metadata wins; the
551
- * protocol-owned family — the error/format/single-flight tags, `Location`,
552
- * `X-Revalidate` — never fills, and neither does `Content-Type`/`Content-
553
- * Length` onto a bodiless response) — and marks the stub `committed`, so
554
- * later cookie/header writes report instead of silently missing the wire.
555
- *
556
- * ## Thrown-error sanitization (security default)
557
- *
558
- * A thrown `Response`/envelope (`redirect`/`reload`/`respond`) is intentional
559
- * control flow and is forwarded untouched. A *plain* thrown value (a bare
560
- * `Error`, string, or object) is different: serialized verbatim it would ship
561
- * its `message` and every own-property to the client — a driver/ORM error's
562
- * failing query, connection string, or bound parameters included. So outside
563
- * the dev build a plain thrown value is replaced with a generic `Error`
564
- * before serialization; the client still receives *an* `Error` (the shape
565
- * `submission.error` etc. expect), just with no leaked content. The dev
566
- * build keeps full fidelity (message, stack, own-props) for DX and the dev
567
- * toolbar inspector. Dev/prod is the BUILD VARIANT, not `NODE_ENV`:
568
- * `@solidjs/web` publishes a dev copy of this entry behind the
569
- * `development` export condition (what Vite dev resolves) and the default
570
- * resolution sanitizes — as does importing the runtime source directly with
571
- * no bundler signal (fail-safe).
572
- *
573
- * Escape hatch: brand the value with `markSafeError` (`Symbol.for(
574
- * "solid.SafeError")`) to send its content intact in every environment.
575
- * A `wrapInvocation`/`transformResult` override that maps errors expresses
576
- * intent the same way — throw a `Response`/envelope, or brand the mapped
577
- * error safe; an unbranded plain error it lets propagate is sanitized like
578
- * any other, so a framework onError policy must brand its result to keep a
579
- * custom client-facing message in production.
379
+ * The response-side codec stream: `serializeStream` (shared.js) hardened
380
+ * with request-lifetime teardown. Server-only on purpose the shared half
381
+ * is re-exported into client bundles, where this plumbing is dead weight.
580
382
  *
581
- * @example
582
- * ```ts
583
- * import { handleServerFunctionRequest } from "@solidjs/web/server-functions";
584
- * import "virtual:solid-server-function-manifest";
585
- *
586
- * // in the server's request handling:
587
- * if (url.pathname.startsWith("/_server")) {
588
- * return handleServerFunctionRequest(request);
589
- * }
590
- * ```
383
+ * An abort of `signal` (the platform fires request.signal when the caller's
384
+ * fetch aborts or the tab goes away) or the consumer cancelling the
385
+ * ReadableStream (how platforms surface a dropped connection to the body)
386
+ * stops pending serialization and tears down a top-level async-iterable
387
+ * value — the producer's `iterator.return()` runs, so generator `finally`
388
+ * blocks execute instead of the server pumping a stream nobody is reading.
389
+ * Top-level only: that is the value-tier shape ("return a stream from the
390
+ * server function"); iterables nested inside user objects are consumed by
391
+ * the codec directly and stay untouched.
591
392
  */
592
- export function handleServerFunctionRequest(
593
- request: Request,
594
- options?: HandleServerFunctionOptions
595
- ): Promise<Response>;
596
-
393
+ export declare function serializeResponseStream(value: any, codecOptions: any, signal: any): ReadableStream<any>;
597
394
  /** Message a sanitized (production) server error carries on the wire. */
598
- export const GENERIC_SERVER_ERROR_MESSAGE: string;
599
-
600
- /**
601
- * The production error-sanitization policy `handleServerFunctionRequest`
602
- * applies to a plain thrown value before serialization. Returns `value`
603
- * unchanged in the dev build or when it is branded safe (`markSafeError`);
604
- * otherwise returns a generic `Error` carrying `GENERIC_SERVER_ERROR_MESSAGE`.
605
- * Exposed for frameworks composing their own dispatch around the same policy.
606
- */
607
- export function sanitizeServerError(value: unknown): unknown;
608
-
609
- /**
610
- * Overrides the build-variant dev flag for this module instance — the seam
611
- * for test harnesses and hand-rolled bundles whose packaging cannot replace
612
- * `_DX_DEV_`. Applications never call this; select the dev build through
613
- * the `development` export condition instead.
614
- * @internal
615
- */
616
- export function setServerFunctionsDev(dev: boolean): void;
395
+ export declare const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
396
+ export declare function setServerFunctionsDev(dev: boolean): void;
397
+ export declare function sanitizeServerError(value: unknown): unknown;
398
+ export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
399
+ export declare function handleServerFunctionRequest(request: Request, options?: HandleServerFunctionOptions): Promise<Response>;