@solidjs/web 2.0.0-beta.31 → 2.0.0-beta.33

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 (73) hide show
  1. package/README.md +1 -6
  2. package/dist/dev.cjs +285 -60
  3. package/dist/dev.js +267 -57
  4. package/dist/server.cjs +1148 -176
  5. package/dist/server.js +1133 -175
  6. package/dist/web.cjs +285 -60
  7. package/dist/web.js +267 -57
  8. package/frames/dist/client.cjs +397 -175
  9. package/frames/dist/client.dev.cjs +401 -175
  10. package/frames/dist/client.dev.js +399 -173
  11. package/frames/dist/client.js +395 -173
  12. package/frames/dist/server.cjs +1424 -277
  13. package/frames/dist/server.js +1426 -280
  14. package/package.json +69 -7
  15. package/serialization/decode/package.json +20 -0
  16. package/serialization/dist/decode.cjs +110 -0
  17. package/serialization/dist/decode.js +104 -0
  18. package/serialization/dist/serialization.cjs +106 -43
  19. package/serialization/dist/serialization.js +100 -44
  20. package/serialization/types/index.d.ts +85 -60
  21. package/serialization/types/serializer-decode.d.ts +182 -0
  22. package/serialization/types-cjs/index.d.cts +85 -60
  23. package/serialization/types-cjs/serializer-decode.d.cts +182 -0
  24. package/server-functions/dist/client.cjs +131 -98
  25. package/server-functions/dist/client.js +131 -99
  26. package/server-functions/dist/rich-args.cjs +11 -0
  27. package/server-functions/dist/rich-args.js +9 -0
  28. package/server-functions/dist/server.cjs +367 -194
  29. package/server-functions/dist/server.dev.cjs +1077 -0
  30. package/server-functions/dist/server.dev.js +1045 -0
  31. package/server-functions/dist/server.js +365 -195
  32. package/server-functions/package.json +10 -0
  33. package/server-functions/rich-args/package.json +20 -0
  34. package/storage/types/index.d.ts +1 -1
  35. package/storage/types-cjs/index.d.cts +1 -1
  36. package/types/client.d.ts +149 -6
  37. package/types/cookies.d.ts +93 -0
  38. package/types/core.d.ts +4 -2
  39. package/types/frames/client.d.ts +15 -1
  40. package/types/frames/frame-client.d.ts +63 -7
  41. package/types/frames/frame-sink.d.ts +26 -3
  42. package/types/frames/frame-transport.d.ts +40 -8
  43. package/types/frames/serializer.d.ts +85 -60
  44. package/types/frames/server.d.ts +22 -0
  45. package/types/index.d.ts +2 -3
  46. package/types/response.d.ts +45 -0
  47. package/types/serializer-decode.d.ts +182 -0
  48. package/types/serializer.d.ts +85 -60
  49. package/types/server-functions/client.d.ts +2 -1
  50. package/types/server-functions/rich-args.d.ts +10 -0
  51. package/types/server-functions/server.d.ts +99 -1
  52. package/types/server-functions/shared.d.ts +79 -1
  53. package/types/server-mock.d.ts +171 -59
  54. package/types/server.d.ts +209 -37
  55. package/types-cjs/client.d.cts +149 -6
  56. package/types-cjs/cookies.d.cts +93 -0
  57. package/types-cjs/core.d.cts +4 -2
  58. package/types-cjs/frames/client.d.cts +15 -1
  59. package/types-cjs/frames/frame-client.d.cts +63 -7
  60. package/types-cjs/frames/frame-sink.d.cts +26 -3
  61. package/types-cjs/frames/frame-transport.d.cts +40 -8
  62. package/types-cjs/frames/serializer.d.cts +85 -60
  63. package/types-cjs/frames/server.d.cts +22 -0
  64. package/types-cjs/index.d.cts +2 -3
  65. package/types-cjs/response.d.cts +45 -0
  66. package/types-cjs/serializer-decode.d.cts +182 -0
  67. package/types-cjs/serializer.d.cts +85 -60
  68. package/types-cjs/server-functions/client.d.cts +2 -1
  69. package/types-cjs/server-functions/rich-args.d.cts +10 -0
  70. package/types-cjs/server-functions/server.d.cts +99 -1
  71. package/types-cjs/server-functions/shared.d.cts +79 -1
  72. package/types-cjs/server-mock.d.cts +171 -59
  73. package/types-cjs/server.d.cts +209 -37
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.31",
4
+ "version": "2.0.0-beta.33",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -33,8 +33,10 @@
33
33
  "serialization/types",
