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