@solidjs/web 2.0.0-experimental.9 → 2.0.0-rc.0
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 +22 -4
- package/dist/dev.cjs +1585 -225
- package/dist/dev.js +1510 -201
- package/dist/server.cjs +2642 -264
- package/dist/server.js +2542 -217
- package/dist/web.cjs +1523 -218
- package/dist/web.js +1448 -194
- package/frames/dist/client.cjs +1916 -0
- package/frames/dist/client.dev.cjs +1933 -0
- package/frames/dist/client.dev.js +1921 -0
- package/frames/dist/client.js +1904 -0
- package/frames/dist/server.cjs +3667 -0
- package/frames/dist/server.js +3654 -0
- package/frames/package.json +30 -0
- package/package.json +349 -37
- package/serialization/decode/package.json +20 -0
- package/serialization/dist/decode.cjs +110 -0
- package/serialization/dist/decode.js +104 -0
- package/serialization/dist/serialization.cjs +232 -0
- package/serialization/dist/serialization.js +215 -0
- package/serialization/package.json +20 -0
- package/serialization/types/index.d.ts +182 -0
- package/serialization/types/serializer-decode.d.ts +182 -0
- package/serialization/types-cjs/index.d.cts +182 -0
- package/serialization/types-cjs/package.json +3 -0
- package/serialization/types-cjs/serializer-decode.d.cts +182 -0
- package/server-functions/dist/client.cjs +646 -0
- package/server-functions/dist/client.js +617 -0
- package/server-functions/dist/rich-args.cjs +11 -0
- package/server-functions/dist/rich-args.js +9 -0
- package/server-functions/dist/server.cjs +1077 -0
- package/server-functions/dist/server.dev.cjs +1077 -0
- package/server-functions/dist/server.dev.js +1045 -0
- package/server-functions/dist/server.js +1045 -0
- package/server-functions/package.json +40 -0
- package/server-functions/rich-args/package.json +20 -0
- package/storage/package.json +8 -3
- package/storage/types/index.d.ts +26 -0
- package/storage/types-cjs/index.d.cts +28 -0
- package/storage/types-cjs/package.json +3 -0
- package/types/client.d.ts +290 -27
- package/types/cookies.d.ts +93 -0
- package/types/core.d.ts +6 -2
- package/types/frames/client.d.ts +36 -0
- package/types/frames/frame-client.d.ts +338 -0
- package/types/frames/frame-sink.d.ts +194 -0
- package/types/frames/frame-transport.d.ts +222 -0
- package/types/frames/serializer.d.ts +182 -0
- package/types/frames/server.d.ts +52 -0
- package/types/index.d.ts +209 -24
- package/types/jsx-properties.d.ts +93 -0
- package/types/jsx.d.ts +4150 -1
- package/types/response.d.ts +174 -0
- package/types/serializer-decode.d.ts +182 -0
- package/types/serializer.d.ts +182 -0
- package/types/server-functions/client.d.ts +201 -0
- package/types/server-functions/flash.d.ts +38 -0
- package/types/server-functions/rich-args.d.ts +10 -0
- package/types/server-functions/server.d.ts +588 -0
- package/types/server-functions/shared.d.ts +523 -0
- package/types/server-mock.d.ts +249 -12
- package/types/server.d.ts +424 -51
- package/types-cjs/client.d.cts +337 -0
- package/types-cjs/cookies.d.cts +93 -0
- package/types-cjs/core.d.cts +6 -0
- package/types-cjs/frames/client.d.cts +36 -0
- package/types-cjs/frames/frame-client.d.cts +338 -0
- package/types-cjs/frames/frame-sink.d.cts +194 -0
- package/types-cjs/frames/frame-transport.d.cts +222 -0
- package/types-cjs/frames/serializer.d.cts +182 -0
- package/types-cjs/frames/server.d.cts +52 -0
- package/types-cjs/index.d.cts +230 -0
- package/types-cjs/jsx-properties.d.cts +93 -0
- package/types-cjs/jsx.d.cts +4150 -0
- package/types-cjs/package.json +3 -0
- package/types-cjs/response.d.cts +174 -0
- package/types-cjs/serializer-decode.d.cts +182 -0
- package/types-cjs/serializer.d.cts +182 -0
- package/types-cjs/server-functions/client.d.cts +201 -0
- package/types-cjs/server-functions/flash.d.cts +38 -0
- package/types-cjs/server-functions/rich-args.d.cts +10 -0
- package/types-cjs/server-functions/server.d.cts +588 -0
- package/types-cjs/server-functions/shared.d.cts +523 -0
- package/types-cjs/server-mock.d.cts +277 -0
- package/types-cjs/server.d.cts +523 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Feature, fromCrossJSON } from 'seroval';
|
|
2
|
+
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
3
|
+
|
|
4
|
+
const STATE = Symbol.for("dom-expressions.container-trace-state");
|
|
5
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
6
|
+
materialized: new WeakMap(),
|
|
7
|
+
materializedValues: new WeakSet()
|
|
8
|
+
});
|
|
9
|
+
const TRACE = Symbol.for("dom-expressions.container-trace");
|
|
10
|
+
function materialize(marker) {
|
|
11
|
+
let value = state.materialized.get(marker.$tr);
|
|
12
|
+
if (value === undefined) {
|
|
13
|
+
value = state.materializeTrace(marker);
|
|
14
|
+
state.materialized.set(marker.$tr, value);
|
|
15
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function parseTrace(value, ctx) {
|
|
20
|
+
const trace = value[TRACE];
|
|
21
|
+
return {
|
|
22
|
+
a: trace.array ? 1 : 0,
|
|
23
|
+
i: ctx.parse(trace.subscribe())
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const ContainerTracePlugin = {
|
|
27
|
+
tag: "dom-expressions/container-trace",
|
|
28
|
+
test(value) {
|
|
29
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
30
|
+
},
|
|
31
|
+
parse: {
|
|
32
|
+
sync() {
|
|
33
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
34
|
+
},
|
|
35
|
+
async async(value, ctx) {
|
|
36
|
+
const trace = value[TRACE];
|
|
37
|
+
return {
|
|
38
|
+
a: trace.array ? 1 : 0,
|
|
39
|
+
i: await ctx.parse(trace.subscribe())
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
stream: parseTrace
|
|
43
|
+
},
|
|
44
|
+
serialize(node, ctx) {
|
|
45
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
46
|
+
},
|
|
47
|
+
deserialize(node, ctx) {
|
|
48
|
+
const iterable = ctx.deserialize(node.i);
|
|
49
|
+
const marker = {
|
|
50
|
+
$tr: iterable,
|
|
51
|
+
$ta: node.a
|
|
52
|
+
};
|
|
53
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
58
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
59
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
60
|
+
ContainerTracePlugin]);
|
|
61
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
62
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
63
|
+
}
|
|
64
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
65
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
66
|
+
function resolveCodecOptions({
|
|
67
|
+
plugins,
|
|
68
|
+
disabledFeatures,
|
|
69
|
+
depthLimit
|
|
70
|
+
} = {}) {
|
|
71
|
+
return {
|
|
72
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
73
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
74
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createJSONDeserializer(options) {
|
|
78
|
+
const refs = new Map();
|
|
79
|
+
const resolved = resolveCodecOptions(options);
|
|
80
|
+
return function deserializeJSONChunk(node) {
|
|
81
|
+
return fromCrossJSON(node, {
|
|
82
|
+
refs,
|
|
83
|
+
...resolved
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createJSONDataTable(options) {
|
|
88
|
+
const deserialize = createJSONDeserializer(options);
|
|
89
|
+
const table = new Map();
|
|
90
|
+
return {
|
|
91
|
+
apply(record) {
|
|
92
|
+
const value = deserialize(record.node);
|
|
93
|
+
if (record.initial) table.set(record.key, value);
|
|
94
|
+
},
|
|
95
|
+
get(key) {
|
|
96
|
+
return table.get(key);
|
|
97
|
+
},
|
|
98
|
+
resolve(ref) {
|
|
99
|
+
return table.get(ref.$ref);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { DEFAULT_WEB_PLUGINS, createJSONDataTable, createJSONDeserializer, resolveCodecOptions, resolveSerializerPlugins };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var seroval = require('seroval');
|
|
4
|
+
var web = require('seroval-plugins/web');
|
|
5
|
+
|
|
6
|
+
const STATE = Symbol.for("dom-expressions.container-trace-state");
|
|
7
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
8
|
+
materialized: new WeakMap(),
|
|
9
|
+
materializedValues: new WeakSet()
|
|
10
|
+
});
|
|
11
|
+
const TRACE = Symbol.for("dom-expressions.container-trace");
|
|
12
|
+
function materialize(marker) {
|
|
13
|
+
let value = state.materialized.get(marker.$tr);
|
|
14
|
+
if (value === undefined) {
|
|
15
|
+
value = state.materializeTrace(marker);
|
|
16
|
+
state.materialized.set(marker.$tr, value);
|
|
17
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function parseTrace(value, ctx) {
|
|
22
|
+
const trace = value[TRACE];
|
|
23
|
+
return {
|
|
24
|
+
a: trace.array ? 1 : 0,
|
|
25
|
+
i: ctx.parse(trace.subscribe())
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const ContainerTracePlugin = {
|
|
29
|
+
tag: "dom-expressions/container-trace",
|
|
30
|
+
test(value) {
|
|
31
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
32
|
+
},
|
|
33
|
+
parse: {
|
|
34
|
+
sync() {
|
|
35
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
36
|
+
},
|
|
37
|
+
async async(value, ctx) {
|
|
38
|
+
const trace = value[TRACE];
|
|
39
|
+
return {
|
|
40
|
+
a: trace.array ? 1 : 0,
|
|
41
|
+
i: await ctx.parse(trace.subscribe())
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
stream: parseTrace
|
|
45
|
+
},
|
|
46
|
+
serialize(node, ctx) {
|
|
47
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
48
|
+
},
|
|
49
|
+
deserialize(node, ctx) {
|
|
50
|
+
const iterable = ctx.deserialize(node.i);
|
|
51
|
+
const marker = {
|
|
52
|
+
$tr: iterable,
|
|
53
|
+
$ta: node.a
|
|
54
|
+
};
|
|
55
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
|
|
60
|
+
web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
|
|
61
|
+
web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin,
|
|
62
|
+
ContainerTracePlugin]);
|
|
63
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
64
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
65
|
+
}
|
|
66
|
+
const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
|
|
67
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
68
|
+
function resolveCodecOptions({
|
|
69
|
+
plugins,
|
|
70
|
+
disabledFeatures,
|
|
71
|
+
depthLimit
|
|
72
|
+
} = {}) {
|
|
73
|
+
return {
|
|
74
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
75
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
76
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function createJSONDeserializer(options) {
|
|
80
|
+
const refs = new Map();
|
|
81
|
+
const resolved = resolveCodecOptions(options);
|
|
82
|
+
return function deserializeJSONChunk(node) {
|
|
83
|
+
return seroval.fromCrossJSON(node, {
|
|
84
|
+
refs,
|
|
85
|
+
...resolved
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function createJSONDataTable(options) {
|
|
90
|
+
const deserialize = createJSONDeserializer(options);
|
|
91
|
+
const table = new Map();
|
|
92
|
+
return {
|
|
93
|
+
apply(record) {
|
|
94
|
+
const value = deserialize(record.node);
|
|
95
|
+
if (record.initial) table.set(record.key, value);
|
|
96
|
+
},
|
|
97
|
+
get(key) {
|
|
98
|
+
return table.get(key);
|
|
99
|
+
},
|
|
100
|
+
resolve(ref) {
|
|
101
|
+
return table.get(ref.$ref);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
|
|
107
|
+
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
|
|
108
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
109
|
+
function createSerializer(options) {
|
|
110
|
+
return new seroval.Serializer({
|
|
111
|
+
...options,
|
|
112
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
113
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function createHydrationSerializer({
|
|
117
|
+
onData,
|
|
118
|
+
onDone,
|
|
119
|
+
scopeId,
|
|
120
|
+
onError,
|
|
121
|
+
plugins
|
|
122
|
+
}) {
|
|
123
|
+
return createSerializer({
|
|
124
|
+
scopeId,
|
|
125
|
+
plugins,
|
|
126
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
127
|
+
onData,
|
|
128
|
+
onDone,
|
|
129
|
+
onError
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function getLocalHeaderScript(id) {
|
|
133
|
+
return seroval.getCrossReferenceHeader(id) + ";";
|
|
134
|
+
}
|
|
135
|
+
function serializeJSON(value, {
|
|
136
|
+
onParse,
|
|
137
|
+
onDone,
|
|
138
|
+
onError,
|
|
139
|
+
...codecOptions
|
|
140
|
+
}) {
|
|
141
|
+
const resolved = resolveCodecOptions(codecOptions);
|
|
142
|
+
return seroval.toCrossJSONStream(value, {
|
|
143
|
+
onParse,
|
|
144
|
+
onDone,
|
|
145
|
+
onError,
|
|
146
|
+
...resolved,
|
|
147
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function createJSONSerializer({
|
|
151
|
+
onData,
|
|
152
|
+
onDone,
|
|
153
|
+
onError,
|
|
154
|
+
plugins,
|
|
155
|
+
disabledFeatures,
|
|
156
|
+
depthLimit
|
|
157
|
+
}) {
|
|
158
|
+
const resolved = resolveCodecOptions({
|
|
159
|
+
plugins,
|
|
160
|
+
disabledFeatures,
|
|
161
|
+
depthLimit
|
|
162
|
+
});
|
|
163
|
+
const refs = new Map();
|
|
164
|
+
const cancels = new Set();
|
|
165
|
+
let pendingWrites = 0;
|
|
166
|
+
let flushed = false;
|
|
167
|
+
let done = false;
|
|
168
|
+
const maybeDone = () => {
|
|
169
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
170
|
+
done = true;
|
|
171
|
+
onDone && onDone();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
write(key, value) {
|
|
176
|
+
if (flushed) return;
|
|
177
|
+
pendingWrites++;
|
|
178
|
+
let settled = false;
|
|
179
|
+
let cancel = null;
|
|
180
|
+
const stream = seroval.toCrossJSONStream(value, {
|
|
181
|
+
refs,
|
|
182
|
+
plugins: resolved.plugins,
|
|
183
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
|
|
184
|
+
onParse(node, initial) {
|
|
185
|
+
onData({
|
|
186
|
+
key,
|
|
187
|
+
node,
|
|
188
|
+
initial
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
onError,
|
|
192
|
+
onDone() {
|
|
193
|
+
settled = true;
|
|
194
|
+
if (cancel) cancels.delete(cancel);
|
|
195
|
+
pendingWrites--;
|
|
196
|
+
maybeDone();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
if (!settled) {
|
|
200
|
+
cancel = stream;
|
|
201
|
+
cancels.add(cancel);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
flush() {
|
|
205
|
+
flushed = true;
|
|
206
|
+
maybeDone();
|
|
207
|
+
},
|
|
208
|
+
close() {
|
|
209
|
+
flushed = true;
|
|
210
|
+
for (const cancel of cancels) cancel();
|
|
211
|
+
cancels.clear();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
Object.defineProperty(exports, "OpaqueReference", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () { return seroval.OpaqueReference; }
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () { return seroval.createPlugin; }
|
|
223
|
+
});
|
|
224
|
+
exports.DEFAULT_WEB_PLUGINS = DEFAULT_WEB_PLUGINS;
|
|
225
|
+
exports.createHydrationSerializer = createHydrationSerializer;
|
|
226
|
+
exports.createJSONDataTable = createJSONDataTable;
|
|
227
|
+
exports.createJSONDeserializer = createJSONDeserializer;
|
|
228
|
+
exports.createJSONSerializer = createJSONSerializer;
|
|
229
|
+
exports.createSerializer = createSerializer;
|
|
230
|
+
exports.getLocalHeaderScript = getLocalHeaderScript;
|
|
231
|
+
exports.resolveSerializerPlugins = resolveSerializerPlugins;
|
|
232
|
+
exports.serializeJSON = serializeJSON;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Feature, fromCrossJSON, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
2
|
+
export { OpaqueReference, createPlugin } from 'seroval';
|
|
3
|
+
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
4
|
+
|
|
5
|
+
const STATE = Symbol.for("dom-expressions.container-trace-state");
|
|
6
|
+
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
7
|
+
materialized: new WeakMap(),
|
|
8
|
+
materializedValues: new WeakSet()
|
|
9
|
+
});
|
|
10
|
+
const TRACE = Symbol.for("dom-expressions.container-trace");
|
|
11
|
+
function materialize(marker) {
|
|
12
|
+
let value = state.materialized.get(marker.$tr);
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
value = state.materializeTrace(marker);
|
|
15
|
+
state.materialized.set(marker.$tr, value);
|
|
16
|
+
if (value !== null && typeof value === "object") state.materializedValues.add(value);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function parseTrace(value, ctx) {
|
|
21
|
+
const trace = value[TRACE];
|
|
22
|
+
return {
|
|
23
|
+
a: trace.array ? 1 : 0,
|
|
24
|
+
i: ctx.parse(trace.subscribe())
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ContainerTracePlugin = {
|
|
28
|
+
tag: "dom-expressions/container-trace",
|
|
29
|
+
test(value) {
|
|
30
|
+
return value != null && typeof value === "object" && TRACE in value;
|
|
31
|
+
},
|
|
32
|
+
parse: {
|
|
33
|
+
sync() {
|
|
34
|
+
throw new Error("A reactive container can only be serialized by a streaming serializer.");
|
|
35
|
+
},
|
|
36
|
+
async async(value, ctx) {
|
|
37
|
+
const trace = value[TRACE];
|
|
38
|
+
return {
|
|
39
|
+
a: trace.array ? 1 : 0,
|
|
40
|
+
i: await ctx.parse(trace.subscribe())
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
stream: parseTrace
|
|
44
|
+
},
|
|
45
|
+
serialize(node, ctx) {
|
|
46
|
+
return "{$tr:" + ctx.serialize(node.i) + ",$ta:" + node.a + "}";
|
|
47
|
+
},
|
|
48
|
+
deserialize(node, ctx) {
|
|
49
|
+
const iterable = ctx.deserialize(node.i);
|
|
50
|
+
const marker = {
|
|
51
|
+
$tr: iterable,
|
|
52
|
+
$ta: node.a
|
|
53
|
+
};
|
|
54
|
+
return state.materializeTrace ? materialize(marker) : marker;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
59
|
+
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
60
|
+
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
61
|
+
ContainerTracePlugin]);
|
|
62
|
+
function resolveSerializerPlugins(customPlugins) {
|
|
63
|
+
return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
|
|
64
|
+
}
|
|
65
|
+
const JSON_CODEC_DISABLED_FEATURES = Feature.RegExp;
|
|
66
|
+
const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
67
|
+
function resolveCodecOptions({
|
|
68
|
+
plugins,
|
|
69
|
+
disabledFeatures,
|
|
70
|
+
depthLimit
|
|
71
|
+
} = {}) {
|
|
72
|
+
return {
|
|
73
|
+
plugins: resolveSerializerPlugins(plugins),
|
|
74
|
+
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
75
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function createJSONDeserializer(options) {
|
|
79
|
+
const refs = new Map();
|
|
80
|
+
const resolved = resolveCodecOptions(options);
|
|
81
|
+
return function deserializeJSONChunk(node) {
|
|
82
|
+
return fromCrossJSON(node, {
|
|
83
|
+
refs,
|
|
84
|
+
...resolved
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createJSONDataTable(options) {
|
|
89
|
+
const deserialize = createJSONDeserializer(options);
|
|
90
|
+
const table = new Map();
|
|
91
|
+
return {
|
|
92
|
+
apply(record) {
|
|
93
|
+
const value = deserialize(record.node);
|
|
94
|
+
if (record.initial) table.set(record.key, value);
|
|
95
|
+
},
|
|
96
|
+
get(key) {
|
|
97
|
+
return table.get(key);
|
|
98
|
+
},
|
|
99
|
+
resolve(ref) {
|
|
100
|
+
return table.get(ref.$ref);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
106
|
+
const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : Feature.ErrorPrototypeStack;
|
|
107
|
+
const HYDRATION_GLOBAL = "_$HY.r";
|
|
108
|
+
function createSerializer(options) {
|
|
109
|
+
return new Serializer({
|
|
110
|
+
...options,
|
|
111
|
+
plugins: resolveSerializerPlugins(options.plugins),
|
|
112
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function createHydrationSerializer({
|
|
116
|
+
onData,
|
|
117
|
+
onDone,
|
|
118
|
+
scopeId,
|
|
119
|
+
onError,
|
|
120
|
+
plugins
|
|
121
|
+
}) {
|
|
122
|
+
return createSerializer({
|
|
123
|
+
scopeId,
|
|
124
|
+
plugins,
|
|
125
|
+
globalIdentifier: HYDRATION_GLOBAL,
|
|
126
|
+
onData,
|
|
127
|
+
onDone,
|
|
128
|
+
onError
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function getLocalHeaderScript(id) {
|
|
132
|
+
return getCrossReferenceHeader(id) + ";";
|
|
133
|
+
}
|
|
134
|
+
function serializeJSON(value, {
|
|
135
|
+
onParse,
|
|
136
|
+
onDone,
|
|
137
|
+
onError,
|
|
138
|
+
...codecOptions
|
|
139
|
+
}) {
|
|
140
|
+
const resolved = resolveCodecOptions(codecOptions);
|
|
141
|
+
return toCrossJSONStream(value, {
|
|
142
|
+
onParse,
|
|
143
|
+
onDone,
|
|
144
|
+
onError,
|
|
145
|
+
...resolved,
|
|
146
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function createJSONSerializer({
|
|
150
|
+
onData,
|
|
151
|
+
onDone,
|
|
152
|
+
onError,
|
|
153
|
+
plugins,
|
|
154
|
+
disabledFeatures,
|
|
155
|
+
depthLimit
|
|
156
|
+
}) {
|
|
157
|
+
const resolved = resolveCodecOptions({
|
|
158
|
+
plugins,
|
|
159
|
+
disabledFeatures,
|
|
160
|
+
depthLimit
|
|
161
|
+
});
|
|
162
|
+
const refs = new Map();
|
|
163
|
+
const cancels = new Set();
|
|
164
|
+
let pendingWrites = 0;
|
|
165
|
+
let flushed = false;
|
|
166
|
+
let done = false;
|
|
167
|
+
const maybeDone = () => {
|
|
168
|
+
if (flushed && pendingWrites === 0 && !done) {
|
|
169
|
+
done = true;
|
|
170
|
+
onDone && onDone();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
write(key, value) {
|
|
175
|
+
if (flushed) return;
|
|
176
|
+
pendingWrites++;
|
|
177
|
+
let settled = false;
|
|
178
|
+
let cancel = null;
|
|
179
|
+
const stream = toCrossJSONStream(value, {
|
|
180
|
+
refs,
|
|
181
|
+
plugins: resolved.plugins,
|
|
182
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
|
|
183
|
+
onParse(node, initial) {
|
|
184
|
+
onData({
|
|
185
|
+
key,
|
|
186
|
+
node,
|
|
187
|
+
initial
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
onError,
|
|
191
|
+
onDone() {
|
|
192
|
+
settled = true;
|
|
193
|
+
if (cancel) cancels.delete(cancel);
|
|
194
|
+
pendingWrites--;
|
|
195
|
+
maybeDone();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
if (!settled) {
|
|
199
|
+
cancel = stream;
|
|
200
|
+
cancels.add(cancel);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
flush() {
|
|
204
|
+
flushed = true;
|
|
205
|
+
maybeDone();
|
|
206
|
+
},
|
|
207
|
+
close() {
|
|
208
|
+
flushed = true;
|
|
209
|
+
for (const cancel of cancels) cancel();
|
|
210
|
+
cancels.clear();
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { DEFAULT_WEB_PLUGINS, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createSerializer, getLocalHeaderScript, resolveSerializerPlugins, serializeJSON };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solidjs/web/serialization",
|
|
3
|
+
"main": "./dist/serialization.cjs",
|
|
4
|
+
"module": "./dist/serialization.js",
|
|
5
|
+
"types": "./types/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"default": "./dist/serialization.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./types-cjs/index.d.cts",
|
|
16
|
+
"default": "./dist/serialization.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|