34
34
  "serialization/types-cjs",
35
35
  "serialization/package.json",
36
+ "serialization/decode/package.json",
36
37
  "server-functions/dist",
37
38
  "server-functions/package.json",
39
+ "server-functions/rich-args/package.json",
38
40
  "frames/dist",
39
41
  "frames/package.json"
40
42
  ],
@@ -149,8 +151,28 @@
149
151
  "default": "./serialization/dist/serialization.cjs"
150
152
  }
151
153
  },
154
+ "./serialization/decode": {
155
+ "import": {
156
+ "types": "./serialization/types/serializer-decode.d.ts",
157
+ "default": "./serialization/dist/decode.js"
158
+ },
159
+ "require": {
160
+ "types": "./serialization/types-cjs/serializer-decode.d.cts",
161
+ "default": "./serialization/dist/decode.cjs"
162
+ }
163
+ },
152
164
  "./server-functions": {
153
165
  "worker": {
166
+ "development": {
167
+ "import": {
168
+ "types": "./types/server-functions/server.d.ts",
169
+ "default": "./server-functions/dist/server.dev.js"
170
+ },
171
+ "require": {
172
+ "types": "./types-cjs/server-functions/server.d.cts",
173
+ "default": "./server-functions/dist/server.dev.cjs"
174
+ }
175
+ },
154
176
  "import": {
155
177
  "types": "./types/server-functions/server.d.ts",
156
178
  "default": "./server-functions/dist/server.js"
@@ -171,6 +193,16 @@
171
193
  }
172
194
  },
173
195
  "deno": {
196
+ "development": {
197
+ "import": {
198
+ "types": "./types/server-functions/server.d.ts",
199
+ "default": "./server-functions/dist/server.dev.js"
200
+ },
201
+ "require": {
202
+ "types": "./types-cjs/server-functions/server.d.cts",
203
+ "default": "./server-functions/dist/server.dev.cjs"
204
+ }
205
+ },
174
206
  "import": {
175
207
  "types": "./types/server-functions/server.d.ts",
176
208
  "default": "./server-functions/dist/server.js"
@@ -181,6 +213,16 @@
181
213
  }
182
214
  },
183
215
  "node": {
216
+ "development": {
217
+ "import": {
218
+ "types": "./types/server-functions/server.d.ts",
219
+ "default": "./server-functions/dist/server.dev.js"
220
+ },
221
+ "require": {
222
+ "types": "./types-cjs/server-functions/server.d.cts",
223
+ "default": "./server-functions/dist/server.dev.cjs"
224
+ }
225
+ },
184
226
  "import": {
185
227
  "types": "./types/server-functions/server.d.ts",
186
228
  "default": "./server-functions/dist/server.js"
@@ -200,6 +242,16 @@
200
242
  }
201
243
  },
202
244
  "./server-functions/server": {
245
+ "development": {
246
+ "import": {
247
+ "types": "./types/server-functions/server.d.ts",
248
+ "default": "./server-functions/dist/server.dev.js"
249
+ },
250
+ "require": {
251
+ "types": "./types-cjs/server-functions/server.d.cts",
252
+ "default": "./server-functions/dist/server.dev.cjs"
253
+ }
254
+ },
203
255
  "import": {
204
256
  "types": "./types/server-functions/server.d.ts",
205
257
  "default": "./server-functions/dist/server.js"
@@ -219,6 +271,16 @@
219
271
  "default": "./server-functions/dist/client.cjs"
220
272
  }
221
273
  },
274
+ "./server-functions/rich-args": {
275
+ "import": {
276
+ "types": "./types/server-functions/rich-args.d.ts",
277
+ "default": "./server-functions/dist/rich-args.js"
278
+ },
279
+ "require": {
280
+ "types": "./types-cjs/server-functions/rich-args.d.cts",
281
+ "default": "./server-functions/dist/rich-args.cjs"
282
+ }
283
+ },
222
284
  "./frames": {
223
285
  "worker": {
224
286
  "import": {
@@ -316,25 +378,25 @@
316
378
  "seroval-plugins": "~1.5.4"
317
379
  },
318
380
  "peerDependencies": {
319
- "solid-js": "^2.0.0-beta.31"
381
+ "solid-js": "^2.0.0-beta.33"
320
382
  },
321
383
  "devDependencies": {
322
- "solid-js": "2.0.0-beta.31"
384
+ "solid-js": "2.0.0-beta.33"
323
385
  },
324
386
  "scripts": {
325
387
  "build": "npm-run-all -nl build:clean types:copy-jsx build:js",
326
388
  "build:clean": "rimraf dist/",
327
389
  "build:js": "rollup -c",
328
390
  "link": "symlink-dir . node_modules/@solidjs/web",
329
- "types": "npm-run-all -nl types:clean types:copy-jsx types:web types:copy-web types:web-storage types:copy-server-functions types:web-frames types:copy-serialization types:copy-frames types:cjs",
391
+ "types": "npm-run-all -nl types:clean types:copy-jsx types:web types:copy-web types:web-storage types:copy-server-functions types:copy-serialization types:web-frames types:copy-frames types:cjs",
330
392
  "types:clean": "rimraf types/ types-cjs/ storage/types/ storage/types-cjs/ serialization/types/ serialization/types-cjs/ frames/types/",
331
393
  "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\";'",
332
394
  "types:web": "tsc --project ./tsconfig.build.json",
333
- "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",
395
+ "types:copy-web": "node -e \"const src = fs.readFileSync('../../node_modules/@dom-expressions/runtime/src/client.d.ts', 'utf8'); const marker = 'export type { RequestEventLocals } from'; if (!src.includes(marker)) throw new Error('client.d.ts drift: the type-only RequestEventLocals re-export was not found — revisit the augmentation-identity rewrite'); fs.writeFileSync('./types/client.d.ts', src.replace(marker, 'export { RequestEventLocals } from'));\" && 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/serializer-decode.d.ts ./types/serializer-decode.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/response.d.ts ./types/response.d.ts && ncp ../../node_modules/@dom-expressions/runtime/src/cookies.d.ts ./types/cookies.d.ts && ncp ./src/jsx.d.ts ./types/jsx.d.ts && ncp ./src/jsx-properties.d.ts ./types/jsx-properties.d.ts",
334
396
  "types:web-storage": "tsc --project ./storage/tsconfig.build.json",
335
397
  "types:web-frames": "tsc --project ./frames/tsconfig.build.json",
336
- "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');\"",
398
+ "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'); fs.copyFileSync('../../node_modules/@dom-expressions/runtime/src/serializer-decode.d.ts', './serialization/types/serializer-decode.d.ts');\"",
399
+ "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
400
  "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
401
  "types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./storage/types ./storage/types-cjs ./serialization/types ./serialization/types-cjs",
340
402
  "test": "vitest run && vitest run --config vite.config.server.mjs && vitest run --config vite.config.hydrate.mjs",
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@solidjs/web/serialization/decode",
3
+ "main": "../dist/decode.cjs",
4
+ "module": "../dist/decode.js",
5
+ "types": "../types/serializer-decode.d.ts",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "../types/serializer-decode.d.ts",
12
+ "default": "../dist/decode.js"
13
+ },
14
+ "require": {
15
+ "types": "../types-cjs/serializer-decode.d.cts",
16
+ "default": "../dist/decode.cjs"
17
+ }
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,110 @@
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
+ exports.DEFAULT_WEB_PLUGINS = DEFAULT_WEB_PLUGINS;
107
+ exports.createJSONDataTable = createJSONDataTable;
108
+ exports.createJSONDeserializer = createJSONDeserializer;
109
+ exports.resolveCodecOptions = resolveCodecOptions;
110
+ exports.resolveSerializerPlugins = resolveSerializerPlugins;
@@ -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 };
@@ -3,15 +3,109 @@
3
3
  var seroval = require('seroval');
4
4
  var web = require('seroval-plugins/web');
5
5
 
6
- const DEFAULT_DISABLED_FEATURES = seroval.Feature.AggregateError | seroval.Feature.BigIntTypedArray;
7
- const serializeOnlyDisabledFeatures = () => process.env.NODE_ENV === "development" ? 0 : seroval.Feature.ErrorPrototypeStack;
8
- const HYDRATION_GLOBAL = "_$HY.r";
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
+
9
59
  const DEFAULT_WEB_PLUGINS = Object.freeze([web.AbortSignalPlugin,
10
60
  web.CustomEventPlugin, web.DOMExceptionPlugin, web.EventPlugin,
11
- web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin]);
61
+ web.FormDataPlugin, web.HeadersPlugin, web.ReadableStreamPlugin, web.RequestPlugin, web.ResponsePlugin, web.URLSearchParamsPlugin, web.URLPlugin,
62
+ ContainerTracePlugin]);
12
63
  function resolveSerializerPlugins(customPlugins) {
13
64
  return customPlugins ? [...customPlugins, ...DEFAULT_WEB_PLUGINS] : [...DEFAULT_WEB_PLUGINS];
14
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";
15
109
  function createSerializer(options) {
16
110
  return new seroval.Serializer({
17
111
  ...options,
@@ -38,19 +132,6 @@ function createHydrationSerializer({
38
132
  function getLocalHeaderScript(id) {
39
133
  return seroval.getCrossReferenceHeader(id) + ";";
40
134
  }
41
- const JSON_CODEC_DISABLED_FEATURES = seroval.Feature.RegExp;
42
- const JSON_CODEC_DEPTH_LIMIT = 64;
43
- function resolveCodecOptions({
44
- plugins,
45
- disabledFeatures,
46
- depthLimit
47
- } = {}) {
48
- return {
49
- plugins: resolveSerializerPlugins(plugins),
50
- disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
51
- depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
52
- };
53
- }
54
135
  function serializeJSON(value, {
55
136
  onParse,
56
137
  onDone,
@@ -66,16 +147,6 @@ function serializeJSON(value, {
66
147
  disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
67
148
  });
68
149
  }
69
- function createJSONDeserializer(options) {
70
- const refs = new Map();
71
- const resolved = resolveCodecOptions(options);
72
- return function deserializeJSONChunk(node) {
73
- return seroval.fromCrossJSON(node, {
74
- refs,
75
- ...resolved
76
- });
77
- };
78
- }
79
150
  function createJSONSerializer({
80
151
  onData,
81
152
  onDone,
@@ -141,23 +212,15 @@ function createJSONSerializer({
141
212
  }
142
213
  };
143
214
  }
144
- function createJSONDataTable(options) {
145
- const deserialize = createJSONDeserializer(options);
146
- const table = new Map();
147
- return {
148
- apply(record) {
149
- const value = deserialize(record.node);
150
- if (record.initial) table.set(record.key, value);
151
- },
152
- get(key) {
153
- return table.get(key);
154
- },
155
- resolve(ref) {
156
- return table.get(ref.$ref);
157
- }
158
- };
159
- }
160
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
+ });
161
224
  exports.DEFAULT_WEB_PLUGINS = DEFAULT_WEB_PLUGINS;
162
225
  exports.createHydrationSerializer = createHydrationSerializer;
163
226
  exports.createJSONDataTable = createJSONDataTable;