@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,182 +1,94 @@
1
- // Serialization surface (published as `@solidjs/web/serialization`): the
2
- // runtime's Seroval machinery, exposed for the runtime's own entries and
3
- // for integrations building transports on the same codec. This is
4
- // INTEGRATION-FACING plumbing, not application API — it is exempt from the
5
- // 2.0 stability guarantee and may change between releases. Application and
6
- // router code should configure `codec` on the server-function entries
7
- // instead of importing from here.
8
- import type { Serializer } from "seroval";
9
- import {
10
- JSONCodecOptions,
11
- PluginInfo,
12
- SerializerPlugin,
13
- SerovalNode
14
- } from "./serializer-decode.js";
15
-
16
- // The decode half — `SerovalNode`, the plugin TYPES, `DEFAULT_WEB_PLUGINS`,
17
- // `resolveSerializerPlugins`, `JSONCodecOptions`, `createJSONDeserializer`,
18
- // `createJSONDataTable` — is declared in serializer-decode.d.ts (published
19
- // as `@solidjs/web/serialization/decode`, the module lazy client consumers
20
- // load) and re-exported here so this remains the full surface.
21
- export * from "./serializer-decode.js";
22
-
23
- // ---- Plugin authoring ----
24
- //
25
- // Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
26
- // it is the supported way to feed the serializers' `plugins` options and
27
- // the server-function entries' `codec.plugins`. The values re-export
28
- // seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
29
- // the plugin TYPES live in serializer-decode.d.ts (hand-declared there —
30
- // see its banner for why).
31
-
32
- /**
33
- * Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
34
- * plugin authors stay on the exact seroval instance/version the runtime
35
- * serializes with. Import it from HERE, not from your own `seroval`
36
- * dependency: a plugin built against a different copy/version would not
37
- * fail the build — it would emit nodes the other peer can't interpret.
38
- *
39
- * Application-facing (see the plugin-authoring banner above).
40
- */
41
- export function createPlugin<Value, Info extends PluginInfo>(
42
- plugin: SerializerPlugin<Value, Info>
43
- ): SerializerPlugin<Value, Info>;
44
-
45
- /**
46
- * Seroval's `OpaqueReference`, re-exported from the runtime's own instance
47
- * (an `OpaqueReference` from another seroval copy fails the serializer's
48
- * instanceof check and serializes as a plain value): wraps a value so it
49
- * crosses the wire as its `replacement` (default `undefined`) while
50
- * staying readable in-process through `.value`.
51
- *
52
- * Application-facing (see the plugin-authoring banner above).
53
- */
54
- export class OpaqueReference<V, R = undefined> {
55
- readonly value: V;
56
- readonly replacement?: R;
57
- constructor(value: V, replacement?: R);
58
- }
59
-
1
+ import { Serializer } from "seroval";
2
+ import type { JSONCodecOptions, PluginInfo, SerializerPlugin, SerovalNode } from "./serializer-decode.js";
3
+ export { DEFAULT_WEB_PLUGINS, createJSONDataTable, createJSONDeserializer, resolveSerializerPlugins } from "./serializer-decode.js";
4
+ export type * from "./serializer-decode.js";
60
5
  /**
61
6
  * Options for `createSerializer`.
62
7
  *
63
8
  * Integration-facing; may change (see the entry banner).
64
9
  */
