content-query 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/build-C5ef0kkR.mjs +1401 -0
- package/dist/build-DSyoRxkZ.d.mts +24 -0
- package/dist/build.d.mts +2 -0
- package/dist/build.mjs +2 -0
- package/dist/chunk-CJs4Fogs.mjs +34 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +97 -0
- package/dist/computed.d.mts +37 -0
- package/dist/computed.mjs +138 -0
- package/dist/content-Crag1Uch.d.mts +99 -0
- package/dist/content-Dj2fQCJ5.mjs +902 -0
- package/dist/descriptor-Xbo9u5eR.d.mts +19 -0
- package/dist/diagnostics-Dol6ANtq.mjs +79 -0
- package/dist/dist-BQGVLZyl.mjs +5396 -0
- package/dist/errors-C8lWyiy2.mjs +72 -0
- package/dist/github-slugger-BCAkwEOL.mjs +72 -0
- package/dist/glob-DJmebCMM.mjs +159 -0
- package/dist/index.d.mts +60 -0
- package/dist/index.mjs +43 -0
- package/dist/internal/markdown.d.mts +7 -0
- package/dist/internal/markdown.mjs +2 -0
- package/dist/internal.d.mts +54 -0
- package/dist/internal.mjs +89 -0
- package/dist/loaders.d.mts +12 -0
- package/dist/loaders.mjs +85 -0
- package/dist/markdown-CZBL4Ux_.mjs +54 -0
- package/dist/next.d.mts +21 -0
- package/dist/next.mjs +142 -0
- package/dist/operators-BQpLfJlx.mjs +173 -0
- package/dist/query.d.mts +45 -0
- package/dist/query.mjs +2 -0
- package/dist/relational-types-DLniKi5S.d.mts +245 -0
- package/dist/runtime.d.mts +3 -0
- package/dist/runtime.mjs +6 -0
- package/dist/schema-CnCbMosm.mjs +20 -0
- package/dist/schema.d.mts +13 -0
- package/dist/schema.mjs +2 -0
- package/dist/server-only-CIE-FHx0.mjs +7 -0
- package/dist/types-BPh2cBPs.d.mts +48 -0
- package/dist/types-DcvHRmxO.d.mts +20 -0
- package/dist/types-hmDOw87q.d.mts +135 -0
- package/dist/validation-BvvjSUFc.mjs +84 -0
- package/dist/values-B7lo_2_x.mjs +900 -0
- package/dist/vite.d.mts +8 -0
- package/dist/vite.mjs +296 -0
- package/package.json +90 -10
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/constants.js
|
|
2
|
+
const MAX_ARRAY_LEN = 2 ** 32 - 1;
|
|
3
|
+
const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/utils.js
|
|
6
|
+
var DevalueError = class extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} message
|
|
9
|
+
* @param {string[]} keys
|
|
10
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
11
|
+
* @param {any} [root] - The root value being serialized
|
|
12
|
+
*/
|
|
13
|
+
constructor(message, keys, value, root) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "DevalueError";
|
|
16
|
+
this.path = keys.join("");
|
|
17
|
+
this.value = value;
|
|
18
|
+
this.root = root;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Marks a Map key on the path being serialized. The key itself is recorded
|
|
23
|
+
* right after the marker, so nothing is formatted or allocated per entry.
|
|
24
|
+
*/
|
|
25
|
+
const MAP_KEY = Symbol();
|
|
26
|
+
/**
|
|
27
|
+
* Formats the path recorded on the way to the value being serialized — a
|
|
28
|
+
* property key, an array index, or `MAP_KEY` followed by a Map key — into
|
|
29
|
+
* the segments a `DevalueError` joins. Only runs when an error is raised.
|
|
30
|
+
* @param {any[]} keys
|
|
31
|
+
* @param {(key: any) => string} format_map_key
|
|
32
|
+
* @returns {string[]}
|
|
33
|
+
*/
|
|
34
|
+
function format_path(keys, format_map_key) {
|
|
35
|
+
/** @type {string[]} */
|
|
36
|
+
const path = [];
|
|
37
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
38
|
+
const segment = keys[i];
|
|
39
|
+
if (segment === MAP_KEY) path.push(`.get(${format_map_key(keys[++i])})`);
|
|
40
|
+
else if (typeof segment === "number") path.push(`[${segment}]`);
|
|
41
|
+
else path.push(stringify_key(segment));
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
|
|
46
|
+
/** @param {any} thing */
|
|
47
|
+
function is_plain_object(thing) {
|
|
48
|
+
const proto = Object.getPrototypeOf(thing);
|
|
49
|
+
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
|
|
50
|
+
}
|
|
51
|
+
/** @param {any} thing */
|
|
52
|
+
function get_type(thing) {
|
|
53
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
54
|
+
}
|
|
55
|
+
/** @param {any} thing */
|
|
56
|
+
function is_buffer(thing) {
|
|
57
|
+
return typeof Buffer !== "undefined" && Buffer.isBuffer(thing);
|
|
58
|
+
}
|
|
59
|
+
/** @param {string} char */
|
|
60
|
+
function get_escaped_char(char) {
|
|
61
|
+
switch (char) {
|
|
62
|
+
case "\"": return "\\\"";
|
|
63
|
+
case "<": return "\\u003C";
|
|
64
|
+
case "\\": return "\\\\";
|
|
65
|
+
case "\n": return "\\n";
|
|
66
|
+
case "\r": return "\\r";
|
|
67
|
+
case " ": return "\\t";
|
|
68
|
+
case "\b": return "\\b";
|
|
69
|
+
case "\f": return "\\f";
|
|
70
|
+
case "\u2028": return "\\u2028";
|
|
71
|
+
case "\u2029": return "\\u2029";
|
|
72
|
+
default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const needs_escape = /["<\\\u0000-\u001f\u2028\u2029]/;
|
|
76
|
+
/** @param {string} str */
|
|
77
|
+
function stringify_string(str) {
|
|
78
|
+
if (!needs_escape.test(str) && str.isWellFormed()) return `"${str}"`;
|
|
79
|
+
let result = "";
|
|
80
|
+
let last_pos = 0;
|
|
81
|
+
const len = str.length;
|
|
82
|
+
for (let i = 0; i < len; i += 1) {
|
|
83
|
+
const code = str.charCodeAt(i);
|
|
84
|
+
if (code >= 55296 && code <= 57343) {
|
|
85
|
+
if (code <= 56319 && i + 1 < len && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
86
|
+
i += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
result += str.slice(last_pos, i) + `\\u${code.toString(16)}`;
|
|
90
|
+
last_pos = i + 1;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const replacement = get_escaped_char(str[i]);
|
|
94
|
+
if (replacement) {
|
|
95
|
+
result += str.slice(last_pos, i) + replacement;
|
|
96
|
+
last_pos = i + 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
100
|
+
}
|
|
101
|
+
const MAX_CACHED_KEY_LENGTH = 64;
|
|
102
|
+
/** @type {Map<string, string>} */
|
|
103
|
+
const quoted_keys = /* @__PURE__ */ new Map();
|
|
104
|
+
/** @param {string} key */
|
|
105
|
+
function quote_key(key) {
|
|
106
|
+
if (key.length > MAX_CACHED_KEY_LENGTH) return stringify_string(key);
|
|
107
|
+
let quoted = quoted_keys.get(key);
|
|
108
|
+
if (quoted === void 0) {
|
|
109
|
+
if (quoted_keys.size >= 1024) quoted_keys.clear();
|
|
110
|
+
quoted = stringify_string(key);
|
|
111
|
+
quoted_keys.set(key, quoted);
|
|
112
|
+
}
|
|
113
|
+
return quoted;
|
|
114
|
+
}
|
|
115
|
+
/** @param {Record<string | symbol, any>} object */
|
|
116
|
+
function enumerable_symbols(object) {
|
|
117
|
+
const symbols = Object.getOwnPropertySymbols(object);
|
|
118
|
+
return symbols.length === 0 ? symbols : symbols.filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol)?.enumerable);
|
|
119
|
+
}
|
|
120
|
+
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
121
|
+
/** @param {string} key */
|
|
122
|
+
function stringify_key(key) {
|
|
123
|
+
return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
|
|
124
|
+
}
|
|
125
|
+
/** @param {number} n */
|
|
126
|
+
function is_valid_array_index(n) {
|
|
127
|
+
if (!Number.isInteger(n)) return false;
|
|
128
|
+
if (n < 0) return false;
|
|
129
|
+
if (n > MAX_ARRAY_INDEX) return false;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
/** @param {number} n */
|
|
133
|
+
function is_valid_array_len(n) {
|
|
134
|
+
if (!Number.isInteger(n)) return false;
|
|
135
|
+
if (n < 0) return false;
|
|
136
|
+
if (n > MAX_ARRAY_LEN) return false;
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
/** @param {string} s */
|
|
140
|
+
function is_valid_array_index_string(s) {
|
|
141
|
+
if (s.length === 0) return false;
|
|
142
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false;
|
|
143
|
+
for (let i = 0; i < s.length; i++) {
|
|
144
|
+
const c = s.charCodeAt(i);
|
|
145
|
+
if (c < 48 || c > 57) return false;
|
|
146
|
+
}
|
|
147
|
+
return is_valid_array_index(+s);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns the length of the leading run of valid array indices in `keys`.
|
|
151
|
+
* @param {readonly string[]} keys
|
|
152
|
+
*/
|
|
153
|
+
function array_index_cut(keys) {
|
|
154
|
+
for (var i = keys.length - 1; i >= 0; i--) if (is_valid_array_index_string(keys[i])) break;
|
|
155
|
+
return i + 1;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Finds the populated indices of an array.
|
|
159
|
+
* @param {unknown[]} array
|
|
160
|
+
*/
|
|
161
|
+
function valid_array_indices(array) {
|
|
162
|
+
const keys = Object.keys(array);
|
|
163
|
+
keys.length = array_index_cut(keys);
|
|
164
|
+
return keys;
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/base64.js
|
|
168
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
169
|
+
function encode_native(array_buffer) {
|
|
170
|
+
return new Uint8Array(array_buffer).toBase64();
|
|
171
|
+
}
|
|
172
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
173
|
+
function decode_native(base64) {
|
|
174
|
+
return Uint8Array.fromBase64(base64).buffer;
|
|
175
|
+
}
|
|
176
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
177
|
+
function encode_buffer(array_buffer) {
|
|
178
|
+
return Buffer.from(array_buffer).toString("base64");
|
|
179
|
+
}
|
|
180
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
181
|
+
function decode_buffer(base64) {
|
|
182
|
+
return Uint8Array.from(Buffer.from(base64, "base64")).buffer;
|
|
183
|
+
}
|
|
184
|
+
/** @type {(array_buffer: ArrayBuffer) => string} */
|
|
185
|
+
function encode_legacy(array_buffer) {
|
|
186
|
+
const array = new Uint8Array(array_buffer);
|
|
187
|
+
let binary = "";
|
|
188
|
+
const chunk_size = 32768;
|
|
189
|
+
for (let i = 0; i < array.length; i += chunk_size) {
|
|
190
|
+
const chunk = array.subarray(i, i + chunk_size);
|
|
191
|
+
binary += String.fromCharCode.apply(null, chunk);
|
|
192
|
+
}
|
|
193
|
+
return btoa(binary);
|
|
194
|
+
}
|
|
195
|
+
/** @type {(base64: string) => ArrayBuffer} */
|
|
196
|
+
function decode_legacy(base64) {
|
|
197
|
+
const binary_string = atob(base64);
|
|
198
|
+
const len = binary_string.length;
|
|
199
|
+
const array = new Uint8Array(len);
|
|
200
|
+
for (let i = 0; i < len; i++) array[i] = binary_string.charCodeAt(i);
|
|
201
|
+
return array.buffer;
|
|
202
|
+
}
|
|
203
|
+
const native = typeof Uint8Array.fromBase64 === "function";
|
|
204
|
+
const buffer = typeof process === "object" && process.versions?.node !== void 0;
|
|
205
|
+
const encode64 = native ? encode_native : buffer ? encode_buffer : encode_legacy;
|
|
206
|
+
const decode64 = native ? decode_native : buffer ? decode_buffer : decode_legacy;
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/operations.js
|
|
209
|
+
/**
|
|
210
|
+
* Merges caller-provided operation overrides over the defaults. Iterating the
|
|
211
|
+
* default keys (rather than the override's own keys) means nullish members
|
|
212
|
+
* fall back to the default, and inherited members — e.g. from a class
|
|
213
|
+
* instance — are picked up.
|
|
214
|
+
*
|
|
215
|
+
* @template {Record<string, any>} T
|
|
216
|
+
* @param {T} defaults
|
|
217
|
+
* @param {Partial<T> | undefined} overrides
|
|
218
|
+
* @returns {T}
|
|
219
|
+
*/
|
|
220
|
+
function merge_operations(defaults, overrides) {
|
|
221
|
+
if (!overrides) return defaults;
|
|
222
|
+
const merged = {};
|
|
223
|
+
for (const key of Object.keys(defaults)) merged[key] = overrides[key] ?? defaults[key];
|
|
224
|
+
return merged;
|
|
225
|
+
}
|
|
226
|
+
/** @type {{ kind: 'not-plain' }} */
|
|
227
|
+
const NOT_PLAIN = /* @__PURE__ */ Object.freeze({ kind: "not-plain" });
|
|
228
|
+
/** @type {{ kind: 'symbol-keys' }} */
|
|
229
|
+
const SYMBOL_KEYS = /* @__PURE__ */ Object.freeze({ kind: "symbol-keys" });
|
|
230
|
+
const default_stringify_operations = /* @__PURE__ */ Object.freeze({
|
|
231
|
+
identify: (value) => value,
|
|
232
|
+
typeOf: (value) => value === null ? "null" : typeof value,
|
|
233
|
+
toPrimitive: (value) => value,
|
|
234
|
+
tagOf: (value) => get_type(value),
|
|
235
|
+
isThenable: (value) => typeof value.then === "function",
|
|
236
|
+
toPromise: (thenable) => Promise.resolve(thenable),
|
|
237
|
+
unbox: (boxed) => boxed.valueOf(),
|
|
238
|
+
toISOString: (date) => isNaN(date.getDate()) ? "" : date.toISOString(),
|
|
239
|
+
toStringValue: (value) => value.toString(),
|
|
240
|
+
regExpInfo: (regexp) => ({
|
|
241
|
+
source: regexp.source,
|
|
242
|
+
flags: regexp.flags
|
|
243
|
+
}),
|
|
244
|
+
valuesOf: (set) => set,
|
|
245
|
+
entriesOf: (map) => map,
|
|
246
|
+
viewInfo: (view) => {
|
|
247
|
+
if (is_buffer(view)) view = new Uint8Array(view);
|
|
248
|
+
return {
|
|
249
|
+
buffer: view.buffer,
|
|
250
|
+
byteOffset: view.byteOffset,
|
|
251
|
+
byteLength: view.byteLength,
|
|
252
|
+
length: view.length,
|
|
253
|
+
bufferByteLength: view.buffer.byteLength
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
toArrayBuffer: (buffer) => buffer,
|
|
257
|
+
lengthOf: (array) => array.length,
|
|
258
|
+
hasOwn: (value, key) => Object.hasOwn(value, key),
|
|
259
|
+
indicesOf: (array) => valid_array_indices(array),
|
|
260
|
+
shapeOf: (value) => {
|
|
261
|
+
if (!is_plain_object(value)) return NOT_PLAIN;
|
|
262
|
+
if (enumerable_symbols(value).length > 0) return SYMBOL_KEYS;
|
|
263
|
+
return {
|
|
264
|
+
kind: Object.getPrototypeOf(value) === null ? "null-proto" : "plain",
|
|
265
|
+
keys: Object.keys(value)
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
get: (value, key) => value[key]
|
|
269
|
+
});
|
|
270
|
+
const array_buffer_byte_length = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength")?.get;
|
|
271
|
+
const shared_array_buffer_byte_length = typeof SharedArrayBuffer === "undefined" ? void 0 : Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength")?.get;
|
|
272
|
+
const default_parse_operations = /* @__PURE__ */ Object.freeze({
|
|
273
|
+
fromPrimitive: (primitive) => primitive,
|
|
274
|
+
fromISOString: (iso) => new Date(iso),
|
|
275
|
+
fromStringValue: (tag, text) => {
|
|
276
|
+
if (tag === "URL") return new URL(text);
|
|
277
|
+
if (tag === "URLSearchParams") return new URLSearchParams(text);
|
|
278
|
+
return Temporal[tag.slice(9)].from(text);
|
|
279
|
+
},
|
|
280
|
+
fromArrayBuffer: (buffer) => buffer,
|
|
281
|
+
fromRegExpInfo: (source, flags) => new RegExp(source, flags),
|
|
282
|
+
fromViewInfo: (tag, buffer, byteOffset, length) => {
|
|
283
|
+
try {
|
|
284
|
+
array_buffer_byte_length.call(buffer);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (!shared_array_buffer_byte_length) throw error;
|
|
287
|
+
shared_array_buffer_byte_length.call(buffer);
|
|
288
|
+
}
|
|
289
|
+
const Constructor = globalThis[tag];
|
|
290
|
+
return byteOffset !== void 0 ? new Constructor(buffer, byteOffset, length) : new Constructor(buffer);
|
|
291
|
+
},
|
|
292
|
+
box: (value) => Object(value),
|
|
293
|
+
createArray: (length) => new Array(length),
|
|
294
|
+
createSparseArray: (length) => {
|
|
295
|
+
/** @type {any[]} */
|
|
296
|
+
const array = [];
|
|
297
|
+
array[MAX_ARRAY_INDEX] = void 0;
|
|
298
|
+
delete array[MAX_ARRAY_INDEX];
|
|
299
|
+
array.length = length;
|
|
300
|
+
return array;
|
|
301
|
+
},
|
|
302
|
+
createObject: () => ({}),
|
|
303
|
+
createNullPrototypeObject: () => Object.create(null),
|
|
304
|
+
createSet: () => /* @__PURE__ */ new Set(),
|
|
305
|
+
createMap: () => /* @__PURE__ */ new Map(),
|
|
306
|
+
set: (target, key, value) => {
|
|
307
|
+
target[key] = value;
|
|
308
|
+
},
|
|
309
|
+
addValue: (set, value) => {
|
|
310
|
+
set.add(value);
|
|
311
|
+
},
|
|
312
|
+
addEntry: (map, key, value) => {
|
|
313
|
+
map.set(key, value);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
//#endregion
|
|
317
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/parse.js
|
|
318
|
+
function invalid() {
|
|
319
|
+
throw new Error("Invalid input");
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Revive a value serialized with `devalue.stringify`
|
|
323
|
+
* @param {string} serialized
|
|
324
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
325
|
+
* @param {import('./types.js').ParseOptions} [options]
|
|
326
|
+
*/
|
|
327
|
+
function parse(serialized, revivers, options) {
|
|
328
|
+
return unflatten(JSON.parse(serialized), revivers, options);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Revive a value flattened with `devalue.stringify`
|
|
332
|
+
* @param {number | any[]} parsed
|
|
333
|
+
* @param {Record<string, (value: any) => any>} [revivers]
|
|
334
|
+
* @param {import('./types.js').ParseOptions} [options]
|
|
335
|
+
*/
|
|
336
|
+
function unflatten(parsed, revivers, options) {
|
|
337
|
+
/** @type {import('./types.js').ParseOperations} */
|
|
338
|
+
const ops = merge_operations(default_parse_operations, options?.operations);
|
|
339
|
+
if (typeof parsed === "number") return hydrate(parsed, true);
|
|
340
|
+
if (!Array.isArray(parsed) || parsed.length === 0) invalid();
|
|
341
|
+
const values = parsed;
|
|
342
|
+
const hydrated = Array(values.length);
|
|
343
|
+
/**
|
|
344
|
+
* A set of values currently being hydrated with custom revivers,
|
|
345
|
+
* used to detect invalid cyclical dependencies
|
|
346
|
+
* @type {Set<number> | null}
|
|
347
|
+
*/
|
|
348
|
+
let hydrating = null;
|
|
349
|
+
/**
|
|
350
|
+
* @param {number} index
|
|
351
|
+
* @returns {any}
|
|
352
|
+
*/
|
|
353
|
+
function get_raw(index) {
|
|
354
|
+
if (!is_valid_array_index(index) || index >= values.length) invalid();
|
|
355
|
+
return values[index];
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* @param {number} index
|
|
359
|
+
* @returns {any}
|
|
360
|
+
*/
|
|
361
|
+
function hydrate(index, standalone = false) {
|
|
362
|
+
if (index === -1) return ops.fromPrimitive(void 0);
|
|
363
|
+
if (index === -3) return ops.fromPrimitive(NaN);
|
|
364
|
+
if (index === -4) return ops.fromPrimitive(Infinity);
|
|
365
|
+
if (index === -5) return ops.fromPrimitive(-Infinity);
|
|
366
|
+
if (index === -6) return ops.fromPrimitive(-0);
|
|
367
|
+
if (standalone || typeof index !== "number") invalid();
|
|
368
|
+
if (index in hydrated) return hydrated[index];
|
|
369
|
+
if (index >= values.length) invalid();
|
|
370
|
+
const value = values[index];
|
|
371
|
+
if (!value || typeof value !== "object") hydrated[index] = ops.fromPrimitive(value);
|
|
372
|
+
else if (Array.isArray(value)) if (typeof value[0] === "string") {
|
|
373
|
+
const type = value[0];
|
|
374
|
+
const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : void 0;
|
|
375
|
+
if (reviver) {
|
|
376
|
+
let i = value[1];
|
|
377
|
+
if (typeof i !== "number") i = values.push(value[1]) - 1;
|
|
378
|
+
if (Object.hasOwn(hydrated, i)) return hydrated[index] = reviver(hydrated[i]);
|
|
379
|
+
hydrating ??= /* @__PURE__ */ new Set();
|
|
380
|
+
if (hydrating.has(i)) throw new Error("Invalid circular reference");
|
|
381
|
+
hydrating.add(i);
|
|
382
|
+
hydrated[index] = reviver(hydrate(i));
|
|
383
|
+
hydrating.delete(i);
|
|
384
|
+
return hydrated[index];
|
|
385
|
+
}
|
|
386
|
+
switch (type) {
|
|
387
|
+
case "Date":
|
|
388
|
+
hydrated[index] = ops.fromISOString(value[1]);
|
|
389
|
+
break;
|
|
390
|
+
case "Set":
|
|
391
|
+
const set = ops.createSet();
|
|
392
|
+
hydrated[index] = set;
|
|
393
|
+
for (let i = 1; i < value.length; i += 1) ops.addValue(set, hydrate(value[i]));
|
|
394
|
+
break;
|
|
395
|
+
case "Map":
|
|
396
|
+
const map = ops.createMap();
|
|
397
|
+
hydrated[index] = map;
|
|
398
|
+
for (let i = 1; i < value.length; i += 2) ops.addEntry(map, hydrate(value[i]), hydrate(value[i + 1]));
|
|
399
|
+
break;
|
|
400
|
+
case "RegExp":
|
|
401
|
+
hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
|
|
402
|
+
break;
|
|
403
|
+
case "Object": {
|
|
404
|
+
const wrapped_index = value[1];
|
|
405
|
+
if (!(wrapped_index === -3 || wrapped_index === -4 || wrapped_index === -5 || wrapped_index === -6)) {
|
|
406
|
+
const wrapped = get_raw(wrapped_index);
|
|
407
|
+
const is_bigint = Array.isArray(wrapped) && wrapped[0] === "BigInt";
|
|
408
|
+
if ((wrapped === void 0 || typeof wrapped === "object") && !is_bigint) invalid();
|
|
409
|
+
}
|
|
410
|
+
hydrated[index] = ops.box(hydrate(wrapped_index));
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case "BigInt":
|
|
414
|
+
hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
|
|
415
|
+
break;
|
|
416
|
+
case "null":
|
|
417
|
+
const obj = ops.createNullPrototypeObject();
|
|
418
|
+
hydrated[index] = obj;
|
|
419
|
+
for (let i = 1; i < value.length; i += 2) {
|
|
420
|
+
const key = value[i];
|
|
421
|
+
if (typeof key !== "string") throw new Error("Cannot parse an object with a non-string key");
|
|
422
|
+
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
|
423
|
+
ops.set(obj, key, hydrate(value[i + 1]));
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
case "Int8Array":
|
|
427
|
+
case "Uint8Array":
|
|
428
|
+
case "Uint8ClampedArray":
|
|
429
|
+
case "Int16Array":
|
|
430
|
+
case "Uint16Array":
|
|
431
|
+
case "Float16Array":
|
|
432
|
+
case "Int32Array":
|
|
433
|
+
case "Uint32Array":
|
|
434
|
+
case "Float32Array":
|
|
435
|
+
case "Float64Array":
|
|
436
|
+
case "BigInt64Array":
|
|
437
|
+
case "BigUint64Array":
|
|
438
|
+
case "DataView": {
|
|
439
|
+
const buffer_index = value[1];
|
|
440
|
+
const raw = get_raw(buffer_index);
|
|
441
|
+
if (!Array.isArray(raw) || raw[0] !== "ArrayBuffer") invalid();
|
|
442
|
+
const buffer = hydrate(buffer_index);
|
|
443
|
+
hydrated[index] = ops.fromViewInfo(type, buffer, value[2], value[3]);
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
case "ArrayBuffer": {
|
|
447
|
+
const base64 = value[1];
|
|
448
|
+
if (typeof base64 !== "string") throw new Error("Invalid ArrayBuffer encoding");
|
|
449
|
+
hydrated[index] = ops.fromArrayBuffer(decode64(base64));
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
case "URL":
|
|
453
|
+
case "URLSearchParams":
|
|
454
|
+
case "Temporal.Duration":
|
|
455
|
+
case "Temporal.Instant":
|
|
456
|
+
case "Temporal.PlainDate":
|
|
457
|
+
case "Temporal.PlainTime":
|
|
458
|
+
case "Temporal.PlainDateTime":
|
|
459
|
+
case "Temporal.PlainMonthDay":
|
|
460
|
+
case "Temporal.PlainYearMonth":
|
|
461
|
+
case "Temporal.ZonedDateTime":
|
|
462
|
+
hydrated[index] = ops.fromStringValue(type, value[1]);
|
|
463
|
+
break;
|
|
464
|
+
default: throw new Error(`Unknown type ${type}`);
|
|
465
|
+
}
|
|
466
|
+
} else if (value[0] === -7) {
|
|
467
|
+
const len = value[1];
|
|
468
|
+
if (!is_valid_array_len(len)) invalid();
|
|
469
|
+
const array = ops.createSparseArray(len);
|
|
470
|
+
hydrated[index] = array;
|
|
471
|
+
for (let i = 2; i < value.length; i += 2) {
|
|
472
|
+
const idx = value[i];
|
|
473
|
+
if (!is_valid_array_index(idx) || idx >= len) invalid();
|
|
474
|
+
ops.set(array, idx, hydrate(value[i + 1]));
|
|
475
|
+
}
|
|
476
|
+
} else {
|
|
477
|
+
const array = ops.createArray(value.length);
|
|
478
|
+
hydrated[index] = array;
|
|
479
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
480
|
+
const n = value[i];
|
|
481
|
+
if (n === -2) continue;
|
|
482
|
+
ops.set(array, i, hydrate(n));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
const object = ops.createObject();
|
|
487
|
+
hydrated[index] = object;
|
|
488
|
+
for (const key of Object.keys(value)) {
|
|
489
|
+
if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
|
|
490
|
+
ops.set(object, key, hydrate(value[key]));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return hydrated[index];
|
|
494
|
+
}
|
|
495
|
+
return hydrate(0);
|
|
496
|
+
}
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region ../../node_modules/.pnpm/devalue@6.0.2/node_modules/devalue/src/stringify.js
|
|
499
|
+
/**
|
|
500
|
+
* Turn a value into a JSON string that can be parsed with `devalue.parse`
|
|
501
|
+
* @param {any} value
|
|
502
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
503
|
+
* @param {import('./types.js').StringifyOptions} [options]
|
|
504
|
+
*/
|
|
505
|
+
function stringify(value, reducers, options) {
|
|
506
|
+
const stringified = run(false, value, reducers, options);
|
|
507
|
+
return typeof stringified === "string" ? stringified : `[${stringified.join(",")}]`;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* @param {boolean} async
|
|
511
|
+
* @param {any} value
|
|
512
|
+
* @param {Record<string, (value: any) => any>} [reducers]
|
|
513
|
+
* @param {import('./types.js').StringifyOptions} [options]
|
|
514
|
+
*/
|
|
515
|
+
function run(async, value, reducers, options) {
|
|
516
|
+
const ops = merge_operations(default_stringify_operations, options?.operations);
|
|
517
|
+
/** @type {any[]} */
|
|
518
|
+
const stringified = [];
|
|
519
|
+
/** @type {Map<any, number>} */
|
|
520
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
521
|
+
/** @type {Array<{ key: string, fn: (value: any) => any }>} */
|
|
522
|
+
const custom = [];
|
|
523
|
+
if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
|
|
524
|
+
key,
|
|
525
|
+
fn: reducers[key]
|
|
526
|
+
});
|
|
527
|
+
/** @type {any[]} */
|
|
528
|
+
let keys = [];
|
|
529
|
+
let p = 0;
|
|
530
|
+
/**
|
|
531
|
+
* @param {string} message
|
|
532
|
+
* @param {any} thing
|
|
533
|
+
* @returns {never}
|
|
534
|
+
*/
|
|
535
|
+
function error(message, thing) {
|
|
536
|
+
throw new DevalueError(message, format_path(keys, (key) => {
|
|
537
|
+
const key_type = ops.typeOf(key);
|
|
538
|
+
return key_type !== "object" && key_type !== "function" && key_type !== "symbol" ? stringify_primitive(ops.toPrimitive(key)) : "...";
|
|
539
|
+
}), thing, value);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* @param {any} thing
|
|
543
|
+
* @param {number} [index]
|
|
544
|
+
*/
|
|
545
|
+
function flatten(thing, index) {
|
|
546
|
+
const type = ops.typeOf(thing);
|
|
547
|
+
if (type === "undefined") return -1;
|
|
548
|
+
/** @type {number | undefined} */
|
|
549
|
+
let number;
|
|
550
|
+
if (type === "number") {
|
|
551
|
+
number = ops.toPrimitive(thing);
|
|
552
|
+
if (Number.isNaN(number)) return -3;
|
|
553
|
+
if (number === Infinity) return -4;
|
|
554
|
+
if (number === -Infinity) return -5;
|
|
555
|
+
if (number === 0 && 1 / number < 0) return -6;
|
|
556
|
+
}
|
|
557
|
+
const id = ops.identify(thing);
|
|
558
|
+
if (indexes.has(id)) return indexes.get(id);
|
|
559
|
+
index ??= p++;
|
|
560
|
+
indexes.set(id, index);
|
|
561
|
+
for (const { key, fn } of custom) {
|
|
562
|
+
const value = fn(thing);
|
|
563
|
+
if (value) {
|
|
564
|
+
stringified[index] = `["${key}",${flatten(value)}]`;
|
|
565
|
+
return index;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (type === "function") error(`Cannot stringify a function`, thing);
|
|
569
|
+
else if (type === "symbol") error(`Cannot stringify a Symbol primitive`, thing);
|
|
570
|
+
/** @type {string | Promise<any>} */
|
|
571
|
+
let str = "";
|
|
572
|
+
if (type !== "object") str = stringify_primitive(type === "number" ? number : ops.toPrimitive(thing));
|
|
573
|
+
else if (ops.isThenable(thing)) {
|
|
574
|
+
if (!async) error(`Cannot stringify a Promise or thenable — use stringifyAsync instead`, thing);
|
|
575
|
+
const prev_keys = keys.slice();
|
|
576
|
+
str = ops.toPromise(thing).then((value) => {
|
|
577
|
+
keys = prev_keys;
|
|
578
|
+
const i = flatten(value, index);
|
|
579
|
+
if (i < 0) stringified[index] = i;
|
|
580
|
+
});
|
|
581
|
+
str.catch(() => {});
|
|
582
|
+
} else {
|
|
583
|
+
const tag = ops.tagOf(thing);
|
|
584
|
+
switch (tag) {
|
|
585
|
+
case "Number":
|
|
586
|
+
case "String":
|
|
587
|
+
case "Boolean":
|
|
588
|
+
case "BigInt":
|
|
589
|
+
str = `["Object",${flatten(ops.unbox(thing))}]`;
|
|
590
|
+
break;
|
|
591
|
+
case "Date":
|
|
592
|
+
str = `["Date","${ops.toISOString(thing)}"]`;
|
|
593
|
+
break;
|
|
594
|
+
case "URL":
|
|
595
|
+
str = `["URL",${stringify_string(ops.toStringValue(thing))}]`;
|
|
596
|
+
break;
|
|
597
|
+
case "URLSearchParams":
|
|
598
|
+
str = `["URLSearchParams",${stringify_string(ops.toStringValue(thing))}]`;
|
|
599
|
+
break;
|
|
600
|
+
case "RegExp":
|
|
601
|
+
const { source, flags } = ops.regExpInfo(thing);
|
|
602
|
+
str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
|
|
603
|
+
break;
|
|
604
|
+
case "Array": {
|
|
605
|
+
let mostly_dense = false;
|
|
606
|
+
const length = ops.lengthOf(thing);
|
|
607
|
+
str = "[";
|
|
608
|
+
for (let i = 0; i < length; i += 1) {
|
|
609
|
+
if (i > 0) str += ",";
|
|
610
|
+
if (ops.hasOwn(thing, i)) {
|
|
611
|
+
keys.push(i);
|
|
612
|
+
str += flatten(ops.get(thing, i));
|
|
613
|
+
keys.pop();
|
|
614
|
+
} else if (mostly_dense) str += -2;
|
|
615
|
+
else {
|
|
616
|
+
const populated_keys = ops.indicesOf(thing);
|
|
617
|
+
const population = populated_keys.length;
|
|
618
|
+
const d = String(length).length;
|
|
619
|
+
if ((length - population) * 3 > 4 + d + population * (d + 1)) {
|
|
620
|
+
str = "[-7," + length;
|
|
621
|
+
for (let j = 0; j < populated_keys.length; j++) {
|
|
622
|
+
const key = populated_keys[j];
|
|
623
|
+
keys.push(+key);
|
|
624
|
+
str += "," + key + "," + flatten(ops.get(thing, key));
|
|
625
|
+
keys.pop();
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
628
|
+
} else {
|
|
629
|
+
mostly_dense = true;
|
|
630
|
+
str += -2;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
str += "]";
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
case "Set":
|
|
638
|
+
str = "[\"Set\"";
|
|
639
|
+
for (const value of ops.valuesOf(thing)) str += `,${flatten(value)}`;
|
|
640
|
+
str += "]";
|
|
641
|
+
break;
|
|
642
|
+
case "Map":
|
|
643
|
+
str = "[\"Map\"";
|
|
644
|
+
for (const [key, value] of ops.entriesOf(thing)) {
|
|
645
|
+
keys.push(MAP_KEY, key);
|
|
646
|
+
str += `,${flatten(key)},${flatten(value)}`;
|
|
647
|
+
keys.pop();
|
|
648
|
+
keys.pop();
|
|
649
|
+
}
|
|
650
|
+
str += "]";
|
|
651
|
+
break;
|
|
652
|
+
case "Int8Array":
|
|
653
|
+
case "Uint8Array":
|
|
654
|
+
case "Uint8ClampedArray":
|
|
655
|
+
case "Int16Array":
|
|
656
|
+
case "Uint16Array":
|
|
657
|
+
case "Float16Array":
|
|
658
|
+
case "Int32Array":
|
|
659
|
+
case "Uint32Array":
|
|
660
|
+
case "Float32Array":
|
|
661
|
+
case "Float64Array":
|
|
662
|
+
case "BigInt64Array":
|
|
663
|
+
case "BigUint64Array": {
|
|
664
|
+
const info = ops.viewInfo(thing);
|
|
665
|
+
str = "[\"" + tag + "\"," + flatten(info.buffer);
|
|
666
|
+
if (info.byteLength !== info.bufferByteLength) str += `,${info.byteOffset},${info.length}`;
|
|
667
|
+
str += "]";
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
case "DataView": {
|
|
671
|
+
const info = ops.viewInfo(thing);
|
|
672
|
+
str = "[\"" + tag + "\"," + flatten(info.buffer);
|
|
673
|
+
if (info.byteLength !== info.bufferByteLength) str += `,${info.byteOffset},${info.byteLength}`;
|
|
674
|
+
str += "]";
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "ArrayBuffer":
|
|
678
|
+
str = `["ArrayBuffer","${encode64(ops.toArrayBuffer(thing))}"]`;
|
|
679
|
+
break;
|
|
680
|
+
case "Temporal.Duration":
|
|
681
|
+
case "Temporal.Instant":
|
|
682
|
+
case "Temporal.PlainDate":
|
|
683
|
+
case "Temporal.PlainTime":
|
|
684
|
+
case "Temporal.PlainDateTime":
|
|
685
|
+
case "Temporal.PlainMonthDay":
|
|
686
|
+
case "Temporal.PlainYearMonth":
|
|
687
|
+
case "Temporal.ZonedDateTime":
|
|
688
|
+
str = `["${tag}",${stringify_string(ops.toStringValue(thing))}]`;
|
|
689
|
+
break;
|
|
690
|
+
default: {
|
|
691
|
+
const shape = ops.shapeOf(thing);
|
|
692
|
+
if (shape.kind === "not-plain") error(`Cannot stringify arbitrary non-POJOs`, thing);
|
|
693
|
+
if (shape.kind === "symbol-keys") error(`Cannot stringify POJOs with symbolic keys`, thing);
|
|
694
|
+
if (shape.kind === "null-proto") {
|
|
695
|
+
str = "[\"null\"";
|
|
696
|
+
for (const key of shape.keys) {
|
|
697
|
+
if (key === "__proto__") error(`Cannot stringify objects with __proto__ keys`, thing);
|
|
698
|
+
keys.push(key);
|
|
699
|
+
str += `,${quote_key(key)},${flatten(ops.get(thing, key))}`;
|
|
700
|
+
keys.pop();
|
|
701
|
+
}
|
|
702
|
+
str += "]";
|
|
703
|
+
} else {
|
|
704
|
+
str = "{";
|
|
705
|
+
let started = false;
|
|
706
|
+
for (const key of shape.keys) {
|
|
707
|
+
if (key === "__proto__") error(`Cannot stringify objects with __proto__ keys`, thing);
|
|
708
|
+
if (started) str += ",";
|
|
709
|
+
started = true;
|
|
710
|
+
keys.push(key);
|
|
711
|
+
str += `${quote_key(key)}:${flatten(ops.get(thing, key))}`;
|
|
712
|
+
keys.pop();
|
|
713
|
+
}
|
|
714
|
+
str += "}";
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
stringified[index] = str;
|
|
720
|
+
return index;
|
|
721
|
+
}
|
|
722
|
+
const index = flatten(value);
|
|
723
|
+
if (index < 0) return `${index}`;
|
|
724
|
+
return stringified;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* @param {any} thing
|
|
728
|
+
* @returns {string}
|
|
729
|
+
*/
|
|
730
|
+
function stringify_primitive(thing) {
|
|
731
|
+
const type = typeof thing;
|
|
732
|
+
if (type === "string") return stringify_string(thing);
|
|
733
|
+
if (thing === void 0) return (-1).toString();
|
|
734
|
+
if (thing === 0 && 1 / thing < 0) return (-6).toString();
|
|
735
|
+
if (type === "bigint") return `["BigInt","${thing}"]`;
|
|
736
|
+
return String(thing);
|
|
737
|
+
}
|
|
738
|
+
//#endregion
|
|
739
|
+
//#region src/shared/values.ts
|
|
740
|
+
/** Encodes supported values without reducers, preserving presence and graph references. */
|
|
741
|
+
function encode(value) {
|
|
742
|
+
return stringify(value);
|
|
743
|
+
}
|
|
744
|
+
const pathSegment = /^(?:\.get\(("(?:[^"\\]|\\.)*"|[^)]*)\)|\.([A-Za-z_$][\w$]*)|\[(\d+)\]|\[("(?:[^"\\]|\\.)*")\])/;
|
|
745
|
+
/**
|
|
746
|
+
* Converts devalue's formatted error path, such as `.tags[0]` or `.map.get("key")`, into
|
|
747
|
+
* property segments. Map entries are identified by their key; unparsable text is kept whole.
|
|
748
|
+
*/
|
|
749
|
+
function valuePath(formatted) {
|
|
750
|
+
const segments = [];
|
|
751
|
+
let rest = formatted;
|
|
752
|
+
while (rest) {
|
|
753
|
+
const match = pathSegment.exec(rest);
|
|
754
|
+
if (!match) return [formatted];
|
|
755
|
+
const [text, mapKey, identifier, index, quoted] = match;
|
|
756
|
+
if (identifier !== void 0) segments.push(identifier);
|
|
757
|
+
else if (index !== void 0) segments.push(Number(index));
|
|
758
|
+
else if (quoted !== void 0) segments.push(JSON.parse(quoted));
|
|
759
|
+
else {
|
|
760
|
+
const key = mapKey;
|
|
761
|
+
segments.push(key.startsWith("\"") ? JSON.parse(key) : /^-?\d+(?:\.\d+)?$/.test(key) ? Number(key) : key);
|
|
762
|
+
}
|
|
763
|
+
rest = rest.slice(text.length);
|
|
764
|
+
}
|
|
765
|
+
return segments;
|
|
766
|
+
}
|
|
767
|
+
/** Restores supported values without invoking application schemas or transforms. */
|
|
768
|
+
function decode(encoded) {
|
|
769
|
+
return parse(encoded);
|
|
770
|
+
}
|
|
771
|
+
/** Reads the built-in tag that the encoder uses to choose a value's encoding. */
|
|
772
|
+
function tagOf(value) {
|
|
773
|
+
return Object.prototype.toString.call(value);
|
|
774
|
+
}
|
|
775
|
+
/** Marks a graph that only the general encode/decode round trip can detach faithfully. */
|
|
776
|
+
const general = Symbol("general");
|
|
777
|
+
/**
|
|
778
|
+
* Copies a graph of primitives, plain or null-prototype objects, dense arrays, and dates
|
|
779
|
+
* directly. Each object must pass the same tag, thenable, symbol-key, and `__proto__` checks
|
|
780
|
+
* that the encoder applies; objects and dates also need their standard prototype. The encoder
|
|
781
|
+
* reads any array-tagged value by index, so array subclasses and arrays from other realms
|
|
782
|
+
* copy into ordinary arrays either way. Anything else returns `general` so the caller detaches
|
|
783
|
+
* the whole graph through devalue, which keeps aliases consistent across rich values and
|
|
784
|
+
* reports unsupported values with their paths.
|
|
785
|
+
*/
|
|
786
|
+
function copyDirect(value, copies) {
|
|
787
|
+
if (typeof value !== "object" || value === null) return typeof value === "function" || typeof value === "symbol" ? general : value;
|
|
788
|
+
const existing = copies.get(value);
|
|
789
|
+
if (existing !== void 0) return existing;
|
|
790
|
+
if (typeof value.then === "function") return general;
|
|
791
|
+
const tag = tagOf(value);
|
|
792
|
+
if (tag === "[object Array]") {
|
|
793
|
+
const source = value;
|
|
794
|
+
const copy = [];
|
|
795
|
+
copies.set(value, copy);
|
|
796
|
+
for (let index = 0; index < source.length; index++) {
|
|
797
|
+
const item = source[index];
|
|
798
|
+
if (item === void 0 && !Object.hasOwn(source, index)) return general;
|
|
799
|
+
const copied = copyDirect(item, copies);
|
|
800
|
+
if (copied === general) return general;
|
|
801
|
+
copy.push(copied);
|
|
802
|
+
}
|
|
803
|
+
return copy;
|
|
804
|
+
}
|
|
805
|
+
const prototype = Object.getPrototypeOf(value);
|
|
806
|
+
if (tag === "[object Object]" && (prototype === Object.prototype || prototype === null)) {
|
|
807
|
+
if (Object.getOwnPropertySymbols(value).length) return general;
|
|
808
|
+
const source = value;
|
|
809
|
+
const copy = prototype === null ? Object.create(null) : {};
|
|
810
|
+
copies.set(value, copy);
|
|
811
|
+
for (const key of Object.keys(source)) {
|
|
812
|
+
if (key === "__proto__") return general;
|
|
813
|
+
const copied = copyDirect(source[key], copies);
|
|
814
|
+
if (copied === general) return general;
|
|
815
|
+
copy[key] = copied;
|
|
816
|
+
}
|
|
817
|
+
return copy;
|
|
818
|
+
}
|
|
819
|
+
if (tag === "[object Date]" && prototype === Date.prototype) {
|
|
820
|
+
const copy = new Date(value.getTime());
|
|
821
|
+
copies.set(value, copy);
|
|
822
|
+
return copy;
|
|
823
|
+
}
|
|
824
|
+
return general;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Detaches an entire value graph with the supported-value semantics, preserving cycles and
|
|
828
|
+
* repeated references. Graphs of primitives, plain objects, dense arrays, and dates are copied
|
|
829
|
+
* directly; any other graph, including one containing a `Map`, an array hole, or an unsupported
|
|
830
|
+
* value, takes the devalue encode/decode round trip as a whole, which throws for unsupported
|
|
831
|
+
* values. Getters on a graph that falls back can therefore be read twice.
|
|
832
|
+
*
|
|
833
|
+
* @param value - The value to copy; it is never modified.
|
|
834
|
+
* @returns An independent copy that callers can mutate without affecting `value`.
|
|
835
|
+
*/
|
|
836
|
+
function detach(value) {
|
|
837
|
+
const copied = copyDirect(value, /* @__PURE__ */ new Map());
|
|
838
|
+
return copied === general ? decode(encode(value)) : copied;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Detaches the named fields of one record together, so references shared between selected
|
|
842
|
+
* fields remain shared in the result. Every name becomes an own enumerable property, including
|
|
843
|
+
* `__proto__`, and missing fields become own `undefined` values. Each field is read once.
|
|
844
|
+
*
|
|
845
|
+
* @param record - The stored record to read; it is never modified.
|
|
846
|
+
* @param fields - The selected field names, in result order.
|
|
847
|
+
* @returns A new object containing detached copies of the selected values.
|
|
848
|
+
*/
|
|
849
|
+
function detachSelection(record, fields) {
|
|
850
|
+
const values = fields.map((field) => Object.hasOwn(record, field) ? record[field] : void 0);
|
|
851
|
+
const copies = /* @__PURE__ */ new Map();
|
|
852
|
+
const selection = {};
|
|
853
|
+
for (let index = 0; index < fields.length; index++) {
|
|
854
|
+
const copied = copyDirect(values[index], copies);
|
|
855
|
+
if (copied === general) return Object.fromEntries(decode(encode(new Map(fields.map((field, position) => [field, values[position]])))));
|
|
856
|
+
const field = fields[index];
|
|
857
|
+
if (field === "__proto__") Object.defineProperty(selection, field, {
|
|
858
|
+
value: copied,
|
|
859
|
+
enumerable: true,
|
|
860
|
+
configurable: true,
|
|
861
|
+
writable: true
|
|
862
|
+
});
|
|
863
|
+
else selection[field] = copied;
|
|
864
|
+
}
|
|
865
|
+
return selection;
|
|
866
|
+
}
|
|
867
|
+
/** Compares strings by Unicode code point rather than locale or UTF-16 code unit. */
|
|
868
|
+
function compareStrings(left, right) {
|
|
869
|
+
const leftPoints = Array.from(left, (character) => character.codePointAt(0));
|
|
870
|
+
const rightPoints = Array.from(right, (character) => character.codePointAt(0));
|
|
871
|
+
for (let index = 0; index < Math.min(leftPoints.length, rightPoints.length); index++) if (leftPoints[index] !== rightPoints[index]) return leftPoints[index] < rightPoints[index] ? -1 : 1;
|
|
872
|
+
return Math.sign(leftPoints.length - rightPoints.length);
|
|
873
|
+
}
|
|
874
|
+
/** Tests the scalar categories accepted by equality and relationship matching. */
|
|
875
|
+
function isScalar(value) {
|
|
876
|
+
return value == null || [
|
|
877
|
+
"string",
|
|
878
|
+
"number",
|
|
879
|
+
"bigint",
|
|
880
|
+
"boolean"
|
|
881
|
+
].includes(typeof value) || value instanceof Date;
|
|
882
|
+
}
|
|
883
|
+
/** Applies scalar equality with date timestamps and SameValueZero numeric behavior. */
|
|
884
|
+
function equal(left, right) {
|
|
885
|
+
if (left instanceof Date || right instanceof Date) return left instanceof Date && right instanceof Date && equal(left.getTime(), right.getTime());
|
|
886
|
+
return left === right || typeof left === "number" && typeof right === "number" && Number.isNaN(left) && Number.isNaN(right);
|
|
887
|
+
}
|
|
888
|
+
/** Orders comparable scalar values; undefined denotes incomparable values. */
|
|
889
|
+
function compare(left, right) {
|
|
890
|
+
if (left == null || right == null) return;
|
|
891
|
+
if (left instanceof Date || right instanceof Date) return left instanceof Date && right instanceof Date ? compare(left.getTime(), right.getTime()) : void 0;
|
|
892
|
+
if (typeof left !== typeof right) return;
|
|
893
|
+
if (typeof left === "string" && typeof right === "string") return compareStrings(left, right);
|
|
894
|
+
if (typeof left === "number" && typeof right === "number" || typeof left === "bigint" && typeof right === "bigint" || typeof left === "boolean" && typeof right === "boolean") {
|
|
895
|
+
if (typeof left === "number" && (Number.isNaN(left) || Number.isNaN(right))) return;
|
|
896
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
//#endregion
|
|
900
|
+
export { detachSelection as a, isScalar as c, detach as i, valuePath as l, compareStrings as n, encode as o, decode as r, equal as s, compare as t };
|