@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,126 @@
1
+ /**
2
+ * @module core/validator/value_types
3
+ *
4
+ * Per-type value validators for profile-declared attributes. Each validator
5
+ * takes a string value and the attribute's declaration, returns `null` when
6
+ * valid or a short error message explaining why it's invalid.
7
+ *
8
+ * The top-level {@linkcode validateValue} dispatches on the declared type.
9
+ */
10
+ import { ULID_RE, URI_SCHEME_RE } from "../model/mod.js";
11
+ /**
12
+ * Validate one string value against an attribute's declared value type.
13
+ * Returns `null` when the value is valid, or a short human-readable detail
14
+ * string (without the attribute name or display ID — the caller composes the
15
+ * full diagnostic message).
16
+ */
17
+ export function validateValue(value, decl) {
18
+ const fn = VALIDATORS[decl.type];
19
+ return fn(value, decl);
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // Individual validators (Task 6.3 simple types)
23
+ // ---------------------------------------------------------------------------
24
+ const validateText = (_value, _decl) => {
25
+ return null;
26
+ };
27
+ const INTEGER_RE = /^-?\d+$/;
28
+ const validateInteger = (value, _decl) => {
29
+ return INTEGER_RE.test(value)
30
+ ? null
31
+ : `not a valid integer: '${value}' (expected digits optionally prefixed with '-')`;
32
+ };
33
+ const validateBoolean = (value, _decl) => {
34
+ return value === "true" || value === "false"
35
+ ? null
36
+ : `not a valid boolean: '${value}' (expected 'true' or 'false')`;
37
+ };
38
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
39
+ const validateDate = (value, _decl) => {
40
+ return DATE_RE.test(value)
41
+ ? null
42
+ : `not a valid ISO 8601 date: '${value}' (expected YYYY-MM-DD)`;
43
+ };
44
+ const validateEnum = (value, decl) => {
45
+ const values = decl.values ?? [];
46
+ if (values.includes(value))
47
+ return null;
48
+ return `value '${value}' is not in declared enum [${values.join(", ")}]`;
49
+ };
50
+ // ---------------------------------------------------------------------------
51
+ // Individual validators (Task 6.4 ID/URI types)
52
+ // ---------------------------------------------------------------------------
53
+ const validateId = (value, _decl) => {
54
+ if (ULID_RE.test(value))
55
+ return null;
56
+ if (URI_SCHEME_RE.test(value))
57
+ return null;
58
+ return `not a valid id: '${value}' (expected 26-char ULID or scheme-qualified URI)`;
59
+ };
60
+ const HTTP_URL_RE = /^https?:\/\//;
61
+ const validateUrl = (value, _decl) => {
62
+ return HTTP_URL_RE.test(value) ? null : `not a valid http(s) URL: '${value}'`;
63
+ };
64
+ const validateUri = (value, _decl) => {
65
+ return URI_SCHEME_RE.test(value)
66
+ ? null
67
+ : `not a valid URI: '${value}' (expected scheme-qualified per RFC 3986)`;
68
+ };
69
+ const validateExternalId = (value, _decl) => {
70
+ return value.trim().length > 0
71
+ ? null
72
+ : `external-id cannot be empty or whitespace-only`;
73
+ };
74
+ // ---------------------------------------------------------------------------
75
+ // Individual validators (Task 6.5 path / list / citation types)
76
+ // ---------------------------------------------------------------------------
77
+ // `/absolute` (POSIX) or `C:` / `C:\` / `C:/` (Windows) → absolute.
78
+ const ABSOLUTE_RE = /^(\/|[A-Za-z]:[\\/]?)/;
79
+ const validatePath = (value, _decl) => {
80
+ if (value.length === 0)
81
+ return `path cannot be empty`;
82
+ if (ABSOLUTE_RE.test(value)) {
83
+ return `absolute paths are not allowed: '${value}' (use a relative path)`;
84
+ }
85
+ return null;
86
+ };
87
+ const validatePathOrId = (value, decl) => {
88
+ if (ULID_RE.test(value))
89
+ return null;
90
+ if (URI_SCHEME_RE.test(value))
91
+ return null;
92
+ return validatePath(value, decl);
93
+ };
94
+ const TAG_RE = /^[A-Za-z0-9_\-.]+$/;
95
+ const validateTagList = (value, _decl) => {
96
+ if (value.length === 0)
97
+ return `tag cannot be empty`;
98
+ return TAG_RE.test(value)
99
+ ? null
100
+ : `invalid tag '${value}' (expected bareword of letters, digits, '_', '-', '.')`;
101
+ };
102
+ const validateCitation = (value, _decl) => {
103
+ return value.trim().length > 0
104
+ ? null
105
+ : `citation cannot be empty or whitespace-only`;
106
+ };
107
+ // ---------------------------------------------------------------------------
108
+ // Registry — all 14 value types are now implemented.
109
+ // ---------------------------------------------------------------------------
110
+ /** Registry of per-type validators. */
111
+ const VALIDATORS = {
112
+ text: validateText,
113
+ integer: validateInteger,
114
+ boolean: validateBoolean,
115
+ date: validateDate,
116
+ enum: validateEnum,
117
+ id: validateId,
118
+ "id-list": validateId,
119
+ uri: validateUri,
120
+ url: validateUrl,
121
+ "external-id": validateExternalId,
122
+ path: validatePath,
123
+ "path-or-id": validatePathOrId,
124
+ "tag-list": validateTagList,
125
+ citation: validateCitation,
126
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module compiler/inverses
3
+ *
4
+ * Inverse attribute generation — walks forward link attributes that carry
5
+ * an `inverse:` declaration and emits synthetic back-link values on target
6
+ * entries.
7
+ */
8
+ import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
9
+ /** Result of inverse generation. */
10
+ export interface GenerateInversesResult {
11
+ readonly entries: readonly Entry[];
12
+ readonly diagnostics: readonly Diagnostic[];
13
+ }
14
+ /**
15
+ * Generate inverse (back-link) attributes from forward link declarations.
16
+ *
17
+ * Walks every identified entry's `typedAttributes` for attributes that match
18
+ * an `inverse:` declaration in the effective profile, then accumulates
19
+ * back-links on target entries.
20
+ */
21
+ export declare function generateInverses(entries: readonly Entry[], profile: EffectiveProfile): GenerateInversesResult;
22
+ //# sourceMappingURL=inverses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inverses.d.ts","sourceRoot":"","sources":["../../src/compiler/inverses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAEzB,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAcD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,sBAAsB,CA4GxB"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * @module compiler/inverses
4
+ *
5
+ * Inverse attribute generation — walks forward link attributes that carry
6
+ * an `inverse:` declaration and emits synthetic back-link values on target
7
+ * entries.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.generateInverses = generateInverses;
11
+ /**
12
+ * Generate inverse (back-link) attributes from forward link declarations.
13
+ *
14
+ * Walks every identified entry's `typedAttributes` for attributes that match
15
+ * an `inverse:` declaration in the effective profile, then accumulates
16
+ * back-links on target entries.
17
+ */
18
+ function generateInverses(entries, profile) {
19
+ if (entries.length === 0) {
20
+ return { entries: [], diagnostics: [] };
21
+ }
22
+ // Step 1: Collect all inverse declarations from the profile
23
+ const inverseSpecs = collectInverseSpecs(profile);
24
+ if (inverseSpecs.length === 0) {
25
+ return { entries: [...entries], diagnostics: [] };
26
+ }
27
+ // Step 2: Index entries by id
28
+ const byId = new Map();
29
+ for (const e of entries) {
30
+ if (e.id !== undefined) {
31
+ byId.set(e.id, e);
32
+ }
33
+ }
34
+ // Step 3–5: Walk entries, accumulate back-links
35
+ // Map: targetId → Map<inverseAttrName, Set<sourceId>>
36
+ const generated = new Map();
37
+ for (const source of entries) {
38
+ if (source.shape !== "identified" || source.id === undefined)
39
+ continue;
40
+ const applicableSpecs = resolveApplicableSpecs(inverseSpecs, source.type);
41
+ for (const spec of applicableSpecs) {
42
+ const forwardValues = source.typedAttributes.get(spec.attrName);
43
+ if (!forwardValues)
44
+ continue;
45
+ for (const targetId of forwardValues) {
46
+ const target = byId.get(targetId);
47
+ if (!target || target.type !== spec.inverse.category)
48
+ continue;
49
+ let targetMap = generated.get(targetId);
50
+ if (!targetMap) {
51
+ targetMap = new Map();
52
+ generated.set(targetId, targetMap);
53
+ }
54
+ let idSet = targetMap.get(spec.inverse.name);
55
+ if (!idSet) {
56
+ idSet = new Set();
57
+ targetMap.set(spec.inverse.name, idSet);
58
+ }
59
+ idSet.add(source.id);
60
+ }
61
+ }
62
+ }
63
+ // Step 6–7: Merge generated values into entries, emit diagnostics
64
+ const diagnostics = [];
65
+ const result = [];
66
+ for (const e of entries) {
67
+ const targetInverses = e.id ? generated.get(e.id) : undefined;
68
+ if (!targetInverses) {
69
+ result.push(e);
70
+ continue;
71
+ }
72
+ const newAttrs = new Map(e.typedAttributes);
73
+ let changed = false;
74
+ for (const [inverseName, generatedIds] of targetInverses) {
75
+ const generatedArr = [...generatedIds];
76
+ const authored = e.typedAttributes.get(inverseName);
77
+ if (authored && authored.length > 0) {
78
+ const authoredSet = new Set(authored);
79
+ const genSet = generatedIds;
80
+ const match = authoredSet.size === genSet.size &&
81
+ [...authoredSet].every((v) => genSet.has(v));
82
+ if (!match) {
83
+ diagnostics.push({
84
+ code: "MSL-L005",
85
+ severity: "warning",
86
+ message: `authored "${inverseName}" on ${e.displayId} differs from generated inverse values`,
87
+ location: e.location,
88
+ });
89
+ // Union authored + generated
90
+ const union = new Set([...authored, ...generatedArr]);
91
+ newAttrs.set(inverseName, [...union]);
92
+ changed = true;
93
+ }
94
+ // If match, keep as-is
95
+ }
96
+ else {
97
+ newAttrs.set(inverseName, generatedArr);
98
+ changed = true;
99
+ }
100
+ }
101
+ if (changed) {
102
+ result.push({ ...e, typedAttributes: newAttrs });
103
+ }
104
+ else {
105
+ result.push(e);
106
+ }
107
+ }
108
+ return { entries: result, diagnostics };
109
+ }
110
+ /** Collect all inverse-bearing attribute declarations from the profile. */
111
+ function collectInverseSpecs(profile) {
112
+ const specs = [];
113
+ // Universal scope
114
+ for (const [, entry] of profile.attributes) {
115
+ if (entry.value.inverse) {
116
+ specs.push({
117
+ attrName: entry.value.name,
118
+ inverse: entry.value.inverse,
119
+ sourceType: null,
120
+ });
121
+ }
122
+ }
123
+ // Identified shape scope
124
+ for (const [, entry] of profile.identified.attributes) {
125
+ if (entry.value.inverse) {
126
+ specs.push({
127
+ attrName: entry.value.name,
128
+ inverse: entry.value.inverse,
129
+ sourceType: null,
130
+ });
131
+ }
132
+ }
133
+ // Type scopes
134
+ for (const [typeName, typeEntry] of profile.types) {
135
+ for (const [, attrEntry] of typeEntry.value.attributes) {
136
+ if (attrEntry.value.inverse) {
137
+ specs.push({
138
+ attrName: attrEntry.value.name,
139
+ inverse: attrEntry.value.inverse,
140
+ sourceType: typeName,
141
+ });
142
+ }
143
+ }
144
+ }
145
+ return specs;
146
+ }
147
+ /** Filter specs applicable to a source entry's type. */
148
+ function resolveApplicableSpecs(specs, sourceType) {
149
+ return specs.filter((s) => s.sourceType === null || s.sourceType === sourceType);
150
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module core/compiler/link_target
3
+ *
4
+ * MSL-T013: Tiered link-target severity. After links are extracted and
5
+ * inverses generated, check the state of each link target:
6
+ *
7
+ * | Target state | Severity |
8
+ * |---|---|
9
+ * | Active | OK (no diagnostic) |
10
+ * | Draft (Labels: DRAFT) | info |
11
+ * | Retired (Superseded-by: set OR Deprecated: set) | warning |
12
+ */
13
+ import type { Diagnostic, DisplayId, Entry, Link } from "../model/mod.js";
14
+ /**
15
+ * Check all link targets for retirement/draft state.
16
+ * Run after inverse generation so `Superseded-by:` is available.
17
+ */
18
+ export declare function checkLinkTargets(entries: ReadonlyMap<DisplayId, Entry>, links: readonly Link[]): Diagnostic[];
19
+ //# sourceMappingURL=link_target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"link_target.d.ts","sourceRoot":"","sources":["../../src/compiler/link_target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,EACtC,KAAK,EAAE,SAAS,IAAI,EAAE,GACrB,UAAU,EAAE,CA4Bd"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/compiler/link_target
4
+ *
5
+ * MSL-T013: Tiered link-target severity. After links are extracted and
6
+ * inverses generated, check the state of each link target:
7
+ *
8
+ * | Target state | Severity |
9
+ * |---|---|
10
+ * | Active | OK (no diagnostic) |
11
+ * | Draft (Labels: DRAFT) | info |
12
+ * | Retired (Superseded-by: set OR Deprecated: set) | warning |
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkLinkTargets = checkLinkTargets;
16
+ /**
17
+ * Check all link targets for retirement/draft state.
18
+ * Run after inverse generation so `Superseded-by:` is available.
19
+ */
20
+ function checkLinkTargets(entries, links) {
21
+ const diagnostics = [];
22
+ for (const link of links) {
23
+ const target = entries.get(link.to);
24
+ if (!target)
25
+ continue; // Unresolved — handled by MSL-T005/MSL-T012
26
+ const state = classifyTargetState(target);
27
+ if (state === "active")
28
+ continue;
29
+ if (state === "draft") {
30
+ diagnostics.push({
31
+ code: "MSL-T013",
32
+ severity: "info",
33
+ message: `${link.from}: link target '${link.to}' is marked DRAFT`,
34
+ location: link.location,
35
+ });
36
+ }
37
+ else {
38
+ diagnostics.push({
39
+ code: "MSL-T013",
40
+ severity: "warning",
41
+ message: `${link.from}: link target '${link.to}' is retired`,
42
+ location: link.location,
43
+ });
44
+ }
45
+ }
46
+ return diagnostics;
47
+ }
48
+ function classifyTargetState(entry) {
49
+ // Check for retirement markers
50
+ const hasDeprecated = entry.rawAttributes.some((a) => a.key === "Deprecated");
51
+ if (hasDeprecated)
52
+ return "retired";
53
+ const supersededBy = entry.typedAttributes.get("Superseded-by");
54
+ if (supersededBy && supersededBy.length > 0)
55
+ return "retired";
56
+ // Check for DRAFT label via typedAttributes
57
+ const labels = entry.typedAttributes.get("Labels");
58
+ if (labels && labels.includes("DRAFT"))
59
+ return "draft";
60
+ // Also check raw attributes for Labels containing DRAFT
61
+ for (const attr of entry.rawAttributes) {
62
+ if (attr.key === "Labels") {
63
+ const values = attr.value.split(",").map((s) => s.trim());
64
+ if (values.includes("DRAFT"))
65
+ return "draft";
66
+ }
67
+ }
68
+ return "active";
69
+ }
@@ -4,11 +4,13 @@
4
4
  * Compiler pipeline. Takes file paths, parses all entries, validates them,
5
5
  * builds a bidirectional traceability graph, and returns the compiled model.
6
6
  */
7
- import type { Diagnostic, DisplayId, Entry, Link } from "../model/mod.js";
7
+ import type { Diagnostic, DisplayId, Document, EffectiveProfile, Entry, Link } from "../model/mod.js";
8
8
  /** Options for {@linkcode compile}. */
9
9
  export interface CompileOptions {
10
10
  /** File reader function. Required — no default to avoid Deno dependency in library code. */
11
11
  readonly readFile: (path: string) => Promise<string>;
12
+ /** Active profile for inverse attribute generation. Optional — when absent, inverses are skipped. */
13
+ readonly profile?: EffectiveProfile;
12
14
  }
13
15
  /** Compiled project output with resolved traceability graph. */
14
16
  export interface CompileResult {
@@ -20,6 +22,8 @@ export interface CompileResult {
20
22
  readonly forward: ReadonlyMap<DisplayId, readonly Link[]>;
21
23
  /** Incoming links per entry (entry → sources pointing to it). */
22
24
  readonly reverse: ReadonlyMap<DisplayId, readonly Link[]>;
25
+ /** Documents keyed by file path. A file appears here only when it carried YAML front matter per ADR-007. */
26
+ readonly documents: ReadonlyMap<string, Document>;
23
27
  /** Diagnostics from parsing and validation. */
24
28
  readonly diagnostics: readonly Diagnostic[];
25
29
  }
@@ -34,4 +38,6 @@ export interface CompileResult {
34
38
  export declare function compile(paths: readonly string[], options: CompileOptions): Promise<CompileResult>;
35
39
  export { serializeCompileResult } from "./schema.js";
36
40
  export type { SerializedCompileResult } from "./schema.js";
41
+ export { generateInverses } from "./inverses.js";
42
+ export type { GenerateInversesResult } from "./inverses.js";
37
43
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,KAAK,EACL,IAAI,EAGL,MAAM,iBAAiB,CAAC;AAIzB,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACtD;AAED,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAChD,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAC1D,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAC1D,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CA6CxB;AAgFD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,IAAI,EAG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Property(exports, "__esModule", { value: true });
9
- exports.serializeCompileResult = void 0;
9
+ exports.generateInverses = exports.serializeCompileResult = void 0;
10
10
  exports.compile = compile;
11
11
  const mod_js_1 = require("../parser/mod.js");
12
12
  const mod_js_2 = require("../validator/mod.js");
13
+ const inverses_js_1 = require("./inverses.js");
14
+ const link_target_js_1 = require("./link_target.js");
13
15
  /**
14
16
  * Compile MarkSpec files from the given paths into a resolved
15
17
  * traceability graph.
@@ -22,6 +24,7 @@ async function compile(paths, options) {
22
24
  const read = options.readFile;
23
25
  const allEntries = [];
24
26
  const parseDiagnostics = [];
27
+ const documents = new Map();
25
28
  // Phase 1: Read and parse all files.
26
29
  for (const filePath of paths) {
27
30
  let content;
@@ -37,45 +40,78 @@ async function compile(paths, options) {
37
40
  });
38
41
  continue;
39
42
  }
40
- const entries = await (0, mod_js_1.parseFile)(content, { file: filePath });
41
- allEntries.push(...entries);
43
+ const result = await (0, mod_js_1.parseFile)(content, { file: filePath });
44
+ allEntries.push(...result.entries);
45
+ parseDiagnostics.push(...result.diagnostics);
46
+ if (result.document)
47
+ documents.set(filePath, result.document);
42
48
  }
43
49
  // Phase 2: Validate all entries.
44
50
  const validationResult = (0, mod_js_2.validate)(allEntries);
51
+ // Phase 2.5: Classify entries when a profile is loaded.
52
+ let classifiedEntries = allEntries;
53
+ if (options.profile) {
54
+ const stage2 = (0, mod_js_2.classifyEntriesStage)(allEntries, options.profile);
55
+ classifiedEntries = stage2.entries;
56
+ parseDiagnostics.push(...stage2.diagnostics);
57
+ }
45
58
  // Phase 3: Build traceability graph.
46
59
  // Keep first occurrence of each display ID (validator catches duplicates).
47
60
  const entries = new Map();
48
- for (const entry of allEntries) {
61
+ for (const entry of classifiedEntries) {
49
62
  if (!entries.has(entry.displayId)) {
50
63
  entries.set(entry.displayId, entry);
51
64
  }
52
65
  }
53
- const links = extractLinks(allEntries);
66
+ // Phase 3.5: Generate inverse attributes from profile declarations.
67
+ if (options.profile) {
68
+ const inverseResult = (0, inverses_js_1.generateInverses)([...entries.values()], options.profile);
69
+ parseDiagnostics.push(...inverseResult.diagnostics);
70
+ entries.clear();
71
+ for (const entry of inverseResult.entries) {
72
+ if (!entries.has(entry.displayId)) {
73
+ entries.set(entry.displayId, entry);
74
+ }
75
+ }
76
+ }
77
+ const links = extractLinks([...entries.values()]);
78
+ // MSL-T013: check link targets for draft/retired state.
79
+ const linkTargetDiags = (0, link_target_js_1.checkLinkTargets)(entries, links);
54
80
  const forward = buildAdjacency(links, (l) => l.from);
55
81
  const reverse = buildAdjacency(links, (l) => l.to);
56
82
  const diagnostics = [
57
83
  ...parseDiagnostics,
58
84
  ...validationResult.diagnostics,
85
+ ...linkTargetDiags,
59
86
  ];
60
- return { entries, links, forward, reverse, diagnostics };
87
+ return { entries, links, forward, reverse, documents, diagnostics };
61
88
  }
62
89
  /** Extract traceability links from entry attributes. */
63
90
  function extractLinks(entries) {
64
91
  const links = [];
65
92
  for (const entry of entries) {
66
- for (const attr of entry.attributes) {
93
+ for (const attr of entry.rawAttributes) {
67
94
  const extracted = extractLinksFromAttribute(entry.displayId, attr.key, attr.value, entry.location);
68
95
  links.push(...extracted);
69
96
  }
70
97
  }
71
98
  return links;
72
99
  }
100
+ /**
101
+ * Attributes whose value is `slug + optional free-text locator` per
102
+ * ADR-002 §2.6 (citation type + legacy Derived-from tolerance). The link
103
+ * target is the leading non-whitespace token only.
104
+ */
105
+ const LOCATOR_BEARING_ATTRS = new Set([
106
+ "Derived-from",
107
+ "References",
108
+ ]);
73
109
  /** Map an attribute key+value to zero or more links. */
74
110
  function extractLinksFromAttribute(from, key, value, location) {
75
111
  const kind = ATTR_TO_LINK_KIND[key];
76
112
  if (!kind)
77
113
  return [];
78
- if (key === "Derived-from") {
114
+ if (LOCATOR_BEARING_ATTRS.has(key)) {
79
115
  // Format: "ID §section" — extract ID part only.
80
116
  const idPart = value.split(/\s/)[0];
81
117
  if (idPart) {
@@ -83,7 +119,7 @@ function extractLinksFromAttribute(from, key, value, location) {
83
119
  }
84
120
  return [];
85
121
  }
86
- // Comma-separated targets (Satisfies, Allocates, Verifies, Implements).
122
+ // Comma-separated targets for id-list attributes.
87
123
  return value
88
124
  .split(",")
89
125
  .map((s) => s.trim())
@@ -91,16 +127,25 @@ function extractLinksFromAttribute(from, key, value, location) {
91
127
  .map((to) => ({ from, to, kind, location }));
92
128
  }
93
129
  /**
94
- * Attribute keys that produce traceability links.
95
- * Note: Constrains targets are component names (free text), not entry IDs,
96
- * so they are not included here. They would produce dangling links.
130
+ * Attribute keys that produce traceability links per ADR-002.
131
+ *
132
+ * Spec attributes: Satisfies, Derived-from, References, Allocated-to.
133
+ * Test attributes: Verifies, Tests.
134
+ * Element attributes: Realizes, Depends-on, Part-of, Generated-from.
135
+ * Universal: Supersedes (same-family).
97
136
  */
98
137
  const ATTR_TO_LINK_KIND = {
99
138
  "Satisfies": "satisfies",
100
139
  "Derived-from": "derived-from",
101
- "Allocates": "allocates",
140
+ "References": "references",
141
+ "Allocated-to": "allocated-to",
142
+ "Realizes": "realizes",
102
143
  "Verifies": "verifies",
103
- "Implements": "implements",
144
+ "Tests": "tests",
145
+ "Depends-on": "depends-on",
146
+ "Part-of": "part-of",
147
+ "Generated-from": "generated-from",
148
+ "Supersedes": "supersedes",
104
149
  };
105
150
  /** Build an adjacency map from links using a key selector. */
106
151
  function buildAdjacency(links, keyFn) {
@@ -119,3 +164,6 @@ function buildAdjacency(links, keyFn) {
119
164
  // Re-export serialization helper.
120
165
  var schema_js_1 = require("./schema.js");
121
166
  Object.defineProperty(exports, "serializeCompileResult", { enumerable: true, get: function () { return schema_js_1.serializeCompileResult; } });
167
+ // Re-export inverse generation.
168
+ var inverses_js_2 = require("./inverses.js");
169
+ Object.defineProperty(exports, "generateInverses", { enumerable: true, get: function () { return inverses_js_2.generateInverses; } });
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/compiler/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO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AAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,GACpB,uBAAuB,CAazB"}
@@ -18,11 +18,30 @@ exports.serializeCompileResult = serializeCompileResult;
18
18
  * @returns A plain object safe for `JSON.stringify`
19
19
  */
20
20
  function serializeCompileResult(result) {
21
+ const rawEntries = Object.fromEntries(result.entries);
22
+ const entries = {};
23
+ for (const [key, entry] of Object.entries(rawEntries)) {
24
+ entries[key] = serializeEntry(entry);
25
+ }
21
26
  return {
22
- entries: Object.fromEntries(result.entries),
27
+ entries,
23
28
  links: result.links,
24
29
  forward: Object.fromEntries(result.forward),
25
30
  reverse: Object.fromEntries(result.reverse),
26
31
  diagnostics: result.diagnostics,
27
32
  };
28
33
  }
34
+ /**
35
+ * Convert an {@linkcode Entry} to a JSON-safe form by replacing
36
+ * `typedAttributes` (a `ReadonlyMap`) with a plain object.
37
+ */
38
+ function serializeEntry(entry) {
39
+ if (!entry.typedAttributes || entry.typedAttributes.size === 0) {
40
+ return entry;
41
+ }
42
+ const typedObj = Object.fromEntries(entry.typedAttributes);
43
+ return {
44
+ ...entry,
45
+ typedAttributes: typedObj,
46
+ };
47
+ }