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

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 (65) hide show
  1. package/dist/dev.cjs +398 -17
  2. package/dist/dev.js +396 -19
  3. package/dist/server.cjs +166 -38
  4. package/dist/server.js +165 -39
  5. package/dist/web.cjs +369 -17
  6. package/dist/web.js +367 -19
  7. package/frames/dist/client.cjs +41 -8
  8. package/frames/dist/client.dev.cjs +41 -8
  9. package/frames/dist/client.dev.js +41 -8
  10. package/frames/dist/client.js +41 -8
  11. package/frames/dist/server.cjs +432 -44
  12. package/frames/dist/server.js +432 -44
  13. package/package.json +2 -2
  14. package/serialization/dist/decode.cjs +4 -2
  15. package/serialization/dist/decode.js +4 -2
  16. package/serialization/dist/serialization.cjs +12 -8
  17. package/serialization/dist/serialization.js +12 -8
  18. package/serialization/types/index.d.ts +7 -0
  19. package/serialization/types/serializer-decode.d.ts +14 -1
  20. package/serialization/types/serializer.d.ts +7 -0
  21. package/serialization/types-cjs/index.d.cts +7 -0
  22. package/serialization/types-cjs/serializer-decode.d.cts +14 -1
  23. package/serialization/types-cjs/serializer.d.cts +7 -0
  24. package/server-functions/dist/client.cjs +271 -47
  25. package/server-functions/dist/client.js +264 -47
  26. package/server-functions/dist/server.cjs +872 -131
  27. package/server-functions/dist/server.dev.cjs +892 -131
  28. package/server-functions/dist/server.dev.js +884 -131
  29. package/server-functions/dist/server.js +864 -131
  30. package/types/client.d.ts +4 -2
  31. package/types/cookies.d.ts +6 -14
  32. package/types/frames/frame-client.d.ts +4 -0
  33. package/types/frames/serializer-decode.d.ts +14 -1
  34. package/types/frames/serializer.d.ts +7 -0
  35. package/types/index.d.ts +1 -0
  36. package/types/jsx.d.ts +11 -16
  37. package/types/patch-driver.d.ts +3 -0
  38. package/types/response.d.ts +20 -1
  39. package/types/serializer-decode.d.ts +14 -1
  40. package/types/serializer.d.ts +7 -0
  41. package/types/server-functions/client.d.ts +58 -7
  42. package/types/server-functions/flash.d.ts +9 -0
  43. package/types/server-functions/registry.d.ts +38 -1
  44. package/types/server-functions/server.d.ts +66 -14
  45. package/types/server-functions/shared.d.ts +122 -16
  46. package/types/server-mock.d.ts +17 -2
  47. package/types/server.d.ts +16 -2
  48. package/types-cjs/client.d.cts +4 -2
  49. package/types-cjs/cookies.d.cts +6 -14
  50. package/types-cjs/frames/frame-client.d.cts +4 -0
  51. package/types-cjs/frames/serializer-decode.d.cts +14 -1
  52. package/types-cjs/frames/serializer.d.cts +7 -0
  53. package/types-cjs/index.d.cts +1 -0
  54. package/types-cjs/jsx.d.cts +11 -16
  55. package/types-cjs/patch-driver.d.cts +3 -0
  56. package/types-cjs/response.d.cts +20 -1
  57. package/types-cjs/serializer-decode.d.cts +14 -1
  58. package/types-cjs/serializer.d.cts +7 -0
  59. package/types-cjs/server-functions/client.d.cts +58 -7
  60. package/types-cjs/server-functions/flash.d.cts +9 -0
  61. package/types-cjs/server-functions/registry.d.cts +38 -1
  62. package/types-cjs/server-functions/server.d.cts +66 -14
  63. package/types-cjs/server-functions/shared.d.cts +122 -16
  64. package/types-cjs/server-mock.d.cts +17 -2
  65. package/types-cjs/server.d.cts +16 -2
