@solidjs/web 2.0.0-experimental.8 → 2.0.0-rc.0
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 +22 -4
- package/dist/dev.cjs +1585 -225
- package/dist/dev.js +1510 -201
- package/dist/server.cjs +2642 -264
- package/dist/server.js +2542 -217
- package/dist/web.cjs +1523 -218
- package/dist/web.js +1448 -194
- package/frames/dist/client.cjs +1916 -0
- package/frames/dist/client.dev.cjs +1933 -0
- package/frames/dist/client.dev.js +1921 -0
- package/frames/dist/client.js +1904 -0
- package/frames/dist/server.cjs +3667 -0
- package/frames/dist/server.js +3654 -0
- package/frames/package.json +30 -0
- package/package.json +349 -37
- package/serialization/decode/package.json +20 -0
- package/serialization/dist/decode.cjs +110 -0
- package/serialization/dist/decode.js +104 -0
- package/serialization/dist/serialization.cjs +232 -0
- package/serialization/dist/serialization.js +215 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +182 -0
- package/serialization/types/serializer-decode.d.ts +182 -0
- package/serialization/types-cjs/index.d.cts +182 -0
- package/serialization/types-cjs/package.json +3 -0
- package/serialization/types-cjs/serializer-decode.d.cts +182 -0
- package/server-functions/dist/client.cjs +646 -0
- package/server-functions/dist/client.js +617 -0
- package/server-functions/dist/rich-args.cjs +11 -0
- package/server-functions/dist/rich-args.js +9 -0
- package/server-functions/dist/server.cjs +1077 -0
- package/server-functions/dist/server.dev.cjs +1077 -0
- package/server-functions/dist/server.dev.js +1045 -0
- package/server-functions/dist/server.js +1045 -0
- package/server-functions/package.json +40 -0
- package/server-functions/rich-args/package.json +20 -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 +290 -27
- package/types/cookies.d.ts +93 -0
- package/types/core.d.ts +6 -2
- package/types/frames/client.d.ts +36 -0
- package/types/frames/frame-client.d.ts +338 -0
- package/types/frames/frame-sink.d.ts +194 -0
- package/types/frames/frame-transport.d.ts +222 -0
- package/types/frames/serializer.d.ts +182 -0
- package/types/frames/server.d.ts +52 -0
- package/types/index.d.ts +209 -24
- package/types/jsx-properties.d.ts +93 -0
- package/types/jsx.d.ts +4150 -1
- package/types/response.d.ts +174 -0
- package/types/serializer-decode.d.ts +182 -0
- package/types/serializer.d.ts +182 -0
- package/types/server-functions/client.d.ts +201 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/rich-args.d.ts +10 -0
- package/types/server-functions/server.d.ts +588 -0
- package/types/server-functions/shared.d.ts +523 -0
- package/types/server-mock.d.ts +249 -12
- package/types/server.d.ts +424 -51
- package/types-cjs/client.d.cts +337 -0
- package/types-cjs/cookies.d.cts +93 -0
- package/types-cjs/core.d.cts +6 -0
- package/types-cjs/frames/client.d.cts +36 -0
- package/types-cjs/frames/frame-client.d.cts +338 -0
- package/types-cjs/frames/frame-sink.d.cts +194 -0
- package/types-cjs/frames/frame-transport.d.cts +222 -0
- package/types-cjs/frames/serializer.d.cts +182 -0
- package/types-cjs/frames/server.d.cts +52 -0
- package/types-cjs/index.d.cts +230 -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 +174 -0
- package/types-cjs/serializer-decode.d.cts +182 -0
- package/types-cjs/serializer.d.cts +182 -0
- package/types-cjs/server-functions/client.d.cts +201 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/rich-args.d.cts +10 -0
- package/types-cjs/server-functions/server.d.cts +588 -0
- package/types-cjs/server-functions/shared.d.cts +523 -0
- package/types-cjs/server-mock.d.cts +277 -0
- package/types-cjs/server.d.cts +523 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { JSONCodecOptions } from "../serializer-decode.js";
|
|
2
|
+
import { ServerFunction, ServerFunctionMetadata } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
ChunkReader,
|
|
6
|
+
ERROR_HEADER,
|
|
7
|
+
FLASH_COOKIE,
|
|
8
|
+
FUNCTION_HEADER,
|
|
9
|
+
INSTANCE_HEADER,
|
|
10
|
+
SINGLE_FLIGHT_HEADER,
|
|
11
|
+
clearFlashCookie,
|
|
12
|
+
createChunk,
|
|
13
|
+
decodeErrorHeaderValue,
|
|
14
|
+
decodeResponse,
|
|
15
|
+
decodeResponsePayload,
|
|
16
|
+
deserializeStream,
|
|
17
|
+
encodeErrorHeaderValue,
|
|
18
|
+
frameAddress,
|
|
19
|
+
getFlightDataConsumer,
|
|
20
|
+
getServerFunctionMetadata,
|
|
21
|
+
getServerFunctionsCodec,
|
|
22
|
+
hasFlashCookie,
|
|
23
|
+
isServerFunction,
|
|
24
|
+
serializeString,
|
|
25
|
+
subscribeFlightData,
|
|
26
|
+
withMeta
|
|
27
|
+
} from "./shared.js";
|
|
28
|
+
export { REVALIDATE_HEADER } from "../response.js";
|
|
29
|
+
export type {
|
|
30
|
+
FlightDataConsumer,
|
|
31
|
+
FlightDataContext,
|
|
32
|
+
ServerFunction,
|
|
33
|
+
ServerFunctionMetadata,
|
|
34
|
+
SingleFlightPayload
|
|
35
|
+
} from "./shared.js";
|
|
36
|
+
|
|
37
|
+
/** The context `prepareRequest` receives alongside the outgoing RequestInit. */
|
|
38
|
+
export interface PrepareRequestContext {
|
|
39
|
+
/** The build-stable id of the function being called. */
|
|
40
|
+
id: string;
|
|
41
|
+
/**
|
|
42
|
+
* The reference's declaration metadata (e.g. `method: "GET"` for
|
|
43
|
+
* `GET(fn)` references). Plain references carry an empty object.
|
|
44
|
+
*/
|
|
45
|
+
meta: ServerFunctionMetadata | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Client-side session-dynamic transport hook: runs before every
|
|
50
|
+
* server-function fetch. Return (or mutate and return) the RequestInit the
|
|
51
|
+
* transport will use — the hook sees the final init, transport headers
|
|
52
|
+
* included. The motivating case is dynamic credentials that rotate during
|
|
53
|
+
* a session and apply uniformly to every call (OAuth bearer tokens); it is
|
|
54
|
+
* the client-side symmetric of the server handler hooks. Single hook, not
|
|
55
|
+
* a chain — compose by wrapping functions in userland.
|
|
56
|
+
*/
|
|
57
|
+
export type PrepareRequestHook = (
|
|
58
|
+
init: RequestInit,
|
|
59
|
+
context: PrepareRequestContext
|
|
60
|
+
) => RequestInit | Promise<RequestInit>;
|
|
61
|
+
|
|
62
|
+
/** Options for `configureServerFunctionsClient`. */
|
|
63
|
+
export interface ServerFunctionsClientConfig {
|
|
64
|
+
/**
|
|
65
|
+
* Endpoint the server's HTTP handler is mounted on. Must match the
|
|
66
|
+
* server configuration — SSR'd reference `url`s (e.g. form actions) and
|
|
67
|
+
* client fetches both derive from it. Prefix it when the app serves from
|
|
68
|
+
* a base path (e.g. `` `${BASE_URL}_server` ``).
|
|
69
|
+
* @default "/_server"
|
|
70
|
+
*/
|
|
71
|
+
endpoint?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Codec options (extra plugins etc.) for encoding arguments and decoding
|
|
74
|
+
* results — must match the server's. Stored in the shared layer, so
|
|
75
|
+
* `decodeResponse` sees them too.
|
|
76
|
+
*/
|
|
77
|
+
codec?: JSONCodecOptions;
|
|
78
|
+
/**
|
|
79
|
+
* Runs before every server-function fetch. Return (or mutate and return)
|
|
80
|
+
* the RequestInit the transport will use; `context.meta` is the
|
|
81
|
+
* reference's declaration metadata (e.g. method). For session-dynamic
|
|
82
|
+
* cross-cutting concerns — bearer tokens, tracing headers:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* configureServerFunctionsClient({
|
|
86
|
+
* prepareRequest(init) {
|
|
87
|
+
* return {
|
|
88
|
+
* ...init,
|
|
89
|
+
* headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
|
|
90
|
+
* };
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
prepareRequest?: PrepareRequestHook;
|
|
96
|
+
/**
|
|
97
|
+
* Response-side integration seam — the client mirror of the handler's
|
|
98
|
+
* `transformResult`. `handle(response, ctx)` sees every response before
|
|
99
|
+
* the transport decodes it; returning anything but undefined resolves the
|
|
100
|
+
* call with that value. `capture(info)` runs synchronously at the call
|
|
101
|
+
* site (before any await) and its return arrives as `ctx.context`, so
|
|
102
|
+
* ambient per-call state (e.g. a reactive owner) survives to response
|
|
103
|
+
* time. See `createServerComponentHandler` in frame-transport for the
|
|
104
|
+
* canonical implementation.
|
|
105
|
+
*/
|
|
106
|
+
responseHandler?: {
|
|
107
|
+
capture?(info: { id: string; meta: unknown }): unknown;
|
|
108
|
+
handle(
|
|
109
|
+
response: Response,
|
|
110
|
+
ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
|
|
111
|
+
): unknown;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Encoder for argument lists JSON can't carry faithfully. JSON-safe args
|
|
115
|
+
* always go as plain JSON (no codec in the bundle); anything else throws
|
|
116
|
+
* unless this is set. Installed by `enableRichArguments()` from the
|
|
117
|
+
* rich-args entry — set directly only for custom wire encodings.
|
|
118
|
+
*/
|
|
119
|
+
serializeArgs?(args: unknown[]): string | Promise<string>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Configures the client transport. Call once, before any server function is
|
|
124
|
+
* invoked — typically in the client entry, next to `hydrate()`. Only needed
|
|
125
|
+
* when deviating from the defaults (custom endpoint, codec plugins, or a
|
|
126
|
+
* `prepareRequest` hook).
|
|
127
|
+
*/
|
|
128
|
+
export function configureServerFunctionsClient(config?: ServerFunctionsClientConfig): void;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Declares a server function callable over HTTP GET: calls to the returned
|
|
132
|
+
* reference go out as GET requests with the arguments codec-encoded in the
|
|
133
|
+
* query string — cacheable by HTTP infrastructure. Cache headers flow
|
|
134
|
+
* through the handler's header forwarding
|
|
135
|
+
* (`respond(data, { headers: { "cache-control": "max-age=60" } })`).
|
|
136
|
+
*
|
|
137
|
+
* The declaration rides the metadata channel
|
|
138
|
+
* (`getServerFunctionMetadata(fn)?.method === "GET"`) for routers and
|
|
139
|
+
* integrations to detect, and the server honors it: GET-declared functions
|
|
140
|
+
* accept GET requests in addition to the default POST transport (declaring
|
|
141
|
+
* GET grants, it does not revoke); functions that never declared GET answer
|
|
142
|
+
* GET requests with 405. Server-side the wrapper is identity-flavored — SSR
|
|
143
|
+
* calls stay in-process.
|
|
144
|
+
*
|
|
145
|
+
* Wrap the reference at its declaration; the compiler round-trips the call
|
|
146
|
+
* in both builds:
|
|
147
|
+
*
|
|
148
|
+
* ```ts
|
|
149
|
+
* export const getUser = GET(async (id: string) => {
|
|
150
|
+
* "use server";
|
|
151
|
+
* return db.users.find(id);
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function GET<A extends readonly any[], R>(
|
|
156
|
+
fn: (...args: A) => R
|
|
157
|
+
): ServerFunction<A, Awaited<R>>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Compiler ABI — emitted by compiled `"use server"` client output where a
|
|
161
|
+
* server function was referenced; produces the fetch-backed callable for
|
|
162
|
+
* the function's build-stable id. Development builds pass the function's
|
|
163
|
+
* source name as the trailing argument (dev-only metadata seeded on the
|
|
164
|
+
* metadata channel; never emitted in production). Not meant for
|
|
165
|
+
* hand-written code.
|
|
166
|
+
*
|
|
167
|
+
* The optional `base` targets calls at that url verbatim instead of the
|
|
168
|
+
* configured endpoint — for integrations reconstructing a callable from a
|
|
169
|
+
* server-rendered action url (e.g. a router intercepting a form submit whose
|
|
170
|
+
* `action="/_server?id=...&args=..."` came off the wire): bound arguments
|
|
171
|
+
* stay in the query string, where the server reads them for natural-encoding
|
|
172
|
+
* bodies (FormData, urlencoded).
|
|
173
|
+
* @internal
|
|
174
|
+
*/
|
|
175
|
+
export function createServerReference(id: string, name?: string, base?: string): ServerFunction;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Compiler ABI — only ever referenced by server-mode compiler output;
|
|
179
|
+
* throws so a misconfigured build (server transform feeding a client
|
|
180
|
+
* bundle) fails loudly instead of with a missing-export error. Not meant
|
|
181
|
+
* for hand-written code.
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
export function registerServerReference(): never;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Identity of the currently executing server function call — see the
|
|
188
|
+
* server entry. Named here so isomorphic code can import the type from
|
|
189
|
+
* either entry.
|
|
190
|
+
*/
|
|
191
|
+
export interface ServerFunctionInvocation {
|
|
192
|
+
id: string;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Client no-op mirror of the server entry's accessor: there is never a
|
|
197
|
+
* server function call in flight on the client, so this always returns
|
|
198
|
+
* undefined. Present so `"use server"` modules that import it stay
|
|
199
|
+
* import-stable in client builds before dead-code elimination.
|
|
200
|
+
*/
|
|
201
|
+
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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in codec encoding for server-function ARGUMENTS. By default the client
|
|
3
|
+
* sends argument lists as plain JSON (no serializer in the bundle) and
|
|
4
|
+
* throws on values JSON can't carry faithfully. Call once at startup to
|
|
5
|
+
* send Dates, Maps, Sets, typed arrays, cyclic structures, etc. through the
|
|
6
|
+
* codec — at the cost of the serializer's write half (~5 KB gz on top of
|
|
7
|
+
* the decode half responses already need). The handler accepts both
|
|
8
|
+
* encodings unconditionally.
|
|
9
|
+
*/
|
|
10
|
+
export function enableRichArguments(): void;
|