@solidjs/web 2.0.0-beta.2 → 2.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +27 -4
  2. package/dist/dev.cjs +783 -223
  3. package/dist/dev.js +757 -217
  4. package/dist/server.cjs +742 -186
  5. package/dist/server.js +714 -183
  6. package/dist/web.cjs +772 -196
  7. package/dist/web.js +746 -190
  8. package/package.json +193 -38
  9. package/serialization/dist/serialization.cjs +83 -0
  10. package/serialization/dist/serialization.js +75 -0
  11. package/serialization/package.json +20 -0
  12. package/serialization/types/index.d.ts +139 -0
  13. package/serialization/types-cjs/index.d.cts +139 -0
  14. package/serialization/types-cjs/package.json +3 -0
  15. package/server-functions/dist/client.cjs +370 -0
  16. package/server-functions/dist/client.js +363 -0
  17. package/server-functions/dist/server.cjs +542 -0
  18. package/server-functions/dist/server.js +531 -0
  19. package/server-functions/package.json +30 -0
  20. package/storage/package.json +8 -3
  21. package/storage/types/index.d.ts +26 -0
  22. package/storage/types-cjs/index.d.cts +28 -0
  23. package/storage/types-cjs/package.json +3 -0
  24. package/types/client.d.ts +64 -21
  25. package/types/core.d.ts +3 -3
  26. package/types/index.d.ts +156 -24
  27. package/types/jsx-properties.d.ts +93 -0
  28. package/types/jsx.d.ts +4135 -1
  29. package/types/response.d.ts +93 -0
  30. package/types/serializer.d.ts +139 -0
  31. package/types/server-functions/client.d.ts +63 -0
  32. package/types/server-functions/server.d.ts +188 -0
  33. package/types/server-functions/shared.d.ts +171 -0
  34. package/types/server-mock.d.ts +89 -0
  35. package/types/server.d.ts +123 -28
  36. package/types-cjs/client.d.cts +131 -0
  37. package/types-cjs/core.d.cts +3 -0
  38. package/types-cjs/index.d.cts +178 -0
  39. package/types-cjs/jsx-properties.d.cts +93 -0
  40. package/types-cjs/jsx.d.cts +4135 -0
  41. package/types-cjs/package.json +3 -0
  42. package/types-cjs/response.d.cts +93 -0
  43. package/types-cjs/serializer.d.cts +139 -0
  44. package/types-cjs/server-functions/client.d.cts +63 -0
  45. package/types-cjs/server-functions/server.d.cts +188 -0
  46. package/types-cjs/server-functions/shared.d.cts +171 -0
  47. package/types-cjs/server-mock.d.cts +161 -0
  48. package/types-cjs/server.d.cts +251 -0
  49. package/storage/types/src/client.d.ts +0 -1
  50. package/storage/types/src/index.d.ts +0 -46
  51. package/storage/types/src/server-mock.d.ts +0 -72
  52. package/storage/types/storage/src/index.d.ts +0 -2
package/package.json CHANGED
@@ -1,99 +1,254 @@
1
1
  {
2
2
  "name": "@solidjs/web",
3
- "description": "Solid's web runtime for the browser and the server",
4
- "version": "2.0.0-beta.2",
3
+ "description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
4
+ "version": "2.0.0-beta.20",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/solidjs/solid-web"
10
+ "url": "git+https://github.com/solidjs/solid.git",
11
+ "directory": "packages/solid-web"
11
12
  },
12
13
  "publishConfig": {
13
14
  "access": "public"
14
15
  },
15
16
  "main": "./dist/server.cjs",
16
17
  "module": "./dist/server.js",
17
- "unpkg": "./dist/web.cjs",
18
+ "unpkg": "./dist/web.js",
19
+ "jsdelivr": "./dist/web.js",
18
20
  "types": "./types/index.d.ts",
19
21
  "type": "module",
20
22
  "sideEffects": false,
21
23
  "files": [
22
24
  "dist",
23
25
  "types",
26
+ "types-cjs",
24
27
  "package.json",
25
28
  "storage/dist",
26
29
  "storage/types",
27
- "storage/package.json"
30
+ "storage/types-cjs",
31
+ "storage/package.json",
32
+ "serialization/dist",
33
+ "serialization/types",
34
+ "serialization/types-cjs",
35
+ "serialization/package.json",
36
+ "server-functions/dist",
37
+ "server-functions/package.json"
28
38
  ],
