@solidjs/web 2.0.0-beta.3 → 2.0.0-beta.30
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/README.md +27 -4
- package/dist/dev.cjs +1211 -205
- package/dist/dev.js +1175 -199
- package/dist/server.cjs +1342 -234
- package/dist/server.js +1304 -231
- package/dist/web.cjs +1195 -196
- package/dist/web.js +1159 -190
- package/frames/dist/client.cjs +1746 -0
- package/frames/dist/client.dev.cjs +1759 -0
- package/frames/dist/client.dev.js +1747 -0
- package/frames/dist/client.js +1734 -0
- package/frames/dist/server.cjs +2426 -0
- package/frames/dist/server.js +2414 -0
- package/frames/package.json +30 -0
- package/package.json +287 -38
- package/serialization/dist/serialization.cjs +169 -0
- package/serialization/dist/serialization.js +159 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +157 -0
- package/serialization/types-cjs/index.d.cts +157 -0
- package/serialization/types-cjs/package.json +3 -0
- package/server-functions/dist/client.cjs +613 -0
- package/server-functions/dist/client.js +585 -0
- package/server-functions/dist/server.cjs +904 -0
- package/server-functions/dist/server.js +875 -0
- package/server-functions/package.json +30 -0
- package/storage/package.json +8 -3
- package/storage/types/index.d.ts +26 -0
- package/storage/types-cjs/index.d.cts +28 -0
- package/storage/types-cjs/package.json +3 -0
- package/types/client.d.ts +125 -21
- package/types/core.d.ts +4 -3
- package/types/frames/client.d.ts +20 -0
- package/types/frames/frame-client.d.ts +270 -0
- package/types/frames/frame-sink.d.ts +168 -0
- package/types/frames/frame-transport.d.ts +196 -0
- package/types/frames/serializer.d.ts +157 -0
- package/types/frames/server.d.ts +30 -0
- package/types/index.d.ts +211 -26
- package/types/jsx-properties.d.ts +93 -0
- package/types/jsx.d.ts +4150 -1
- package/types/response.d.ts +129 -0
- package/types/serializer.d.ts +157 -0
- package/types/server-functions/client.d.ts +200 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/server.d.ts +490 -0
- package/types/server-functions/shared.d.ts +445 -0
- package/types/server-mock.d.ts +93 -0
- package/types/server.d.ts +221 -28
- package/types-cjs/client.d.cts +192 -0
- package/types-cjs/core.d.cts +4 -0
- package/types-cjs/frames/client.d.cts +20 -0
- package/types-cjs/frames/frame-client.d.cts +270 -0
- package/types-cjs/frames/frame-sink.d.cts +168 -0
- package/types-cjs/frames/frame-transport.d.cts +196 -0
- package/types-cjs/frames/serializer.d.cts +157 -0
- package/types-cjs/frames/server.d.cts +30 -0
- package/types-cjs/index.d.cts +231 -0
- package/types-cjs/jsx-properties.d.cts +93 -0
- package/types-cjs/jsx.d.cts +4150 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/response.d.cts +129 -0
- package/types-cjs/serializer.d.cts +157 -0
- package/types-cjs/server-functions/client.d.cts +200 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/server.d.cts +490 -0
- package/types-cjs/server-functions/shared.d.cts +445 -0
- package/types-cjs/server-mock.d.cts +165 -0
- package/types-cjs/server.d.cts +349 -0
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -46
- package/storage/types/src/server-mock.d.ts +0 -72
- package/storage/types/storage/src/index.d.ts +0 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope pairing HTTP metadata (a `Response`) with an in-memory value.
|
|
3
|
+
* Produced by `respond()` and by server-function `transformResult`
|
|
4
|
+
* implementations (e.g. single-flight payloads). The HTTP handler forwards
|
|
5
|
+
* `response`'s headers and (non-redirect) status and encodes `value` as the
|
|
6
|
+
* body through the codec, while client-only integrations read `value`
|
|
7
|
+
* directly — no reparse. Mostly consumed by integrations (routers);
|
|
8
|
+
* application code usually just returns what `respond()` gives it.
|
|
9
|
+
*/
|
|
10
|
+
export class ResponseEnvelope<T = unknown> {
|
|
11
|
+
constructor(response: Response | undefined, value: T);
|
|
12
|
+
/** The HTTP metadata: status and headers to forward (body ignored by integrations). */
|
|
13
|
+
response: Response | undefined;
|
|
14
|
+
/** The structured value the caller receives. */
|
|
15
|
+
value: T;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether `value` is a `ResponseEnvelope`. Uses a registered-symbol brand
|
|
20
|
+
* rather than `instanceof`, so it stays correct when separately bundled
|
|
21
|
+
* entries each carry a copy of the class. Integrations should always use
|
|
22
|
+
* this over `instanceof`.
|
|
23
|
+
*/
|
|
24
|
+
export function isResponseEnvelope(value: unknown): value is ResponseEnvelope;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registered-symbol brand (`Symbol.for("solid.Href")`) marking URL-bearing
|
|
28
|
+
* values. Declared `unique symbol` type-side; the runtime value is the
|
|
29
|
+
* registered symbol, so separately bundled copies agree on identity.
|
|
30
|
+
*/
|
|
31
|
+
export declare const HREF: unique symbol;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A URL-bearing value: coerces to its URL via `toString()` and carries the
|
|
35
|
+
* `HREF` registered-symbol brand. Integrations mint these (e.g. a router's
|
|
36
|
+
* typed path objects answer the brand from their proxy) and URL-accepting
|
|
37
|
+
* APIs like `redirect()` accept them alongside plain strings. The brand is
|
|
38
|
+
* what makes the type meaningful — every object has `toString()`.
|
|
39
|
+
*/
|
|
40
|
+
export interface Href {
|
|
41
|
+
[HREF]: true;
|
|
42
|
+
toString(): string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Whether `value` is an `Href`-branded URL-bearing value. Registered-symbol
|
|
47
|
+
* check, so it stays correct across duplicated module instances — same
|
|
48
|
+
* rationale as `isResponseEnvelope`.
|
|
49
|
+
*/
|
|
50
|
+
export function isHref(value: unknown): value is Href;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Response header naming the cache keys a mutation invalidated
|
|
54
|
+
* (`"X-Revalidate"`), comma separated. The response helpers below set it
|
|
55
|
+
* from their `revalidate` option; the client transport treats its presence
|
|
56
|
+
* as control flow, and integrations read it to invalidate their own cache.
|
|
57
|
+
* Core never inspects the keys, so how they are matched (prefixes, exact
|
|
58
|
+
* names, namespaces) is the integration's business.
|
|
59
|
+
*/
|
|
60
|
+
export const REVALIDATE_HEADER: string;
|
|
61
|
+
|
|
62
|
+
/** `ResponseInit` accepted by the response helpers, plus `revalidate`. */
|
|
63
|
+
export interface ResponseHelperInit extends ResponseInit {
|
|
64
|
+
/**
|
|
65
|
+
* Cache keys the mutation invalidated, carried in the `X-Revalidate`
|
|
66
|
+
* header. Opaque to the protocol — the integration's keyed cache (e.g.
|
|
67
|
+
* the router's `query` cache) assigns them meaning.
|
|
68
|
+
*/
|
|
69
|
+
revalidate?: string | string[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Response redirecting to `url` (default status 302). Return (or throw) it
|
|
74
|
+
* from a server function — the HTTP handler forwards the redirect for the
|
|
75
|
+
* client integration to follow — or return it from a client-side action,
|
|
76
|
+
* where the integration interprets it in memory. Same object, same
|
|
77
|
+
* meaning, both sides.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { redirect } from "@solidjs/web";
|
|
82
|
+
*
|
|
83
|
+
* async function login(form: FormData) {
|
|
84
|
+
* "use server";
|
|
85
|
+
* // ...
|
|
86
|
+
* return redirect("/dashboard", { revalidate: "session" });
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function redirect(url: string | Href, init?: number | ResponseHelperInit): Response;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Empty response requesting revalidation of the named cache keys — all of
|
|
94
|
+
* them when omitted. For mutations whose only effect the caller needs is
|
|
95
|
+
* "refetch your data".
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { reload } from "@solidjs/web";
|
|
100
|
+
*
|
|
101
|
+
* async function addTodo(title: string) {
|
|
102
|
+
* "use server";
|
|
103
|
+
* await db.insert(title);
|
|
104
|
+
* return reload({ revalidate: "todos" });
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function reload(init?: ResponseHelperInit): Response;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A value paired with response metadata (status, headers, `revalidate`) —
|
|
112
|
+
* for the things a naked return can't express. Scripted callers receive
|
|
113
|
+
* `value` transparently (the transport unwraps the envelope), and
|
|
114
|
+
* progressive enhancement stays invisible: the carried response holds a
|
|
115
|
+
* plain JSON body so consumers without the client runtime (no-JS form
|
|
116
|
+
* posts, direct HTTP) get real JSON.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { respond } from "@solidjs/web";
|
|
121
|
+
*
|
|
122
|
+
* async function createItem(input: Item) {
|
|
123
|
+
* "use server";
|
|
124
|
+
* const item = await db.create(input);
|
|
125
|
+
* return respond(item, { status: 201, revalidate: "items" });
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export function respond<T>(value: T, init?: ResponseHelperInit): ResponseEnvelope<T>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Plugin, Serializer, SerovalNode } from "seroval";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
5
|
+
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
6
|
+
*/
|
|
7
|
+
export type { SerovalNode };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
11
|
+
* to encode/decode a custom value type. Supply matching plugins on both
|
|
12
|
+
* peers of a transport.
|
|
13
|
+
*/
|
|
14
|
+
export type SerializerPlugin = Plugin<any, any>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
18
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
19
|
+
* Applied by every serializer in this module; custom plugins compose ahead
|
|
20
|
+
* of it via `resolveSerializerPlugins`.
|
|
21
|
+
*/
|
|
22
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
26
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
27
|
+
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
28
|
+
* plugin list to another serialization layer.
|
|
29
|
+
*/
|
|
30
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
|
+
|
|
32
|
+
/** Options for `createSerializer`. */
|
|
33
|
+
export interface WebSerializerOptions {
|
|
34
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
|
+
globalIdentifier: string;
|
|
36
|
+
/** Cross-reference scope id, for isolating multiple streams on one page. */
|
|
37
|
+
scopeId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
40
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays). Outside
|
|
41
|
+
* development, `Error.prototype.stack` is additionally stripped on top of
|
|
42
|
+
* any override — serialized stacks leak server paths to the client.
|
|
43
|
+
*/
|
|
44
|
+
disabledFeatures?: number;
|
|
45
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
46
|
+
plugins?: SerializerPlugin[];
|
|
47
|
+
/** Receives each emitted script chunk. */
|
|
48
|
+
onData: (result: string) => void;
|
|
49
|
+
onError?: (error: unknown) => void;
|
|
50
|
+
/** Fires once all async values have settled. */
|
|
51
|
+
onDone?: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
56
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
57
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
58
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
59
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
61
|
+
*/
|
|
62
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
66
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type HydrationSerializerOptions = Omit<
|
|
70
|
+
WebSerializerOptions,
|
|
71
|
+
"globalIdentifier" | "disabledFeatures"
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
76
|
+
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
77
|
+
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
78
|
+
* for hand-written code — custom serialization should use
|
|
79
|
+
* `createSerializer` or the JSON codec.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
86
|
+
* emits ahead of hydration data for a render scope. Not meant for
|
|
87
|
+
* hand-written code.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
91
|
+
|
|
92
|
+
// ---- JSON codec (server function transports) ----
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
96
|
+
* on the serializing and deserializing peer or payloads will not
|
|
97
|
+
* round-trip — for server functions, set them once through the
|
|
98
|
+
* client/server `codec` config option.
|
|
99
|
+
*/
|
|
100
|
+
export interface JSONCodecOptions {
|
|
101
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
102
|
+
plugins?: SerializerPlugin[];
|
|
103
|
+
/**
|
|
104
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
105
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
106
|
+
* Outside development, the encoding side additionally strips
|
|
107
|
+
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
108
|
+
* server paths to the client. Decoding stays permissive, so payloads from
|
|
109
|
+
* a development peer still round-trip.
|
|
110
|
+
*/
|
|
111
|
+
disabledFeatures?: number;
|
|
112
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
113
|
+
depthLimit?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Options for `serializeJSON`. */
|
|
117
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
120
|
+
* (the source value itself). Async values produce additional chunks as
|
|
121
|
+
* they resolve.
|
|
122
|
+
*/
|
|
123
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
124
|
+
onError?: (error: unknown) => void;
|
|
125
|
+
/** Fires once all async values have settled. */
|
|
126
|
+
onDone?: () => void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
131
|
+
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
132
|
+
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
|
+
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
|
+
* function that aborts pending async serialization.
|
|
135
|
+
*/
|
|
136
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
140
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
141
|
+
* from one stream must go through the same deserializer instance. The first
|
|
142
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
143
|
+
* settles the async values referenced inside it.
|
|
144
|
+
*/
|
|
145
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
149
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
150
|
+
* `resolve`. The frames client host wires one per response
|
|
151
|
+
* (`applyData: c => table.apply(c)`).
|
|
152
|
+
*/
|
|
153
|
+
export interface JSONDataTable {
|
|
154
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
155
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
156
|
+
}
|
|
157
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { JSONCodecOptions } from "../serializer.js";
|
|
2
|
+
import { ServerFunction, ServerFunctionMetadata } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
ChunkReader,
|
|
6
|
+
ERROR_HEADER,
|
|
7
|
+
FLASH_COOKIE,
|
|
8
|
+
FUNCTION_HEADER,
|
|
9
|
+
INSTANCE_HEADER,
|
|
10
|
+
SINGLE_FLIGHT_HEADER,
|
|
11
|
+
clearFlashCookie,
|
|
12
|
+
createChunk,
|
|
13
|
+
decodeErrorHeaderValue,
|
|
14
|
+
decodeResponse,
|
|
15
|
+
decodeResponsePayload,
|
|
16
|
+
deserializeStream,
|
|
17
|
+
encodeErrorHeaderValue,
|
|
18
|
+
frameAddress,
|
|
19
|
+
getFlightDataConsumer,
|
|
20
|
+
getServerFunctionMetadata,
|
|
21
|
+
getServerFunctionsCodec,
|
|
22
|
+
hasFlashCookie,
|
|
23
|
+
isServerFunction,
|
|
24
|
+
subscribeFlightData,
|
|
25
|
+
withMeta
|
|
26
|
+
} from "./shared.js";
|
|
27
|
+
export { REVALIDATE_HEADER } from "../response.js";
|
|
28
|
+
export type {
|
|
29
|
+
FlightDataConsumer,
|
|
30
|
+
FlightDataContext,
|
|
31
|
+
ServerFunction,
|
|
32
|
+
ServerFunctionMetadata,
|
|
33
|
+
SingleFlightPayload
|
|
34
|
+
} from "./shared.js";
|
|
35
|
+
|
|
36
|
+
/** The context `prepareRequest` receives alongside the outgoing RequestInit. */
|
|
37
|
+
export interface PrepareRequestContext {
|
|
38
|
+
/** The build-stable id of the function being called. */
|
|
39
|
+
id: string;
|
|
40
|
+
/**
|
|
41
|
+
* The reference's declaration metadata (e.g. `method: "GET"` for
|
|
42
|
+
* `GET(fn)` references). Plain references carry an empty object.
|
|
43
|
+
*/
|
|
44
|
+
meta: ServerFunctionMetadata | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Client-side session-dynamic transport hook: runs before every
|
|
49
|
+
* server-function fetch. Return (or mutate and return) the RequestInit the
|
|
50
|
+
* transport will use — the hook sees the final init, transport headers
|
|
51
|
+
* included. The motivating case is dynamic credentials that rotate during
|
|
52
|
+
* a session and apply uniformly to every call (OAuth bearer tokens); it is
|
|
53
|
+
* the client-side symmetric of the server handler hooks. Single hook, not
|
|
54
|
+
* a chain — compose by wrapping functions in userland.
|
|
55
|
+
*/
|
|
56
|
+
export type PrepareRequestHook = (
|
|
57
|
+
init: RequestInit,
|
|
58
|
+
context: PrepareRequestContext
|
|
59
|
+
) => RequestInit | Promise<RequestInit>;
|
|
60
|
+
|
|
61
|
+
/** Options for `configureServerFunctionsClient`. */
|
|
62
|
+
export interface ServerFunctionsClientConfig {
|
|
63
|
+
/**
|
|
64
|
+
* Endpoint the server's HTTP handler is mounted on. Must match the
|
|
65
|
+
* server configuration — SSR'd reference `url`s (e.g. form actions) and
|
|
66
|
+
* client fetches both derive from it. Prefix it when the app serves from
|
|
67
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
68
|
+
* @default "/_server"
|
|
69
|
+
*/
|
|
70
|
+
endpoint?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Codec options (extra plugins etc.) for encoding arguments and decoding
|
|
73
|
+
* results — must match the server's. Stored in the shared layer, so
|
|
74
|
+
* `decodeResponse` sees them too.
|
|
75
|
+
*/
|
|
76
|
+
codec?: JSONCodecOptions;
|
|
77
|
+
/**
|
|
78
|
+
* Runs before every server-function fetch. Return (or mutate and return)
|
|
79
|
+
* the RequestInit the transport will use; `context.meta` is the
|
|
80
|
+
* reference's declaration metadata (e.g. method). For session-dynamic
|
|
81
|
+
* cross-cutting concerns — bearer tokens, tracing headers:
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* configureServerFunctionsClient({
|
|
85
|
+
* prepareRequest(init) {
|
|
86
|
+
* return {
|
|
87
|
+
* ...init,
|
|
88
|
+
* headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
|
|
89
|
+
* };
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
prepareRequest?: PrepareRequestHook;
|
|
95
|
+
/**
|
|
96
|
+
* Response-side integration seam — the client mirror of the handler's
|
|
97
|
+
* `transformResult`. `handle(response, ctx)` sees every response before
|
|
98
|
+
* the transport decodes it; returning anything but undefined resolves the
|
|
99
|
+
* call with that value. `capture(info)` runs synchronously at the call
|
|
100
|
+
* site (before any await) and its return arrives as `ctx.context`, so
|
|
101
|
+
* ambient per-call state (e.g. a reactive owner) survives to response
|
|
102
|
+
* time. See `createServerComponentHandler` in frame-transport for the
|
|
103
|
+
* canonical implementation.
|
|
104
|
+
*/
|
|
105
|
+
responseHandler?: {
|
|
106
|
+
capture?(info: { id: string; meta: unknown }): unknown;
|
|
107
|
+
handle(
|
|
108
|
+
response: Response,
|
|
109
|
+
ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
|
|
110
|
+
): unknown;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Encoder for argument lists JSON can't carry faithfully. JSON-safe args
|
|
114
|
+
* always go as plain JSON (no codec in the bundle); anything else throws
|
|
115
|
+
* unless this is set. Installed by `enableRichArguments()` from the
|
|
116
|
+
* rich-args entry — set directly only for custom wire encodings.
|
|
117
|
+
*/
|
|
118
|
+
serializeArgs?(args: unknown[]): string | Promise<string>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Configures the client transport. Call once, before any server function is
|
|
123
|
+
* invoked — typically in the client entry, next to `hydrate()`. Only needed
|
|
124
|
+
* when deviating from the defaults (custom endpoint, codec plugins, or a
|
|
125
|
+
* `prepareRequest` hook).
|
|
126
|
+
*/
|
|
127
|
+
export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Declares a server function callable over HTTP GET: calls to the returned
|
|
131
|
+
* reference go out as GET requests with the arguments codec-encoded in the
|
|
132
|
+
* query string — cacheable by HTTP infrastructure. Cache headers flow
|
|
133
|
+
* through the handler's header forwarding
|
|
134
|
+
* (`respond(data, { headers: { "cache-control": "max-age=60" } })`).
|
|
135
|
+
*
|
|
136
|
+
* The declaration rides the metadata channel
|
|
137
|
+
* (`getServerFunctionMetadata(fn)?.method === "GET"`) for routers and
|
|
138
|
+
* integrations to detect, and the server honors it: GET-declared functions
|
|
139
|
+
* accept GET requests in addition to the default POST transport (declaring
|
|
140
|
+
* GET grants, it does not revoke); functions that never declared GET answer
|
|
141
|
+
* GET requests with 405. Server-side the wrapper is identity-flavored — SSR
|
|
142
|
+
* calls stay in-process.
|
|
143
|
+
*
|
|
144
|
+
* Wrap the reference at its declaration; the compiler round-trips the call
|
|
145
|
+
* in both builds:
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* export const getUser = GET(async (id: string) => {
|
|
149
|
+
* "use server";
|
|
150
|
+
* return db.users.find(id);
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function GET<A extends readonly any[], R>(
|
|
155
|
+
fn: (...args: A) => R
|
|
156
|
+
): ServerFunction<A, Awaited<R>>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Compiler ABI — emitted by compiled `"use server"` client output where a
|
|
160
|
+
* server function was referenced; produces the fetch-backed callable for
|
|
161
|
+
* the function's build-stable id. Development builds pass the function's
|
|
162
|
+
* source name as the trailing argument (dev-only metadata seeded on the
|
|
163
|
+
* metadata channel; never emitted in production). Not meant for
|
|
164
|
+
* hand-written code.
|
|
165
|
+
*
|
|
166
|
+
* The optional `base` targets calls at that url verbatim instead of the
|
|
167
|
+
* configured endpoint — for integrations reconstructing a callable from a
|
|
168
|
+
* server-rendered action url (e.g. a router intercepting a form submit whose
|
|
169
|
+
* `action="/_server?id=...&args=..."` came off the wire): bound arguments
|
|
170
|
+
* stay in the query string, where the server reads them for natural-encoding
|
|
171
|
+
* bodies (FormData, urlencoded).
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
export function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Compiler ABI — only ever referenced by server-mode compiler output;
|
|
178
|
+
* throws so a misconfigured build (server transform feeding a client
|
|
179
|
+
* bundle) fails loudly instead of with a missing-export error. Not meant
|
|
180
|
+
* for hand-written code.
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
export function registerServerReference(): never;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Identity of the currently executing server function call — see the
|
|
187
|
+
* server entry. Named here so isomorphic code can import the type from
|
|
188
|
+
* either entry.
|
|
189
|
+
*/
|
|
190
|
+
export interface ServerFunctionInvocation {
|
|
191
|
+
id: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Client no-op mirror of the server entry's accessor: there is never a
|
|
196
|
+
* server function call in flight on the client, so this always returns
|
|
197
|
+
* undefined. Present so `"use server"` modules that import it stay
|
|
198
|
+
* import-stable in client builds before dead-code elimination.
|
|
199
|
+
*/
|
|
200
|
+
export function getServerFunctionInvocation(): ServerFunctionInvocation | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outcome of a call made without the client runtime, as it rides the
|
|
3
|
+
* flash cookie: what was submitted, where, and what came back. `result` and
|
|
4
|
+
* `error` are mutually exclusive — a thrown outcome fills `error`, a
|
|
5
|
+
* returned one fills `result` — mirroring the split a scripted call sees.
|
|
6
|
+
*/
|
|
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;
|
|
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;
|