@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.21

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 (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +790 -223
  3. package/dist/dev.js +764 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +779 -196
  7. package/dist/web.js +753 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +448 -0
  16. package/server-functions/dist/client.js +435 -0
  17. package/server-functions/dist/server.cjs +632 -0
  18. package/server-functions/dist/server.js +615 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +137 -0
  32. package/types/server-functions/server.d.ts +307 -0
  33. package/types/server-functions/shared.d.ts +342 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +137 -0
  45. package/types-cjs/server-functions/server.d.cts +307 -0
  46. package/types-cjs/server-functions/shared.d.cts +342 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,342 @@
1
+ import { JSONCodecOptions } from "../serializer.js";
2
+
3
+ export type { JSONCodecOptions };
4
+
5
+ /**
6
+ * Configures the codec options for the server function wire format (extra
7
+ * Seroval plugins, feature policy, depth limit). Both peers must configure
8
+ * identical options or payloads will not round-trip. Usually called
9
+ * indirectly through `configureServerFunctionsClient` /
10
+ * `configureServerFunctionsServer` (their `codec` option writes through to
11
+ * here); call it directly only from universal code configuring both sides
12
+ * at once.
13
+ */
14
+ export function configureServerFunctionsCodec(codec: JSONCodecOptions | undefined): void;
15
+
16
+ /**
17
+ * The currently configured codec options (set through
18
+ * `configureServerFunctionsCodec` or the client/server `codec` option), or
19
+ * undefined when running on the defaults. Integrations pass this to
20
+ * lower-level codec helpers so custom plugins configured by the app apply.
21
+ */
22
+ export function getServerFunctionsCodec(): JSONCodecOptions | undefined;
23
+
24
+ /**
25
+ * Request header carrying the server function id (`"X-Server-Function-Id"`).
26
+ * Integrations can read it to identify which function a request targets;
27
+ * the id also arrives as the `id` query parameter for GET calls and no-JS
28
+ * form posts.
29
+ */
30
+ export const FUNCTION_HEADER: string;
31
+
32
+ /**
33
+ * Request header carrying a per-call instance id
34
+ * (`"X-Server-Function-Instance"`). Its presence tells the server the call
35
+ * came through the client runtime — its absence marks a no-JS form post or
36
+ * direct HTTP call, which receive plain responses instead of codec-encoded
37
+ * ones.
38
+ */
39
+ export const INSTANCE_HEADER: string;
40
+
41
+ /**
42
+ * Header driving the single-flight protocol on both legs
43
+ * (`"X-Single-Flight"`). On the request it opts the call into data
44
+ * collection — the transport sends it automatically on non-GET calls while
45
+ * a flight-data consumer is subscribed (subscribing IS the opt-in). On the
46
+ * response it marks a body carrying the standardized `SingleFlightPayload`.
47
+ * How the data is produced (a data-only render, running route preloads,
48
+ * anything else) and what it means is entirely the integration's business —
49
+ * the protocol only standardizes the wire shape and the delivery.
50
+ */
51
+ export const SINGLE_FLIGHT_HEADER: string;
52
+
53
+ /**
54
+ * The standardized body of a single-flight response (a response tagged with
55
+ * `SINGLE_FLIGHT_HEADER`): the function's return `value` plus the
56
+ * integration-produced `data` payload, folded into one round trip by the
57
+ * HTTP handler. Integrations decoding passthrough responses themselves (no
58
+ * registered consumer) see this shape from `decodeResponse`. The top level
59
+ * is reserved for the protocol — integration payload lives entirely under
60
+ * `data`, which can be any codec-serializable value.
61
+ */
62
+ export interface SingleFlightPayload<T = unknown, D = unknown> {
63
+ /** The server function's return (or thrown) value. */
64
+ value: T;
65
+ /** The integration-produced data payload. */
66
+ data: D;
67
+ }
68
+
69
+ /**
70
+ * Envelope context delivered alongside single-flight data: the transport
71
+ * response, whose headers carry the integration metadata (`Location` for
72
+ * redirect-with-data, `X-Revalidate` keys) and status. The body is already
73
+ * consumed — read `data` and `value` from the delivery, not from here.
74
+ */
75
+ export interface FlightDataContext {
76
+ /** The HTTP response the data arrived on (metadata only). */
77
+ response: Response;
78
+ }
79
+
80
+ /**
81
+ * Consumer receiving single-flight data on the client: `data` is the
82
+ * integration-produced payload (opaque to the protocol), `context` carries
83
+ * the envelope metadata. Async consumers are awaited before the function
84
+ * value is returned to the caller, so caches are seeded first.
85
+ */
86
+ export type FlightDataConsumer<D = unknown> = (
87
+ data: D,
88
+ context: FlightDataContext
89
+ ) => void | Promise<void>;
90
+
91
+ /**
92
+ * Registers the consumer the client transport delivers single-flight data
93
+ * to. Subscribing is the single-flight opt-in: while a consumer is
94
+ * registered the transport sends the request-leg `SINGLE_FLIGHT_HEADER` on
95
+ * non-GET calls (GET reads stay plain and cacheable), asking the server's
96
+ * collection hook to fold data into the response. When a single-flight
97
+ * response arrives, the transport decodes the standardized
98
+ * `{ value, data }` payload, delivers `data` (with the response as
99
+ * envelope context — redirect location, revalidation keys), and returns
100
+ * `value` to the caller as if the call were plain. What to do with the
101
+ * data (seed caches, navigate, ...) is entirely the consumer's business.
102
+ * One active consumer at a time — a later registration replaces the
103
+ * current one; returns an unsubscribe function. With no consumer
104
+ * registered, no header is sent and the server does no collection work;
105
+ * responses an integration opted in manually still pass through to the
106
+ * caller whole, exactly like other integration responses.
107
+ */
108
+ export function subscribeFlightData<D = unknown>(consumer: FlightDataConsumer<D>): () => void;
109
+
110
+ /**
111
+ * The currently registered single-flight consumer.
112
+ *
113
+ * Transport building block; not meant for hand-written code.
114
+ * @internal
115
+ */
116
+ export function getFlightDataConsumer(): FlightDataConsumer | undefined;
117
+
118
+ /**
119
+ * The public contract of a server function reference — what a `"use
120
+ * server"` import is at runtime on either side: an async callable plus its
121
+ * build-stable identity.
122
+ */
123
+ export interface ServerFunction<A extends readonly any[] = any[], T = any> {
124
+ (...args: A): Promise<T>;
125
+ /** The build-stable function id (stable across the client and server builds). */
126
+ readonly id: string;
127
+ /** URL invoking this function directly over HTTP (form `action`s, raw fetches). */
128
+ readonly url: string;
129
+ }
130
+
131
+ /**
132
+ * Declaration-static metadata attached to a server function reference
133
+ * through declaration wrappers (`GET`, `withMeta`). Read it with
134
+ * `getServerFunctionMetadata`; routers and integrations detect capability
135
+ * from here instead of property sniffing, and `prepareRequest` receives it
136
+ * as `context.meta`. Write through `withMeta` — later writes shallow-merge
137
+ * over earlier ones.
138
+ */
139
+ export interface ServerFunctionMetadata {
140
+ /** The declared HTTP method. Undeclared references call over POST. */
141
+ readonly method?: "GET" | "POST";
142
+ /**
143
+ * A human-readable label for the function, seeded by development builds
144
+ * from the compiled function's source name (dev tooling — inspectors,
145
+ * logs). Dev-only: production builds emit no name. Not unique and not an
146
+ * identity key — use `id` for identity. Seeded as a default: an explicit
147
+ * `withMeta` write wins.
148
+ */
149
+ readonly name?: string;
150
+ /** User-declared transport metadata attached with `withMeta`. */
151
+ readonly [key: string]: unknown;
152
+ }
153
+
154
+ /**
155
+ * Reads a server function reference's declaration metadata — e.g.
156
+ * `getServerFunctionMetadata(fn)?.method === "GET"` detects a `GET(fn)`
157
+ * declaration. Returns undefined when `fn` is not a server function
158
+ * reference; plain references carry an empty metadata object. Works on
159
+ * client proxies and server-side references alike, across duplicated
160
+ * module instances (registered-symbol brand).
161
+ */
162
+ export function getServerFunctionMetadata(fn: unknown): ServerFunctionMetadata | undefined;
163
+
164
+ /**
165
+ * Whether `fn` is a server function reference (a client proxy or a
166
+ * server-side registered callable). Detection is structural — a
167
+ * registered-symbol metadata brand — so it holds across duplicated module
168
+ * instances and both sides of the directive boundary.
169
+ */
170
+ export function isServerFunction(fn: unknown): fn is ServerFunction;
171
+
172
+ /**
173
+ * Attaches user-declared transport metadata to a server function reference
174
+ * (client proxy or server-registered callable) and returns the reference.
175
+ * Writes ride the same channel `GET` uses: later writes shallow-merge over
176
+ * earlier ones, and `getServerFunctionMetadata(fn)` reads the merged bag —
177
+ * so `withMeta` composes with `GET` in either order
178
+ * (`GET(withMeta(fn, meta))` ≡ `withMeta(GET(fn), meta)`).
179
+ *
180
+ * The pattern is declare-on-function, react-in-hook: metadata declared
181
+ * here reaches `prepareRequest` as `context.meta`, letting session-dynamic
182
+ * transport policy key on declarations instead of comparing function ids:
183
+ *
184
+ * ```ts
185
+ * export const chargeCard = withMeta(async (amount: number) => {
186
+ * "use server";
187
+ * // ...
188
+ * }, { requiresAuth: true });
189
+ *
190
+ * configureServerFunctionsClient({
191
+ * prepareRequest(init, { meta }) {
192
+ * if (meta?.requiresAuth) {
193
+ * return {
194
+ * ...init,
195
+ * headers: { ...init.headers, Authorization: `Bearer ${session.token()}` }
196
+ * };
197
+ * }
198
+ * return init;
199
+ * }
200
+ * });
201
+ * ```
202
+ */
203
+ export function withMeta<F extends (...args: any[]) => any>(fn: F, meta: ServerFunctionMetadata): F;
204
+
205
+ /**
206
+ * The registered symbol branding server function references with their
207
+ * declaration metadata. Use the typed accessors instead.
208
+ * @internal
209
+ */
210
+ export const SERVER_FUNCTION_METADATA: unique symbol;
211
+
212
+ /**
213
+ * Header carrying the body format tag (a `BodyFormat` value) —
214
+ * `"X-Server-Function-Format"`.
215
+ *
216
+ * Transport wire detail; not meant for hand-written code.
217
+ * @internal
218
+ */
219
+ export const BODY_FORMAT_HEADER: string;
220
+
221
+ /**
222
+ * FormData key used when a lone File is sent as the argument.
223
+ *
224
+ * Transport wire detail; not meant for hand-written code.
225
+ * @internal
226
+ */
227
+ export const FILE_FORM_KEY: string;
228
+
229
+ /**
230
+ * Wire tags naming how a request/response body was encoded, carried in
231
+ * `BODY_FORMAT_HEADER`.
232
+ *
233
+ * Transport wire detail; not meant for hand-written code.
234
+ * @internal
235
+ */
236
+ export const BodyFormat: {
237
+ readonly Serialized: "0";
238
+ readonly String: "1";
239
+ readonly FormData: "2";
240
+ readonly URLSearchParams: "3";
241
+ readonly Blob: "4";
242
+ readonly File: "5";
243
+ readonly ArrayBuffer: "6";
244
+ readonly Uint8Array: "7";
245
+ };
246
+
247
+ /**
248
+ * Transport wire detail; not meant for hand-written code.
249
+ * @internal
250
+ */
251
+ export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
252
+
253
+ /**
254
+ * Picks a direct HTTP encoding (headers + BodyInit) for values that have
255
+ * one — strings, FormData, URLSearchParams, File, Blob, ArrayBuffer,
256
+ * Uint8Array. Returns undefined when the value needs the serializer.
257
+ *
258
+ * Transport building block used by the fetch transport and the HTTP
259
+ * handler; not meant for hand-written code.
260
+ * @internal
261
+ */
262
+ export function getHeadersAndBody(
263
+ body: unknown
264
+ ): { headers?: Record<string, string>; body: BodyInit } | undefined;
265
+
266
+ /**
267
+ * Decodes a Request/Response body according to its `BODY_FORMAT_HEADER`
268
+ * tag (falling back to content-type sniffing for form posts that never saw
269
+ * the client runtime). The inverse of `getHeadersAndBody` + the serialized
270
+ * stream. Resolves undefined for bodies without a recognized encoding.
271
+ *
272
+ * Transport building block; use `decodeResponse` from integration code.
273
+ * @internal
274
+ */
275
+ export function extractBody(
276
+ source: Request | Response,
277
+ codecOptions?: JSONCodecOptions
278
+ ): Promise<unknown>;
279
+
280
+ /**
281
+ * Serializes a value as a stream of length-prefixed SerovalNode chunks.
282
+ * Async values (promises, streams) keep the stream open until they settle,
283
+ * so one connection carries incremental results. Codec options must match
284
+ * the deserializing peer.
285
+ *
286
+ * Transport building block; not meant for hand-written code.
287
+ * @internal
288
+ */
289
+ export function serializeStream(
290
+ value: unknown,
291
+ codecOptions?: JSONCodecOptions
292
+ ): ReadableStream<Uint8Array>;
293
+
294
+ /**
295
+ * `serializeStream` drained to a string (async values fully awaited).
296
+ *
297
+ * Transport building block; not meant for hand-written code.
298
+ * @internal
299
+ */
300
+ export function serializeString(value: unknown, codecOptions?: JSONCodecOptions): Promise<string>;
301
+
302
+ /**
303
+ * Decodes a framed chunk stream from a Request/Response body. Resolves with
304
+ * the first chunk's value (the source value); later chunks settle the async
305
+ * values referenced inside it as they arrive.
306
+ *
307
+ * Transport building block; use `decodeResponse` from integration code.
308
+ * @internal
309
+ */
310
+ export function deserializeStream<T = unknown>(
311
+ source: Request | Response,
312
+ codecOptions?: JSONCodecOptions
313
+ ): Promise<T>;
314
+
315
+ /**
316
+ * `deserializeStream` for an already-buffered string.
317
+ *
318
+ * Transport building block; not meant for hand-written code.
319
+ * @internal
320
+ */
321
+ export function deserializeString<T = unknown>(
322
+ text: string,
323
+ codecOptions?: JSONCodecOptions
324
+ ): Promise<T>;
325
+
326
+ /**
327
+ * Decodes a server function response body using the configured codec. This
328
+ * is the integration-facing decoder: routers call it on responses the
329
+ * transport hands over whole — redirects, revalidation, single-flight
330
+ * payloads — to recover the structured value inside. Resolves undefined for
331
+ * empty bodies and bodies without a recognized encoding (e.g. a raw user
332
+ * Response). Renderer- and platform-neutral: safe to use from universal
333
+ * code.
334
+ *
335
+ * @param response the transport response; its body is read from a clone,
336
+ * so the original stays readable
337
+ * @param codecOptions overrides the configured codec for this call
338
+ */
339
+ export function decodeResponse<T = unknown>(
340
+ response: Response,
341
+ codecOptions?: JSONCodecOptions
342
+ ): Promise<T | undefined>;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Renders a component tree synchronously to an HTML string. Async reads inside
3
+ * `<Loading>` boundaries emit their `fallback` content; for full-graph
4
+ * resolution use `renderToStringAsync` instead.
5
+ *
6
+ * Pair the returned HTML with `hydrate()` on the client.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { renderToString } from "@solidjs/web";
11
+ *
12
+ * const html = renderToString(() => <App />);
13
+ * res.send(`<!doctype html><html><body><div id="root">${html}</div></body></html>`);
14
+ * ```
15
+ */
1
16
  export declare function renderToString<T>(fn: () => T, options?: {
2
17
  nonce?: string;
3
18
  renderId?: string;
@@ -12,6 +27,21 @@ export declare function renderToString<T>(fn: () => T, options?: {
12
27
  }>;
13
28
  onError?: (err: any) => void;
14
29
  }): string;
30
+ /**
31
+ * Renders a component tree to an HTML string and awaits all async reads in the
32
+ * subtree before resolving. The returned HTML reflects the fully-settled state
33
+ * — no `<Loading>` fallbacks appear in the output.
34
+ *
35
+ * Use this when you want a complete page in one round-trip. For incremental
36
+ * streaming with progressive boundary resolution, use `renderToStream`.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * import { renderToStringAsync } from "@solidjs/web";
41
+ *
42
+ * const html = await renderToStringAsync(() => <App />);
43
+ * ```
44
+ */
15
45
  export declare function renderToStringAsync<T>(fn: () => T, options?: {
16
46
  timeoutMs?: number;
17
47
  nonce?: string;
@@ -27,6 +57,25 @@ export declare function renderToStringAsync<T>(fn: () => T, options?: {
27
57
  }>;
28
58
  onError?: (err: any) => void;
29
59
  }): Promise<string>;
60
+ /**
61
+ * Streams an HTML response, flushing the synchronous shell first and then
62
+ * progressively emitting async-resolved fragments as their `<Loading>`
63
+ * boundaries settle. Good for time-to-first-byte sensitive pages.
64
+ *
65
+ * Returns an object with `pipe`/`pipeTo` for piping to a Node `Writable` or
66
+ * a Web `WritableStream`, plus a `then` for awaiting full completion.
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * import { renderToStream } from "@solidjs/web";
71
+ *
72
+ * // Node:
73
+ * renderToStream(() => <App />).pipe(res);
74
+ *
75
+ * // Web (Workers / Deno):
76
+ * await renderToStream(() => <App />).pipeTo(stream.writable);
77
+ * ```
78
+ */
30
79
  export declare function renderToStream<T>(fn: () => T, options?: {
31
80
  nonce?: string;
32
81
  renderId?: string;
@@ -54,19 +103,59 @@ export declare function renderToStream<T>(fn: () => T, options?: {
54
103
  }) => void;
55
104
  pipeTo: (writable: WritableStream) => Promise<void>;
56
105
  };
106
+ /**
107
+ * Compiler primitive — emitted by JSX-DOM-Expressions for tagged-template
108
+ * SSR output. Not meant for hand-written code.
109
+ * @internal
110
+ */
57
111
  export declare function ssr(template: string[] | string, ...nodes: any[]): {
58
112
  t: string;
59
113
  };
114
+ /**
115
+ * Compiler primitive — emitted by JSX-DOM-Expressions for SSR element
116
+ * output. Not meant for hand-written code.
117
+ * @internal
118
+ */
60
119
  export declare function ssrElement(name: string, props: any, children: any, needsId: boolean): {
61
120
  t: string;
62
121
  };
122
+ /**
123
+ * Compiler primitive — serializes a classList object for SSR output. Not
124
+ * meant for hand-written code.
125
+ * @internal
126
+ */
63
127
  export declare function ssrClassList(value: {
64
128
  [k: string]: boolean;
65
129
  }): string;
130
+ /**
131
+ * Compiler primitive — serializes a style object for SSR output. Not meant
132
+ * for hand-written code.
133
+ * @internal
134
+ */
66
135
  export declare function ssrStyle(value: {
67
136
  [k: string]: string;
68
137
  }): string;
138
+ /**
139
+ * Compiler primitive — serializes a boolean attribute for SSR output. Not
140
+ * meant for hand-written code.
141
+ * @internal
142
+ */
69
143
  export declare function ssrAttribute(key: string, value: boolean): string;
144
+ /**
145
+ * Compiler primitive — generates the hydration-key attribute for SSR
146
+ * output. Not meant for hand-written code.
147
+ * @internal
148
+ */
70
149
  export declare function ssrHydrationKey(): string;
150
+ /**
151
+ * Compiler primitive — collapses an SSR-shaped node into its HTML string.
152
+ * Not meant for hand-written code.
153
+ * @internal
154
+ */
71
155
  export declare function resolveSSRNode(node: any): string;
156
+ /**
157
+ * Escapes a string for safe inclusion in HTML output. Used by the SSR
158
+ * runtime; not generally part of user code.
159
+ * @internal
160
+ */
72
161
  export declare function escape(html: string): string;