@solidjs/web 2.0.0-beta.22 → 2.0.0-beta.24

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 (46) hide show
  1. package/dist/dev.cjs +25 -1
  2. package/dist/dev.js +25 -2
  3. package/dist/server.cjs +109 -45
  4. package/dist/server.js +109 -46
  5. package/dist/web.cjs +25 -1
  6. package/dist/web.js +25 -2
  7. package/frames/dist/client.cjs +1467 -0
  8. package/frames/dist/client.js +1455 -0
  9. package/frames/dist/server.cjs +1723 -0
  10. package/frames/dist/server.js +1712 -0
  11. package/frames/package.json +30 -0
  12. package/package.json +78 -5
  13. package/serialization/dist/serialization.cjs +83 -0
  14. package/serialization/dist/serialization.js +82 -1
  15. package/serialization/types/index.d.ts +12 -0
  16. package/serialization/types-cjs/index.d.cts +12 -0
  17. package/server-functions/dist/client.cjs +82 -55
  18. package/server-functions/dist/client.js +83 -56
  19. package/server-functions/dist/server.cjs +28 -7
  20. package/server-functions/dist/server.js +28 -7
  21. package/types/client.d.ts +8 -0
  22. package/types/core.d.ts +2 -1
  23. package/types/frames/client.d.ts +53 -0
  24. package/types/frames/frame-client.d.ts +222 -0
  25. package/types/frames/frame-sink.d.ts +145 -0
  26. package/types/frames/frame-transport.d.ts +106 -0
  27. package/types/frames/serializer.d.ts +151 -0
  28. package/types/frames/server.d.ts +21 -0
  29. package/types/serializer.d.ts +12 -0
  30. package/types/server-functions/client.d.ts +24 -0
  31. package/types/server-functions/server.d.ts +17 -0
  32. package/types/server-functions/shared.d.ts +17 -0
  33. package/types/server.d.ts +2 -0
  34. package/types-cjs/client.d.cts +8 -0
  35. package/types-cjs/core.d.cts +2 -1
  36. package/types-cjs/frames/client.d.cts +53 -0
  37. package/types-cjs/frames/frame-client.d.cts +222 -0
  38. package/types-cjs/frames/frame-sink.d.cts +145 -0
  39. package/types-cjs/frames/frame-transport.d.cts +106 -0
  40. package/types-cjs/frames/serializer.d.cts +151 -0
  41. package/types-cjs/frames/server.d.cts +21 -0
  42. package/types-cjs/serializer.d.cts +12 -0
  43. package/types-cjs/server-functions/client.d.cts +24 -0
  44. package/types-cjs/server-functions/server.d.cts +17 -0
  45. package/types-cjs/server-functions/shared.d.cts +17 -0
  46. package/types-cjs/server.d.cts +2 -0
@@ -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
  /**
@@ -102,6 +102,23 @@ export interface ServerFunctionsServerConfig {
102
102
  * router); per-handler `collectFlightData` options override it.
103
103
  */
104
104
  collectFlightData?: CollectFlightDataHook;
105
+ /**
106
+ * Server-wide default for the handler's `transformResult` (same contract
107
+ * — see `HandleServerFunctionRequestOptions`); a per-request option
108
+ * overrides it. Registering it here makes result policies (e.g. frames'
109
+ * `frameTransformResult`) work through generic dispatchers that call
110
+ * `handleServerFunctionRequest(request)` with no options.
111
+ */
112
+ transformResult?(
113
+ event: ServerFunctionEvent,
114
+ result: unknown,
115
+ context: { instance: string | null; request: Request; thrown?: boolean }
116
+ ): unknown | ResponseEnvelope | Promise<unknown | ResponseEnvelope>;
117
+ /**
118
+ * The in-process mirror of `transformResult` for direct (same-server)
119
+ * calls during document SSR — e.g. frames' `frameTransformDirectResult`.
120
+ */
121
+ transformDirectResult?(value: unknown, options: { id: string }): unknown;
105
122
  /**
106
123
  * Endpoint the HTTP handler is mounted on, used for the `url` of SSR'd
107
124
  * references (e.g. form actions) — must match the client configuration.
@@ -369,3 +369,20 @@ export function decodeResponse<T = unknown>(
369
369
  response: Response,
370
370
  codecOptions?: JSONCodecOptions
371
371
  ): Promise<T | undefined>;
372
+
373
+ /**
374
+ * Frame one payload for the server-function wire: a `;0x<len32>;` length
375
+ * prefix followed by the utf-8 data. Both transports (server-function
376
+ * responses and frame streams) share this framing.
377
+ */
378
+ export function createChunk(data: string): Uint8Array;
379
+
380
+ /**
381
+ * Incremental decoder for `createChunk` framing over a byte stream: `next()`
382
+ * yields one complete payload string per call (async-iterator result shape),
383
+ * buffering partial frames internally until their length prefix is satisfied.
384
+ */
385
+ export class ChunkReader {
386
+ constructor(stream: ReadableStream<Uint8Array>);
387
+ next(): Promise<{ done: boolean; value: string | undefined }>;
388
+ }
@@ -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;