@driftsys/markspec 0.2.0 → 0.4.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.
Files changed (214) hide show
  1. package/README.md +32 -8
  2. package/esm/compiler/inverses.d.ts +22 -0
  3. package/esm/compiler/inverses.d.ts.map +1 -0
  4. package/esm/compiler/inverses.js +147 -0
  5. package/esm/compiler/link_target.d.ts +19 -0
  6. package/esm/compiler/link_target.d.ts.map +1 -0
  7. package/esm/compiler/link_target.js +66 -0
  8. package/esm/compiler/mod.d.ts +7 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +61 -14
  11. package/esm/compiler/schema.d.ts.map +1 -1
  12. package/esm/compiler/schema.js +20 -1
  13. package/esm/config/markspec.d.ts +51 -0
  14. package/esm/config/markspec.d.ts.map +1 -0
  15. package/esm/config/markspec.js +216 -0
  16. package/esm/config/mod.d.ts +4 -0
  17. package/esm/config/mod.d.ts.map +1 -1
  18. package/esm/config/mod.js +27 -16
  19. package/esm/formatter/mod.d.ts +19 -4
  20. package/esm/formatter/mod.d.ts.map +1 -1
  21. package/esm/formatter/mod.js +139 -29
  22. package/esm/mod.d.ts +11 -7
  23. package/esm/mod.d.ts.map +1 -1
  24. package/esm/mod.js +6 -3
  25. package/esm/model/attributes.d.ts +47 -0
  26. package/esm/model/attributes.d.ts.map +1 -0
  27. package/esm/model/attributes.js +97 -0
  28. package/esm/model/mod.d.ts +257 -26
  29. package/esm/model/mod.d.ts.map +1 -1
  30. package/esm/model/mod.js +28 -1
  31. package/esm/model/palette.d.ts +18 -0
  32. package/esm/model/palette.d.ts.map +1 -0
  33. package/esm/model/palette.js +23 -0
  34. package/esm/model/profile.d.ts +189 -0
  35. package/esm/model/profile.d.ts.map +1 -0
  36. package/esm/model/profile.js +31 -0
  37. package/esm/parser/attributes.d.ts +13 -1
  38. package/esm/parser/attributes.d.ts.map +1 -1
  39. package/esm/parser/attributes.js +47 -0
  40. package/esm/parser/frontmatter.d.ts +53 -0
  41. package/esm/parser/frontmatter.d.ts.map +1 -0
  42. package/esm/parser/frontmatter.js +185 -0
  43. package/esm/parser/grammars.js +11 -2
  44. package/esm/parser/markdown.d.ts +21 -7
  45. package/esm/parser/markdown.d.ts.map +1 -1
  46. package/esm/parser/markdown.js +101 -40
  47. package/esm/parser/mod.d.ts +26 -10
  48. package/esm/parser/mod.d.ts.map +1 -1
  49. package/esm/parser/mod.js +40 -10
  50. package/esm/parser/source.d.ts +12 -8
  51. package/esm/parser/source.d.ts.map +1 -1
  52. package/esm/parser/source.js +21 -14
  53. package/esm/profile/cache.d.ts +29 -0
  54. package/esm/profile/cache.d.ts.map +1 -0
  55. package/esm/profile/cache.js +45 -0
  56. package/esm/profile/chain.d.ts +42 -0
  57. package/esm/profile/chain.d.ts.map +1 -0
  58. package/esm/profile/chain.js +193 -0
  59. package/esm/profile/colors.d.ts +26 -0
  60. package/esm/profile/colors.d.ts.map +1 -0
  61. package/esm/profile/colors.js +46 -0
  62. package/esm/profile/git-cache.d.ts +73 -0
  63. package/esm/profile/git-cache.d.ts.map +1 -0
  64. package/esm/profile/git-cache.js +96 -0
  65. package/esm/profile/load.d.ts +28 -0
  66. package/esm/profile/load.d.ts.map +1 -0
  67. package/esm/profile/load.js +50 -0
  68. package/esm/profile/manifest.d.ts +21 -0
  69. package/esm/profile/manifest.d.ts.map +1 -0
  70. package/esm/profile/manifest.js +815 -0
  71. package/esm/profile/merge.d.ts +26 -0
  72. package/esm/profile/merge.d.ts.map +1 -0
  73. package/esm/profile/merge.js +518 -0
  74. package/esm/profile/mod.d.ts +24 -0
  75. package/esm/profile/mod.d.ts.map +1 -0
  76. package/esm/profile/mod.js +15 -0
  77. package/esm/profile/npm.d.ts +51 -0
  78. package/esm/profile/npm.d.ts.map +1 -0
  79. package/esm/profile/npm.js +186 -0
  80. package/esm/profile/resolver.d.ts +60 -0
  81. package/esm/profile/resolver.d.ts.map +1 -0
  82. package/esm/profile/resolver.js +132 -0
  83. package/esm/reporter/mod.js +14 -27
  84. package/esm/validator/attributes.d.ts +43 -0
  85. package/esm/validator/attributes.d.ts.map +1 -0
  86. package/esm/validator/attributes.js +169 -0
  87. package/esm/validator/mod.d.ts +27 -6
  88. package/esm/validator/mod.d.ts.map +1 -1
  89. package/esm/validator/mod.js +132 -124
  90. package/esm/validator/normalize.d.ts +21 -0
  91. package/esm/validator/normalize.d.ts.map +1 -0
  92. package/esm/validator/normalize.js +58 -0
  93. package/esm/validator/pattern.d.ts +23 -0
  94. package/esm/validator/pattern.d.ts.map +1 -0
  95. package/esm/validator/pattern.js +44 -0
  96. package/esm/validator/pipeline.d.ts +30 -0
  97. package/esm/validator/pipeline.d.ts.map +1 -0
  98. package/esm/validator/pipeline.js +115 -0
  99. package/esm/validator/traceability.d.ts +48 -0
  100. package/esm/validator/traceability.d.ts.map +1 -0
  101. package/esm/validator/traceability.js +141 -0
  102. package/esm/validator/types.d.ts +48 -0
  103. package/esm/validator/types.d.ts.map +1 -0
  104. package/esm/validator/types.js +140 -0
  105. package/esm/validator/value_types.d.ts +20 -0
  106. package/esm/validator/value_types.d.ts.map +1 -0
  107. package/esm/validator/value_types.js +126 -0
  108. package/package.json +1 -1
  109. package/script/compiler/inverses.d.ts +22 -0
  110. package/script/compiler/inverses.d.ts.map +1 -0
  111. package/script/compiler/inverses.js +150 -0
  112. package/script/compiler/link_target.d.ts +19 -0
  113. package/script/compiler/link_target.d.ts.map +1 -0
  114. package/script/compiler/link_target.js +69 -0
  115. package/script/compiler/mod.d.ts +7 -1
  116. package/script/compiler/mod.d.ts.map +1 -1
  117. package/script/compiler/mod.js +62 -14
  118. package/script/compiler/schema.d.ts.map +1 -1
  119. package/script/compiler/schema.js +20 -1
  120. package/script/config/markspec.d.ts +51 -0
  121. package/script/config/markspec.d.ts.map +1 -0
  122. package/script/config/markspec.js +222 -0
  123. package/script/config/mod.d.ts +4 -0
  124. package/script/config/mod.d.ts.map +1 -1
  125. package/script/config/mod.js +28 -16
  126. package/script/formatter/mod.d.ts +19 -4
  127. package/script/formatter/mod.d.ts.map +1 -1
  128. package/script/formatter/mod.js +140 -29
  129. package/script/mod.d.ts +11 -7
  130. package/script/mod.d.ts.map +1 -1
  131. package/script/mod.js +50 -19
  132. package/script/model/attributes.d.ts +47 -0
  133. package/script/model/attributes.d.ts.map +1 -0
  134. package/script/model/attributes.js +101 -0
  135. package/script/model/mod.d.ts +257 -26
  136. package/script/model/mod.d.ts.map +1 -1
  137. package/script/model/mod.js +37 -2
  138. package/script/model/palette.d.ts +18 -0
  139. package/script/model/palette.d.ts.map +1 -0
  140. package/script/model/palette.js +26 -0
  141. package/script/model/profile.d.ts +189 -0
  142. package/script/model/profile.d.ts.map +1 -0
  143. package/script/model/profile.js +34 -0
  144. package/script/parser/attributes.d.ts +13 -1
  145. package/script/parser/attributes.d.ts.map +1 -1
  146. package/script/parser/attributes.js +48 -0
  147. package/script/parser/frontmatter.d.ts +53 -0
  148. package/script/parser/frontmatter.d.ts.map +1 -0
  149. package/script/parser/frontmatter.js +188 -0
  150. package/script/parser/grammars.js +11 -2
  151. package/script/parser/markdown.d.ts +21 -7
  152. package/script/parser/markdown.d.ts.map +1 -1
  153. package/script/parser/markdown.js +100 -39
  154. package/script/parser/mod.d.ts +26 -10
  155. package/script/parser/mod.d.ts.map +1 -1
  156. package/script/parser/mod.js +42 -11
  157. package/script/parser/source.d.ts +12 -8
  158. package/script/parser/source.d.ts.map +1 -1
  159. package/script/parser/source.js +21 -14
  160. package/script/profile/cache.d.ts +29 -0
  161. package/script/profile/cache.d.ts.map +1 -0
  162. package/script/profile/cache.js +48 -0
  163. package/script/profile/chain.d.ts +42 -0
  164. package/script/profile/chain.d.ts.map +1 -0
  165. package/script/profile/chain.js +229 -0
  166. package/script/profile/colors.d.ts +26 -0
  167. package/script/profile/colors.d.ts.map +1 -0
  168. package/script/profile/colors.js +49 -0
  169. package/script/profile/git-cache.d.ts +73 -0
  170. package/script/profile/git-cache.d.ts.map +1 -0
  171. package/script/profile/git-cache.js +104 -0
  172. package/script/profile/load.d.ts +28 -0
  173. package/script/profile/load.d.ts.map +1 -0
  174. package/script/profile/load.js +53 -0
  175. package/script/profile/manifest.d.ts +21 -0
  176. package/script/profile/manifest.d.ts.map +1 -0
  177. package/script/profile/manifest.js +818 -0
  178. package/script/profile/merge.d.ts +26 -0
  179. package/script/profile/merge.d.ts.map +1 -0
  180. package/script/profile/merge.js +521 -0
  181. package/script/profile/mod.d.ts +24 -0
  182. package/script/profile/mod.d.ts.map +1 -0
  183. package/script/profile/mod.js +33 -0
  184. package/script/profile/npm.d.ts +51 -0
  185. package/script/profile/npm.d.ts.map +1 -0
  186. package/script/profile/npm.js +191 -0
  187. package/script/profile/resolver.d.ts +60 -0
  188. package/script/profile/resolver.d.ts.map +1 -0
  189. package/script/profile/resolver.js +136 -0
  190. package/script/reporter/mod.js +14 -27
  191. package/script/validator/attributes.d.ts +43 -0
  192. package/script/validator/attributes.d.ts.map +1 -0
  193. package/script/validator/attributes.js +173 -0
  194. package/script/validator/mod.d.ts +27 -6
  195. package/script/validator/mod.d.ts.map +1 -1
  196. package/script/validator/mod.js +145 -123
  197. package/script/validator/normalize.d.ts +21 -0
  198. package/script/validator/normalize.d.ts.map +1 -0
  199. package/script/validator/normalize.js +61 -0
  200. package/script/validator/pattern.d.ts +23 -0
  201. package/script/validator/pattern.d.ts.map +1 -0
  202. package/script/validator/pattern.js +47 -0
  203. package/script/validator/pipeline.d.ts +30 -0
  204. package/script/validator/pipeline.d.ts.map +1 -0
  205. package/script/validator/pipeline.js +118 -0
  206. package/script/validator/traceability.d.ts +48 -0
  207. package/script/validator/traceability.d.ts.map +1 -0
  208. package/script/validator/traceability.js +146 -0
  209. package/script/validator/types.d.ts +48 -0
  210. package/script/validator/types.d.ts.map +1 -0
  211. package/script/validator/types.js +144 -0
  212. package/script/validator/value_types.d.ts +20 -0
  213. package/script/validator/value_types.d.ts.map +1 -0
  214. package/script/validator/value_types.js +129 -0
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/normalize
4
+ *
5
+ * Stage 2.5 normalization: split comma-separated values for profile-declared
6
+ * list-typed attributes.
7
+ *
8
+ * Runs between Stage 2 (classification) and Stage 3 (typed attributes). The
9
+ * core parser already CSV-splits values for core-catalog list types; this
10
+ * step handles list types declared by a profile (which the parser doesn't
11
+ * see). Idempotent — values that don't contain commas pass through unchanged.
12
+ *
13
+ * Empty-string fragments (e.g. from `"a,,b"`) are dropped; surrounding
14
+ * whitespace is trimmed.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.normalizeListValues = normalizeListValues;
18
+ const attributes_js_1 = require("./attributes.js");
19
+ const LIST_TYPES = new Set(["id-list", "tag-list"]);
20
+ /**
21
+ * Return a new Entry with list-typed attribute values split on commas. If no
22
+ * change is needed, returns the input entry unchanged (reference equality).
23
+ */
24
+ function normalizeListValues(entry, profile) {
25
+ const scope = (0, attributes_js_1.effectiveScope)(entry, profile);
26
+ const rewritten = new Map();
27
+ let anyChange = false;
28
+ for (const [name, values] of entry.typedAttributes) {
29
+ const decl = scope.attributes.get(name);
30
+ if (decl !== undefined && LIST_TYPES.has(decl.type)) {
31
+ const split = splitListValues(values);
32
+ if (!arraysEqual(split, values)) {
33
+ rewritten.set(name, split);
34
+ anyChange = true;
35
+ continue;
36
+ }
37
+ }
38
+ rewritten.set(name, values);
39
+ }
40
+ if (!anyChange)
41
+ return entry;
42
+ return { ...entry, typedAttributes: rewritten };
43
+ }
44
+ function splitListValues(values) {
45
+ const out = [];
46
+ for (const v of values) {
47
+ const parts = v.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
48
+ if (parts.length === 0)
49
+ continue;
50
+ out.push(...parts);
51
+ }
52
+ return out;
53
+ }
54
+ function arraysEqual(a, b) {
55
+ if (a.length !== b.length)
56
+ return false;
57
+ for (let i = 0; i < a.length; i++)
58
+ if (a[i] !== b[i])
59
+ return false;
60
+ return true;
61
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @module core/validator/pattern
3
+ *
4
+ * Display-ID pattern template → anchored RegExp.
5
+ *
6
+ * Grammar (per ADR-009 §5):
7
+ * pattern := literal-prefix placeholder (literal-suffix)?
8
+ * placeholder := "{n}" | "{n:" PADDING "d}"
9
+ * PADDING := "0" digits
10
+ *
11
+ * Examples:
12
+ * REQ-{n} → ^REQ-(\d+)$
13
+ * REQ-{n:04d} → ^REQ-(\d{4})$
14
+ * STAKE-REQ-{n:06d} → ^STAKE-REQ-(\d{6})$
15
+ */
16
+ /**
17
+ * Compile a display-ID pattern template into an anchored RegExp.
18
+ *
19
+ * Throws if the template is missing the `{n}` placeholder or has an invalid
20
+ * padding specifier.
21
+ */
22
+ export declare function compileDisplayIdPattern(template: string): RegExp;
23
+ //# sourceMappingURL=pattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern.d.ts","sourceRoot":"","sources":["../../src/validator/pattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA0BhE"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/pattern
4
+ *
5
+ * Display-ID pattern template → anchored RegExp.
6
+ *
7
+ * Grammar (per ADR-009 §5):
8
+ * pattern := literal-prefix placeholder (literal-suffix)?
9
+ * placeholder := "{n}" | "{n:" PADDING "d}"
10
+ * PADDING := "0" digits
11
+ *
12
+ * Examples:
13
+ * REQ-{n} → ^REQ-(\d+)$
14
+ * REQ-{n:04d} → ^REQ-(\d{4})$
15
+ * STAKE-REQ-{n:06d} → ^STAKE-REQ-(\d{6})$
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.compileDisplayIdPattern = compileDisplayIdPattern;
19
+ const PLACEHOLDER_RE = /\{n(?::(0\d+)d)?\}/;
20
+ /**
21
+ * Compile a display-ID pattern template into an anchored RegExp.
22
+ *
23
+ * Throws if the template is missing the `{n}` placeholder or has an invalid
24
+ * padding specifier.
25
+ */
26
+ function compileDisplayIdPattern(template) {
27
+ const match = PLACEHOLDER_RE.exec(template);
28
+ if (!match) {
29
+ if (/\{n:[^}]*\}/.test(template)) {
30
+ throw new Error(`display-id-pattern '${template}': invalid padding specifier ` +
31
+ `(expected {n} or {n:NNd})`);
32
+ }
33
+ throw new Error(`display-id-pattern '${template}': missing {n} placeholder`);
34
+ }
35
+ const padding = match[1];
36
+ const placeholderStart = match.index;
37
+ const placeholderEnd = match.index + match[0].length;
38
+ const prefix = template.slice(0, placeholderStart);
39
+ const suffix = template.slice(placeholderEnd);
40
+ const digitGroup = padding ? `\\d{${Number(padding)}}` : `\\d+`;
41
+ const regexSource = "^" + escapeRegex(prefix) + "(" + digitGroup + ")" +
42
+ escapeRegex(suffix) + "$";
43
+ return new RegExp(regexSource);
44
+ }
45
+ function escapeRegex(s) {
46
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
47
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @module core/validator/pipeline
3
+ *
4
+ * Validator pipeline. Composes Stage 1 (core hygiene — existing `validate`),
5
+ * Stage 2 (type classification — {@linkcode classifyEntriesStage}),
6
+ * Stage 2.5 (list-value normalization — {@linkcode normalizeListValues}),
7
+ * Stage 3 (typed attribute validation — {@linkcode validateAttributesForEntry}),
8
+ * and Stage 4 (traceability rules — {@linkcode validateTraceabilityForEntry}).
9
+ */
10
+ import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
11
+ /** Result of running the full validator pipeline. */
12
+ export interface PipelineResult {
13
+ /** Entries after classification — `type` set on those that classified. */
14
+ readonly entries: readonly Entry[];
15
+ readonly diagnostics: readonly Diagnostic[];
16
+ /** `true` when no error-severity diagnostics were emitted. */
17
+ readonly valid: boolean;
18
+ }
19
+ /**
20
+ * Run the validator pipeline.
21
+ *
22
+ * - Stage 1 (always): core hygiene via {@linkcode validate}.
23
+ * - Stage 2 (when `profile` is non-null): entry classification via
24
+ * {@linkcode classifyEntriesStage}.
25
+ *
26
+ * When `profile` is `null`, entries pass through unchanged (no `type`
27
+ * assignments).
28
+ */
29
+ export declare function runPipeline(entries: readonly Entry[], profile: EffectiveProfile | null): PipelineResult;
30
+ //# sourceMappingURL=pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/validator/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO3E,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAC/B,cAAc,CA2DhB"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/pipeline
4
+ *
5
+ * Validator pipeline. Composes Stage 1 (core hygiene — existing `validate`),
6
+ * Stage 2 (type classification — {@linkcode classifyEntriesStage}),
7
+ * Stage 2.5 (list-value normalization — {@linkcode normalizeListValues}),
8
+ * Stage 3 (typed attribute validation — {@linkcode validateAttributesForEntry}),
9
+ * and Stage 4 (traceability rules — {@linkcode validateTraceabilityForEntry}).
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runPipeline = runPipeline;
13
+ const mod_js_1 = require("./mod.js");
14
+ const types_js_1 = require("./types.js");
15
+ const attributes_js_1 = require("./attributes.js");
16
+ const normalize_js_1 = require("./normalize.js");
17
+ const traceability_js_1 = require("./traceability.js");
18
+ /**
19
+ * Run the validator pipeline.
20
+ *
21
+ * - Stage 1 (always): core hygiene via {@linkcode validate}.
22
+ * - Stage 2 (when `profile` is non-null): entry classification via
23
+ * {@linkcode classifyEntriesStage}.
24
+ *
25
+ * When `profile` is `null`, entries pass through unchanged (no `type`
26
+ * assignments).
27
+ */
28
+ function runPipeline(entries, profile) {
29
+ const diagnostics = [];
30
+ // Stage 1 — core hygiene. When a profile is loaded, suppress MSL-R010
31
+ // warnings for attributes the profile actually declares (Stage 3's scope
32
+ // validates them directly — the core-only R010 check would be noise).
33
+ const stage1 = (0, mod_js_1.validate)(entries);
34
+ const profileDeclaredAttrs = profile !== null
35
+ ? collectAllProfileAttributes(entries, profile)
36
+ : null;
37
+ const filteredStage1 = profileDeclaredAttrs === null
38
+ ? stage1.diagnostics
39
+ : stage1.diagnostics.filter((d) => {
40
+ if (d.code !== "MSL-R010")
41
+ return true;
42
+ const match = /attribute '([^']+)'/.exec(d.message);
43
+ if (!match)
44
+ return true;
45
+ return !profileDeclaredAttrs.has(match[1]);
46
+ });
47
+ diagnostics.push(...filteredStage1);
48
+ // Stage 2 — classification (only when a profile is loaded).
49
+ let finalEntries = entries;
50
+ if (profile !== null) {
51
+ const stage2 = (0, types_js_1.classifyEntriesStage)(entries, profile);
52
+ finalEntries = stage2.entries;
53
+ diagnostics.push(...stage2.diagnostics);
54
+ }
55
+ // Stage 2.5 — normalize profile-declared list-value attributes. Splits
56
+ // comma-separated values for `id-list`/`tag-list` attributes the core parser
57
+ // didn't see so that Stage 3 sees already-split values.
58
+ if (profile !== null) {
59
+ finalEntries = finalEntries.map((e) => (0, normalize_js_1.normalizeListValues)(e, profile));
60
+ }
61
+ // Stage 3 — typed attributes (only when a profile is loaded).
62
+ if (profile !== null) {
63
+ for (const entry of finalEntries) {
64
+ const stage3 = (0, attributes_js_1.validateAttributesForEntry)(entry, profile);
65
+ diagnostics.push(...stage3);
66
+ }
67
+ }
68
+ // Stage 4 — traceability rules (only when a profile is loaded). Builds a
69
+ // graph index keyed by `entry.id` from the post-classification entries so
70
+ // trace-rule target matchers can look up the classified type/shape.
71
+ if (profile !== null) {
72
+ const graph = new Map();
73
+ for (const e of finalEntries) {
74
+ if (e.id)
75
+ graph.set(e.id, e);
76
+ }
77
+ for (const entry of finalEntries) {
78
+ const stage4 = (0, traceability_js_1.validateTraceabilityForEntry)(entry, profile, graph);
79
+ diagnostics.push(...stage4);
80
+ }
81
+ }
82
+ const valid = !diagnostics.some((d) => d.severity === "error");
83
+ return { entries: finalEntries, diagnostics, valid };
84
+ }
85
+ /**
86
+ * Union of all attribute names declared by the profile's effective scope
87
+ * across all entries. Used to suppress core Stage 1 MSL-R010 warnings for
88
+ * attributes that Stage 3 already validates.
89
+ *
90
+ * Computed per-entry because the effective scope for an entry depends on
91
+ * its shape and (when classified) type. Stage 1 runs before classification,
92
+ * so we pre-classify by iterating; entries without `type` still contribute
93
+ * their universal+shape scope.
94
+ */
95
+ function collectAllProfileAttributes(entries, profile) {
96
+ const out = new Set();
97
+ for (const entry of entries) {
98
+ const scope = (0, attributes_js_1.effectiveScope)(entry, profile);
99
+ for (const name of scope.attributes.keys())
100
+ out.add(name);
101
+ }
102
+ // Also include every type-scoped attribute in the profile, since an entry
103
+ // may have declared attributes before Stage 2 classification runs.
104
+ for (const [, typeEntry] of profile.types) {
105
+ for (const name of typeEntry.value.attributes.keys())
106
+ out.add(name);
107
+ // Trace rule link names are implicitly id-list attributes — include them
108
+ // so Stage 1's MSL-R010 doesn't flag them before Stage 2 classifies.
109
+ for (const name of typeEntry.value.traceability.keys())
110
+ out.add(name);
111
+ }
112
+ // Shape-level trace rule link names too.
113
+ for (const name of profile.identified.traceability.keys())
114
+ out.add(name);
115
+ for (const name of profile.referenced.traceability.keys())
116
+ out.add(name);
117
+ return out;
118
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module core/validator/traceability
3
+ *
4
+ * Validator Stage 4 — traceability rule enforcement.
5
+ *
6
+ * Runs after Stage 3. For each classified identified entry, checks the
7
+ * profile's declared trace rules against the entry's outgoing link
8
+ * attributes:
9
+ * - Required (MSL-L001)
10
+ * - Cardinality bounds (MSL-L002 upper / MSL-L003 lower)
11
+ * - Target match against the rule's target matchers (MSL-L004)
12
+ *
13
+ * Referenced entries are skipped entirely — the profile manifest parser
14
+ * rejects `referenced.traceability` at load time, so referenced entries
15
+ * never have declared outgoing links.
16
+ */
17
+ import type { Diagnostic, EffectiveProfile, Entry, TargetMatcher, TraceRule } from "../model/mod.js";
18
+ /**
19
+ * Effective trace rules for an entry: union of identified-shape-scope rules
20
+ * and (when classified) type-scope rules. Type-scope rules win on
21
+ * link-attribute-name collision.
22
+ *
23
+ * Referenced entries always return an empty map.
24
+ */
25
+ export declare function effectiveTraceRules(entry: Entry, profile: EffectiveProfile): ReadonlyMap<string, TraceRule>;
26
+ /**
27
+ * Return true if the target entry matches any of the rule's target matchers.
28
+ * OR semantics across the list.
29
+ *
30
+ * - Type-name matcher (string): target's classified type equals the name.
31
+ * An un-classified target never matches a type-name matcher.
32
+ * - Shape matcher ({shape: "identified"|"referenced"}): target's shape
33
+ * equals the matcher's shape.
34
+ */
35
+ export declare function matchesAnyTarget(target: Entry, matchers: readonly TargetMatcher[]): boolean;
36
+ /**
37
+ * Run Stage 4 traceability checks for one entry.
38
+ *
39
+ * Skips referenced entries entirely. For identified entries, iterates the
40
+ * effective trace rules and emits MSL-L001..L004 as appropriate.
41
+ *
42
+ * @param entry - The entry to validate (after Stage 2 classification +
43
+ * Stage 2.5 normalization)
44
+ * @param profile - The effective profile (null → never called)
45
+ * @param graph - Index keyed by entry.id for target lookup
46
+ */
47
+ export declare function validateTraceabilityForEntry(entry: Entry, profile: EffectiveProfile, graph: ReadonlyMap<string, Entry>): Diagnostic[];
48
+ //# sourceMappingURL=traceability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traceability.d.ts","sourceRoot":"","sources":["../../src/validator/traceability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAoBhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,KAAK,EACb,QAAQ,EAAE,SAAS,aAAa,EAAE,GACjC,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAChC,UAAU,EAAE,CAuEd"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/traceability
4
+ *
5
+ * Validator Stage 4 — traceability rule enforcement.
6
+ *
7
+ * Runs after Stage 3. For each classified identified entry, checks the
8
+ * profile's declared trace rules against the entry's outgoing link
9
+ * attributes:
10
+ * - Required (MSL-L001)
11
+ * - Cardinality bounds (MSL-L002 upper / MSL-L003 lower)
12
+ * - Target match against the rule's target matchers (MSL-L004)
13
+ *
14
+ * Referenced entries are skipped entirely — the profile manifest parser
15
+ * rejects `referenced.traceability` at load time, so referenced entries
16
+ * never have declared outgoing links.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.effectiveTraceRules = effectiveTraceRules;
20
+ exports.matchesAnyTarget = matchesAnyTarget;
21
+ exports.validateTraceabilityForEntry = validateTraceabilityForEntry;
22
+ /**
23
+ * Effective trace rules for an entry: union of identified-shape-scope rules
24
+ * and (when classified) type-scope rules. Type-scope rules win on
25
+ * link-attribute-name collision.
26
+ *
27
+ * Referenced entries always return an empty map.
28
+ */
29
+ function effectiveTraceRules(entry, profile) {
30
+ const out = new Map();
31
+ if (entry.shape !== "identified")
32
+ return out;
33
+ // Shape scope.
34
+ for (const [name, ruleEntry] of profile.identified.traceability) {
35
+ out.set(name, ruleEntry.value);
36
+ }
37
+ // Type scope (only when classified AND type is declared in the profile).
38
+ if (entry.type !== undefined) {
39
+ const typeEntry = profile.types.get(entry.type);
40
+ if (typeEntry !== undefined) {
41
+ for (const [name, ruleEntry] of typeEntry.value.traceability) {
42
+ out.set(name, ruleEntry.value);
43
+ }
44
+ }
45
+ }
46
+ return out;
47
+ }
48
+ /**
49
+ * Return true if the target entry matches any of the rule's target matchers.
50
+ * OR semantics across the list.
51
+ *
52
+ * - Type-name matcher (string): target's classified type equals the name.
53
+ * An un-classified target never matches a type-name matcher.
54
+ * - Shape matcher ({shape: "identified"|"referenced"}): target's shape
55
+ * equals the matcher's shape.
56
+ */
57
+ function matchesAnyTarget(target, matchers) {
58
+ for (const m of matchers) {
59
+ if (typeof m === "string") {
60
+ if (target.type === m)
61
+ return true;
62
+ }
63
+ else {
64
+ if (target.shape === m.shape)
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ }
70
+ /**
71
+ * Run Stage 4 traceability checks for one entry.
72
+ *
73
+ * Skips referenced entries entirely. For identified entries, iterates the
74
+ * effective trace rules and emits MSL-L001..L004 as appropriate.
75
+ *
76
+ * @param entry - The entry to validate (after Stage 2 classification +
77
+ * Stage 2.5 normalization)
78
+ * @param profile - The effective profile (null → never called)
79
+ * @param graph - Index keyed by entry.id for target lookup
80
+ */
81
+ function validateTraceabilityForEntry(entry, profile, graph) {
82
+ const diagnostics = [];
83
+ if (entry.shape !== "identified")
84
+ return diagnostics;
85
+ const rules = effectiveTraceRules(entry, profile);
86
+ const present = entry.typedAttributes;
87
+ for (const [linkName, rule] of rules) {
88
+ const values = present.get(linkName);
89
+ const count = values?.length ?? 0;
90
+ const card = rule.cardinality ?? { lower: 0, upper: Infinity };
91
+ // MSL-L001: required link missing.
92
+ if (rule.required && count === 0) {
93
+ diagnostics.push({
94
+ code: "MSL-L001",
95
+ severity: "error",
96
+ message: `${entry.displayId}: required link attribute '${linkName}' is missing`,
97
+ location: entry.location,
98
+ });
99
+ continue;
100
+ }
101
+ if (count === 0)
102
+ continue;
103
+ // MSL-L002: upper cardinality.
104
+ if (count > card.upper) {
105
+ diagnostics.push({
106
+ code: "MSL-L002",
107
+ severity: "error",
108
+ message: `${entry.displayId}: link '${linkName}' has ${count} values but max is ${formatUpper(card.upper)}`,
109
+ location: entry.location,
110
+ });
111
+ }
112
+ // MSL-L003: lower cardinality.
113
+ if (count < card.lower) {
114
+ diagnostics.push({
115
+ code: "MSL-L003",
116
+ severity: "error",
117
+ message: `${entry.displayId}: link '${linkName}' has ${count} values but min is ${card.lower}`,
118
+ location: entry.location,
119
+ });
120
+ }
121
+ // MSL-L004: target match for each resolved value.
122
+ for (const v of values) {
123
+ const target = graph.get(v);
124
+ if (!target)
125
+ continue;
126
+ if (!matchesAnyTarget(target, rule.target)) {
127
+ diagnostics.push({
128
+ code: "MSL-L004",
129
+ severity: "error",
130
+ message: `${entry.displayId}: link '${linkName}' targets ${target.displayId} ` +
131
+ `whose type '${target.type ?? "<unclassified>"}' / shape '${target.shape}' ` +
132
+ `is not accepted by rule target ${stringifyMatchers(rule.target)}`,
133
+ location: entry.location,
134
+ });
135
+ }
136
+ }
137
+ }
138
+ return diagnostics;
139
+ }
140
+ function formatUpper(u) {
141
+ return u === Infinity ? "N" : String(u);
142
+ }
143
+ function stringifyMatchers(matchers) {
144
+ const parts = matchers.map((m) => typeof m === "string" ? m : `{shape: ${m.shape}}`);
145
+ return `[${parts.join(", ")}]`;
146
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module core/validator/types
3
+ *
4
+ * Validator Stage 2 — entry classification.
5
+ *
6
+ * Each entry is assigned a profile-declared type either by an explicit
7
+ * `Type:` trailer attribute or by display-ID pattern matching. Un-classified
8
+ * entries in a strict profile (types declared) produce MSL-T003.
9
+ */
10
+ import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
11
+ /** Result of classifying a single entry. */
12
+ export interface ClassifyResult {
13
+ /** The assigned type name, or `undefined` if un-classified. */
14
+ readonly type: string | undefined;
15
+ readonly diagnostics: readonly Diagnostic[];
16
+ }
17
+ /**
18
+ * Classify one {@linkcode Entry} against the profile's type vocabulary.
19
+ *
20
+ * Order of precedence:
21
+ * 1. Explicit `Type:` trailer attribute (if present).
22
+ * 2. Display-ID pattern match across types whose `shape` matches
23
+ * `entry.shape`.
24
+ *
25
+ * Emits:
26
+ * - `MSL-T001` when explicit `Type:` value is not in the profile's type
27
+ * vocabulary.
28
+ * - `MSL-T002` when the display ID matches more than one type's pattern.
29
+ * - `MSL-T003` when strict mode (types declared) and no classification
30
+ * could be assigned.
31
+ */
32
+ export declare function classifyEntry(entry: Entry, profile: EffectiveProfile): ClassifyResult;
33
+ /** Result of running the classification stage over a batch of entries. */
34
+ export interface ClassifyStageResult {
35
+ /** Entries with `type` set on successful classification. */
36
+ readonly entries: readonly Entry[];
37
+ readonly diagnostics: readonly Diagnostic[];
38
+ }
39
+ /**
40
+ * Run classification across all entries. Produces new {@linkcode Entry}
41
+ * objects with `type` set when classification succeeds; un-classified
42
+ * entries pass through with `type` unchanged.
43
+ *
44
+ * Also emits `MSL-T004` when a classified entry's display ID violates the
45
+ * type's `display-id-pattern-enforcement` level.
46
+ */
47
+ export declare function classifyEntriesStage(entries: readonly Entry[], profile: EffectiveProfile): ClassifyStageResult;
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validator/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAEhB,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAGzB,4CAA4C;AAC5C,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,cAAc,CA4DhB;AAWD,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CAuBrB"}