@solidjs/web 2.0.0-beta.22 → 2.0.0-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev.cjs +25 -1
- package/dist/dev.js +25 -2
- package/dist/server.cjs +79 -33
- package/dist/server.js +79 -34
- package/dist/web.cjs +25 -1
- package/dist/web.js +25 -2
- package/frames/dist/client.cjs +1442 -0
- package/frames/dist/client.js +1430 -0
- package/frames/dist/server.cjs +1705 -0
- package/frames/dist/server.js +1694 -0
- package/frames/package.json +30 -0
- package/package.json +78 -5
- package/serialization/dist/serialization.cjs +83 -0
- package/serialization/dist/serialization.js +82 -1
- package/serialization/types/index.d.ts +12 -0
- package/serialization/types-cjs/index.d.cts +12 -0
- package/server-functions/dist/client.cjs +82 -55
- package/server-functions/dist/client.js +83 -56
- package/server-functions/dist/server.cjs +20 -3
- package/server-functions/dist/server.js +20 -3
- package/types/client.d.ts +8 -0
- package/types/core.d.ts +2 -1
- package/types/frames/client.d.ts +53 -0
- package/types/frames/frame-client.d.ts +205 -0
- package/types/frames/frame-sink.d.ts +145 -0
- package/types/frames/frame-transport.d.ts +105 -0
- package/types/frames/serializer.d.ts +151 -0
- package/types/frames/server.d.ts +21 -0
- package/types/serializer.d.ts +12 -0
- package/types/server-functions/client.d.ts +24 -0
- package/types/server.d.ts +2 -0
- package/types-cjs/client.d.cts +8 -0
- package/types-cjs/core.d.cts +2 -1
- package/types-cjs/frames/client.d.cts +53 -0
- package/types-cjs/frames/frame-client.d.cts +205 -0
- package/types-cjs/frames/frame-sink.d.cts +145 -0
- package/types-cjs/frames/frame-transport.d.cts +105 -0
- package/types-cjs/frames/serializer.d.cts +151 -0
- package/types-cjs/frames/server.d.cts +21 -0
- package/types-cjs/serializer.d.cts +12 -0
- package/types-cjs/server-functions/client.d.cts +24 -0
- package/types-cjs/server.d.cts +2 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client frame runtime — the consumer side of a frame stream. A frame
|
|
3
|
+
* renders server-owned content into a DOM boundary from a resident keyed
|
|
4
|
+
* record store: chunks are writes, not events, so application is
|
|
5
|
+
* prerequisite-driven and order-independent. Client-owned slot ranges
|
|
6
|
+
* inside the boundary are preserved across server updates — the
|
|
7
|
+
* version is a stale-guard only ("policy A"): newer content morphs in
|
|
8
|
+
* place, and teardown is `dispose()`, never a version bump.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** One transport chunk of a frame stream, addressed by frame `id`. */
|
|
12
|
+
export type FrameChunk =
|
|
13
|
+
| { type: "start"; id: string; version: number }
|
|
14
|
+
| { type: "html"; id: string; version: number; html: string }
|
|
15
|
+
| { type: "fragment"; id: string; version: number; key: string; html: string }
|
|
16
|
+
| {
|
|
17
|
+
type: "reveal";
|
|
18
|
+
id: string;
|
|
19
|
+
version: number;
|
|
20
|
+
keys: string[];
|
|
21
|
+
waitForStyles?: boolean;
|
|
22
|
+
fallback?: boolean;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
type: "data";
|
|
26
|
+
id: string;
|
|
27
|
+
version: number;
|
|
28
|
+
key?: string;
|
|
29
|
+
node?: unknown;
|
|
30
|
+
initial?: boolean;
|
|
31
|
+
/** Eval-style hydration script — only when produced with the hydration serializer. */
|
|
32
|
+
payload?: string;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
type: "assets";
|
|
36
|
+
id: string;
|
|
37
|
+
version: number;
|
|
38
|
+
key: string;
|
|
39
|
+
modules?: string[];
|
|
40
|
+
styles?: string[];
|
|
41
|
+
inlineStyles?: { id: string; content?: string; attrs?: Record<string, string> }[];
|
|
42
|
+
}
|
|
43
|
+
| { type: "slot"; id: string; version: number; key: string; args: Record<string, unknown> }
|
|
44
|
+
| { type: "template"; id: string; version: number; key: string; html: string; fields: string[] }
|
|
45
|
+
| {
|
|
46
|
+
type: "block";
|
|
47
|
+
id: string;
|
|
48
|
+
version: number;
|
|
49
|
+
key: string;
|
|
50
|
+
template: string;
|
|
51
|
+
values: unknown[];
|
|
52
|
+
}
|
|
53
|
+
| { type: "complete"; id: string; version: number }
|
|
54
|
+
| { type: "error"; id: string; version: number; key?: string; error: unknown };
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Maps a wire chunk onto resident-store record writes. `data` chunks map to
|
|
58
|
+
* no records — they are response-scoped and the host applies them through
|
|
59
|
+
* its data hook.
|
|
60
|
+
*/
|
|
61
|
+
export function chunkToRecords(chunk: FrameChunk): Record<string, unknown>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One store write applied to a frame: `r` maps record keys to values
|
|
65
|
+
* (`chunkToRecords` produces these from wire chunks) and `version` is the
|
|
66
|
+
* stream stamp — an older version than the frame's current one is ignored.
|
|
67
|
+
*/
|
|
68
|
+
export interface FrameWrite {
|
|
69
|
+
version: number;
|
|
70
|
+
r: Record<string, unknown>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Context passed to a slot callback. */
|
|
74
|
+
export interface SlotContext {
|
|
75
|
+
/**
|
|
76
|
+
* Register cleanup for when this occurrence's range is removed from the
|
|
77
|
+
* server content, or the owning frame is disposed.
|
|
78
|
+
*/
|
|
79
|
+
onCleanup(fn: () => void): void;
|
|
80
|
+
/**
|
|
81
|
+
* The range's current interior — server-rendered client content on an
|
|
82
|
+
* adopted document-SSR boot, or the previous output on a re-call. A
|
|
83
|
+
* framework binding hydrates onto it and returns `undefined` to claim it
|
|
84
|
+
* in place (zero DOM mutation).
|
|
85
|
+
*/
|
|
86
|
+
existing: ChildNode[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Client content for a server-declared slot. Direct-insert occurrences
|
|
91
|
+
* call it with empty props; render-prop occurrences pass the occurrence's
|
|
92
|
+
* resolved args (primitives literal, `{$ref}` data resolved through the
|
|
93
|
+
* host, `{$frame}` regions as marker-range fragments). Return nodes to fill
|
|
94
|
+
* the range, or `undefined` to claim `ctx.existing` untouched.
|
|
95
|
+
*/
|
|
96
|
+
export type Slot = (props: Record<string, unknown>, ctx: SlotContext) => Node | Node[] | undefined;
|
|
97
|
+
|
|
98
|
+
export interface Frame {
|
|
99
|
+
/** Merge a write into the store and flush (morph/reveal/slot sync). */
|
|
100
|
+
apply(write: FrameWrite): void;
|
|
101
|
+
/** The active version, or undefined before the first apply. */
|
|
102
|
+
readonly version: number | undefined;
|
|
103
|
+
/** Read-only view of the resident record store. */
|
|
104
|
+
readonly store: Readonly<Record<string, unknown>>;
|
|
105
|
+
/** The stream's error record, if an `error` chunk arrived. */
|
|
106
|
+
readonly error: unknown;
|
|
107
|
+
/** Whether the named fragment has been revealed into the boundary. */
|
|
108
|
+
isRevealed(segment: string): boolean;
|
|
109
|
+
/** Tear down: slot cleanups cascade, later chunks are ignored. Idempotent. */
|
|
110
|
+
dispose(): void;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Routes a flat stream of addressed chunks to frames by id, buffering chunks
|
|
115
|
+
* for frames that have not registered yet (only the newest version's chunks
|
|
116
|
+
* are kept). `data` chunks are response-scoped and go to `applyData`.
|
|
117
|
+
*
|
|
118
|
+
* An id may have several frames (the same server component mounted more
|
|
119
|
+
* than once): chunks fan out to all of them, and a frame registering after
|
|
120
|
+
* delivery is seeded from a sibling's store.
|
|
121
|
+
*/
|
|
122
|
+
export interface FrameHost {
|
|
123
|
+
register(id: string, frame: Frame): void;
|
|
124
|
+
/** Remove one frame (or all frames of the id when `frame` is omitted). */
|
|
125
|
+
unregister(id: string, frame?: Frame): void;
|
|
126
|
+
apply(chunk: FrameChunk): void;
|
|
127
|
+
/** The first registered frame under the id, if any. */
|
|
128
|
+
get(id: string): Frame | undefined;
|
|
129
|
+
serialize(value: unknown): { $ref: string };
|
|
130
|
+
/** `frameId` is the resolving frame's id — route to its stream's table. */
|
|
131
|
+
resolve(ref: { $ref: string }, frameId?: string): unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The bubbling DOM event (`"frame:applied"`) a frame dispatches from its
|
|
136
|
+
* parent element whenever server content lands in the document — root
|
|
137
|
+
* materialize/morph, segment reveal, fallback materialization — with
|
|
138
|
+
* `detail: { id, version, reason }`. One document-level listener sees every
|
|
139
|
+
* boundary (nested region frames dispatch too); use it to re-apply
|
|
140
|
+
* client-owned decorations on server-owned markup (router affordance
|
|
141
|
+
* reflection, e.g. `aria-current`) without a MutationObserver.
|
|
142
|
+
*/
|
|
143
|
+
export const FRAME_APPLIED_EVENT: "frame:applied";
|
|
144
|
+
|
|
145
|
+
/** Options for `createFrameHost`. */
|
|
146
|
+
export interface FrameHostOptions {
|
|
147
|
+
/**
|
|
148
|
+
* Backs `{$ref}` slot args (typically a codec data table's `resolve`).
|
|
149
|
+
* `frameId` identifies the resolving frame — data tables are
|
|
150
|
+
* response-scoped, so multi-stream hosts route by it (nested region ids
|
|
151
|
+
* prefix-match their root).
|
|
152
|
+
*/
|
|
153
|
+
resolve?(ref: { $ref: string }, frameId?: string): unknown;
|
|
154
|
+
/** Test/host-side counterpart of `resolve`. */
|
|
155
|
+
serialize?(value: unknown): { $ref: string };
|
|
156
|
+
/**
|
|
157
|
+
* Receives each `data` chunk whole. Wire a codec table:
|
|
158
|
+
* `applyData: c => table.apply(c)` (see `createJSONDataTable`).
|
|
159
|
+
*/
|
|
160
|
+
applyData?(chunk: Extract<FrameChunk, { type: "data" }>): void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function createFrameHost(options?: FrameHostOptions): FrameHost;
|
|
164
|
+
|
|
165
|
+
/** Options for `createFrame` / `createFrameInsertable`. */
|
|
166
|
+
export interface FrameOptions {
|
|
167
|
+
/** Register with this host under `id`, receiving routed/buffered chunks. */
|
|
168
|
+
host?: FrameHost;
|
|
169
|
+
id?: string;
|
|
170
|
+
/** Client content keyed by prop name (occurrences resolve by prop). */
|
|
171
|
+
slots?: Record<string, Slot>;
|
|
172
|
+
/**
|
|
173
|
+
* Adopt existing server-rendered DOM: the first apply morphs against it,
|
|
174
|
+
* and slots sync immediately (hydration attach) — a document-SSR boot
|
|
175
|
+
* needs no chunk.
|
|
176
|
+
*/
|
|
177
|
+
adopt?: boolean;
|
|
178
|
+
/** Called after each apply flush (tests/telemetry). */
|
|
179
|
+
onApply?(info: { version: number; reason: "materialize" | "morph" | "reveal" }): void;
|
|
180
|
+
/**
|
|
181
|
+
* Wraps element-claim sweeps (`a[href]`/`form[action]` in materialized
|
|
182
|
+
* server content — and only those) so claim consumers register their
|
|
183
|
+
* per-element cleanup against the boundary's reactive owner, e.g.
|
|
184
|
+
* `fn => runWithOwner(owner, fn)`. Nested region frames inherit it.
|
|
185
|
+
* Without it, sweeps run under whatever owner is current (none, for
|
|
186
|
+
* streamed chunks).
|
|
187
|
+
*/
|
|
188
|
+
ownerScope?<T>(fn: () => T): T;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A frame rendering into an element boundary. */
|
|
192
|
+
export function createFrame(boundary: Element, options?: FrameOptions): Frame;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A branded frame-insertable value: the client runtime's `insert` recognizes
|
|
196
|
+
* it (registered `$$FRAME` symbol) and calls the mount handler the value
|
|
197
|
+
* carries — a comment range is established at the insertion point and a
|
|
198
|
+
* host-registered frame binds to it. One static mount per value; lifecycle
|
|
199
|
+
* belongs to the creator via `dispose()` (register it with your owner's
|
|
200
|
+
* cleanup).
|
|
201
|
+
*/
|
|
202
|
+
export function createFrameInsertable(options: FrameOptions): {
|
|
203
|
+
readonly frame: Frame | null;
|
|
204
|
+
dispose(): void;
|
|
205
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { FrameChunk } from "./frame-client.cjs";
|
|
2
|
+
|
|
3
|
+
/** Addresses a frame stream: the boundary id and this response's version. */
|
|
4
|
+
export interface FrameAddress {
|
|
5
|
+
id: string;
|
|
6
|
+
version: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The emission surface `renderToStream` routes through when producing a
|
|
11
|
+
* frame stream instead of a document (see the `sink` render option). Each
|
|
12
|
+
* method emits transport-agnostic chunks; `emit` is the envelope boundary.
|
|
13
|
+
* @internal Compiler/renderer wiring — use `renderToFrameStream` or
|
|
14
|
+
* `renderServerComponent` instead.
|
|
15
|
+
*/
|
|
16
|
+
export function createFrameSink(
|
|
17
|
+
emit: (chunk: FrameChunk) => void,
|
|
18
|
+
frame: FrameAddress
|
|
19
|
+
): Record<string, (...args: any[]) => void>;
|
|
20
|
+
|
|
21
|
+
/** Options shared by the frame producers. */
|
|
22
|
+
export interface FrameStreamOptions {
|
|
23
|
+
/** Boundary address; defaults to `{ id: "", version: 1 }`. */
|
|
24
|
+
frame?: { id?: string; version?: number };
|
|
25
|
+
/** Remaining `renderToStream` options (plugins, onError, manifest, ...). */
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A produced frame stream: pipe chunks, or await the collected array. */
|
|
30
|
+
export interface FrameStream extends PromiseLike<FrameChunk[]> {
|
|
31
|
+
pipe(writable: { write(chunk: FrameChunk): void; end?(): void }): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Render to a FrameChunk stream: the same render core as `renderToStream`
|
|
36
|
+
* with emission swapped to the frame sink and the document writable replaced
|
|
37
|
+
* by a chunk envelope (`start` up front, `complete` at stream end). Data
|
|
38
|
+
* records default to the keyed JSON codec (decode with
|
|
39
|
+
* `createJSONDataTable`).
|
|
40
|
+
*/
|
|
41
|
+
export function renderToFrameStream(code: () => unknown, options?: FrameStreamOptions): FrameStream;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Render a **server component** — a `props => JSX` function, typically
|
|
45
|
+
* returned from a server function — to a FrameChunk stream. `props` is a
|
|
46
|
+
* slot-props proxy, not data:
|
|
47
|
+
*
|
|
48
|
+
* - reading a prop as a child emits a marker range the client fills;
|
|
49
|
+
* - calling a prop as a render function emits a `slot` chunk for a fresh
|
|
50
|
+
* occurrence (a primitive `$key` arg names it, so client state follows the
|
|
51
|
+
* entity across responses — the slot-level analogue of For's `keyed`
|
|
52
|
+
* function; positional otherwise, which is the right default for most
|
|
53
|
+
* flows);
|
|
54
|
+
* - primitive args ride the chunk; server JSX args stream as nested regions
|
|
55
|
+
* (`{$frame}` — html once, never data); other values serialize as `{$ref}`
|
|
56
|
+
* data records with referential dedupe.
|
|
57
|
+
*
|
|
58
|
+
* The props a *client* passes never reach the server — server inputs are the
|
|
59
|
+
* function's arguments.
|
|
60
|
+
*/
|
|
61
|
+
export function renderServerComponent(
|
|
62
|
+
component: (props: Record<string, any>) => unknown,
|
|
63
|
+
options?: FrameStreamOptions
|
|
64
|
+
): FrameStream;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The slot props proxy used by `renderServerComponent`. Every key
|
|
68
|
+
* virtually exists (`in` is always true — a prop is a position the client
|
|
69
|
+
* may fill), enumeration is empty by design, and serialization goes through
|
|
70
|
+
* the live render context, so it must only be used during the frame's
|
|
71
|
+
* render.
|
|
72
|
+
* @internal Exposed for framework bindings composing their own producers.
|
|
73
|
+
*/
|
|
74
|
+
export function createSlotProps(
|
|
75
|
+
sink: ReturnType<typeof createFrameSink>,
|
|
76
|
+
frame: FrameAddress
|
|
77
|
+
): Record<string, any>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A server component as an HTTP Response: the chunk stream framed with the
|
|
81
|
+
* server-function wire convention, tagged `X-Frame-Stream: <frame id>` for
|
|
82
|
+
* the client and `X-Content-Raw` so the server-function handler forwards it
|
|
83
|
+
* untouched. `init` (headers/status, e.g. from a `respond()` envelope)
|
|
84
|
+
* merges in; the frame tags win on conflict.
|
|
85
|
+
*/
|
|
86
|
+
export function serverComponentResponse(
|
|
87
|
+
component: (props: Record<string, any>) => unknown,
|
|
88
|
+
options?: FrameStreamOptions,
|
|
89
|
+
init?: { headers?: HeadersInit; status?: number }
|
|
90
|
+
): Response;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The server-component convention as a `transformResult` policy for
|
|
94
|
+
* `handleServerFunctionRequest`: a function result — or a `respond()`
|
|
95
|
+
* envelope whose value is a function — becomes a frame-stream Response,
|
|
96
|
+
* with the frame id defaulting to the server function's id so repeat calls
|
|
97
|
+
* target the same client boundary. Everything else passes through.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* handleServerFunctionRequest(request, {
|
|
102
|
+
* transformResult: frameTransformResult,
|
|
103
|
+
* provideEvent
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function frameTransformResult(event: unknown, result: unknown): unknown;
|
|
108
|
+
|
|
109
|
+
// === Document SSR (t = 0) ===
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Document-mode slot props — the t = 0 counterpart of
|
|
113
|
+
* `createSlotProps`: the server component renders INLINE in the
|
|
114
|
+
* document and the client's real props render server-side inside its
|
|
115
|
+
* positions (the one hydration-time exception), wrapped in the same marker
|
|
116
|
+
* dialect the chunk producer emits so the adopting client binds slots and
|
|
117
|
+
* regions onto the server-rendered ranges.
|
|
118
|
+
*/
|
|
119
|
+
export function createDocumentSlotProps(
|
|
120
|
+
clientProps: Record<string, unknown>,
|
|
121
|
+
frameId: string
|
|
122
|
+
): Record<string, unknown>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The in-process mirror of `frameTransformResult` for DOCUMENT SSR: install
|
|
126
|
+
* as `configureServerFunctionsServer({ transformDirectResult })` and a
|
|
127
|
+
* direct (same-process) server-function result that is a function comes back
|
|
128
|
+
* as an inline-renderable server component (frame markers + document
|
|
129
|
+
* slot props). Non-function results pass through.
|
|
130
|
+
*/
|
|
131
|
+
export function frameTransformDirectResult<T>(value: T, options: { id: string }): T;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Seroval plugin for the hydration serializer: writes an inline server
|
|
135
|
+
* component as a stable per-function-id placeholder reference
|
|
136
|
+
* (`self._$SC.r(id)`) instead of meeting an unserializable function.
|
|
137
|
+
*/
|
|
138
|
+
export const ServerComponentPlugin: unknown;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Inline bootstrap for the document shell: installs the `self._$SC`
|
|
142
|
+
* placeholder registry the hydration references resolve through; the client
|
|
143
|
+
* upgrades it via `installServerComponents()`.
|
|
144
|
+
*/
|
|
145
|
+
export const SERVER_COMPONENT_BOOTSTRAP: string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { FrameChunk, FrameHost } from "./frame-client.cjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Header tagging a Response as a frame stream; its value is the producing
|
|
5
|
+
* frame's id. Frame-owned wire contract — deliberately not a server-function
|
|
6
|
+
* `BodyFormat` entry, since the body is frame chunks, not a serialized value.
|
|
7
|
+
*/
|
|
8
|
+
export const FRAME_STREAM_HEADER: "X-Frame-Stream";
|
|
9
|
+
|
|
10
|
+
/** Whether a fetch Response carries a frame stream. */
|
|
11
|
+
export function isFrameStreamResponse(response: Response): boolean;
|
|
12
|
+
|
|
13
|
+
/** Options for `applyFrameResponse`. */
|
|
14
|
+
export interface ApplyFrameResponseOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Remap the producer's root frame id onto a local one — the id your
|
|
17
|
+
* insertable/frame registered under — so navigations to the same boundary
|
|
18
|
+
* reuse the same frame regardless of what the server called it. Boundary
|
|
19
|
+
* identity belongs to the client.
|
|
20
|
+
*/
|
|
21
|
+
as?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Restamp every chunk of the response with this version (one response IS
|
|
24
|
+
* one version). Versions belong to the client too: the producer cannot
|
|
25
|
+
* know how many streams a boundary has consumed, so pass the Nth-response
|
|
26
|
+
* counter to make policy A's stale-guard real across navigations.
|
|
27
|
+
*/
|
|
28
|
+
version?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Reads a frame-stream Response to completion, applying every chunk to
|
|
33
|
+
* `host`. Chunks are length-prefixed JSON over the server-function wire
|
|
34
|
+
* framing. Resolves with the id the chunks were applied under once the
|
|
35
|
+
* stream ends; rejects on a malformed or errored stream.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const response = await getStory(id); // frame-tagged server function result
|
|
40
|
+
* if (isFrameStreamResponse(response)) {
|
|
41
|
+
* await applyFrameResponse(response, host, { as: "story-pane" });
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function applyFrameResponse(
|
|
46
|
+
response: Response,
|
|
47
|
+
host: FrameHost,
|
|
48
|
+
options?: ApplyFrameResponseOptions
|
|
49
|
+
): Promise<string>;
|
|
50
|
+
|
|
51
|
+
/** Options for `createServerComponentHandler`. */
|
|
52
|
+
export interface ServerComponentHandlerOptions<C = unknown> {
|
|
53
|
+
host: FrameHost;
|
|
54
|
+
/**
|
|
55
|
+
* Builds the framework's mountable component for a boundary. Invoked once
|
|
56
|
+
* per boundary and cached; every mount of the returned component is its
|
|
57
|
+
* own frame instance under the boundary id (multi-mount fans out).
|
|
58
|
+
*/
|
|
59
|
+
component(frameId: string): C;
|
|
60
|
+
/**
|
|
61
|
+
* Runs synchronously at each server-function call site (before any
|
|
62
|
+
* await); its return is the call's ambient identity — e.g. Solid's
|
|
63
|
+
* `getOwner`. Calls sharing a captured context share one boundary.
|
|
64
|
+
*/
|
|
65
|
+
capture?(info: { id: string; meta: unknown }): unknown;
|
|
66
|
+
/**
|
|
67
|
+
* A new response is about to stream into a boundary: rotate
|
|
68
|
+
* response-scoped state (codec data tables) here. `version` is the
|
|
69
|
+
* client-owned stream counter the chunks will be stamped with.
|
|
70
|
+
*/
|
|
71
|
+
onStream?(frameId: string, version: number, response: Response): void;
|
|
72
|
+
/**
|
|
73
|
+
* Document-SSR adoption: given a boundary id the page already carries
|
|
74
|
+
* (server-rendered between `frame:<id>` markers), return the component
|
|
75
|
+
* that adopts that range — or `undefined` to stream normally. Consulted
|
|
76
|
+
* once per boundary, before any fetch.
|
|
77
|
+
*/
|
|
78
|
+
documentComponent?(frameId: string): C | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Answer a call SYNCHRONOUSLY before any request is made (t = 0 local
|
|
81
|
+
* answers — e.g. a boundary the document already carries). Returning a
|
|
82
|
+
* non-undefined value resolves the call with it; a hydrating consumer
|
|
83
|
+
* never observes a pending beat.
|
|
84
|
+
*/
|
|
85
|
+
intercept?(info: { id: string; meta: unknown; args: unknown[] }): C | undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The client mirror of `frameTransformResult`, shaped for the server-function
|
|
90
|
+
* client's `responseHandler` seam: frame-stream responses resolve the call
|
|
91
|
+
* with a **stable component** instead of data, so an equals-gated consumer
|
|
92
|
+
* (Solid's `dynamic`) never remounts across refetches — the response streams
|
|
93
|
+
* into the boundary underneath as the only observable effect.
|
|
94
|
+
*
|
|
95
|
+
* Boundary identity is derived, never declared: contexts captured per call
|
|
96
|
+
* key a WeakMap of boundaries (dying with their call sites); ownerless calls
|
|
97
|
+
* fall back to one boundary per function id.
|
|
98
|
+
*/
|
|
99
|
+
export function createServerComponentHandler<C>(
|
|
100
|
+
options: ServerComponentHandlerOptions<C>
|
|
101
|
+
): {
|
|
102
|
+
capture?(info: { id: string; meta: unknown }): unknown;
|
|
103
|
+
intercept?(info: { id: string; meta: unknown; args: unknown[] }): C | undefined;
|
|
104
|
+
handle(response: Response, ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }): C | undefined;
|
|
105
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
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).
|
|
41
|
+
*/
|
|
42
|
+
disabledFeatures?: number;
|
|
43
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
44
|
+
plugins?: SerializerPlugin[];
|
|
45
|
+
/** Receives each emitted script chunk. */
|
|
46
|
+
onData: (result: string) => void;
|
|
47
|
+
onError?: (error: unknown) => void;
|
|
48
|
+
/** Fires once all async values have settled. */
|
|
49
|
+
onDone?: () => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
54
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
55
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
56
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
57
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
58
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
59
|
+
*/
|
|
60
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
64
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export type HydrationSerializerOptions = Omit<
|
|
68
|
+
WebSerializerOptions,
|
|
69
|
+
"globalIdentifier" | "disabledFeatures"
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
74
|
+
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
75
|
+
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
76
|
+
* for hand-written code — custom serialization should use
|
|
77
|
+
* `createSerializer` or the JSON codec.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
84
|
+
* emits ahead of hydration data for a render scope. Not meant for
|
|
85
|
+
* hand-written code.
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
89
|
+
|
|
90
|
+
// ---- JSON codec (server function transports) ----
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
94
|
+
* on the serializing and deserializing peer or payloads will not
|
|
95
|
+
* round-trip — for server functions, set them once through the
|
|
96
|
+
* client/server `codec` config option.
|
|
97
|
+
*/
|
|
98
|
+
export interface JSONCodecOptions {
|
|
99
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
100
|
+
plugins?: SerializerPlugin[];
|
|
101
|
+
/**
|
|
102
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
103
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
104
|
+
*/
|
|
105
|
+
disabledFeatures?: number;
|
|
106
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
107
|
+
depthLimit?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Options for `serializeJSON`. */
|
|
111
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
114
|
+
* (the source value itself). Async values produce additional chunks as
|
|
115
|
+
* they resolve.
|
|
116
|
+
*/
|
|
117
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
118
|
+
onError?: (error: unknown) => void;
|
|
119
|
+
/** Fires once all async values have settled. */
|
|
120
|
+
onDone?: () => void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
125
|
+
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
126
|
+
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
127
|
+
* framing of the nodes is the transport's concern. Returns a cancel
|
|
128
|
+
* function that aborts pending async serialization.
|
|
129
|
+
*/
|
|
130
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
134
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
135
|
+
* from one stream must go through the same deserializer instance. The first
|
|
136
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
137
|
+
* settles the async values referenced inside it.
|
|
138
|
+
*/
|
|
139
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
143
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
144
|
+
* `resolve`. The frames client host wires one per response
|
|
145
|
+
* (`applyData: c => table.apply(c)`).
|
|
146
|
+
*/
|
|
147
|
+
export interface JSONDataTable {
|
|
148
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
149
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
150
|
+
}
|
|
151
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @solidjs/web/frames — server half. Render server components (functions
|
|
3
|
+
* returned from server functions) to frame-chunk streams, serve them as
|
|
4
|
+
* framed HTTP responses through the server-function handler's
|
|
5
|
+
* transformResult hook, and render them inline during document SSR.
|
|
6
|
+
*
|
|
7
|
+
* Copied next to the runtime's frame d.ts files at publish (see
|
|
8
|
+
* types:copy-frames), so the relative imports below resolve in-place.
|
|
9
|
+
*/
|
|
10
|
+
export {
|
|
11
|
+
renderToFrameStream,
|
|
12
|
+
renderServerComponent,
|
|
13
|
+
serverComponentResponse,
|
|
14
|
+
frameTransformResult,
|
|
15
|
+
createFrameSink,
|
|
16
|
+
frameTransformDirectResult,
|
|
17
|
+
ServerComponentPlugin,
|
|
18
|
+
SERVER_COMPONENT_BOOTSTRAP
|
|
19
|
+
} from "./frame-sink.cjs";
|
|
20
|
+
export type { FrameAddress, FrameStream, FrameStreamOptions } from "./frame-sink.cjs";
|
|
21
|
+
export { FRAME_STREAM_HEADER, isFrameStreamResponse } from "./frame-transport.cjs";
|
|
@@ -137,3 +137,15 @@ export function serializeJSON(value: unknown, options: JSONSerializeOptions): ()
|
|
|
137
137
|
* settles the async values referenced inside it.
|
|
138
138
|
*/
|
|
139
139
|
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
143
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
144
|
+
* `resolve`. The frames client host wires one per response
|
|
145
|
+
* (`applyData: c => table.apply(c)`).
|
|
146
|
+
*/
|
|
147
|
+
export interface JSONDataTable {
|
|
148
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
149
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
150
|
+
}
|
|
151
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -81,6 +81,30 @@ export interface ServerFunctionsClientConfig {
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
prepareRequest?: PrepareRequestHook;
|
|
84
|
+
/**
|
|
85
|
+
* Response-side integration seam — the client mirror of the handler's
|
|
86
|
+
* `transformResult`. `handle(response, ctx)` sees every response before
|
|
87
|
+
* the transport decodes it; returning anything but undefined resolves the
|
|
88
|
+
* call with that value. `capture(info)` runs synchronously at the call
|
|
89
|
+
* site (before any await) and its return arrives as `ctx.context`, so
|
|
90
|
+
* ambient per-call state (e.g. a reactive owner) survives to response
|
|
91
|
+
* time. See `createServerComponentHandler` in frame-transport for the
|
|
92
|
+
* canonical implementation.
|
|
93
|
+
*/
|
|
94
|
+
responseHandler?: {
|
|
95
|
+
capture?(info: { id: string; meta: unknown }): unknown;
|
|
96
|
+
handle(
|
|
97
|
+
response: Response,
|
|
98
|
+
ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
|
|
99
|
+
): unknown;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Encoder for argument lists JSON can't carry faithfully. JSON-safe args
|
|
103
|
+
* always go as plain JSON (no codec in the bundle); anything else throws
|
|
104
|
+
* unless this is set. Installed by `enableRichArguments()` from the
|
|
105
|
+
* rich-args entry — set directly only for custom wire encodings.
|
|
106
|
+
*/
|
|
107
|
+
serializeArgs?(args: unknown[]): string | Promise<string>;
|
|
84
108
|
}
|
|
85
109
|
|
|
86
110
|
/**
|
package/types-cjs/server.d.cts
CHANGED
|
@@ -212,6 +212,8 @@ export function setAttributeNS(node: Element, namespace: string, name: string, v
|
|
|
212
212
|
export function registerElementClaim(handler: (element: Element) => void): () => void;
|
|
213
213
|
/** Server no-op: returns `node` unchanged. Claims never fire during SSR. */
|
|
214
214
|
export function claimElement<T extends Element>(node: T): T;
|
|
215
|
+
/** Server no-op: returns `root` unchanged. Claims never fire during SSR. */
|
|
216
|
+
export function claimElementTree<T extends Node>(root: T): T;
|
|
215
217
|
|
|
216
218
|
/** @deprecated not supported on the server side */
|
|
217
219
|
export function addEvent(node: Element, name: string, handler: () => void, delegate: boolean): void;
|