doxum 0.1.1

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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +218 -0
  3. package/dist/chunk-pbuEa-1d.js +13 -0
  4. package/dist/contract-DwNiKioc.d.ts +480 -0
  5. package/dist/contract-Otb5W6cQ.d.cts +480 -0
  6. package/dist/dependency-BdEMyquf.js +735 -0
  7. package/dist/dependency-BdEMyquf.js.map +1 -0
  8. package/dist/dependency-DLcCvNKq.cjs +1015 -0
  9. package/dist/dependency-DLcCvNKq.cjs.map +1 -0
  10. package/dist/index.cjs +2718 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +89 -0
  13. package/dist/index.d.ts +87 -0
  14. package/dist/index.js +2689 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/integration.cjs +15 -0
  17. package/dist/integration.cjs.map +1 -0
  18. package/dist/integration.d.cts +11 -0
  19. package/dist/integration.d.ts +11 -0
  20. package/dist/integration.js +14 -0
  21. package/dist/integration.js.map +1 -0
  22. package/dist/react.cjs +99 -0
  23. package/dist/react.cjs.map +1 -0
  24. package/dist/react.d.cts +16 -0
  25. package/dist/react.d.ts +16 -0
  26. package/dist/react.js +96 -0
  27. package/dist/react.js.map +1 -0
  28. package/package.json +89 -0
  29. package/skills/doxum-runtime/SKILL.md +51 -0
  30. package/skills/doxum-runtime/agents/openai.yaml +4 -0
  31. package/skills/doxum-runtime/references/guide.en.md +295 -0
  32. package/skills/doxum-runtime/references/guide.zh-CN.md +240 -0
  33. package/skills/doxum-runtime/references/invariants.en.md +147 -0
  34. package/skills/doxum-runtime/references/invariants.zh-CN.md +97 -0
  35. package/skills/doxum-runtime/references/patterns.en.md +287 -0
  36. package/skills/doxum-runtime/references/patterns.zh-CN.md +240 -0
