@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.33

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 (73) hide show
  1. package/README.md +1 -6
  2. package/dist/dev.cjs +285 -60
  3. package/dist/dev.js +267 -57
  4. package/dist/server.cjs +1148 -176
  5. package/dist/server.js +1133 -175
  6. package/dist/web.cjs +285 -60
  7. package/dist/web.js +267 -57
  8. package/frames/dist/client.cjs +397 -175
  9. package/frames/dist/client.dev.cjs +401 -175
  10. package/frames/dist/client.dev.js +399 -173
  11. package/frames/dist/client.js +395 -173
  12. package/frames/dist/server.cjs +1424 -277
  13. package/frames/dist/server.js +1426 -280
  14. package/package.json +69 -7
  15. package/serialization/decode/package.json +20 -0
  16. package/serialization/dist/decode.cjs +110 -0
  17. package/serialization/dist/decode.js +104 -0
  18. package/serialization/dist/serialization.cjs +106 -43
  19. package/serialization/dist/serialization.js +100 -44
  20. package/serialization/types/index.d.ts +85 -60
  21. package/serialization/types/serializer-decode.d.ts +182 -0
  22. package/serialization/types-cjs/index.d.cts +85 -60
  23. package/serialization/types-cjs/serializer-decode.d.cts +182 -0
  24. package/server-functions/dist/client.cjs +131 -98
  25. package/server-functions/dist/client.js +131 -99
  26. package/server-functions/dist/rich-args.cjs +11 -0
  27. package/server-functions/dist/rich-args.js +9 -0
  28. package/server-functions/dist/server.cjs +367 -194
  29. package/server-functions/dist/server.dev.cjs +1077 -0
  30. package/server-functions/dist/server.dev.js +1045 -0
  31. package/server-functions/dist/server.js +365 -195
  32. package/server-functions/package.json +10 -0
  33. package/server-functions/rich-args/package.json +20 -0
  34. package/storage/types/index.d.ts +1 -1
  35. package/storage/types-cjs/index.d.cts +1 -1
  36. package/types/client.d.ts +149 -6
  37. package/types/cookies.d.ts +93 -0
  38. package/types/core.d.ts +4 -2
  39. package/types/frames/client.d.ts +15 -1
  40. package/types/frames/frame-client.d.ts +63 -7
  41. package/types/frames/frame-sink.d.ts +26 -3
  42. package/types/frames/frame-transport.d.ts +40 -8
  43. package/types/frames/serializer.d.ts +85 -60
  44. package/types/frames/server.d.ts +22 -0
  45. package/types/index.d.ts +2 -3
  46. package/types/response.d.ts +45 -0
  47. package/types/serializer-decode.d.ts +182 -0
  48. package/types/serializer.d.ts +85 -60
  49. package/types/server-functions/client.d.ts +2 -1
  50. package/types/server-functions/rich-args.d.ts +10 -0
  51. package/types/server-functions/server.d.ts +99 -1
  52. package/types/server-functions/shared.d.ts +79 -1
  53. package/types/server-mock.d.ts +171 -59
  54. package/types/server.d.ts +209 -37
  55. package/types-cjs/client.d.cts +149 -6
  56. package/types-cjs/cookies.d.cts +93 -0
  57. package/types-cjs/core.d.cts +4 -2
  58. package/types-cjs/frames/client.d.cts +15 -1
  59. package/types-cjs/frames/frame-client.d.cts +63 -7
  60. package/types-cjs/frames/frame-sink.d.cts +26 -3
  61. package/types-cjs/frames/frame-transport.d.cts +40 -8
  62. package/types-cjs/frames/serializer.d.cts +85 -60
  63. package/types-cjs/frames/server.d.cts +22 -0
  64. package/types-cjs/index.d.cts +2 -3
  65. package/types-cjs/response.d.cts +45 -0
  66. package/types-cjs/serializer-decode.d.cts +182 -0
  67. package/types-cjs/serializer.d.cts +85 -60
  68. package/types-cjs/server-functions/client.d.cts +2 -1
  69. package/types-cjs/server-functions/rich-args.d.cts +10 -0
  70. package/types-cjs/server-functions/server.d.cts +99 -1
  71. package/types-cjs/server-functions/shared.d.cts +79 -1
  72. package/types-cjs/server-mock.d.cts +171 -59
  73. package/types-cjs/server.d.cts +209 -37