65
10
  export interface WebSerializerOptions {
66
- /** Name of the global object the emitted scripts write resolved values into. */
67
- globalIdentifier: string;
68
- /** Cross-reference scope id, for isolating multiple streams on one page. */
69
- scopeId?: string;
70
- /**
71
- * Seroval feature bitflags to exclude from output. Defaults to disabling
72
- * post-ES2017 features (AggregateError, BigInt typed arrays). Outside
73
- * development, `Error.prototype.stack` is additionally stripped on top of
74
- * any override — serialized stacks leak server paths to the client.
75
- */
76
- disabledFeatures?: number;
77
- /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
78
- plugins?: SerializerPlugin[];
79
- /** Receives each emitted script chunk. */
80
- onData: (result: string) => void;
81
- onError?: (error: unknown) => void;
82
- /** Fires once all async values have settled. */
83
- onDone?: () => void;
11
+ /** Name of the global object the emitted scripts write resolved values into. */
12
+ globalIdentifier: string;
13
+ /** Cross-reference scope id, for isolating multiple streams on one page. */
14
+ scopeId?: string;
15
+ /**
16
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
17
+ * post-ES2017 features (AggregateError, BigInt typed arrays). Outside
18
+ * development, `Error.prototype.stack` is additionally stripped on top of
19
+ * any override — serialized stacks leak server paths to the client.
20
+ */
21
+ disabledFeatures?: number;
22
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
23
+ plugins?: SerializerPlugin[];
24
+ /** Receives each emitted script chunk. */
25
+ onData: (result: string) => void;
26
+ onError?: (error: unknown) => void;
27
+ /** Fires once all async values have settled. */
28
+ onDone?: () => void;
84
29
  }
85
-
86
- /**
87
- * Creates a streaming Seroval serializer preconfigured with the web plugin
88
- * set and the default feature policy. Emits JavaScript chunks (through
89
- * `onData`) that reconstruct the values under `globalIdentifier` when
90
- * evaluated — the script-injection form of serialization renderers build
91
- * on. For a JSON-based wire codec (no eval on the receiving side), use
92
- * `serializeJSON` / `createJSONDeserializer` instead.
93
- *
94
- * Integration-facing; may change (see the entry banner).
95
- */
96
- export function createSerializer(options: WebSerializerOptions): Serializer;
97
-
98
30
  /**
99
31
  * Options for `createHydrationSerializer` — `WebSerializerOptions` minus
100
32
  * the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
101
33
  * @internal
102
34
  */
103
- export type HydrationSerializerOptions = Omit<
104
- WebSerializerOptions,
105
- "globalIdentifier" | "disabledFeatures"
106
- >;
107
-
108
- /**
109
- * Renderer primitive — the serializer SSR uses for hydration output. Pins
110
- * the hydration global (`_$HY.r`) and feature policy; only the wiring
111
- * options (callbacks, scope, extra plugins) are configurable. Not meant
112
- * for hand-written code — custom serialization should use
113
- * `createSerializer` or the JSON codec.
114
- * @internal
115
- */
116
- export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
117
-
118
- /**
119
- * Renderer primitive — returns the cross-reference bootstrap script SSR
120
- * emits ahead of hydration data for a render scope. Not meant for
121
- * hand-written code.
122
- * @internal
123
- */
124
- export function getLocalHeaderScript(id?: string): string;
125
-
126
- // ---- JSON codec (server function transports) ----
127
- // (`JSONCodecOptions` and the decode half are declared in
128
- // serializer-decode.d.ts and re-exported above.)
129
-
35
+ export type HydrationSerializerOptions = Omit<WebSerializerOptions, "globalIdentifier" | "disabledFeatures">;
130
36
  /**
131
37
  * Options for `serializeJSON`.
132
38
  *
133
39
  * Integration-facing; may change (see the entry banner).
134
40
  */
135
41
  export interface JSONSerializeOptions extends JSONCodecOptions {
136
- /**
137
- * Receives each serialized node; `initial` is true for the first chunk
138
- * (the source value itself). Async values produce additional chunks as
139
- * they resolve.
140
- */
141
- onParse: (node: SerovalNode, initial: boolean) => void;
142
- onError?: (error: unknown) => void;
143
- /** Fires once all async values have settled. */
144
- onDone?: () => void;
42
+ /**
43
+ * Receives each serialized node; `initial` is true for the first chunk
44
+ * (the source value itself). Async values produce additional chunks as
45
+ * they resolve.
46
+ */
47
+ onParse: (node: SerovalNode, initial: boolean) => void;
48
+ onError?: (error: unknown) => void;
49
+ /** Fires once all async values have settled. */
50
+ onDone?: () => void;
145
51
  }
