@aopslabs/aops-server 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/THIRD_PARTY_NOTICES +88 -10
- package/THIRD_PARTY_NOTICES.inventory.json +53 -15
- package/build/client/_app/immutable/chunks/DfJYK3Wh.js +1 -0
- package/build/client/_app/immutable/entry/{app.DyrORum_.js → app.B4DZH0Dz.js} +2 -2
- package/build/client/_app/immutable/entry/start.Ccnf0Qxp.js +1 -0
- package/build/client/_app/immutable/nodes/{1.DM-iOsKD.js → 1.FCISkwbh.js} +1 -1
- package/build/client/_app/version.json +1 -1
- package/build/handler.js +3 -3
- package/build/index.js +3 -3
- package/build/server/chunks/{1-CbIMYd7N.js → 1-ocYFK-Eh.js} +2 -2
- package/build/server/chunks/{_server.ts-BWMQcP-R.js → _server.ts-8ddxpKwo.js} +1 -1
- package/build/server/chunks/{_server.ts-P-bj5Kfv.js → _server.ts-BTCau5Qo.js} +1 -1
- package/build/server/chunks/{_server.ts-C1zRNRcN.js → _server.ts-BTPwnDzW.js} +1 -1
- package/build/server/chunks/{_server.ts-BUI8oOpK.js → _server.ts-BcAX_nZO.js} +1 -1
- package/build/server/chunks/{_server.ts-CX96Yo6-.js → _server.ts-BxY5vQr8.js} +1 -1
- package/build/server/chunks/{_server.ts-BrEAWHDb.js → _server.ts-CH2eRv7y.js} +1 -1
- package/build/server/chunks/{_server.ts-D7mxMg8q.js → _server.ts-CHzmD_jo.js} +1 -1
- package/build/server/chunks/{_server.ts-DbPb54XR.js → _server.ts-D6VCtEo3.js} +1 -1
- package/build/server/chunks/{_server.ts-ClhXKSU-.js → _server.ts-D82k__aK.js} +1 -1
- package/build/server/chunks/{_server.ts-p6Wxv_wG.js → _server.ts-D9O8VBl2.js} +1 -1
- package/build/server/chunks/{_server.ts-CQ436Lhs.js → _server.ts-DFAJmU0m.js} +1 -1
- package/build/server/chunks/{_server.ts-DHaqrCbN.js → _server.ts-DSIC4IRw.js} +1 -1
- package/build/server/chunks/{_server.ts-5jTLRkY0.js → _server.ts-DSTj8HQv.js} +1 -1
- package/build/server/chunks/{_server.ts-6MVYw3sO.js → _server.ts-DTn_9fwd.js} +1 -1
- package/build/server/chunks/{_server.ts-BF5YsxES.js → _server.ts-DUnNnYvH.js} +1 -1
- package/build/server/chunks/{_server.ts-B7LBExsI.js → _server.ts-DbOhLbKc.js} +1 -1
- package/build/server/chunks/{_server.ts-CkYsJYFX.js → _server.ts-Dq7UZyiB.js} +1 -1
- package/build/server/chunks/{_server.ts-Bd_TqS-J.js → _server.ts-raQSF1L0.js} +1 -1
- package/build/server/chunks/{error.svelte-BTdVSWca.js → error.svelte-D5SYTGsr.js} +1 -1
- package/build/server/chunks/{handler-VLy1sI9x.js → handler-CeuuYN3g.js} +2 -2
- package/build/server/chunks/{hooks.server-Zx-k_ERd.js → hooks.server-BGc6cSdu.js} +1 -1
- package/build/server/chunks/{index.js-CWgll4BT.js → index.js-Ciyn4OZi.js} +1361 -2237
- package/build/server/chunks/{manifest.js-C2lkmNzz.js → manifest.js-4ARh-5fa.js} +20 -20
- package/npm-shrinkwrap.json +51 -12
- package/package.json +4 -4
- package/runtime-closure.package.json +38 -14
- package/build/client/_app/immutable/chunks/B88gKiyt.js +0 -1
- package/build/client/_app/immutable/entry/start.BCM14rdL.js +0 -1
|
@@ -75,6 +75,42 @@ class ActionFailure {
|
|
|
75
75
|
|
|
76
76
|
const text_encoder$2 = new TextEncoder();
|
|
77
77
|
|
|
78
|
+
const text_encoder$1 = new TextEncoder();
|
|
79
|
+
function get_relative_path(from, to) {
|
|
80
|
+
const from_parts = from.split(/[/\\]/);
|
|
81
|
+
const to_parts = to.split(/[/\\]/);
|
|
82
|
+
from_parts.pop();
|
|
83
|
+
while (from_parts[0] === to_parts[0]) {
|
|
84
|
+
from_parts.shift();
|
|
85
|
+
to_parts.shift();
|
|
86
|
+
}
|
|
87
|
+
let i = from_parts.length;
|
|
88
|
+
while (i--) from_parts[i] = "..";
|
|
89
|
+
return from_parts.concat(to_parts).join("/");
|
|
90
|
+
}
|
|
91
|
+
function base64_encode$1(bytes) {
|
|
92
|
+
if (globalThis.Buffer) {
|
|
93
|
+
return globalThis.Buffer.from(bytes).toString("base64");
|
|
94
|
+
}
|
|
95
|
+
let binary = "";
|
|
96
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
97
|
+
binary += String.fromCharCode(bytes[i]);
|
|
98
|
+
}
|
|
99
|
+
return btoa(binary);
|
|
100
|
+
}
|
|
101
|
+
function base64_decode(encoded) {
|
|
102
|
+
if (globalThis.Buffer) {
|
|
103
|
+
const buffer = globalThis.Buffer.from(encoded, "base64");
|
|
104
|
+
return new Uint8Array(buffer);
|
|
105
|
+
}
|
|
106
|
+
const binary = atob(encoded);
|
|
107
|
+
const bytes = new Uint8Array(binary.length);
|
|
108
|
+
for (let i = 0; i < binary.length; i++) {
|
|
109
|
+
bytes[i] = binary.charCodeAt(i);
|
|
110
|
+
}
|
|
111
|
+
return bytes;
|
|
112
|
+
}
|
|
113
|
+
|
|
78
114
|
const UNDEFINED = -1;
|
|
79
115
|
const HOLE = -2;
|
|
80
116
|
const NAN = -3;
|
|
@@ -82,1653 +118,496 @@ const POSITIVE_INFINITY = -4;
|
|
|
82
118
|
const NEGATIVE_INFINITY = -5;
|
|
83
119
|
const NEGATIVE_ZERO = -6;
|
|
84
120
|
const SPARSE = -7;
|
|
85
|
-
|
|
86
|
-
// The largest valid value for a JavaScript array's `length` property,
|
|
87
|
-
// and the largest valid array index (one less than the max length).
|
|
88
121
|
const MAX_ARRAY_LEN = 2 ** 32 - 1;
|
|
89
122
|
const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;
|
|
90
|
-
|
|
91
|
-
/** @type {Record<string, string>} */
|
|
92
123
|
const escaped = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
"<": "\\u003C",
|
|
125
|
+
"\\": "\\\\",
|
|
126
|
+
"\b": "\\b",
|
|
127
|
+
"\f": "\\f",
|
|
128
|
+
"\n": "\\n",
|
|
129
|
+
"\r": "\\r",
|
|
130
|
+
" ": "\\t",
|
|
131
|
+
"\u2028": "\\u2028",
|
|
132
|
+
"\u2029": "\\u2029"
|
|
102
133
|
};
|
|
103
|
-
|
|
104
134
|
class DevalueError extends Error {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
135
|
+
/**
|
|
136
|
+
* @param {string} message
|
|
137
|
+
* @param {string[]} keys
|
|
138
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
139
|
+
* @param {any} [root] - The root value being serialized
|
|
140
|
+
*/
|
|
141
|
+
constructor(message, keys, value, root) {
|
|
142
|
+
super(message);
|
|
143
|
+
this.name = "DevalueError";
|
|
144
|
+
this.path = keys.join("");
|
|
145
|
+
this.value = value;
|
|
146
|
+
this.root = root;
|
|
147
|
+
}
|
|
118
148
|
}
|
|
119
|
-
|
|
120
|
-
/** @param {any} thing */
|
|
121
149
|
function is_primitive(thing) {
|
|
122
|
-
|
|
150
|
+
return thing === null || typeof thing !== "object" && typeof thing !== "function";
|
|
123
151
|
}
|
|
124
|
-
|
|
125
|
-
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype)
|
|
126
|
-
.sort()
|
|
127
|
-
.join('\0');
|
|
128
|
-
|
|
129
|
-
/** @param {any} thing */
|
|
152
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
130
153
|
function is_plain_object(thing) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
proto === Object.prototype ||
|
|
135
|
-
proto === null ||
|
|
136
|
-
Object.getPrototypeOf(proto) === null ||
|
|
137
|
-
Object.getOwnPropertyNames(proto).sort().join('\0') === object_proto_names
|
|
138
|
-
);
|
|
154
|
+
const proto = Object.getPrototypeOf(thing);
|
|
155
|
+
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
|
139
156
|
}
|
|
140
|
-
|
|
141
|
-
/** @param {any} thing */
|
|
142
157
|
function get_type(thing) {
|
|
143
|
-
|
|
158
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
144
159
|
}
|
|
145
|
-
|
|
146
|
-
/** @param {string} char */
|
|
147
160
|
function get_escaped_char(char) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
161
|
+
switch (char) {
|
|
162
|
+
case '"':
|
|
163
|
+
return '\\"';
|
|
164
|
+
case "<":
|
|
165
|
+
return "\\u003C";
|
|
166
|
+
case "\\":
|
|
167
|
+
return "\\\\";
|
|
168
|
+
case "\n":
|
|
169
|
+
return "\\n";
|
|
170
|
+
case "\r":
|
|
171
|
+
return "\\r";
|
|
172
|
+
case " ":
|
|
173
|
+
return "\\t";
|
|
174
|
+
case "\b":
|
|
175
|
+
return "\\b";
|
|
176
|
+
case "\f":
|
|
177
|
+
return "\\f";
|
|
178
|
+
case "\u2028":
|
|
179
|
+
return "\\u2028";
|
|
180
|
+
case "\u2029":
|
|
181
|
+
return "\\u2029";
|
|
182
|
+
default:
|
|
183
|
+
return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
|
|
184
|
+
}
|
|
172
185
|
}
|
|
173
|
-
|
|
174
|
-
/** @param {string} str */
|
|
175
186
|
function stringify_string(str) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
187
|
+
let result = "";
|
|
188
|
+
let last_pos = 0;
|
|
189
|
+
const len = str.length;
|
|
190
|
+
for (let i = 0; i < len; i += 1) {
|
|
191
|
+
const char = str[i];
|
|
192
|
+
const replacement = get_escaped_char(char);
|
|
193
|
+
if (replacement) {
|
|
194
|
+
result += str.slice(last_pos, i) + replacement;
|
|
195
|
+
last_pos = i + 1;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
190
199
|
}
|
|
191
|
-
|
|
192
|
-
/** @param {Record<string | symbol, any>} object */
|
|
193
200
|
function enumerable_symbols(object) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
return Object.getOwnPropertySymbols(object).filter(
|
|
202
|
+
(symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable
|
|
203
|
+
);
|
|
197
204
|
}
|
|
198
|
-
|
|
199
205
|
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
200
|
-
|
|
201
|
-
/** @param {string} key */
|
|
202
206
|
function stringify_key(key) {
|
|
203
|
-
|
|
207
|
+
return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
|
|
204
208
|
}
|
|
205
|
-
|
|
206
|
-
/** @param {number} n */
|
|
207
209
|
function is_valid_array_index(n) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
if (!Number.isInteger(n)) return false;
|
|
211
|
+
if (n < 0) return false;
|
|
212
|
+
if (n > MAX_ARRAY_INDEX) return false;
|
|
213
|
+
return true;
|
|
212
214
|
}
|
|
213
|
-
|
|
214
|
-
/** @param {number} n */
|
|
215
215
|
function is_valid_array_len(n) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
if (!Number.isInteger(n)) return false;
|
|
217
|
+
if (n < 0) return false;
|
|
218
|
+
if (n > MAX_ARRAY_LEN) return false;
|
|
219
|
+
return true;
|
|
220
220
|
}
|
|
221
|
-
|
|
222
|
-
/** @param {string} s */
|
|
223
221
|
function is_valid_array_index_string(s) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// the range of valid array indices
|
|
232
|
-
return is_valid_array_index(+s);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Returns the length of the leading run of valid array indices in `keys`.
|
|
237
|
-
* @param {readonly string[]} keys
|
|
238
|
-
*/
|
|
239
|
-
function array_index_cut(keys) {
|
|
240
|
-
for (var i = keys.length - 1; i >= 0; i--) {
|
|
241
|
-
if (is_valid_array_index_string(keys[i])) {
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return i + 1;
|
|
222
|
+
if (s.length === 0) return false;
|
|
223
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false;
|
|
224
|
+
for (let i = 0; i < s.length; i++) {
|
|
225
|
+
const c = s.charCodeAt(i);
|
|
226
|
+
if (c < 48 || c > 57) return false;
|
|
227
|
+
}
|
|
228
|
+
return is_valid_array_index(+s);
|
|
246
229
|
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Finds the populated indices of an array.
|
|
250
|
-
* @param {unknown[]} array
|
|
251
|
-
*/
|
|
252
230
|
function valid_array_indices(array) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
231
|
+
const keys = Object.keys(array);
|
|
232
|
+
for (var i = keys.length - 1; i >= 0; i--) {
|
|
233
|
+
if (is_valid_array_index_string(keys[i])) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
keys.length = i + 1;
|
|
238
|
+
return keys;
|
|
256
239
|
}
|
|
257
|
-
|
|
258
|
-
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
|
|
240
|
+
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
|
|
259
241
|
const unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
260
|
-
const reserved =
|
|
261
|
-
/^(?: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)$/;
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Turn a value into the JavaScript that creates an equivalent value
|
|
265
|
-
* @param {any} value
|
|
266
|
-
* @param {(value: any, uneval: (value: any) => string) => string | void} [replacer]
|
|
267
|
-
*/
|
|
242
|
+
const reserved = /^(?: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)$/;
|
|
268
243
|
function uneval(value, replacer) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
/** @type {string[]} */
|
|
607
|
-
const values = [];
|
|
608
|
-
|
|
609
|
-
// Reconstructions (e.g. `b = new Uint8Array(...)`) reassign a placeholder
|
|
610
|
-
// parameter. They must run before the `statements` that reference them,
|
|
611
|
-
// otherwise those statements capture the placeholder. They only depend on
|
|
612
|
-
// IIFE arguments (never on each other), so emitting them first is safe.
|
|
613
|
-
/** @type {string[]} */
|
|
614
|
-
const reconstructions = [];
|
|
615
|
-
|
|
616
|
-
names.forEach((name, thing) => {
|
|
617
|
-
params.push(name);
|
|
618
|
-
|
|
619
|
-
if (custom.has(thing)) {
|
|
620
|
-
values.push(/** @type {string} */ (custom.get(thing)));
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (is_primitive(thing)) {
|
|
625
|
-
values.push(stringify_primitive$1(thing));
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
const type = get_type(thing);
|
|
630
|
-
|
|
631
|
-
switch (type) {
|
|
632
|
-
case 'Number':
|
|
633
|
-
case 'String':
|
|
634
|
-
case 'Boolean':
|
|
635
|
-
case 'BigInt':
|
|
636
|
-
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
637
|
-
break;
|
|
638
|
-
|
|
639
|
-
case 'RegExp':
|
|
640
|
-
const { source, flags } = thing;
|
|
641
|
-
const regexp = flags
|
|
642
|
-
? `new RegExp(${stringify_string(source)},"${flags}")`
|
|
643
|
-
: `new RegExp(${stringify_string(source)})`;
|
|
644
|
-
values.push(regexp);
|
|
645
|
-
break;
|
|
646
|
-
|
|
647
|
-
case 'Date':
|
|
648
|
-
values.push(`new Date(${thing.getTime()})`);
|
|
649
|
-
break;
|
|
650
|
-
|
|
651
|
-
case 'URL':
|
|
652
|
-
values.push(`new URL(${stringify_string(thing.toString())})`);
|
|
653
|
-
break;
|
|
654
|
-
|
|
655
|
-
case 'URLSearchParams':
|
|
656
|
-
values.push(`new URLSearchParams(${stringify_string(thing.toString())})`);
|
|
657
|
-
break;
|
|
658
|
-
|
|
659
|
-
case 'Array':
|
|
660
|
-
values.push(`Array(${thing.length})`);
|
|
661
|
-
/** @type {any[]} */ (thing).forEach((v, i) => {
|
|
662
|
-
statements.push(`${name}[${i}]=${stringify(v)}`);
|
|
663
|
-
});
|
|
664
|
-
break;
|
|
665
|
-
|
|
666
|
-
case 'Set': {
|
|
667
|
-
values.push(`new Set`);
|
|
668
|
-
const adds = Array.from(thing).map((v) => `.add(${stringify(v)})`);
|
|
669
|
-
// An empty Set is fully built by `new Set`; a chained statement would
|
|
670
|
-
// otherwise be a dangling `name.`.
|
|
671
|
-
if (adds.length > 0) statements.push(name + adds.join(''));
|
|
672
|
-
break;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
case 'Map': {
|
|
676
|
-
values.push(`new Map`);
|
|
677
|
-
const sets = Array.from(thing).map(
|
|
678
|
-
([k, v]) => `.set(${stringify(k)}, ${stringify(v)})`
|
|
679
|
-
);
|
|
680
|
-
if (sets.length > 0) statements.push(name + sets.join(''));
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
case 'Int8Array':
|
|
685
|
-
case 'Uint8Array':
|
|
686
|
-
case 'Uint8ClampedArray':
|
|
687
|
-
case 'Int16Array':
|
|
688
|
-
case 'Uint16Array':
|
|
689
|
-
case 'Float16Array':
|
|
690
|
-
case 'Int32Array':
|
|
691
|
-
case 'Uint32Array':
|
|
692
|
-
case 'Float32Array':
|
|
693
|
-
case 'Float64Array':
|
|
694
|
-
case 'BigInt64Array':
|
|
695
|
-
case 'BigUint64Array': {
|
|
696
|
-
let str = `new ${type}`;
|
|
697
|
-
|
|
698
|
-
if (!names.has(thing.buffer)) {
|
|
699
|
-
str += `([${stringify_typed_array_elements(new thing.constructor(thing.buffer))}])`;
|
|
700
|
-
} else {
|
|
701
|
-
str += `(${stringify(thing.buffer)})`;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// handle subarrays
|
|
705
|
-
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
706
|
-
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
707
|
-
const end = start + thing.length;
|
|
708
|
-
str += `.subarray(${start},${end})`;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
values.push(`{}`);
|
|
712
|
-
reconstructions.push(`${name}=${str}`);
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
case 'DataView': {
|
|
717
|
-
let str = `new DataView`;
|
|
718
|
-
|
|
719
|
-
if (!names.has(thing.buffer)) {
|
|
720
|
-
str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
721
|
-
} else {
|
|
722
|
-
str += `(${stringify(thing.buffer)}`;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// handle subviews
|
|
726
|
-
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
727
|
-
str += `,${thing.byteOffset},${thing.byteLength}`;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
str += ')';
|
|
731
|
-
|
|
732
|
-
values.push(`{}`);
|
|
733
|
-
reconstructions.push(`${name}=${str}`);
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
case 'ArrayBuffer':
|
|
738
|
-
values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`);
|
|
739
|
-
break;
|
|
740
|
-
|
|
741
|
-
case 'Temporal.Duration':
|
|
742
|
-
case 'Temporal.Instant':
|
|
743
|
-
case 'Temporal.PlainDate':
|
|
744
|
-
case 'Temporal.PlainTime':
|
|
745
|
-
case 'Temporal.PlainDateTime':
|
|
746
|
-
case 'Temporal.PlainMonthDay':
|
|
747
|
-
case 'Temporal.PlainYearMonth':
|
|
748
|
-
case 'Temporal.ZonedDateTime':
|
|
749
|
-
values.push(`${type}.from(${stringify_string(thing.toString())})`);
|
|
750
|
-
break;
|
|
751
|
-
|
|
752
|
-
default:
|
|
753
|
-
values.push(Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}');
|
|
754
|
-
Object.keys(thing).forEach((key) => {
|
|
755
|
-
statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
});
|
|
759
|
-
|
|
760
|
-
statements.push(`return ${str}`);
|
|
761
|
-
|
|
762
|
-
const body = [...reconstructions, ...statements].join(';');
|
|
763
|
-
return `(function(${params.join(',')}){${body}}(${values.join(',')}))`;
|
|
764
|
-
} else {
|
|
765
|
-
return str;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Serialize the elements of a typed array as a comma-separated list.
|
|
771
|
-
* `BigInt64Array`/`BigUint64Array` elements are bigints and must be written
|
|
772
|
-
* with an `n` suffix, otherwise the emitted `new BigInt64Array([...])` throws.
|
|
773
|
-
* @param {import('./types.js').TypedArray} array
|
|
774
|
-
*/
|
|
775
|
-
function stringify_typed_array_elements(array) {
|
|
776
|
-
if (array instanceof BigInt64Array || array instanceof BigUint64Array) {
|
|
777
|
-
return Array.from(array, (element) => `${element}n`).join(',');
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
return array.toString();
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
/** @param {number} num */
|
|
784
|
-
function get_name(num) {
|
|
785
|
-
let name = '';
|
|
786
|
-
|
|
787
|
-
do {
|
|
788
|
-
name = chars[num % chars.length] + name;
|
|
789
|
-
num = ~~(num / chars.length) - 1;
|
|
790
|
-
} while (num >= 0);
|
|
791
|
-
|
|
792
|
-
return reserved.test(name) ? `${name}0` : name;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/** @param {string} c */
|
|
796
|
-
function escape_unsafe_char(c) {
|
|
797
|
-
return escaped[c] || c;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
/** @param {string} str */
|
|
801
|
-
function escape_unsafe_chars(str) {
|
|
802
|
-
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
/** @param {string} key */
|
|
806
|
-
function safe_key(key) {
|
|
807
|
-
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
/** @param {string} key */
|
|
811
|
-
function safe_prop(key) {
|
|
812
|
-
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key)
|
|
813
|
-
? `.${key}`
|
|
814
|
-
: `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/** @param {any} thing */
|
|
818
|
-
function stringify_primitive$1(thing) {
|
|
819
|
-
const type = typeof thing;
|
|
820
|
-
if (type === 'string') return stringify_string(thing);
|
|
821
|
-
if (thing === void 0) return 'void 0';
|
|
822
|
-
if (thing === 0 && 1 / thing < 0) return '-0';
|
|
823
|
-
const str = String(thing);
|
|
824
|
-
if (type === 'number') return str.replace(/^(-)?0\./, '$1.');
|
|
825
|
-
if (type === 'bigint') return thing + 'n';
|
|
826
|
-
return str;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
/* Baseline 2025 runtimes */
|
|
830
|
-
|
|
831
|
-
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
832
|
-
function encode_native(array_buffer) {
|
|
833
|
-
return new Uint8Array(array_buffer).toBase64();
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
/** @type {(base64: string) => ArrayBuffer} */
|
|
837
|
-
function decode_native(base64) {
|
|
838
|
-
return Uint8Array.fromBase64(base64).buffer;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
/* Node-compatible runtimes */
|
|
842
|
-
|
|
843
|
-
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
844
|
-
function encode_buffer(array_buffer) {
|
|
845
|
-
return Buffer.from(array_buffer).toString('base64');
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
/** @type {(base64: string) => ArrayBuffer} */
|
|
849
|
-
function decode_buffer(base64) {
|
|
850
|
-
return Uint8Array.from(Buffer.from(base64, 'base64')).buffer;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
/* Legacy runtimes */
|
|
854
|
-
|
|
855
|
-
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
856
|
-
function encode_legacy(array_buffer) {
|
|
857
|
-
const array = new Uint8Array(array_buffer);
|
|
858
|
-
let binary = '';
|
|
859
|
-
|
|
860
|
-
// the maximum number of arguments to String.fromCharCode.apply
|
|
861
|
-
// should be around 0xFFFF in modern engines
|
|
862
|
-
const chunk_size = 0x8000;
|
|
863
|
-
for (let i = 0; i < array.length; i += chunk_size) {
|
|
864
|
-
const chunk = array.subarray(i, i + chunk_size);
|
|
865
|
-
binary += String.fromCharCode.apply(null, chunk);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
return btoa(binary);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/** @type {(base64: string) => ArrayBuffer} */
|
|
872
|
-
function decode_legacy(base64) {
|
|
873
|
-
const binary_string = atob(base64);
|
|
874
|
-
const len = binary_string.length;
|
|
875
|
-
const array = new Uint8Array(len);
|
|
876
|
-
|
|
877
|
-
for (let i = 0; i < len; i++) {
|
|
878
|
-
array[i] = binary_string.charCodeAt(i);
|
|
879
|
-
}
|
|
880
|
-
|
|
881
|
-
return array.buffer;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
const native = typeof Uint8Array.fromBase64 === 'function';
|
|
885
|
-
const buffer = typeof process === 'object' && process.versions?.node !== undefined;
|
|
886
|
-
|
|
887
|
-
const encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
888
|
-
const decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* Merges caller-provided operation overrides over the defaults. Iterating the
|
|
892
|
-
* default keys (rather than the override's own keys) means nullish members
|
|
893
|
-
* fall back to the default, and inherited members — e.g. from a class
|
|
894
|
-
* instance — are picked up.
|
|
895
|
-
*
|
|
896
|
-
* @template {Record<string, any>} T
|
|
897
|
-
* @param {T} defaults
|
|
898
|
-
* @param {Partial<T> | undefined} overrides
|
|
899
|
-
* @returns {T}
|
|
900
|
-
*/
|
|
901
|
-
function merge_operations(defaults, overrides) {
|
|
902
|
-
return defaults;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/** @type {{ kind: 'not-plain' }} */
|
|
906
|
-
const NOT_PLAIN = Object.freeze({ kind: 'not-plain' });
|
|
907
|
-
|
|
908
|
-
/** @type {{ kind: 'symbol-keys' }} */
|
|
909
|
-
const SYMBOL_KEYS = Object.freeze({ kind: 'symbol-keys' });
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
* The default implementations of every introspection/extraction operation
|
|
913
|
-
* `stringify` performs on the value being serialized. Each one uses native
|
|
914
|
-
* JavaScript semantics (property access, iteration, prototype methods, etc).
|
|
915
|
-
*
|
|
916
|
-
* Pass overrides via the `operations` option of `stringify`/`stringifyAsync`
|
|
917
|
-
* to customize how values are inspected — e.g. to serialize values without
|
|
918
|
-
* triggering getters, proxy traps, or patched prototype methods, or to
|
|
919
|
-
* serialize values that live in a different JavaScript runtime (a `node:vm`
|
|
920
|
-
* context, a WASM-hosted engine, a remote process) through handle objects.
|
|
921
|
-
*
|
|
922
|
-
* The object is frozen — it is shared by every `stringify` call that does
|
|
923
|
-
* not override a given operation.
|
|
924
|
-
*
|
|
925
|
-
*/
|
|
926
|
-
/** @type {import('./types.js').DefaultStringifyOperations} */
|
|
927
|
-
const stringify_operations = {
|
|
928
|
-
identify: (value) => value,
|
|
929
|
-
|
|
930
|
-
typeOf: (value) => (value === null ? 'null' : typeof value),
|
|
931
|
-
|
|
932
|
-
toPrimitive: (value) => value,
|
|
933
|
-
|
|
934
|
-
tagOf: (value) => get_type(value),
|
|
935
|
-
|
|
936
|
-
isThenable: (value) => typeof value.then === 'function',
|
|
937
|
-
|
|
938
|
-
toPromise: (thenable) => Promise.resolve(thenable),
|
|
939
|
-
|
|
940
|
-
unbox: (boxed) => boxed.valueOf(),
|
|
941
|
-
|
|
942
|
-
toISOString: (date) => (isNaN(date.getDate()) ? '' : date.toISOString()),
|
|
943
|
-
|
|
944
|
-
toStringValue: (value) => value.toString(),
|
|
945
|
-
|
|
946
|
-
regExpInfo: (regexp) => ({ source: regexp.source, flags: regexp.flags }),
|
|
947
|
-
|
|
948
|
-
valuesOf: (set) => set,
|
|
949
|
-
|
|
950
|
-
entriesOf: (map) => map,
|
|
951
|
-
|
|
952
|
-
viewInfo: (view) => ({
|
|
953
|
-
buffer: view.buffer,
|
|
954
|
-
byteOffset: view.byteOffset,
|
|
955
|
-
byteLength: view.byteLength,
|
|
956
|
-
length: view.length,
|
|
957
|
-
bufferByteLength: view.buffer.byteLength
|
|
958
|
-
}),
|
|
959
|
-
|
|
960
|
-
toArrayBuffer: (buffer) => buffer,
|
|
961
|
-
|
|
962
|
-
lengthOf: (array) => array.length,
|
|
963
|
-
|
|
964
|
-
hasOwn: (value, key) => Object.hasOwn(value, key),
|
|
965
|
-
|
|
966
|
-
indicesOf: (array) => valid_array_indices(array),
|
|
967
|
-
|
|
968
|
-
shapeOf: (value) => {
|
|
969
|
-
if (!is_plain_object(value)) return NOT_PLAIN;
|
|
970
|
-
if (enumerable_symbols(value).length > 0) return SYMBOL_KEYS;
|
|
971
|
-
|
|
972
|
-
return {
|
|
973
|
-
kind: Object.getPrototypeOf(value) === null ? 'null-proto' : 'plain',
|
|
974
|
-
keys: Object.keys(value)
|
|
975
|
-
};
|
|
976
|
-
},
|
|
977
|
-
|
|
978
|
-
get: (value, key) => value[key]
|
|
979
|
-
};
|
|
980
|
-
|
|
981
|
-
const default_stringify_operations = Object.freeze(stringify_operations);
|
|
982
|
-
|
|
983
|
-
/**
|
|
984
|
-
* The default implementations of every construction operation `parse` and
|
|
985
|
-
* `unflatten` perform while reviving a value. Each one uses native
|
|
986
|
-
* JavaScript semantics (built-in constructors, property assignment, etc).
|
|
987
|
-
*
|
|
988
|
-
* Pass overrides via the `operations` option of `parse`/`unflatten` to
|
|
989
|
-
* customize how values are built — e.g. to construct them from the
|
|
990
|
-
* intrinsics of a different realm (a `node:vm` context), or to build up
|
|
991
|
-
* values inside another JavaScript runtime (a WASM-hosted engine, a remote
|
|
992
|
-
* process) through handle objects.
|
|
993
|
-
*
|
|
994
|
-
* The object is frozen — it is shared by every `parse` call that does not
|
|
995
|
-
* override a given operation.
|
|
996
|
-
*
|
|
997
|
-
*/
|
|
998
|
-
/** @type {import('./types.js').DefaultParseOperations} */
|
|
999
|
-
const parse_operations = {
|
|
1000
|
-
fromPrimitive: (primitive) => primitive,
|
|
1001
|
-
|
|
1002
|
-
fromISOString: (iso) => new Date(iso),
|
|
1003
|
-
|
|
1004
|
-
fromStringValue: (tag, text) => {
|
|
1005
|
-
if (tag === 'URL') return new URL(text);
|
|
1006
|
-
if (tag === 'URLSearchParams') return new URLSearchParams(text);
|
|
1007
|
-
// 'Temporal.Instant', 'Temporal.PlainDate', ...
|
|
1008
|
-
// @ts-expect-error TS doesn't know about Temporal yet
|
|
1009
|
-
return Temporal[tag.slice(9)].from(text);
|
|
1010
|
-
},
|
|
1011
|
-
|
|
1012
|
-
fromArrayBuffer: (buffer) => buffer,
|
|
1013
|
-
|
|
1014
|
-
fromRegExpInfo: (source, flags) => new RegExp(source, flags),
|
|
1015
|
-
|
|
1016
|
-
fromViewInfo: (tag, buffer, byteOffset, length) => {
|
|
1017
|
-
const Constructor = /** @type {any} */ (globalThis)[tag];
|
|
1018
|
-
return byteOffset !== undefined
|
|
1019
|
-
? new Constructor(buffer, byteOffset, length)
|
|
1020
|
-
: new Constructor(buffer);
|
|
1021
|
-
},
|
|
1022
|
-
|
|
1023
|
-
box: (value) => Object(value),
|
|
1024
|
-
|
|
1025
|
-
createArray: (length) => new Array(length),
|
|
1026
|
-
|
|
1027
|
-
createSparseArray: (length) => {
|
|
1028
|
-
/** @type {any[]} */
|
|
1029
|
-
const array = [];
|
|
1030
|
-
|
|
1031
|
-
// Setting `array.length = length` (or equivalently calling
|
|
1032
|
-
// `new Array(length)`) on an untrusted length is a DoS vector: V8
|
|
1033
|
-
// eagerly allocates a contiguous backing store for array lengths below
|
|
1034
|
-
// ~10^8, so a small payload with a huge declared length can force
|
|
1035
|
-
// arbitrary memory allocation. Touching the largest-possible index
|
|
1036
|
-
// first forces V8 into dictionary-elements mode, where `length` is
|
|
1037
|
-
// just a number and no contiguous allocation occurs.
|
|
1038
|
-
array[MAX_ARRAY_INDEX] = undefined;
|
|
1039
|
-
delete array[MAX_ARRAY_INDEX];
|
|
1040
|
-
array.length = length;
|
|
1041
|
-
|
|
1042
|
-
return array;
|
|
1043
|
-
},
|
|
1044
|
-
|
|
1045
|
-
createObject: () => ({}),
|
|
1046
|
-
|
|
1047
|
-
createNullPrototypeObject: () => Object.create(null),
|
|
1048
|
-
|
|
1049
|
-
createSet: () => new Set(),
|
|
1050
|
-
|
|
1051
|
-
createMap: () => new Map(),
|
|
1052
|
-
|
|
1053
|
-
set: (target, key, value) => {
|
|
1054
|
-
target[key] = value;
|
|
1055
|
-
},
|
|
1056
|
-
|
|
1057
|
-
addValue: (set, value) => {
|
|
1058
|
-
set.add(value);
|
|
1059
|
-
},
|
|
1060
|
-
|
|
1061
|
-
addEntry: (map, key, value) => {
|
|
1062
|
-
map.set(key, value);
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
|
|
1066
|
-
const default_parse_operations = Object.freeze(parse_operations);
|
|
1067
|
-
|
|
1068
|
-
/**
|
|
1069
|
-
* Revive a value serialized with `devalue.stringify`
|
|
1070
|
-
* @param {string} serialized
|
|
1071
|
-
* @param {Record<string, (value: any) => any>} [revivers]
|
|
1072
|
-
* @param {import('./types.js').ParseOptions} [options]
|
|
1073
|
-
*/
|
|
1074
|
-
function parse(serialized, revivers, options) {
|
|
1075
|
-
return unflatten(JSON.parse(serialized), revivers);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
/**
|
|
1079
|
-
* Revive a value flattened with `devalue.stringify`
|
|
1080
|
-
* @param {number | any[]} parsed
|
|
1081
|
-
* @param {Record<string, (value: any) => any>} [revivers]
|
|
1082
|
-
* @param {import('./types.js').ParseOptions} [options]
|
|
1083
|
-
*/
|
|
1084
|
-
function unflatten(parsed, revivers, options) {
|
|
1085
|
-
/** @type {import('./types.js').ParseOperations} */
|
|
1086
|
-
const ops = merge_operations(default_parse_operations);
|
|
1087
|
-
|
|
1088
|
-
if (typeof parsed === 'number') return hydrate(parsed, true);
|
|
1089
|
-
|
|
1090
|
-
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
1091
|
-
throw new Error('Invalid input');
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
const values = /** @type {any[]} */ (parsed);
|
|
1095
|
-
|
|
1096
|
-
const hydrated = Array(values.length);
|
|
1097
|
-
|
|
1098
|
-
/**
|
|
1099
|
-
* A set of values currently being hydrated with custom revivers,
|
|
1100
|
-
* used to detect invalid cyclical dependencies
|
|
1101
|
-
* @type {Set<number> | null}
|
|
1102
|
-
*/
|
|
1103
|
-
let hydrating = null;
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* @param {number} index
|
|
1107
|
-
* @returns {any}
|
|
1108
|
-
*/
|
|
1109
|
-
function hydrate(index, standalone = false) {
|
|
1110
|
-
if (index === UNDEFINED) return ops.fromPrimitive(undefined);
|
|
1111
|
-
if (index === NAN) return ops.fromPrimitive(NaN);
|
|
1112
|
-
if (index === POSITIVE_INFINITY) return ops.fromPrimitive(Infinity);
|
|
1113
|
-
if (index === NEGATIVE_INFINITY) return ops.fromPrimitive(-Infinity);
|
|
1114
|
-
if (index === NEGATIVE_ZERO) return ops.fromPrimitive(-0);
|
|
1115
|
-
|
|
1116
|
-
if (standalone || typeof index !== 'number') {
|
|
1117
|
-
throw new Error(`Invalid input`);
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
if (index in hydrated) return hydrated[index];
|
|
1121
|
-
|
|
1122
|
-
const value = values[index];
|
|
1123
|
-
|
|
1124
|
-
if (!value || typeof value !== 'object') {
|
|
1125
|
-
hydrated[index] = ops.fromPrimitive(value);
|
|
1126
|
-
} else if (Array.isArray(value)) {
|
|
1127
|
-
if (typeof value[0] === 'string') {
|
|
1128
|
-
const type = value[0];
|
|
1129
|
-
|
|
1130
|
-
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : undefined;
|
|
1131
|
-
|
|
1132
|
-
if (reviver) {
|
|
1133
|
-
let i = value[1];
|
|
1134
|
-
if (typeof i !== 'number') {
|
|
1135
|
-
// if it's not a number, it was serialized by a builtin reviver
|
|
1136
|
-
// so we need to munge it into the format expected by a custom reviver
|
|
1137
|
-
i = values.push(value[1]) - 1;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
// If the payload is already hydrated, its recursion has already
|
|
1141
|
-
// terminated (e.g. a self-referential object cached itself before
|
|
1142
|
-
// following its own back-reference), so revive it directly. Falling
|
|
1143
|
-
// through to the `hydrating` guard here would wrongly reject a valid
|
|
1144
|
-
// cycle. An actually infinite payload (e.g. `[["Custom", 0]]`) is never
|
|
1145
|
-
// cached, so it still hits the guard below.
|
|
1146
|
-
if (Object.hasOwn(hydrated, i)) {
|
|
1147
|
-
return (hydrated[index] = reviver(hydrated[i]));
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
hydrating ??= new Set();
|
|
1151
|
-
|
|
1152
|
-
if (hydrating.has(i)) {
|
|
1153
|
-
throw new Error('Invalid circular reference');
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
hydrating.add(i);
|
|
1157
|
-
hydrated[index] = reviver(hydrate(i));
|
|
1158
|
-
hydrating.delete(i);
|
|
1159
|
-
|
|
1160
|
-
return hydrated[index];
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
switch (type) {
|
|
1164
|
-
case 'Date':
|
|
1165
|
-
hydrated[index] = ops.fromISOString(value[1]);
|
|
1166
|
-
break;
|
|
1167
|
-
|
|
1168
|
-
case 'Set':
|
|
1169
|
-
const set = ops.createSet();
|
|
1170
|
-
hydrated[index] = set;
|
|
1171
|
-
for (let i = 1; i < value.length; i += 1) {
|
|
1172
|
-
ops.addValue(set, hydrate(value[i]));
|
|
1173
|
-
}
|
|
1174
|
-
break;
|
|
1175
|
-
|
|
1176
|
-
case 'Map':
|
|
1177
|
-
const map = ops.createMap();
|
|
1178
|
-
hydrated[index] = map;
|
|
1179
|
-
for (let i = 1; i < value.length; i += 2) {
|
|
1180
|
-
ops.addEntry(map, hydrate(value[i]), hydrate(value[i + 1]));
|
|
1181
|
-
}
|
|
1182
|
-
break;
|
|
1183
|
-
|
|
1184
|
-
case 'RegExp':
|
|
1185
|
-
hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
|
|
1186
|
-
break;
|
|
1187
|
-
|
|
1188
|
-
case 'Object': {
|
|
1189
|
-
const wrapped_index = value[1];
|
|
1190
|
-
|
|
1191
|
-
if (
|
|
1192
|
-
typeof values[wrapped_index] === 'object' &&
|
|
1193
|
-
values[wrapped_index][0] !== 'BigInt'
|
|
1194
|
-
) {
|
|
1195
|
-
// avoid infinite recusion in case of malformed input
|
|
1196
|
-
throw new Error('Invalid input');
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
hydrated[index] = ops.box(hydrate(wrapped_index));
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
case 'BigInt':
|
|
1204
|
-
hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
|
|
1205
|
-
break;
|
|
1206
|
-
|
|
1207
|
-
case 'null':
|
|
1208
|
-
const obj = ops.createNullPrototypeObject();
|
|
1209
|
-
hydrated[index] = obj;
|
|
1210
|
-
for (let i = 1; i < value.length; i += 2) {
|
|
1211
|
-
if (value[i] === '__proto__') {
|
|
1212
|
-
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
ops.set(obj, value[i], hydrate(value[i + 1]));
|
|
1216
|
-
}
|
|
1217
|
-
break;
|
|
1218
|
-
|
|
1219
|
-
case 'Int8Array':
|
|
1220
|
-
case 'Uint8Array':
|
|
1221
|
-
case 'Uint8ClampedArray':
|
|
1222
|
-
case 'Int16Array':
|
|
1223
|
-
case 'Uint16Array':
|
|
1224
|
-
case 'Float16Array':
|
|
1225
|
-
case 'Int32Array':
|
|
1226
|
-
case 'Uint32Array':
|
|
1227
|
-
case 'Float32Array':
|
|
1228
|
-
case 'Float64Array':
|
|
1229
|
-
case 'BigInt64Array':
|
|
1230
|
-
case 'BigUint64Array':
|
|
1231
|
-
case 'DataView': {
|
|
1232
|
-
if (values[value[1]][0] !== 'ArrayBuffer') {
|
|
1233
|
-
// without this, if we receive malformed input we could
|
|
1234
|
-
// end up trying to hydrate in a circle or allocate
|
|
1235
|
-
// huge amounts of memory when we call `new TypedArrayConstructor(buffer)`
|
|
1236
|
-
throw new Error('Invalid data');
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
const buffer = hydrate(value[1]);
|
|
1240
|
-
|
|
1241
|
-
hydrated[index] = ops.fromViewInfo(type, buffer, value[2], value[3]);
|
|
1242
|
-
|
|
1243
|
-
break;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
case 'ArrayBuffer': {
|
|
1247
|
-
const base64 = value[1];
|
|
1248
|
-
if (typeof base64 !== 'string') {
|
|
1249
|
-
throw new Error('Invalid ArrayBuffer encoding');
|
|
1250
|
-
}
|
|
1251
|
-
hydrated[index] = ops.fromArrayBuffer(decode64(base64));
|
|
1252
|
-
break;
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
case 'URL':
|
|
1256
|
-
case 'URLSearchParams':
|
|
1257
|
-
case 'Temporal.Duration':
|
|
1258
|
-
case 'Temporal.Instant':
|
|
1259
|
-
case 'Temporal.PlainDate':
|
|
1260
|
-
case 'Temporal.PlainTime':
|
|
1261
|
-
case 'Temporal.PlainDateTime':
|
|
1262
|
-
case 'Temporal.PlainMonthDay':
|
|
1263
|
-
case 'Temporal.PlainYearMonth':
|
|
1264
|
-
case 'Temporal.ZonedDateTime': {
|
|
1265
|
-
// the same tags `toStringValue` serializes on the stringify side
|
|
1266
|
-
hydrated[index] = ops.fromStringValue(type, value[1]);
|
|
1267
|
-
break;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
default:
|
|
1271
|
-
throw new Error(`Unknown type ${type}`);
|
|
1272
|
-
}
|
|
1273
|
-
} else if (value[0] === SPARSE) {
|
|
1274
|
-
// Sparse array encoding: [SPARSE, length, idx, val, idx, val, ...]
|
|
1275
|
-
const len = value[1];
|
|
1276
|
-
|
|
1277
|
-
if (!is_valid_array_len(len)) {
|
|
1278
|
-
throw new Error('Invalid input');
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
// `len` comes from the input rather than being bounded by it, so
|
|
1282
|
-
// `createSparseArray` is responsible for not allocating storage
|
|
1283
|
-
// proportional to it.
|
|
1284
|
-
const array = ops.createSparseArray(len);
|
|
1285
|
-
hydrated[index] = array;
|
|
1286
|
-
|
|
1287
|
-
for (let i = 2; i < value.length; i += 2) {
|
|
1288
|
-
const idx = value[i];
|
|
1289
|
-
|
|
1290
|
-
if (!is_valid_array_index(idx) || idx >= len) {
|
|
1291
|
-
throw new Error('Invalid input');
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
ops.set(array, idx, hydrate(value[i + 1]));
|
|
1295
|
-
}
|
|
1296
|
-
} else {
|
|
1297
|
-
const array = ops.createArray(value.length);
|
|
1298
|
-
hydrated[index] = array;
|
|
1299
|
-
|
|
1300
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
1301
|
-
const n = value[i];
|
|
1302
|
-
if (n === HOLE) continue;
|
|
1303
|
-
|
|
1304
|
-
ops.set(array, i, hydrate(n));
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
} else {
|
|
1308
|
-
const object = ops.createObject();
|
|
1309
|
-
hydrated[index] = object;
|
|
1310
|
-
|
|
1311
|
-
for (const key of Object.keys(value)) {
|
|
1312
|
-
if (key === '__proto__') {
|
|
1313
|
-
throw new Error('Cannot parse an object with a `__proto__` property');
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
ops.set(object, key, hydrate(value[key]));
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
return hydrated[index];
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
return hydrate(0);
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
/**
|
|
1327
|
-
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
1328
|
-
* @param {any} value
|
|
1329
|
-
* @param {Record<string, (value: any) => any>} [reducers]
|
|
1330
|
-
* @param {import('./types.js').StringifyOptions} [options]
|
|
1331
|
-
*/
|
|
1332
|
-
function stringify$1(value, reducers, options) {
|
|
1333
|
-
const stringified = run(false, value, reducers);
|
|
1334
|
-
return typeof stringified === 'string' ? stringified : `[${stringified.join(',')}]`;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
/**
|
|
1338
|
-
* @param {boolean} async
|
|
1339
|
-
* @param {any} value
|
|
1340
|
-
* @param {Record<string, (value: any) => any>} [reducers]
|
|
1341
|
-
* @param {import('./types.js').StringifyOptions} [options]
|
|
1342
|
-
*/
|
|
1343
|
-
function run(async, value, reducers, options) {
|
|
1344
|
-
const ops = merge_operations(default_stringify_operations);
|
|
1345
|
-
|
|
1346
|
-
/** @type {any[]} */
|
|
1347
|
-
const stringified = [];
|
|
1348
|
-
|
|
1349
|
-
/** @type {Map<any, number>} */
|
|
1350
|
-
const indexes = new Map();
|
|
1351
|
-
|
|
1352
|
-
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
1353
|
-
const custom = [];
|
|
1354
|
-
if (reducers) {
|
|
1355
|
-
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
1356
|
-
custom.push({ key, fn: reducers[key] });
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
/** @type {string[]} */
|
|
1361
|
-
const keys = [];
|
|
1362
|
-
|
|
1363
|
-
let p = 0;
|
|
1364
|
-
|
|
1365
|
-
/**
|
|
1366
|
-
* @param {any} thing
|
|
1367
|
-
* @param {number} [index]
|
|
1368
|
-
*/
|
|
1369
|
-
function flatten(thing, index) {
|
|
1370
|
-
const type = ops.typeOf(thing);
|
|
1371
|
-
|
|
1372
|
-
if (type === 'undefined') return UNDEFINED;
|
|
1373
|
-
|
|
1374
|
-
/** @type {number | undefined} */
|
|
1375
|
-
let number;
|
|
1376
|
-
|
|
1377
|
-
// `ops.toPrimitive` is the boundary between the value being serialized and
|
|
1378
|
-
// plain host JavaScript: everything below operates on the extracted host
|
|
1379
|
-
// primitive, so native comparisons and arithmetic are correct there.
|
|
1380
|
-
if (type === 'number') {
|
|
1381
|
-
number = /** @type {number} */ (ops.toPrimitive(thing));
|
|
1382
|
-
if (Number.isNaN(number)) return NAN;
|
|
1383
|
-
if (number === Infinity) return POSITIVE_INFINITY;
|
|
1384
|
-
if (number === -Infinity) return NEGATIVE_INFINITY;
|
|
1385
|
-
if (number === 0 && 1 / number < 0) return NEGATIVE_ZERO;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
const id = ops.identify(thing);
|
|
1389
|
-
|
|
1390
|
-
if (indexes.has(id)) return /** @type {number} */ (indexes.get(id));
|
|
1391
|
-
|
|
1392
|
-
index ??= p++;
|
|
1393
|
-
indexes.set(id, index);
|
|
1394
|
-
|
|
1395
|
-
for (const { key, fn } of custom) {
|
|
1396
|
-
const value = fn(thing);
|
|
1397
|
-
if (value) {
|
|
1398
|
-
stringified[index] = `["${key}",${flatten(value)}]`;
|
|
1399
|
-
return index;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
if (type === 'function') {
|
|
1404
|
-
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
1405
|
-
} else if (type === 'symbol') {
|
|
1406
|
-
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
/** @type {string | Promise<any>} */
|
|
1410
|
-
let str = '';
|
|
1411
|
-
|
|
1412
|
-
if (type !== 'object') {
|
|
1413
|
-
str = stringify_primitive(type === 'number' ? number : ops.toPrimitive(thing));
|
|
1414
|
-
} else if (ops.isThenable(thing)) {
|
|
1415
|
-
{
|
|
1416
|
-
throw new DevalueError(
|
|
1417
|
-
`Cannot stringify a Promise or thenable — use stringifyAsync instead`,
|
|
1418
|
-
keys,
|
|
1419
|
-
thing,
|
|
1420
|
-
value
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
} else {
|
|
1424
|
-
const tag = ops.tagOf(thing);
|
|
1425
|
-
|
|
1426
|
-
switch (tag) {
|
|
1427
|
-
case 'Number':
|
|
1428
|
-
case 'String':
|
|
1429
|
-
case 'Boolean':
|
|
1430
|
-
case 'BigInt':
|
|
1431
|
-
str = `["Object",${flatten(ops.unbox(thing))}]`;
|
|
1432
|
-
break;
|
|
1433
|
-
|
|
1434
|
-
case 'Date':
|
|
1435
|
-
str = `["Date","${ops.toISOString(thing)}"]`;
|
|
1436
|
-
break;
|
|
1437
|
-
|
|
1438
|
-
case 'URL':
|
|
1439
|
-
str = `["URL",${stringify_string(ops.toStringValue(thing))}]`;
|
|
1440
|
-
break;
|
|
1441
|
-
|
|
1442
|
-
case 'URLSearchParams':
|
|
1443
|
-
str = `["URLSearchParams",${stringify_string(ops.toStringValue(thing))}]`;
|
|
1444
|
-
break;
|
|
1445
|
-
|
|
1446
|
-
case 'RegExp':
|
|
1447
|
-
const { source, flags } = ops.regExpInfo(thing);
|
|
1448
|
-
str = flags
|
|
1449
|
-
? `["RegExp",${stringify_string(source)},"${flags}"]`
|
|
1450
|
-
: `["RegExp",${stringify_string(source)}]`;
|
|
1451
|
-
break;
|
|
1452
|
-
|
|
1453
|
-
case 'Array': {
|
|
1454
|
-
// For dense arrays (no holes), we iterate normally.
|
|
1455
|
-
// When we encounter the first hole, we call Object.keys
|
|
1456
|
-
// to determine the sparseness, then decide between:
|
|
1457
|
-
// - HOLE encoding: [-2, val, -2, ...] (default)
|
|
1458
|
-
// - Sparse encoding: [-7, length, idx, val, ...] (for very sparse arrays)
|
|
1459
|
-
// Only the sparse path avoids iterating every slot, which
|
|
1460
|
-
// is what protects against the DoS of e.g. `arr[1000000] = 1`.
|
|
1461
|
-
let mostly_dense = false;
|
|
1462
|
-
|
|
1463
|
-
const length = ops.lengthOf(thing);
|
|
1464
|
-
|
|
1465
|
-
str = '[';
|
|
1466
|
-
|
|
1467
|
-
for (let i = 0; i < length; i += 1) {
|
|
1468
|
-
if (i > 0) str += ',';
|
|
1469
|
-
|
|
1470
|
-
if (ops.hasOwn(thing, i)) {
|
|
1471
|
-
keys.push(`[${i}]`);
|
|
1472
|
-
str += flatten(ops.get(thing, i));
|
|
1473
|
-
keys.pop();
|
|
1474
|
-
} else if (mostly_dense) {
|
|
1475
|
-
// Use dense encoding. The heuristic guarantees the
|
|
1476
|
-
// array is only mildly sparse, so iterating over every
|
|
1477
|
-
// slot is fine.
|
|
1478
|
-
str += HOLE;
|
|
1479
|
-
} else {
|
|
1480
|
-
// Decide between HOLE encoding and sparse encoding.
|
|
1481
|
-
//
|
|
1482
|
-
// HOLE encoding: each hole is serialized as the HOLE
|
|
1483
|
-
// sentinel (-2). For example, [, "a", ,] becomes
|
|
1484
|
-
// [-2, 0, -2]. Each hole costs 3 chars ("-2" + comma).
|
|
1485
|
-
//
|
|
1486
|
-
// Sparse encoding: lists only populated indices.
|
|
1487
|
-
// For example, [, "a", ,] becomes [-7, 3, 1, 0] — the
|
|
1488
|
-
// -7 sentinel, the array length (3), then index-value
|
|
1489
|
-
// pairs. This avoids paying per-hole, but each element
|
|
1490
|
-
// costs extra chars to write its index.
|
|
1491
|
-
//
|
|
1492
|
-
// The values are the same size either way, so the
|
|
1493
|
-
// choice comes down to structural overhead:
|
|
1494
|
-
//
|
|
1495
|
-
// HOLE overhead:
|
|
1496
|
-
// 3 chars per hole ("-2" + comma)
|
|
1497
|
-
// = (L - P) * 3
|
|
1498
|
-
//
|
|
1499
|
-
// Sparse overhead:
|
|
1500
|
-
// "-7," — 3 chars (sparse sentinel + comma)
|
|
1501
|
-
// + length + "," — (d + 1) chars (array length + comma)
|
|
1502
|
-
// + per element: index + "," — (d + 1) chars
|
|
1503
|
-
// = (4 + d) + P * (d + 1)
|
|
1504
|
-
//
|
|
1505
|
-
// where L is the array length, P is the number of
|
|
1506
|
-
// populated elements, and d is the number of digits
|
|
1507
|
-
// in L (an upper bound on the digits in any index).
|
|
1508
|
-
//
|
|
1509
|
-
// Sparse encoding is cheaper when:
|
|
1510
|
-
// (4 + d) + P * (d + 1) < (L - P) * 3
|
|
1511
|
-
const populated_keys = ops.indicesOf(thing);
|
|
1512
|
-
const population = populated_keys.length;
|
|
1513
|
-
const d = String(length).length;
|
|
1514
|
-
|
|
1515
|
-
const hole_cost = (length - population) * 3;
|
|
1516
|
-
const sparse_cost = 4 + d + population * (d + 1);
|
|
1517
|
-
|
|
1518
|
-
if (hole_cost > sparse_cost) {
|
|
1519
|
-
str = '[' + SPARSE + ',' + length;
|
|
1520
|
-
for (let j = 0; j < populated_keys.length; j++) {
|
|
1521
|
-
const key = populated_keys[j];
|
|
1522
|
-
keys.push(`[${key}]`);
|
|
1523
|
-
str += ',' + key + ',' + flatten(ops.get(thing, key));
|
|
1524
|
-
keys.pop();
|
|
1525
|
-
}
|
|
1526
|
-
break;
|
|
1527
|
-
} else {
|
|
1528
|
-
mostly_dense = true;
|
|
1529
|
-
str += HOLE;
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
str += ']';
|
|
1535
|
-
|
|
1536
|
-
break;
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
case 'Set':
|
|
1540
|
-
str = '["Set"';
|
|
1541
|
-
|
|
1542
|
-
for (const value of ops.valuesOf(thing)) {
|
|
1543
|
-
str += `,${flatten(value)}`;
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
str += ']';
|
|
1547
|
-
break;
|
|
1548
|
-
|
|
1549
|
-
case 'Map':
|
|
1550
|
-
str = '["Map"';
|
|
1551
|
-
|
|
1552
|
-
for (const [key, value] of ops.entriesOf(thing)) {
|
|
1553
|
-
const key_type = ops.typeOf(key);
|
|
1554
|
-
const key_is_primitive =
|
|
1555
|
-
key_type !== 'object' && key_type !== 'function' && key_type !== 'symbol';
|
|
1556
|
-
keys.push(
|
|
1557
|
-
`.get(${key_is_primitive ? stringify_primitive(ops.toPrimitive(key)) : '...'})`
|
|
1558
|
-
);
|
|
1559
|
-
str += `,${flatten(key)},${flatten(value)}`;
|
|
1560
|
-
keys.pop();
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
str += ']';
|
|
1564
|
-
break;
|
|
1565
|
-
|
|
1566
|
-
case 'Int8Array':
|
|
1567
|
-
case 'Uint8Array':
|
|
1568
|
-
case 'Uint8ClampedArray':
|
|
1569
|
-
case 'Int16Array':
|
|
1570
|
-
case 'Uint16Array':
|
|
1571
|
-
case 'Float16Array':
|
|
1572
|
-
case 'Int32Array':
|
|
1573
|
-
case 'Uint32Array':
|
|
1574
|
-
case 'Float32Array':
|
|
1575
|
-
case 'Float64Array':
|
|
1576
|
-
case 'BigInt64Array':
|
|
1577
|
-
case 'BigUint64Array': {
|
|
1578
|
-
const info = ops.viewInfo(thing);
|
|
1579
|
-
str = '["' + tag + '",' + flatten(info.buffer);
|
|
1580
|
-
|
|
1581
|
-
// handle subarrays
|
|
1582
|
-
if (info.byteLength !== info.bufferByteLength) {
|
|
1583
|
-
str += `,${info.byteOffset},${info.length}`;
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
str += ']';
|
|
1587
|
-
break;
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
case 'DataView': {
|
|
1591
|
-
const info = ops.viewInfo(thing);
|
|
1592
|
-
str = '["' + tag + '",' + flatten(info.buffer);
|
|
1593
|
-
|
|
1594
|
-
if (info.byteLength !== info.bufferByteLength) {
|
|
1595
|
-
str += `,${info.byteOffset},${info.byteLength}`;
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
str += ']';
|
|
1599
|
-
break;
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
case 'ArrayBuffer': {
|
|
1603
|
-
const base64 = encode64(ops.toArrayBuffer(thing));
|
|
1604
|
-
|
|
1605
|
-
str = `["ArrayBuffer","${base64}"]`;
|
|
1606
|
-
break;
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
case 'Temporal.Duration':
|
|
1610
|
-
case 'Temporal.Instant':
|
|
1611
|
-
case 'Temporal.PlainDate':
|
|
1612
|
-
case 'Temporal.PlainTime':
|
|
1613
|
-
case 'Temporal.PlainDateTime':
|
|
1614
|
-
case 'Temporal.PlainMonthDay':
|
|
1615
|
-
case 'Temporal.PlainYearMonth':
|
|
1616
|
-
case 'Temporal.ZonedDateTime':
|
|
1617
|
-
str = `["${tag}",${stringify_string(ops.toStringValue(thing))}]`;
|
|
1618
|
-
break;
|
|
1619
|
-
|
|
1620
|
-
default: {
|
|
1621
|
-
const shape = ops.shapeOf(thing);
|
|
1622
|
-
|
|
1623
|
-
if (shape.kind === 'not-plain') {
|
|
1624
|
-
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
if (shape.kind === 'symbol-keys') {
|
|
1628
|
-
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
if (shape.kind === 'null-proto') {
|
|
1632
|
-
str = '["null"';
|
|
1633
|
-
for (const key of shape.keys) {
|
|
1634
|
-
if (key === '__proto__') {
|
|
1635
|
-
throw new DevalueError(
|
|
1636
|
-
`Cannot stringify objects with __proto__ keys`,
|
|
1637
|
-
keys,
|
|
1638
|
-
thing,
|
|
1639
|
-
value
|
|
1640
|
-
);
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
keys.push(stringify_key(key));
|
|
1644
|
-
str += `,${stringify_string(key)},${flatten(ops.get(thing, key))}`;
|
|
1645
|
-
keys.pop();
|
|
1646
|
-
}
|
|
1647
|
-
str += ']';
|
|
1648
|
-
} else {
|
|
1649
|
-
str = '{';
|
|
1650
|
-
let started = false;
|
|
1651
|
-
for (const key of shape.keys) {
|
|
1652
|
-
if (key === '__proto__') {
|
|
1653
|
-
throw new DevalueError(
|
|
1654
|
-
`Cannot stringify objects with __proto__ keys`,
|
|
1655
|
-
keys,
|
|
1656
|
-
thing,
|
|
1657
|
-
value
|
|
1658
|
-
);
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
if (started) str += ',';
|
|
1662
|
-
started = true;
|
|
1663
|
-
keys.push(stringify_key(key));
|
|
1664
|
-
str += `${stringify_string(key)}:${flatten(ops.get(thing, key))}`;
|
|
1665
|
-
keys.pop();
|
|
1666
|
-
}
|
|
1667
|
-
str += '}';
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
stringified[index] = str;
|
|
1674
|
-
return index;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
const index = flatten(value);
|
|
1678
|
-
|
|
1679
|
-
// special case — value is represented as a negative index
|
|
1680
|
-
if (index < 0) return `${index}`;
|
|
1681
|
-
|
|
1682
|
-
return stringified;
|
|
244
|
+
const counts = /* @__PURE__ */ new Map();
|
|
245
|
+
const keys = [];
|
|
246
|
+
const custom = /* @__PURE__ */ new Map();
|
|
247
|
+
function walk(thing) {
|
|
248
|
+
if (!is_primitive(thing)) {
|
|
249
|
+
if (counts.has(thing)) {
|
|
250
|
+
counts.set(thing, counts.get(thing) + 1);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
counts.set(thing, 1);
|
|
254
|
+
if (replacer) {
|
|
255
|
+
const str2 = replacer(thing, (value2) => uneval(value2, replacer));
|
|
256
|
+
if (typeof str2 === "string") {
|
|
257
|
+
custom.set(thing, str2);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (typeof thing === "function") {
|
|
262
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
263
|
+
}
|
|
264
|
+
const type = get_type(thing);
|
|
265
|
+
switch (type) {
|
|
266
|
+
case "Number":
|
|
267
|
+
case "BigInt":
|
|
268
|
+
case "String":
|
|
269
|
+
case "Boolean":
|
|
270
|
+
case "Date":
|
|
271
|
+
case "RegExp":
|
|
272
|
+
case "URL":
|
|
273
|
+
case "URLSearchParams":
|
|
274
|
+
return;
|
|
275
|
+
case "Array":
|
|
276
|
+
thing.forEach((value2, i) => {
|
|
277
|
+
keys.push(`[${i}]`);
|
|
278
|
+
walk(value2);
|
|
279
|
+
keys.pop();
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
case "Set":
|
|
283
|
+
Array.from(thing).forEach(walk);
|
|
284
|
+
break;
|
|
285
|
+
case "Map":
|
|
286
|
+
for (const [key, value2] of thing) {
|
|
287
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive$1(key) : "..."})`);
|
|
288
|
+
walk(value2);
|
|
289
|
+
keys.pop();
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
case "Int8Array":
|
|
293
|
+
case "Uint8Array":
|
|
294
|
+
case "Uint8ClampedArray":
|
|
295
|
+
case "Int16Array":
|
|
296
|
+
case "Uint16Array":
|
|
297
|
+
case "Float16Array":
|
|
298
|
+
case "Int32Array":
|
|
299
|
+
case "Uint32Array":
|
|
300
|
+
case "Float32Array":
|
|
301
|
+
case "Float64Array":
|
|
302
|
+
case "BigInt64Array":
|
|
303
|
+
case "BigUint64Array":
|
|
304
|
+
case "DataView":
|
|
305
|
+
walk(thing.buffer);
|
|
306
|
+
return;
|
|
307
|
+
case "ArrayBuffer":
|
|
308
|
+
return;
|
|
309
|
+
case "Temporal.Duration":
|
|
310
|
+
case "Temporal.Instant":
|
|
311
|
+
case "Temporal.PlainDate":
|
|
312
|
+
case "Temporal.PlainTime":
|
|
313
|
+
case "Temporal.PlainDateTime":
|
|
314
|
+
case "Temporal.PlainMonthDay":
|
|
315
|
+
case "Temporal.PlainYearMonth":
|
|
316
|
+
case "Temporal.ZonedDateTime":
|
|
317
|
+
return;
|
|
318
|
+
default:
|
|
319
|
+
if (!is_plain_object(thing)) {
|
|
320
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
321
|
+
}
|
|
322
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
323
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
324
|
+
}
|
|
325
|
+
for (const key of Object.keys(thing)) {
|
|
326
|
+
if (key === "__proto__") {
|
|
327
|
+
throw new DevalueError(
|
|
328
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
329
|
+
keys,
|
|
330
|
+
thing,
|
|
331
|
+
value
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
keys.push(stringify_key(key));
|
|
335
|
+
walk(thing[key]);
|
|
336
|
+
keys.pop();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else if (typeof thing === "symbol") {
|
|
340
|
+
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
walk(value);
|
|
344
|
+
const names = /* @__PURE__ */ new Map();
|
|
345
|
+
Array.from(counts).filter((entry) => entry[1] > 1).sort((a, b) => b[1] - a[1]).forEach((entry, i) => {
|
|
346
|
+
names.set(entry[0], get_name(i));
|
|
347
|
+
});
|
|
348
|
+
function stringify(thing) {
|
|
349
|
+
if (names.has(thing)) {
|
|
350
|
+
return names.get(thing);
|
|
351
|
+
}
|
|
352
|
+
if (is_primitive(thing)) {
|
|
353
|
+
return stringify_primitive$1(thing);
|
|
354
|
+
}
|
|
355
|
+
if (custom.has(thing)) {
|
|
356
|
+
return custom.get(thing);
|
|
357
|
+
}
|
|
358
|
+
const type = get_type(thing);
|
|
359
|
+
switch (type) {
|
|
360
|
+
case "Number":
|
|
361
|
+
case "String":
|
|
362
|
+
case "Boolean":
|
|
363
|
+
case "BigInt":
|
|
364
|
+
return `Object(${stringify(thing.valueOf())})`;
|
|
365
|
+
case "RegExp":
|
|
366
|
+
const { source, flags } = thing;
|
|
367
|
+
return flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`;
|
|
368
|
+
case "Date":
|
|
369
|
+
return `new Date(${thing.getTime()})`;
|
|
370
|
+
case "URL":
|
|
371
|
+
return `new URL(${stringify_string(thing.toString())})`;
|
|
372
|
+
case "URLSearchParams":
|
|
373
|
+
return `new URLSearchParams(${stringify_string(thing.toString())})`;
|
|
374
|
+
case "Array": {
|
|
375
|
+
let has_holes = false;
|
|
376
|
+
let result = "[";
|
|
377
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
378
|
+
if (i > 0) result += ",";
|
|
379
|
+
if (Object.hasOwn(thing, i)) {
|
|
380
|
+
result += stringify(thing[i]);
|
|
381
|
+
} else if (!has_holes) {
|
|
382
|
+
const populated_keys = valid_array_indices(
|
|
383
|
+
/** @type {any[]} */
|
|
384
|
+
thing
|
|
385
|
+
);
|
|
386
|
+
const population = populated_keys.length;
|
|
387
|
+
const d = String(thing.length).length;
|
|
388
|
+
const hole_cost = thing.length + 2;
|
|
389
|
+
const sparse_cost = 25 + d + population * (d + 2);
|
|
390
|
+
if (hole_cost > sparse_cost) {
|
|
391
|
+
const entries = populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(",");
|
|
392
|
+
return `Object.assign(Array(${thing.length}),{${entries}})`;
|
|
393
|
+
}
|
|
394
|
+
has_holes = true;
|
|
395
|
+
i -= 1;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const tail = thing.length === 0 || thing.length - 1 in thing ? "" : ",";
|
|
399
|
+
return result + tail + "]";
|
|
400
|
+
}
|
|
401
|
+
case "Set":
|
|
402
|
+
case "Map":
|
|
403
|
+
return `new ${type}([${Array.from(thing).map(stringify).join(",")}])`;
|
|
404
|
+
case "Int8Array":
|
|
405
|
+
case "Uint8Array":
|
|
406
|
+
case "Uint8ClampedArray":
|
|
407
|
+
case "Int16Array":
|
|
408
|
+
case "Uint16Array":
|
|
409
|
+
case "Float16Array":
|
|
410
|
+
case "Int32Array":
|
|
411
|
+
case "Uint32Array":
|
|
412
|
+
case "Float32Array":
|
|
413
|
+
case "Float64Array":
|
|
414
|
+
case "BigInt64Array":
|
|
415
|
+
case "BigUint64Array": {
|
|
416
|
+
let str2 = `new ${type}`;
|
|
417
|
+
if (!names.has(thing.buffer)) {
|
|
418
|
+
const array = new thing.constructor(thing.buffer);
|
|
419
|
+
str2 += `([${array}])`;
|
|
420
|
+
} else {
|
|
421
|
+
str2 += `(${stringify(thing.buffer)})`;
|
|
422
|
+
}
|
|
423
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
424
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
425
|
+
const end = start + thing.length;
|
|
426
|
+
str2 += `.subarray(${start},${end})`;
|
|
427
|
+
}
|
|
428
|
+
return str2;
|
|
429
|
+
}
|
|
430
|
+
case "DataView": {
|
|
431
|
+
let str2 = `new DataView`;
|
|
432
|
+
if (!names.has(thing.buffer)) {
|
|
433
|
+
str2 += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
434
|
+
} else {
|
|
435
|
+
str2 += `(${stringify(thing.buffer)}`;
|
|
436
|
+
}
|
|
437
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
438
|
+
str2 += `,${thing.startOffset},${thing.byteLength}`;
|
|
439
|
+
}
|
|
440
|
+
return str2 + ")";
|
|
441
|
+
}
|
|
442
|
+
case "ArrayBuffer": {
|
|
443
|
+
const ui8 = new Uint8Array(thing);
|
|
444
|
+
return `new Uint8Array([${ui8.toString()}]).buffer`;
|
|
445
|
+
}
|
|
446
|
+
case "Temporal.Duration":
|
|
447
|
+
case "Temporal.Instant":
|
|
448
|
+
case "Temporal.PlainDate":
|
|
449
|
+
case "Temporal.PlainTime":
|
|
450
|
+
case "Temporal.PlainDateTime":
|
|
451
|
+
case "Temporal.PlainMonthDay":
|
|
452
|
+
case "Temporal.PlainYearMonth":
|
|
453
|
+
case "Temporal.ZonedDateTime":
|
|
454
|
+
return `${type}.from(${stringify_string(thing.toString())})`;
|
|
455
|
+
default:
|
|
456
|
+
const keys2 = Object.keys(thing);
|
|
457
|
+
const obj = keys2.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(",");
|
|
458
|
+
const proto = Object.getPrototypeOf(thing);
|
|
459
|
+
if (proto === null) {
|
|
460
|
+
return keys2.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`;
|
|
461
|
+
}
|
|
462
|
+
return `{${obj}}`;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const str = stringify(value);
|
|
466
|
+
if (names.size) {
|
|
467
|
+
const params = [];
|
|
468
|
+
const statements = [];
|
|
469
|
+
const values = [];
|
|
470
|
+
names.forEach((name, thing) => {
|
|
471
|
+
params.push(name);
|
|
472
|
+
if (custom.has(thing)) {
|
|
473
|
+
values.push(
|
|
474
|
+
/** @type {string} */
|
|
475
|
+
custom.get(thing)
|
|
476
|
+
);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (is_primitive(thing)) {
|
|
480
|
+
values.push(stringify_primitive$1(thing));
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const type = get_type(thing);
|
|
484
|
+
switch (type) {
|
|
485
|
+
case "Number":
|
|
486
|
+
case "String":
|
|
487
|
+
case "Boolean":
|
|
488
|
+
case "BigInt":
|
|
489
|
+
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
490
|
+
break;
|
|
491
|
+
case "RegExp":
|
|
492
|
+
const { source, flags } = thing;
|
|
493
|
+
const regexp = flags ? `new RegExp(${stringify_string(source)},"${flags}")` : `new RegExp(${stringify_string(source)})`;
|
|
494
|
+
values.push(regexp);
|
|
495
|
+
break;
|
|
496
|
+
case "Date":
|
|
497
|
+
values.push(`new Date(${thing.getTime()})`);
|
|
498
|
+
break;
|
|
499
|
+
case "URL":
|
|
500
|
+
values.push(`new URL(${stringify_string(thing.toString())})`);
|
|
501
|
+
break;
|
|
502
|
+
case "URLSearchParams":
|
|
503
|
+
values.push(`new URLSearchParams(${stringify_string(thing.toString())})`);
|
|
504
|
+
break;
|
|
505
|
+
case "Array":
|
|
506
|
+
values.push(`Array(${thing.length})`);
|
|
507
|
+
thing.forEach((v, i) => {
|
|
508
|
+
statements.push(`${name}[${i}]=${stringify(v)}`);
|
|
509
|
+
});
|
|
510
|
+
break;
|
|
511
|
+
case "Set":
|
|
512
|
+
values.push(`new Set`);
|
|
513
|
+
statements.push(
|
|
514
|
+
`${name}.${Array.from(thing).map((v) => `add(${stringify(v)})`).join(".")}`
|
|
515
|
+
);
|
|
516
|
+
break;
|
|
517
|
+
case "Map":
|
|
518
|
+
values.push(`new Map`);
|
|
519
|
+
statements.push(
|
|
520
|
+
`${name}.${Array.from(thing).map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`).join(".")}`
|
|
521
|
+
);
|
|
522
|
+
break;
|
|
523
|
+
case "Int8Array":
|
|
524
|
+
case "Uint8Array":
|
|
525
|
+
case "Uint8ClampedArray":
|
|
526
|
+
case "Int16Array":
|
|
527
|
+
case "Uint16Array":
|
|
528
|
+
case "Float16Array":
|
|
529
|
+
case "Int32Array":
|
|
530
|
+
case "Uint32Array":
|
|
531
|
+
case "Float32Array":
|
|
532
|
+
case "Float64Array":
|
|
533
|
+
case "BigInt64Array":
|
|
534
|
+
case "BigUint64Array": {
|
|
535
|
+
let str2 = `new ${type}`;
|
|
536
|
+
if (!names.has(thing.buffer)) {
|
|
537
|
+
const array = new thing.constructor(thing.buffer);
|
|
538
|
+
str2 += `([${array}])`;
|
|
539
|
+
} else {
|
|
540
|
+
str2 += `(${stringify(thing.buffer)})`;
|
|
541
|
+
}
|
|
542
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
543
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
544
|
+
const end = start + thing.length;
|
|
545
|
+
str2 += `.subarray(${start},${end})`;
|
|
546
|
+
}
|
|
547
|
+
values.push(`{}`);
|
|
548
|
+
statements.push(`${name}=${str2}`);
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case "DataView": {
|
|
552
|
+
let str2 = `new DataView`;
|
|
553
|
+
if (!names.has(thing.buffer)) {
|
|
554
|
+
str2 += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
555
|
+
} else {
|
|
556
|
+
str2 += `(${stringify(thing.buffer)}`;
|
|
557
|
+
}
|
|
558
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
559
|
+
str2 += `,${thing.byteOffset},${thing.byteLength}`;
|
|
560
|
+
}
|
|
561
|
+
str2 += ")";
|
|
562
|
+
values.push(`{}`);
|
|
563
|
+
statements.push(`${name}=${str2}`);
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
case "ArrayBuffer":
|
|
567
|
+
values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`);
|
|
568
|
+
break;
|
|
569
|
+
default:
|
|
570
|
+
values.push(Object.getPrototypeOf(thing) === null ? "Object.create(null)" : "{}");
|
|
571
|
+
Object.keys(thing).forEach((key) => {
|
|
572
|
+
statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
statements.push(`return ${str}`);
|
|
577
|
+
return `(function(${params.join(",")}){${statements.join(";")}}(${values.join(",")}))`;
|
|
578
|
+
} else {
|
|
579
|
+
return str;
|
|
580
|
+
}
|
|
1683
581
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
if (type === 'string') return stringify_string(thing);
|
|
1692
|
-
if (thing === void 0) return UNDEFINED.toString();
|
|
1693
|
-
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
1694
|
-
if (type === 'bigint') return `["BigInt","${thing}"]`;
|
|
1695
|
-
return String(thing);
|
|
582
|
+
function get_name(num) {
|
|
583
|
+
let name = "";
|
|
584
|
+
do {
|
|
585
|
+
name = chars[num % chars.length] + name;
|
|
586
|
+
num = ~~(num / chars.length) - 1;
|
|
587
|
+
} while (num >= 0);
|
|
588
|
+
return reserved.test(name) ? `${name}0` : name;
|
|
1696
589
|
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
function get_relative_path(from, to) {
|
|
1700
|
-
const from_parts = from.split(/[/\\]/);
|
|
1701
|
-
const to_parts = to.split(/[/\\]/);
|
|
1702
|
-
from_parts.pop();
|
|
1703
|
-
while (from_parts[0] === to_parts[0]) {
|
|
1704
|
-
from_parts.shift();
|
|
1705
|
-
to_parts.shift();
|
|
1706
|
-
}
|
|
1707
|
-
let i = from_parts.length;
|
|
1708
|
-
while (i--) from_parts[i] = "..";
|
|
1709
|
-
return from_parts.concat(to_parts).join("/");
|
|
590
|
+
function escape_unsafe_char(c) {
|
|
591
|
+
return escaped[c] || c;
|
|
1710
592
|
}
|
|
1711
|
-
function
|
|
1712
|
-
|
|
1713
|
-
return globalThis.Buffer.from(bytes).toString("base64");
|
|
1714
|
-
}
|
|
1715
|
-
let binary = "";
|
|
1716
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
1717
|
-
binary += String.fromCharCode(bytes[i]);
|
|
1718
|
-
}
|
|
1719
|
-
return btoa(binary);
|
|
593
|
+
function escape_unsafe_chars(str) {
|
|
594
|
+
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
1720
595
|
}
|
|
1721
|
-
function
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
return
|
|
596
|
+
function safe_key(key) {
|
|
597
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
598
|
+
}
|
|
599
|
+
function safe_prop(key) {
|
|
600
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? `.${key}` : `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
601
|
+
}
|
|
602
|
+
function stringify_primitive$1(thing) {
|
|
603
|
+
const type = typeof thing;
|
|
604
|
+
if (type === "string") return stringify_string(thing);
|
|
605
|
+
if (thing === void 0) return "void 0";
|
|
606
|
+
if (thing === 0 && 1 / thing < 0) return "-0";
|
|
607
|
+
const str = String(thing);
|
|
608
|
+
if (type === "number") return str.replace(/^(-)?0\./, "$1.");
|
|
609
|
+
if (type === "bigint") return thing + "n";
|
|
610
|
+
return str;
|
|
1732
611
|
}
|
|
1733
612
|
|
|
1734
613
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
@@ -1915,266 +794,449 @@ function merge_tracing(event_like, current) {
|
|
|
1915
794
|
};
|
|
1916
795
|
}
|
|
1917
796
|
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
map: false,
|
|
1921
|
-
silent: false,
|
|
1922
|
-
split: "auto", // auto = split strings but not arrays
|
|
1923
|
-
};
|
|
1924
|
-
|
|
1925
|
-
function isForbiddenKey(key) {
|
|
1926
|
-
return typeof key !== "string" || key in {};
|
|
797
|
+
function encode_native(array_buffer) {
|
|
798
|
+
return new Uint8Array(array_buffer).toBase64();
|
|
1927
799
|
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
return Object.create(null);
|
|
800
|
+
function decode_native(base64) {
|
|
801
|
+
return Uint8Array.fromBase64(base64).buffer;
|
|
1931
802
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
return typeof str === "string" && !!str.trim();
|
|
803
|
+
function encode_buffer(array_buffer) {
|
|
804
|
+
return Buffer.from(array_buffer).toString("base64");
|
|
1935
805
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
1939
|
-
|
|
1940
|
-
var nameValuePairStr = parts.shift();
|
|
1941
|
-
if (!nameValuePairStr) {
|
|
1942
|
-
return null;
|
|
1943
|
-
}
|
|
1944
|
-
var parsed = parseNameValuePair(nameValuePairStr);
|
|
1945
|
-
var name = parsed.name;
|
|
1946
|
-
var value = parsed.value;
|
|
1947
|
-
|
|
1948
|
-
options = options
|
|
1949
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
1950
|
-
: defaultParseOptions;
|
|
1951
|
-
|
|
1952
|
-
if (isForbiddenKey(name)) {
|
|
1953
|
-
return null;
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
try {
|
|
1957
|
-
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
1958
|
-
} catch (e) {
|
|
1959
|
-
console.error(
|
|
1960
|
-
"set-cookie-parser: failed to decode cookie value. Set options.decodeValues=false to disable decoding.",
|
|
1961
|
-
e
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
var cookie = createNullObj();
|
|
1966
|
-
cookie.name = name;
|
|
1967
|
-
cookie.value = value;
|
|
1968
|
-
|
|
1969
|
-
parts.forEach(function (part) {
|
|
1970
|
-
var sides = part.split("=");
|
|
1971
|
-
var key = sides.shift().trim().toLowerCase();
|
|
1972
|
-
if (isForbiddenKey(key)) {
|
|
1973
|
-
return;
|
|
1974
|
-
}
|
|
1975
|
-
var value = sides.join("=").trim();
|
|
1976
|
-
if (key === "expires") {
|
|
1977
|
-
cookie.expires = new Date(value);
|
|
1978
|
-
} else if (key === "max-age") {
|
|
1979
|
-
var n = parseInt(value, 10);
|
|
1980
|
-
if (!Number.isNaN(n)) cookie.maxAge = n;
|
|
1981
|
-
} else if (key === "secure") {
|
|
1982
|
-
cookie.secure = true;
|
|
1983
|
-
} else if (key === "httponly") {
|
|
1984
|
-
cookie.httpOnly = true;
|
|
1985
|
-
} else if (key === "samesite") {
|
|
1986
|
-
cookie.sameSite = value;
|
|
1987
|
-
} else if (key === "partitioned") {
|
|
1988
|
-
cookie.partitioned = true;
|
|
1989
|
-
} else if (key) {
|
|
1990
|
-
cookie[key] = value;
|
|
1991
|
-
}
|
|
1992
|
-
});
|
|
1993
|
-
|
|
1994
|
-
return cookie;
|
|
806
|
+
function decode_buffer(base64) {
|
|
807
|
+
return Uint8Array.from(Buffer.from(base64, "base64")).buffer;
|
|
1995
808
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
if (nameValueArr.length > 1) {
|
|
2004
|
-
name = nameValueArr.shift();
|
|
2005
|
-
value = nameValueArr.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
2006
|
-
} else {
|
|
2007
|
-
value = nameValuePairStr;
|
|
809
|
+
function encode_legacy(array_buffer) {
|
|
810
|
+
const array = new Uint8Array(array_buffer);
|
|
811
|
+
let binary = "";
|
|
812
|
+
const chunk_size = 32768;
|
|
813
|
+
for (let i = 0; i < array.length; i += chunk_size) {
|
|
814
|
+
const chunk = array.subarray(i, i + chunk_size);
|
|
815
|
+
binary += String.fromCharCode.apply(null, chunk);
|
|
2008
816
|
}
|
|
2009
|
-
|
|
2010
|
-
return { name: name, value: value };
|
|
817
|
+
return btoa(binary);
|
|
2011
818
|
}
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
if (!input) {
|
|
2019
|
-
if (!options.map) {
|
|
2020
|
-
return [];
|
|
2021
|
-
} else {
|
|
2022
|
-
return createNullObj();
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
if (input.headers) {
|
|
2027
|
-
if (typeof input.headers.getSetCookie === "function") {
|
|
2028
|
-
// for fetch responses - they combine headers of the same type in the headers array,
|
|
2029
|
-
// but getSetCookie returns an uncombined array
|
|
2030
|
-
input = input.headers.getSetCookie();
|
|
2031
|
-
} else if (input.headers["set-cookie"]) {
|
|
2032
|
-
// fast-path for node.js (which automatically normalizes header names to lower-case)
|
|
2033
|
-
input = input.headers["set-cookie"];
|
|
2034
|
-
} else {
|
|
2035
|
-
// slow-path for other environments - see #25
|
|
2036
|
-
var sch =
|
|
2037
|
-
input.headers[
|
|
2038
|
-
Object.keys(input.headers).find(function (key) {
|
|
2039
|
-
return key.toLowerCase() === "set-cookie";
|
|
2040
|
-
})
|
|
2041
|
-
];
|
|
2042
|
-
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
2043
|
-
if (!sch && input.headers.cookie && !options.silent) {
|
|
2044
|
-
console.warn(
|
|
2045
|
-
"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."
|
|
2046
|
-
);
|
|
2047
|
-
}
|
|
2048
|
-
input = sch;
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
|
-
var split = options.split;
|
|
2053
|
-
var isArray = Array.isArray(input);
|
|
2054
|
-
|
|
2055
|
-
if (split === "auto") {
|
|
2056
|
-
split = !isArray;
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
if (!isArray) {
|
|
2060
|
-
input = [input];
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
input = input.filter(isNonEmptyString);
|
|
2064
|
-
|
|
2065
|
-
if (split) {
|
|
2066
|
-
input = input.map(splitCookiesString).flat();
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
if (!options.map) {
|
|
2070
|
-
return input
|
|
2071
|
-
.map(function (str) {
|
|
2072
|
-
return parseString(str, options);
|
|
2073
|
-
})
|
|
2074
|
-
.filter(Boolean);
|
|
2075
|
-
} else {
|
|
2076
|
-
var cookies = createNullObj();
|
|
2077
|
-
return input.reduce(function (cookies, str) {
|
|
2078
|
-
var cookie = parseString(str, options);
|
|
2079
|
-
if (cookie && !isForbiddenKey(cookie.name)) {
|
|
2080
|
-
cookies[cookie.name] = cookie;
|
|
2081
|
-
}
|
|
2082
|
-
return cookies;
|
|
2083
|
-
}, cookies);
|
|
819
|
+
function decode_legacy(base64) {
|
|
820
|
+
const binary_string = atob(base64);
|
|
821
|
+
const len = binary_string.length;
|
|
822
|
+
const array = new Uint8Array(len);
|
|
823
|
+
for (let i = 0; i < len; i++) {
|
|
824
|
+
array[i] = binary_string.charCodeAt(i);
|
|
2084
825
|
}
|
|
826
|
+
return array.buffer;
|
|
2085
827
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
828
|
+
const native = typeof Uint8Array.fromBase64 === "function";
|
|
829
|
+
const buffer = typeof process === "object" && process.versions?.node !== void 0;
|
|
830
|
+
const encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
831
|
+
const decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
832
|
+
function parse(serialized, revivers) {
|
|
833
|
+
return unflatten(JSON.parse(serialized), revivers);
|
|
834
|
+
}
|
|
835
|
+
function unflatten(parsed, revivers) {
|
|
836
|
+
if (typeof parsed === "number") return hydrate(parsed, true);
|
|
837
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
838
|
+
throw new Error("Invalid input");
|
|
839
|
+
}
|
|
840
|
+
const values = (
|
|
841
|
+
/** @type {any[]} */
|
|
842
|
+
parsed
|
|
843
|
+
);
|
|
844
|
+
const hydrated = Array(values.length);
|
|
845
|
+
let hydrating = null;
|
|
846
|
+
function hydrate(index, standalone = false) {
|
|
847
|
+
if (index === UNDEFINED) return void 0;
|
|
848
|
+
if (index === NAN) return NaN;
|
|
849
|
+
if (index === POSITIVE_INFINITY) return Infinity;
|
|
850
|
+
if (index === NEGATIVE_INFINITY) return -Infinity;
|
|
851
|
+
if (index === NEGATIVE_ZERO) return -0;
|
|
852
|
+
if (standalone || typeof index !== "number") {
|
|
853
|
+
throw new Error(`Invalid input`);
|
|
854
|
+
}
|
|
855
|
+
if (index in hydrated) return hydrated[index];
|
|
856
|
+
const value = values[index];
|
|
857
|
+
if (!value || typeof value !== "object") {
|
|
858
|
+
hydrated[index] = value;
|
|
859
|
+
} else if (Array.isArray(value)) {
|
|
860
|
+
if (typeof value[0] === "string") {
|
|
861
|
+
const type = value[0];
|
|
862
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
863
|
+
if (reviver) {
|
|
864
|
+
let i = value[1];
|
|
865
|
+
if (typeof i !== "number") {
|
|
866
|
+
i = values.push(value[1]) - 1;
|
|
867
|
+
}
|
|
868
|
+
hydrating ??= /* @__PURE__ */ new Set();
|
|
869
|
+
if (hydrating.has(i)) {
|
|
870
|
+
throw new Error("Invalid circular reference");
|
|
871
|
+
}
|
|
872
|
+
hydrating.add(i);
|
|
873
|
+
hydrated[index] = reviver(hydrate(i));
|
|
874
|
+
hydrating.delete(i);
|
|
875
|
+
return hydrated[index];
|
|
876
|
+
}
|
|
877
|
+
switch (type) {
|
|
878
|
+
case "Date":
|
|
879
|
+
hydrated[index] = new Date(value[1]);
|
|
880
|
+
break;
|
|
881
|
+
case "Set":
|
|
882
|
+
const set = /* @__PURE__ */ new Set();
|
|
883
|
+
hydrated[index] = set;
|
|
884
|
+
for (let i = 1; i < value.length; i += 1) {
|
|
885
|
+
set.add(hydrate(value[i]));
|
|
886
|
+
}
|
|
887
|
+
break;
|
|
888
|
+
case "Map":
|
|
889
|
+
const map = /* @__PURE__ */ new Map();
|
|
890
|
+
hydrated[index] = map;
|
|
891
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
892
|
+
map.set(hydrate(value[i]), hydrate(value[i + 1]));
|
|
893
|
+
}
|
|
894
|
+
break;
|
|
895
|
+
case "RegExp":
|
|
896
|
+
hydrated[index] = new RegExp(value[1], value[2]);
|
|
897
|
+
break;
|
|
898
|
+
case "Object": {
|
|
899
|
+
const wrapped_index = value[1];
|
|
900
|
+
if (typeof values[wrapped_index] === "object" && values[wrapped_index][0] !== "BigInt") {
|
|
901
|
+
throw new Error("Invalid input");
|
|
902
|
+
}
|
|
903
|
+
hydrated[index] = Object(hydrate(wrapped_index));
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
case "BigInt":
|
|
907
|
+
hydrated[index] = BigInt(value[1]);
|
|
908
|
+
break;
|
|
909
|
+
case "null":
|
|
910
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
911
|
+
hydrated[index] = obj;
|
|
912
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
913
|
+
if (value[i] === "__proto__") {
|
|
914
|
+
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
915
|
+
}
|
|
916
|
+
obj[value[i]] = hydrate(value[i + 1]);
|
|
917
|
+
}
|
|
918
|
+
break;
|
|
919
|
+
case "Int8Array":
|
|
920
|
+
case "Uint8Array":
|
|
921
|
+
case "Uint8ClampedArray":
|
|
922
|
+
case "Int16Array":
|
|
923
|
+
case "Uint16Array":
|
|
924
|
+
case "Float16Array":
|
|
925
|
+
case "Int32Array":
|
|
926
|
+
case "Uint32Array":
|
|
927
|
+
case "Float32Array":
|
|
928
|
+
case "Float64Array":
|
|
929
|
+
case "BigInt64Array":
|
|
930
|
+
case "BigUint64Array":
|
|
931
|
+
case "DataView": {
|
|
932
|
+
if (values[value[1]][0] !== "ArrayBuffer") {
|
|
933
|
+
throw new Error("Invalid data");
|
|
934
|
+
}
|
|
935
|
+
const TypedArrayConstructor = globalThis[type];
|
|
936
|
+
const buffer2 = hydrate(value[1]);
|
|
937
|
+
hydrated[index] = value[2] !== void 0 ? new TypedArrayConstructor(buffer2, value[2], value[3]) : new TypedArrayConstructor(buffer2);
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
case "ArrayBuffer": {
|
|
941
|
+
const base64 = value[1];
|
|
942
|
+
if (typeof base64 !== "string") {
|
|
943
|
+
throw new Error("Invalid ArrayBuffer encoding");
|
|
944
|
+
}
|
|
945
|
+
const arraybuffer = decode64(base64);
|
|
946
|
+
hydrated[index] = arraybuffer;
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
case "Temporal.Duration":
|
|
950
|
+
case "Temporal.Instant":
|
|
951
|
+
case "Temporal.PlainDate":
|
|
952
|
+
case "Temporal.PlainTime":
|
|
953
|
+
case "Temporal.PlainDateTime":
|
|
954
|
+
case "Temporal.PlainMonthDay":
|
|
955
|
+
case "Temporal.PlainYearMonth":
|
|
956
|
+
case "Temporal.ZonedDateTime": {
|
|
957
|
+
const temporalName = type.slice(9);
|
|
958
|
+
hydrated[index] = Temporal[temporalName].from(value[1]);
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
case "URL": {
|
|
962
|
+
const url = new URL(value[1]);
|
|
963
|
+
hydrated[index] = url;
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
case "URLSearchParams": {
|
|
967
|
+
const url = new URLSearchParams(value[1]);
|
|
968
|
+
hydrated[index] = url;
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
default:
|
|
972
|
+
throw new Error(`Unknown type ${type}`);
|
|
973
|
+
}
|
|
974
|
+
} else if (value[0] === SPARSE) {
|
|
975
|
+
const len = value[1];
|
|
976
|
+
if (!is_valid_array_len(len)) {
|
|
977
|
+
throw new Error("Invalid input");
|
|
978
|
+
}
|
|
979
|
+
const array = [];
|
|
980
|
+
hydrated[index] = array;
|
|
981
|
+
array[MAX_ARRAY_INDEX] = void 0;
|
|
982
|
+
delete array[MAX_ARRAY_INDEX];
|
|
983
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
984
|
+
const idx = value[i];
|
|
985
|
+
if (!is_valid_array_index(idx) || idx >= len) {
|
|
986
|
+
throw new Error("Invalid input");
|
|
987
|
+
}
|
|
988
|
+
array[idx] = hydrate(value[i + 1]);
|
|
2157
989
|
}
|
|
990
|
+
array.length = len;
|
|
2158
991
|
} else {
|
|
2159
|
-
|
|
992
|
+
const array = new Array(value.length);
|
|
993
|
+
hydrated[index] = array;
|
|
994
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
995
|
+
const n = value[i];
|
|
996
|
+
if (n === HOLE) continue;
|
|
997
|
+
array[i] = hydrate(n);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
} else {
|
|
1001
|
+
const object = {};
|
|
1002
|
+
hydrated[index] = object;
|
|
1003
|
+
for (const key of Object.keys(value)) {
|
|
1004
|
+
if (key === "__proto__") {
|
|
1005
|
+
throw new Error("Cannot parse an object with a `__proto__` property");
|
|
1006
|
+
}
|
|
1007
|
+
const n = value[key];
|
|
1008
|
+
object[key] = hydrate(n);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
return hydrated[index];
|
|
1012
|
+
}
|
|
1013
|
+
return hydrate(0);
|
|
1014
|
+
}
|
|
1015
|
+
function stringify$1(value, reducers) {
|
|
1016
|
+
const stringified = run(false, value, reducers);
|
|
1017
|
+
return typeof stringified === "string" ? stringified : `[${stringified.join(",")}]`;
|
|
1018
|
+
}
|
|
1019
|
+
function run(async, value, reducers) {
|
|
1020
|
+
const stringified = [];
|
|
1021
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
1022
|
+
const custom = [];
|
|
1023
|
+
if (reducers) {
|
|
1024
|
+
for (const key of Object.getOwnPropertyNames(reducers)) {
|
|
1025
|
+
custom.push({ key, fn: reducers[key] });
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
const keys = [];
|
|
1029
|
+
let p = 0;
|
|
1030
|
+
function flatten(thing, index2) {
|
|
1031
|
+
if (thing === void 0) return UNDEFINED;
|
|
1032
|
+
if (Number.isNaN(thing)) return NAN;
|
|
1033
|
+
if (thing === Infinity) return POSITIVE_INFINITY;
|
|
1034
|
+
if (thing === -Infinity) return NEGATIVE_INFINITY;
|
|
1035
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
|
|
1036
|
+
if (indexes.has(thing)) return (
|
|
1037
|
+
/** @type {number} */
|
|
1038
|
+
indexes.get(thing)
|
|
1039
|
+
);
|
|
1040
|
+
index2 ??= p++;
|
|
1041
|
+
indexes.set(thing, index2);
|
|
1042
|
+
for (const { key, fn } of custom) {
|
|
1043
|
+
const value2 = fn(thing);
|
|
1044
|
+
if (value2) {
|
|
1045
|
+
stringified[index2] = `["${key}",${flatten(value2)}]`;
|
|
1046
|
+
return index2;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (typeof thing === "function") {
|
|
1050
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
1051
|
+
} else if (typeof thing === "symbol") {
|
|
1052
|
+
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
1053
|
+
}
|
|
1054
|
+
let str = "";
|
|
1055
|
+
if (is_primitive(thing)) {
|
|
1056
|
+
str = stringify_primitive(thing);
|
|
1057
|
+
} else if (typeof thing.then === "function") {
|
|
1058
|
+
{
|
|
1059
|
+
throw new DevalueError(
|
|
1060
|
+
`Cannot stringify a Promise or thenable — use stringifyAsync instead`,
|
|
1061
|
+
keys,
|
|
1062
|
+
thing,
|
|
1063
|
+
value
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
} else {
|
|
1067
|
+
const type = get_type(thing);
|
|
1068
|
+
switch (type) {
|
|
1069
|
+
case "Number":
|
|
1070
|
+
case "String":
|
|
1071
|
+
case "Boolean":
|
|
1072
|
+
case "BigInt":
|
|
1073
|
+
str = `["Object",${flatten(thing.valueOf())}]`;
|
|
1074
|
+
break;
|
|
1075
|
+
case "Date":
|
|
1076
|
+
const valid = !isNaN(thing.getDate());
|
|
1077
|
+
str = `["Date","${valid ? thing.toISOString() : ""}"]`;
|
|
1078
|
+
break;
|
|
1079
|
+
case "URL":
|
|
1080
|
+
str = `["URL",${stringify_string(thing.toString())}]`;
|
|
1081
|
+
break;
|
|
1082
|
+
case "URLSearchParams":
|
|
1083
|
+
str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
|
|
1084
|
+
break;
|
|
1085
|
+
case "RegExp":
|
|
1086
|
+
const { source, flags } = thing;
|
|
1087
|
+
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
1088
|
+
break;
|
|
1089
|
+
case "Array": {
|
|
1090
|
+
let mostly_dense = false;
|
|
1091
|
+
str = "[";
|
|
1092
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
1093
|
+
if (i > 0) str += ",";
|
|
1094
|
+
if (Object.hasOwn(thing, i)) {
|
|
1095
|
+
keys.push(`[${i}]`);
|
|
1096
|
+
str += flatten(thing[i]);
|
|
1097
|
+
keys.pop();
|
|
1098
|
+
} else if (mostly_dense) {
|
|
1099
|
+
str += HOLE;
|
|
1100
|
+
} else {
|
|
1101
|
+
const populated_keys = valid_array_indices(
|
|
1102
|
+
/** @type {any[]} */
|
|
1103
|
+
thing
|
|
1104
|
+
);
|
|
1105
|
+
const population = populated_keys.length;
|
|
1106
|
+
const d = String(thing.length).length;
|
|
1107
|
+
const hole_cost = (thing.length - population) * 3;
|
|
1108
|
+
const sparse_cost = 4 + d + population * (d + 1);
|
|
1109
|
+
if (hole_cost > sparse_cost) {
|
|
1110
|
+
str = "[" + SPARSE + "," + thing.length;
|
|
1111
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
1112
|
+
const key = populated_keys[j];
|
|
1113
|
+
keys.push(`[${key}]`);
|
|
1114
|
+
str += "," + key + "," + flatten(thing[key]);
|
|
1115
|
+
keys.pop();
|
|
1116
|
+
}
|
|
1117
|
+
break;
|
|
1118
|
+
} else {
|
|
1119
|
+
mostly_dense = true;
|
|
1120
|
+
str += HOLE;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
str += "]";
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
case "Set":
|
|
1128
|
+
str = '["Set"';
|
|
1129
|
+
for (const value2 of thing) {
|
|
1130
|
+
str += `,${flatten(value2)}`;
|
|
1131
|
+
}
|
|
1132
|
+
str += "]";
|
|
1133
|
+
break;
|
|
1134
|
+
case "Map":
|
|
1135
|
+
str = '["Map"';
|
|
1136
|
+
for (const [key, value2] of thing) {
|
|
1137
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
|
|
1138
|
+
str += `,${flatten(key)},${flatten(value2)}`;
|
|
1139
|
+
keys.pop();
|
|
1140
|
+
}
|
|
1141
|
+
str += "]";
|
|
1142
|
+
break;
|
|
1143
|
+
case "Int8Array":
|
|
1144
|
+
case "Uint8Array":
|
|
1145
|
+
case "Uint8ClampedArray":
|
|
1146
|
+
case "Int16Array":
|
|
1147
|
+
case "Uint16Array":
|
|
1148
|
+
case "Float16Array":
|
|
1149
|
+
case "Int32Array":
|
|
1150
|
+
case "Uint32Array":
|
|
1151
|
+
case "Float32Array":
|
|
1152
|
+
case "Float64Array":
|
|
1153
|
+
case "BigInt64Array":
|
|
1154
|
+
case "BigUint64Array":
|
|
1155
|
+
case "DataView": {
|
|
1156
|
+
const typedArray = thing;
|
|
1157
|
+
str = '["' + type + '",' + flatten(typedArray.buffer);
|
|
1158
|
+
if (typedArray.byteLength !== typedArray.buffer.byteLength) {
|
|
1159
|
+
str += `,${typedArray.byteOffset},${typedArray.length}`;
|
|
1160
|
+
}
|
|
1161
|
+
str += "]";
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
case "ArrayBuffer": {
|
|
1165
|
+
const arraybuffer = thing;
|
|
1166
|
+
const base64 = encode64(arraybuffer);
|
|
1167
|
+
str = `["ArrayBuffer","${base64}"]`;
|
|
1168
|
+
break;
|
|
1169
|
+
}
|
|
1170
|
+
case "Temporal.Duration":
|
|
1171
|
+
case "Temporal.Instant":
|
|
1172
|
+
case "Temporal.PlainDate":
|
|
1173
|
+
case "Temporal.PlainTime":
|
|
1174
|
+
case "Temporal.PlainDateTime":
|
|
1175
|
+
case "Temporal.PlainMonthDay":
|
|
1176
|
+
case "Temporal.PlainYearMonth":
|
|
1177
|
+
case "Temporal.ZonedDateTime":
|
|
1178
|
+
str = `["${type}",${stringify_string(thing.toString())}]`;
|
|
1179
|
+
break;
|
|
1180
|
+
default:
|
|
1181
|
+
if (!is_plain_object(thing)) {
|
|
1182
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
1183
|
+
}
|
|
1184
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
1185
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
1186
|
+
}
|
|
1187
|
+
if (Object.getPrototypeOf(thing) === null) {
|
|
1188
|
+
str = '["null"';
|
|
1189
|
+
for (const key of Object.keys(thing)) {
|
|
1190
|
+
if (key === "__proto__") {
|
|
1191
|
+
throw new DevalueError(
|
|
1192
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1193
|
+
keys,
|
|
1194
|
+
thing,
|
|
1195
|
+
value
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
keys.push(stringify_key(key));
|
|
1199
|
+
str += `,${stringify_string(key)},${flatten(thing[key])}`;
|
|
1200
|
+
keys.pop();
|
|
1201
|
+
}
|
|
1202
|
+
str += "]";
|
|
1203
|
+
} else {
|
|
1204
|
+
str = "{";
|
|
1205
|
+
let started = false;
|
|
1206
|
+
for (const key of Object.keys(thing)) {
|
|
1207
|
+
if (key === "__proto__") {
|
|
1208
|
+
throw new DevalueError(
|
|
1209
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
1210
|
+
keys,
|
|
1211
|
+
thing,
|
|
1212
|
+
value
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
if (started) str += ",";
|
|
1216
|
+
started = true;
|
|
1217
|
+
keys.push(stringify_key(key));
|
|
1218
|
+
str += `${stringify_string(key)}:${flatten(thing[key])}`;
|
|
1219
|
+
keys.pop();
|
|
1220
|
+
}
|
|
1221
|
+
str += "}";
|
|
1222
|
+
}
|
|
2160
1223
|
}
|
|
2161
1224
|
}
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
2165
|
-
}
|
|
1225
|
+
stringified[index2] = str;
|
|
1226
|
+
return index2;
|
|
2166
1227
|
}
|
|
2167
|
-
|
|
2168
|
-
return
|
|
1228
|
+
const index = flatten(value);
|
|
1229
|
+
if (index < 0) return `${index}`;
|
|
1230
|
+
return stringified;
|
|
1231
|
+
}
|
|
1232
|
+
function stringify_primitive(thing) {
|
|
1233
|
+
const type = typeof thing;
|
|
1234
|
+
if (type === "string") return stringify_string(thing);
|
|
1235
|
+
if (thing === void 0) return UNDEFINED.toString();
|
|
1236
|
+
if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
|
|
1237
|
+
if (type === "bigint") return `["BigInt","${thing}"]`;
|
|
1238
|
+
return String(thing);
|
|
2169
1239
|
}
|
|
2170
|
-
|
|
2171
|
-
// named export for CJS
|
|
2172
|
-
parseSetCookie.parseSetCookie = parseSetCookie;
|
|
2173
|
-
// for backwards compatibility
|
|
2174
|
-
parseSetCookie.parse = parseSetCookie;
|
|
2175
|
-
parseSetCookie.parseString = parseString;
|
|
2176
|
-
parseSetCookie.splitCookiesString = splitCookiesString;
|
|
2177
|
-
|
|
2178
1240
|
const SVELTE_KIT_ASSETS = "/_svelte_kit_assets";
|
|
2179
1241
|
const ENDPOINT_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
2180
1242
|
const PAGE_METHODS = ["GET", "POST", "HEAD"];
|
|
@@ -2279,13 +1341,13 @@ async function deserialize_binary_form(request) {
|
|
|
2279
1341
|
chunks2.push(chunk);
|
|
2280
1342
|
cursor += chunk.byteLength;
|
|
2281
1343
|
}
|
|
2282
|
-
const
|
|
1344
|
+
const buffer2 = new Uint8Array(length);
|
|
2283
1345
|
cursor = 0;
|
|
2284
1346
|
for (const chunk of chunks2) {
|
|
2285
|
-
|
|
1347
|
+
buffer2.set(chunk, cursor);
|
|
2286
1348
|
cursor += chunk.byteLength;
|
|
2287
1349
|
}
|
|
2288
|
-
return
|
|
1350
|
+
return buffer2;
|
|
2289
1351
|
}
|
|
2290
1352
|
const header = await get_buffer(0, HEADER_BYTES);
|
|
2291
1353
|
if (!header) throw deserialize_error("too short");
|
|
@@ -2542,76 +1604,266 @@ function create_remote_arg_revivers(transport) {
|
|
|
2542
1604
|
if (!Array.isArray(value)) {
|
|
2543
1605
|
throw new Error("Invalid data for Set reviver");
|
|
2544
1606
|
}
|
|
2545
|
-
const set = /* @__PURE__ */ new Set();
|
|
2546
|
-
for (const item of value) {
|
|
2547
|
-
if (typeof item !== "string") {
|
|
2548
|
-
throw new Error("Invalid data for Set reviver");
|
|
1607
|
+
const set = /* @__PURE__ */ new Set();
|
|
1608
|
+
for (const item of value) {
|
|
1609
|
+
if (typeof item !== "string") {
|
|
1610
|
+
throw new Error("Invalid data for Set reviver");
|
|
1611
|
+
}
|
|
1612
|
+
set.add(parse$1(item));
|
|
1613
|
+
}
|
|
1614
|
+
return set;
|
|
1615
|
+
},
|
|
1616
|
+
/** @type {(value: any) => File} */
|
|
1617
|
+
[remote_file]: (value) => {
|
|
1618
|
+
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)) {
|
|
1619
|
+
throw new Error("Invalid data for File reviver");
|
|
1620
|
+
}
|
|
1621
|
+
const { data, name, ...meta } = value;
|
|
1622
|
+
return new File([data], name, meta);
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
const user_revivers = Object.fromEntries(
|
|
1626
|
+
Object.entries(transport).map(([k, v]) => [k, v.decode])
|
|
1627
|
+
);
|
|
1628
|
+
const all_revivers = { ...user_revivers, ...remote_fns_revivers };
|
|
1629
|
+
const parse$1 = (data) => parse(data, all_revivers);
|
|
1630
|
+
return all_revivers;
|
|
1631
|
+
}
|
|
1632
|
+
function parse_remote_arg(string, transport) {
|
|
1633
|
+
if (!string) return void 0;
|
|
1634
|
+
const json_string = new TextDecoder().decode(
|
|
1635
|
+
// no need to add back `=` characters, atob can handle it
|
|
1636
|
+
base64_decode(string.replaceAll("-", "+").replaceAll("_", "/"))
|
|
1637
|
+
);
|
|
1638
|
+
return parse(json_string, create_remote_arg_revivers(transport));
|
|
1639
|
+
}
|
|
1640
|
+
function create_remote_key(id, payload) {
|
|
1641
|
+
return id + "/" + payload;
|
|
1642
|
+
}
|
|
1643
|
+
function split_remote_key(key) {
|
|
1644
|
+
const i = key.lastIndexOf("/");
|
|
1645
|
+
if (i === -1) {
|
|
1646
|
+
throw new Error(`Invalid remote key: ${key}`);
|
|
1647
|
+
}
|
|
1648
|
+
return {
|
|
1649
|
+
id: key.slice(0, i),
|
|
1650
|
+
payload: key.slice(i + 1)
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function coalesce_to_error(err) {
|
|
1654
|
+
return err instanceof Error || err && /** @type {any} */
|
|
1655
|
+
err.name && /** @type {any} */
|
|
1656
|
+
err.message ? (
|
|
1657
|
+
/** @type {Error} */
|
|
1658
|
+
err
|
|
1659
|
+
) : new Error(JSON.stringify(err));
|
|
1660
|
+
}
|
|
1661
|
+
function normalize_error(error) {
|
|
1662
|
+
return (
|
|
1663
|
+
/** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
1664
|
+
error
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
function get_status(error) {
|
|
1668
|
+
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
1669
|
+
}
|
|
1670
|
+
function get_message(error) {
|
|
1671
|
+
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
|
1672
|
+
}
|
|
1673
|
+
var defaultParseOptions = {
|
|
1674
|
+
decodeValues: true,
|
|
1675
|
+
map: false,
|
|
1676
|
+
silent: false,
|
|
1677
|
+
split: "auto"
|
|
1678
|
+
// auto = split strings but not arrays
|
|
1679
|
+
};
|
|
1680
|
+
function isForbiddenKey(key) {
|
|
1681
|
+
return typeof key !== "string" || key in {};
|
|
1682
|
+
}
|
|
1683
|
+
function createNullObj() {
|
|
1684
|
+
return /* @__PURE__ */ Object.create(null);
|
|
1685
|
+
}
|
|
1686
|
+
function isNonEmptyString(str) {
|
|
1687
|
+
return typeof str === "string" && !!str.trim();
|
|
1688
|
+
}
|
|
1689
|
+
function parseString(setCookieValue, options) {
|
|
1690
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
1691
|
+
var nameValuePairStr = parts.shift();
|
|
1692
|
+
if (!nameValuePairStr) {
|
|
1693
|
+
return null;
|
|
1694
|
+
}
|
|
1695
|
+
var parsed = parseNameValuePair(nameValuePairStr);
|
|
1696
|
+
var name = parsed.name;
|
|
1697
|
+
var value = parsed.value;
|
|
1698
|
+
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
1699
|
+
if (isForbiddenKey(name)) {
|
|
1700
|
+
return null;
|
|
1701
|
+
}
|
|
1702
|
+
try {
|
|
1703
|
+
value = options.decodeValues ? decodeURIComponent(value) : value;
|
|
1704
|
+
} catch (e) {
|
|
1705
|
+
console.error(
|
|
1706
|
+
"set-cookie-parser: failed to decode cookie value. Set options.decodeValues=false to disable decoding.",
|
|
1707
|
+
e
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1710
|
+
var cookie = createNullObj();
|
|
1711
|
+
cookie.name = name;
|
|
1712
|
+
cookie.value = value;
|
|
1713
|
+
parts.forEach(function(part) {
|
|
1714
|
+
var sides = part.split("=");
|
|
1715
|
+
var key = sides.shift().trim().toLowerCase();
|
|
1716
|
+
if (isForbiddenKey(key)) {
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
var value2 = sides.join("=").trim();
|
|
1720
|
+
if (key === "expires") {
|
|
1721
|
+
cookie.expires = new Date(value2);
|
|
1722
|
+
} else if (key === "max-age") {
|
|
1723
|
+
var n = parseInt(value2, 10);
|
|
1724
|
+
if (!Number.isNaN(n)) cookie.maxAge = n;
|
|
1725
|
+
} else if (key === "secure") {
|
|
1726
|
+
cookie.secure = true;
|
|
1727
|
+
} else if (key === "httponly") {
|
|
1728
|
+
cookie.httpOnly = true;
|
|
1729
|
+
} else if (key === "samesite") {
|
|
1730
|
+
cookie.sameSite = value2;
|
|
1731
|
+
} else if (key === "partitioned") {
|
|
1732
|
+
cookie.partitioned = true;
|
|
1733
|
+
} else if (key) {
|
|
1734
|
+
cookie[key] = value2;
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
return cookie;
|
|
1738
|
+
}
|
|
1739
|
+
function parseNameValuePair(nameValuePairStr) {
|
|
1740
|
+
var name = "";
|
|
1741
|
+
var value = "";
|
|
1742
|
+
var nameValueArr = nameValuePairStr.split("=");
|
|
1743
|
+
if (nameValueArr.length > 1) {
|
|
1744
|
+
name = nameValueArr.shift();
|
|
1745
|
+
value = nameValueArr.join("=");
|
|
1746
|
+
} else {
|
|
1747
|
+
value = nameValuePairStr;
|
|
1748
|
+
}
|
|
1749
|
+
return { name, value };
|
|
1750
|
+
}
|
|
1751
|
+
function parseSetCookie(input, options) {
|
|
1752
|
+
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
1753
|
+
if (!input) {
|
|
1754
|
+
if (!options.map) {
|
|
1755
|
+
return [];
|
|
1756
|
+
} else {
|
|
1757
|
+
return createNullObj();
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
if (input.headers) {
|
|
1761
|
+
if (typeof input.headers.getSetCookie === "function") {
|
|
1762
|
+
input = input.headers.getSetCookie();
|
|
1763
|
+
} else if (input.headers["set-cookie"]) {
|
|
1764
|
+
input = input.headers["set-cookie"];
|
|
1765
|
+
} else {
|
|
1766
|
+
var sch = input.headers[Object.keys(input.headers).find(function(key) {
|
|
1767
|
+
return key.toLowerCase() === "set-cookie";
|
|
1768
|
+
})];
|
|
1769
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
1770
|
+
console.warn(
|
|
1771
|
+
"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."
|
|
1772
|
+
);
|
|
1773
|
+
}
|
|
1774
|
+
input = sch;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
var split = options.split;
|
|
1778
|
+
var isArray = Array.isArray(input);
|
|
1779
|
+
if (split === "auto") {
|
|
1780
|
+
split = !isArray;
|
|
1781
|
+
}
|
|
1782
|
+
if (!isArray) {
|
|
1783
|
+
input = [input];
|
|
1784
|
+
}
|
|
1785
|
+
input = input.filter(isNonEmptyString);
|
|
1786
|
+
if (split) {
|
|
1787
|
+
input = input.map(splitCookiesString).flat();
|
|
1788
|
+
}
|
|
1789
|
+
if (!options.map) {
|
|
1790
|
+
return input.map(function(str) {
|
|
1791
|
+
return parseString(str, options);
|
|
1792
|
+
}).filter(Boolean);
|
|
1793
|
+
} else {
|
|
1794
|
+
var cookies = createNullObj();
|
|
1795
|
+
return input.reduce(function(cookies2, str) {
|
|
1796
|
+
var cookie = parseString(str, options);
|
|
1797
|
+
if (cookie && !isForbiddenKey(cookie.name)) {
|
|
1798
|
+
cookies2[cookie.name] = cookie;
|
|
1799
|
+
}
|
|
1800
|
+
return cookies2;
|
|
1801
|
+
}, cookies);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
function splitCookiesString(cookiesString) {
|
|
1805
|
+
if (Array.isArray(cookiesString)) {
|
|
1806
|
+
return cookiesString;
|
|
1807
|
+
}
|
|
1808
|
+
if (typeof cookiesString !== "string") {
|
|
1809
|
+
return [];
|
|
1810
|
+
}
|
|
1811
|
+
var cookiesStrings = [];
|
|
1812
|
+
var pos = 0;
|
|
1813
|
+
var start;
|
|
1814
|
+
var ch;
|
|
1815
|
+
var lastComma;
|
|
1816
|
+
var nextStart;
|
|
1817
|
+
var cookiesSeparatorFound;
|
|
1818
|
+
function skipWhitespace() {
|
|
1819
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
1820
|
+
pos += 1;
|
|
1821
|
+
}
|
|
1822
|
+
return pos < cookiesString.length;
|
|
1823
|
+
}
|
|
1824
|
+
function notSpecialChar() {
|
|
1825
|
+
ch = cookiesString.charAt(pos);
|
|
1826
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
1827
|
+
}
|
|
1828
|
+
while (pos < cookiesString.length) {
|
|
1829
|
+
start = pos;
|
|
1830
|
+
cookiesSeparatorFound = false;
|
|
1831
|
+
while (skipWhitespace()) {
|
|
1832
|
+
ch = cookiesString.charAt(pos);
|
|
1833
|
+
if (ch === ",") {
|
|
1834
|
+
lastComma = pos;
|
|
1835
|
+
pos += 1;
|
|
1836
|
+
skipWhitespace();
|
|
1837
|
+
nextStart = pos;
|
|
1838
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
1839
|
+
pos += 1;
|
|
2549
1840
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
1841
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
1842
|
+
cookiesSeparatorFound = true;
|
|
1843
|
+
pos = nextStart;
|
|
1844
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
1845
|
+
start = pos;
|
|
1846
|
+
} else {
|
|
1847
|
+
pos = lastComma + 1;
|
|
1848
|
+
}
|
|
1849
|
+
} else {
|
|
1850
|
+
pos += 1;
|
|
2558
1851
|
}
|
|
2559
|
-
const { data, name, ...meta } = value;
|
|
2560
|
-
return new File([data], name, meta);
|
|
2561
1852
|
}
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
);
|
|
2566
|
-
const all_revivers = { ...user_revivers, ...remote_fns_revivers };
|
|
2567
|
-
const parse$1 = (data) => parse(data, all_revivers);
|
|
2568
|
-
return all_revivers;
|
|
2569
|
-
}
|
|
2570
|
-
function parse_remote_arg(string, transport) {
|
|
2571
|
-
if (!string) return void 0;
|
|
2572
|
-
const json_string = new TextDecoder().decode(
|
|
2573
|
-
// no need to add back `=` characters, atob can handle it
|
|
2574
|
-
base64_decode(string.replaceAll("-", "+").replaceAll("_", "/"))
|
|
2575
|
-
);
|
|
2576
|
-
return parse(json_string, create_remote_arg_revivers(transport));
|
|
2577
|
-
}
|
|
2578
|
-
function create_remote_key(id, payload) {
|
|
2579
|
-
return id + "/" + payload;
|
|
2580
|
-
}
|
|
2581
|
-
function split_remote_key(key) {
|
|
2582
|
-
const i = key.lastIndexOf("/");
|
|
2583
|
-
if (i === -1) {
|
|
2584
|
-
throw new Error(`Invalid remote key: ${key}`);
|
|
1853
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
1854
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
1855
|
+
}
|
|
2585
1856
|
}
|
|
2586
|
-
return
|
|
2587
|
-
id: key.slice(0, i),
|
|
2588
|
-
payload: key.slice(i + 1)
|
|
2589
|
-
};
|
|
2590
|
-
}
|
|
2591
|
-
function coalesce_to_error(err) {
|
|
2592
|
-
return err instanceof Error || err && /** @type {any} */
|
|
2593
|
-
err.name && /** @type {any} */
|
|
2594
|
-
err.message ? (
|
|
2595
|
-
/** @type {Error} */
|
|
2596
|
-
err
|
|
2597
|
-
) : new Error(JSON.stringify(err));
|
|
2598
|
-
}
|
|
2599
|
-
function normalize_error(error) {
|
|
2600
|
-
return (
|
|
2601
|
-
/** @type {import('../exports/internal/index.js').Redirect | HttpError | SvelteKitError | Error} */
|
|
2602
|
-
error
|
|
2603
|
-
);
|
|
2604
|
-
}
|
|
2605
|
-
function get_status(error) {
|
|
2606
|
-
return error instanceof HttpError || error instanceof SvelteKitError ? error.status : 500;
|
|
2607
|
-
}
|
|
2608
|
-
function get_message(error) {
|
|
2609
|
-
return error instanceof SvelteKitError ? error.text : "Internal Error";
|
|
1857
|
+
return cookiesStrings;
|
|
2610
1858
|
}
|
|
1859
|
+
parseSetCookie.parseSetCookie = parseSetCookie;
|
|
1860
|
+
parseSetCookie.parse = parseSetCookie;
|
|
1861
|
+
parseSetCookie.parseString = parseString;
|
|
1862
|
+
parseSetCookie.splitCookiesString = splitCookiesString;
|
|
2611
1863
|
function negotiate(accept, types) {
|
|
2612
1864
|
const parts = [];
|
|
2613
1865
|
accept.split(",").forEach((str, i) => {
|
|
2614
|
-
const match =
|
|
1866
|
+
const match = /^[ \t]*([^/ \t]+)\/([^; \t]+)[ \t]*(?:;[ \t]*q=([0-9.]+))?/.exec(str);
|
|
2615
1867
|
if (match) {
|
|
2616
1868
|
const [, type, subtype, q = "1"] = match;
|
|
2617
1869
|
parts.push({ type, subtype, q: +q, i });
|
|
@@ -2812,8 +2064,6 @@ function create_replacer(transport) {
|
|
|
2812
2064
|
return replacer;
|
|
2813
2065
|
}
|
|
2814
2066
|
|
|
2815
|
-
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx$1(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
2816
|
-
|
|
2817
2067
|
const DERIVED = 1 << 1;
|
|
2818
2068
|
const EFFECT = 1 << 2;
|
|
2819
2069
|
const RENDER_EFFECT = 1 << 3;
|
|
@@ -4108,7 +3358,7 @@ class Batch {
|
|
|
4108
3358
|
if (this.#roots.length > 0) {
|
|
4109
3359
|
if (next_batch !== null) {
|
|
4110
3360
|
const batch2 = next_batch;
|
|
4111
|
-
batch2.#roots.push(...this.#roots.filter((
|
|
3361
|
+
batch2.#roots.push(...this.#roots.filter((r2) => !batch2.#roots.includes(r2)));
|
|
4112
3362
|
} else {
|
|
4113
3363
|
next_batch = this;
|
|
4114
3364
|
}
|
|
@@ -5812,6 +5062,19 @@ function escape_html(value, is_attr) {
|
|
|
5812
5062
|
}
|
|
5813
5063
|
return escaped + str.substring(last);
|
|
5814
5064
|
}
|
|
5065
|
+
function r(e) {
|
|
5066
|
+
var t, f, n = "";
|
|
5067
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
5068
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
5069
|
+
var o = e.length;
|
|
5070
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
5071
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
5072
|
+
return n;
|
|
5073
|
+
}
|
|
5074
|
+
function clsx$1() {
|
|
5075
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
5076
|
+
return n;
|
|
5077
|
+
}
|
|
5815
5078
|
const replacements$1 = {
|
|
5816
5079
|
translate: /* @__PURE__ */ new Map([
|
|
5817
5080
|
[true, "yes"],
|
|
@@ -6345,14 +5608,14 @@ class Renderer {
|
|
|
6345
5608
|
};
|
|
6346
5609
|
if (typeof body === "function") {
|
|
6347
5610
|
this.child((renderer) => {
|
|
6348
|
-
const
|
|
6349
|
-
body(
|
|
5611
|
+
const r2 = new Renderer(this.global, this);
|
|
5612
|
+
body(r2);
|
|
6350
5613
|
if (this.global.mode === "async") {
|
|
6351
|
-
return
|
|
5614
|
+
return r2.#collect_content_async().then((content) => {
|
|
6352
5615
|
close(renderer, content.body.replaceAll("<!---->", ""), content);
|
|
6353
5616
|
});
|
|
6354
5617
|
} else {
|
|
6355
|
-
const content =
|
|
5618
|
+
const content = r2.#collect_content();
|
|
6356
5619
|
close(renderer, content.body.replaceAll("<!---->", ""), content);
|
|
6357
5620
|
}
|
|
6358
5621
|
});
|
|
@@ -6369,14 +5632,14 @@ class Renderer {
|
|
|
6369
5632
|
this.global.set_title(head, path);
|
|
6370
5633
|
};
|
|
6371
5634
|
this.child((renderer) => {
|
|
6372
|
-
const
|
|
6373
|
-
fn(
|
|
5635
|
+
const r2 = new Renderer(renderer.global, renderer);
|
|
5636
|
+
fn(r2);
|
|
6374
5637
|
if (renderer.global.mode === "async") {
|
|
6375
|
-
return
|
|
5638
|
+
return r2.#collect_content_async().then((content) => {
|
|
6376
5639
|
close(content.head);
|
|
6377
5640
|
});
|
|
6378
5641
|
} else {
|
|
6379
|
-
const content =
|
|
5642
|
+
const content = r2.#collect_content();
|
|
6380
5643
|
close(content.head);
|
|
6381
5644
|
}
|
|
6382
5645
|
});
|
|
@@ -7312,7 +6575,7 @@ const options = {
|
|
|
7312
6575
|
app: ({ head, body, assets, nonce, env }) => '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <link rel="icon" href="' + assets + '/favicon.png" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n ' + head + '\n </head>\n <body data-sveltekit-preload-data="hover">\n <div style="display: contents">' + body + "</div>\n </body>\n</html>\n",
|
|
7313
6576
|
error
|
|
7314
6577
|
},
|
|
7315
|
-
version_hash: "
|
|
6578
|
+
version_hash: "cmtin0"
|
|
7316
6579
|
};
|
|
7317
6580
|
async function get_hooks() {
|
|
7318
6581
|
let handle;
|
|
@@ -7320,7 +6583,7 @@ async function get_hooks() {
|
|
|
7320
6583
|
let handleError;
|
|
7321
6584
|
let handleValidationError;
|
|
7322
6585
|
let init;
|
|
7323
|
-
({ handle, handleFetch, handleError, handleValidationError, init } = await import('./hooks.server-
|
|
6586
|
+
({ handle, handleFetch, handleError, handleValidationError, init } = await import('./hooks.server-BGc6cSdu.js'));
|
|
7324
6587
|
let reroute;
|
|
7325
6588
|
let transport;
|
|
7326
6589
|
return {
|
|
@@ -7334,291 +6597,6 @@ async function get_hooks() {
|
|
|
7334
6597
|
};
|
|
7335
6598
|
}
|
|
7336
6599
|
|
|
7337
|
-
var cookie = {};
|
|
7338
|
-
|
|
7339
|
-
/*!
|
|
7340
|
-
* cookie
|
|
7341
|
-
* Copyright(c) 2012-2014 Roman Shtylman
|
|
7342
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
7343
|
-
* MIT Licensed
|
|
7344
|
-
*/
|
|
7345
|
-
|
|
7346
|
-
var hasRequiredCookie;
|
|
7347
|
-
|
|
7348
|
-
function requireCookie () {
|
|
7349
|
-
if (hasRequiredCookie) return cookie;
|
|
7350
|
-
hasRequiredCookie = 1;
|
|
7351
|
-
|
|
7352
|
-
/**
|
|
7353
|
-
* Module exports.
|
|
7354
|
-
* @public
|
|
7355
|
-
*/
|
|
7356
|
-
|
|
7357
|
-
cookie.parse = parse;
|
|
7358
|
-
cookie.serialize = serialize;
|
|
7359
|
-
|
|
7360
|
-
/**
|
|
7361
|
-
* Module variables.
|
|
7362
|
-
* @private
|
|
7363
|
-
*/
|
|
7364
|
-
|
|
7365
|
-
var __toString = Object.prototype.toString;
|
|
7366
|
-
|
|
7367
|
-
/**
|
|
7368
|
-
* RegExp to match field-content in RFC 7230 sec 3.2
|
|
7369
|
-
*
|
|
7370
|
-
* field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
|
|
7371
|
-
* field-vchar = VCHAR / obs-text
|
|
7372
|
-
* obs-text = %x80-FF
|
|
7373
|
-
*/
|
|
7374
|
-
|
|
7375
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
7376
|
-
|
|
7377
|
-
/**
|
|
7378
|
-
* Parse a cookie header.
|
|
7379
|
-
*
|
|
7380
|
-
* Parse the given cookie header string into an object
|
|
7381
|
-
* The object has the various cookies as keys(names) => values
|
|
7382
|
-
*
|
|
7383
|
-
* @param {string} str
|
|
7384
|
-
* @param {object} [options]
|
|
7385
|
-
* @return {object}
|
|
7386
|
-
* @public
|
|
7387
|
-
*/
|
|
7388
|
-
|
|
7389
|
-
function parse(str, options) {
|
|
7390
|
-
if (typeof str !== 'string') {
|
|
7391
|
-
throw new TypeError('argument str must be a string');
|
|
7392
|
-
}
|
|
7393
|
-
|
|
7394
|
-
var obj = {};
|
|
7395
|
-
var opt = options || {};
|
|
7396
|
-
var dec = opt.decode || decode;
|
|
7397
|
-
|
|
7398
|
-
var index = 0;
|
|
7399
|
-
while (index < str.length) {
|
|
7400
|
-
var eqIdx = str.indexOf('=', index);
|
|
7401
|
-
|
|
7402
|
-
// no more cookie pairs
|
|
7403
|
-
if (eqIdx === -1) {
|
|
7404
|
-
break
|
|
7405
|
-
}
|
|
7406
|
-
|
|
7407
|
-
var endIdx = str.indexOf(';', index);
|
|
7408
|
-
|
|
7409
|
-
if (endIdx === -1) {
|
|
7410
|
-
endIdx = str.length;
|
|
7411
|
-
} else if (endIdx < eqIdx) {
|
|
7412
|
-
// backtrack on prior semicolon
|
|
7413
|
-
index = str.lastIndexOf(';', eqIdx - 1) + 1;
|
|
7414
|
-
continue
|
|
7415
|
-
}
|
|
7416
|
-
|
|
7417
|
-
var key = str.slice(index, eqIdx).trim();
|
|
7418
|
-
|
|
7419
|
-
// only assign once
|
|
7420
|
-
if (undefined === obj[key]) {
|
|
7421
|
-
var val = str.slice(eqIdx + 1, endIdx).trim();
|
|
7422
|
-
|
|
7423
|
-
// quoted values
|
|
7424
|
-
if (val.charCodeAt(0) === 0x22) {
|
|
7425
|
-
val = val.slice(1, -1);
|
|
7426
|
-
}
|
|
7427
|
-
|
|
7428
|
-
obj[key] = tryDecode(val, dec);
|
|
7429
|
-
}
|
|
7430
|
-
|
|
7431
|
-
index = endIdx + 1;
|
|
7432
|
-
}
|
|
7433
|
-
|
|
7434
|
-
return obj;
|
|
7435
|
-
}
|
|
7436
|
-
|
|
7437
|
-
/**
|
|
7438
|
-
* Serialize data into a cookie header.
|
|
7439
|
-
*
|
|
7440
|
-
* Serialize the a name value pair into a cookie string suitable for
|
|
7441
|
-
* http headers. An optional options object specified cookie parameters.
|
|
7442
|
-
*
|
|
7443
|
-
* serialize('foo', 'bar', { httpOnly: true })
|
|
7444
|
-
* => "foo=bar; httpOnly"
|
|
7445
|
-
*
|
|
7446
|
-
* @param {string} name
|
|
7447
|
-
* @param {string} val
|
|
7448
|
-
* @param {object} [options]
|
|
7449
|
-
* @return {string}
|
|
7450
|
-
* @public
|
|
7451
|
-
*/
|
|
7452
|
-
|
|
7453
|
-
function serialize(name, val, options) {
|
|
7454
|
-
var opt = options || {};
|
|
7455
|
-
var enc = opt.encode || encode;
|
|
7456
|
-
|
|
7457
|
-
if (typeof enc !== 'function') {
|
|
7458
|
-
throw new TypeError('option encode is invalid');
|
|
7459
|
-
}
|
|
7460
|
-
|
|
7461
|
-
if (!fieldContentRegExp.test(name)) {
|
|
7462
|
-
throw new TypeError('argument name is invalid');
|
|
7463
|
-
}
|
|
7464
|
-
|
|
7465
|
-
var value = enc(val);
|
|
7466
|
-
|
|
7467
|
-
if (value && !fieldContentRegExp.test(value)) {
|
|
7468
|
-
throw new TypeError('argument val is invalid');
|
|
7469
|
-
}
|
|
7470
|
-
|
|
7471
|
-
var str = name + '=' + value;
|
|
7472
|
-
|
|
7473
|
-
if (null != opt.maxAge) {
|
|
7474
|
-
var maxAge = opt.maxAge - 0;
|
|
7475
|
-
|
|
7476
|
-
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
7477
|
-
throw new TypeError('option maxAge is invalid')
|
|
7478
|
-
}
|
|
7479
|
-
|
|
7480
|
-
str += '; Max-Age=' + Math.floor(maxAge);
|
|
7481
|
-
}
|
|
7482
|
-
|
|
7483
|
-
if (opt.domain) {
|
|
7484
|
-
if (!fieldContentRegExp.test(opt.domain)) {
|
|
7485
|
-
throw new TypeError('option domain is invalid');
|
|
7486
|
-
}
|
|
7487
|
-
|
|
7488
|
-
str += '; Domain=' + opt.domain;
|
|
7489
|
-
}
|
|
7490
|
-
|
|
7491
|
-
if (opt.path) {
|
|
7492
|
-
if (!fieldContentRegExp.test(opt.path)) {
|
|
7493
|
-
throw new TypeError('option path is invalid');
|
|
7494
|
-
}
|
|
7495
|
-
|
|
7496
|
-
str += '; Path=' + opt.path;
|
|
7497
|
-
}
|
|
7498
|
-
|
|
7499
|
-
if (opt.expires) {
|
|
7500
|
-
var expires = opt.expires;
|
|
7501
|
-
|
|
7502
|
-
if (!isDate(expires) || isNaN(expires.valueOf())) {
|
|
7503
|
-
throw new TypeError('option expires is invalid');
|
|
7504
|
-
}
|
|
7505
|
-
|
|
7506
|
-
str += '; Expires=' + expires.toUTCString();
|
|
7507
|
-
}
|
|
7508
|
-
|
|
7509
|
-
if (opt.httpOnly) {
|
|
7510
|
-
str += '; HttpOnly';
|
|
7511
|
-
}
|
|
7512
|
-
|
|
7513
|
-
if (opt.secure) {
|
|
7514
|
-
str += '; Secure';
|
|
7515
|
-
}
|
|
7516
|
-
|
|
7517
|
-
if (opt.partitioned) {
|
|
7518
|
-
str += '; Partitioned';
|
|
7519
|
-
}
|
|
7520
|
-
|
|
7521
|
-
if (opt.priority) {
|
|
7522
|
-
var priority = typeof opt.priority === 'string'
|
|
7523
|
-
? opt.priority.toLowerCase()
|
|
7524
|
-
: opt.priority;
|
|
7525
|
-
|
|
7526
|
-
switch (priority) {
|
|
7527
|
-
case 'low':
|
|
7528
|
-
str += '; Priority=Low';
|
|
7529
|
-
break
|
|
7530
|
-
case 'medium':
|
|
7531
|
-
str += '; Priority=Medium';
|
|
7532
|
-
break
|
|
7533
|
-
case 'high':
|
|
7534
|
-
str += '; Priority=High';
|
|
7535
|
-
break
|
|
7536
|
-
default:
|
|
7537
|
-
throw new TypeError('option priority is invalid')
|
|
7538
|
-
}
|
|
7539
|
-
}
|
|
7540
|
-
|
|
7541
|
-
if (opt.sameSite) {
|
|
7542
|
-
var sameSite = typeof opt.sameSite === 'string'
|
|
7543
|
-
? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
7544
|
-
|
|
7545
|
-
switch (sameSite) {
|
|
7546
|
-
case true:
|
|
7547
|
-
str += '; SameSite=Strict';
|
|
7548
|
-
break;
|
|
7549
|
-
case 'lax':
|
|
7550
|
-
str += '; SameSite=Lax';
|
|
7551
|
-
break;
|
|
7552
|
-
case 'strict':
|
|
7553
|
-
str += '; SameSite=Strict';
|
|
7554
|
-
break;
|
|
7555
|
-
case 'none':
|
|
7556
|
-
str += '; SameSite=None';
|
|
7557
|
-
break;
|
|
7558
|
-
default:
|
|
7559
|
-
throw new TypeError('option sameSite is invalid');
|
|
7560
|
-
}
|
|
7561
|
-
}
|
|
7562
|
-
|
|
7563
|
-
return str;
|
|
7564
|
-
}
|
|
7565
|
-
|
|
7566
|
-
/**
|
|
7567
|
-
* URL-decode string value. Optimized to skip native call when no %.
|
|
7568
|
-
*
|
|
7569
|
-
* @param {string} str
|
|
7570
|
-
* @returns {string}
|
|
7571
|
-
*/
|
|
7572
|
-
|
|
7573
|
-
function decode (str) {
|
|
7574
|
-
return str.indexOf('%') !== -1
|
|
7575
|
-
? decodeURIComponent(str)
|
|
7576
|
-
: str
|
|
7577
|
-
}
|
|
7578
|
-
|
|
7579
|
-
/**
|
|
7580
|
-
* URL-encode value.
|
|
7581
|
-
*
|
|
7582
|
-
* @param {string} val
|
|
7583
|
-
* @returns {string}
|
|
7584
|
-
*/
|
|
7585
|
-
|
|
7586
|
-
function encode (val) {
|
|
7587
|
-
return encodeURIComponent(val)
|
|
7588
|
-
}
|
|
7589
|
-
|
|
7590
|
-
/**
|
|
7591
|
-
* Determine if value is a Date.
|
|
7592
|
-
*
|
|
7593
|
-
* @param {*} val
|
|
7594
|
-
* @private
|
|
7595
|
-
*/
|
|
7596
|
-
|
|
7597
|
-
function isDate (val) {
|
|
7598
|
-
return __toString.call(val) === '[object Date]' ||
|
|
7599
|
-
val instanceof Date
|
|
7600
|
-
}
|
|
7601
|
-
|
|
7602
|
-
/**
|
|
7603
|
-
* Try decoding a string using a decoding function.
|
|
7604
|
-
*
|
|
7605
|
-
* @param {string} str
|
|
7606
|
-
* @param {function} decode
|
|
7607
|
-
* @private
|
|
7608
|
-
*/
|
|
7609
|
-
|
|
7610
|
-
function tryDecode(str, decode) {
|
|
7611
|
-
try {
|
|
7612
|
-
return decode(str);
|
|
7613
|
-
} catch (e) {
|
|
7614
|
-
return str;
|
|
7615
|
-
}
|
|
7616
|
-
}
|
|
7617
|
-
return cookie;
|
|
7618
|
-
}
|
|
7619
|
-
|
|
7620
|
-
var cookieExports = requireCookie();
|
|
7621
|
-
|
|
7622
6600
|
const s = JSON.stringify;
|
|
7623
6601
|
function exec(match, params, matchers) {
|
|
7624
6602
|
const result = {};
|
|
@@ -10588,6 +9566,152 @@ function redirect_json_response(redirect) {
|
|
|
10588
9566
|
}
|
|
10589
9567
|
);
|
|
10590
9568
|
}
|
|
9569
|
+
var cookie = {};
|
|
9570
|
+
var hasRequiredCookie;
|
|
9571
|
+
function requireCookie() {
|
|
9572
|
+
if (hasRequiredCookie) return cookie;
|
|
9573
|
+
hasRequiredCookie = 1;
|
|
9574
|
+
cookie.parse = parse;
|
|
9575
|
+
cookie.serialize = serialize;
|
|
9576
|
+
var __toString = Object.prototype.toString;
|
|
9577
|
+
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
9578
|
+
function parse(str, options2) {
|
|
9579
|
+
if (typeof str !== "string") {
|
|
9580
|
+
throw new TypeError("argument str must be a string");
|
|
9581
|
+
}
|
|
9582
|
+
var obj = {};
|
|
9583
|
+
var opt = options2 || {};
|
|
9584
|
+
var dec = opt.decode || decode;
|
|
9585
|
+
var index = 0;
|
|
9586
|
+
while (index < str.length) {
|
|
9587
|
+
var eqIdx = str.indexOf("=", index);
|
|
9588
|
+
if (eqIdx === -1) {
|
|
9589
|
+
break;
|
|
9590
|
+
}
|
|
9591
|
+
var endIdx = str.indexOf(";", index);
|
|
9592
|
+
if (endIdx === -1) {
|
|
9593
|
+
endIdx = str.length;
|
|
9594
|
+
} else if (endIdx < eqIdx) {
|
|
9595
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
9596
|
+
continue;
|
|
9597
|
+
}
|
|
9598
|
+
var key2 = str.slice(index, eqIdx).trim();
|
|
9599
|
+
if (void 0 === obj[key2]) {
|
|
9600
|
+
var val = str.slice(eqIdx + 1, endIdx).trim();
|
|
9601
|
+
if (val.charCodeAt(0) === 34) {
|
|
9602
|
+
val = val.slice(1, -1);
|
|
9603
|
+
}
|
|
9604
|
+
obj[key2] = tryDecode(val, dec);
|
|
9605
|
+
}
|
|
9606
|
+
index = endIdx + 1;
|
|
9607
|
+
}
|
|
9608
|
+
return obj;
|
|
9609
|
+
}
|
|
9610
|
+
function serialize(name, val, options2) {
|
|
9611
|
+
var opt = options2 || {};
|
|
9612
|
+
var enc = opt.encode || encode2;
|
|
9613
|
+
if (typeof enc !== "function") {
|
|
9614
|
+
throw new TypeError("option encode is invalid");
|
|
9615
|
+
}
|
|
9616
|
+
if (!fieldContentRegExp.test(name)) {
|
|
9617
|
+
throw new TypeError("argument name is invalid");
|
|
9618
|
+
}
|
|
9619
|
+
var value = enc(val);
|
|
9620
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
9621
|
+
throw new TypeError("argument val is invalid");
|
|
9622
|
+
}
|
|
9623
|
+
var str = name + "=" + value;
|
|
9624
|
+
if (null != opt.maxAge) {
|
|
9625
|
+
var maxAge = opt.maxAge - 0;
|
|
9626
|
+
if (isNaN(maxAge) || !isFinite(maxAge)) {
|
|
9627
|
+
throw new TypeError("option maxAge is invalid");
|
|
9628
|
+
}
|
|
9629
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
9630
|
+
}
|
|
9631
|
+
if (opt.domain) {
|
|
9632
|
+
if (!fieldContentRegExp.test(opt.domain)) {
|
|
9633
|
+
throw new TypeError("option domain is invalid");
|
|
9634
|
+
}
|
|
9635
|
+
str += "; Domain=" + opt.domain;
|
|
9636
|
+
}
|
|
9637
|
+
if (opt.path) {
|
|
9638
|
+
if (!fieldContentRegExp.test(opt.path)) {
|
|
9639
|
+
throw new TypeError("option path is invalid");
|
|
9640
|
+
}
|
|
9641
|
+
str += "; Path=" + opt.path;
|
|
9642
|
+
}
|
|
9643
|
+
if (opt.expires) {
|
|
9644
|
+
var expires = opt.expires;
|
|
9645
|
+
if (!isDate(expires) || isNaN(expires.valueOf())) {
|
|
9646
|
+
throw new TypeError("option expires is invalid");
|
|
9647
|
+
}
|
|
9648
|
+
str += "; Expires=" + expires.toUTCString();
|
|
9649
|
+
}
|
|
9650
|
+
if (opt.httpOnly) {
|
|
9651
|
+
str += "; HttpOnly";
|
|
9652
|
+
}
|
|
9653
|
+
if (opt.secure) {
|
|
9654
|
+
str += "; Secure";
|
|
9655
|
+
}
|
|
9656
|
+
if (opt.partitioned) {
|
|
9657
|
+
str += "; Partitioned";
|
|
9658
|
+
}
|
|
9659
|
+
if (opt.priority) {
|
|
9660
|
+
var priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
9661
|
+
switch (priority) {
|
|
9662
|
+
case "low":
|
|
9663
|
+
str += "; Priority=Low";
|
|
9664
|
+
break;
|
|
9665
|
+
case "medium":
|
|
9666
|
+
str += "; Priority=Medium";
|
|
9667
|
+
break;
|
|
9668
|
+
case "high":
|
|
9669
|
+
str += "; Priority=High";
|
|
9670
|
+
break;
|
|
9671
|
+
default:
|
|
9672
|
+
throw new TypeError("option priority is invalid");
|
|
9673
|
+
}
|
|
9674
|
+
}
|
|
9675
|
+
if (opt.sameSite) {
|
|
9676
|
+
var sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
9677
|
+
switch (sameSite) {
|
|
9678
|
+
case true:
|
|
9679
|
+
str += "; SameSite=Strict";
|
|
9680
|
+
break;
|
|
9681
|
+
case "lax":
|
|
9682
|
+
str += "; SameSite=Lax";
|
|
9683
|
+
break;
|
|
9684
|
+
case "strict":
|
|
9685
|
+
str += "; SameSite=Strict";
|
|
9686
|
+
break;
|
|
9687
|
+
case "none":
|
|
9688
|
+
str += "; SameSite=None";
|
|
9689
|
+
break;
|
|
9690
|
+
default:
|
|
9691
|
+
throw new TypeError("option sameSite is invalid");
|
|
9692
|
+
}
|
|
9693
|
+
}
|
|
9694
|
+
return str;
|
|
9695
|
+
}
|
|
9696
|
+
function decode(str) {
|
|
9697
|
+
return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
|
|
9698
|
+
}
|
|
9699
|
+
function encode2(val) {
|
|
9700
|
+
return encodeURIComponent(val);
|
|
9701
|
+
}
|
|
9702
|
+
function isDate(val) {
|
|
9703
|
+
return __toString.call(val) === "[object Date]" || val instanceof Date;
|
|
9704
|
+
}
|
|
9705
|
+
function tryDecode(str, decode2) {
|
|
9706
|
+
try {
|
|
9707
|
+
return decode2(str);
|
|
9708
|
+
} catch (e) {
|
|
9709
|
+
return str;
|
|
9710
|
+
}
|
|
9711
|
+
}
|
|
9712
|
+
return cookie;
|
|
9713
|
+
}
|
|
9714
|
+
var cookieExports = requireCookie();
|
|
10591
9715
|
const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
|
|
10592
9716
|
function validate_options(options2) {
|
|
10593
9717
|
if (options2?.path === void 0) {
|
|
@@ -10624,8 +9748,8 @@ function get_cookies(request, url) {
|
|
|
10624
9748
|
return best_match.options.maxAge === 0 ? void 0 : best_match.value;
|
|
10625
9749
|
}
|
|
10626
9750
|
const req_cookies = cookieExports.parse(header, { decode: opts?.decode });
|
|
10627
|
-
const
|
|
10628
|
-
return
|
|
9751
|
+
const cookie2 = req_cookies[name];
|
|
9752
|
+
return cookie2;
|
|
10629
9753
|
},
|
|
10630
9754
|
/**
|
|
10631
9755
|
* @param {import('cookie').CookieParseOptions} [opts]
|
|
@@ -10693,11 +9817,11 @@ function get_cookies(request, url) {
|
|
|
10693
9817
|
// cookies sent by the user agent have lowest precedence
|
|
10694
9818
|
...initial_cookies
|
|
10695
9819
|
};
|
|
10696
|
-
for (const
|
|
10697
|
-
if (!domain_matches(destination.hostname,
|
|
10698
|
-
if (!path_matches(destination.pathname,
|
|
10699
|
-
const encoder =
|
|
10700
|
-
combined_cookies[
|
|
9820
|
+
for (const cookie2 of new_cookies.values()) {
|
|
9821
|
+
if (!domain_matches(destination.hostname, cookie2.options.domain)) continue;
|
|
9822
|
+
if (!path_matches(destination.pathname, cookie2.options.path)) continue;
|
|
9823
|
+
const encoder = cookie2.options.encode || encodeURIComponent;
|
|
9824
|
+
combined_cookies[cookie2.name] = encoder(cookie2.value);
|
|
10701
9825
|
}
|
|
10702
9826
|
if (header2) {
|
|
10703
9827
|
const parsed = cookieExports.parse(header2, { decode: (value) => value });
|
|
@@ -10718,8 +9842,8 @@ function get_cookies(request, url) {
|
|
|
10718
9842
|
path = resolve(normalized_url, path);
|
|
10719
9843
|
}
|
|
10720
9844
|
const cookie_key = generate_cookie_key(options2.domain, path, name);
|
|
10721
|
-
const
|
|
10722
|
-
new_cookies.set(cookie_key,
|
|
9845
|
+
const cookie2 = { name, value, options: { ...options2, path } };
|
|
9846
|
+
new_cookies.set(cookie_key, cookie2);
|
|
10723
9847
|
}
|
|
10724
9848
|
function set_trailing_slash(trailing_slash) {
|
|
10725
9849
|
normalized_url = normalize_path(url.pathname, trailing_slash);
|
|
@@ -10773,8 +9897,8 @@ function create_fetch({ event, options: options2, manifest, state, get_cookie_he
|
|
|
10773
9897
|
const decoded = decodeURIComponent(url.pathname);
|
|
10774
9898
|
if (url.origin !== event.url.origin || base && decoded !== base && !decoded.startsWith(`${base}/`)) {
|
|
10775
9899
|
if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
|
|
10776
|
-
const
|
|
10777
|
-
if (
|
|
9900
|
+
const cookie2 = get_cookie_header(url, request.headers.get("cookie"));
|
|
9901
|
+
if (cookie2) request.headers.set("cookie", cookie2);
|
|
10778
9902
|
}
|
|
10779
9903
|
return fetch(request);
|
|
10780
9904
|
}
|
|
@@ -10806,9 +9930,9 @@ function create_fetch({ event, options: options2, manifest, state, get_cookie_he
|
|
|
10806
9930
|
return await fetch(request);
|
|
10807
9931
|
}
|
|
10808
9932
|
if (credentials !== "omit") {
|
|
10809
|
-
const
|
|
10810
|
-
if (
|
|
10811
|
-
request.headers.set("cookie",
|
|
9933
|
+
const cookie2 = get_cookie_header(url, request.headers.get("cookie"));
|
|
9934
|
+
if (cookie2) {
|
|
9935
|
+
request.headers.set("cookie", cookie2);
|
|
10812
9936
|
}
|
|
10813
9937
|
const authorization = event.request.headers.get("authorization");
|
|
10814
9938
|
if (authorization && !request.headers.has("authorization")) {
|
|
@@ -11246,8 +10370,8 @@ async function internal_respond(request, options2, manifest, state) {
|
|
|
11246
10370
|
const value = response.headers.get(key2);
|
|
11247
10371
|
if (value) headers22.set(key2, value);
|
|
11248
10372
|
}
|
|
11249
|
-
for (const
|
|
11250
|
-
headers22.append("set-cookie",
|
|
10373
|
+
for (const cookie2 of get_set_cookies(response.headers)) {
|
|
10374
|
+
headers22.append("set-cookie", cookie2);
|
|
11251
10375
|
}
|
|
11252
10376
|
return new Response(void 0, {
|
|
11253
10377
|
status: 304,
|