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

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 +27 -4
  2. package/dist/dev.cjs +1224 -205
  3. package/dist/dev.js +1188 -199
  4. package/dist/server.cjs +1429 -234
  5. package/dist/server.js +1391 -231
  6. package/dist/web.cjs +1207 -195
  7. package/dist/web.js +1171 -189
  8. package/frames/dist/client.cjs +1694 -0
  9. package/frames/dist/client.dev.cjs +1707 -0
  10. package/frames/dist/client.dev.js +1695 -0
  11. package/frames/dist/client.js +1682 -0
  12. package/frames/dist/server.cjs +2520 -0
  13. package/frames/dist/server.js +2508 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +285 -37
  16. package/serialization/dist/serialization.cjs +169 -0
  17. package/serialization/dist/serialization.js +159 -0
  18. package/serialization/package.json +20 -0
  19. package/serialization/types/index.d.ts +157 -0
  20. package/serialization/types-cjs/index.d.cts +157 -0
  21. package/serialization/types-cjs/package.json +3 -0
  22. package/server-functions/dist/client.cjs +613 -0
  23. package/server-functions/dist/client.js +585 -0
  24. package/server-functions/dist/server.cjs +904 -0
  25. package/server-functions/dist/server.js +875 -0
  26. package/server-functions/package.json +30 -0
  27. package/storage/package.json +8 -3
  28. package/storage/types/index.d.ts +26 -0
  29. package/storage/types-cjs/index.d.cts +28 -0
  30. package/storage/types-cjs/package.json +3 -0
  31. package/types/client.d.ts +127 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +22 -0
  34. package/types/frames/frame-client.d.ts +282 -0
  35. package/types/frames/frame-sink.d.ts +171 -0
  36. package/types/frames/frame-transport.d.ts +190 -0
  37. package/types/frames/serializer.d.ts +157 -0
  38. package/types/frames/server.d.ts +30 -0
  39. package/types/index.d.ts +211 -26
  40. package/types/jsx-properties.d.ts +93 -0
  41. package/types/jsx.d.ts +4150 -1
  42. package/types/response.d.ts +129 -0
  43. package/types/serializer.d.ts +157 -0
  44. package/types/server-functions/client.d.ts +200 -0
  45. package/types/server-functions/flash.d.ts +38 -0
  46. package/types/server-functions/server.d.ts +490 -0
  47. package/types/server-functions/shared.d.ts +445 -0
  48. package/types/server-mock.d.ts +93 -0
  49. package/types/server.d.ts +223 -28
  50. package/types-cjs/client.d.cts +194 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +22 -0
  53. package/types-cjs/frames/frame-client.d.cts +282 -0
  54. package/types-cjs/frames/frame-sink.d.cts +171 -0
  55. package/types-cjs/frames/frame-transport.d.cts +190 -0
  56. package/types-cjs/frames/serializer.d.cts +157 -0
  57. package/types-cjs/frames/server.d.cts +30 -0
  58. package/types-cjs/index.d.cts +231 -0
  59. package/types-cjs/jsx-properties.d.cts +93 -0
  60. package/types-cjs/jsx.d.cts +4150 -0
  61. package/types-cjs/package.json +3 -0
  62. package/types-cjs/response.d.cts +129 -0
  63. package/types-cjs/serializer.d.cts +157 -0
  64. package/types-cjs/server-functions/client.d.cts +200 -0
  65. package/types-cjs/server-functions/flash.d.cts +38 -0
  66. package/types-cjs/server-functions/server.d.cts +490 -0
  67. package/types-cjs/server-functions/shared.d.cts +445 -0
  68. package/types-cjs/server-mock.d.cts +165 -0
  69. package/types-cjs/server.d.cts +351 -0
  70. package/storage/types/src/client.d.ts +0 -1
  71. package/storage/types/src/index.d.ts +0 -46
  72. package/storage/types/src/server-mock.d.ts +0 -72
  73. package/storage/types/storage/src/index.d.ts +0 -2