@@ -1,7 +1,8 @@
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";
1
+ import type { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
2
+ export { ChunkReader, ERROR_HEADER, FLASH_COOKIE, INSTANCE_HEADER, REDIRECT_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, clearFlashCookie, createChunk, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, deserializeStream, encodeErrorHeaderValue, frameAddress, getFlightDataConsumer, getFlightDataSourceIds, getServerFunctionMetadata, getServerFunctionsCodec, hasFlashCookie, invoke, isServerFunction, serializeString, subscribeFlightData, withMeta } from "./shared.cjs";
2
3
  export { REVALIDATE_HEADER } from "../response.cjs";
3
4
  import { JSONCodecOptions } from "../serializer-decode.cjs";
4
- export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
5
+ export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
5
6
  /** The context `prepareRequest` receives alongside the outgoing RequestInit. */
6
7
  export interface PrepareRequestContext {
7
8
  /** The build-stable id of the function being called. */
@@ -25,10 +26,11 @@ export type PrepareRequestHook = (init: RequestInit, context: PrepareRequestCont
25
26
  /** Options for `configureServerFunctionsClient`. */
26
27
  export interface ServerFunctionsClientConfig {
27
28
  /**
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` ``).
29
+ * Mount path the server's HTTP handler answers on. Must match the server
30
+ * configuration — the id travels as the segment after it, and SSR'd
31
+ * reference `url`s (e.g. form actions) and client fetches both derive
32
+ * from it. Prefix it when the app serves from a base path
33
+ * (e.g. `` `${BASE_URL}_server` ``).
32
34
  * @default "/_server"
33
35
  */
34
36
  endpoint?: string;
@@ -38,6 +40,34 @@ export interface ServerFunctionsClientConfig {
38
40
  * `decodeResponse` sees them too.
39
41
  */
40
42
  codec?: JSONCodecOptions;
43
+ /**
44
+ * Sends every server-function request — retries, telemetry, a test
45
+ * double, or an app's own route. Always called as `(address, init)`, the
46
+ * address relative to the document as the global one receives it, so
47
+ * `parseServerFunctionUrl` reads the id back out for telemetry. `null`
48
+ * restores the global.
49
+ *
50
+ * ```ts
51
+ * configureServerFunctionsClient({
52
+ * fetch: (address, init) => fetch(rewrite(address), init)
53
+ * });
54
+ * ```
55
+ *
56
+ * Forward `init` — the call's `signal` rides on it, and dropping it voids
57
+ * both the caller's abort and the teardown a live source's `break`
58
+ * performs. Keep the call same-origin, since a cross-origin send is
59
+ * stamped `Sec-Fetch-Site: cross-site` and the handler's origin gate
60
+ * refuses it, and hand back what the peer answered, unread.
61
+ *
62
+ * A retrying wrapper may re-send a request that got NO response; it must
63
+ * never replay one whose response ended. A response that dies mid-body may
64
+ * have executed (mutations are not idempotent), and reconnecting a live
65
+ * source is the runtime's job — a replay would race it.
66
+ *
67
+ * The wrapper replaces delivery for the requests the runtime chooses to
68
+ * send; the call-to-request mapping itself is not contractual.
69
+ */
70
+ fetch?: ((address: string, init: RequestInit) => Response | Promise<Response>) | null;
41
71
  /**
42
72
  * Runs before every server-function fetch. Return (or mutate and return)
43
73
  * the RequestInit the transport will use; `context.meta` is the
@@ -125,9 +155,30 @@ export interface ServerFunctionInvocation {
125
155
  id: string;
126
156
  }
127
157
  export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
158
+ export declare function serverFunctionUrl(id: string, boundArgs?: readonly unknown[]): string;
159
+ export declare function parseServerFunctionUrl(url: string): string | null;
128
160
  export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
129
161
  export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
130
162
  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>>>;
163
+ export interface LiveServerFunction<A extends readonly any[] = any[], R = any> {
164
+ (...args: A): LiveSource<R>;
165
+ /** The build-stable function id (stable across the client and server builds). */
166
+ readonly id: string;
167
+ /** URL invoking this function directly over HTTP. */
168
+ readonly url: string;
169
+ }
170
+ /**
171
+ * Declares a value-shaped live source: a server function returning an async
172
+ * iterable whose yields are successive VALUES of one logical query, with the
173
+ * contract that the source re-yields current state on every invocation.
174
+ * Calls to the returned reference produce an iterable that survives the
175
+ * connection — post-connect deaths re-invoke with exponential backoff
176
+ * (reset per healthy value, woken early by connectivity returning),
177
+ * first-connect failures reject like a normal call, and `break` aborts the
178
+ * in-flight request. Live calls are reads and never opt into single-flight
179
+ * enveloping. Wire state, if wanted, rides the returned iterable's
180
+ * `onstatus` hook. Compose with `GET` inside-out: `live(GET(fn))`.
181
+ */
182
+ export declare function live<A extends readonly any[], R>(fn: (...args: A) => R): LiveServerFunction<A, Awaited<R>>;
132
183
  export declare function registerServerReference(): never;
133
184
  export declare function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
@@ -13,6 +13,15 @@ export interface FlashSubmission {
13
13
  result?: any;
14
14
  /** The thrown value, when the call threw. */
15
15
  error?: any;
16
+ /**
17
+ * Set when the outcome was too large for the cookie's 4 KB ceiling and
18
+ * was degraded to fit (#3137): the input echo is dropped, and `result` /
19
+ * `error` may carry a bounded prefix — or the bare outcome flag `true` —
20
+ * rather than the full value. The submission still says what happened
21
+ * and where; integrations should render it as "succeeded (result too
22
+ * large to display)" rather than replaying the value.
23
+ */
24
+ truncated?: boolean;
16
25
  }
17
26
  export declare function encodeFlashCookie(url: string, result: any, input: any[], thrown?: boolean): string;
18
27
  export declare function decodeFlashCookie(cookieHeader: string | null): FlashSubmission | undefined;
@@ -1,4 +1,5 @@
1
- export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "./shared.cjs";
1
+ export type { InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, ServerFunctionRPC } from "./shared.cjs";
2
+ import type { InvokeOptions } from "./shared.cjs";
2
3
  export declare const SERVER_FUNCTION_METADATA: unique symbol;
3
4
  /**
4
5
  * Reads a server function reference's declaration metadata (e.g.
@@ -45,6 +46,42 @@ export declare function isServerFunction(fn: any): boolean;
45
46
  * ```
46
47
  */
47
48
  export declare function withMeta(fn: any, meta: any): any;
49
+ export declare const SERVER_FUNCTION_INVOKE: unique symbol;
50
+ /**
51
+ * Applies a server function once with per-call, invocation-scoped options —
52
+ * `Function.prototype.call` for server functions, the options bag in the
53
+ * `thisArg` slot (declaration wrappers like `GET` and `withMeta` are `bind`:
54
+ * they return a new reference with context baked in; `invoke` applies one
55
+ * call and leaves no residue on the reference).
56
+ *
57
+ * ```ts
58
+ * import { invoke } from "@solidjs/web/server-functions";
59
+ *
60
+ * const user = await invoke(getUser, { signal: controller.signal }, id);
61
+ * ```
62
+ *
63
+ * Options are strictly invocation-scoped — things that vary between calls
64
+ * of the SAME function and cannot be declared or configured: `signal`
65
+ * (the call's lifecycle; aborting rejects the call and cancels the
66
+ * request), `keepalive` (calls made while the page unloads), `priority`
67
+ * (fetch priority hint). Anything with a longer lifetime is refused with a
68
+ * pointer to its home: session-dynamic transport policy → `prepareRequest`;
69
+ * declaration-static shape → `GET`/`withMeta`; call policy (retries,
70
+ * dedupe, deadlines) → the data layer that owns the call, wired through
71
+ * `signal`.
72
+ *
73
+ * Dispatches through the reference's invocation channel
74
+ * (`SERVER_FUNCTION_INVOKE`). Core's declaration wrappers forward it —
75
+ * `GET` invokes over its query encoding, `live` ends its iteration on
76
+ * abort. Wrappers that share calls (caches, channels) may adapt or decline
77
+ * it; a data layer needs neither — it holds the reference below such
78
+ * wrappers and invokes it directly with its own signal. On the server the
79
+ * call runs in-process: `signal`
80
+ * rejects the caller (the work, like a server behind HTTP, runs on unless
81
+ * the function observes a signal itself) and the transport hints are
82
+ * no-ops, since they describe a wire that does not exist.
83
+ */
84
+ export declare function invoke<A extends readonly any[], R>(fn: (...args: A) => R, options: InvokeOptions, ...args: A): R;
48
85
  export declare const LIVE_SOURCE: unique symbol;
49
86
  /**
50
87
  * Fills the RPC seam. Called by the transport halves (client fetch RPC,
@@ -1,9 +1,10 @@
1
- export { ERROR_HEADER, FLASH_COOKIE, FUNCTION_HEADER, INSTANCE_HEADER, SINGLE_FLIGHT_HEADER, clearFlashCookie, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, isServerFunction, subscribeFlightData, withMeta } from "./shared.cjs";
1
+ export { ERROR_HEADER, FLASH_COOKIE, INSTANCE_HEADER, REDIRECT_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, UNKNOWN_HEADER, clearFlashCookie, decodeErrorHeaderValue, decodeRedirectHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, invoke, isServerFunction, subscribeFlightData, withMeta } from "./shared.cjs";
2
2
  export { decodeFlashCookie, encodeFlashCookie } from "./flash.cjs";
3
3
  import { ResponseEnvelope } from "../response.cjs";
4
4
  import { JSONCodecOptions } from "../serializer-decode.cjs";
5
5
  import { RequestEvent } from "../server.cjs";
6
- export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
6
+ import type { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
7
+ export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
7
8
  export type { FlashSubmission } from "./flash.cjs";
8
9
  /**
9
10
  * The request event a server function call runs under: the base
@@ -130,6 +131,18 @@ export interface ServerFunctionCSRFOptions {
130
131
  * @default false
131
132
  */
132
133
  allowRequestsWithoutOriginCheck?: boolean;
134
+ /**
135
+ * Applies the origin gate to GET-declared reads as well. By default the
136
+ * gate is skipped for declared reads: same-origin policy already keeps a
137
+ * cross-site caller from READING the response, and the gate's `Vary`
138
+ * fragments (or, on CDNs that ignore Vary, poisons) the shared-cache
139
+ * entries the `GET` helper exists to enable (#3071). The premise that
140
+ * skip rests on is `GET()`'s safety contract — declared reads are safe
141
+ * to EXECUTE from any origin (#3114). A deployment that does not rely
142
+ * on shared caches can enable this to gate its reads too.
143
+ * @default false
144
+ */
145
+ protectDeclaredReads?: boolean;
133
146
  }
134
147
  /** Options for `configureServerFunctionsServer`. */
135
148
  export interface ServerFunctionsServerConfig {
@@ -150,10 +163,13 @@ export interface ServerFunctionsServerConfig {
150
163
  */
151
164
  wrapInvocation?: WrapInvocationHook;
152
165
  /**
153
- * The single-flight hook: produces the data payload folded into
166
+ * The unnamed single-flight hook: produces the data payload folded into
154
167
  * responses of calls that opted in (see `CollectFlightDataHook`).
155
168
  * Registered once by the integration that owns data production (a
156
- * router); per-handler `collectFlightData` options override it.
169
+ * router); per-handler `collectFlightData` options override it. Other
170
+ * integrations contribute additively through
171
+ * `registerFlightDataSource(id, hook)` instead of competing for this
172
+ * slot.
157
173
  */
158
174
  collectFlightData?: CollectFlightDataHook;
159
175
  /**
@@ -208,10 +224,11 @@ export interface ServerFunctionsServerConfig {
208
224
  */
209
225
  handleNoJS?: ((result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response | Promise<Response>) | null;
210
226
  /**
211
- * Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
212
- * references (e.g. form actions) must match the client configuration.
213
- * Prefix it when the app serves from a base path (e.g.
214
- * `` `${BASE_URL}_server` ``).
227
+ * Mount path the HTTP handler answers on. Must match the client
228
+ * configuration the id travels as the segment after it, a request whose
229
+ * path does not start with it is not a call, and SSR'd reference `url`s
230
+ * (e.g. form actions) derive from it. Prefix it when the app serves from
231
+ * a base path (e.g. `` `${BASE_URL}_server` ``).
215
232
  * @default "/_server"
216
233
  */
217
234
  endpoint?: string;
@@ -227,6 +244,24 @@ export interface ServerFunctionsServerConfig {
227
244
  * `decodeResponse` sees them too.
228
245
  */
229
246
  codec?: JSONCodecOptions;
247
+ /**
248
+ * Upper bound, in bytes, on a call's argument payload — the POST body,
249
+ * or the `?args=` query encoding. The payload is buffered and decoded
250
+ * before dispatch, so its cost is paid before application code can
251
+ * decline it; the bound is enforced up front and a request over it is
252
+ * refused with `413` before any decoding (#3115). Raise it for functions
253
+ * that accept large uploads, or set `Infinity` to remove the bound.
254
+ * @default 1_048_576 (1 MiB)
255
+ */
256
+ bodySizeLimit?: number;
257
+ /**
258
+ * Upper bound on the number of arguments a call may carry. The decoded
259
+ * argument array is spread into the function call, so an unbounded list
260
+ * forces a range error out of any function regardless of what it does;
261
+ * past the bound the request is refused with `400` (#3115).
262
+ * @default 1000
263
+ */
264
+ maxArguments?: number;
230
265
  }
231
266
  /**
232
267
  * A registered server function: its build-stable id paired with the
@@ -346,6 +381,16 @@ export interface HandleServerFunctionOptions {
346
381
  csrf?: boolean | ServerFunctionCSRFOptions;
347
382
  /** Overrides the configured codec options for this handler. */
348
383
  codec?: JSONCodecOptions;
384
+ /**
385
+ * Overrides the configured argument payload bound for this handler (see
386
+ * `ServerFunctionsServerConfig.bodySizeLimit`).
387
+ */
388
+ bodySizeLimit?: number;
389
+ /**
390
+ * Overrides the configured argument count bound for this handler (see
391
+ * `ServerFunctionsServerConfig.maxArguments`).
392
+ */
393
+ maxArguments?: number;
349
394
  }
350
395
  export interface ServerFunctionRequestCall {
351
396
  type: "request";
@@ -365,6 +410,7 @@ export interface ServerFunctionResponseCall {
365
410
  }
366
411
  export type ServerFunctionCall = ServerFunctionRequestCall | ServerFunctionResponseCall;
367
412
  export declare function configureServerFunctionsServer(config?: ServerFunctionsServerConfig): void;
413
+ export declare function registerFlightDataSource(source: string, hook: CollectFlightDataHook): () => void;
368
414
  export declare function registerServerFunction<T extends any[], R>(id: string, callback: (...args: T) => R): (...args: T) => R;
369
415
  export declare function getServerFunction<T extends any[], R>(id: string): (...args: T) => R;
370
416
  export declare function registerServerReference<T extends any[], R>(id: string, fn: (...args: T) => R, name?: string): ServerFunctionReference<T, R>;
@@ -375,6 +421,8 @@ export declare function getServerFunctionInvocation(): ServerFunctionInvocation
375
421
  export declare function getEventServerFunctionInvocation(event: RequestEvent | undefined): ServerFunctionInvocation | undefined;
376
422
  export declare function foldSetCookies(headers: Headers, setCookies: readonly string[]): Headers;
377
423
  export declare function createNoJSHandler(options?: NoJSHandlerOptions): (result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response;
424
+ /** @internal */
425
+ export declare function guardFailures(value: any, state: any): any;
378
426
  /**
379
427
  * The response-side codec stream: `serializeStream` (shared.js) hardened
380
428
  * with request-lifetime teardown. Server-only on purpose — the shared half
@@ -383,12 +431,14 @@ export declare function createNoJSHandler(options?: NoJSHandlerOptions): (result
383
431
  * An abort of `signal` (the platform fires request.signal when the caller's
384
432
  * fetch aborts or the tab goes away) or the consumer cancelling the
385
433
  * ReadableStream (how platforms surface a dropped connection to the body)
386
- * stops pending serialization and tears down a top-level async-iterable
387
- * value the producer's `iterator.return()` runs, so generator `finally`
388
- * blocks execute instead of the server pumping a stream nobody is reading.
389
- * Top-level only: that is the value-tier shape ("return a stream from the
390
- * server function"); iterables nested inside user objects are consumed by
391
- * the codec directly and stay untouched.
434
+ * stops pending serialization and tears down EVERY async-iterable or
435
+ * ReadableStream source in the result graph, nested ones included (#3125) —
436
+ * each producer's `iterator.return()` / `reader.cancel()` runs, so
437
+ * generator `finally` blocks execute instead of the server pumping streams
438
+ * nobody is reading. The wiring rides guardFailures' walk: it already wraps
439
+ * every channel before the codec sees the value, so the demand gate and the
440
+ * teardown registry are threaded through its state (`{ items: rows() }` —
441
+ * a cursor beside a total — gets the same two guarantees as `return rows()`).
392
442
  */
393
443
  export declare function serializeResponseStream(value: any, codecOptions: any, signal: any): ReadableStream<any>;
394
444
  /** Message a sanitized (production) server error carries on the wire. */
@@ -396,4 +446,6 @@ export declare const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
396
446
  export declare function setServerFunctionsDev(dev: boolean): void;
397
447
  export declare function sanitizeServerError(value: unknown): unknown;
398
448
  export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
449
+ export declare function serverFunctionUrl(id: string, boundArgs?: readonly unknown[]): string;
450
+ export declare function parseServerFunctionUrl(url: string): string | null;
399
451
  export declare function handleServerFunctionRequest(request: Request, options?: HandleServerFunctionOptions): Promise<Response>;
@@ -1,4 +1,4 @@
1
- export { LIVE_SOURCE, SERVER_FUNCTION_METADATA, getServerFunctionMetadata, getServerFunctionRPC, isServerFunction, provideServerFunctionRPC, withMeta } from "./registry.cjs";
1
+ export { LIVE_SOURCE, SERVER_FUNCTION_INVOKE, SERVER_FUNCTION_METADATA, getServerFunctionMetadata, getServerFunctionRPC, invoke, isServerFunction, provideServerFunctionRPC, withMeta } from "./registry.cjs";
2
2
  export { FLASH_COOKIE, clearFlashCookie, hasFlashCookie, matchFlashCookie } from "../cookies.cjs";
3
3
  import { JSONCodecOptions } from "../serializer-decode.cjs";
4
4
  /**
@@ -8,19 +8,22 @@ import { JSONCodecOptions } from "../serializer-decode.cjs";
8
8
  * HTTP handler. Integrations decoding passthrough responses themselves (no
9
9
  * registered consumer) see this shape from `decodeResponse`. The top level
10
10
  * is reserved for the protocol — integration payload lives entirely under
11
- * `data`, which can be any codec-serializable value.
11
+ * `data`, the envelope keyed by source id (the unnamed registration's
12
+ * slice rides under the reserved id "true"); each slice can be any
13
+ * codec-serializable value.
12
14
  */
13
15
  export interface SingleFlightPayload<T = unknown, D = unknown> {
14
16
  /** The server function's return (or thrown) value. */
15
17
  value: T;
16
- /** The integration-produced data payload. */
18
+ /** The integration-produced data payload, keyed by source id. */
17
19
  data: D;
18
20
  }
19
21
  /**
20
22
  * Envelope context delivered alongside single-flight data: the transport
21
- * response, whose headers carry the integration metadata (`Location` for
22
- * redirect-with-data, `X-Revalidate` keys) and status. The body is already
23
- * consumed — read `data` and `value` from the delivery, not from here.
23
+ * response, whose headers carry the integration metadata (the redirect
24
+ * carrier for redirect-with-data, `X-Revalidate` keys) and status. The
25
+ * body is already consumed — read `data` and `value` from the delivery,
26
+ * not from here.
24
27
  */
25
28
  export interface FlightDataContext {
26
29
  /** The HTTP response the data arrived on (metadata only). */
@@ -45,6 +48,42 @@ export interface ServerFunction<A extends readonly any[] = any[], T = any> {
45
48
  /** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
46
49
  readonly url: string;
47
50
  }
51
+ /**
52
+ * Per-call, invocation-scoped options for `invoke` — things that vary
53
+ * between calls of the SAME function and cannot be declared (`GET`,
54
+ * `withMeta`) or configured (`prepareRequest`). On the server the call is
55
+ * in-process: `signal` still rejects the caller, the transport hints are
56
+ * no-ops (they describe a wire that does not exist).
57
+ */
58
+ export interface InvokeOptions {
59
+ /**
60
+ * The call's lifecycle. Aborting rejects the call with the signal's
61
+ * reason and cancels the request (firing `request.signal` server-side);
62
+ * a live source's iteration ends across reconnects. When provided, the
63
+ * signal owns the wire — timeouts compose through it
64
+ * (`AbortSignal.timeout`, `AbortSignal.any`).
65
+ */
66
+ signal?: AbortSignal;
67
+ /**
68
+ * Lets the request outlive the page — fire-and-forget calls during
69
+ * unload (`pagehide`). Maps to fetch's `keepalive`, body-size caps
70
+ * included.
71
+ */
72
+ keepalive?: boolean;
73
+ /** Fetch priority hint — speculative prefetch vs. interaction fetch. */
74
+ priority?: "high" | "low" | "auto";
75
+ }
76
+ /**
77
+ * A reference's invocation channel, carried under `SERVER_FUNCTION_INVOKE`:
78
+ * applies one call with per-call options. Declaration wrappers (`GET`,
79
+ * `live`) forward it mechanically — they keep the call mapping 1:1. A
80
+ * wrapper that shares calls (a deduping cache, a multicast channel) opts
81
+ * in deliberately, deciding first what a caller's abort means for shared
82
+ * work — or declines, leaving `invoke` to answer with a directed error.
83
+ * Options arrive already validated — `invoke` admits only
84
+ * invocation-scoped keys.
85
+ */
86
+ export type ServerFunctionInvoker<A extends readonly any[] = any[], R = any> = (args: A, options?: InvokeOptions) => R;
48
87
  /**
49
88
  * Declaration-static metadata attached to a server function reference
50
89
  * through declaration wrappers (`GET`, `withMeta`). Read it with
@@ -95,11 +134,27 @@ export interface ServerFunctionRPC {
95
134
  export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
96
135
  export declare function configureServerFunctionsCodec(codec: JSONCodecOptions | undefined): void;
97
136
  export declare function getServerFunctionsCodec(): JSONCodecOptions | undefined;
137
+ /**
138
+ * Validates a flight data source id (both registration halves share the
139
+ * rule): ids travel the `SINGLE_FLIGHT_HEADER` as a comma-separated list,
140
+ * so they cannot be empty or contain commas, and "true" is reserved for
141
+ * the unnamed registration.
142
+ *
143
+ * Transport building block; not meant for hand-written code.
144
+ * @internal
145
+ */
146
+ export declare function assertFlightSource(source: string): void;
98
147
  export declare function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
99
- export declare function getFlightDataConsumer(): FlightDataConsumer | undefined;
148
+ export declare function subscribeFlightData<D = unknown>(source: string, consumer: FlightDataConsumer<D>): () => void;
149
+ export declare function getFlightDataConsumer(source?: string): FlightDataConsumer | undefined;
150
+ export declare function getFlightDataSourceIds(): string[];
100
151
  export declare function frameAddress(id: string, args?: readonly unknown[]): string;
101
- /** Header carrying the server function id. */
102
- export declare const FUNCTION_HEADER = "X-Server-Function-Id";
152
+ export declare function serverFunctionAddress(endpoint: string, id: string): string;
153
+ export declare function serverFunctionDataAddress(endpoint: string, id: string): string;
154
+ export declare function parseServerFunctionAddress(pathname: string, endpoint: string): {
155
+ id: string;
156
+ data: boolean;
157
+ } | null;
103
158
  /**
104
159
  * Response header marking a thrown server-function error. The value is the
105
160
  * error's message (the structured error itself travels in the body); `"true"`
@@ -115,6 +170,51 @@ export declare function decodeErrorHeaderValue(value: string): string;
115
170
  export declare const INSTANCE_HEADER = "X-Server-Function-Instance";
116
171
  /** Header carrying the body format tag (a `BodyFormat` value). */
117
172
  export declare const BODY_FORMAT_HEADER = "X-Server-Function-Format";
173
+ /**
174
+ * Header labelling the unknown-id 404: the address was well-formed but its
175
+ * id is not registered in the deployment that answered (#3110). This is the
176
+ * ordinary shape of version skew — a tab holding the previous build's ids
177
+ * across a deploy — and the label is what lets an integration recover
178
+ * (e.g. reload the document) instead of surfacing a generic failed call.
179
+ * Nothing distinguishes it otherwise: a CDN 404 and a skew 404 look alike.
180
+ */
181
+ export declare const UNKNOWN_HEADER = "X-Server-Function-Unknown";
182
+ /**
183
+ * Header carrying a redirect to scripted callers. fetch FOLLOWS redirect
184
+ * statuses before the transport can read them, so a scripted answer masks
185
+ * the 3xx to 200 and this header carries what the mask erases: the author's
186
+ * status and the target RESOLVED against the request url — exactly the
187
+ * meaning HTTP assigns the `Location` a form post would have received.
188
+ * Value: `<status> <absolute-url>`, decode with `decodeRedirectHeaderValue`.
189
+ *
190
+ * Carrying the resolved absolute form is the point (#3102, #3107): the
191
+ * reader never guesses navigation strategy from how the author spelled the
192
+ * target — `redirect("/")` and `redirect(new URL("/", url).href)` arrive
193
+ * identical by construction, and same-origin vs cross-origin is a real URL
194
+ * comparison, not a `startsWith("http")` coin toss. `Location` itself never
195
+ * rides a masked answer: on a 200 it has no HTTP meaning, and it collided
196
+ * with authored Locations on statuses that forward (a 201's created-at is
197
+ * data, not navigation).
198
+ */
199
+ export declare const REDIRECT_HEADER = "X-Server-Function-Redirect";
200
+ /**
201
+ * Decodes a `REDIRECT_HEADER` value into the author's status and the
202
+ * resolved absolute target. Integration plumbing for readers of the header
203
+ * (routers); the wire format is the runtime's own, not a contract to parse
204
+ * by hand.
205
+ *
206
+ * The documented output — a resolved ABSOLUTE http(s) target and a redirect
207
+ * status — is enforced, not assumed (#3175): the absoluteness used to be a
208
+ * property of the server having resolved it, and a hostile or buggy peer
209
+ * could ride a `javascript:` target straight into the `location.href =
210
+ * decoded.url` an integration reasonably writes. A value that does not
211
+ * parse as an absolute http(s) url, or whose status is not one the runtime
212
+ * masks, decodes to `undefined` — the same answer a missing header gives.
213
+ */
214
+ export declare function decodeRedirectHeaderValue(value: string | null | undefined): {
215
+ status: number;
216
+ url: string;
217
+ } | undefined;
118
218
  /**
119
219
  * Header driving the single-flight protocol on both legs: on the request it
120
220
  * opts the call into flight-data collection (the integration sends it on
@@ -141,6 +241,13 @@ export declare const BodyFormat: {
141
241
  * included) on the response.
142
242
  */
143
243
  Json: string;
244
+ /**
245
+ * No body at all — a function that returned nothing. It marks the response
246
+ * as one the runtime encoded, which separates a void result with a status
247
+ * on it from a refusal answered by something else. Decoding falls through
248
+ * to `undefined`, which is what a peer predating the tag reads too.
249
+ */
250
+ Void: string;
144
251
  };
145
252
  export declare function isJSONSafe(value: unknown): boolean;
146
253
  export declare function getHeadersAndBody(body: unknown): {
@@ -157,15 +264,14 @@ export declare class ChunkReader {
157
264
  value: string;
158
265
  }>;
159
266
  drain(interpret: any): Promise<void>;
160
- } /**
161
- * Serializes a value as a stream of length-prefixed SerovalNode chunks.
162
- * Async values (promises, streams) keep the stream open until they settle,
163
- * so one connection carries incremental results. Codec options must match
164
- * the deserializing peer.
165
- *
166
- * Transport building block; not meant for hand-written code.
267
+ }
268
+ /**
269
+ * Encodes a terminal error-trailer frame payload. The value is expected to
270
+ * be already sanitized by the caller; only `name` and `message` travel.
271
+ * Transport wire detail; not meant for hand-written code.
167
272
  * @internal
168
273
  */
274
+ export declare function encodeErrorTrailer(error: unknown): string;
169
275
  export declare function serializeStream(value: unknown, codecOptions?: JSONCodecOptions): ReadableStream<Uint8Array>;
170
276
  export declare function serializeString(value: unknown, codecOptions?: JSONCodecOptions): Promise<string>;
171
277
  export declare function deserializeStream<T = unknown>(source: Request | Response, codecOptions?: JSONCodecOptions): Promise<T>;
@@ -1,10 +1,23 @@
1
1
  import type { RequestEvent, RequestEventLocals, ResponseStub } from "./client.cjs";
2
+ import type { JSX } from "./jsx.cjs";
3
+ /** An explicit `<link rel="preload">` emitted by the SSR asset pipeline. */
4
+ export type PreloadLink = {
5
+ href: string;
6
+ as: JSX.HTMLPreloadAs;
7
+ type?: string;
8
+ crossorigin?: JSX.HTMLCrossorigin;
9
+ integrity?: string;
10
+ referrerpolicy?: JSX.HTMLReferrerPolicy;
11
+ fetchpriority?: JSX.HTMLFetchPriority;
12
+ media?: string;
13
+ };
2
14
  /** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
3
15
  export type AssetManifest = Record<string, {
4
16
  file: string;
5
17
  css?: string[];
6
18
  isEntry?: boolean;
7
19
  imports?: string[];
20
+ preloads?: PreloadLink[];
8
21
  }> & {
9
22
  _base?: string;
10
23
  };
@@ -17,6 +30,7 @@ export type InlineStyleAsset = {
17
30
  export type ResolvedAssets = {
18
31
  js: string[];
19
32
  css: (string | InlineStyleAsset)[];
33
+ preloads?: PreloadLink[];
20
34
  };
21
35
  /**
22
36
  * Resolver form of the manifest option — the primitive a dev server
@@ -24,8 +38,9 @@ export type ResolvedAssets = {
24
38
  * normalized into a sync resolver internally). `resolve` may return a
25
39
  * promise (async resolvers require streaming rendering); CSS entries may be
26
40
  * URL strings (emitted as load-gated `<link>` tags) or inline-style
27
- * descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
28
- * is accepted as shorthand for `{ resolve }`.
41
+ * descriptors (emitted as `<style>` tags), and `preloads` carries explicit
42
+ * preload links selected by the integration. A bare `resolve`-shaped
43
+ * function is accepted as shorthand for `{ resolve }`.
29
44
  */
30
45
  export type AssetResolver = {
31
46
  resolve(key: string): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
@@ -5,12 +5,24 @@ export { clearFlashCookie, hasFlashCookie } from "./cookies.cjs";
5
5
  export { getServerFunctionMetadata, getServerFunctionRPC, isServerFunction } from "./server-functions/registry.cjs";
6
6
  import { JSX } from "./jsx.cjs";
7
7
  import { SerializerPlugin } from "./serializer-decode.cjs";
8
+ /** An explicit `<link rel="preload">` emitted by the SSR asset pipeline. */
9
+ export type PreloadLink = {
10
+ href: string;
11
+ as: JSX.HTMLPreloadAs;
12
+ type?: string;
13
+ crossorigin?: JSX.HTMLCrossorigin;
14
+ integrity?: string;
15
+ referrerpolicy?: JSX.HTMLReferrerPolicy;
16
+ fetchpriority?: JSX.HTMLFetchPriority;
17
+ media?: string;
18
+ };
8
19
  /** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
9
20
  export type AssetManifest = Record<string, {
10
21
  file: string;
11
22
  css?: string[];
12
23
  isEntry?: boolean;
13
24
  imports?: string[];
25
+ preloads?: PreloadLink[];
14
26
  }> & {
15
27
  _base?: string;
16
28
  };
@@ -23,6 +35,7 @@ export type InlineStyleAsset = {
23
35
  export type ResolvedAssets = {
24
36
  js: string[];
25
37
  css: (string | InlineStyleAsset)[];
38
+ preloads?: PreloadLink[];
26
39
  };
27
40
  /**
28
41
  * Resolver form of the manifest option — the primitive a dev server
@@ -30,8 +43,9 @@ export type ResolvedAssets = {
30
43
  * normalized into a sync resolver internally). `resolve` may return a
31
44
  * promise (async resolvers require streaming rendering); CSS entries may be
32
45
  * URL strings (emitted as load-gated `<link>` tags) or inline-style
33
- * descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
34
- * is accepted as shorthand for `{ resolve }`.
46
+ * descriptors (emitted as `<style>` tags), and `preloads` carries explicit
47
+ * preload links selected by the integration. A bare `resolve`-shaped
48
+ * function is accepted as shorthand for `{ resolve }`.
35
49
  */
36
50
  export type AssetResolver = {
37
51
  resolve(key: string): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;