146
-
147
- /**
148
- * Serializes `value` as SerovalNode chunks delivered through `onParse` —
149
- * the encoding half of the eval-free JSON codec (RPC-style transports;
150
- * the deserializing peer needs no script evaluation, so CSP-safe). Wire
151
- * framing of the nodes is the transport's concern. Returns a cancel
152
- * function that aborts pending async serialization.
153
- *
154
- * Integration-facing; may change (see the entry banner).
155
- */
156
- export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
157
-
158
52
  /** Options for `createJSONSerializer`. */
159
53
  export interface JSONSerializerOptions extends JSONCodecOptions {
160
- /**
161
- * Receives each keyed record — `initial` is true for a key's first node
162
- * (the written value itself); async values patch through later records
163
- * under the same key. The decoding peer is `createJSONDataTable`.
164
- */
165
- onData: (record: { key: string; node: SerovalNode; initial: boolean }) => void;
166
- onError?: (error: unknown) => void;
167
- /** Fires once `flush()` has been called and every pending value settled. */
168
- onDone?: () => void;
54
+ /**
55
+ * Receives each keyed record — `initial` is true for a key's first node
56
+ * (the written value itself); async values patch through later records
57
+ * under the same key. The decoding peer is `createJSONDataTable`.
58
+ */
59
+ onData: (record: {
60
+ key: string;
61
+ node: SerovalNode;
62
+ initial: boolean;
63
+ }) => void;
64
+ onError?: (error: unknown) => void;
65
+ /** Fires once `flush()` has been called and every pending value settled. */
66
+ onDone?: () => void;
67
+ }
68
+ export declare const createPlugin: <Value, Info extends PluginInfo>(plugin: SerializerPlugin<Value, Info>) => SerializerPlugin<Value, Info>;
69
+ export interface OpaqueReference<V = unknown, R = undefined> {
70
+ readonly value: V;
71
+ readonly replacement?: R;
169
72
  }
170
-
73
+ export declare const OpaqueReference: {
74
+ new <V, R = undefined>(value: V, replacement?: R): OpaqueReference<V, R>;
75
+ };
171
76
  /**
172
- * The keyed, streaming encoder of the eval-free JSON codec — the render
173
- * stream's data serializer (frames default to it). Each `write(key, value)`
174
- * shares one reference space, so cross-record identity holds; `flush()`
175
- * marks the write set complete (writes after it are dropped, mirroring the
176
- * hydration serializer); `close()` aborts pending async serialization.
77
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
78
+ * set and the default feature policy. Emits JavaScript chunks (through
79
+ * `onData`) that reconstruct the values under `globalIdentifier` when
80
+ * evaluated the script-injection form of serialization renderers build
81
+ * on. For a JSON-based wire codec (no eval on the receiving side), use
82
+ * `serializeJSON` / `createJSONDeserializer` instead.
83
+ *
84
+ * Integration-facing; may change (see the entry banner).
177
85
  */
