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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/dev.cjs +116 -66
  2. package/dist/dev.js +109 -65
  3. package/dist/server.cjs +386 -109
  4. package/dist/server.js +378 -113
  5. package/dist/web.cjs +113 -64
  6. package/dist/web.js +106 -63
  7. package/frames/dist/client.cjs +100 -14
  8. package/frames/dist/client.dev.cjs +103 -14
  9. package/frames/dist/client.dev.js +104 -15
  10. package/frames/dist/client.js +101 -15
  11. package/frames/dist/server.cjs +285 -154
  12. package/frames/dist/server.js +287 -156
  13. package/package.json +20 -22
  14. package/serialization/dist/decode.cjs +22 -5
  15. package/serialization/dist/decode.js +23 -6
  16. package/serialization/dist/serialization.cjs +26 -13
  17. package/serialization/dist/serialization.js +26 -8
  18. package/serialization/types/index.d.ts +69 -157
  19. package/serialization/types/serializer-decode.d.ts +89 -112
  20. package/serialization/types/serializer.d.ts +94 -0
  21. package/serialization/types-cjs/index.d.cts +69 -157
  22. package/serialization/types-cjs/serializer-decode.d.cts +89 -112
  23. package/serialization/types-cjs/serializer.d.cts +94 -0
  24. package/server-functions/dist/client.cjs +48 -7
  25. package/server-functions/dist/client.js +48 -8
  26. package/server-functions/dist/server.cjs +76 -5
  27. package/server-functions/dist/server.dev.cjs +76 -5
  28. package/server-functions/dist/server.dev.js +76 -6
  29. package/server-functions/dist/server.js +76 -6
  30. package/types/client.d.ts +150 -290
  31. package/types/constants.d.ts +18 -0
  32. package/types/cookies.d.ts +31 -75
  33. package/types/frames/frame-client.d.ts +287 -259
  34. package/types/frames/frame-container-plugin.d.ts +71 -0
  35. package/types/frames/frame-sink.d.ts +58 -160
  36. package/types/frames/frame-transport.d.ts +161 -194
  37. package/types/frames/serializer-decode.d.ts +159 -0
  38. package/types/frames/serializer.d.ts +69 -157
  39. package/types/head.d.ts +16 -0
  40. package/types/index.d.ts +0 -65
  41. package/types/index.server.d.ts +125 -0
  42. package/types/jsx.d.ts +5 -13
  43. package/types/reconcile.d.ts +1 -0
  44. package/types/render.d.ts +4 -0
  45. package/types/response.d.ts +41 -153
  46. package/types/serializer-decode.d.ts +89 -112
  47. package/types/serializer.d.ts +69 -157
  48. package/types/server-functions/client.d.ts +101 -199
  49. package/types/server-functions/flash.d.ts +10 -30
  50. package/types/server-functions/registry.d.ts +63 -0
  51. package/types/server-functions/rich-args.d.ts +1 -10
  52. package/types/server-functions/server.d.ts +301 -518
  53. package/types/server-functions/shared.d.ts +112 -458
  54. package/types/server-mock.d.ts +13 -4
  55. package/types/server.d.ts +256 -427
  56. package/types-cjs/client.d.cts +150 -290
  57. package/types-cjs/constants.d.cts +18 -0
  58. package/types-cjs/cookies.d.cts +31 -75
  59. package/types-cjs/frames/frame-client.d.cts +287 -259
  60. package/types-cjs/frames/frame-container-plugin.d.cts +71 -0
  61. package/types-cjs/frames/frame-sink.d.cts +58 -160
  62. package/types-cjs/frames/frame-transport.d.cts +161 -194
  63. package/types-cjs/frames/serializer-decode.d.cts +159 -0
  64. package/types-cjs/frames/serializer.d.cts +69 -157
  65. package/types-cjs/head.d.cts +16 -0
  66. package/types-cjs/index.d.cts +0 -65
  67. package/types-cjs/index.server.d.cts +125 -0
  68. package/types-cjs/jsx.d.cts +5 -13
  69. package/types-cjs/reconcile.d.cts +1 -0
  70. package/types-cjs/render.d.cts +4 -0
  71. package/types-cjs/response.d.cts +41 -153
  72. package/types-cjs/serializer-decode.d.cts +89 -112
  73. package/types-cjs/serializer.d.cts +69 -157
  74. package/types-cjs/server-functions/client.d.cts +101 -199
  75. package/types-cjs/server-functions/flash.d.cts +10 -30
  76. package/types-cjs/server-functions/registry.d.cts +63 -0
  77. package/types-cjs/server-functions/rich-args.d.cts +1 -10
  78. package/types-cjs/server-functions/server.d.cts +301 -518
  79. package/types-cjs/server-functions/shared.d.cts +112 -458
  80. package/types-cjs/server-mock.d.cts +13 -4
  81. package/types-cjs/server.d.cts +256 -427
  82. package/LICENSE +0 -21
  83. package/types/core.d.ts +0 -6
  84. package/types-cjs/core.d.cts +0 -6
