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

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 +1211 -205
  3. package/dist/dev.js +1175 -199
  4. package/dist/server.cjs +1342 -234
  5. package/dist/server.js +1304 -231
  6. package/dist/web.cjs +1195 -196
  7. package/dist/web.js +1159 -190
  8. package/frames/dist/client.cjs +1746 -0
  9. package/frames/dist/client.dev.cjs +1759 -0
  10. package/frames/dist/client.dev.js +1747 -0
  11. package/frames/dist/client.js +1734 -0
  12. package/frames/dist/server.cjs +2426 -0
  13. package/frames/dist/server.js +2414 -0
  14. package/frames/package.json +30 -0
  15. package/package.json +287 -38
  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 +125 -21
  32. package/types/core.d.ts +4 -3
  33. package/types/frames/client.d.ts +20 -0
  34. package/types/frames/frame-client.d.ts +270 -0
  35. package/types/frames/frame-sink.d.ts +168 -0
  36. package/types/frames/frame-transport.d.ts +196 -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 +221 -28
  50. package/types-cjs/client.d.cts +192 -0
  51. package/types-cjs/core.d.cts +4 -0
  52. package/types-cjs/frames/client.d.cts +20 -0
  53. package/types-cjs/frames/frame-client.d.cts +270 -0
  54. package/types-cjs/frames/frame-sink.d.cts +168 -0
  55. package/types-cjs/frames/frame-transport.d.cts +196 -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 +349 -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,270 @@
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
+
244
+ /**
245
+ * A frame rendering into an EXISTING element boundary. Pass `adopt: true` for
246
+ * the document-SSR path: the element already holds server-rendered content,
247
+ * so the first apply morphs against it and slots sync immediately (hydration
248
+ * attach), claiming their server-rendered DOM — a document boot needs no
249
+ * chunk.
250
+ */
251
+ export function createFrame(boundary: Element, options?: FrameOptions): Frame;
252
+
253
+ /** The default boundary/region element tag and its id attribute — the DOM
254
+ * contract the producer emits at t=0 and the consumer creates/adopts. */
255
+ export const FRAME_TAG: "dx-frame";
256
+ export const FRAME_ID_ATTR: "data-fid";
257
+
258
+ /**
259
+ * Create a boundary/region ELEMENT and bind a host-registered frame to it.
260
+ * The frame mounts INTO the element (server content is its children, morphed
261
+ * in place). Because the boundary is a real node, `insert` places the
262
+ * returned `element` in any position — single, array, or fragment — with no
263
+ * special-casing. One frame per element; lifecycle belongs to the creator via
264
+ * `dispose()` (register it with your owner's cleanup).
265
+ */
266
+ export function createFrameElement(options: FrameOptions): {
267
+ readonly element: Element;
268
+ readonly frame: Frame;
269
+ dispose(): void;
270
+ };
@@ -0,0 +1,168 @@
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
+ * Inline bootstrap for the document shell: installs the `self._$SC`
165
+ * placeholder registry the hydration references resolve through; the client
166
+ * upgrades it via `installServerComponents()`.
167
+ */
168
+ export const SERVER_COMPONENT_BOOTSTRAP: string;
@@ -0,0 +1,196 @@
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
+ * Remap any frame id other than the response's own root onto a local one
41
+ * — how a consumer resolves the addresses a single-flight response uses
42
+ * for the regions it refreshed.
43
+ */
44
+ route?(id: string): string;
45
+ /**
46
+ * Receives the payload text of each `outcome` chunk — the response-scoped
47
+ * single-flight envelope, the caller's result rather than anything the
48
+ * host renders.
49
+ */
50
+ onOutcome?(payload: string): void;
51
+ }
52
+
53
+ /**
54
+ * Reads a frame-stream Response to completion, applying every chunk to
55
+ * `host`. Chunks are length-prefixed JSON over the server-function wire
56
+ * framing. Resolves with the id the chunks were applied under once the
57
+ * stream ends; rejects on a malformed or errored stream.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * const response = await getStory(id); // frame-tagged server function result
62
+ * if (isFrameStreamResponse(response)) {
63
+ * await applyFrameResponse(response, host, { as: "story-pane" });
64
+ * }
65
+ * ```
66
+ */
67
+ export function applyFrameResponse(
68
+ response: Response,
69
+ host: FrameHost,
70
+ options?: ApplyFrameResponseOptions
71
+ ): Promise<string>;
72
+
73
+ /** Brands an inline-rendered server component with its function id. */
74
+ export const SERVER_COMPONENT: unique symbol;
75
+
76
+ /** The unwrapped server component behind an inline-render wrap. */
77
+ export const SERVER_COMPONENT_SOURCE: unique symbol;
78
+
79
+ /** The call's wire address (`frameAddress`), for regions to be emitted under. */
80
+ export const SERVER_COMPONENT_ADDRESS: unique symbol;
81
+
82
+ /**
83
+ * The handoff contract on components the transport resolves: `{ fnId,
84
+ * frameId, take(prev) }`. A reader whose source resolved a NEW component
85
+ * while a previous one is mounted offers the old one — `take` rebinds the
86
+ * live mount when both are boundaries of the same function (the element and
87
+ * its slot state stay; the incoming stream morphs it), and the reader keeps
88
+ * its previous value instead of remounting. `Symbol.for`, so frameworks can
89
+ * honor it without importing this module.
90
+ */
91
+ export const COMPONENT_HANDOFF: unique symbol;
92
+
93
+ /** The value under `COMPONENT_HANDOFF` on a transport-resolved component. */
94
+ export interface ComponentHandoff {
95
+ /** The server function id both peers derive the boundary's calls from. */
96
+ fnId: string;
97
+ /** The frame id this component's fresh mounts register under. */
98
+ frameId: string;
99
+ /**
100
+ * Offer `prev` (the reader's current value) to this component. Returns
101
+ * true when the reader should KEEP prev — the mounted frame was rebound
102
+ * to this component's id (or already showed it); false means swap
103
+ * normally (different function, unbranded prev, or nothing mounted).
104
+ */
105
+ take(prev: unknown): boolean;
106
+ }
107
+
108
+ /**
109
+ * Seroval plugin for a server component crossing a serialization boundary:
110
+ * a branded component serializes as a REFERENCE — a per-function document
111
+ * placeholder in the hydration serializer, a live-registry lookup by call
112
+ * address in the JSON codec (single-flight envelopes) — its markup never
113
+ * rides as data.
114
+ */
115
+ export const ServerComponentPlugin: unknown;
116
+
117
+ /**
118
+ * The codec options for a single-flight envelope: `codec` plus
119
+ * `ServerComponentPlugin` (deduped by tag). Injected by the protocol on both
120
+ * legs; exported for integrations composing their own flight carriers.
121
+ */
122
+ export function flightCodec(codec?: JSONCodecOptions): JSONCodecOptions;
123
+
124
+ /** Options for `createServerComponentHandler`. */
125
+ export interface ServerComponentHandlerOptions<C = unknown> {
126
+ host: FrameHost;
127
+ /**
128
+ * Builds the framework's mountable component for a boundary. Invoked once
129
+ * per boundary and cached; every mount of the returned component is its
130
+ * own frame instance under the boundary id (multi-mount fans out).
131
+ */
132
+ component(frameId: string): C;
133
+ /**
134
+ * A new response is about to stream into a boundary: 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?(frameId: string, version: number, response: Response): void;
139
+ /**
140
+ * Document-SSR adoption: given a boundary id the page already carries
141
+ * (server-rendered between `frame:<id>` markers), return the component
142
+ * that adopts that range — or `undefined` to stream normally. Consulted
143
+ * once per boundary, before any fetch.
144
+ */
145
+ documentComponent?(frameId: string): C | undefined;
146
+ /**
147
+ * Answer a call SYNCHRONOUSLY before any request is made (t = 0 local
148
+ * answers — e.g. a boundary the document already carries). Returning a
149
+ * non-undefined value resolves the call with it; a hydrating consumer
150
+ * never observes a pending beat.
151
+ */
152
+ intercept?(info: { id: string; meta: unknown; args: unknown[] }): C | undefined;
153
+ /**
154
+ * Reads the registered single-flight consumer at delivery time. The
155
+ * consumer is module state in the server-function client's SHARED
156
+ * instance; pass a getter reading that instance when your bundling gives
157
+ * this module a private copy. Defaults to the local copy's reader.
158
+ */
159
+ consumer?(): FlightConsumer | undefined;
160
+ /**
161
+ * Reads the configured codec options at decode time — same instance-
162
+ * identity contract as `consumer`. Defaults to the local copy's reader.
163
+ */
164
+ codec?(): JSONCodecOptions | undefined;
165
+ }
166
+
167
+ /**
168
+ * The client mirror of `frameTransformResult`, shaped for the server-function
169
+ * client's `responseHandler` seam: frame-stream responses resolve the call
170
+ * with a **stable component** instead of data, so an equals-gated consumer
171
+ * (Solid's `dynamic`) never remounts across refetches — the response streams
172
+ * into the boundary underneath as the only observable effect.
173
+ *
174
+ * Boundary identity is derived, never declared: every call keys by its
175
+ * intrinsic (function, arguments) address — the query cache's per-args rule,
176
+ * so cached components and boundaries stay one-to-one. Same-args calls
177
+ * resolve the identical component and morph in place; an args switch swaps
178
+ * boundaries, re-materialized from the host's retained state.
179
+ */
180
+ export function createServerComponentHandler<C>(options: ServerComponentHandlerOptions<C>): {
181
+ intercept?(info: { id: string; meta: unknown; args: unknown[] }): C | undefined;
182
+ handle(
183
+ response: Response,
184
+ ctx: { id: string; meta: unknown; args: unknown[]; context: unknown }
185
+ ): C | undefined;
186
+ /**
187
+ * Declares that the document is showing a call: hydration-data references
188
+ * carry their call's address (`_$SC.r(id, address)`) but never travel
189
+ * through the transport, so the integration forwards those records here —
190
+ * they are how a post-load call for the same (function, arguments) finds
191
+ * its way back to the adopted boundary. `component` must be the exact
192
+ * reference the integration's cache holds for the call (the per-function
193
+ * placeholder), or readers' equals-gates fail into remounts.
194
+ */
195
+ showing(address: string, functionId: string, component: C): void;
196
+ };