doxum 0.1.1 → 0.1.3

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 (44) hide show
  1. package/README.md +77 -2
  2. package/dist/{contract-DwNiKioc.d.ts → contract-BsY1XLiG.d.ts} +64 -5
  3. package/dist/{contract-Otb5W6cQ.d.cts → contract-D8kjdfqT.d.cts} +64 -5
  4. package/dist/{dependency-BdEMyquf.js → dependency-C5_R1tvQ.js} +24 -263
  5. package/dist/dependency-C5_R1tvQ.js.map +1 -0
  6. package/dist/{dependency-DLcCvNKq.cjs → dependency-Dfzs3khk.cjs} +48 -341
  7. package/dist/dependency-Dfzs3khk.cjs.map +1 -0
  8. package/dist/driver-CNxqMVFH.cjs +69 -0
  9. package/dist/driver-CNxqMVFH.cjs.map +1 -0
  10. package/dist/driver-CbzfW5MR.js +46 -0
  11. package/dist/driver-CbzfW5MR.js.map +1 -0
  12. package/dist/index.cjs +428 -133
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +8 -5
  15. package/dist/index.d.ts +8 -5
  16. package/dist/index.js +352 -61
  17. package/dist/index.js.map +1 -1
  18. package/dist/integration.cjs +1 -1
  19. package/dist/integration.cjs.map +1 -1
  20. package/dist/integration.d.cts +2 -2
  21. package/dist/integration.d.ts +2 -2
  22. package/dist/integration.js +1 -1
  23. package/dist/integration.js.map +1 -1
  24. package/dist/local-sync.cjs +485 -0
  25. package/dist/local-sync.cjs.map +1 -0
  26. package/dist/local-sync.d.cts +74 -0
  27. package/dist/local-sync.d.ts +74 -0
  28. package/dist/local-sync.js +476 -0
  29. package/dist/local-sync.js.map +1 -0
  30. package/dist/ownership-B-VAPcce.js +242 -0
  31. package/dist/ownership-B-VAPcce.js.map +1 -0
  32. package/dist/ownership-CU-9DKJQ.cjs +301 -0
  33. package/dist/ownership-CU-9DKJQ.cjs.map +1 -0
  34. package/dist/react.cjs.map +1 -1
  35. package/dist/react.d.cts +2 -2
  36. package/dist/react.d.ts +2 -2
  37. package/dist/react.js.map +1 -1
  38. package/package.json +14 -8
  39. package/skills/doxum-runtime/references/guide.en.md +60 -5
  40. package/skills/doxum-runtime/references/guide.zh-CN.md +48 -2
  41. package/skills/doxum-runtime/references/invariants.en.md +23 -8
  42. package/skills/doxum-runtime/references/invariants.zh-CN.md +2 -2
  43. package/dist/dependency-BdEMyquf.js.map +0 -1
  44. package/dist/dependency-DLcCvNKq.cjs.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { t as __exportAll } from "./chunk-pbuEa-1d.js";
2
+ import { i as isRecord$1, t as cloneValue, u as profile } from "./ownership-B-VAPcce.js";
2
3
  //#region core/src/schema.ts
3
4
  const node = (value) => Object.freeze(value);
4
5
  const field = () => node({ kind: "field" });
@@ -58,186 +59,6 @@ const schema = (shape) => {
58
59
  return Object.freeze(result);
59
60
  };
60
61
  //#endregion
61
- //#region core/src/profile.ts
62
- const active = { current: void 0 };
63
- const profile = {
64
- clone: {
65
- call: () => {
66
- const value = active.current;
67
- if (value) value.clone.calls += 1;
68
- },
69
- node: (reason) => {
70
- const value = active.current;
71
- if (!value) return;
72
- value.clone.nodes[reason] += 1;
73
- },
74
- container: () => {
75
- const value = active.current;
76
- if (value) value.clone.containers += 1;
77
- },
78
- deepEqual: () => {
79
- const value = active.current;
80
- if (value) value.clone.deepEqual.calls += 1;
81
- },
82
- deepEqualContainer: () => {
83
- const value = active.current;
84
- if (value) value.clone.deepEqual.containers += 1;
85
- },
86
- initialDocument: () => {
87
- const value = active.current;
88
- if (value) value.clone.documents.initial += 1;
89
- }
90
- },
91
- mutation: {
92
- normalized: () => {
93
- const value = active.current;
94
- if (value) value.mutation.normalized += 1;
95
- },
96
- executed: () => {
97
- const value = active.current;
98
- if (value) value.mutation.executed += 1;
99
- },
100
- inverse: () => {
101
- const value = active.current;
102
- if (value) value.mutation.inverseCreated += 1;
103
- }
104
- },
105
- batch: {
106
- operation: () => {
107
- const value = active.current;
108
- if (value) value.batch.operations += 1;
109
- },
110
- entry: (amount = 1) => {
111
- const value = active.current;
112
- if (value) value.batch.entries += amount;
113
- },
114
- collectionResolved: () => {
115
- const value = active.current;
116
- if (value) value.batch.collectionsResolved += 1;
117
- },
118
- journalRecord: () => {
119
- const value = active.current;
120
- if (value) value.batch.journalRecords += 1;
121
- },
122
- rejected: () => {
123
- const value = active.current;
124
- if (value) value.batch.rejected += 1;
125
- },
126
- inverse: () => {
127
- const value = active.current;
128
- if (value) value.batch.inverseOperations += 1;
129
- },
130
- payloadTransferred: () => {
131
- const value = active.current;
132
- if (value) value.batch.payloadTransferred += 1;
133
- },
134
- payloadSnapshot: () => {
135
- const value = active.current;
136
- if (value) value.batch.payloadSnapshots += 1;
137
- }
138
- },
139
- journal: {
140
- subject: () => {
141
- const value = active.current;
142
- if (value) value.journal.subjects += 1;
143
- },
144
- comparison: () => {
145
- const value = active.current;
146
- if (value) value.journal.comparisons += 1;
147
- },
148
- absorbed: () => {
149
- const value = active.current;
150
- if (value) value.journal.absorbed += 1;
151
- },
152
- orderSnapshot: (items) => {
153
- const value = active.current;
154
- if (!value) return;
155
- value.journal.orderSnapshots += 1;
156
- value.journal.orderItems += items;
157
- }
158
- },
159
- address: {
160
- schemaStep: () => {
161
- const value = active.current;
162
- if (value) value.address.schemaSteps += 1;
163
- },
164
- documentStep: () => {
165
- const value = active.current;
166
- if (value) value.address.documentSteps += 1;
167
- },
168
- arrayCopied: () => {
169
- const value = active.current;
170
- if (value) value.address.arraysCopied += 1;
171
- },
172
- prefixComparison: () => {
173
- const value = active.current;
174
- if (value) value.address.prefixComparisons += 1;
175
- },
176
- segmentCompared: () => {
177
- const value = active.current;
178
- if (value) value.address.segmentsCompared += 1;
179
- }
180
- },
181
- impact: { affects: () => {
182
- const value = active.current;
183
- if (value) value.impact.affectsChecks += 1;
184
- } },
185
- reader: {
186
- session: () => {
187
- const value = active.current;
188
- if (value) value.reader.sessions += 1;
189
- },
190
- lookup: () => {
191
- const value = active.current;
192
- if (value) value.reader.nodeLookups += 1;
193
- },
194
- collectionIds: (amount = 1) => {
195
- const value = active.current;
196
- if (value) value.reader.collectionIds += amount;
197
- },
198
- structuralSnapshot: () => {
199
- const value = active.current;
200
- if (value) value.reader.structuralSnapshots += 1;
201
- }
202
- },
203
- collectionView: {
204
- mapped: () => {
205
- const value = active.current;
206
- if (value) value.collectionView.mappedItems += 1;
207
- },
208
- idsScanned: (amount = 1) => {
209
- const value = active.current;
210
- if (value) value.collectionView.idsScanned += amount;
211
- },
212
- arrayCopied: () => {
213
- const value = active.current;
214
- if (value) value.collectionView.arraysCopied += 1;
215
- }
216
- },
217
- materialized: {
218
- updated: () => {
219
- const value = active.current;
220
- if (value) value.materialized.updated += 1;
221
- },
222
- skipped: () => {
223
- const value = active.current;
224
- if (value) value.materialized.skipped += 1;
225
- },
226
- rebuilt: () => {
227
- const value = active.current;
228
- if (value) value.materialized.rebuilt += 1;
229
- },
230
- sourceChanged: () => {
231
- const value = active.current;
232
- if (value) value.materialized.sourceChanges += 1;
233
- },
234
- notification: () => {
235
- const value = active.current;
236
- if (value) value.materialized.notifications += 1;
237
- }
238
- }
239
- };
240
- //#endregion
241
62
  //#region core/src/address.ts
