doxum 0.1.9 → 0.1.10

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 (33) hide show
  1. package/README.md +34 -18
  2. package/dist/{contract-BNStLbSE.d.ts → contract-CeAnEPBA.d.ts} +31 -14
  3. package/dist/{contract-CIU5FCC1.d.cts → contract-DtGVSXSK.d.cts} +31 -14
  4. package/dist/index.cjs +2 -2
  5. package/dist/index.d.cts +3 -3
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +2 -2
  8. package/dist/{integration-C87tjRop.cjs → integration-BKgGuodm.cjs} +2 -2
  9. package/dist/{integration-C87tjRop.cjs.map → integration-BKgGuodm.cjs.map} +1 -1
  10. package/dist/{integration-D5XCBLJ8.js → integration-VTZ3ICsO.js} +2 -2
  11. package/dist/{integration-D5XCBLJ8.js.map → integration-VTZ3ICsO.js.map} +1 -1
  12. package/dist/integration.cjs +2 -2
  13. package/dist/integration.d.cts +2 -2
  14. package/dist/integration.d.ts +2 -2
  15. package/dist/integration.js +2 -2
  16. package/dist/local-sync.d.cts +1 -1
  17. package/dist/local-sync.d.ts +1 -1
  18. package/dist/react.cjs +2 -2
  19. package/dist/react.js +2 -2
  20. package/dist/{store-cp5CpfCy.d.ts → store-Bs0C0rNd.d.ts} +2 -2
  21. package/dist/{store-CD0KdGsq.d.cts → store-CJuwJl_K.d.cts} +2 -2
  22. package/dist/{store-D7QH6Rzw.js → store-DHFXfWSz.js} +90 -47
  23. package/dist/store-DHFXfWSz.js.map +1 -0
  24. package/dist/{store-1Uob0Ghk.cjs → store-DU2u-qFH.cjs} +95 -52
  25. package/dist/store-DU2u-qFH.cjs.map +1 -0
  26. package/package.json +1 -1
  27. package/skills/doxum-runtime/SKILL.md +3 -1
  28. package/skills/doxum-runtime/references/guide.en.md +18 -14
  29. package/skills/doxum-runtime/references/guide.zh-CN.md +16 -13
  30. package/skills/doxum-runtime/references/patterns.en.md +6 -6
  31. package/skills/doxum-runtime/references/patterns.zh-CN.md +6 -6
  32. package/dist/store-1Uob0Ghk.cjs.map +0 -1
  33. package/dist/store-D7QH6Rzw.js.map +0 -1
@@ -269,6 +269,16 @@ const compilePath = (owner, kind, pick) => {
269
269
  });
270
270
  };
271
271
  //#endregion
272
+ //#region core/src/mutation/operations/map.ts
273
+ function put(session, container, id, value) {
274
+ if (container.node.kind !== "map") return require_issue.fail(container.at, "invalid-collection", "Expected a map.");
275
+ session.writeMember(container, id, value, "set");
276
+ }
277
+ function remove$3(session, container, id) {
278
+ if (container.node.kind !== "map") return require_issue.fail(container.at, "invalid-collection", "Expected a map.");
279
+ session.writeMember(container, id, void 0, "remove");
280
+ }
281
+ //#endregion
272
282
  //#region core/src/mutation/operations/table.ts