178
- export function createJSONSerializer(options: JSONSerializerOptions): {
179
- write(key: string, value: unknown): void;
180
- flush(): void;
181
- close(): void;
86
+ export declare function createSerializer(options: WebSerializerOptions): Serializer;
87
+ export declare function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
88
+ export declare function getLocalHeaderScript(id?: string): string;
89
+ export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
90
+ export declare function createJSONSerializer(options: JSONSerializerOptions): {
91
+ write(key: string, value: unknown): void;
92
+ flush(): void;
93
+ close(): void;
182
94
  };
@@ -1,50 +1,17 @@
1
- import { JSONCodecOptions } from "../serializer-decode.js";
2
- import { ServerFunction, ServerFunctionMetadata } from "./shared.js";
3
-
4
- export {
5
- ChunkReader,
6
- ERROR_HEADER,
7
- FLASH_COOKIE,
8
- FUNCTION_HEADER,
9
- INSTANCE_HEADER,
10
- SINGLE_FLIGHT_HEADER,
11
- clearFlashCookie,
12
- createChunk,
13
- decodeErrorHeaderValue,
14
- decodeResponse,
15
- decodeResponsePayload,
16
- deserializeStream,
17
- encodeErrorHeaderValue,
18
- frameAddress,
19
- getFlightDataConsumer,
20
- getServerFunctionMetadata,
21
- getServerFunctionsCodec,
22
- hasFlashCookie,
23
- isServerFunction,
24
- serializeString,
25
- subscribeFlightData,
26
- withMeta
27
- } from "./shared.js";
1
+ export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, INSTANCE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, clearFlashCookie, createChunk, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, invoke, isServerFunction, serializeString, subscribeFlightData, withMeta } from "./shared.js";
28
2
  export { REVALIDATE_HEADER } from "../response.js";
29
- export type {
30
- FlightDataConsumer,
31
- FlightDataContext,
32
- ServerFunction,
33
- ServerFunctionMetadata,
34
- SingleFlightPayload
35
- } from "./shared.js";
36
-
3
+ import { JSONCodecOptions } from "../serializer-decode.js";
4
+ export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.js";
37
5
  /** The context `prepareRequest` receives alongside the outgoing RequestInit. */
38
6
  export interface PrepareRequestContext {
39
- /** The build-stable id of the function being called. */
40
- id: string;
41
- /**
42
- * The reference's declaration metadata (e.g. `method: "GET"` for
43
- * `GET(fn)` references). Plain references carry an empty object.
44
- */
45
- meta: ServerFunctionMetadata | undefined;
7
+ /** The build-stable id of the function being called. */
8
+ id: string;
9
+ /**
10
+ * The reference's declaration metadata (e.g. `method: "GET"` for
11
+ * `GET(fn)` references). Plain references carry an empty object.
12
+ */
13
+ meta: ServerFunctionMetadata | undefined;
46
14
  }
47
-
48
15
  /**
49
16
  * Client-side session-dynamic transport hook: runs before every
50
17
  * server-function fetch. Return (or mutate and return) the RequestInit the
@@ -54,141 +21,119 @@ export interface PrepareRequestContext {
54
21
  * the client-side symmetric of the server handler hooks. Single hook, not
55
22
  * a chain — compose by wrapping functions in userland.
56
23
  */
57
- export type PrepareRequestHook = (
58
- init: RequestInit,
59
- context: PrepareRequestContext
60
- ) => RequestInit | Promise<RequestInit>;
61
-
24
+ export type PrepareRequestHook = (init: RequestInit, context: PrepareRequestContext) => RequestInit | Promise<RequestInit>;
62
25
  /** Options for `configureServerFunctionsClient`. */