29
39
  "exports": {
30
40
  ".": {
31
41
  "worker": {
32
- "types": "./types/index.d.ts",
33
- "import": "./dist/server.js",
34
- "require": "./dist/server.cjs"
42
+ "import": {
43
+ "types": "./types/index.d.ts",
44
+ "default": "./dist/server.js"
45
+ },
46
+ "require": {
47
+ "types": "./types-cjs/index.d.cts",
48
+ "default": "./dist/server.cjs"
49
+ }
35
50
  },
36
51
  "browser": {
37
52
  "development": {
53
+ "import": {
54
+ "types": "./types/index.d.ts",
55
+ "default": "./dist/dev.js"
56
+ },
57
+ "require": {
58
+ "types": "./types-cjs/index.d.cts",
59
+ "default": "./dist/dev.cjs"
60
+ }
61
+ },
62
+ "import": {
38
63
  "types": "./types/index.d.ts",
39
- "import": "./dist/dev.js",
40
- "require": "./dist/dev.cjs"
64
+ "default": "./dist/web.js"
41
65
  },
42
- "types": "./types/index.d.ts",
43
- "import": "./dist/web.js",
44
- "require": "./dist/web.cjs"
66
+ "require": {
67
+ "types": "./types-cjs/index.d.cts",
68
+ "default": "./dist/web.cjs"
69
+ }
45
70
  },
46
71
  "deno": {
47
- "types": "./types/index.d.ts",
48
- "import": "./dist/server.js",
49
- "require": "./dist/server.cjs"
72
+ "import": {
73
+ "types": "./types/index.d.ts",
74
+ "default": "./dist/server.js"
75
+ },
76
+ "require": {
77
+ "types": "./types-cjs/index.d.cts",
78
+ "default": "./dist/server.cjs"
79
+ }
50
80
  },
51
81
  "node": {
52
- "types": "./types/index.d.ts",
53
- "import": "./dist/server.js",
54
- "require": "./dist/server.cjs"
82
+ "import": {
83
+ "types": "./types/index.d.ts",
84
+ "default": "./dist/server.js"
85
+ },
86
+ "require": {
87
+ "types": "./types-cjs/index.d.cts",
88
+ "default": "./dist/server.cjs"
89
+ }
55
90
  },
56
91
  "development": {
92
+ "import": {
93
+ "types": "./types/index.d.ts",
94
+ "default": "./dist/dev.js"
95
+ },
96
+ "require": {
97
+ "types": "./types-cjs/index.d.cts",
98
+ "default": "./dist/dev.cjs"
99
+ }
100
+ },
101
+ "import": {
57
102
  "types": "./types/index.d.ts",
58
- "import": "./dist/dev.js",
59
- "require": "./dist/dev.cjs"
103
+ "default": "./dist/web.js"
104
+ },
105
+ "require": {
106
+ "types": "./types-cjs/index.d.cts",
107
+ "default": "./dist/web.cjs"
108
+ }
109
+ },
110
+ "./jsx-runtime": {
111
+ "import": {
112
+ "types": "./types/jsx.d.ts",
113
+ "default": "./dist/web.js"
114
+ },
115
+ "require": {
116
+ "types": "./types-cjs/jsx.d.cts",
117
+ "default": "./dist/web.cjs"
118
+ }
119
+ },
120
+ "./jsx-dev-runtime": {
121
+ "import": {
122
+ "types": "./types/jsx.d.ts",
123
+ "default": "./dist/dev.js"
60
124
  },
61
- "types": "./types/index.d.ts",
62
- "import": "./dist/web.js",
63
- "require": "./dist/web.cjs"
125
+ "require": {
126
+ "types": "./types-cjs/jsx.d.cts",
127
+ "default": "./dist/dev.cjs"
128
+ }
64
129
  },
65
130
  "./storage": {
66
- "types": "./storage/types/index.d.ts",
67
- "import": "./storage/dist/storage.js",
68
- "require": "./storage/dist/storage.cjs"
131
+ "import": {
132
+ "types": "./storage/types/index.d.ts",
133
+ "default": "./storage/dist/storage.js"
134
+ },
135
+ "require": {
136
+ "types": "./storage/types-cjs/index.d.cts",
137
+ "default": "./storage/dist/storage.cjs"
138
+ }
139
+ },
140
+ "./serialization": {
141
+ "import": {
142
+ "types": "./serialization/types/index.d.ts",
143
+ "default": "./serialization/dist/serialization.js"
144
+ },
145
+ "require": {
146
+ "types": "./serialization/types-cjs/index.d.cts",
147
+ "default": "./serialization/dist/serialization.cjs"
148
+ }
149
+ },
150
+ "./server-functions": {
151
+ "worker": {
152
+ "import": {
153
+ "types": "./types/server-functions/server.d.ts",
154
+ "default": "./server-functions/dist/server.js"
155
+ },
156
+ "require": {
157
+ "types": "./types-cjs/server-functions/server.d.cts",
158
+ "default": "./server-functions/dist/server.cjs"
159
+ }
160
+ },
161
+ "browser": {
162
+ "import": {
163
+ "types": "./types/server-functions/client.d.ts",
164
+ "default": "./server-functions/dist/client.js"
165
+ },
166
+ "require": {
167
+ "types": "./types-cjs/server-functions/client.d.cts",
168
+ "default": "./server-functions/dist/client.cjs"
169
+ }
170
+ },
171
+ "deno": {
172
+ "import": {
173
+ "types": "./types/server-functions/server.d.ts",
174
+ "default": "./server-functions/dist/server.js"
175
+ },
176
+ "require": {
177
+ "types": "./types-cjs/server-functions/server.d.cts",
178
+ "default": "./server-functions/dist/server.cjs"
179
+ }
180
+ },
181
+ "node": {
182
+ "import": {
183
+ "types": "./types/server-functions/server.d.ts",
184
+ "default": "./server-functions/dist/server.js"
185
+ },
186
+ "require": {
187
+ "types": "./types-cjs/server-functions/server.d.cts",
188
+ "default": "./server-functions/dist/server.cjs"
189
+ }
190
+ },
191
+ "import": {
192
+ "types": "./types/server-functions/client.d.ts",
193
+ "default": "./server-functions/dist/client.js"
194
+ },
195
+ "require": {
196
+ "types": "./types-cjs/server-functions/client.d.cts",
197
+ "default": "./server-functions/dist/client.cjs"
198
+ }
199
+ },
200
+ "./server-functions/server": {
201
+ "import": {
202
+ "types": "./types/server-functions/server.d.ts",
203
+ "default": "./server-functions/dist/server.js"
204
+ },
205
+ "require": {
206
+ "types": "./types-cjs/server-functions/server.d.cts",
207
+ "default": "./server-functions/dist/server.cjs"
208
+ }
209
+ },
210
+ "./server-functions/client": {
211
+ "import": {
212
+ "types": "./types/server-functions/client.d.ts",
213
+ "default": "./server-functions/dist/client.js"
214
+ },
215
+ "require": {
216
+ "types": "./types-cjs/server-functions/client.d.cts",
217
+ "default": "./server-functions/dist/client.cjs"
218
+ }
69
219
  },
70
- "./dist/*": "./dist/*",
71
220
  "./types/*": "./types/*"
72
221
  },