@@ -0,0 +1,735 @@
1
+ import { t as __exportAll } from "./chunk-pbuEa-1d.js";
2
+ //#region core/src/schema.ts
3
+ const node = (value) => Object.freeze(value);
4
+ const field = () => node({ kind: "field" });
5
+ const optional = (value) => node({
6
+ ...value,
7
+ optional: true
8
+ });
9
+ const object = (shape) => node({
10
+ kind: "object",
11
+ shape
12
+ });
13
+ const variant = (tag, variants) => node({
14
+ kind: "variant",
15
+ tag,
16
+ variants
17
+ });
18
+ const single = (value) => node({
19
+ kind: "single",
20
+ value
21
+ });
22
+ const table = (value) => node({
23
+ kind: "table",
24
+ value
25
+ });
26
+ const map = (value) => node({
27
+ kind: "map",
28
+ value
29
+ });
30
+ const record = () => node({ kind: "record" });
31
+ const dict = () => node({ kind: "dict" });
32
+ const list = (config) => ({
33
+ kind: "list",
34
+ keyOf: config.keyOf
35
+ });
36
+ const tree = () => node({ kind: "tree" });
37
+ const pathProxy = (address) => new Proxy({ address }, { get: (_target, property) => {
38
+ if (property === "address") return address;
39
+ if (property === "item") return (id) => pathProxy([...address, id]);
40
+ if (typeof property === "symbol") return void 0;
41
+ return pathProxy([...address, property]);
42
+ } });
43
+ const select = (owner, kind, pick) => {
44
+ const selected = pick(pathProxy([]));
45
+ return Object.freeze({
46
+ kind,
47
+ schema: owner,
48
+ address: Object.freeze([...selected.address ?? []])
49
+ });
50
+ };
51
+ const schema = (shape) => {
52
+ const result = {
53
+ kind: "schema",
54
+ shape,
55
+ collection: (pick) => select(result, "collection", pick),
56
+ value: (pick) => select(result, "value", pick)
57
+ };
58
+ return Object.freeze(result);
59
+ };
60
+ //#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
+ //#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 hashText = (value, seed) => {
255
+ let hash = seed;
256
+ for (let index = 0; index < value.length; index += 1) hash = Math.imul(hash ^ value.charCodeAt(index), 16777619);
257
+ return hash >>> 0;
258
+ };
259
+ const appendAddressHash = (hash, segment) => hashText(segment, hashText("/", hash));
260
+ const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
261
+ const unwrap = (node) => {
262
+ let current = node;
263
+ while (current?.kind === "single") current = current.value;
264
+ return current;
265
+ };
266
+ const variantNode = (node, value) => {
267
+ const tag = isRecord$1(value) && typeof value[node.tag] === "string" ? value[node.tag] : void 0;
268
+ return node.variants[String(tag ?? Object.keys(node.variants)[0] ?? "")];
269
+ };
270
+ const schemaRoot$1 = (schema) => ({
271
+ kind: "object",
272
+ shape: schema.shape
273
+ });
274
+ const step = (nodeInput, value, segment) => {
275
+ let node = unwrap(nodeInput);
276
+ if (!node) return {
277
+ node: void 0,
278
+ dynamic: false
279
+ };
280
+ if (node.kind === "variant") node = unwrap(variantNode(node, value));
281
+ if (!node) return {
282
+ node: void 0,
283
+ dynamic: false
284
+ };
285
+ if (node.kind === "object") return {
286
+ node: node.shape[segment],
287
+ dynamic: false
288
+ };
289
+ if (node.kind === "table" || node.kind === "map") return {
290
+ node: node.value,
291
+ dynamic: true
292
+ };
293
+ if (node.kind === "record" || node.kind === "dict" || node.kind === "list" || node.kind === "tree") return {
294
+ node,
295
+ dynamic: true
296
+ };
297
+ return {
298
+ node: void 0,
299
+ dynamic: false
300
+ };
301
+ };
302
+ const pathFor = (schema, address, document) => {
303
+ const registry = registryFor(schema);
304
+ let trie = registry.root;
305
+ let node = schemaRoot$1(schema);
306
+ let value = document;
307
+ for (const segment of address) {
308
+ profile.address.schemaStep();
309
+ profile.address.documentStep();
310
+ const resolved = step(node, value, segment);
311
+ if (!resolved.node) return void 0;
312
+ trie = resolved.dynamic ? trie.dynamic ??= registryNode() : (() => {
313
+ const existing = trie.static.get(segment);
314
+ if (existing) return existing;
315
+ const created = registryNode();
316
+ trie.static.set(segment, created);
317
+ return created;
318
+ })();
319
+ node = resolved.node;
320
+ value = readSegment(value, segment);
321
+ }
322
+ if (trie.path === void 0) trie.path = registry.nextPath++;
323
+ return trie.path;
324
+ };
325
+ const resolveAddress = (schema, address, document) => {
326
+ if (!Array.isArray(address)) return void 0;
327
+ for (const segment of address) if (typeof segment !== "string") return void 0;
328
+ profile.address.arrayCopied();
329
+ const owned = Object.freeze(address.slice());
330
+ const path = pathFor(schema, owned, document);
331
+ return path === void 0 ? void 0 : {
332
+ path,
333
+ address: owned
334
+ };
335
+ };
336
+ const nodeAt = (schema, address, document) => {
337
+ let node = schemaRoot$1(schema);
338
+ let value = document;
339
+ for (const segment of address) {
340
+ node = step(node, value, segment).node;
341
+ value = readSegment(value, segment);
342
+ if (!node) return void 0;
343
+ }
344
+ return unwrap(node);
345
+ };
346
+ 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)) {
349
+ const entity = value.byId[segment];
350
+ if (entity !== void 0 || Object.prototype.hasOwnProperty.call(value.byId, segment)) return entity;
351
+ }
352
+ return value[segment];
353
+ };
354
+ const read = (root, address) => {
355
+ let value = root;
356
+ for (const segment of address) {
357
+ value = readSegment(value, segment);
358
+ if (value === void 0) return void 0;
359
+ }
360
+ return value;
361
+ };
362
+ /** Resolves schema and document location in one address traversal. */
363
+ const resolveLocated = (schema, root, address) => {
364
+ if (address.length === 0) return void 0;
365
+ let node = schemaRoot$1(schema);
366
+ let current = root;
367
+ let collection;
368
+ let addressHash = 2166136261;
369
+ for (let index = 0; index < address.length - 1; index += 1) {
370
+ profile.address.schemaStep();
371
+ profile.address.documentStep();
372
+ const resolved = step(node, current, address[index]);
373
+ if (!resolved.node) return void 0;
374
+ if (node?.kind === "table" || node?.kind === "map") collection = {
375
+ address: address.slice(0, index),
376
+ addressHash,
377
+ id: address[index],
378
+ ...collection ? { parent: collection } : {}
379
+ };
380
+ addressHash = appendAddressHash(addressHash, address[index]);
381
+ node = resolved.node;
382
+ current = readSegment(current, address[index]);
383
+ if (!node) return void 0;
384
+ }
385
+ profile.address.schemaStep();
386
+ profile.address.documentStep();
387
+ const last = address[address.length - 1];
388
+ const resolved = step(node, current, last);
389
+ if (!resolved.node || !isRecord$1(current) && !Array.isArray(current)) return void 0;
390
+ if (node?.kind === "table" || node?.kind === "map") collection = {
391
+ address: address.slice(0, -1),
392
+ addressHash,
393
+ id: last,
394
+ ...collection ? { parent: collection } : {}
395
+ };
396
+ addressHash = appendAddressHash(addressHash, last);
397
+ if (isRecord$1(current) && "byId" in current && isRecord$1(current.byId) && last in current.byId) return {
398
+ addressHash,
399
+ node: resolved.node,
400
+ parent: current.byId,
401
+ key: last,
402
+ value: current.byId[last],
403
+ ...collection ? { collection } : {}
404
+ };
405
+ return {
406
+ addressHash,
407
+ node: resolved.node,
408
+ parent: current,
409
+ key: Array.isArray(current) && /^\d+$/.test(last) ? Number(last) : last,
410
+ value: readSegment(current, last),
411
+ ...collection ? { collection } : {}
412
+ };
413
+ };
414
+ const locate = (root, address) => {
415
+ if (address.length === 0) return void 0;
416
+ let current = root;
417
+ 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;
419
+ const last = address[address.length - 1];
420
+ if (isRecord$1(current) && "byId" in current && isRecord$1(current.byId) && last in current.byId) return {
421
+ parent: current.byId,
422
+ key: last,
423
+ value: current.byId[last]
424
+ };
425
+ return {
426
+ parent: current,
427
+ key: Array.isArray(current) && /^\d+$/.test(last) ? Number(last) : last,
428
+ value: readSegment(current, last)
429
+ };
430
+ };
431
+ const set = (root, address, value) => {
432
+ const target = locate(root, address);
433
+ if (!target) return false;
434
+ target.parent[target.key] = value;
435
+ return true;
436
+ };
437
+ const contains = (parent, child) => {
438
+ profile.address.prefixComparison();
439
+ if (parent.length > child.length) return false;
440
+ for (let index = 0; index < parent.length; index += 1) {
441
+ profile.address.segmentCompared();
442
+ if (parent[index] !== child[index]) return false;
443
+ }
444
+ return true;
445
+ };
446
+ const overlaps = (a, b) => contains(a, b) || contains(b, a);
447
+ const debugKey = (address) => {
448
+ let result = "";
449
+ for (let index = 0; index < address.length; index += 1) {
450
+ if (index > 0) result += "/";
451
+ result += address[index].replaceAll("~", "~~").replaceAll("/", "~/");
452
+ }
453
+ return result;
454
+ };
455
+ //#endregion
456
+ //#region core/src/impact-target.ts
457
+ var impact_target_exports = /* @__PURE__ */ __exportAll({
458
+ address: () => address,
459
+ belongs: () => belongs,
460
+ bucket: () => bucket,
461
+ id: () => id,
462
+ same: () => same
463
+ });
464
+ const address = (target) => "at" in target ? target.at : target.address;
465
+ const id = (target) => target.kind === "collection" && "id" in target ? target.id : void 0;
466
+ const belongs = (target, schema) => !("schema" in target) || target.schema === schema;
467
+ const same = (left, right) => {
468
+ if (left.kind !== right.kind) return false;
469
+ if ("schema" in left && "schema" in right && left.schema !== right.schema) return false;
470
+ const leftAddress = address(left);
471
+ const rightAddress = address(right);
472
+ if (leftAddress.length !== rightAddress.length) return false;
473
+ for (let index = 0; index < leftAddress.length; index += 1) if (leftAddress[index] !== rightAddress[index]) return false;
474
+ return left.kind !== "collection" || id(left) === id(right);
475
+ };
476
+ const bucket = (target) => address(target)[0];
477
+ //#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
+ //#region core/src/access/reader.ts
539
+ const schemaRoot = (schema) => object(schema.shape);
540
+ const assertActive = (context) => {
541
+ if (!context.active()) throw new Error("Document reader is no longer active.");
542
+ };
543
+ const readAt = (context, address) => {
544
+ assertActive(context);
545
+ profile.reader.lookup();
546
+ return read(context.root(), address);
547
+ };
548
+ const collectValue = (context, address) => {
549
+ context.dependencies?.record({
550
+ kind: "value",
551
+ at: address
552
+ });
553
+ };
554
+ const collectCollection = (context, address, id) => {
555
+ const target = {
556
+ kind: "collection",
557
+ at: address,
558
+ ...id === void 0 ? {} : { id }
559
+ };
560
+ context.dependencies?.record(target);
561
+ };
562
+ const readerFor = (node, context, address = []) => {
563
+ if (node.kind === "field") return { get: () => {
564
+ collectValue(context, address);
565
+ return readAt(context, address);
566
+ } };
567
+ if (node.kind === "dict" || node.kind === "record") return { get: () => {
568
+ collectValue(context, address);
569
+ profile.reader.structuralSnapshot();
570
+ return cloneValue(readAt(context, address), "reader");
571
+ } };
572
+ if (node.kind === "list") return {
573
+ values: () => {
574
+ collectValue(context, address);
575
+ const value = readAt(context, address);
576
+ profile.reader.structuralSnapshot();
577
+ return cloneValue(Array.isArray(value) ? value : [], "reader");
578
+ },
579
+ length: () => {
580
+ collectValue(context, address);
581
+ const value = readAt(context, address);
582
+ return Array.isArray(value) ? value.length : 0;
583
+ },
584
+ at: (index) => {
585
+ collectValue(context, address);
586
+ const value = readAt(context, address);
587
+ profile.reader.structuralSnapshot();
588
+ return cloneValue(Array.isArray(value) ? value[index] : void 0, "reader");
589
+ }
590
+ };
591
+ if (node.kind === "tree") return {
592
+ rootId: () => {
593
+ collectValue(context, address);
594
+ const value = readAt(context, address);
595
+ return isRecord(value) && typeof value.rootId === "string" ? value.rootId : void 0;
596
+ },
597
+ has: (id) => {
598
+ collectValue(context, address);
599
+ const value = readAt(context, address);
600
+ return isRecord(value) && isRecord(value.nodes) && Object.prototype.hasOwnProperty.call(value.nodes, id);
601
+ },
602
+ value: (id) => {
603
+ collectValue(context, address);
604
+ const value = readAt(context, address);
605
+ profile.reader.structuralSnapshot();
606
+ return cloneValue(isRecord(value) && isRecord(value.nodes) && isRecord(value.nodes[id]) ? value.nodes[id].value : void 0, "reader");
607
+ },
608
+ parent: (id) => {
609
+ collectValue(context, address);
610
+ 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;
613
+ },
614
+ children: (id) => {
615
+ collectValue(context, address);
616
+ 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] : [];
619
+ }
620
+ };
621
+ if (node.kind === "table" || node.kind === "map") {
622
+ let items;
623
+ return {
624
+ ids: () => {
625
+ collectCollection(context, address);
626
+ const value = readAt(context, address);
627
+ const ids = node.kind === "table" && isRecord(value) && Array.isArray(value.ids) ? [...value.ids] : isRecord(value) ? Object.keys(value) : [];
628
+ profile.reader.collectionIds(ids.length);
629
+ return ids;
630
+ },
631
+ has: (id) => {
632
+ collectCollection(context, address, id);
633
+ 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);
636
+ },
637
+ get: (id) => {
638
+ collectCollection(context, address, id);
639
+ 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;
642
+ const cached = items?.get(id);
643
+ if (cached) return cached;
644
+ const reader = readerFor(node.value, context, [...address, id]);
645
+ (items ??= /* @__PURE__ */ new Map()).set(id, reader);
646
+ return reader;
647
+ }
648
+ };
649
+ }
650
+ if (node.kind === "single") return readerFor(node.value, context, address);
651
+ if (node.kind === "variant") return new Proxy({}, { get: (_target, property) => {
652
+ if (typeof property === "symbol") return void 0;
653
+ const value = readAt(context, address);
654
+ const tag = isRecord(value) && typeof value[node.tag] === "string" ? String(value[node.tag]) : void 0;
655
+ const child = (tag ? node.variants[tag] : void 0)?.shape[property];
656
+ return child ? readerFor(child, context, [...address, property]) : void 0;
657
+ } });
658
+ let children;
659
+ return new Proxy({}, { get: (_target, property) => {
660
+ if (typeof property === "symbol") return void 0;
661
+ const child = node.shape[property];
662
+ if (!child) return void 0;
663
+ const cached = children?.get(property);
664
+ if (cached) return cached;
665
+ const reader = readerFor(child, context, [...address, property]);
666
+ (children ??= /* @__PURE__ */ new Map()).set(property, reader);
667
+ return reader;
668
+ } });
669
+ };
670
+ const documentReader = (schema, root, active, dependencies) => {
671
+ profile.reader.session();
672
+ return readerFor(schemaRoot(schema), {
673
+ root,
674
+ active,
675
+ dependencies
676
+ });
677
+ };
678
+ //#endregion
679
+ //#region core/src/runtime/contract.ts
680
+ var DocumentReentrancyError = class extends Error {
681
+ constructor() {
682
+ super("Document writes cannot be re-entered during an update or notification.");
683
+ this.name = "DocumentReentrancyError";
684
+ }
685
+ };
686
+ var DocumentDisposedError = class extends Error {
687
+ constructor() {
688
+ super("Doxum runtime has been disposed.");
689
+ this.name = "DocumentDisposedError";
690
+ }
691
+ };
692
+ //#endregion
693
+ //#region core/src/runtime/access.ts
694
+ const states = /* @__PURE__ */ new WeakMap();
695
+ const bindRuntimeAccess = (runtime, state) => {
696
+ states.set(runtime, state);
697
+ };
698
+ const accessOf = (runtime) => {
699
+ const state = states.get(runtime);
700
+ if (!state) throw new Error("Unknown Doxum runtime.");
701
+ return state;
702
+ };
703
+ const schemaOf = (runtime) => accessOf(runtime).schema;
704
+ const documentOf = (runtime) => accessOf(runtime).document;
705
+ const readWith = (runtime, run, dependencies) => {
706
+ const state = accessOf(runtime);
707
+ if (state.disposed) throw new DocumentDisposedError();
708
+ let active = true;
709
+ const reader = documentReader(state.schema, () => state.document, () => active, dependencies);
710
+ try {
711
+ return run(reader);
712
+ } finally {
713
+ active = false;
714
+ }
715
+ };
716
+ //#endregion
717
+ //#region core/src/access/dependency.ts
718
+ const createDependencyTracker = () => {
719
+ const targets = [];
720
+ return {
721
+ record: (value) => {
722
+ if (!targets.some((entry) => same(entry, value))) targets.push(value);
723
+ },
724
+ clear: () => {
725
+ targets.length = 0;
726
+ },
727
+ size: () => targets.length,
728
+ some: (test) => targets.some(test),
729
+ snapshot: () => Object.freeze(targets.slice())
730
+ };
731
+ };
732
+ //#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 };
734
+
735
+ //# sourceMappingURL=dependency-BdEMyquf.js.map