63
26
  export interface ServerFunctionsClientConfig {
64
- /**
65
- * Endpoint the server's HTTP handler is mounted on. Must match the
66
- * server configuration — SSR'd reference `url`s (e.g. form actions) and
67
- * client fetches both derive from it. Prefix it when the app serves from
68
- * a base path (e.g. `` `${BASE_URL}_server` ``).
69
- * @default "/_server"
70
- */
71
- endpoint?: string;
72
- /**
73
- * Codec options (extra plugins etc.) for encoding arguments and decoding
74
- * results must match the server's. Stored in the shared layer, so
75
- * `decodeResponse` sees them too.
76
- */
77
- codec?: JSONCodecOptions;
78
- /**
79
- * Runs before every server-function fetch. Return (or mutate and return)
80
- * the RequestInit the transport will use; `context.meta` is the
81
- * reference's declaration metadata (e.g. method). For session-dynamic
82
- * cross-cutting concerns bearer tokens, tracing headers:
83
- *
84
- * ```ts
85
- * configureServerFunctionsClient({
86
- * prepareRequest(init) {
87
- * return {
88
- * ...init,
89
- * headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
90
- * };
91
- * }
92
- * });
93
- * ```
94
- */
95
- prepareRequest?: PrepareRequestHook;
96
- /**
97
- * Response-side integration seam — the client mirror of the handler's
98
- * `transformResult`. `handle(response, ctx)` sees every response before
99
- * the transport decodes it; returning anything but undefined resolves the
100
- * call with that value. `capture(info)` runs synchronously at the call
101
- * site (before any await) and its return arrives as `ctx.context`, so
102
- * ambient per-call state (e.g. a reactive owner) survives to response
103
- * time. See `createServerComponentHandler` in frame-transport for the
104
- * canonical implementation.
105
- */
106
- responseHandler?: {
107
- capture?(info: { id: string; meta: unknown }): unknown;
108
- handle(
109
- response: Response,
110
- ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
111
- ): unknown;
112
- };
113
- /**
114
- * Encoder for argument lists JSON can't carry faithfully. JSON-safe args
115
- * always go as plain JSON (no codec in the bundle); anything else throws
116
- * unless this is set. Installed by `enableRichArguments()` from the
117
- * rich-args entry — set directly only for custom wire encodings.
118
- */
119
- serializeArgs?(args: unknown[]): string | Promise<string>;
27
+ /**
28
+ * Mount path the server's HTTP handler answers on. Must match the server
29
+ * configuration — the id travels as the segment after it, and SSR'd
30
+ * reference `url`s (e.g. form actions) and client fetches both derive
31
+ * from it. Prefix it when the app serves from a base path
32
+ * (e.g. `` `${BASE_URL}_server` ``).
33
+ * @default "/_server"
34
+ */
35
+ endpoint?: string;
36
+ /**
37
+ * Codec options (extra plugins etc.) for encoding arguments and decoding
38
+ * results must match the server's. Stored in the shared layer, so
39
+ * `decodeResponse` sees them too.
40
+ */
41
+ codec?: JSONCodecOptions;
42
+ /**
43
+ * Sends every server-function request retries, telemetry, a test
44
+ * double, or an app's own route. Always called as `(address, init)`, the
45
+ * address relative to the document as the global one receives it, so
46
+ * `parseServerFunctionUrl` reads the id back out for telemetry. `null`
47
+ * restores the global.
48
+ *
49
+ * ```ts
50
+ * configureServerFunctionsClient({
51
+ * fetch: (address, init) => fetch(rewrite(address), init)
52
+ * });
53
+ * ```
54
+ *
55
+ * Forward `init` — the call's `signal` rides on it, and dropping it voids
56
+ * both the caller's abort and the teardown a live source's `break`
57
+ * performs. Keep the call same-origin, since a cross-origin send is
58
+ * stamped `Sec-Fetch-Site: cross-site` and the handler's origin gate
59
+ * refuses it, and hand back what the peer answered, unread.
60
+ *
61
+ * A retrying wrapper may re-send a request that got NO response; it must
62
+ * never replay one whose response ended. A response that dies mid-body may
63
+ * have executed (mutations are not idempotent), and reconnecting a live
64
+ * source is the runtime's job a replay would race it.
65
+ *
66
+ * The wrapper replaces delivery for the requests the runtime chooses to
67
+ * send; the call-to-request mapping itself is not contractual.
68
+ */
69
+ fetch?: ((address: string, init: RequestInit) => Response | Promise<Response>) | null;
70
+ /**
71
+ * Runs before every server-function fetch. Return (or mutate and return)
72
+ * the RequestInit the transport will use; `context.meta` is the
73
+ * reference's declaration metadata (e.g. method). For session-dynamic
74
+ * cross-cutting concerns — bearer tokens, tracing headers:
75
+ *
76
+ * ```ts
77
+ * configureServerFunctionsClient({
78
+ * prepareRequest(init) {
79
+ * return {
80
+ * ...init,
81
+ * headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
82
+ * };
83
+ * }
84
+ * });
85
+ * ```
86
+ */
87
+ prepareRequest?: PrepareRequestHook;
88
+ /**
89
+ * Response-side integration seam — the client mirror of the handler's
90
+ * `transformResult`. `handle(response, ctx)` sees every response before
91
+ * the transport decodes it; returning anything but undefined resolves the
92
+ * call with that value. `capture(info)` runs synchronously at the call
93
+ * site (before any await) and its return arrives as `ctx.context`, so
94
+ * ambient per-call state (e.g. a reactive owner) survives to response
95
+ * time. See `createServerComponentHandler` in frame-transport for the
96
+ * canonical implementation.
97
+ */
98
+ responseHandler?: {
99
+ capture?(info: {
100
+ id: string;
101
+ meta: unknown;
102
+ }): unknown;
103
+ handle(response: Response, ctx: {
104
+ id: string;
105
+ meta: unknown;
106
+ args: unknown[];
107
+ context: unknown;
108
+ }): unknown;
109
+ };
110
+ /**
111
+ * Encoder for argument lists JSON can't carry faithfully. JSON-safe args
112
+ * always go as plain JSON (no codec in the bundle); anything else throws
113
+ * unless this is set. Installed by `enableRichArguments()` from the
114
+ * rich-args entry — set directly only for custom wire encodings.
115
+ */
116
+ serializeArgs?(args: unknown[]): string | Promise<string>;
120
117
  }