@@ -1,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.cjs";
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.cjs";
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.cjs";
3
+ export { DEFAULT_WEB_PLUGINS, createJSONDataTable, createJSONDeserializer, resolveSerializerPlugins } from "./serializer-decode.cjs";
4
+ export type * from "./serializer-decode.cjs";
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.cjs";
2
- import { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
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.cjs";
1
+ export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, createChunk, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, isServerFunction, serializeString, subscribeFlightData, withMeta } from "./shared.cjs";
28
2
  export { REVALIDATE_HEADER } from "../response.cjs";
29
- export type {
30
- FlightDataConsumer,
31
- FlightDataContext,
32
- ServerFunction,
33
- ServerFunctionMetadata,
34
- SingleFlightPayload
35
- } from "./shared.cjs";
36
-
3
+ import { JSONCodecOptions } from "../serializer-decode.cjs";
4
+ export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
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,178 +21,113 @@ 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
+ * Endpoint the server's HTTP handler is mounted on. Must match the
29
+ * server configuration — SSR'd reference `url`s (e.g. form actions) and
30
+ * client fetches both derive from it. Prefix it when the app serves from
31
+ * a base path (e.g. `` `${BASE_URL}_server` ``).
32
+ * @default "/_server"
33
+ */
34
+ endpoint?: string;
35
+ /**
36
+ * Codec options (extra plugins etc.) for encoding arguments and decoding
37
+ * results — must match the server's. Stored in the shared layer, so
38
+ * `decodeResponse` sees them too.
39
+ */
40
+ codec?: JSONCodecOptions;
41
+ /**
42
+ * Runs before every server-function fetch. Return (or mutate and return)
43
+ * the RequestInit the transport will use; `context.meta` is the
44
+ * reference's declaration metadata (e.g. method). For session-dynamic
45
+ * cross-cutting concerns — bearer tokens, tracing headers:
46
+ *
47
+ * ```ts
48
+ * configureServerFunctionsClient({
49
+ * prepareRequest(init) {
50
+ * return {
51
+ * ...init,
52
+ * headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
53
+ * };
54
+ * }
55
+ * });
56
+ * ```
57
+ */
58
+ prepareRequest?: PrepareRequestHook;
59
+ /**
60
+ * Response-side integration seam — the client mirror of the handler's
61
+ * `transformResult`. `handle(response, ctx)` sees every response before
62
+ * the transport decodes it; returning anything but undefined resolves the
63
+ * call with that value. `capture(info)` runs synchronously at the call
64
+ * site (before any await) and its return arrives as `ctx.context`, so
65
+ * ambient per-call state (e.g. a reactive owner) survives to response
66
+ * time. See `createServerComponentHandler` in frame-transport for the
67
+ * canonical implementation.
68
+ */
69
+ responseHandler?: {
70
+ capture?(info: {
71
+ id: string;
72
+ meta: unknown;
73
+ }): unknown;
74
+ handle(response: Response, ctx: {
75
+ id: string;
76
+ meta: unknown;
77
+ args: unknown[];
78
+ context: unknown;
79
+ }): unknown;
80
+ };
81
+ /**
82
+ * Encoder for argument lists JSON can't carry faithfully. JSON-safe args
83
+ * always go as plain JSON (no codec in the bundle); anything else throws
84
+ * unless this is set. Installed by `enableRichArguments()` from the
85
+ * rich-args entry — set directly only for custom wire encodings.
86
+ */
87
+ serializeArgs?(args: unknown[]): string | Promise<string>;
120
88
  }
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
- /**
131
- * Declares a server function callable over HTTP GET: calls to the returned
132
- * reference go out as GET requests with the arguments codec-encoded in the
133
- * query string — cacheable by HTTP infrastructure. Cache headers flow
134
- * through the handler's header forwarding
135
- * (`respond(data, { headers: { "cache-control": "max-age=60" } })`).
136
- *
137
- * The declaration rides the metadata channel
138
- * (`getServerFunctionMetadata(fn)?.method === "GET"`) for routers and
139
- * integrations to detect, and the server honors it: GET-declared functions
140
- * accept GET requests in addition to the default POST transport (declaring
141
- * GET grants, it does not revoke); functions that never declared GET answer
142
- * GET requests with 405. Server-side the wrapper is identity-flavored — SSR
143
- * calls stay in-process.
144
- *
145
- * Wrap the reference at its declaration; the compiler round-trips the call
146
- * in both builds:
147
- *
148
- * ```ts
149
- * export const getUser = GET(async (id: string) => {
150
- * "use server";
151
- * return db.users.find(id);
152
- * });
153
- * ```
154
- */
155
- export function GET<A extends readonly any[], R>(
156
- fn: (...args: A) => R
157
- ): ServerFunction<A, Awaited<R>>;
158
-
89
+ export interface ServerFunctionRequestCall {
90
+ type: "request";
91
+ id: string;
92
+ instance: string;
93
+ request: Request;
94
+ meta: ServerFunctionMetadata | undefined;
95
+ time: number;
96
+ }
97
+ export interface ServerFunctionResponseCall {
98
+ type: "response";
99
+ id: string;
100
+ instance: string;
101
+ response: Response;
102
+ meta: ServerFunctionMetadata | undefined;
103
+ time: number;
104
+ }
105
+ export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
159
106
  /** Wire-state transitions a live call's iterable can report. */
