@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -6
- package/dist/dev.cjs +285 -60
- package/dist/dev.js +267 -57
- package/dist/server.cjs +1148 -176
- package/dist/server.js +1133 -175
- package/dist/web.cjs +285 -60
- package/dist/web.js +267 -57
- package/frames/dist/client.cjs +397 -175
- package/frames/dist/client.dev.cjs +401 -175
- package/frames/dist/client.dev.js +399 -173
- package/frames/dist/client.js +395 -173
- package/frames/dist/server.cjs +1424 -277
- package/frames/dist/server.js +1426 -280
- package/package.json +69 -7
- package/serialization/decode/package.json +20 -0
- package/serialization/dist/decode.cjs +110 -0
- package/serialization/dist/decode.js +104 -0
- package/serialization/dist/serialization.cjs +106 -43
- package/serialization/dist/serialization.js +100 -44
- package/serialization/types/index.d.ts +85 -60
- package/serialization/types/serializer-decode.d.ts +182 -0
- package/serialization/types-cjs/index.d.cts +85 -60
- package/serialization/types-cjs/serializer-decode.d.cts +182 -0
- package/server-functions/dist/client.cjs +131 -98
- package/server-functions/dist/client.js +131 -99
- package/server-functions/dist/rich-args.cjs +11 -0
- package/server-functions/dist/rich-args.js +9 -0
- package/server-functions/dist/server.cjs +367 -194
- package/server-functions/dist/server.dev.cjs +1077 -0
- package/server-functions/dist/server.dev.js +1045 -0
- package/server-functions/dist/server.js +365 -195
- package/server-functions/package.json +10 -0
- package/server-functions/rich-args/package.json +20 -0
- package/storage/types/index.d.ts +1 -1
- package/storage/types-cjs/index.d.cts +1 -1
- package/types/client.d.ts +149 -6
- package/types/cookies.d.ts +93 -0
- package/types/core.d.ts +4 -2
- package/types/frames/client.d.ts +15 -1
- package/types/frames/frame-client.d.ts +63 -7
- package/types/frames/frame-sink.d.ts +26 -3
- package/types/frames/frame-transport.d.ts +40 -8
- package/types/frames/serializer.d.ts +85 -60
- package/types/frames/server.d.ts +22 -0
- package/types/index.d.ts +2 -3
- package/types/response.d.ts +45 -0
- package/types/serializer-decode.d.ts +182 -0
- package/types/serializer.d.ts +85 -60
- package/types/server-functions/client.d.ts +2 -1
- package/types/server-functions/rich-args.d.ts +10 -0
- package/types/server-functions/server.d.ts +99 -1
- package/types/server-functions/shared.d.ts +79 -1
- package/types/server-mock.d.ts +171 -59
- package/types/server.d.ts +209 -37
- package/types-cjs/client.d.cts +149 -6
- package/types-cjs/cookies.d.cts +93 -0
- package/types-cjs/core.d.cts +4 -2
- package/types-cjs/frames/client.d.cts +15 -1
- package/types-cjs/frames/frame-client.d.cts +63 -7
- package/types-cjs/frames/frame-sink.d.cts +26 -3
- package/types-cjs/frames/frame-transport.d.cts +40 -8
- package/types-cjs/frames/serializer.d.cts +85 -60
- package/types-cjs/frames/server.d.cts +22 -0
- package/types-cjs/index.d.cts +2 -3
- package/types-cjs/response.d.cts +45 -0
- package/types-cjs/serializer-decode.d.cts +182 -0
- package/types-cjs/serializer.d.cts +85 -60
- package/types-cjs/server-functions/client.d.cts +2 -1
- package/types-cjs/server-functions/rich-args.d.cts +10 -0
- package/types-cjs/server-functions/server.d.cts +99 -1
- package/types-cjs/server-functions/shared.d.cts +79 -1
- package/types-cjs/server-mock.d.cts +171 -59
- package/types-cjs/server.d.cts +209 -37
|
@@ -1,35 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
// Serialization surface (published as `@solidjs/web/serialization`): the
|
|
2
|
+
// runtime's Seroval machinery, exposed for the runtime's own entries and
|
|
3
|
+
// for integrations building transports on the same codec. This is
|
|
4
|
+
// INTEGRATION-FACING plumbing, not application API — it is exempt from the
|
|
5
|
+
// 2.0 stability guarantee and may change between releases. Application and
|
|
6
|
+
// router code should configure `codec` on the server-function entries
|
|
7
|
+
// instead of importing from here.
|
|
8
|
+
import type { Serializer } from "seroval";
|
|
9
|
+
import {
|
|
10
|
+
JSONCodecOptions,
|
|
11
|
+
PluginInfo,
|
|
12
|
+
SerializerPlugin,
|
|
13
|
+
SerovalNode
|
|
14
|
+
} from "./serializer-decode.cjs";
|
|
2
15
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
// The decode half — `SerovalNode`, the plugin TYPES, `DEFAULT_WEB_PLUGINS`,
|
|
17
|
+
// `resolveSerializerPlugins`, `JSONCodecOptions`, `createJSONDeserializer`,
|
|
18
|
+
// `createJSONDataTable` — is declared in serializer-decode.d.ts (published
|
|
19
|
+
// as `@solidjs/web/serialization/decode`, the module lazy client consumers
|
|
20
|
+
// load) and re-exported here so this remains the full surface.
|
|
21
|
+
export * from "./serializer-decode.cjs";
|
|
22
|
+
|
|
23
|
+
// ---- Plugin authoring ----
|
|
24
|
+
//
|
|
25
|
+
// Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
|
|
26
|
+
// it is the supported way to feed the serializers' `plugins` options and
|
|
27
|
+
// the server-function entries' `codec.plugins`. The values re-export
|
|
28
|
+
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
29
|
+
// the plugin TYPES live in serializer-decode.d.ts (hand-declared there —
|
|
30
|
+
// see its banner for why).
|
|
8
31
|
|
|
9
32
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
33
|
+
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
34
|
+
* plugin authors stay on the exact seroval instance/version the runtime
|
|
35
|
+
* serializes with. Import it from HERE, not from your own `seroval`
|
|
36
|
+
* dependency: a plugin built against a different copy/version would not
|
|
37
|
+
* fail the build — it would emit nodes the other peer can't interpret.
|
|
38
|
+
*
|
|
39
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
13
40
|
*/
|
|
14
|
-
export
|
|
41
|
+
export function createPlugin<Value, Info extends PluginInfo>(
|
|
42
|
+
plugin: SerializerPlugin<Value, Info>
|
|
43
|
+
): SerializerPlugin<Value, Info>;
|
|
15
44
|
|
|
16
45
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
46
|
+
* Seroval's `OpaqueReference`, re-exported from the runtime's own instance
|
|
47
|
+
* (an `OpaqueReference` from another seroval copy fails the serializer's
|
|
48
|
+
* instanceof check and serializes as a plain value): wraps a value so it
|
|
49
|
+
* crosses the wire as its `replacement` (default `undefined`) while
|
|
50
|
+
* staying readable in-process through `.value`.
|
|
51
|
+
*
|
|
52
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
21
53
|
*/
|
|
22
|
-
export
|
|
54
|
+
export class OpaqueReference<V, R = undefined> {
|
|
55
|
+
readonly value: V;
|
|
56
|
+
readonly replacement?: R;
|
|
57
|
+
constructor(value: V, replacement?: R);
|
|
58
|
+
}
|
|
23
59
|
|
|
24
60
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* plugin list to another serialization layer.
|
|
61
|
+
* Options for `createSerializer`.
|
|
62
|
+
*
|
|
63
|
+
* Integration-facing; may change (see the entry banner).
|
|
29
64
|
*/
|
|
30
|
-
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
|
-
|
|
32
|
-
/** Options for `createSerializer`. */
|
|
33
65
|
export interface WebSerializerOptions {
|
|
34
66
|
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
67
|
globalIdentifier: string;
|
|
@@ -58,6 +90,8 @@ export interface WebSerializerOptions {
|
|
|
58
90
|
* evaluated — the script-injection form of serialization renderers build
|
|
59
91
|
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
92
|
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
93
|
+
*
|
|
94
|
+
* Integration-facing; may change (see the entry banner).
|
|
61
95
|
*/
|
|
62
96
|
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
97
|
|
|
@@ -90,30 +124,14 @@ export function createHydrationSerializer(options: HydrationSerializerOptions):
|
|
|
90
124
|
export function getLocalHeaderScript(id?: string): string;
|
|
91
125
|
|
|
92
126
|
// ---- JSON codec (server function transports) ----
|
|
127
|
+
// (`JSONCodecOptions` and the decode half are declared in
|
|
128
|
+
// serializer-decode.d.ts and re-exported above.)
|
|
93
129
|
|
|
94
130
|
/**
|
|
95
|
-
* Options
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* client/server `codec` config option.
|
|
131
|
+
* Options for `serializeJSON`.
|
|
132
|
+
*
|
|
133
|
+
* Integration-facing; may change (see the entry banner).
|
|
99
134
|
*/
|
|
100
|
-
export interface JSONCodecOptions {
|
|
101
|
-
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
102
|
-
plugins?: SerializerPlugin[];
|
|
103
|
-
/**
|
|
104
|
-
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
105
|
-
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
106
|
-
* Outside development, the encoding side additionally strips
|
|
107
|
-
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
108
|
-
* server paths to the client. Decoding stays permissive, so payloads from
|
|
109
|
-
* a development peer still round-trip.
|
|
110
|
-
*/
|
|
111
|
-
disabledFeatures?: number;
|
|
112
|
-
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
113
|
-
depthLimit?: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Options for `serializeJSON`. */
|
|
117
135
|
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
136
|
/**
|
|
119
137
|
* Receives each serialized node; `initial` is true for the first chunk
|
|
@@ -132,26 +150,33 @@ export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
|
132
150
|
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
151
|
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
152
|
* function that aborts pending async serialization.
|
|
153
|
+
*
|
|
154
|
+
* Integration-facing; may change (see the entry banner).
|
|
135
155
|
*/
|
|
136
156
|
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
157
|
|
|
138
|
-
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
/** Options for `createJSONSerializer`. */
|
|
159
|
+
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Receives each keyed record — `initial` is true for a key's first node
|
|
162
|
+
* (the written value itself); async values patch through later records
|
|
163
|
+
* under the same key. The decoding peer is `createJSONDataTable`.
|
|
164
|
+
*/
|
|
165
|
+
onData: (record: { key: string; node: SerovalNode; initial: boolean }) => void;
|
|
166
|
+
onError?: (error: unknown) => void;
|
|
167
|
+
/** Fires once `flush()` has been called and every pending value settled. */
|
|
168
|
+
onDone?: () => void;
|
|
169
|
+
}
|
|
146
170
|
|
|
147
171
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* (
|
|
172
|
+
* The keyed, streaming encoder of the eval-free JSON codec — the render
|
|
173
|
+
* stream's data serializer (frames default to it). Each `write(key, value)`
|
|
174
|
+
* shares one reference space, so cross-record identity holds; `flush()`
|
|
175
|
+
* marks the write set complete (writes after it are dropped, mirroring the
|
|
176
|
+
* hydration serializer); `close()` aborts pending async serialization.
|
|
152
177
|
*/
|
|
153
|
-
export
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
export function createJSONSerializer(options: JSONSerializerOptions): {
|
|
179
|
+
write(key: string, value: unknown): void;
|
|
180
|
+
flush(): void;
|
|
181
|
+
close(): void;
|
|
182
|
+
};
|
|
@@ -22,9 +22,31 @@ import type { Element as SolidElement } from "solid-js";
|
|
|
22
22
|
* re-creates everything. It is occurrence identity, not client data: it is
|
|
23
23
|
* stripped before the client component sees its props. Positional identity is
|
|
24
24
|
* the right default; `$key` matters when a live list reorders.
|
|
25
|
+
* @experimental
|
|
25
26
|
*/
|
|
26
27
|
export type Slot<P = {}> = (props: P & {
|
|
27
28
|
$key?: string | number;
|
|
28
29
|
}) => SolidElement;
|
|
30
|
+
/**
|
|
31
|
+
* Types an async value crossing the slot border (DR-2, value tier). What you
|
|
32
|
+
* pass is what ships — the promise / async iterable itself rides the data
|
|
33
|
+
* channel — but the client's prop READ settles: it suspends into the covering
|
|
34
|
+
* boundary until first arrival (a promise's resolution, an iterable's first
|
|
35
|
+
* yield), then reads as the settled value, updating per yield for iterables.
|
|
36
|
+
*
|
|
37
|
+
* `asyncArg` is the type-level statement of that contract: identity at
|
|
38
|
+
* runtime, settled type at the border, so `Slot<P>` keeps the fill's props
|
|
39
|
+
* truthful to what its reads actually return.
|
|
40
|
+
*
|
|
41
|
+
* Slots render as JSX — the compiler wraps each prop in a getter so the read
|
|
42
|
+
* defers to the slot border, where the runtime owns it. A call form
|
|
43
|
+
* (`props.status({ … })`) evaluates its args eagerly in the component body —
|
|
44
|
+
* a top-level read, an error in most cases.
|
|
45
|
+
*
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <props.status progress={asyncArg(gen.progress)} stats={asyncArg(gen.stats)} />
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function asyncArg<T>(value: PromiseLike<T> | AsyncIterable<T>): T;
|
|
29
51
|
export { renderToFrameStream, renderServerComponent, serverComponentResponse, frameTransformResult, frameTransformFlightResult, createFrameSink, frameTransformDirectResult, ServerComponentPlugin, SERVER_COMPONENT_BOOTSTRAP } from "./frame-sink.cjs";
|
|
30
52
|
export { FRAME_STREAM_HEADER, isFrameStreamResponse } from "./frame-transport.cjs";
|
package/types-cjs/index.d.cts
CHANGED
|
@@ -96,9 +96,8 @@ export declare function render(code: () => JSX.Element, element: MountableElemen
|
|
|
96
96
|
* and reactive bindings without reconstructing the DOM. Returns a `dispose`
|
|
97
97
|
* function that tears down reactive scopes (DOM nodes are left in place).
|
|
98
98
|
*
|
|
99
|
-
* Use this when the page HTML was produced by `renderToString
|
|
100
|
-
* `
|
|
101
|
-
* `render` instead.
|
|
99
|
+
* Use this when the page HTML was produced by `renderToString` or
|
|
100
|
+
* `renderToStream`. For client-only apps, use `render` instead.
|
|
102
101
|
*
|
|
103
102
|
* Pass `options.renderId` to hydrate one of multiple roots emitted by a
|
|
104
103
|
* server render that used the same id.
|
package/types-cjs/response.d.cts
CHANGED
|
@@ -49,6 +49,51 @@ export interface Href {
|
|
|
49
49
|
*/
|
|
50
50
|
export function isHref(value: unknown): value is Href;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Registered-symbol brand (`Symbol.for("solid.SafeError")`) marking a thrown
|
|
54
|
+
* value as safe to serialize to the client verbatim. Declared `unique
|
|
55
|
+
* symbol` type-side; the runtime value is the registered symbol, so
|
|
56
|
+
* separately bundled copies agree on identity.
|
|
57
|
+
*/
|
|
58
|
+
export declare const SAFE_ERROR: unique symbol;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Marks `error` as safe to serialize to the client verbatim, opting it out
|
|
62
|
+
* of the server-function handler's production error sanitization.
|
|
63
|
+
*
|
|
64
|
+
* By default a plain `Error` thrown from a server function is sanitized to a
|
|
65
|
+
* generic `Error` outside the dev build (the `development` export condition
|
|
66
|
+
* selects the full-fidelity copy; every other resolution sanitizes):
|
|
67
|
+
* its `message`, `stack`, and own-properties are dropped so a driver/ORM
|
|
68
|
+
* error can't leak a failing query or connection string over the wire.
|
|
69
|
+
* Dev builds keep full fidelity. This is the escape hatch for errors whose
|
|
70
|
+
* content is *intentional* client-facing information — brand them and their
|
|
71
|
+
* message/properties travel intact in every environment.
|
|
72
|
+
*
|
|
73
|
+
* The brand is a non-enumerable, symbol-keyed property, so it never itself
|
|
74
|
+
* serializes as an own-property. Sets the brand and returns the same value.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { markSafeError } from "@solidjs/web";
|
|
79
|
+
*
|
|
80
|
+
* async function transfer(amount: number) {
|
|
81
|
+
* "use server";
|
|
82
|
+
* if (amount > balance) {
|
|
83
|
+
* // The user must see this message; opt out of sanitization.
|
|
84
|
+
* throw markSafeError(new Error("Insufficient funds"));
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function markSafeError<E>(error: E): E;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Whether `value` is branded safe to serialize (via `markSafeError`).
|
|
93
|
+
* Registered-symbol check, correct across duplicated module instances.
|
|
94
|
+
*/
|
|
95
|
+
export function isSafeError(value: unknown): value is Error;
|
|
96
|
+
|
|
52
97
|
/**
|
|
53
98
|
* Response header naming the cache keys a mutation invalidated
|
|
54
99
|
* (`"X-Revalidate"`), comma separated. The response helpers below set it
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// The DECODE half of the serialization surface (published as
|
|
2
|
+
// `@solidjs/web/serialization/decode`): what reading a serialized payload
|
|
3
|
+
// needs — `fromCrossJSON`-backed deserializers and the shared plugin set —
|
|
4
|
+
// with none of the encode machinery. Lazy client consumers (the frames
|
|
5
|
+
// data tables, `deserializeStream`) load this module so the encode half
|
|
6
|
+
// never ships to a browser that only reads. The full serializer.d.ts
|
|
7
|
+
// re-exports everything here; see its banner for the stability contract
|
|
8
|
+
// (integration-facing, exempt from the 2.0 stability guarantee).
|
|
9
|
+
// ---- Plugin types ----
|
|
10
|
+
//
|
|
11
|
+
// Declared here by hand (seroval's published d.ts use extensionless
|
|
12
|
+
// ESM-relative imports that `moduleResolution: "nodenext"` cannot follow —
|
|
13
|
+
// a bare type re-export would silently degrade the surface to `any` under
|
|
14
|
+
// skipLibCheck, and an import would make every entry whose types reach
|
|
15
|
+
// this module — the MAIN client entry included, via the server-function
|
|
16
|
+
// seam's `JSONCodecOptions` — unimportable from a strict Node16 CJS
|
|
17
|
+
// consumer). The declarations mirror seroval ~1.5 exactly; the `~` pin is
|
|
18
|
+
// what makes mirroring safe. Plugin AUTHORING (`createPlugin`,
|
|
19
|
+
// `OpaqueReference`) lives on the full serialization entry.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
23
|
+
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
24
|
+
* Declared by hand like the plugin types below (same rationale): the
|
|
25
|
+
* observable envelope — a numeric type tag, an optional reference id —
|
|
26
|
+
* with the rest owned by the codec. Real seroval nodes satisfy it; treat
|
|
27
|
+
* it as an opaque token.
|
|
28
|
+
*
|
|
29
|
+
* Integration-facing; may change (see the entry banner).
|
|
30
|
+
*/
|
|
31
|
+
export interface SerovalNode {
|
|
32
|
+
/** Node type tag (seroval-internal enum). */
|
|
33
|
+
t: number;
|
|
34
|
+
/** Reference id, when the node participates in cross-referencing. */
|
|
35
|
+
i?: number | undefined;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Per-plugin bookkeeping seroval hands each plugin callback. */
|
|
40
|
+
export interface PluginData {
|
|
41
|
+
id: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The shape of a plugin's parsed payload: a map of `SerovalNode`s produced
|
|
46
|
+
* by the parse contexts, consumed by `serialize`/`deserialize`.
|
|
47
|
+
*/
|
|
48
|
+
export type PluginInfo = { [key: string]: SerovalNode };
|
|
49
|
+
|
|
50
|
+
/** Parse context for `parse.sync`: turns child values into nodes. */
|
|
51
|
+
export interface SyncParsePluginContext {
|
|
52
|
+
parse<T>(current: T): SerovalNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Parse context for `parse.async`: like sync, but child parses await. */
|
|
56
|
+
export interface AsyncParsePluginContext {
|
|
57
|
+
parse<T>(current: T): Promise<SerovalNode>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse context for `parse.stream`: sync parsing plus the streaming
|
|
62
|
+
* lifecycle (pending-state tracking, late node emission, cleanup).
|
|
63
|
+
*/
|
|
64
|
+
export interface StreamParsePluginContext {
|
|
65
|
+
parse<T>(current: T): SerovalNode;
|
|
66
|
+
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
67
|
+
isAlive(): boolean;
|
|
68
|
+
pushPendingState(): void;
|
|
69
|
+
popPendingState(): void;
|
|
70
|
+
onParse(node: SerovalNode): void;
|
|
71
|
+
onError(error: unknown): void;
|
|
72
|
+
addCleanup(callback: () => void): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Serialize context: renders child nodes to JS source. */
|
|
76
|
+
export interface SerializePluginContext {
|
|
77
|
+
serialize(node: SerovalNode): string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Deserialize context: revives child nodes to runtime values. */
|
|
81
|
+
export interface DeserializePluginContext {
|
|
82
|
+
deserialize<T>(node: SerovalNode): T;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
87
|
+
* to encode/decode a custom value type (`Value` is the value it matches,
|
|
88
|
+
* `Info` its parsed payload). Supply matching plugins on both peers of a
|
|
89
|
+
* transport. Bare `SerializerPlugin` (both parameters defaulted to `any`)
|
|
90
|
+
* is the list-element type every `plugins` option accepts.
|
|
91
|
+
*
|
|
92
|
+
* Integration-facing; may change (see the entry banner).
|
|
93
|
+
*/
|
|
94
|
+
export interface SerializerPlugin<Value = any, Info extends PluginInfo = any> {
|
|
95
|
+
/** A unique string identifying the plugin — namespace it (`"app/Thing"`). */
|
|
96
|
+
tag: string;
|
|
97
|
+
/** Dependency plugins, resolved ahead of this one. */
|
|
98
|
+
extends?: SerializerPlugin[];
|
|
99
|
+
/** Whether `value` is this plugin's to encode. */
|
|
100
|
+
test(value: unknown): boolean;
|
|
101
|
+
/** Parsing modes — provide the ones the transports you target use. */
|
|
102
|
+
parse: {
|
|
103
|
+
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
104
|
+
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
105
|
+
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
106
|
+
};
|
|
107
|
+
/** Renders the parsed payload as JS source (script-injection form). */
|
|
108
|
+
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
109
|
+
/** Revives the parsed payload back into the runtime value. */
|
|
110
|
+
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
115
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
116
|
+
* Applied by every serializer in this module; custom plugins compose ahead
|
|
117
|
+
* of it via `resolveSerializerPlugins`.
|
|
118
|
+
*
|
|
119
|
+
* Integration-facing; may change (see the entry banner).
|
|
120
|
+
*/
|
|
121
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
125
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
126
|
+
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
127
|
+
* plugin list to another serialization layer.
|
|
128
|
+
*
|
|
129
|
+
* Integration-facing; may change (see the entry banner).
|
|
130
|
+
*/
|
|
131
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
135
|
+
* on the serializing and deserializing peer or payloads will not
|
|
136
|
+
* round-trip — for server functions, set them once through the
|
|
137
|
+
* client/server `codec` config option.
|
|
138
|
+
*
|
|
139
|
+
* Integration-facing; may change (see the entry banner).
|
|
140
|
+
*/
|
|
141
|
+
export interface JSONCodecOptions {
|
|
142
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
143
|
+
plugins?: SerializerPlugin[];
|
|
144
|
+
/**
|
|
145
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
146
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
147
|
+
* Outside development, the encoding side additionally strips
|
|
148
|
+
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
149
|
+
* server paths to the client. Decoding stays permissive, so payloads from
|
|
150
|
+
* a development peer still round-trip.
|
|
151
|
+
*/
|
|
152
|
+
disabledFeatures?: number;
|
|
153
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
154
|
+
depthLimit?: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
159
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
160
|
+
* from one stream must go through the same deserializer instance. The first
|
|
161
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
162
|
+
* settles the async values referenced inside it.
|
|
163
|
+
*
|
|
164
|
+
* Integration-facing; may change (see the entry banner).
|
|
165
|
+
*/
|
|
166
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
170
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
171
|
+
* `resolve`. The frames client host wires one per response
|
|
172
|
+
* (`applyData: c => table.apply(c)`).
|
|
173
|
+
*
|
|
174
|
+
* Integration-facing; may change (see the entry banner). This serialization
|
|
175
|
+
* entry is the single home of the data table — the frames client consumes
|
|
176
|
+
* it internally rather than re-exporting it.
|
|
177
|
+
*/
|
|
178
|
+
export interface JSONDataTable {
|
|
179
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
180
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
181
|
+
}
|
|
182
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -1,35 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
// Serialization surface (published as `@solidjs/web/serialization`): the
|
|
2
|
+
// runtime's Seroval machinery, exposed for the runtime's own entries and
|
|
3
|
+
// for integrations building transports on the same codec. This is
|
|
4
|
+
// INTEGRATION-FACING plumbing, not application API — it is exempt from the
|
|
5
|
+
// 2.0 stability guarantee and may change between releases. Application and
|
|
6
|
+
// router code should configure `codec` on the server-function entries
|
|
7
|
+
// instead of importing from here.
|
|
8
|
+
import type { Serializer } from "seroval";
|
|
9
|
+
import {
|
|
10
|
+
JSONCodecOptions,
|
|
11
|
+
PluginInfo,
|
|
12
|
+
SerializerPlugin,
|
|
13
|
+
SerovalNode
|
|
14
|
+
} from "./serializer-decode.cjs";
|
|
2
15
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
16
|
+
// The decode half — `SerovalNode`, the plugin TYPES, `DEFAULT_WEB_PLUGINS`,
|
|
17
|
+
// `resolveSerializerPlugins`, `JSONCodecOptions`, `createJSONDeserializer`,
|
|
18
|
+
// `createJSONDataTable` — is declared in serializer-decode.d.ts (published
|
|
19
|
+
// as `@solidjs/web/serialization/decode`, the module lazy client consumers
|
|
20
|
+
// load) and re-exported here so this remains the full surface.
|
|
21
|
+
export * from "./serializer-decode.cjs";
|
|
22
|
+
|
|
23
|
+
// ---- Plugin authoring ----
|
|
24
|
+
//
|
|
25
|
+
// Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
|
|
26
|
+
// it is the supported way to feed the serializers' `plugins` options and
|
|
27
|
+
// the server-function entries' `codec.plugins`. The values re-export
|
|
28
|
+
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
29
|
+
// the plugin TYPES live in serializer-decode.d.ts (hand-declared there —
|
|
30
|
+
// see its banner for why).
|
|
8
31
|
|
|
9
32
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
33
|
+
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
34
|
+
* plugin authors stay on the exact seroval instance/version the runtime
|
|
35
|
+
* serializes with. Import it from HERE, not from your own `seroval`
|
|
36
|
+
* dependency: a plugin built against a different copy/version would not
|
|
37
|
+
* fail the build — it would emit nodes the other peer can't interpret.
|
|
38
|
+
*
|
|
39
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
13
40
|
*/
|
|
14
|
-
export
|
|
41
|
+
export function createPlugin<Value, Info extends PluginInfo>(
|
|
42
|
+
plugin: SerializerPlugin<Value, Info>
|
|
43
|
+
): SerializerPlugin<Value, Info>;
|
|
15
44
|
|
|
16
45
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
46
|
+
* Seroval's `OpaqueReference`, re-exported from the runtime's own instance
|
|
47
|
+
* (an `OpaqueReference` from another seroval copy fails the serializer's
|
|
48
|
+
* instanceof check and serializes as a plain value): wraps a value so it
|
|
49
|
+
* crosses the wire as its `replacement` (default `undefined`) while
|
|
50
|
+
* staying readable in-process through `.value`.
|
|
51
|
+
*
|
|
52
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
21
53
|
*/
|
|
22
|
-
export
|
|
54
|
+
export class OpaqueReference<V, R = undefined> {
|
|
55
|
+
readonly value: V;
|
|
56
|
+
readonly replacement?: R;
|
|
57
|
+
constructor(value: V, replacement?: R);
|
|
58
|
+
}
|
|
23
59
|
|
|
24
60
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* plugin list to another serialization layer.
|
|
61
|
+
* Options for `createSerializer`.
|
|
62
|
+
*
|
|
63
|
+
* Integration-facing; may change (see the entry banner).
|
|
29
64
|
*/
|
|
30
|
-
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
|
-
|
|
32
|
-
/** Options for `createSerializer`. */
|
|
33
65
|
export interface WebSerializerOptions {
|
|
34
66
|
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
67
|
globalIdentifier: string;
|
|
@@ -58,6 +90,8 @@ export interface WebSerializerOptions {
|
|
|
58
90
|
* evaluated — the script-injection form of serialization renderers build
|
|
59
91
|
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
92
|
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
93
|
+
*
|
|
94
|
+
* Integration-facing; may change (see the entry banner).
|
|
61
95
|
*/
|
|
62
96
|
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
97
|
|
|
@@ -90,30 +124,14 @@ export function createHydrationSerializer(options: HydrationSerializerOptions):
|
|
|
90
124
|
export function getLocalHeaderScript(id?: string): string;
|
|
91
125
|
|
|
92
126
|
// ---- JSON codec (server function transports) ----
|
|
127
|
+
// (`JSONCodecOptions` and the decode half are declared in
|
|
128
|
+
// serializer-decode.d.ts and re-exported above.)
|
|
93
129
|
|
|
94
130
|
/**
|
|
95
|
-
* Options
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* client/server `codec` config option.
|
|
131
|
+
* Options for `serializeJSON`.
|
|
132
|
+
*
|
|
133
|
+
* Integration-facing; may change (see the entry banner).
|
|
99
134
|
*/
|
|
100
|
-
export interface JSONCodecOptions {
|
|
101
|
-
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
102
|
-
plugins?: SerializerPlugin[];
|
|
103
|
-
/**
|
|
104
|
-
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
105
|
-
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
106
|
-
* Outside development, the encoding side additionally strips
|
|
107
|
-
* `Error.prototype.stack` on top of any override — serialized stacks leak
|
|
108
|
-
* server paths to the client. Decoding stays permissive, so payloads from
|
|
109
|
-
* a development peer still round-trip.
|
|
110
|
-
*/
|
|
111
|
-
disabledFeatures?: number;
|
|
112
|
-
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
113
|
-
depthLimit?: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Options for `serializeJSON`. */
|
|
117
135
|
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
136
|
/**
|
|
119
137
|
* Receives each serialized node; `initial` is true for the first chunk
|
|
@@ -132,26 +150,33 @@ export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
|
132
150
|
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
151
|
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
152
|
* function that aborts pending async serialization.
|
|
153
|
+
*
|
|
154
|
+
* Integration-facing; may change (see the entry banner).
|
|
135
155
|
*/
|
|
136
156
|
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
157
|
|
|
138
|
-
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
/** Options for `createJSONSerializer`. */
|
|
159
|
+
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
160
|
+
/**
|
|
161
|
+
* Receives each keyed record — `initial` is true for a key's first node
|
|
162
|
+
* (the written value itself); async values patch through later records
|
|
163
|
+
* under the same key. The decoding peer is `createJSONDataTable`.
|
|
164
|
+
*/
|
|
165
|
+
onData: (record: { key: string; node: SerovalNode; initial: boolean }) => void;
|
|
166
|
+
onError?: (error: unknown) => void;
|
|
167
|
+
/** Fires once `flush()` has been called and every pending value settled. */
|
|
168
|
+
onDone?: () => void;
|
|
169
|
+
}
|
|
146
170
|
|
|
147
171
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* (
|
|
172
|
+
* The keyed, streaming encoder of the eval-free JSON codec — the render
|
|
173
|
+
* stream's data serializer (frames default to it). Each `write(key, value)`
|
|
174
|
+
* shares one reference space, so cross-record identity holds; `flush()`
|
|
175
|
+
* marks the write set complete (writes after it are dropped, mirroring the
|
|
176
|
+
* hydration serializer); `close()` aborts pending async serialization.
|
|
152
177
|
*/
|
|
153
|
-
export
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
export function createJSONSerializer(options: JSONSerializerOptions): {
|
|
179
|
+
write(key: string, value: unknown): void;
|
|
180
|
+
flush(): void;
|
|
181
|
+
close(): void;
|
|
182
|
+
};
|