doxum 0.1.39 → 0.1.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/advanced.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_transform = require("./transform-BnQZlLRP.cjs");
2
+ const require_transform = require("./transform-8xXf0OKB.cjs");
3
3
  const require_record = require("./record-ChYUi8PP.cjs");
4
4
  //#region core/src/projection/advanced.ts
5
5
  const resetCollectionChange = Object.freeze({ kind: "reset" });
package/dist/advanced.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as defineProcessor, S as compileProjectionDependencies, _ as assertSynchronous, r as collectionChange, t as createKeyedTransform, w as collectionView } from "./transform-Cl7CSsdR.js";
1
+ import { D as defineProcessor, S as compileProjectionDependencies, _ as assertSynchronous, r as collectionChange, t as createKeyedTransform, w as collectionView } from "./transform--WCn6_v0.js";
2
2
  import { n as isPlainObject } from "./record-B2yRhYsc.js";
3
3
  //#region core/src/projection/advanced.ts
4
4
  const resetCollectionChange = Object.freeze({ kind: "reset" });
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_transform = require("./transform-BnQZlLRP.cjs");
2
+ const require_transform = require("./transform-8xXf0OKB.cjs");
3
3
  const require_record = require("./record-ChYUi8PP.cjs");
4
4
  const require_driver = require("./driver-CN3dGxQI.cjs");
5
5
  //#region core/src/schema/model.ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ownProjections, C as snapshotProjectionValues, D as defineProcessor, E as snapshotCollectionView, M as projectionRef, N as profile, O as defineSource, S as compileProjectionDependencies, T as mapRead, _ as assertSynchronous, a as collectionChangeTouchesKey, b as ProjectionError, c as assertKeyedProjection, d as outputKind, f as createKeyRelation, g as assertScope, h as snapshotArray, i as collectionChangeIntersects, j as producerOf, k as isProjection, l as compileKeyedDependencies, m as sameArray, n as keyedAbsent, o as collectionHasStructuralChange, p as iterableMatchesArray, s as createCollectionChange, t as createKeyedTransform, u as createKeyedDependencyRuntime, v as createScheduler, w as collectionView, x as collectKeyedInvalidation, y as ProjectionDisposedError } from "./transform-Cl7CSsdR.js";
1
+ import { A as ownProjections, C as snapshotProjectionValues, D as defineProcessor, E as snapshotCollectionView, M as projectionRef, N as profile, O as defineSource, S as compileProjectionDependencies, T as mapRead, _ as assertSynchronous, a as collectionChangeTouchesKey, b as ProjectionError, c as assertKeyedProjection, d as outputKind, f as createKeyRelation, g as assertScope, h as snapshotArray, i as collectionChangeIntersects, j as producerOf, k as isProjection, l as compileKeyedDependencies, m as sameArray, n as keyedAbsent, o as collectionHasStructuralChange, p as iterableMatchesArray, s as createCollectionChange, t as createKeyedTransform, u as createKeyedDependencyRuntime, v as createScheduler, w as collectionView, x as collectKeyedInvalidation, y as ProjectionDisposedError } from "./transform--WCn6_v0.js";
2
2
  import { n as isPlainObject, r as isRecord, t as installOwn } from "./record-B2yRhYsc.js";
3
3
  import { c as AddressIndex, d as invalidValue, f as children, g as validate, h as parent, i as contextOf, l as MutationRejected, m as is, o as decodeChanges, p as contains$1, r as bindContext, s as sealChanges, t as assertRuntimeWritable, u as fail } from "./driver-B7RR-VfX.js";
4
4
  //#region core/src/schema/model.ts
@@ -1,5 +1,6 @@
1
1
  import { n as isPlainObject } from "./record-B2yRhYsc.js";
