@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.
- package/README.md +32 -8
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +43 -0
- package/esm/compiler/mod.d.ts.map +1 -0
- package/esm/compiler/mod.js +163 -0
- package/esm/compiler/schema.d.ts +38 -0
- package/esm/compiler/schema.d.ts.map +1 -0
- package/esm/compiler/schema.js +44 -0
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +48 -0
- package/esm/config/mod.d.ts.map +1 -0
- package/esm/config/mod.js +243 -0
- package/esm/formatter/mod.d.ts +65 -0
- package/esm/formatter/mod.d.ts.map +1 -0
- package/esm/formatter/mod.js +306 -0
- package/esm/mod.d.ts +19 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +18 -0
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +381 -0
- package/esm/model/mod.d.ts.map +1 -0
- package/esm/model/mod.js +73 -0
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +48 -0
- package/esm/parser/attributes.d.ts.map +1 -0
- package/esm/parser/attributes.js +131 -0
- package/esm/parser/captions.d.ts +25 -0
- package/esm/parser/captions.d.ts.map +1 -0
- package/esm/parser/captions.js +148 -0
- package/esm/parser/directives.d.ts +29 -0
- package/esm/parser/directives.d.ts.map +1 -0
- package/esm/parser/directives.js +88 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.d.ts +22 -0
- package/esm/parser/grammars.d.ts.map +1 -0
- package/esm/parser/grammars.js +70 -0
- package/esm/parser/markdown.d.ts +32 -0
- package/esm/parser/markdown.d.ts.map +1 -0
- package/esm/parser/markdown.js +225 -0
- package/esm/parser/mod.d.ts +73 -0
- package/esm/parser/mod.d.ts.map +1 -0
- package/esm/parser/mod.js +89 -0
- package/esm/parser/references.d.ts +24 -0
- package/esm/parser/references.d.ts.map +1 -0
- package/esm/parser/references.js +71 -0
- package/esm/parser/remark.d.ts +9 -0
- package/esm/parser/remark.d.ts.map +1 -0
- package/esm/parser/remark.js +11 -0
- package/esm/parser/source.d.ts +33 -0
- package/esm/parser/source.d.ts.map +1 -0
- package/esm/parser/source.js +192 -0
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +830 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +23 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +14 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.d.ts +31 -0
- package/esm/reporter/mod.d.ts.map +1 -0
- package/esm/reporter/mod.js +173 -0
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +44 -0
- package/esm/validator/mod.d.ts.map +1 -0
- package/esm/validator/mod.js +214 -0
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +8 -1
- package/script/_dnt.polyfills.d.ts +101 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +130 -0
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +43 -0
- package/script/compiler/mod.d.ts.map +1 -0
- package/script/compiler/mod.js +169 -0
- package/script/compiler/schema.d.ts +38 -0
- package/script/compiler/schema.d.ts.map +1 -0
- package/script/compiler/schema.js +47 -0
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +48 -0
- package/script/config/mod.d.ts.map +1 -0
- package/script/config/mod.js +250 -0
- package/script/formatter/mod.d.ts +65 -0
- package/script/formatter/mod.d.ts.map +1 -0
- package/script/formatter/mod.js +313 -0
- package/script/mod.d.ts +19 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +65 -2
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +381 -0
- package/script/model/mod.d.ts.map +1 -0
- package/script/model/mod.js +83 -0
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +48 -0
- package/script/parser/attributes.d.ts.map +1 -0
- package/script/parser/attributes.js +137 -0
- package/script/parser/captions.d.ts +25 -0
- package/script/parser/captions.d.ts.map +1 -0
- package/script/parser/captions.js +151 -0
- package/script/parser/directives.d.ts +29 -0
- package/script/parser/directives.d.ts.map +1 -0
- package/script/parser/directives.js +91 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.d.ts +22 -0
- package/script/parser/grammars.d.ts.map +1 -0
- package/script/parser/grammars.js +77 -0
- package/script/parser/markdown.d.ts +32 -0
- package/script/parser/markdown.d.ts.map +1 -0
- package/script/parser/markdown.js +228 -0
- package/script/parser/mod.d.ts +73 -0
- package/script/parser/mod.d.ts.map +1 -0
- package/script/parser/mod.js +101 -0
- package/script/parser/references.d.ts +24 -0
- package/script/parser/references.d.ts.map +1 -0
- package/script/parser/references.js +74 -0
- package/script/parser/remark.d.ts +9 -0
- package/script/parser/remark.d.ts.map +1 -0
- package/script/parser/remark.js +17 -0
- package/script/parser/source.d.ts +33 -0
- package/script/parser/source.d.ts.map +1 -0
- package/script/parser/source.js +198 -0
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +833 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +23 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +31 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.d.ts +31 -0
- package/script/reporter/mod.d.ts.map +1 -0
- package/script/reporter/mod.js +176 -0
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +44 -0
- package/script/validator/mod.d.ts.map +1 -0
- package/script/validator/mod.js +231 -0
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/pipeline
|
|
4
|
+
*
|
|
5
|
+
* Validator pipeline. Composes Stage 1 (core hygiene — existing `validate`),
|
|
6
|
+
* Stage 2 (type classification — {@linkcode classifyEntriesStage}),
|
|
7
|
+
* Stage 2.5 (list-value normalization — {@linkcode normalizeListValues}),
|
|
8
|
+
* Stage 3 (typed attribute validation — {@linkcode validateAttributesForEntry}),
|
|
9
|
+
* and Stage 4 (traceability rules — {@linkcode validateTraceabilityForEntry}).
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runPipeline = runPipeline;
|
|
13
|
+
const mod_js_1 = require("./mod.js");
|
|
14
|
+
const types_js_1 = require("./types.js");
|
|
15
|
+
const attributes_js_1 = require("./attributes.js");
|
|
16
|
+
const normalize_js_1 = require("./normalize.js");
|
|
17
|
+
const traceability_js_1 = require("./traceability.js");
|
|
18
|
+
/**
|
|
19
|
+
* Run the validator pipeline.
|
|
20
|
+
*
|
|
21
|
+
* - Stage 1 (always): core hygiene via {@linkcode validate}.
|
|
22
|
+
* - Stage 2 (when `profile` is non-null): entry classification via
|
|
23
|
+
* {@linkcode classifyEntriesStage}.
|
|
24
|
+
*
|
|
25
|
+
* When `profile` is `null`, entries pass through unchanged (no `type`
|
|
26
|
+
* assignments).
|
|
27
|
+
*/
|
|
28
|
+
function runPipeline(entries, profile) {
|
|
29
|
+
const diagnostics = [];
|
|
30
|
+
// Stage 1 — core hygiene. When a profile is loaded, suppress MSL-R010
|
|
31
|
+
// warnings for attributes the profile actually declares (Stage 3's scope
|
|
32
|
+
// validates them directly — the core-only R010 check would be noise).
|
|
33
|
+
const stage1 = (0, mod_js_1.validate)(entries);
|
|
34
|
+
const profileDeclaredAttrs = profile !== null
|
|
35
|
+
? collectAllProfileAttributes(entries, profile)
|
|
36
|
+
: null;
|
|
37
|
+
const filteredStage1 = profileDeclaredAttrs === null
|
|
38
|
+
? stage1.diagnostics
|
|
39
|
+
: stage1.diagnostics.filter((d) => {
|
|
40
|
+
if (d.code !== "MSL-R010")
|
|
41
|
+
return true;
|
|
42
|
+
const match = /attribute '([^']+)'/.exec(d.message);
|
|
43
|
+
if (!match)
|
|
44
|
+
return true;
|
|
45
|
+
return !profileDeclaredAttrs.has(match[1]);
|
|
46
|
+
});
|
|
47
|
+
diagnostics.push(...filteredStage1);
|
|
48
|
+
// Stage 2 — classification (only when a profile is loaded).
|
|
49
|
+
let finalEntries = entries;
|
|
50
|
+
if (profile !== null) {
|
|
51
|
+
const stage2 = (0, types_js_1.classifyEntriesStage)(entries, profile);
|
|
52
|
+
finalEntries = stage2.entries;
|
|
53
|
+
diagnostics.push(...stage2.diagnostics);
|
|
54
|
+
}
|
|
55
|
+
// Stage 2.5 — normalize profile-declared list-value attributes. Splits
|
|
56
|
+
// comma-separated values for `id-list`/`tag-list` attributes the core parser
|
|
57
|
+
// didn't see so that Stage 3 sees already-split values.
|
|
58
|
+
if (profile !== null) {
|
|
59
|
+
finalEntries = finalEntries.map((e) => (0, normalize_js_1.normalizeListValues)(e, profile));
|
|
60
|
+
}
|
|
61
|
+
// Stage 3 — typed attributes (only when a profile is loaded).
|
|
62
|
+
if (profile !== null) {
|
|
63
|
+
for (const entry of finalEntries) {
|
|
64
|
+
const stage3 = (0, attributes_js_1.validateAttributesForEntry)(entry, profile);
|
|
65
|
+
diagnostics.push(...stage3);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Stage 4 — traceability rules (only when a profile is loaded). Builds a
|
|
69
|
+
// graph index keyed by `entry.id` from the post-classification entries so
|
|
70
|
+
// trace-rule target matchers can look up the classified type/shape.
|
|
71
|
+
if (profile !== null) {
|
|
72
|
+
const graph = new Map();
|
|
73
|
+
for (const e of finalEntries) {
|
|
74
|
+
if (e.id)
|
|
75
|
+
graph.set(e.id, e);
|
|
76
|
+
}
|
|
77
|
+
for (const entry of finalEntries) {
|
|
78
|
+
const stage4 = (0, traceability_js_1.validateTraceabilityForEntry)(entry, profile, graph);
|
|
79
|
+
diagnostics.push(...stage4);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const valid = !diagnostics.some((d) => d.severity === "error");
|
|
83
|
+
return { entries: finalEntries, diagnostics, valid };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Union of all attribute names declared by the profile's effective scope
|
|
87
|
+
* across all entries. Used to suppress core Stage 1 MSL-R010 warnings for
|
|
88
|
+
* attributes that Stage 3 already validates.
|
|
89
|
+
*
|
|
90
|
+
* Computed per-entry because the effective scope for an entry depends on
|
|
91
|
+
* its shape and (when classified) type. Stage 1 runs before classification,
|
|
92
|
+
* so we pre-classify by iterating; entries without `type` still contribute
|
|
93
|
+
* their universal+shape scope.
|
|
94
|
+
*/
|
|
95
|
+
function collectAllProfileAttributes(entries, profile) {
|
|
96
|
+
const out = new Set();
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
const scope = (0, attributes_js_1.effectiveScope)(entry, profile);
|
|
99
|
+
for (const name of scope.attributes.keys())
|
|
100
|
+
out.add(name);
|
|
101
|
+
}
|
|
102
|
+
// Also include every type-scoped attribute in the profile, since an entry
|
|
103
|
+
// may have declared attributes before Stage 2 classification runs.
|
|
104
|
+
for (const [, typeEntry] of profile.types) {
|
|
105
|
+
for (const name of typeEntry.value.attributes.keys())
|
|
106
|
+
out.add(name);
|
|
107
|
+
// Trace rule link names are implicitly id-list attributes — include them
|
|
108
|
+
// so Stage 1's MSL-R010 doesn't flag them before Stage 2 classifies.
|
|
109
|
+
for (const name of typeEntry.value.traceability.keys())
|
|
110
|
+
out.add(name);
|
|
111
|
+
}
|
|
112
|
+
// Shape-level trace rule link names too.
|
|
113
|
+
for (const name of profile.identified.traceability.keys())
|
|
114
|
+
out.add(name);
|
|
115
|
+
for (const name of profile.referenced.traceability.keys())
|
|
116
|
+
out.add(name);
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/validator/traceability
|
|
3
|
+
*
|
|
4
|
+
* Validator Stage 4 — traceability rule enforcement.
|
|
5
|
+
*
|
|
6
|
+
* Runs after Stage 3. For each classified identified entry, checks the
|
|
7
|
+
* profile's declared trace rules against the entry's outgoing link
|
|
8
|
+
* attributes:
|
|
9
|
+
* - Required (MSL-L001)
|
|
10
|
+
* - Cardinality bounds (MSL-L002 upper / MSL-L003 lower)
|
|
11
|
+
* - Target match against the rule's target matchers (MSL-L004)
|
|
12
|
+
*
|
|
13
|
+
* Referenced entries are skipped entirely — the profile manifest parser
|
|
14
|
+
* rejects `referenced.traceability` at load time, so referenced entries
|
|
15
|
+
* never have declared outgoing links.
|
|
16
|
+
*/
|
|
17
|
+
import type { Diagnostic, EffectiveProfile, Entry, TargetMatcher, TraceRule } from "../model/mod.js";
|
|
18
|
+
/**
|
|
19
|
+
* Effective trace rules for an entry: union of identified-shape-scope rules
|
|
20
|
+
* and (when classified) type-scope rules. Type-scope rules win on
|
|
21
|
+
* link-attribute-name collision.
|
|
22
|
+
*
|
|
23
|
+
* Referenced entries always return an empty map.
|
|
24
|
+
*/
|
|
25
|
+
export declare function effectiveTraceRules(entry: Entry, profile: EffectiveProfile): ReadonlyMap<string, TraceRule>;
|
|
26
|
+
/**
|
|
27
|
+
* Return true if the target entry matches any of the rule's target matchers.
|
|
28
|
+
* OR semantics across the list.
|
|
29
|
+
*
|
|
30
|
+
* - Type-name matcher (string): target's classified type equals the name.
|
|
31
|
+
* An un-classified target never matches a type-name matcher.
|
|
32
|
+
* - Shape matcher ({shape: "identified"|"referenced"}): target's shape
|
|
33
|
+
* equals the matcher's shape.
|
|
34
|
+
*/
|
|
35
|
+
export declare function matchesAnyTarget(target: Entry, matchers: readonly TargetMatcher[]): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Run Stage 4 traceability checks for one entry.
|
|
38
|
+
*
|
|
39
|
+
* Skips referenced entries entirely. For identified entries, iterates the
|
|
40
|
+
* effective trace rules and emits MSL-L001..L004 as appropriate.
|
|
41
|
+
*
|
|
42
|
+
* @param entry - The entry to validate (after Stage 2 classification +
|
|
43
|
+
* Stage 2.5 normalization)
|
|
44
|
+
* @param profile - The effective profile (null → never called)
|
|
45
|
+
* @param graph - Index keyed by entry.id for target lookup
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateTraceabilityForEntry(entry: Entry, profile: EffectiveProfile, graph: ReadonlyMap<string, Entry>): Diagnostic[];
|
|
48
|
+
//# sourceMappingURL=traceability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traceability.d.ts","sourceRoot":"","sources":["../../src/validator/traceability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,aAAa,EACb,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAoBhC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,KAAK,EACb,QAAQ,EAAE,SAAS,aAAa,EAAE,GACjC,OAAO,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAChC,UAAU,EAAE,CAuEd"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/traceability
|
|
4
|
+
*
|
|
5
|
+
* Validator Stage 4 — traceability rule enforcement.
|
|
6
|
+
*
|
|
7
|
+
* Runs after Stage 3. For each classified identified entry, checks the
|
|
8
|
+
* profile's declared trace rules against the entry's outgoing link
|
|
9
|
+
* attributes:
|
|
10
|
+
* - Required (MSL-L001)
|
|
11
|
+
* - Cardinality bounds (MSL-L002 upper / MSL-L003 lower)
|
|
12
|
+
* - Target match against the rule's target matchers (MSL-L004)
|
|
13
|
+
*
|
|
14
|
+
* Referenced entries are skipped entirely — the profile manifest parser
|
|
15
|
+
* rejects `referenced.traceability` at load time, so referenced entries
|
|
16
|
+
* never have declared outgoing links.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.effectiveTraceRules = effectiveTraceRules;
|
|
20
|
+
exports.matchesAnyTarget = matchesAnyTarget;
|
|
21
|
+
exports.validateTraceabilityForEntry = validateTraceabilityForEntry;
|
|
22
|
+
/**
|
|
23
|
+
* Effective trace rules for an entry: union of identified-shape-scope rules
|
|
24
|
+
* and (when classified) type-scope rules. Type-scope rules win on
|
|
25
|
+
* link-attribute-name collision.
|
|
26
|
+
*
|
|
27
|
+
* Referenced entries always return an empty map.
|
|
28
|
+
*/
|
|
29
|
+
function effectiveTraceRules(entry, profile) {
|
|
30
|
+
const out = new Map();
|
|
31
|
+
if (entry.shape !== "identified")
|
|
32
|
+
return out;
|
|
33
|
+
// Shape scope.
|
|
34
|
+
for (const [name, ruleEntry] of profile.identified.traceability) {
|
|
35
|
+
out.set(name, ruleEntry.value);
|
|
36
|
+
}
|
|
37
|
+
// Type scope (only when classified AND type is declared in the profile).
|
|
38
|
+
if (entry.type !== undefined) {
|
|
39
|
+
const typeEntry = profile.types.get(entry.type);
|
|
40
|
+
if (typeEntry !== undefined) {
|
|
41
|
+
for (const [name, ruleEntry] of typeEntry.value.traceability) {
|
|
42
|
+
out.set(name, ruleEntry.value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return true if the target entry matches any of the rule's target matchers.
|
|
50
|
+
* OR semantics across the list.
|
|
51
|
+
*
|
|
52
|
+
* - Type-name matcher (string): target's classified type equals the name.
|
|
53
|
+
* An un-classified target never matches a type-name matcher.
|
|
54
|
+
* - Shape matcher ({shape: "identified"|"referenced"}): target's shape
|
|
55
|
+
* equals the matcher's shape.
|
|
56
|
+
*/
|
|
57
|
+
function matchesAnyTarget(target, matchers) {
|
|
58
|
+
for (const m of matchers) {
|
|
59
|
+
if (typeof m === "string") {
|
|
60
|
+
if (target.type === m)
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (target.shape === m.shape)
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run Stage 4 traceability checks for one entry.
|
|
72
|
+
*
|
|
73
|
+
* Skips referenced entries entirely. For identified entries, iterates the
|
|
74
|
+
* effective trace rules and emits MSL-L001..L004 as appropriate.
|
|
75
|
+
*
|
|
76
|
+
* @param entry - The entry to validate (after Stage 2 classification +
|
|
77
|
+
* Stage 2.5 normalization)
|
|
78
|
+
* @param profile - The effective profile (null → never called)
|
|
79
|
+
* @param graph - Index keyed by entry.id for target lookup
|
|
80
|
+
*/
|
|
81
|
+
function validateTraceabilityForEntry(entry, profile, graph) {
|
|
82
|
+
const diagnostics = [];
|
|
83
|
+
if (entry.shape !== "identified")
|
|
84
|
+
return diagnostics;
|
|
85
|
+
const rules = effectiveTraceRules(entry, profile);
|
|
86
|
+
const present = entry.typedAttributes;
|
|
87
|
+
for (const [linkName, rule] of rules) {
|
|
88
|
+
const values = present.get(linkName);
|
|
89
|
+
const count = values?.length ?? 0;
|
|
90
|
+
const card = rule.cardinality ?? { lower: 0, upper: Infinity };
|
|
91
|
+
// MSL-L001: required link missing.
|
|
92
|
+
if (rule.required && count === 0) {
|
|
93
|
+
diagnostics.push({
|
|
94
|
+
code: "MSL-L001",
|
|
95
|
+
severity: "error",
|
|
96
|
+
message: `${entry.displayId}: required link attribute '${linkName}' is missing`,
|
|
97
|
+
location: entry.location,
|
|
98
|
+
});
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (count === 0)
|
|
102
|
+
continue;
|
|
103
|
+
// MSL-L002: upper cardinality.
|
|
104
|
+
if (count > card.upper) {
|
|
105
|
+
diagnostics.push({
|
|
106
|
+
code: "MSL-L002",
|
|
107
|
+
severity: "error",
|
|
108
|
+
message: `${entry.displayId}: link '${linkName}' has ${count} values but max is ${formatUpper(card.upper)}`,
|
|
109
|
+
location: entry.location,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
// MSL-L003: lower cardinality.
|
|
113
|
+
if (count < card.lower) {
|
|
114
|
+
diagnostics.push({
|
|
115
|
+
code: "MSL-L003",
|
|
116
|
+
severity: "error",
|
|
117
|
+
message: `${entry.displayId}: link '${linkName}' has ${count} values but min is ${card.lower}`,
|
|
118
|
+
location: entry.location,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// MSL-L004: target match for each resolved value.
|
|
122
|
+
for (const v of values) {
|
|
123
|
+
const target = graph.get(v);
|
|
124
|
+
if (!target)
|
|
125
|
+
continue;
|
|
126
|
+
if (!matchesAnyTarget(target, rule.target)) {
|
|
127
|
+
diagnostics.push({
|
|
128
|
+
code: "MSL-L004",
|
|
129
|
+
severity: "error",
|
|
130
|
+
message: `${entry.displayId}: link '${linkName}' targets ${target.displayId} ` +
|
|
131
|
+
`whose type '${target.type ?? "<unclassified>"}' / shape '${target.shape}' ` +
|
|
132
|
+
`is not accepted by rule target ${stringifyMatchers(rule.target)}`,
|
|
133
|
+
location: entry.location,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return diagnostics;
|
|
139
|
+
}
|
|
140
|
+
function formatUpper(u) {
|
|
141
|
+
return u === Infinity ? "N" : String(u);
|
|
142
|
+
}
|
|
143
|
+
function stringifyMatchers(matchers) {
|
|
144
|
+
const parts = matchers.map((m) => typeof m === "string" ? m : `{shape: ${m.shape}}`);
|
|
145
|
+
return `[${parts.join(", ")}]`;
|
|
146
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/validator/types
|
|
3
|
+
*
|
|
4
|
+
* Validator Stage 2 — entry classification.
|
|
5
|
+
*
|
|
6
|
+
* Each entry is assigned a profile-declared type either by an explicit
|
|
7
|
+
* `Type:` trailer attribute or by display-ID pattern matching. Un-classified
|
|
8
|
+
* entries in a strict profile (types declared) produce MSL-T003.
|
|
9
|
+
*/
|
|
10
|
+
import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
|
|
11
|
+
/** Result of classifying a single entry. */
|
|
12
|
+
export interface ClassifyResult {
|
|
13
|
+
/** The assigned type name, or `undefined` if un-classified. */
|
|
14
|
+
readonly type: string | undefined;
|
|
15
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Classify one {@linkcode Entry} against the profile's type vocabulary.
|
|
19
|
+
*
|
|
20
|
+
* Order of precedence:
|
|
21
|
+
* 1. Explicit `Type:` trailer attribute (if present).
|
|
22
|
+
* 2. Display-ID pattern match across types whose `shape` matches
|
|
23
|
+
* `entry.shape`.
|
|
24
|
+
*
|
|
25
|
+
* Emits:
|
|
26
|
+
* - `MSL-T001` when explicit `Type:` value is not in the profile's type
|
|
27
|
+
* vocabulary.
|
|
28
|
+
* - `MSL-T002` when the display ID matches more than one type's pattern.
|
|
29
|
+
* - `MSL-T003` when strict mode (types declared) and no classification
|
|
30
|
+
* could be assigned.
|
|
31
|
+
*/
|
|
32
|
+
export declare function classifyEntry(entry: Entry, profile: EffectiveProfile): ClassifyResult;
|
|
33
|
+
/** Result of running the classification stage over a batch of entries. */
|
|
34
|
+
export interface ClassifyStageResult {
|
|
35
|
+
/** Entries with `type` set on successful classification. */
|
|
36
|
+
readonly entries: readonly Entry[];
|
|
37
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Run classification across all entries. Produces new {@linkcode Entry}
|
|
41
|
+
* objects with `type` set when classification succeeds; un-classified
|
|
42
|
+
* entries pass through with `type` unchanged.
|
|
43
|
+
*
|
|
44
|
+
* Also emits `MSL-T004` when a classified entry's display ID violates the
|
|
45
|
+
* type's `display-id-pattern-enforcement` level.
|
|
46
|
+
*/
|
|
47
|
+
export declare function classifyEntriesStage(entries: readonly Entry[], profile: EffectiveProfile): ClassifyStageResult;
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/validator/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAEhB,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAGzB,4CAA4C;AAC5C,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,cAAc,CA4DhB;AAWD,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CAuBrB"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/types
|
|
4
|
+
*
|
|
5
|
+
* Validator Stage 2 — entry classification.
|
|
6
|
+
*
|
|
7
|
+
* Each entry is assigned a profile-declared type either by an explicit
|
|
8
|
+
* `Type:` trailer attribute or by display-ID pattern matching. Un-classified
|
|
9
|
+
* entries in a strict profile (types declared) produce MSL-T003.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.classifyEntry = classifyEntry;
|
|
13
|
+
exports.classifyEntriesStage = classifyEntriesStage;
|
|
14
|
+
const pattern_js_1 = require("./pattern.js");
|
|
15
|
+
/**
|
|
16
|
+
* Classify one {@linkcode Entry} against the profile's type vocabulary.
|
|
17
|
+
*
|
|
18
|
+
* Order of precedence:
|
|
19
|
+
* 1. Explicit `Type:` trailer attribute (if present).
|
|
20
|
+
* 2. Display-ID pattern match across types whose `shape` matches
|
|
21
|
+
* `entry.shape`.
|
|
22
|
+
*
|
|
23
|
+
* Emits:
|
|
24
|
+
* - `MSL-T001` when explicit `Type:` value is not in the profile's type
|
|
25
|
+
* vocabulary.
|
|
26
|
+
* - `MSL-T002` when the display ID matches more than one type's pattern.
|
|
27
|
+
* - `MSL-T003` when strict mode (types declared) and no classification
|
|
28
|
+
* could be assigned.
|
|
29
|
+
*/
|
|
30
|
+
function classifyEntry(entry, profile) {
|
|
31
|
+
const diagnostics = [];
|
|
32
|
+
// 1. Explicit Type: trailer?
|
|
33
|
+
const explicitType = findExplicitTypeAttribute(entry);
|
|
34
|
+
if (explicitType !== undefined) {
|
|
35
|
+
if (profile.types.has(explicitType)) {
|
|
36
|
+
return { type: explicitType, diagnostics };
|
|
37
|
+
}
|
|
38
|
+
diagnostics.push({
|
|
39
|
+
code: "MSL-T001",
|
|
40
|
+
severity: "error",
|
|
41
|
+
message: `${entry.displayId}: explicit Type: '${explicitType}' is not a declared type`,
|
|
42
|
+
location: entry.location,
|
|
43
|
+
});
|
|
44
|
+
return { type: undefined, diagnostics };
|
|
45
|
+
}
|
|
46
|
+
// 2. Display-ID pattern match across same-shape types.
|
|
47
|
+
const matches = [];
|
|
48
|
+
for (const [typeName, typeEntry] of profile.types) {
|
|
49
|
+
if (typeEntry.value.shape !== entry.shape)
|
|
50
|
+
continue;
|
|
51
|
+
const pattern = typeEntry.value.displayIdPattern.value;
|
|
52
|
+
if (pattern === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
const regex = (0, pattern_js_1.compileDisplayIdPattern)(pattern);
|
|
55
|
+
if (regex.test(entry.displayId)) {
|
|
56
|
+
matches.push(typeName);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (matches.length === 1) {
|
|
60
|
+
return { type: matches[0], diagnostics };
|
|
61
|
+
}
|
|
62
|
+
if (matches.length > 1) {
|
|
63
|
+
diagnostics.push({
|
|
64
|
+
code: "MSL-T002",
|
|
65
|
+
severity: "error",
|
|
66
|
+
message: `${entry.displayId}: display ID matches multiple type patterns ` +
|
|
67
|
+
`(${matches.join(", ")}); add an explicit 'Type:' trailer to disambiguate`,
|
|
68
|
+
location: entry.location,
|
|
69
|
+
});
|
|
70
|
+
return { type: undefined, diagnostics };
|
|
71
|
+
}
|
|
72
|
+
// 0 matches. Strict mode → MSL-T003; permissive → OK.
|
|
73
|
+
if (profile.types.size > 0) {
|
|
74
|
+
diagnostics.push({
|
|
75
|
+
code: "MSL-T003",
|
|
76
|
+
severity: "error",
|
|
77
|
+
message: `${entry.displayId}: un-classified entry ` +
|
|
78
|
+
`(profile declares ${profile.types.size} types; display ID matched none)`,
|
|
79
|
+
location: entry.location,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return { type: undefined, diagnostics };
|
|
83
|
+
}
|
|
84
|
+
function findExplicitTypeAttribute(entry) {
|
|
85
|
+
for (const attr of entry.rawAttributes) {
|
|
86
|
+
if (attr.key === "Type") {
|
|
87
|
+
return attr.value.trim();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Run classification across all entries. Produces new {@linkcode Entry}
|
|
94
|
+
* objects with `type` set when classification succeeds; un-classified
|
|
95
|
+
* entries pass through with `type` unchanged.
|
|
96
|
+
*
|
|
97
|
+
* Also emits `MSL-T004` when a classified entry's display ID violates the
|
|
98
|
+
* type's `display-id-pattern-enforcement` level.
|
|
99
|
+
*/
|
|
100
|
+
function classifyEntriesStage(entries, profile) {
|
|
101
|
+
const diagnostics = [];
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const classified = classifyEntry(entry, profile);
|
|
105
|
+
diagnostics.push(...classified.diagnostics);
|
|
106
|
+
if (classified.type !== undefined) {
|
|
107
|
+
const typeEntry = profile.types.get(classified.type);
|
|
108
|
+
if (typeEntry !== undefined) {
|
|
109
|
+
const enforceDiag = checkEnforcement(entry, typeEntry);
|
|
110
|
+
if (enforceDiag !== undefined) {
|
|
111
|
+
diagnostics.push(enforceDiag);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
out.push({ ...entry, type: classified.type });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
out.push(entry);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { entries: out, diagnostics };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* If the classified type declares a display-id-pattern and the entry's
|
|
124
|
+
* display ID doesn't match it, emit an MSL-T004 at the configured severity.
|
|
125
|
+
* Returns `undefined` when the display ID matches or enforcement is `off`.
|
|
126
|
+
*/
|
|
127
|
+
function checkEnforcement(entry, typeEntry) {
|
|
128
|
+
const pattern = typeEntry.value.displayIdPattern.value;
|
|
129
|
+
if (pattern === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
const level = typeEntry.value.displayIdPatternEnforcement.value;
|
|
132
|
+
if (level === "off")
|
|
133
|
+
return undefined;
|
|
134
|
+
const regex = (0, pattern_js_1.compileDisplayIdPattern)(pattern);
|
|
135
|
+
if (regex.test(entry.displayId))
|
|
136
|
+
return undefined;
|
|
137
|
+
return {
|
|
138
|
+
code: "MSL-T004",
|
|
139
|
+
severity: level === "error" ? "error" : "warning",
|
|
140
|
+
message: `${entry.displayId}: display ID doesn't match pattern ` +
|
|
141
|
+
`'${pattern}' for type '${typeEntry.value.name}'`,
|
|
142
|
+
location: entry.location,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 type { AttrDecl } 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 declare function validateValue(value: string, decl: AttrDecl): string | null;
|
|
18
|
+
/** Signature for a single value-type validator. */
|
|
19
|
+
export type ValueValidator = (value: string, decl: AttrDecl) => string | null;
|
|
20
|
+
//# sourceMappingURL=value_types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value_types.d.ts","sourceRoot":"","sources":["../../src/validator/value_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAG3D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAG1E;AAED,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,MAAM,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/validator/value_types
|
|
4
|
+
*
|
|
5
|
+
* Per-type value validators for profile-declared attributes. Each validator
|
|
6
|
+
* takes a string value and the attribute's declaration, returns `null` when
|
|
7
|
+
* valid or a short error message explaining why it's invalid.
|
|
8
|
+
*
|
|
9
|
+
* The top-level {@linkcode validateValue} dispatches on the declared type.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.validateValue = validateValue;
|
|
13
|
+
const mod_js_1 = require("../model/mod.js");
|
|
14
|
+
/**
|
|
15
|
+
* Validate one string value against an attribute's declared value type.
|
|
16
|
+
* Returns `null` when the value is valid, or a short human-readable detail
|
|
17
|
+
* string (without the attribute name or display ID — the caller composes the
|
|
18
|
+
* full diagnostic message).
|
|
19
|
+
*/
|
|
20
|
+
function validateValue(value, decl) {
|
|
21
|
+
const fn = VALIDATORS[decl.type];
|
|
22
|
+
return fn(value, decl);
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Individual validators (Task 6.3 simple types)
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
const validateText = (_value, _decl) => {
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
const INTEGER_RE = /^-?\d+$/;
|
|
31
|
+
const validateInteger = (value, _decl) => {
|
|
32
|
+
return INTEGER_RE.test(value)
|
|
33
|
+
? null
|
|
34
|
+
: `not a valid integer: '${value}' (expected digits optionally prefixed with '-')`;
|
|
35
|
+
};
|
|
36
|
+
const validateBoolean = (value, _decl) => {
|
|
37
|
+
return value === "true" || value === "false"
|
|
38
|
+
? null
|
|
39
|
+
: `not a valid boolean: '${value}' (expected 'true' or 'false')`;
|
|
40
|
+
};
|
|
41
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
42
|
+
const validateDate = (value, _decl) => {
|
|
43
|
+
return DATE_RE.test(value)
|
|
44
|
+
? null
|
|
45
|
+
: `not a valid ISO 8601 date: '${value}' (expected YYYY-MM-DD)`;
|
|
46
|
+
};
|
|
47
|
+
const validateEnum = (value, decl) => {
|
|
48
|
+
const values = decl.values ?? [];
|
|
49
|
+
if (values.includes(value))
|
|
50
|
+
return null;
|
|
51
|
+
return `value '${value}' is not in declared enum [${values.join(", ")}]`;
|
|
52
|
+
};
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Individual validators (Task 6.4 ID/URI types)
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
const validateId = (value, _decl) => {
|
|
57
|
+
if (mod_js_1.ULID_RE.test(value))
|
|
58
|
+
return null;
|
|
59
|
+
if (mod_js_1.URI_SCHEME_RE.test(value))
|
|
60
|
+
return null;
|
|
61
|
+
return `not a valid id: '${value}' (expected 26-char ULID or scheme-qualified URI)`;
|
|
62
|
+
};
|
|
63
|
+
const HTTP_URL_RE = /^https?:\/\//;
|
|
64
|
+
const validateUrl = (value, _decl) => {
|
|
65
|
+
return HTTP_URL_RE.test(value) ? null : `not a valid http(s) URL: '${value}'`;
|
|
66
|
+
};
|
|
67
|
+
const validateUri = (value, _decl) => {
|
|
68
|
+
return mod_js_1.URI_SCHEME_RE.test(value)
|
|
69
|
+
? null
|
|
70
|
+
: `not a valid URI: '${value}' (expected scheme-qualified per RFC 3986)`;
|
|
71
|
+
};
|
|
72
|
+
const validateExternalId = (value, _decl) => {
|
|
73
|
+
return value.trim().length > 0
|
|
74
|
+
? null
|
|
75
|
+
: `external-id cannot be empty or whitespace-only`;
|
|
76
|
+
};
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Individual validators (Task 6.5 path / list / citation types)
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// `/absolute` (POSIX) or `C:` / `C:\` / `C:/` (Windows) → absolute.
|
|
81
|
+
const ABSOLUTE_RE = /^(\/|[A-Za-z]:[\\/]?)/;
|
|
82
|
+
const validatePath = (value, _decl) => {
|
|
83
|
+
if (value.length === 0)
|
|
84
|
+
return `path cannot be empty`;
|
|
85
|
+
if (ABSOLUTE_RE.test(value)) {
|
|
86
|
+
return `absolute paths are not allowed: '${value}' (use a relative path)`;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
const validatePathOrId = (value, decl) => {
|
|
91
|
+
if (mod_js_1.ULID_RE.test(value))
|
|
92
|
+
return null;
|
|
93
|
+
if (mod_js_1.URI_SCHEME_RE.test(value))
|
|
94
|
+
return null;
|
|
95
|
+
return validatePath(value, decl);
|
|
96
|
+
};
|
|
97
|
+
const TAG_RE = /^[A-Za-z0-9_\-.]+$/;
|
|
98
|
+
const validateTagList = (value, _decl) => {
|
|
99
|
+
if (value.length === 0)
|
|
100
|
+
return `tag cannot be empty`;
|
|
101
|
+
return TAG_RE.test(value)
|
|
102
|
+
? null
|
|
103
|
+
: `invalid tag '${value}' (expected bareword of letters, digits, '_', '-', '.')`;
|
|
104
|
+
};
|
|
105
|
+
const validateCitation = (value, _decl) => {
|
|
106
|
+
return value.trim().length > 0
|
|
107
|
+
? null
|
|
108
|
+
: `citation cannot be empty or whitespace-only`;
|
|
109
|
+
};
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Registry — all 14 value types are now implemented.
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
/** Registry of per-type validators. */
|
|
114
|
+
const VALIDATORS = {
|
|
115
|
+
text: validateText,
|
|
116
|
+
integer: validateInteger,
|
|
117
|
+
boolean: validateBoolean,
|
|
118
|
+
date: validateDate,
|
|
119
|
+
enum: validateEnum,
|
|
120
|
+
id: validateId,
|
|
121
|
+
"id-list": validateId,
|
|
122
|
+
uri: validateUri,
|
|
123
|
+
url: validateUrl,
|
|
124
|
+
"external-id": validateExternalId,
|
|
125
|
+
path: validatePath,
|
|
126
|
+
"path-or-id": validatePathOrId,
|
|
127
|
+
"tag-list": validateTagList,
|
|
128
|
+
citation: validateCitation,
|
|
129
|
+
};
|