doxum 0.1.21 → 0.1.23

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.
Files changed (72) hide show
  1. package/README.md +35 -7
  2. package/dist/{advanced-FgdTwu5b.d.ts → advanced-CLJCWkHa.d.cts} +3 -3
  3. package/dist/{advanced-COFJtWMT.js → advanced-CRNHfJBu.js} +482 -446
  4. package/dist/advanced-CRNHfJBu.js.map +1 -0
  5. package/dist/{advanced-BRL5pN0y.cjs → advanced-Cle5g3B4.cjs} +615 -459
  6. package/dist/advanced-Cle5g3B4.cjs.map +1 -0
  7. package/dist/{advanced-DfKc7TZR.d.cts → advanced-d6J61er9.d.ts} +3 -3
  8. package/dist/advanced.cjs +1 -1
  9. package/dist/advanced.d.cts +1 -1
  10. package/dist/advanced.d.ts +1 -1
  11. package/dist/advanced.js +1 -1
  12. package/dist/context-BcLKGfq8.cjs +149 -0
  13. package/dist/context-BcLKGfq8.cjs.map +1 -0
  14. package/dist/context-DFEaDUv5.js +84 -0
  15. package/dist/context-DFEaDUv5.js.map +1 -0
  16. package/dist/{contract-CdmDHRUq.d.cts → contract-SYJFP0lM.d.cts} +62 -88
  17. package/dist/{contract-KG5XnQZt.d.ts → contract-ULPQmiEs.d.ts} +62 -88
  18. package/dist/driver-BD3DQOW6.cjs +382 -0
  19. package/dist/driver-BD3DQOW6.cjs.map +1 -0
  20. package/dist/{driver-CLYJOGDQ.js → driver-yFfvDMX5.js} +155 -26
  21. package/dist/driver-yFfvDMX5.js.map +1 -0
  22. package/dist/index.cjs +2370 -406
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +6 -5
  25. package/dist/index.d.ts +6 -5
  26. package/dist/index.js +2293 -330
  27. package/dist/index.js.map +1 -1
  28. package/dist/local-sync.cjs +5 -5
  29. package/dist/local-sync.cjs.map +1 -1
  30. package/dist/local-sync.d.cts +1 -1
  31. package/dist/local-sync.d.ts +1 -1
  32. package/dist/local-sync.js +2 -2
  33. package/dist/local-sync.js.map +1 -1
  34. package/dist/react.cjs +2 -69
  35. package/dist/react.cjs.map +1 -1
  36. package/dist/react.d.cts +0 -1
  37. package/dist/react.d.ts +1 -2
  38. package/dist/react.js +3 -70
  39. package/dist/react.js.map +1 -1
  40. package/package.json +1 -6
  41. package/skills/doxum-runtime/SKILL.md +7 -1
  42. package/skills/doxum-runtime/references/guide.en.md +17 -6
  43. package/skills/doxum-runtime/references/guide.zh-CN.md +15 -5
  44. package/skills/doxum-runtime/references/invariants.en.md +5 -3
  45. package/skills/doxum-runtime/references/invariants.zh-CN.md +4 -3
  46. package/skills/doxum-runtime/references/projections.en.md +5 -0
  47. package/skills/doxum-runtime/references/projections.zh-CN.md +5 -0
  48. package/dist/access-BeSV5ve-.js +0 -816
  49. package/dist/access-BeSV5ve-.js.map +0 -1
  50. package/dist/access-Bienf28h.cjs +0 -911
  51. package/dist/access-Bienf28h.cjs.map +0 -1
  52. package/dist/advanced-BRL5pN0y.cjs.map +0 -1
  53. package/dist/advanced-COFJtWMT.js.map +0 -1
  54. package/dist/driver-CLYJOGDQ.js.map +0 -1
  55. package/dist/driver-Djr3BVvo.cjs +0 -241
  56. package/dist/driver-Djr3BVvo.cjs.map +0 -1
  57. package/dist/integration-C4Isp8lJ.js +0 -26
  58. package/dist/integration-C4Isp8lJ.js.map +0 -1
  59. package/dist/integration-Z6MsfFI7.cjs +0 -31
  60. package/dist/integration-Z6MsfFI7.cjs.map +0 -1
  61. package/dist/integration.cjs +0 -12
  62. package/dist/integration.d.cts +0 -17
  63. package/dist/integration.d.ts +0 -17
  64. package/dist/integration.js +0 -4
  65. package/dist/issue-DjK1xp5K.cjs +0 -881
  66. package/dist/issue-DjK1xp5K.cjs.map +0 -1
  67. package/dist/issue-W0hT8u8D.js +0 -642
  68. package/dist/issue-W0hT8u8D.js.map +0 -1
  69. package/dist/notification-Bkjau6B6.js +0 -232
  70. package/dist/notification-Bkjau6B6.js.map +0 -1
  71. package/dist/notification-DJfouMEb.cjs +0 -309
  72. package/dist/notification-DJfouMEb.cjs.map +0 -1
