@solidjs/web 2.0.0-rc.2 → 2.0.0-rc.4

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 (86) hide show
  1. package/dist/dev.cjs +433 -72
  2. package/dist/dev.js +426 -71
  3. package/dist/server.cjs +39 -21
  4. package/dist/server.js +40 -23
  5. package/dist/web.cjs +421 -70
  6. package/dist/web.js +414 -69
  7. package/frames/dist/client.cjs +8 -8
  8. package/frames/dist/client.dev.cjs +8 -8
  9. package/frames/dist/client.dev.js +8 -8
  10. package/frames/dist/client.js +8 -8
  11. package/frames/dist/server.cjs +28 -18
  12. package/frames/dist/server.js +29 -19
  13. package/package.json +20 -22
  14. package/serialization/dist/decode.cjs +3 -3
  15. package/serialization/dist/decode.js +3 -3
  16. package/serialization/dist/serialization.cjs +7 -11
  17. package/serialization/dist/serialization.js +7 -6
  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 +126 -19
  25. package/server-functions/dist/client.js +123 -19
  26. package/server-functions/dist/server.cjs +156 -28
  27. package/server-functions/dist/server.dev.cjs +156 -28
  28. package/server-functions/dist/server.dev.js +153 -28
  29. package/server-functions/dist/server.js +153 -28
  30. package/types/client.d.ts +152 -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 -277
  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 +1 -65
  41. package/types/index.server.d.ts +125 -0
  42. package/types/jsx.d.ts +5 -13
  43. package/types/patch-driver.d.ts +3 -0
  44. package/types/reconcile.d.ts +1 -0
  45. package/types/render.d.ts +4 -0
  46. package/types/response.d.ts +48 -152
  47. package/types/serializer-decode.d.ts +89 -112
  48. package/types/serializer.d.ts +69 -157
  49. package/types/server-functions/client.d.ts +124 -222
  50. package/types/server-functions/flash.d.ts +10 -30
  51. package/types/server-functions/registry.d.ts +100 -0
  52. package/types/server-functions/rich-args.d.ts +1 -10
  53. package/types/server-functions/server.d.ts +295 -574
  54. package/types/server-functions/shared.d.ts +155 -458
  55. package/types/server-mock.d.ts +2 -2
  56. package/types/server.d.ts +242 -434
  57. package/types-cjs/client.d.cts +152 -290
  58. package/types-cjs/constants.d.cts +18 -0
  59. package/types-cjs/cookies.d.cts +31 -75
  60. package/types-cjs/frames/frame-client.d.cts +287 -277
  61. package/types-cjs/frames/frame-container-plugin.d.cts +71 -0
  62. package/types-cjs/frames/frame-sink.d.cts +58 -160
  63. package/types-cjs/frames/frame-transport.d.cts +161 -194
  64. package/types-cjs/frames/serializer-decode.d.cts +159 -0
  65. package/types-cjs/frames/serializer.d.cts +69 -157
  66. package/types-cjs/head.d.cts +16 -0
  67. package/types-cjs/index.d.cts +1 -65
  68. package/types-cjs/index.server.d.cts +125 -0
  69. package/types-cjs/jsx.d.cts +5 -13
  70. package/types-cjs/patch-driver.d.cts +3 -0
  71. package/types-cjs/reconcile.d.cts +1 -0
  72. package/types-cjs/render.d.cts +4 -0
  73. package/types-cjs/response.d.cts +48 -152
  74. package/types-cjs/serializer-decode.d.cts +89 -112
  75. package/types-cjs/serializer.d.cts +69 -157
  76. package/types-cjs/server-functions/client.d.cts +124 -222
  77. package/types-cjs/server-functions/flash.d.cts +10 -30
  78. package/types-cjs/server-functions/registry.d.cts +100 -0
  79. package/types-cjs/server-functions/rich-args.d.cts +1 -10
  80. package/types-cjs/server-functions/server.d.cts +295 -574
  81. package/types-cjs/server-functions/shared.d.cts +155 -458
  82. package/types-cjs/server-mock.d.cts +2 -2
  83. package/types-cjs/server.d.cts +242 -434
  84. package/LICENSE +0 -21
  85. package/types/core.d.ts +0 -9
  86. package/types-cjs/core.d.cts +0 -9