121
-
122
- /**
123
- * Configures the client transport. Call once, before any server function is
124
- * invoked — typically in the client entry, next to `hydrate()`. Only needed
125
- * when deviating from the defaults (custom endpoint, codec plugins, or a
126
- * `prepareRequest` hook).
127
- */
128
- export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
129
-
130
118
  export interface ServerFunctionRequestCall {
131
- type: "request";
132
- id: string;
133
- instance: string;
134
- request: Request;
135
- meta: ServerFunctionMetadata | undefined;
136
- time: number;
119
+ type: "request";
120
+ id: string;
121
+ instance: string;
122
+ request: Request;
123
+ meta: ServerFunctionMetadata | undefined;
124
+ time: number;
137
125
  }
138
-
139
126
  export interface ServerFunctionResponseCall {
140
- type: "response";
141
- id: string;
142
- instance: string;
143
- response: Response;
144
- meta: ServerFunctionMetadata | undefined;
145
- time: number;
127
+ type: "response";
128
+ id: string;
129
+ instance: string;
130
+ response: Response;
131
+ meta: ServerFunctionMetadata | undefined;
132
+ time: number;
146
133
  }
147
-
148
134
  export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
149
-
150
- /**
151
- * Observes cloned requests and responses without handling them. Subscribe
152
- * from devtools; do not use this to replace `prepareRequest` /
153
- * `responseHandler`. The server entry exports a no-op of the same name so
154
- * isomorphic `@solidjs/web/server-functions` imports resolve.
155
- */
156
- export function observeServerFunctionCalls(
157
- observer: (call: ServerFunctionCall) => void
158
- ): () => void;
159
-
160
- /**
161
- * Declares a server function callable over HTTP GET: calls to the returned
162
- * reference go out as GET requests with the arguments codec-encoded in the
163
- * query string — cacheable by HTTP infrastructure. Cache headers flow
164
- * through the handler's header forwarding
165
- * (`respond(data, { headers: { "cache-control": "max-age=60" } })`).
166
- *
167
- * The declaration rides the metadata channel
168
- * (`getServerFunctionMetadata(fn)?.method === "GET"`) for routers and
169
- * integrations to detect, and the server honors it: GET-declared functions
170
- * accept GET requests in addition to the default POST transport (declaring
171
- * GET grants, it does not revoke); functions that never declared GET answer
172
- * GET requests with 405. Server-side the wrapper is identity-flavored — SSR
173
- * calls stay in-process.
174
- *
175
- * Wrap the reference at its declaration; the compiler round-trips the call
176
- * in both builds:
177
- *
178
- * ```ts
179
- * export const getUser = GET(async (id: string) => {
180
- * "use server";
181
- * return db.users.find(id);
182
- * });
183
- * ```
184
- */
185
- export function GET<A extends readonly any[], R>(
186
- fn: (...args: A) => R
187
- ): ServerFunction<A, Awaited<R>>;
188
-
189
135
  /** Wire-state transitions a live call's iterable can report. */