@@ -1,881 +0,0 @@
1
- const profile = {
2
- projection: (key, amount = 1) => {},
3
- recorder: (key, amount = 1) => {},
4
- access: (key) => {},
5
- copy: { structure: () => {} },
6
- equality: {
7
- call: () => {},
8
- container: () => {}
9
- },
10
- address: {
11
- listIndex: (items) => {},
12
- schemaStep: () => {},
13
- documentStep: () => {},
14
- arrayCopied: () => {},
15
- prefixComparison: () => {},
16
- segmentCompared: () => {}
17
- },
18
- impact: {
19
- index: () => {},
20
- affects: () => {}
21
- },
22
- collectionView: {
23
- mapped: () => {},
24
- idsScanned: (amount = 1) => {},
25
- arrayCopied: () => {}
26
- },
27
- materialized: {
28
- updated: () => {},
29
- rebuilt: () => {},
30
- notification: () => {}
31
- }
32
- };
33
- //#endregion
34
- //#region core/src/mutation/anchor.ts
35
- const equal = (left, right) => {
36
- profile.equality.call();
37
- if (left === right) return true;
38
- profile.equality.container();
39
- if (left.length !== right.length) return false;
40
- for (let i = 0; i < left.length; i++) if (left[i] !== keyAt(right, i)) return false;
41
- return true;
42
- };
43
- const length = (keys) => keys.length;
44
- const keyAt = (keys, index) => Array.isArray(keys) ? keys[index] : keys.at(index);
45
- const keyIndex = (keys, key) => Array.isArray(keys) ? keys.indexOf(key) : keys.index(key);
46
- const keys = (values, keyOf) => ({
47
- length: values.length,
48
- at: (index) => index >= 0 && index < values.length ? keyOf(values[index]) : void 0,
49
- index: (key) => {
50
- for (let index = 0; index < values.length; index += 1) if (keyOf(values[index]) === key) return index;
51
- return -1;
52
- }
53
- });
54
- const listIndexes = /* @__PURE__ */ new WeakMap();
55
- const knownKeys = (keys) => {
56
- let positions;
57
- return {
58
- length: keys.length,
59
- at: (index) => keys[index],
60
- index: (key) => {
61
- if (!positions) {
62
- positions = /* @__PURE__ */ new Map();
63
- for (let index = 0; index < keys.length; index++) positions.set(keys[index], index);
64
- profile.address.listIndex(keys.length);
65
- }
66
- return positions.get(key) ?? -1;
67
- }
68
- };
69
- };
70
- const cacheKnownKeys = (values, keyOf, keys) => {
71
- listIndexes.set(values, {
72
- keyOf,
73
- order: knownKeys(keys)
74
- });
75
- };
76
- /** Canonical lists keep their key positions until a structural write invalidates them. */
77
- const indexedKeys = (values, keyOf) => {
78
- const cached = listIndexes.get(values);
79
- if (cached?.keyOf === keyOf) return cached.order;
80
- let positions;
81
- const order = {
82
- length: values.length,
83
- at: (index) => index >= 0 && index < values.length ? keyOf(values[index]) : void 0,
84
- index: (key) => {
85
- if (!positions) {
86
- positions = /* @__PURE__ */ new Map();
87
- for (let i = 0; i < values.length; i++) positions.set(keyOf(values[i]), i);
88
- profile.address.listIndex(values.length);
89
- }
90
- return positions.get(key) ?? -1;
91
- }
92
- };
93
- listIndexes.set(values, {
94
- keyOf,
95
- order
96
- });
97
- return order;
98
- };
99
- const toArray = (keys) => {
100
- const result = new Array(length(keys));
101
- for (let index = 0; index < result.length; index++) result[index] = keyAt(keys, index);
102
- return result;
103
- };
104
- /** One operation-local list scan provides both stable keys and item association. */
105
- const listSequence = (values, keyOf) => {
106
- const current = indexedKeys(values, keyOf);
107
- const order = new Array(values.length);
108
- const byKey = /* @__PURE__ */ new Map();
109
- for (let index = 0; index < values.length; index++) {
110
- const key = current.at(index);
111
- order[index] = key;
112
- byKey.set(key, values[index]);
113
- }
114
- cacheKnownKeys(values, keyOf, order);
115
- return {
116
- order,
117
- values: byKey
118
- };
119
- };
120
- /** Plan one relative move against the order that remains after removing the selection. */
121
- const moveSelection = (current, selection, position) => {
122
- if (!selection.length) return {
123
- kind: "ok",
124
- order: current
125
- };
126
- const selected = /* @__PURE__ */ new Set();
127
- for (const key of selection) {
128
- if (selected.has(key)) return { kind: "duplicate" };
129
- selected.add(key);
130
- }
131
- const moved = [];
132
- const remaining = [];
133
- for (const key of current) (selected.has(key) ? moved : remaining).push(key);
134
- if (moved.length !== selected.size) return { kind: "missing" };
135
- if (!valid(remaining, position)) return { kind: "invalid-anchor" };
136
- const insertion = index(remaining, position);
137
- return {
138
- kind: "ok",
139
- order: [
140
- ...remaining.slice(0, insertion),
141
- ...moved,
142
- ...remaining.slice(insertion)
143
- ]
144
- };
145
- };
146
- /** Structural sequence writes own invalidation, including rollback writes. */
147
- const insert = (values, index, value) => {
148
- values.splice(index, 0, value);
149
- listIndexes.delete(values);
150
- };
151
- const remove = (values, index) => {
152
- values.splice(index, 1);
153
- listIndexes.delete(values);
154
- };
155
- /** Install an exact string-key sequence such as table ids in one structural write. */
156
- const installKeys = (values, order) => {
157
- values.length = order.length;
158
- for (let index = 0; index < order.length; index++) values[index] = order[index];
159
- };
160
- /** Install a pre-resolved list sequence without running keyOf again. */
161
- const installList = (values, keyOf, sequence, order) => {
162
- values.length = order.length;
163
- for (let index = 0; index < order.length; index++) values[index] = sequence.values.get(order[index]);
164
- cacheKnownKeys(values, keyOf, order);
165
- };
166
- const install = (values, keyOf, order) => {
167
- installList(values, keyOf, listSequence(values, keyOf), order);
168
- };
169
- const matches = (order, members) => {
170
- if (order.length !== members.length) return false;
171
- const ids = new Set(order);
172
- return ids.size === order.length && members.every((id) => ids.has(id));
173
- };
174
- const index = (keys, anchor) => {
175
- if (!anchor) return length(keys);
176
- if ("at" in anchor) return anchor.at === "start" ? 0 : length(keys);
177
- if ("before" in anchor) return keyIndex(keys, anchor.before);
178
- return keyIndex(keys, anchor.after) + 1;
179
- };
180
- const valid = (keys, anchor) => {
181
- if (!anchor) return true;
182
- if (typeof anchor !== "object" || anchor === null) return false;
183
- if (Number("at" in anchor) + Number("before" in anchor) + Number("after" in anchor) !== 1) return false;
184
- if ("at" in anchor) return anchor.at === "start" || anchor.at === "end";
185
- return keyIndex(keys, "before" in anchor ? anchor.before : anchor.after) >= 0;
186
- };
187
- //#endregion
188
- //#region core/src/value/ownership.ts
189
- const isPlainObject = (value) => {
190
- if (value === null || typeof value !== "object") return false;
191
- const prototype = Object.getPrototypeOf(value);
192
- return prototype === Object.prototype || prototype === null;
193
- };
194
- const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
195
- //#endregion
196
- //#region core/src/mutation/tree.ts
197
- const node = (tree, id) => Object.hasOwn(tree.nodes, id) ? tree.nodes[id] : void 0;
198
- const is = (value) => isRecord$1(value) && isRecord$1(value.nodes);
199
- const validNode = (value) => {
200
- if (!isRecord$1(value) || !Array.isArray(value.children)) return false;
201
- if (value.parentId !== void 0 && typeof value.parentId !== "string") return false;
202
- const children = /* @__PURE__ */ new Set();
203
- for (const id of value.children) {
204
- if (typeof id !== "string" || children.has(id)) return false;
205
- children.add(id);
206
- }
207
- return true;
208
- };
209
- const contains$1 = (tree, id) => Object.hasOwn(tree.nodes, id);
210
- const parent = (tree, id) => node(tree, id)?.parentId;
211
- const children = (tree, id) => node(tree, id)?.children;
212
- const validate = (value) => {
213
- if (!is(value)) return false;
214
- const ids = Object.keys(value.nodes);
215
- if (ids.length === 0) return value.rootId === void 0;
216
- if (typeof value.rootId !== "string" || !Object.hasOwn(value.nodes, value.rootId)) return false;
217
- for (const id of ids) {
218
- const entry = value.nodes[id];
219
- if (!validNode(entry)) return false;
220
- if (id === value.rootId) {
221
- if (entry.parentId !== void 0) return false;
222
- } else if (entry.parentId === void 0 || !Object.hasOwn(value.nodes, entry.parentId)) return false;
223
- for (const child of entry.children) {
224
- const childNode = value.nodes[child];
225
- if (!childNode || childNode.parentId !== id) return false;
226
- }
227
- }
228
- const seen = /* @__PURE__ */ new Set();
229
- const stack = [value.rootId];
230
- while (stack.length) {
231
- const id = stack.pop();
232
- if (seen.has(id)) return false;
233
- seen.add(id);
234
- const entry = value.nodes[id];
235
- if (!entry) return false;
236
- for (const child of entry.children) stack.push(child);
237
- }
238
- return seen.size === ids.length;
239
- };
240
- //#endregion
241
- //#region core/src/address.ts
242
- const registries = /* @__PURE__ */ new WeakMap();
243
- const registryNode = () => ({ static: /* @__PURE__ */ new Map() });
244
- const registryFor = (schema) => {
245
- const cached = registries.get(schema);
246
- if (cached) return cached;
247
- const registry = {
248
- root: registryNode(),
249
- nextPath: 0
250
- };
251
- registries.set(schema, registry);
252
- return registry;
253
- };
254
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
255
- const variantNode = (node, value) => {
256
- const tag = isRecord(value) && typeof value[node.tag] === "string" ? value[node.tag] : void 0;
257
- return node.variants[String(tag ?? Object.keys(node.variants)[0] ?? "")];
258
- };
259
- const step = (nodeInput, value, segment) => {
260
- let node = nodeInput;
261
- if (!node) return void 0;
262
- if (node.kind === "variant") node = variantNode(node, value);
263
- if (!node) return void 0;
264
- if (node.kind === "object") return Object.hasOwn(node.shape, segment) ? node.shape[segment] : void 0;
265
- if (node.kind === "table" || node.kind === "map") return node.value;
266
- if (node.kind === "list") return node.value;
267
- };
268
- const pathFor = (schema, address, document) => {
269
- const registry = registryFor(schema);
270
- let trie = registry.root;
271
- let node = schema;
272
- let value = document;
273
- for (const segment of address) {
274
- profile.address.schemaStep();
275
- profile.address.documentStep();
276
- const resolved = step(node, value, segment);
277
- if (!resolved) return void 0;
278
- trie = node && (node.kind === "table" || node.kind === "map" || node.kind === "list" || node.kind === "tree") ? trie.dynamic ??= registryNode() : (() => {
279
- const existing = trie.static.get(segment);
280
- if (existing) return existing;
281
- const created = registryNode();
282
- trie.static.set(segment, created);
283
- return created;
284
- })();
285
- value = readSegment(value, segment, node);
286
- node = resolved;
287
- }
288
- if (trie.path === void 0) trie.path = registry.nextPath++;
289
- return trie.path;
290
- };
291
- const resolveAddress = (schema, address, document) => {
292
- if (!Array.isArray(address)) return void 0;
293
- for (const segment of address) if (typeof segment !== "string") return void 0;
294
- profile.address.arrayCopied();
295
- const owned = Object.freeze(address.slice());
296
- const path = pathFor(schema, owned, document);
297
- return path === void 0 ? void 0 : {
298
- path,
299
- address: owned
300
- };
301
- };
302
- const nodeAt = (schema, address, document) => {
303
- let node = schema;
304
- let value = document;
305
- for (const segment of address) {
306
- const resolved = step(node, value, segment);
307
- value = readSegment(value, segment, node);
308
- node = resolved;
309
- if (!node) return void 0;
310
- }
311
- return node;
312
- };
313
- const readSegment = (value, segment, node) => {
314
- if (!isRecord(value) && !Array.isArray(value)) return void 0;
315
- if (node?.kind === "list" && Array.isArray(value)) return value[indexedKeys(value, node.keyOf).index(segment)];
316
- if (node?.kind === "table" && isRecord(value) && isRecord(value.byId)) return Object.hasOwn(value.byId, segment) ? value.byId[segment] : void 0;
317
- return Object.prototype.hasOwnProperty.call(value, segment) ? value[segment] : void 0;
318
- };
319
- const read = (root, address, schema) => {
320
- let value = root;
321
- let node = schema;
322
- for (const segment of address) {
323
- const next = step(node, value, segment);
324
- value = readSegment(value, segment, node);
325
- node = next;
326
- if (value === void 0) return void 0;
327
- }
328
- return value;
329
- };
330
- const compiledObjects = /* @__PURE__ */ new WeakMap();
331
- const compiledEntries = /* @__PURE__ */ new WeakMap();
332
- const compiledShape = (node, value) => {
333
- const branch = node.kind === "variant" ? variantNode(node, value) : node;
334
- if (branch?.kind !== "object") return void 0;
335
- const shape = branch.shape;
336
- let layout = compiledObjects.get(shape);
337
- if (!layout) {
338
- const compiled = /* @__PURE__ */ new Map();
339
- for (const key of Object.keys(shape).sort()) {
340
- profile.address.schemaStep();
341
- compiled.set(key, {
342
- kind: "fixed",
343
- key,
344
- node: shape[key],
345
- field: shape[key].kind === "field",
346
- slot: compiled.size
347
- });
348
- }
349
- layout = {
350
- kind: "fixed",
351
- members: compiled
352
- };
353
- compiledObjects.set(shape, layout);
354
- }
355
- return layout;
356
- };
357
- const resolveContainer = (owner, generation, at, node, value) => {
358
- if (!node || !isRecord(value) && !Array.isArray(value)) return void 0;
359
- const parent = node.kind === "table" && isRecord(value) ? value.byId : value;
360
- if (!isRecord(parent) && !Array.isArray(parent)) return void 0;
361
- if (node.kind === "tree") return void 0;
362
- let layout;
363
- if (node.kind === "map" || node.kind === "table" || node.kind === "list") {
364
- let dynamic = compiledEntries.get(node);
365
- if (!dynamic) {
366
- dynamic = {
367
- kind: "dynamic",
368
- entry: {
369
- kind: "entry",
370
- node: node.value,
371
- field: node.value.kind === "field"
372
- }
373
- };
374
- compiledEntries.set(node, dynamic);
375
- }
376
- layout = dynamic;
377
- } else {
378
- const fixed = compiledShape(node, value);
379
- if (!fixed) return void 0;
380
- layout = fixed;
381
- }
382
- return {
383
- owner,
384
- generation,
385
- at,
386
- node,
387
- parent,
388
- value,
389
- layout
390
- };
391
- };
392
- const resolveTreeContainer = (owner, generation, at, node, value) => node?.kind === "tree" && is(value) ? {
393
- owner,
394
- generation,
395
- at,
396
- node,
397
- value
398
- } : void 0;
399
- const memberKey = (container, key) => container.node.kind === "list" ? indexedKeys(container.parent, container.node.keyOf).index(key) : key;
400
- /** One recent path per transaction; structural writes invalidate all retained locations. */
401
- const createAddressResolver = (schema, root) => {
402
- const prefix = [];
403
- return {
404
- container: (owner, generation, at) => {
405
- if (!at.length) return resolveContainer(owner, generation, at, schema, root);
406
- const location = resolveWithPrefix(schema, root, at, prefix);
407
- if (!location || !Object.hasOwn(location.parent, location.key)) return void 0;
408
- return resolveContainer(owner, generation, at, location.node, location.parent[location.key]);
409
- },
410
- invalidate: () => {
411
- prefix.length = 0;
412
- }
413
- };
414
- };
415
- /** A subtree root is a value, not a fabricated member of an ObjectNode. */
416
- const resolveValue = (schema, root, address, prefix) => {
417
- if (!address.length) return {
418
- node: schema,
419
- value: root
420
- };
421
- const location = resolveWithPrefix(schema, root, address, prefix);
422
- return location && {
423
- node: location.node,
424
- value: Object.hasOwn(location.parent, location.key) ? location.parent[location.key] : void 0
425
- };
426
- };
427
- /** Resolves schema and document location in one address traversal. */
428
- const resolveLocated = (schema, root, address) => resolveWithPrefix(schema, root, address);
429
- const resolveWithPrefix = (schema, root, address, prefix) => {
430
- if (address.length === 0) return void 0;
431
- let node = schema;
432
- let current = root;
433
- let start = 0;
434
- if (prefix) {
435
- while (start < prefix.length && start < address.length - 1 && prefix[start].segment === address[start]) start++;
436
- prefix.length = start;
437
- if (start) {
438
- const retained = prefix[start - 1];
439
- node = retained.node;
440
- current = retained.value;
441
- }
442
- }
443
- let cacheable = true;
444
- for (let index = start; index < address.length - 1; index += 1) {
445
- profile.address.schemaStep();
446
- profile.address.documentStep();
447
- const resolved = step(node, current, address[index]);
448
- if (!resolved) return void 0;
449
- if (node?.kind !== "object" && node?.kind !== "table" && node?.kind !== "map") cacheable = false;
450
- current = readSegment(current, address[index], node);
451
- node = resolved;
452
- if (prefix && cacheable) prefix.push({
453
- segment: address[index],
454
- node: resolved,
455
- value: current
456
- });
457
- if (!node) return void 0;
458
- }
459
- const last = address[address.length - 1];
460
- return resolveChild(node, current, last);
461
- };
462
- /** Resolves one member from an already current schema/container pair. */
463
- const resolveChild = (node, current, last) => {
464
- profile.address.schemaStep();
465
- profile.address.documentStep();
466
- const resolved = step(node, current, last);
467
- if (!resolved || !isRecord(current) && !Array.isArray(current)) return void 0;
468
- if (node?.kind === "table" && isRecord(current) && isRecord(current.byId)) return {
469
- node: resolved,
470
- parent: current.byId,
471
- key: last
472
- };
473
- return {
474
- node: resolved,
475
- parent: current,
476
- key: node?.kind === "list" && Array.isArray(current) ? indexedKeys(current, node.keyOf).index(last) : last
477
- };
478
- };
479
- const contains = (parent, child) => {
480
- profile.address.prefixComparison();
481
- if (parent.length > child.length) return false;
482
- for (let index = 0; index < parent.length; index += 1) {
483
- profile.address.segmentCompared();
484
- if (parent[index] !== child[index]) return false;
485
- }
486
- return true;
487
- };
488
- const overlaps = (a, b) => contains(a, b) || contains(b, a);
489
- const debugKey = (address) => {
490
- let result = "";
491
- for (let index = 0; index < address.length; index += 1) {
492
- if (index > 0) result += "/";
493
- result += address[index].replaceAll("~", "~~").replaceAll("/", "~/");
494
- }
495
- return result;
496
- };
497
- /** An index over canonical address segments, shared by impact and subscriptions. */
498
- var AddressIndex = class {
499
- root = {
500
- children: /* @__PURE__ */ new Map(),
501
- values: /* @__PURE__ */ new Set()
502
- };
503
- add(address, value, member) {
504
- let node = this.root;
505
- for (let i = 0; i < address.length + (member === void 0 ? 0 : 1); i++) {
506
- const segment = i < address.length ? address[i] : member;
507
- let child = node.children.get(segment);
508
- if (!child) {
509
- child = {
510
- children: /* @__PURE__ */ new Map(),
511
- values: /* @__PURE__ */ new Set()
512
- };
513
- node.children.set(segment, child);
514
- }
515
- node = child;
516
- }
517
- node.values.add(value);
518
- }
519
- delete(address, value) {
520
- const parents = [];
521
- let node = this.root;
522
- for (const segment of address) {
523
- const child = node.children.get(segment);
524
- if (!child) return;
525
- parents.push(node);
526
- node = child;
527
- }
528
- node.values.delete(value);
529
- for (let i = address.length - 1; i >= 0 && !node.values.size && !node.children.size; i--) {
530
- node = parents[i];
531
- node.children.delete(address[i]);
532
- }
533
- }
534
- exact(address) {
535
- let node = this.root;
536
- for (const segment of address) {
537
- const child = node.children.get(segment);
538
- if (!child) return void 0;
539
- node = child;
540
- }
541
- return node.values;
542
- }
543
- hasAncestor(address, strict = false) {
544
- let node = this.root;
545
- for (let i = 0; i < address.length; i++) {
546
- if (node.values.size) return true;
547
- const child = node.children.get(address[i]);
548
- if (!child) return false;
549
- node = child;
550
- }
551
- return !strict && node.values.size > 0;
552
- }
553
- someAncestor(address, predicate) {
554
- let node = this.root;
555
- for (let i = 0;; i++) {
556
- for (const value of node.values) if (predicate(value)) return true;
557
- if (i === address.length) return false;
558
- const child = node.children.get(address[i]);
559
- if (!child) return false;
560
- node = child;
561
- }
562
- }
563
- overlaps(address) {
564
- let node = this.root;
565
- for (const segment of address) {
566
- if (node.values.size) return true;
567
- const child = node.children.get(segment);
568
- if (!child) return false;
569
- node = child;
570
- }
571
- return node.values.size > 0 || node.children.size > 0;
572
- }
573
- hasDescendant(address) {
574
- let node = this.root;
575
- for (const segment of address) {
576
- const child = node.children.get(segment);
577
- if (!child) return false;
578
- node = child;
579
- }
580
- return node.values.size > 0 || node.children.size > 0;
581
- }
582
- query(visit, relation = "overlap") {
583
- const visited = /* @__PURE__ */ new Set();
584
- const subtrees = /* @__PURE__ */ new Set();
585
- const values = (node) => {
586
- if (visited.has(node)) return;
587
- visited.add(node);
588
- node.values.forEach(visit);
589
- };
590
- const descend = (current) => {
591
- if (subtrees.has(current)) return;
592
- subtrees.add(current);
593
- values(current);
594
- current.children.forEach(descend);
595
- };
596
- const terminal = (node) => relation === "ancestors" ? values(node) : descend(node);
597
- return (address, members) => {
598
- let node = this.root;
599
- for (const segment of address) {
600
- if (subtrees.has(node)) return;
601
- if (relation !== "descendants") values(node);
602
- const child = node.children.get(segment);
603
- if (!child) return;
604
- node = child;
605
- }
606
- if (!members) terminal(node);
607
- else {
608
- if (relation !== "descendants") values(node);
609
- for (const member of members) {
610
- const child = node.children.get(member.key);
611
- if (child) terminal(child);
612
- }
613
- }
614
- };
615
- }
616
- clear() {
617
- this.root.values.clear();
618
- this.root.children.clear();
619
- }
620
- };
621
- //#endregion
622
- //#region core/src/mutation/issue.ts
623
- const at = (address, code, message) => Object.freeze({
624
- source: "mutation",
625
- code,
626
- address: Object.freeze([...address]),
627
- message
628
- });
629
- var MutationRejected = class extends Error {
630
- constructor(issue) {
631
- super(issue.message);
632
- this.issue = issue;
633
- }
634
- };
635
- const fail = (address, code, message) => {
636
- throw new MutationRejected(at(address, code, message));
637
- };
638
- const invalidValue = (issue, address = issue.address) => fail(address, issue.code === "missing-validator" ? "invalid-value" : issue.code, issue.message);
639
- //#endregion
640
- Object.defineProperty(exports, "AddressIndex", {
641
- enumerable: true,
642
- get: function() {
643
- return AddressIndex;
644
- }
645
- });
646
- Object.defineProperty(exports, "MutationRejected", {
647
- enumerable: true,
648
- get: function() {
649
- return MutationRejected;
650
- }
651
- });
652
- Object.defineProperty(exports, "children", {
653
- enumerable: true,
654
- get: function() {
655
- return children;
656
- }
657
- });
658
- Object.defineProperty(exports, "compiledShape", {
659
- enumerable: true,
660
- get: function() {
661
- return compiledShape;
662
- }
663
- });
664
- Object.defineProperty(exports, "contains", {
665
- enumerable: true,
666
- get: function() {
667
- return contains;
668
- }
669
- });
670
- Object.defineProperty(exports, "contains$1", {
671
- enumerable: true,
672
- get: function() {
673
- return contains$1;
674
- }
675
- });
676
- Object.defineProperty(exports, "createAddressResolver", {
677
- enumerable: true,
678
- get: function() {
679
- return createAddressResolver;
680
- }
681
- });
682
- Object.defineProperty(exports, "debugKey", {
683
- enumerable: true,
684
- get: function() {
685
- return debugKey;
686
- }
687
- });
688
- Object.defineProperty(exports, "equal", {
689
- enumerable: true,
690
- get: function() {
691
- return equal;
692
- }
693
- });
694
- Object.defineProperty(exports, "fail", {
695
- enumerable: true,
696
- get: function() {
697
- return fail;
698
- }
699
- });
700
- Object.defineProperty(exports, "index", {
701
- enumerable: true,
702
- get: function() {
703
- return index;
704
- }
705
- });
706
- Object.defineProperty(exports, "indexedKeys", {
707
- enumerable: true,
708
- get: function() {
709
- return indexedKeys;
710
- }
711
- });
712
- Object.defineProperty(exports, "insert", {
713
- enumerable: true,
714
- get: function() {
715
- return insert;
716
- }
717
- });
718
- Object.defineProperty(exports, "install", {
719
- enumerable: true,
720
- get: function() {
721
- return install;
722
- }
723
- });
724
- Object.defineProperty(exports, "installKeys", {
725
- enumerable: true,
726
- get: function() {
727
- return installKeys;
728
- }
729
- });
730
- Object.defineProperty(exports, "installList", {
731
- enumerable: true,
732
- get: function() {
733
- return installList;
734
- }
735
- });
736
- Object.defineProperty(exports, "invalidValue", {
737
- enumerable: true,
738
- get: function() {
739
- return invalidValue;
740
- }
741
- });
742
- Object.defineProperty(exports, "isPlainObject", {
743
- enumerable: true,
744
- get: function() {
745
- return isPlainObject;
746
- }
747
- });
748
- Object.defineProperty(exports, "isRecord", {
749
- enumerable: true,
750
- get: function() {
751
- return isRecord$1;
752
- }
753
- });
754
- Object.defineProperty(exports, "keys", {
755
- enumerable: true,
756
- get: function() {
757
- return keys;
758
- }
759
- });
760
- Object.defineProperty(exports, "listSequence", {
761
- enumerable: true,
762
- get: function() {
763
- return listSequence;
764
- }
765
- });
766
- Object.defineProperty(exports, "matches", {
767
- enumerable: true,
768
- get: function() {
769
- return matches;
770
- }
771
- });
772
- Object.defineProperty(exports, "memberKey", {
773
- enumerable: true,
774
- get: function() {
775
- return memberKey;
776
- }
777
- });
778
- Object.defineProperty(exports, "moveSelection", {
779
- enumerable: true,
780
- get: function() {
781
- return moveSelection;
782
- }
783
- });
784
- Object.defineProperty(exports, "nodeAt", {
785
- enumerable: true,
786
- get: function() {
787
- return nodeAt;
788
- }
789
- });
790
- Object.defineProperty(exports, "overlaps", {
791
- enumerable: true,
792
- get: function() {
793
- return overlaps;
794
- }
795
- });
796
- Object.defineProperty(exports, "parent", {
797
- enumerable: true,
798
- get: function() {
799
- return parent;
800
- }
801
- });
802
- Object.defineProperty(exports, "profile", {
803
- enumerable: true,
804
- get: function() {
805
- return profile;
806
- }
807
- });
808
- Object.defineProperty(exports, "read", {
809
- enumerable: true,
810
- get: function() {
811
- return read;
812
- }
813
- });
814
- Object.defineProperty(exports, "remove", {
815
- enumerable: true,
816
- get: function() {
817
- return remove;
818
- }
819
- });
820
- Object.defineProperty(exports, "resolveAddress", {
821
- enumerable: true,
822
- get: function() {
823
- return resolveAddress;
824
- }
825
- });
826
- Object.defineProperty(exports, "resolveChild", {
827
- enumerable: true,
828
- get: function() {
829
- return resolveChild;
830
- }
831
- });
832
- Object.defineProperty(exports, "resolveContainer", {
833
- enumerable: true,
834
- get: function() {
835
- return resolveContainer;
836
- }
837
- });
838
- Object.defineProperty(exports, "resolveLocated", {
839
- enumerable: true,
840
- get: function() {
841
- return resolveLocated;
842
- }
843
- });
844
- Object.defineProperty(exports, "resolveTreeContainer", {
845
- enumerable: true,
846
- get: function() {
847
- return resolveTreeContainer;
848
- }
849
- });
850
- Object.defineProperty(exports, "resolveValue", {
851
- enumerable: true,
852
- get: function() {
853
- return resolveValue;
854
- }
855
- });
856
- Object.defineProperty(exports, "toArray", {
857
- enumerable: true,
858
- get: function() {
859
- return toArray;
860
- }
861
- });
862
- Object.defineProperty(exports, "valid", {
863
- enumerable: true,
864
- get: function() {
865
- return valid;
866
- }
867
- });
868
- Object.defineProperty(exports, "validNode", {
869
- enumerable: true,
870
- get: function() {
871
- return validNode;
872
- }
873
- });
874
- Object.defineProperty(exports, "validate", {
875
- enumerable: true,
876
- get: function() {
877
- return validate;
878
- }
879
- });
880
-
881
- //# sourceMappingURL=issue-DjK1xp5K.cjs.map