@@ -1,94 +1,6 @@
1
+ export { LIVE_SOURCE, SERVER_FUNCTION_INVOKE, SERVER_FUNCTION_METADATA, getServerFunctionMetadata, getServerFunctionRPC, invoke, isServerFunction, provideServerFunctionRPC, withMeta } from "./registry.cjs";
2
+ export { FLASH_COOKIE, clearFlashCookie, hasFlashCookie, matchFlashCookie } from "../cookies.cjs";
1
3
  import { JSONCodecOptions } from "../serializer-decode.cjs";
2
-
3
- export type { JSONCodecOptions };
4
-
5
- /**
6
- * Configures the codec options for the server function wire format (extra
7
- * Seroval plugins, feature policy, depth limit). Both peers must configure
8
- * identical options or payloads will not round-trip. Usually called
9
- * indirectly through `configureServerFunctionsClient` /
10
- * `configureServerFunctionsServer` (their `codec` option writes through to
11
- * here); call it directly only from universal code configuring both sides
12
- * at once.
13
- */
14
- export function configureServerFunctionsCodec(codec: JSONCodecOptions | undefined): void;
15
-
16
- /**
17
- * The currently configured codec options (set through
18
- * `configureServerFunctionsCodec` or the client/server `codec` option), or
19
- * undefined when running on the defaults. Integrations pass this to
20
- * lower-level codec helpers so custom plugins configured by the app apply.
21
- *
22
- * Integration plumbing; not meant for hand-written application code.
23
- * @internal
24
- */
25
- export function getServerFunctionsCodec(): JSONCodecOptions | undefined;
26
-
27
- /**
28
- * Request header carrying the server function id (`"X-Server-Function-Id"`).
29
- * Integrations can read it to identify which function a request targets;
30
- * the id also arrives as the `id` query parameter for GET calls and no-JS
31
- * form posts.
32
- */
33
- export const FUNCTION_HEADER: string;
34
-
35
- /**
36
- * Request header carrying a per-call instance id
37
- * (`"X-Server-Function-Instance"`). Its presence tells the server the call
38
- * came through the client runtime — its absence marks a no-JS form post or
39
- * direct HTTP call, which receive plain responses instead of codec-encoded
40
- * ones.
41
- */
42
- export const INSTANCE_HEADER: string;
43
-
44
- /**
45
- * Response header marking a thrown server-function error
46
- * (`"X-Server-Function-Error"`). The client transport rejects with the
47
- * decoded body when it is present (unless redirect/revalidation metadata
48
- * marks the response as control flow). The value carries the error's
49
- * message — `"true"` for thrown control-flow responses and non-Error
50
- * values — encoded with `encodeErrorHeaderValue`, so integrations reading
51
- * it must pass it through `decodeErrorHeaderValue`.
52
- */
53
- export const ERROR_HEADER: string;
54
-
55
- /**
56
- * Encodes an error message for the `ERROR_HEADER` value. HTTP header values
57
- * are latin1 ByteStrings — `Headers.set` throws on code points above U+00FF
58
- * — so plain printable-latin1 messages ride verbatim (ASCII stays
59
- * byte-identical on the wire) and everything else (CJK, emoji, controls)
60
- * travels percent-encoded behind a marker. `decodeErrorHeaderValue`
61
- * round-trips the message exactly, astral-plane characters included (lone
62
- * surrogates are replaced with U+FFFD — they cannot survive UTF-8 anyway).
63
- *
64
- * Transport wire detail; not meant for hand-written code.
65
- * @internal
66
- */
67
- export function encodeErrorHeaderValue(value: string): string;
68
-
69
- /**
70
- * Decodes an `ERROR_HEADER` value produced by `encodeErrorHeaderValue`:
71
- * marked values are percent-decoded, everything else (including values from
72
- * peers that never encode) passes through untouched.
73
- *
74
- * Integration plumbing for readers of `ERROR_HEADER`; not meant for
75
- * hand-written application code.
76
- * @internal
77
- */
78
- export function decodeErrorHeaderValue(value: string): string;
79
-
80
- /**
81
- * Header driving the single-flight protocol on both legs
82
- * (`"X-Single-Flight"`). On the request it opts the call into data
83
- * collection — the transport sends it automatically on non-GET calls while
84
- * a flight-data consumer is subscribed (subscribing IS the opt-in). On the
85
- * response it marks a body carrying the standardized `SingleFlightPayload`.
86
- * How the data is produced (a data-only render, running route preloads,
87
- * anything else) and what it means is entirely the integration's business —
88
- * the protocol only standardizes the wire shape and the delivery.
89
- */
90
- export const SINGLE_FLIGHT_HEADER: string;
91
-
92
4
  /**
93
5
  * The standardized body of a single-flight response (a response tagged with
94
6
  * `SINGLE_FLIGHT_HEADER`): the function's return `value` plus the
@@ -99,12 +11,11 @@ export const SINGLE_FLIGHT_HEADER: string;
99
11
  * `data`, which can be any codec-serializable value.
100
12
  */