@@ -0,0 +1,282 @@
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: "complete"; id: string; version: number }
45
+ | { type: "error"; id: string; version: number; key?: string; error: unknown };
46
+
47
+ /**
48
+ * Maps a wire chunk onto resident-store record writes. `data` chunks map to
49
+ * no records — they are response-scoped and the host applies them through
50
+ * its data hook.
51
+ */
52
+ export function chunkToRecords(chunk: FrameChunk): Record<string, unknown>;
53
+
54
+ /**
55
+ * One store write applied to a frame: `r` maps record keys to values
56
+ * (`chunkToRecords` produces these from wire chunks) and `version` is the
57
+ * stream stamp — an older version than the frame's current one is ignored.
58
+ */
59
+ export interface FrameWrite {
60
+ version: number;
61
+ r: Record<string, unknown>;
62
+ }
63
+
64
+ /** Context passed to a slot callback. */
65
+ export interface SlotContext {
66
+ /**
67
+ * True only for the hydration-attach invocation of an adopted
68
+ * document-SSR range — the one call a consumer may answer with a claim
69
+ * (`existing` IS the server-rendered output for these args). Unset on
70
+ * stream-driven re-calls: those must render for real, or content the
71
+ * re-call displaced (e.g. `{$frame}` region ranges) is dropped.
72
+ */
73
+ adopted?: boolean;
74
+ /**
75
+ * Whether this occurrence is a render-prop CALL (the producer placed it
76
+ * with arguments — possibly empty — via a slot record) as opposed to a
77
+ * direct-insert position. Consumers cannot tell from the resolved props
78
+ * alone: an argless render prop and a direct insert both arrive as `{}`,
79
+ * but one is a function to invoke and the other a value to place.
80
+ */
81
+ invoked?: boolean;
82
+ /**
83
+ * Register cleanup for when this occurrence's range is removed from the
84
+ * server content, or the owning frame is disposed.
85
+ */
86
+ onCleanup(fn: () => void): void;
87
+ /**
88
+ * Live-props opt-in: a binding that registers here receives the
89
+ * re-resolved props when a re-sent record's args CHANGE in value, instead
90
+ * of the occurrence being re-called — the invocation's instance (and its
91
+ * client state) survives the change. Register synchronously during the
92
+ * invocation; one updater per occurrence (last registration wins). A
93
+ * genuine re-call or unmount clears it before/with the binding it served.
94
+ */
95
+ onUpdate(fn: (props: Record<string, unknown>) => void): void;
96
+ /**
97
+ * The range's current interior — server-rendered client content on an
98
+ * adopted document-SSR boot, or the previous output on a re-call. A
99
+ * framework binding hydrates onto it and returns `undefined` to claim it
100
+ * in place (zero DOM mutation).
101
+ */
102
+ existing: ChildNode[];
103
+ /**
104
+ * The range's own marker comments, when the occurrence has a placed range.
105
+ * A framework binding whose slot content is reactive at the top level (a
106
+ * boundary accessor, changing route children) owns the interior instead of
107
+ * returning nodes: bind before `end` with the framework's insert primitive
108
+ * and return `undefined` — the frame leaves the range alone (server morphs
109
+ * already protect slot ranges).
110
+ */
111
+ range?: { start: Comment; end: Comment };
112
+ }
113
+
114
+ /**
115
+ * Client content for a server-declared slot. Direct-insert occurrences
116
+ * call it with empty props; render-prop occurrences pass the occurrence's
117
+ * resolved args (primitives literal, `{$ref}` data resolved through the
118
+ * host, `{$frame}` regions as marker-range fragments). Return nodes to fill
119
+ * the range, or `undefined` to claim `ctx.existing` untouched.
120
+ */
121
+ export type Slot = (props: Record<string, unknown>, ctx: SlotContext) => Node | Node[] | undefined;
122
+
123
+ export interface Frame {
124
+ /** Merge a write into the store and flush (morph/reveal/slot sync). */
125
+ apply(write: FrameWrite): void;
126
+ /** The active version, or undefined before the first apply. */
127
+ readonly version: number | undefined;
128
+ /** Read-only view of the resident record store. */
129
+ readonly store: Readonly<Record<string, unknown>>;
130
+ /** The stream's error record, if an `error` chunk arrived. */
131
+ readonly error: unknown;
132
+ /** Whether the named fragment has been revealed into the boundary. */
133
+ isRevealed(segment: string): boolean;
134
+ /**
135
+ * Re-key this live frame to a different boundary id (the mount-preserving
136
+ * half of a call-site handoff): nothing tears down — the element, store,
137
+ * and slot state stay — while leaving the old id stashes a retention
138
+ * snapshot under it and joining the new id seeds/drains its retained
139
+ * store and buffered chunks. Version affinity resets: histories are per
140
+ * boundary id.
141
+ */
142
+ rebind(id: string): void;
143
+ /**
144
+ * Forget the version baseline without touching content — the next write
145
+ * is accepted whatever its number. Called by the host after seeding a
146
+ * registration from a retained snapshot, whose numbering belongs to a
147
+ * different stream space.
148
+ */
149
+ rebase(): void;
150
+ /** Tear down: slot cleanups cascade, later chunks are ignored. Idempotent. */
151
+ dispose(): void;
152
+ }
153
+
154
+ /**
155
+ * Routes a flat stream of addressed chunks to frames by id, buffering chunks
156
+ * for frames that have not registered yet (only the newest version's chunks
157
+ * are kept). `data` chunks are response-scoped and go to `applyData`.
158
+ *
159
+ * An id may have several frames (the same server component mounted more
160
+ * than once): chunks fan out to all of them, and a frame registering after
161
+ * delivery is seeded from a sibling's store.
162
+ */
163
+ export interface FrameHost {
164
+ register(id: string, frame: Frame): void;
165
+ /** Remove one frame (or all frames of the id when `frame` is omitted). */
166
+ unregister(id: string, frame?: Frame): void;
167
+ apply(chunk: FrameChunk): void;
168
+ /** The first registered frame under the id, if any. */
169
+ get(id: string): Frame | undefined;
170
+ serialize(value: unknown): { $ref: string };
171
+ /** `frameId` is the resolving frame's id — route to its stream's table. */
172
+ resolve(ref: { $ref: string }, frameId?: string): unknown;
173
+ }
174
+
175
+ /**
176
+ * The bubbling DOM event (`"frame:applied"`) a frame dispatches from its
177
+ * parent element whenever server content lands in the document — root
178
+ * materialize/morph, segment reveal, fallback materialization — with
179
+ * `detail: { id, version, reason }`. One document-level listener sees every
180
+ * boundary (nested region frames dispatch too); use it to re-apply
181
+ * client-owned decorations on server-owned markup (router affordance
182
+ * reflection, e.g. `aria-current`) without a MutationObserver.
183
+ */
184
+ export const FRAME_APPLIED_EVENT: "frame:applied";
185
+
186
+ /** Options for `createFrameHost`. */
187
+ export interface FrameHostOptions {
188
+ /**
189
+ * Backs `{$ref}` slot args (typically a codec data table's `resolve`).
190
+ * `frameId` identifies the resolving frame — data tables are
191
+ * response-scoped, so multi-stream hosts route by it (nested region ids
192
+ * prefix-match their root).
193
+ */
194
+ resolve?(ref: { $ref: string }, frameId?: string): unknown;
195
+ /** Test/host-side counterpart of `resolve`. */
196
+ serialize?(value: unknown): { $ref: string };
197
+ /**
198
+ * Receives each `data` chunk whole. Wire a codec table:
199
+ * `applyData: c => table.apply(c)` (see `createJSONDataTable`).
200
+ */
201
+ applyData?(chunk: Extract<FrameChunk, { type: "data" }>): void;
202
+ }
203
+
204
+ export function createFrameHost(options?: FrameHostOptions): FrameHost;
205
+
206
+ /** Options for `createFrame` / `createFrameElement`. */
207
+ export interface FrameOptions {
208
+ /** Register with this host under `id`, receiving routed/buffered chunks. */
209
+ host?: FrameHost;
210
+ id?: string;
211
+ /** Client content keyed by prop name (occurrences resolve by prop). */
212
+ slots?: Record<string, Slot>;
213
+ /**
214
+ * Adopt existing server-rendered DOM: the first apply morphs against it,
215
+ * and slots sync immediately (hydration attach) — a document-SSR boot
216
+ * needs no chunk.
217
+ */
218
+ adopt?: boolean;
219
+ /** Called after each apply flush (tests/telemetry). */
220
+ onApply?(info: { version: number; reason: "materialize" | "morph" | "reveal" }): void;
221
+ /**
222
+ * Wraps element-claim sweeps (`a[href]`/`form[action]` in materialized
223
+ * server content — and only those) so claim consumers register their
224
+ * per-element cleanup against the boundary's reactive owner, e.g.
225
+ * `fn => runWithOwner(owner, fn)`. Nested region frames inherit it.
226
+ * Without it, sweeps run under whatever owner is current (none, for
227
+ * streamed chunks).
228
+ */
229
+ ownerScope?<T>(fn: () => T): T;
230
+ /**
231
+ * Boundary-driven segment reveal. When present, `#revealSegment` hands the
232
+ * placeholder seam to this hook instead of swapping imperatively: the binding
233
+ * reconstructs a client `<Loading>` there — `fallback` is the placeholder's
234
+ * own template content (shown while holding), `content()` materializes the
235
+ * segment and renders its client fills INSIDE the boundary so their readiness
236
+ * gates the reveal — and inserts it before `before`. An unboundaried async
237
+ * fill suspends up to that boundary and is covered instead of orphaned; one
238
+ * boundary per revealed segment, i.e. per author-placed `<Loading>`. Omit it
239
+ * for the framework-agnostic imperative swap (no reactive reveal).
240
+ */
241
+ reveal?(seam: { before: Node; fallback: Node[]; content: () => Node | DocumentFragment }): void;
242
+ /**
243
+ * Document-face record-race guard (adopt path only — solidjs/solid#2968).
244
+ * Nothing on the wire formally orders an occurrence's args-record data
245
+ * script before the event that triggers adoption, so a recordless
246
+ * occurrence is ambiguous while this returns true: the frame defers its
247
+ * mount one macrotask (all currently parsed scripts run first), calls
248
+ * `drainRecords`, and classifies with whatever is then resolvable. Return
249
+ * false once the document can run no further data scripts.
250
+ */
251
+ recordsPending?(): boolean;
252
+ /** Re-absorb the document's arrived-by-now records (idempotent per key). */
253
+ drainRecords?(): void;
254
+ }
255
+
256
+ /**
257
+ * A frame rendering into an EXISTING element boundary. Pass `adopt: true` for
258
+ * the document-SSR path: the element already holds server-rendered content,
259
+ * so the first apply morphs against it and slots sync immediately (hydration
260
+ * attach), claiming their server-rendered DOM — a document boot needs no
261
+ * chunk.
262
+ */
263
+ export function createFrame(boundary: Element, options?: FrameOptions): Frame;
264
+
265
+ /** The default boundary/region element tag and its id attribute — the DOM
266
+ * contract the producer emits at t=0 and the consumer creates/adopts. */
267
+ export const FRAME_TAG: "dx-frame";
268
+ export const FRAME_ID_ATTR: "data-fid";
269
+
270
+ /**
271
+ * Create a boundary/region ELEMENT and bind a host-registered frame to it.
272
+ * The frame mounts INTO the element (server content is its children, morphed
273
+ * in place). Because the boundary is a real node, `insert` places the
274
+ * returned `element` in any position — single, array, or fragment — with no
275
+ * special-casing. One frame per element; lifecycle belongs to the creator via
276
+ * `dispose()` (register it with your owner's cleanup).
277
+ */
278
+ export function createFrameElement(options: FrameOptions): {
279
+ readonly element: Element;
280
+ readonly frame: Frame;
281
+ dispose(): void;
282
+ };
@@ -0,0 +1,171 @@
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), branded with its function id and the call's wire address.
130
+ * Non-function results pass through.
131
+ */
132
+ export function frameTransformDirectResult<T>(
133
+ value: T,
134
+ options: { id: string; args?: unknown[] }
135
+ ): T;
136
+
137
+ /**
138
+ * The frame half of single-flight, as a `transformFlightResult` policy for
139
+ * `handleServerFunctionRequest`: when part of what a mutation invalidated is
140
+ * markup (a component-valued flight-data entry), the frame stream carries
141
+ * the whole payload — each component's content as a region addressed by its
142
+ * call, the `{ value, data }` envelope as `outcome` chunks with the
143
+ * component entries serialized as flight references. Returns `undefined`
144
+ * when nothing invalidated is markup (the response stays the plain
145
+ * single-flight envelope).
146
+ */
147
+ export function frameTransformFlightResult(
148
+ event: unknown,
149
+ outcome: { value: unknown; data: unknown },
150
+ context?: unknown
151
+ ): Promise<Response | undefined>;
152
+
153
+ // The brands and the codec plugin live with the transport (client bundles
154
+ // resolve flight references against the live registry); re-exported here for
155
+ // server integrations importing the document-SSR surface.
156
+ export {
157
+ SERVER_COMPONENT,
158
+ SERVER_COMPONENT_ADDRESS,
159
+ SERVER_COMPONENT_SOURCE,
160
+ ServerComponentPlugin
161
+ } from "./frame-transport.cjs";
162
+
163
+ /**
164
+ * Statement form of the `self._$SC` placeholder-registry bootstrap
165
+ * (idempotent — first definition wins). No longer required in the document
166
+ * shell: each hydration script's first serialized server-component reference
167
+ * self-bootstraps the registry. Kept for integrations still installing it
168
+ * document-wide; the client upgrades the registry via
169
+ * `installServerComponents()`.
170
+ */
171
+ export const SERVER_COMPONENT_BOOTSTRAP: string;
@@ -0,0 +1,190 @@
1
+ import { FrameChunk, FrameHost } from "./frame-client.cjs";
2
+ import { JSONCodecOptions } from "./serializer.cjs";
3
+
4
+ // Structural mirror of server-functions/shared.js's FlightDataConsumer:
5
+ // this file may only reference siblings that ship with it when integrations
6
+ // copy the frames declaration set (solid-web's types build), and the
7
+ // server-functions declarations are copied to a different root.
8
+ type FlightConsumer = (data: unknown, context: { response: Response }) => void | Promise<void>;
9
+
10
+ /**
11
+ * Header tagging a Response as a frame stream; its value is the producing
12
+ * frame's id. Frame-owned wire contract — deliberately not a server-function
13
+ * `BodyFormat` entry, since the body is frame chunks, not a serialized value.
14
+ */
15
+ export const FRAME_STREAM_HEADER: "X-Frame-Stream";
16
+
17
+ /** Whether a fetch Response carries a frame stream. */
18
+ export function isFrameStreamResponse(response: Response): boolean;
19
+
20
+ /** Options for `applyFrameResponse`. */
21
+ export interface ApplyFrameResponseOptions {
22
+ /**
23
+ * Remap the producer's root frame id onto a local one — the id your
24
+ * insertable/frame registered under — so navigations to the same boundary
25
+ * reuse the same frame regardless of what the server called it. Boundary
26
+ * identity belongs to the client.
27
+ */
28
+ as?: string;
29
+ /**
30
+ * Restamp every chunk of the response with this version (one response IS
31
+ * one version). Versions belong to the client too: the producer cannot
32
+ * know how many streams a boundary has consumed, so pass the Nth-response
33
+ * counter to make policy A's stale-guard real across navigations. A
34
+ * single-flight response addresses several boundaries, each with its own
35
+ * history — pass a function and it is called once per frame in the
36
+ * response.
37
+ */
38
+ version?: number | ((frameId: string) => number);
39
+ /**
40
+ * Receives the payload text of each `outcome` chunk — the response-scoped
41
+ * single-flight envelope, the caller's result rather than anything the
42
+ * host renders.
43
+ */
44
+ onOutcome?(payload: string): void;
45
+ }
46
+
47
+ /**
48
+ * Reads a frame-stream Response to completion, applying every chunk to
49
+ * `host`. Chunks are length-prefixed JSON over the server-function wire
50
+ * framing. Resolves with the id the chunks were applied under once the
51
+ * stream ends; rejects on a malformed or errored stream.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const response = await getStory(id); // frame-tagged server function result
56
+ * if (isFrameStreamResponse(response)) {
57
+ * await applyFrameResponse(response, host, { as: "story-pane" });
58
+ * }
59
+ * ```
60
+ */
61
+ export function applyFrameResponse(
62
+ response: Response,
63
+ host: FrameHost,
64
+ options?: ApplyFrameResponseOptions
65
+ ): Promise<string>;
66
+
67
+ /** Brands an inline-rendered server component with its function id. */
68
+ export const SERVER_COMPONENT: unique symbol;
69
+
70
+ /** The unwrapped server component behind an inline-render wrap. */
71
+ export const SERVER_COMPONENT_SOURCE: unique symbol;
72
+
73
+ /** The call's wire address (`frameAddress`), for regions to be emitted under. */
74
+ export const SERVER_COMPONENT_ADDRESS: unique symbol;
75
+
76
+ /**
77
+ * The binding brand on values the transport resolves: `{ component, address }`
78
+ * — the identity split (DR-1). `component` is the mount identity, one per
79
+ * server function; `address` names the call's content store. An equals-gated
80
+ * reader compares `component` across resolutions: same function means "same
81
+ * instance, new binding" — keep the mounted instance and deliver the new
82
+ * address into it; a different function swaps normally. `Symbol.for`, so
83
+ * frameworks can honor it without importing this module.
84
+ */
85
+ export const COMPONENT_BINDING: unique symbol;
86
+
87
+ /** The value under `COMPONENT_BINDING` on a transport-resolved binding. */
88
+ export interface ComponentBinding<C = unknown> {
89
+ /** The per-function mount component (the equals-gate identity). */
90
+ component: C;
91
+ /** The call's intrinsic (function, arguments) address — its store's key. */
92
+ address: string;
93
+ }
94
+
95
+ /**
96
+ * Seroval plugin for a server component crossing a serialization boundary:
97
+ * a branded component serializes as a REFERENCE — a per-function document
98
+ * placeholder in the hydration serializer, a live-registry lookup by call
99
+ * address in the JSON codec (single-flight envelopes) — its markup never
100
+ * rides as data.
101
+ */
102
+ export const ServerComponentPlugin: unknown;
103
+
104
+ /**
105
+ * Installs the hydration-serializer registry prefix: given the emitted
106
+ * script's serializer context, returns the expression the next serialized
107
+ * reference reads the `_$SC` registry through (the self-bootstrapping form
108
+ * on a script's first reference, a bare read after). Loaded document-SSR
109
+ * modules install this (see frame-sink); client bundles never carry the
110
+ * bootstrap text.
111
+ */
112
+ export function setServerComponentBootstrap(resolve: (ctx: unknown) => string): void;
113
+
114
+ /**
115
+ * The codec options for a single-flight envelope: `codec` plus
116
+ * `ServerComponentPlugin` (deduped by tag). Injected by the protocol on both
117
+ * legs; exported for integrations composing their own flight carriers.
118
+ */
119
+ export function flightCodec(codec?: JSONCodecOptions): JSONCodecOptions;
120
+
121
+ /** Options for `createServerComponentHandler`. */
122
+ export interface ServerComponentHandlerOptions<C = unknown> {
123
+ host: FrameHost;
124
+ /**
125
+ * Builds the framework's mount component for a server FUNCTION. Invoked
126
+ * once per function and cached — this is the equals-gate identity every
127
+ * call of the function resolves through. The component is CALLED (by the
128
+ * binding wrapper or a gated reader), receiving its current address as a
129
+ * second argument (`() => string`); it should (re-)bind its frame's pull
130
+ * to that address's store. Multi-mount fans out per site.
131
+ */
132
+ component(fnId: string): C;
133
+ /**
134
+ * A new response is about to stream into an address: rotate
135
+ * response-scoped state (codec data tables) here. `version` is the
136
+ * client-owned stream counter the chunks will be stamped with.
137
+ */
138
+ onStream?(address: string, version: number, response: Response): void;
139
+ /**
140
+ * Answer a call SYNCHRONOUSLY before any request is made (t = 0 local
141
+ * answers — e.g. a boundary the document already carries). Returning a
142
+ * non-undefined value resolves the call with it; a hydrating consumer
143
+ * never observes a pending beat.
144
+ */
145
+ intercept?(info: { id: string; meta: unknown; args: unknown[] }): C | undefined;
146
+ /**
147
+ * Reads the registered single-flight consumer at delivery time. The
148
+ * consumer is module state in the server-function client's SHARED
149
+ * instance; pass a getter reading that instance when your bundling gives
150
+ * this module a private copy. Defaults to the local copy's reader.
151
+ */
152
+ consumer?(): FlightConsumer | undefined;
153
+ /**
154
+ * Reads the configured codec options at decode time — same instance-
155
+ * identity contract as `consumer`. Defaults to the local copy's reader.
156
+ */
157
+ codec?(): JSONCodecOptions | undefined;
158
+ }
159
+
160
+ /**
161
+ * The client mirror of `frameTransformResult`, shaped for the server-function
162
+ * client's `responseHandler` seam: frame-stream responses resolve the call
163
+ * with a **binding** — a callable wrapper branded `COMPONENT_BINDING` — so
164
+ * an equals-gated consumer (Solid's `dynamic`) never remounts across
165
+ * refetches or argument changes; the response streams into the address's
166
+ * resident store as the only observable effect.
167
+ *
168
+ * The identity split (DR-1): stores are keyed per-ADDRESS — the call's
169
+ * intrinsic (function, arguments) name, one-to-one with a query cache's
170
+ * per-args entries — while mounts are per-SITE, rendering the per-function
171
+ * component and following delivered addresses. An address nothing is bound
172
+ * to warms its store (preload isolation is the default, not a rule).
173
+ */
174
+ export function createServerComponentHandler<C>(options: ServerComponentHandlerOptions<C>): {
175
+ intercept?(info: { id: string; meta: unknown; args: unknown[] }): unknown;
176
+ handle(
177
+ response: Response,
178
+ ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
179
+ ): unknown;
180
+ /**
181
+ * Declares that the document is showing a call: hydration-data references
182
+ * carry their call's address (`_$SC.r(id, address)`) but never travel
183
+ * through the transport, so the integration forwards those records here.
184
+ * Mints the call's binding (a post-load refetch then resolves a value
185
+ * whose component matches what the document mounted) and brands the
186
+ * per-function component so cache-seeded readers deliver instead of
187
+ * remounting when their site later switches calls.
188
+ */
189
+ showing(address: string, functionId: string): void;
190
+ };