@solidjs/web 2.0.0-rc.3 → 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.
- package/dist/dev.cjs +347 -11
- package/dist/dev.js +347 -13
- package/dist/server.cjs +5 -4
- package/dist/server.js +5 -4
- package/dist/web.cjs +338 -11
- package/dist/web.js +338 -13
- package/package.json +2 -2
- package/server-functions/dist/client.cjs +126 -19
- package/server-functions/dist/client.js +123 -19
- package/server-functions/dist/server.cjs +156 -28
- package/server-functions/dist/server.dev.cjs +156 -28
- package/server-functions/dist/server.dev.js +153 -28
- package/server-functions/dist/server.js +153 -28
- package/types/client.d.ts +4 -2
- package/types/index.d.ts +1 -0
- package/types/patch-driver.d.ts +3 -0
- package/types/response.d.ts +9 -1
- package/types/server-functions/client.d.ts +37 -6
- package/types/server-functions/registry.d.ts +38 -1
- package/types/server-functions/server.d.ts +9 -6
- package/types/server-functions/shared.d.ts +46 -3
- package/types-cjs/client.d.cts +4 -2
- package/types-cjs/index.d.cts +1 -0
- package/types-cjs/patch-driver.d.cts +3 -0
- package/types-cjs/response.d.cts +9 -1
- package/types-cjs/server-functions/client.d.cts +37 -6
- package/types-cjs/server-functions/registry.d.cts +38 -1
- package/types-cjs/server-functions/server.d.cts +9 -6
- package/types-cjs/server-functions/shared.d.cts +46 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE,
|
|
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";
|
|
2
2
|
export { REVALIDATE_HEADER } from "../response.js";
|
|
3
3
|
import { JSONCodecOptions } from "../serializer-decode.js";
|
|
4
|
-
export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.js";
|
|
4
|
+
export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.js";
|
|
5
5
|
/** The context `prepareRequest` receives alongside the outgoing RequestInit. */
|
|
6
6
|
export interface PrepareRequestContext {
|
|
7
7
|
/** The build-stable id of the function being called. */
|
|
@@ -25,10 +25,11 @@ export type PrepareRequestHook = (init: RequestInit, context: PrepareRequestCont
|
|
|
25
25
|
/** Options for `configureServerFunctionsClient`. */
|
|
26
26
|
export interface ServerFunctionsClientConfig {
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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` ``).
|
|
32
33
|
* @default "/_server"
|
|
33
34
|
*/
|
|
34
35
|
endpoint?: string;
|
|
@@ -38,6 +39,34 @@ export interface ServerFunctionsClientConfig {
|
|
|
38
39
|
* `decodeResponse` sees them too.
|
|
39
40
|
*/
|
|
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;
|
|
41
70
|
/**
|
|
42
71
|
* Runs before every server-function fetch. Return (or mutate and return)
|
|
43
72
|
* the RequestInit the transport will use; `context.meta` is the
|
|
@@ -125,6 +154,8 @@ export interface ServerFunctionInvocation {
|
|
|
125
154
|
id: string;
|
|
126
155
|
}
|
|
127
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;
|
|
128
159
|
export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
129
160
|
export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
130
161
|
export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "./shared.js";
|
|
1
|
+
export type { InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, ServerFunctionRPC } from "./shared.js";
|
|
2
|
+
import type { InvokeOptions } from "./shared.js";
|
|
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,9 @@
|
|
|
1
|
-
export { ERROR_HEADER, FLASH_COOKIE,
|
|
1
|
+
export { ERROR_HEADER, FLASH_COOKIE, INSTANCE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, clearFlashCookie, decodeErrorHeaderValue, decodeResponse, decodeResponsePayload, encodeErrorHeaderValue, getServerFunctionMetadata, hasFlashCookie, invoke, isServerFunction, subscribeFlightData, withMeta } from "./shared.js";
|
|
2
2
|
export { decodeFlashCookie, encodeFlashCookie } from "./flash.js";
|
|
3
3
|
import { ResponseEnvelope } from "../response.js";
|
|
4
4
|
import { JSONCodecOptions } from "../serializer-decode.js";
|
|
5
5
|
import { RequestEvent } from "../server.js";
|
|
6
|
-
export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.js";
|
|
6
|
+
export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.js";
|
|
7
7
|
export type { FlashSubmission } from "./flash.js";
|
|
8
8
|
/**
|
|
9
9
|
* The request event a server function call runs under: the base
|
|
@@ -208,10 +208,11 @@ export interface ServerFunctionsServerConfig {
|
|
|
208
208
|
*/
|
|
209
209
|
handleNoJS?: ((result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response | Promise<Response>) | null;
|
|
210
210
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
211
|
+
* Mount path the HTTP handler answers on. Must match the client
|
|
212
|
+
* configuration — the id travels as the segment after it, a request whose
|
|
213
|
+
* path does not start with it is not a call, and SSR'd reference `url`s
|
|
214
|
+
* (e.g. form actions) derive from it. Prefix it when the app serves from
|
|
215
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
215
216
|
* @default "/_server"
|
|
216
217
|
*/
|
|
217
218
|
endpoint?: string;
|
|
@@ -396,4 +397,6 @@ export declare const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
|
|
|
396
397
|
export declare function setServerFunctionsDev(dev: boolean): void;
|
|
397
398
|
export declare function sanitizeServerError(value: unknown): unknown;
|
|
398
399
|
export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
|
|
400
|
+
export declare function serverFunctionUrl(id: string, boundArgs?: readonly unknown[]): string;
|
|
401
|
+
export declare function parseServerFunctionUrl(url: string): string | null;
|
|
399
402
|
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.js";
|
|
1
|
+
export { LIVE_SOURCE, SERVER_FUNCTION_INVOKE, SERVER_FUNCTION_METADATA, getServerFunctionMetadata, getServerFunctionRPC, invoke, isServerFunction, provideServerFunctionRPC, withMeta } from "./registry.js";
|
|
2
2
|
export { FLASH_COOKIE, clearFlashCookie, hasFlashCookie, matchFlashCookie } from "../cookies.js";
|
|
3
3
|
import { JSONCodecOptions } from "../serializer-decode.js";
|
|
4
4
|
/**
|
|
@@ -45,6 +45,42 @@ export interface ServerFunction<A extends readonly any[] = any[], T = any> {
|
|
|
45
45
|
/** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
|
|
46
46
|
readonly url: string;
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Per-call, invocation-scoped options for `invoke` — things that vary
|
|
50
|
+
* between calls of the SAME function and cannot be declared (`GET`,
|
|
51
|
+
* `withMeta`) or configured (`prepareRequest`). On the server the call is
|
|
52
|
+
* in-process: `signal` still rejects the caller, the transport hints are
|
|
53
|
+
* no-ops (they describe a wire that does not exist).
|
|
54
|
+
*/
|
|
55
|
+
export interface InvokeOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The call's lifecycle. Aborting rejects the call with the signal's
|
|
58
|
+
* reason and cancels the request (firing `request.signal` server-side);
|
|
59
|
+
* a live source's iteration ends across reconnects. When provided, the
|
|
60
|
+
* signal owns the wire — timeouts compose through it
|
|
61
|
+
* (`AbortSignal.timeout`, `AbortSignal.any`).
|
|
62
|
+
*/
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
/**
|
|
65
|
+
* Lets the request outlive the page — fire-and-forget calls during
|
|
66
|
+
* unload (`pagehide`). Maps to fetch's `keepalive`, body-size caps
|
|
67
|
+
* included.
|
|
68
|
+
*/
|
|
69
|
+
keepalive?: boolean;
|
|
70
|
+
/** Fetch priority hint — speculative prefetch vs. interaction fetch. */
|
|
71
|
+
priority?: "high" | "low" | "auto";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A reference's invocation channel, carried under `SERVER_FUNCTION_INVOKE`:
|
|
75
|
+
* applies one call with per-call options. Declaration wrappers (`GET`,
|
|
76
|
+
* `live`) forward it mechanically — they keep the call mapping 1:1. A
|
|
77
|
+
* wrapper that shares calls (a deduping cache, a multicast channel) opts
|
|
78
|
+
* in deliberately, deciding first what a caller's abort means for shared
|
|
79
|
+
* work — or declines, leaving `invoke` to answer with a directed error.
|
|
80
|
+
* Options arrive already validated — `invoke` admits only
|
|
81
|
+
* invocation-scoped keys.
|
|
82
|
+
*/
|
|
83
|
+
export type ServerFunctionInvoker<A extends readonly any[] = any[], R = any> = (args: A, options?: InvokeOptions) => R;
|
|
48
84
|
/**
|
|
49
85
|
* Declaration-static metadata attached to a server function reference
|
|
50
86
|
* through declaration wrappers (`GET`, `withMeta`). Read it with
|
|
@@ -98,8 +134,8 @@ export declare function getServerFunctionsCodec(): JSONCodecOptions | undefined;
|
|
|
98
134
|
export declare function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
|
|
99
135
|
export declare function getFlightDataConsumer(): FlightDataConsumer | undefined;
|
|
100
136
|
export declare function frameAddress(id: string, args?: readonly unknown[]): string;
|
|
101
|
-
|
|
102
|
-
export declare
|
|
137
|
+
export declare function serverFunctionAddress(endpoint: string, id: string): string;
|
|
138
|
+
export declare function parseServerFunctionAddress(pathname: string, endpoint: string): string | null;
|
|
103
139
|
/**
|
|
104
140
|
* Response header marking a thrown server-function error. The value is the
|
|
105
141
|
* error's message (the structured error itself travels in the body); `"true"`
|
|
@@ -141,6 +177,13 @@ export declare const BodyFormat: {
|
|
|
141
177
|
* included) on the response.
|
|
142
178
|
*/
|
|
143
179
|
Json: string;
|
|
180
|
+
/**
|
|
181
|
+
* No body at all — a function that returned nothing. It marks the response
|
|
182
|
+
* as one the runtime encoded, which separates a void result with a status
|
|
183
|
+
* on it from a refusal answered by something else. Decoding falls through
|
|
184
|
+
* to `undefined`, which is what a peer predating the tag reads too.
|
|
185
|
+
*/
|
|
186
|
+
Void: string;
|
|
144
187
|
};
|
|
145
188
|
export declare function isJSONSafe(value: unknown): boolean;
|
|
146
189
|
export declare function getHeadersAndBody(body: unknown): {
|
package/types-cjs/client.d.cts
CHANGED
|
@@ -79,6 +79,8 @@ export interface RequestEvent {
|
|
|
79
79
|
export type { CookieOptions } from "./cookies.cjs";
|
|
80
80
|
export type { ServerFunction, ServerFunctionMetadata, ServerFunctionRPC } from "./server-functions/shared.cjs";
|
|
81
81
|
export declare const waitAsset: (promise: Promise<unknown>) => void;
|
|
82
|
+
export declare let listDriver: ((parent: Node, listFn: any, marker?: Node, lateClassic?: () => void) => boolean) | undefined;
|
|
83
|
+
export declare function installListDriver(driver: typeof listDriver): void;
|
|
82
84
|
export { DOMWithState, ChildProperties, DOMElements, SVGElements, MathMLElements, VoidElements, RawTextElements, Namespaces, DelegatedEvents } from "./constants.cjs";
|
|
83
85
|
/** Client stub — hydration bootstrap is a server-only emit. */
|
|
84
86
|
export declare function generateHydrationScript(_options?: {
|
|
@@ -145,10 +147,10 @@ export declare function spread<T>(node: Element, accessor: T, skipChildren?: Boo
|
|
|
145
147
|
export declare function dynamicProperty(props: unknown, key: string): unknown;
|
|
146
148
|
export declare function applyRef<T extends Element = Element>(r: ((element: NoInfer<T>) => void) | ((element: NoInfer<T>) => void)[], element: T): void;
|
|
147
149
|
export declare function ref(fn: () => ((element: Element) => void) | ((element: Element) => void)[], element: Element): void;
|
|
148
|
-
|
|
150
|
+
/** Compiler-emitted primitive; not for hand-written code. @internal */
|
|
149
151
|
export declare function scope<T extends () => any>(fn: T): T;
|
|
150
152
|
export declare function installHydrationRuntime(): void;
|
|
151
|
-
|
|
153
|
+
/**
|
|
152
154
|
* Compiler-emitted primitive; not for hand-written code.
|
|
153
155
|
* @internal
|
|
154
156
|
*/
|
package/types-cjs/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component } from "solid-js";
|
|
2
2
|
import type { JSX } from "./jsx.cjs";
|
|
3
3
|
export * from "./client.cjs";
|
|
4
|
+
export { patchDriver, rowProof, driveList } from "./patch-driver.cjs";
|
|
4
5
|
export * from "./server-mock.cjs";
|
|
5
6
|
export * from "./response.cjs";
|
|
6
7
|
export type { JSX } from "./jsx.cjs";
|
package/types-cjs/response.d.cts
CHANGED
|
@@ -16,7 +16,15 @@ export declare const ResponseEnvelope: {
|
|
|
16
16
|
export declare function isResponseEnvelope(value: unknown): value is ResponseEnvelope;
|
|
17
17
|
export declare const HREF: unique symbol;
|
|
18
18
|
export interface Href {
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The brand doubles as a channel: when the slot holds a string it is the
|
|
21
|
+
* value's *logical* path — the routable pathname before an integration's
|
|
22
|
+
* display rendering (eg. a hash router's `#` prefix). `redirect()` prefers
|
|
23
|
+
* it over coercion so Location headers carry routable paths; `toString()`
|
|
24
|
+
* remains the display href for the DOM. `true` brands a value whose
|
|
25
|
+
* string form is already logical.
|
|
26
|
+
*/
|
|
27
|
+
[HREF]: true | string;
|
|
20
28
|
toString(): string;
|
|
21
29
|
}
|
|
22
30
|
/** Whether `value` is an `Href`-branded URL-bearing value. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { ChunkReader, ERROR_HEADER, FLASH_COOKIE,
|
|
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.cjs";
|
|
2
2
|
export { REVALIDATE_HEADER } from "../response.cjs";
|
|
3
3
|
import { JSONCodecOptions } from "../serializer-decode.cjs";
|
|
4
|
-
export type { FlightDataConsumer, FlightDataContext, ServerFunction, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
|
|
4
|
+
export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
|
|
5
5
|
/** The context `prepareRequest` receives alongside the outgoing RequestInit. */
|
|
6
6
|
export interface PrepareRequestContext {
|
|
7
7
|
/** The build-stable id of the function being called. */
|
|
@@ -25,10 +25,11 @@ export type PrepareRequestHook = (init: RequestInit, context: PrepareRequestCont
|
|
|
25
25
|
/** Options for `configureServerFunctionsClient`. */
|
|
26
26
|
export interface ServerFunctionsClientConfig {
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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` ``).
|
|
32
33
|
* @default "/_server"
|
|
33
34
|
*/
|
|
34
35
|
endpoint?: string;
|
|
@@ -38,6 +39,34 @@ export interface ServerFunctionsClientConfig {
|
|
|
38
39
|
* `decodeResponse` sees them too.
|
|
39
40
|
*/
|
|
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;
|
|
41
70
|
/**
|
|
42
71
|
* Runs before every server-function fetch. Return (or mutate and return)
|
|
43
72
|
* the RequestInit the transport will use; `context.meta` is the
|
|
@@ -125,6 +154,8 @@ export interface ServerFunctionInvocation {
|
|
|
125
154
|
id: string;
|
|
126
155
|
}
|
|
127
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;
|
|
128
159
|
export declare function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
129
160
|
export declare function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
130
161
|
export declare function GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
|
|
@@ -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,9 @@
|
|
|
1
|
-
export { ERROR_HEADER, FLASH_COOKIE,
|
|
1
|
+
export { ERROR_HEADER, FLASH_COOKIE, INSTANCE_HEADER, SERVER_FUNCTION_INVOKE, SINGLE_FLIGHT_HEADER, clearFlashCookie, decodeErrorHeaderValue, 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
|
+
export type { FlightDataConsumer, FlightDataContext, InvokeOptions, ServerFunction, ServerFunctionInvoker, ServerFunctionMetadata, SingleFlightPayload } from "./shared.cjs";
|
|
7
7
|
export type { FlashSubmission } from "./flash.cjs";
|
|
8
8
|
/**
|
|
9
9
|
* The request event a server function call runs under: the base
|
|
@@ -208,10 +208,11 @@ export interface ServerFunctionsServerConfig {
|
|
|
208
208
|
*/
|
|
209
209
|
handleNoJS?: ((result: unknown, request: Request, args: unknown[], thrown?: boolean) => Response | Promise<Response>) | null;
|
|
210
210
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
211
|
+
* Mount path the HTTP handler answers on. Must match the client
|
|
212
|
+
* configuration — the id travels as the segment after it, a request whose
|
|
213
|
+
* path does not start with it is not a call, and SSR'd reference `url`s
|
|
214
|
+
* (e.g. form actions) derive from it. Prefix it when the app serves from
|
|
215
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
215
216
|
* @default "/_server"
|
|
216
217
|
*/
|
|
217
218
|
endpoint?: string;
|
|
@@ -396,4 +397,6 @@ export declare const GENERIC_SERVER_ERROR_MESSAGE = "Internal Server Error";
|
|
|
396
397
|
export declare function setServerFunctionsDev(dev: boolean): void;
|
|
397
398
|
export declare function sanitizeServerError(value: unknown): unknown;
|
|
398
399
|
export declare function observeServerFunctionCalls(observer: (call: ServerFunctionCall) => void): () => void;
|
|
400
|
+
export declare function serverFunctionUrl(id: string, boundArgs?: readonly unknown[]): string;
|
|
401
|
+
export declare function parseServerFunctionUrl(url: string): string | null;
|
|
399
402
|
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
|
/**
|
|
@@ -45,6 +45,42 @@ export interface ServerFunction<A extends readonly any[] = any[], T = any> {
|
|
|
45
45
|
/** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
|
|
46
46
|
readonly url: string;
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Per-call, invocation-scoped options for `invoke` — things that vary
|
|
50
|
+
* between calls of the SAME function and cannot be declared (`GET`,
|
|
51
|
+
* `withMeta`) or configured (`prepareRequest`). On the server the call is
|
|
52
|
+
* in-process: `signal` still rejects the caller, the transport hints are
|
|
53
|
+
* no-ops (they describe a wire that does not exist).
|
|
54
|
+
*/
|
|
55
|
+
export interface InvokeOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The call's lifecycle. Aborting rejects the call with the signal's
|
|
58
|
+
* reason and cancels the request (firing `request.signal` server-side);
|
|
59
|
+
* a live source's iteration ends across reconnects. When provided, the
|
|
60
|
+
* signal owns the wire — timeouts compose through it
|
|
61
|
+
* (`AbortSignal.timeout`, `AbortSignal.any`).
|
|
62
|
+
*/
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
/**
|
|
65
|
+
* Lets the request outlive the page — fire-and-forget calls during
|
|
66
|
+
* unload (`pagehide`). Maps to fetch's `keepalive`, body-size caps
|
|
67
|
+
* included.
|
|
68
|
+
*/
|
|
69
|
+
keepalive?: boolean;
|
|
70
|
+
/** Fetch priority hint — speculative prefetch vs. interaction fetch. */
|
|
71
|
+
priority?: "high" | "low" | "auto";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A reference's invocation channel, carried under `SERVER_FUNCTION_INVOKE`:
|
|
75
|
+
* applies one call with per-call options. Declaration wrappers (`GET`,
|
|
76
|
+
* `live`) forward it mechanically — they keep the call mapping 1:1. A
|
|
77
|
+
* wrapper that shares calls (a deduping cache, a multicast channel) opts
|
|
78
|
+
* in deliberately, deciding first what a caller's abort means for shared
|
|
79
|
+
* work — or declines, leaving `invoke` to answer with a directed error.
|
|
80
|
+
* Options arrive already validated — `invoke` admits only
|
|
81
|
+
* invocation-scoped keys.
|
|
82
|
+
*/
|
|
83
|
+
export type ServerFunctionInvoker<A extends readonly any[] = any[], R = any> = (args: A, options?: InvokeOptions) => R;
|
|
48
84
|
/**
|
|
49
85
|
* Declaration-static metadata attached to a server function reference
|
|
50
86
|
* through declaration wrappers (`GET`, `withMeta`). Read it with
|
|
@@ -98,8 +134,8 @@ export declare function getServerFunctionsCodec(): JSONCodecOptions | undefined;
|
|
|
98
134
|
export declare function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
|
|
99
135
|
export declare function getFlightDataConsumer(): FlightDataConsumer | undefined;
|
|
100
136
|
export declare function frameAddress(id: string, args?: readonly unknown[]): string;
|
|
101
|
-
|
|
102
|
-
export declare
|
|
137
|
+
export declare function serverFunctionAddress(endpoint: string, id: string): string;
|
|
138
|
+
export declare function parseServerFunctionAddress(pathname: string, endpoint: string): string | null;
|
|
103
139
|
/**
|
|
104
140
|
* Response header marking a thrown server-function error. The value is the
|
|
105
141
|
* error's message (the structured error itself travels in the body); `"true"`
|
|
@@ -141,6 +177,13 @@ export declare const BodyFormat: {
|
|
|
141
177
|
* included) on the response.
|
|
142
178
|
*/
|
|
143
179
|
Json: string;
|
|
180
|
+
/**
|
|
181
|
+
* No body at all — a function that returned nothing. It marks the response
|
|
182
|
+
* as one the runtime encoded, which separates a void result with a status
|
|
183
|
+
* on it from a refusal answered by something else. Decoding falls through
|
|
184
|
+
* to `undefined`, which is what a peer predating the tag reads too.
|
|
185
|
+
*/
|
|
186
|
+
Void: string;
|
|
144
187
|
};
|
|
145
188
|
export declare function isJSONSafe(value: unknown): boolean;
|
|
146
189
|
export declare function getHeadersAndBody(body: unknown): {
|