101
13
  export interface SingleFlightPayload<T = unknown, D = unknown> {
102
- /** The server function's return (or thrown) value. */
103
- value: T;
104
- /** The integration-produced data payload. */
105
- data: D;
14
+ /** The server function's return (or thrown) value. */
15
+ value: T;
16
+ /** The integration-produced data payload. */
17
+ data: D;
106
18
  }
107
-
108
19
  /**
109
20
  * Envelope context delivered alongside single-flight data: the transport
110
21
  * response, whose headers carry the integration metadata (`Location` for
@@ -112,96 +23,64 @@ export interface SingleFlightPayload<T = unknown, D = unknown> {
112
23
  * consumed — read `data` and `value` from the delivery, not from here.
113
24
  */
114
25
  export interface FlightDataContext {
115
- /** The HTTP response the data arrived on (metadata only). */
116
- response: Response;
26
+ /** The HTTP response the data arrived on (metadata only). */
27
+ response: Response;
117
28
  }
118
-
119
29
  /**
120
30
  * Consumer receiving single-flight data on the client: `data` is the
121
31
  * integration-produced payload (opaque to the protocol), `context` carries
122
32
  * the envelope metadata. Async consumers are awaited before the function
123
33
  * value is returned to the caller, so caches are seeded first.
124
34
  */
125
- export type FlightDataConsumer<D = unknown> = (
126
- data: D,
127
- context: FlightDataContext
128
- ) => void | Promise<void>;
129
-
130
- /**
131
- * Registers the consumer the client transport delivers single-flight data
132
- * to. Subscribing is the single-flight opt-in: while a consumer is
133
- * registered the transport sends the request-leg `SINGLE_FLIGHT_HEADER` on
134
- * non-GET calls (GET reads stay plain and cacheable), asking the server's
135
- * collection hook to fold data into the response. When a single-flight
136
- * response arrives, the transport decodes the standardized
137
- * `{ value, data }` payload, delivers `data` (with the response as
138
- * envelope context — redirect location, revalidation keys), and returns
139
- * `value` to the caller as if the call were plain. What to do with the
140
- * data (seed caches, navigate, ...) is entirely the consumer's business.
141
- * One active consumer at a time — a later registration replaces the
142
- * current one; returns an unsubscribe function. With no consumer
143
- * registered, no header is sent and the server does no collection work;
144
- * responses an integration opted in manually still pass through to the
145
- * caller whole, exactly like other integration responses.
146
- */
147
- export function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
148
-
149
- /**
150
- * Name of the cookie carrying the outcome of a call made without the client
151
- * runtime (`"flash"`). A no-JS form post has no way to receive a value —
152
- * the browser follows the redirect and renders the next page — so the
153
- * handler stashes the outcome here for the render after it to pick up,
154
- * which is how a form submitted without JavaScript still shows its result.
155
- *
156
- * The name, detection and clearing are isomorphic (integrations read the
157
- * cookie from code that also ships to the browser); the codec that fills it
158
- * is server-only and lives behind the server entry.
159
- */
160
- export const FLASH_COOKIE: string;
161
-
162
- /**
163
- * Whether a Cookie header carries a flash cookie, readable or not. Cheap
164
- * enough to call on every render so the clear can be queued before the
165
- * response headers flush.
166
- */
167
- export function hasFlashCookie(cookieHeader: string | null): boolean;
168
-
169
- /**
170
- * The `Set-Cookie` value clearing the flash cookie. The outcome is
171
- * one-shot: append this as soon as the cookie is detected, whether or not
172
- * it decodes, so a stale outcome cannot resurface on a later request.
173
- */
174
- export function clearFlashCookie(): string;
175
-
176
- /**
177
- * The raw encoded flash payload out of a Cookie header, if present — the
178
- * codec's own accessor.
179
- *
180
- * @internal
181
- */
182
- export function matchFlashCookie(cookieHeader: string | null): string | undefined;
183
-
184
- /**
185
- * The currently registered single-flight consumer.
186
- *
187
- * Transport building block; not meant for hand-written code.
188
- * @internal
189
- */
190
- export function getFlightDataConsumer(): FlightDataConsumer | undefined;
191
-
35
+ export type FlightDataConsumer<D = unknown> = (data: D, context: FlightDataContext) => void | Promise<void>;
192
36
  /**
193
37
  * The public contract of a server function reference — what a `"use
194
38
  * server"` import is at runtime on either side: an async callable plus its
195
39
  * build-stable identity.
196
40
  */