@@ -1,4 +1,4 @@
1
- import { JSONCodecOptions } from "../serializer.cjs";
1
+ import { JSONCodecOptions } from "../serializer-decode.cjs";
2
2
  import { ServerFunction, ServerFunctionMetadata } from "./shared.cjs";
3
3
 
4
4
  export {
@@ -21,6 +21,7 @@ export {
21
21
  getServerFunctionsCodec,
22
22
  hasFlashCookie,
23
23
  isServerFunction,
24
+ serializeString,
24
25
  subscribeFlightData,
25
26
  withMeta
26
27
  } from "./shared.cjs";
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { ResponseEnvelope } from "../response.cjs";
2
- import { JSONCodecOptions } from "../serializer.cjs";
2
+ import { JSONCodecOptions } from "../serializer-decode.cjs";
3
3
  import { RequestEvent } from "../server.cjs";
4
4
 
5
5
  export {
@@ -119,6 +119,33 @@ export type CollectFlightDataHook = (
119
119
  outcome: ServerFunctionOutcome
120
120
  ) => unknown | Promise<unknown>;
121
121
 
122
+ /**
123
+ * Wraps a server function execution — the per-invocation seam for
124
+ * framework policies (per-function middleware, auth, logging, error
125
+ * mapping). Called inside the call's event scope with the invocation
126
+ * identity already established: `getServerFunctionInvocation()` answers
127
+ * before, during and after `run()`. Must return (or resolve to) `run()`'s
128
+ * result — replacing it replaces the function's result; throwing routes
129
+ * through the handler's normal error encoding.
130
+ *
131
+ * The context carries the call's identity (`id`, parsed `args`), its
132
+ * `event`, and how it arrived: `direct` is `true` for in-process SSR calls
133
+ * (where `request` is absent) and `false` for HTTP dispatch. On the direct
134
+ * path the wrapper must stay transparent for synchronous functions —
135
+ * return `run()`'s value, not an unconditional promise, unless it needs to
136
+ * be async.
137
+ */
138
+ export type WrapInvocationHook = (
139
+ run: () => unknown,
140
+ context: {
141
+ id: string;
142
+ args: unknown[];
143
+ event: ServerFunctionEvent;
144
+ request?: Request;
145
+ direct: boolean;
146
+ }
147
+ ) => unknown;
148
+
122
149
  /**
123
150
  * Request headers with `setCookies` folded into the `Cookie` header, as the
124
151
  * browser would have applied them before its next request. Later entries
@@ -180,6 +207,14 @@ export interface ServerFunctionsServerConfig {
180
207
  * an established request scope parks on the global.
181
208
  */
182
209
  provideEvent?: <T>(event: ServerFunctionEvent, fn: () => T) => T;
210
+ /**
211
+ * Wraps every server function execution — HTTP dispatch and direct SSR
212
+ * calls alike — with the invocation identity already established (see
213
+ * `WrapInvocationHook`). The per-invocation seam for framework policies:
214
+ * per-function middleware, auth, logging, error mapping. A per-request
215
+ * option overrides it for HTTP dispatch.
216
+ */
217
+ wrapInvocation?: WrapInvocationHook;
183
218
  /**
184
219
  * The single-flight hook: produces the data payload folded into
185
220
  * responses of calls that opted in (see `CollectFlightDataHook`).
@@ -402,6 +437,13 @@ export interface HandleServerFunctionOptions {
402
437
  * contract as the `provideEvent` config option.
403
438
  */
404
439
  provideEvent?<T>(event: ServerFunctionEvent, fn: () => T): T;
440
+ /**
441
+ * Overrides the configured per-invocation wrap for this handler — same
442
+ * contract as the `wrapInvocation` config option (see
443
+ * `WrapInvocationHook`), except it only applies to HTTP dispatch (a
444
+ * per-request option can't see direct SSR calls).
445
+ */
446
+ wrapInvocation?: WrapInvocationHook;
405
447
  /**
406
448
  * Observes or replaces the function's result before encoding — the
407
449
  * extension point for response metadata policies (headers, statuses,
@@ -473,6 +515,41 @@ export interface HandleServerFunctionOptions {
473
515
  * (default `/_server`); platform adapters (h3, express, ...) convert their
474
516
  * request shape to a web `Request` around it.
475
517
  *
518
+ * When the event carries a `response` head stub (`event.response`, see the
519
+ * server entry's `ResponseStub`), the handler folds it onto every outgoing
520
+ * response as the head freezes — its `Set-Cookie` values (cookies appended
521
+ * during the call) append cookie-by-cookie alongside the result's own,
522
+ * other stub headers fill gaps (the call's response metadata wins; the
523
+ * protocol-owned family — the error/format/single-flight tags, `Location`,
524
+ * `X-Revalidate` — never fills, and neither does `Content-Type`/`Content-
525
+ * Length` onto a bodiless response) — and marks the stub `committed`, so
526
+ * later cookie/header writes report instead of silently missing the wire.
527
+ *
528
+ * ## Thrown-error sanitization (security default)
529
+ *
530
+ * A thrown `Response`/envelope (`redirect`/`reload`/`respond`) is intentional
531
+ * control flow and is forwarded untouched. A *plain* thrown value (a bare
532
+ * `Error`, string, or object) is different: serialized verbatim it would ship
533
+ * its `message` and every own-property to the client — a driver/ORM error's
534
+ * failing query, connection string, or bound parameters included. So outside
535
+ * the dev build a plain thrown value is replaced with a generic `Error`
536
+ * before serialization; the client still receives *an* `Error` (the shape
537
+ * `submission.error` etc. expect), just with no leaked content. The dev
538
+ * build keeps full fidelity (message, stack, own-props) for DX and the dev
539
+ * toolbar inspector. Dev/prod is the BUILD VARIANT, not `NODE_ENV`:
540
+ * `@solidjs/web` publishes a dev copy of this entry behind the
541
+ * `development` export condition (what Vite dev resolves) and the default
542
+ * resolution sanitizes — as does importing the runtime source directly with
543
+ * no bundler signal (fail-safe).
544
+ *
545
+ * Escape hatch: brand the value with `markSafeError` (`Symbol.for(
546
+ * "solid.SafeError")`) to send its content intact in every environment.
547
+ * A `wrapInvocation`/`transformResult` override that maps errors expresses
548
+ * intent the same way — throw a `Response`/envelope, or brand the mapped
549
+ * error safe; an unbranded plain error it lets propagate is sanitized like
550
+ * any other, so a framework onError policy must brand its result to keep a
551
+ * custom client-facing message in production.
552
+ *
476
553
  * @example
477
554
  * ```ts
478
555
  * import { handleServerFunctionRequest } from "@solidjs/web/server-functions";
@@ -488,3 +565,24 @@ export function handleServerFunctionRequest(
488
565
  request: Request,
489
566
  options?: HandleServerFunctionOptions
490
567
  ): Promise<Response>;
568
+
569
+ /** Message a sanitized (production) server error carries on the wire. */
570
+ export const GENERIC_SERVER_ERROR_MESSAGE: string;
571
+
572
+ /**
573
+ * The production error-sanitization policy `handleServerFunctionRequest`
574
+ * applies to a plain thrown value before serialization. Returns `value`
575
+ * unchanged in the dev build or when it is branded safe (`markSafeError`);
576
+ * otherwise returns a generic `Error` carrying `GENERIC_SERVER_ERROR_MESSAGE`.
577
+ * Exposed for frameworks composing their own dispatch around the same policy.
578
+ */
579
+ export function sanitizeServerError(value: unknown): unknown;
580
+
581
+ /**
582
+ * Overrides the build-variant dev flag for this module instance — the seam
583
+ * for test harnesses and hand-rolled bundles whose packaging cannot replace
584
+ * `_DX_DEV_`. Applications never call this; select the dev build through
585
+ * the `development` export condition instead.
586
+ * @internal
587
+ */
588
+ export function setServerFunctionsDev(dev: boolean): void;
@@ -1,4 +1,4 @@
1
- import { JSONCodecOptions } from "../serializer.cjs";
1
+ import { JSONCodecOptions } from "../serializer-decode.cjs";
2
2
 
3
3
  export type { JSONCodecOptions };
4
4
 
@@ -18,6 +18,9 @@ export function configureServerFunctionsCodec(codec: JSONCodecOptions | undefine
18
18
  * `configureServerFunctionsCodec` or the client/server `codec` option), or
19
19
  * undefined when running on the defaults. Integrations pass this to
20
20
  * lower-level codec helpers so custom plugins configured by the app apply.
21
+ *
22
+ * Integration plumbing; not meant for hand-written application code.
23
+ * @internal
21
24
  */
22
25
  export function getServerFunctionsCodec(): JSONCodecOptions | undefined;
23
26
 
@@ -57,6 +60,9 @@ export const ERROR_HEADER: string;
57
60
  * travels percent-encoded behind a marker. `decodeErrorHeaderValue`
58
61
  * round-trips the message exactly, astral-plane characters included (lone
59
62
  * surrogates are replaced with U+FFFD — they cannot survive UTF-8 anyway).
63
+ *
64
+ * Transport wire detail; not meant for hand-written code.
65
+ * @internal
60
66
  */
61
67
  export function encodeErrorHeaderValue(value: string): string;
62
68
 
@@ -64,6 +70,10 @@ export function encodeErrorHeaderValue(value: string): string;
64
70
  * Decodes an `ERROR_HEADER` value produced by `encodeErrorHeaderValue`:
65
71
  * marked values are percent-decoded, everything else (including values from
66
72
  * peers that never encode) passes through untouched.
73
+ *
74
+ * Integration plumbing for readers of `ERROR_HEADER`; not meant for
75
+ * hand-written application code.
76
+ * @internal
67
77
  */
68
78
  export function decodeErrorHeaderValue(value: string): string;
69
79
 
@@ -273,6 +283,46 @@ export function withMeta<F extends (...args: any[]) => any>(fn: F, meta: ServerF
273
283
  */
274
284
  export const SERVER_FUNCTION_METADATA: unique symbol;
275
285
 
286
+ /**
287
+ * The transport surface integrations consume through the late-bound RPC
288
+ * seam (server-functions/registry.js) — filled by the transport halves when
289
+ * the first server function reference is created (code that only exists in
290
+ * a bundle when a `"use server"` function was actually compiled in), read
291
+ * by routers so they never import the transport/codec statically.
292
+ */
293
+ export interface ServerFunctionRPC {
294
+ /**
295
+ * The build's `GET` declaration wrapper (client fetch transport or
296
+ * server in-process dispatch — see the respective entries).
297
+ */
298
+ GET<A extends readonly any[], R>(fn: (...args: A) => R): ServerFunction<A, Awaited<R>>;
299
+ /**
300
+ * `decodeResponse` bound to the configured codec: decodes a server
301
+ * function response body the transport handed over whole (redirects,
302
+ * revalidation). Resolves undefined for empty bodies and bodies without
303
+ * a recognized encoding (e.g. a raw user Response).
304
+ */
305
+ decodeResponse<T = unknown>(response: Response): Promise<T | undefined>;
306
+ }
307
+
308
+ /**
309
+ * Fills the RPC seam. Called by the transport halves when the first server
310
+ * function reference is created; first write wins.
311
+ * @internal
312
+ */
313
+ export function provideServerFunctionRPC(rpc: ServerFunctionRPC): void;
314
+
315
+ /**
316
+ * The registered RPC surface, or undefined when no server function exists
317
+ * in this build's graph. Integration plumbing (routers): gate every use of
318
+ * the transport/codec behind this read instead of importing it — an app
319
+ * with no server functions then ships none of it, while a reference in the
320
+ * bundle guarantees the seam is filled before integration code can hold
321
+ * that reference (compiled output creates references at module scope).
322
+ * @internal
323
+ */
324
+ export function getServerFunctionRPC(): ServerFunctionRPC | undefined;
325
+
276
326
  /**
277
327
  * Header carrying the body format tag (a `BodyFormat` value) —
278
328
  * `"X-Server-Function-Format"`.
@@ -306,6 +356,11 @@ export const BodyFormat: {
306
356
  readonly File: "5";
307
357
  readonly ArrayBuffer: "6";
308
358
  readonly Uint8Array: "7";
359
+ /**
360
+ * Plain `JSON.stringify` — the fast path for JSON-safe payloads on both
361
+ * legs: argument lists on the request, results on the response.
362
+ */
363
+ readonly Json: "8";
309
364
  };
310
365
 
311
366
  /**
@@ -314,6 +369,17 @@ export const BodyFormat: {
314
369
  */
315
370
  export type BodyFormatValue = (typeof BodyFormat)[keyof typeof BodyFormat];
316
371
 
372
+ /**
373
+ * Whether a value survives a `JSON.stringify` round trip faithfully: JSON
374
+ * primitives (finite numbers only), arrays, and plain objects. Anything
375
+ * else — Dates, Maps, typed arrays, undefined (bare or as a property),
376
+ * NaN, class instances, cyclic structures — needs the codec. Never throws:
377
+ * cycles and pathological depth answer `false`. Both peers negotiate the
378
+ * wire format with this guard: the client for argument lists, the server
379
+ * for results.
380
+ */
381
+ export function isJSONSafe(value: unknown): boolean;
382
+
317
383
  /**
318
384
  * Picks a direct HTTP encoding (headers + BodyInit) for values that have
319
385
  * one — strings, FormData, URLSearchParams, File, Blob, ArrayBuffer,
@@ -412,6 +478,9 @@ export function decodeResponse<T = unknown>(
412
478
  * undefined for body-less responses) rides as `{ value }`. Integrations
413
479
  * that apply response metadata themselves use this so the payload shape
414
480
  * stays core's own.
481
+ *
482
+ * Integration plumbing; not meant for hand-written application code.
483
+ * @internal
415
484
  */
416
485
  export function decodeResponsePayload<T = unknown, D = unknown>(
417
486
  response: Response,
@@ -422,6 +491,9 @@ export function decodeResponsePayload<T = unknown, D = unknown>(
422
491
  * Frame one payload for the server-function wire: a `;0x<len32>;` length
423
492
  * prefix followed by the utf-8 data. Both transports (server-function
424
493
  * responses and frame streams) share this framing.
494
+ *
495
+ * Transport wire detail; not meant for hand-written code.
496
+ * @internal
425
497
  */
426
498
  export function createChunk(data: string): Uint8Array;
427
499
 
@@ -429,6 +501,9 @@ export function createChunk(data: string): Uint8Array;
429
501
  * Incremental decoder for `createChunk` framing over a byte stream: `next()`
430
502
  * yields one complete payload string per call (async-iterator result shape),
431
503
  * buffering partial frames internally until their length prefix is satisfied.
504
+ *
505
+ * Transport wire detail; not meant for hand-written code.
506
+ * @internal
432
507
  */
433
508
  export class ChunkReader {
434
509
  constructor(stream: ReadableStream<Uint8Array>);
@@ -441,5 +516,8 @@ export class ChunkReader {
441
516
  * Both peers derive it independently — the server names flight regions with
442
517
  * it, the client routes them by it — so it must stay deterministic across
443
518
  * realms and releases.
519
+ *
520
+ * Transport wire detail; not meant for hand-written code.
521
+ * @internal
444
522
  */
445
523
  export function frameAddress(id: string, args?: readonly unknown[]): string;
@@ -1,7 +1,48 @@
1
+ import type { RequestEvent, RequestEventLocals, ResponseStub } from "./client.cjs";
2
+ /** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
3
+ export type AssetManifest = Record<string, {
4
+ file: string;
5
+ css?: string[];
6
+ isEntry?: boolean;
7
+ imports?: string[];
8
+ }> & {
9
+ _base?: string;
10
+ };
11
+ /** Inline style content, e.g. dev CSS collected from a bundler's module graph. */
12
+ export type InlineStyleAsset = {
13
+ id: string;
14
+ content: string;
15
+ attrs?: Record<string, string>;
16
+ };
17
+ export type ResolvedAssets = {
18
+ js: string[];
19
+ css: (string | InlineStyleAsset)[];
20
+ };
21
+ /**
22
+ * Resolver form of the manifest option — the primitive a dev server
23
+ * implements against its live module graph (a static manifest object is
24
+ * normalized into a sync resolver internally). `resolve` may return a
25
+ * promise (async resolvers require streaming rendering); CSS entries may be
26
+ * URL strings (emitted as load-gated `<link>` tags) or inline-style
27
+ * descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
28
+ * is accepted as shorthand for `{ resolve }`.
29
+ */
30
+ export type AssetResolver = {
31
+ resolve(key: string): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
32
+ /**
33
+ * Synchronous fast path answering with whatever is knowable without async
34
+ * work (typically js URLs, omitting css). Sync consumers — e.g. a lazy
35
+ * component's `moduleUrl` getter used by islands — use this when `resolve`
36
+ * would return a promise, so adapters should provide it whenever possible.
37
+ */
38
+ resolveSync?(key: string): ResolvedAssets | null | undefined;
39
+ };
40
+ /** Bare-function shorthand for `AssetResolver` (no sync fast path). */
41
+ export type AssetResolverFn = (key: string) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
1
42
  /**
2
43
  * Renders a component tree synchronously to an HTML string. Async reads inside
3
44
  * `<Loading>` boundaries emit their `fallback` content; for full-graph
4
- * resolution use `renderToStringAsync` instead.
45
+ * resolution await `renderToStream` instead.
5
46
  *
6
47
  * Pair the returned HTML with `hydrate()` on the client.
7
48
  *
@@ -18,45 +59,20 @@ export declare function renderToString<T>(fn: () => T, options?: {
18
59
  renderId?: string;
19
60
  noScripts?: boolean;
20
61
  plugins?: any[];
21
- manifest?: Record<string, {
22
- file: string;
23
- css?: string[];
24
- isEntry?: boolean;
25
- isDynamicEntry?: boolean;
26
- imports?: string[];
27
- }>;
62
+ manifest?: AssetManifest | AssetResolver | AssetResolverFn;
28
63
  onError?: (err: any) => void;
64
+ /**
65
+ * Embedded-render contract for hosts that own the document. When the
66
+ * render output contains no `</head>`, everything head-bound (resolved
67
+ * `useHead` winners, eager resources, tracked asset links, inline
68
+ * styles) is delivered here as one HTML string — prelude (charset/base)
69
+ * first — for the host to splice into its own `<head>` template, instead
70
+ * of being dropped. Called synchronously before `renderToString`
71
+ * returns; not called when the output has a `</head>` (splicing is
72
+ * automatic then).
73
+ */
74
+ onHead?: (head: string) => void;
29
75
  }): 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
- */
45
- export declare function renderToStringAsync<T>(fn: () => T, options?: {
46
- timeoutMs?: number;
47
- nonce?: string;
48
- renderId?: string;
49
- noScripts?: boolean;
50
- plugins?: any[];
51
- manifest?: Record<string, {
52
- file: string;
53
- css?: string[];
54
- isEntry?: boolean;
55
- isDynamicEntry?: boolean;
56
- imports?: string[];
57
- }>;
58
- onError?: (err: any) => void;
59
- }): Promise<string>;
60
76
  /**
61
77
  * Streams an HTML response, flushing the synchronous shell first and then
62
78
  * progressively emitting async-resolved fragments as their `<Loading>`
@@ -64,9 +80,10 @@ export declare function renderToStringAsync<T>(fn: () => T, options?: {
64
80
  *
65
81
  * Returns an object with `pipe`/`pipeTo` for piping to a Node `Writable` or
66
82
  * a Web `WritableStream`, a lazy `readable` byte-stream view for
67
- * `new Response(stream.readable)`, plus a `then` for awaiting full
68
- * completion. `pipe`, `pipeTo`, and `readable` each consume the render
69
- * use exactly one of the three.
83
+ * `new Response(stream.readable)`, plus a thenable for awaiting full
84
+ * completion `await renderToStream(...)` resolves with the settled HTML
85
+ * (the fully-resolved-string form of the render). `pipe`, `pipeTo`, and
86
+ * `readable` each consume the render — use exactly one of the three.
70
87
  *
71
88
  * @example
72
89
  * ```tsx
@@ -77,6 +94,9 @@ export declare function renderToStringAsync<T>(fn: () => T, options?: {
77
94
  *
78
95
  * // Web (Workers / Deno):
79
96
  * return new Response(renderToStream(() => <App />).readable);
97
+ *
98
+ * // Fully settled string:
99
+ * const html = await renderToStream(() => <App />);
80
100
  * ```
81
101
  */
82
102
  export declare function renderToStream<T>(fn: () => T, options?: {
@@ -84,13 +104,7 @@ export declare function renderToStream<T>(fn: () => T, options?: {
84
104
  renderId?: string;
85
105
  noScripts?: boolean;
86
106
  plugins?: any[];
87
- manifest?: Record<string, {
88
- file: string;
89
- css?: string[];
90
- isEntry?: boolean;
91
- isDynamicEntry?: boolean;
92
- imports?: string[];
93
- }>;
107
+ manifest?: AssetManifest | AssetResolver | AssetResolverFn;
94
108
  onCompleteShell?: (info: {
95
109
  write: (v: string) => void;
96
110
  }) => void;
@@ -98,8 +112,25 @@ export declare function renderToStream<T>(fn: () => T, options?: {
98
112
  write: (v: string) => void;
99
113
  }) => void;
100
114
  onError?: (err: any) => void;
115
+ /**
116
+ * Embedded-render contract for hosts that own the document. When the
117
+ * shell contains no `</head>`, everything head-bound at first flush
118
+ * (resolved `useHead` winners, eager resources, tracked asset links,
119
+ * inline styles) is delivered here as one HTML string — prelude first —
120
+ * before the shell chunk is emitted, so the host can write its own
121
+ * `<head>` ahead of piping the stream. Post-shell head updates flow
122
+ * through the stream itself and apply in the browser. Not called when
123
+ * the shell has a `</head>` (splicing is automatic then).
124
+ */
125
+ onHead?: (head: string) => void;
101
126
  }): {
102
- then: (fn: (html: string) => void) => void;
127
+ /**
128
+ * Awaiting the stream resolves with the complete HTML once every boundary
129
+ * settles — the fully-settled-string form of the render. Render errors
130
+ * route through `onError` and the promise resolves with whatever HTML the
131
+ * render produced; it never rejects.
132
+ */
133
+ then<TResult1 = string, TResult2 = never>(onfulfilled?: ((html: string) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
103
134
  pipe: (writable: {
104
135
  write: (v: string) => void;
105
136
  end: () => void;
@@ -107,6 +138,75 @@ export declare function renderToStream<T>(fn: () => T, options?: {
107
138
  pipeTo: (writable: WritableStream) => Promise<void>;
108
139
  readonly readable: ReadableStream<Uint8Array>;
109
140
  };
141
+ /**
142
+ * Fetch-style middleware: receives the `Request` and a `next` continuation
143
+ * (pass a `Request` to substitute it downstream) and returns the `Response`.
144
+ * Composed with `composeMiddleware`; runs inside the request-event scope, so
145
+ * `getRequestEvent()` works exactly as in application code.
146
+ */
147
+ export type FetchMiddleware = (request: Request, next: (request?: Request) => Promise<Response>) => Response | Promise<Response>;
148
+ /**
149
+ * Creates a fresh, uncommitted {@link ResponseStub}. Server-only.
150
+ */
151
+ export declare function createResponseStub(): ResponseStub;
152
+ /**
153
+ * Builds the canonical request event — a web-standard `Request`, a `locals`
154
+ * bag, and a stub-backed `response` head — for `provideRequestEvent`.
155
+ * Server-only: on the client the request event belongs to the server that
156
+ * rendered the page.
157
+ */
158
+ export declare function createRequestEvent<T extends object = {}>(request: Request, init?: T): {
159
+ request: Request;
160
+ locals: RequestEventLocals;
161
+ response: ResponseStub;
162
+ } & T;
163
+ /**
164
+ * The HTTP status a redirect should use: the stub's own status when it is a
165
+ * redirect status (301/302/303/307/308), 302 otherwise. Server-only.
166
+ */
167
+ export declare function getExpectedRedirectStatus(response: ResponseStub): number;
168
+ /**
169
+ * Derives the outgoing `Response` for an SSR render result, running the
170
+ * response-head lifecycle against `event.response`: the stub commits at
171
+ * shell flush, a pre-flush `Location` becomes a real redirect
172
+ * (`getExpectedRedirectStatus`), and a post-flush one appends the
173
+ * nonce-aware `<script>window.location=...</script>` fallback. String
174
+ * results return a `Response` synchronously; stream results resolve at
175
+ * shell flush. Server-only.
176
+ */
177
+ export declare function createSSRResponse(result: string, event: RequestEvent | undefined, options?: {
178
+ responseInit?: ResponseInit;
179
+ nonce?: string;
180
+ transformChunk?: (chunk: string) => string;
181
+ }): Response;
182
+ export declare function createSSRResponse(result: {
183
+ pipe(writable: {
184
+ write: (v: string) => void;
185
+ end: () => void;
186
+ }): void;
187
+ }, event: RequestEvent | undefined, options?: {
188
+ responseInit?: ResponseInit;
189
+ nonce?: string;
190
+ transformChunk?: (chunk: string) => string;
191
+ }): Promise<Response>;
192
+ /**
193
+ * Handler-lifecycle plumbing — the exit for a `Response` that did not go
194
+ * through `createSSRResponse` (a middleware early return, an API result):
195
+ * folds the request event's response stub onto it (cookies append
196
+ * entry-by-entry, other headers gap-fill, status never) and commits the
197
+ * stub. Already-committed stubs pass the response through untouched, so
198
+ * handlers apply it unconditionally after their middleware chain unwinds.
199
+ * `event` defaults to the ambient `getRequestEvent()`. Application
200
+ * middleware never calls this. Server-only.
201
+ */
202
+ export declare function commitEventResponse(response: Response, event?: RequestEvent): Response;
203
+ /**
204
+ * Composes fetch-style middleware — `(request, next) => Response` — into a
205
+ * single function of the same shape. Nothing reaches the wire until the
206
+ * outermost middleware returns, so headers on the returned `Response` stay
207
+ * mutable through the whole unwind, streamed bodies included. Server-only.
208
+ */
209
+ export declare function composeMiddleware(middlewares: FetchMiddleware[]): (request: Request, next: (request?: Request) => Response | Promise<Response>) => Promise<Response>;
110
210
  /**
111
211
  * Compiler primitive — emitted by JSX-DOM-Expressions for tagged-template
112
212
  * SSR output. Not meant for hand-written code.
@@ -124,27 +224,39 @@ export declare function ssrElement(name: string, props: any, children: any, need
124
224
  t: string;
125
225
  };
126
226
  /**
127
- * Compiler primitive — serializes a classList object for SSR output. Not
128
- * meant for hand-written code.
227
+ * Compiler primitive — serializes a class value (string, object map, or
228
+ * array) for SSR output. Not meant for hand-written code.
129
229
  * @internal
130
230
  */
131
- export declare function ssrClassList(value: {
231
+ export declare function ssrClassName(value: string | {
132
232
  [k: string]: boolean;
133
- }): string;
233
+ } | Array<any>): string;
134
234
  /**
135
- * Compiler primitive — serializes a style object for SSR output. Not meant
235
+ * Compiler primitive — serializes a style value for SSR output. Not meant
136
236
  * for hand-written code.
137
237
  * @internal
138
238
  */
139
- export declare function ssrStyle(value: {
239
+ export declare function ssrStyle(value: string | {
140
240
  [k: string]: string;
141
241
  }): string;
142
242
  /**
143
- * Compiler primitive — serializes a boolean attribute for SSR output. Not
243
+ * Compiler primitive — serializes one style property for SSR output. Not
244
+ * meant for hand-written code.
245
+ * @internal
246
+ */
247
+ export declare function ssrStyleProperty(name: string, value: any): string;
248
+ /**
249
+ * Compiler primitive — serializes an attribute for SSR output. Not meant
250
+ * for hand-written code.
251
+ * @internal
252
+ */
253
+ export declare function ssrAttribute(key: string, value: any): string;
254
+ /**
255
+ * Compiler primitive — wraps a template-group closure for SSR output. Not
144
256
  * meant for hand-written code.
145
257
  * @internal
146
258
  */
147
- export declare function ssrAttribute(key: string, value: boolean): string;
259
+ export declare function ssrGroup<T extends () => any[]>(fn: T, n: number): T;
148
260
  /**
149
261
  * Compiler primitive — generates the hydration-key attribute for SSR
150
262
  * output. Not meant for hand-written code.
@@ -156,10 +268,10 @@ export declare function ssrHydrationKey(): string;
156
268
  * Not meant for hand-written code.
157
269
  * @internal
158
270
  */
159
- export declare function resolveSSRNode(node: any): string;
271
+ export declare function resolveSSRNode(node: any, result?: any, top?: boolean): any;
160
272
  /**
161
273
  * Escapes a string for safe inclusion in HTML output. Used by the SSR
162
274
  * runtime; not generally part of user code.
163
275
  * @internal
164
276
  */
165
- export declare function escape(html: string): string;
277
+ export declare function escape(s: any, attr?: boolean): any;