@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.20

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 (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +783 -223
  3. package/dist/dev.js +757 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +772 -196
  7. package/dist/web.js +746 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +370 -0
  16. package/server-functions/dist/client.js +363 -0
  17. package/server-functions/dist/server.cjs +542 -0
  18. package/server-functions/dist/server.js +531 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +63 -0
  32. package/types/server-functions/server.d.ts +188 -0
  33. package/types/server-functions/shared.d.ts +171 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +63 -0
  45. package/types-cjs/server-functions/server.d.cts +188 -0
  46. package/types-cjs/server-functions/shared.d.cts +171 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Envelope pairing HTTP metadata (a `Response`) with an in-memory value.
3
+ * Produced by `respond()` and by server-function `transformResult`
4
+ * implementations (e.g. single-flight payloads). The HTTP handler forwards
5
+ * `response`'s headers and (non-redirect) status and encodes `value` as the
6
+ * body through the codec, while client-only integrations read `value`
7
+ * directly — no reparse. Mostly consumed by integrations (routers);
8
+ * application code usually just returns what `respond()` gives it.
9
+ */
10
+ export class ResponseEnvelope<T = unknown> {
11
+ constructor(response: Response | undefined, value: T);
12
+ /** The HTTP metadata: status and headers to forward (body ignored by integrations). */
13
+ response: Response | undefined;
14
+ /** The structured value the caller receives. */
15
+ value: T;
16
+ }
17
+
18
+ /**
19
+ * Whether `value` is a `ResponseEnvelope`. Uses a registered-symbol brand
20
+ * rather than `instanceof`, so it stays correct when separately bundled
21
+ * entries each carry a copy of the class. Integrations should always use
22
+ * this over `instanceof`.
23
+ */
24
+ export function isResponseEnvelope(value: unknown): value is ResponseEnvelope;
25
+
26
+ /** `ResponseInit` accepted by the response helpers, plus `revalidate`. */
27
+ export interface ResponseHelperInit extends ResponseInit {
28
+ /**
29
+ * Cache keys the mutation invalidated, carried in the `X-Revalidate`
30
+ * header. Opaque to the protocol — the integration's keyed cache (e.g.
31
+ * the router's `query` cache) assigns them meaning.
32
+ */
33
+ revalidate?: string | string[];
34
+ }
35
+
36
+ /**
37
+ * Response redirecting to `url` (default status 302). Return (or throw) it
38
+ * from a server function — the HTTP handler forwards the redirect for the
39
+ * client integration to follow — or return it from a client-side action,
40
+ * where the integration interprets it in memory. Same object, same
41
+ * meaning, both sides.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { redirect } from "@solidjs/web";
46
+ *
47
+ * async function login(form: FormData) {
48
+ * "use server";
49
+ * // ...
50
+ * return redirect("/dashboard", { revalidate: "session" });
51
+ * }
52
+ * ```
53
+ */
54
+ export function redirect(url: string, init?: number | ResponseHelperInit): Response;
55
+
56
+ /**
57
+ * Empty response requesting revalidation of the named cache keys — all of
58
+ * them when omitted. For mutations whose only effect the caller needs is
59
+ * "refetch your data".
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { reload } from "@solidjs/web";
64
+ *
65
+ * async function addTodo(title: string) {
66
+ * "use server";
67
+ * await db.insert(title);
68
+ * return reload({ revalidate: "todos" });
69
+ * }
70
+ * ```
71
+ */
72
+ export function reload(init?: ResponseHelperInit): Response;
73
+
74
+ /**
75
+ * A value paired with response metadata (status, headers, `revalidate`) —
76
+ * for the things a naked return can't express. Scripted callers receive
77
+ * `value` transparently (the transport unwraps the envelope), and
78
+ * progressive enhancement stays invisible: the carried response holds a
79
+ * plain JSON body so consumers without the client runtime (no-JS form
80
+ * posts, direct HTTP) get real JSON.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { respond } from "@solidjs/web";
85
+ *
86
+ * async function createItem(input: Item) {
87
+ * "use server";
88
+ * const item = await db.create(input);
89
+ * return respond(item, { status: 201, revalidate: "items" });
90
+ * }
91
+ * ```
92
+ */
93
+ export function respond<T>(value: T, init?: ResponseHelperInit): ResponseEnvelope<T>;
@@ -0,0 +1,139 @@
1
+ import { Plugin, Serializer, SerovalNode } from "seroval";
2
+
3
+ /**
4
+ * Seroval's node shape — the intermediate representation `serializeJSON`
5
+ * emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
6
+ */
7
+ export type { SerovalNode };
8
+
9
+ /**
10
+ * A Seroval plugin usable with the web serializers — teaches the codec how
11
+ * to encode/decode a custom value type. Supply matching plugins on both
12
+ * peers of a transport.
13
+ */
14
+ export type SerializerPlugin = Plugin<any, any>;
15
+
16
+ /**
17
+ * Baseline plugin set for serializing web-platform values (AbortSignal,
18
+ * Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
19
+ * Applied by every serializer in this module; custom plugins compose ahead
20
+ * of it via `resolveSerializerPlugins`.
21
+ */
22
+ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
23
+
24
+ /**
25
+ * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
26
+ * first so they can shadow a default for values both would match. Returns a
27
+ * fresh array; the defaults are never mutated. Useful when handing a full
28
+ * plugin list to another serialization layer.
29
+ */
30
+ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
31
+
32
+ /** Options for `createSerializer`. */
33
+ export interface WebSerializerOptions {
34
+ /** Name of the global object the emitted scripts write resolved values into. */
35
+ globalIdentifier: string;
36
+ /** Cross-reference scope id, for isolating multiple streams on one page. */
37
+ scopeId?: string;
38
+ /**
39
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays).
41
+ */
42
+ disabledFeatures?: number;
43
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
44
+ plugins?: SerializerPlugin[];
45
+ /** Receives each emitted script chunk. */
46
+ onData: (result: string) => void;
47
+ onError?: (error: unknown) => void;
48
+ /** Fires once all async values have settled. */
49
+ onDone?: () => void;
50
+ }
51
+
52
+ /**
53
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
54
+ * set and the default feature policy. Emits JavaScript chunks (through
55
+ * `onData`) that reconstruct the values under `globalIdentifier` when
56
+ * evaluated — the script-injection form of serialization renderers build
57
+ * on. For a JSON-based wire codec (no eval on the receiving side), use
58
+ * `serializeJSON` / `createJSONDeserializer` instead.
59
+ */
60
+ export function createSerializer(options: WebSerializerOptions): Serializer;
61
+
62
+ /**
63
+ * Options for `createHydrationSerializer` — `WebSerializerOptions` minus
64
+ * the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
65
+ * @internal
66
+ */
67
+ export type HydrationSerializerOptions = Omit<
68
+ WebSerializerOptions,
69
+ "globalIdentifier" | "disabledFeatures"
70
+ >;
71
+
72
+ /**
73
+ * Renderer primitive — the serializer SSR uses for hydration output. Pins
74
+ * the hydration global (`_$HY.r`) and feature policy; only the wiring
75
+ * options (callbacks, scope, extra plugins) are configurable. Not meant
76
+ * for hand-written code — custom serialization should use
77
+ * `createSerializer` or the JSON codec.
78
+ * @internal
79
+ */
80
+ export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
81
+
82
+ /**
83
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
84
+ * emits ahead of hydration data for a render scope. Not meant for
85
+ * hand-written code.
86
+ * @internal
87
+ */
88
+ export function getLocalHeaderScript(id?: string): string;
89
+
90
+ // ---- JSON codec (server function transports) ----
91
+
92
+ /**
93
+ * Options shared by both halves of the JSON codec. All of them must match
94
+ * on the serializing and deserializing peer or payloads will not
95
+ * round-trip — for server functions, set them once through the
96
+ * client/server `codec` config option.
97
+ */
98
+ export interface JSONCodecOptions {
99
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
100
+ plugins?: SerializerPlugin[];
101
+ /**
102
+ * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
103
+ * (payloads may come from an untrusted peer). Must match on both peers.
104
+ */
105
+ disabledFeatures?: number;
106
+ /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
107
+ depthLimit?: number;
108
+ }
109
+
110
+ /** Options for `serializeJSON`. */
111
+ export interface JSONSerializeOptions extends JSONCodecOptions {
112
+ /**
113
+ * Receives each serialized node; `initial` is true for the first chunk
114
+ * (the source value itself). Async values produce additional chunks as
115
+ * they resolve.
116
+ */
117
+ onParse: (node: SerovalNode, initial: boolean) => void;
118
+ onError?: (error: unknown) => void;
119
+ /** Fires once all async values have settled. */
120
+ onDone?: () => void;
121
+ }
122
+
123
+ /**
124
+ * Serializes `value` as SerovalNode chunks delivered through `onParse` —
125
+ * the encoding half of the eval-free JSON codec (RPC-style transports;
126
+ * the deserializing peer needs no script evaluation, so CSP-safe). Wire
127
+ * framing of the nodes is the transport's concern. Returns a cancel
128
+ * function that aborts pending async serialization.
129
+ */
130
+ export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
131
+
132
+ /**
133
+ * Creates the decoding counterpart of `serializeJSON`. Cross-references
134
+ * between chunks resolve through state shared across calls, so all chunks
135
+ * from one stream must go through the same deserializer instance. The first
136
+ * chunk's return value is the decoded source value; feeding later chunks
137
+ * settles the async values referenced inside it.
138
+ */
139
+ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
@@ -0,0 +1,63 @@
1
+ import { JSONCodecOptions } from "../serializer.cjs";
2
+
3
+ export { FUNCTION_HEADER, INSTANCE_HEADER, decodeResponse } from "./shared.cjs";
4
+
5
+ /** Options for `configureServerFunctionsClient`. */
6
+ export interface ServerFunctionsClientConfig {
7
+ /**
8
+ * Endpoint the server's HTTP handler is mounted on. Must match the
9
+ * server configuration — SSR'd reference `url`s (e.g. form actions) and
10
+ * client fetches both derive from it. Prefix it when the app serves from
11
+ * a base path (e.g. `` `${BASE_URL}_server` ``).
12
+ * @default "/_server"
13
+ */
14
+ endpoint?: string;
15
+ /**
16
+ * Codec options (extra plugins etc.) for encoding arguments and decoding
17
+ * results — must match the server's. Stored in the shared layer, so
18
+ * `decodeResponse` sees them too.
19
+ */
20
+ codec?: JSONCodecOptions;
21
+ }
22
+
23
+ /**
24
+ * Configures the client transport. Call once, before any server function is
25
+ * invoked — typically in the client entry, next to `hydrate()`. Only needed
26
+ * when deviating from the defaults (custom endpoint or codec plugins).
27
+ */
28
+ export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
29
+
30
+ /**
31
+ * What a server function import is at runtime on the client: an async
32
+ * callable that fetches the server, plus escape hatches for forms and
33
+ * custom requests.
34
+ */
35
+ export interface ServerFunctionCallable {
36
+ (...args: any[]): Promise<any>;
37
+ /** URL invoking this function directly over HTTP (e.g. form `action`s). */
38
+ url: string;
39
+ /**
40
+ * Variant issuing GET requests with the arguments encoded in the query
41
+ * string — cacheable by HTTP infrastructure.
42
+ */
43
+ GET: ServerFunctionCallable;
44
+ /** Variant applying a custom RequestInit to every call (headers etc.). */
45
+ withOptions(options: RequestInit): ServerFunctionCallable;
46
+ }
47
+
48
+ /**
49
+ * Compiler ABI — emitted by compiled `"use server"` client output where a
50
+ * server function was referenced; produces the fetch-backed callable for
51
+ * the function's build-stable id. Not meant for hand-written code.
52
+ * @internal
53
+ */
54
+ export function createServerReference(id: string): ServerFunctionCallable;
55
+
56
+ /**
57
+ * Compiler ABI — only ever referenced by server-mode compiler output;
58
+ * throws so a misconfigured build (server transform feeding a client
59
+ * bundle) fails loudly instead of with a missing-export error. Not meant
60
+ * for hand-written code.
61
+ * @internal
62
+ */
63
+ export function registerServerReference(): never;
@@ -0,0 +1,188 @@
1
+ import { ResponseEnvelope } from "../response.cjs";
2
+ import { JSONCodecOptions } from "../serializer.cjs";
3
+ import { RequestEvent } from "../server.cjs";
4
+
5
+ export { FUNCTION_HEADER, INSTANCE_HEADER, decodeResponse } from "./shared.cjs";
6
+
7
+ /**
8
+ * The request event a server function call runs under: the base
9
+ * `RequestEvent` (request + locals) plus `serverOnly`, set when the call is
10
+ * an in-process SSR invocation whose result never serializes to a client.
11
+ */
12
+ export interface ServerFunctionEvent extends RequestEvent {
13
+ serverOnly?: boolean;
14
+ }
15
+
16
+ /** Options for `configureServerFunctionsServer`. */
17
+ export interface ServerFunctionsServerConfig {
18
+ /**
19
+ * Establishes the request-event scope for a call — the function passed
20
+ * runs with `event` visible to `getRequestEvent()`. Wire it to
21
+ * `provideRequestEvent` from `@solidjs/web/storage` (or the framework's
22
+ * equivalent). When omitted, falls back to the AsyncLocalStorage instance
23
+ * an established request scope parks on the global.
24
+ */
25
+ provideEvent?: <T>(event: ServerFunctionEvent, fn: () => T) => T;
26
+ /**
27
+ * Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
28
+ * references (e.g. form actions) — must match the client configuration.
29
+ * Prefix it when the app serves from a base path (e.g.
30
+ * `` `${BASE_URL}_server` ``).
31
+ * @default "/_server"
32
+ */
33
+ endpoint?: string;
34
+ /**
35
+ * Codec options (extra plugins etc.) for decoding arguments and encoding
36
+ * results — must match the client's. Stored in the shared layer, so
37
+ * `decodeResponse` sees them too.
38
+ */
39
+ codec?: JSONCodecOptions;
40
+ }
41
+
42
+ /**
43
+ * Configures the server runtime. Call once at server startup, before
44
+ * handling requests. Only needed when deviating from the defaults (custom
45
+ * endpoint, codec plugins, or an explicit event provider).
46
+ */
47
+ export function configureServerFunctionsServer(config?: ServerFunctionsServerConfig): void;
48
+
49
+ /**
50
+ * A registered server function: its build-stable id paired with the
51
+ * original implementation. Returned by `registerServerReference` and
52
+ * consumed by the server-side `createServerReference`.
53
+ *
54
+ * Compiler ABI shape; hand-written code rarely constructs these.
55
+ * @internal
56
+ */
57
+ export interface ServerFunctionReference<T extends any[] = any[], R = any> {
58
+ id: string;
59
+ fn: (...args: T) => R;
60
+ }
61
+
62
+ /**
63
+ * Adds a function to the dispatch registry under an id and returns it
64
+ * unchanged. The low-level registry write for integrations registering
65
+ * functions outside the compiler (e.g. a router registering its own
66
+ * endpoints); compiled output goes through `registerServerReference`
67
+ * instead. Ids must be stable across the client and server builds.
68
+ */
69
+ export function registerServerFunction<T extends any[], R>(
70
+ id: string,
71
+ callback: (...args: T) => R
72
+ ): (...args: T) => R;
73
+
74
+ /**
75
+ * Looks up a registered server function by id; throws for unknown ids.
76
+ * The HTTP handler uses this for dispatch — integrations building custom
77
+ * dispatch (or introspection) can too.
78
+ */
79
+ export function getServerFunction<T extends any[], R>(id: string): (...args: T) => R;
80
+
81
+ /**
82
+ * Compiler ABI — emitted by compiled `"use server"` server output for
83
+ * every server function: registers `fn` for HTTP dispatch under its
84
+ * build-stable id and returns the reference the server-side
85
+ * `createServerReference` consumes. Not meant for hand-written code.
86
+ * @internal
87
+ */
88
+ export function registerServerReference<T extends any[], R>(
89
+ id: string,
90
+ fn: (...args: T) => R
91
+ ): ServerFunctionReference<T, R>;
92
+
93
+ /**
94
+ * Compiler ABI — emitted by compiled `"use server"` server output where
95
+ * the function was referenced; produces the server-side callable. Calling
96
+ * it during SSR runs the original function in-process (no HTTP), under a
97
+ * request event derived from the current one — marked `serverOnly` and
98
+ * carrying the function's meta. Not meant for hand-written code.
99
+ * @internal
100
+ */
101
+ export function createServerReference<T extends any[], R>(
102
+ reference: ServerFunctionReference<T, R>
103
+ ): (...args: T) => R;
104
+
105
+ /** Identity of the currently executing server function. */
106
+ export interface ServerFunctionMeta {
107
+ id: string;
108
+ }
109
+
110
+ /**
111
+ * Reads the calling server function's meta (its id) off the current request
112
+ * event — usable inside a server function body, e.g. to key caches or logs
113
+ * by function. Returns undefined outside a server function call.
114
+ */
115
+ export function getServerFunctionMeta(): ServerFunctionMeta | undefined;
116
+
117
+ /**
118
+ * Hooks layering framework policy onto `handleServerFunctionRequest`.
119
+ * All are optional — the bare handler dispatches, scopes events, and
120
+ * encodes results on its own.
121
+ */
122
+ export interface HandleServerFunctionOptions {
123
+ /**
124
+ * Builds the request event a call runs under (default: bare
125
+ * `{ request, locals: {} }`). Integrations supply their richer event
126
+ * (cookies, response helpers, platform handles).
127
+ */
128
+ createEvent?(request: Request): ServerFunctionEvent;
129
+ /**
130
+ * Overrides the configured event provider for this handler — same
131
+ * contract as the `provideEvent` config option.
132
+ */
133
+ provideEvent?<T>(event: ServerFunctionEvent, fn: () => T): T;
134
+ /**
135
+ * Observes or replaces the function's result before encoding — the
136
+ * extension point for policies like single-flight payloads. Runs for
137
+ * returned and thrown results alike (`context.thrown` distinguishes);
138
+ * `context.instance` is null for no-JS calls. Return the result
139
+ * unchanged to pass through, or a `ResponseEnvelope` (exposed through
140
+ * the core entry) to send HTTP metadata plus a structured payload.
141
+ */
142
+ transformResult?(
143
+ event: ServerFunctionEvent,
144
+ result: unknown,
145
+ context: { instance: string | null; request: Request; thrown?: boolean }
146
+ ): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
147
+ /**
148
+ * Builds the response for calls made without the client runtime (no
149
+ * instance header — no-JS form posts, direct HTTP) — the extension
150
+ * point for conventions like redirect-with-flash-cookie. Receives the
151
+ * (transformed) result, the request, and the decoded arguments; `thrown`
152
+ * is set when the result was thrown rather than returned. Defaults to
153
+ * the normal serialized response.
154
+ */
155
+ handleNoJS?(
156
+ result: unknown,
157
+ request: Request,
158
+ args: unknown[],
159
+ thrown?: boolean
160
+ ): Response | Promise<Response>;
161
+ /** Overrides the configured codec options for this handler. */
162
+ codec?: JSONCodecOptions;
163
+ }
164
+
165
+ /**
166
+ * Web-standard HTTP handler for server function calls: resolves the
167
+ * function id from the request, decodes arguments, runs the function under
168
+ * a request-event scope, and encodes the result (forwarding
169
+ * redirect/revalidation metadata through headers). Mount it on the endpoint
170
+ * the client transport targets (default `/_server`); platform adapters
171
+ * (h3, express, ...) convert their request shape to a web `Request` around
172
+ * it.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { handleServerFunctionRequest } from "@solidjs/web/server-functions";
177
+ * import "virtual:solid-server-function-manifest";
178
+ *
179
+ * // in the server's request handling:
180
+ * if (url.pathname.startsWith("/_server")) {
181
+ * return handleServerFunctionRequest(request);
182
+ * }
183
+ * ```
184
+ */
185
+ export function handleServerFunctionRequest(
186
+ request: Request,
187
+ options?: HandleServerFunctionOptions
188
+ ): Promise<Response>;
@@ -0,0 +1,171 @@
1
+ import { JSONCodecOptions } from "../serializer.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
+ export function getServerFunctionsCodec(): JSONCodecOptions | undefined;
23
+
24
+ /**
25
+ * Request header carrying the server function id (`"X-Server-Function-Id"`).
26
+ * Integrations can read it to identify which function a request targets;
27
+ * the id also arrives as the `id` query parameter for GET calls and no-JS
28
+ * form posts.
29
+ */
30
+ export const FUNCTION_HEADER: string;
31
+
32
+ /**
33
+ * Request header carrying a per-call instance id
34
+ * (`"X-Server-Function-Instance"`). Its presence tells the server the call
35
+ * came through the client runtime — its absence marks a no-JS form post or
36
+ * direct HTTP call, which receive plain responses instead of codec-encoded
37
+ * ones.
38
+ */
39
+ export const INSTANCE_HEADER: string;
40
+
41
+ /**
42
+ * Header carrying the body format tag (a `BodyFormat` value) —
43
+ * `"X-Server-Function-Format"`.
44
+ *
45
+ * Transport wire detail; not meant for hand-written code.
46
+ * @internal
47
+ */
48
+ export const BODY_FORMAT_HEADER: string;
49
+
50
+ /**
51
+ * FormData key used when a lone File is sent as the argument.
52
+ *
53
+ * Transport wire detail; not meant for hand-written code.
54
+ * @internal
55
+ */
56
+ export const FILE_FORM_KEY: string;
57
+
58
+ /**
59
+ * Wire tags naming how a request/response body was encoded, carried in
60
+ * `BODY_FORMAT_HEADER`.
61
+ *
62
+ * Transport wire detail; not meant for hand-written code.
63
+ * @internal
64
+ */
65
+ export const BodyFormat: {
66
+ readonly Serialized: "0";
67
+ readonly String: "1";
68
+ readonly FormData: "2";
69
+ readonly URLSearchParams: "3";
70
+ readonly Blob: "4";
71
+ readonly File: "5";
72
+ readonly ArrayBuffer: "6";
73
+ readonly Uint8Array: "7";
74
+ };
75
+
76
+ /**
77
+ * Transport wire detail; not meant for hand-written code.
78
+ * @internal
79
+ */
80
+ export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
81
+
82
+ /**
83
+ * Picks a direct HTTP encoding (headers + BodyInit) for values that have
84
+ * one — strings, FormData, URLSearchParams, File, Blob, ArrayBuffer,
85
+ * Uint8Array. Returns undefined when the value needs the serializer.
86
+ *
87
+ * Transport building block used by the fetch transport and the HTTP
88
+ * handler; not meant for hand-written code.
89
+ * @internal
90
+ */
91
+ export function getHeadersAndBody(
92
+ body: unknown
93
+ ): { headers?: Record<string, string>; body: BodyInit } | undefined;
94
+
95
+ /**
96
+ * Decodes a Request/Response body according to its `BODY_FORMAT_HEADER`
97
+ * tag (falling back to content-type sniffing for form posts that never saw
98
+ * the client runtime). The inverse of `getHeadersAndBody` + the serialized
99
+ * stream. Resolves undefined for bodies without a recognized encoding.
100
+ *
101
+ * Transport building block; use `decodeResponse` from integration code.
102
+ * @internal
103
+ */
104
+ export function extractBody(
105
+ source: Request | Response,
106
+ codecOptions?: JSONCodecOptions
107
+ ): Promise<unknown>;
108
+
109
+ /**
110
+ * Serializes a value as a stream of length-prefixed SerovalNode chunks.
111
+ * Async values (promises, streams) keep the stream open until they settle,
112
+ * so one connection carries incremental results. Codec options must match
113
+ * the deserializing peer.
114
+ *
115
+ * Transport building block; not meant for hand-written code.
116
+ * @internal
117
+ */
118
+ export function serializeStream(
119
+ value: unknown,
120
+ codecOptions?: JSONCodecOptions
121
+ ): ReadableStream<Uint8Array>;
122
+
123
+ /**
124
+ * `serializeStream` drained to a string (async values fully awaited).
125
+ *
126
+ * Transport building block; not meant for hand-written code.
127
+ * @internal
128
+ */
129
+ export function serializeString(value: unknown, codecOptions?: JSONCodecOptions): Promise<string>;
130
+
131
+ /**
132
+ * Decodes a framed chunk stream from a Request/Response body. Resolves with
133
+ * the first chunk's value (the source value); later chunks settle the async
134
+ * values referenced inside it as they arrive.
135
+ *
136
+ * Transport building block; use `decodeResponse` from integration code.
137
+ * @internal
138
+ */
139
+ export function deserializeStream<T = unknown>(
140
+ source: Request | Response,
141
+ codecOptions?: JSONCodecOptions
142
+ ): Promise<T>;
143
+
144
+ /**
145
+ * `deserializeStream` for an already-buffered string.
146
+ *
147
+ * Transport building block; not meant for hand-written code.
148
+ * @internal
149
+ */
150
+ export function deserializeString<T = unknown>(
151
+ text: string,
152
+ codecOptions?: JSONCodecOptions
153
+ ): Promise<T>;
154
+
155
+ /**
156
+ * Decodes a server function response body using the configured codec. This
157
+ * is the integration-facing decoder: routers call it on responses the
158
+ * transport hands over whole — redirects, revalidation, single-flight
159
+ * payloads — to recover the structured value inside. Resolves undefined for
160
+ * empty bodies and bodies without a recognized encoding (e.g. a raw user
161
+ * Response). Renderer- and platform-neutral: safe to use from universal
162
+ * code.
163
+ *
164
+ * @param response the transport response; its body is read from a clone,
165
+ * so the original stays readable
166
+ * @param codecOptions overrides the configured codec for this call
167
+ */
168
+ export function decodeResponse<T = unknown>(
169
+ response: Response,
170
+ codecOptions?: JSONCodecOptions
171
+ ): Promise<T | undefined>;