@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.
- package/README.md +27 -4
- package/dist/dev.cjs +1211 -205
- package/dist/dev.js +1175 -199
- package/dist/server.cjs +1342 -234
- package/dist/server.js +1304 -231
- package/dist/web.cjs +1195 -196
- package/dist/web.js +1159 -190
- package/frames/dist/client.cjs +1746 -0
- package/frames/dist/client.dev.cjs +1759 -0
- package/frames/dist/client.dev.js +1747 -0
- package/frames/dist/client.js +1734 -0
- package/frames/dist/server.cjs +2426 -0
- package/frames/dist/server.js +2414 -0
- package/frames/package.json +30 -0
- package/package.json +287 -38
- package/serialization/dist/serialization.cjs +169 -0
- package/serialization/dist/serialization.js +159 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +157 -0
- package/serialization/types-cjs/index.d.cts +157 -0
- package/serialization/types-cjs/package.json +3 -0
- package/server-functions/dist/client.cjs +613 -0
- package/server-functions/dist/client.js +585 -0
- package/server-functions/dist/server.cjs +904 -0
- package/server-functions/dist/server.js +875 -0
- package/server-functions/package.json +30 -0
- package/storage/package.json +8 -3
- package/storage/types/index.d.ts +26 -0
- package/storage/types-cjs/index.d.cts +28 -0
- package/storage/types-cjs/package.json +3 -0
- package/types/client.d.ts +125 -21
- package/types/core.d.ts +4 -3
- package/types/frames/client.d.ts +20 -0
- package/types/frames/frame-client.d.ts +270 -0
- package/types/frames/frame-sink.d.ts +168 -0
- package/types/frames/frame-transport.d.ts +196 -0
- package/types/frames/serializer.d.ts +157 -0
- package/types/frames/server.d.ts +30 -0
- package/types/index.d.ts +211 -26
- package/types/jsx-properties.d.ts +93 -0
- package/types/jsx.d.ts +4150 -1
- package/types/response.d.ts +129 -0
- package/types/serializer.d.ts +157 -0
- package/types/server-functions/client.d.ts +200 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/server.d.ts +490 -0
- package/types/server-functions/shared.d.ts +445 -0
- package/types/server-mock.d.ts +93 -0
- package/types/server.d.ts +221 -28
- package/types-cjs/client.d.cts +192 -0
- package/types-cjs/core.d.cts +4 -0
- package/types-cjs/frames/client.d.cts +20 -0
- package/types-cjs/frames/frame-client.d.cts +270 -0
- package/types-cjs/frames/frame-sink.d.cts +168 -0
- package/types-cjs/frames/frame-transport.d.cts +196 -0
- package/types-cjs/frames/serializer.d.cts +157 -0
- package/types-cjs/frames/server.d.cts +30 -0
- package/types-cjs/index.d.cts +231 -0
- package/types-cjs/jsx-properties.d.cts +93 -0
- package/types-cjs/jsx.d.cts +4150 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/response.d.cts +129 -0
- package/types-cjs/serializer.d.cts +157 -0
- package/types-cjs/server-functions/client.d.cts +200 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/server.d.cts +490 -0
- package/types-cjs/server-functions/shared.d.cts +445 -0
- package/types-cjs/server-mock.d.cts +165 -0
- package/types-cjs/server.d.cts +349 -0
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -46
- package/storage/types/src/server-mock.d.ts +0 -72
- package/storage/types/storage/src/index.d.ts +0 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Feature, Serializer, getCrossReferenceHeader, toCrossJSONStream, fromCrossJSON } from 'seroval';
|
|
2
|
+
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
3
|
+
|
|
4
|
+
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
5
|
+
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
|
|
6
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
7
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
8
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
9
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
|
|
10
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
11
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
12
|
+
}
|
|
13
|
+
function createSerializer(options) {
|
|
14
|
+
return new Serializer({
|
|
15
|
+
...options,
|
|
16
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
17
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function createHydrationSerializer({
|
|
21
|
+
onData,
|
|
22
|
+
onDone,
|
|
23
|
+
scopeId,
|
|
24
|
+
onError,
|
|
25
|
+
plugins
|
|
26
|
+
}) {
|
|
27
|
+
return createSerializer({
|
|
28
|
+
scopeId,
|
|
29
|
+
plugins,
|
|
30
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
31
|
+
onData,
|
|
32
|
+
onDone,
|
|
33
|
+
onError
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function getLocalHeaderScript(id) {
|
|
37
|
+
return getCrossReferenceHeader(id) + ";";
|
|
38
|
+
}
|
|
39
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
40
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
41
|
+
function resolveCodecOptions({
|
|
42
|
+
plugins,
|
|
43
|
+
disabledFeatures,
|
|
44
|
+
depthLimit
|
|
45
|
+
} = {}) {
|
|
46
|
+
return {
|
|
47
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
48
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
49
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function serializeJSON(value, {
|
|
53
|
+
onParse,
|
|
54
|
+
onDone,
|
|
55
|
+
onError,
|
|
56
|
+
...codecOptions
|
|
57
|
+
}) {
|
|
58
|
+
const resolved = resolveCodecOptions(codecOptions);
|
|
59
|
+
return toCrossJSONStream(value, {
|
|
60
|
+
onParse,
|
|
61
|
+
onDone,
|
|
62
|
+
onError,
|
|
63
|
+
...resolved,
|
|
64
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function createJSONDeserializer(options) {
|
|
68
|
+
const refs = new Map();
|
|
69
|
+
const resolved = resolveCodecOptions(options);
|
|
70
|
+
return function deserializeJSONChunk(node) {
|
|
71
|
+
return fromCrossJSON(node, {
|
|
72
|
+
refs,
|
|
73
|
+
...resolved
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createJSONSerializer({
|
|
78
|
+
onData,
|
|
79
|
+
onDone,
|
|
80
|
+
onError,
|
|
81
|
+
plugins,
|
|
82
|
+
disabledFeatures,
|
|
83
|
+
depthLimit
|
|
84
|
+
}) {
|
|
85
|
+
const resolved = resolveCodecOptions({
|
|
86
|
+
plugins,
|
|
87
|
+
disabledFeatures,
|
|
88
|
+
depthLimit
|
|
89
|
+
});
|
|
90
|
+
const refs = new Map();
|
|
91
|
+
const cancels = new Set();
|
|
92
|
+
let pendingWrites = 0;
|
|
93
|
+
let flushed = false;
|
|
94
|
+
let done = false;
|
|
95
|
+
const maybeDone = () => {
|
|
96
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
97
|
+
done = true;
|
|
98
|
+
onDone && onDone();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
write(key, value) {
|
|
103
|
+
if (flushed) return;
|
|
104
|
+
pendingWrites++;
|
|
105
|
+
let settled = false;
|
|
106
|
+
let cancel = null;
|
|
107
|
+
const stream = toCrossJSONStream(value, {
|
|
108
|
+
refs,
|
|
109
|
+
plugins: resolved.plugins,
|
|
110
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
|
|
111
|
+
onParse(node, initial) {
|
|
112
|
+
onData({
|
|
113
|
+
key,
|
|
114
|
+
node,
|
|
115
|
+
initial
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
onError,
|
|
119
|
+
onDone() {
|
|
120
|
+
settled = true;
|
|
121
|
+
if (cancel) cancels.delete(cancel);
|
|
122
|
+
pendingWrites--;
|
|
123
|
+
maybeDone();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (!settled) {
|
|
127
|
+
cancel = stream;
|
|
128
|
+
cancels.add(cancel);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
flush() {
|
|
132
|
+
flushed = true;
|
|
133
|
+
maybeDone();
|
|
134
|
+
},
|
|
135
|
+
close() {
|
|
136
|
+
flushed = true;
|
|
137
|
+
for (const cancel of cancels) cancel();
|
|
138
|
+
cancels.clear();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function createJSONDataTable(options) {
|
|
143
|
+
const deserialize = createJSONDeserializer(options);
|
|
144
|
+
const table = new Map();
|
|
145
|
+
return {
|
|
146
|
+
apply(record) {
|
|
147
|
+
const value = deserialize(record.node);
|
|
148
|
+
if (record.initial) table.set(record.key, value);
|
|
149
|
+
},
|
|
150
|
+
get(key) {
|
|
151
|
+
return table.get(key);
|
|
152
|
+
},
|
|
153
|
+
resolve(ref) {
|
|
154
|
+
return table.get(ref.$ref);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { DEFAULT_WEB_PLUGINS, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createSerializer, getLocalHeaderScript, resolveSerializerPlugins, serializeJSON };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solidjs/web/serialization",
|
|
3
|
+
"main": "./dist/serialization.cjs",
|
|
4
|
+
"module": "./dist/serialization.js",
|
|
5
|
+
"types": "./types/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"default": "./dist/serialization.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./types-cjs/index.d.cts",
|
|
16
|
+
"default": "./dist/serialization.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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). Outside
|
|
41
|
+
* development, `Error.prototype.stack` is additionally stripped on top of
|
|
42
|
+
* any override — serialized stacks leak server paths to the client.
|
|
43
|
+
*/
|
|
44
|
+
disabledFeatures?: number;
|
|
45
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
46
|
+
plugins?: SerializerPlugin[];
|
|
47
|
+
/** Receives each emitted script chunk. */
|
|
48
|
+
onData: (result: string) => void;
|
|
49
|
+
onError?: (error: unknown) => void;
|
|
50
|
+
/** Fires once all async values have settled. */
|
|
51
|
+
onDone?: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
56
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
57
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
58
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
59
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
61
|
+
*/
|
|
62
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
66
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type HydrationSerializerOptions = Omit<
|
|
70
|
+
WebSerializerOptions,
|
|
71
|
+
"globalIdentifier" | "disabledFeatures"
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
76
|
+
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
77
|
+
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
78
|
+
* for hand-written code — custom serialization should use
|
|
79
|
+
* `createSerializer` or the JSON codec.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
86
|
+
* emits ahead of hydration data for a render scope. Not meant for
|
|
87
|
+
* hand-written code.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
91
|
+
|
|
92
|
+
// ---- JSON codec (server function transports) ----
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
96
|
+
* on the serializing and deserializing peer or payloads will not
|
|
97
|
+
* round-trip — for server functions, set them once through the
|
|
98
|
+
* client/server `codec` config option.
|
|
99
|
+
*/
|
|
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
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
120
|
+
* (the source value itself). Async values produce additional chunks as
|
|
121
|
+
* they resolve.
|
|
122
|
+
*/
|
|
123
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
124
|
+
onError?: (error: unknown) => void;
|
|
125
|
+
/** Fires once all async values have settled. */
|
|
126
|
+
onDone?: () => void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
131
|
+
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
132
|
+
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
|
+
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
|
+
* function that aborts pending async serialization.
|
|
135
|
+
*/
|
|
136
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
140
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
141
|
+
* from one stream must go through the same deserializer instance. The first
|
|
142
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
143
|
+
* settles the async values referenced inside it.
|
|
144
|
+
*/
|
|
145
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
149
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
150
|
+
* `resolve`. The frames client host wires one per response
|
|
151
|
+
* (`applyData: c => table.apply(c)`).
|
|
152
|
+
*/
|
|
153
|
+
export interface JSONDataTable {
|
|
154
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
155
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
156
|
+
}
|
|
157
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|
|
@@ -0,0 +1,157 @@
|
|
|
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). Outside
|
|
41
|
+
* development, `Error.prototype.stack` is additionally stripped on top of
|
|
42
|
+
* any override — serialized stacks leak server paths to the client.
|
|
43
|
+
*/
|
|
44
|
+
disabledFeatures?: number;
|
|
45
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
46
|
+
plugins?: SerializerPlugin[];
|
|
47
|
+
/** Receives each emitted script chunk. */
|
|
48
|
+
onData: (result: string) => void;
|
|
49
|
+
onError?: (error: unknown) => void;
|
|
50
|
+
/** Fires once all async values have settled. */
|
|
51
|
+
onDone?: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
56
|
+
* set and the default feature policy. Emits JavaScript chunks (through
|
|
57
|
+
* `onData`) that reconstruct the values under `globalIdentifier` when
|
|
58
|
+
* evaluated — the script-injection form of serialization renderers build
|
|
59
|
+
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
|
+
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
61
|
+
*/
|
|
62
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Options for `createHydrationSerializer` — `WebSerializerOptions` minus
|
|
66
|
+
* the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export type HydrationSerializerOptions = Omit<
|
|
70
|
+
WebSerializerOptions,
|
|
71
|
+
"globalIdentifier" | "disabledFeatures"
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Renderer primitive — the serializer SSR uses for hydration output. Pins
|
|
76
|
+
* the hydration global (`_$HY.r`) and feature policy; only the wiring
|
|
77
|
+
* options (callbacks, scope, extra plugins) are configurable. Not meant
|
|
78
|
+
* for hand-written code — custom serialization should use
|
|
79
|
+
* `createSerializer` or the JSON codec.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Renderer primitive — returns the cross-reference bootstrap script SSR
|
|
86
|
+
* emits ahead of hydration data for a render scope. Not meant for
|
|
87
|
+
* hand-written code.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
91
|
+
|
|
92
|
+
// ---- JSON codec (server function transports) ----
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Options shared by both halves of the JSON codec. All of them must match
|
|
96
|
+
* on the serializing and deserializing peer or payloads will not
|
|
97
|
+
* round-trip — for server functions, set them once through the
|
|
98
|
+
* client/server `codec` config option.
|
|
99
|
+
*/
|
|
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
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
120
|
+
* (the source value itself). Async values produce additional chunks as
|
|
121
|
+
* they resolve.
|
|
122
|
+
*/
|
|
123
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
124
|
+
onError?: (error: unknown) => void;
|
|
125
|
+
/** Fires once all async values have settled. */
|
|
126
|
+
onDone?: () => void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse` —
|
|
131
|
+
* the encoding half of the eval-free JSON codec (RPC-style transports;
|
|
132
|
+
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
|
+
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
|
+
* function that aborts pending async serialization.
|
|
135
|
+
*/
|
|
136
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
140
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
141
|
+
* from one stream must go through the same deserializer instance. The first
|
|
142
|
+
* chunk's return value is the decoded source value; feeding later chunks
|
|
143
|
+
* settles the async values referenced inside it.
|
|
144
|
+
*/
|
|
145
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
149
|
+
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
150
|
+
* `resolve`. The frames client host wires one per response
|
|
151
|
+
* (`applyData: c => table.apply(c)`).
|
|
152
|
+
*/
|
|
153
|
+
export interface JSONDataTable {
|
|
154
|
+
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
155
|
+
resolve<T = unknown>(ref: { $ref: string }): T;
|
|
156
|
+
}
|
|
157
|
+
export function createJSONDataTable(options?: JSONCodecOptions): JSONDataTable;
|