160
107
  export type LiveSourceStatus = "connected" | "reconnecting" | "closed";
161
-
162
108
  /**
163
109
  * A live call's answer: the source's iterable, plus an optional `onstatus`
164
110
  * side channel for the wire facts the reconnect loop erases from the value
165
111
  * stream — `"connected"` on each successful (re)connect, `"reconnecting"`
166
- * (with the error) on each post-connect death, `"closed"` when the source
167
- * completes or the consumer ends it.
112
+ * (with the error) on each transient post-connect death, `"closed"` when
113
+ * the source completes or the consumer ends it — with the error when the
114
+ * end was a definite rejection (4xx) failing fast instead of retrying.
168
115
  */
169
116
  export type LiveSource<R> = R & {
170
- onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
117
+ onstatus?: (state: LiveSourceStatus, error?: unknown) => void;
171
118
  };
172
-
173
- /**
174
- * Declares a value-shaped live source: a server function returning an async
175
- * iterable whose yields are successive VALUES of one logical query, with the
176
- * contract that the source re-yields current state on every invocation.
177
- * Calls to the returned reference produce an iterable that survives the
178
- * connection — post-connect deaths re-invoke with exponential backoff
179
- * (reset per healthy value, woken early by connectivity returning),
180
- * first-connect failures reject like a normal call, and `break` aborts the
181
- * in-flight request. Live calls are reads and never opt into single-flight
182
- * enveloping. Wire state, if wanted, rides the returned iterable's
183
- * `onstatus` hook. Compose with `GET` inside-out: `live(GET(fn))`.
184
- */
185
- export function live<A extends readonly any[], R>(
186
- fn: (...args: A) => R
187
- ): ServerFunction<A, LiveSource<Awaited<R>>>;
188
-
189
- /**
190
- * Compiler ABI — emitted by compiled `"use server"` client output where a
191
- * server function was referenced; produces the fetch-backed callable for
192
- * the function's build-stable id. Development builds pass the function's
193
- * source name as the trailing argument (dev-only metadata seeded on the
194
- * metadata channel; never emitted in production). Not meant for
195
- * hand-written code.
196
- *
197
- * The optional `base` targets calls at that url verbatim instead of the
198
- * configured endpoint — for integrations reconstructing a callable from a
199
- * server-rendered action url (e.g. a router intercepting a form submit whose
200
- * `action="/_server?id=...&args=..."` came off the wire): bound arguments
201
- * stay in the query string, where the server reads them for natural-encoding
202
- * bodies (FormData, urlencoded).
203
- * @internal
204
- */
205
- export function createServerReference(id: string, name?: string, base?: string): ServerFunction;
206
-
207
- /**
208
- * Compiler ABI — only ever referenced by server-mode compiler output;
209
- * throws so a misconfigured build (server transform feeding a client
210
- * bundle) fails loudly instead of with a missing-export error. Not meant
211
- * for hand-written code.
212
- * @internal
213
- */
214
- export function registerServerReference(): never;
215
-
216
119
  /**
217
120
  * Identity of the currently executing server function call — see the
218
121
  * server entry. Named here so isomorphic code can import the type from
219
122
  * either entry.
220
123
  */
