@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.32
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 +234 -45
- package/dist/dev.js +221 -42
- package/dist/server.cjs +456 -123
- package/dist/server.js +445 -120
- package/dist/web.cjs +234 -45
- package/dist/web.js +221 -42
- package/frames/dist/client.cjs +217 -112
- package/frames/dist/client.dev.cjs +217 -112
- package/frames/dist/client.dev.js +218 -113
- package/frames/dist/client.js +218 -113
- package/frames/dist/server.cjs +488 -177
- package/frames/dist/server.js +489 -179
- package/package.json +55 -4
- package/serialization/dist/serialization.cjs +8 -0
- package/serialization/dist/serialization.js +1 -0
- package/serialization/types/index.d.ts +173 -6
- package/serialization/types-cjs/index.d.cts +173 -6
- package/server-functions/dist/client.cjs +46 -9
- package/server-functions/dist/client.js +47 -11
- package/server-functions/dist/rich-args.cjs +11 -0
- package/server-functions/dist/rich-args.js +9 -0
- package/server-functions/dist/server.cjs +275 -126
- package/server-functions/dist/server.dev.cjs +1053 -0
- package/server-functions/dist/server.dev.js +1021 -0
- package/server-functions/dist/server.js +273 -127
- 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 +127 -6
- package/types/core.d.ts +3 -1
- package/types/frames/client.d.ts +15 -1
- package/types/frames/frame-client.d.ts +37 -7
- package/types/frames/frame-sink.d.ts +26 -3
- package/types/frames/frame-transport.d.ts +39 -7
- package/types/frames/serializer.d.ts +173 -6
- 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.d.ts +173 -6
- package/types/server-functions/client.d.ts +1 -0
- package/types/server-functions/rich-args.d.ts +10 -0
- package/types/server-functions/server.d.ts +98 -0
- package/types/server-functions/shared.d.ts +22 -0
- package/types/server-mock.d.ts +171 -59
- package/types/server.d.ts +188 -36
- package/types-cjs/client.d.cts +127 -6
- package/types-cjs/core.d.cts +3 -1
- package/types-cjs/frames/client.d.cts +15 -1
- package/types-cjs/frames/frame-client.d.cts +37 -7
- package/types-cjs/frames/frame-sink.d.cts +26 -3
- package/types-cjs/frames/frame-transport.d.cts +39 -7
- package/types-cjs/frames/serializer.d.cts +173 -6
- 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.d.cts +173 -6
- package/types-cjs/server-functions/client.d.cts +1 -0
- package/types-cjs/server-functions/rich-args.d.cts +10 -0
- package/types-cjs/server-functions/server.d.cts +98 -0
- package/types-cjs/server-functions/shared.d.cts +22 -0
- package/types-cjs/server-mock.d.cts +171 -59
- package/types-cjs/server.d.cts +188 -36
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.32",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"serialization/package.json",
|
|
36
36
|
"server-functions/dist",
|
|
37
37
|
"server-functions/package.json",
|
|
38
|
+
"server-functions/rich-args/package.json",
|
|
38
39
|
"frames/dist",
|
|
39
40
|
"frames/package.json"
|
|
40
41
|
],
|
|
@@ -151,6 +152,16 @@
|
|
|
151
152
|
},
|
|
152
153
|
"./server-functions": {
|
|
153
154
|
"worker": {
|
|
155
|
+
"development": {
|
|
156
|
+
"import": {
|
|
157
|
+
"types": "./types/server-functions/server.d.ts",
|
|
158
|
+
"default": "./server-functions/dist/server.dev.js"
|
|
159
|
+
},
|
|
160
|
+
"require": {
|
|
161
|
+
"types": "./types-cjs/server-functions/server.d.cts",
|
|
162
|
+
"default": "./server-functions/dist/server.dev.cjs"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
154
165
|
"import": {
|
|
155
166
|
"types": "./types/server-functions/server.d.ts",
|
|
156
167
|
"default": "./server-functions/dist/server.js"
|
|
@@ -171,6 +182,16 @@
|
|
|
171
182
|
}
|
|
172
183
|
},
|
|
173
184
|
"deno": {
|
|
185
|
+
"development": {
|
|
186
|
+
"import": {
|
|
187
|
+
"types": "./types/server-functions/server.d.ts",
|
|
188
|
+
"default": "./server-functions/dist/server.dev.js"
|
|
189
|
+
},
|
|
190
|
+
"require": {
|
|
191
|
+
"types": "./types-cjs/server-functions/server.d.cts",
|
|
192
|
+
"default": "./server-functions/dist/server.dev.cjs"
|
|
193
|
+
}
|
|
194
|
+
},
|
|
174
195
|
"import": {
|
|
175
196
|
"types": "./types/server-functions/server.d.ts",
|
|
176
197
|
"default": "./server-functions/dist/server.js"
|
|
@@ -181,6 +202,16 @@
|
|
|
181
202
|
}
|
|
182
203
|
},
|
|
183
204
|
"node": {
|
|
205
|
+
"development": {
|
|
206
|
+
"import": {
|
|
207
|
+
"types": "./types/server-functions/server.d.ts",
|
|
208
|
+
"default": "./server-functions/dist/server.dev.js"
|
|
209
|
+
},
|
|
210
|
+
"require": {
|
|
211
|
+
"types": "./types-cjs/server-functions/server.d.cts",
|
|
212
|
+
"default": "./server-functions/dist/server.dev.cjs"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
184
215
|
"import": {
|
|
185
216
|
"types": "./types/server-functions/server.d.ts",
|
|
186
217
|
"default": "./server-functions/dist/server.js"
|
|
@@ -200,6 +231,16 @@
|
|
|
200
231
|
}
|
|
201
232
|
},
|
|
202
233
|
"./server-functions/server": {
|
|
234
|
+
"development": {
|
|
235
|
+
"import": {
|
|
236
|
+
"types": "./types/server-functions/server.d.ts",
|
|
237
|
+
"default": "./server-functions/dist/server.dev.js"
|
|
238
|
+
},
|
|
239
|
+
"require": {
|
|
240
|
+
"types": "./types-cjs/server-functions/server.d.cts",
|
|
241
|
+
"default": "./server-functions/dist/server.dev.cjs"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
203
244
|
"import": {
|
|
204
245
|
"types": "./types/server-functions/server.d.ts",
|
|
205
246
|
"default": "./server-functions/dist/server.js"
|
|
@@ -219,6 +260,16 @@
|
|
|
219
260
|
"default": "./server-functions/dist/client.cjs"
|
|
220
261
|
}
|
|
221
262
|
},
|
|
263
|
+
"./server-functions/rich-args": {
|
|
264
|
+
"import": {
|
|
265
|
+
"types": "./types/server-functions/rich-args.d.ts",
|
|
266
|
+
"default": "./server-functions/dist/rich-args.js"
|
|
267
|
+
},
|
|
268
|
+
"require": {
|
|
269
|
+
"types": "./types-cjs/server-functions/rich-args.d.cts",
|
|
270
|
+
"default": "./server-functions/dist/rich-args.cjs"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
222
273
|
"./frames": {
|
|
223
274
|
"worker": {
|
|
224
275
|
"import": {
|
|
@@ -316,10 +367,10 @@
|
|
|
316
367
|
"seroval-plugins": "~1.5.4"
|
|
317
368
|
},
|
|
318
369
|
"peerDependencies": {
|
|
319
|
-
"solid-js": "^2.0.0-beta.
|
|
370
|
+
"solid-js": "^2.0.0-beta.32"
|
|
320
371
|
},
|
|
321
372
|
"devDependencies": {
|
|
322
|
-
"solid-js": "2.0.0-beta.
|
|
373
|
+
"solid-js": "2.0.0-beta.32"
|
|
323
374
|
},
|
|
324
375
|
"scripts": {
|
|
325
376
|
"build": "npm-run-all -nl build:clean types:copy-jsx build:js",
|
|
@@ -334,7 +385,7 @@
|
|
|
334
385
|
"types:web-storage": "tsc --project ./storage/tsconfig.build.json",
|
|
335
386
|
"types:web-frames": "tsc --project ./frames/tsconfig.build.json",
|
|
336
387
|
"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');\"",
|
|
337
|
-
"types:copy-server-functions": "node -e \"fs.mkdirSync('./types/server-functions', { recursive: true }); for (const f of ['shared', 'flash', 'client', 'server']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/server-functions/' + f + '.d.ts', './types/server-functions/' + f + '.d.ts');\"",
|
|
388
|
+
"types:copy-server-functions": "node -e \"fs.mkdirSync('./types/server-functions', { recursive: true }); for (const f of ['shared', 'flash', 'client', 'server', 'rich-args']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/server-functions/' + f + '.d.ts', './types/server-functions/' + f + '.d.ts');\"",
|
|
338
389
|
"types:copy-frames": "node -e \"fs.mkdirSync('./types/frames', { recursive: true }); for (const f of ['frame-client', 'frame-transport', 'frame-sink', 'serializer']) fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/' + f + '.d.ts', './types/frames/' + f + '.d.ts'); for (const f of ['client', 'server']) fs.writeFileSync('./types/frames/' + f + '.d.ts', fs.readFileSync('./frames/types/' + f + '.d.ts', 'utf8').replaceAll('@dom-expressions/runtime/src/', './'));\"",
|
|
339
390
|
"types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./storage/types ./storage/types-cjs ./serialization/types ./serialization/types-cjs",
|
|
340
391
|
"test": "vitest run && vitest run --config vite.config.server.mjs && vitest run --config vite.config.hydrate.mjs",
|
|
@@ -158,6 +158,14 @@ function createJSONDataTable(options) {
|
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
Object.defineProperty(exports, "OpaqueReference", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function () { return seroval.OpaqueReference; }
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function () { return seroval.createPlugin; }
|
|
168
|
+
});
|
|
161
169
|
exports.DEFAULT_WEB_PLUGINS = DEFAULT_WEB_PLUGINS;
|
|
162
170
|
exports.createHydrationSerializer = createHydrationSerializer;
|
|
163
171
|
exports.createJSONDataTable = createJSONDataTable;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Feature, Serializer, getCrossReferenceHeader, toCrossJSONStream, fromCrossJSON } from 'seroval';
|
|
2
|
+
export { OpaqueReference, createPlugin } from 'seroval';
|
|
2
3
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
3
4
|
|
|
4
5
|
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
@@ -1,23 +1,142 @@
|
|
|
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 { Serializer, SerovalNode } from "seroval";
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
5
12
|
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
13
|
+
*
|
|
14
|
+
* Integration-facing; may change (see the entry banner).
|
|
6
15
|
*/
|
|
7
16
|
export type { SerovalNode };
|
|
8
17
|
|
|
18
|
+
// ---- Plugin authoring ----
|
|
19
|
+
//
|
|
20
|
+
// Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
|
|
21
|
+
// it is the supported way to feed the serializers' `plugins` options and
|
|
22
|
+
// the server-function entries' `codec.plugins`. The values re-export
|
|
23
|
+
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
24
|
+
// the TYPES are declared here by hand, like everything else in this file,
|
|
25
|
+
// because seroval's published d.ts use extensionless ESM-relative imports
|
|
26
|
+
// that `moduleResolution: "nodenext"` cannot follow — a bare type
|
|
27
|
+
// re-export would silently degrade the whole authoring surface to `any`
|
|
28
|
+
// under skipLibCheck. The declarations mirror seroval ~1.5 exactly; the
|
|
29
|
+
// `~` pin is what makes mirroring safe.
|
|
30
|
+
|
|
31
|
+
/** Per-plugin bookkeeping seroval hands each plugin callback. */
|
|
32
|
+
export interface PluginData {
|
|
33
|
+
id: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The shape of a plugin's parsed payload: a map of `SerovalNode`s produced
|
|
38
|
+
* by the parse contexts, consumed by `serialize`/`deserialize`.
|
|
39
|
+
*/
|
|
40
|
+
export type PluginInfo = { [key: string]: SerovalNode };
|
|
41
|
+
|
|
42
|
+
/** Parse context for `parse.sync`: turns child values into nodes. */
|
|
43
|
+
export interface SyncParsePluginContext {
|
|
44
|
+
parse<T>(current: T): SerovalNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Parse context for `parse.async`: like sync, but child parses await. */
|
|
48
|
+
export interface AsyncParsePluginContext {
|
|
49
|
+
parse<T>(current: T): Promise<SerovalNode>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parse context for `parse.stream`: sync parsing plus the streaming
|
|
54
|
+
* lifecycle (pending-state tracking, late node emission, cleanup).
|
|
55
|
+
*/
|
|
56
|
+
export interface StreamParsePluginContext {
|
|
57
|
+
parse<T>(current: T): SerovalNode;
|
|
58
|
+
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
59
|
+
isAlive(): boolean;
|
|
60
|
+
pushPendingState(): void;
|
|
61
|
+
popPendingState(): void;
|
|
62
|
+
onParse(node: SerovalNode): void;
|
|
63
|
+
onError(error: unknown): void;
|
|
64
|
+
addCleanup(callback: () => void): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Serialize context: renders child nodes to JS source. */
|
|
68
|
+
export interface SerializePluginContext {
|
|
69
|
+
serialize(node: SerovalNode): string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Deserialize context: revives child nodes to runtime values. */
|
|
73
|
+
export interface DeserializePluginContext {
|
|
74
|
+
deserialize<T>(node: SerovalNode): T;
|
|
75
|
+
}
|
|
76
|
+
|
|
9
77
|
/**
|
|
10
78
|
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
11
|
-
* to encode/decode a custom value type
|
|
12
|
-
* peers of a
|
|
79
|
+
* to encode/decode a custom value type (`Value` is the value it matches,
|
|
80
|
+
* `Info` its parsed payload). Supply matching plugins on both peers of a
|
|
81
|
+
* transport. Bare `SerializerPlugin` (both parameters defaulted to `any`)
|
|
82
|
+
* is the list-element type every `plugins` option accepts.
|
|
83
|
+
*
|
|
84
|
+
* Integration-facing; may change (see the entry banner).
|
|
13
85
|
*/
|
|
14
|
-
export
|
|
86
|
+
export interface SerializerPlugin<Value = any, Info extends PluginInfo = any> {
|
|
87
|
+
/** A unique string identifying the plugin — namespace it (`"app/Thing"`). */
|
|
88
|
+
tag: string;
|
|
89
|
+
/** Dependency plugins, resolved ahead of this one. */
|
|
90
|
+
extends?: SerializerPlugin[];
|
|
91
|
+
/** Whether `value` is this plugin's to encode. */
|
|
92
|
+
test(value: unknown): boolean;
|
|
93
|
+
/** Parsing modes — provide the ones the transports you target use. */
|
|
94
|
+
parse: {
|
|
95
|
+
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
96
|
+
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
97
|
+
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
98
|
+
};
|
|
99
|
+
/** Renders the parsed payload as JS source (script-injection form). */
|
|
100
|
+
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
101
|
+
/** Revives the parsed payload back into the runtime value. */
|
|
102
|
+
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
107
|
+
* plugin authors stay on the exact seroval instance/version the runtime
|
|
108
|
+
* serializes with. Import it from HERE, not from your own `seroval`
|
|
109
|
+
* dependency: a plugin built against a different copy/version would not
|
|
110
|
+
* fail the build — it would emit nodes the other peer can't interpret.
|
|
111
|
+
*
|
|
112
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
113
|
+
*/
|
|
114
|
+
export function createPlugin<Value, Info extends PluginInfo>(
|
|
115
|
+
plugin: SerializerPlugin<Value, Info>
|
|
116
|
+
): SerializerPlugin<Value, Info>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Seroval's `OpaqueReference`, re-exported from the runtime's own instance
|
|
120
|
+
* (an `OpaqueReference` from another seroval copy fails the serializer's
|
|
121
|
+
* instanceof check and serializes as a plain value): wraps a value so it
|
|
122
|
+
* crosses the wire as its `replacement` (default `undefined`) while
|
|
123
|
+
* staying readable in-process through `.value`.
|
|
124
|
+
*
|
|
125
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
126
|
+
*/
|
|
127
|
+
export class OpaqueReference<V, R = undefined> {
|
|
128
|
+
readonly value: V;
|
|
129
|
+
readonly replacement?: R;
|
|
130
|
+
constructor(value: V, replacement?: R);
|
|
131
|
+
}
|
|
15
132
|
|
|
16
133
|
/**
|
|
17
134
|
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
18
135
|
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
19
136
|
* Applied by every serializer in this module; custom plugins compose ahead
|
|
20
137
|
* of it via `resolveSerializerPlugins`.
|
|
138
|
+
*
|
|
139
|
+
* Integration-facing; may change (see the entry banner).
|
|
21
140
|
*/
|
|
22
141
|
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
23
142
|
|
|
@@ -26,10 +145,16 @@ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
|
26
145
|
* first so they can shadow a default for values both would match. Returns a
|
|
27
146
|
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
28
147
|
* plugin list to another serialization layer.
|
|
148
|
+
*
|
|
149
|
+
* Integration-facing; may change (see the entry banner).
|
|
29
150
|
*/
|
|
30
151
|
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
152
|
|
|
32
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Options for `createSerializer`.
|
|
155
|
+
*
|
|
156
|
+
* Integration-facing; may change (see the entry banner).
|
|
157
|
+
*/
|
|
33
158
|
export interface WebSerializerOptions {
|
|
34
159
|
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
160
|
globalIdentifier: string;
|
|
@@ -58,6 +183,8 @@ export interface WebSerializerOptions {
|
|
|
58
183
|
* evaluated — the script-injection form of serialization renderers build
|
|
59
184
|
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
185
|
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
186
|
+
*
|
|
187
|
+
* Integration-facing; may change (see the entry banner).
|
|
61
188
|
*/
|
|
62
189
|
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
190
|
|
|
@@ -96,6 +223,8 @@ export function getLocalHeaderScript(id?: string): string;
|
|
|
96
223
|
* on the serializing and deserializing peer or payloads will not
|
|
97
224
|
* round-trip — for server functions, set them once through the
|
|
98
225
|
* client/server `codec` config option.
|
|
226
|
+
*
|
|
227
|
+
* Integration-facing; may change (see the entry banner).
|
|
99
228
|
*/
|
|
100
229
|
export interface JSONCodecOptions {
|
|
101
230
|
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
@@ -113,7 +242,11 @@ export interface JSONCodecOptions {
|
|
|
113
242
|
depthLimit?: number;
|
|
114
243
|
}
|
|
115
244
|
|
|
116
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Options for `serializeJSON`.
|
|
247
|
+
*
|
|
248
|
+
* Integration-facing; may change (see the entry banner).
|
|
249
|
+
*/
|
|
117
250
|
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
251
|
/**
|
|
119
252
|
* Receives each serialized node; `initial` is true for the first chunk
|
|
@@ -132,6 +265,8 @@ export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
|
132
265
|
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
266
|
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
267
|
* function that aborts pending async serialization.
|
|
268
|
+
*
|
|
269
|
+
* Integration-facing; may change (see the entry banner).
|
|
135
270
|
*/
|
|
136
271
|
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
272
|
|
|
@@ -141,14 +276,46 @@ export function serializeJSON(value: unknown, options: JSONSerializeOptions): ()
|
|
|
141
276
|
* from one stream must go through the same deserializer instance. The first
|
|
142
277
|
* chunk's return value is the decoded source value; feeding later chunks
|
|
143
278
|
* settles the async values referenced inside it.
|
|
279
|
+
*
|
|
280
|
+
* Integration-facing; may change (see the entry banner).
|
|
144
281
|
*/
|
|
145
282
|
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
146
283
|
|
|
284
|
+
/** Options for `createJSONSerializer`. */
|
|
285
|
+
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
286
|
+
/**
|
|
287
|
+
* Receives each keyed record — `initial` is true for a key's first node
|
|
288
|
+
* (the written value itself); async values patch through later records
|
|
289
|
+
* under the same key. The decoding peer is `createJSONDataTable`.
|
|
290
|
+
*/
|
|
291
|
+
onData: (record: { key: string; node: SerovalNode; initial: boolean }) => void;
|
|
292
|
+
onError?: (error: unknown) => void;
|
|
293
|
+
/** Fires once `flush()` has been called and every pending value settled. */
|
|
294
|
+
onDone?: () => void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The keyed, streaming encoder of the eval-free JSON codec — the render
|
|
299
|
+
* stream's data serializer (frames default to it). Each `write(key, value)`
|
|
300
|
+
* shares one reference space, so cross-record identity holds; `flush()`
|
|
301
|
+
* marks the write set complete (writes after it are dropped, mirroring the
|
|
302
|
+
* hydration serializer); `close()` aborts pending async serialization.
|
|
303
|
+
*/
|
|
304
|
+
export function createJSONSerializer(options: JSONSerializerOptions): {
|
|
305
|
+
write(key: string, value: unknown): void;
|
|
306
|
+
flush(): void;
|
|
307
|
+
close(): void;
|
|
308
|
+
};
|
|
309
|
+
|
|
147
310
|
/**
|
|
148
311
|
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
149
312
|
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
150
313
|
* `resolve`. The frames client host wires one per response
|
|
151
314
|
* (`applyData: c => table.apply(c)`).
|
|
315
|
+
*
|
|
316
|
+
* Integration-facing; may change (see the entry banner). This serialization
|
|
317
|
+
* entry is the single home of the data table — the frames client consumes
|
|
318
|
+
* it internally rather than re-exporting it.
|
|
152
319
|
*/
|
|
153
320
|
export interface JSONDataTable {
|
|
154
321
|
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|
|
@@ -1,23 +1,142 @@
|
|
|
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 { Serializer, SerovalNode } from "seroval";
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
* Seroval's node shape — the intermediate representation `serializeJSON`
|
|
5
12
|
* emits and `createJSONDeserializer` consumes. Safe to `JSON.stringify`.
|
|
13
|
+
*
|
|
14
|
+
* Integration-facing; may change (see the entry banner).
|
|
6
15
|
*/
|
|
7
16
|
export type { SerovalNode };
|
|
8
17
|
|
|
18
|
+
// ---- Plugin authoring ----
|
|
19
|
+
//
|
|
20
|
+
// Unlike the rest of this entry, plugin authoring is APPLICATION-FACING —
|
|
21
|
+
// it is the supported way to feed the serializers' `plugins` options and
|
|
22
|
+
// the server-function entries' `codec.plugins`. The values re-export
|
|
23
|
+
// seroval's own (`createPlugin`, `OpaqueReference` — see serializer.js);
|
|
24
|
+
// the TYPES are declared here by hand, like everything else in this file,
|
|
25
|
+
// because seroval's published d.ts use extensionless ESM-relative imports
|
|
26
|
+
// that `moduleResolution: "nodenext"` cannot follow — a bare type
|
|
27
|
+
// re-export would silently degrade the whole authoring surface to `any`
|
|
28
|
+
// under skipLibCheck. The declarations mirror seroval ~1.5 exactly; the
|
|
29
|
+
// `~` pin is what makes mirroring safe.
|
|
30
|
+
|
|
31
|
+
/** Per-plugin bookkeeping seroval hands each plugin callback. */
|
|
32
|
+
export interface PluginData {
|
|
33
|
+
id: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The shape of a plugin's parsed payload: a map of `SerovalNode`s produced
|
|
38
|
+
* by the parse contexts, consumed by `serialize`/`deserialize`.
|
|
39
|
+
*/
|
|
40
|
+
export type PluginInfo = { [key: string]: SerovalNode };
|
|
41
|
+
|
|
42
|
+
/** Parse context for `parse.sync`: turns child values into nodes. */
|
|
43
|
+
export interface SyncParsePluginContext {
|
|
44
|
+
parse<T>(current: T): SerovalNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Parse context for `parse.async`: like sync, but child parses await. */
|
|
48
|
+
export interface AsyncParsePluginContext {
|
|
49
|
+
parse<T>(current: T): Promise<SerovalNode>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Parse context for `parse.stream`: sync parsing plus the streaming
|
|
54
|
+
* lifecycle (pending-state tracking, late node emission, cleanup).
|
|
55
|
+
*/
|
|
56
|
+
export interface StreamParsePluginContext {
|
|
57
|
+
parse<T>(current: T): SerovalNode;
|
|
58
|
+
parseWithError<T>(current: T): SerovalNode | undefined;
|
|
59
|
+
isAlive(): boolean;
|
|
60
|
+
pushPendingState(): void;
|
|
61
|
+
popPendingState(): void;
|
|
62
|
+
onParse(node: SerovalNode): void;
|
|
63
|
+
onError(error: unknown): void;
|
|
64
|
+
addCleanup(callback: () => void): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Serialize context: renders child nodes to JS source. */
|
|
68
|
+
export interface SerializePluginContext {
|
|
69
|
+
serialize(node: SerovalNode): string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Deserialize context: revives child nodes to runtime values. */
|
|
73
|
+
export interface DeserializePluginContext {
|
|
74
|
+
deserialize<T>(node: SerovalNode): T;
|
|
75
|
+
}
|
|
76
|
+
|
|
9
77
|
/**
|
|
10
78
|
* A Seroval plugin usable with the web serializers — teaches the codec how
|
|
11
|
-
* to encode/decode a custom value type
|
|
12
|
-
* peers of a
|
|
79
|
+
* to encode/decode a custom value type (`Value` is the value it matches,
|
|
80
|
+
* `Info` its parsed payload). Supply matching plugins on both peers of a
|
|
81
|
+
* transport. Bare `SerializerPlugin` (both parameters defaulted to `any`)
|
|
82
|
+
* is the list-element type every `plugins` option accepts.
|
|
83
|
+
*
|
|
84
|
+
* Integration-facing; may change (see the entry banner).
|
|
13
85
|
*/
|
|
14
|
-
export
|
|
86
|
+
export interface SerializerPlugin<Value = any, Info extends PluginInfo = any> {
|
|
87
|
+
/** A unique string identifying the plugin — namespace it (`"app/Thing"`). */
|
|
88
|
+
tag: string;
|
|
89
|
+
/** Dependency plugins, resolved ahead of this one. */
|
|
90
|
+
extends?: SerializerPlugin[];
|
|
91
|
+
/** Whether `value` is this plugin's to encode. */
|
|
92
|
+
test(value: unknown): boolean;
|
|
93
|
+
/** Parsing modes — provide the ones the transports you target use. */
|
|
94
|
+
parse: {
|
|
95
|
+
sync?: (value: Value, ctx: SyncParsePluginContext, data: PluginData) => Info;
|
|
96
|
+
async?: (value: Value, ctx: AsyncParsePluginContext, data: PluginData) => Promise<Info>;
|
|
97
|
+
stream?: (value: Value, ctx: StreamParsePluginContext, data: PluginData) => Info;
|
|
98
|
+
};
|
|
99
|
+
/** Renders the parsed payload as JS source (script-injection form). */
|
|
100
|
+
serialize(node: Info, ctx: SerializePluginContext, data: PluginData): string;
|
|
101
|
+
/** Revives the parsed payload back into the runtime value. */
|
|
102
|
+
deserialize(node: Info, ctx: DeserializePluginContext, data: PluginData): Value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Builds a `SerializerPlugin` — seroval's `createPlugin`, re-exported so
|
|
107
|
+
* plugin authors stay on the exact seroval instance/version the runtime
|
|
108
|
+
* serializes with. Import it from HERE, not from your own `seroval`
|
|
109
|
+
* dependency: a plugin built against a different copy/version would not
|
|
110
|
+
* fail the build — it would emit nodes the other peer can't interpret.
|
|
111
|
+
*
|
|
112
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
113
|
+
*/
|
|
114
|
+
export function createPlugin<Value, Info extends PluginInfo>(
|
|
115
|
+
plugin: SerializerPlugin<Value, Info>
|
|
116
|
+
): SerializerPlugin<Value, Info>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Seroval's `OpaqueReference`, re-exported from the runtime's own instance
|
|
120
|
+
* (an `OpaqueReference` from another seroval copy fails the serializer's
|
|
121
|
+
* instanceof check and serializes as a plain value): wraps a value so it
|
|
122
|
+
* crosses the wire as its `replacement` (default `undefined`) while
|
|
123
|
+
* staying readable in-process through `.value`.
|
|
124
|
+
*
|
|
125
|
+
* Application-facing (see the plugin-authoring banner above).
|
|
126
|
+
*/
|
|
127
|
+
export class OpaqueReference<V, R = undefined> {
|
|
128
|
+
readonly value: V;
|
|
129
|
+
readonly replacement?: R;
|
|
130
|
+
constructor(value: V, replacement?: R);
|
|
131
|
+
}
|
|
15
132
|
|
|
16
133
|
/**
|
|
17
134
|
* Baseline plugin set for serializing web-platform values (AbortSignal,
|
|
18
135
|
* Event, FormData, Headers, ReadableStream, Request, Response, URL, ...).
|
|
19
136
|
* Applied by every serializer in this module; custom plugins compose ahead
|
|
20
137
|
* of it via `resolveSerializerPlugins`.
|
|
138
|
+
*
|
|
139
|
+
* Integration-facing; may change (see the entry banner).
|
|
21
140
|
*/
|
|
22
141
|
export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
23
142
|
|
|
@@ -26,10 +145,16 @@ export const DEFAULT_WEB_PLUGINS: readonly SerializerPlugin[];
|
|
|
26
145
|
* first so they can shadow a default for values both would match. Returns a
|
|
27
146
|
* fresh array; the defaults are never mutated. Useful when handing a full
|
|
28
147
|
* plugin list to another serialization layer.
|
|
148
|
+
*
|
|
149
|
+
* Integration-facing; may change (see the entry banner).
|
|
29
150
|
*/
|
|
30
151
|
export function resolveSerializerPlugins(customPlugins?: SerializerPlugin[]): SerializerPlugin[];
|
|
31
152
|
|
|
32
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Options for `createSerializer`.
|
|
155
|
+
*
|
|
156
|
+
* Integration-facing; may change (see the entry banner).
|
|
157
|
+
*/
|
|
33
158
|
export interface WebSerializerOptions {
|
|
34
159
|
/** Name of the global object the emitted scripts write resolved values into. */
|
|
35
160
|
globalIdentifier: string;
|
|
@@ -58,6 +183,8 @@ export interface WebSerializerOptions {
|
|
|
58
183
|
* evaluated — the script-injection form of serialization renderers build
|
|
59
184
|
* on. For a JSON-based wire codec (no eval on the receiving side), use
|
|
60
185
|
* `serializeJSON` / `createJSONDeserializer` instead.
|
|
186
|
+
*
|
|
187
|
+
* Integration-facing; may change (see the entry banner).
|
|
61
188
|
*/
|
|
62
189
|
export function createSerializer(options: WebSerializerOptions): Serializer;
|
|
63
190
|
|
|
@@ -96,6 +223,8 @@ export function getLocalHeaderScript(id?: string): string;
|
|
|
96
223
|
* on the serializing and deserializing peer or payloads will not
|
|
97
224
|
* round-trip — for server functions, set them once through the
|
|
98
225
|
* client/server `codec` config option.
|
|
226
|
+
*
|
|
227
|
+
* Integration-facing; may change (see the entry banner).
|
|
99
228
|
*/
|
|
100
229
|
export interface JSONCodecOptions {
|
|
101
230
|
/** Extra plugins, composed ahead of `DEFAULT_WEB_PLUGINS`. Must match on both peers. */
|
|
@@ -113,7 +242,11 @@ export interface JSONCodecOptions {
|
|
|
113
242
|
depthLimit?: number;
|
|
114
243
|
}
|
|
115
244
|
|
|
116
|
-
/**
|
|
245
|
+
/**
|
|
246
|
+
* Options for `serializeJSON`.
|
|
247
|
+
*
|
|
248
|
+
* Integration-facing; may change (see the entry banner).
|
|
249
|
+
*/
|
|
117
250
|
export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
118
251
|
/**
|
|
119
252
|
* Receives each serialized node; `initial` is true for the first chunk
|
|
@@ -132,6 +265,8 @@ export interface JSONSerializeOptions extends JSONCodecOptions {
|
|
|
132
265
|
* the deserializing peer needs no script evaluation, so CSP-safe). Wire
|
|
133
266
|
* framing of the nodes is the transport's concern. Returns a cancel
|
|
134
267
|
* function that aborts pending async serialization.
|
|
268
|
+
*
|
|
269
|
+
* Integration-facing; may change (see the entry banner).
|
|
135
270
|
*/
|
|
136
271
|
export function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
|
|
137
272
|
|
|
@@ -141,14 +276,46 @@ export function serializeJSON(value: unknown, options: JSONSerializeOptions): ()
|
|
|
141
276
|
* from one stream must go through the same deserializer instance. The first
|
|
142
277
|
* chunk's return value is the decoded source value; feeding later chunks
|
|
143
278
|
* settles the async values referenced inside it.
|
|
279
|
+
*
|
|
280
|
+
* Integration-facing; may change (see the entry banner).
|
|
144
281
|
*/
|
|
145
282
|
export function createJSONDeserializer(options?: JSONCodecOptions): <T>(node: SerovalNode) => T;
|
|
146
283
|
|
|
284
|
+
/** Options for `createJSONSerializer`. */
|
|
285
|
+
export interface JSONSerializerOptions extends JSONCodecOptions {
|
|
286
|
+
/**
|
|
287
|
+
* Receives each keyed record — `initial` is true for a key's first node
|
|
288
|
+
* (the written value itself); async values patch through later records
|
|
289
|
+
* under the same key. The decoding peer is `createJSONDataTable`.
|
|
290
|
+
*/
|
|
291
|
+
onData: (record: { key: string; node: SerovalNode; initial: boolean }) => void;
|
|
292
|
+
onError?: (error: unknown) => void;
|
|
293
|
+
/** Fires once `flush()` has been called and every pending value settled. */
|
|
294
|
+
onDone?: () => void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* The keyed, streaming encoder of the eval-free JSON codec — the render
|
|
299
|
+
* stream's data serializer (frames default to it). Each `write(key, value)`
|
|
300
|
+
* shares one reference space, so cross-record identity holds; `flush()`
|
|
301
|
+
* marks the write set complete (writes after it are dropped, mirroring the
|
|
302
|
+
* hydration serializer); `close()` aborts pending async serialization.
|
|
303
|
+
*/
|
|
304
|
+
export function createJSONSerializer(options: JSONSerializerOptions): {
|
|
305
|
+
write(key: string, value: unknown): void;
|
|
306
|
+
flush(): void;
|
|
307
|
+
close(): void;
|
|
308
|
+
};
|
|
309
|
+
|
|
147
310
|
/**
|
|
148
311
|
* A resident, response-scoped decode table over the keyed JSON codec: apply
|
|
149
312
|
* each frame `data` chunk with `apply`, resolve `{ $ref }` slot args with
|
|
150
313
|
* `resolve`. The frames client host wires one per response
|
|
151
314
|
* (`applyData: c => table.apply(c)`).
|
|
315
|
+
*
|
|
316
|
+
* Integration-facing; may change (see the entry banner). This serialization
|
|
317
|
+
* entry is the single home of the data table — the frames client consumes
|
|
318
|
+
* it internally rather than re-exporting it.
|
|
152
319
|
*/
|
|
153
320
|
export interface JSONDataTable {
|
|
154
321
|
apply(chunk: { key?: string; node?: unknown; initial?: boolean }): void;
|