@sentropic/h2a 0.85.16 → 0.85.18
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/.claude-plugin/plugin.json +29 -0
- package/.codex-plugin/plugin.json +35 -0
- package/.mcp.json +19 -0
- package/README.md +3 -0
- package/dist/bin-routing.d.ts +14 -3
- package/dist/bin-routing.d.ts.map +1 -1
- package/dist/bin-routing.js +31 -6
- package/dist/bin-routing.js.map +1 -1
- package/dist/bin.js +45 -14
- package/dist/bin.js.map +1 -1
- package/dist/cli-contract.d.ts.map +1 -1
- package/dist/cli-contract.js +41 -1
- package/dist/cli-contract.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +146 -18
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +1 -0
- package/dist/mcp.js.map +1 -1
- package/dist/runtime/focus/serve.d.ts +42 -0
- package/dist/runtime/focus/serve.d.ts.map +1 -0
- package/dist/runtime/focus/serve.js +366 -0
- package/dist/runtime/focus/serve.js.map +1 -0
- package/dist/runtime/loop/engine/adapters.d.ts +62 -6
- package/dist/runtime/loop/engine/adapters.d.ts.map +1 -1
- package/dist/runtime/loop/engine/adapters.js +272 -36
- package/dist/runtime/loop/engine/adapters.js.map +1 -1
- package/dist/runtime/loop/engine/decision.d.ts.map +1 -1
- package/dist/runtime/loop/engine/decision.js +20 -2
- package/dist/runtime/loop/engine/decision.js.map +1 -1
- package/dist/runtime/loop/engine/execute.d.ts +13 -4
- package/dist/runtime/loop/engine/execute.d.ts.map +1 -1
- package/dist/runtime/loop/engine/execute.js +17 -7
- package/dist/runtime/loop/engine/execute.js.map +1 -1
- package/dist/runtime/loop/index.d.ts +16 -0
- package/dist/runtime/loop/index.d.ts.map +1 -1
- package/dist/runtime/loop/index.js +146 -13
- package/dist/runtime/loop/index.js.map +1 -1
- package/dist/runtime/mcp/agent-launch.d.ts +33 -0
- package/dist/runtime/mcp/agent-launch.d.ts.map +1 -0
- package/dist/runtime/mcp/agent-launch.js +250 -0
- package/dist/runtime/mcp/agent-launch.js.map +1 -0
- package/dist/runtime/mcp/handlers.d.ts +8 -0
- package/dist/runtime/mcp/handlers.d.ts.map +1 -1
- package/dist/runtime/mcp/handlers.js +34 -4
- package/dist/runtime/mcp/handlers.js.map +1 -1
- package/dist/runtime/mcp/index.d.ts +2 -1
- package/dist/runtime/mcp/index.d.ts.map +1 -1
- package/dist/runtime/mcp/index.js +2 -1
- package/dist/runtime/mcp/index.js.map +1 -1
- package/dist/runtime/mcp/server.d.ts +5 -0
- package/dist/runtime/mcp/server.d.ts.map +1 -1
- package/dist/runtime/mcp/server.js +3 -0
- package/dist/runtime/mcp/server.js.map +1 -1
- package/dist/runtime/mcp/stdio.d.ts +17 -0
- package/dist/runtime/mcp/stdio.d.ts.map +1 -1
- package/dist/runtime/mcp/stdio.js +65 -13
- package/dist/runtime/mcp/stdio.js.map +1 -1
- package/dist/runtime/mcp/tools.d.ts.map +1 -1
- package/dist/runtime/mcp/tools.js +96 -5
- package/dist/runtime/mcp/tools.js.map +1 -1
- package/dist/runtime/path-safety.d.ts +3 -0
- package/dist/runtime/path-safety.d.ts.map +1 -0
- package/dist/runtime/path-safety.js +12 -0
- package/dist/runtime/path-safety.js.map +1 -0
- package/dist/runtime/reporting/config.d.ts +21 -0
- package/dist/runtime/reporting/config.d.ts.map +1 -0
- package/dist/runtime/reporting/config.js +76 -0
- package/dist/runtime/reporting/config.js.map +1 -0
- package/dist/runtime/reporting/context.d.ts +27 -0
- package/dist/runtime/reporting/context.d.ts.map +1 -0
- package/dist/runtime/reporting/context.js +265 -0
- package/dist/runtime/reporting/context.js.map +1 -0
- package/dist/runtime/reporting/index.d.ts +4 -0
- package/dist/runtime/reporting/index.d.ts.map +1 -0
- package/dist/runtime/reporting/index.js +4 -0
- package/dist/runtime/reporting/index.js.map +1 -0
- package/dist/runtime/reporting/report-ai.d.ts +49 -0
- package/dist/runtime/reporting/report-ai.d.ts.map +1 -0
- package/dist/runtime/reporting/report-ai.js +325 -0
- package/dist/runtime/reporting/report-ai.js.map +1 -0
- package/focus-app/client/_app/immutable/assets/0.BdzHFb9q.css +1 -0
- package/focus-app/client/_app/immutable/assets/0.BdzHFb9q.css.br +2 -0
- package/focus-app/client/_app/immutable/assets/0.BdzHFb9q.css.gz +0 -0
- package/focus-app/client/_app/immutable/assets/2.Ddxq02y4.css +1 -0
- package/focus-app/client/_app/immutable/assets/2.Ddxq02y4.css.br +0 -0
- package/focus-app/client/_app/immutable/assets/2.Ddxq02y4.css.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/Bs3f1UbD.js +2 -0
- package/focus-app/client/_app/immutable/chunks/Bs3f1UbD.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/Bs3f1UbD.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/Bv8OL8ib.js +1 -0
- package/focus-app/client/_app/immutable/chunks/Bv8OL8ib.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/Bv8OL8ib.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/CVq_IFFr.js +2 -0
- package/focus-app/client/_app/immutable/chunks/CVq_IFFr.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/CVq_IFFr.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/Cj6wo28J.js +1 -0
- package/focus-app/client/_app/immutable/chunks/Cj6wo28J.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/Cj6wo28J.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/DEmooz0s.js +1 -0
- package/focus-app/client/_app/immutable/chunks/DEmooz0s.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/DEmooz0s.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/DQIRXgdC.js +2 -0
- package/focus-app/client/_app/immutable/chunks/DQIRXgdC.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/DQIRXgdC.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/ZxFklh9T.js +1 -0
- package/focus-app/client/_app/immutable/chunks/ZxFklh9T.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/ZxFklh9T.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/_wRuVGPs.js +1 -0
- package/focus-app/client/_app/immutable/chunks/_wRuVGPs.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/_wRuVGPs.js.gz +0 -0
- package/focus-app/client/_app/immutable/chunks/wbPk3Yxo.js +81 -0
- package/focus-app/client/_app/immutable/chunks/wbPk3Yxo.js.br +0 -0
- package/focus-app/client/_app/immutable/chunks/wbPk3Yxo.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/app.6DKouWRt.js +2 -0
- package/focus-app/client/_app/immutable/entry/app.6DKouWRt.js.br +0 -0
- package/focus-app/client/_app/immutable/entry/app.6DKouWRt.js.gz +0 -0
- package/focus-app/client/_app/immutable/entry/start.DlLmkUb7.js +1 -0
- package/focus-app/client/_app/immutable/entry/start.DlLmkUb7.js.br +2 -0
- package/focus-app/client/_app/immutable/entry/start.DlLmkUb7.js.gz +0 -0
- package/focus-app/client/_app/immutable/nodes/0.CuSOF0Of.js +5 -0
- package/focus-app/client/_app/immutable/nodes/0.CuSOF0Of.js.br +0 -0
- package/focus-app/client/_app/immutable/nodes/0.CuSOF0Of.js.gz +0 -0
- package/focus-app/client/_app/immutable/nodes/1.D39jdnqm.js +1 -0
- package/focus-app/client/_app/immutable/nodes/1.D39jdnqm.js.br +0 -0
- package/focus-app/client/_app/immutable/nodes/1.D39jdnqm.js.gz +0 -0
- package/focus-app/client/_app/immutable/nodes/2.CnU8ifRl.js +1 -0
- package/focus-app/client/_app/immutable/nodes/2.CnU8ifRl.js.br +0 -0
- package/focus-app/client/_app/immutable/nodes/2.CnU8ifRl.js.gz +0 -0
- package/focus-app/client/_app/version.json +1 -0
- package/focus-app/client/_app/version.json.br +0 -0
- package/focus-app/client/_app/version.json.gz +0 -0
- package/focus-app/env.js +70 -0
- package/focus-app/env.js.map +1 -0
- package/focus-app/h2a-focus.json +114 -0
- package/focus-app/handler.js +24 -0
- package/focus-app/handler.js.map +1 -0
- package/focus-app/index.js +147 -0
- package/focus-app/index.js.map +1 -0
- package/focus-app/server/chunks/chunks/exports.js-DUTkELZq.js +217 -0
- package/focus-app/server/chunks/chunks/exports.js-DUTkELZq.js.map +1 -0
- package/focus-app/server/chunks/chunks/false.js-B2gHlHjM.js +4 -0
- package/focus-app/server/chunks/chunks/false.js-B2gHlHjM.js.map +1 -0
- package/focus-app/server/chunks/chunks/friendly.js-D4fjovnZ.js +246 -0
- package/focus-app/server/chunks/chunks/friendly.js-D4fjovnZ.js.map +1 -0
- package/focus-app/server/chunks/chunks/index.js-Di21TltP.js +1315 -0
- package/focus-app/server/chunks/chunks/index.js-Di21TltP.js.map +1 -0
- package/focus-app/server/chunks/chunks/internal.js-33vbd70h.js +126 -0
- package/focus-app/server/chunks/chunks/internal.js-33vbd70h.js.map +1 -0
- package/focus-app/server/chunks/chunks/root.js-DO1m-gJA.js +2967 -0
- package/focus-app/server/chunks/chunks/root.js-DO1m-gJA.js.map +1 -0
- package/focus-app/server/chunks/chunks/server.js-Bf8x1V_n.js +16 -0
- package/focus-app/server/chunks/chunks/server.js-Bf8x1V_n.js.map +1 -0
- package/focus-app/server/chunks/chunks/utils.js-C_3_iViC.js +2545 -0
- package/focus-app/server/chunks/chunks/utils.js-C_3_iViC.js.map +1 -0
- package/focus-app/server/chunks/chunks/utils2.js-BQzn9ikS.js +38 -0
- package/focus-app/server/chunks/chunks/utils2.js-BQzn9ikS.js.map +1 -0
- package/focus-app/server/chunks/entries/endpoints/api/actions/launch/_server.ts.js-DUQcf9xd.js +63 -0
- package/focus-app/server/chunks/entries/endpoints/api/actions/launch/_server.ts.js-DUQcf9xd.js.map +1 -0
- package/focus-app/server/chunks/entries/endpoints/api/decisions/inject/_server.ts.js-j0NNcOSZ.js +100 -0
- package/focus-app/server/chunks/entries/endpoints/api/decisions/inject/_server.ts.js-j0NNcOSZ.js.map +1 -0
- package/focus-app/server/chunks/entries/fallbacks/error.svelte.js-Dj3sETSX.js +50 -0
- package/focus-app/server/chunks/entries/fallbacks/error.svelte.js-Dj3sETSX.js.map +1 -0
- package/focus-app/server/chunks/entries/pages/_layout.svelte.js-BoLsbuC2.js +1420 -0
- package/focus-app/server/chunks/entries/pages/_layout.svelte.js-BoLsbuC2.js.map +1 -0
- package/focus-app/server/chunks/entries/pages/_page.server.ts.js-ChRBj_xK.js +246 -0
- package/focus-app/server/chunks/entries/pages/_page.server.ts.js-ChRBj_xK.js.map +1 -0
- package/focus-app/server/chunks/entries/pages/_page.svelte.js-QDldMYhk.js +2725 -0
- package/focus-app/server/chunks/entries/pages/_page.svelte.js-QDldMYhk.js.map +1 -0
- package/focus-app/server/chunks/handler-Cp_5hLyY.js +1474 -0
- package/focus-app/server/chunks/handler-Cp_5hLyY.js.map +1 -0
- package/focus-app/server/chunks/index.js-CBh7Wjqp.js +4242 -0
- package/focus-app/server/chunks/index.js-CBh7Wjqp.js.map +1 -0
- package/focus-app/server/chunks/manifest.js-Cm6cC7mC.js +56 -0
- package/focus-app/server/chunks/manifest.js-Cm6cC7mC.js.map +1 -0
- package/focus-app/server/chunks/nodes/0.js-4wlmdsk8.js +9 -0
- package/focus-app/server/chunks/nodes/0.js-4wlmdsk8.js.map +1 -0
- package/focus-app/server/chunks/nodes/1.js-B-LpY-lC.js +9 -0
- package/focus-app/server/chunks/nodes/1.js-B-LpY-lC.js.map +1 -0
- package/focus-app/server/chunks/nodes/2.js-F6jp5eD9.js +19 -0
- package/focus-app/server/chunks/nodes/2.js-F6jp5eD9.js.map +1 -0
- package/focus-app/shims.js +33 -0
- package/focus-app/shims.js.map +1 -0
- package/package.json +8 -4
- package/skills/h2a/SKILL.md +7 -5
- package/skills/harness/SKILL.md +17 -0
- package/skills/harness/using-harness/SKILL.md +26 -0
|
@@ -0,0 +1,2545 @@
|
|
|
1
|
+
import { b as base64_decode } from './utils2.js-BQzn9ikS.js';
|
|
2
|
+
|
|
3
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
4
|
+
|
|
5
|
+
class HttpError {
|
|
6
|
+
/**
|
|
7
|
+
* @param {number} status
|
|
8
|
+
* @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
|
|
9
|
+
*/
|
|
10
|
+
constructor(status, body) {
|
|
11
|
+
this.status = status;
|
|
12
|
+
if (typeof body === 'string') {
|
|
13
|
+
this.body = { message: body };
|
|
14
|
+
} else if (body) {
|
|
15
|
+
this.body = body;
|
|
16
|
+
} else {
|
|
17
|
+
this.body = { message: `Error: ${status}` };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
toString() {
|
|
22
|
+
return JSON.stringify(this.body);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class Redirect {
|
|
27
|
+
/**
|
|
28
|
+
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
|
|
29
|
+
* @param {string} location
|
|
30
|
+
*/
|
|
31
|
+
constructor(status, location) {
|
|
32
|
+
try {
|
|
33
|
+
new Headers({ location });
|
|
34
|
+
} catch {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Invalid redirect location ${JSON.stringify(location)}: ` +
|
|
37
|
+
'this string contains characters that cannot be used in HTTP headers'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.location = location;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An error that was thrown from within the SvelteKit runtime that is not fatal and doesn't result in a 500, such as a 404.
|
|
48
|
+
* `SvelteKitError` goes through `handleError`.
|
|
49
|
+
* @extends Error
|
|
50
|
+
*/
|
|
51
|
+
class SvelteKitError extends Error {
|
|
52
|
+
/**
|
|
53
|
+
* @param {number} status
|
|
54
|
+
* @param {string} text
|
|
55
|
+
* @param {string} message
|
|
56
|
+
*/
|
|
57
|
+
constructor(status, text, message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.status = status;
|
|
60
|
+
this.text = text;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @template [T=undefined]
|
|
66
|
+
*/
|
|
67
|
+
class ActionFailure {
|
|
68
|
+
/**
|
|
69
|
+
* @param {number} status
|
|
70
|
+
* @param {T} data
|
|
71
|
+
*/
|
|
72
|
+
constructor(status, data) {
|
|
73
|
+
this.status = status;
|
|
74
|
+
this.data = data;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var defaultParseOptions = {
|
|
79
|
+
decodeValues: true,
|
|
80
|
+
map: false,
|
|
81
|
+
silent: false,
|
|
82
|
+
split: "auto", // auto = split strings but not arrays
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function isForbiddenKey(key) {
|
|
86
|
+
return typeof key !== "string" || key in {};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function createNullObj() {
|
|
90
|
+
return Object.create(null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isNonEmptyString(str) {
|
|
94
|
+
return typeof str === "string" && !!str.trim();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function parseString(setCookieValue, options) {
|
|
98
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
99
|
+
|
|
100
|
+
var nameValuePairStr = parts.shift();
|
|
101
|
+
if (!nameValuePairStr) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
var parsed = parseNameValuePair(nameValuePairStr);
|
|
105
|
+
var name = parsed.name;
|
|
106
|
+
var value = parsed.value;
|
|
107
|
+
|
|
108
|
+
options = options
|
|
109
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
110
|
+
: defaultParseOptions;
|
|
111
|
+
|
|
112
|
+
if (isForbiddenKey(name)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error(
|
|
120
|
+
"set-cookie-parser: failed to decode cookie value. Set options.decodeValues=false to disable decoding.",
|
|
121
|
+
e
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var cookie = createNullObj();
|
|
126
|
+
cookie.name = name;
|
|
127
|
+
cookie.value = value;
|
|
128
|
+
|
|
129
|
+
parts.forEach(function (part) {
|
|
130
|
+
var sides = part.split("=");
|
|
131
|
+
var key = sides.shift().trim().toLowerCase();
|
|
132
|
+
if (isForbiddenKey(key)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
var value = sides.join("=").trim();
|
|
136
|
+
if (key === "expires") {
|
|
137
|
+
cookie.expires = new Date(value);
|
|
138
|
+
} else if (key === "max-age") {
|
|
139
|
+
var n = parseInt(value, 10);
|
|
140
|
+
if (!Number.isNaN(n)) cookie.maxAge = n;
|
|
141
|
+
} else if (key === "secure") {
|
|
142
|
+
cookie.secure = true;
|
|
143
|
+
} else if (key === "httponly") {
|
|
144
|
+
cookie.httpOnly = true;
|
|
145
|
+
} else if (key === "samesite") {
|
|
146
|
+
cookie.sameSite = value;
|
|
147
|
+
} else if (key === "partitioned") {
|
|
148
|
+
cookie.partitioned = true;
|
|
149
|
+
} else if (key) {
|
|
150
|
+
cookie[key] = value;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return cookie;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function parseNameValuePair(nameValuePairStr) {
|
|
158
|
+
// Parses name-value-pair according to rfc6265bis draft
|
|
159
|
+
|
|
160
|
+
var name = "";
|
|
161
|
+
var value = "";
|
|
162
|
+
var nameValueArr = nameValuePairStr.split("=");
|
|
163
|
+
if (nameValueArr.length > 1) {
|
|
164
|
+
name = nameValueArr.shift();
|
|
165
|
+
value = nameValueArr.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
166
|
+
} else {
|
|
167
|
+
value = nameValuePairStr;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { name: name, value: value };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function parseSetCookie(input, options) {
|
|
174
|
+
options = options
|
|
175
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
176
|
+
: defaultParseOptions;
|
|
177
|
+
|
|
178
|
+
if (!input) {
|
|
179
|
+
if (!options.map) {
|
|
180
|
+
return [];
|
|
181
|
+
} else {
|
|
182
|
+
return createNullObj();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (input.headers) {
|
|
187
|
+
if (typeof input.headers.getSetCookie === "function") {
|
|
188
|
+
// for fetch responses - they combine headers of the same type in the headers array,
|
|
189
|
+
// but getSetCookie returns an uncombined array
|
|
190
|
+
input = input.headers.getSetCookie();
|
|
191
|
+
} else if (input.headers["set-cookie"]) {
|
|
192
|
+
// fast-path for node.js (which automatically normalizes header names to lower-case)
|
|
193
|
+
input = input.headers["set-cookie"];
|
|
194
|
+
} else {
|
|
195
|
+
// slow-path for other environments - see #25
|
|
196
|
+
var sch =
|
|
197
|
+
input.headers[
|
|
198
|
+
Object.keys(input.headers).find(function (key) {
|
|
199
|
+
return key.toLowerCase() === "set-cookie";
|
|
200
|
+
})
|
|
201
|
+
];
|
|
202
|
+
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
203
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
204
|
+
console.warn(
|
|
205
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
input = sch;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var split = options.split;
|
|
213
|
+
var isArray = Array.isArray(input);
|
|
214
|
+
|
|
215
|
+
if (split === "auto") {
|
|
216
|
+
split = !isArray;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!isArray) {
|
|
220
|
+
input = [input];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
input = input.filter(isNonEmptyString);
|
|
224
|
+
|
|
225
|
+
if (split) {
|
|
226
|
+
input = input.map(splitCookiesString).flat();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!options.map) {
|
|
230
|
+
return input
|
|
231
|
+
.map(function (str) {
|
|
232
|
+
return parseString(str, options);
|
|
233
|
+
})
|
|
234
|
+
.filter(Boolean);
|
|
235
|
+
} else {
|
|
236
|
+
var cookies = createNullObj();
|
|
237
|
+
return input.reduce(function (cookies, str) {
|
|
238
|
+
var cookie = parseString(str, options);
|
|
239
|
+
if (cookie && !isForbiddenKey(cookie.name)) {
|
|
240
|
+
cookies[cookie.name] = cookie;
|
|
241
|
+
}
|
|
242
|
+
return cookies;
|
|
243
|
+
}, cookies);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/*
|
|
248
|
+
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
249
|
+
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
250
|
+
|
|
251
|
+
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
252
|
+
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
253
|
+
React Native's fetch does this for *every* header, including set-cookie.
|
|
254
|
+
|
|
255
|
+
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
256
|
+
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
257
|
+
*/
|
|
258
|
+
function splitCookiesString(cookiesString) {
|
|
259
|
+
if (Array.isArray(cookiesString)) {
|
|
260
|
+
return cookiesString;
|
|
261
|
+
}
|
|
262
|
+
if (typeof cookiesString !== "string") {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var cookiesStrings = [];
|
|
267
|
+
var pos = 0;
|
|
268
|
+
var start;
|
|
269
|
+
var ch;
|
|
270
|
+
var lastComma;
|
|
271
|
+
var nextStart;
|
|
272
|
+
var cookiesSeparatorFound;
|
|
273
|
+
|
|
274
|
+
function skipWhitespace() {
|
|
275
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
276
|
+
pos += 1;
|
|
277
|
+
}
|
|
278
|
+
return pos < cookiesString.length;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function notSpecialChar() {
|
|
282
|
+
ch = cookiesString.charAt(pos);
|
|
283
|
+
|
|
284
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
while (pos < cookiesString.length) {
|
|
288
|
+
start = pos;
|
|
289
|
+
cookiesSeparatorFound = false;
|
|
290
|
+
|
|
291
|
+
while (skipWhitespace()) {
|
|
292
|
+
ch = cookiesString.charAt(pos);
|
|
293
|
+
if (ch === ",") {
|
|
294
|
+
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
295
|
+
lastComma = pos;
|
|
296
|
+
pos += 1;
|
|
297
|
+
|
|
298
|
+
skipWhitespace();
|
|
299
|
+
nextStart = pos;
|
|
300
|
+
|
|
301
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
302
|
+
pos += 1;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// currently special character
|
|
306
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
307
|
+
// we found cookies separator
|
|
308
|
+
cookiesSeparatorFound = true;
|
|
309
|
+
// pos is inside the next cookie, so back up and return it.
|
|
310
|
+
pos = nextStart;
|
|
311
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
312
|
+
start = pos;
|
|
313
|
+
} else {
|
|
314
|
+
// in param ',' or param separator ';',
|
|
315
|
+
// we continue from that comma
|
|
316
|
+
pos = lastComma + 1;
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
pos += 1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
324
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return cookiesStrings;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// named export for CJS
|
|
332
|
+
parseSetCookie.parseSetCookie = parseSetCookie;
|
|
333
|
+
// for backwards compatibility
|
|
334
|
+
parseSetCookie.parse = parseSetCookie;
|
|
335
|
+
parseSetCookie.parseString = parseString;
|
|
336
|
+
parseSetCookie.splitCookiesString = splitCookiesString;
|
|
337
|
+
|
|
338
|
+
const UNDEFINED = -1;
|
|
339
|
+
const HOLE = -2;
|
|
340
|
+
const NAN = -3;
|
|
341
|
+
const POSITIVE_INFINITY = -4;
|
|
342
|
+
const NEGATIVE_INFINITY = -5;
|
|
343
|
+
const NEGATIVE_ZERO = -6;
|
|
344
|
+
const SPARSE = -7;
|
|
345
|
+
|
|
346
|
+
// The largest valid value for a JavaScript array's `length` property,
|
|
347
|
+
// and the largest valid array index (one less than the max length).
|
|
348
|
+
const MAX_ARRAY_LEN = 2 ** 32 - 1;
|
|
349
|
+
const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;
|
|
350
|
+
|
|
351
|
+
/** @type {Record<string, string>} */
|
|
352
|
+
const escaped = {
|
|
353
|
+
'<': '\\u003C',
|
|
354
|
+
'\\': '\\\\',
|
|
355
|
+
'\b': '\\b',
|
|
356
|
+
'\f': '\\f',
|
|
357
|
+
'\n': '\\n',
|
|
358
|
+
'\r': '\\r',
|
|
359
|
+
'\t': '\\t',
|
|
360
|
+
'\u2028': '\\u2028',
|
|
361
|
+
'\u2029': '\\u2029'
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
class DevalueError extends Error {
|
|
365
|
+
/**
|
|
366
|
+
* @param {string} message
|
|
367
|
+
* @param {string[]} keys
|
|
368
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
369
|
+
* @param {any} [root] - The root value being serialized
|
|
370
|
+
*/
|
|
371
|
+
constructor(message, keys, value, root) {
|
|
372
|
+
super(message);
|
|
373
|
+
this.name = 'DevalueError';
|
|
374
|
+
this.path = keys.join('');
|
|
375
|
+
this.value = value;
|
|
376
|
+
this.root = root;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** @param {any} thing */
|
|
381
|
+
function is_primitive(thing) {
|
|
382
|
+
return thing === null || (typeof thing !== 'object' && typeof thing !== 'function');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype)
|
|
386
|
+
.sort()
|
|
387
|
+
.join('\0');
|
|
388
|
+
|
|
389
|
+
/** @param {any} thing */
|
|
390
|
+
function is_plain_object(thing) {
|
|
391
|
+
const proto = Object.getPrototypeOf(thing);
|
|
392
|
+
|
|
393
|
+
return (
|
|
394
|
+
proto === Object.prototype ||
|
|
395
|
+
proto === null ||
|
|
396
|
+
Object.getPrototypeOf(proto) === null ||
|
|
397
|
+
Object.getOwnPropertyNames(proto).sort().join('\0') === object_proto_names
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** @param {any} thing */
|
|
402
|
+
function get_type(thing) {
|
|
403
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** @param {string} char */
|
|
407
|
+
function get_escaped_char(char) {
|
|
408
|
+
switch (char) {
|
|
409
|
+
case '"':
|
|
410
|
+
return '\\"';
|
|
411
|
+
case '<':
|
|
412
|
+
return '\\u003C';
|
|
413
|
+
case '\\':
|
|
414
|
+
return '\\\\';
|
|
415
|
+
case '\n':
|
|
416
|
+
return '\\n';
|
|
417
|
+
case '\r':
|
|
418
|
+
return '\\r';
|
|
419
|
+
case '\t':
|
|
420
|
+
return '\\t';
|
|
421
|
+
case '\b':
|
|
422
|
+
return '\\b';
|
|
423
|
+
case '\f':
|
|
424
|
+
return '\\f';
|
|
425
|
+
case '\u2028':
|
|
426
|
+
return '\\u2028';
|
|
427
|
+
case '\u2029':
|
|
428
|
+
return '\\u2029';
|
|
429
|
+
default:
|
|
430
|
+
return char < ' ' ? `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}` : '';
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** @param {string} str */
|
|
435
|
+
function stringify_string(str) {
|
|
436
|
+
let result = '';
|
|
437
|
+
let last_pos = 0;
|
|
438
|
+
const len = str.length;
|
|
439
|
+
|
|
440
|
+
for (let i = 0; i < len; i += 1) {
|
|
441
|
+
const char = str[i];
|
|
442
|
+
const replacement = get_escaped_char(char);
|
|
443
|
+
if (replacement) {
|
|
444
|
+
result += str.slice(last_pos, i) + replacement;
|
|
445
|
+
last_pos = i + 1;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** @param {Record<string | symbol, any>} object */
|
|
453
|
+
function enumerable_symbols(object) {
|
|
454
|
+
return Object.getOwnPropertySymbols(object).filter(
|
|
455
|
+
(symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
460
|
+
|
|
461
|
+
/** @param {string} key */
|
|
462
|
+
function stringify_key(key) {
|
|
463
|
+
return is_identifier.test(key) ? '.' + key : '[' + JSON.stringify(key) + ']';
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** @param {number} n */
|
|
467
|
+
function is_valid_array_index(n) {
|
|
468
|
+
if (!Number.isInteger(n)) return false;
|
|
469
|
+
if (n < 0) return false;
|
|
470
|
+
if (n > MAX_ARRAY_INDEX) return false;
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** @param {number} n */
|
|
475
|
+
function is_valid_array_len(n) {
|
|
476
|
+
if (!Number.isInteger(n)) return false;
|
|
477
|
+
if (n < 0) return false;
|
|
478
|
+
if (n > MAX_ARRAY_LEN) return false;
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** @param {string} s */
|
|
483
|
+
function is_valid_array_index_string(s) {
|
|
484
|
+
if (s.length === 0) return false;
|
|
485
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false; // leading zero
|
|
486
|
+
for (let i = 0; i < s.length; i++) {
|
|
487
|
+
const c = s.charCodeAt(i);
|
|
488
|
+
if (c < 48 || c > 57) return false;
|
|
489
|
+
}
|
|
490
|
+
// by this point we know it's a string of digits, but it has to be within
|
|
491
|
+
// the range of valid array indices
|
|
492
|
+
return is_valid_array_index(+s);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Finds the populated indices of an array.
|
|
497
|
+
* @param {unknown[]} array
|
|
498
|
+
*/
|
|
499
|
+
function valid_array_indices(array) {
|
|
500
|
+
const keys = Object.keys(array);
|
|
501
|
+
for (var i = keys.length - 1; i >= 0; i--) {
|
|
502
|
+
if (is_valid_array_index_string(keys[i])) {
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
keys.length = i + 1;
|
|
507
|
+
return keys;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
|
|
511
|
+
const unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
512
|
+
const reserved =
|
|
513
|
+
/^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Turn a value into the JavaScript that creates an equivalent value
|
|
517
|
+
* @param {any} value
|
|
518
|
+
* @param {(value: any, uneval: (value: any) => string) => string | void} [replacer]
|
|
519
|
+
*/
|
|
520
|
+
function uneval(value, replacer) {
|
|
521
|
+
const counts = new Map();
|
|
522
|
+
|
|
523
|
+
/** @type {string[]} */
|
|
524
|
+
const keys = [];
|
|
525
|
+
|
|
526
|
+
const custom = new Map();
|
|
527
|
+
|
|
528
|
+
/** @param {any} thing */
|
|
529
|
+
function walk(thing) {
|
|
530
|
+
if (!is_primitive(thing)) {
|
|
531
|
+
if (counts.has(thing)) {
|
|
532
|
+
counts.set(thing, counts.get(thing) + 1);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
counts.set(thing, 1);
|
|
537
|
+
|
|
538
|
+
if (replacer) {
|
|
539
|
+
const str = replacer(thing, (value) => uneval(value, replacer));
|
|
540
|
+
|
|
541
|
+
if (typeof str === 'string') {
|
|
542
|
+
custom.set(thing, str);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (typeof thing === 'function') {
|
|
548
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const type = get_type(thing);
|
|
552
|
+
|
|
553
|
+
switch (type) {
|
|
554
|
+
case 'Number':
|
|
555
|
+
case 'BigInt':
|
|
556
|
+
case 'String':
|
|
557
|
+
case 'Boolean':
|
|
558
|
+
case 'Date':
|
|
559
|
+
case 'RegExp':
|
|
560
|
+
case 'URL':
|
|
561
|
+
case 'URLSearchParams':
|
|
562
|
+
return;
|
|
563
|
+
|
|
564
|
+
case 'Array':
|
|
565
|
+
/** @type {any[]} */ (thing).forEach((value, i) => {
|
|
566
|
+
keys.push(`[${i}]`);
|
|
567
|
+
walk(value);
|
|
568
|
+
keys.pop();
|
|
569
|
+
});
|
|
570
|
+
break;
|
|
571
|
+
|
|
572
|
+
case 'Set':
|
|
573
|
+
Array.from(thing).forEach(walk);
|
|
574
|
+
break;
|
|
575
|
+
|
|
576
|
+
case 'Map':
|
|
577
|
+
for (const [key, value] of thing) {
|
|
578
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive$1(key) : '...'})`);
|
|
579
|
+
walk(value);
|
|
580
|
+
keys.pop();
|
|
581
|
+
}
|
|
582
|
+
break;
|
|
583
|
+
|
|
584
|
+
case 'Int8Array':
|
|
585
|
+
case 'Uint8Array':
|
|
586
|
+
case 'Uint8ClampedArray':
|
|
587
|
+
case 'Int16Array':
|
|
588
|
+
case 'Uint16Array':
|
|
589
|
+
case 'Float16Array':
|
|
590
|
+
case 'Int32Array':
|
|
591
|
+
case 'Uint32Array':
|
|
592
|
+
case 'Float32Array':
|
|
593
|
+
case 'Float64Array':
|
|
594
|
+
case 'BigInt64Array':
|
|
595
|
+
case 'BigUint64Array':
|
|
596
|
+
case 'DataView':
|
|
597
|
+
walk(thing.buffer);
|
|
598
|
+
return;
|
|
599
|
+
|
|
600
|
+
case 'ArrayBuffer':
|
|
601
|
+
return;
|
|
602
|
+
|
|
603
|
+
case 'Temporal.Duration':
|
|
604
|
+
case 'Temporal.Instant':
|
|
605
|
+
case 'Temporal.PlainDate':
|
|
606
|
+
case 'Temporal.PlainTime':
|
|
607
|
+
case 'Temporal.PlainDateTime':
|
|
608
|
+
case 'Temporal.PlainMonthDay':
|
|
609
|
+
case 'Temporal.PlainYearMonth':
|
|
610
|
+
case 'Temporal.ZonedDateTime':
|
|
611
|
+
return;
|
|
612
|
+
|
|
613
|
+
default:
|
|
614
|
+
if (!is_plain_object(thing)) {
|
|
615
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
619
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
for (const key of Object.keys(thing)) {
|
|
623
|
+
if (key === '__proto__') {
|
|
624
|
+
throw new DevalueError(
|
|
625
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
626
|
+
keys,
|
|
627
|
+
thing,
|
|
628
|
+
value
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
keys.push(stringify_key(key));
|
|
633
|
+
walk(thing[key]);
|
|
634
|
+
keys.pop();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
} else if (typeof thing === 'symbol') {
|
|
638
|
+
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
walk(value);
|
|
643
|
+
|
|
644
|
+
const names = new Map();
|
|
645
|
+
|
|
646
|
+
Array.from(counts)
|
|
647
|
+
.filter((entry) => entry[1] > 1)
|
|
648
|
+
.sort((a, b) => b[1] - a[1])
|
|
649
|
+
.forEach((entry, i) => {
|
|
650
|
+
names.set(entry[0], get_name(i));
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* @param {any} thing
|
|
655
|
+
* @returns {string}
|
|
656
|
+
*/
|
|
657
|
+
function stringify(thing) {
|
|
658
|
+
if (names.has(thing)) {
|
|
659
|
+
return names.get(thing);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (is_primitive(thing)) {
|
|
663
|
+
return stringify_primitive$1(thing);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (custom.has(thing)) {
|
|
667
|
+
return custom.get(thing);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const type = get_type(thing);
|
|
671
|
+
|
|
672
|
+
switch (type) {
|
|
673
|
+
case 'Number':
|
|
674
|
+
case 'String':
|
|
675
|
+
case 'Boolean':
|
|
676
|
+
case 'BigInt':
|
|
677
|
+
return `Object(${stringify(thing.valueOf())})`;
|
|
678
|
+
|
|
679
|
+
case 'RegExp':
|
|
680
|
+
const { source, flags } = thing;
|
|
681
|
+
return flags
|
|
682
|
+
? `new RegExp(${stringify_string(source)},"${flags}")`
|
|
683
|
+
: `new RegExp(${stringify_string(source)})`;
|
|
684
|
+
|
|
685
|
+
case 'Date':
|
|
686
|
+
return `new Date(${thing.getTime()})`;
|
|
687
|
+
|
|
688
|
+
case 'URL':
|
|
689
|
+
return `new URL(${stringify_string(thing.toString())})`;
|
|
690
|
+
|
|
691
|
+
case 'URLSearchParams':
|
|
692
|
+
return `new URLSearchParams(${stringify_string(thing.toString())})`;
|
|
693
|
+
|
|
694
|
+
case 'Array': {
|
|
695
|
+
// For dense arrays (no holes), we iterate normally.
|
|
696
|
+
// When we encounter the first hole, we call Object.keys
|
|
697
|
+
// to determine the sparseness, then decide between:
|
|
698
|
+
// - Array literal with holes: [,"a",,] (default)
|
|
699
|
+
// - Object.assign: Object.assign(Array(n),{...}) (for very sparse arrays)
|
|
700
|
+
// Only the Object.assign path avoids iterating every slot, which
|
|
701
|
+
// is what protects against the DoS of e.g. `arr[1000000] = 1`.
|
|
702
|
+
let has_holes = false;
|
|
703
|
+
|
|
704
|
+
let result = '[';
|
|
705
|
+
|
|
706
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
707
|
+
if (i > 0) result += ',';
|
|
708
|
+
|
|
709
|
+
if (Object.hasOwn(thing, i)) {
|
|
710
|
+
result += stringify(thing[i]);
|
|
711
|
+
} else if (!has_holes) {
|
|
712
|
+
// Decide between array literal and Object.assign.
|
|
713
|
+
//
|
|
714
|
+
// Array literal: holes are consecutive commas.
|
|
715
|
+
// For example, [, "a", ,] is written as [,"a",,].
|
|
716
|
+
// Each hole costs 1 char (a comma).
|
|
717
|
+
//
|
|
718
|
+
// Object.assign: populated indices are listed explicitly.
|
|
719
|
+
// For example, [, "a", ,] would be written as
|
|
720
|
+
// Object.assign(Array(3),{1:"a"}). This avoids paying
|
|
721
|
+
// per-hole, but has a large fixed overhead for the
|
|
722
|
+
// "Object.assign(Array(n),{...})" wrapper, and each
|
|
723
|
+
// element costs extra chars for its index and colon.
|
|
724
|
+
//
|
|
725
|
+
// The serialized values are the same size either way, so
|
|
726
|
+
// the choice comes down to the structural overhead:
|
|
727
|
+
//
|
|
728
|
+
// Array literal overhead:
|
|
729
|
+
// 1 char per element or hole (comma separators)
|
|
730
|
+
// + 2 chars for "[" and "]"
|
|
731
|
+
// = L + 2
|
|
732
|
+
//
|
|
733
|
+
// Object.assign overhead:
|
|
734
|
+
// "Object.assign(Array(" — 20 chars
|
|
735
|
+
// + length — d chars
|
|
736
|
+
// + "),{" — 3 chars
|
|
737
|
+
// + for each populated element:
|
|
738
|
+
// index + ":" + "," — (d + 2) chars
|
|
739
|
+
// + "})" — 2 chars
|
|
740
|
+
// = (25 + d) + P * (d + 2)
|
|
741
|
+
//
|
|
742
|
+
// where L is the array length, P is the number of
|
|
743
|
+
// populated elements, and d is the number of digits
|
|
744
|
+
// in L (an upper bound on the digits in any index).
|
|
745
|
+
//
|
|
746
|
+
// Object.assign is cheaper when:
|
|
747
|
+
// (25 + d) + P * (d + 2) < L + 2
|
|
748
|
+
const populated_keys = valid_array_indices(/** @type {any[]} */ (thing));
|
|
749
|
+
const population = populated_keys.length;
|
|
750
|
+
const d = String(thing.length).length;
|
|
751
|
+
|
|
752
|
+
const hole_cost = thing.length + 2;
|
|
753
|
+
const sparse_cost = 25 + d + population * (d + 2);
|
|
754
|
+
|
|
755
|
+
if (hole_cost > sparse_cost) {
|
|
756
|
+
const entries = populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(',');
|
|
757
|
+
return `Object.assign(Array(${thing.length}),{${entries}})`;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// Re-process this index as a hole in the array literal
|
|
761
|
+
has_holes = true;
|
|
762
|
+
i -= 1;
|
|
763
|
+
}
|
|
764
|
+
// else: already decided on array literal, hole is just an empty slot
|
|
765
|
+
// (the comma separator is all we need — no content for this position)
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const tail = thing.length === 0 || thing.length - 1 in thing ? '' : ',';
|
|
769
|
+
return result + tail + ']';
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
case 'Set':
|
|
773
|
+
case 'Map':
|
|
774
|
+
return `new ${type}([${Array.from(thing).map(stringify).join(',')}])`;
|
|
775
|
+
|
|
776
|
+
case 'Int8Array':
|
|
777
|
+
case 'Uint8Array':
|
|
778
|
+
case 'Uint8ClampedArray':
|
|
779
|
+
case 'Int16Array':
|
|
780
|
+
case 'Uint16Array':
|
|
781
|
+
case 'Float16Array':
|
|
782
|
+
case 'Int32Array':
|
|
783
|
+
case 'Uint32Array':
|
|
784
|
+
case 'Float32Array':
|
|
785
|
+
case 'Float64Array':
|
|
786
|
+
case 'BigInt64Array':
|
|
787
|
+
case 'BigUint64Array': {
|
|
788
|
+
let str = `new ${type}`;
|
|
789
|
+
|
|
790
|
+
if (!names.has(thing.buffer)) {
|
|
791
|
+
const array = new thing.constructor(thing.buffer);
|
|
792
|
+
str += `([${array}])`;
|
|
793
|
+
} else {
|
|
794
|
+
str += `(${stringify(thing.buffer)})`;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// handle subarrays
|
|
798
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
799
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
800
|
+
const end = start + thing.length;
|
|
801
|
+
str += `.subarray(${start},${end})`;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
return str;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
case 'DataView': {
|
|
808
|
+
let str = `new DataView`;
|
|
809
|
+
|
|
810
|
+
if (!names.has(thing.buffer)) {
|
|
811
|
+
str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
812
|
+
} else {
|
|
813
|
+
str += `(${stringify(thing.buffer)}`;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// handle subviews
|
|
817
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
818
|
+
str += `,${thing.startOffset},${thing.byteLength}`;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return str + ')';
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
case 'ArrayBuffer': {
|
|
825
|
+
const ui8 = new Uint8Array(thing);
|
|
826
|
+
return `new Uint8Array([${ui8.toString()}]).buffer`;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
case 'Temporal.Duration':
|
|
830
|
+
case 'Temporal.Instant':
|
|
831
|
+
case 'Temporal.PlainDate':
|
|
832
|
+
case 'Temporal.PlainTime':
|
|
833
|
+
case 'Temporal.PlainDateTime':
|
|
834
|
+
case 'Temporal.PlainMonthDay':
|
|
835
|
+
case 'Temporal.PlainYearMonth':
|
|
836
|
+
case 'Temporal.ZonedDateTime':
|
|
837
|
+
return `${type}.from(${stringify_string(thing.toString())})`;
|
|
838
|
+
|
|
839
|
+
default:
|
|
840
|
+
const keys = Object.keys(thing);
|
|
841
|
+
const obj = keys.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(',');
|
|
842
|
+
const proto = Object.getPrototypeOf(thing);
|
|
843
|
+
if (proto === null) {
|
|
844
|
+
return keys.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
return `{${obj}}`;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const str = stringify(value);
|
|
852
|
+
|
|
853
|
+
if (names.size) {
|
|
854
|
+
/** @type {string[]} */
|
|
855
|
+
const params = [];
|
|
856
|
+
|
|
857
|
+
/** @type {string[]} */
|
|
858
|
+
const statements = [];
|
|
859
|
+
|
|
860
|
+
/** @type {string[]} */
|
|
861
|
+
const values = [];
|
|
862
|
+
|
|
863
|
+
names.forEach((name, thing) => {
|
|
864
|
+
params.push(name);
|
|
865
|
+
|
|
866
|
+
if (custom.has(thing)) {
|
|
867
|
+
values.push(/** @type {string} */ (custom.get(thing)));
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
if (is_primitive(thing)) {
|
|
872
|
+
values.push(stringify_primitive$1(thing));
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const type = get_type(thing);
|
|
877
|
+
|
|
878
|
+
switch (type) {
|
|
879
|
+
case 'Number':
|
|
880
|
+
case 'String':
|
|
881
|
+
case 'Boolean':
|
|
882
|
+
case 'BigInt':
|
|
883
|
+
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
884
|
+
break;
|
|
885
|
+
|
|
886
|
+
case 'RegExp':
|
|
887
|
+
const { source, flags } = thing;
|
|
888
|
+
const regexp = flags
|
|
889
|
+
? `new RegExp(${stringify_string(source)},"${flags}")`
|
|
890
|
+
: `new RegExp(${stringify_string(source)})`;
|
|
891
|
+
values.push(regexp);
|
|
892
|
+
break;
|
|
893
|
+
|
|
894
|
+
case 'Date':
|
|
895
|
+
values.push(`new Date(${thing.getTime()})`);
|
|
896
|
+
break;
|
|
897
|
+
|
|
898
|
+
case 'URL':
|
|
899
|
+
values.push(`new URL(${stringify_string(thing.toString())})`);
|
|
900
|
+
break;
|
|
901
|
+
|
|
902
|
+
case 'URLSearchParams':
|
|
903
|
+
values.push(`new URLSearchParams(${stringify_string(thing.toString())})`);
|
|
904
|
+
break;
|
|
905
|
+
|
|
906
|
+
case 'Array':
|
|
907
|
+
values.push(`Array(${thing.length})`);
|
|
908
|
+
/** @type {any[]} */ (thing).forEach((v, i) => {
|
|
909
|
+
statements.push(`${name}[${i}]=${stringify(v)}`);
|
|
910
|
+
});
|
|
911
|
+
break;
|
|
912
|
+
|
|
913
|
+
case 'Set':
|
|
914
|
+
values.push(`new Set`);
|
|
915
|
+
statements.push(
|
|
916
|
+
`${name}.${Array.from(thing)
|
|
917
|
+
.map((v) => `add(${stringify(v)})`)
|
|
918
|
+
.join('.')}`
|
|
919
|
+
);
|
|
920
|
+
break;
|
|
921
|
+
|
|
922
|
+
case 'Map':
|
|
923
|
+
values.push(`new Map`);
|
|
924
|
+
statements.push(
|
|
925
|
+
`${name}.${Array.from(thing)
|
|
926
|
+
.map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`)
|
|
927
|
+
.join('.')}`
|
|
928
|
+
);
|
|
929
|
+
break;
|
|
930
|
+
|
|
931
|
+
case 'Int8Array':
|
|
932
|
+
case 'Uint8Array':
|
|
933
|
+
case 'Uint8ClampedArray':
|
|
934
|
+
case 'Int16Array':
|
|
935
|
+
case 'Uint16Array':
|
|
936
|
+
case 'Float16Array':
|
|
937
|
+
case 'Int32Array':
|
|
938
|
+
case 'Uint32Array':
|
|
939
|
+
case 'Float32Array':
|
|
940
|
+
case 'Float64Array':
|
|
941
|
+
case 'BigInt64Array':
|
|
942
|
+
case 'BigUint64Array': {
|
|
943
|
+
let str = `new ${type}`;
|
|
944
|
+
|
|
945
|
+
if (!names.has(thing.buffer)) {
|
|
946
|
+
const array = new thing.constructor(thing.buffer);
|
|
947
|
+
str += `([${array}])`;
|
|
948
|
+
} else {
|
|
949
|
+
str += `(${stringify(thing.buffer)})`;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// handle subarrays
|
|
953
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
954
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
955
|
+
const end = start + thing.length;
|
|
956
|
+
str += `.subarray(${start},${end})`;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
values.push(`{}`);
|
|
960
|
+
statements.push(`${name}=${str}`);
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
case 'DataView': {
|
|
965
|
+
let str = `new DataView`;
|
|
966
|
+
|
|
967
|
+
if (!names.has(thing.buffer)) {
|
|
968
|
+
str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
969
|
+
} else {
|
|
970
|
+
str += `(${stringify(thing.buffer)}`;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// handle subviews
|
|
974
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
975
|
+
str += `,${thing.byteOffset},${thing.byteLength}`;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
str += ')';
|
|
979
|
+
|
|
980
|
+
values.push(`{}`);
|
|
981
|
+
statements.push(`${name}=${str}`);
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
case 'ArrayBuffer':
|
|
986
|
+
values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`);
|
|
987
|
+
break;
|
|
988
|
+
|
|
989
|
+
default:
|
|
990
|
+
values.push(Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}');
|
|
991
|
+
Object.keys(thing).forEach((key) => {
|
|
992
|
+
statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
statements.push(`return ${str}`);
|
|
998
|
+
|
|
999
|
+
return `(function(${params.join(',')}){${statements.join(';')}}(${values.join(',')}))`;
|
|
1000
|
+
} else {
|
|
1001
|
+
return str;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/** @param {number} num */
|
|
1006
|
+
function get_name(num) {
|
|
1007
|
+
let name = '';
|
|
1008
|
+
|
|
1009
|
+
do {
|
|
1010
|
+
name = chars[num % chars.length] + name;
|
|
1011
|
+
num = ~~(num / chars.length) - 1;
|
|
1012
|
+
} while (num >= 0);
|
|
1013
|
+
|
|
1014
|
+
return reserved.test(name) ? `${name}0` : name;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/** @param {string} c */
|
|
1018
|
+
function escape_unsafe_char(c) {
|
|
1019
|
+
return escaped[c] || c;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/** @param {string} str */
|
|
1023
|
+
function escape_unsafe_chars(str) {
|
|
1024
|
+
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/** @param {string} key */
|
|
1028
|
+
function safe_key(key) {
|
|
1029
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/** @param {string} key */
|
|
1033
|
+
function safe_prop(key) {
|
|
1034
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key)
|
|
1035
|
+
? `.${key}`
|
|
1036
|
+
: `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/** @param {any} thing */
|
|
1040
|
+
function stringify_primitive$1(thing) {
|
|
1041
|
+
const type = typeof thing;
|
|
1042
|
+
if (type === 'string') return stringify_string(thing);
|
|
1043
|
+
if (thing === void 0) return 'void 0';
|
|
1044
|
+
if (thing === 0 && 1 / thing < 0) return '-0';
|
|
1045
|
+
const str = String(thing);
|
|
1046
|
+
if (type === 'number') return str.replace(/^(-)?0\./, '$1.');
|
|
1047
|
+
if (type === 'bigint') return thing + 'n';
|
|
1048
|
+
return str;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/* Baseline 2025 runtimes */
|
|
1052
|
+
|
|
1053
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
1054
|
+
function encode_native(array_buffer) {
|
|
1055
|
+
return new Uint8Array(array_buffer).toBase64();
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
1059
|
+
function decode_native(base64) {
|
|
1060
|
+
return Uint8Array.fromBase64(base64).buffer;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
/* Node-compatible runtimes */
|
|
1064
|
+
|
|
1065
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
1066
|
+
function encode_buffer(array_buffer) {
|
|
1067
|
+
return Buffer.from(array_buffer).toString('base64');
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
1071
|
+
function decode_buffer(base64) {
|
|
1072
|
+
return Uint8Array.from(Buffer.from(base64, 'base64')).buffer;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/* Legacy runtimes */
|
|
1076
|
+
|
|
1077
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
1078
|
+
function encode_legacy(array_buffer) {
|
|
1079
|
+
const array = new Uint8Array(array_buffer);
|
|
1080
|
+
let binary = '';
|
|
1081
|
+
|
|
1082
|
+
// the maximum number of arguments to String.fromCharCode.apply
|
|
1083
|
+
// should be around 0xFFFF in modern engines
|
|
1084
|
+
const chunk_size = 0x8000;
|
|
1085
|
+
for (let i = 0; i < array.length; i += chunk_size) {
|
|
1086
|
+
const chunk = array.subarray(i, i + chunk_size);
|
|
1087
|
+
binary += String.fromCharCode.apply(null, chunk);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
return btoa(binary);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
1094
|
+
function decode_legacy(base64) {
|
|
1095
|
+
const binary_string = atob(base64);
|
|
1096
|
+
const len = binary_string.length;
|
|
1097
|
+
const array = new Uint8Array(len);
|
|
1098
|
+
|
|
1099
|
+
for (let i = 0; i < len; i++) {
|
|
1100
|
+
array[i] = binary_string.charCodeAt(i);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
return array.buffer;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
const native = typeof Uint8Array.fromBase64 === 'function';
|
|
1107
|
+
const buffer = typeof process === 'object' && process.versions?.node !== undefined;
|
|
1108
|
+
|
|
1109
|
+
const encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
1110
|
+
const decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Revive a value serialized with `devalue.stringify`
|
|
1114
|
+
* @param {string} serialized
|
|
1115
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
1116
|
+
*/
|
|
1117
|
+
function parse(serialized, revivers) {
|
|
1118
|
+
return unflatten(JSON.parse(serialized), revivers);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Revive a value flattened with `devalue.stringify`
|
|
1123
|
+
* @param {number | any[]} parsed
|
|
1124
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
1125
|
+
*/
|
|
1126
|
+
function unflatten(parsed, revivers) {
|
|
1127
|
+
if (typeof parsed === 'number') return hydrate(parsed, true);
|
|
1128
|
+
|
|
1129
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
1130
|
+
throw new Error('Invalid input');
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
const values = /** @type {any[]} */ (parsed);
|
|
1134
|
+
|
|
1135
|
+
const hydrated = Array(values.length);
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* A set of values currently being hydrated with custom revivers,
|
|
1139
|
+
* used to detect invalid cyclical dependencies
|
|
1140
|
+
* @type {Set<number> | null}
|
|
1141
|
+
*/
|
|
1142
|
+
let hydrating = null;
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* @param {number} index
|
|
1146
|
+
* @returns {any}
|
|
1147
|
+
*/
|
|
1148
|
+
function hydrate(index, standalone = false) {
|
|
1149
|
+
if (index === UNDEFINED) return undefined;
|
|
1150
|
+
if (index === NAN) return NaN;
|
|
1151
|
+
if (index === POSITIVE_INFINITY) return Infinity;
|
|
1152
|
+
if (index === NEGATIVE_INFINITY) return -Infinity;
|
|
1153
|
+
if (index === NEGATIVE_ZERO) return -0;
|
|
1154
|
+
|
|
1155
|
+
if (standalone || typeof index !== 'number') {
|
|
1156
|
+
throw new Error(`Invalid input`);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
if (index in hydrated) return hydrated[index];
|
|
1160
|
+
|
|
1161
|
+
const value = values[index];
|
|
1162
|
+
|
|
1163
|
+
if (!value || typeof value !== 'object') {
|
|
1164
|
+
hydrated[index] = value;
|
|
1165
|
+
} else if (Array.isArray(value)) {
|
|
1166
|
+
if (typeof value[0] === 'string') {
|
|
1167
|
+
const type = value[0];
|
|
1168
|
+
|
|
1169
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : undefined;
|
|
1170
|
+
|
|
1171
|
+
if (reviver) {
|
|
1172
|
+
let i = value[1];
|
|
1173
|
+
if (typeof i !== 'number') {
|
|
1174
|
+
// if it's not a number, it was serialized by a builtin reviver
|
|
1175
|
+
// so we need to munge it into the format expected by a custom reviver
|
|
1176
|
+
i = values.push(value[1]) - 1;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
hydrating ??= new Set();
|
|
1180
|
+
|
|
1181
|
+
if (hydrating.has(i)) {
|
|
1182
|
+
throw new Error('Invalid circular reference');
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
hydrating.add(i);
|
|
1186
|
+
hydrated[index] = reviver(hydrate(i));
|
|
1187
|
+
hydrating.delete(i);
|
|
1188
|
+
|
|
1189
|
+
return hydrated[index];
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
switch (type) {
|
|
1193
|
+
case 'Date':
|
|
1194
|
+
hydrated[index] = new Date(value[1]);
|
|
1195
|
+
break;
|
|
1196
|
+
|
|
1197
|
+
case 'Set':
|
|
1198
|
+
const set = new Set();
|
|
1199
|
+
hydrated[index] = set;
|
|
1200
|
+
for (let i = 1; i < value.length; i += 1) {
|
|
1201
|
+
set.add(hydrate(value[i]));
|
|
1202
|
+
}
|
|
1203
|
+
break;
|
|
1204
|
+
|
|
1205
|
+
case 'Map':
|
|
1206
|
+
const map = new Map();
|
|
1207
|
+
hydrated[index] = map;
|
|
1208
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
1209
|
+
map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
|
1210
|
+
}
|
|
1211
|
+
break;
|
|
1212
|
+
|
|
1213
|
+
case 'RegExp':
|
|
1214
|
+
hydrated[index] = new RegExp(value[1], value[2]);
|
|
1215
|
+
break;
|
|
1216
|
+
|
|
1217
|
+
case 'Object': {
|
|
1218
|
+
const wrapped_index = value[1];
|
|
1219
|
+
|
|
1220
|
+
if (
|
|
1221
|
+
typeof values[wrapped_index] === 'object' &&
|
|
1222
|
+
values[wrapped_index][0] !== 'BigInt'
|
|
1223
|
+
) {
|
|
1224
|
+
// avoid infinite recusion in case of malformed input
|
|
1225
|
+
throw new Error('Invalid input');
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
hydrated[index] = Object(hydrate(wrapped_index));
|
|
1229
|
+
break;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
case 'BigInt':
|
|
1233
|
+
hydrated[index] = BigInt(value[1]);
|
|
1234
|
+
break;
|
|
1235
|
+
|
|
1236
|
+
case 'null':
|
|
1237
|
+
const obj = Object.create(null);
|
|
1238
|
+
hydrated[index] = obj;
|
|
1239
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
1240
|
+
if (value[i] === '__proto__') {
|
|
1241
|
+
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
obj[value[i]] = hydrate(value[i + 1]);
|
|
1245
|
+
}
|
|
1246
|
+
break;
|
|
1247
|
+
|
|
1248
|
+
case 'Int8Array':
|
|
1249
|
+
case 'Uint8Array':
|
|
1250
|
+
case 'Uint8ClampedArray':
|
|
1251
|
+
case 'Int16Array':
|
|
1252
|
+
case 'Uint16Array':
|
|
1253
|
+
case 'Float16Array':
|
|
1254
|
+
case 'Int32Array':
|
|
1255
|
+
case 'Uint32Array':
|
|
1256
|
+
case 'Float32Array':
|
|
1257
|
+
case 'Float64Array':
|
|
1258
|
+
case 'BigInt64Array':
|
|
1259
|
+
case 'BigUint64Array':
|
|
1260
|
+
case 'DataView': {
|
|
1261
|
+
if (values[value[1]][0] !== 'ArrayBuffer') {
|
|
1262
|
+
// without this, if we receive malformed input we could
|
|
1263
|
+
// end up trying to hydrate in a circle or allocate
|
|
1264
|
+
// huge amounts of memory when we call `new TypedArrayConstructor(buffer)`
|
|
1265
|
+
throw new Error('Invalid data');
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
const TypedArrayConstructor = globalThis[type];
|
|
1269
|
+
const buffer = hydrate(value[1]);
|
|
1270
|
+
|
|
1271
|
+
hydrated[index] =
|
|
1272
|
+
value[2] !== undefined
|
|
1273
|
+
? new TypedArrayConstructor(buffer, value[2], value[3])
|
|
1274
|
+
: new TypedArrayConstructor(buffer);
|
|
1275
|
+
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
case 'ArrayBuffer': {
|
|
1280
|
+
const base64 = value[1];
|
|
1281
|
+
if (typeof base64 !== 'string') {
|
|
1282
|
+
throw new Error('Invalid ArrayBuffer encoding');
|
|
1283
|
+
}
|
|
1284
|
+
const arraybuffer = decode64(base64);
|
|
1285
|
+
hydrated[index] = arraybuffer;
|
|
1286
|
+
break;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
case 'Temporal.Duration':
|
|
1290
|
+
case 'Temporal.Instant':
|
|
1291
|
+
case 'Temporal.PlainDate':
|
|
1292
|
+
case 'Temporal.PlainTime':
|
|
1293
|
+
case 'Temporal.PlainDateTime':
|
|
1294
|
+
case 'Temporal.PlainMonthDay':
|
|
1295
|
+
case 'Temporal.PlainYearMonth':
|
|
1296
|
+
case 'Temporal.ZonedDateTime': {
|
|
1297
|
+
const temporalName = type.slice(9);
|
|
1298
|
+
// @ts-expect-error TS doesn't know about Temporal yet
|
|
1299
|
+
hydrated[index] = Temporal[temporalName].from(value[1]);
|
|
1300
|
+
break;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
case 'URL': {
|
|
1304
|
+
const url = new URL(value[1]);
|
|
1305
|
+
hydrated[index] = url;
|
|
1306
|
+
break;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
case 'URLSearchParams': {
|
|
1310
|
+
const url = new URLSearchParams(value[1]);
|
|
1311
|
+
hydrated[index] = url;
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
default:
|
|
1316
|
+
throw new Error(`Unknown type ${type}`);
|
|
1317
|
+
}
|
|
1318
|
+
} else if (value[0] === SPARSE) {
|
|
1319
|
+
// Sparse array encoding: [SPARSE, length, idx, val, idx, val, ...]
|
|
1320
|
+
const len = value[1];
|
|
1321
|
+
|
|
1322
|
+
if (!is_valid_array_len(len)) {
|
|
1323
|
+
throw new Error('Invalid input');
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/** @type {any[]} */
|
|
1327
|
+
const array = [];
|
|
1328
|
+
hydrated[index] = array;
|
|
1329
|
+
|
|
1330
|
+
// Setting `array.length = len` (or equivalently calling `new Array(len)`)
|
|
1331
|
+
// on an untrusted `len` is a DoS vector: V8 eagerly allocates a
|
|
1332
|
+
// contiguous backing store for array lengths below ~10^8, so a
|
|
1333
|
+
// small payload with a huge declared length can force arbitrary
|
|
1334
|
+
// memory allocation. Touching the largest-possible index first
|
|
1335
|
+
// forces V8 into dictionary-elements mode, where `length` is
|
|
1336
|
+
// just a number and no contiguous allocation occurs.
|
|
1337
|
+
array[MAX_ARRAY_INDEX] = undefined;
|
|
1338
|
+
delete array[MAX_ARRAY_INDEX];
|
|
1339
|
+
|
|
1340
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
1341
|
+
const idx = value[i];
|
|
1342
|
+
|
|
1343
|
+
if (!is_valid_array_index(idx) || idx >= len) {
|
|
1344
|
+
throw new Error('Invalid input');
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
array[idx] = hydrate(value[i + 1]);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
array.length = len;
|
|
1351
|
+
} else {
|
|
1352
|
+
const array = new Array(value.length);
|
|
1353
|
+
hydrated[index] = array;
|
|
1354
|
+
|
|
1355
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
1356
|
+
const n = value[i];
|
|
1357
|
+
if (n === HOLE) continue;
|
|
1358
|
+
|
|
1359
|
+
array[i] = hydrate(n);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
} else {
|
|
1363
|
+
/** @type {Record<string, any>} */
|
|
1364
|
+
const object = {};
|
|
1365
|
+
hydrated[index] = object;
|
|
1366
|
+
|
|
1367
|
+
for (const key of Object.keys(value)) {
|
|
1368
|
+
if (key === '__proto__') {
|
|
1369
|
+
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const n = value[key];
|
|
1373
|
+
object[key] = hydrate(n);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
return hydrated[index];
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return hydrate(0);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
1385
|
+
* @param {any} value
|
|
1386
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
1387
|
+
*/
|
|
1388
|
+
function stringify$1(value, reducers) {
|
|
1389
|
+
const stringified = run(false, value, reducers);
|
|
1390
|
+
return typeof stringified === 'string' ? stringified : `[${stringified.join(',')}]`;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* @param {boolean} async
|
|
1395
|
+
* @param {any} value
|
|
1396
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
1397
|
+
*/
|
|
1398
|
+
function run(async, value, reducers) {
|
|
1399
|
+
/** @type {any[]} */
|
|
1400
|
+
const stringified = [];
|
|
1401
|
+
|
|
1402
|
+
/** @type {Map<any, number>} */
|
|
1403
|
+
const indexes = new Map();
|
|
1404
|
+
|
|
1405
|
+
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
1406
|
+
const custom = [];
|
|
1407
|
+
if (reducers) {
|
|
1408
|
+
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
1409
|
+
custom.push({ key, fn: reducers[key] });
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/** @type {string[]} */
|
|
1414
|
+
const keys = [];
|
|
1415
|
+
|
|
1416
|
+
let p = 0;
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* @param {any} thing
|
|
1420
|
+
* @param {number} [index]
|
|
1421
|
+
*/
|
|
1422
|
+
function flatten(thing, index) {
|
|
1423
|
+
if (thing === undefined) return UNDEFINED;
|
|
1424
|
+
if (Number.isNaN(thing)) return NAN;
|
|
1425
|
+
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
1426
|
+
if (thing === -Infinity) return NEGATIVE_INFINITY;
|
|
1427
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
|
|
1428
|
+
|
|
1429
|
+
if (indexes.has(thing)) return /** @type {number} */ (indexes.get(thing));
|
|
1430
|
+
|
|
1431
|
+
index ??= p++;
|
|
1432
|
+
indexes.set(thing, index);
|
|
1433
|
+
|
|
1434
|
+
for (const { key, fn } of custom) {
|
|
1435
|
+
const value = fn(thing);
|
|
1436
|
+
if (value) {
|
|
1437
|
+
stringified[index] = `["${key}",${flatten(value)}]`;
|
|
1438
|
+
return index;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
if (typeof thing === 'function') {
|
|
1443
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
1444
|
+
} else if (typeof thing === 'symbol') {
|
|
1445
|
+
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/** @type {string | Promise<any>} */
|
|
1449
|
+
let str = '';
|
|
1450
|
+
|
|
1451
|
+
if (is_primitive(thing)) {
|
|
1452
|
+
str = stringify_primitive(thing);
|
|
1453
|
+
} else if (typeof thing.then === 'function') {
|
|
1454
|
+
{
|
|
1455
|
+
throw new DevalueError(
|
|
1456
|
+
`Cannot stringify a Promise or thenable — use stringifyAsync instead`,
|
|
1457
|
+
keys,
|
|
1458
|
+
thing,
|
|
1459
|
+
value
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
} else {
|
|
1463
|
+
const type = get_type(thing);
|
|
1464
|
+
|
|
1465
|
+
switch (type) {
|
|
1466
|
+
case 'Number':
|
|
1467
|
+
case 'String':
|
|
1468
|
+
case 'Boolean':
|
|
1469
|
+
case 'BigInt':
|
|
1470
|
+
str = `["Object",${flatten(thing.valueOf())}]`;
|
|
1471
|
+
break;
|
|
1472
|
+
|
|
1473
|
+
case 'Date':
|
|
1474
|
+
const valid = !isNaN(thing.getDate());
|
|
1475
|
+
str = `["Date","${valid ? thing.toISOString() : ''}"]`;
|
|
1476
|
+
break;
|
|
1477
|
+
|
|
1478
|
+
case 'URL':
|
|
1479
|
+
str = `["URL",${stringify_string(thing.toString())}]`;
|
|
1480
|
+
break;
|
|
1481
|
+
|
|
1482
|
+
case 'URLSearchParams':
|
|
1483
|
+
str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
|
|
1484
|
+
break;
|
|
1485
|
+
|
|
1486
|
+
case 'RegExp':
|
|
1487
|
+
const { source, flags } = thing;
|
|
1488
|
+
str = flags
|
|
1489
|
+
? `["RegExp",${stringify_string(source)},"${flags}"]`
|
|
1490
|
+
: `["RegExp",${stringify_string(source)}]`;
|
|
1491
|
+
break;
|
|
1492
|
+
|
|
1493
|
+
case 'Array': {
|
|
1494
|
+
// For dense arrays (no holes), we iterate normally.
|
|
1495
|
+
// When we encounter the first hole, we call Object.keys
|
|
1496
|
+
// to determine the sparseness, then decide between:
|
|
1497
|
+
// - HOLE encoding: [-2, val, -2, ...] (default)
|
|
1498
|
+
// - Sparse encoding: [-7, length, idx, val, ...] (for very sparse arrays)
|
|
1499
|
+
// Only the sparse path avoids iterating every slot, which
|
|
1500
|
+
// is what protects against the DoS of e.g. `arr[1000000] = 1`.
|
|
1501
|
+
let mostly_dense = false;
|
|
1502
|
+
|
|
1503
|
+
str = '[';
|
|
1504
|
+
|
|
1505
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
1506
|
+
if (i > 0) str += ',';
|
|
1507
|
+
|
|
1508
|
+
if (Object.hasOwn(thing, i)) {
|
|
1509
|
+
keys.push(`[${i}]`);
|
|
1510
|
+
str += flatten(thing[i]);
|
|
1511
|
+
keys.pop();
|
|
1512
|
+
} else if (mostly_dense) {
|
|
1513
|
+
// Use dense encoding. The heuristic guarantees the
|
|
1514
|
+
// array is only mildly sparse, so iterating over every
|
|
1515
|
+
// slot is fine.
|
|
1516
|
+
str += HOLE;
|
|
1517
|
+
} else {
|
|
1518
|
+
// Decide between HOLE encoding and sparse encoding.
|
|
1519
|
+
//
|
|
1520
|
+
// HOLE encoding: each hole is serialized as the HOLE
|
|
1521
|
+
// sentinel (-2). For example, [, "a", ,] becomes
|
|
1522
|
+
// [-2, 0, -2]. Each hole costs 3 chars ("-2" + comma).
|
|
1523
|
+
//
|
|
1524
|
+
// Sparse encoding: lists only populated indices.
|
|
1525
|
+
// For example, [, "a", ,] becomes [-7, 3, 1, 0] — the
|
|
1526
|
+
// -7 sentinel, the array length (3), then index-value
|
|
1527
|
+
// pairs. This avoids paying per-hole, but each element
|
|
1528
|
+
// costs extra chars to write its index.
|
|
1529
|
+
//
|
|
1530
|
+
// The values are the same size either way, so the
|
|
1531
|
+
// choice comes down to structural overhead:
|
|
1532
|
+
//
|
|
1533
|
+
// HOLE overhead:
|
|
1534
|
+
// 3 chars per hole ("-2" + comma)
|
|
1535
|
+
// = (L - P) * 3
|
|
1536
|
+
//
|
|
1537
|
+
// Sparse overhead:
|
|
1538
|
+
// "-7," — 3 chars (sparse sentinel + comma)
|
|
1539
|
+
// + length + "," — (d + 1) chars (array length + comma)
|
|
1540
|
+
// + per element: index + "," — (d + 1) chars
|
|
1541
|
+
// = (4 + d) + P * (d + 1)
|
|
1542
|
+
//
|
|
1543
|
+
// where L is the array length, P is the number of
|
|
1544
|
+
// populated elements, and d is the number of digits
|
|
1545
|
+
// in L (an upper bound on the digits in any index).
|
|
1546
|
+
//
|
|
1547
|
+
// Sparse encoding is cheaper when:
|
|
1548
|
+
// (4 + d) + P * (d + 1) < (L - P) * 3
|
|
1549
|
+
const populated_keys = valid_array_indices(/** @type {any[]} */ (thing));
|
|
1550
|
+
const population = populated_keys.length;
|
|
1551
|
+
const d = String(thing.length).length;
|
|
1552
|
+
|
|
1553
|
+
const hole_cost = (thing.length - population) * 3;
|
|
1554
|
+
const sparse_cost = 4 + d + population * (d + 1);
|
|
1555
|
+
|
|
1556
|
+
if (hole_cost > sparse_cost) {
|
|
1557
|
+
str = '[' + SPARSE + ',' + thing.length;
|
|
1558
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
1559
|
+
const key = populated_keys[j];
|
|
1560
|
+
keys.push(`[${key}]`);
|
|
1561
|
+
str += ',' + key + ',' + flatten(thing[key]);
|
|
1562
|
+
keys.pop();
|
|
1563
|
+
}
|
|
1564
|
+
break;
|
|
1565
|
+
} else {
|
|
1566
|
+
mostly_dense = true;
|
|
1567
|
+
str += HOLE;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
str += ']';
|
|
1573
|
+
|
|
1574
|
+
break;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
case 'Set':
|
|
1578
|
+
str = '["Set"';
|
|
1579
|
+
|
|
1580
|
+
for (const value of thing) {
|
|
1581
|
+
str += `,${flatten(value)}`;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
str += ']';
|
|
1585
|
+
break;
|
|
1586
|
+
|
|
1587
|
+
case 'Map':
|
|
1588
|
+
str = '["Map"';
|
|
1589
|
+
|
|
1590
|
+
for (const [key, value] of thing) {
|
|
1591
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : '...'})`);
|
|
1592
|
+
str += `,${flatten(key)},${flatten(value)}`;
|
|
1593
|
+
keys.pop();
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
str += ']';
|
|
1597
|
+
break;
|
|
1598
|
+
|
|
1599
|
+
case 'Int8Array':
|
|
1600
|
+
case 'Uint8Array':
|
|
1601
|
+
case 'Uint8ClampedArray':
|
|
1602
|
+
case 'Int16Array':
|
|
1603
|
+
case 'Uint16Array':
|
|
1604
|
+
case 'Float16Array':
|
|
1605
|
+
case 'Int32Array':
|
|
1606
|
+
case 'Uint32Array':
|
|
1607
|
+
case 'Float32Array':
|
|
1608
|
+
case 'Float64Array':
|
|
1609
|
+
case 'BigInt64Array':
|
|
1610
|
+
case 'BigUint64Array':
|
|
1611
|
+
case 'DataView': {
|
|
1612
|
+
/** @type {import("./types.js").TypedArray} */
|
|
1613
|
+
const typedArray = thing;
|
|
1614
|
+
str = '["' + type + '",' + flatten(typedArray.buffer);
|
|
1615
|
+
|
|
1616
|
+
// handle subarrays
|
|
1617
|
+
if (typedArray.byteLength !== typedArray.buffer.byteLength) {
|
|
1618
|
+
// to be used with `new TypedArray(buffer, byteOffset, length)`
|
|
1619
|
+
str += `,${typedArray.byteOffset},${typedArray.length}`;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
str += ']';
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
case 'ArrayBuffer': {
|
|
1627
|
+
/** @type {ArrayBuffer} */
|
|
1628
|
+
const arraybuffer = thing;
|
|
1629
|
+
const base64 = encode64(arraybuffer);
|
|
1630
|
+
|
|
1631
|
+
str = `["ArrayBuffer","${base64}"]`;
|
|
1632
|
+
break;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
case 'Temporal.Duration':
|
|
1636
|
+
case 'Temporal.Instant':
|
|
1637
|
+
case 'Temporal.PlainDate':
|
|
1638
|
+
case 'Temporal.PlainTime':
|
|
1639
|
+
case 'Temporal.PlainDateTime':
|
|
1640
|
+
case 'Temporal.PlainMonthDay':
|
|
1641
|
+
case 'Temporal.PlainYearMonth':
|
|
1642
|
+
case 'Temporal.ZonedDateTime':
|
|
1643
|
+
str = `["${type}",${stringify_string(thing.toString())}]`;
|
|
1644
|
+
break;
|
|
1645
|
+
|
|
1646
|
+
default:
|
|
1647
|
+
if (!is_plain_object(thing)) {
|
|
1648
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
1652
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if (Object.getPrototypeOf(thing) === null) {
|
|
1656
|
+
str = '["null"';
|
|
1657
|
+
for (const key of Object.keys(thing)) {
|
|
1658
|
+
if (key === '__proto__') {
|
|
1659
|
+
throw new DevalueError(
|
|
1660
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1661
|
+
keys,
|
|
1662
|
+
thing,
|
|
1663
|
+
value
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
keys.push(stringify_key(key));
|
|
1668
|
+
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
1669
|
+
keys.pop();
|
|
1670
|
+
}
|
|
1671
|
+
str += ']';
|
|
1672
|
+
} else {
|
|
1673
|
+
str = '{';
|
|
1674
|
+
let started = false;
|
|
1675
|
+
for (const key of Object.keys(thing)) {
|
|
1676
|
+
if (key === '__proto__') {
|
|
1677
|
+
throw new DevalueError(
|
|
1678
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1679
|
+
keys,
|
|
1680
|
+
thing,
|
|
1681
|
+
value
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
if (started) str += ',';
|
|
1686
|
+
started = true;
|
|
1687
|
+
keys.push(stringify_key(key));
|
|
1688
|
+
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
|
1689
|
+
keys.pop();
|
|
1690
|
+
}
|
|
1691
|
+
str += '}';
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
stringified[index] = str;
|
|
1697
|
+
return index;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
const index = flatten(value);
|
|
1701
|
+
|
|
1702
|
+
// special case — value is represented as a negative index
|
|
1703
|
+
if (index < 0) return `${index}`;
|
|
1704
|
+
|
|
1705
|
+
return stringified;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* @param {any} thing
|
|
1710
|
+
* @returns {string}
|
|
1711
|
+
*/
|
|
1712
|
+
function stringify_primitive(thing) {
|
|
1713
|
+
const type = typeof thing;
|
|
1714
|
+
if (type === 'string') return stringify_string(thing);
|
|
1715
|
+
if (thing === void 0) return UNDEFINED.toString();
|
|
1716
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
1717
|
+
if (type === 'bigint') return `["BigInt","${thing}"]`;
|
|
1718
|
+
return String(thing);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
const text_encoder = new TextEncoder();
|
|
1722
|
+
|
|
1723
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
1724
|
+
|
|
1725
|
+
|
|
1726
|
+
// TODO 3.0: remove these types as they are not used anymore (we can't remove them yet because that would be a breaking change)
|
|
1727
|
+
/**
|
|
1728
|
+
* @template {number} TNumber
|
|
1729
|
+
* @template {any[]} [TArray=[]]
|
|
1730
|
+
* @typedef {TNumber extends TArray['length'] ? TArray[number] : LessThan<TNumber, [...TArray, TArray['length']]>} LessThan
|
|
1731
|
+
*/
|
|
1732
|
+
|
|
1733
|
+
/**
|
|
1734
|
+
* @template {number} TStart
|
|
1735
|
+
* @template {number} TEnd
|
|
1736
|
+
* @typedef {Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>} NumericRange
|
|
1737
|
+
*/
|
|
1738
|
+
|
|
1739
|
+
// Keep the status codes as `number` because restricting to certain numbers makes it unnecessarily hard to use compared to the benefits
|
|
1740
|
+
// (we have runtime errors already to check for invalid codes). Also see https://github.com/sveltejs/kit/issues/11780
|
|
1741
|
+
|
|
1742
|
+
// we have to repeat the JSDoc because the display for function overloads is broken
|
|
1743
|
+
// see https://github.com/microsoft/TypeScript/issues/55056
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
1747
|
+
* When called during request handling, this will cause SvelteKit to
|
|
1748
|
+
* return an error response without invoking `handleError`.
|
|
1749
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
1750
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1751
|
+
* @param {App.Error} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1752
|
+
* @overload
|
|
1753
|
+
* @param {number} status
|
|
1754
|
+
* @param {App.Error} body
|
|
1755
|
+
* @return {never}
|
|
1756
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
1757
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
1758
|
+
*/
|
|
1759
|
+
/**
|
|
1760
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
1761
|
+
* When called during request handling, this will cause SvelteKit to
|
|
1762
|
+
* return an error response without invoking `handleError`.
|
|
1763
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
1764
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1765
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body] An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1766
|
+
* @overload
|
|
1767
|
+
* @param {number} status
|
|
1768
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body]
|
|
1769
|
+
* @return {never}
|
|
1770
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
1771
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
1772
|
+
*/
|
|
1773
|
+
/**
|
|
1774
|
+
* Throws an error with a HTTP status code and an optional message.
|
|
1775
|
+
* When called during request handling, this will cause SvelteKit to
|
|
1776
|
+
* return an error response without invoking `handleError`.
|
|
1777
|
+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
|
|
1778
|
+
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
1779
|
+
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
1780
|
+
* @return {never}
|
|
1781
|
+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
1782
|
+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
1783
|
+
*/
|
|
1784
|
+
function error(status, body) {
|
|
1785
|
+
if ((isNaN(status) || status < 400 || status > 599)) {
|
|
1786
|
+
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
throw new HttpError(status, body);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
* Checks whether this is a redirect thrown by {@link redirect}.
|
|
1794
|
+
* @param {unknown} e The object to check.
|
|
1795
|
+
* @return {e is Redirect}
|
|
1796
|
+
*/
|
|
1797
|
+
function isRedirect(e) {
|
|
1798
|
+
return e instanceof Redirect;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
/**
|
|
1802
|
+
* Create a JSON `Response` object from the supplied data.
|
|
1803
|
+
* @param {any} data The value that will be serialized as JSON.
|
|
1804
|
+
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
|
|
1805
|
+
*/
|
|
1806
|
+
function json(data, init) {
|
|
1807
|
+
// TODO deprecate this in favour of `Response.json` when it's
|
|
1808
|
+
// more widely supported
|
|
1809
|
+
const body = JSON.stringify(data);
|
|
1810
|
+
|
|
1811
|
+
// we can't just do `text(JSON.stringify(data), init)` because
|
|
1812
|
+
// it will set a default `content-type` header. duplicated code
|
|
1813
|
+
// means less duplicated work
|
|
1814
|
+
const headers = new Headers(init?.headers);
|
|
1815
|
+
if (!headers.has('content-length')) {
|
|
1816
|
+
headers.set('content-length', text_encoder.encode(body).byteLength.toString());
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
if (!headers.has('content-type')) {
|
|
1820
|
+
headers.set('content-type', 'application/json');
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
return new Response(body, {
|
|
1824
|
+
...init,
|
|
1825
|
+
headers
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Create a `Response` object from the supplied body.
|
|
1831
|
+
* @param {string} body The value that will be used as-is.
|
|
1832
|
+
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
|
|
1833
|
+
*/
|
|
1834
|
+
function text(body, init) {
|
|
1835
|
+
const headers = new Headers(init?.headers);
|
|
1836
|
+
if (!headers.has('content-length')) {
|
|
1837
|
+
const encoded = text_encoder.encode(body);
|
|
1838
|
+
headers.set('content-length', encoded.byteLength.toString());
|
|
1839
|
+
return new Response(encoded, {
|
|
1840
|
+
...init,
|
|
1841
|
+
headers
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
return new Response(body, {
|
|
1846
|
+
...init,
|
|
1847
|
+
headers
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
// eslint-disable-next-line n/prefer-global/process
|
|
1852
|
+
const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
|
|
1853
|
+
|
|
1854
|
+
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
1855
|
+
/** @import { RequestStore } from 'types' */
|
|
1856
|
+
/** @import { AsyncLocalStorage } from 'node:async_hooks' */
|
|
1857
|
+
|
|
1858
|
+
|
|
1859
|
+
/** @type {RequestStore | null} */
|
|
1860
|
+
let sync_store = null;
|
|
1861
|
+
|
|
1862
|
+
/** @type {AsyncLocalStorage<RequestStore | null> | null} */
|
|
1863
|
+
let als;
|
|
1864
|
+
|
|
1865
|
+
import('node:async_hooks')
|
|
1866
|
+
.then((hooks) => (als = new hooks.AsyncLocalStorage()))
|
|
1867
|
+
.catch(() => {
|
|
1868
|
+
// can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
|
|
1869
|
+
// this isn't behind `supports` because it's basically just StackBlitz (i.e.
|
|
1870
|
+
// in-browser usage) that doesn't support it AFAICT
|
|
1871
|
+
});
|
|
1872
|
+
|
|
1873
|
+
/**
|
|
1874
|
+
* @template T
|
|
1875
|
+
* @param {RequestStore | null} store
|
|
1876
|
+
* @param {() => T} fn
|
|
1877
|
+
*/
|
|
1878
|
+
function with_request_store(store, fn) {
|
|
1879
|
+
try {
|
|
1880
|
+
sync_store = store;
|
|
1881
|
+
return als ? als.run(store, fn) : fn();
|
|
1882
|
+
} finally {
|
|
1883
|
+
// Since AsyncLocalStorage is not working in webcontainers, we don't reset `sync_store`
|
|
1884
|
+
// and handle only one request at a time in `src/runtime/server/index.js`.
|
|
1885
|
+
if (!IN_WEBCONTAINER) {
|
|
1886
|
+
sync_store = null;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* @template {{ tracing: { enabled: boolean, root: import('@opentelemetry/api').Span, current: import('@opentelemetry/api').Span } }} T
|
|
1893
|
+
* @param {T} event_like
|
|
1894
|
+
* @param {import('@opentelemetry/api').Span} current
|
|
1895
|
+
* @returns {T}
|
|
1896
|
+
*/
|
|
1897
|
+
function merge_tracing(event_like, current) {
|
|
1898
|
+
return {
|
|
1899
|
+
...event_like,
|
|
1900
|
+
tracing: {
|
|
1901
|
+
...event_like.tracing,
|
|
1902
|
+
current
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
const SVELTE_KIT_ASSETS = "/_svelte_kit_assets";
|
|
1908
|
+
const ENDPOINT_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
1909
|
+
const PAGE_METHODS = ["GET", "POST", "HEAD"];
|
|
1910
|
+
function noop() {
|
|
1911
|
+
}
|
|
1912
|
+
function once(fn) {
|
|
1913
|
+
let done = false;
|
|
1914
|
+
let result;
|
|
1915
|
+
return () => {
|
|
1916
|
+
if (done) return result;
|
|
1917
|
+
done = true;
|
|
1918
|
+
return result = fn();
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
const decoder = new TextDecoder();
|
|
1922
|
+
function set_nested_value(object, path_string, value) {
|
|
1923
|
+
if (path_string.startsWith("n:")) {
|
|
1924
|
+
path_string = path_string.slice(2);
|
|
1925
|
+
value = value === "" ? void 0 : parseFloat(value);
|
|
1926
|
+
} else if (path_string.startsWith("b:")) {
|
|
1927
|
+
path_string = path_string.slice(2);
|
|
1928
|
+
value = value === "on";
|
|
1929
|
+
}
|
|
1930
|
+
deep_set(object, split_path(path_string), value);
|
|
1931
|
+
}
|
|
1932
|
+
const DELETE_KEY = {};
|
|
1933
|
+
function convert_formdata(data) {
|
|
1934
|
+
const result = {};
|
|
1935
|
+
for (let key of data.keys()) {
|
|
1936
|
+
const is_array = key.endsWith("[]");
|
|
1937
|
+
let values = data.getAll(key);
|
|
1938
|
+
if (is_array) key = key.slice(0, -2);
|
|
1939
|
+
values = values.filter(
|
|
1940
|
+
(entry) => typeof entry === "string" || entry.name !== "" || entry.size > 0
|
|
1941
|
+
);
|
|
1942
|
+
if (values.length === 0 && !is_array) continue;
|
|
1943
|
+
if (key.startsWith("n:")) {
|
|
1944
|
+
key = key.slice(2);
|
|
1945
|
+
values = values.map((v) => v === "" ? void 0 : parseFloat(
|
|
1946
|
+
/** @type {string} */
|
|
1947
|
+
v
|
|
1948
|
+
));
|
|
1949
|
+
} else if (key.startsWith("b:")) {
|
|
1950
|
+
key = key.slice(2);
|
|
1951
|
+
values = values.map((v) => v === "on");
|
|
1952
|
+
}
|
|
1953
|
+
if (values.length > 1 && !is_array) {
|
|
1954
|
+
throw new Error(`Form cannot contain duplicated keys — "${key}" has ${values.length} values`);
|
|
1955
|
+
}
|
|
1956
|
+
set_nested_value(result, key, is_array ? values : values[0]);
|
|
1957
|
+
}
|
|
1958
|
+
return result;
|
|
1959
|
+
}
|
|
1960
|
+
const BINARY_FORM_CONTENT_TYPE = "application/x-sveltekit-formdata";
|
|
1961
|
+
const BINARY_FORM_VERSION = 0;
|
|
1962
|
+
const HEADER_BYTES = 1 + 4 + 2;
|
|
1963
|
+
async function deserialize_binary_form(request) {
|
|
1964
|
+
if (request.headers.get("content-type") !== BINARY_FORM_CONTENT_TYPE) {
|
|
1965
|
+
const form_data = await request.formData();
|
|
1966
|
+
return { data: convert_formdata(form_data), meta: {}, form_data };
|
|
1967
|
+
}
|
|
1968
|
+
if (!request.body) {
|
|
1969
|
+
throw deserialize_error("no body");
|
|
1970
|
+
}
|
|
1971
|
+
const reader = request.body.getReader();
|
|
1972
|
+
const chunks = [];
|
|
1973
|
+
function get_chunk(index) {
|
|
1974
|
+
if (index in chunks) return chunks[index];
|
|
1975
|
+
let i = chunks.length;
|
|
1976
|
+
while (i <= index) {
|
|
1977
|
+
chunks[i] = reader.read().then((chunk) => chunk.value);
|
|
1978
|
+
i++;
|
|
1979
|
+
}
|
|
1980
|
+
return chunks[index];
|
|
1981
|
+
}
|
|
1982
|
+
async function get_buffer(offset, length) {
|
|
1983
|
+
let start_chunk;
|
|
1984
|
+
let chunk_start = 0;
|
|
1985
|
+
let chunk_index;
|
|
1986
|
+
for (chunk_index = 0; ; chunk_index++) {
|
|
1987
|
+
const chunk = await get_chunk(chunk_index);
|
|
1988
|
+
if (!chunk) return null;
|
|
1989
|
+
const chunk_end = chunk_start + chunk.byteLength;
|
|
1990
|
+
if (offset >= chunk_start && offset < chunk_end) {
|
|
1991
|
+
start_chunk = chunk;
|
|
1992
|
+
break;
|
|
1993
|
+
}
|
|
1994
|
+
chunk_start = chunk_end;
|
|
1995
|
+
}
|
|
1996
|
+
if (offset + length <= chunk_start + start_chunk.byteLength) {
|
|
1997
|
+
return start_chunk.subarray(offset - chunk_start, offset + length - chunk_start);
|
|
1998
|
+
}
|
|
1999
|
+
const chunks2 = [start_chunk.subarray(offset - chunk_start)];
|
|
2000
|
+
let cursor = start_chunk.byteLength - offset + chunk_start;
|
|
2001
|
+
while (cursor < length) {
|
|
2002
|
+
chunk_index++;
|
|
2003
|
+
let chunk = await get_chunk(chunk_index);
|
|
2004
|
+
if (!chunk) return null;
|
|
2005
|
+
if (chunk.byteLength > length - cursor) {
|
|
2006
|
+
chunk = chunk.subarray(0, length - cursor);
|
|
2007
|
+
}
|
|
2008
|
+
chunks2.push(chunk);
|
|
2009
|
+
cursor += chunk.byteLength;
|
|
2010
|
+
}
|
|
2011
|
+
const buffer = new Uint8Array(length);
|
|
2012
|
+
cursor = 0;
|
|
2013
|
+
for (const chunk of chunks2) {
|
|
2014
|
+
buffer.set(chunk, cursor);
|
|
2015
|
+
cursor += chunk.byteLength;
|
|
2016
|
+
}
|
|
2017
|
+
return buffer;
|
|
2018
|
+
}
|
|
2019
|
+
const header = await get_buffer(0, HEADER_BYTES);
|
|
2020
|
+
if (!header) throw deserialize_error("too short");
|
|
2021
|
+
if (header[0] !== BINARY_FORM_VERSION) {
|
|
2022
|
+
throw deserialize_error(`got version ${header[0]}, expected version ${BINARY_FORM_VERSION}`);
|
|
2023
|
+
}
|
|
2024
|
+
const header_view = new DataView(header.buffer, header.byteOffset, header.byteLength);
|
|
2025
|
+
const data_length = header_view.getUint32(1, true);
|
|
2026
|
+
const file_offsets_length = header_view.getUint16(5, true);
|
|
2027
|
+
const data_buffer = await get_buffer(HEADER_BYTES, data_length);
|
|
2028
|
+
if (!data_buffer) throw deserialize_error("data too short");
|
|
2029
|
+
let file_offsets;
|
|
2030
|
+
let files_start_offset;
|
|
2031
|
+
if (file_offsets_length > 0) {
|
|
2032
|
+
const file_offsets_buffer = await get_buffer(HEADER_BYTES + data_length, file_offsets_length);
|
|
2033
|
+
if (!file_offsets_buffer) throw deserialize_error("file offset table too short");
|
|
2034
|
+
const parsed_offsets = JSON.parse(decoder.decode(file_offsets_buffer));
|
|
2035
|
+
if (!Array.isArray(parsed_offsets) || parsed_offsets.some((n) => typeof n !== "number" || !Number.isInteger(n) || n < 0)) {
|
|
2036
|
+
throw deserialize_error("invalid file offset table");
|
|
2037
|
+
}
|
|
2038
|
+
file_offsets = /** @type {Array<number>} */
|
|
2039
|
+
parsed_offsets;
|
|
2040
|
+
files_start_offset = HEADER_BYTES + data_length + file_offsets_length;
|
|
2041
|
+
}
|
|
2042
|
+
const file_spans = [];
|
|
2043
|
+
const [data, meta] = parse(decoder.decode(data_buffer), {
|
|
2044
|
+
File: ([name, type, size, last_modified, index]) => {
|
|
2045
|
+
if (typeof name !== "string" || typeof type !== "string" || typeof size !== "number" || typeof last_modified !== "number" || typeof index !== "number") {
|
|
2046
|
+
throw deserialize_error("invalid file metadata");
|
|
2047
|
+
}
|
|
2048
|
+
let offset = file_offsets[index];
|
|
2049
|
+
if (offset === void 0) {
|
|
2050
|
+
throw deserialize_error("duplicate file offset table index");
|
|
2051
|
+
}
|
|
2052
|
+
file_offsets[index] = void 0;
|
|
2053
|
+
offset += files_start_offset;
|
|
2054
|
+
file_spans.push({ offset, size });
|
|
2055
|
+
return new Proxy(new LazyFile(name, type, size, last_modified, get_chunk, offset), {
|
|
2056
|
+
getPrototypeOf() {
|
|
2057
|
+
return File.prototype;
|
|
2058
|
+
}
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
});
|
|
2062
|
+
file_spans.sort((a, b) => a.offset - b.offset || a.size - b.size);
|
|
2063
|
+
for (let i = 1; i < file_spans.length; i++) {
|
|
2064
|
+
const previous = file_spans[i - 1];
|
|
2065
|
+
const current = file_spans[i];
|
|
2066
|
+
const previous_end = previous.offset + previous.size;
|
|
2067
|
+
if (previous_end < current.offset) {
|
|
2068
|
+
throw deserialize_error("gaps in file data");
|
|
2069
|
+
}
|
|
2070
|
+
if (previous_end > current.offset) {
|
|
2071
|
+
throw deserialize_error("overlapping file data");
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
void (async () => {
|
|
2075
|
+
let has_more = true;
|
|
2076
|
+
while (has_more) {
|
|
2077
|
+
const chunk = await get_chunk(chunks.length);
|
|
2078
|
+
has_more = !!chunk;
|
|
2079
|
+
}
|
|
2080
|
+
})().catch(noop);
|
|
2081
|
+
return { data, meta, form_data: null };
|
|
2082
|
+
}
|
|
2083
|
+
function deserialize_error(message) {
|
|
2084
|
+
return new SvelteKitError(400, "Bad Request", `Could not deserialize binary form: ${message}`);
|
|
2085
|
+
}
|
|
2086
|
+
class LazyFile {
|
|
2087
|
+
/** @type {(index: number) => Promise<Uint8Array<ArrayBuffer> | undefined>} */
|
|
2088
|
+
#get_chunk;
|
|
2089
|
+
/** @type {number} */
|
|
2090
|
+
#offset;
|
|
2091
|
+
/**
|
|
2092
|
+
* @param {string} name
|
|
2093
|
+
* @param {string} type
|
|
2094
|
+
* @param {number} size
|
|
2095
|
+
* @param {number} last_modified
|
|
2096
|
+
* @param {(index: number) => Promise<Uint8Array<ArrayBuffer> | undefined>} get_chunk
|
|
2097
|
+
* @param {number} offset
|
|
2098
|
+
*/
|
|
2099
|
+
constructor(name, type, size, last_modified, get_chunk, offset) {
|
|
2100
|
+
this.name = name;
|
|
2101
|
+
this.type = type;
|
|
2102
|
+
this.size = size;
|
|
2103
|
+
this.lastModified = last_modified;
|
|
2104
|
+
this.webkitRelativePath = "";
|
|
2105
|
+
this.#get_chunk = get_chunk;
|
|
2106
|
+
this.#offset = offset;
|
|
2107
|
+
this.arrayBuffer = this.arrayBuffer.bind(this);
|
|
2108
|
+
this.bytes = this.bytes.bind(this);
|
|
2109
|
+
this.slice = this.slice.bind(this);
|
|
2110
|
+
this.stream = this.stream.bind(this);
|
|
2111
|
+
this.text = this.text.bind(this);
|
|
2112
|
+
}
|
|
2113
|
+
/** @type {ArrayBuffer | undefined} */
|
|
2114
|
+
#buffer;
|
|
2115
|
+
async arrayBuffer() {
|
|
2116
|
+
this.#buffer ??= await new Response(this.stream()).arrayBuffer();
|
|
2117
|
+
return this.#buffer;
|
|
2118
|
+
}
|
|
2119
|
+
async bytes() {
|
|
2120
|
+
return new Uint8Array(await this.arrayBuffer());
|
|
2121
|
+
}
|
|
2122
|
+
/**
|
|
2123
|
+
* @param {number=} start
|
|
2124
|
+
* @param {number=} end
|
|
2125
|
+
* @param {string=} contentType
|
|
2126
|
+
*/
|
|
2127
|
+
slice(start = 0, end = this.size, contentType = this.type) {
|
|
2128
|
+
if (start < 0) {
|
|
2129
|
+
start = Math.max(this.size + start, 0);
|
|
2130
|
+
} else {
|
|
2131
|
+
start = Math.min(start, this.size);
|
|
2132
|
+
}
|
|
2133
|
+
if (end < 0) {
|
|
2134
|
+
end = Math.max(this.size + end, 0);
|
|
2135
|
+
} else {
|
|
2136
|
+
end = Math.min(end, this.size);
|
|
2137
|
+
}
|
|
2138
|
+
const size = Math.max(end - start, 0);
|
|
2139
|
+
const file = new LazyFile(
|
|
2140
|
+
this.name,
|
|
2141
|
+
contentType,
|
|
2142
|
+
size,
|
|
2143
|
+
this.lastModified,
|
|
2144
|
+
this.#get_chunk,
|
|
2145
|
+
this.#offset + start
|
|
2146
|
+
);
|
|
2147
|
+
return file;
|
|
2148
|
+
}
|
|
2149
|
+
stream() {
|
|
2150
|
+
let cursor = 0;
|
|
2151
|
+
let chunk_index = 0;
|
|
2152
|
+
return new ReadableStream({
|
|
2153
|
+
start: async (controller) => {
|
|
2154
|
+
let chunk_start = 0;
|
|
2155
|
+
let start_chunk;
|
|
2156
|
+
for (chunk_index = 0; ; chunk_index++) {
|
|
2157
|
+
const chunk = await this.#get_chunk(chunk_index);
|
|
2158
|
+
if (!chunk) return null;
|
|
2159
|
+
const chunk_end = chunk_start + chunk.byteLength;
|
|
2160
|
+
if (this.#offset >= chunk_start && this.#offset < chunk_end) {
|
|
2161
|
+
start_chunk = chunk;
|
|
2162
|
+
break;
|
|
2163
|
+
}
|
|
2164
|
+
chunk_start = chunk_end;
|
|
2165
|
+
}
|
|
2166
|
+
if (this.#offset + this.size <= chunk_start + start_chunk.byteLength) {
|
|
2167
|
+
controller.enqueue(
|
|
2168
|
+
start_chunk.subarray(this.#offset - chunk_start, this.#offset + this.size - chunk_start)
|
|
2169
|
+
);
|
|
2170
|
+
controller.close();
|
|
2171
|
+
} else {
|
|
2172
|
+
controller.enqueue(start_chunk.subarray(this.#offset - chunk_start));
|
|
2173
|
+
cursor = start_chunk.byteLength - this.#offset + chunk_start;
|
|
2174
|
+
}
|
|
2175
|
+
},
|
|
2176
|
+
pull: async (controller) => {
|
|
2177
|
+
chunk_index++;
|
|
2178
|
+
let chunk = await this.#get_chunk(chunk_index);
|
|
2179
|
+
if (!chunk) {
|
|
2180
|
+
controller.error("incomplete file data");
|
|
2181
|
+
controller.close();
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
if (chunk.byteLength > this.size - cursor) {
|
|
2185
|
+
chunk = chunk.subarray(0, this.size - cursor);
|
|
2186
|
+
}
|
|
2187
|
+
controller.enqueue(chunk);
|
|
2188
|
+
cursor += chunk.byteLength;
|
|
2189
|
+
if (cursor >= this.size) {
|
|
2190
|
+
controller.close();
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
async text() {
|
|
2196
|
+
return decoder.decode(await this.arrayBuffer());
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
const path_regex = /^[a-zA-Z_$]\w*(\.[a-zA-Z_$]\w*|\[\d+\])*$/;
|
|
2200
|
+
function split_path(path) {
|
|
2201
|
+
if (!path_regex.test(path)) {
|
|
2202
|
+
throw new Error(`Invalid path ${path}`);
|
|
2203
|
+
}
|
|
2204
|
+
return path.split(/\.|\[|\]/).filter(Boolean);
|
|
2205
|
+
}
|
|
2206
|
+
function check_prototype_pollution(key) {
|
|
2207
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
2208
|
+
throw new Error(
|
|
2209
|
+
`Invalid key "${key}"`
|
|
2210
|
+
);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
function deep_set(object, keys, value) {
|
|
2214
|
+
let current = object;
|
|
2215
|
+
for (let i = 0; i < keys.length - 1; i += 1) {
|
|
2216
|
+
const key = keys[i];
|
|
2217
|
+
check_prototype_pollution(key);
|
|
2218
|
+
const is_array = /^\d+$/.test(keys[i + 1]);
|
|
2219
|
+
const inner = Object.hasOwn(current, key) ? current[key] : void 0;
|
|
2220
|
+
const exists = inner != null;
|
|
2221
|
+
if (exists && is_array !== Array.isArray(inner)) {
|
|
2222
|
+
throw new Error(`Invalid array key ${keys[i + 1]}`);
|
|
2223
|
+
}
|
|
2224
|
+
if (!exists) {
|
|
2225
|
+
if (value === DELETE_KEY) {
|
|
2226
|
+
return;
|
|
2227
|
+
}
|
|
2228
|
+
current[key] = is_array ? [] : {};
|
|
2229
|
+
}
|
|
2230
|
+
current = current[key];
|
|
2231
|
+
}
|
|
2232
|
+
const final_key = keys[keys.length - 1];
|
|
2233
|
+
check_prototype_pollution(final_key);
|
|
2234
|
+
if (value === DELETE_KEY) {
|
|
2235
|
+
delete current[final_key];
|
|
2236
|
+
} else {
|
|
2237
|
+
current[final_key] = value;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
const INVALIDATED_PARAM = "x-sveltekit-invalidated";
|
|
2241
|
+
const TRAILING_SLASH_PARAM = "x-sveltekit-trailing-slash";
|
|
2242
|
+
function stringify(data, transport) {
|
|
2243
|
+
const encoders = Object.fromEntries(Object.entries(transport).map(([k, v]) => [k, v.encode]));
|
|
2244
|
+
return stringify$1(data, encoders);
|
|
2245
|
+
}
|
|
2246
|
+
const remote_object = "__skrao";
|
|
2247
|
+
const remote_map = "__skram";
|
|
2248
|
+
const remote_set = "__skras";
|
|
2249
|
+
const remote_file = "__skraf";
|
|
2250
|
+
function create_remote_arg_revivers(transport) {
|
|
2251
|
+
const remote_fns_revivers = {
|
|
2252
|
+
/** @type {(value: unknown) => unknown} */
|
|
2253
|
+
[remote_object]: (value) => value,
|
|
2254
|
+
/** @type {(value: unknown) => Map<unknown, unknown>} */
|
|
2255
|
+
[remote_map]: (value) => {
|
|
2256
|
+
if (!Array.isArray(value)) {
|
|
2257
|
+
throw new Error("Invalid data for Map reviver");
|
|
2258
|
+
}
|
|
2259
|
+
const map = /* @__PURE__ */ new Map();
|
|
2260
|
+
for (const item of value) {
|
|
2261
|
+
if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== "string" || typeof item[1] !== "string") {
|
|
2262
|
+
throw new Error("Invalid data for Map reviver");
|
|
2263
|
+
}
|
|
2264
|
+
const [key, val] = item;
|
|
2265
|
+
map.set(parse$1(key), parse$1(val));
|
|
2266
|
+
}
|
|
2267
|
+
return map;
|
|
2268
|
+
},
|
|
2269
|
+
/** @type {(value: unknown) => Set<unknown>} */
|
|
2270
|
+
[remote_set]: (value) => {
|
|
2271
|
+
if (!Array.isArray(value)) {
|
|
2272
|
+
throw new Error("Invalid data for Set reviver");
|
|
2273
|
+
}
|
|
2274
|
+
const set = /* @__PURE__ */ new Set();
|
|
2275
|
+
for (const item of value) {
|
|
2276
|
+
if (typeof item !== "string") {
|
|
2277
|
+
throw new Error("Invalid data for Set reviver");
|
|
2278
|
+
}
|
|
2279
|
+
set.add(parse$1(item));
|
|
2280
|
+
}
|
|
2281
|
+
return set;
|
|
2282
|
+
},
|
|
2283
|
+
/** @type {(value: any) => File} */
|
|
2284
|
+
[remote_file]: (value) => {
|
|
2285
|
+
if (!value || typeof value !== "object" || typeof value.name !== "string" || typeof value.type !== "string" || typeof value.size !== "number" || typeof value.lastModified !== "number" || !(value.data instanceof ArrayBuffer)) {
|
|
2286
|
+
throw new Error("Invalid data for File reviver");
|
|
2287
|
+
}
|
|
2288
|
+
const { data, name, ...meta } = value;
|
|
2289
|
+
return new File([data], name, meta);
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
const user_revivers = Object.fromEntries(
|
|
2293
|
+
Object.entries(transport).map(([k, v]) => [k, v.decode])
|
|
2294
|
+
);
|
|
2295
|
+
const all_revivers = { ...user_revivers, ...remote_fns_revivers };
|
|
2296
|
+
const parse$1 = (data) => parse(data, all_revivers);
|
|
2297
|
+
return all_revivers;
|
|
2298
|
+
}
|
|
2299
|
+
function parse_remote_arg(string, transport) {
|
|
2300
|
+
if (!string) return void 0;
|
|
2301
|
+
const json_string = new TextDecoder().decode(
|
|
2302
|
+
// no need to add back `=` characters, atob can handle it
|
|
2303
|
+
base64_decode(string.replaceAll("-", "+").replaceAll("_", "/"))
|
|
2304
|
+
);
|
|
2305
|
+
return parse(json_string, create_remote_arg_revivers(transport));
|
|
2306
|
+
}
|
|
2307
|
+
function create_remote_key(id, payload) {
|
|
2308
|
+
return id + "/" + payload;
|
|
2309
|
+
}
|
|
2310
|
+
function split_remote_key(key) {
|
|
2311
|
+
const i = key.lastIndexOf("/");
|
|
2312
|
+
if (i === -1) {
|
|
2313
|
+
throw new Error(`Invalid remote key: ${key}`);
|
|
2314
|
+
}
|
|
2315
|
+
return {
|
|
2316
|
+
id: key.slice(0, i),
|
|
2317
|
+
payload: key.slice(i + 1)
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
function coalesce_to_error(err) {
|
|
2321
|
+
return err instanceof Error || err && /** @type {any} */
|
|
2322
|
+
err.name && /** @type {any} */
|
|
2323
|
+
err.message ? (
|
|
2324
|
+
/** @type {Error} */
|
|
2325
|
+
err
|
|
2326
|
+
) : new Error(JSON.stringify(err));
|
|
2327
|
+
}
|
|
2328
|
+
function normalize_error(error) {
|
|
2329
|
+
return (
|
|
2330
|
+
/** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
2331
|
+
error
|
|
2332
|
+
);
|
|
2333
|
+
}
|
|
2334
|
+
function get_status(error) {
|
|
2335
|
+
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
2336
|
+
}
|
|
2337
|
+
function get_message(error) {
|
|
2338
|
+
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
|
2339
|
+
}
|
|
2340
|
+
function negotiate(accept, types) {
|
|
2341
|
+
const parts = [];
|
|
2342
|
+
accept.split(",").forEach((str, i) => {
|
|
2343
|
+
const match = /([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
|
|
2344
|
+
if (match) {
|
|
2345
|
+
const [, type, subtype, q = "1"] = match;
|
|
2346
|
+
parts.push({ type, subtype, q: +q, i });
|
|
2347
|
+
}
|
|
2348
|
+
});
|
|
2349
|
+
parts.sort((a, b) => {
|
|
2350
|
+
if (a.q !== b.q) {
|
|
2351
|
+
return b.q - a.q;
|
|
2352
|
+
}
|
|
2353
|
+
if (a.subtype === "*" !== (b.subtype === "*")) {
|
|
2354
|
+
return a.subtype === "*" ? 1 : -1;
|
|
2355
|
+
}
|
|
2356
|
+
if (a.type === "*" !== (b.type === "*")) {
|
|
2357
|
+
return a.type === "*" ? 1 : -1;
|
|
2358
|
+
}
|
|
2359
|
+
return a.i - b.i;
|
|
2360
|
+
});
|
|
2361
|
+
let accepted;
|
|
2362
|
+
let min_priority = Infinity;
|
|
2363
|
+
for (const mimetype of types) {
|
|
2364
|
+
const [type, subtype] = mimetype.split("/");
|
|
2365
|
+
const priority = parts.findIndex(
|
|
2366
|
+
(part) => (part.type === type || part.type === "*") && (part.subtype === subtype || part.subtype === "*")
|
|
2367
|
+
);
|
|
2368
|
+
if (priority !== -1 && priority < min_priority) {
|
|
2369
|
+
accepted = mimetype;
|
|
2370
|
+
min_priority = priority;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
return accepted;
|
|
2374
|
+
}
|
|
2375
|
+
function get_set_cookies(headers) {
|
|
2376
|
+
if (typeof headers.getSetCookie === "function") {
|
|
2377
|
+
return headers.getSetCookie();
|
|
2378
|
+
}
|
|
2379
|
+
const set_cookie = headers.get("set-cookie");
|
|
2380
|
+
return set_cookie ? splitCookiesString(set_cookie) : [];
|
|
2381
|
+
}
|
|
2382
|
+
function is_content_type(request, ...types) {
|
|
2383
|
+
const type = request.headers.get("content-type")?.split(";", 1)[0].trim() ?? "";
|
|
2384
|
+
return types.includes(type.toLowerCase());
|
|
2385
|
+
}
|
|
2386
|
+
function is_form_content_type(request) {
|
|
2387
|
+
return is_content_type(
|
|
2388
|
+
request,
|
|
2389
|
+
"application/x-www-form-urlencoded",
|
|
2390
|
+
"multipart/form-data",
|
|
2391
|
+
"text/plain",
|
|
2392
|
+
BINARY_FORM_CONTENT_TYPE
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
const escape_html_attr_dict = {
|
|
2396
|
+
"&": "&",
|
|
2397
|
+
'"': """
|
|
2398
|
+
// Svelte also escapes < because the escape function could be called inside a `noscript` there
|
|
2399
|
+
// https://github.com/sveltejs/svelte/security/advisories/GHSA-8266-84wp-wv5c
|
|
2400
|
+
// However, that doesn't apply in SvelteKit
|
|
2401
|
+
};
|
|
2402
|
+
const escape_html_dict = {
|
|
2403
|
+
"&": "&",
|
|
2404
|
+
"<": "<"
|
|
2405
|
+
};
|
|
2406
|
+
const surrogates = (
|
|
2407
|
+
// high surrogate without paired low surrogate
|
|
2408
|
+
"[\\ud800-\\udbff](?![\\udc00-\\udfff])|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\udc00-\\udfff]"
|
|
2409
|
+
);
|
|
2410
|
+
const escape_html_attr_regex = new RegExp(
|
|
2411
|
+
`[${Object.keys(escape_html_attr_dict).join("")}]|` + surrogates,
|
|
2412
|
+
"g"
|
|
2413
|
+
);
|
|
2414
|
+
const escape_html_regex = new RegExp(
|
|
2415
|
+
`[${Object.keys(escape_html_dict).join("")}]|` + surrogates,
|
|
2416
|
+
"g"
|
|
2417
|
+
);
|
|
2418
|
+
function escape_html(str, is_attr) {
|
|
2419
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
2420
|
+
const escaped_str = str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => {
|
|
2421
|
+
if (match.length === 2) {
|
|
2422
|
+
return match;
|
|
2423
|
+
}
|
|
2424
|
+
return dict[match] ?? `&#${match.charCodeAt(0)};`;
|
|
2425
|
+
});
|
|
2426
|
+
return escaped_str;
|
|
2427
|
+
}
|
|
2428
|
+
function method_not_allowed(mod, method) {
|
|
2429
|
+
return text(`${method} method not allowed`, {
|
|
2430
|
+
status: 405,
|
|
2431
|
+
headers: {
|
|
2432
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
2433
|
+
// "The server must generate an Allow header field in a 405 status code response"
|
|
2434
|
+
allow: allowed_methods(mod).join(", ")
|
|
2435
|
+
}
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
function allowed_methods(mod) {
|
|
2439
|
+
const allowed = ENDPOINT_METHODS.filter((method) => method in mod);
|
|
2440
|
+
if ("GET" in mod && !("HEAD" in mod)) {
|
|
2441
|
+
allowed.push("HEAD");
|
|
2442
|
+
}
|
|
2443
|
+
return allowed;
|
|
2444
|
+
}
|
|
2445
|
+
function get_global_name(options) {
|
|
2446
|
+
return `__sveltekit_${options.version_hash}`;
|
|
2447
|
+
}
|
|
2448
|
+
function static_error_page(options, status, message) {
|
|
2449
|
+
let page = options.templates.error({ status, message: escape_html(message) });
|
|
2450
|
+
return text(page, {
|
|
2451
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
2452
|
+
status
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
async function handle_fatal_error(event, state, options, error) {
|
|
2456
|
+
error = error instanceof HttpError ? error : coalesce_to_error(error);
|
|
2457
|
+
const status = get_status(error);
|
|
2458
|
+
const body = await handle_error_and_jsonify(event, state, options, error);
|
|
2459
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", [
|
|
2460
|
+
"application/json",
|
|
2461
|
+
"text/html"
|
|
2462
|
+
]);
|
|
2463
|
+
if (event.isDataRequest || type === "application/json") {
|
|
2464
|
+
return json(body, {
|
|
2465
|
+
status
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
return static_error_page(options, status, body.message);
|
|
2469
|
+
}
|
|
2470
|
+
async function handle_error_and_jsonify(event, state, options, error) {
|
|
2471
|
+
if (error instanceof HttpError) {
|
|
2472
|
+
return { message: "Unknown Error", ...error.body };
|
|
2473
|
+
}
|
|
2474
|
+
const status = get_status(error);
|
|
2475
|
+
const message = get_message(error);
|
|
2476
|
+
return await with_request_store(
|
|
2477
|
+
{ event, state },
|
|
2478
|
+
() => options.hooks.handleError({ error, event, status, message })
|
|
2479
|
+
) ?? { message };
|
|
2480
|
+
}
|
|
2481
|
+
function redirect_response(status, location) {
|
|
2482
|
+
const response = new Response(void 0, {
|
|
2483
|
+
status,
|
|
2484
|
+
headers: { location }
|
|
2485
|
+
});
|
|
2486
|
+
return response;
|
|
2487
|
+
}
|
|
2488
|
+
function clarify_devalue_error(event, error) {
|
|
2489
|
+
if (error.path) {
|
|
2490
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error.message} (${error.path}). If you need to serialize/deserialize custom types, use transport hooks: https://svelte.dev/docs/kit/hooks#Universal-hooks-transport.`;
|
|
2491
|
+
}
|
|
2492
|
+
if (error.path === "") {
|
|
2493
|
+
return `Data returned from \`load\` while rendering ${event.route.id} is not a plain object`;
|
|
2494
|
+
}
|
|
2495
|
+
return error.message;
|
|
2496
|
+
}
|
|
2497
|
+
function serialize_uses(node) {
|
|
2498
|
+
const uses = {};
|
|
2499
|
+
if (node.uses && node.uses.dependencies.size > 0) {
|
|
2500
|
+
uses.dependencies = Array.from(node.uses.dependencies);
|
|
2501
|
+
}
|
|
2502
|
+
if (node.uses && node.uses.search_params.size > 0) {
|
|
2503
|
+
uses.search_params = Array.from(node.uses.search_params);
|
|
2504
|
+
}
|
|
2505
|
+
if (node.uses && node.uses.params.size > 0) {
|
|
2506
|
+
uses.params = Array.from(node.uses.params);
|
|
2507
|
+
}
|
|
2508
|
+
if (node.uses?.parent) uses.parent = 1;
|
|
2509
|
+
if (node.uses?.route) uses.route = 1;
|
|
2510
|
+
if (node.uses?.url) uses.url = 1;
|
|
2511
|
+
return uses;
|
|
2512
|
+
}
|
|
2513
|
+
function has_prerendered_path(manifest, pathname) {
|
|
2514
|
+
return manifest._.prerendered_routes.has(pathname) || pathname.at(-1) === "/" && manifest._.prerendered_routes.has(pathname.slice(0, -1));
|
|
2515
|
+
}
|
|
2516
|
+
function format_server_error(status, error, event) {
|
|
2517
|
+
const formatted_text = `
|
|
2518
|
+
\x1B[1;31m[${status}] ${event.request.method} ${event.url.pathname}\x1B[0m`;
|
|
2519
|
+
if (status === 404) {
|
|
2520
|
+
return formatted_text;
|
|
2521
|
+
}
|
|
2522
|
+
return `${formatted_text}
|
|
2523
|
+
${error.stack}`;
|
|
2524
|
+
}
|
|
2525
|
+
function get_node_type(node_id) {
|
|
2526
|
+
const parts = node_id?.split("/");
|
|
2527
|
+
const filename = parts?.at(-1);
|
|
2528
|
+
if (!filename) return "unknown";
|
|
2529
|
+
const dot_parts = filename.split(".");
|
|
2530
|
+
return dot_parts.slice(0, -1).join(".");
|
|
2531
|
+
}
|
|
2532
|
+
function create_replacer(transport) {
|
|
2533
|
+
const replacer = (thing) => {
|
|
2534
|
+
for (const key in transport) {
|
|
2535
|
+
const encoded = transport[key].encode(thing);
|
|
2536
|
+
if (encoded) {
|
|
2537
|
+
return `app.decode('${key}', ${uneval(encoded, replacer)})`;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
return replacer;
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
export { escape_html as A, create_remote_key as B, error as C, parse_remote_arg as D, ENDPOINT_METHODS as E, deserialize_binary_form as F, stringify as G, HttpError as H, INVALIDATED_PARAM as I, stringify$1 as J, ActionFailure as K, split_remote_key as L, SVELTE_KIT_ASSETS as M, splitCookiesString as N, PAGE_METHODS as P, Redirect as R, SvelteKitError as S, TRAILING_SLASH_PARAM as T, handle_fatal_error as a, negotiate as b, method_not_allowed as c, handle_error_and_jsonify as d, get_status as e, format_server_error as f, get_set_cookies as g, has_prerendered_path as h, is_form_content_type as i, json as j, get_global_name as k, create_replacer as l, merge_tracing as m, noop as n, serialize_uses as o, parseString as p, clarify_devalue_error as q, redirect_response as r, static_error_page as s, text as t, uneval as u, once as v, with_request_store as w, normalize_error as x, get_node_type as y, isRedirect as z };
|
|
2545
|
+
//# sourceMappingURL=utils.js-C_3_iViC.js.map
|