@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,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/validator/attributes
|
|
3
|
+
*
|
|
4
|
+
* Validator Stage 3 — typed attribute validation.
|
|
5
|
+
*
|
|
6
|
+
* Runs after Stage 2 classification. For each entry, computes the effective
|
|
7
|
+
* attribute scope (universal ∪ shape ∪ type) and checks:
|
|
8
|
+
* - Required presence (MSL-A001)
|
|
9
|
+
* - Cardinality (MSL-A002 upper / MSL-A003 lower)
|
|
10
|
+
* - Value-type conformance (MSL-A004, delegated to value_types.ts)
|
|
11
|
+
* - Unknown attributes (MSL-A005 warning)
|
|
12
|
+
*/
|
|
13
|
+
import { UNIVERSAL_ATTRIBUTE_KEYS } from "../model/mod.js";
|
|
14
|
+
import { validateValue } from "./value_types.js";
|
|
15
|
+
/** Core-reserved attribute keys that are always permitted regardless of profile. */
|
|
16
|
+
const CORE_RESERVED_KEYS = new Set([
|
|
17
|
+
"Id",
|
|
18
|
+
"Type",
|
|
19
|
+
...UNIVERSAL_ATTRIBUTE_KEYS,
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
* Compute the effective attribute scope for a given entry against the
|
|
23
|
+
* profile. Uses universal + shape scope always; adds type scope only when
|
|
24
|
+
* `entry.type` is set and the type is declared in the profile.
|
|
25
|
+
*/
|
|
26
|
+
export function effectiveScope(entry, profile) {
|
|
27
|
+
const required = [];
|
|
28
|
+
const attributes = new Map();
|
|
29
|
+
// Universal scope.
|
|
30
|
+
required.push(...profile.required.value);
|
|
31
|
+
for (const [name, attrEntry] of profile.attributes) {
|
|
32
|
+
attributes.set(name, attrEntry.value);
|
|
33
|
+
}
|
|
34
|
+
// Shape scope.
|
|
35
|
+
const shapeScope = entry.shape === "identified"
|
|
36
|
+
? profile.identified
|
|
37
|
+
: profile.referenced;
|
|
38
|
+
required.push(...shapeScope.required.value);
|
|
39
|
+
for (const [name, e] of shapeScope.attributes) {
|
|
40
|
+
attributes.set(name, e.value);
|
|
41
|
+
}
|
|
42
|
+
// Type scope (only when classified).
|
|
43
|
+
if (entry.type !== undefined) {
|
|
44
|
+
const typeEntry = profile.types.get(entry.type);
|
|
45
|
+
if (typeEntry !== undefined) {
|
|
46
|
+
required.push(...typeEntry.value.required.value);
|
|
47
|
+
for (const [name, e] of typeEntry.value.attributes) {
|
|
48
|
+
attributes.set(name, e.value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Synthesize implicit id-list attribute declarations for trace rule link
|
|
53
|
+
// names that aren't explicitly declared as attributes. A trace rule IS an
|
|
54
|
+
// id-list attribute by definition — profile authors shouldn't have to
|
|
55
|
+
// declare it in both places.
|
|
56
|
+
const shapeTrace = entry.shape === "identified"
|
|
57
|
+
? profile.identified.traceability
|
|
58
|
+
: profile.referenced.traceability;
|
|
59
|
+
for (const [name] of shapeTrace) {
|
|
60
|
+
if (!attributes.has(name)) {
|
|
61
|
+
attributes.set(name, synthesizedLinkAttr(name));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (entry.type !== undefined) {
|
|
65
|
+
const typeEntry = profile.types.get(entry.type);
|
|
66
|
+
if (typeEntry !== undefined) {
|
|
67
|
+
for (const [name] of typeEntry.value.traceability) {
|
|
68
|
+
if (!attributes.has(name)) {
|
|
69
|
+
attributes.set(name, synthesizedLinkAttr(name));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { required, attributes };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a synthesized `id-list` AttrDecl for a trace rule's link name when
|
|
78
|
+
* the profile doesn't explicitly declare the attribute. This keeps Stage 2.5
|
|
79
|
+
* (CSV normalization) and Stage 3 (unknown-attribute check) honest without
|
|
80
|
+
* requiring profile authors to double-declare link attributes.
|
|
81
|
+
*
|
|
82
|
+
* Cardinality defaults to 0..N (unbounded list). Cardinality on the trace
|
|
83
|
+
* rule itself is enforced by Stage 4 (traceability), which reads the rule
|
|
84
|
+
* directly.
|
|
85
|
+
*/
|
|
86
|
+
function synthesizedLinkAttr(name) {
|
|
87
|
+
return {
|
|
88
|
+
name,
|
|
89
|
+
type: "id-list",
|
|
90
|
+
required: false,
|
|
91
|
+
cardinality: { lower: 0, upper: Infinity },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Run Stage 3 structural + value-type checks for one entry. Returns all
|
|
96
|
+
* diagnostics the entry produced.
|
|
97
|
+
*
|
|
98
|
+
* Task 6.2 ships required / cardinality / unknown checks. Task 6.6 wires in
|
|
99
|
+
* value-type conformance (MSL-A004) through the value-types registry.
|
|
100
|
+
*/
|
|
101
|
+
export function validateAttributesForEntry(entry, profile) {
|
|
102
|
+
const diagnostics = [];
|
|
103
|
+
const scope = effectiveScope(entry, profile);
|
|
104
|
+
const present = entry.typedAttributes;
|
|
105
|
+
// MSL-A001: required attribute missing.
|
|
106
|
+
for (const name of scope.required) {
|
|
107
|
+
if (!present.has(name)) {
|
|
108
|
+
diagnostics.push({
|
|
109
|
+
code: "MSL-A001",
|
|
110
|
+
severity: "error",
|
|
111
|
+
message: `${entry.displayId}: required attribute '${name}' is missing`,
|
|
112
|
+
location: entry.location,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Iterate attributes present on the entry.
|
|
117
|
+
for (const [name, values] of present) {
|
|
118
|
+
const decl = scope.attributes.get(name);
|
|
119
|
+
if (decl === undefined) {
|
|
120
|
+
// MSL-A005: unknown attribute (warn). Skip core-reserved keys.
|
|
121
|
+
if (!CORE_RESERVED_KEYS.has(name)) {
|
|
122
|
+
diagnostics.push({
|
|
123
|
+
code: "MSL-A005",
|
|
124
|
+
severity: "warning",
|
|
125
|
+
message: `${entry.displayId}: attribute '${name}' is not declared in the profile scope`,
|
|
126
|
+
location: entry.location,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
// MSL-A002: upper cardinality.
|
|
132
|
+
if (values.length > decl.cardinality.upper) {
|
|
133
|
+
diagnostics.push({
|
|
134
|
+
code: "MSL-A002",
|
|
135
|
+
severity: "error",
|
|
136
|
+
message: `${entry.displayId}: attribute '${name}' has ${values.length} values ` +
|
|
137
|
+
`but max is ${formatUpper(decl.cardinality.upper)}`,
|
|
138
|
+
location: entry.location,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// MSL-A003: lower cardinality (only when attribute is present).
|
|
142
|
+
if (values.length < decl.cardinality.lower) {
|
|
143
|
+
diagnostics.push({
|
|
144
|
+
code: "MSL-A003",
|
|
145
|
+
severity: "error",
|
|
146
|
+
message: `${entry.displayId}: attribute '${name}' has ${values.length} values ` +
|
|
147
|
+
`but min is ${decl.cardinality.lower}`,
|
|
148
|
+
location: entry.location,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// MSL-A004: value-type conformance.
|
|
152
|
+
for (const v of values) {
|
|
153
|
+
const detail = validateValue(v, decl);
|
|
154
|
+
if (detail !== null) {
|
|
155
|
+
diagnostics.push({
|
|
156
|
+
code: "MSL-A004",
|
|
157
|
+
severity: "error",
|
|
158
|
+
message: `${entry.displayId}: attribute '${name}' has invalid value: ${detail}`,
|
|
159
|
+
location: entry.location,
|
|
160
|
+
});
|
|
161
|
+
break; // one diagnostic per attribute is enough
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return diagnostics;
|
|
166
|
+
}
|
|
167
|
+
function formatUpper(u) {
|
|
168
|
+
return u === Infinity ? "N" : String(u);
|
|
169
|
+
}
|
|
@@ -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,214 @@
|
|
|
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 { IDENTITY_KEY, ULID_RE, UNIVERSAL_ATTRIBUTE_KEYS, URI_SCHEME_RE, } from "../model/mod.js";
|
|
17
|
+
/** Universal attribute keys the core recognizes. */
|
|
18
|
+
const UNIVERSAL_KEYS = new Set(UNIVERSAL_ATTRIBUTE_KEYS);
|
|
19
|
+
/**
|
|
20
|
+
* Validate a set of parsed entries for structural correctness and
|
|
21
|
+
* cross-reference integrity.
|
|
22
|
+
*
|
|
23
|
+
* @param entries - Parsed entries to validate
|
|
24
|
+
*/
|
|
25
|
+
export function validate(entries) {
|
|
26
|
+
const diagnostics = [];
|
|
27
|
+
checkStructural(entries, diagnostics);
|
|
28
|
+
checkReferences(entries, diagnostics);
|
|
29
|
+
const valid = !diagnostics.some((d) => d.severity === "error");
|
|
30
|
+
return { diagnostics, valid };
|
|
31
|
+
}
|
|
32
|
+
/** MSL-R structural checks on individual entries and cross-entry uniqueness. */
|
|
33
|
+
function checkStructural(entries, diagnostics) {
|
|
34
|
+
const displayIds = new Map();
|
|
35
|
+
const ids = new Map();
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
// MSL-R003: exactly one `Id:` attribute per entry.
|
|
38
|
+
const idAttrs = entry.rawAttributes.filter((a) => a.key === IDENTITY_KEY);
|
|
39
|
+
if (idAttrs.length === 0) {
|
|
40
|
+
diagnostics.push({
|
|
41
|
+
code: "MSL-R003",
|
|
42
|
+
severity: "error",
|
|
43
|
+
message: `${entry.displayId}: missing Id: attribute`,
|
|
44
|
+
location: entry.location,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else if (idAttrs.length > 1) {
|
|
48
|
+
diagnostics.push({
|
|
49
|
+
code: "MSL-R003",
|
|
50
|
+
severity: "error",
|
|
51
|
+
message: `${entry.displayId}: multiple Id: attributes (${idAttrs.length}) — exactly one is required`,
|
|
52
|
+
location: entry.location,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// MSL-R004: `Id:` value must be a ULID or a scheme-qualified URI.
|
|
56
|
+
if (idAttrs.length > 0) {
|
|
57
|
+
const value = idAttrs[0].value;
|
|
58
|
+
const isUlid = ULID_RE.test(value);
|
|
59
|
+
const isUri = URI_SCHEME_RE.test(value);
|
|
60
|
+
if (!isUlid && !isUri) {
|
|
61
|
+
diagnostics.push({
|
|
62
|
+
code: "MSL-R004",
|
|
63
|
+
severity: "error",
|
|
64
|
+
message: `${entry.displayId}: Id: value '${value}' is neither a bare ULID nor a scheme-qualified URI`,
|
|
65
|
+
location: entry.location,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Shape consistency: ULID ↔ identified, URI ↔ referenced.
|
|
69
|
+
if (isUlid && entry.shape !== "identified") {
|
|
70
|
+
diagnostics.push({
|
|
71
|
+
code: "MSL-R004",
|
|
72
|
+
severity: "error",
|
|
73
|
+
message: `${entry.displayId}: Id: value is a ULID but entry shape is ${entry.shape}`,
|
|
74
|
+
location: entry.location,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (isUri && entry.shape !== "referenced") {
|
|
78
|
+
diagnostics.push({
|
|
79
|
+
code: "MSL-R004",
|
|
80
|
+
severity: "error",
|
|
81
|
+
message: `${entry.displayId}: Id: value is a URI but entry shape is ${entry.shape}`,
|
|
82
|
+
location: entry.location,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// MSL-R006: Display ID unique across all entries.
|
|
87
|
+
const existingDisplay = displayIds.get(entry.displayId);
|
|
88
|
+
if (existingDisplay) {
|
|
89
|
+
diagnostics.push({
|
|
90
|
+
code: "MSL-R006",
|
|
91
|
+
severity: "error",
|
|
92
|
+
message: `duplicate display ID '${entry.displayId}' (also at ${existingDisplay.location.file}:${existingDisplay.location.line})`,
|
|
93
|
+
location: entry.location,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
displayIds.set(entry.displayId, entry);
|
|
98
|
+
}
|
|
99
|
+
// MSL-R005: identity value unique across all entries.
|
|
100
|
+
if (entry.id) {
|
|
101
|
+
const existingId = ids.get(entry.id);
|
|
102
|
+
if (existingId) {
|
|
103
|
+
diagnostics.push({
|
|
104
|
+
code: "MSL-R005",
|
|
105
|
+
severity: "error",
|
|
106
|
+
message: `duplicate Id '${entry.id}' (also at ${existingId.location.file}:${existingId.location.line})`,
|
|
107
|
+
location: entry.location,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
ids.set(entry.id, entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// MSL-R010: Unknown attributes are warnings in the core. A
|
|
115
|
+
// profile-aware validator widens this check to include profile-declared
|
|
116
|
+
// attributes; until then, anything outside the universal set is
|
|
117
|
+
// unrecognized.
|
|
118
|
+
for (const attr of entry.rawAttributes) {
|
|
119
|
+
if (!UNIVERSAL_KEYS.has(attr.key) && attr.key !== "Type") {
|
|
120
|
+
diagnostics.push({
|
|
121
|
+
code: "MSL-R010",
|
|
122
|
+
severity: "warning",
|
|
123
|
+
message: `${entry.displayId}: unknown attribute '${attr.key}' (not in core universal set; profile-declared attributes are permitted when a profile is loaded)`,
|
|
124
|
+
location: entry.location,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Cross-reference integrity checks. */
|
|
131
|
+
function checkReferences(entries, diagnostics) {
|
|
132
|
+
// Build a display-ID index for cross-reference resolution.
|
|
133
|
+
const byDisplayId = new Map();
|
|
134
|
+
for (const entry of entries) {
|
|
135
|
+
if (!byDisplayId.has(entry.displayId)) {
|
|
136
|
+
byDisplayId.set(entry.displayId, entry);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Also index by `Id:` value so references may target ULIDs or URIs
|
|
140
|
+
// directly (profile tooling commonly accepts either).
|
|
141
|
+
const byId = new Map();
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
if (entry.id && !byId.has(entry.id)) {
|
|
144
|
+
byId.set(entry.id, entry);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// MSL-T012: `Supersedes:` — the one baked-in relation. Target must
|
|
148
|
+
// resolve; profile rules check type/shape compatibility separately.
|
|
149
|
+
for (const entry of entries) {
|
|
150
|
+
const supersedes = entry.rawAttributes.find((a) => a.key === "Supersedes");
|
|
151
|
+
if (!supersedes)
|
|
152
|
+
continue;
|
|
153
|
+
const target = supersedes.value.trim();
|
|
154
|
+
const resolved = byDisplayId.get(target) ?? byId.get(target);
|
|
155
|
+
if (!resolved) {
|
|
156
|
+
diagnostics.push({
|
|
157
|
+
code: "MSL-T012",
|
|
158
|
+
severity: "error",
|
|
159
|
+
message: `${entry.displayId}: Supersedes target '${target}' not found`,
|
|
160
|
+
location: entry.location,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// MSL-T005: `References:` — citations must resolve to a referenced
|
|
165
|
+
// entry. This is a universal relation (citing identified → referenced).
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
const citations = entry.rawAttributes.filter((a) => a.key === "References");
|
|
168
|
+
for (const attr of citations) {
|
|
169
|
+
// Citation format: "slug [free-text locator]"; take the first token.
|
|
170
|
+
const slug = attr.value.split(/\s/)[0];
|
|
171
|
+
if (!slug)
|
|
172
|
+
continue;
|
|
173
|
+
const resolved = byDisplayId.get(slug) ?? byId.get(slug);
|
|
174
|
+
if (!resolved) {
|
|
175
|
+
diagnostics.push({
|
|
176
|
+
code: "MSL-T005",
|
|
177
|
+
severity: "error",
|
|
178
|
+
message: `${entry.displayId}: References: unresolved citation '${slug}'`,
|
|
179
|
+
location: entry.location,
|
|
180
|
+
});
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (resolved.shape !== "referenced") {
|
|
184
|
+
diagnostics.push({
|
|
185
|
+
code: "MSL-T005",
|
|
186
|
+
severity: "error",
|
|
187
|
+
message: `${entry.displayId}: References: target '${slug}' is shape '${resolved.shape}', expected 'referenced'`,
|
|
188
|
+
location: entry.location,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Re-exported for callers that want to write their own cross-reference
|
|
195
|
+
// checks over the core index.
|
|
196
|
+
export function indexByDisplayId(entries) {
|
|
197
|
+
const map = new Map();
|
|
198
|
+
for (const entry of entries) {
|
|
199
|
+
if (!map.has(entry.displayId))
|
|
200
|
+
map.set(entry.displayId, entry);
|
|
201
|
+
}
|
|
202
|
+
return map;
|
|
203
|
+
}
|
|
204
|
+
// Retained export for downstream consumers.
|
|
205
|
+
export function findAttr(attrs, key) {
|
|
206
|
+
return attrs.find((a) => a.key === key);
|
|
207
|
+
}
|
|
208
|
+
export { runPipeline } from "./pipeline.js";
|
|
209
|
+
export { classifyEntriesStage, classifyEntry } from "./types.js";
|
|
210
|
+
export { compileDisplayIdPattern } from "./pattern.js";
|
|
211
|
+
export { effectiveScope, validateAttributesForEntry } from "./attributes.js";
|
|
212
|
+
export { validateValue } from "./value_types.js";
|
|
213
|
+
export { normalizeListValues } from "./normalize.js";
|
|
214
|
+
export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
|
|
@@ -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,58 @@
|
|
|
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 { effectiveScope } from "./attributes.js";
|
|
16
|
+
const LIST_TYPES = new Set(["id-list", "tag-list"]);
|
|
17
|
+
/**
|
|
18
|
+
* Return a new Entry with list-typed attribute values split on commas. If no
|
|
19
|
+
* change is needed, returns the input entry unchanged (reference equality).
|
|
20
|
+
*/
|
|
21
|
+
export function normalizeListValues(entry, profile) {
|
|
22
|
+
const scope = effectiveScope(entry, profile);
|
|
23
|
+
const rewritten = new Map();
|
|
24
|
+
let anyChange = false;
|
|
25
|
+
for (const [name, values] of entry.typedAttributes) {
|
|
26
|
+
const decl = scope.attributes.get(name);
|
|
27
|
+
if (decl !== undefined && LIST_TYPES.has(decl.type)) {
|
|
28
|
+
const split = splitListValues(values);
|
|
29
|
+
if (!arraysEqual(split, values)) {
|
|
30
|
+
rewritten.set(name, split);
|
|
31
|
+
anyChange = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
rewritten.set(name, values);
|
|
36
|
+
}
|
|
37
|
+
if (!anyChange)
|
|
38
|
+
return entry;
|
|
39
|
+
return { ...entry, typedAttributes: rewritten };
|
|
40
|
+
}
|
|
41
|
+
function splitListValues(values) {
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const v of values) {
|
|
44
|
+
const parts = v.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
45
|
+
if (parts.length === 0)
|
|
46
|
+
continue;
|
|
47
|
+
out.push(...parts);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
function arraysEqual(a, b) {
|
|
52
|
+
if (a.length !== b.length)
|
|
53
|
+
return false;
|
|
54
|
+
for (let i = 0; i < a.length; i++)
|
|
55
|
+
if (a[i] !== b[i])
|
|
56
|
+
return false;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
@@ -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,44 @@
|
|
|
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
|
+
const PLACEHOLDER_RE = /\{n(?::(0\d+)d)?\}/;
|
|
17
|
+
/**
|
|
18
|
+
* Compile a display-ID pattern template into an anchored RegExp.
|
|
19
|
+
*
|
|
20
|
+
* Throws if the template is missing the `{n}` placeholder or has an invalid
|
|
21
|
+
* padding specifier.
|
|
22
|
+
*/
|
|
23
|
+
export function compileDisplayIdPattern(template) {
|
|
24
|
+
const match = PLACEHOLDER_RE.exec(template);
|
|
25
|
+
if (!match) {
|
|
26
|
+
if (/\{n:[^}]*\}/.test(template)) {
|
|
27
|
+
throw new Error(`display-id-pattern '${template}': invalid padding specifier ` +
|
|
28
|
+
`(expected {n} or {n:NNd})`);
|
|
29
|
+
}
|
|
30
|
+
throw new Error(`display-id-pattern '${template}': missing {n} placeholder`);
|
|
31
|
+
}
|
|
32
|
+
const padding = match[1];
|
|
33
|
+
const placeholderStart = match.index;
|
|
34
|
+
const placeholderEnd = match.index + match[0].length;
|
|
35
|
+
const prefix = template.slice(0, placeholderStart);
|
|
36
|
+
const suffix = template.slice(placeholderEnd);
|
|
37
|
+
const digitGroup = padding ? `\\d{${Number(padding)}}` : `\\d+`;
|
|
38
|
+
const regexSource = "^" + escapeRegex(prefix) + "(" + digitGroup + ")" +
|
|
39
|
+
escapeRegex(suffix) + "$";
|
|
40
|
+
return new RegExp(regexSource);
|
|
41
|
+
}
|
|
42
|
+
function escapeRegex(s) {
|
|
43
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
44
|
+
}
|
|
@@ -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"}
|