@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,830 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/manifest
|
|
3
|
+
*
|
|
4
|
+
* Parse a markspec.yaml manifest string into a validated ProfileManifest.
|
|
5
|
+
* Emits PROFILE-LOAD-002 for YAML parse errors and PROFILE-LOAD-003 for
|
|
6
|
+
* schema violations.
|
|
7
|
+
*/
|
|
8
|
+
import { parse as parseYaml } from "@std/yaml";
|
|
9
|
+
import { LIST_VALUE_TYPES, VALUE_TYPES, } from "../model/mod.js";
|
|
10
|
+
const VALUE_TYPE_SET = new Set(VALUE_TYPES);
|
|
11
|
+
/**
|
|
12
|
+
* The seven palette hues a profile may bind a semantic name to.
|
|
13
|
+
* Mirrors the `diagram:` group in `theme/tokens.yaml`.
|
|
14
|
+
*/
|
|
15
|
+
const PALETTE_HUES = [
|
|
16
|
+
"blue",
|
|
17
|
+
"cyan",
|
|
18
|
+
"teal",
|
|
19
|
+
"orange",
|
|
20
|
+
"red",
|
|
21
|
+
"purple",
|
|
22
|
+
"grey",
|
|
23
|
+
];
|
|
24
|
+
/** Regex for valid semantic-name keys in `profile.colors:`. */
|
|
25
|
+
const COLOR_NAME_RE = /^[a-z][a-z0-9-]*$/;
|
|
26
|
+
const ALLOWED_ROOT_KEYS = new Set([
|
|
27
|
+
"id",
|
|
28
|
+
"version",
|
|
29
|
+
"description",
|
|
30
|
+
"license",
|
|
31
|
+
"extends",
|
|
32
|
+
"profile",
|
|
33
|
+
]);
|
|
34
|
+
const ALLOWED_PROFILE_KEYS = new Set([
|
|
35
|
+
"required",
|
|
36
|
+
"attributes",
|
|
37
|
+
"labels",
|
|
38
|
+
"colors",
|
|
39
|
+
"identified",
|
|
40
|
+
"referenced",
|
|
41
|
+
"types",
|
|
42
|
+
"documents",
|
|
43
|
+
]);
|
|
44
|
+
const ALLOWED_IDENTIFIED_KEYS = new Set([
|
|
45
|
+
"required",
|
|
46
|
+
"attributes",
|
|
47
|
+
"traceability",
|
|
48
|
+
]);
|
|
49
|
+
const ALLOWED_REFERENCED_KEYS = new Set(["required", "attributes"]);
|
|
50
|
+
const ALLOWED_TYPE_KEYS = new Set([
|
|
51
|
+
"shape",
|
|
52
|
+
"description",
|
|
53
|
+
"display-id-pattern",
|
|
54
|
+
"display-id-pattern-enforcement",
|
|
55
|
+
"required",
|
|
56
|
+
"attributes",
|
|
57
|
+
"traceability",
|
|
58
|
+
"color",
|
|
59
|
+
]);
|
|
60
|
+
const ALLOWED_DOC_TYPE_KEYS = new Set(["id", "contains", "description"]);
|
|
61
|
+
const ALLOWED_DOCUMENTS_KEYS = new Set(["types", "frontMatter"]);
|
|
62
|
+
const ALLOWED_ATTR_KEYS = new Set([
|
|
63
|
+
"name",
|
|
64
|
+
"type",
|
|
65
|
+
"required",
|
|
66
|
+
"cardinality",
|
|
67
|
+
"values",
|
|
68
|
+
"inverse",
|
|
69
|
+
]);
|
|
70
|
+
const ALLOWED_INVERSE_KEYS = new Set(["name", "category"]);
|
|
71
|
+
const ALLOWED_TRACE_RULE_KEYS = new Set(["target", "cardinality", "required"]);
|
|
72
|
+
function parseShapeScope(raw, allowedKeys, context, sourcePath, diagnostics) {
|
|
73
|
+
if (raw === undefined)
|
|
74
|
+
return {};
|
|
75
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
76
|
+
diagnostics.push({
|
|
77
|
+
code: "PROFILE-LOAD-003",
|
|
78
|
+
severity: "error",
|
|
79
|
+
message: `${context}: must be a mapping`,
|
|
80
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
81
|
+
});
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const r = raw;
|
|
85
|
+
for (const key of Object.keys(r)) {
|
|
86
|
+
if (!allowedKeys.has(key)) {
|
|
87
|
+
diagnostics.push({
|
|
88
|
+
code: "PROFILE-LOAD-003",
|
|
89
|
+
severity: "error",
|
|
90
|
+
message: `${context}: unknown key '${key}'`,
|
|
91
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return r;
|
|
96
|
+
}
|
|
97
|
+
function parseStringList(raw, key, sourcePath, diagnostics) {
|
|
98
|
+
if (raw === undefined)
|
|
99
|
+
return [];
|
|
100
|
+
if (!Array.isArray(raw) || !raw.every((v) => typeof v === "string")) {
|
|
101
|
+
diagnostics.push({
|
|
102
|
+
code: "PROFILE-LOAD-003",
|
|
103
|
+
severity: "error",
|
|
104
|
+
message: `'${key}' must be a list of strings`,
|
|
105
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
106
|
+
});
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
return raw;
|
|
110
|
+
}
|
|
111
|
+
function parseSpecifier(raw, sourcePath, diagnostics) {
|
|
112
|
+
if (raw === undefined)
|
|
113
|
+
return undefined;
|
|
114
|
+
if (typeof raw !== "string" || raw.length === 0) {
|
|
115
|
+
diagnostics.push({
|
|
116
|
+
code: "PROFILE-LOAD-003",
|
|
117
|
+
severity: "error",
|
|
118
|
+
message: `'extends' must be a non-empty string specifier`,
|
|
119
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
120
|
+
});
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
if (raw.startsWith("./") || raw.startsWith("../")) {
|
|
124
|
+
return { kind: "local", path: raw };
|
|
125
|
+
}
|
|
126
|
+
if (raw.startsWith("git+")) {
|
|
127
|
+
const m = /^git\+((?:https?|file):\/\/[^#]+?\.git)(\/[^#]+)?#(.+)$/.exec(raw);
|
|
128
|
+
if (!m) {
|
|
129
|
+
diagnostics.push({
|
|
130
|
+
code: "PROFILE-LOAD-003",
|
|
131
|
+
severity: "error",
|
|
132
|
+
message: `'extends' git specifier malformed; expected git+<https|file>://host/.git[/subpath]#<tag>`,
|
|
133
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
134
|
+
});
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
const [, repo, rawSubpath, tag] = m;
|
|
138
|
+
const subpath = rawSubpath ? rawSubpath.slice(1) : undefined;
|
|
139
|
+
return { kind: "git", repo, subpath, tag };
|
|
140
|
+
}
|
|
141
|
+
if (raw.startsWith("npm:")) {
|
|
142
|
+
const body = raw.slice(4);
|
|
143
|
+
const scopedMatch = /^(@[a-z0-9-]+\/[a-z0-9-]+)@(.+)$/.exec(body);
|
|
144
|
+
if (scopedMatch) {
|
|
145
|
+
const [, fullName, range] = scopedMatch;
|
|
146
|
+
const slashIdx = fullName.indexOf("/");
|
|
147
|
+
return {
|
|
148
|
+
kind: "npm",
|
|
149
|
+
scope: fullName.slice(0, slashIdx),
|
|
150
|
+
name: fullName.slice(slashIdx + 1),
|
|
151
|
+
range,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const unscopedMatch = /^([a-z0-9-]+)@(.+)$/.exec(body);
|
|
155
|
+
if (unscopedMatch) {
|
|
156
|
+
const [, name, range] = unscopedMatch;
|
|
157
|
+
return { kind: "npm", scope: undefined, name, range };
|
|
158
|
+
}
|
|
159
|
+
diagnostics.push({
|
|
160
|
+
code: "PROFILE-LOAD-003",
|
|
161
|
+
severity: "error",
|
|
162
|
+
message: `'extends' npm specifier malformed; expected npm:[@scope/]name@<version-range>`,
|
|
163
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
164
|
+
});
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
diagnostics.push({
|
|
168
|
+
code: "PROFILE-LOAD-003",
|
|
169
|
+
severity: "error",
|
|
170
|
+
message: `'extends' specifier scheme not supported (use './path', 'git+<https|file>://…#<tag>', or 'npm:[@scope/]name@<range>')`,
|
|
171
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
172
|
+
});
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
function defaultCardinality(type) {
|
|
176
|
+
return LIST_VALUE_TYPES.has(type)
|
|
177
|
+
? { lower: 0, upper: Infinity }
|
|
178
|
+
: { lower: 0, upper: 1 };
|
|
179
|
+
}
|
|
180
|
+
function parseCardinality(raw, fallback, context, sourcePath, diagnostics) {
|
|
181
|
+
if (raw === undefined)
|
|
182
|
+
return fallback;
|
|
183
|
+
if (typeof raw !== "string") {
|
|
184
|
+
diagnostics.push({
|
|
185
|
+
code: "PROFILE-LOAD-003",
|
|
186
|
+
severity: "error",
|
|
187
|
+
message: `${context}: cardinality must be a string like '1..N'`,
|
|
188
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
189
|
+
});
|
|
190
|
+
return fallback;
|
|
191
|
+
}
|
|
192
|
+
const m = /^(\d+)\.\.(\d+|N)$/.exec(raw);
|
|
193
|
+
if (!m) {
|
|
194
|
+
diagnostics.push({
|
|
195
|
+
code: "PROFILE-LOAD-003",
|
|
196
|
+
severity: "error",
|
|
197
|
+
message: `${context}: invalid cardinality '${raw}'`,
|
|
198
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
199
|
+
});
|
|
200
|
+
return fallback;
|
|
201
|
+
}
|
|
202
|
+
const lower = Number(m[1]);
|
|
203
|
+
const upper = m[2] === "N" ? Infinity : Number(m[2]);
|
|
204
|
+
if (upper < lower) {
|
|
205
|
+
diagnostics.push({
|
|
206
|
+
code: "PROFILE-LOAD-003",
|
|
207
|
+
severity: "error",
|
|
208
|
+
message: `${context}: cardinality upper (${m[2]}) less than lower (${lower})`,
|
|
209
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
210
|
+
});
|
|
211
|
+
return fallback;
|
|
212
|
+
}
|
|
213
|
+
return { lower, upper };
|
|
214
|
+
}
|
|
215
|
+
function parseAttrDecl(raw, context, sourcePath, diagnostics) {
|
|
216
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
217
|
+
diagnostics.push({
|
|
218
|
+
code: "PROFILE-LOAD-003",
|
|
219
|
+
severity: "error",
|
|
220
|
+
message: `${context}: attribute entry must be a mapping`,
|
|
221
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
222
|
+
});
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const r = raw;
|
|
226
|
+
for (const key of Object.keys(r)) {
|
|
227
|
+
if (!ALLOWED_ATTR_KEYS.has(key)) {
|
|
228
|
+
diagnostics.push({
|
|
229
|
+
code: "PROFILE-LOAD-003",
|
|
230
|
+
severity: "error",
|
|
231
|
+
message: `${context}: attribute entry has unknown key '${key}'`,
|
|
232
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
233
|
+
});
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const name = r.name;
|
|
238
|
+
const type = r.type;
|
|
239
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
240
|
+
diagnostics.push({
|
|
241
|
+
code: "PROFILE-LOAD-003",
|
|
242
|
+
severity: "error",
|
|
243
|
+
message: `${context}: attribute missing 'name'`,
|
|
244
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
245
|
+
});
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
if (typeof type !== "string" || !VALUE_TYPE_SET.has(type)) {
|
|
249
|
+
diagnostics.push({
|
|
250
|
+
code: "PROFILE-LOAD-003",
|
|
251
|
+
severity: "error",
|
|
252
|
+
message: `${context}: attribute '${name}' has invalid type '${type}'`,
|
|
253
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
254
|
+
});
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
const vtype = type;
|
|
258
|
+
const required = r.required === true;
|
|
259
|
+
const cardinality = parseCardinality(r.cardinality, defaultCardinality(vtype), `${context}/${name}`, sourcePath, diagnostics);
|
|
260
|
+
let values;
|
|
261
|
+
if (vtype === "enum") {
|
|
262
|
+
const rawValues = r.values;
|
|
263
|
+
if (!Array.isArray(rawValues) ||
|
|
264
|
+
rawValues.some((v) => typeof v !== "string") ||
|
|
265
|
+
rawValues.length === 0) {
|
|
266
|
+
diagnostics.push({
|
|
267
|
+
code: "PROFILE-LOAD-003",
|
|
268
|
+
severity: "error",
|
|
269
|
+
message: `${context}: enum attribute '${name}' requires a non-empty 'values' list of strings`,
|
|
270
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
271
|
+
});
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
values = rawValues;
|
|
275
|
+
}
|
|
276
|
+
let inverse;
|
|
277
|
+
if (r.inverse !== undefined) {
|
|
278
|
+
if (vtype !== "id" && vtype !== "id-list") {
|
|
279
|
+
diagnostics.push({
|
|
280
|
+
code: "PROFILE-LOAD-003",
|
|
281
|
+
severity: "error",
|
|
282
|
+
message: `${context}/${name}: 'inverse' only valid on id or id-list attributes`,
|
|
283
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
284
|
+
});
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
if (r.inverse == null || typeof r.inverse !== "object" ||
|
|
288
|
+
Array.isArray(r.inverse)) {
|
|
289
|
+
diagnostics.push({
|
|
290
|
+
code: "PROFILE-LOAD-003",
|
|
291
|
+
severity: "error",
|
|
292
|
+
message: `${context}/${name}: 'inverse' must be a mapping`,
|
|
293
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
294
|
+
});
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
const inv = r.inverse;
|
|
298
|
+
for (const key of Object.keys(inv)) {
|
|
299
|
+
if (!ALLOWED_INVERSE_KEYS.has(key)) {
|
|
300
|
+
diagnostics.push({
|
|
301
|
+
code: "PROFILE-LOAD-003",
|
|
302
|
+
severity: "error",
|
|
303
|
+
message: `${context}/${name}: 'inverse' has unknown key '${key}'`,
|
|
304
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
305
|
+
});
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (typeof inv.name !== "string" || inv.name.length === 0 ||
|
|
310
|
+
typeof inv.category !== "string" || inv.category.length === 0) {
|
|
311
|
+
diagnostics.push({
|
|
312
|
+
code: "PROFILE-LOAD-003",
|
|
313
|
+
severity: "error",
|
|
314
|
+
message: `${context}/${name}: 'inverse' requires string 'name' and 'category'`,
|
|
315
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
316
|
+
});
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
inverse = { name: inv.name, category: inv.category };
|
|
320
|
+
}
|
|
321
|
+
return { name, type: vtype, required, cardinality, values, inverse };
|
|
322
|
+
}
|
|
323
|
+
function parseAttrList(raw, context, sourcePath, diagnostics) {
|
|
324
|
+
if (raw === undefined)
|
|
325
|
+
return [];
|
|
326
|
+
if (!Array.isArray(raw)) {
|
|
327
|
+
diagnostics.push({
|
|
328
|
+
code: "PROFILE-LOAD-003",
|
|
329
|
+
severity: "error",
|
|
330
|
+
message: `${context}: 'attributes' must be a list`,
|
|
331
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
332
|
+
});
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
const out = [];
|
|
336
|
+
for (const item of raw) {
|
|
337
|
+
const attr = parseAttrDecl(item, context, sourcePath, diagnostics);
|
|
338
|
+
if (attr)
|
|
339
|
+
out.push(attr);
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
function parseTargetMatcher(raw, context, sourcePath, diagnostics) {
|
|
344
|
+
if (typeof raw === "string" && raw.length > 0)
|
|
345
|
+
return raw;
|
|
346
|
+
if (raw != null && typeof raw === "object" && !Array.isArray(raw)) {
|
|
347
|
+
const r = raw;
|
|
348
|
+
if (typeof r.shape === "string" &&
|
|
349
|
+
(r.shape === "identified" || r.shape === "referenced")) {
|
|
350
|
+
return { shape: r.shape };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
diagnostics.push({
|
|
354
|
+
code: "PROFILE-LOAD-003",
|
|
355
|
+
severity: "error",
|
|
356
|
+
message: `${context}: target matcher must be a type-name string or {shape: identified|referenced}`,
|
|
357
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
358
|
+
});
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
function parseTraceRule(raw, context, sourcePath, diagnostics) {
|
|
362
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
363
|
+
diagnostics.push({
|
|
364
|
+
code: "PROFILE-LOAD-003",
|
|
365
|
+
severity: "error",
|
|
366
|
+
message: `${context}: trace rule must be a mapping`,
|
|
367
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
368
|
+
});
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
const r = raw;
|
|
372
|
+
for (const key of Object.keys(r)) {
|
|
373
|
+
if (!ALLOWED_TRACE_RULE_KEYS.has(key)) {
|
|
374
|
+
diagnostics.push({
|
|
375
|
+
code: "PROFILE-LOAD-003",
|
|
376
|
+
severity: "error",
|
|
377
|
+
message: `${context}: trace rule has unknown key '${key}'`,
|
|
378
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
379
|
+
});
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (!Array.isArray(r.target) || r.target.length === 0) {
|
|
384
|
+
diagnostics.push({
|
|
385
|
+
code: "PROFILE-LOAD-003",
|
|
386
|
+
severity: "error",
|
|
387
|
+
message: `${context}: trace rule requires non-empty 'target' list`,
|
|
388
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
389
|
+
});
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
const targets = [];
|
|
393
|
+
for (const item of r.target) {
|
|
394
|
+
const m = parseTargetMatcher(item, `${context}.target`, sourcePath, diagnostics);
|
|
395
|
+
if (m !== undefined)
|
|
396
|
+
targets.push(m);
|
|
397
|
+
}
|
|
398
|
+
if (targets.length === 0)
|
|
399
|
+
return undefined;
|
|
400
|
+
const cardinality = r.cardinality !== undefined
|
|
401
|
+
? parseCardinality(r.cardinality, { lower: 0, upper: Infinity }, `${context}.cardinality`, sourcePath, diagnostics)
|
|
402
|
+
: undefined;
|
|
403
|
+
const required = r.required === true;
|
|
404
|
+
return { target: targets, cardinality, required };
|
|
405
|
+
}
|
|
406
|
+
function parseTraceabilityMap(raw, context, sourcePath, diagnostics) {
|
|
407
|
+
const out = new Map();
|
|
408
|
+
if (raw === undefined)
|
|
409
|
+
return out;
|
|
410
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
411
|
+
diagnostics.push({
|
|
412
|
+
code: "PROFILE-LOAD-003",
|
|
413
|
+
severity: "error",
|
|
414
|
+
message: `${context}: 'traceability' must be a mapping`,
|
|
415
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
416
|
+
});
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
for (const [linkName, ruleRaw] of Object.entries(raw)) {
|
|
420
|
+
const rule = parseTraceRule(ruleRaw, `${context}.${linkName}`, sourcePath, diagnostics);
|
|
421
|
+
if (rule)
|
|
422
|
+
out.set(linkName, rule);
|
|
423
|
+
}
|
|
424
|
+
return out;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Parse the `profile.colors:` block. Each key must match COLOR_NAME_RE;
|
|
428
|
+
* each value must be one of PALETTE_HUES. Unknown hues emit
|
|
429
|
+
* MSL-PROFILE-COLOR-002 (error). Returns an empty map when the block is
|
|
430
|
+
* absent.
|
|
431
|
+
*/
|
|
432
|
+
function parseColorsMap(raw, sourcePath, diagnostics) {
|
|
433
|
+
const out = new Map();
|
|
434
|
+
if (raw === undefined)
|
|
435
|
+
return out;
|
|
436
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
437
|
+
diagnostics.push({
|
|
438
|
+
code: "PROFILE-LOAD-003",
|
|
439
|
+
severity: "error",
|
|
440
|
+
message: "profile.colors: must be a mapping",
|
|
441
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
442
|
+
});
|
|
443
|
+
return out;
|
|
444
|
+
}
|
|
445
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
446
|
+
if (!COLOR_NAME_RE.test(name)) {
|
|
447
|
+
diagnostics.push({
|
|
448
|
+
code: "PROFILE-LOAD-003",
|
|
449
|
+
severity: "error",
|
|
450
|
+
message: `profile.colors: '${name}' is not a valid semantic name (lowercase letters, digits, hyphens; must start with a letter)`,
|
|
451
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
452
|
+
});
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
if (typeof value !== "string") {
|
|
456
|
+
diagnostics.push({
|
|
457
|
+
code: "MSL-PROFILE-COLOR-002",
|
|
458
|
+
severity: "error",
|
|
459
|
+
message: `profile.colors.${name}: value must be a string palette hue name`,
|
|
460
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
461
|
+
});
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
if (!PALETTE_HUES.includes(value)) {
|
|
465
|
+
diagnostics.push({
|
|
466
|
+
code: "MSL-PROFILE-COLOR-002",
|
|
467
|
+
severity: "error",
|
|
468
|
+
message: `profile.colors.${name}: '${value}' is not a palette hue (allowed: ${PALETTE_HUES.join(", ")})`,
|
|
469
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
470
|
+
});
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
out.set(name, value);
|
|
474
|
+
}
|
|
475
|
+
return out;
|
|
476
|
+
}
|
|
477
|
+
function parseTypeDef(name, raw, sourcePath, diagnostics) {
|
|
478
|
+
const ctx = `profile.types.${name}`;
|
|
479
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
480
|
+
diagnostics.push({
|
|
481
|
+
code: "PROFILE-LOAD-003",
|
|
482
|
+
severity: "error",
|
|
483
|
+
message: `${ctx}: must be a mapping`,
|
|
484
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
485
|
+
});
|
|
486
|
+
return undefined;
|
|
487
|
+
}
|
|
488
|
+
const r = raw;
|
|
489
|
+
for (const key of Object.keys(r)) {
|
|
490
|
+
if (!ALLOWED_TYPE_KEYS.has(key)) {
|
|
491
|
+
diagnostics.push({
|
|
492
|
+
code: "PROFILE-LOAD-003",
|
|
493
|
+
severity: "error",
|
|
494
|
+
message: `${ctx}: unknown key '${key}'`,
|
|
495
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const shape = r.shape;
|
|
500
|
+
if (shape !== "identified" && shape !== "referenced") {
|
|
501
|
+
diagnostics.push({
|
|
502
|
+
code: "PROFILE-LOAD-003",
|
|
503
|
+
severity: "error",
|
|
504
|
+
message: `${ctx}: 'shape' must be 'identified' or 'referenced'`,
|
|
505
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
506
|
+
});
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
509
|
+
if (shape === "referenced" && r.traceability !== undefined) {
|
|
510
|
+
diagnostics.push({
|
|
511
|
+
code: "PROFILE-LOAD-003",
|
|
512
|
+
severity: "error",
|
|
513
|
+
message: `${ctx}: referenced types cannot declare traceability (referenced entries don't originate links)`,
|
|
514
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
515
|
+
});
|
|
516
|
+
return undefined;
|
|
517
|
+
}
|
|
518
|
+
let displayIdPattern;
|
|
519
|
+
if (r["display-id-pattern"] !== undefined) {
|
|
520
|
+
if (typeof r["display-id-pattern"] !== "string") {
|
|
521
|
+
diagnostics.push({
|
|
522
|
+
code: "PROFILE-LOAD-003",
|
|
523
|
+
severity: "error",
|
|
524
|
+
message: `${ctx}: 'display-id-pattern' must be a string`,
|
|
525
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
526
|
+
});
|
|
527
|
+
return undefined;
|
|
528
|
+
}
|
|
529
|
+
displayIdPattern = r["display-id-pattern"];
|
|
530
|
+
}
|
|
531
|
+
let enforcement = "off";
|
|
532
|
+
const rawEnf = r["display-id-pattern-enforcement"];
|
|
533
|
+
if (rawEnf !== undefined) {
|
|
534
|
+
if (rawEnf !== "off" && rawEnf !== "warn" && rawEnf !== "error") {
|
|
535
|
+
diagnostics.push({
|
|
536
|
+
code: "PROFILE-LOAD-003",
|
|
537
|
+
severity: "error",
|
|
538
|
+
message: `${ctx}: 'display-id-pattern-enforcement' must be off|warn|error`,
|
|
539
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
540
|
+
});
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
543
|
+
enforcement = rawEnf;
|
|
544
|
+
}
|
|
545
|
+
let color;
|
|
546
|
+
if (r.color !== undefined) {
|
|
547
|
+
if (typeof r.color !== "string") {
|
|
548
|
+
diagnostics.push({
|
|
549
|
+
code: "PROFILE-LOAD-003",
|
|
550
|
+
severity: "error",
|
|
551
|
+
message: `${ctx}: 'color' must be a string`,
|
|
552
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
553
|
+
});
|
|
554
|
+
return undefined;
|
|
555
|
+
}
|
|
556
|
+
color = r.color;
|
|
557
|
+
if (shape === "referenced") {
|
|
558
|
+
diagnostics.push({
|
|
559
|
+
code: "MSL-PROFILE-COLOR-001",
|
|
560
|
+
severity: "warning",
|
|
561
|
+
message: `${ctx}: 'color' on a referenced-shape type is ignored at render time`,
|
|
562
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const required = parseStringList(r.required, `${ctx}.required`, sourcePath, diagnostics);
|
|
567
|
+
const attributes = parseAttrList(r.attributes, `${ctx}.attributes`, sourcePath, diagnostics);
|
|
568
|
+
const traceability = shape === "identified"
|
|
569
|
+
? parseTraceabilityMap(r.traceability, `${ctx}.traceability`, sourcePath, diagnostics)
|
|
570
|
+
: new Map();
|
|
571
|
+
return {
|
|
572
|
+
name,
|
|
573
|
+
shape: shape,
|
|
574
|
+
displayIdPattern,
|
|
575
|
+
displayIdPatternEnforcement: enforcement,
|
|
576
|
+
required,
|
|
577
|
+
attributes,
|
|
578
|
+
traceability,
|
|
579
|
+
color,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function parseTypesMap(raw, sourcePath, diagnostics) {
|
|
583
|
+
const out = new Map();
|
|
584
|
+
if (raw === undefined)
|
|
585
|
+
return out;
|
|
586
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
587
|
+
diagnostics.push({
|
|
588
|
+
code: "PROFILE-LOAD-003",
|
|
589
|
+
severity: "error",
|
|
590
|
+
message: `profile.types: must be a mapping`,
|
|
591
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
592
|
+
});
|
|
593
|
+
return out;
|
|
594
|
+
}
|
|
595
|
+
for (const [name, rawType] of Object.entries(raw)) {
|
|
596
|
+
const td = parseTypeDef(name, rawType, sourcePath, diagnostics);
|
|
597
|
+
if (td)
|
|
598
|
+
out.set(name, td);
|
|
599
|
+
}
|
|
600
|
+
return out;
|
|
601
|
+
}
|
|
602
|
+
function parseDocTypeDef(raw, sourcePath, diagnostics) {
|
|
603
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
604
|
+
diagnostics.push({
|
|
605
|
+
code: "PROFILE-LOAD-003",
|
|
606
|
+
severity: "error",
|
|
607
|
+
message: `profile.documents.types: each entry must be a mapping`,
|
|
608
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
609
|
+
});
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
const r = raw;
|
|
613
|
+
for (const key of Object.keys(r)) {
|
|
614
|
+
if (!ALLOWED_DOC_TYPE_KEYS.has(key)) {
|
|
615
|
+
diagnostics.push({
|
|
616
|
+
code: "PROFILE-LOAD-003",
|
|
617
|
+
severity: "error",
|
|
618
|
+
message: `profile.documents.types: unknown key '${key}'`,
|
|
619
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (typeof r.id !== "string" || r.id.length === 0) {
|
|
624
|
+
diagnostics.push({
|
|
625
|
+
code: "PROFILE-LOAD-003",
|
|
626
|
+
severity: "error",
|
|
627
|
+
message: `profile.documents.types: entry missing 'id'`,
|
|
628
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
629
|
+
});
|
|
630
|
+
return undefined;
|
|
631
|
+
}
|
|
632
|
+
const contains = parseStringList(r.contains, `profile.documents.types.${r.id}.contains`, sourcePath, diagnostics);
|
|
633
|
+
const description = typeof r.description === "string"
|
|
634
|
+
? r.description
|
|
635
|
+
: undefined;
|
|
636
|
+
return { id: r.id, contains, description };
|
|
637
|
+
}
|
|
638
|
+
function parseDocumentsSection(raw, sourcePath, diagnostics) {
|
|
639
|
+
if (raw === undefined)
|
|
640
|
+
return { types: [], frontMatter: [] };
|
|
641
|
+
if (raw == null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
642
|
+
diagnostics.push({
|
|
643
|
+
code: "PROFILE-LOAD-003",
|
|
644
|
+
severity: "error",
|
|
645
|
+
message: `profile.documents: must be a mapping`,
|
|
646
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
647
|
+
});
|
|
648
|
+
return { types: [], frontMatter: [] };
|
|
649
|
+
}
|
|
650
|
+
const r = raw;
|
|
651
|
+
for (const key of Object.keys(r)) {
|
|
652
|
+
if (!ALLOWED_DOCUMENTS_KEYS.has(key)) {
|
|
653
|
+
diagnostics.push({
|
|
654
|
+
code: "PROFILE-LOAD-003",
|
|
655
|
+
severity: "error",
|
|
656
|
+
message: `profile.documents: unknown key '${key}'`,
|
|
657
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
const types = [];
|
|
662
|
+
if (r.types !== undefined) {
|
|
663
|
+
if (!Array.isArray(r.types)) {
|
|
664
|
+
diagnostics.push({
|
|
665
|
+
code: "PROFILE-LOAD-003",
|
|
666
|
+
severity: "error",
|
|
667
|
+
message: `profile.documents.types: must be a list`,
|
|
668
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
for (const item of r.types) {
|
|
673
|
+
const dt = parseDocTypeDef(item, sourcePath, diagnostics);
|
|
674
|
+
if (dt)
|
|
675
|
+
types.push(dt);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const frontMatter = parseAttrList(r.frontMatter, "profile.documents.frontMatter", sourcePath, diagnostics);
|
|
680
|
+
return { types, frontMatter };
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Parse and validate a raw markspec.yaml string.
|
|
684
|
+
*
|
|
685
|
+
* @param rawYaml - File contents as a UTF-8 string
|
|
686
|
+
* @param sourcePath - Optional file path for diagnostic location
|
|
687
|
+
*/
|
|
688
|
+
export function parseManifest(rawYaml, sourcePath = "<markspec.yaml>") {
|
|
689
|
+
const diagnostics = [];
|
|
690
|
+
let parsed;
|
|
691
|
+
try {
|
|
692
|
+
parsed = parseYaml(rawYaml);
|
|
693
|
+
}
|
|
694
|
+
catch (err) {
|
|
695
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
696
|
+
diagnostics.push({
|
|
697
|
+
code: "PROFILE-LOAD-002",
|
|
698
|
+
severity: "error",
|
|
699
|
+
message: `YAML parse error: ${message}`,
|
|
700
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
701
|
+
});
|
|
702
|
+
return { manifest: null, diagnostics };
|
|
703
|
+
}
|
|
704
|
+
if (parsed == null || typeof parsed !== "object") {
|
|
705
|
+
diagnostics.push({
|
|
706
|
+
code: "PROFILE-LOAD-003",
|
|
707
|
+
severity: "error",
|
|
708
|
+
message: "manifest must be a YAML mapping",
|
|
709
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
710
|
+
});
|
|
711
|
+
return { manifest: null, diagnostics };
|
|
712
|
+
}
|
|
713
|
+
const root = parsed;
|
|
714
|
+
for (const key of Object.keys(root)) {
|
|
715
|
+
if (!ALLOWED_ROOT_KEYS.has(key)) {
|
|
716
|
+
diagnostics.push({
|
|
717
|
+
code: "PROFILE-LOAD-003",
|
|
718
|
+
severity: "error",
|
|
719
|
+
message: `unknown top-level manifest key '${key}'`,
|
|
720
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
// if any unknown key, bail out now before further parsing
|
|
725
|
+
if (diagnostics.length > 0) {
|
|
726
|
+
return { manifest: null, diagnostics };
|
|
727
|
+
}
|
|
728
|
+
const id = requireString(root, "id", sourcePath, diagnostics);
|
|
729
|
+
const version = requireString(root, "version", sourcePath, diagnostics);
|
|
730
|
+
if (id === undefined || version === undefined) {
|
|
731
|
+
return { manifest: null, diagnostics };
|
|
732
|
+
}
|
|
733
|
+
const extendsSpec = parseSpecifier(root.extends, sourcePath, diagnostics);
|
|
734
|
+
if (root.extends !== undefined && extendsSpec === undefined) {
|
|
735
|
+
return { manifest: null, diagnostics };
|
|
736
|
+
}
|
|
737
|
+
const rawProfile = root.profile;
|
|
738
|
+
if (rawProfile !== undefined) {
|
|
739
|
+
if (rawProfile == null || typeof rawProfile !== "object" ||
|
|
740
|
+
Array.isArray(rawProfile)) {
|
|
741
|
+
diagnostics.push({
|
|
742
|
+
code: "PROFILE-LOAD-003",
|
|
743
|
+
severity: "error",
|
|
744
|
+
message: "'profile' must be a mapping",
|
|
745
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
746
|
+
});
|
|
747
|
+
return { manifest: null, diagnostics };
|
|
748
|
+
}
|
|
749
|
+
for (const key of Object.keys(rawProfile)) {
|
|
750
|
+
if (!ALLOWED_PROFILE_KEYS.has(key)) {
|
|
751
|
+
diagnostics.push({
|
|
752
|
+
code: "PROFILE-LOAD-003",
|
|
753
|
+
severity: "error",
|
|
754
|
+
message: `unknown key under 'profile': '${key}'`,
|
|
755
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (diagnostics.length > 0) {
|
|
760
|
+
return { manifest: null, diagnostics };
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const profileSection = (rawProfile ?? {});
|
|
764
|
+
const universalRequired = parseStringList(profileSection.required, "profile.required", sourcePath, diagnostics);
|
|
765
|
+
const universalAttributes = parseAttrList(profileSection.attributes, "profile.attributes", sourcePath, diagnostics);
|
|
766
|
+
const labels = parseStringList(profileSection.labels, "profile.labels", sourcePath, diagnostics);
|
|
767
|
+
const colors = parseColorsMap(profileSection.colors, sourcePath, diagnostics);
|
|
768
|
+
if (diagnostics.length > 0) {
|
|
769
|
+
return { manifest: null, diagnostics };
|
|
770
|
+
}
|
|
771
|
+
const idRaw = parseShapeScope(profileSection.identified, ALLOWED_IDENTIFIED_KEYS, "profile.identified", sourcePath, diagnostics);
|
|
772
|
+
const refRaw = parseShapeScope(profileSection.referenced, ALLOWED_REFERENCED_KEYS, "profile.referenced", sourcePath, diagnostics);
|
|
773
|
+
if (idRaw === undefined || refRaw === undefined || diagnostics.length > 0) {
|
|
774
|
+
return { manifest: null, diagnostics };
|
|
775
|
+
}
|
|
776
|
+
const identifiedRequired = parseStringList(idRaw.required, "profile.identified.required", sourcePath, diagnostics);
|
|
777
|
+
const identifiedAttributes = parseAttrList(idRaw.attributes, "profile.identified.attributes", sourcePath, diagnostics);
|
|
778
|
+
const identifiedTraceability = parseTraceabilityMap(idRaw.traceability, "profile.identified.traceability", sourcePath, diagnostics);
|
|
779
|
+
const referencedRequired = parseStringList(refRaw.required, "profile.referenced.required", sourcePath, diagnostics);
|
|
780
|
+
const referencedAttributes = parseAttrList(refRaw.attributes, "profile.referenced.attributes", sourcePath, diagnostics);
|
|
781
|
+
if (diagnostics.length > 0) {
|
|
782
|
+
return { manifest: null, diagnostics };
|
|
783
|
+
}
|
|
784
|
+
const types = parseTypesMap(profileSection.types, sourcePath, diagnostics);
|
|
785
|
+
if (diagnostics.some((d) => d.severity === "error")) {
|
|
786
|
+
return { manifest: null, diagnostics };
|
|
787
|
+
}
|
|
788
|
+
const documents = parseDocumentsSection(profileSection.documents, sourcePath, diagnostics);
|
|
789
|
+
if (diagnostics.some((d) => d.severity === "error")) {
|
|
790
|
+
return { manifest: null, diagnostics };
|
|
791
|
+
}
|
|
792
|
+
const manifest = {
|
|
793
|
+
id,
|
|
794
|
+
version,
|
|
795
|
+
description: typeof root.description === "string"
|
|
796
|
+
? root.description
|
|
797
|
+
: undefined,
|
|
798
|
+
license: typeof root.license === "string" ? root.license : undefined,
|
|
799
|
+
extends: extendsSpec,
|
|
800
|
+
universalRequired,
|
|
801
|
+
universalAttributes,
|
|
802
|
+
labels,
|
|
803
|
+
colors,
|
|
804
|
+
identified: {
|
|
805
|
+
required: identifiedRequired,
|
|
806
|
+
attributes: identifiedAttributes,
|
|
807
|
+
traceability: identifiedTraceability,
|
|
808
|
+
},
|
|
809
|
+
referenced: {
|
|
810
|
+
required: referencedRequired,
|
|
811
|
+
attributes: referencedAttributes,
|
|
812
|
+
},
|
|
813
|
+
types: types,
|
|
814
|
+
documents: documents,
|
|
815
|
+
};
|
|
816
|
+
return { manifest, diagnostics };
|
|
817
|
+
}
|
|
818
|
+
function requireString(root, key, sourcePath, diagnostics) {
|
|
819
|
+
const v = root[key];
|
|
820
|
+
if (typeof v !== "string" || v.trim().length === 0) {
|
|
821
|
+
diagnostics.push({
|
|
822
|
+
code: "PROFILE-LOAD-003",
|
|
823
|
+
severity: "error",
|
|
824
|
+
message: `manifest missing required field '${key}' (string)`,
|
|
825
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
826
|
+
});
|
|
827
|
+
return undefined;
|
|
828
|
+
}
|
|
829
|
+
return v;
|
|
830
|
+
}
|