@driftsys/markspec 0.3.0 → 0.5.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 (331) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +56 -6
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +372 -41
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +21 -8
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +16 -5
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +100 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +58 -2
  68. package/esm/model/palette.d.ts +18 -0
  69. package/esm/model/palette.d.ts.map +1 -0
  70. package/esm/model/palette.js +23 -0
  71. package/esm/model/profile.d.ts +33 -27
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/model/source_introspection.d.ts +26 -0
  74. package/esm/model/source_introspection.d.ts.map +1 -0
  75. package/esm/model/source_introspection.js +77 -0
  76. package/esm/model/type_hierarchy.d.ts +51 -0
  77. package/esm/model/type_hierarchy.d.ts.map +1 -0
  78. package/esm/model/type_hierarchy.js +126 -0
  79. package/esm/model/uri_scheme_map.d.ts +21 -0
  80. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  81. package/esm/model/uri_scheme_map.js +66 -0
  82. package/esm/parser/attributes.d.ts.map +1 -1
  83. package/esm/parser/attributes.js +9 -6
  84. package/esm/parser/entity_refs.d.ts +53 -0
  85. package/esm/parser/entity_refs.d.ts.map +1 -0
  86. package/esm/parser/entity_refs.js +151 -0
  87. package/esm/parser/glossary.d.ts +43 -0
  88. package/esm/parser/glossary.d.ts.map +1 -0
  89. package/esm/parser/glossary.js +217 -0
  90. package/esm/parser/markdown.d.ts +10 -3
  91. package/esm/parser/markdown.d.ts.map +1 -1
  92. package/esm/parser/markdown.js +241 -11
  93. package/esm/parser/mod.d.ts +1 -0
  94. package/esm/parser/mod.d.ts.map +1 -1
  95. package/esm/parser/mod.js +4 -3
  96. package/esm/parser/source.d.ts +20 -0
  97. package/esm/parser/source.d.ts.map +1 -1
  98. package/esm/parser/source.js +4 -4
  99. package/esm/profile/chain.js +3 -13
  100. package/esm/profile/colors.d.ts +26 -0
  101. package/esm/profile/colors.d.ts.map +1 -0
  102. package/esm/profile/colors.js +46 -0
  103. package/esm/profile/introspect.d.ts +135 -0
  104. package/esm/profile/introspect.d.ts.map +1 -0
  105. package/esm/profile/introspect.js +378 -0
  106. package/esm/profile/load.d.ts.map +1 -1
  107. package/esm/profile/load.js +67 -0
  108. package/esm/profile/manifest.d.ts.map +1 -1
  109. package/esm/profile/manifest.js +278 -104
  110. package/esm/profile/merge.js +139 -39
  111. package/esm/profile/mod.d.ts +3 -4
  112. package/esm/profile/mod.d.ts.map +1 -1
  113. package/esm/profile/mod.js +6 -2
  114. package/esm/reporter/mod.js +4 -4
  115. package/esm/util/fence.d.ts +30 -0
  116. package/esm/util/fence.d.ts.map +1 -0
  117. package/esm/util/fence.js +40 -0
  118. package/esm/validator/attributes.d.ts +3 -3
  119. package/esm/validator/attributes.d.ts.map +1 -1
  120. package/esm/validator/attributes.js +1 -18
  121. package/esm/validator/body_blocks.d.ts +38 -0
  122. package/esm/validator/body_blocks.d.ts.map +1 -0
  123. package/esm/validator/body_blocks.js +218 -0
  124. package/esm/validator/caption_convention.d.ts +29 -0
  125. package/esm/validator/caption_convention.d.ts.map +1 -0
  126. package/esm/validator/caption_convention.js +58 -0
  127. package/esm/validator/captions.d.ts +22 -0
  128. package/esm/validator/captions.d.ts.map +1 -0
  129. package/esm/validator/captions.js +137 -0
  130. package/esm/validator/component_schemes.d.ts +73 -0
  131. package/esm/validator/component_schemes.d.ts.map +1 -0
  132. package/esm/validator/component_schemes.js +375 -0
  133. package/esm/validator/feature_ac.d.ts +28 -0
  134. package/esm/validator/feature_ac.d.ts.map +1 -0
  135. package/esm/validator/feature_ac.js +102 -0
  136. package/esm/validator/listing.d.ts +42 -0
  137. package/esm/validator/listing.d.ts.map +1 -0
  138. package/esm/validator/listing.js +295 -0
  139. package/esm/validator/mod.d.ts +2 -0
  140. package/esm/validator/mod.d.ts.map +1 -1
  141. package/esm/validator/mod.js +253 -12
  142. package/esm/validator/modal_keywords.d.ts +23 -0
  143. package/esm/validator/modal_keywords.d.ts.map +1 -0
  144. package/esm/validator/modal_keywords.js +137 -0
  145. package/esm/validator/per_type_attrs.d.ts +29 -0
  146. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  147. package/esm/validator/per_type_attrs.js +75 -0
  148. package/esm/validator/pipeline.d.ts +7 -2
  149. package/esm/validator/pipeline.d.ts.map +1 -1
  150. package/esm/validator/pipeline.js +40 -7
  151. package/esm/validator/trace_types.d.ts +26 -0
  152. package/esm/validator/trace_types.d.ts.map +1 -0
  153. package/esm/validator/trace_types.js +232 -0
  154. package/esm/validator/traceability.d.ts +3 -4
  155. package/esm/validator/traceability.d.ts.map +1 -1
  156. package/esm/validator/traceability.js +5 -10
  157. package/esm/validator/type_resolution.d.ts +67 -0
  158. package/esm/validator/type_resolution.d.ts.map +1 -0
  159. package/esm/validator/type_resolution.js +140 -0
  160. package/esm/validator/types.d.ts +45 -0
  161. package/esm/validator/types.d.ts.map +1 -1
  162. package/esm/validator/types.js +128 -16
  163. package/esm/validator/value_types.d.ts +8 -0
  164. package/esm/validator/value_types.d.ts.map +1 -1
  165. package/esm/validator/value_types.js +8 -1
  166. package/package.json +1 -1
  167. package/script/ast/build.d.ts +70 -0
  168. package/script/ast/build.d.ts.map +1 -0
  169. package/script/ast/build.js +610 -0
  170. package/script/ast/equivalence.d.ts +18 -0
  171. package/script/ast/equivalence.d.ts.map +1 -0
  172. package/script/ast/equivalence.js +59 -0
  173. package/script/ast/nodes.d.ts +221 -0
  174. package/script/ast/nodes.d.ts.map +1 -0
  175. package/script/ast/nodes.js +13 -0
  176. package/script/ast/normalize.d.ts +67 -0
  177. package/script/ast/normalize.d.ts.map +1 -0
  178. package/script/ast/normalize.js +258 -0
  179. package/script/ast/render.d.ts +34 -0
  180. package/script/ast/render.d.ts.map +1 -0
  181. package/script/ast/render.js +218 -0
  182. package/script/compiler/inverses.d.ts +2 -8
  183. package/script/compiler/inverses.d.ts.map +1 -1
  184. package/script/compiler/inverses.js +50 -14
  185. package/script/compiler/manifest.d.ts +59 -0
  186. package/script/compiler/manifest.d.ts.map +1 -0
  187. package/script/compiler/manifest.js +51 -0
  188. package/script/compiler/mod.d.ts +9 -1
  189. package/script/compiler/mod.d.ts.map +1 -1
  190. package/script/compiler/mod.js +21 -2
  191. package/script/compiler/ndjson_writer.d.ts +50 -0
  192. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  193. package/script/compiler/ndjson_writer.js +78 -0
  194. package/script/compiler/schema.d.ts +18 -1
  195. package/script/compiler/schema.d.ts.map +1 -1
  196. package/script/compiler/schema.js +18 -8
  197. package/script/config/mod.d.ts.map +1 -1
  198. package/script/config/mod.js +54 -0
  199. package/script/formatter/mod.d.ts +56 -6
  200. package/script/formatter/mod.d.ts.map +1 -1
  201. package/script/formatter/mod.js +375 -41
  202. package/script/formatter/synth_ulid.d.ts +21 -0
  203. package/script/formatter/synth_ulid.d.ts.map +1 -0
  204. package/script/formatter/synth_ulid.js +67 -0
  205. package/script/lint/mod.d.ts +10 -0
  206. package/script/lint/mod.d.ts.map +1 -0
  207. package/script/lint/mod.js +12 -0
  208. package/script/lint/rules/lexicon.d.ts +24 -0
  209. package/script/lint/rules/lexicon.d.ts.map +1 -0
  210. package/script/lint/rules/lexicon.js +240 -0
  211. package/script/lint/rules/struct.d.ts +17 -0
  212. package/script/lint/rules/struct.d.ts.map +1 -0
  213. package/script/lint/rules/struct.js +59 -0
  214. package/script/lint/rules/suppression.d.ts +19 -0
  215. package/script/lint/rules/suppression.d.ts.map +1 -0
  216. package/script/lint/rules/suppression.js +80 -0
  217. package/script/lint/runner.d.ts +39 -0
  218. package/script/lint/runner.d.ts.map +1 -0
  219. package/script/lint/runner.js +116 -0
  220. package/script/lint/types.d.ts +19 -0
  221. package/script/lint/types.d.ts.map +1 -0
  222. package/script/lint/types.js +10 -0
  223. package/script/mod.d.ts +21 -8
  224. package/script/mod.d.ts.map +1 -1
  225. package/script/mod.js +58 -32
  226. package/script/model/attributes.d.ts.map +1 -1
  227. package/script/model/attributes.js +163 -2
  228. package/script/model/discriminating_attr.d.ts +33 -0
  229. package/script/model/discriminating_attr.d.ts.map +1 -0
  230. package/script/model/discriminating_attr.js +77 -0
  231. package/script/model/mod.d.ts +100 -3
  232. package/script/model/mod.d.ts.map +1 -1
  233. package/script/model/mod.js +67 -3
  234. package/script/model/palette.d.ts +18 -0
  235. package/script/model/palette.d.ts.map +1 -0
  236. package/script/model/palette.js +26 -0
  237. package/script/model/profile.d.ts +33 -27
  238. package/script/model/profile.d.ts.map +1 -1
  239. package/script/model/source_introspection.d.ts +26 -0
  240. package/script/model/source_introspection.d.ts.map +1 -0
  241. package/script/model/source_introspection.js +80 -0
  242. package/script/model/type_hierarchy.d.ts +51 -0
  243. package/script/model/type_hierarchy.d.ts.map +1 -0
  244. package/script/model/type_hierarchy.js +130 -0
  245. package/script/model/uri_scheme_map.d.ts +21 -0
  246. package/script/model/uri_scheme_map.d.ts.map +1 -0
  247. package/script/model/uri_scheme_map.js +69 -0
  248. package/script/parser/attributes.d.ts.map +1 -1
  249. package/script/parser/attributes.js +9 -6
  250. package/script/parser/entity_refs.d.ts +53 -0
  251. package/script/parser/entity_refs.d.ts.map +1 -0
  252. package/script/parser/entity_refs.js +155 -0
  253. package/script/parser/glossary.d.ts +43 -0
  254. package/script/parser/glossary.d.ts.map +1 -0
  255. package/script/parser/glossary.js +221 -0
  256. package/script/parser/markdown.d.ts +10 -3
  257. package/script/parser/markdown.d.ts.map +1 -1
  258. package/script/parser/markdown.js +240 -10
  259. package/script/parser/mod.d.ts +1 -0
  260. package/script/parser/mod.d.ts.map +1 -1
  261. package/script/parser/mod.js +8 -4
  262. package/script/parser/source.d.ts +20 -0
  263. package/script/parser/source.d.ts.map +1 -1
  264. package/script/parser/source.js +4 -1
  265. package/script/profile/chain.js +3 -13
  266. package/script/profile/colors.d.ts +26 -0
  267. package/script/profile/colors.d.ts.map +1 -0
  268. package/script/profile/colors.js +49 -0
  269. package/script/profile/introspect.d.ts +135 -0
  270. package/script/profile/introspect.d.ts.map +1 -0
  271. package/script/profile/introspect.js +381 -0
  272. package/script/profile/load.d.ts.map +1 -1
  273. package/script/profile/load.js +67 -0
  274. package/script/profile/manifest.d.ts.map +1 -1
  275. package/script/profile/manifest.js +280 -106
  276. package/script/profile/merge.js +139 -39
  277. package/script/profile/mod.d.ts +3 -4
  278. package/script/profile/mod.d.ts.map +1 -1
  279. package/script/profile/mod.js +9 -6
  280. package/script/reporter/mod.js +4 -4
  281. package/script/util/fence.d.ts +30 -0
  282. package/script/util/fence.d.ts.map +1 -0
  283. package/script/util/fence.js +44 -0
  284. package/script/validator/attributes.d.ts +3 -3
  285. package/script/validator/attributes.d.ts.map +1 -1
  286. package/script/validator/attributes.js +1 -18
  287. package/script/validator/body_blocks.d.ts +38 -0
  288. package/script/validator/body_blocks.d.ts.map +1 -0
  289. package/script/validator/body_blocks.js +221 -0
  290. package/script/validator/caption_convention.d.ts +29 -0
  291. package/script/validator/caption_convention.d.ts.map +1 -0
  292. package/script/validator/caption_convention.js +61 -0
  293. package/script/validator/captions.d.ts +22 -0
  294. package/script/validator/captions.d.ts.map +1 -0
  295. package/script/validator/captions.js +140 -0
  296. package/script/validator/component_schemes.d.ts +73 -0
  297. package/script/validator/component_schemes.d.ts.map +1 -0
  298. package/script/validator/component_schemes.js +384 -0
  299. package/script/validator/feature_ac.d.ts +28 -0
  300. package/script/validator/feature_ac.d.ts.map +1 -0
  301. package/script/validator/feature_ac.js +105 -0
  302. package/script/validator/listing.d.ts +42 -0
  303. package/script/validator/listing.d.ts.map +1 -0
  304. package/script/validator/listing.js +298 -0
  305. package/script/validator/mod.d.ts +2 -0
  306. package/script/validator/mod.d.ts.map +1 -1
  307. package/script/validator/mod.js +256 -14
  308. package/script/validator/modal_keywords.d.ts +23 -0
  309. package/script/validator/modal_keywords.d.ts.map +1 -0
  310. package/script/validator/modal_keywords.js +140 -0
  311. package/script/validator/per_type_attrs.d.ts +29 -0
  312. package/script/validator/per_type_attrs.d.ts.map +1 -0
  313. package/script/validator/per_type_attrs.js +78 -0
  314. package/script/validator/pipeline.d.ts +7 -2
  315. package/script/validator/pipeline.d.ts.map +1 -1
  316. package/script/validator/pipeline.js +39 -6
  317. package/script/validator/trace_types.d.ts +26 -0
  318. package/script/validator/trace_types.d.ts.map +1 -0
  319. package/script/validator/trace_types.js +235 -0
  320. package/script/validator/traceability.d.ts +3 -4
  321. package/script/validator/traceability.d.ts.map +1 -1
  322. package/script/validator/traceability.js +5 -10
  323. package/script/validator/type_resolution.d.ts +67 -0
  324. package/script/validator/type_resolution.d.ts.map +1 -0
  325. package/script/validator/type_resolution.js +146 -0
  326. package/script/validator/types.d.ts +45 -0
  327. package/script/validator/types.d.ts.map +1 -1
  328. package/script/validator/types.js +131 -16
  329. package/script/validator/value_types.d.ts +8 -0
  330. package/script/validator/value_types.d.ts.map +1 -1
  331. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,384 @@