197
41
  export interface ServerFunction<A extends readonly any[] = any[], T = any> {
198
- (...args: A): Promise<T>;
199
- /** The build-stable function id (stable across the client and server builds). */
200
- readonly id: string;
201
- /** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
202
- readonly url: string;
42
+ (...args: A): Promise<T>;
43
+ /** The build-stable function id (stable across the client and server builds). */
44
+ readonly id: string;
45
+ /** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
46
+ readonly url: string;
47
+ }
48
+ /**
49
+ * Per-call, invocation-scoped options for `invoke` — things that vary
50
+ * between calls of the SAME function and cannot be declared (`GET`,
51
+ * `withMeta`) or configured (`prepareRequest`). On the server the call is
52
+ * in-process: `signal` still rejects the caller, the transport hints are
53
+ * no-ops (they describe a wire that does not exist).
54
+ */
55
+ export interface InvokeOptions {
56
+ /**
57
+ * The call's lifecycle. Aborting rejects the call with the signal's
58
+ * reason and cancels the request (firing `request.signal` server-side);
59
+ * a live source's iteration ends across reconnects. When provided, the
60
+ * signal owns the wire — timeouts compose through it
61
+ * (`AbortSignal.timeout`, `AbortSignal.any`).
62
+ */
63
+ signal?: AbortSignal;
64
+ /**
65
+ * Lets the request outlive the page — fire-and-forget calls during
66
+ * unload (`pagehide`). Maps to fetch's `keepalive`, body-size caps
67
+ * included.
68
+ */
69
+ keepalive?: boolean;
70
+ /** Fetch priority hint — speculative prefetch vs. interaction fetch. */
71
+ priority?: "high" | "low" | "auto";
203
72
  }
204
-
73
+ /**
74
+ * A reference's invocation channel, carried under `SERVER_FUNCTION_INVOKE`:
75
+ * applies one call with per-call options. Declaration wrappers (`GET`,
76
+ * `live`) forward it mechanically — they keep the call mapping 1:1. A
77
+ * wrapper that shares calls (a deduping cache, a multicast channel) opts
78
+ * in deliberately, deciding first what a caller's abort means for shared
79
+ * work — or declines, leaving `invoke` to answer with a directed error.
80
+ * Options arrive already validated — `invoke` admits only
81
+ * invocation-scoped keys.
82
+ */
83
+ export type ServerFunctionInvoker<A extends readonly any[] = any[], R = any> = (args: A, options?: InvokeOptions) => R;
205
84
  /**
206
85
  * Declaration-static metadata attached to a server function reference
207
86
  * through declaration wrappers (`GET`, `withMeta`). Read it with
@@ -211,78 +90,19 @@ export interface ServerFunction<A extends readonly any[] = any[], T = any> {
211
90
  * over earlier ones.
212
91
  */
213
92
  export interface ServerFunctionMetadata {
214
- /** The declared HTTP method. Undeclared references call over POST. */
215
- readonly method?: "GET" | "POST";
216
- /**
217
- * A human-readable label for the function, seeded by development builds
218
- * from the compiled function's source name (dev tooling — inspectors,
219
- * logs). Dev-only: production builds emit no name. Not unique and not an
220
- * identity key — use `id` for identity. Seeded as a default: an explicit
221
- * `withMeta` write wins.
222
- */
223
- readonly name?: string;
224
- /** User-declared transport metadata attached with `withMeta`. */
225
- readonly [key: string]: unknown;
93
+ /** The declared HTTP method. Undeclared references call over POST. */
94
+ readonly method?: "GET" | "POST";
95
+ /**
96
+ * A human-readable label for the function, seeded by development builds
97
+ * from the compiled function's source name (dev tooling — inspectors,
98
+ * logs). Dev-only: production builds emit no name. Not unique and not an
99
+ * identity key — use `id` for identity. Seeded as a default: an explicit
100
+ * `withMeta` write wins.
101
+ */
102
+ readonly name?: string;
103
+ /** User-declared transport metadata attached with `withMeta`. */
104
+ readonly [key: string]: unknown;
226
105
  }
227
-
228
- /**
229
- * Reads a server function reference's declaration metadata — e.g.
230
- * `getServerFunctionMetadata(fn)?.method === "GET"` detects a `GET(fn)`
231
- * declaration. Returns undefined when `fn` is not a server function
232
- * reference; plain references carry an empty metadata object. Works on
233
- * client proxies and server-side references alike, across duplicated
234
- * module instances (registered-symbol brand).
235
- */
236
- export function getServerFunctionMetadata(fn: unknown): ServerFunctionMetadata | undefined;
237
-
238
- /**
239
- * Whether `fn` is a server function reference (a client proxy or a
240
- * server-side registered callable). Detection is structural — a
241
- * registered-symbol metadata brand — so it holds across duplicated module
242
- * instances and both sides of the directive boundary.
243
- */
244
- export function isServerFunction(fn: unknown): fn is ServerFunction;
245
-
246
- /**
247
- * Attaches user-declared transport metadata to a server function reference
248
- * (client proxy or server-registered callable) and returns the reference.
249
- * Writes ride the same channel `GET` uses: later writes shallow-merge over
250
- * earlier ones, and `getServerFunctionMetadata(fn)` reads the merged bag —
251
- * so `withMeta` composes with `GET` in either order
252
- * (`GET(withMeta(fn, meta))` ≡ `withMeta(GET(fn), meta)`).
253
- *
254
- * The pattern is declare-on-function, react-in-hook: metadata declared
255
- * here reaches `prepareRequest` as `context.meta`, letting session-dynamic
256
- * transport policy key on declarations instead of comparing function ids:
257
- *
258
- * ```ts
259
- * export const chargeCard = withMeta(async (amount: number) => {
260
- * "use server";
261
- * // ...
262
- * }, { requiresAuth: true });
263
- *
264
- * configureServerFunctionsClient({
265
- * prepareRequest(init, { meta }) {
266
- * if (meta?.requiresAuth) {
267
- * return {
268
- * ...init,
269
- * headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
270
- * };
271
- * }
272
- * return init;
273
- * }
274
- * });
275
- * ```
276
- */
277
- export function withMeta<F extends (...args: any[]) => any>(fn: F, meta: ServerFunctionMetadata): F;
278
-
279
- /**
280
- * The registered symbol branding server function references with their
281
- * declaration metadata. Use the typed accessors instead.
282
- * @internal
283
- */
284
- export const SERVER_FUNCTION_METADATA: unique symbol;
285
-
286
106
  /**
287
107
  * The transport surface integrations consume through the late-bound RPC
288
108
  * seam (server-functions/registry.js) — filled by the transport halves when
@@ -291,123 +111,96 @@ export const SERVER_FUNCTION_METADATA: unique symbol;
291
111
  * by routers so they never import the transport/codec statically.
292
112
  */
293
113
  export interface ServerFunctionRPC {
294
- /**
295
- * The build's `GET` declaration wrapper (client fetch transport or
296
- * server in-process dispatch — see the respective entries).
297
- */
298
- GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
299
- /**
300
- * `decodeResponse` bound to the configured codec: decodes a server
301
- * function response body the transport handed over whole (redirects,
302
- * revalidation). Resolves undefined for empty bodies and bodies without
303
- * a recognized encoding (e.g. a raw user Response).
304
- */
305
- decodeResponse<T = unknown>(response: Response): Promise<T | undefined>;
114
+ /**
115
+ * The build's `GET` declaration wrapper (client fetch transport or
116
+ * server in-process dispatch — see the respective entries).
117
+ */
118
+ GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
119
+ /**
120
+ * `decodeResponse` bound to the configured codec: decodes a server
121
+ * function response body the transport handed over whole (redirects,
122
+ * revalidation). Resolves undefined for empty bodies and bodies without
123
+ * a recognized encoding (e.g. a raw user Response).
124
+ */
125
+ decodeResponse<T = unknown>(response: Response): Promise<T | undefined>;
306
126
  }
307
-
308
- /**
309
- * Fills the RPC seam. Called by the transport halves when the first server
310
- * function reference is created; first write wins.
311
- * @internal
312
- */
313
- export function provideServerFunctionRPC(rpc: ServerFunctionRPC): void;
314
-
315
- /**
316
- * The registered RPC surface, or undefined when no server function exists
317
- * in this build's graph. Integration plumbing (routers): gate every use of
318
- * the transport/codec behind this read instead of importing it — an app
319
- * with no server functions then ships none of it, while a reference in the
320
- * bundle guarantees the seam is filled before integration code can hold
321
- * that reference (compiled output creates references at module scope).
322
- * @internal
323
- */
324
- export function getServerFunctionRPC(): ServerFunctionRPC | undefined;
325
-
326
- /**
327
- * Header carrying the body format tag (a `BodyFormat` value) —
328
- * `"X-Server-Function-Format"`.
329
- *
330
- * Transport wire detail; not meant for hand-written code.
331
- * @internal
332
- */
333
- export const BODY_FORMAT_HEADER: string;
334
-
335
- /**
336
- * FormData key used when a lone File is sent as the argument.
337
- *
338
- * Transport wire detail; not meant for hand-written code.
339
- * @internal
340
- */
341
- export const FILE_FORM_KEY: string;
342
-
343
- /**
344
- * Wire tags naming how a request/response body was encoded, carried in
345
- * `BODY_FORMAT_HEADER`.
346
- *
347
- * Transport wire detail; not meant for hand-written code.
348
- * @internal
349
- */
350
- export const BodyFormat: {
351
- readonly Serialized: "0";
352
- readonly String: "1";
353
- readonly FormData: "2";
354
- readonly URLSearchParams: "3";
355
- readonly Blob: "4";
356
- readonly File: "5";
357
- readonly ArrayBuffer: "6";
358
- readonly Uint8Array: "7";
359
- /**
360
- * Plain `JSON.stringify` — the fast path for JSON-safe payloads on both
361
- * legs: argument lists on the request, results on the response.
362
- */
363
- readonly Json: "8";
364
- };
365
-
366
127
  /**
367
128
  * Transport wire detail; not meant for hand-written code.
368
129
  * @internal
369
130
  */
370
131
  export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
371
-
372
- /**
373
- * Whether a value survives a `JSON.stringify` round trip faithfully: JSON
374
- * primitives (finite numbers only), arrays, and plain objects. Anything
375
- * else Dates, Maps, typed arrays, undefined (bare or as a property),
376
- * NaN, class instances, cyclic structures — needs the codec. Never throws:
377
- * cycles and pathological depth answer `false`. Both peers negotiate the
378
- * wire format with this guard: the client for argument lists, the server
379
- * for results.
380
- */
381
- export function isJSONSafe(value: unknown): boolean;
382
-
383
- /**
384
- * Picks a direct HTTP encoding (headers + BodyInit) for values that have
385
- * one strings, FormData, URLSearchParams, File, Blob, ArrayBuffer,
386
- * Uint8Array. Returns undefined when the value needs the serializer.
387
- *
388
- * Transport building block used by the fetch transport and the HTTP
389
- * handler; not meant for hand-written code.
390
- * @internal
391
- */
392
- export function getHeadersAndBody(
393
- body: unknown
394
- ): { headers?: Record<string, string>; body: BodyInit } | undefined;
395
-
396
- /**
397
- * Decodes a Request/Response body according to its `BODY_FORMAT_HEADER`
398
- * tag (falling back to content-type sniffing for form posts that never saw
399
- * the client runtime). The inverse of `getHeadersAndBody` + the serialized
400
- * stream. Resolves undefined for bodies without a recognized encoding.
401
- *
402
- * Transport building block; use `decodeResponse` from integration code.
403
- * @internal
404
- */
405
- export function extractBody(
406
- source: Request | Response,
407
- codecOptions?: JSONCodecOptions
408
- ): Promise<unknown>;
409
-
410
- /**
132
+ export declare function configureServerFunctionsCodec(codec: JSONCodecOptions | undefined): void;
133
+ export declare function getServerFunctionsCodec(): JSONCodecOptions | undefined;
134
+ export declare function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
135
+ export declare function getFlightDataConsumer(): FlightDataConsumer | undefined;
136
+ export declare function frameAddress(id: string, args?: readonly unknown[]): string;
137
+ export declare function serverFunctionAddress(endpoint: string, id: string): string;
138
+ export declare function parseServerFunctionAddress(pathname: string, endpoint: string): string | null;
139
+ /**
140
+ * Response header marking a thrown server-function error. The value is the
141
+ * error's message (the structured error itself travels in the body); `"true"`
142
+ * for thrown control-flow responses and non-Error values.
143
+ */
144
+ export declare const ERROR_HEADER = "X-Server-Function-Error";
145
+ export declare function encodeErrorHeaderValue(value: string): string;
146
+ export declare function decodeErrorHeaderValue(value: string): string;
147
+ /**
148
+ * Header carrying a per-call instance id. Its presence tells the server a
149
+ * scripted client is on the other end (vs. a no-JS form post).
150
+ */
151
+ export declare const INSTANCE_HEADER = "X-Server-Function-Instance";
152
+ /** Header carrying the body format tag (a `BodyFormat` value). */
153
+ export declare const BODY_FORMAT_HEADER = "X-Server-Function-Format";
154
+ /**
155
+ * Header driving the single-flight protocol on both legs: on the request it
156
+ * opts the call into flight-data collection (the integration sends it on
157
+ * calls whose response should fold in data), on the response it marks a
158
+ * body carrying the standardized `{ value, data }` payload. How the data
159
+ * is produced (and what it means) is entirely the integration's business
160
+ * core only owns the wire shape and the delivery.
161
+ */
162
+ export declare const SINGLE_FLIGHT_HEADER = "X-Single-Flight";
163
+ /** FormData key used when a lone File is sent as the argument. */
164
+ export declare const FILE_FORM_KEY = "__server_function_file__";
165
+ export declare const BodyFormat: {
166
+ Serialized: string;
167
+ String: string;
168
+ FormData: string;
169
+ URLSearchParams: string;
170
+ Blob: string;
171
+ File: string;
172
+ ArrayBuffer: string;
173
+ Uint8Array: string;
174
+ /**
175
+ * Plain `JSON.stringify` — the fast path for JSON-safe payloads on both
176
+ * legs: argument lists on the request, results (single-flight envelopes
177
+ * included) on the response.
178
+ */
179
+ Json: string;
180
+ /**
181
+ * No body at all — a function that returned nothing. It marks the response
182
+ * as one the runtime encoded, which separates a void result with a status
183
+ * on it from a refusal answered by something else. Decoding falls through
184
+ * to `undefined`, which is what a peer predating the tag reads too.
185
+ */
186
+ Void: string;
187
+ };
188
+ export declare function isJSONSafe(value: unknown): boolean;
189
+ export declare function getHeadersAndBody(body: unknown): {
190
+ headers?: Record<string, string>;
191
+ body: BodyInit;
192
+ } | undefined;
193
+ export declare function extractBody(source: Request | Response, codecOptions?: JSONCodecOptions): Promise<unknown>;
194
+ export declare function createChunk(data: string): Uint8Array;
195
+ export declare class ChunkReader {
196
+ constructor(stream: any);
197
+ readChunk(): Promise<void>;
198
+ next(): Promise<{
199
+ done: boolean;
200
+ value: string;
201
+ }>;
202
+ drain(interpret: any): Promise<void>;
203
+ } /**
411
204
  * Serializes a value as a stream of length-prefixed SerovalNode chunks.
412
205
  * Async values (promises, streams) keep the stream open until they settle,
413
206
  * so one connection carries incremental results. Codec options must match
@@ -416,108 +209,12 @@ export function extractBody(
416
209
  * Transport building block; not meant for hand-written code.
417
210
  * @internal
418
211
  */
419
- export function serializeStream(
420
- value: unknown,
421
- codecOptions?: JSONCodecOptions
422
- ): ReadableStream<Uint8Array>;
423
-
424
- /**
425
- * `serializeStream` drained to a string (async values fully awaited).
426
- *
427
- * Transport building block; not meant for hand-written code.
428
- * @internal
429
- */
430
- export function serializeString(value: unknown, codecOptions?: JSONCodecOptions): Promise<string>;
431
-
432
- /**
433
- * Decodes a framed chunk stream from a Request/Response body. Resolves with
434
- * the first chunk's value (the source value); later chunks settle the async
435
- * values referenced inside it as they arrive.
436
- *
437
- * Transport building block; use `decodeResponse` from integration code.
438
- * @internal
439
- */
440
- export function deserializeStream<T = unknown>(
441
- source: Request | Response,
442
- codecOptions?: JSONCodecOptions
443
- ): Promise<T>;
444
-
445
- /**
446
- * `deserializeStream` for an already-buffered string.
447
- *
448
- * Transport building block; not meant for hand-written code.
449
- * @internal
450
- */
451
- export function deserializeString<T = unknown>(
452
- text: string,
453
- codecOptions?: JSONCodecOptions
454
- ): Promise<T>;
455
-
456
- /**
457
- * Decodes a server function response body using the configured codec. This
458
- * is the integration-facing decoder: routers call it on responses the
459
- * transport hands over whole — redirects, revalidation, single-flight
460
- * payloads — to recover the structured value inside. Resolves undefined for
461
- * empty bodies and bodies without a recognized encoding (e.g. a raw user
462
- * Response). Renderer- and platform-neutral: safe to use from universal
463
- * code.
464
- *
465
- * @param response the transport response; its body is read from a clone,
466
- * so the original stays readable
467
- * @param codecOptions overrides the configured codec for this call
468
- */
469
- export function decodeResponse<T = unknown>(
470
- response: Response,
471
- codecOptions?: JSONCodecOptions
472
- ): Promise<T | undefined>;
473
-
474
- /**
475
- * `decodeResponse` plus the single-flight envelope split: when the response
476
- * carries the single-flight header the decoded `{ value, data }` payload is
477
- * unwrapped into `{ value, flightData }`; otherwise the decoded body (or
478
- * undefined for body-less responses) rides as `{ value }`. Integrations
479
- * that apply response metadata themselves use this so the payload shape
480
- * stays core's own.
481
- *
482
- * Integration plumbing; not meant for hand-written application code.
483
- * @internal
484
- */
485
- export function decodeResponsePayload<T = unknown, D = unknown>(
486
- response: Response,
487
- codecOptions?: JSONCodecOptions
488
- ): Promise<{ value: T | undefined; flightData?: D }>;
489
-
490
- /**
491
- * Frame one payload for the server-function wire: a `;0x<len32>;` length
492
- * prefix followed by the utf-8 data. Both transports (server-function
493
- * responses and frame streams) share this framing.
494
- *
495
- * Transport wire detail; not meant for hand-written code.
496
- * @internal
497
- */
498
- export function createChunk(data: string): Uint8Array;
499
-
500
- /**
501
- * Incremental decoder for `createChunk` framing over a byte stream: `next()`
502
- * yields one complete payload string per call (async-iterator result shape),
503
- * buffering partial frames internally until their length prefix is satisfied.
504
- *
505
- * Transport wire detail; not meant for hand-written code.
506
- * @internal
507
- */
508
- export class ChunkReader {
509
- constructor(stream: ReadableStream<Uint8Array>);
510
- next(): Promise<{ done: boolean; value: string | undefined }>;
511
- }
512
-
513
- /**
514
- * The intrinsic wire address of a server-component call: the function id,
515
- * suffixed with a realm-stable hash of the arguments when there are any.
516
- * Both peers derive it independently — the server names flight regions with
517
- * it, the client routes them by it — so it must stay deterministic across
518
- * realms and releases.
519
- *
520
- * Transport wire detail; not meant for hand-written code.
521
- * @internal
522
- */
523
- export function frameAddress(id: string, args?: readonly unknown[]): string;
212
+ export declare function serializeStream(value: unknown, codecOptions?: JSONCodecOptions): ReadableStream<Uint8Array>;
213
+ export declare function serializeString(value: unknown, codecOptions?: JSONCodecOptions): Promise<string>;
214
+ export declare function deserializeStream<T = unknown>(source: Request | Response, codecOptions?: JSONCodecOptions): Promise<T>;
215
+ export declare function deserializeString<T = unknown>(text: string, codecOptions?: JSONCodecOptions): Promise<T>;
216
+ export declare function decodeResponse<T = unknown>(response: Response, codecOptions?: JSONCodecOptions): Promise<T | undefined>;
217
+ export declare function decodeResponsePayload<T = unknown, D = unknown>(response: Response, codecOptions?: JSONCodecOptions): Promise<{
218
+ value: T | undefined;
219
+ flightData?: D;
220
+ }>;