@solidjs/web 2.0.0-rc.1 → 2.0.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.dev.js +4472 -0
- package/dist/server.js +1301 -251
- package/dist/{server.cjs → server.observe.js} +1501 -452
- package/dist/{dev.cjs → web.dev.js} +699 -360
- package/dist/web.js +454 -139
- package/dist/{dev.js → web.observe.js} +505 -211
- package/frames/dist/client.dev.js +463 -71
- package/frames/dist/client.js +363 -70
- package/frames/dist/{client.dev.cjs → client.observe.js} +486 -133
- package/frames/dist/server.dev.js +1713 -0
- package/frames/dist/server.js +552 -2583
- package/frames/dist/server.observe.js +1713 -0
- package/frames/package.json +2 -25
- package/package.json +214 -255
- package/performance-tracks/dist/performance-tracks.dev.js +678 -0
- package/performance-tracks/dist/performance-tracks.js +6 -0
- package/performance-tracks/dist/performance-tracks.observe.js +666 -0
- package/performance-tracks/package.json +7 -0
- package/performance-tracks/types/index.d.ts +67 -0
- package/serialization/decode/package.json +2 -15
- package/serialization/dist/decode.js +92 -15
- package/serialization/dist/serialization.js +103 -23
- package/serialization/package.json +2 -15
- package/serialization/types/index.d.ts +76 -157
- package/serialization/types/serializer-decode.d.ts +149 -112
- package/serialization/types/serializer.d.ts +101 -0
- package/server-functions/dist/client.dev.js +1364 -0
- package/server-functions/dist/client.js +611 -97
- package/server-functions/dist/client.observe.js +1343 -0
- package/server-functions/dist/server.dev.js +2138 -202
- package/server-functions/dist/server.js +2042 -199
- package/server-functions/dist/server.observe.js +3043 -0
- package/server-functions/package.json +2 -35
- package/server-functions/rich-args/package.json +2 -15
- package/storage/package.json +2 -15
- package/types/client.d.ts +193 -288
- package/types/constants.d.ts +20 -0
- package/types/cookies.d.ts +32 -84
- package/types/diagnostics.d.ts +56 -0
- package/types/frames/client.d.ts +1 -1
- package/types/frames/frame-client.d.ts +323 -259
- package/types/frames/frame-container-plugin.d.ts +72 -0
- package/types/frames/frame-sink.d.ts +101 -158
- package/types/frames/frame-transport.d.ts +192 -190
- package/types/frames/serializer-decode.d.ts +219 -0
- package/types/frames/serializer.d.ts +76 -157
- package/types/frames/server.d.ts +1 -1
- package/types/head.d.ts +19 -0
- package/types/index.d.ts +52 -80
- package/types/index.server.d.ts +174 -0
- package/types/jsx.d.ts +33 -35
- package/types/observe.d.ts +358 -0
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +9 -0
- package/types/response.d.ts +75 -150
- package/types/serializer-decode.d.ts +149 -112
- package/types/serializer.d.ts +76 -157
- package/types/server-functions/client.d.ts +192 -194
- package/types/server-functions/flash.d.ts +28 -30
- package/types/server-functions/registry.d.ts +102 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +511 -475
- package/types/server-functions/shared.d.ts +366 -425
- package/types/server-mock.d.ts +110 -13
- package/types/server-observe.d.ts +77 -0
- package/types/server.d.ts +425 -425
- package/types/trace.d.ts +127 -0
- package/LICENSE +0 -21
- package/dist/web.cjs +0 -2008
- package/frames/dist/client.cjs +0 -1916
- package/frames/dist/server.cjs +0 -3756
- package/serialization/dist/decode.cjs +0 -122
- package/serialization/dist/serialization.cjs +0 -244
- package/serialization/types-cjs/index.d.cts +0 -182
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -182
- package/server-functions/dist/client.cjs +0 -793
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.cjs +0 -1171
- package/server-functions/dist/server.dev.cjs +0 -1171
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types/core.d.ts +0 -6
- package/types-cjs/client.d.cts +0 -337
- package/types-cjs/cookies.d.cts +0 -93
- package/types-cjs/core.d.cts +0 -6
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -338
- package/types-cjs/frames/frame-sink.d.cts +0 -194
- package/types-cjs/frames/frame-transport.d.cts +0 -222
- package/types-cjs/frames/serializer.d.cts +0 -182
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/index.d.cts +0 -244
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4159
- package/types-cjs/package.json +0 -3
- package/types-cjs/response.d.cts +0 -174
- package/types-cjs/serializer-decode.d.cts +0 -182
- package/types-cjs/serializer.d.cts +0 -182
- package/types-cjs/server-functions/client.d.cts +0 -231
- package/types-cjs/server-functions/flash.d.cts +0 -38
- package/types-cjs/server-functions/rich-args.d.cts +0 -10
- package/types-cjs/server-functions/server.d.cts +0 -616
- package/types-cjs/server-functions/shared.d.cts +0 -523
- package/types-cjs/server-mock.d.cts +0 -277
- package/types-cjs/server.d.cts +0 -523
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type AttributionOptions } from "solid-js/attribution";
|
|
2
|
+
export interface PerformanceTracksOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Options for the engine hold this adapter takes
|
|
5
|
+
* (`attribution.enable({ log: false, ...attribution })`). The adapter asks
|
|
6
|
+
* for no console log — the timeline is the output — which, the engine
|
|
7
|
+
* combining holds by the most demanding request, quiets the console only
|
|
8
|
+
* while nobody else wants it: a console session beside the tracks keeps
|
|
9
|
+
* its log. `checks` is left to the engine's default; pass `checks: false`
|
|
10
|
+
* for records only (honoured while no other holder wants the checks).
|
|
11
|
+
*/
|
|
12
|
+
attribution?: AttributionOptions;
|
|
13
|
+
/**
|
|
14
|
+
* Floor for run spans on `Propagation`, `Effects` and `Memos` — compute
|
|
15
|
+
* runs (by `totalMs`), creation runs and effect callbacks (by their
|
|
16
|
+
* duration): spans under it are not painted. The wave span on
|
|
17
|
+
* `Propagation` always is, and its label carries the counts, so a
|
|
18
|
+
* fan-out of runs too small to paint still reads as `47 runs`. Default
|
|
19
|
+
* `0` in dev (every run; Chrome shows zero-width spans zoomed in) and
|
|
20
|
+
* `0.05` in observe builds, so a production trace carries the runs that
|
|
21
|
+
* cost something.
|
|
22
|
+
*/
|
|
23
|
+
minMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Emit through `performance.measure` with `detail.devtools` — tooltips
|
|
26
|
+
* (the why-chain of a re-run) and properties (causes, deps, blockers…)
|
|
27
|
+
* on every span — instead of `console.timeStamp`. Costs a User Timing
|
|
28
|
+
* entry per span; the adapter clears the entries it made in batches (a
|
|
29
|
+
* name it shares with an app measure is left alone). Default: dev builds.
|
|
30
|
+
* Each path falls back to the other where its API is missing.
|
|
31
|
+
*/
|
|
32
|
+
rich?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Paint the attribution engine's records — and the web runtime's
|
|
36
|
+
* server-function `call` and `frame` records, with the server's own timing
|
|
37
|
+
* for each response under them (its `Server-Timing` metrics, placed by the
|
|
38
|
+
* browser's resource timing; the document's at enable) — as tracks in the
|
|
39
|
+
* Chrome Performance panel, from now until the returned function is called. The
|
|
40
|
+
* tracks themselves are Chrome's (its `detail.devtools` extension); in rich
|
|
41
|
+
* mode the spans are standard User Timing measures underneath, so any tool
|
|
42
|
+
* that reads those — Firefox's profiler, Lighthouse, RUM — sees the same
|
|
43
|
+
* spans as plain measures.
|
|
44
|
+
*
|
|
45
|
+
* Takes its own hold on the engine (`attribution.enable`): enabling beside
|
|
46
|
+
* a diagnostics capture or an APM adapter disturbs neither, and releasing
|
|
47
|
+
* here leaves theirs in place. Subscribing
|
|
48
|
+
* to the engine's timeline records (`create`, `effect`, `flush`, `flight`,
|
|
49
|
+
* `fallback`) is what turns them on — they are built only while a listener
|
|
50
|
+
* exists, so the engine pays for them only while the tracks are enabled.
|
|
51
|
+
* Every diagnostic delivered while enabled becomes a marker on the panel's
|
|
52
|
+
* Timings track (`SILENT_HOLD — <Search>`), annotated as a
|
|
53
|
+
* performance issue for the Insights sidebar when its severity is a
|
|
54
|
+
* warning or worse. In dev, spans and markers are emitted inside the
|
|
55
|
+
* `console.createTask` task of the component they belong to, so an entry's
|
|
56
|
+
* stack in the panel points at the JSX site that rendered the component.
|
|
57
|
+
*
|
|
58
|
+
* One instance per page: the tracks are a view of one engine, and a second
|
|
59
|
+
* painter would paint every span twice. A call while enabled joins the
|
|
60
|
+
* running instance — its options are not re-read; the first call's apply —
|
|
61
|
+
* and returns a release of its own; the instance is torn down when every
|
|
62
|
+
* release has been called (a module re-evaluated by HMR that enables again
|
|
63
|
+
* and disposes the old one lands back on one instance either way). A no-op
|
|
64
|
+
* (returning a no-op) in prod builds, where the observe tier is absent, and
|
|
65
|
+
* in an environment without `console.timeStamp` or `performance.measure`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function enablePerformanceTracks(options?: PerformanceTracksOptions): () => void;
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"main": "../dist/decode.cjs",
|
|
2
|
+
"main": "../dist/decode.js",
|
|
4
3
|
"module": "../dist/decode.js",
|
|
5
4
|
"types": "../types/serializer-decode.d.ts",
|
|
6
5
|
"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
|
-
}
|
|
6
|
+
"sideEffects": false
|
|
20
7
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Feature, fromCrossJSON } from 'seroval';
|
|
1
|
+
import { Feature, fromCrossJSON, createStream } from 'seroval';
|
|
2
2
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
3
3
|
|
|
4
|
-
const STATE = Symbol.for("
|
|
4
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
5
5
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
6
6
|
materialized: new WeakMap(),
|
|
7
7
|
materializedValues: new WeakSet()
|
|
8
8
|
});
|
|
9
|
-
|
|
9
|
+
function setContainerTraceStreamMint(fn) {
|
|
10
|
+
state.streamOf = fn;
|
|
11
|
+
}
|
|
12
|
+
const TRACE = Symbol.for("solid.container-trace");
|
|
10
13
|
function materialize(marker) {
|
|
11
14
|
let value = state.materialized.get(marker.$tr);
|
|
12
15
|
if (value === undefined) {
|
|
@@ -18,13 +21,14 @@ function materialize(marker) {
|
|
|
18
21
|
}
|
|
19
22
|
function parseTrace(value, ctx) {
|
|
20
23
|
const trace = value[TRACE];
|
|
24
|
+
const sub = trace.subscribe();
|
|
21
25
|
return {
|
|
22
26
|
a: trace.array ? 1 : 0,
|
|
23
|
-
i: ctx.parse(
|
|
27
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
30
|
const ContainerTracePlugin = {
|
|
27
|
-
tag: "
|
|
31
|
+
tag: "solid/container-trace",
|
|
28
32
|
test(value) {
|
|
29
33
|
return value != null && typeof value === "object" && TRACE in value;
|
|
30
34
|
},
|
|
@@ -34,9 +38,10 @@ const ContainerTracePlugin = {
|
|
|
34
38
|
},
|
|
35
39
|
async async(value, ctx) {
|
|
36
40
|
const trace = value[TRACE];
|
|
41
|
+
const sub = trace.subscribe();
|
|
37
42
|
return {
|
|
38
43
|
a: trace.array ? 1 : 0,
|
|
39
|
-
i: await ctx.parse(
|
|
44
|
+
i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
40
45
|
};
|
|
41
46
|
},
|
|
42
47
|
stream: parseTrace
|
|
@@ -54,6 +59,18 @@ const ContainerTracePlugin = {
|
|
|
54
59
|
}
|
|
55
60
|
};
|
|
56
61
|
|
|
62
|
+
setContainerTraceStreamMint(iterable => {
|
|
63
|
+
const stream = createStream();
|
|
64
|
+
(async () => {
|
|
65
|
+
try {
|
|
66
|
+
for await (const value of iterable) stream.next(value);
|
|
67
|
+
stream.return(undefined);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
stream.throw(error);
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
return stream;
|
|
73
|
+
});
|
|
57
74
|
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
58
75
|
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
59
76
|
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
@@ -66,34 +83,94 @@ const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
|
66
83
|
function resolveCodecOptions({
|
|
67
84
|
plugins,
|
|
68
85
|
disabledFeatures,
|
|
69
|
-
depthLimit
|
|
86
|
+
depthLimit,
|
|
87
|
+
serializeErrorStacks
|
|
70
88
|
} = {}) {
|
|
71
89
|
return {
|
|
72
90
|
plugins: resolveSerializerPlugins(plugins),
|
|
73
91
|
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
74
|
-
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
92
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
93
|
+
serializeErrorStacks
|
|
75
94
|
};
|
|
76
95
|
}
|
|
77
96
|
function createJSONDeserializer(options) {
|
|
78
97
|
const refs = new Map();
|
|
79
98
|
const resolved = resolveCodecOptions(options);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
let owned = 0;
|
|
100
|
+
const pendingResolvers = new Set();
|
|
101
|
+
const streams = new Set();
|
|
102
|
+
const STREAM = 1;
|
|
103
|
+
const RESOLVER = 2;
|
|
104
|
+
function classify(value) {
|
|
105
|
+
if (value === null || typeof value !== "object") return 0;
|
|
106
|
+
try {
|
|
107
|
+
if (value.__SEROVAL_STREAM__) return STREAM;
|
|
108
|
+
if (typeof value.s === "function" && typeof value.f === "function" && value.p instanceof Promise) return RESOLVER;
|
|
109
|
+
} catch {}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
function ownDecodedPromises() {
|
|
113
|
+
if (refs.size === owned) return;
|
|
114
|
+
let index = 0;
|
|
115
|
+
for (const value of refs.values()) {
|
|
116
|
+
if (index++ < owned) continue;
|
|
117
|
+
if (value instanceof Promise) value.then(undefined, () => {});else {
|
|
118
|
+
const kind = classify(value);
|
|
119
|
+
if (kind === STREAM) streams.add(value);else if (kind === RESOLVER) {
|
|
120
|
+
pendingResolvers.add(value);
|
|
121
|
+
const settled = () => pendingResolvers.delete(value);
|
|
122
|
+
value.p.then(settled, settled);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
owned = refs.size;
|
|
127
|
+
}
|
|
128
|
+
function isOpenStream(stream) {
|
|
129
|
+
let alive = true;
|
|
130
|
+
const close = () => {
|
|
131
|
+
alive = false;
|
|
132
|
+
};
|
|
133
|
+
const off = stream.on({
|
|
134
|
+
next() {},
|
|
135
|
+
throw: close,
|
|
136
|
+
return: close
|
|
84
137
|
});
|
|
138
|
+
if (typeof off === "function") off();
|
|
139
|
+
return alive;
|
|
140
|
+
}
|
|
141
|
+
function deserializeJSONChunk(node) {
|
|
142
|
+
try {
|
|
143
|
+
return fromCrossJSON(node, {
|
|
144
|
+
refs,
|
|
145
|
+
...resolved
|
|
146
|
+
});
|
|
147
|
+
} finally {
|
|
148
|
+
ownDecodedPromises();
|
|
149
|
+
}
|
|
85
150
|
}
|
|
86
151
|
deserializeJSONChunk.abort = function abort(error) {
|
|
87
152
|
for (const value of refs.values()) {
|
|
88
|
-
|
|
89
|
-
if (
|
|
153
|
+
const kind = classify(value);
|
|
154
|
+
if (kind === STREAM) {
|
|
90
155
|
value.throw(error);
|
|
91
|
-
} else if (
|
|
156
|
+
} else if (kind === RESOLVER) {
|
|
92
157
|
value.p.then(undefined, () => {});
|
|
93
158
|
value.f(error);
|
|
94
159
|
}
|
|
95
160
|
}
|
|
96
161
|
};
|
|
162
|
+
deserializeJSONChunk.close = function close() {
|
|
163
|
+
for (const value of refs.values()) {
|
|
164
|
+
if (classify(value) === STREAM) value.return(undefined);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
deserializeJSONChunk.open = function open() {
|
|
168
|
+
let count = pendingResolvers.size;
|
|
169
|
+
for (const stream of streams) {
|
|
170
|
+
if (isOpenStream(stream)) count++;else streams.delete(stream);
|
|
171
|
+
}
|
|
172
|
+
return count;
|
|
173
|
+
};
|
|
97
174
|
return deserializeJSONChunk;
|
|
98
175
|
}
|
|
99
176
|
function createJSONDataTable(options) {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Feature, fromCrossJSON, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
2
|
-
export { OpaqueReference, createPlugin } from 'seroval';
|
|
1
|
+
import { Feature, fromCrossJSON, createStream, OpaqueReference as OpaqueReference$1, createPlugin as createPlugin$1, toCrossJSONStream, Serializer, getCrossReferenceHeader } from 'seroval';
|
|
3
2
|
import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
|
|
4
3
|
|
|
5
|
-
const STATE = Symbol.for("
|
|
4
|
+
const STATE = Symbol.for("solid.container-trace-state");
|
|
6
5
|
const state = globalThis[STATE] || (globalThis[STATE] = {
|
|
7
6
|
materialized: new WeakMap(),
|
|
8
7
|
materializedValues: new WeakSet()
|
|
9
8
|
});
|
|
10
|
-
|
|
9
|
+
function setContainerTraceStreamMint(fn) {
|
|
10
|
+
state.streamOf = fn;
|
|
11
|
+
}
|
|
12
|
+
const TRACE = Symbol.for("solid.container-trace");
|
|
11
13
|
function materialize(marker) {
|
|
12
14
|
let value = state.materialized.get(marker.$tr);
|
|
13
15
|
if (value === undefined) {
|
|
@@ -19,13 +21,14 @@ function materialize(marker) {
|
|
|
19
21
|
}
|
|
20
22
|
function parseTrace(value, ctx) {
|
|
21
23
|
const trace = value[TRACE];
|
|
24
|
+
const sub = trace.subscribe();
|
|
22
25
|
return {
|
|
23
26
|
a: trace.array ? 1 : 0,
|
|
24
|
-
i: ctx.parse(
|
|
27
|
+
i: ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
30
|
const ContainerTracePlugin = {
|
|
28
|
-
tag: "
|
|
31
|
+
tag: "solid/container-trace",
|
|
29
32
|
test(value) {
|
|
30
33
|
return value != null && typeof value === "object" && TRACE in value;
|
|
31
34
|
},
|
|
@@ -35,9 +38,10 @@ const ContainerTracePlugin = {
|
|
|
35
38
|
},
|
|
36
39
|
async async(value, ctx) {
|
|
37
40
|
const trace = value[TRACE];
|
|
41
|
+
const sub = trace.subscribe();
|
|
38
42
|
return {
|
|
39
43
|
a: trace.array ? 1 : 0,
|
|
40
|
-
i: await ctx.parse(
|
|
44
|
+
i: await ctx.parse(state.streamOf ? state.streamOf(sub) : sub)
|
|
41
45
|
};
|
|
42
46
|
},
|
|
43
47
|
stream: parseTrace
|
|
@@ -55,6 +59,18 @@ const ContainerTracePlugin = {
|
|
|
55
59
|
}
|
|
56
60
|
};
|
|
57
61
|
|
|
62
|
+
setContainerTraceStreamMint(iterable => {
|
|
63
|
+
const stream = createStream();
|
|
64
|
+
(async () => {
|
|
65
|
+
try {
|
|
66
|
+
for await (const value of iterable) stream.next(value);
|
|
67
|
+
stream.return(undefined);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
stream.throw(error);
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
return stream;
|
|
73
|
+
});
|
|
58
74
|
const DEFAULT_WEB_PLUGINS = Object.freeze([AbortSignalPlugin,
|
|
59
75
|
CustomEventPlugin, DOMExceptionPlugin, EventPlugin,
|
|
60
76
|
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin,
|
|
@@ -67,34 +83,94 @@ const JSON_CODEC_DEPTH_LIMIT = 64;
|
|
|
67
83
|
function resolveCodecOptions({
|
|
68
84
|
plugins,
|
|
69
85
|
disabledFeatures,
|
|
70
|
-
depthLimit
|
|
86
|
+
depthLimit,
|
|
87
|
+
serializeErrorStacks
|
|
71
88
|
} = {}) {
|
|
72
89
|
return {
|
|
73
90
|
plugins: resolveSerializerPlugins(plugins),
|
|
74
91
|
disabledFeatures: disabledFeatures === undefined ? JSON_CODEC_DISABLED_FEATURES : disabledFeatures,
|
|
75
|
-
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit
|
|
92
|
+
depthLimit: depthLimit === undefined ? JSON_CODEC_DEPTH_LIMIT : depthLimit,
|
|
93
|
+
serializeErrorStacks
|
|
76
94
|
};
|
|
77
95
|
}
|
|
78
96
|
function createJSONDeserializer(options) {
|
|
79
97
|
const refs = new Map();
|
|
80
98
|
const resolved = resolveCodecOptions(options);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
99
|
+
let owned = 0;
|
|
100
|
+
const pendingResolvers = new Set();
|
|
101
|
+
const streams = new Set();
|
|
102
|
+
const STREAM = 1;
|
|
103
|
+
const RESOLVER = 2;
|
|
104
|
+
function classify(value) {
|
|
105
|
+
if (value === null || typeof value !== "object") return 0;
|
|
106
|
+
try {
|
|
107
|
+
if (value.__SEROVAL_STREAM__) return STREAM;
|
|
108
|
+
if (typeof value.s === "function" && typeof value.f === "function" && value.p instanceof Promise) return RESOLVER;
|
|
109
|
+
} catch {}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
function ownDecodedPromises() {
|
|
113
|
+
if (refs.size === owned) return;
|
|
114
|
+
let index = 0;
|
|
115
|
+
for (const value of refs.values()) {
|
|
116
|
+
if (index++ < owned) continue;
|
|
117
|
+
if (value instanceof Promise) value.then(undefined, () => {});else {
|
|
118
|
+
const kind = classify(value);
|
|
119
|
+
if (kind === STREAM) streams.add(value);else if (kind === RESOLVER) {
|
|
120
|
+
pendingResolvers.add(value);
|
|
121
|
+
const settled = () => pendingResolvers.delete(value);
|
|
122
|
+
value.p.then(settled, settled);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
owned = refs.size;
|
|
127
|
+
}
|
|
128
|
+
function isOpenStream(stream) {
|
|
129
|
+
let alive = true;
|
|
130
|
+
const close = () => {
|
|
131
|
+
alive = false;
|
|
132
|
+
};
|
|
133
|
+
const off = stream.on({
|
|
134
|
+
next() {},
|
|
135
|
+
throw: close,
|
|
136
|
+
return: close
|
|
85
137
|
});
|
|
138
|
+
if (typeof off === "function") off();
|
|
139
|
+
return alive;
|
|
140
|
+
}
|
|
141
|
+
function deserializeJSONChunk(node) {
|
|
142
|
+
try {
|
|
143
|
+
return fromCrossJSON(node, {
|
|
144
|
+
refs,
|
|
145
|
+
...resolved
|
|
146
|
+
});
|
|
147
|
+
} finally {
|
|
148
|
+
ownDecodedPromises();
|
|
149
|
+
}
|
|
86
150
|
}
|
|
87
151
|
deserializeJSONChunk.abort = function abort(error) {
|
|
88
152
|
for (const value of refs.values()) {
|
|
89
|
-
|
|
90
|
-
if (
|
|
153
|
+
const kind = classify(value);
|
|
154
|
+
if (kind === STREAM) {
|
|
91
155
|
value.throw(error);
|
|
92
|
-
} else if (
|
|
156
|
+
} else if (kind === RESOLVER) {
|
|
93
157
|
value.p.then(undefined, () => {});
|
|
94
158
|
value.f(error);
|
|
95
159
|
}
|
|
96
160
|
}
|
|
97
161
|
};
|
|
162
|
+
deserializeJSONChunk.close = function close() {
|
|
163
|
+
for (const value of refs.values()) {
|
|
164
|
+
if (classify(value) === STREAM) value.return(undefined);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
deserializeJSONChunk.open = function open() {
|
|
168
|
+
let count = pendingResolvers.size;
|
|
169
|
+
for (const stream of streams) {
|
|
170
|
+
if (isOpenStream(stream)) count++;else streams.delete(stream);
|
|
171
|
+
}
|
|
172
|
+
return count;
|
|
173
|
+
};
|
|
98
174
|
return deserializeJSONChunk;
|
|
99
175
|
}
|
|
100
176
|
function createJSONDataTable(options) {
|
|
@@ -115,13 +191,15 @@ function createJSONDataTable(options) {
|
|
|
115
191
|
}
|
|
116
192
|
|
|
117
193
|
const DEFAULT_DISABLED_FEATURES = Feature.AggregateError | Feature.BigIntTypedArray;
|
|
118
|
-
const serializeOnlyDisabledFeatures =
|
|
194
|
+
const serializeOnlyDisabledFeatures = serializeErrorStacks => (serializeErrorStacks === undefined ? process.env.NODE_ENV === "development" : serializeErrorStacks) ? 0 : Feature.ErrorPrototypeStack;
|
|
119
195
|
const HYDRATION_GLOBAL = "_$HY.r";
|
|
196
|
+
const createPlugin = createPlugin$1;
|
|
197
|
+
const OpaqueReference = OpaqueReference$1;
|
|
120
198
|
function createSerializer(options) {
|
|
121
199
|
return new Serializer({
|
|
122
200
|
...options,
|
|
123
201
|
plugins: resolveSerializerPlugins(options.plugins),
|
|
124
|
-
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures()
|
|
202
|
+
disabledFeatures: (options.disabledFeatures === undefined ? DEFAULT_DISABLED_FEATURES : options.disabledFeatures) | serializeOnlyDisabledFeatures(options.serializeErrorStacks)
|
|
125
203
|
});
|
|
126
204
|
}
|
|
127
205
|
function createHydrationSerializer({
|
|
@@ -155,7 +233,7 @@ function serializeJSON(value, {
|
|
|
155
233
|
onDone,
|
|
156
234
|
onError,
|
|
157
235
|
...resolved,
|
|
158
|
-
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures()
|
|
236
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks)
|
|
159
237
|
});
|
|
160
238
|
}
|
|
161
239
|
function createJSONSerializer({
|
|
@@ -164,12 +242,14 @@ function createJSONSerializer({
|
|
|
164
242
|
onError,
|
|
165
243
|
plugins,
|
|
166
244
|
disabledFeatures,
|
|
167
|
-
depthLimit
|
|
245
|
+
depthLimit,
|
|
246
|
+
serializeErrorStacks
|
|
168
247
|
}) {
|
|
169
248
|
const resolved = resolveCodecOptions({
|
|
170
249
|
plugins,
|
|
171
250
|
disabledFeatures,
|
|
172
|
-
depthLimit
|
|
251
|
+
depthLimit,
|
|
252
|
+
serializeErrorStacks
|
|
173
253
|
});
|
|
174
254
|
const refs = new Map();
|
|
175
255
|
const cancels = new Set();
|
|
@@ -191,7 +271,7 @@ function createJSONSerializer({
|
|
|
191
271
|
const stream = toCrossJSONStream(value, {
|
|
192
272
|
refs,
|
|
193
273
|
plugins: resolved.plugins,
|
|
194
|
-
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(),
|
|
274
|
+
disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
|
|
195
275
|
onParse(node, initial) {
|
|
196
276
|
onData({
|
|
197
277
|
key,
|
|
@@ -224,4 +304,4 @@ function createJSONSerializer({
|
|
|
224
304
|
};
|
|
225
305
|
}
|
|
226
306
|
|
|
227
|
-
export { DEFAULT_WEB_PLUGINS, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createSerializer, getLocalHeaderScript, resolveSerializerPlugins, serializeJSON };
|
|
307
|
+
export { DEFAULT_WEB_PLUGINS, OpaqueReference, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createPlugin, createSerializer, getLocalHeaderScript, resolveSerializerPlugins, serializeJSON };
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"main": "./dist/serialization.cjs",
|
|
2
|
+
"main": "./dist/serialization.js",
|
|
4
3
|
"module": "./dist/serialization.js",
|
|
5
4
|
"types": "./types/index.d.ts",
|
|
6
5
|
"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
|
-
}
|
|
6
|
+
"sideEffects": false
|
|
20
7
|
}
|