73
222
  "dependencies": {
74
- "seroval": "^1.1.0",
75
- "seroval-plugins": "^1.1.0"
223
+ "seroval": "~1.5.4",
224
+ "seroval-plugins": "~1.5.4"
76
225
  },
77
226
  "peerDependencies": {
78
- "solid-js": "^2.0.0-beta.2",
79
- "@solidjs/signals": "^0.12.0"
227
+ "solid-js": "^2.0.0-beta.20"
80
228
  },
81
229
  "devDependencies": {
82
- "solid-js": "2.0.0-beta.2"
230
+ "solid-js": "2.0.0-beta.20"
83
231
  },
84
232
  "scripts": {
85
- "build": "npm-run-all -nl build:*",
233
+ "build": "npm-run-all -nl build:clean types:copy-jsx build:js",
86
234
  "build:clean": "rimraf dist/",
87
235
  "build:js": "rollup -c",
88
236
  "link": "symlink-dir . node_modules/@solidjs/web",
89
- "types": "npm-run-all -nl types:*",
90
- "types:clean": "rimraf types/",
237
+ "types": "npm-run-all -nl types:clean types:copy-jsx types:web types:copy-web types:web-storage types:copy-serialization types:copy-server-functions types:cjs",
238
+ "types:clean": "rimraf types/ types-cjs/ storage/types/ storage/types-cjs/ serialization/types/ serialization/types-cjs/",
239
+ "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\";'",
91
240
  "types:web": "tsc --project ./tsconfig.build.json",
92
- "types:copy-web": "ncp ../../node_modules/dom-expressions/src/client.d.ts ./types/client.d.ts && ncp ../../node_modules/dom-expressions/src/server.d.ts ./types/server.d.ts",
241
+ "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 ../../node_modules/@dom-expressions/runtime/src/response.d.ts ./types/response.d.ts && ncp ./src/jsx.d.ts ./types/jsx.d.ts && ncp ./src/jsx-properties.d.ts ./types/jsx-properties.d.ts",
93
242
  "types:web-storage": "tsc --project ./storage/tsconfig.build.json",
243
+ "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');\"",
244
+ "types:copy-server-functions": "node -e \"fs.mkdirSync('./types/server-functions', { recursive: true }); for (const f of ['shared', 'client', 'server']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/server-functions/' + f + '.d.ts', './types/server-functions/' + f + '.d.ts');\"",
245
+ "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./storage/types ./storage/types-cjs ./serialization/types ./serialization/types-cjs",
94
246
  "test": "vitest run && vitest run --config vite.config.server.mjs && vitest run --config vite.config.hydrate.mjs",
95
247
  "test:server": "vitest run --config vite.config.server.mjs",
96
248
  "coverage": "vitest run --coverage",
97
- "test-types": "tsc --project tsconfig.test.json"
249
+ "bench": "vitest bench --run",
250
+ "bench:server": "vitest bench --run --config vite.config.server-bench.mjs",
251
+ "test-types": "npm-run-all -nl types test-types:tsc",
252
+ "test-types:tsc": "tsc --project tsconfig.test.json"
98
253
  }
