@sdd-method/author-cli 0.10.0 → 0.12.0
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/lib/behaviour-store/archive.js +13 -0
- package/dist/lib/catalogue/build.js +45 -2
- package/dist/lib/catalogue/builders/adr-governs.js +39 -0
- package/dist/lib/catalogue/builders/adrs.js +11 -0
- package/dist/lib/catalogue/builders/capability-spec.js +1 -0
- package/dist/lib/catalogue/builders/contract-revisions.js +126 -0
- package/dist/lib/catalogue/builders/data-model.js +316 -0
- package/dist/lib/catalogue/builders/entities-mermaid.js +18 -85
- package/dist/lib/catalogue/builders/feature-grounding.js +1 -0
- package/dist/lib/catalogue/builders/features.js +23 -2
- package/dist/lib/catalogue/builders/integration-components.js +49 -5
- package/dist/lib/catalogue/builders/journey-requirement.js +144 -0
- package/dist/lib/catalogue/builders/quality-scores.js +17 -0
- package/dist/lib/catalogue/builders/requirements.js +168 -32
- package/dist/lib/catalogue/canonical-schema.yaml +845 -28
- package/dist/lib/catalogue/manifest-loader.js +13 -0
- package/dist/lib/catalogue/retired-catalogues.js +25 -0
- package/dist/lib/catalogue/rubric-coverage-map.yaml +108 -2
- package/dist/lib/catalogue/schema-compat.js +1 -1
- package/dist/lib/catalogue/schema-loader.js +3 -0
- package/dist/lib/catalogue/staleness-verdicts.js +75 -6
- package/dist/lib/intents/migrate.js +35 -9
- package/dist/lib/metamodel/tql-subset-parser.js +35 -2
- package/dist/lib/structure/catalogue.js +183 -0
- package/dist/lib/structure/compose.js +174 -0
- package/dist/lib/structure/effects.js +36 -0
- package/dist/lib/structure/model.js +212 -0
- package/dist/lib/structure/render.js +242 -0
- package/dist/lib/structure/view.js +301 -0
- package/dist/lib/validate/agreement-evidence.js +216 -0
- package/dist/lib/validate/behaviour-store.js +516 -28
- package/dist/lib/validate/dispatch.js +21 -0
- package/dist/lib/validate/feature-spec-pointers.js +175 -0
- package/dist/lib/validate/journey-impact.js +193 -0
- package/dist/lib/validate/structural-model.js +265 -0
- package/dist/maintain-version.json +2 -2
- package/dist/verify-version.json +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// The catalogue from the structural model, and the model a built catalogue implies (M-ADR 0230 §4.3, §5.3,
|
|
2
|
+
// Proposed). Where an SDD has a model, it is the record of structure, so every structure catalogue is built from it whole:
|
|
3
|
+
// a row per element of the current view, with the model's structure columns;
|
|
4
|
+
// its other columns (every class but structure: derived, declaration, evidence, intent, execution) from the
|
|
5
|
+
// source-built row with the same id;
|
|
6
|
+
// for an element only the model holds, the derived columns the model itself settles (MODEL_DERIVED).
|
|
7
|
+
// What the sources hold and the model does not, and a structure column where they disagree, is reported once per
|
|
8
|
+
// catalogue. The model wins: either finding means the sources moved outside a change. Pure: no file is read or written.
|
|
9
|
+
import { stringify } from "yaml";
|
|
10
|
+
import { FORMAT_VERSION } from "./model.js";
|
|
11
|
+
import { STRUCTURE } from "./view.js";
|
|
12
|
+
/** The view each generated file renders, for a derived path column of an element only the model holds. */
|
|
13
|
+
export const VIEW_PATHS = {
|
|
14
|
+
c4Context: "docs/structure/c4-context.md",
|
|
15
|
+
c4Containers: "docs/structure/c4-containers.md",
|
|
16
|
+
services: "docs/structure/services.md",
|
|
17
|
+
featureTree: "docs/structure/feature-tree.md",
|
|
18
|
+
dataModel: "docs/structure/data-model.md",
|
|
19
|
+
};
|
|
20
|
+
const EXAMPLES = 5;
|
|
21
|
+
const cell = (v) => (v === null || v === undefined ? "" : typeof v === "boolean" ? (v ? "true" : "false") : String(v));
|
|
22
|
+
/** The derived columns of a row built from an element the sources do not hold. */
|
|
23
|
+
function modelDerived(catalogue, e, view) {
|
|
24
|
+
switch (catalogue) {
|
|
25
|
+
case "features":
|
|
26
|
+
case "capabilities":
|
|
27
|
+
return { source: "structural-model" };
|
|
28
|
+
case "domain_models":
|
|
29
|
+
return { doc_path: VIEW_PATHS.dataModel };
|
|
30
|
+
case "c4_systems":
|
|
31
|
+
return { diagram_path: VIEW_PATHS.c4Context };
|
|
32
|
+
case "domains":
|
|
33
|
+
return { repo_count: [...(view.get("repositories")?.values() ?? [])].filter((r) => r.columns["domain_id"] === e.id).length };
|
|
34
|
+
default:
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function structureColumns(cat) {
|
|
39
|
+
return cat.columns.filter((c) => c.name !== cat.primaryKey && c.sourceOfTruth === STRUCTURE).map((c) => c.name);
|
|
40
|
+
}
|
|
41
|
+
function sample(ids) {
|
|
42
|
+
return ids.slice(0, EXAMPLES).join(", ") + (ids.length > EXAMPLES ? `, and ${ids.length - EXAMPLES} more` : "");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Replace every structure catalogue's rows with the view's. Rows of other catalogues are returned as they are. Source
|
|
46
|
+
* rows sharing an id are merged first, later values filling earlier gaps, as the keyed-table dedupe would.
|
|
47
|
+
*/
|
|
48
|
+
export function overlayModel(schema, view, rows, findings) {
|
|
49
|
+
const out = new Map(rows);
|
|
50
|
+
for (const cat of schema.catalogues) {
|
|
51
|
+
if (cat.sourceOfTruth !== STRUCTURE)
|
|
52
|
+
continue;
|
|
53
|
+
const pk = cat.primaryKey;
|
|
54
|
+
const structural = structureColumns(cat);
|
|
55
|
+
const source = new Map();
|
|
56
|
+
for (const r of rows.get(cat.name) ?? []) {
|
|
57
|
+
const id = cell(r[pk]);
|
|
58
|
+
const prior = source.get(id);
|
|
59
|
+
if (!prior)
|
|
60
|
+
source.set(id, { ...r });
|
|
61
|
+
else
|
|
62
|
+
for (const [k, v] of Object.entries(r))
|
|
63
|
+
if (cell(prior[k]) === "" && cell(v) !== "")
|
|
64
|
+
prior[k] = v;
|
|
65
|
+
}
|
|
66
|
+
const elements = view.get(cat.name) ?? new Map();
|
|
67
|
+
const built = [];
|
|
68
|
+
const differ = [];
|
|
69
|
+
for (const e of elements.values()) {
|
|
70
|
+
const from = source.get(e.id);
|
|
71
|
+
const row = {};
|
|
72
|
+
if (from) {
|
|
73
|
+
for (const [k, v] of Object.entries(from))
|
|
74
|
+
if (!structural.includes(k))
|
|
75
|
+
row[k] = v;
|
|
76
|
+
const cols = structural.filter((c) => cell(from[c]) !== "" && cell(from[c]) !== cell(e.columns[c]));
|
|
77
|
+
if (cols.length > 0)
|
|
78
|
+
differ.push(`${e.id} (${cols.join(", ")})`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
Object.assign(row, modelDerived(cat.name, e, view));
|
|
82
|
+
}
|
|
83
|
+
row[pk] = e.id;
|
|
84
|
+
for (const c of structural)
|
|
85
|
+
row[c] = e.columns[c];
|
|
86
|
+
built.push(row);
|
|
87
|
+
}
|
|
88
|
+
const missing = [...source.keys()].filter((id) => id !== "" && !elements.has(id)).sort();
|
|
89
|
+
if (missing.length > 0) {
|
|
90
|
+
findings.add("divergence", `${cat.name}: the sources hold ${missing.length} row(s) the structural model does not (${sample(missing)}); the model is the record of structure, so they are not catalogued. Add them through a change's structural deltas, or remove them from the sources (M-ADR 0230 §4.3, Proposed)`, "warn", `catalogue:${cat.name}`);
|
|
91
|
+
}
|
|
92
|
+
if (differ.length > 0) {
|
|
93
|
+
findings.add("divergence", `${cat.name}: ${differ.length} element(s) where the sources and the structural model disagree, catalogued as the model states them: ${sample(differ.sort())}. A source that is a generated view is rendered again; any other is brought into line through a change (M-ADR 0230 §4.3, Proposed)`, "warn", `catalogue:${cat.name}`);
|
|
94
|
+
}
|
|
95
|
+
out.set(cat.name, built);
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function typed(type, v) {
|
|
100
|
+
switch (type) {
|
|
101
|
+
case "int":
|
|
102
|
+
case "integer":
|
|
103
|
+
case "number": {
|
|
104
|
+
const n = Number(v);
|
|
105
|
+
return Number.isFinite(n) ? n : null;
|
|
106
|
+
}
|
|
107
|
+
case "boolean":
|
|
108
|
+
return v === "true" ? true : v === "false" ? false : null;
|
|
109
|
+
default:
|
|
110
|
+
return v;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The model a built catalogue implies: each structure row as an element of its non-empty structure columns, typed by
|
|
115
|
+
* column. A platform's element goes to its domain's partition (its own `domain_id`, or the first element it references
|
|
116
|
+
* that has one; a domain is its own), else to `platform`; an application or integration SDD's to its sdd_id. A cell
|
|
117
|
+
* that does not parse as its column's type is reported and left out, which is the projection's only loss.
|
|
118
|
+
*/
|
|
119
|
+
export function modelFromRows(schema, rows, partitioning, loss) {
|
|
120
|
+
const byKey = new Map();
|
|
121
|
+
for (const cat of schema.catalogues) {
|
|
122
|
+
if (cat.sourceOfTruth !== STRUCTURE)
|
|
123
|
+
continue;
|
|
124
|
+
for (const r of rows.get(cat.name) ?? [])
|
|
125
|
+
byKey.set(`${cat.name}/${cell(r[cat.primaryKey])}`, r);
|
|
126
|
+
}
|
|
127
|
+
const memo = new Map();
|
|
128
|
+
const domainOf = (catName, row, seen) => {
|
|
129
|
+
const cat = schema.catalogues.find((c) => c.name === catName);
|
|
130
|
+
const key = `${catName}/${cell(row[cat.primaryKey])}`;
|
|
131
|
+
if (memo.has(key))
|
|
132
|
+
return memo.get(key);
|
|
133
|
+
if (seen.has(key))
|
|
134
|
+
return null;
|
|
135
|
+
seen.add(key);
|
|
136
|
+
let d = catName === "domains" ? cell(row[cat.primaryKey]) : cell(row["domain_id"]) || null;
|
|
137
|
+
for (const fk of d === null ? cat.foreignKeys : []) {
|
|
138
|
+
const [target, column] = fk.references.split(".");
|
|
139
|
+
if (fk.external || column !== "id" || cell(row[fk.column]) === "")
|
|
140
|
+
continue;
|
|
141
|
+
const next = byKey.get(`${target}/${cell(row[fk.column])}`);
|
|
142
|
+
if (next && (d = domainOf(target, next, seen)) !== null)
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
memo.set(key, d);
|
|
146
|
+
return d;
|
|
147
|
+
};
|
|
148
|
+
const out = new Map();
|
|
149
|
+
for (const cat of schema.catalogues) {
|
|
150
|
+
if (cat.sourceOfTruth !== STRUCTURE)
|
|
151
|
+
continue;
|
|
152
|
+
const cols = cat.columns.filter((c) => c.name !== cat.primaryKey && c.sourceOfTruth === STRUCTURE);
|
|
153
|
+
const sorted = [...(rows.get(cat.name) ?? [])].sort((a, b) => cell(a[cat.primaryKey]).localeCompare(cell(b[cat.primaryKey])));
|
|
154
|
+
const seen = new Set();
|
|
155
|
+
for (const r of sorted) {
|
|
156
|
+
const id = cell(r[cat.primaryKey]);
|
|
157
|
+
if (id === "" || seen.has(id))
|
|
158
|
+
continue;
|
|
159
|
+
seen.add(id);
|
|
160
|
+
const element = { id };
|
|
161
|
+
for (const c of cols) {
|
|
162
|
+
const v = cell(r[c.name]);
|
|
163
|
+
if (v === "")
|
|
164
|
+
continue;
|
|
165
|
+
const t = typed(c.type, v);
|
|
166
|
+
if (t === null)
|
|
167
|
+
loss.push(`${cat.name}/${id}.${c.name}: ${JSON.stringify(v)} is not of type ${c.type}`);
|
|
168
|
+
else
|
|
169
|
+
element[c.name] = t;
|
|
170
|
+
}
|
|
171
|
+
const partition = partitioning.platform ? (domainOf(cat.name, r, new Set()) ?? "platform") : partitioning.sddId;
|
|
172
|
+
const file = out.get(partition) ?? {};
|
|
173
|
+
(file[cat.name] ??= []).push(element);
|
|
174
|
+
out.set(partition, file);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
/** One partition's model file, in the format loadModel reads. */
|
|
180
|
+
export function modelFileText(partition, elements) {
|
|
181
|
+
return stringify({ schema_version: FORMAT_VERSION, partition, elements });
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=catalogue.js.map
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Views over the structural model, and how changes compose (M-ADR 0230 §4.5, §4.7, Proposed).
|
|
2
|
+
// current the model as published
|
|
3
|
+
// at a change current with that change's deltas and those of its dependency closure, dependencies first
|
|
4
|
+
// intended current with every agreed change's deltas
|
|
5
|
+
// Distinct ids do not prove independence, so three checks run:
|
|
6
|
+
// 1 write overlap two agreed changes never MODIFY or REMOVE one element, and never ADD one id; a change
|
|
7
|
+
// not yet agreed that overlaps an agreed one cannot be agreed while that one is open
|
|
8
|
+
// 2 composed validation each view is validated on its own; what fails in a view and not in current is reported
|
|
9
|
+
// against the changes that write the elements it names
|
|
10
|
+
// 3 read dependencies base revisions still current (validateDeltas); a dependency withdrawn invalidates its
|
|
11
|
+
// dependants; an agreed change depending on one not yet agreed; a cycle of dependencies
|
|
12
|
+
// Pure: reads nothing; the structural-model validator uses it.
|
|
13
|
+
import { elementKey } from "./model.js";
|
|
14
|
+
/** Element key -> the write a change makes to it. */
|
|
15
|
+
export function writesOf(s) {
|
|
16
|
+
const out = new Map();
|
|
17
|
+
for (const d of s.deltas) {
|
|
18
|
+
for (const e of d.added)
|
|
19
|
+
out.set(elementKey(e.catalogue, e.id), "ADDED");
|
|
20
|
+
for (const e of d.modified)
|
|
21
|
+
out.set(elementKey(e.catalogue, e.id), "MODIFIED");
|
|
22
|
+
for (const r of d.removed)
|
|
23
|
+
out.set(elementKey(r.catalogue, r.id), "REMOVED");
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function copy(view) {
|
|
28
|
+
const out = new Map();
|
|
29
|
+
for (const [c, m] of view)
|
|
30
|
+
out.set(c, new Map(m));
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/** The view with one change's deltas applied: an addition or modification replaces whole, a removal deletes. */
|
|
34
|
+
export function apply(view, s) {
|
|
35
|
+
const out = copy(view);
|
|
36
|
+
const put = (e) => {
|
|
37
|
+
const m = out.get(e.catalogue) ?? new Map();
|
|
38
|
+
m.set(e.id, e);
|
|
39
|
+
out.set(e.catalogue, m);
|
|
40
|
+
};
|
|
41
|
+
for (const d of s.deltas) {
|
|
42
|
+
for (const e of d.added)
|
|
43
|
+
put(e);
|
|
44
|
+
for (const e of d.modified)
|
|
45
|
+
put(e);
|
|
46
|
+
for (const r of d.removed)
|
|
47
|
+
out.get(r.catalogue)?.delete(r.id);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A change's dependency closure, dependencies first and the change last. A dependency that is not open is skipped
|
|
53
|
+
* here (archived: its additions are current; otherwise reported as withdrawn by checkDependencies). A cycle stops the
|
|
54
|
+
* walk and is reported there too.
|
|
55
|
+
*/
|
|
56
|
+
export function closure(change, open) {
|
|
57
|
+
const order = [];
|
|
58
|
+
const visiting = new Set();
|
|
59
|
+
const visit = (c) => {
|
|
60
|
+
if (order.includes(c) || visiting.has(c))
|
|
61
|
+
return;
|
|
62
|
+
const oc = open.get(c);
|
|
63
|
+
if (!oc)
|
|
64
|
+
return;
|
|
65
|
+
visiting.add(c);
|
|
66
|
+
for (const d of oc.structure.deltas)
|
|
67
|
+
for (const dep of d.dependsOn)
|
|
68
|
+
visit(dep);
|
|
69
|
+
visiting.delete(c);
|
|
70
|
+
order.push(c);
|
|
71
|
+
};
|
|
72
|
+
visit(change);
|
|
73
|
+
return order;
|
|
74
|
+
}
|
|
75
|
+
export function viewAt(current, change, open) {
|
|
76
|
+
let v = current;
|
|
77
|
+
for (const c of closure(change, open))
|
|
78
|
+
v = apply(v, open.get(c).structure);
|
|
79
|
+
return v;
|
|
80
|
+
}
|
|
81
|
+
/** Agreed changes in an order that applies each after its dependencies. */
|
|
82
|
+
export function agreedOrder(open) {
|
|
83
|
+
const order = [];
|
|
84
|
+
for (const [name, oc] of [...open].sort(([a], [b]) => a.localeCompare(b))) {
|
|
85
|
+
if (oc.status !== "agreed")
|
|
86
|
+
continue;
|
|
87
|
+
for (const c of closure(name, open))
|
|
88
|
+
if (!order.includes(c) && open.get(c).status === "agreed")
|
|
89
|
+
order.push(c);
|
|
90
|
+
}
|
|
91
|
+
return order;
|
|
92
|
+
}
|
|
93
|
+
export function intended(current, open) {
|
|
94
|
+
let v = current;
|
|
95
|
+
for (const c of agreedOrder(open))
|
|
96
|
+
v = apply(v, open.get(c).structure);
|
|
97
|
+
return v;
|
|
98
|
+
}
|
|
99
|
+
/** Check 1: write overlap. */
|
|
100
|
+
export function checkOverlap(open, problems) {
|
|
101
|
+
const names = [...open.keys()].sort();
|
|
102
|
+
const writes = new Map(names.map((n) => [n, writesOf(open.get(n).structure)]));
|
|
103
|
+
for (let i = 0; i < names.length; i++) {
|
|
104
|
+
for (let j = i + 1; j < names.length; j++) {
|
|
105
|
+
const a = names[i];
|
|
106
|
+
const b = names[j];
|
|
107
|
+
const sa = open.get(a).status;
|
|
108
|
+
const sb = open.get(b).status;
|
|
109
|
+
if (sa !== "agreed" && sb !== "agreed")
|
|
110
|
+
continue;
|
|
111
|
+
for (const [key, wa] of writes.get(a)) {
|
|
112
|
+
const wb = writes.get(b).get(key);
|
|
113
|
+
if (wb === undefined)
|
|
114
|
+
continue;
|
|
115
|
+
// One adding what the other modifies or removes is reported by the other's own deltas, whose base cannot exist.
|
|
116
|
+
// Two additions of one id are one id claimed twice, whatever their content.
|
|
117
|
+
if ((wa === "ADDED") !== (wb === "ADDED"))
|
|
118
|
+
continue;
|
|
119
|
+
const verb = wa === "ADDED" ? "both ADD" : wa === wb ? `both ${wa}` : `${wa} and ${wb}`;
|
|
120
|
+
if (sa === "agreed" && sb === "agreed")
|
|
121
|
+
problems.push(`write overlap: agreed changes ${a} and ${b} ${verb} ${key}; reorder or merge them`);
|
|
122
|
+
else {
|
|
123
|
+
const [held, waiting] = sa === "agreed" ? [a, b] : [b, a];
|
|
124
|
+
problems.push(`write overlap: ${waiting} ${verb === "both ADD" ? "adds" : "writes"} ${key}, which agreed change ${held} also ${verb === "both ADD" ? "adds" : "writes"}; it cannot be agreed while ${held} is open`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Check 3, beyond base revisions: withdrawn dependencies, agreement before a dependency, cycles. */
|
|
131
|
+
export function checkDependencies(open, archived, problems) {
|
|
132
|
+
for (const [name, oc] of [...open].sort(([a], [b]) => a.localeCompare(b))) {
|
|
133
|
+
const deps = new Set(oc.structure.deltas.flatMap((d) => [...d.dependsOn]));
|
|
134
|
+
for (const dep of deps) {
|
|
135
|
+
const target = open.get(dep);
|
|
136
|
+
if (target === undefined) {
|
|
137
|
+
if (!archived.has(dep))
|
|
138
|
+
problems.push(`read dependency: ${name} depends on ${dep}, which is neither open nor archived: withdrawn, so ${name} is invalidated until it no longer needs it`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (target.status === "withdrawn" || target.status === "superseded") {
|
|
142
|
+
problems.push(`read dependency: ${name} depends on ${dep}, whose agreement record is ${target.status}: ${name} is invalidated until it no longer needs it`);
|
|
143
|
+
}
|
|
144
|
+
else if (oc.status === "agreed" && target.status !== "agreed") {
|
|
145
|
+
problems.push(`read dependency: ${name} is agreed and depends on ${dep}, which is not: a change is agreed with its dependency closure`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// A cycle through this change.
|
|
149
|
+
const seen = new Set();
|
|
150
|
+
const stack = [...deps];
|
|
151
|
+
while (stack.length > 0) {
|
|
152
|
+
const c = stack.pop();
|
|
153
|
+
if (c === name) {
|
|
154
|
+
problems.push(`read dependency: ${name} depends on itself through depends_on; a cycle can never archive`);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (seen.has(c))
|
|
158
|
+
continue;
|
|
159
|
+
seen.add(c);
|
|
160
|
+
for (const d of open.get(c)?.structure.deltas ?? [])
|
|
161
|
+
stack.push(...d.dependsOn);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const KEY_RE = /\b([a-z][a-z0-9_]*)\/([^\s,;:()"]+)/g;
|
|
166
|
+
/** The changes that write any element a finding names. */
|
|
167
|
+
export function attribute(problem, open, among) {
|
|
168
|
+
const keys = new Set([...problem.matchAll(KEY_RE)].map((m) => `${m[1]}/${m[2]}`));
|
|
169
|
+
return among.filter((c) => {
|
|
170
|
+
const w = writesOf(open.get(c).structure);
|
|
171
|
+
return [...keys].some((k) => w.has(k));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A change's structural effect, and the effect record an archive leaves (M-ADR 0230 §4.6, §4.7, Proposed). Pure reads,
|
|
2
|
+
// so the catalogue builder and the verify-only CLI can carry them; writing the record is apply.ts's.
|
|
3
|
+
import { parseDocument } from "yaml";
|
|
4
|
+
import { elementKey, revision } from "./model.js";
|
|
5
|
+
export function effectsOf(s, current) {
|
|
6
|
+
const out = [];
|
|
7
|
+
const rev = (catalogue, id) => {
|
|
8
|
+
const e = current.get(catalogue)?.get(id);
|
|
9
|
+
return e ? revision(e.catalogue, e.id, e.columns) : undefined;
|
|
10
|
+
};
|
|
11
|
+
for (const d of s.deltas) {
|
|
12
|
+
for (const e of d.added)
|
|
13
|
+
out.push({ element: elementKey(e.catalogue, e.id), operation: "ADDED", target: revision(e.catalogue, e.id, e.columns) });
|
|
14
|
+
for (const e of d.modified) {
|
|
15
|
+
const base = rev(e.catalogue, e.id);
|
|
16
|
+
out.push({ element: elementKey(e.catalogue, e.id), operation: "MODIFIED", ...(base ? { base } : {}), target: revision(e.catalogue, e.id, e.columns) });
|
|
17
|
+
}
|
|
18
|
+
for (const r of d.removed) {
|
|
19
|
+
const base = rev(r.catalogue, r.id);
|
|
20
|
+
out.push({ element: elementKey(r.catalogue, r.id), operation: "REMOVED", ...(base ? { base } : {}) });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out.sort((a, b) => a.element.localeCompare(b.element));
|
|
24
|
+
}
|
|
25
|
+
export function parseAppliedRecord(text) {
|
|
26
|
+
try {
|
|
27
|
+
const v = parseDocument(text).toJS();
|
|
28
|
+
if (!v || typeof v.change !== "string" || !Array.isArray(v.effects))
|
|
29
|
+
return null;
|
|
30
|
+
return { change: v.change, baseCommit: String(v.base_commit ?? ""), effects: v.effects };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=effects.js.map
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// The structural model and a change's structural deltas (M-ADR 0230 §4.3, §4.4, Proposed). Pure reads, so the
|
|
2
|
+
// verify-only CLI can carry them. The format is docs/method/methods/guides/structural-model-format.md:
|
|
3
|
+
// openspec/structure/<partition>.yaml the model, one file per partition
|
|
4
|
+
// openspec/changes/<change>/structure/<partition>.yaml a change's delta for that partition
|
|
5
|
+
// openspec/changes/<change>/structure/none.yaml a change's typed claim of no structural effect
|
|
6
|
+
// An element is a catalogue row of a `structure` catalogue, keyed by its immutable id. Its revision is the
|
|
7
|
+
// SHA-256 of its canonical JSON, so two readers agree on it without agreeing on anything else.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { parseDocument } from "yaml";
|
|
12
|
+
export const STRUCTURE_DIR = join("openspec", "structure");
|
|
13
|
+
export const NO_OP_FILE = "none.yaml";
|
|
14
|
+
/** An archived change's record of its structural effect, beside its deltas (M-ADR 0230 §4.6). */
|
|
15
|
+
export const APPLIED_FILE = "applied.yaml";
|
|
16
|
+
/** Partition names a file name would confuse with the no-op claim or the effect record. */
|
|
17
|
+
export const RESERVED_PARTITIONS = new Set(["none", "applied"]);
|
|
18
|
+
export const FORMAT_VERSION = "1.0.0";
|
|
19
|
+
/** `sha256:<hex>` of the element's canonical JSON: {catalogue, columns (sorted), id}, no whitespace, UTF-8. */
|
|
20
|
+
export function revision(catalogue, id, columns) {
|
|
21
|
+
const sorted = {};
|
|
22
|
+
for (const k of Object.keys(columns).sort())
|
|
23
|
+
sorted[k] = columns[k];
|
|
24
|
+
const canonical = JSON.stringify({ catalogue, columns: sorted, id });
|
|
25
|
+
return `sha256:${createHash("sha256").update(canonical, "utf8").digest("hex")}`;
|
|
26
|
+
}
|
|
27
|
+
export function elementKey(catalogue, id) {
|
|
28
|
+
return `${catalogue}/${id}`;
|
|
29
|
+
}
|
|
30
|
+
async function readText(p) {
|
|
31
|
+
try {
|
|
32
|
+
return await readFile(p, "utf8");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function yamlFiles(dir) {
|
|
39
|
+
try {
|
|
40
|
+
return (await readdir(dir, { withFileTypes: true }))
|
|
41
|
+
.filter((e) => e.isFile() && e.name.endsWith(".yaml"))
|
|
42
|
+
.map((e) => e.name)
|
|
43
|
+
.sort();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function parseYamlMap(text, where, problems) {
|
|
50
|
+
const doc = parseDocument(text);
|
|
51
|
+
if (doc.errors.length > 0) {
|
|
52
|
+
problems.push(`${where}: not valid YAML (${doc.errors[0].message.split("\n")[0]})`);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const v = doc.toJS();
|
|
56
|
+
if (v === null || typeof v !== "object" || Array.isArray(v)) {
|
|
57
|
+
problems.push(`${where}: not a YAML mapping`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
function checkVersion(m, where, problems) {
|
|
63
|
+
if (m["schema_version"] === undefined) {
|
|
64
|
+
problems.push(`${where}: no schema_version`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (String(m["schema_version"]) !== FORMAT_VERSION) {
|
|
68
|
+
problems.push(`${where}: schema_version ${JSON.stringify(String(m["schema_version"]))} is not ${FORMAT_VERSION}, the format this CLI reads`);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
/** Elements under a `<catalogue>: [ {id, ...} ]` map. */
|
|
74
|
+
function readElements(block, where, partition, file, problems) {
|
|
75
|
+
const out = [];
|
|
76
|
+
if (block === undefined || block === null)
|
|
77
|
+
return out;
|
|
78
|
+
if (typeof block !== "object" || Array.isArray(block)) {
|
|
79
|
+
problems.push(`${where}: must map catalogue names to lists of elements`);
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
for (const [catalogue, list] of Object.entries(block)) {
|
|
83
|
+
if (!Array.isArray(list)) {
|
|
84
|
+
problems.push(`${where}.${catalogue}: must be a list of elements`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
list.forEach((raw, i) => {
|
|
88
|
+
const at = `${where}.${catalogue}[${i}]`;
|
|
89
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
90
|
+
problems.push(`${at}: an element must be a mapping`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const r = raw;
|
|
94
|
+
const id = r["id"];
|
|
95
|
+
if (typeof id !== "string" || id === "") {
|
|
96
|
+
problems.push(`${at}: no id`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const columns = {};
|
|
100
|
+
for (const [k, v] of Object.entries(r)) {
|
|
101
|
+
if (k === "id")
|
|
102
|
+
continue;
|
|
103
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
104
|
+
columns[k] = v;
|
|
105
|
+
else
|
|
106
|
+
problems.push(`${at} (${id}).${k}: a value must be a string, number or boolean`);
|
|
107
|
+
}
|
|
108
|
+
out.push({ catalogue, id, columns, partition, file });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
/** The model, or null when the SDD has no openspec/structure/ directory. */
|
|
114
|
+
export async function loadModel(repo, problems) {
|
|
115
|
+
const names = await yamlFiles(join(repo, STRUCTURE_DIR));
|
|
116
|
+
if (names === null)
|
|
117
|
+
return null;
|
|
118
|
+
const files = [];
|
|
119
|
+
for (const name of names) {
|
|
120
|
+
const file = join(STRUCTURE_DIR, name);
|
|
121
|
+
const m = parseYamlMap((await readText(join(repo, file))) ?? "", file, problems);
|
|
122
|
+
if (m === null || !checkVersion(m, file, problems))
|
|
123
|
+
continue;
|
|
124
|
+
const partition = name.slice(0, -".yaml".length);
|
|
125
|
+
if (RESERVED_PARTITIONS.has(partition)) {
|
|
126
|
+
problems.push(`${file}: ${partition} is a reserved name, not a partition`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (m["partition"] !== partition) {
|
|
130
|
+
problems.push(`${file}: partition ${JSON.stringify(m["partition"] ?? null)} does not match the file name (${partition})`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
for (const k of Object.keys(m))
|
|
134
|
+
if (!["schema_version", "partition", "elements"].includes(k))
|
|
135
|
+
problems.push(`${file}: unknown key ${k}`);
|
|
136
|
+
files.push({ partition, file, elements: readElements(m["elements"], `${file}: elements`, partition, file, problems) });
|
|
137
|
+
}
|
|
138
|
+
return files;
|
|
139
|
+
}
|
|
140
|
+
/** A change's structural artifact. */
|
|
141
|
+
export async function loadChangeStructure(repo, change, problems) {
|
|
142
|
+
const dir = join("openspec", "changes", change, "structure");
|
|
143
|
+
const names = await yamlFiles(join(repo, dir));
|
|
144
|
+
if (names === null)
|
|
145
|
+
return { change, deltas: [], noOp: null, present: false };
|
|
146
|
+
const deltas = [];
|
|
147
|
+
let noOp = null;
|
|
148
|
+
for (const name of names) {
|
|
149
|
+
if (name === APPLIED_FILE)
|
|
150
|
+
continue;
|
|
151
|
+
const file = join(dir, name);
|
|
152
|
+
const m = parseYamlMap((await readText(join(repo, file))) ?? "", file, problems);
|
|
153
|
+
if (m === null || !checkVersion(m, file, problems))
|
|
154
|
+
continue;
|
|
155
|
+
if (name === NO_OP_FILE) {
|
|
156
|
+
const reason = typeof m["reason"] === "string" ? m["reason"].trim() : "";
|
|
157
|
+
if (m["no_structural_effect"] !== true)
|
|
158
|
+
problems.push(`${file}: a no-op claim states no_structural_effect: true`);
|
|
159
|
+
else if (reason === "")
|
|
160
|
+
problems.push(`${file}: a no-op claim states its reason`);
|
|
161
|
+
else
|
|
162
|
+
noOp = { file, reason };
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const partition = name.slice(0, -".yaml".length);
|
|
166
|
+
if (m["partition"] !== partition) {
|
|
167
|
+
problems.push(`${file}: partition ${JSON.stringify(m["partition"] ?? null)} does not match the file name (${partition})`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const dependsOn = m["depends_on"] ?? [];
|
|
171
|
+
if (!Array.isArray(dependsOn) || dependsOn.some((d) => typeof d !== "string"))
|
|
172
|
+
problems.push(`${file}: depends_on must be a list of change names`);
|
|
173
|
+
const base = new Map();
|
|
174
|
+
const rawBase = m["base"] ?? {};
|
|
175
|
+
if (typeof rawBase !== "object" || rawBase === null || Array.isArray(rawBase))
|
|
176
|
+
problems.push(`${file}: base must map <catalogue>/<id> to a revision`);
|
|
177
|
+
else {
|
|
178
|
+
for (const [k, v] of Object.entries(rawBase)) {
|
|
179
|
+
if (typeof v !== "string" || !/^sha256:[0-9a-f]{64}$/.test(v))
|
|
180
|
+
problems.push(`${file}: base ${k} is not a revision (sha256:<64 hex digits>)`);
|
|
181
|
+
else
|
|
182
|
+
base.set(k, v);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const removed = [];
|
|
186
|
+
for (const r of readElements(m["REMOVED"], `${file}: REMOVED`, partition, file, problems)) {
|
|
187
|
+
const reason = r.columns["reason"];
|
|
188
|
+
if (typeof reason !== "string" || reason.trim() === "")
|
|
189
|
+
problems.push(`${file}: REMOVED ${elementKey(r.catalogue, r.id)} gives no reason`);
|
|
190
|
+
const extra = Object.keys(r.columns).filter((k) => k !== "reason");
|
|
191
|
+
if (extra.length > 0)
|
|
192
|
+
problems.push(`${file}: REMOVED ${elementKey(r.catalogue, r.id)} states ${extra.join(", ")}; a removal gives its id and a reason only`);
|
|
193
|
+
removed.push({ catalogue: r.catalogue, id: r.id, reason: typeof reason === "string" ? reason : "" });
|
|
194
|
+
}
|
|
195
|
+
for (const k of Object.keys(m)) {
|
|
196
|
+
if (!["schema_version", "partition", "depends_on", "ADDED", "MODIFIED", "REMOVED", "base"].includes(k))
|
|
197
|
+
problems.push(`${file}: unknown key ${k}`);
|
|
198
|
+
}
|
|
199
|
+
deltas.push({
|
|
200
|
+
change,
|
|
201
|
+
partition,
|
|
202
|
+
file,
|
|
203
|
+
dependsOn: Array.isArray(dependsOn) ? dependsOn.map(String) : [],
|
|
204
|
+
added: readElements(m["ADDED"], `${file}: ADDED`, partition, file, problems),
|
|
205
|
+
modified: readElements(m["MODIFIED"], `${file}: MODIFIED`, partition, file, problems),
|
|
206
|
+
removed,
|
|
207
|
+
base,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return { change, deltas, noOp, present: true };
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=model.js.map
|