221
124
  export interface ServerFunctionInvocation {
222
- id: string;
125
+ id: string;
223
126
  }
224
-
225
- /**
226
- * Client no-op mirror of the server entry's accessor: there is never a
227
- * server function call in flight on the client, so this always returns
228
- * undefined. Present so `"use server"` modules that import it stay
229
- * import-stable in client builds before dead-code elimination.
230
- */
231
- export function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
127
+ export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
128
+ export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
129
+ export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
130
+ export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
131
+ export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, LiveSource<Awaited<R>>>;
132
+ export declare function registerServerReference(): never;
133
+ export declare function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
@@ -5,34 +5,14 @@
5
5
  * returned one fills `result` — mirroring the split a scripted call sees.
6
6
  */
7
7
  export interface FlashSubmission {
8
- /** The arguments the call was made with (files are dropped). */
9
- input: any[];
10
- /** The call's url: pathname + search of the server function request. */
11
- url: string;
12
- /** The returned value, when the call returned. */
13
- result?: any;
14
- /** The thrown value, when the call threw. */
15
- error?: any;
8
+ /** The arguments the call was made with (files are dropped). */
9
+ input: any[];
10
+ /** The call's url: pathname + search of the server function request. */
11
+ url: string;
12
+ /** The returned value, when the call returned. */
13
+ result?: any;
14
+ /** The thrown value, when the call threw. */
15
+ error?: any;
16
16
  }
17
-
18
- /**
19
- * Encodes the outcome of a no-JS call as a `Set-Cookie` value, for the
20
- * handler to send with its redirect. `url` identifies which submission the
21
- * outcome belongs to; pass `thrown` when the call threw rather than
22
- * returned.
23
- *
24
- * The payload is JSON inside the cookie: `FormData` and `URLSearchParams`
25
- * arguments are captured as entry pairs and revived on decode, and `File`
26
- * entries are dropped (they cannot ride a cookie). Keep in mind the 4 KB
27
- * cookie budget — outcomes larger than that will not survive the round
28
- * trip.
29
- */
30
- export function encodeFlashCookie(url: string, result: any, input: any[], thrown?: boolean): string;
31
-
32
- /**
33
- * Decodes the flash cookie out of a request's `Cookie` header, for the
34
- * render that follows the redirect. Returns undefined when the cookie is
35
- * absent or unreadable — a malformed cookie never takes down the render,
36
- * and `clearFlashCookie` should be appended regardless.
37
- */
38
- export function decodeFlashCookie(cookieHeader: string | null): FlashSubmission | undefined;
17
+ export declare function encodeFlashCookie(url: string, result: any, input: any[], thrown?: boolean): string;
18
+ export declare function decodeFlashCookie(cookieHeader: string | null): FlashSubmission | undefined;