99
254
  }
@@ -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,139 @@
1
+ import { Plugin, Serializer, SerovalNode } from "seroval";
2
+
3
+ /**
4
+ * Seroval's node shape — the intermediate representation `serializeJSON`
5
+ * emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
6
+ */
7
+ export type { SerovalNode };
8
+
9
+ /**
10
+ * A Seroval plugin usable with the web serializers — teaches the codec how
11
+ * to encode/decode a custom value type. Supply matching plugins on both
12
+ * peers of a transport.
13
+ */
14
+ export type SerializerPlugin = Plugin<any, any>;
15
+
16
+ /**
17
+ * Baseline plugin set for serializing web-platform values (AbortSignal,
18
+ * Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
19
+ * Applied by every serializer in this module; custom plugins compose ahead
20
+ * of it via `resolveSerializerPlugins`.
21
+ */
22
+ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
23
+
24
+ /**
25
+ * Composes custom plugins with `DEFAULT_WEB_PLUGINS`. Custom plugins come
26
+ * first so they can shadow a default for values both would match. Returns a
27
+ * fresh array; the defaults are never mutated. Useful when handing a full
28
+ * plugin list to another serialization layer.
29
+ */
30
+ export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
31
+
32
+ /** Options for `createSerializer`. */
33
+ export interface WebSerializerOptions {
34
+ /** Name of the global object the emitted scripts write resolved values into. */
35
+ globalIdentifier: string;
36
+ /** Cross-reference scope id, for isolating multiple streams on one page. */
37
+ scopeId?: string;
38
+ /**
39
+ * Seroval feature bitflags to exclude from output. Defaults to disabling
40
+ * post-ES2017 features (AggregateError, BigInt typed arrays).
41
+ */
42
+ disabledFeatures?: number;
43
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. */
44
+ plugins?: SerializerPlugin[];
45
+ /** Receives each emitted script chunk. */
46
+ onData: (result: string) => void;
47
+ onError?: (error: unknown) => void;
48
+ /** Fires once all async values have settled. */
49
+ onDone?: () => void;
50
+ }
51
+
52
+ /**
53
+ * Creates a streaming Seroval serializer preconfigured with the web plugin
54
+ * set and the default feature policy. Emits JavaScript chunks (through
55
+ * `onData`) that reconstruct the values under `globalIdentifier` when
56
+ * evaluated — the script-injection form of serialization renderers build
57
+ * on. For a JSON-based wire codec (no eval on the receiving side), use
58
+ * `serializeJSON` / `createJSONDeserializer` instead.
59
+ */
60
+ export function createSerializer(options: WebSerializerOptions): Serializer;
61
+
62
+ /**
63
+ * Options for `createHydrationSerializer` — `WebSerializerOptions` minus
64
+ * the knobs hydration pins (`globalIdentifier`, `disabledFeatures`).
65
+ * @internal
66
+ */
67
+ export type HydrationSerializerOptions = Omit<
68
+ WebSerializerOptions,
69
+ "globalIdentifier" | "disabledFeatures"
70
+ >;
71
+
72
+ /**
73
+ * Renderer primitive — the serializer SSR uses for hydration output. Pins
74
+ * the hydration global (`_$HY.r`) and feature policy; only the wiring
75
+ * options (callbacks, scope, extra plugins) are configurable. Not meant
76
+ * for hand-written code — custom serialization should use
77
+ * `createSerializer` or the JSON codec.
78
+ * @internal
79
+ */
80
+ export function createHydrationSerializer(options: HydrationSerializerOptions): Serializer;
81
+
82
+ /**
83
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
84
+ * emits ahead of hydration data for a render scope. Not meant for
85
+ * hand-written code.
86
+ * @internal
87
+ */
88
+ export function getLocalHeaderScript(id?: string): string;
89
+
90
+ // ---- JSON codec (server function transports) ----
91
+
92
+ /**
93
+ * Options shared by both halves of the JSON codec. All of them must match
94
+ * on the serializing and deserializing peer or payloads will not
95
+ * round-trip — for server functions, set them once through the
96
+ * client/server `codec` config option.
97
+ */
98
+ export interface JSONCodecOptions {
99
+ /** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
100
+ plugins?: SerializerPlugin[];
101
+ /**
102
+ * Seroval feature bitflags to exclude. Defaults to disabling `RegExp`
103
+ * (payloads may come from an untrusted peer). Must match on both peers.
104
+ */
105
+ disabledFeatures?: number;
106
+ /** Maximum parse/deserialize depth. Defaults to 64. Must match on both peers. */
107
+ depthLimit?: number;
108
+ }
109
+
110
+ /** Options for `serializeJSON`. */
111
+ export interface JSONSerializeOptions extends JSONCodecOptions {
112
+ /**
113
+ * Receives each serialized node; `initial` is true for the first chunk
114
+ * (the source value itself). Async values produce additional chunks as
115
+ * they resolve.
116
+ */
117
+ onParse: (node: SerovalNode, initial: boolean) => void;
118
+ onError?: (error: unknown) => void;
119
+ /** Fires once all async values have settled. */
120
+ onDone?: () => void;
121
+ }
122
+
123
+ /**
124
+ * Serializes `value` as SerovalNode chunks delivered through `onParse` —
125
+ * the encoding half of the eval-free JSON codec (RPC-style transports;
126
+ * the deserializing peer needs no script evaluation, so CSP-safe). Wire
127
+ * framing of the nodes is the transport's concern. Returns a cancel
128
+ * function that aborts pending async serialization.
129
+ */
130
+ export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
131
+
132
+ /**
133
+ * Creates the decoding counterpart of `serializeJSON`. Cross-references
134
+ * between chunks resolve through state shared across calls, so all chunks
135
+ * from one stream must go through the same deserializer instance. The first
136
+ * chunk's return value is the decoded source value; feeding later chunks
137
+ * settles the async values referenced inside it.
138
+ */
139
+ export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;