190
136
  export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
191
-
192
137
  /**
193
138
  * A live call's answer: the source's iterable, plus an optional `onstatus`
194
139
  * side channel for the wire facts the reconnect loop erases from the value
@@ -198,65 +143,22 @@ export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
198
143
  * end was a definite rejection (4xx) failing fast instead of retrying.
199
144
  */
200
145
  export type LiveSource<R> = R & {
201
- onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
146
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
202
147
  };
203
-
204
- /**
205
- * Declares a value-shaped live source: a server function returning an async
206
- * iterable whose yields are successive VALUES of one logical query, with the
207
- * contract that the source re-yields current state on every invocation.
208
- * Calls to the returned reference produce an iterable that survives the
209
- * connection — post-connect deaths re-invoke with exponential backoff
210
- * (reset per healthy value, woken early by connectivity returning),
211
- * first-connect failures reject like a normal call, and `break` aborts the
212
- * in-flight request. Live calls are reads and never opt into single-flight
213
- * enveloping. Wire state, if wanted, rides the returned iterable's
214
- * `onstatus` hook. Compose with `GET` inside-out: `live(GET(fn))`.
215
- */
216
- export function live<A extends readonly any[], R>(
217
- fn: (...args: A) => R
218
- ): ServerFunction<A, LiveSource<Awaited<R>>>;
219
-
220
- /**
221
- * Compiler ABI — emitted by compiled `"use server"` client output where a
222
- * server function was referenced; produces the fetch-backed callable for
223
- * the function's build-stable id. Development builds pass the function's
224
- * source name as the trailing argument (dev-only metadata seeded on the
225
- * metadata channel; never emitted in production). Not meant for
226
- * hand-written code.
227
- *
228
- * The optional `base` targets calls at that url verbatim instead of the
229
- * configured endpoint — for integrations reconstructing a callable from a
230
- * server-rendered action url (e.g. a router intercepting a form submit whose
231
- * `action="/_server?id=...&args=..."` came off the wire): bound arguments
232
- * stay in the query string, where the server reads them for natural-encoding
233
- * bodies (FormData, urlencoded).
234
- * @internal
235
- */
236
- export function createServerReference(id: string, name?: string, base?: string): ServerFunction;
237
-
238
- /**
239
- * Compiler ABI — only ever referenced by server-mode compiler output;
240
- * throws so a misconfigured build (server transform feeding a client
241
- * bundle) fails loudly instead of with a missing-export error. Not meant
242
- * for hand-written code.
243
- * @internal
244
- */
245
- export function registerServerReference(): never;
246
-
247
148
  /**
248
149
  * Identity of the currently executing server function call — see the
249
150
  * server entry. Named here so isomorphic code can import the type from
250
151
  * either entry.
251
152
  */
252
153
  export interface ServerFunctionInvocation {
253
- id: string;
154
+ id: string;
254
155
  }
255
-
256
- /**
257
- * Client no-op mirror of the server entry's accessor: there is never a
258
- * server function call in flight on the client, so this always returns
259
- * undefined. Present so `"use server"` modules that import it stay
260
- * import-stable in client builds before dead-code elimination.
261
- */
262
- export function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
156
+ export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
157
+ export declare function serverFunctionUrl(id: string, boundArgs?: readonly unknown[]): string;
158
+ export declare function parseServerFunctionUrl(url: string): string | null;
159
+ export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
160
+ export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
161
+ export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
162
+ export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, LiveSource<Awaited<R>>>;
163
+ export declare function registerServerReference(): never;
164
+ export declare function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;