273
283
  function create(session, container, entries, position) {
274
284
  const { at, node, value } = container;
@@ -298,6 +308,13 @@ function remove$2(session, container, ids) {
298
308
  for (const id of removed) session.writeMember(container, id, void 0, "remove");
299
309
  table.ids = table.ids.filter((id) => !removed.has(id));
300
310
  }
311
+ function replace$3(session, container, id, value) {
312
+ const { at, node, value: tableValue } = container;
313
+ if (node.kind !== "table") return require_issue.fail(at, "invalid-collection", "Expected a table.");
314
+ const table = tableValue;
315
+ if (!Object.hasOwn(table.byId, id)) return require_issue.fail(at.concat(id), "missing-entity", "Table key does not exist.");
316
+ session.writeMember(container, id, value, "set");
317
+ }
301
318
  //#endregion
302
319
  //#region core/src/mutation/operations/list.ts
303
320
  function insert$1(session, container, value, position) {
@@ -314,7 +331,7 @@ function insert$1(session, container, value, position) {
314
331
  require_issue.insert(items, require_issue.index(keys$2, position), value);
315
332
  session.invalidate();
316
333
  }
317
- function set$1(session, container, id, value) {
334
+ function replace$2(session, container, id, value) {
318
335
  const { at, node, value: items } = container;
319
336
  if (node.kind !== "list") return require_issue.fail(at, "invalid-list-key", "Expected a list.");
320
337
  const index = require_issue.indexedKeys(items, node.keyOf).index(id);
@@ -360,7 +377,7 @@ const insert = (session, container, id, value, position) => {
360
377
  else tree.rootId = id;
361
378
  session.invalidate();
362
379
  };
363
- const set = (session, container, id, value) => {
380
+ const replace$1 = (session, container, id, value) => {
364
381
  const { at, node: schema, value: tree } = container;
365
382
  const entry = node(tree, id);
366
383
  if (!entry) return require_issue.fail(at, "missing-tree-node", "Tree node does not exist.");
@@ -456,9 +473,8 @@ const snapshot = (value) => {
456
473
  if (!resolved.node) throw new Error("The selected schema address no longer exists.");
457
474
  return copyValue(resolved.node, resolved.value);
458
475
  };
459
- /** TypeScript cannot express asymmetric index signatures for nested collection tools. */
460
- const assign = (container, key, value) => {
461
- if (!locationOf(container)) throw new TypeError("assign requires scoped document access.");
476
+ const replace = (container, key, value) => {
477
+ if (!locationOf(container)) throw new TypeError("replace requires scoped document access.");
462
478
  if (typeof key !== "string") throw new TypeError("Document keys must be strings.");
463
479
  Reflect.set(container, key, value);
464
480
  };
@@ -563,6 +579,42 @@ const createAccess = (context, initial = []) => {
563
579
  if (target.container?.generation === session.generation && !("layout" in target.container)) return target.container;
564
580
  return target.container = session.bindTree(addressOf(target), target.node, target.value);
565
581
  };
582
+ const replaceCollection = (target, node, value) => {
583
+ const session = mutable();
584
+ collectionValue(target, node);
585
+ session.replace(addressOf(target), value);
586
+ };
587
+ const mapMethod = (target, property, node) => {
588
+ if (property === "ids") return () => {
589
+ const current = collectionValue(target, node);
590
+ if (context.dependencies) collect(context, addressOf(target), "collection");
591
+ return Object.keys(current);
592
+ };
593
+ if (property === "has") return (id) => {
594
+ const current = collectionValue(target, node);
595
+ if (context.dependencies) collect(context, addressOf(target), "collection", id);
596
+ return Object.hasOwn(current, id);
597
+ };
598
+ if (property === "get") return (id) => {
599
+ const current = collectionValue(target, node);
600
+ if (context.dependencies) collect(context, addressOf(target), "collection", id);
601
+ if (!Object.hasOwn(current, id)) return void 0;
602
+ if (node.value.kind === "field") {
603
+ if (context.dependencies) collect(context, childAt(target, id));
604
+ return current[id];
605
+ }
606
+ return childAccess(target, id, node.value, current[id]);
607
+ };
608
+ if (property === "put") return (id, value) => {
609
+ const writable = writableCollection(target, node);
610
+ put(context.session, writable, id, value);
611
+ };
612
+ if (property === "remove") return (id) => {
613
+ const writable = writableCollection(target, node);
614
+ remove$3(context.session, writable, id);
615
+ };
616
+ if (property === "replace") return (value) => replaceCollection(target, node, value);
617
+ };
566
618
  const orderedMethod = (target, property, node) => {
567
619
  const at = addressOf(target);
568
620
  if (property === "ids") return () => {
@@ -588,18 +640,26 @@ const createAccess = (context, initial = []) => {
588
640
  };
589
641
  };
590
642
  const tableMethod = (target, property, node) => {
591
- if (property === "create") return (input, position) => {
643
+ if (property === "create") return (input, valueOrPosition, position) => {
592
644
  const writable = writableCollection(target, node);
593
- create(context.session, writable, Array.isArray(input) ? input : [input], position);
645
+ create(context.session, writable, Array.isArray(input) ? input : [{
646
+ id: input,
647
+ value: valueOrPosition
648
+ }], Array.isArray(input) ? valueOrPosition : position);
594
649
  };
595
650
  if (property === "remove") return (ids) => {
596
651
  const writable = writableCollection(target, node);
597
652
  remove$2(context.session, writable, typeof ids === "string" ? [ids] : ids);
598
653
  };
654
+ if (property === "replace") return (...args) => {
655
+ const [valueOrId, value] = args;
656
+ if (args.length === 1) return replaceCollection(target, node, valueOrId);
657
+ const writable = writableCollection(target, node);
658
+ replace$3(context.session, writable, valueOrId, value);
659
+ };
599
660
  return orderedMethod(target, property, node);
600
661
  };
601
662
  const listMethod = (target, property, node) => {
602
- const at = addressOf(target);
603
663
  if (property === "insert") return (value, position) => {
604
664
  const writable = writableCollection(target, node);
605
665
  insert$1(context.session, writable, value, position);
@@ -608,14 +668,11 @@ const createAccess = (context, initial = []) => {
608
668
  const writable = writableCollection(target, node);
609
669
  remove$1(context.session, writable, id);
610
670
  };
611
- if (property === "set") return (id, value) => {
671
+ if (property === "replace") return (...args) => {
672
+ const [valueOrId, value] = args;
673
+ if (args.length === 1) return replaceCollection(target, node, valueOrId);
612
674
  const writable = writableCollection(target, node);
613
- set$1(context.session, writable, id, value);
614
- };
615
- if (property === "replace") return (value) => {
616
- const session = mutable();
617
- collectionValue(target, node);
618
- session.replace(at, value);
675
+ replace$2(context.session, writable, valueOrId, value);
619
676
  };
620
677
  return orderedMethod(target, property, node);
621
678
  };
@@ -625,10 +682,6 @@ const createAccess = (context, initial = []) => {
625
682
  const writable = writableTree(target, node);
626
683
  insert(context.session, writable, id, value, position);
627
684
  };
628
- if (property === "set") return (id, value) => {
629
- const writable = writableTree(target, node);
630
- set(context.session, writable, id, value);
631
- };
632
685
  if (property === "remove") return (id) => {
633
686
  const writable = writableTree(target, node);
634
687
  remove(context.session, writable, id);
@@ -637,10 +690,11 @@ const createAccess = (context, initial = []) => {
637
690
  const writable = writableTree(target, node);
638
691
  move$1(context.session, writable, id, position);
639
692
  };
640
- if (property === "replace") return (value) => {
641
- const session = mutable();
642
- collectionValue(target, node);
643
- session.replace(at, value);
693
+ if (property === "replace") return (...args) => {
694
+ const [valueOrId, value] = args;
695
+ if (args.length === 1) return replaceCollection(target, node, valueOrId);
696
+ const writable = writableTree(target, node);
697
+ replace$1(context.session, writable, valueOrId, value);
644
698
  };
645
699
  const current = () => {
646
700
  collect(context, at);
@@ -663,15 +717,7 @@ const createAccess = (context, initial = []) => {
663
717
  const { node, value } = resolve(context, target);
664
718
  if (!node || value === void 0) return void 0;
665
719
  if (typeof property !== "string") return void 0;
666
- if (node.kind === "map") {
667
- if (context.dependencies) collect(context, addressOf(target), "collection", property);
668
- if (!Object.hasOwn(value, property)) return void 0;
669
- if (node.value.kind === "field") {
670
- if (context.dependencies) collect(context, childAt(target, property));
671
- return value[property];
672
- }
673
- return childAccess(target, property, node.value, value[property]);
674
- }
720
+ if (node.kind === "map") return mapMethod(target, property, node);
675
721
  if (node.kind === "table") return tableMethod(target, property, node);
676
722
  if (node.kind === "list") return listMethod(target, property, node);
677
723
  if (node.kind === "tree") return treeMethod(target, property, node);
@@ -689,30 +735,33 @@ const createAccess = (context, initial = []) => {
689
735
  },
690
736
  set: (target, property, value) => {
691
737
  const session = mutable(), { node } = resolve(context, target);
692
- if (typeof property !== "string" || !node || node.kind !== "object" && node.kind !== "variant" && node.kind !== "map") throw new TypeError("Invalid structural assignment.");
738
+ if (typeof property !== "string" || !node || node.kind !== "object" && node.kind !== "variant") throw new TypeError("Invalid structural assignment.");
693
739
  if (node.kind === "variant" && node.tag === property) throw new TypeError("Variant discriminants are read-only.");
694
740
  session.assignMember(writableContainer(target, session), property, value);
695
741
  return true;
696
742
  },
697
743
  deleteProperty: (target, property) => {
698
744
  const session = mutable(), { node } = resolve(context, target);
699
- if (typeof property !== "string" || node?.kind === "variant" && node.tag === property) throw new TypeError("Invalid structural deletion.");
745
+ if (typeof property !== "string" || node?.kind === "map" || node?.kind === "variant" && node.tag === property) throw new TypeError("Invalid structural deletion.");
700
746
  session.removeMember(writableContainer(target, session), property);
701
747
  return true;
702
748
  },
703
749
  has: (target, property) => {
704
750
  const { node, value } = resolve(context, target);
705
751
  if (typeof property !== "string") return false;
706
- collect(context, addressOf(target), node?.kind === "map" ? "collection" : "value", node?.kind === "map" ? property : void 0);
752
+ if (node?.kind === "map") return false;
753
+ collect(context, addressOf(target));
707
754
  return value !== void 0 && Object.hasOwn(value, property);
708
755
  },
709
756
  ownKeys: (target) => {
710
- const { value } = resolve(context, target);
711
- if (context.dependencies) collect(context, addressOf(target), "collection");
757
+ const { node, value } = resolve(context, target);
758
+ if (node?.kind === "map") return [];
759
+ if (context.dependencies) collect(context, addressOf(target));
712
760
  return value && typeof value === "object" ? Object.keys(value) : [];
713
761
  },
714
762
  getOwnPropertyDescriptor: (target, property) => {
715
- const { value } = resolve(context, target);
763
+ const { node, value } = resolve(context, target);
764
+ if (node?.kind === "map") return void 0;
716
765
  return value && Object.hasOwn(value, property) ? {
717
766
  enumerable: true,
718
767
  configurable: true
@@ -753,13 +802,7 @@ const collectionAccess = (context, at) => {
753
802
  return [];
754
803
  }
755
804
  };
756
- if (locations.get(value).target.node?.kind === "table") return value;
757
- const map = value;
758
- return {
759
- get: (id) => map[id],
760
- has: (id) => id in map,
761
- ids: () => Object.keys(map)
762
- };
805
+ return value;
763
806
  };
764
807
  //#endregion
765
808
  //#region core/src/impact-target.ts
@@ -2548,12 +2591,6 @@ Object.defineProperty(exports, "accessOf", {
2548
2591
  return accessOf;
2549
2592
  }
2550
2593
  });
2551
- Object.defineProperty(exports, "assign", {
2552
- enumerable: true,
2553
- get: function() {
2554
- return assign;
2555
- }
2556
- });
2557
2594
  Object.defineProperty(exports, "bindDocumentReadable", {
2558
2595
  enumerable: true,
2559
2596
  get: function() {
@@ -2692,6 +2729,12 @@ Object.defineProperty(exports, "readWith", {
2692
2729
  return readWith;
2693
2730
  }
2694
2731
  });
2732
+ Object.defineProperty(exports, "replace", {
2733
+ enumerable: true,
2734
+ get: function() {
2735
+ return replace;
2736
+ }
2737
+ });
2695
2738
  Object.defineProperty(exports, "same", {
2696
2739
  enumerable: true,
2697
2740
  get: function() {
@@ -2747,4 +2790,4 @@ Object.defineProperty(exports, "variant", {
2747
2790
  }
2748
2791
  });
2749
2792
 
2750
- //# sourceMappingURL=store-1Uob0Ghk.cjs.map
2793
+ //# sourceMappingURL=store-DU2u-qFH.cjs.map