@solidjs/web 2.0.0-beta.17 → 2.0.0-beta.18
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/dist/dev.cjs +26 -12
- package/dist/dev.js +27 -13
- package/dist/server.cjs +40 -19
- package/dist/server.js +41 -20
- package/dist/web.cjs +26 -12
- package/dist/web.js +27 -13
- package/package.json +25 -10
- package/serialization/dist/serialization.cjs +83 -0
- package/serialization/dist/serialization.js +75 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +97 -0
- package/serialization/types-cjs/index.d.cts +97 -0
- package/serialization/types-cjs/package.json +3 -0
- package/types/index.d.ts +7 -1
- package/types/serializer.d.ts +97 -0
- package/types/server.d.ts +52 -15
- package/types-cjs/index.d.cts +7 -1
- package/types-cjs/serializer.d.cts +97 -0
- package/types-cjs/server.d.cts +52 -15
- package/storage/types/src/client.d.ts +0 -1
- package/storage/types/src/index.d.ts +0 -171
- package/storage/types/src/server-mock.d.ts +0 -161
- package/storage/types-cjs/src/client.d.cts +0 -1
- package/storage/types-cjs/src/index.d.cts +0 -171
- package/storage/types-cjs/src/server-mock.d.cts +0 -161
- /package/storage/types/{storage/src/index.d.ts → index.d.ts} +0 -0
- /package/storage/types-cjs/{storage/src/index.d.cts → index.d.cts} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/web",
|
|
3
3
|
"description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.18",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -27,7 +27,11 @@
|
|
|
27
27
|
"storage/dist",
|
|
28
28
|
"storage/types",
|
|
29
29
|
"storage/types-cjs",
|
|
30
|
-
"storage/package.json"
|
|
30
|
+
"storage/package.json",
|
|
31
|
+
"serialization/dist",
|
|
32
|
+
"serialization/types",
|
|
33
|
+
"serialization/types-cjs",
|
|
34
|
+
"serialization/package.json"
|
|
31
35
|
],
|
|
32
36
|
"exports": {
|
|
33
37
|
".": {
|
|
@@ -130,30 +134,41 @@
|
|
|
130
134
|
"default": "./storage/dist/storage.cjs"
|
|
131
135
|
}
|
|
132
136
|
},
|
|
137
|
+
"./serialization": {
|
|
138
|
+
"import": {
|
|
139
|
+
"types": "./serialization/types/index.d.ts",
|
|
140
|
+
"default": "./serialization/dist/serialization.js"
|
|
141
|
+
},
|
|
142
|
+
"require": {
|
|
143
|
+
"types": "./serialization/types-cjs/index.d.cts",
|
|
144
|
+
"default": "./serialization/dist/serialization.cjs"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
133
147
|
"./types/*": "./types/*"
|
|
134
148
|
},
|
|
135
149
|
"dependencies": {
|
|
136
|
-
"seroval": "
|
|
137
|
-
"seroval-plugins": "
|
|
150
|
+
"seroval": "~1.5.4",
|
|
151
|
+
"seroval-plugins": "~1.5.4"
|
|
138
152
|
},
|
|
139
153
|
"peerDependencies": {
|
|
140
|
-
"solid-js": "^2.0.0-beta.
|
|
154
|
+
"solid-js": "^2.0.0-beta.18"
|
|
141
155
|
},
|
|
142
156
|
"devDependencies": {
|
|
143
|
-
"solid-js": "2.0.0-beta.
|
|
157
|
+
"solid-js": "2.0.0-beta.18"
|
|
144
158
|
},
|
|
145
159
|
"scripts": {
|
|
146
160
|
"build": "npm-run-all -nl build:clean types:copy-jsx build:js",
|
|
147
161
|
"build:clean": "rimraf dist/",
|
|
148
162
|
"build:js": "rollup -c",
|
|
149
163
|
"link": "symlink-dir . node_modules/@solidjs/web",
|
|
150
|
-
"types": "npm-run-all -nl types:clean types:copy-jsx types:web types:copy-web types:web-storage types:cjs",
|
|
151
|
-
"types:clean": "rimraf types/ types-cjs/ storage/types-cjs/",
|
|
164
|
+
"types": "npm-run-all -nl types:clean types:copy-jsx types:web types:copy-web types:web-storage types:copy-serialization types:cjs",
|
|
165
|
+
"types:clean": "rimraf types/ types-cjs/ storage/types/ storage/types-cjs/ serialization/types/ serialization/types-cjs/",
|
|
152
166
|
"types:copy-jsx": "ncp ../../node_modules/@dom-expressions/runtime/src/jsx.d.ts ./src/jsx.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/jsx-properties.d.ts ./src/jsx-properties.d.ts && dom-expressions-jsx-types --input ./src/jsx.d.ts --element \"SolidElement | Node | ArrayElement\" --import 'import type { Element as SolidElement } from \"solid-js\";'",
|
|
153
167
|
"types:web": "tsc --project ./tsconfig.build.json",
|
|
154
|
-
"types:copy-web": "ncp ../../node_modules/@dom-expressions/runtime/src/client.d.ts ./types/client.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/server.d.ts ./types/server.d.ts && ncp ./src/jsx.d.ts ./types/jsx.d.ts && ncp ./src/jsx-properties.d.ts ./types/jsx-properties.d.ts",
|
|
168
|
+
"types:copy-web": "ncp ../../node_modules/@dom-expressions/runtime/src/client.d.ts ./types/client.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/server.d.ts ./types/server.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/serializer.d.ts ./types/serializer.d.ts && ncp ./src/jsx.d.ts ./types/jsx.d.ts && ncp ./src/jsx-properties.d.ts ./types/jsx-properties.d.ts",
|
|
155
169
|
"types:web-storage": "tsc --project ./storage/tsconfig.build.json",
|
|
156
|
-
"types:
|
|
170
|
+
"types:copy-serialization": "node -e \"fs.mkdirSync('./serialization/types', { recursive: true }); fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/serializer.d.ts', './serialization/types/index.d.ts');\"",
|
|
171
|
+
"types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./storage/types ./storage/types-cjs ./serialization/types ./serialization/types-cjs",
|
|
157
172
|
"test": "vitest run && vitest run --config vite.config.server.mjs && vitest run --config vite.config.hydrate.mjs",
|
|
158
173
|
"test:server": "vitest run --config vite.config.server.mjs",
|
|
159
174
|
"coverage": "vitest run --coverage",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var seroval = require('seroval');
|
|
4
|
+
var web = require('seroval-plugins/web');
|
|
5
|
+
|
|
6
|
+
const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
7
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
8
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
9
|
+
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
10
|
+
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
|
|
11
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
12
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
13
|
+
}
|
|
14
|
+
function createSerializer(options) {
|
|
15
|
+
return new seroval.Serializer({
|
|
16
|
+
...options,
|
|
17
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
18
|
+
disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function createHydrationSerializer({
|
|
22
|
+
onData,
|
|
23
|
+
onDone,
|
|
24
|
+
scopeId,
|
|
25
|
+
onError,
|
|
26
|
+
plugins
|
|
27
|
+
}) {
|
|
28
|
+
return createSerializer({
|
|
29
|
+
scopeId,
|
|
30
|
+
plugins,
|
|
31
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
32
|
+
onData,
|
|
33
|
+
onDone,
|
|
34
|
+
onError
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function getLocalHeaderScript(id) {
|
|
38
|
+
return seroval.getCrossReferenceHeader(id) + ";";
|
|
39
|
+
}
|
|
40
|
+
const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
|
|
41
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
42
|
+
function resolveCodecOptions({
|
|
43
|
+
plugins,
|
|
44
|
+
disabledFeatures,
|
|
45
|
+
depthLimit
|
|
46
|
+
} = {}) {
|
|
47
|
+
return {
|
|
48
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
49
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
50
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function serializeJSON(value, {
|
|
54
|
+
onParse,
|
|
55
|
+
onDone,
|
|
56
|
+
onError,
|
|
57
|
+
...codecOptions
|
|
58
|
+
}) {
|
|
59
|
+
return seroval.toCrossJSONStream(value, {
|
|
60
|
+
onParse,
|
|
61
|
+
onDone,
|
|
62
|
+
onError,
|
|
63
|
+
...resolveCodecOptions(codecOptions)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function createJSONDeserializer(options) {
|
|
67
|
+
const refs = new Map();
|
|
68
|
+
const resolved = resolveCodecOptions(options);
|
|
69
|
+
return function deserializeJSONChunk(node) {
|
|
70
|
+
return seroval.fromCrossJSON(node, {
|
|
71
|
+
refs,
|
|
72
|
+
...resolved
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
exports.DEFAULT_WEB_PLUGINS = DEFAULT_WEB_PLUGINS;
|
|
78
|
+
exports.createHydrationSerializer = createHydrationSerializer;
|
|
79
|
+
exports.createJSONDeserializer = createJSONDeserializer;
|
|
80
|
+
exports.createSerializer = createSerializer;
|
|
81
|
+
exports.getLocalHeaderScript = getLocalHeaderScript;
|
|
82
|
+
exports.resolveSerializerPlugins = resolveSerializerPlugins;
|
|
83
|
+
exports.serializeJSON = serializeJSON;
|
|
@@ -0,0 +1,75 @@
|
|
|
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 HYDRATION_GLOBAL = "_$HY.r";
|
|
6
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
7
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
8
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin]);
|
|
9
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
10
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
11
|
+
}
|
|
12
|
+
function createSerializer(options) {
|
|
13
|
+
return new Serializer({
|
|
14
|
+
...options,
|
|
15
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
16
|
+
disabledFeatures: options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createHydrationSerializer({
|
|
20
|
+
onData,
|
|
21
|
+
onDone,
|
|
22
|
+
scopeId,
|
|
23
|
+
onError,
|
|
24
|
+
plugins
|
|
25
|
+
}) {
|
|
26
|
+
return createSerializer({
|
|
27
|
+
scopeId,
|
|
28
|
+
plugins,
|
|
29
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
30
|
+
onData,
|
|
31
|
+
onDone,
|
|
32
|
+
onError
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function getLocalHeaderScript(id) {
|
|
36
|
+
return getCrossReferenceHeader(id) + ";";
|
|
37
|
+
}
|
|
38
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
39
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
40
|
+
function resolveCodecOptions({
|
|
41
|
+
plugins,
|
|
42
|
+
disabledFeatures,
|
|
43
|
+
depthLimit
|
|
44
|
+
} = {}) {
|
|
45
|
+
return {
|
|
46
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
47
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
48
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function serializeJSON(value, {
|
|
52
|
+
onParse,
|
|
53
|
+
onDone,
|
|
54
|
+
onError,
|
|
55
|
+
...codecOptions
|
|
56
|
+
}) {
|
|
57
|
+
return toCrossJSONStream(value, {
|
|
58
|
+
onParse,
|
|
59
|
+
onDone,
|
|
60
|
+
onError,
|
|
61
|
+
...resolveCodecOptions(codecOptions)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function createJSONDeserializer(options) {
|
|
65
|
+
const refs = new Map();
|
|
66
|
+
const resolved = resolveCodecOptions(options);
|
|
67
|
+
return function deserializeJSONChunk(node) {
|
|
68
|
+
return fromCrossJSON(node, {
|
|
69
|
+
refs,
|
|
70
|
+
...resolved
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { DEFAULT_WEB_PLUGINS, createHydrationSerializer, createJSONDeserializer, 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,97 @@
|
|
|
1
|
+
import { Plugin, Serializer, SerovalNode } from "seroval";
|
|
2
|
+
|
|
3
|
+
export type { SerovalNode };
|
|
4
|
+
|
|
5
|
+
/** A Seroval plugin usable with the web serializers. */
|
|
6
|
+
export type SerializerPlugin = Plugin<any, any>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
10
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
16
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
17
|
+
* fresh array; the defaults are never mutated.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
20
|
+
|
|
21
|
+
export interface WebSerializerOptions {
|
|
22
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
23
|
+
globalIdentifier: string;
|
|
24
|
+
scopeId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
27
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays).
|
|
28
|
+
*/
|
|
29
|
+
disabledFeatures?: number;
|
|
30
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
31
|
+
plugins?: SerializerPlugin[];
|
|
32
|
+
onData: (result: string) => void;
|
|
33
|
+
onError?: (error: unknown) => void;
|
|
34
|
+
onDone?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
39
|
+
* set and the default feature policy.
|
|
40
|
+
*/
|
|
41
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
42
|
+
|
|
43
|
+
export type HydrationSerializerOptions = Omit<
|
|
44
|
+
WebSerializerOptions,
|
|
45
|
+
"globalIdentifier" | "disabledFeatures"
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Serializer for SSR hydration output. Pins the hydration global (`_$HY.r`)
|
|
50
|
+
* and feature policy — only the wiring options (callbacks, scope, extra
|
|
51
|
+
* plugins) are configurable.
|
|
52
|
+
*/
|
|
53
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
54
|
+
|
|
55
|
+
/** Returns the cross-reference bootstrap script for a render scope. */
|
|
56
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
57
|
+
|
|
58
|
+
// ---- JSON codec (server function transports) ----
|
|
59
|
+
|
|
60
|
+
export interface JSONCodecOptions {
|
|
61
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
62
|
+
plugins?: SerializerPlugin[];
|
|
63
|
+
/**
|
|
64
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
65
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
66
|
+
*/
|
|
67
|
+
disabledFeatures?: number;
|
|
68
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
69
|
+
depthLimit?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
75
|
+
* (the source value itself). Async values produce additional chunks as
|
|
76
|
+
* they resolve.
|
|
77
|
+
*/
|
|
78
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
79
|
+
onError?: (error: unknown) => void;
|
|
80
|
+
/** Fires once all async values have settled. */
|
|
81
|
+
onDone?: () => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse`.
|
|
86
|
+
* Wire framing of the nodes is the transport's concern. Returns a cancel
|
|
87
|
+
* function that aborts pending async serialization.
|
|
88
|
+
*/
|
|
89
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
93
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
94
|
+
* from one stream must go through the same deserializer instance. The first
|
|
95
|
+
* chunk's return value is the decoded source value.
|
|
96
|
+
*/
|
|
97
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Plugin, Serializer, SerovalNode } from "seroval";
|
|
2
|
+
|
|
3
|
+
export type { SerovalNode };
|
|
4
|
+
|
|
5
|
+
/** A Seroval plugin usable with the web serializers. */
|
|
6
|
+
export type SerializerPlugin = Plugin<any, any>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
10
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
16
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
17
|
+
* fresh array; the defaults are never mutated.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
20
|
+
|
|
21
|
+
export interface WebSerializerOptions {
|
|
22
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
23
|
+
globalIdentifier: string;
|
|
24
|
+
scopeId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
27
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays).
|
|
28
|
+
*/
|
|
29
|
+
disabledFeatures?: number;
|
|
30
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
31
|
+
plugins?: SerializerPlugin[];
|
|
32
|
+
onData: (result: string) => void;
|
|
33
|
+
onError?: (error: unknown) => void;
|
|
34
|
+
onDone?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
39
|
+
* set and the default feature policy.
|
|
40
|
+
*/
|
|
41
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
42
|
+
|
|
43
|
+
export type HydrationSerializerOptions = Omit<
|
|
44
|
+
WebSerializerOptions,
|
|
45
|
+
"globalIdentifier" | "disabledFeatures"
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Serializer for SSR hydration output. Pins the hydration global (`_$HY.r`)
|
|
50
|
+
* and feature policy — only the wiring options (callbacks, scope, extra
|
|
51
|
+
* plugins) are configurable.
|
|
52
|
+
*/
|
|
53
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
54
|
+
|
|
55
|
+
/** Returns the cross-reference bootstrap script for a render scope. */
|
|
56
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
57
|
+
|
|
58
|
+
// ---- JSON codec (server function transports) ----
|
|
59
|
+
|
|
60
|
+
export interface JSONCodecOptions {
|
|
61
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
62
|
+
plugins?: SerializerPlugin[];
|
|
63
|
+
/**
|
|
64
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
65
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
66
|
+
*/
|
|
67
|
+
disabledFeatures?: number;
|
|
68
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
69
|
+
depthLimit?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
75
|
+
* (the source value itself). Async values produce additional chunks as
|
|
76
|
+
* they resolve.
|
|
77
|
+
*/
|
|
78
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
79
|
+
onError?: (error: unknown) => void;
|
|
80
|
+
/** Fires once all async values have settled. */
|
|
81
|
+
onDone?: () => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse`.
|
|
86
|
+
* Wire framing of the nodes is the transport's concern. Returns a cancel
|
|
87
|
+
* function that aborts pending async serialization.
|
|
88
|
+
*/
|
|
89
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
93
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
94
|
+
* from one stream must go through the same deserializer instance. The first
|
|
95
|
+
* chunk's return value is the decoded source value.
|
|
96
|
+
*/
|
|
97
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
package/types/index.d.ts
CHANGED
|
@@ -118,6 +118,12 @@ export declare const hydrate: typeof hydrateCore;
|
|
|
118
118
|
* still participates in the parent's reactive scope and disposes when the
|
|
119
119
|
* parent does.
|
|
120
120
|
*
|
|
121
|
+
* Portals are client-only islands: the server renders nothing for them, and
|
|
122
|
+
* under hydration the children render fresh once hydration settles. Async
|
|
123
|
+
* read inside a portal therefore starts on the client — data that should be
|
|
124
|
+
* fetched on the server belongs above the portal (hoist the read, not the
|
|
125
|
+
* render), and async UI inside one wants its own `<Loading>` boundary.
|
|
126
|
+
*
|
|
121
127
|
* @example
|
|
122
128
|
* ```tsx
|
|
123
129
|
* <Portal mount={document.getElementById("modal-root")!}>
|
|
@@ -127,7 +133,7 @@ export declare const hydrate: typeof hydrateCore;
|
|
|
127
133
|
*
|
|
128
134
|
* @description https://docs.solidjs.com/reference/components/portal
|
|
129
135
|
*/
|
|
130
|
-
export declare function Portal
|
|
136
|
+
export declare function Portal(props: {
|
|
131
137
|
mount?: Element;
|
|
132
138
|
children: JSX.Element;
|
|
133
139
|
}): JSX.Element;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Plugin, Serializer, SerovalNode } from "seroval";
|
|
2
|
+
|
|
3
|
+
export type { SerovalNode };
|
|
4
|
+
|
|
5
|
+
/** A Seroval plugin usable with the web serializers. */
|
|
6
|
+
export type SerializerPlugin = Plugin<any, any>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
10
|
+
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
|
|
16
|
+
* first so they can shadow a default for values both would match. Returns a
|
|
17
|
+
* fresh array; the defaults are never mutated.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
20
|
+
|
|
21
|
+
export interface WebSerializerOptions {
|
|
22
|
+
/** Name of the global object the emitted scripts write resolved values into. */
|
|
23
|
+
globalIdentifier: string;
|
|
24
|
+
scopeId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Seroval feature bitflags to exclude from output. Defaults to disabling
|
|
27
|
+
* post-ES2017 features (AggregateError, BigInt typed arrays).
|
|
28
|
+
*/
|
|
29
|
+
disabledFeatures?: number;
|
|
30
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
|
|
31
|
+
plugins?: SerializerPlugin[];
|
|
32
|
+
onData: (result: string) => void;
|
|
33
|
+
onError?: (error: unknown) => void;
|
|
34
|
+
onDone?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates a streaming Seroval serializer preconfigured with the web plugin
|
|
39
|
+
* set and the default feature policy.
|
|
40
|
+
*/
|
|
41
|
+
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
42
|
+
|
|
43
|
+
export type HydrationSerializerOptions = Omit<
|
|
44
|
+
WebSerializerOptions,
|
|
45
|
+
"globalIdentifier" | "disabledFeatures"
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Serializer for SSR hydration output. Pins the hydration global (`_$HY.r`)
|
|
50
|
+
* and feature policy — only the wiring options (callbacks, scope, extra
|
|
51
|
+
* plugins) are configurable.
|
|
52
|
+
*/
|
|
53
|
+
export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
|
|
54
|
+
|
|
55
|
+
/** Returns the cross-reference bootstrap script for a render scope. */
|
|
56
|
+
export function getLocalHeaderScript(id?: string): string;
|
|
57
|
+
|
|
58
|
+
// ---- JSON codec (server function transports) ----
|
|
59
|
+
|
|
60
|
+
export interface JSONCodecOptions {
|
|
61
|
+
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
62
|
+
plugins?: SerializerPlugin[];
|
|
63
|
+
/**
|
|
64
|
+
* Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
|
|
65
|
+
* (payloads may come from an untrusted peer). Must match on both peers.
|
|
66
|
+
*/
|
|
67
|
+
disabledFeatures?: number;
|
|
68
|
+
/** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
|
|
69
|
+
depthLimit?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Receives each serialized node; `initial` is true for the first chunk
|
|
75
|
+
* (the source value itself). Async values produce additional chunks as
|
|
76
|
+
* they resolve.
|
|
77
|
+
*/
|
|
78
|
+
onParse: (node: SerovalNode, initial: boolean) => void;
|
|
79
|
+
onError?: (error: unknown) => void;
|
|
80
|
+
/** Fires once all async values have settled. */
|
|
81
|
+
onDone?: () => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Serializes `value` as SerovalNode chunks delivered through `onParse`.
|
|
86
|
+
* Wire framing of the nodes is the transport's concern. Returns a cancel
|
|
87
|
+
* function that aborts pending async serialization.
|
|
88
|
+
*/
|
|
89
|
+
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates the decoding counterpart of `serializeJSON`. Cross-references
|
|
93
|
+
* between chunks resolve through state shared across calls, so all chunks
|
|
94
|
+
* from one stream must go through the same deserializer instance. The first
|
|
95
|
+
* chunk's return value is the decoded source value.
|
|
96
|
+
*/
|
|
97
|
+
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
package/types/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JSX } from "./jsx.js";
|
|
2
|
+
import { SerializerPlugin } from "./serializer.js";
|
|
2
3
|
export const DOMWithState: Record<string, Record<string, 1 | 2>>;
|
|
3
4
|
export const ChildProperties: Set<string>;
|
|
4
5
|
export const DelegatedEvents: Set<string>;
|
|
@@ -11,17 +12,59 @@ export const Namespaces: Record<string, string>;
|
|
|
11
12
|
|
|
12
13
|
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
|
13
14
|
|
|
15
|
+
/** Static asset manifest produced by a build (e.g. parsed Vite manifest.json). */
|
|
16
|
+
export type AssetManifest = Record<
|
|
17
|
+
string,
|
|
18
|
+
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
19
|
+
> & { _base?: string };
|
|
20
|
+
|
|
21
|
+
/** Inline style content, e.g. dev CSS collected from a bundler's module graph. */
|
|
22
|
+
export type InlineStyleAsset = {
|
|
23
|
+
id: string;
|
|
24
|
+
content: string;
|
|
25
|
+
attrs?: Record<string, string>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ResolvedAssets = {
|
|
29
|
+
js: string[];
|
|
30
|
+
css: (string | InlineStyleAsset)[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolver form of the manifest option — the primitive a dev server
|
|
35
|
+
* implements against its live module graph (a static manifest object is
|
|
36
|
+
* normalized into a sync resolver internally). `resolve` may return a
|
|
37
|
+
* promise (async resolvers require streaming rendering); CSS entries may be
|
|
38
|
+
* URL strings (emitted as load-gated `<link>` tags) or inline-style
|
|
39
|
+
* descriptors (emitted as `<style>` tags). A bare `resolve`-shaped function
|
|
40
|
+
* is accepted as shorthand for `{ resolve }`.
|
|
41
|
+
*/
|
|
42
|
+
export type AssetResolver = {
|
|
43
|
+
resolve(
|
|
44
|
+
key: string
|
|
45
|
+
): ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Synchronous fast path answering with whatever is knowable without async
|
|
48
|
+
* work (typically js URLs, omitting css). Sync consumers — e.g. a lazy
|
|
49
|
+
* component's `moduleUrl` getter used by islands — use this when `resolve`
|
|
50
|
+
* would return a promise, so adapters should provide it whenever possible.
|
|
51
|
+
*/
|
|
52
|
+
resolveSync?(key: string): ResolvedAssets | null | undefined;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Bare-function shorthand for `AssetResolver` (no sync fast path). */
|
|
56
|
+
export type AssetResolverFn = (
|
|
57
|
+
key: string
|
|
58
|
+
) => ResolvedAssets | null | undefined | Promise<ResolvedAssets | null | undefined>;
|
|
59
|
+
|
|
14
60
|
export function renderToString<T>(
|
|
15
61
|
fn: () => T,
|
|
16
62
|
options?: {
|
|
17
63
|
nonce?: string;
|
|
18
64
|
renderId?: string;
|
|
19
65
|
noScripts?: boolean;
|
|
20
|
-
plugins?:
|
|
21
|
-
manifest?:
|
|
22
|
-
string,
|
|
23
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
24
|
-
> & { _base?: string };
|
|
66
|
+
plugins?: SerializerPlugin[];
|
|
67
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
25
68
|
onError?: (err: any) => void;
|
|
26
69
|
}
|
|
27
70
|
): string;
|
|
@@ -33,11 +76,8 @@ export function renderToStringAsync<T>(
|
|
|
33
76
|
nonce?: string;
|
|
34
77
|
renderId?: string;
|
|
35
78
|
noScripts?: boolean;
|
|
36
|
-
plugins?:
|
|
37
|
-
manifest?:
|
|
38
|
-
string,
|
|
39
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
40
|
-
> & { _base?: string };
|
|
79
|
+
plugins?: SerializerPlugin[];
|
|
80
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
41
81
|
onError?: (err: any) => void;
|
|
42
82
|
}
|
|
43
83
|
): Promise<string>;
|
|
@@ -47,11 +87,8 @@ export function renderToStream<T>(
|
|
|
47
87
|
nonce?: string;
|
|
48
88
|
renderId?: string;
|
|
49
89
|
noScripts?: boolean;
|
|
50
|
-
plugins?:
|
|
51
|
-
manifest?:
|
|
52
|
-
string,
|
|
53
|
-
{ file: string; css?: string[]; isEntry?: boolean; imports?: string[] }
|
|
54
|
-
> & { _base?: string };
|
|
90
|
+
plugins?: SerializerPlugin[];
|
|
91
|
+
manifest?: AssetManifest | AssetResolver | AssetResolverFn;
|
|
55
92
|
onCompleteShell?: (info: { write: (v: string) => void }) => void;
|
|
56
93
|
onCompleteAll?: (info: { write: (v: string) => void }) => void;
|
|
57
94
|
onError?: (err: any) => void;
|