@sdd-method/maintain-cli 0.11.0 → 0.13.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/aggregate.js +64 -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/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
|
@@ -218,6 +218,16 @@ const ManifestSchema = z.object({
|
|
|
218
218
|
// Shared-library trait (sdd-manifest-schema 1.12.0, M-ADR 0217 §4.4). Profile-agnostic,
|
|
219
219
|
// like `exemplar`; absent is the unmarked norm, no finding.
|
|
220
220
|
shared_library: z.boolean().optional(),
|
|
221
|
+
// Where this estate's journey behaviour is mastered (sdd-manifest-schema 1.13.0, M-ADR 0229 §4.2, Proposed).
|
|
222
|
+
// `master` is declared at the root, and journey-impact treats a member naming its platform as inheriting it.
|
|
223
|
+
// `test_paths` is never inherited: it is relative to this SDD, so an SDD that holds end-to-end files declares
|
|
224
|
+
// its own block, with the master and its paths. Unknown values fail at load.
|
|
225
|
+
journeys: z
|
|
226
|
+
.object({
|
|
227
|
+
master: z.enum(["test-file", "store"]),
|
|
228
|
+
test_paths: z.array(z.string()).optional(),
|
|
229
|
+
})
|
|
230
|
+
.optional(),
|
|
221
231
|
// Application-product archetype trait (M-ADR 0191, sdd-manifest-schema
|
|
222
232
|
// 1.2.0). RESOLVED enum, not fixed: the loader validates only the slug
|
|
223
233
|
// shape here. Whether the value resolves against the active vocabulary
|
|
@@ -378,6 +388,9 @@ export async function loadSddManifest(sddPath, options) {
|
|
|
378
388
|
...(parsed.data.packaging !== undefined ? { packaging: parsed.data.packaging } : {}),
|
|
379
389
|
...(parsed.data.exemplar !== undefined ? { exemplar: parsed.data.exemplar } : {}),
|
|
380
390
|
...(parsed.data.shared_library !== undefined ? { sharedLibrary: parsed.data.shared_library } : {}),
|
|
391
|
+
...(parsed.data.journeys !== undefined
|
|
392
|
+
? { journeys: { master: parsed.data.journeys.master, testPaths: parsed.data.journeys.test_paths ?? [] } }
|
|
393
|
+
: {}),
|
|
381
394
|
...(parsed.data.application_archetype !== undefined
|
|
382
395
|
? { applicationArchetype: parsed.data.application_archetype }
|
|
383
396
|
: {}),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Catalogues a schema major has retired. A build writes the catalogues the schema declares, so the file of one
|
|
2
|
+
// it no longer declares would otherwise stay on disk beside its replacement, and `catalogue build --check`
|
|
3
|
+
// would report it committed and no longer produced in every estate after the wave. The build and the aggregate
|
|
4
|
+
// remove it from the directory they write, and say so. Only a catalogue named here is removed: a CSV the method
|
|
5
|
+
// never declared is left alone.
|
|
6
|
+
import { rm, stat } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
/** name -> why it went, and what replaced it. */
|
|
9
|
+
export const RETIRED_CATALOGUES = new Map([
|
|
10
|
+
["requirement_status", "retired in catalogue schema 6.0.0: evidence about one revision of a requirement is requirement_assertions (M-ADR 0230 §4.7, Proposed)"],
|
|
11
|
+
]);
|
|
12
|
+
/** Remove each retired catalogue's file from `dir`. Returns the file names removed. */
|
|
13
|
+
export async function removeRetiredCatalogues(dir, findings, label) {
|
|
14
|
+
const removed = [];
|
|
15
|
+
for (const [name, why] of RETIRED_CATALOGUES) {
|
|
16
|
+
const file = join(dir, `${name}.csv`);
|
|
17
|
+
if (!(await stat(file).then((s) => s.isFile(), () => false)))
|
|
18
|
+
continue;
|
|
19
|
+
await rm(file);
|
|
20
|
+
removed.push(`${name}.csv`);
|
|
21
|
+
findings.add("convention", `${label}/${name}.csv: removed, ${why}; commit its removal with the rebuilt catalogues`, "warn", `${label}/${name}.csv`);
|
|
22
|
+
}
|
|
23
|
+
return removed;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=retired-catalogues.js.map
|
|
@@ -883,7 +883,7 @@ coverage:
|
|
|
883
883
|
class: lineage
|
|
884
884
|
impact_flow: none
|
|
885
885
|
reason: derived from the archived changes scored by their own judge
|
|
886
|
-
|
|
886
|
+
requirement_assertions:
|
|
887
887
|
kind: edge
|
|
888
888
|
scoring: derived-edge
|
|
889
889
|
class: realisation
|
|
@@ -901,7 +901,7 @@ coverage:
|
|
|
901
901
|
kind: enum
|
|
902
902
|
scoring: not-applicable
|
|
903
903
|
reason: closed vocabulary, not an artefact
|
|
904
|
-
|
|
904
|
+
requirement_assertion_kind:
|
|
905
905
|
kind: enum
|
|
906
906
|
scoring: not-applicable
|
|
907
907
|
reason: closed vocabulary, not an artefact
|
|
@@ -933,3 +933,109 @@ coverage:
|
|
|
933
933
|
kind: enum
|
|
934
934
|
scoring: not-applicable
|
|
935
935
|
reason: closed vocabulary, not an artefact
|
|
936
|
+
feature_status:
|
|
937
|
+
kind: enum
|
|
938
|
+
scoring: not-applicable
|
|
939
|
+
reason: closed vocabulary, not an artefact
|
|
940
|
+
journey_requirement:
|
|
941
|
+
kind: edge
|
|
942
|
+
scoring: derived-edge
|
|
943
|
+
class: dependency
|
|
944
|
+
impact_flow: toward-source
|
|
945
|
+
reason: derived from end-to-end test tags or journey features' living specs
|
|
946
|
+
feature_kind:
|
|
947
|
+
kind: enum
|
|
948
|
+
scoring: not-applicable
|
|
949
|
+
reason: closed vocabulary, not an artefact
|
|
950
|
+
journey_requirement_basis:
|
|
951
|
+
kind: enum
|
|
952
|
+
scoring: not-applicable
|
|
953
|
+
reason: closed vocabulary, not an artefact
|
|
954
|
+
entity_attributes:
|
|
955
|
+
kind: entity
|
|
956
|
+
scoring: scored-at-source
|
|
957
|
+
instrument: an element of the structural model (M-ADR 0230, Proposed); scored with its domain model by rubrics/domain-architecture-rubric.md
|
|
958
|
+
relationships:
|
|
959
|
+
entity_id:
|
|
960
|
+
class: membership
|
|
961
|
+
impact_flow: toward-target
|
|
962
|
+
entity_relationships:
|
|
963
|
+
kind: entity
|
|
964
|
+
scoring: scored-at-source
|
|
965
|
+
instrument: an element of the structural model (M-ADR 0230, Proposed); scored with its domain model by rubrics/domain-architecture-rubric.md
|
|
966
|
+
relationships:
|
|
967
|
+
from_entity_id:
|
|
968
|
+
class: membership
|
|
969
|
+
impact_flow: toward-target
|
|
970
|
+
to_entity_id:
|
|
971
|
+
class: dependency
|
|
972
|
+
impact_flow: toward-source
|
|
973
|
+
domain_invariants:
|
|
974
|
+
kind: entity
|
|
975
|
+
scoring: scored-at-source
|
|
976
|
+
instrument: an element of the structural model (M-ADR 0230, Proposed); scored with its domain model by rubrics/domain-architecture-rubric.md
|
|
977
|
+
relationships:
|
|
978
|
+
entity_id:
|
|
979
|
+
class: membership
|
|
980
|
+
impact_flow: toward-target
|
|
981
|
+
relationship_id:
|
|
982
|
+
class: dependency
|
|
983
|
+
impact_flow: toward-source
|
|
984
|
+
source_of_truth:
|
|
985
|
+
kind: enum
|
|
986
|
+
scoring: not-applicable
|
|
987
|
+
reason: closed vocabulary, not an artefact
|
|
988
|
+
relationship_end_cardinality:
|
|
989
|
+
kind: enum
|
|
990
|
+
scoring: not-applicable
|
|
991
|
+
reason: closed vocabulary, not an artefact
|
|
992
|
+
domain_invariant_kind:
|
|
993
|
+
kind: enum
|
|
994
|
+
scoring: not-applicable
|
|
995
|
+
reason: closed vocabulary, not an artefact
|
|
996
|
+
requirement_revisions:
|
|
997
|
+
kind: entity
|
|
998
|
+
scoring: scored-at-source
|
|
999
|
+
instrument: a revision of a requirement; scored with its living spec by the behaviour-store check
|
|
1000
|
+
relationships:
|
|
1001
|
+
requirement_id:
|
|
1002
|
+
class: membership
|
|
1003
|
+
impact_flow: toward-target
|
|
1004
|
+
change_id:
|
|
1005
|
+
class: lineage
|
|
1006
|
+
impact_flow: toward-source
|
|
1007
|
+
revision_state:
|
|
1008
|
+
kind: enum
|
|
1009
|
+
scoring: not-applicable
|
|
1010
|
+
reason: closed vocabulary, not an artefact
|
|
1011
|
+
change_effects:
|
|
1012
|
+
kind: entity
|
|
1013
|
+
scoring: scored-at-source
|
|
1014
|
+
instrument: a change's effect; scored with the change by the behaviour-store and structural-model checks
|
|
1015
|
+
relationships:
|
|
1016
|
+
change_id:
|
|
1017
|
+
class: membership
|
|
1018
|
+
impact_flow: toward-target
|
|
1019
|
+
change_effect_element_kind:
|
|
1020
|
+
kind: enum
|
|
1021
|
+
scoring: not-applicable
|
|
1022
|
+
reason: closed vocabulary, not an artefact
|
|
1023
|
+
adr_governs:
|
|
1024
|
+
kind: enum
|
|
1025
|
+
scoring: not-applicable
|
|
1026
|
+
reason: closed vocabulary, not an artefact
|
|
1027
|
+
contract_revisions:
|
|
1028
|
+
kind: entity
|
|
1029
|
+
scoring: scored-at-source
|
|
1030
|
+
instrument: a revision of a contract; scored with its contract by the contract rubrics
|
|
1031
|
+
relationships:
|
|
1032
|
+
contract_id:
|
|
1033
|
+
class: membership
|
|
1034
|
+
impact_flow: toward-target
|
|
1035
|
+
change_id:
|
|
1036
|
+
class: lineage
|
|
1037
|
+
impact_flow: toward-source
|
|
1038
|
+
contract_revision_state:
|
|
1039
|
+
kind: enum
|
|
1040
|
+
scoring: not-applicable
|
|
1041
|
+
reason: closed vocabulary, not an artefact
|
|
@@ -36,6 +36,7 @@ function normalise(raw) {
|
|
|
36
36
|
type: c.type,
|
|
37
37
|
nullable: c.nullable ?? false,
|
|
38
38
|
...(c.description !== undefined ? { description: c.description } : {}),
|
|
39
|
+
...((c.source_of_truth ?? def.source_of_truth) !== undefined ? { sourceOfTruth: c.source_of_truth ?? def.source_of_truth } : {}),
|
|
39
40
|
})),
|
|
40
41
|
foreignKeys: (def.foreign_keys ?? []).map((fk) => ({
|
|
41
42
|
column: fk.column,
|
|
@@ -45,6 +46,8 @@ function normalise(raw) {
|
|
|
45
46
|
externalForProfiles: fk.external_for_profiles ?? [],
|
|
46
47
|
})),
|
|
47
48
|
columnEnums: def.column_enums ?? {},
|
|
49
|
+
...(def.source_of_truth !== undefined ? { sourceOfTruth: def.source_of_truth } : {}),
|
|
50
|
+
...(def.natural_key !== undefined ? { naturalKey: def.natural_key } : {}),
|
|
48
51
|
}));
|
|
49
52
|
const enums = {};
|
|
50
53
|
for (const [name, def] of Object.entries(raw.enums ?? {})) {
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
// none — already reported by scores-coverage as unknown currency; not
|
|
41
41
|
// re-reported here.
|
|
42
42
|
//
|
|
43
|
+
// ASSESSED INPUTS (M-ADR 0230 §4.9, Proposed): a review that names its other inputs (`input_paths`) is read with
|
|
44
|
+
// each of them, once its target is current. An input that moved stales the score, with the input named. So does an
|
|
45
|
+
// input gone from HEAD, and one the corpus did not hold at the anchor: unlike a missing target, the score can still
|
|
46
|
+
// be re-reviewed against its target, and a review cannot have read an input that was not there, so both prescribe a
|
|
47
|
+
// re-review rather than a withdrawal. An input present but uncommitted is UNKNOWN, as the target is, unless another
|
|
48
|
+
// input moved, which decides it whatever order the inputs are listed in. On the
|
|
49
|
+
// scored_at basis an input changed after the review stales it.
|
|
50
|
+
//
|
|
43
51
|
// MEMBER TIER ONLY, stated not silent: the aggregate tier reads sibling
|
|
44
52
|
// catalogues whose target files and git histories are not local, so a verdict
|
|
45
53
|
// there would be a guess. Reporting-only (`coverage` class) like the rest of
|
|
@@ -163,9 +171,12 @@ export async function runStalenessVerdicts(session, options) {
|
|
|
163
171
|
};
|
|
164
172
|
}
|
|
165
173
|
const asStr = (v) => v === null || v === undefined ? "" : String(v).trim();
|
|
166
|
-
|
|
174
|
+
// input_paths (schema 6.0.0, M-ADR 0230 §4.9, Proposed): a catalogue built before it has no such column, and its
|
|
175
|
+
// scores are read as naming no other input.
|
|
176
|
+
const query = (inputs) => `SELECT rubric_id, target_ref, target_path, corpus_ref, scored_at, staleness_basis, ${inputs}
|
|
167
177
|
FROM "quality_scores"
|
|
168
|
-
WHERE staleness_basis IN ('corpus_ref', 'scored_at')
|
|
178
|
+
WHERE staleness_basis IN ('corpus_ref', 'scored_at');`;
|
|
179
|
+
const reader = await session.conn.runAndReadAll(query("input_paths")).catch(() => session.conn.runAndReadAll(query("NULL")));
|
|
169
180
|
const rows = reader.getRows();
|
|
170
181
|
const stale = [];
|
|
171
182
|
let current = 0;
|
|
@@ -176,10 +187,13 @@ export async function runStalenessVerdicts(session, options) {
|
|
|
176
187
|
const targetMissing = [];
|
|
177
188
|
const anchorKnown = new Map();
|
|
178
189
|
const renamesByAnchor = new Map();
|
|
179
|
-
for (const [rubricIdRaw, targetRefRaw, targetPathRaw, corpusRefRaw, scoredAtRaw, basisRaw] of rows) {
|
|
190
|
+
for (const [rubricIdRaw, targetRefRaw, targetPathRaw, corpusRefRaw, scoredAtRaw, basisRaw, inputPathsRaw] of rows) {
|
|
180
191
|
const rubricId = asStr(rubricIdRaw);
|
|
181
192
|
const targetRef = asStr(targetRefRaw);
|
|
182
193
|
const basis = asStr(basisRaw);
|
|
194
|
+
// The review's other assessed inputs (M-ADR 0230 §4.9, Proposed): read with the target, so an edit to any of
|
|
195
|
+
// them makes the score stale as an edit to the target does.
|
|
196
|
+
const inputs = asStr(inputPathsRaw).split(";").map((x) => x.trim()).filter((x) => x !== "");
|
|
183
197
|
// Counted for BOTH bases, before the branch. The first cut of this counter
|
|
184
198
|
// sat inside the corpus_ref branch only, so it was blind to every
|
|
185
199
|
// scored_at row — and the estate that ASKED for this count has all 18 of
|
|
@@ -242,7 +256,42 @@ export async function runStalenessVerdicts(session, options) {
|
|
|
242
256
|
if (anchorBlob === headBlob) {
|
|
243
257
|
// Byte-identical to its assessed state — including across a rename,
|
|
244
258
|
// which is the whole point of testing content instead of touches.
|
|
245
|
-
|
|
259
|
+
let moved = null;
|
|
260
|
+
let unknown = false;
|
|
261
|
+
for (const input of inputs) {
|
|
262
|
+
const now = await blobAt(options.sddRoot, "HEAD", input);
|
|
263
|
+
if (now === null && (await existsOnDisk(options.sddRoot, input))) {
|
|
264
|
+
unknown = true; // present but uncommitted: no blob to compare, as for the target
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
let then = await blobAt(options.sddRoot, anchor, input);
|
|
268
|
+
if (then === null) {
|
|
269
|
+
let renames = renamesByAnchor.get(anchor);
|
|
270
|
+
if (renames === undefined) {
|
|
271
|
+
renames = await renameMap(options.sddRoot, anchor);
|
|
272
|
+
renamesByAnchor.set(anchor, renames);
|
|
273
|
+
}
|
|
274
|
+
const oldPath = renames.get(input);
|
|
275
|
+
if (oldPath !== undefined)
|
|
276
|
+
then = await blobAt(options.sddRoot, anchor, oldPath);
|
|
277
|
+
}
|
|
278
|
+
if (now === null)
|
|
279
|
+
moved = `assessed input ${input} no longer exists at HEAD`;
|
|
280
|
+
else if (then === null)
|
|
281
|
+
moved = `assessed input ${input} was not in the corpus at the anchor`;
|
|
282
|
+
else if (then !== now)
|
|
283
|
+
moved = `assessed input ${input} CONTENT differs from its state at the anchor`;
|
|
284
|
+
if (moved !== null)
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
// An input that moved decides it, whatever the others are; with none moved, an uncommitted input leaves the
|
|
288
|
+
// score undecided.
|
|
289
|
+
if (moved !== null)
|
|
290
|
+
stale.push({ rubricId, targetRef, basis: "corpus_ref", detail: moved });
|
|
291
|
+
else if (unknown)
|
|
292
|
+
unknownAnchor += 1;
|
|
293
|
+
else
|
|
294
|
+
current += 1;
|
|
246
295
|
}
|
|
247
296
|
else {
|
|
248
297
|
stale.push({
|
|
@@ -284,10 +333,30 @@ export async function runStalenessVerdicts(session, options) {
|
|
|
284
333
|
basis: "scored_at",
|
|
285
334
|
detail: `target last changed ${last.stdout.slice(0, 10)}, after the review of ${at.slice(0, 10)}`,
|
|
286
335
|
});
|
|
336
|
+
continue;
|
|
287
337
|
}
|
|
288
|
-
|
|
289
|
-
|
|
338
|
+
let moved = null;
|
|
339
|
+
let unknown = false;
|
|
340
|
+
for (const input of inputs) {
|
|
341
|
+
const changed = await git(options.sddRoot, ["log", "-1", "--format=%cI", "--", input]);
|
|
342
|
+
if ((await blobAt(options.sddRoot, "HEAD", input)) === null) {
|
|
343
|
+
if (await existsOnDisk(options.sddRoot, input)) {
|
|
344
|
+
unknown = true; // present but uncommitted: git has no history for it
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
moved = `assessed input ${input} no longer exists at HEAD`;
|
|
348
|
+
}
|
|
349
|
+
else if (changed.ok && changed.stdout !== "" && Date.parse(changed.stdout) > reviewedMs)
|
|
350
|
+
moved = `assessed input ${input} last changed ${changed.stdout.slice(0, 10)}, after the review of ${at.slice(0, 10)}`;
|
|
351
|
+
if (moved !== null)
|
|
352
|
+
break;
|
|
290
353
|
}
|
|
354
|
+
if (moved !== null)
|
|
355
|
+
stale.push({ rubricId, targetRef, basis: "scored_at", detail: moved });
|
|
356
|
+
else if (unknown)
|
|
357
|
+
unknownAnchor += 1;
|
|
358
|
+
else
|
|
359
|
+
current += 1;
|
|
291
360
|
}
|
|
292
361
|
}
|
|
293
362
|
return {
|
|
@@ -174,7 +174,13 @@ export function parseTypes(text, fileLabel = "catalogue-schema.tql", options = {
|
|
|
174
174
|
throw new ParseError(`${where}: plays needs <relation>:<role>`);
|
|
175
175
|
if (decl.plays.has(w[1]))
|
|
176
176
|
throw new ParseError(`${where}: ${lab} plays ${w[1]} twice`);
|
|
177
|
-
|
|
177
|
+
const ann = parseAnnotations(w.slice(2), where);
|
|
178
|
+
// A plays clause's cardinality constrains participation, which the relational projection has no place for:
|
|
179
|
+
// refused, so a constraint the model gained can never be dropped by the projection with the gate green.
|
|
180
|
+
if (ann.key || ann.required || ann.multi || ann.optional) {
|
|
181
|
+
throw new ParseError(`${where}: ${lab} plays ${w[1]} with a cardinality annotation; participation cardinality cannot be projected onto the catalogue schema, so it is not admitted`);
|
|
182
|
+
}
|
|
183
|
+
decl.plays.set(w[1], ann);
|
|
178
184
|
}
|
|
179
185
|
else if (head === "relates") {
|
|
180
186
|
if (kind !== "relation")
|
|
@@ -225,6 +231,16 @@ export function parseTypes(text, fileLabel = "catalogue-schema.tql", options = {
|
|
|
225
231
|
}
|
|
226
232
|
const ROW_RE = /^insert \$m isa ([a-z][a-z0-9-]*), (.*);$/;
|
|
227
233
|
const TOK_RE = /has ([a-z][a-z0-9-]*) ("(?:[^"\\]|\\.)*"|-?\d+|true|false)/y;
|
|
234
|
+
function valueFamily(v) {
|
|
235
|
+
return typeof v === "boolean" ? "boolean" : typeof v === "number" ? "integer" : "string";
|
|
236
|
+
}
|
|
237
|
+
function attrFamily(valueType) {
|
|
238
|
+
if (valueType === undefined)
|
|
239
|
+
return undefined;
|
|
240
|
+
if (valueType === "long" || valueType === "integer")
|
|
241
|
+
return "integer";
|
|
242
|
+
return valueType;
|
|
243
|
+
}
|
|
228
244
|
export function parseMeta(text, fileLabel = "catalogue-schema-meta.tql", options = {}) {
|
|
229
245
|
const metaTypes = options.metaTypes ?? META_TYPES;
|
|
230
246
|
const rows = new Map();
|
|
@@ -268,9 +284,26 @@ export function parseMeta(text, fileLabel = "catalogue-schema-meta.tql", options
|
|
|
268
284
|
else
|
|
269
285
|
throw new ParseError(`${where}: expected ', has ...' at offset ${i}: ${JSON.stringify(body.slice(i, i + 40))}`);
|
|
270
286
|
}
|
|
287
|
+
const decl = options.types?.entities.get(typ);
|
|
288
|
+
if (options.types && !decl)
|
|
289
|
+
throw new ParseError(`${where}: meta type ${typ} is not declared in the type file`);
|
|
290
|
+
if (decl) {
|
|
291
|
+
for (const [k, vs] of acc) {
|
|
292
|
+
const own = decl.owns.get(k);
|
|
293
|
+
if (!own)
|
|
294
|
+
throw new ParseError(`${where}: ${typ} does not own ${k}; an undeclared meta property is refused, not ignored`);
|
|
295
|
+
if (!own.multi && vs.length > 1)
|
|
296
|
+
throw new ParseError(`${where}: ${typ}.${k} is a single value and appears ${vs.length} times; a repeated scalar is refused, not reduced to its first value`);
|
|
297
|
+
const fam = attrFamily(options.types.attrs.get(k));
|
|
298
|
+
for (const v of vs) {
|
|
299
|
+
if (fam !== undefined && valueFamily(v) !== fam)
|
|
300
|
+
throw new ParseError(`${where}: ${typ}.${k} holds ${JSON.stringify(v)}, but ${k} is of value type ${options.types.attrs.get(k)}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
271
304
|
const row = {};
|
|
272
305
|
for (const [k, vs] of acc)
|
|
273
|
-
row[k] = LIST_KEYS.has(k) ? vs : vs[0];
|
|
306
|
+
row[k] = (decl ? decl.owns.get(k).multi : LIST_KEYS.has(k)) ? vs : vs[0];
|
|
274
307
|
const list = rows.get(typ) ?? [];
|
|
275
308
|
list.push(row);
|
|
276
309
|
rows.set(typ, list);
|
|
@@ -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
|