242
63
  const registries = /* @__PURE__ */ new WeakMap();
243
64
  const registryNode = () => ({ static: /* @__PURE__ */ new Map() });
@@ -257,14 +78,14 @@ const hashText = (value, seed) => {
257
78
  return hash >>> 0;
258
79
  };
259
80
  const appendAddressHash = (hash, segment) => hashText(segment, hashText("/", hash));
260
- const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
81
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
261
82
  const unwrap = (node) => {
262
83
  let current = node;
263
84
  while (current?.kind === "single") current = current.value;
264
85
  return current;
265
86
  };
266
87
  const variantNode = (node, value) => {
267
- const tag = isRecord$1(value) && typeof value[node.tag] === "string" ? value[node.tag] : void 0;
88
+ const tag = isRecord(value) && typeof value[node.tag] === "string" ? value[node.tag] : void 0;
268
89
  return node.variants[String(tag ?? Object.keys(node.variants)[0] ?? "")];
269
90
  };
270
91
  const schemaRoot$1 = (schema) => ({
@@ -344,8 +165,8 @@ const nodeAt = (schema, address, document) => {
344
165
  return unwrap(node);
345
166
  };
346
167
  const readSegment = (value, segment) => {
347
- if (!isRecord$1(value) && !Array.isArray(value)) return void 0;
348
- if (isRecord$1(value) && "byId" in value && isRecord$1(value.byId)) {
168
+ if (!isRecord(value) && !Array.isArray(value)) return void 0;
169
+ if (isRecord(value) && "byId" in value && isRecord(value.byId)) {
349
170
  const entity = value.byId[segment];
350
171
  if (entity !== void 0 || Object.prototype.hasOwnProperty.call(value.byId, segment)) return entity;
351
172
  }
@@ -386,7 +207,7 @@ const resolveLocated = (schema, root, address) => {
386
207
  profile.address.documentStep();
387
208
  const last = address[address.length - 1];
388
209
  const resolved = step(node, current, last);
389
- if (!resolved.node || !isRecord$1(current) && !Array.isArray(current)) return void 0;
210
+ if (!resolved.node || !isRecord(current) && !Array.isArray(current)) return void 0;
390
211
  if (node?.kind === "table" || node?.kind === "map") collection = {
391
212
  address: address.slice(0, -1),
392
213
  addressHash,
@@ -394,7 +215,7 @@ const resolveLocated = (schema, root, address) => {
394
215
  ...collection ? { parent: collection } : {}
395
216
  };
396
217
  addressHash = appendAddressHash(addressHash, last);
397
- if (isRecord$1(current) && "byId" in current && isRecord$1(current.byId) && last in current.byId) return {
218
+ if (isRecord(current) && "byId" in current && isRecord(current.byId) && last in current.byId) return {
398
219
  addressHash,
399
220
  node: resolved.node,
400
221
  parent: current.byId,
@@ -415,9 +236,9 @@ const locate = (root, address) => {
415
236
  if (address.length === 0) return void 0;
416
237
  let current = root;
417
238
  for (let index = 0; index < address.length - 1; index += 1) current = readSegment(current, address[index]);
418
- if (!isRecord$1(current) && !Array.isArray(current)) return void 0;
239
+ if (!isRecord(current) && !Array.isArray(current)) return void 0;
419
240
  const last = address[address.length - 1];
420
- if (isRecord$1(current) && "byId" in current && isRecord$1(current.byId) && last in current.byId) return {
241
+ if (isRecord(current) && "byId" in current && isRecord(current.byId) && last in current.byId) return {
421
242
  parent: current.byId,
422
243
  key: last,
423
244
  value: current.byId[last]
@@ -475,66 +296,6 @@ const same = (left, right) => {
475
296
  };
476
297
  const bucket = (target) => address(target)[0];
477
298
  //#endregion
478
- //#region core/src/value/ownership.ts
479
- const stablePayloads = /* @__PURE__ */ new WeakSet();
480
- const markStablePayload = (value) => {
481
- if (Array.isArray(value) || isPlainObject(value)) stablePayloads.add(value);
482
- return value;
483
- };
484
- const isStablePayload = (value) => (Array.isArray(value) || isPlainObject(value)) && stablePayloads.has(value);
485
- const isPlainObject = (value) => {
486
- if (value === null || typeof value !== "object") return false;
487
- const prototype = Object.getPrototypeOf(value);
488
- return prototype === Object.prototype || prototype === null;
489
- };
490
- const countCloneReason = (reason) => {
491
- if (reason) profile.clone.node(reason);
492
- };
493
- const cloneValue = (value, reason) => {
494
- profile.clone.call();
495
- countCloneReason(reason);
496
- if (Array.isArray(value)) {
497
- profile.clone.container();
498
- const result = new Array(value.length);
499
- for (let index = 0; index < value.length; index += 1) result[index] = cloneValue(value[index], reason);
500
- return reason === "commit" || reason === "inverse" ? markStablePayload(Object.freeze(result)) : result;
501
- }
502
- if (isPlainObject(value)) {
503
- profile.clone.container();
504
- const result = Object.create(Object.getPrototypeOf(value));
505
- for (const key in value) if (Object.prototype.hasOwnProperty.call(value, key)) result[key] = cloneValue(value[key], reason);
506
- return reason === "commit" || reason === "inverse" ? markStablePayload(Object.freeze(result)) : result;
507
- }
508
- return value;
509
- };
510
- const ownPayload = (value, reason = "canonical") => Array.isArray(value) || isPlainObject(value) ? cloneValue(value, reason) : value;
511
- const transferPayload = (value) => {
512
- profile.batch.payloadTransferred();
513
- return value;
514
- };
515
- const snapshotPayload = (value, reason = "commit") => (profile.batch.payloadSnapshot(), ownPayload(value, reason));
516
- const operationOwnsStructuralPayload = (operation) => operation.type === "variant.replace" || operation.type === "dict.replace" || operation.type === "entity.create" || operation.type === "list.insert" || operation.type === "list.replace" || operation.type === "tree.replace";
517
- const deepEqual = (left, right) => {
518
- profile.clone.deepEqual();
519
- if (Object.is(left, right)) return true;
520
- if (Array.isArray(left) && Array.isArray(right)) {
521
- profile.clone.deepEqualContainer();
522
- if (left.length !== right.length) return false;
523
- for (let index = 0; index < left.length; index += 1) if (!deepEqual(left[index], right[index])) return false;
524
- return true;
525
- }
526
- if (isPlainObject(left) && isPlainObject(right)) {
527
- profile.clone.deepEqualContainer();
528
- const leftKeys = Object.keys(left);
529
- if (leftKeys.length !== Object.keys(right).length) return false;
530
- for (const key of leftKeys) if (!Object.prototype.hasOwnProperty.call(right, key) || !deepEqual(left[key], right[key])) return false;
531
- return true;
532
- }
533
- return false;
534
- };
535
- const sameStructuralValue = (left, right) => Object.is(left, right) || (Array.isArray(left) || isPlainObject(left)) && deepEqual(left, right);
536
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
537
- //#endregion
538
299
  //#region core/src/access/reader.ts
539
300
  const schemaRoot = (schema) => object(schema.shape);
540
301
  const assertActive = (context) => {
@@ -592,30 +353,30 @@ const readerFor = (node, context, address = []) => {
592
353
  rootId: () => {
593
354
  collectValue(context, address);
594
355
  const value = readAt(context, address);
595
- return isRecord(value) && typeof value.rootId === "string" ? value.rootId : void 0;
356
+ return isRecord$1(value) && typeof value.rootId === "string" ? value.rootId : void 0;
596
357
  },
597
358
  has: (id) => {
598
359
  collectValue(context, address);
599
360
  const value = readAt(context, address);
600
- return isRecord(value) && isRecord(value.nodes) && Object.prototype.hasOwnProperty.call(value.nodes, id);
361
+ return isRecord$1(value) && isRecord$1(value.nodes) && Object.prototype.hasOwnProperty.call(value.nodes, id);
601
362
  },
602
363
  value: (id) => {
603
364
  collectValue(context, address);
604
365
  const value = readAt(context, address);
605
366
  profile.reader.structuralSnapshot();
606
- return cloneValue(isRecord(value) && isRecord(value.nodes) && isRecord(value.nodes[id]) ? value.nodes[id].value : void 0, "reader");
367
+ return cloneValue(isRecord$1(value) && isRecord$1(value.nodes) && isRecord$1(value.nodes[id]) ? value.nodes[id].value : void 0, "reader");
607
368
  },
608
369
  parent: (id) => {
609
370
  collectValue(context, address);
610
371
  const value = readAt(context, address);
611
- const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : void 0;
612
- return isRecord(entry) && typeof entry.parentId === "string" ? entry.parentId : void 0;
372
+ const entry = isRecord$1(value) && isRecord$1(value.nodes) ? value.nodes[id] : void 0;
373
+ return isRecord$1(entry) && typeof entry.parentId === "string" ? entry.parentId : void 0;
613
374
  },
614
375
  children: (id) => {
615
376
  collectValue(context, address);
616
377
  const value = readAt(context, address);
617
- const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : void 0;
618
- return isRecord(entry) && Array.isArray(entry.children) ? [...entry.children] : [];
378
+ const entry = isRecord$1(value) && isRecord$1(value.nodes) ? value.nodes[id] : void 0;
379
+ return isRecord$1(entry) && Array.isArray(entry.children) ? [...entry.children] : [];
619
380
  }
620
381
  };
621
382
  if (node.kind === "table" || node.kind === "map") {
@@ -624,21 +385,21 @@ const readerFor = (node, context, address = []) => {
624
385
  ids: () => {
625
386
  collectCollection(context, address);
626
387
  const value = readAt(context, address);
627
- const ids = node.kind === "table" && isRecord(value) && Array.isArray(value.ids) ? [...value.ids] : isRecord(value) ? Object.keys(value) : [];
388
+ const ids = node.kind === "table" && isRecord$1(value) && Array.isArray(value.ids) ? [...value.ids] : isRecord$1(value) ? Object.keys(value) : [];
628
389
  profile.reader.collectionIds(ids.length);
629
390
  return ids;
630
391
  },
631
392
  has: (id) => {
632
393
  collectCollection(context, address, id);
633
394
  const value = readAt(context, address);
634
- const byId = node.kind === "table" && isRecord(value) && isRecord(value.byId) ? value.byId : value;
635
- return isRecord(byId) && Object.prototype.hasOwnProperty.call(byId, id);
395
+ const byId = node.kind === "table" && isRecord$1(value) && isRecord$1(value.byId) ? value.byId : value;
396
+ return isRecord$1(byId) && Object.prototype.hasOwnProperty.call(byId, id);
636
397
  },
637
398
  get: (id) => {
638
399
  collectCollection(context, address, id);
639
400
  const value = readAt(context, address);
640
- const byId = node.kind === "table" && isRecord(value) && isRecord(value.byId) ? value.byId : value;
641
- if (!isRecord(byId) || !Object.prototype.hasOwnProperty.call(byId, id)) return void 0;
401
+ const byId = node.kind === "table" && isRecord$1(value) && isRecord$1(value.byId) ? value.byId : value;
402
+ if (!isRecord$1(byId) || !Object.prototype.hasOwnProperty.call(byId, id)) return void 0;
642
403
  const cached = items?.get(id);
643
404
  if (cached) return cached;
644
405
  const reader = readerFor(node.value, context, [...address, id]);
@@ -651,7 +412,7 @@ const readerFor = (node, context, address = []) => {
651
412
  if (node.kind === "variant") return new Proxy({}, { get: (_target, property) => {
652
413
  if (typeof property === "symbol") return void 0;
653
414
  const value = readAt(context, address);
654
- const tag = isRecord(value) && typeof value[node.tag] === "string" ? String(value[node.tag]) : void 0;
415
+ const tag = isRecord$1(value) && typeof value[node.tag] === "string" ? String(value[node.tag]) : void 0;
655
416
  const child = (tag ? node.variants[tag] : void 0)?.shape[property];
656
417
  return child ? readerFor(child, context, [...address, property]) : void 0;
657
418
  } });
@@ -730,6 +491,6 @@ const createDependencyTracker = () => {
730
491
  };
731
492
  };
732
493
  //#endregion
733
- export { resolveAddress as A, record as B, impact_target_exports as C, nodeAt as D, locate as E, field as F, variant as G, single as H, list as I, map as L, set as M, profile as N, overlaps as O, dict as P, object as R, id as S, debugKey as T, table as U, schema as V, tree as W, snapshotPayload as _, schemaOf as a, belongs as b, documentReader as c, deepEqual as d, isRecord as f, sameStructuralValue as g, ownPayload as h, readWith as i, resolveLocated as j, read as k, readerFor as l, operationOwnsStructuralPayload as m, bindRuntimeAccess as n, DocumentDisposedError as o, isStablePayload as p, documentOf as r, DocumentReentrancyError as s, createDependencyTracker as t, cloneValue as u, transferPayload as v, contains as w, bucket as x, address as y, optional as z };
494
+ export { optional as A, resolveLocated as C, list as D, field as E, tree as F, variant as I, schema as M, single as N, map as O, table as P, resolveAddress as S, dict as T, debugKey as _, readWith as a, overlaps as b, DocumentReentrancyError as c, address as d, belongs as f, contains as g, impact_target_exports as h, documentOf as i, record as j, object as k, documentReader as l, id as m, accessOf as n, schemaOf as o, bucket as p, bindRuntimeAccess as r, DocumentDisposedError as s, createDependencyTracker as t, readerFor as u, locate as v, set as w, read as x, nodeAt as y };
734
495
 
735
- //# sourceMappingURL=dependency-BdEMyquf.js.map
496
+ //# sourceMappingURL=dependency-C5_R1tvQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-C5_R1tvQ.js","names":["schemaRoot","readAddress","isRecord","impactTarget.same"],"sources":["../core/src/schema.ts","../core/src/address.ts","../core/src/impact-target.ts","../core/src/access/reader.ts","../core/src/runtime/contract.ts","../core/src/runtime/access.ts","../core/src/access/dependency.ts"],"sourcesContent":["export type DocumentAddress = readonly string[];\n\nexport type DocumentListConfig<TItem> = {\n readonly keyOf: (item: TItem) => string;\n};\nexport type DocumentTreeNode<TValue> = {\n readonly parentId?: string;\n readonly children: readonly string[];\n readonly value?: TValue;\n};\nexport type DocumentTreeValue<TValue> = {\n readonly rootId?: string;\n readonly nodes: Readonly<Record<string, DocumentTreeNode<TValue>>>;\n};\n\ntype BaseNode<K extends string> = { readonly kind: K };\nexport type FieldNode<T, Optional extends boolean = false> = BaseNode<'field'> & {\n readonly __value?: T;\n readonly optional?: Optional;\n};\nexport type OptionalNode<TNode extends DocumentNode> = TNode & {\n readonly optional: true;\n};\nexport interface ObjectShape {\n readonly [key: string]: DocumentNode;\n}\nexport type ObjectNode<TShape extends ObjectShape> = BaseNode<'object'> & {\n readonly shape: TShape;\n};\nexport interface VariantShape {\n readonly [key: string]: ObjectNode<ObjectShape>;\n}\nexport type VariantNode<\n TTag extends string,\n TVariants extends VariantShape,\n> = BaseNode<'variant'> & {\n readonly tag: TTag;\n readonly variants: TVariants;\n};\nexport type SingleNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'single'> & {\n readonly value: TValue;\n };\nexport type TableNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'table'> & {\n readonly value: TValue;\n };\nexport type MapNode<TValue extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n BaseNode<'map'> & {\n readonly value: TValue;\n };\nexport type RecordNode<TId extends string, TValue> = BaseNode<'record'> & {\n readonly __id?: TId;\n readonly __value?: TValue;\n};\nexport type DictNode<TKey extends string, TValue> = BaseNode<'dict'> & {\n readonly __key?: TKey;\n readonly __value?: TValue;\n};\nexport type ListNode<TItem> = BaseNode<'list'> & {\n readonly __item?: TItem;\n keyOf(item: TItem): string;\n};\nexport type TreeNode<TValue> = BaseNode<'tree'> & {\n readonly __value?: TValue;\n};\n\nexport type DocumentNode =\n | FieldNode<unknown, boolean>\n | ObjectNode<ObjectShape>\n | VariantNode<string, VariantShape>\n | SingleNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | TableNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | MapNode<ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>\n | RecordNode<string, unknown>\n | DictNode<string, unknown>\n | ListNode<unknown>\n | TreeNode<unknown>;\n\ntype EntityValue<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n N extends ObjectNode<infer S>\n ? DocumentValueOfShape<S>\n : N extends VariantNode<infer T, infer V>\n ? {\n [K in keyof V & string]: { [P in T]: K } & DocumentValueOfShape<\n V[K] extends ObjectNode<infer S> ? S : never\n >;\n }[keyof V & string]\n : never;\n\nexport type DocumentValueOfNode<N> =\n N extends FieldNode<infer T, infer O>\n ? O extends true\n ? T | undefined\n : T\n : N extends ObjectNode<infer S>\n ? DocumentValueOfShape<S>\n : N extends VariantNode<infer T, infer V>\n ? EntityValue<VariantNode<T, V>>\n : N extends SingleNode<infer V>\n ? EntityValue<V>\n : N extends TableNode<infer V>\n ? {\n readonly ids: readonly string[];\n readonly byId: Readonly<Record<string, EntityValue<V>>>;\n }\n : N extends MapNode<infer V>\n ? Readonly<Record<string, EntityValue<V>>>\n : N extends RecordNode<infer I, infer T>\n ? Readonly<Record<I, T>>\n : N extends DictNode<infer K, infer T>\n ? Readonly<Partial<Record<K, T>>>\n : N extends ListNode<infer I>\n ? readonly I[]\n : N extends TreeNode<infer T>\n ? DocumentTreeValue<T>\n : never;\n\ntype OptionalKeys<S extends ObjectShape> = {\n [K in keyof S]: S[K] extends { readonly optional: true } ? K : never;\n}[keyof S];\ntype RequiredKeys<S extends ObjectShape> = Exclude<keyof S, OptionalKeys<S>>;\nexport type DocumentValueOfShape<S extends ObjectShape> = {\n readonly [K in RequiredKeys<S>]: DocumentValueOfNode<S[K]>;\n} & { readonly [K in OptionalKeys<S>]?: DocumentValueOfNode<S[K]> };\nexport type ReadonlyDocument<S extends DocumentSchema> = DocumentValueOfShape<S['shape']>;\n\nexport type CollectionSelector<TId extends string = string, TEntry = unknown> = {\n readonly kind: 'collection';\n readonly schema: DocumentSchema;\n readonly address: DocumentAddress;\n readonly __id?: TId;\n readonly __entry?: TEntry;\n};\nexport type ValueSelector<TResult = unknown> = {\n readonly kind: 'value';\n readonly schema: DocumentSchema;\n readonly address: DocumentAddress;\n readonly __value?: TResult;\n};\nexport type ImpactTarget<T = unknown> =\n | { readonly kind: 'value'; readonly at: DocumentAddress }\n | ValueSelector<T>\n | {\n readonly kind: 'collection';\n readonly at: DocumentAddress;\n readonly id?: string;\n }\n | CollectionSelector<string, T>;\ntype PathMarker<TValue> = { readonly __value?: TValue };\n\ntype SchemaPathFor<S extends ObjectShape = ObjectShape, TValue = unknown> = {\n readonly [K in keyof S]: PathValue<S[K]>;\n} & {\n readonly item: (id: string) => SchemaPathFor<{}, unknown>;\n} & PathMarker<TValue>;\n\nexport type DocumentSchema<TShape extends ObjectShape = {}> = {\n readonly kind: 'schema';\n readonly shape: TShape;\n collection<TPath extends PathMarker<unknown>>(\n pick: (path: SchemaPath<TShape>) => TPath\n ): CollectionSelector<CollectionId<TPath>, CollectionEntry<TPath>>;\n value<TPath extends PathMarker<unknown>>(\n pick: (path: SchemaPath<TShape>) => TPath\n ): ValueSelector<PathValueResult<TPath>>;\n};\n\nexport type SchemaPath<S extends ObjectShape = {}> = SchemaPathFor<S, DocumentValueOfShape<S>>;\n\ntype VariantKeys<V extends VariantShape> = {\n [K in keyof V & string]: keyof (V[K] extends ObjectNode<infer S> ? S : {});\n}[keyof V & string] &\n string;\ntype VariantFieldPath<V extends VariantShape, K extends string> = {\n [P in keyof V & string]: V[P] extends ObjectNode<infer S>\n ? K extends keyof S\n ? PathValue<S[K]>\n : never\n : never;\n}[keyof V & string];\ntype VariantPath<V extends VariantShape> = {\n readonly [K in VariantKeys<V>]: VariantFieldPath<V, K>;\n} & {\n readonly item: (id: string) => SchemaPathFor<{}, unknown>;\n} & PathMarker<EntityValue<VariantNode<string, V>>>;\ntype PathNodeValue<N extends DocumentNode> = N extends { readonly optional: true }\n ? DocumentValueOfNode<N> | undefined\n : DocumentValueOfNode<N>;\ntype EntityPath<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> =\n N extends ObjectNode<infer S>\n ? SchemaPathFor<S, PathNodeValue<N>>\n : N extends VariantNode<string, infer V>\n ? VariantPath<V>\n : never;\ntype CollectionPath<N extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>> = Omit<\n EntityPath<N>,\n 'item'\n> & {\n readonly item: (id: string) => EntityPath<N>;\n readonly __collection?: {\n readonly id: string;\n readonly entry: DocumentValueOfNode<N>;\n };\n};\n\ntype PathValue<N extends DocumentNode> =\n N extends ObjectNode<infer S>\n ? SchemaPathFor<S, PathNodeValue<N>>\n : N extends VariantNode<infer _TTag, infer V>\n ? VariantPath<V>\n : N extends TableNode<infer V> | MapNode<infer V>\n ? CollectionPath<V>\n : N extends SingleNode<infer V>\n ? EntityPath<V>\n : SchemaPathFor<{}, PathNodeValue<N>>;\ntype CollectionInfo<T> = T extends {\n readonly __collection?: {\n readonly id: infer TId;\n readonly entry: infer TEntry;\n };\n}\n ? { readonly id: TId; readonly entry: TEntry }\n : never;\ntype CollectionId<T> =\n CollectionInfo<T> extends { readonly id: infer TId extends string } ? TId : string;\ntype CollectionEntry<T> =\n CollectionInfo<T> extends { readonly entry: infer TEntry } ? TEntry : never;\ntype PathValueResult<T> = T extends PathMarker<infer TValue> ? TValue : unknown;\n\nconst node = <T extends DocumentNode>(value: T): T => Object.freeze(value);\nexport const field = <T>(): FieldNode<T> => node({ kind: 'field' });\nexport const optional = <T extends DocumentNode>(value: T): OptionalNode<T> =>\n node({ ...value, optional: true } as OptionalNode<T>);\nexport const object = <S extends ObjectShape>(shape: S): ObjectNode<S> =>\n node({ kind: 'object', shape });\nexport const variant = <T extends string, V extends VariantShape>(\n tag: T,\n variants: V\n): VariantNode<T, V> => node({ kind: 'variant', tag, variants });\nexport const single = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): SingleNode<V> => node({ kind: 'single', value });\nexport const table = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): TableNode<V> => node({ kind: 'table', value });\nexport const map = <V extends ObjectNode<ObjectShape> | VariantNode<string, VariantShape>>(\n value: V\n): MapNode<V> => node({ kind: 'map', value });\nexport const record = <TId extends string = string, TValue = unknown>(): RecordNode<TId, TValue> =>\n node({ kind: 'record' });\nexport const dict = <TKey extends string = string, TValue = unknown>(): DictNode<TKey, TValue> =>\n node({ kind: 'dict' });\nexport const list = <TItem>(config: DocumentListConfig<TItem>): ListNode<TItem> =>\n ({ kind: 'list', keyOf: config.keyOf }) as ListNode<TItem>;\nexport const tree = <TValue = unknown>(): TreeNode<TValue> => node({ kind: 'tree' });\n\nconst pathProxy = (address: DocumentAddress): SchemaPath & { readonly address: DocumentAddress } =>\n new Proxy({ address } as SchemaPath & { readonly address: DocumentAddress }, {\n get: (_target, property: string | symbol) => {\n if (property === 'address') return address;\n if (property === 'item') return (id: string) => pathProxy([...address, id]);\n if (typeof property === 'symbol') return undefined;\n return pathProxy([...address, property]);\n },\n });\n\nconst select = <S extends ObjectShape>(\n owner: DocumentSchema<S>,\n kind: 'collection' | 'value',\n pick: (path: SchemaPath<S>) => unknown\n): CollectionSelector | ValueSelector => {\n const value = pick(pathProxy([]) as unknown as SchemaPath<S>);\n const selected = value as { readonly address?: DocumentAddress };\n return Object.freeze({\n kind,\n schema: owner,\n address: Object.freeze([...(selected.address ?? [])]),\n }) as CollectionSelector | ValueSelector;\n};\n\nexport const schema = <S extends ObjectShape>(shape: S): DocumentSchema<S> => {\n const result: DocumentSchema<S> = {\n kind: 'schema',\n shape,\n collection: <TPath extends PathMarker<unknown>>(pick: (path: SchemaPath<S>) => TPath) =>\n select(result, 'collection', pick) as CollectionSelector<\n CollectionId<TPath>,\n CollectionEntry<TPath>\n >,\n value: <TPath extends PathMarker<unknown>>(pick: (path: SchemaPath<S>) => TPath) =>\n select(result, 'value', pick) as ValueSelector<PathValueResult<TPath>>,\n };\n return Object.freeze(result);\n};\n","import type { DocumentAddress, DocumentNode, DocumentSchema, ObjectShape } from './schema';\nimport { profile } from './profile';\n\n/** The only resolved address representation used inside the runtime. */\nexport type AddressRef = {\n readonly path: number;\n readonly address: DocumentAddress;\n};\n\ntype RegistryNode = {\n readonly static: Map<string, RegistryNode>;\n dynamic?: RegistryNode;\n path?: number;\n};\n\ntype Registry = {\n readonly root: RegistryNode;\n nextPath: number;\n};\n\nconst registries = new WeakMap<object, Registry>();\nconst registryNode = (): RegistryNode => ({ static: new Map() });\nconst registryFor = (schema: DocumentSchema): Registry => {\n const cached = registries.get(schema as object);\n if (cached) return cached;\n const registry: Registry = { root: registryNode(), nextPath: 0 };\n registries.set(schema as object, registry);\n return registry;\n};\n\nconst hashText = (value: string, seed: number): number => {\n let hash = seed;\n for (let index = 0; index < value.length; index += 1)\n hash = Math.imul(hash ^ value.charCodeAt(index), 16_777_619);\n return hash >>> 0;\n};\n\nconst appendAddressHash = (hash: number, segment: string): number =>\n hashText(segment, hashText('/', hash));\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst unwrap = (node: DocumentNode | undefined): DocumentNode | undefined => {\n let current = node;\n while (current?.kind === 'single') current = current.value;\n return current;\n};\n\nconst variantNode = (\n node: Extract<DocumentNode, { kind: 'variant' }>,\n value: unknown\n): DocumentNode | undefined => {\n const tag = isRecord(value) && typeof value[node.tag] === 'string' ? value[node.tag] : undefined;\n return node.variants[String(tag ?? Object.keys(node.variants)[0] ?? '')];\n};\n\nconst schemaRoot = (schema: DocumentSchema): DocumentNode => ({\n kind: 'object',\n shape: schema.shape,\n});\n\ntype Step = {\n readonly node: DocumentNode | undefined;\n readonly dynamic: boolean;\n};\n\nconst step = (nodeInput: DocumentNode | undefined, value: unknown, segment: string): Step => {\n let node = unwrap(nodeInput);\n if (!node) return { node: undefined, dynamic: false };\n if (node.kind === 'variant') {\n node = unwrap(variantNode(node, value));\n }\n if (!node) return { node: undefined, dynamic: false };\n if (node.kind === 'object') return { node: node.shape[segment], dynamic: false };\n if (node.kind === 'table' || node.kind === 'map') return { node: node.value, dynamic: true };\n // These nodes use operation-specific keys rather than address segments, but\n // accepting a dynamic step keeps address resolution total for user targets.\n if (\n node.kind === 'record' ||\n node.kind === 'dict' ||\n node.kind === 'list' ||\n node.kind === 'tree'\n )\n return { node, dynamic: true };\n return { node: undefined, dynamic: false };\n};\n\nconst pathFor = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): number | undefined => {\n const registry = registryFor(schema);\n let trie = registry.root;\n let node: DocumentNode | undefined = schemaRoot(schema);\n let value: unknown = document;\n for (const segment of address) {\n profile.address.schemaStep();\n profile.address.documentStep();\n const resolved = step(node, value, segment);\n if (!resolved.node) return undefined;\n const next = resolved.dynamic\n ? (trie.dynamic ??= registryNode())\n : (() => {\n const existing = trie.static.get(segment);\n if (existing) return existing;\n const created = registryNode();\n trie.static.set(segment, created);\n return created;\n })();\n trie = next;\n node = resolved.node;\n value = readSegment(value, segment);\n }\n if (trie.path === undefined) trie.path = registry.nextPath++;\n return trie.path;\n};\n\nexport const resolveAddress = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): AddressRef | undefined => {\n if (!Array.isArray(address)) return undefined;\n for (const segment of address) if (typeof segment !== 'string') return undefined;\n profile.address.arrayCopied();\n const owned = Object.freeze(address.slice()) as DocumentAddress;\n const path = pathFor(schema, owned, document);\n return path === undefined ? undefined : { path, address: owned };\n};\n\nexport const nodeAt = (\n schema: DocumentSchema,\n address: DocumentAddress,\n document?: unknown\n): DocumentNode | undefined => {\n let node: DocumentNode | undefined = schemaRoot(schema);\n let value = document;\n for (const segment of address) {\n const resolved = step(node, value, segment);\n node = resolved.node;\n value = readSegment(value, segment);\n if (!node) return undefined;\n }\n return unwrap(node);\n};\n\nexport const readSegment = (value: unknown, segment: string): unknown => {\n if (!isRecord(value) && !Array.isArray(value)) return undefined;\n if (isRecord(value) && 'byId' in value && isRecord(value.byId)) {\n const entity = value.byId[segment];\n if (entity !== undefined || Object.prototype.hasOwnProperty.call(value.byId, segment))\n return entity;\n }\n return (value as Record<string, unknown>)[segment];\n};\n\nexport const read = (root: unknown, address: DocumentAddress): unknown => {\n let value = root;\n for (const segment of address) {\n value = readSegment(value, segment);\n if (value === undefined) return undefined;\n }\n return value;\n};\n\nexport type Located = {\n readonly parent: Record<string, unknown> | unknown[];\n readonly key: string | number;\n readonly value: unknown;\n};\n\ntype ResolvedCollection = {\n readonly address: DocumentAddress;\n readonly addressHash: number;\n readonly id: string;\n readonly parent?: ResolvedCollection;\n};\n\nexport type ResolvedAddress = Located & {\n readonly addressHash: number;\n readonly node: DocumentNode;\n readonly collection?: ResolvedCollection;\n};\n\n/** Resolves schema and document location in one address traversal. */\nexport const resolveLocated = (\n schema: DocumentSchema,\n root: unknown,\n address: DocumentAddress\n): ResolvedAddress | undefined => {\n if (address.length === 0) return undefined;\n let node: DocumentNode | undefined = schemaRoot(schema);\n let current: unknown = root;\n let collection: ResolvedCollection | undefined;\n let addressHash = 2_166_136_261;\n for (let index = 0; index < address.length - 1; index += 1) {\n profile.address.schemaStep();\n profile.address.documentStep();\n const resolved = step(node, current, address[index]);\n if (!resolved.node) return undefined;\n if (node?.kind === 'table' || node?.kind === 'map')\n collection = {\n address: address.slice(0, index),\n addressHash,\n id: address[index],\n ...(collection ? { parent: collection } : {}),\n };\n addressHash = appendAddressHash(addressHash, address[index]);\n node = resolved.node;\n current = readSegment(current, address[index]);\n if (!node) return undefined;\n }\n profile.address.schemaStep();\n profile.address.documentStep();\n const last = address[address.length - 1];\n const resolved = step(node, current, last);\n if (!resolved.node || (!isRecord(current) && !Array.isArray(current))) return undefined;\n if (node?.kind === 'table' || node?.kind === 'map')\n collection = {\n address: address.slice(0, -1),\n addressHash,\n id: last,\n ...(collection ? { parent: collection } : {}),\n };\n addressHash = appendAddressHash(addressHash, last);\n if (isRecord(current) && 'byId' in current && isRecord(current.byId) && last in current.byId)\n return {\n addressHash,\n node: resolved.node,\n parent: current.byId,\n key: last,\n value: current.byId[last],\n ...(collection ? { collection } : {}),\n };\n return {\n addressHash,\n node: resolved.node,\n parent: current,\n key: Array.isArray(current) && /^\\d+$/.test(last) ? Number(last) : last,\n value: readSegment(current, last),\n ...(collection ? { collection } : {}),\n };\n};\n\nexport const locate = (root: unknown, address: DocumentAddress): Located | undefined => {\n if (address.length === 0) return undefined;\n let current: unknown = root;\n for (let index = 0; index < address.length - 1; index += 1)\n current = readSegment(current, address[index]);\n if (!isRecord(current) && !Array.isArray(current)) return undefined;\n const last = address[address.length - 1];\n if (isRecord(current) && 'byId' in current && isRecord(current.byId) && last in current.byId)\n return { parent: current.byId, key: last, value: current.byId[last] };\n return {\n parent: current,\n key: Array.isArray(current) && /^\\d+$/.test(last) ? Number(last) : last,\n value: readSegment(current, last),\n };\n};\n\nexport const set = (root: unknown, address: DocumentAddress, value: unknown): boolean => {\n const target = locate(root, address);\n if (!target) return false;\n (target.parent as Record<string | number, unknown>)[target.key] = value;\n return true;\n};\n\nexport const remove = (root: unknown, address: DocumentAddress): boolean => {\n const target = locate(root, address);\n if (!target || !Object.prototype.hasOwnProperty.call(target.parent, target.key)) return false;\n if (Array.isArray(target.parent)) target.parent.splice(Number(target.key), 1);\n else delete target.parent[String(target.key)];\n return true;\n};\n\nexport const contains = (parent: DocumentAddress, child: DocumentAddress): boolean => {\n profile.address.prefixComparison();\n if (parent.length > child.length) return false;\n for (let index = 0; index < parent.length; index += 1) {\n profile.address.segmentCompared();\n if (parent[index] !== child[index]) return false;\n }\n return true;\n};\n\nexport const overlaps = (a: DocumentAddress, b: DocumentAddress): boolean =>\n contains(a, b) || contains(b, a);\n\nexport const debugKey = (address: DocumentAddress): string => {\n let result = '';\n for (let index = 0; index < address.length; index += 1) {\n if (index > 0) result += '/';\n result += address[index].replaceAll('~', '~~').replaceAll('/', '~/');\n }\n return result;\n};\n\nexport const same = (a: AddressRef, b: AddressRef): boolean => {\n if (a.path !== b.path || a.address.length !== b.address.length) return false;\n for (let index = 0; index < a.address.length; index += 1) {\n profile.address.segmentCompared();\n if (a.address[index] !== b.address[index]) return false;\n }\n return true;\n};\n\nexport type { DocumentAddress } from './schema';\n","import type { DocumentAddress, DocumentSchema, ImpactTarget } from './schema';\n\nexport const address = (target: ImpactTarget<unknown>): DocumentAddress =>\n 'at' in target ? target.at : target.address;\n\nexport const id = (target: ImpactTarget<unknown>): string | undefined =>\n target.kind === 'collection' && 'id' in target ? target.id : undefined;\n\nexport const belongs = (target: ImpactTarget<unknown>, schema: DocumentSchema): boolean =>\n !('schema' in target) || target.schema === schema;\n\nexport const same = (left: ImpactTarget<unknown>, right: ImpactTarget<unknown>): boolean => {\n if (left.kind !== right.kind) return false;\n if ('schema' in left && 'schema' in right && left.schema !== right.schema) return false;\n const leftAddress = address(left);\n const rightAddress = address(right);\n if (leftAddress.length !== rightAddress.length) return false;\n for (let index = 0; index < leftAddress.length; index += 1)\n if (leftAddress[index] !== rightAddress[index]) return false;\n return left.kind !== 'collection' || id(left) === id(right);\n};\n\nexport const bucket = (target: ImpactTarget<unknown>): string | undefined => address(target)[0];\n","import { object } from '../schema';\nimport type {\n DictNode,\n DocumentAddress,\n DocumentNode,\n DocumentSchema,\n DocumentValueOfNode,\n ImpactTarget,\n ListNode,\n MapNode,\n ObjectNode,\n ReadonlyDocument,\n SingleNode,\n TableNode,\n TreeNode,\n VariantNode,\n} from '../schema';\nimport { read as readAddress } from '../address';\nimport { cloneValue, isRecord } from '../value/ownership';\nimport { profile } from '../profile';\nimport type { DependencyTracker } from './dependency';\n\nexport type FieldReader<T> = { readonly get: () => T };\nexport type CollectionReader<TId, TEntry> = {\n readonly ids: () => readonly TId[];\n readonly has: (id: TId) => boolean;\n readonly get: (id: TId) => EntityReader<TEntry> | undefined;\n};\nexport type ListReader<T> = {\n readonly values: () => readonly T[];\n readonly length: () => number;\n readonly at: (index: number) => T | undefined;\n};\nexport type TreeReader<T> = {\n readonly rootId: () => string | undefined;\n readonly has: (id: string) => boolean;\n readonly value: (id: string) => T | undefined;\n readonly parent: (id: string) => string | undefined;\n readonly children: (id: string) => readonly string[];\n};\n\nexport type EntityReader<T> = T extends object\n ? { readonly [K in keyof T]: ReaderValue<T[K]> }\n : FieldReader<T>;\nexport type ReaderValue<T> = T extends readonly (infer TItem)[]\n ? ListReader<TItem>\n : T extends object\n ? EntityReader<T>\n : FieldReader<T>;\nexport type ReaderOfNode<TNode extends DocumentNode> = TNode extends {\n kind: 'field';\n}\n ? FieldReader<DocumentValueOfNode<TNode>>\n : TNode extends ObjectNode<infer TShape>\n ? { readonly [K in keyof TShape]: ReaderOfNode<TShape[K]> }\n : TNode extends VariantNode<string, infer TVariants>\n ? { readonly [K in keyof TVariants]: ReaderOfNode<TVariants[K]> }\n : TNode extends SingleNode<infer TValue>\n ? ReaderOfNode<TValue>\n : TNode extends TableNode<infer TValue>\n ? CollectionReader<string, DocumentValueOfNode<TValue>>\n : TNode extends MapNode<infer TValue>\n ? CollectionReader<string, DocumentValueOfNode<TValue>>\n : TNode extends DictNode<infer TKey, infer TValue>\n ? FieldReader<Readonly<Partial<Record<TKey, TValue>>>>\n : TNode extends ListNode<infer TItem>\n ? ListReader<TItem>\n : TNode extends TreeNode<infer TValue>\n ? TreeReader<TValue>\n : FieldReader<DocumentValueOfNode<TNode>>;\nexport type DocumentReader<TSchema extends DocumentSchema> = ReaderOfNode<\n ObjectNode<TSchema['shape']>\n>;\n\nexport type ReaderContext = {\n readonly root: () => unknown;\n readonly active: () => boolean;\n readonly dependencies?: DependencyTracker;\n};\n\nconst schemaRoot = (schema: DocumentSchema): DocumentNode => object(schema.shape);\n\nconst assertActive = (context: ReaderContext): void => {\n if (!context.active()) throw new Error('Document reader is no longer active.');\n};\n\nconst readAt = (context: ReaderContext, address: DocumentAddress): unknown => {\n assertActive(context);\n profile.reader.lookup();\n return readAddress(context.root(), address);\n};\n\nconst collectValue = (context: ReaderContext, address: DocumentAddress): void => {\n context.dependencies?.record({ kind: 'value', at: address });\n};\n\nconst collectCollection = (context: ReaderContext, address: DocumentAddress, id?: string): void => {\n const target: ImpactTarget<unknown> = {\n kind: 'collection',\n at: address,\n ...(id === undefined ? {} : { id }),\n };\n context.dependencies?.record(target);\n};\n\nexport const readerFor = (\n node: DocumentNode,\n context: ReaderContext,\n address: DocumentAddress = []\n): unknown => {\n if (node.kind === 'field')\n return {\n get: () => {\n collectValue(context, address);\n return readAt(context, address);\n },\n };\n if (node.kind === 'dict' || node.kind === 'record')\n return {\n get: () => {\n collectValue(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(readAt(context, address), 'reader');\n },\n };\n if (node.kind === 'list')\n return {\n values: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(Array.isArray(value) ? value : [], 'reader');\n },\n length: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n return Array.isArray(value) ? value.length : 0;\n },\n at: (index: number) => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(Array.isArray(value) ? value[index] : undefined, 'reader');\n },\n };\n if (node.kind === 'tree')\n return {\n rootId: () => {\n collectValue(context, address);\n const value = readAt(context, address);\n return isRecord(value) && typeof value.rootId === 'string' ? value.rootId : undefined;\n },\n has: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n return (\n isRecord(value) &&\n isRecord(value.nodes) &&\n Object.prototype.hasOwnProperty.call(value.nodes, id)\n );\n },\n value: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n profile.reader.structuralSnapshot();\n return cloneValue(\n isRecord(value) && isRecord(value.nodes) && isRecord(value.nodes[id])\n ? value.nodes[id].value\n : undefined,\n 'reader'\n );\n },\n parent: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : undefined;\n return isRecord(entry) && typeof entry.parentId === 'string' ? entry.parentId : undefined;\n },\n children: (id: string) => {\n collectValue(context, address);\n const value = readAt(context, address);\n const entry = isRecord(value) && isRecord(value.nodes) ? value.nodes[id] : undefined;\n return isRecord(entry) && Array.isArray(entry.children) ? [...entry.children] : [];\n },\n };\n if (node.kind === 'table' || node.kind === 'map') {\n let items: Map<string, unknown> | undefined;\n return {\n ids: () => {\n collectCollection(context, address);\n const value = readAt(context, address);\n const ids =\n node.kind === 'table' && isRecord(value) && Array.isArray(value.ids)\n ? [...value.ids]\n : isRecord(value)\n ? Object.keys(value)\n : [];\n profile.reader.collectionIds(ids.length);\n return ids;\n },\n has: (id: string) => {\n collectCollection(context, address, id);\n const value = readAt(context, address);\n const byId =\n node.kind === 'table' && isRecord(value) && isRecord(value.byId) ? value.byId : value;\n return isRecord(byId) && Object.prototype.hasOwnProperty.call(byId, id);\n },\n get: (id: string) => {\n collectCollection(context, address, id);\n const value = readAt(context, address);\n const byId =\n node.kind === 'table' && isRecord(value) && isRecord(value.byId) ? value.byId : value;\n if (!isRecord(byId) || !Object.prototype.hasOwnProperty.call(byId, id)) return undefined;\n const cached = items?.get(id);\n if (cached) return cached as EntityReader<unknown>;\n const reader = readerFor(node.value, context, [...address, id]);\n (items ??= new Map()).set(id, reader);\n return reader;\n },\n };\n }\n if (node.kind === 'single') return readerFor(node.value, context, address);\n if (node.kind === 'variant')\n return new Proxy(\n {},\n {\n get: (_target, property: string | symbol) => {\n if (typeof property === 'symbol') return undefined;\n const value = readAt(context, address);\n const tag =\n isRecord(value) && typeof value[node.tag] === 'string'\n ? String(value[node.tag])\n : undefined;\n const branch = tag ? node.variants[tag] : undefined;\n const child = branch?.shape[property];\n return child ? readerFor(child, context, [...address, property]) : undefined;\n },\n }\n );\n\n let children: Map<string, unknown> | undefined;\n return new Proxy(\n {},\n {\n get: (_target, property: string | symbol) => {\n if (typeof property === 'symbol') return undefined;\n const child = node.shape[property];\n if (!child) return undefined;\n const cached = children?.get(property);\n if (cached) return cached;\n const reader = readerFor(child, context, [...address, property]);\n (children ??= new Map()).set(property, reader);\n return reader;\n },\n }\n );\n};\n\nexport const documentReader = <TSchema extends DocumentSchema>(\n schema: TSchema,\n root: () => ReadonlyDocument<TSchema>,\n active: () => boolean,\n dependencies?: DependencyTracker\n): DocumentReader<TSchema> => {\n profile.reader.session();\n return readerFor(schemaRoot(schema), {\n root,\n active,\n dependencies,\n }) as DocumentReader<TSchema>;\n};\n","import type { DocumentAddress, DocumentSchema, ImpactTarget, ReadonlyDocument } from '../schema';\nimport type { AddressRef } from '../address';\nimport type { DocumentOperationUnion } from '../operations';\nimport type { DocumentImpact } from '../impact';\nimport type { DocumentReader } from '../access/reader';\nimport type { DocumentWriter } from '../access/writer';\nimport type { MutationIssue } from '../mutation/issue';\nimport type { CommandFootprint } from '../mutation/footprint';\n\nexport type Unsubscribe = () => void;\nexport type CommitSource = 'local' | 'system' | 'history' | 'remote';\n\nexport class DocumentReentrancyError extends Error {\n constructor() {\n super('Document writes cannot be re-entered during an update or notification.');\n this.name = 'DocumentReentrancyError';\n }\n}\n\nexport class DocumentDisposedError extends Error {\n constructor() {\n super('Doxum runtime has been disposed.');\n this.name = 'DocumentDisposedError';\n }\n}\nexport type DocumentCommit<TSchema extends DocumentSchema> = {\n readonly revision: number;\n readonly kind: 'operations' | 'replace';\n readonly source: CommitSource;\n readonly operations: readonly DocumentOperationUnion<TSchema>[];\n readonly inverse: readonly DocumentOperationUnion<TSchema>[];\n readonly impact: DocumentImpact<TSchema>;\n};\nexport type DocumentDiagnostic = {\n readonly source: 'application';\n readonly code: string;\n readonly message: string;\n readonly address?: DocumentAddress;\n};\nexport type DocumentProblem = DocumentDiagnostic | MutationIssue;\nexport type ObserverError = {\n readonly phase: 'processor' | 'flush' | 'listener';\n readonly error: unknown;\n};\nexport type TransactionResult<TValue, TCommit> =\n | {\n readonly status: 'committed';\n readonly value: TValue;\n readonly commit: TCommit;\n readonly reports: readonly DocumentDiagnostic[];\n readonly observerErrors: readonly ObserverError[];\n }\n | {\n readonly status: 'unchanged';\n readonly value: TValue;\n readonly revision: number;\n readonly reports: readonly DocumentDiagnostic[];\n }\n | {\n readonly status: 'rejected';\n readonly issues: readonly DocumentProblem[];\n readonly revision: number;\n };\nexport type PreparedUpdateResult<TValue, TSchema extends DocumentSchema> =\n | {\n readonly status: 'prepared';\n readonly value: TValue;\n readonly operations: readonly DocumentOperationUnion<TSchema>[];\n readonly inverse: readonly DocumentOperationUnion<TSchema>[];\n readonly impact: DocumentImpact<TSchema>;\n readonly footprint: CommandFootprint;\n readonly reports: readonly DocumentDiagnostic[];\n }\n | {\n readonly status: 'unchanged';\n readonly value: TValue;\n readonly reports: readonly DocumentDiagnostic[];\n }\n | {\n readonly status: 'rejected';\n readonly issues: readonly DocumentProblem[];\n };\nexport type OperationResult<TCommit> =\n | {\n readonly status: 'committed';\n readonly commit: TCommit;\n readonly observerErrors: readonly ObserverError[];\n }\n | { readonly status: 'unchanged'; readonly revision: number }\n | {\n readonly status: 'rejected';\n readonly issues: readonly MutationIssue[];\n readonly revision: number;\n };\n\nexport type HistoryState = {\n readonly undoDepth: number;\n readonly redoDepth: number;\n};\nexport type LocalHistory<TCommit> = {\n current(): HistoryState;\n subscribe(listener: () => void): Unsubscribe;\n undo(): OperationResult<TCommit>;\n redo(): OperationResult<TCommit>;\n clear(): void;\n};\n\nexport type DocumentTransaction<TSchema extends DocumentSchema> = {\n readonly read: DocumentReader<TSchema>;\n readonly write: DocumentWriter<TSchema>;\n readonly reject: (issue: DocumentDiagnostic | readonly DocumentDiagnostic[]) => never;\n readonly report: (issue: DocumentDiagnostic) => void;\n};\nexport type CommitListener<TSchema extends DocumentSchema> = (\n commit: DocumentCommit<TSchema>\n) => void;\nexport type RuntimeProcessor<TSchema extends DocumentSchema> = {\n readonly process: (commit: DocumentCommit<TSchema>) => void;\n readonly flush: () => void;\n};\n\nexport type DocumentReadable<TSchema extends DocumentSchema> = {\n readonly address: {\n readonly resolve: (address: DocumentAddress) => AddressRef | undefined;\n readonly read: (address: DocumentAddress) => unknown;\n readonly contains: (parent: DocumentAddress, child: DocumentAddress) => boolean;\n readonly overlaps: (left: DocumentAddress, right: DocumentAddress) => boolean;\n readonly debugKey: (address: DocumentAddress) => string;\n };\n revision(): number;\n subscribe(listener: CommitListener<TSchema>): Unsubscribe;\n subscribe(\n target: ImpactTarget<unknown> | readonly [ImpactTarget<unknown>, ...ImpactTarget<unknown>[]],\n listener: CommitListener<TSchema>\n ): Unsubscribe;\n};\n\nexport type DocumentRuntime<TSchema extends DocumentSchema> = DocumentReadable<TSchema> & {\n /** Schema configuration captured when this runtime was created. */\n readonly schema: TSchema;\n update<TResult>(\n run: (transaction: DocumentTransaction<TSchema>) => TResult,\n options?: {\n readonly source?: Extract<CommitSource, 'local' | 'system'>;\n readonly history?: boolean;\n }\n ): TransactionResult<TResult, DocumentCommit<TSchema>>;\n prepare<TResult>(\n run: (transaction: DocumentTransaction<TSchema>) => TResult\n ): PreparedUpdateResult<TResult, TSchema>;\n apply(\n operations: unknown,\n options?: {\n readonly source?: Exclude<CommitSource, 'history'>;\n readonly history?: boolean;\n }\n ): OperationResult<DocumentCommit<TSchema>>;\n replace(\n document: ReadonlyDocument<TSchema>,\n options?: { readonly source?: Extract<CommitSource, 'system' | 'remote'> }\n ): OperationResult<DocumentCommit<TSchema>>;\n snapshot(): ReadonlyDocument<TSchema>;\n readonly history: LocalHistory<DocumentCommit<TSchema>>;\n dispose(): void;\n};\n","import type { DocumentSchema, ReadonlyDocument } from '../schema';\nimport type { DocumentReader } from '../access/reader';\nimport { documentReader } from '../access/reader';\nimport type { DependencyTracker } from '../access/dependency';\nimport { DocumentDisposedError } from './contract';\nimport type { DocumentReadable } from './contract';\n\nexport type RuntimeAccessState<TSchema extends DocumentSchema> = {\n readonly schema: TSchema;\n document: ReadonlyDocument<TSchema>;\n disposed: boolean;\n};\n\nconst states = new WeakMap<object, RuntimeAccessState<DocumentSchema>>();\n\nexport const bindRuntimeAccess = <TSchema extends DocumentSchema>(\n runtime: DocumentReadable<TSchema>,\n state: RuntimeAccessState<TSchema>\n): void => {\n states.set(runtime as object, state as RuntimeAccessState<DocumentSchema>);\n};\n\nexport const accessOf = <TSchema extends DocumentSchema>(\n runtime: DocumentReadable<TSchema>\n): RuntimeAccessState<TSchema> => {\n const state = states.get(runtime as object);\n if (!state) throw new Error('Unknown Doxum runtime.');\n return state as RuntimeAccessState<TSchema>;\n};\n\nexport const schemaOf = <TSchema extends DocumentSchema>(\n runtime: DocumentReadable<TSchema>\n): TSchema => accessOf(runtime).schema;\n\nexport const documentOf = <TSchema extends DocumentSchema>(\n runtime: DocumentReadable<TSchema>\n): ReadonlyDocument<TSchema> => accessOf(runtime).document;\n\nexport const readWith = <TSchema extends DocumentSchema, TResult>(\n runtime: DocumentReadable<TSchema>,\n run: (read: DocumentReader<TSchema>) => TResult,\n dependencies?: DependencyTracker\n): TResult => {\n const state = accessOf(runtime);\n if (state.disposed) throw new DocumentDisposedError();\n let active = true;\n const reader = documentReader(\n state.schema,\n () => state.document,\n () => active,\n dependencies\n );\n try {\n return run(reader);\n } finally {\n // Readers are transaction-scoped; retaining one cannot expose later\n // mutable canonical state outside the coordinating operation.\n active = false;\n }\n};\n","import type { ImpactTarget } from '../schema';\nimport * as impactTarget from '../impact-target';\n\nexport type DependencyTracker = {\n readonly record: (target: ImpactTarget<unknown>) => void;\n readonly clear: () => void;\n readonly size: () => number;\n readonly some: (test: (target: ImpactTarget<unknown>) => boolean) => boolean;\n readonly snapshot: () => readonly ImpactTarget<unknown>[];\n};\n\nexport const createDependencyTracker = (): DependencyTracker => {\n const targets: ImpactTarget<unknown>[] = [];\n return {\n record: value => {\n if (!targets.some(entry => impactTarget.same(entry, value))) targets.push(value);\n },\n clear: () => {\n targets.length = 0;\n },\n size: () => targets.length,\n some: test => targets.some(test),\n snapshot: () => Object.freeze(targets.slice()),\n };\n};\n"],"mappings":";;;AAsOA,MAAM,QAAgC,UAAgB,OAAO,OAAO,MAAM;AAC1E,MAAa,cAA+B,KAAK,EAAE,MAAM,SAAS,CAAC;AACnE,MAAa,YAAoC,UAC/C,KAAK;CAAE,GAAG;CAAO,UAAU;CAAM,CAAoB;AACvD,MAAa,UAAiC,UAC5C,KAAK;CAAE,MAAM;CAAU;CAAO,CAAC;AACjC,MAAa,WACX,KACA,aACsB,KAAK;CAAE,MAAM;CAAW;CAAK;CAAU,CAAC;AAChE,MAAa,UACX,UACkB,KAAK;CAAE,MAAM;CAAU;CAAO,CAAC;AACnD,MAAa,SACX,UACiB,KAAK;CAAE,MAAM;CAAS;CAAO,CAAC;AACjD,MAAa,OACX,UACe,KAAK;CAAE,MAAM;CAAO;CAAO,CAAC;AAC7C,MAAa,eACX,KAAK,EAAE,MAAM,UAAU,CAAC;AAC1B,MAAa,aACX,KAAK,EAAE,MAAM,QAAQ,CAAC;AACxB,MAAa,QAAe,YACzB;CAAE,MAAM;CAAQ,OAAO,OAAO;CAAO;AACxC,MAAa,aAAiD,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEpF,MAAM,aAAa,YACjB,IAAI,MAAM,EAAE,SAAS,EAAwD,EAC3E,MAAM,SAAS,aAA8B;AAC3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