@driftsys/markspec 0.2.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/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 +12 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +130 -22
- package/esm/mod.d.ts +10 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +5 -2
- 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 +255 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +27 -1
- 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 +11 -4
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +85 -38
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +39 -9
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +20 -13
- 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.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 +12 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +131 -22
- package/script/mod.d.ts +10 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -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 +255 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +34 -2
- 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 +11 -4
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +84 -37
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +41 -10
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +20 -13
- 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.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,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
|
+
}
|
package/esm/validator/mod.d.ts
CHANGED
|
@@ -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/esm/validator/mod.js
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"Satisfies",
|
|
11
|
-
"Derived-from",
|
|
12
|
-
"Allocates",
|
|
13
|
-
"Component",
|
|
14
|
-
"Constrains",
|
|
15
|
-
"Between",
|
|
16
|
-
"Interface",
|
|
17
|
-
"Verifies",
|
|
18
|
-
"Implements",
|
|
19
|
-
"Labels",
|
|
20
|
-
]);
|
|
21
|
-
/** Known attribute keys for reference entries. */
|
|
22
|
-
const REF_ATTR_KEYS = new Set([
|
|
23
|
-
"Document",
|
|
24
|
-
"URL",
|
|
25
|
-
"Status",
|
|
26
|
-
"Superseded-by",
|
|
27
|
-
"Derived-from",
|
|
28
|
-
]);
|
|
29
|
-
/** ULID format: TYPE prefix + underscore + 12-26 alphanumeric chars. */
|
|
30
|
-
const ULID_RE = /^[A-Z]+_[0-9A-Z]{12,26}$/;
|
|
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);
|
|
31
19
|
/**
|
|
32
|
-
* Validate a set of parsed entries for structural correctness
|
|
33
|
-
*
|
|
20
|
+
* Validate a set of parsed entries for structural correctness and
|
|
21
|
+
* cross-reference integrity.
|
|
34
22
|
*
|
|
35
23
|
* @param entries - Parsed entries to validate
|
|
36
|
-
* @returns Validation result with diagnostics
|
|
37
24
|
*/
|
|
38
25
|
export function validate(entries) {
|
|
39
26
|
const diagnostics = [];
|
|
@@ -45,162 +32,183 @@ export function validate(entries) {
|
|
|
45
32
|
/** MSL-R structural checks on individual entries and cross-entry uniqueness. */
|
|
46
33
|
function checkStructural(entries, diagnostics) {
|
|
47
34
|
const displayIds = new Map();
|
|
48
|
-
const
|
|
35
|
+
const ids = new Map();
|
|
49
36
|
for (const entry of entries) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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) {
|
|
62
61
|
diagnostics.push({
|
|
63
|
-
code: "MSL-
|
|
62
|
+
code: "MSL-R004",
|
|
64
63
|
severity: "error",
|
|
65
|
-
message: `${entry.displayId}:
|
|
64
|
+
message: `${entry.displayId}: Id: value '${value}' is neither a bare ULID nor a scheme-qualified URI`,
|
|
66
65
|
location: entry.location,
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (isTyped) {
|
|
72
|
-
const idCount = entry.attributes.filter((a) => a.key === "Id").length;
|
|
73
|
-
if (idCount > 1) {
|
|
68
|
+
// Shape consistency: ULID ↔ identified, URI ↔ referenced.
|
|
69
|
+
if (isUlid && entry.shape !== "identified") {
|
|
74
70
|
diagnostics.push({
|
|
75
71
|
code: "MSL-R004",
|
|
76
72
|
severity: "error",
|
|
77
|
-
message: `${entry.displayId}:
|
|
73
|
+
message: `${entry.displayId}: Id: value is a ULID but entry shape is ${entry.shape}`,
|
|
78
74
|
location: entry.location,
|
|
79
75
|
});
|
|
80
76
|
}
|
|
81
|
-
|
|
82
|
-
// MSL-R007: Display ID type prefix must match ULID type prefix.
|
|
83
|
-
if (isTyped && entry.id && ULID_RE.test(entry.id)) {
|
|
84
|
-
const displayPrefix = entry.entryType;
|
|
85
|
-
const ulidPrefix = entry.id.split("_")[0];
|
|
86
|
-
if (displayPrefix !== ulidPrefix) {
|
|
77
|
+
else if (isUri && entry.shape !== "referenced") {
|
|
87
78
|
diagnostics.push({
|
|
88
|
-
code: "MSL-
|
|
79
|
+
code: "MSL-R004",
|
|
89
80
|
severity: "error",
|
|
90
|
-
message: `${entry.displayId}:
|
|
81
|
+
message: `${entry.displayId}: Id: value is a URI but entry shape is ${entry.shape}`,
|
|
91
82
|
location: entry.location,
|
|
92
83
|
});
|
|
93
84
|
}
|
|
94
85
|
}
|
|
95
86
|
// MSL-R006: Display ID unique across all entries.
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
87
|
+
const existingDisplay = displayIds.get(entry.displayId);
|
|
88
|
+
if (existingDisplay) {
|
|
98
89
|
diagnostics.push({
|
|
99
90
|
code: "MSL-R006",
|
|
100
91
|
severity: "error",
|
|
101
|
-
message: `duplicate display ID '${entry.displayId}' (also at ${
|
|
92
|
+
message: `duplicate display ID '${entry.displayId}' (also at ${existingDisplay.location.file}:${existingDisplay.location.line})`,
|
|
102
93
|
location: entry.location,
|
|
103
94
|
});
|
|
104
95
|
}
|
|
105
96
|
else {
|
|
106
97
|
displayIds.set(entry.displayId, entry);
|
|
107
98
|
}
|
|
108
|
-
// MSL-R005:
|
|
99
|
+
// MSL-R005: identity value unique across all entries.
|
|
109
100
|
if (entry.id) {
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
101
|
+
const existingId = ids.get(entry.id);
|
|
102
|
+
if (existingId) {
|
|
112
103
|
diagnostics.push({
|
|
113
104
|
code: "MSL-R005",
|
|
114
105
|
severity: "error",
|
|
115
|
-
message: `duplicate Id '${entry.id}' (also at ${
|
|
106
|
+
message: `duplicate Id '${entry.id}' (also at ${existingId.location.file}:${existingId.location.line})`,
|
|
116
107
|
location: entry.location,
|
|
117
108
|
});
|
|
118
109
|
}
|
|
119
110
|
else {
|
|
120
|
-
|
|
111
|
+
ids.set(entry.id, entry);
|
|
121
112
|
}
|
|
122
113
|
}
|
|
123
|
-
// MSL-R010: Unknown
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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") {
|
|
127
120
|
diagnostics.push({
|
|
128
121
|
code: "MSL-R010",
|
|
129
122
|
severity: "warning",
|
|
130
|
-
message: `${entry.displayId}: unknown attribute '${attr.key}'`,
|
|
123
|
+
message: `${entry.displayId}: unknown attribute '${attr.key}' (not in core universal set; profile-declared attributes are permitted when a profile is loaded)`,
|
|
131
124
|
location: entry.location,
|
|
132
125
|
});
|
|
133
126
|
}
|
|
134
127
|
}
|
|
135
128
|
}
|
|
136
129
|
}
|
|
137
|
-
/**
|
|
130
|
+
/** Cross-reference integrity checks. */
|
|
138
131
|
function checkReferences(entries, diagnostics) {
|
|
139
|
-
|
|
132
|
+
// Build a display-ID index for cross-reference resolution.
|
|
133
|
+
const byDisplayId = new Map();
|
|
140
134
|
for (const entry of entries) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
});
|
|
157
162
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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) {
|
|
163
175
|
diagnostics.push({
|
|
164
|
-
code: "MSL-
|
|
165
|
-
severity: "
|
|
166
|
-
message: `${entry.displayId}: unresolved
|
|
176
|
+
code: "MSL-T005",
|
|
177
|
+
severity: "error",
|
|
178
|
+
message: `${entry.displayId}: References: unresolved citation '${slug}'`,
|
|
167
179
|
location: entry.location,
|
|
168
180
|
});
|
|
181
|
+
continue;
|
|
169
182
|
}
|
|
170
|
-
|
|
171
|
-
// MSL-T008: Allocates targets must be SRS entries (resolve against known IDs).
|
|
172
|
-
const allocates = findAttr(entry.attributes, "Allocates");
|
|
173
|
-
if (allocates) {
|
|
174
|
-
const targets = allocates.value.split(",").map((s) => s.trim());
|
|
175
|
-
for (const target of targets) {
|
|
176
|
-
if (!target)
|
|
177
|
-
continue;
|
|
178
|
-
if (!knownIds.has(target)) {
|
|
179
|
-
diagnostics.push({
|
|
180
|
-
code: "MSL-T008",
|
|
181
|
-
severity: "error",
|
|
182
|
-
message: `${entry.displayId}: unresolved reference '${target}' in Allocates`,
|
|
183
|
-
location: entry.location,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// MSL-T009: Between must list exactly two parties.
|
|
189
|
-
const between = findAttr(entry.attributes, "Between");
|
|
190
|
-
if (between) {
|
|
191
|
-
const parties = between.value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
192
|
-
if (parties.length !== 2) {
|
|
183
|
+
if (resolved.shape !== "referenced") {
|
|
193
184
|
diagnostics.push({
|
|
194
|
-
code: "MSL-
|
|
185
|
+
code: "MSL-T005",
|
|
195
186
|
severity: "error",
|
|
196
|
-
message: `${entry.displayId}:
|
|
187
|
+
message: `${entry.displayId}: References: target '${slug}' is shape '${resolved.shape}', expected 'referenced'`,
|
|
197
188
|
location: entry.location,
|
|
198
189
|
});
|
|
199
190
|
}
|
|
200
191
|
}
|
|
201
192
|
}
|
|
202
193
|
}
|
|
203
|
-
|
|
204
|
-
|
|
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) {
|
|
205
206
|
return attrs.find((a) => a.key === key);
|
|
206
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
|
+
}
|