2
2
  const profile = {
3
+ keyRelation: (key, amount = 1) => {},
3
4
  projection: (key, amount = 1) => {},
4
5
  recorder: (key, amount = 1) => {},
5
6
  access: (key) => {},
@@ -661,57 +662,95 @@ const iterableMatchesArray = (values, expected) => {
661
662
  };
662
663
  //#endregion
663
664
  //#region core/src/projection/keyed/relation.ts
664
- /** Runtime-local domain-neutral many-to-many keyed relation. */
665
+ /** Runtime-local many-to-many relation. Callers validate unique string keys before replacing.
666
+ * Forward order is meaningful; reverse sets and map iteration carry no formal order.
667
+ */
665
668
  const createKeyRelation = () => {
666
669
  const forward = /* @__PURE__ */ new Map();
667
670
  const reverse = /* @__PURE__ */ new Map();
668
671
  const detach = (left, right) => {
669
- for (const key of right) {
670
- const dependents = reverse.get(key);
671
- dependents?.delete(left);
672
- if (dependents?.size === 0) reverse.delete(key);
672
+ const dependents = reverse.get(right);
673
+ if (!dependents?.delete(left)) return;
674
+ profile.keyRelation("detachedEdges");
675
+ if (dependents.size === 0) {
676
+ reverse.delete(right);
677
+ profile.keyRelation("deletedBuckets");
673
678
  }
674
679
  };
675
680
  const attach = (left, right) => {
676
- for (const key of right) {
677
- const dependents = reverse.get(key);
678
- if (dependents) dependents.add(left);
679
- else reverse.set(key, new Set([left]));
681
+ const dependents = reverse.get(right);
682
+ if (dependents) {
683
+ if (dependents.has(left)) return false;
684
+ dependents.add(left);
685
+ } else {
686
+ reverse.set(right, new Set([left]));
687
+ profile.keyRelation("createdBuckets");
680
688
  }
689
+ profile.keyRelation("attachedEdges");
690
+ return true;
681
691
  };
682
692
  return {
683
693
  replaceOne(left, right) {
684
694
  const previous = forward.get(left);
685
695
  if (right === void 0) {
686
696
  if (!previous) return false;
687
- detach(left, previous);
697
+ for (const key of previous) detach(left, key);
688
698
  forward.delete(left);
689
699
  return true;
690
700
  }
691
701
  if (previous?.length === 1 && previous[0] === right) return false;
692
- if (previous) detach(left, previous);
693
702
  const next = Object.freeze([right]);
703
+ if (previous) {
704
+ for (const key of previous) if (key !== right) detach(left, key);
705
+ }
706
+ attach(left, right);
694
707
  forward.set(left, next);
695
- attach(left, next);
696
708
  return true;
697
709
  },
698
710
  replace(left, right) {
699
711
  const previous = forward.get(left);
700
- if (previous ? sameArray(previous, right) : right.length === 0) return false;
701
- if (previous) detach(left, previous);
712
+ if (!previous) {
713
+ if (!right.length) return false;
714
+ const next = snapshotArray(right);
715
+ for (const key of next) attach(left, key);
716
+ forward.set(left, next);
717
+ return true;
718
+ }
719
+ if (previous === right) return false;
702
720
  if (!right.length) {
721
+ for (const key of previous) detach(left, key);
703
722
  forward.delete(left);
704
723
  return true;
705
724
  }
725
+ let start = 0;
726
+ while (start < previous.length && start < right.length && previous[start] === right[start]) start++;
727
+ if (start === previous.length && start === right.length) return false;
706
728
  const next = snapshotArray(right);
729
+ let oldEnd = previous.length;
730
+ let nextEnd = next.length;
731
+ while (oldEnd > start && nextEnd > start && previous[oldEnd - 1] === next[nextEnd - 1]) {
732
+ oldEnd--;
733
+ nextEnd--;
734
+ }
735
+ let retained = 0;
736
+ for (let index = start; index < nextEnd; index++) if (!attach(left, next[index])) retained++;
737
+ if (retained === 0) for (let index = start; index < oldEnd; index++) detach(left, previous[index]);
738
+ else if (retained < oldEnd - start) if (nextEnd - start === 1) {
739
+ for (let index = start; index < oldEnd; index++) if (previous[index] !== next[start]) detach(left, previous[index]);
740
+ } else {
741
+ const requested = /* @__PURE__ */ new Set();
742
+ for (let index = start; index < nextEnd; index++) requested.add(next[index]);
743
+ profile.keyRelation("diffSets");
744
+ profile.keyRelation("diffKeys", requested.size);
745
+ for (let index = start; index < oldEnd; index++) if (!requested.has(previous[index])) detach(left, previous[index]);
746
+ }
707
747
  forward.set(left, next);
708
- attach(left, next);
709
748
  return true;
710
749
  },
711
750
  delete(left) {
712
751
  const previous = forward.get(left);
713
752
  if (!previous) return false;
714
- detach(left, previous);
753
+ for (const key of previous) detach(left, key);
715
754
  forward.delete(left);
716
755
  return true;
717
756
  },
@@ -1,5 +1,6 @@
1
1
  const require_record = require("./record-ChYUi8PP.cjs");
2
2
  const profile = {
3
+ keyRelation: (key, amount = 1) => {},
3
4
  projection: (key, amount = 1) => {},
4
5
  recorder: (key, amount = 1) => {},
5
6
  access: (key) => {},
@@ -661,57 +662,95 @@ const iterableMatchesArray = (values, expected) => {
661
662
  };
662
663
  //#endregion
663
664
  //#region core/src/projection/keyed/relation.ts
664
- /** Runtime-local domain-neutral many-to-many keyed relation. */
665
+ /** Runtime-local many-to-many relation. Callers validate unique string keys before replacing.
666
+ * Forward order is meaningful; reverse sets and map iteration carry no formal order.
667
+ */
665
668
  const createKeyRelation = () => {
666
669
  const forward = /* @__PURE__ */ new Map();
667
670
  const reverse = /* @__PURE__ */ new Map();
668
671
  const detach = (left, right) => {
669
- for (const key of right) {
670
- const dependents = reverse.get(key);
671
- dependents?.delete(left);
672
- if (dependents?.size === 0) reverse.delete(key);
672
+ const dependents = reverse.get(right);
673
+ if (!dependents?.delete(left)) return;
674
+ profile.keyRelation("detachedEdges");
675
+ if (dependents.size === 0) {
676
+ reverse.delete(right);
677
+ profile.keyRelation("deletedBuckets");
673
678
  }
674
679
  };
675
680
  const attach = (left, right) => {
676
- for (const key of right) {
677
- const dependents = reverse.get(key);
678
- if (dependents) dependents.add(left);
679
- else reverse.set(key, new Set([left]));
681
+ const dependents = reverse.get(right);
682
+ if (dependents) {
683
+ if (dependents.has(left)) return false;
684
+ dependents.add(left);
685
+ } else {
686
+ reverse.set(right, new Set([left]));
687
+ profile.keyRelation("createdBuckets");
680
688
  }
689
+ profile.keyRelation("attachedEdges");
690
+ return true;
681
691
  };
682
692
  return {
683
693
  replaceOne(left, right) {
684
694
  const previous = forward.get(left);
685
695
  if (right === void 0) {
686
696
  if (!previous) return false;
687
- detach(left, previous);
697
+ for (const key of previous) detach(left, key);
688
698
  forward.delete(left);
689
699
  return true;
690
700
  }
691
701
  if (previous?.length === 1 && previous[0] === right) return false;
692
- if (previous) detach(left, previous);
693
702
  const next = Object.freeze([right]);
703
+ if (previous) {
704
+ for (const key of previous) if (key !== right) detach(left, key);
705
+ }
706
+ attach(left, right);
694
707
  forward.set(left, next);
695
- attach(left, next);
696
708
  return true;
697
709
  },
698
710
  replace(left, right) {
699
711
  const previous = forward.get(left);
700
- if (previous ? sameArray(previous, right) : right.length === 0) return false;
701
- if (previous) detach(left, previous);
712
+ if (!previous) {
713
+ if (!right.length) return false;
714
+ const next = snapshotArray(right);
715
+ for (const key of next) attach(left, key);
716
+ forward.set(left, next);
717
+ return true;
718
+ }
719
+ if (previous === right) return false;
702
720
  if (!right.length) {
721
+ for (const key of previous) detach(left, key);
703
722
  forward.delete(left);
704
723
  return true;
705
724
  }
725
+ let start = 0;
726
+ while (start < previous.length && start < right.length && previous[start] === right[start]) start++;
727
+ if (start === previous.length && start === right.length) return false;
706
728
  const next = snapshotArray(right);
729
+ let oldEnd = previous.length;
730
+ let nextEnd = next.length;
731
+ while (oldEnd > start && nextEnd > start && previous[oldEnd - 1] === next[nextEnd - 1]) {
732
+ oldEnd--;
733
+ nextEnd--;
734
+ }
735
+ let retained = 0;
736
+ for (let index = start; index < nextEnd; index++) if (!attach(left, next[index])) retained++;
737
+ if (retained === 0) for (let index = start; index < oldEnd; index++) detach(left, previous[index]);
738
+ else if (retained < oldEnd - start) if (nextEnd - start === 1) {
739
+ for (let index = start; index < oldEnd; index++) if (previous[index] !== next[start]) detach(left, previous[index]);
740
+ } else {
741
+ const requested = /* @__PURE__ */ new Set();
742
+ for (let index = start; index < nextEnd; index++) requested.add(next[index]);
743
+ profile.keyRelation("diffSets");
744
+ profile.keyRelation("diffKeys", requested.size);
745
+ for (let index = start; index < oldEnd; index++) if (!requested.has(previous[index])) detach(left, previous[index]);
746
+ }
707
747
  forward.set(left, next);
708
- attach(left, next);
709
748
  return true;
710
749
  },
711
750
  delete(left) {
712
751
  const previous = forward.get(left);
713
752
  if (!previous) return false;
714
- detach(left, previous);
753
+ for (const key of previous) detach(left, key);
715
754
  forward.delete(left);
716
755
  return true;
717
756
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doxum",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Doxum is a typed runtime for complex mutable documents.",
@@ -41,7 +41,11 @@ This file is maintainer-only. Application/library consumers should use [Public A
41
41
  remains static. `derive.keyed` declares extra sources in one named dependency object;
42
42
  `{ source, key }` members bind one source key and `{ source, keys }` members bind an
43
43
  ordered duplicate-free set of source keys for each output key. The materialized Runtime owns those bindings and reverse indexes,
44
- including bindings to currently missing source entries. Processors do not create graph
44
+ including bindings to currently missing source entries. `projection/keyed/relation.ts`
45
+ owns edge differences and ordered forward snapshots. Keep retained reverse buckets intact;
46
+ pure reorder changes forward order even with zero edge writes. Callers validate unique
47
+ string keys, and reverse iteration is not formal order. Sequence comparison and
48
+ dependency snapshots can still cost O(number of selected keys). Processors do not create graph
45
49
  dependencies through imperative Runtime reads. A scope adds lifecycle ownership only
46
50
  through `scope.own`; scoped definitions may depend on root definitions, while root and
47
51
  sibling scopes cannot depend on scoped definitions. Notification failures leave commits