|
@@ -17,6 +17,8 @@ import {
|
|
|
} from "./composite_delta";
|
|
|
import {mockUuid} from "./test_helpers";
|
|
|
import {UUID} from "./types";
|
|
|
+import {assert} from "../util/assert";
|
|
|
+import {visitPartialOrdering} from "../util/partial_ordering";
|
|
|
|
|
|
function getParentLink(cs: Version, parentCorr: Version): [Version,Delta] {
|
|
|
const parentCsEmbedding = parentCorr.getEmbedded("cs");
|
|
@@ -70,7 +72,7 @@ class TrivialParser implements Parser {
|
|
|
}
|
|
|
|
|
|
// these are the new deltas in 'cs'
|
|
|
- const primitives = [...lvl1CsDelta.iterPrimitiveDeltas()];
|
|
|
+ const csDeltas = [...lvl1CsDelta.iterPrimitiveDeltas()];
|
|
|
const parentCorrDeltas = new Set(parentCorr.iterPrimitiveDeltas());
|
|
|
|
|
|
const asDeltas: Delta[] = [];
|
|
@@ -79,21 +81,21 @@ class TrivialParser implements Parser {
|
|
|
const csOverrides = new Map();
|
|
|
const asOverrides = new Map();
|
|
|
|
|
|
- for (const p of primitives) {
|
|
|
- if (p instanceof NodeCreation) {
|
|
|
+ for (const csDelta of csDeltas) {
|
|
|
+ if (csDelta instanceof NodeCreation) {
|
|
|
const corrCreation = new NodeCreation(this.getUuid());
|
|
|
- const corr2Cs = new EdgeCreation(corrCreation, "cs", p);
|
|
|
+ const corr2Cs = new EdgeCreation(corrCreation, "cs", csDelta);
|
|
|
const asCreation = new NodeCreation(this.getUuid());
|
|
|
const corr2As = new EdgeCreation(corrCreation, "as", asCreation);
|
|
|
|
|
|
asDeltas.push(asCreation);
|
|
|
corrDeltas.push(corrCreation, corr2Cs, corr2As);
|
|
|
}
|
|
|
- else if (p instanceof NodeDeletion) {
|
|
|
- const csCreation = p.creation; // the NodeCreation of the deleted cs node
|
|
|
+ else if (csDelta instanceof NodeDeletion) {
|
|
|
+ const csCreation = csDelta.creation; // the NodeCreation of the deleted cs node
|
|
|
|
|
|
- // p will conflict with our earlier 'corr2Cs' EdgeCreation delta:
|
|
|
- const corr2Cs = p.edgeTargetConflicts.find(e => parentCorrDeltas.has(e));
|
|
|
+ // csDelta will conflict with our earlier 'corr2Cs' EdgeCreation delta:
|
|
|
+ const corr2Cs = csDelta.edgeTargetConflicts.find(e => parentCorrDeltas.has(e));
|
|
|
if (corr2Cs === undefined) {
|
|
|
throw new Error("Assertion failed: When a node is deleted, the deletion must be conflicting with the creation of an incoming correspondence edge.");
|
|
|
}
|
|
@@ -118,7 +120,7 @@ class TrivialParser implements Parser {
|
|
|
// We already have the deletion in the CS model, so we only need to create another one to be used in the CORR model:
|
|
|
const csDeletion1 = new NodeDeletion(csCreation, [], [corrDeletion]);
|
|
|
|
|
|
- csOverrides.set(p, csDeletion1);
|
|
|
+ csOverrides.set(csDelta, csDeletion1);
|
|
|
asOverrides.set(asDeletion, asDeletion1);
|
|
|
|
|
|
asDeltas.push(asDeletion);
|
|
@@ -126,30 +128,26 @@ class TrivialParser implements Parser {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // L1-deltas for AS and CORR:
|
|
|
- const asComposite = this.asLvl.createComposite(asDeltas);
|
|
|
-
|
|
|
- const csDeltas1 = lvl1CsDelta.deltas.map(d => {
|
|
|
- const result = csOverrides.get(d) || d;
|
|
|
- // console.log("overridden or not:", result);
|
|
|
- return result;
|
|
|
- });
|
|
|
-
|
|
|
- const asDeltas1 = asDeltas.map(d => asOverrides.get(d) || d);
|
|
|
-
|
|
|
// New AS-version:
|
|
|
+ const asComposite = this.asLvl.createComposite(asDeltas);
|
|
|
const as = this.registry.createVersion(parentAs.embedded, asComposite);
|
|
|
|
|
|
- // L2-delta, where changes to CS, AS and CORR are a single transaction:
|
|
|
- const corrDelta = this.corrLvl.createComposite([...csDeltas1, ...asDeltas1, ...corrDeltas]);
|
|
|
-
|
|
|
// New CORR-version:
|
|
|
- return this.registry.createVersion(parentCorr, corrDelta, embed(["cs", cs, csOverrides], ["as", as, asOverrides]));
|
|
|
+ const csDeltas1 = csDeltas.map(d => csOverrides.get(d) || d);
|
|
|
+ const asDeltas1 = asDeltas.map(d => asOverrides.get(d) || d);
|
|
|
+ // the order in which corr-deltas are put in corrComposite matters - deltas must occur after their dependencies:
|
|
|
+ const orderedByDependency: Delta[] = [];
|
|
|
+ visitPartialOrdering(
|
|
|
+ [...csDeltas1, ...asDeltas1, ...corrDeltas],
|
|
|
+ (d: Delta) => d.getDependencies(),
|
|
|
+ (d: Delta) => orderedByDependency.push(d));
|
|
|
+ const corrComposite = this.corrLvl.createComposite(orderedByDependency);
|
|
|
+ return this.registry.createVersion(parentCorr, corrComposite, embed(["cs", cs, csOverrides], ["as", as, asOverrides]));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
describe("Parser", () => {
|
|
|
- it("Parse CS creation", () => {
|
|
|
+ it("Parse CS creation and deletion", () => {
|
|
|
const registry = new VersionRegistry();
|
|
|
const csLvl = new CompositeLevel();
|
|
|
const asLvl = new CompositeLevel();
|
|
@@ -167,9 +165,7 @@ describe("Parser", () => {
|
|
|
const csV1 = registry.createVersion(csInitial, csLvl.createComposite([csCreation]));
|
|
|
const csV2 = registry.createVersion(csV1, csLvl.createComposite([csDeletion]));
|
|
|
|
|
|
- console.log("parsing csV1...");
|
|
|
const corrV1 = parser.parse(csV1, corrInitial);
|
|
|
- console.log("parsing csV2...");
|
|
|
const corrV2 = parser.parse(csV2, corrV1);
|
|
|
|
|
|
const asV2 = corrV2.getEmbedded("as")?.embedded;
|
|
@@ -177,5 +173,7 @@ describe("Parser", () => {
|
|
|
throw new Error("Expected asV2 to exist!");
|
|
|
}
|
|
|
|
|
|
+ const asV2Primitives = [...asV2.iterPrimitiveDeltas()];
|
|
|
+ assert(asV2Primitives.length === 2, "Expected 2 primitive deltas on AS");
|
|
|
});
|
|
|
});
|