1
+ "use strict";
2
+ /**
3
+ * @module validator/component_schemes
4
+ *
5
+ * Component Id-scheme parsers for `markspec:components` listings.
6
+ *
7
+ * Each exported parser accepts a raw `Id:` URI string and returns either
8
+ * `{ ok: true, type: string }` (accepted, with the inferred Item type) or
9
+ * `{ ok: false, code: "MSL-Lxxx", message: string }` (rejected with a
10
+ * specific diagnostic code). Parsers are pure: no I/O, no external fetches.
11
+ *
12
+ * Spec §5 fixes the grammars; this module is their TypeScript implementation.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.isSchemeQualifiedUri = isSchemeQualifiedUri;
16
+ exports.parsePurl = parsePurl;
17
+ exports.parseMfgId = parseMfgId;
18
+ exports.parseGtinId = parseGtinId;
19
+ exports.parseCpeId = parseCpeId;
20
+ exports.parseUrnSystemOrTool = parseUrnSystemOrTool;
21
+ exports.parseComponentScheme = parseComponentScheme;
22
+ /** Guard: does the Id: value look like a URI for a known or generic scheme? */
23
+ function isSchemeQualifiedUri(value) {
24
+ return /^[A-Za-z][A-Za-z0-9+\-.]*:/.test(value);
25
+ }
26
+ // ---------------------------------------------------------------------------
27
+ // §5.1 pkg: — Package URL (purl)
28
+ // ---------------------------------------------------------------------------
29
+ /**
30
+ * Recognised purl types that map directly to a core Item type.
31
+ * Unmapped types fall back to Component (abstract) with MSL-L030 info.
32
+ */
33
+ const PURL_TYPE_MAP = new Map([
34
+ ["cargo", "SoftwareComponent"],
35
+ ["npm", "SoftwareComponent"],
36
+ ["maven", "SoftwareComponent"],
37
+ ["pypi", "SoftwareComponent"],
38
+ ["go", "SoftwareComponent"],
39
+ ["nuget", "SoftwareComponent"],
40
+ ["deno", "SoftwareComponent"],
41
+ ["swift", "SoftwareComponent"],
42
+ ["firmware", "SoftwareComponent"],
43
+ ["hw", "HardwareComponent"],
44
+ ["device", "HardwareComponent"],
45
+ ]);
46
+ /**
47
+ * Parse a `pkg:` URI per the Package URL specification.
48
+ *
49
+ * Validates: scheme is "pkg", type and name are non-empty, subpath
50
+ * presence → SoftwareUnit. Accepts any well-formed purl and classifies it;
51
+ * rejects malformed purls with MSL-L031.
52
+ */
53
+ function parsePurl(value) {
54
+ // Must start with "pkg:"
55
+ if (!value.startsWith("pkg:")) {
56
+ return {
57
+ ok: false,
58
+ code: "MSL-L031",
59
+ message: `malformed purl: scheme must be 'pkg' (got '${value.split(":")[0]}')`,
60
+ };
61
+ }
62
+ // After "pkg:", the remainder is: type/[namespace/]name[@version][?qualifiers][#subpath]
63
+ const rest = value.slice("pkg:".length);
64
+ // type is required: everything before the first "/"
65
+ const slashIdx = rest.indexOf("/");
66
+ if (slashIdx < 0 || slashIdx === 0) {
67
+ return {
68
+ ok: false,
69
+ code: "MSL-L031",
70
+ message: `malformed purl: 'type' component is required (format: pkg:type/name)`,
71
+ };
72
+ }
73
+ const purlType = rest.slice(0, slashIdx).toLowerCase();
74
+ const afterType = rest.slice(slashIdx + 1);
75
+ // name is required: strip optional qualifiers and subpath, then check
76
+ // namespace/name vs just name (slash-separated paths before @/? end with the name)
77
+ const atIdx = afterType.indexOf("@");
78
+ const qIdx = afterType.indexOf("?");
79
+ const hashIdx = afterType.indexOf("#");
80
+ // Name ends at the first of @, ?, # (or end of string)
81
+ let nameEnd = afterType.length;
82
+ if (atIdx >= 0)
83
+ nameEnd = Math.min(nameEnd, atIdx);
84
+ if (qIdx >= 0)
85
+ nameEnd = Math.min(nameEnd, qIdx);
86
+ if (hashIdx >= 0)
87
+ nameEnd = Math.min(nameEnd, hashIdx);
88
+ const nameAndNamespace = afterType.slice(0, nameEnd);
89
+ const nameParts = nameAndNamespace.split("/").filter((p) => p.length > 0);
90
+ if (nameParts.length === 0) {
91
+ return {
92
+ ok: false,
93
+ code: "MSL-L031",
94
+ message: `malformed purl: 'name' component is required (format: pkg:type/name)`,
95
+ };
96
+ }
97
+ // The last non-empty segment is the name
98
+ const name = nameParts[nameParts.length - 1];
99
+ if (name.length === 0) {
100
+ return {
101
+ ok: false,
102
+ code: "MSL-L031",
103
+ message: `malformed purl: 'name' component must not be empty`,
104
+ };
105
+ }
106
+ // subpath present → SoftwareUnit (spec §5.1-d)
107
+ const hasSubpath = hashIdx >= 0 && afterType.slice(hashIdx + 1).length > 0;
108
+ if (hasSubpath) {
109
+ return { ok: true, type: "SoftwareUnit" };
110
+ }
111
+ // Map type to Item type; unknown types fall back to Component (MSL-L030 caller)
112
+ const itemType = PURL_TYPE_MAP.get(purlType) ?? null;
113
+ if (itemType === null) {
114
+ // Return a special signal: caller emits MSL-L030 and uses Component fallback
115
+ return { ok: true, type: "Component" };
116
+ }
117
+ return { ok: true, type: itemType };
118
+ }
119
+ // ---------------------------------------------------------------------------
120
+ // §5.2 mfg: — manufacturer part
121
+ // ---------------------------------------------------------------------------
122
+ /** Token character set: ALPHA / DIGIT / "-" / "." / "_" */
123
+ const TOKEN_CHAR_RE = /^[A-Za-z0-9\-._]+$/;
124
+ /**
125
+ * Parse a `mfg:vendor:partno` URI per spec §5.2.
126
+ *
127
+ * Rules: literal "mfg:" prefix, non-empty vendor token, ":", non-empty
128
+ * partno (may contain further ":"). Invalid → MSL-L032.
129
+ */
130
+ function parseMfgId(value) {
131
+ if (!value.startsWith("mfg:")) {
132
+ return {
133
+ ok: false,
134
+ code: "MSL-L032",
135
+ message: `malformed mfg id: must start with 'mfg:'`,
136
+ };
137
+ }
138
+ const afterPrefix = value.slice("mfg:".length);
139
+ // First ":" ends the vendor
140
+ const colonIdx = afterPrefix.indexOf(":");
141
+ if (colonIdx < 0) {
142
+ return {
143
+ ok: false,
144
+ code: "MSL-L032",
145
+ message: `malformed mfg id: missing ':' separator between vendor and partno`,
146
+ };
147
+ }
148
+ const vendor = afterPrefix.slice(0, colonIdx);
149
+ const partno = afterPrefix.slice(colonIdx + 1);
150
+ if (vendor.length === 0) {
151
+ return {
152
+ ok: false,
153
+ code: "MSL-L032",
154
+ message: `malformed mfg id: vendor must not be empty`,
155
+ };
156
+ }
157
+ if (!TOKEN_CHAR_RE.test(vendor)) {
158
+ return {
159
+ ok: false,
160
+ code: "MSL-L032",
161
+ message: `malformed mfg id: vendor '${vendor}' contains invalid characters (allowed: [A-Za-z0-9-._ ])`,
162
+ };
163
+ }
164
+ if (partno.length === 0) {
165
+ return {
166
+ ok: false,
167
+ code: "MSL-L032",
168
+ message: `malformed mfg id: partno must not be empty`,
169
+ };
170
+ }
171
+ // Validate all segments of the partno (split by ":" for per-segment check)
172
+ for (const segment of partno.split(":")) {
173
+ if (segment.length === 0) {
174
+ return {
175
+ ok: false,
176
+ code: "MSL-L032",
177
+ message: `malformed mfg id: partno segment must not be empty`,
178
+ };
179
+ }
180
+ if (!TOKEN_CHAR_RE.test(segment)) {
181
+ return {
182
+ ok: false,
183
+ code: "MSL-L032",
184
+ message: `malformed mfg id: partno segment '${segment}' contains invalid characters`,
185
+ };
186
+ }
187
+ }
188
+ return { ok: true, type: "HardwareComponent" };
189
+ }
190
+ // ---------------------------------------------------------------------------
191
+ // §5.3 gtin: — GS1 Global Trade Item Number
192
+ // ---------------------------------------------------------------------------
193
+ const VALID_GTIN_LENGTHS = new Set([8, 12, 13, 14]);
194
+ /**
195
+ * Compute the GS1 mod-10 check digit for a digit string (without the
196
+ * check digit itself). Returns the expected final digit (0–9).
197
+ *
198
+ * Algorithm: multiply alternating digits from right by 3 and 1 (rightmost
199
+ * non-check digit × 3), sum, check digit = (10 - (sum mod 10)) mod 10.
200
+ */
201
+ function computeGtinCheckDigit(digits) {
202
+ let sum = 0;
203
+ for (let i = 0; i < digits.length; i++) {
204
+ const posFromRight = digits.length - i; // 1-based from the right (excl. check)
205
+ const multiplier = posFromRight % 2 === 1 ? 3 : 1;
206
+ sum += parseInt(digits[i], 10) * multiplier;
207
+ }
208
+ return (10 - (sum % 10)) % 10;
209
+ }
210
+ /**
211
+ * Parse a `gtin:` URI per spec §5.3 and GS1 General Specifications.
212
+ *
213
+ * Validates: exactly 8/12/13/14 digits, correct GS1 check digit.
214
+ * Errors: MSL-L033 (wrong length), MSL-L034 (bad check digit).
215
+ */
216
+ function parseGtinId(value) {
217
+ if (!value.startsWith("gtin:")) {
218
+ return {
219
+ ok: false,
220
+ code: "MSL-L033",
221
+ message: `malformed gtin id: must start with 'gtin:'`,
222
+ };
223
+ }
224
+ const digits = value.slice("gtin:".length);
225
+ if (!/^\d+$/.test(digits)) {
226
+ return {
227
+ ok: false,
228
+ code: "MSL-L033",
229
+ message: `malformed gtin id: expected digits after 'gtin:' (got '${digits}')`,
230
+ };
231
+ }
232
+ if (!VALID_GTIN_LENGTHS.has(digits.length)) {
233
+ return {
234
+ ok: false,
235
+ code: "MSL-L033",
236
+ message: `gtin: expected 8/12/13/14 digits, got ${digits.length}`,
237
+ };
238
+ }
239
+ // Verify check digit
240
+ const payload = digits.slice(0, -1);
241
+ const givenCheck = parseInt(digits[digits.length - 1], 10);
242
+ const expectedCheck = computeGtinCheckDigit(payload);
243
+ if (givenCheck !== expectedCheck) {
244
+ return {
245
+ ok: false,
246
+ code: "MSL-L034",
247
+ message: `gtin: check digit mismatch (got ${givenCheck}, expected ${expectedCheck})`,
248
+ };
249
+ }
250
+ return { ok: true, type: "HardwareComponent" };
251
+ }
252
+ // ---------------------------------------------------------------------------
253
+ // §5.4 cpe: — Common Platform Enumeration 2.3
254
+ // ---------------------------------------------------------------------------
255
+ const VALID_CPE_PARTS = new Set(["a", "o", "h"]);
256
+ /**
257
+ * Parse a `cpe:` URI per spec §5.4 and NIST IR 7695.
258
+ *
259
+ * Accepts only the CPE 2.3 formatted-string binding (`cpe:2.3:…`).
260
+ * Errors: MSL-L035 (legacy 2.2 URI binding), MSL-L036 (invalid part).
261
+ */
262
+ function parseCpeId(value) {
263
+ if (!value.startsWith("cpe:")) {
264
+ return {
265
+ ok: false,
266
+ code: "MSL-L035",
267
+ message: `malformed cpe id: must start with 'cpe:'`,
268
+ };
269
+ }
270
+ // Reject CPE 2.2 URI binding (cpe:/)
271
+ if (value.startsWith("cpe:/")) {
272
+ return {
273
+ ok: false,
274
+ code: "MSL-L035",
275
+ message: `cpe: use 2.3 formatted-string binding (cpe:2.3:…), not the legacy URI binding (cpe:/…)`,
276
+ };
277
+ }
278
+ // Must start with cpe:2.3:
279
+ if (!value.startsWith("cpe:2.3:")) {
280
+ return {
281
+ ok: false,
282
+ code: "MSL-L035",
283
+ message: `cpe: use 2.3 formatted-string binding (cpe:2.3:…); '${value.slice(0, 10)}…' is not recognised`,
284
+ };
285
+ }
286
+ // After cpe:2.3: there must be exactly 11 colon-separated components
287
+ const components = value.slice("cpe:2.3:".length).split(":");
288
+ if (components.length !== 11) {
289
+ return {
290
+ ok: false,
291
+ code: "MSL-L035",
292
+ message: `cpe: expected 11 colon-separated components after 'cpe:2.3:' per NIST IR 7695 §6.2, got ${components.length}`,
293
+ };
294
+ }
295
+ const part = components[0].toLowerCase();
296
+ if (!VALID_CPE_PARTS.has(part)) {
297
+ return {
298
+ ok: false,
299
+ code: "MSL-L036",
300
+ message: `cpe: 'part' must be 'a' (application), 'o' (OS), or 'h' (hardware); got '${components[0]}'`,
301
+ };
302
+ }
303
+ const itemType = part === "h" ? "HardwareComponent" : "SoftwareComponent";
304
+ return { ok: true, type: itemType };
305
+ }
306
+ // ---------------------------------------------------------------------------
307
+ // §5.5 urn:system: and urn:tool:
308
+ // ---------------------------------------------------------------------------
309
+ /** URN segment character set per spec §5.5 ABNF. */
310
+ const SEGMENT_CHAR_RE = /^[A-Za-z0-9\-._]+$/;
311
+ /**
312
+ * Parse a `urn:system:` or `urn:tool:` URI per spec §5.5.
313
+ *
314
+ * Validates: non-empty segments separated by ":", all chars in
315
+ * ALPHA/DIGIT/-/./_ . Invalid → MSL-L037.
316
+ */
317
+ function parseUrnSystemOrTool(value) {
318
+ const isSystem = value.startsWith("urn:system:");
319
+ const isTool = value.startsWith("urn:tool:");
320
+ if (!isSystem && !isTool) {
321
+ return {
322
+ ok: false,
323
+ code: "MSL-L037",
324
+ message: `malformed urn id: expected 'urn:system:' or 'urn:tool:' prefix`,
325
+ };
326
+ }
327
+ const prefix = isSystem ? "urn:system:" : "urn:tool:";
328
+ const body = value.slice(prefix.length);
329
+ if (body.length === 0) {
330
+ return {
331
+ ok: false,
332
+ code: "MSL-L037",
333
+ message: `malformed ${prefix} id: path must not be empty after '${prefix}'`,
334
+ };
335
+ }
336
+ const segments = body.split(":");
337
+ for (const seg of segments) {
338
+ if (seg.length === 0) {
339
+ return {
340
+ ok: false,
341
+ code: "MSL-L037",
342
+ message: `malformed ${prefix} id: segment must not be empty (consecutive ':' or trailing ':')`,
343
+ };
344
+ }
345
+ if (!SEGMENT_CHAR_RE.test(seg)) {
346
+ return {
347
+ ok: false,
348
+ code: "MSL-L037",
349
+ message: `malformed ${prefix} id: segment '${seg}' contains invalid characters (allowed: [A-Za-z0-9-._])`,
350
+ };
351
+ }
352
+ }
353
+ const itemType = isSystem ? "Component" : "SoftwareComponent";
354
+ return { ok: true, type: itemType };
355
+ }
356
+ // ---------------------------------------------------------------------------
357
+ // Main dispatcher
358
+ // ---------------------------------------------------------------------------
359
+ /**
360
+ * Classify a component entry's `Id:` value against the six core schemes.
361
+ *
362
+ * Returns a {@linkcode SchemeParseResult}:
363
+ * - `{ ok: true, type }` on recognition (may still emit MSL-L030 for
364
+ * unknown purl types — the caller handles that).
365
+ * - `{ ok: false, code, message }` for scheme-level parse errors.
366
+ * - `null` when the value doesn't look like any component scheme (caller
367
+ * should check if it's a valid RFC 3986 URI for the generic fallback).
368
+ *
369
+ * Matching is longest-declared-prefix-wins per spec §5.
370
+ */
371
+ function parseComponentScheme(value) {
372
+ if (value.startsWith("pkg:"))
373
+ return parsePurl(value);
374
+ if (value.startsWith("mfg:"))
375
+ return parseMfgId(value);
376
+ if (value.startsWith("gtin:"))
377
+ return parseGtinId(value);
378
+ if (value.startsWith("cpe:"))
379
+ return parseCpeId(value);
380
+ if (value.startsWith("urn:system:") || value.startsWith("urn:tool:")) {
381
+ return parseUrnSystemOrTool(value);
382
+ }
383
+ return null;
384
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module core/validator/feature_ac
3
+ *
4
+ * MSL-B044 validator — entry body contains both a Feature (Gherkin)
5
+ * block and a separate list labelled "Acceptance criteria" (the
6
+ * alternative form). Only one canonical form is required; having both
7
+ * is redundant and indicates an inconsistency the author should resolve.
8
+ *
9
+ * Detection heuristic (spec §4.5 "MSL-B044"):
10
+ * - The entry body contains at least one `FeatureNode`.
11
+ * - The entry body also contains a `ListNode` that is introduced by
12
+ * a `ParagraphNode` (or is headed by text in a paragraph) whose
13
+ * text matches "acceptance criteria" case-insensitively — i.e., a
14
+ * paragraph immediately preceding a list whose prose trims to
15
+ * "acceptance criteria" (or starts with it), OR a paragraph
16
+ * immediately following the list that reads like a label, OR the
17
+ * first item text of the list begins with "Acceptance criteria".
18
+ *
19
+ * This is an AST-only check; no external dependency.
20
+ */
21
+ import type { Diagnostic, Entry } from "../model/mod.js";
22
+ /**
23
+ * Validate that an entry's body does not contain both a Feature block
24
+ * (Gherkin) and a separate "Acceptance criteria" list. Emits MSL-B044
25
+ * (warning) when both are present.
26
+ */
27
+ export declare function validateFeatureAc(entry: Entry): readonly Diagnostic[];
28
+ //# sourceMappingURL=feature_ac.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature_ac.d.ts","sourceRoot":"","sources":["../../src/validator/feature_ac.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA2DzD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CA2BrE"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/validator/feature_ac
4
+ *
5
+ * MSL-B044 validator — entry body contains both a Feature (Gherkin)
6
+ * block and a separate list labelled "Acceptance criteria" (the
7
+ * alternative form). Only one canonical form is required; having both
8
+ * is redundant and indicates an inconsistency the author should resolve.
9
+ *
10
+ * Detection heuristic (spec §4.5 "MSL-B044"):
11
+ * - The entry body contains at least one `FeatureNode`.
12
+ * - The entry body also contains a `ListNode` that is introduced by
13
+ * a `ParagraphNode` (or is headed by text in a paragraph) whose
14
+ * text matches "acceptance criteria" case-insensitively — i.e., a
15
+ * paragraph immediately preceding a list whose prose trims to
16
+ * "acceptance criteria" (or starts with it), OR a paragraph
17
+ * immediately following the list that reads like a label, OR the
18
+ * first item text of the list begins with "Acceptance criteria".
19
+ *
20
+ * This is an AST-only check; no external dependency.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.validateFeatureAc = validateFeatureAc;
24
+ /** Case-insensitive match for "acceptance criteria" anywhere in text. */
25
+ const ACCEPTANCE_CRITERIA_RE = /acceptance\s+criteria/i;
26
+ /**
27
+ * Determine whether a body block appears to label an "Acceptance
28
+ * criteria" list — either the block itself is a paragraph whose text
29
+ * matches, or it is a list whose first item text matches.
30
+ */
31
+ function isAcceptanceCriteriaLabel(block) {
32
+ if (block.kind === "paragraph") {
33
+ return ACCEPTANCE_CRITERIA_RE.test(block.content.text);
34
+ }
35
+ if (block.kind === "list") {
36
+ // Check first list item's first paragraph for the label.
37
+ const firstItem = block.items[0];
38
+ if (firstItem) {
39
+ for (const sub of firstItem.blocks) {
40
+ if (sub.kind === "paragraph" &&
41
+ ACCEPTANCE_CRITERIA_RE.test(sub.content.text)) {
42
+ return true;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return false;
48
+ }
49
+ /**
50
+ * Check if there is an "Acceptance criteria" list in the body.
51
+ *
52
+ * Strategies (in priority order):
53
+ * 1. A `ListNode` is preceded by a `ParagraphNode` whose text matches
54
+ * "acceptance criteria".
55
+ * 2. A `ListNode` is followed by a `ParagraphNode` whose text matches
56
+ * "acceptance criteria".
57
+ * 3. A `ListNode`'s first item paragraph text matches.
58
+ */
59
+ function hasAcceptanceCriteriaList(blocks) {
60
+ for (let i = 0; i < blocks.length; i++) {
61
+ const block = blocks[i];
62
+ if (block.kind !== "list")
63
+ continue;
64
+ // Strategy 1: preceding paragraph is the label
65
+ if (i > 0 && isAcceptanceCriteriaLabel(blocks[i - 1]))
66
+ return true;
67
+ // Strategy 2: following paragraph is the label
68
+ if (i + 1 < blocks.length && isAcceptanceCriteriaLabel(blocks[i + 1]))
69
+ return true;
70
+ // Strategy 3: first list item text is the label
71
+ if (isAcceptanceCriteriaLabel(block))
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+ /**
77
+ * Validate that an entry's body does not contain both a Feature block
78
+ * (Gherkin) and a separate "Acceptance criteria" list. Emits MSL-B044
79
+ * (warning) when both are present.
80
+ */
81
+ function validateFeatureAc(entry) {
82
+ const blocks = entry.bodyAst ?? [];
83
+ // Quick exit: need at least one FeatureNode.
84
+ const featureBlock = blocks.find((b) => b.kind === "feature");
85
+ if (!featureBlock)
86
+ return [];
87
+ // Now check for an "Acceptance criteria" list.
88
+ if (!hasAcceptanceCriteriaList(blocks))
89
+ return [];
90
+ const fileLine = entry.location.line + featureBlock.range.start.line;
91
+ return [
92
+ {
93
+ code: "MSL-B044",
94
+ severity: "warning",
95
+ message: `${entry.displayId}: body contains both a Feature (Gherkin) block ` +
96
+ `and a separate "Acceptance criteria" list — use one canonical form ` +
97
+ `(Feature block preferred per spec §4.5)`,
98
+ location: {
99
+ file: entry.location.file,
100
+ line: fileLine,
101
+ column: 1,
102
+ },
103
+ },
104
+ ];
105
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module validator/listing
3
+ *
4
+ * Listing-directive validator — MSL-L010 through MSL-L050.
5
+ *
6
+ * Validates four concern areas:
7
+ *
8
+ * 1. Directive placement / conflict (§2.3): L010, L011, L012
9
+ * 2. Glossary heading-shape grammar (§4.2): L020–L024 (delegated to
10
+ * `validateGlossaryStructure`)
11
+ * 3. Component Id-scheme parsers (§5): L030–L037 (via `parseComponentScheme`)
12
+ * 4. Per-directive content (§6): L040, L041, L042, L043, L050
13
+ *
14
+ * Called from the validate CLI command once per invocation, receiving one
15
+ * {@linkcode ListingFileContext} per validated file. The listing validator
16
+ * is separate from `runPipeline` because it requires per-file context
17
+ * (file name, raw content, directives) that the flat Entry-list pipeline
18
+ * does not carry.
19
+ */
20
+ import type { Diagnostic, Directive, Entry } from "../model/mod.js";
21
+ /** The three recognized listing-directive kinds. */
22
+ export type ListingKind = "references" | "glossary" | "components";
23
+ /** Per-file context passed to {@linkcode validateListingDocuments}. */
24
+ export interface ListingFileContext {
25
+ /** Absolute or relative file path (must match entry locations). */
26
+ readonly file: string;
27
+ /** Raw Markdown source (for glossary AST validation). */
28
+ readonly content: string;
29
+ /** Entries parsed from this file. */
30
+ readonly entries: readonly Entry[];
31
+ /** Directives detected from this file's HTML comments. */
32
+ readonly directives: readonly Directive[];
33
+ }
34
+ /**
35
+ * Validate a set of files for listing-directive conformance.
36
+ *
37
+ * Returns diagnostics in document order (one file at a time in the order
38
+ * `contexts` was supplied). Call this alongside `runPipeline` — both
39
+ * operate independently.
40
+ */
41
+ export declare function validateListingDocuments(contexts: readonly ListingFileContext[]): readonly Diagnostic[];
42
+ //# sourceMappingURL=listing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listing.d.ts","sourceRoot":"","sources":["../../src/validator/listing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAWpE,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,CAAC;AAEnE,uEAAuE;AACvE,MAAM,WAAW,kBAAkB;IACjC,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAC3C;AA8SD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,SAAS,UAAU,EAAE,CAMvB"}