@qilin-agent/util-values 0.0.0-stage → 3.1.4
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.i18n.yaml +43 -0
- package/README.md +94 -2
- package/README.zh.md +95 -0
- package/lib/index.js +923 -0
- package/lib/types/index.d.ts +78 -0
- package/lib/types/partial-json.d.ts +152 -0
- package/package.json +35 -3
package/lib/index.js
ADDED
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
//#region lib/types/partial-json.js
|
|
2
|
+
/**
|
|
3
|
+
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
4
|
+
* that may still be streaming or from an already parsed object. Nothing is
|
|
5
|
+
* scanned until a reader asks; the view remembers every question it answered
|
|
6
|
+
* and reports changed answers when the owner refreshes for publication.
|
|
7
|
+
* Used for model tool-call arguments: a row reads the fields it
|
|
8
|
+
* cares about at whatever granularity it displays, at every stage of the call.
|
|
9
|
+
* @module @qilin-agent/util-values/src/partial-json
|
|
10
|
+
*/
|
|
11
|
+
const SIMPLE_ESCAPES = {
|
|
12
|
+
"\"": "\"",
|
|
13
|
+
"\\": "\\",
|
|
14
|
+
"/": "/",
|
|
15
|
+
b: "\b",
|
|
16
|
+
f: "\f",
|
|
17
|
+
n: "\n",
|
|
18
|
+
r: "\r",
|
|
19
|
+
t: " "
|
|
20
|
+
};
|
|
21
|
+
const CONTENT_ESCAPE = /[\\\u0000-\u001f]/u;
|
|
22
|
+
function isWhitespace(c) {
|
|
23
|
+
return c === " " || c === "\n" || c === "\r" || c === " ";
|
|
24
|
+
}
|
|
25
|
+
function isHex(c) {
|
|
26
|
+
return c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The view. A streaming instance grows through {@link PartialArguments.append};
|
|
30
|
+
* {@link PartialArguments.fromText} and {@link PartialArguments.fromObject} build
|
|
31
|
+
* sealed instances over a finished call. Every reader is total: an absent or
|
|
32
|
+
* differently typed field answers `undefined` (or `false`), never throws.
|
|
33
|
+
*/
|
|
34
|
+
var PartialArguments = class PartialArguments {
|
|
35
|
+
/** The view of a call with no arguments available. */
|
|
36
|
+
static EMPTY = PartialArguments.fromObject({});
|
|
37
|
+
/**
|
|
38
|
+
* View finished argument text without scanning it until a reader asks.
|
|
39
|
+
* @param text - the complete argument JSON text.
|
|
40
|
+
* @returns a sealed view.
|
|
41
|
+
*/
|
|
42
|
+
static fromText(text) {
|
|
43
|
+
const view = new PartialArguments();
|
|
44
|
+
view.append(text);
|
|
45
|
+
view.sealed = true;
|
|
46
|
+
return view;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* View an already parsed argument payload, such as a PTC dispatch object.
|
|
50
|
+
* @param value - the parsed argument value.
|
|
51
|
+
* @returns a sealed view; a non-object payload has no fields.
|
|
52
|
+
*/
|
|
53
|
+
static fromObject(value) {
|
|
54
|
+
const view = new PartialArguments();
|
|
55
|
+
view.object = typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
56
|
+
view.sealed = true;
|
|
57
|
+
return view;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The source: text so far or a parsed object, plus whether it can still grow.
|
|
61
|
+
* These are the only enumerable fields, so two views over the same source
|
|
62
|
+
* compare equal structurally however far each has been read.
|
|
63
|
+
*/
|
|
64
|
+
chunks = [];
|
|
65
|
+
object;
|
|
66
|
+
sealed = false;
|
|
67
|
+
#ends = [];
|
|
68
|
+
#size = 0;
|
|
69
|
+
#consumed = 0;
|
|
70
|
+
#mode = "root";
|
|
71
|
+
#escape = false;
|
|
72
|
+
#keyStart = 0;
|
|
73
|
+
#keyEscaped = false;
|
|
74
|
+
#key = "";
|
|
75
|
+
#current = null;
|
|
76
|
+
#nestedEnds = [];
|
|
77
|
+
#nestedInString = false;
|
|
78
|
+
#invalidAt;
|
|
79
|
+
#invalidValue = false;
|
|
80
|
+
#entries = /* @__PURE__ */ new Map();
|
|
81
|
+
#order = [];
|
|
82
|
+
#reads = /* @__PURE__ */ new Map();
|
|
83
|
+
/** Whether this view rejects further appends; does not scan text or register reads. */
|
|
84
|
+
get isSealed() {
|
|
85
|
+
return this.sealed;
|
|
86
|
+
}
|
|
87
|
+
/** Whether indexing or a content read found invalid JSON; unread value contents are not validated. */
|
|
88
|
+
get invalid() {
|
|
89
|
+
this.scan();
|
|
90
|
+
return this.#mode === "invalid" || this.#invalidValue;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retain streamed argument text without scanning or comparing observed answers.
|
|
94
|
+
* @param fragment - the text following every fragment appended before.
|
|
95
|
+
*/
|
|
96
|
+
append(fragment) {
|
|
97
|
+
if (this.sealed) throw new Error("PartialArguments: cannot append to a sealed view");
|
|
98
|
+
if (fragment.length === 0) return;
|
|
99
|
+
this.chunks.push(fragment);
|
|
100
|
+
this.#size += fragment.length;
|
|
101
|
+
this.#ends.push(this.#size);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Reconcile a streamed prefix with authoritative complete text without joining the fragments.
|
|
105
|
+
* @param text - the final argument text, which replaces missing or conflicting deltas.
|
|
106
|
+
* @returns this view sealed with its caches retained when every character matches; otherwise a new sealed view.
|
|
107
|
+
*/
|
|
108
|
+
settle(text) {
|
|
109
|
+
if (this.object !== void 0 || text.length !== this.#size) return PartialArguments.fromText(text);
|
|
110
|
+
let offset = 0;
|
|
111
|
+
for (const chunk of this.chunks) {
|
|
112
|
+
if (!text.startsWith(chunk, offset)) return PartialArguments.fromText(text);
|
|
113
|
+
offset += chunk.length;
|
|
114
|
+
}
|
|
115
|
+
this.chunks = text.length === 0 ? [] : [text];
|
|
116
|
+
this.#ends = text.length === 0 ? [] : [text.length];
|
|
117
|
+
this.sealed = true;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Compare observed answers and advance their publication baseline. Unread views remain unscanned.
|
|
122
|
+
* @returns whether any observed answer changed since its first read or the preceding refresh.
|
|
123
|
+
*/
|
|
124
|
+
refresh() {
|
|
125
|
+
if (this.#reads.size === 0) return false;
|
|
126
|
+
this.scan();
|
|
127
|
+
let changed = false;
|
|
128
|
+
let completions = false;
|
|
129
|
+
for (const read of this.#reads.values()) {
|
|
130
|
+
if (read.completion) {
|
|
131
|
+
completions = true;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
changed = this.refreshRead(read) || changed;
|
|
135
|
+
}
|
|
136
|
+
if (completions) {
|
|
137
|
+
for (const read of this.#reads.values()) if (read.completion) changed = this.refreshRead(read) || changed;
|
|
138
|
+
}
|
|
139
|
+
if (this.sealed) this.#reads.clear();
|
|
140
|
+
return changed;
|
|
141
|
+
}
|
|
142
|
+
refreshRead(read) {
|
|
143
|
+
const now = read.answer();
|
|
144
|
+
if (Object.is(now, read.last)) return false;
|
|
145
|
+
read.last = now;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check whether no further fields can arrive.
|
|
150
|
+
* @returns whether the outer object closed, indexing failed, or the view is sealed; unread values are not validated.
|
|
151
|
+
*/
|
|
152
|
+
closed() {
|
|
153
|
+
return this.remember("closed", "", () => this.closedNow());
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* List discovered fields in first-appearance order.
|
|
157
|
+
* @returns top-level keys seen so far, in first-appearance order.
|
|
158
|
+
*/
|
|
159
|
+
keys() {
|
|
160
|
+
return this.remember("keys", "", () => this.keysNow(), (keys) => keys.length);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check whether a top-level field has appeared.
|
|
164
|
+
* @param key - argument name.
|
|
165
|
+
* @returns whether the field has appeared (a string opened or another value began).
|
|
166
|
+
*/
|
|
167
|
+
has(key) {
|
|
168
|
+
return this.remember("has", key, () => this.hasNow(key));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Check whether a field's closing delimiter has arrived, without validating its contents.
|
|
172
|
+
* @param key - argument name.
|
|
173
|
+
* @returns whether its delimiter arrived and no content reader has reported an error for this value.
|
|
174
|
+
*/
|
|
175
|
+
complete(key) {
|
|
176
|
+
return this.remember("complete", key, () => this.completeNow(key));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Read string length without materializing its text.
|
|
180
|
+
* @param key - argument name.
|
|
181
|
+
* @param options - change granularity for a streaming string.
|
|
182
|
+
* @returns decoded UTF-16 length of the string field so far; undefined when absent or not a string.
|
|
183
|
+
*/
|
|
184
|
+
stringLength(key, options) {
|
|
185
|
+
const step = Math.max(1, Math.floor(options?.step ?? 1));
|
|
186
|
+
const offset = options?.offset ?? 0;
|
|
187
|
+
return this.remember(`length:${step}:${offset}`, key, () => this.lengthNow(key), (length) => length === void 0 ? void 0 : Math.ceil((length + offset) / step));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Check a string against a decoded UTF-16 length limit without materializing it.
|
|
191
|
+
* @param key - argument name.
|
|
192
|
+
* @param maxLength - decoded UTF-16 limit, floored to at least zero.
|
|
193
|
+
* @returns whether the string is longer than the limit; false when absent or not a string.
|
|
194
|
+
*/
|
|
195
|
+
stringExceeds(key, maxLength) {
|
|
196
|
+
const limit = Math.max(0, Math.floor(maxLength));
|
|
197
|
+
return this.remember(`exceeds:${limit}`, key, () => (this.lengthNow(key, limit + 1) ?? 0) > limit);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Read a decoded string, including a streaming prefix.
|
|
201
|
+
* @param key - argument name.
|
|
202
|
+
* @returns the string field's decoded text so far; undefined when absent or not a string.
|
|
203
|
+
*/
|
|
204
|
+
text(key) {
|
|
205
|
+
return this.remember("text", key, () => this.textNow(key));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Read at most the first decoded UTF-16 units of a string.
|
|
209
|
+
* @param key - argument name.
|
|
210
|
+
* @param maxLength - maximum decoded UTF-16 length, floored to at least one.
|
|
211
|
+
* @returns the bounded string prefix; undefined when absent or not a string.
|
|
212
|
+
*/
|
|
213
|
+
textPrefix(key, maxLength) {
|
|
214
|
+
const limit = Math.max(1, Math.floor(maxLength));
|
|
215
|
+
return this.remember(`prefix:${limit}`, key, () => this.textPrefixNow(key, limit));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Read a completed non-string argument.
|
|
219
|
+
* @param key - argument name.
|
|
220
|
+
* @returns the parsed non-string value once it closed; undefined while open, absent, or a string.
|
|
221
|
+
*/
|
|
222
|
+
value(key) {
|
|
223
|
+
return this.remember("value", key, () => this.valueNow(key));
|
|
224
|
+
}
|
|
225
|
+
/** Answer a question and, on a streaming view, remember it for change detection. */
|
|
226
|
+
remember(kind, key, read, comparison) {
|
|
227
|
+
this.scan();
|
|
228
|
+
const result = read();
|
|
229
|
+
if (!this.sealed) {
|
|
230
|
+
const id = `${kind}/${key}`;
|
|
231
|
+
if (!this.#reads.has(id)) this.#reads.set(id, {
|
|
232
|
+
completion: kind === "complete",
|
|
233
|
+
answer: comparison === void 0 ? read : () => comparison(read()),
|
|
234
|
+
last: comparison === void 0 ? result : comparison(result)
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
closedNow() {
|
|
240
|
+
return this.sealed || this.#mode === "closed" || this.#mode === "invalid";
|
|
241
|
+
}
|
|
242
|
+
keysNow() {
|
|
243
|
+
return this.object === void 0 ? this.#order : Object.keys(this.object);
|
|
244
|
+
}
|
|
245
|
+
hasNow(key) {
|
|
246
|
+
return this.object === void 0 ? this.#entries.has(key) : Object.hasOwn(this.object, key);
|
|
247
|
+
}
|
|
248
|
+
completeNow(key) {
|
|
249
|
+
if (this.object !== void 0) return Object.hasOwn(this.object, key);
|
|
250
|
+
const entry = this.#entries.get(key);
|
|
251
|
+
return entry !== void 0 && entry.end >= 0 && (entry.kind === "string" ? entry.invalidAt === void 0 : !entry.invalid);
|
|
252
|
+
}
|
|
253
|
+
lengthNow(key, limit = Number.POSITIVE_INFINITY) {
|
|
254
|
+
if (this.object !== void 0) {
|
|
255
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
256
|
+
return typeof field === "string" ? field.length : void 0;
|
|
257
|
+
}
|
|
258
|
+
const entry = this.#entries.get(key);
|
|
259
|
+
if (entry?.kind !== "string") return void 0;
|
|
260
|
+
if (entry.text !== void 0 && entry.text.at === entry.end) return entry.text.length;
|
|
261
|
+
const read = entry.length ??= {
|
|
262
|
+
at: entry.start,
|
|
263
|
+
length: 0,
|
|
264
|
+
text: ""
|
|
265
|
+
};
|
|
266
|
+
this.readString(entry, read, limit, false);
|
|
267
|
+
return read.length;
|
|
268
|
+
}
|
|
269
|
+
textNow(key) {
|
|
270
|
+
if (this.object !== void 0) {
|
|
271
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
272
|
+
return typeof field === "string" ? field : void 0;
|
|
273
|
+
}
|
|
274
|
+
const entry = this.#entries.get(key);
|
|
275
|
+
if (entry?.kind !== "string") return void 0;
|
|
276
|
+
if (entry.text === void 0 && entry.end >= 0 && entry.needsDecoding && entry.invalidAt === void 0) {
|
|
277
|
+
let text;
|
|
278
|
+
try {
|
|
279
|
+
text = JSON.parse(`"${this.slice(entry.start, entry.end)}"`);
|
|
280
|
+
} catch (_error) {}
|
|
281
|
+
if (text !== void 0) entry.text = {
|
|
282
|
+
at: entry.end,
|
|
283
|
+
length: text.length,
|
|
284
|
+
text
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const read = entry.text ??= {
|
|
288
|
+
at: entry.start,
|
|
289
|
+
length: 0,
|
|
290
|
+
text: ""
|
|
291
|
+
};
|
|
292
|
+
this.readString(entry, read, Number.POSITIVE_INFINITY, true);
|
|
293
|
+
return read.text;
|
|
294
|
+
}
|
|
295
|
+
textPrefixNow(key, maxLength) {
|
|
296
|
+
if (this.object !== void 0) {
|
|
297
|
+
const field = Object.hasOwn(this.object, key) ? this.object[key] : void 0;
|
|
298
|
+
return typeof field === "string" ? field.slice(0, maxLength) : void 0;
|
|
299
|
+
}
|
|
300
|
+
const entry = this.#entries.get(key);
|
|
301
|
+
if (entry?.kind !== "string") return void 0;
|
|
302
|
+
const prefixes = entry.prefixes ??= /* @__PURE__ */ new Map();
|
|
303
|
+
let read = prefixes.get(maxLength);
|
|
304
|
+
if (read === void 0) {
|
|
305
|
+
read = {
|
|
306
|
+
at: entry.start,
|
|
307
|
+
length: 0,
|
|
308
|
+
text: ""
|
|
309
|
+
};
|
|
310
|
+
prefixes.set(maxLength, read);
|
|
311
|
+
}
|
|
312
|
+
this.readString(entry, read, maxLength, true);
|
|
313
|
+
return read.text;
|
|
314
|
+
}
|
|
315
|
+
valueNow(key) {
|
|
316
|
+
if (this.object !== void 0) {
|
|
317
|
+
if (!Object.hasOwn(this.object, key)) return void 0;
|
|
318
|
+
const field = this.object[key];
|
|
319
|
+
return typeof field === "string" ? void 0 : field;
|
|
320
|
+
}
|
|
321
|
+
const entry = this.#entries.get(key);
|
|
322
|
+
if (entry?.kind !== "value" || entry.end < 0 || entry.invalid) return void 0;
|
|
323
|
+
if (entry.parsed === void 0) try {
|
|
324
|
+
entry.parsed = JSON.parse(this.slice(entry.start, entry.end));
|
|
325
|
+
} catch (_error) {
|
|
326
|
+
entry.invalid = true;
|
|
327
|
+
this.#invalidValue = true;
|
|
328
|
+
}
|
|
329
|
+
return entry.parsed;
|
|
330
|
+
}
|
|
331
|
+
chunkAt(at) {
|
|
332
|
+
let low = 0;
|
|
333
|
+
let high = this.#ends.length;
|
|
334
|
+
while (low < high) {
|
|
335
|
+
const mid = low + high >>> 1;
|
|
336
|
+
if (this.#ends[mid] <= at) low = mid + 1;
|
|
337
|
+
else high = mid;
|
|
338
|
+
}
|
|
339
|
+
return low;
|
|
340
|
+
}
|
|
341
|
+
/** Materialize only a requested range, never the cumulative source. */
|
|
342
|
+
slice(start, end) {
|
|
343
|
+
if (start >= end) return "";
|
|
344
|
+
const first = this.chunkAt(start);
|
|
345
|
+
const last = this.chunkAt(end - 1);
|
|
346
|
+
const base = first === 0 ? 0 : this.#ends[first - 1];
|
|
347
|
+
if (first === last) return this.chunks[first].slice(start - base, end - base);
|
|
348
|
+
const parts = [this.chunks[first].slice(start - base)];
|
|
349
|
+
for (let i = first + 1; i < last; i++) parts.push(this.chunks[i]);
|
|
350
|
+
parts.push(this.chunks[last].slice(0, end - this.#ends[last - 1]));
|
|
351
|
+
return parts.join("");
|
|
352
|
+
}
|
|
353
|
+
readString(entry, read, limit, materialize) {
|
|
354
|
+
const end = Math.min(entry.end < 0 ? this.#consumed : entry.end, entry.invalidAt ?? Number.POSITIVE_INFINITY, this.#invalidAt ?? Number.POSITIVE_INFINITY);
|
|
355
|
+
if (!entry.needsDecoding) {
|
|
356
|
+
const length = Math.min(end - read.at, limit - read.length);
|
|
357
|
+
if (length <= 0) return;
|
|
358
|
+
if (materialize) read.text += this.slice(read.at, read.at + length);
|
|
359
|
+
read.at += length;
|
|
360
|
+
read.length += length;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
let chunkIndex = this.chunkAt(read.at);
|
|
364
|
+
while (read.at < end && read.length < limit) {
|
|
365
|
+
const base = chunkIndex === 0 ? 0 : this.#ends[chunkIndex - 1];
|
|
366
|
+
const chunk = this.chunks[chunkIndex];
|
|
367
|
+
const remaining = chunk.slice(read.at - base, Math.min(chunk.length, end - base));
|
|
368
|
+
const boundary = remaining.search(CONTENT_ESCAPE);
|
|
369
|
+
const length = Math.min(boundary < 0 ? remaining.length : boundary, limit - read.length);
|
|
370
|
+
if (length > 0) {
|
|
371
|
+
if (materialize) read.text += remaining.slice(0, length);
|
|
372
|
+
read.at += length;
|
|
373
|
+
read.length += length;
|
|
374
|
+
if (read.at === base + chunk.length) chunkIndex++;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const type = remaining.length > 1 ? remaining[1] : read.at + 1 < end ? this.chunks[chunkIndex + 1][0] : void 0;
|
|
378
|
+
let decoded;
|
|
379
|
+
let width = 2;
|
|
380
|
+
if (remaining[0] === "\\" && type === void 0 && entry.end < 0) return;
|
|
381
|
+
if (remaining[0] === "\\" && type === "u") {
|
|
382
|
+
const hex = this.slice(read.at + 2, Math.min(end, read.at + 6));
|
|
383
|
+
let valid = true;
|
|
384
|
+
for (let i = 0; i < hex.length; i++) if (!isHex(hex[i])) valid = false;
|
|
385
|
+
if (valid) {
|
|
386
|
+
if (hex.length < 4 && entry.end < 0) return;
|
|
387
|
+
if (hex.length === 4) decoded = String.fromCharCode(Number.parseInt(hex, 16));
|
|
388
|
+
}
|
|
389
|
+
width = 6;
|
|
390
|
+
} else if (remaining[0] === "\\" && type !== void 0) decoded = SIMPLE_ESCAPES[type];
|
|
391
|
+
if (decoded === void 0) {
|
|
392
|
+
entry.invalidAt = read.at;
|
|
393
|
+
this.#invalidValue = true;
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (materialize) read.text += decoded;
|
|
397
|
+
read.length++;
|
|
398
|
+
read.at += width;
|
|
399
|
+
while (chunkIndex < this.chunks.length && read.at >= this.#ends[chunkIndex]) chunkIndex++;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/** Locate new field ranges without decoding or parsing their contents. */
|
|
403
|
+
scan() {
|
|
404
|
+
if (this.object !== void 0 || this.#consumed === this.#size) return;
|
|
405
|
+
for (let i = this.chunkAt(this.#consumed); i < this.chunks.length && this.#invalidAt === void 0; i++) {
|
|
406
|
+
const pending = this.chunks[i];
|
|
407
|
+
const base = i === 0 ? 0 : this.#ends[i - 1];
|
|
408
|
+
for (let index = this.#consumed - base; index < pending.length && this.#mode !== "invalid"; index++) {
|
|
409
|
+
if (this.#mode === "string" || this.#mode === "nested" && this.#nestedInString) {
|
|
410
|
+
const end = this.stringBoundary(pending, index);
|
|
411
|
+
this.#consumed += end - index;
|
|
412
|
+
index = end;
|
|
413
|
+
if (index === pending.length) break;
|
|
414
|
+
}
|
|
415
|
+
this.step(pending[index], this.#consumed);
|
|
416
|
+
this.#consumed++;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/** Only raw quotes and their preceding backslash runs can terminate a string. */
|
|
421
|
+
stringBoundary(fragment, start) {
|
|
422
|
+
let at = start;
|
|
423
|
+
while (true) {
|
|
424
|
+
const quote = fragment.indexOf("\"", at);
|
|
425
|
+
const end = quote < 0 ? fragment.length : quote;
|
|
426
|
+
if (this.#mode === "string") {
|
|
427
|
+
const entry = this.#current;
|
|
428
|
+
if (!entry.needsDecoding && CONTENT_ESCAPE.test(fragment.slice(at, end))) entry.needsDecoding = true;
|
|
429
|
+
}
|
|
430
|
+
let slashStart = end;
|
|
431
|
+
while (slashStart > at && fragment[slashStart - 1] === "\\") slashStart--;
|
|
432
|
+
const escaped = (end - slashStart) % 2 === 1 !== (slashStart === at && this.#escape);
|
|
433
|
+
this.#escape = quote < 0 && escaped;
|
|
434
|
+
if (quote < 0 || !escaped) return end;
|
|
435
|
+
at = quote + 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
step(c, at) {
|
|
439
|
+
switch (this.#mode) {
|
|
440
|
+
case "root":
|
|
441
|
+
if (isWhitespace(c)) return;
|
|
442
|
+
if (c === "{") {
|
|
443
|
+
this.#mode = "key-or-end";
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.fail();
|
|
447
|
+
return;
|
|
448
|
+
case "key-or-end":
|
|
449
|
+
if (isWhitespace(c)) return;
|
|
450
|
+
if (c === "}") {
|
|
451
|
+
this.#mode = "closed";
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (c === "\"") {
|
|
455
|
+
this.beginKey(at);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
this.fail();
|
|
459
|
+
return;
|
|
460
|
+
case "key-only":
|
|
461
|
+
if (isWhitespace(c)) return;
|
|
462
|
+
if (c === "\"") {
|
|
463
|
+
this.beginKey(at);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
this.fail();
|
|
467
|
+
return;
|
|
468
|
+
case "key":
|
|
469
|
+
this.stepKey(c, at);
|
|
470
|
+
return;
|
|
471
|
+
case "colon":
|
|
472
|
+
if (isWhitespace(c)) return;
|
|
473
|
+
if (c === ":") {
|
|
474
|
+
this.#mode = "value";
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.fail();
|
|
478
|
+
return;
|
|
479
|
+
case "value":
|
|
480
|
+
this.beginValue(c, at);
|
|
481
|
+
return;
|
|
482
|
+
case "string": {
|
|
483
|
+
const entry = this.#current;
|
|
484
|
+
entry.end = at;
|
|
485
|
+
this.#current = null;
|
|
486
|
+
this.#mode = "comma-or-end";
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
case "scalar":
|
|
490
|
+
this.stepScalar(c, at);
|
|
491
|
+
return;
|
|
492
|
+
case "nested":
|
|
493
|
+
this.stepNested(c, at);
|
|
494
|
+
return;
|
|
495
|
+
case "comma-or-end":
|
|
496
|
+
if (isWhitespace(c)) return;
|
|
497
|
+
if (c === ",") {
|
|
498
|
+
this.#mode = "key-only";
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
if (c === "}") {
|
|
502
|
+
this.#mode = "closed";
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
this.fail();
|
|
506
|
+
return;
|
|
507
|
+
case "closed":
|
|
508
|
+
if (isWhitespace(c)) return;
|
|
509
|
+
this.fail();
|
|
510
|
+
return;
|
|
511
|
+
/* v8 ignore next 2 -- scan() stops stepping once the view is invalid. */
|
|
512
|
+
case "invalid": return;
|
|
513
|
+
/* v8 ignore next 2 -- Every scanner mode has a handler above. */
|
|
514
|
+
default: assertNever(this.#mode);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
fail() {
|
|
518
|
+
this.#invalidAt = this.#consumed;
|
|
519
|
+
this.#mode = "invalid";
|
|
520
|
+
this.#current = null;
|
|
521
|
+
}
|
|
522
|
+
beginKey(at) {
|
|
523
|
+
this.#mode = "key";
|
|
524
|
+
this.#keyStart = at + 1;
|
|
525
|
+
this.#keyEscaped = false;
|
|
526
|
+
this.#escape = false;
|
|
527
|
+
}
|
|
528
|
+
stepKey(c, at) {
|
|
529
|
+
if (c < " ") {
|
|
530
|
+
this.fail();
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (this.#escape) {
|
|
534
|
+
this.#escape = false;
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if (c === "\\") {
|
|
538
|
+
this.#escape = true;
|
|
539
|
+
this.#keyEscaped = true;
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (c !== "\"") return;
|
|
543
|
+
const raw = this.slice(this.#keyStart, at);
|
|
544
|
+
if (this.#keyEscaped) try {
|
|
545
|
+
this.#key = JSON.parse(`"${raw}"`);
|
|
546
|
+
} catch (_error) {
|
|
547
|
+
this.fail();
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
else this.#key = raw;
|
|
551
|
+
this.#mode = "colon";
|
|
552
|
+
}
|
|
553
|
+
open(entry) {
|
|
554
|
+
if (!this.#entries.has(this.#key)) this.#order.push(this.#key);
|
|
555
|
+
this.#entries.set(this.#key, entry);
|
|
556
|
+
this.#current = entry;
|
|
557
|
+
}
|
|
558
|
+
beginValue(c, at) {
|
|
559
|
+
if (isWhitespace(c)) return;
|
|
560
|
+
if (c === "\"") {
|
|
561
|
+
this.open({
|
|
562
|
+
kind: "string",
|
|
563
|
+
start: at + 1,
|
|
564
|
+
end: -1,
|
|
565
|
+
needsDecoding: false,
|
|
566
|
+
invalidAt: void 0,
|
|
567
|
+
length: void 0,
|
|
568
|
+
text: void 0,
|
|
569
|
+
prefixes: void 0
|
|
570
|
+
});
|
|
571
|
+
this.#escape = false;
|
|
572
|
+
this.#mode = "string";
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (c === "}" || c === "," || c === ":" || c === "]") {
|
|
576
|
+
this.fail();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
this.open({
|
|
580
|
+
kind: "value",
|
|
581
|
+
start: at,
|
|
582
|
+
end: -1,
|
|
583
|
+
parsed: void 0,
|
|
584
|
+
invalid: false
|
|
585
|
+
});
|
|
586
|
+
if (c === "{" || c === "[") {
|
|
587
|
+
this.#mode = "nested";
|
|
588
|
+
this.#nestedEnds = [c === "{" ? "}" : "]"];
|
|
589
|
+
this.#nestedInString = false;
|
|
590
|
+
this.#escape = false;
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this.#mode = "scalar";
|
|
594
|
+
}
|
|
595
|
+
stepScalar(c, at) {
|
|
596
|
+
if (c !== "," && c !== "}" && !isWhitespace(c)) return;
|
|
597
|
+
this.closeValue(at);
|
|
598
|
+
this.#mode = c === "," ? "key-only" : c === "}" ? "closed" : "comma-or-end";
|
|
599
|
+
}
|
|
600
|
+
stepNested(c, at) {
|
|
601
|
+
if (this.#nestedInString) {
|
|
602
|
+
this.#nestedInString = false;
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (c === "\"") {
|
|
606
|
+
this.#nestedInString = true;
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (c === "{" || c === "[") {
|
|
610
|
+
this.#nestedEnds.push(c === "{" ? "}" : "]");
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (c === "}" || c === "]") {
|
|
614
|
+
if (this.#nestedEnds.pop() !== c) {
|
|
615
|
+
this.fail();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
if (this.#nestedEnds.length === 0) {
|
|
619
|
+
this.closeValue(at + 1);
|
|
620
|
+
this.#mode = "comma-or-end";
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
closeValue(end) {
|
|
625
|
+
const entry = this.#current;
|
|
626
|
+
entry.end = end;
|
|
627
|
+
this.#current = null;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region lib/types/index.js
|
|
632
|
+
/** Duplicate-install-safe JSON and immutable-value helpers. @module @qilin-agent/util-values */
|
|
633
|
+
/**
|
|
634
|
+
* Mark an unreachable closed-union branch.
|
|
635
|
+
* @param value - impossible value; an unhandled typed variant fails at the call site.
|
|
636
|
+
* @param context - optional switch-site label included in the failure message.
|
|
637
|
+
* @returns never; a runtime value that escaped its type always throws.
|
|
638
|
+
*/
|
|
639
|
+
function assertNever(value, context) {
|
|
640
|
+
const rendered = JSON.stringify(value) ?? String(value);
|
|
641
|
+
throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
|
|
642
|
+
}
|
|
643
|
+
/** Whether a realm-owned intrinsic prototype has a native constructor matching this engine's representation. */
|
|
644
|
+
function hasIntrinsicConstructor(prototype, name) {
|
|
645
|
+
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
646
|
+
if (typeof constructor !== "function") return false;
|
|
647
|
+
try {
|
|
648
|
+
return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === Function.prototype.toString.call(name === "Array" ? Array : Object);
|
|
649
|
+
} catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
/** Whether a candidate is one realm's intrinsic `Object.prototype`. */
|
|
654
|
+
function isIntrinsicObjectPrototype(value) {
|
|
655
|
+
return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
|
|
656
|
+
}
|
|
657
|
+
/** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
|
|
658
|
+
function hasPlainArrayPrototype(value) {
|
|
659
|
+
const prototype = Object.getPrototypeOf(value);
|
|
660
|
+
if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
|
|
661
|
+
const objectPrototype = Object.getPrototypeOf(prototype);
|
|
662
|
+
return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
|
|
663
|
+
}
|
|
664
|
+
/** Whether an object is a plain or null-prototype record from any JavaScript realm. */
|
|
665
|
+
function hasPlainObjectPrototype(value) {
|
|
666
|
+
const prototype = Object.getPrototypeOf(value);
|
|
667
|
+
return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
|
|
668
|
+
}
|
|
669
|
+
/** Return every JSON-visible object key, or reject own data JSON would discard. */
|
|
670
|
+
function enumerableStringKeys(value) {
|
|
671
|
+
const keys = Reflect.ownKeys(value);
|
|
672
|
+
if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
|
|
673
|
+
return keys;
|
|
674
|
+
}
|
|
675
|
+
/** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
|
|
676
|
+
function walkJsonValue(value, detach) {
|
|
677
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
678
|
+
let root;
|
|
679
|
+
const assign = (destination, item) => {
|
|
680
|
+
if (destination === void 0) return;
|
|
681
|
+
if (destination.kind === "root") root = item;
|
|
682
|
+
else if (destination.kind === "array") destination.target[destination.index] = item;
|
|
683
|
+
else Object.defineProperty(destination.target, destination.key, {
|
|
684
|
+
value: item,
|
|
685
|
+
enumerable: true,
|
|
686
|
+
configurable: true,
|
|
687
|
+
writable: true
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
const tasks = [{
|
|
691
|
+
kind: "visit",
|
|
692
|
+
value,
|
|
693
|
+
...detach ? { destination: { kind: "root" } } : {}
|
|
694
|
+
}];
|
|
695
|
+
for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
|
|
696
|
+
if (task.kind === "leave") {
|
|
697
|
+
ancestors.delete(task.source);
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
if (task.kind === "array-item") {
|
|
701
|
+
if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
|
|
702
|
+
tasks.push({
|
|
703
|
+
kind: "visit",
|
|
704
|
+
value: task.source[task.index],
|
|
705
|
+
...task.target === void 0 ? {} : { destination: {
|
|
706
|
+
kind: "array",
|
|
707
|
+
target: task.target,
|
|
708
|
+
index: task.index
|
|
709
|
+
} }
|
|
710
|
+
});
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
if (task.kind === "object-property") {
|
|
714
|
+
tasks.push({
|
|
715
|
+
kind: "visit",
|
|
716
|
+
value: task.source[task.key],
|
|
717
|
+
...task.target === void 0 ? {} : { destination: {
|
|
718
|
+
kind: "object",
|
|
719
|
+
target: task.target,
|
|
720
|
+
key: task.key
|
|
721
|
+
} }
|
|
722
|
+
});
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
const current = task.value;
|
|
726
|
+
if (current === null) {
|
|
727
|
+
assign(task.destination, null);
|
|
728
|
+
continue;
|
|
729
|
+
}
|
|
730
|
+
if (typeof current === "boolean" || typeof current === "string") {
|
|
731
|
+
assign(task.destination, current);
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
if (typeof current === "number") {
|
|
735
|
+
if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
|
|
736
|
+
assign(task.destination, current);
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (typeof current !== "object") return void 0;
|
|
740
|
+
if (ancestors.has(current)) return void 0;
|
|
741
|
+
if (Array.isArray(current)) {
|
|
742
|
+
if (!hasPlainArrayPrototype(current)) return void 0;
|
|
743
|
+
const length = current.length;
|
|
744
|
+
if (Reflect.ownKeys(current).length !== length + 1) return void 0;
|
|
745
|
+
const target = detach ? [] : void 0;
|
|
746
|
+
if (target !== void 0) assign(task.destination, target);
|
|
747
|
+
ancestors.add(current);
|
|
748
|
+
tasks.push({
|
|
749
|
+
kind: "leave",
|
|
750
|
+
source: current
|
|
751
|
+
});
|
|
752
|
+
for (let index = length - 1; index >= 0; index--) tasks.push({
|
|
753
|
+
kind: "array-item",
|
|
754
|
+
source: current,
|
|
755
|
+
index,
|
|
756
|
+
...target === void 0 ? {} : { target }
|
|
757
|
+
});
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
760
|
+
if (!hasPlainObjectPrototype(current)) return void 0;
|
|
761
|
+
const keys = enumerableStringKeys(current);
|
|
762
|
+
if (keys === void 0) return void 0;
|
|
763
|
+
const target = detach ? {} : void 0;
|
|
764
|
+
if (target !== void 0) assign(task.destination, target);
|
|
765
|
+
ancestors.add(current);
|
|
766
|
+
tasks.push({
|
|
767
|
+
kind: "leave",
|
|
768
|
+
source: current
|
|
769
|
+
});
|
|
770
|
+
for (let index = keys.length - 1; index >= 0; index--) {
|
|
771
|
+
const key = keys[index];
|
|
772
|
+
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
773
|
+
if (key === void 0) return void 0;
|
|
774
|
+
tasks.push({
|
|
775
|
+
kind: "object-property",
|
|
776
|
+
source: current,
|
|
777
|
+
key,
|
|
778
|
+
...target === void 0 ? {} : { target }
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return detach ? root : true;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Validate and detach lossless JSON in one read per property.
|
|
786
|
+
* @param value - candidate value to validate and detach.
|
|
787
|
+
* @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
|
|
788
|
+
*/
|
|
789
|
+
function snapshotJsonValue(value) {
|
|
790
|
+
return walkJsonValue(value, true);
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Test the same lossless JSON rules as {@link snapshotJsonValue} without detaching the value.
|
|
794
|
+
* @param value - candidate value to test.
|
|
795
|
+
* @returns whether the value survives a JSON round trip without loss.
|
|
796
|
+
*/
|
|
797
|
+
function isJsonValue(value) {
|
|
798
|
+
return walkJsonValue(value, false) === true;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Compare JSON-compatible values structurally.
|
|
802
|
+
* @param a - one JSON-compatible value.
|
|
803
|
+
* @param b - the other JSON-compatible value.
|
|
804
|
+
* @returns whether both values contain the same JSON data.
|
|
805
|
+
*/
|
|
806
|
+
function deepEqualJson(a, b) {
|
|
807
|
+
if (a === b) return true;
|
|
808
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
809
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
810
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
|
|
811
|
+
return a.every((entry, index) => deepEqualJson(entry, b[index]));
|
|
812
|
+
}
|
|
813
|
+
const left = a;
|
|
814
|
+
const right = b;
|
|
815
|
+
const keys = Object.keys(left);
|
|
816
|
+
if (keys.length !== Object.keys(right).length) return false;
|
|
817
|
+
return keys.every((key) => key in right && deepEqualJson(left[key], right[key]));
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
|
|
821
|
+
* @param value - value to freeze.
|
|
822
|
+
* @returns the same value after every reachable enumerable child is frozen.
|
|
823
|
+
*/
|
|
824
|
+
function deepFreeze(value) {
|
|
825
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
826
|
+
const pending = [{
|
|
827
|
+
kind: "visit",
|
|
828
|
+
node: value
|
|
829
|
+
}];
|
|
830
|
+
while (pending.length > 0) {
|
|
831
|
+
const task = pending.pop();
|
|
832
|
+
/* v8 ignore next -- the loop condition guarantees one pending task. */
|
|
833
|
+
if (task === void 0) continue;
|
|
834
|
+
if (task.kind === "property") {
|
|
835
|
+
pending.push({
|
|
836
|
+
kind: "visit",
|
|
837
|
+
node: task.source[task.key]
|
|
838
|
+
});
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
const node = task.node;
|
|
842
|
+
if (node === null || typeof node !== "object") continue;
|
|
843
|
+
if (node instanceof AbortSignal) continue;
|
|
844
|
+
if (seen.has(node)) continue;
|
|
845
|
+
seen.add(node);
|
|
846
|
+
Object.freeze(node);
|
|
847
|
+
const keys = Object.keys(node);
|
|
848
|
+
for (let index = keys.length - 1; index >= 0; index--) {
|
|
849
|
+
const key = keys[index];
|
|
850
|
+
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
851
|
+
if (key === void 0) continue;
|
|
852
|
+
pending.push({
|
|
853
|
+
kind: "property",
|
|
854
|
+
source: node,
|
|
855
|
+
key
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return value;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Weak-key lookup with a strongly retained iterable set of associated values.
|
|
863
|
+
*
|
|
864
|
+
* Each value must belong to only one key. The container performs no automatic
|
|
865
|
+
* cleanup; owners delete associations or clear the container at lifecycle end.
|
|
866
|
+
*/
|
|
867
|
+
var WeakMapWithValues = class {
|
|
868
|
+
keys = /* @__PURE__ */ new WeakMap();
|
|
869
|
+
valueSet = /* @__PURE__ */ new Set();
|
|
870
|
+
/** Live strongly retained values in insertion order. */
|
|
871
|
+
values = this.valueSet;
|
|
872
|
+
/**
|
|
873
|
+
* Read the value associated with a key.
|
|
874
|
+
* @param key - weakly held lookup key.
|
|
875
|
+
* @returns the associated value, or absence.
|
|
876
|
+
*/
|
|
877
|
+
get(key) {
|
|
878
|
+
return this.keys.get(key);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Test whether a key has an association.
|
|
882
|
+
* @param key - weakly held lookup key.
|
|
883
|
+
* @returns whether the key is present.
|
|
884
|
+
*/
|
|
885
|
+
has(key) {
|
|
886
|
+
return this.keys.has(key);
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Associate one key with one caller-unique value.
|
|
890
|
+
* @param key - weakly held lookup key.
|
|
891
|
+
* @param value - strongly retained value that belongs to no other key.
|
|
892
|
+
* @returns this container.
|
|
893
|
+
*/
|
|
894
|
+
set(key, value) {
|
|
895
|
+
if (this.keys.has(key)) {
|
|
896
|
+
const previous = this.keys.get(key);
|
|
897
|
+
if (previous === value) return this;
|
|
898
|
+
this.valueSet.delete(previous);
|
|
899
|
+
}
|
|
900
|
+
this.keys.set(key, value);
|
|
901
|
+
this.valueSet.add(value);
|
|
902
|
+
return this;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Remove one association and its strongly retained value.
|
|
906
|
+
* @param key - weakly held lookup key.
|
|
907
|
+
* @returns whether an association was removed.
|
|
908
|
+
*/
|
|
909
|
+
delete(key) {
|
|
910
|
+
if (!this.keys.has(key)) return false;
|
|
911
|
+
const value = this.keys.get(key);
|
|
912
|
+
const deleted = this.keys.delete(key);
|
|
913
|
+
this.valueSet.delete(value);
|
|
914
|
+
return deleted;
|
|
915
|
+
}
|
|
916
|
+
/** Remove every association and strongly retained value. */
|
|
917
|
+
clear() {
|
|
918
|
+
this.keys = /* @__PURE__ */ new WeakMap();
|
|
919
|
+
this.valueSet.clear();
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
//#endregion
|
|
923
|
+
export { PartialArguments, WeakMapWithValues, assertNever, deepEqualJson, deepFreeze, isJsonValue, snapshotJsonValue };
|