@driftsys/markspec 0.1.0 → 0.3.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 (242) hide show
  1. package/README.md +32 -8
  2. package/esm/_dnt.polyfills.d.ts +101 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +127 -0
  5. package/esm/compiler/inverses.d.ts +22 -0
  6. package/esm/compiler/inverses.d.ts.map +1 -0
  7. package/esm/compiler/inverses.js +147 -0
  8. package/esm/compiler/link_target.d.ts +19 -0
  9. package/esm/compiler/link_target.d.ts.map +1 -0
  10. package/esm/compiler/link_target.js +66 -0
  11. package/esm/compiler/mod.d.ts +43 -0
  12. package/esm/compiler/mod.d.ts.map +1 -0
  13. package/esm/compiler/mod.js +163 -0
  14. package/esm/compiler/schema.d.ts +38 -0
  15. package/esm/compiler/schema.d.ts.map +1 -0
  16. package/esm/compiler/schema.js +44 -0
  17. package/esm/config/markspec.d.ts +51 -0
  18. package/esm/config/markspec.d.ts.map +1 -0
  19. package/esm/config/markspec.js +216 -0
  20. package/esm/config/mod.d.ts +48 -0
  21. package/esm/config/mod.d.ts.map +1 -0
  22. package/esm/config/mod.js +243 -0
  23. package/esm/formatter/mod.d.ts +65 -0
  24. package/esm/formatter/mod.d.ts.map +1 -0
  25. package/esm/formatter/mod.js +306 -0
  26. package/esm/mod.d.ts +19 -0
  27. package/esm/mod.d.ts.map +1 -1
  28. package/esm/mod.js +18 -0
  29. package/esm/model/attributes.d.ts +47 -0
  30. package/esm/model/attributes.d.ts.map +1 -0
  31. package/esm/model/attributes.js +97 -0
  32. package/esm/model/mod.d.ts +381 -0
  33. package/esm/model/mod.d.ts.map +1 -0
  34. package/esm/model/mod.js +73 -0
  35. package/esm/model/profile.d.ts +189 -0
  36. package/esm/model/profile.d.ts.map +1 -0
  37. package/esm/model/profile.js +31 -0
  38. package/esm/parser/attributes.d.ts +48 -0
  39. package/esm/parser/attributes.d.ts.map +1 -0
  40. package/esm/parser/attributes.js +131 -0
  41. package/esm/parser/captions.d.ts +25 -0
  42. package/esm/parser/captions.d.ts.map +1 -0
  43. package/esm/parser/captions.js +148 -0
  44. package/esm/parser/directives.d.ts +29 -0
  45. package/esm/parser/directives.d.ts.map +1 -0
  46. package/esm/parser/directives.js +88 -0
  47. package/esm/parser/frontmatter.d.ts +53 -0
  48. package/esm/parser/frontmatter.d.ts.map +1 -0
  49. package/esm/parser/frontmatter.js +185 -0
  50. package/esm/parser/grammars.d.ts +22 -0
  51. package/esm/parser/grammars.d.ts.map +1 -0
  52. package/esm/parser/grammars.js +70 -0
  53. package/esm/parser/markdown.d.ts +32 -0
  54. package/esm/parser/markdown.d.ts.map +1 -0
  55. package/esm/parser/markdown.js +225 -0
  56. package/esm/parser/mod.d.ts +73 -0
  57. package/esm/parser/mod.d.ts.map +1 -0
  58. package/esm/parser/mod.js +89 -0
  59. package/esm/parser/references.d.ts +24 -0
  60. package/esm/parser/references.d.ts.map +1 -0
  61. package/esm/parser/references.js +71 -0
  62. package/esm/parser/remark.d.ts +9 -0
  63. package/esm/parser/remark.d.ts.map +1 -0
  64. package/esm/parser/remark.js +11 -0
  65. package/esm/parser/source.d.ts +33 -0
  66. package/esm/parser/source.d.ts.map +1 -0
  67. package/esm/parser/source.js +192 -0
  68. package/esm/profile/cache.d.ts +29 -0
  69. package/esm/profile/cache.d.ts.map +1 -0
  70. package/esm/profile/cache.js +45 -0
  71. package/esm/profile/chain.d.ts +42 -0
  72. package/esm/profile/chain.d.ts.map +1 -0
  73. package/esm/profile/chain.js +193 -0
  74. package/esm/profile/git-cache.d.ts +73 -0
  75. package/esm/profile/git-cache.d.ts.map +1 -0
  76. package/esm/profile/git-cache.js +96 -0
  77. package/esm/profile/load.d.ts +28 -0
  78. package/esm/profile/load.d.ts.map +1 -0
  79. package/esm/profile/load.js +50 -0
  80. package/esm/profile/manifest.d.ts +21 -0
  81. package/esm/profile/manifest.d.ts.map +1 -0
  82. package/esm/profile/manifest.js +830 -0
  83. package/esm/profile/merge.d.ts +26 -0
  84. package/esm/profile/merge.d.ts.map +1 -0
  85. package/esm/profile/merge.js +518 -0
  86. package/esm/profile/mod.d.ts +23 -0
  87. package/esm/profile/mod.d.ts.map +1 -0
  88. package/esm/profile/mod.js +14 -0
  89. package/esm/profile/npm.d.ts +51 -0
  90. package/esm/profile/npm.d.ts.map +1 -0
  91. package/esm/profile/npm.js +186 -0
  92. package/esm/profile/resolver.d.ts +60 -0
  93. package/esm/profile/resolver.d.ts.map +1 -0
  94. package/esm/profile/resolver.js +132 -0
  95. package/esm/reporter/mod.d.ts +31 -0
  96. package/esm/reporter/mod.d.ts.map +1 -0
  97. package/esm/reporter/mod.js +173 -0
  98. package/esm/validator/attributes.d.ts +43 -0
  99. package/esm/validator/attributes.d.ts.map +1 -0
  100. package/esm/validator/attributes.js +169 -0
  101. package/esm/validator/mod.d.ts +44 -0
  102. package/esm/validator/mod.d.ts.map +1 -0
  103. package/esm/validator/mod.js +214 -0
  104. package/esm/validator/normalize.d.ts +21 -0
  105. package/esm/validator/normalize.d.ts.map +1 -0
  106. package/esm/validator/normalize.js +58 -0
  107. package/esm/validator/pattern.d.ts +23 -0
  108. package/esm/validator/pattern.d.ts.map +1 -0
  109. package/esm/validator/pattern.js +44 -0
  110. package/esm/validator/pipeline.d.ts +30 -0
  111. package/esm/validator/pipeline.d.ts.map +1 -0
  112. package/esm/validator/pipeline.js +115 -0
  113. package/esm/validator/traceability.d.ts +48 -0
  114. package/esm/validator/traceability.d.ts.map +1 -0
  115. package/esm/validator/traceability.js +141 -0
  116. package/esm/validator/types.d.ts +48 -0
  117. package/esm/validator/types.d.ts.map +1 -0
  118. package/esm/validator/types.js +140 -0
  119. package/esm/validator/value_types.d.ts +20 -0
  120. package/esm/validator/value_types.d.ts.map +1 -0
  121. package/esm/validator/value_types.js +126 -0
  122. package/package.json +8 -1
  123. package/script/_dnt.polyfills.d.ts +101 -0
  124. package/script/_dnt.polyfills.d.ts.map +1 -0
  125. package/script/_dnt.polyfills.js +130 -0
  126. package/script/compiler/inverses.d.ts +22 -0
  127. package/script/compiler/inverses.d.ts.map +1 -0
  128. package/script/compiler/inverses.js +150 -0
  129. package/script/compiler/link_target.d.ts +19 -0
  130. package/script/compiler/link_target.d.ts.map +1 -0
  131. package/script/compiler/link_target.js +69 -0
  132. package/script/compiler/mod.d.ts +43 -0
  133. package/script/compiler/mod.d.ts.map +1 -0
  134. package/script/compiler/mod.js +169 -0
  135. package/script/compiler/schema.d.ts +38 -0
  136. package/script/compiler/schema.d.ts.map +1 -0
  137. package/script/compiler/schema.js +47 -0
  138. package/script/config/markspec.d.ts +51 -0
  139. package/script/config/markspec.d.ts.map +1 -0
  140. package/script/config/markspec.js +222 -0
  141. package/script/config/mod.d.ts +48 -0
  142. package/script/config/mod.d.ts.map +1 -0
  143. package/script/config/mod.js +250 -0
  144. package/script/formatter/mod.d.ts +65 -0
  145. package/script/formatter/mod.d.ts.map +1 -0
  146. package/script/formatter/mod.js +313 -0
  147. package/script/mod.d.ts +19 -0
  148. package/script/mod.d.ts.map +1 -1
  149. package/script/mod.js +65 -2
  150. package/script/model/attributes.d.ts +47 -0
  151. package/script/model/attributes.d.ts.map +1 -0
  152. package/script/model/attributes.js +101 -0
  153. package/script/model/mod.d.ts +381 -0
  154. package/script/model/mod.d.ts.map +1 -0
  155. package/script/model/mod.js +83 -0
  156. package/script/model/profile.d.ts +189 -0
  157. package/script/model/profile.d.ts.map +1 -0
  158. package/script/model/profile.js +34 -0
  159. package/script/parser/attributes.d.ts +48 -0
  160. package/script/parser/attributes.d.ts.map +1 -0
  161. package/script/parser/attributes.js +137 -0
  162. package/script/parser/captions.d.ts +25 -0
  163. package/script/parser/captions.d.ts.map +1 -0
  164. package/script/parser/captions.js +151 -0
  165. package/script/parser/directives.d.ts +29 -0
  166. package/script/parser/directives.d.ts.map +1 -0
  167. package/script/parser/directives.js +91 -0
  168. package/script/parser/frontmatter.d.ts +53 -0
  169. package/script/parser/frontmatter.d.ts.map +1 -0
  170. package/script/parser/frontmatter.js +188 -0
  171. package/script/parser/grammars.d.ts +22 -0
  172. package/script/parser/grammars.d.ts.map +1 -0
  173. package/script/parser/grammars.js +77 -0
  174. package/script/parser/markdown.d.ts +32 -0
  175. package/script/parser/markdown.d.ts.map +1 -0
  176. package/script/parser/markdown.js +228 -0
  177. package/script/parser/mod.d.ts +73 -0
  178. package/script/parser/mod.d.ts.map +1 -0
  179. package/script/parser/mod.js +101 -0
  180. package/script/parser/references.d.ts +24 -0
  181. package/script/parser/references.d.ts.map +1 -0
  182. package/script/parser/references.js +74 -0
  183. package/script/parser/remark.d.ts +9 -0
  184. package/script/parser/remark.d.ts.map +1 -0
  185. package/script/parser/remark.js +17 -0
  186. package/script/parser/source.d.ts +33 -0
  187. package/script/parser/source.d.ts.map +1 -0
  188. package/script/parser/source.js +198 -0
  189. package/script/profile/cache.d.ts +29 -0
  190. package/script/profile/cache.d.ts.map +1 -0
  191. package/script/profile/cache.js +48 -0
  192. package/script/profile/chain.d.ts +42 -0
  193. package/script/profile/chain.d.ts.map +1 -0
  194. package/script/profile/chain.js +229 -0
  195. package/script/profile/git-cache.d.ts +73 -0
  196. package/script/profile/git-cache.d.ts.map +1 -0
  197. package/script/profile/git-cache.js +104 -0
  198. package/script/profile/load.d.ts +28 -0
  199. package/script/profile/load.d.ts.map +1 -0
  200. package/script/profile/load.js +53 -0
  201. package/script/profile/manifest.d.ts +21 -0
  202. package/script/profile/manifest.d.ts.map +1 -0
  203. package/script/profile/manifest.js +833 -0
  204. package/script/profile/merge.d.ts +26 -0
  205. package/script/profile/merge.d.ts.map +1 -0
  206. package/script/profile/merge.js +521 -0
  207. package/script/profile/mod.d.ts +23 -0
  208. package/script/profile/mod.d.ts.map +1 -0
  209. package/script/profile/mod.js +31 -0
  210. package/script/profile/npm.d.ts +51 -0
  211. package/script/profile/npm.d.ts.map +1 -0
  212. package/script/profile/npm.js +191 -0
  213. package/script/profile/resolver.d.ts +60 -0
  214. package/script/profile/resolver.d.ts.map +1 -0
  215. package/script/profile/resolver.js +136 -0
  216. package/script/reporter/mod.d.ts +31 -0
  217. package/script/reporter/mod.d.ts.map +1 -0
  218. package/script/reporter/mod.js +176 -0
  219. package/script/validator/attributes.d.ts +43 -0
  220. package/script/validator/attributes.d.ts.map +1 -0
  221. package/script/validator/attributes.js +173 -0
  222. package/script/validator/mod.d.ts +44 -0
  223. package/script/validator/mod.d.ts.map +1 -0
  224. package/script/validator/mod.js +231 -0
  225. package/script/validator/normalize.d.ts +21 -0
  226. package/script/validator/normalize.d.ts.map +1 -0
  227. package/script/validator/normalize.js +61 -0
  228. package/script/validator/pattern.d.ts +23 -0
  229. package/script/validator/pattern.d.ts.map +1 -0
  230. package/script/validator/pattern.js +47 -0
  231. package/script/validator/pipeline.d.ts +30 -0
  232. package/script/validator/pipeline.d.ts.map +1 -0
  233. package/script/validator/pipeline.js +118 -0
  234. package/script/validator/traceability.d.ts +48 -0
  235. package/script/validator/traceability.d.ts.map +1 -0
  236. package/script/validator/traceability.js +146 -0
  237. package/script/validator/types.d.ts +48 -0
  238. package/script/validator/types.d.ts.map +1 -0
  239. package/script/validator/types.js +144 -0
  240. package/script/validator/value_types.d.ts +20 -0
  241. package/script/validator/value_types.d.ts.map +1 -0
  242. package/script/validator/value_types.js +129 -0
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/attributes
4
+ *
5
+ * Validator Stage 3 — typed attribute validation.
6
+ *
7
+ * Runs after Stage 2 classification. For each entry, computes the effective
8
+ * attribute scope (universal ∪ shape ∪ type) and checks:
9
+ * - Required presence (MSL-A001)
10
+ * - Cardinality (MSL-A002 upper / MSL-A003 lower)
11
+ * - Value-type conformance (MSL-A004, delegated to value_types.ts)
12
+ * - Unknown attributes (MSL-A005 warning)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.effectiveScope = effectiveScope;
16
+ exports.validateAttributesForEntry = validateAttributesForEntry;
17
+ const mod_js_1 = require("../model/mod.js");
18
+ const value_types_js_1 = require("./value_types.js");
19
+ /** Core-reserved attribute keys that are always permitted regardless of profile. */
20
+ const CORE_RESERVED_KEYS = new Set([
21
+ "Id",
22
+ "Type",
23
+ ...mod_js_1.UNIVERSAL_ATTRIBUTE_KEYS,
24
+ ]);
25
+ /**
26
+ * Compute the effective attribute scope for a given entry against the
27
+ * profile. Uses universal + shape scope always; adds type scope only when
28
+ * `entry.type` is set and the type is declared in the profile.
29
+ */
30
+ function effectiveScope(entry, profile) {
31
+ const required = [];
32
+ const attributes = new Map();
33
+ // Universal scope.
34
+ required.push(...profile.required.value);
35
+ for (const [name, attrEntry] of profile.attributes) {
36
+ attributes.set(name, attrEntry.value);
37
+ }
38
+ // Shape scope.
39
+ const shapeScope = entry.shape === "identified"
40
+ ? profile.identified
41
+ : profile.referenced;
42
+ required.push(...shapeScope.required.value);
43
+ for (const [name, e] of shapeScope.attributes) {
44
+ attributes.set(name, e.value);
45
+ }
46
+ // Type scope (only when classified).
47
+ if (entry.type !== undefined) {
48
+ const typeEntry = profile.types.get(entry.type);
49
+ if (typeEntry !== undefined) {
50
+ required.push(...typeEntry.value.required.value);
51
+ for (const [name, e] of typeEntry.value.attributes) {
52
+ attributes.set(name, e.value);
53
+ }
54
+ }
55
+ }
56
+ // Synthesize implicit id-list attribute declarations for trace rule link
57
+ // names that aren't explicitly declared as attributes. A trace rule IS an
58
+ // id-list attribute by definition — profile authors shouldn't have to
59
+ // declare it in both places.
60
+ const shapeTrace = entry.shape === "identified"
61
+ ? profile.identified.traceability
62
+ : profile.referenced.traceability;
63
+ for (const [name] of shapeTrace) {
64
+ if (!attributes.has(name)) {
65
+ attributes.set(name, synthesizedLinkAttr(name));
66
+ }
67
+ }
68
+ if (entry.type !== undefined) {
69
+ const typeEntry = profile.types.get(entry.type);
70
+ if (typeEntry !== undefined) {
71
+ for (const [name] of typeEntry.value.traceability) {
72
+ if (!attributes.has(name)) {
73
+ attributes.set(name, synthesizedLinkAttr(name));
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return { required, attributes };
79
+ }
80
+ /**
81
+ * Build a synthesized `id-list` AttrDecl for a trace rule's link name when
82
+ * the profile doesn't explicitly declare the attribute. This keeps Stage 2.5
83
+ * (CSV normalization) and Stage 3 (unknown-attribute check) honest without
84
+ * requiring profile authors to double-declare link attributes.
85
+ *
86
+ * Cardinality defaults to 0..N (unbounded list). Cardinality on the trace
87
+ * rule itself is enforced by Stage 4 (traceability), which reads the rule
88
+ * directly.
89
+ */
90
+ function synthesizedLinkAttr(name) {
91
+ return {
92
+ name,
93
+ type: "id-list",
94
+ required: false,
95
+ cardinality: { lower: 0, upper: Infinity },
96
+ };
97
+ }
98
+ /**
99
+ * Run Stage 3 structural + value-type checks for one entry. Returns all
100
+ * diagnostics the entry produced.
101
+ *
102
+ * Task 6.2 ships required / cardinality / unknown checks. Task 6.6 wires in
103
+ * value-type conformance (MSL-A004) through the value-types registry.
104
+ */
105
+ function validateAttributesForEntry(entry, profile) {
106
+ const diagnostics = [];
107
+ const scope = effectiveScope(entry, profile);
108
+ const present = entry.typedAttributes;
109
+ // MSL-A001: required attribute missing.
110
+ for (const name of scope.required) {
111
+ if (!present.has(name)) {
112
+ diagnostics.push({
113
+ code: "MSL-A001",
114
+ severity: "error",
115
+ message: `${entry.displayId}: required attribute '${name}' is missing`,
116
+ location: entry.location,
117
+ });
118
+ }
119
+ }
120
+ // Iterate attributes present on the entry.
121
+ for (const [name, values] of present) {
122
+ const decl = scope.attributes.get(name);
123
+ if (decl === undefined) {
124
+ // MSL-A005: unknown attribute (warn). Skip core-reserved keys.
125
+ if (!CORE_RESERVED_KEYS.has(name)) {
126
+ diagnostics.push({
127
+ code: "MSL-A005",
128
+ severity: "warning",
129
+ message: `${entry.displayId}: attribute '${name}' is not declared in the profile scope`,
130
+ location: entry.location,
131
+ });
132
+ }
133
+ continue;
134
+ }
135
+ // MSL-A002: upper cardinality.
136
+ if (values.length > decl.cardinality.upper) {
137
+ diagnostics.push({
138
+ code: "MSL-A002",
139
+ severity: "error",
140
+ message: `${entry.displayId}: attribute '${name}' has ${values.length} values ` +
141
+ `but max is ${formatUpper(decl.cardinality.upper)}`,
142
+ location: entry.location,
143
+ });
144
+ }
145
+ // MSL-A003: lower cardinality (only when attribute is present).
146
+ if (values.length < decl.cardinality.lower) {
147
+ diagnostics.push({
148
+ code: "MSL-A003",
149
+ severity: "error",
150
+ message: `${entry.displayId}: attribute '${name}' has ${values.length} values ` +
151
+ `but min is ${decl.cardinality.lower}`,
152
+ location: entry.location,
153
+ });
154
+ }
155
+ // MSL-A004: value-type conformance.
156
+ for (const v of values) {
157
+ const detail = (0, value_types_js_1.validateValue)(v, decl);
158
+ if (detail !== null) {
159
+ diagnostics.push({
160
+ code: "MSL-A004",
161
+ severity: "error",
162
+ message: `${entry.displayId}: attribute '${name}' has invalid value: ${detail}`,
163
+ location: entry.location,
164
+ });
165
+ break; // one diagnostic per attribute is enough
166
+ }
167
+ }
168
+ }
169
+ return diagnostics;
170
+ }
171
+ function formatUpper(u) {
172
+ return u === Infinity ? "N" : String(u);
173
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @module validator
3
+ *
4
+ * Core structural validator. Performs file-local checks and cross-file
5
+ * checks for structural integrity: well-formed `Id:` values, unique
6
+ * display IDs, unique identity values, resolvable cross-references.
7
+ *
8
+ * Shape discrimination follows the language spec Part 2.4: `Id:` value
9
+ * is a bare ULID → identified entry; `Id:` value is a scheme-qualified
10
+ * URI (RFC 3986) → referenced entry; anything else is an error.
11
+ *
12
+ * Type-level rules (required-per-type attributes, relation target-type
13
+ * constraints, enum vocabularies) are profile-declared and evaluated by
14
+ * a profile-aware validator layer (not in the core).
15
+ */
16
+ import type { Attribute, Diagnostic, Entry } from "../model/mod.js";
17
+ /** Result of a validation pass. */
18
+ export interface ValidateResult {
19
+ /** Diagnostics found during validation. */
20
+ readonly diagnostics: readonly Diagnostic[];
21
+ /** Whether validation passed with no errors. */
22
+ readonly valid: boolean;
23
+ }
24
+ /**
25
+ * Validate a set of parsed entries for structural correctness and
26
+ * cross-reference integrity.
27
+ *
28
+ * @param entries - Parsed entries to validate
29
+ */
30
+ export declare function validate(entries: readonly Entry[]): ValidateResult;
31
+ export declare function indexByDisplayId(entries: readonly Entry[]): ReadonlyMap<string, Entry>;
32
+ export declare function findAttr(attrs: readonly Attribute[], key: string): Attribute | undefined;
33
+ export { runPipeline } from "./pipeline.js";
34
+ export type { PipelineResult } from "./pipeline.js";
35
+ export { classifyEntriesStage, classifyEntry } from "./types.js";
36
+ export type { ClassifyResult, ClassifyStageResult } from "./types.js";
37
+ export { compileDisplayIdPattern } from "./pattern.js";
38
+ export { effectiveScope, validateAttributesForEntry } from "./attributes.js";
39
+ export type { EffectiveAttrScope } from "./attributes.js";
40
+ export { validateValue } from "./value_types.js";
41
+ export type { ValueValidator } from "./value_types.js";
42
+ export { normalizeListValues } from "./normalize.js";
43
+ export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
44
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAWpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,cAAc,CAQlE;AAyLD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAM5B;AAGD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAEvB;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ /**
3
+ * @module validator
4
+ *
5
+ * Core structural validator. Performs file-local checks and cross-file
6
+ * checks for structural integrity: well-formed `Id:` values, unique
7
+ * display IDs, unique identity values, resolvable cross-references.
8
+ *
9
+ * Shape discrimination follows the language spec Part 2.4: `Id:` value
10
+ * is a bare ULID → identified entry; `Id:` value is a scheme-qualified
11
+ * URI (RFC 3986) → referenced entry; anything else is an error.
12
+ *
13
+ * Type-level rules (required-per-type attributes, relation target-type
14
+ * constraints, enum vocabularies) are profile-declared and evaluated by
15
+ * a profile-aware validator layer (not in the core).
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.validateTraceabilityForEntry = exports.matchesAnyTarget = exports.effectiveTraceRules = exports.normalizeListValues = exports.validateValue = exports.validateAttributesForEntry = exports.effectiveScope = exports.compileDisplayIdPattern = exports.classifyEntry = exports.classifyEntriesStage = exports.runPipeline = void 0;
19
+ exports.validate = validate;
20
+ exports.indexByDisplayId = indexByDisplayId;
21
+ exports.findAttr = findAttr;
22
+ const mod_js_1 = require("../model/mod.js");
23
+ /** Universal attribute keys the core recognizes. */
24
+ const UNIVERSAL_KEYS = new Set(mod_js_1.UNIVERSAL_ATTRIBUTE_KEYS);
25
+ /**
26
+ * Validate a set of parsed entries for structural correctness and
27
+ * cross-reference integrity.
28
+ *
29
+ * @param entries - Parsed entries to validate
30
+ */
31
+ function validate(entries) {
32
+ const diagnostics = [];
33
+ checkStructural(entries, diagnostics);
34
+ checkReferences(entries, diagnostics);
35
+ const valid = !diagnostics.some((d) => d.severity === "error");
36
+ return { diagnostics, valid };
37
+ }
38
+ /** MSL-R structural checks on individual entries and cross-entry uniqueness. */
39
+ function checkStructural(entries, diagnostics) {
40
+ const displayIds = new Map();
41
+ const ids = new Map();
42
+ for (const entry of entries) {
43
+ // MSL-R003: exactly one `Id:` attribute per entry.
44
+ const idAttrs = entry.rawAttributes.filter((a) => a.key === mod_js_1.IDENTITY_KEY);
45
+ if (idAttrs.length === 0) {
46
+ diagnostics.push({
47
+ code: "MSL-R003",
48
+ severity: "error",
49
+ message: `${entry.displayId}: missing Id: attribute`,
50
+ location: entry.location,
51
+ });
52
+ }
53
+ else if (idAttrs.length > 1) {
54
+ diagnostics.push({
55
+ code: "MSL-R003",
56
+ severity: "error",
57
+ message: `${entry.displayId}: multiple Id: attributes (${idAttrs.length}) — exactly one is required`,
58
+ location: entry.location,
59
+ });
60
+ }
61
+ // MSL-R004: `Id:` value must be a ULID or a scheme-qualified URI.
62
+ if (idAttrs.length > 0) {
63
+ const value = idAttrs[0].value;
64
+ const isUlid = mod_js_1.ULID_RE.test(value);
65
+ const isUri = mod_js_1.URI_SCHEME_RE.test(value);
66
+ if (!isUlid && !isUri) {
67
+ diagnostics.push({
68
+ code: "MSL-R004",
69
+ severity: "error",
70
+ message: `${entry.displayId}: Id: value '${value}' is neither a bare ULID nor a scheme-qualified URI`,
71
+ location: entry.location,
72
+ });
73
+ }
74
+ // Shape consistency: ULID ↔ identified, URI ↔ referenced.
75
+ if (isUlid && entry.shape !== "identified") {
76
+ diagnostics.push({
77
+ code: "MSL-R004",
78
+ severity: "error",
79
+ message: `${entry.displayId}: Id: value is a ULID but entry shape is ${entry.shape}`,
80
+ location: entry.location,
81
+ });
82
+ }
83
+ else if (isUri && entry.shape !== "referenced") {
84
+ diagnostics.push({
85
+ code: "MSL-R004",
86
+ severity: "error",
87
+ message: `${entry.displayId}: Id: value is a URI but entry shape is ${entry.shape}`,
88
+ location: entry.location,
89
+ });
90
+ }
91
+ }
92
+ // MSL-R006: Display ID unique across all entries.
93
+ const existingDisplay = displayIds.get(entry.displayId);
94
+ if (existingDisplay) {
95
+ diagnostics.push({
96
+ code: "MSL-R006",
97
+ severity: "error",
98
+ message: `duplicate display ID '${entry.displayId}' (also at ${existingDisplay.location.file}:${existingDisplay.location.line})`,
99
+ location: entry.location,
100
+ });
101
+ }
102
+ else {
103
+ displayIds.set(entry.displayId, entry);
104
+ }
105
+ // MSL-R005: identity value unique across all entries.
106
+ if (entry.id) {
107
+ const existingId = ids.get(entry.id);
108
+ if (existingId) {
109
+ diagnostics.push({
110
+ code: "MSL-R005",
111
+ severity: "error",
112
+ message: `duplicate Id '${entry.id}' (also at ${existingId.location.file}:${existingId.location.line})`,
113
+ location: entry.location,
114
+ });
115
+ }
116
+ else {
117
+ ids.set(entry.id, entry);
118
+ }
119
+ }
120
+ // MSL-R010: Unknown attributes are warnings in the core. A
121
+ // profile-aware validator widens this check to include profile-declared
122
+ // attributes; until then, anything outside the universal set is
123
+ // unrecognized.
124
+ for (const attr of entry.rawAttributes) {
125
+ if (!UNIVERSAL_KEYS.has(attr.key) && attr.key !== "Type") {
126
+ diagnostics.push({
127
+ code: "MSL-R010",
128
+ severity: "warning",
129
+ message: `${entry.displayId}: unknown attribute '${attr.key}' (not in core universal set; profile-declared attributes are permitted when a profile is loaded)`,
130
+ location: entry.location,
131
+ });
132
+ }
133
+ }
134
+ }
135
+ }
136
+ /** Cross-reference integrity checks. */
137
+ function checkReferences(entries, diagnostics) {
138
+ // Build a display-ID index for cross-reference resolution.
139
+ const byDisplayId = new Map();
140
+ for (const entry of entries) {
141
+ if (!byDisplayId.has(entry.displayId)) {
142
+ byDisplayId.set(entry.displayId, entry);
143
+ }
144
+ }
145
+ // Also index by `Id:` value so references may target ULIDs or URIs
146
+ // directly (profile tooling commonly accepts either).
147
+ const byId = new Map();
148
+ for (const entry of entries) {
149
+ if (entry.id && !byId.has(entry.id)) {
150
+ byId.set(entry.id, entry);
151
+ }
152
+ }
153
+ // MSL-T012: `Supersedes:` — the one baked-in relation. Target must
154
+ // resolve; profile rules check type/shape compatibility separately.
155
+ for (const entry of entries) {
156
+ const supersedes = entry.rawAttributes.find((a) => a.key === "Supersedes");
157
+ if (!supersedes)
158
+ continue;
159
+ const target = supersedes.value.trim();
160
+ const resolved = byDisplayId.get(target) ?? byId.get(target);
161
+ if (!resolved) {
162
+ diagnostics.push({
163
+ code: "MSL-T012",
164
+ severity: "error",
165
+ message: `${entry.displayId}: Supersedes target '${target}' not found`,
166
+ location: entry.location,
167
+ });
168
+ }
169
+ }
170
+ // MSL-T005: `References:` — citations must resolve to a referenced
171
+ // entry. This is a universal relation (citing identified → referenced).
172
+ for (const entry of entries) {
173
+ const citations = entry.rawAttributes.filter((a) => a.key === "References");
174
+ for (const attr of citations) {
175
+ // Citation format: "slug [free-text locator]"; take the first token.
176
+ const slug = attr.value.split(/\s/)[0];
177
+ if (!slug)
178
+ continue;
179
+ const resolved = byDisplayId.get(slug) ?? byId.get(slug);
180
+ if (!resolved) {
181
+ diagnostics.push({
182
+ code: "MSL-T005",
183
+ severity: "error",
184
+ message: `${entry.displayId}: References: unresolved citation '${slug}'`,
185
+ location: entry.location,
186
+ });
187
+ continue;
188
+ }
189
+ if (resolved.shape !== "referenced") {
190
+ diagnostics.push({
191
+ code: "MSL-T005",
192
+ severity: "error",
193
+ message: `${entry.displayId}: References: target '${slug}' is shape '${resolved.shape}', expected 'referenced'`,
194
+ location: entry.location,
195
+ });
196
+ }
197
+ }
198
+ }
199
+ }
200
+ // Re-exported for callers that want to write their own cross-reference
201
+ // checks over the core index.
202
+ function indexByDisplayId(entries) {
203
+ const map = new Map();
204
+ for (const entry of entries) {
205
+ if (!map.has(entry.displayId))
206
+ map.set(entry.displayId, entry);
207
+ }
208
+ return map;
209
+ }
210
+ // Retained export for downstream consumers.
211
+ function findAttr(attrs, key) {
212
+ return attrs.find((a) => a.key === key);
213
+ }
214
+ var pipeline_js_1 = require("./pipeline.js");
215
+ Object.defineProperty(exports, "runPipeline", { enumerable: true, get: function () { return pipeline_js_1.runPipeline; } });
216
+ var types_js_1 = require("./types.js");
217
+ Object.defineProperty(exports, "classifyEntriesStage", { enumerable: true, get: function () { return types_js_1.classifyEntriesStage; } });
218
+ Object.defineProperty(exports, "classifyEntry", { enumerable: true, get: function () { return types_js_1.classifyEntry; } });
219
+ var pattern_js_1 = require("./pattern.js");
220
+ Object.defineProperty(exports, "compileDisplayIdPattern", { enumerable: true, get: function () { return pattern_js_1.compileDisplayIdPattern; } });
221
+ var attributes_js_1 = require("./attributes.js");
222
+ Object.defineProperty(exports, "effectiveScope", { enumerable: true, get: function () { return attributes_js_1.effectiveScope; } });
223
+ Object.defineProperty(exports, "validateAttributesForEntry", { enumerable: true, get: function () { return attributes_js_1.validateAttributesForEntry; } });
224
+ var value_types_js_1 = require("./value_types.js");
225
+ Object.defineProperty(exports, "validateValue", { enumerable: true, get: function () { return value_types_js_1.validateValue; } });
226
+ var normalize_js_1 = require("./normalize.js");
227
+ Object.defineProperty(exports, "normalizeListValues", { enumerable: true, get: function () { return normalize_js_1.normalizeListValues; } });
228
+ var traceability_js_1 = require("./traceability.js");
229
+ Object.defineProperty(exports, "effectiveTraceRules", { enumerable: true, get: function () { return traceability_js_1.effectiveTraceRules; } });
230
+ Object.defineProperty(exports, "matchesAnyTarget", { enumerable: true, get: function () { return traceability_js_1.matchesAnyTarget; } });
231
+ Object.defineProperty(exports, "validateTraceabilityForEntry", { enumerable: true, get: function () { return traceability_js_1.validateTraceabilityForEntry; } });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module core/validator/normalize
3
+ *
4
+ * Stage 2.5 normalization: split comma-separated values for profile-declared
5
+ * list-typed attributes.
6
+ *
7
+ * Runs between Stage 2 (classification) and Stage 3 (typed attributes). The
8
+ * core parser already CSV-splits values for core-catalog list types; this
9
+ * step handles list types declared by a profile (which the parser doesn't
10
+ * see). Idempotent — values that don't contain commas pass through unchanged.
11
+ *
12
+ * Empty-string fragments (e.g. from `"a,,b"`) are dropped; surrounding
13
+ * whitespace is trimmed.
14
+ */
15
+ import type { EffectiveProfile, Entry } from "../model/mod.js";
16
+ /**
17
+ * Return a new Entry with list-typed attribute values split on commas. If no
18
+ * change is needed, returns the input entry unchanged (reference equality).
19
+ */
20
+ export declare function normalizeListValues(entry: Entry, profile: EffectiveProfile): Entry;
21
+ //# sourceMappingURL=normalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/validator/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAa,MAAM,iBAAiB,CAAC;AAK1E;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,KAAK,CAoBP"}
@@ -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"}