@driftsys/markspec 0.4.0 → 0.5.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/esm/ast/build.d.ts +70 -0
- package/esm/ast/build.d.ts.map +1 -0
- package/esm/ast/build.js +605 -0
- package/esm/ast/equivalence.d.ts +18 -0
- package/esm/ast/equivalence.d.ts.map +1 -0
- package/esm/ast/equivalence.js +56 -0
- package/esm/ast/nodes.d.ts +221 -0
- package/esm/ast/nodes.d.ts.map +1 -0
- package/esm/ast/nodes.js +12 -0
- package/esm/ast/normalize.d.ts +67 -0
- package/esm/ast/normalize.d.ts.map +1 -0
- package/esm/ast/normalize.js +255 -0
- package/esm/ast/render.d.ts +34 -0
- package/esm/ast/render.d.ts.map +1 -0
- package/esm/ast/render.js +215 -0
- package/esm/compiler/inverses.d.ts +2 -8
- package/esm/compiler/inverses.d.ts.map +1 -1
- package/esm/compiler/inverses.js +50 -14
- package/esm/compiler/manifest.d.ts +59 -0
- package/esm/compiler/manifest.d.ts.map +1 -0
- package/esm/compiler/manifest.js +48 -0
- package/esm/compiler/mod.d.ts +9 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +21 -2
- package/esm/compiler/ndjson_writer.d.ts +50 -0
- package/esm/compiler/ndjson_writer.d.ts.map +1 -0
- package/esm/compiler/ndjson_writer.js +73 -0
- package/esm/compiler/schema.d.ts +18 -1
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +18 -9
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +54 -0
- package/esm/formatter/mod.d.ts +49 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +362 -33
- package/esm/formatter/synth_ulid.d.ts +21 -0
- package/esm/formatter/synth_ulid.d.ts.map +1 -0
- package/esm/formatter/synth_ulid.js +64 -0
- package/esm/lint/mod.d.ts +10 -0
- package/esm/lint/mod.d.ts.map +1 -0
- package/esm/lint/mod.js +7 -0
- package/esm/lint/rules/lexicon.d.ts +24 -0
- package/esm/lint/rules/lexicon.d.ts.map +1 -0
- package/esm/lint/rules/lexicon.js +236 -0
- package/esm/lint/rules/struct.d.ts +17 -0
- package/esm/lint/rules/struct.d.ts.map +1 -0
- package/esm/lint/rules/struct.js +55 -0
- package/esm/lint/rules/suppression.d.ts +19 -0
- package/esm/lint/rules/suppression.d.ts.map +1 -0
- package/esm/lint/rules/suppression.js +75 -0
- package/esm/lint/runner.d.ts +39 -0
- package/esm/lint/runner.d.ts.map +1 -0
- package/esm/lint/runner.js +112 -0
- package/esm/lint/types.d.ts +19 -0
- package/esm/lint/types.d.ts.map +1 -0
- package/esm/lint/types.js +9 -0
- package/esm/mod.d.ts +19 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +14 -3
- package/esm/model/attributes.d.ts.map +1 -1
- package/esm/model/attributes.js +163 -2
- package/esm/model/discriminating_attr.d.ts +33 -0
- package/esm/model/discriminating_attr.d.ts.map +1 -0
- package/esm/model/discriminating_attr.js +74 -0
- package/esm/model/mod.d.ts +98 -3
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +57 -2
- package/esm/model/profile.d.ts +33 -27
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/model/source_introspection.d.ts +26 -0
- package/esm/model/source_introspection.d.ts.map +1 -0
- package/esm/model/source_introspection.js +77 -0
- package/esm/model/type_hierarchy.d.ts +51 -0
- package/esm/model/type_hierarchy.d.ts.map +1 -0
- package/esm/model/type_hierarchy.js +126 -0
- package/esm/model/uri_scheme_map.d.ts +21 -0
- package/esm/model/uri_scheme_map.d.ts.map +1 -0
- package/esm/model/uri_scheme_map.js +66 -0
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +9 -6
- package/esm/parser/entity_refs.d.ts +53 -0
- package/esm/parser/entity_refs.d.ts.map +1 -0
- package/esm/parser/entity_refs.js +151 -0
- package/esm/parser/glossary.d.ts +43 -0
- package/esm/parser/glossary.d.ts.map +1 -0
- package/esm/parser/glossary.js +217 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +223 -7
- package/esm/parser/mod.d.ts +1 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +1 -0
- package/esm/parser/source.d.ts +20 -0
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +3 -3
- package/esm/profile/chain.js +3 -13
- package/esm/profile/colors.js +1 -1
- package/esm/profile/introspect.d.ts +135 -0
- package/esm/profile/introspect.d.ts.map +1 -0
- package/esm/profile/introspect.js +378 -0
- package/esm/profile/load.d.ts.map +1 -1
- package/esm/profile/load.js +67 -0
- package/esm/profile/manifest.d.ts.map +1 -1
- package/esm/profile/manifest.js +277 -88
- package/esm/profile/merge.js +139 -39
- package/esm/profile/mod.d.ts +2 -4
- package/esm/profile/mod.d.ts.map +1 -1
- package/esm/profile/mod.js +5 -2
- package/esm/reporter/mod.js +4 -4
- package/esm/util/fence.d.ts +30 -0
- package/esm/util/fence.d.ts.map +1 -0
- package/esm/util/fence.js +40 -0
- package/esm/validator/attributes.d.ts +3 -3
- package/esm/validator/attributes.d.ts.map +1 -1
- package/esm/validator/attributes.js +1 -18
- package/esm/validator/body_blocks.d.ts +38 -0
- package/esm/validator/body_blocks.d.ts.map +1 -0
- package/esm/validator/body_blocks.js +218 -0
- package/esm/validator/caption_convention.d.ts +29 -0
- package/esm/validator/caption_convention.d.ts.map +1 -0
- package/esm/validator/caption_convention.js +58 -0
- package/esm/validator/captions.d.ts +22 -0
- package/esm/validator/captions.d.ts.map +1 -0
- package/esm/validator/captions.js +137 -0
- package/esm/validator/component_schemes.d.ts +73 -0
- package/esm/validator/component_schemes.d.ts.map +1 -0
- package/esm/validator/component_schemes.js +375 -0
- package/esm/validator/feature_ac.d.ts +28 -0
- package/esm/validator/feature_ac.d.ts.map +1 -0
- package/esm/validator/feature_ac.js +102 -0
- package/esm/validator/listing.d.ts +42 -0
- package/esm/validator/listing.d.ts.map +1 -0
- package/esm/validator/listing.js +295 -0
- package/esm/validator/mod.d.ts +2 -0
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +253 -12
- package/esm/validator/modal_keywords.d.ts +23 -0
- package/esm/validator/modal_keywords.d.ts.map +1 -0
- package/esm/validator/modal_keywords.js +137 -0
- package/esm/validator/per_type_attrs.d.ts +29 -0
- package/esm/validator/per_type_attrs.d.ts.map +1 -0
- package/esm/validator/per_type_attrs.js +75 -0
- package/esm/validator/pipeline.d.ts +7 -2
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +40 -7
- package/esm/validator/trace_types.d.ts +26 -0
- package/esm/validator/trace_types.d.ts.map +1 -0
- package/esm/validator/trace_types.js +232 -0
- package/esm/validator/traceability.d.ts +3 -4
- package/esm/validator/traceability.d.ts.map +1 -1
- package/esm/validator/traceability.js +5 -10
- package/esm/validator/type_resolution.d.ts +67 -0
- package/esm/validator/type_resolution.d.ts.map +1 -0
- package/esm/validator/type_resolution.js +140 -0
- package/esm/validator/types.d.ts +45 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/types.js +128 -16
- package/esm/validator/value_types.d.ts +8 -0
- package/esm/validator/value_types.d.ts.map +1 -1
- package/esm/validator/value_types.js +8 -1
- package/package.json +1 -1
- package/script/ast/build.d.ts +70 -0
- package/script/ast/build.d.ts.map +1 -0
- package/script/ast/build.js +610 -0
- package/script/ast/equivalence.d.ts +18 -0
- package/script/ast/equivalence.d.ts.map +1 -0
- package/script/ast/equivalence.js +59 -0
- package/script/ast/nodes.d.ts +221 -0
- package/script/ast/nodes.d.ts.map +1 -0
- package/script/ast/nodes.js +13 -0
- package/script/ast/normalize.d.ts +67 -0
- package/script/ast/normalize.d.ts.map +1 -0
- package/script/ast/normalize.js +258 -0
- package/script/ast/render.d.ts +34 -0
- package/script/ast/render.d.ts.map +1 -0
- package/script/ast/render.js +218 -0
- package/script/compiler/inverses.d.ts +2 -8
- package/script/compiler/inverses.d.ts.map +1 -1
- package/script/compiler/inverses.js +50 -14
- package/script/compiler/manifest.d.ts +59 -0
- package/script/compiler/manifest.d.ts.map +1 -0
- package/script/compiler/manifest.js +51 -0
- package/script/compiler/mod.d.ts +9 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +21 -2
- package/script/compiler/ndjson_writer.d.ts +50 -0
- package/script/compiler/ndjson_writer.d.ts.map +1 -0
- package/script/compiler/ndjson_writer.js +78 -0
- package/script/compiler/schema.d.ts +18 -1
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +18 -8
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +54 -0
- package/script/formatter/mod.d.ts +49 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +365 -33
- package/script/formatter/synth_ulid.d.ts +21 -0
- package/script/formatter/synth_ulid.d.ts.map +1 -0
- package/script/formatter/synth_ulid.js +67 -0
- package/script/lint/mod.d.ts +10 -0
- package/script/lint/mod.d.ts.map +1 -0
- package/script/lint/mod.js +12 -0
- package/script/lint/rules/lexicon.d.ts +24 -0
- package/script/lint/rules/lexicon.d.ts.map +1 -0
- package/script/lint/rules/lexicon.js +240 -0
- package/script/lint/rules/struct.d.ts +17 -0
- package/script/lint/rules/struct.d.ts.map +1 -0
- package/script/lint/rules/struct.js +59 -0
- package/script/lint/rules/suppression.d.ts +19 -0
- package/script/lint/rules/suppression.d.ts.map +1 -0
- package/script/lint/rules/suppression.js +80 -0
- package/script/lint/runner.d.ts +39 -0
- package/script/lint/runner.d.ts.map +1 -0
- package/script/lint/runner.js +116 -0
- package/script/lint/types.d.ts +19 -0
- package/script/lint/types.d.ts.map +1 -0
- package/script/lint/types.js +10 -0
- package/script/mod.d.ts +19 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +56 -32
- package/script/model/attributes.d.ts.map +1 -1
- package/script/model/attributes.js +163 -2
- package/script/model/discriminating_attr.d.ts +33 -0
- package/script/model/discriminating_attr.d.ts.map +1 -0
- package/script/model/discriminating_attr.js +77 -0
- package/script/model/mod.d.ts +98 -3
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +64 -3
- package/script/model/profile.d.ts +33 -27
- package/script/model/profile.d.ts.map +1 -1
- package/script/model/source_introspection.d.ts +26 -0
- package/script/model/source_introspection.d.ts.map +1 -0
- package/script/model/source_introspection.js +80 -0
- package/script/model/type_hierarchy.d.ts +51 -0
- package/script/model/type_hierarchy.d.ts.map +1 -0
- package/script/model/type_hierarchy.js +130 -0
- package/script/model/uri_scheme_map.d.ts +21 -0
- package/script/model/uri_scheme_map.d.ts.map +1 -0
- package/script/model/uri_scheme_map.js +69 -0
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +9 -6
- package/script/parser/entity_refs.d.ts +53 -0
- package/script/parser/entity_refs.d.ts.map +1 -0
- package/script/parser/entity_refs.js +155 -0
- package/script/parser/glossary.d.ts +43 -0
- package/script/parser/glossary.d.ts.map +1 -0
- package/script/parser/glossary.js +221 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +222 -6
- package/script/parser/mod.d.ts +1 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +5 -1
- package/script/parser/source.d.ts +20 -0
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +3 -0
- package/script/profile/chain.js +3 -13
- package/script/profile/colors.js +1 -1
- package/script/profile/introspect.d.ts +135 -0
- package/script/profile/introspect.d.ts.map +1 -0
- package/script/profile/introspect.js +381 -0
- package/script/profile/load.d.ts.map +1 -1
- package/script/profile/load.js +67 -0
- package/script/profile/manifest.d.ts.map +1 -1
- package/script/profile/manifest.js +276 -87
- package/script/profile/merge.js +139 -39
- package/script/profile/mod.d.ts +2 -4
- package/script/profile/mod.d.ts.map +1 -1
- package/script/profile/mod.js +7 -6
- package/script/reporter/mod.js +4 -4
- package/script/util/fence.d.ts +30 -0
- package/script/util/fence.d.ts.map +1 -0
- package/script/util/fence.js +44 -0
- package/script/validator/attributes.d.ts +3 -3
- package/script/validator/attributes.d.ts.map +1 -1
- package/script/validator/attributes.js +1 -18
- package/script/validator/body_blocks.d.ts +38 -0
- package/script/validator/body_blocks.d.ts.map +1 -0
- package/script/validator/body_blocks.js +221 -0
- package/script/validator/caption_convention.d.ts +29 -0
- package/script/validator/caption_convention.d.ts.map +1 -0
- package/script/validator/caption_convention.js +61 -0
- package/script/validator/captions.d.ts +22 -0
- package/script/validator/captions.d.ts.map +1 -0
- package/script/validator/captions.js +140 -0
- package/script/validator/component_schemes.d.ts +73 -0
- package/script/validator/component_schemes.d.ts.map +1 -0
- package/script/validator/component_schemes.js +384 -0
- package/script/validator/feature_ac.d.ts +28 -0
- package/script/validator/feature_ac.d.ts.map +1 -0
- package/script/validator/feature_ac.js +105 -0
- package/script/validator/listing.d.ts +42 -0
- package/script/validator/listing.d.ts.map +1 -0
- package/script/validator/listing.js +298 -0
- package/script/validator/mod.d.ts +2 -0
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +256 -14
- package/script/validator/modal_keywords.d.ts +23 -0
- package/script/validator/modal_keywords.d.ts.map +1 -0
- package/script/validator/modal_keywords.js +140 -0
- package/script/validator/per_type_attrs.d.ts +29 -0
- package/script/validator/per_type_attrs.d.ts.map +1 -0
- package/script/validator/per_type_attrs.js +78 -0
- package/script/validator/pipeline.d.ts +7 -2
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +39 -6
- package/script/validator/trace_types.d.ts +26 -0
- package/script/validator/trace_types.d.ts.map +1 -0
- package/script/validator/trace_types.js +235 -0
- package/script/validator/traceability.d.ts +3 -4
- package/script/validator/traceability.d.ts.map +1 -1
- package/script/validator/traceability.js +5 -10
- package/script/validator/type_resolution.d.ts +67 -0
- package/script/validator/type_resolution.d.ts.map +1 -0
- package/script/validator/type_resolution.js +146 -0
- package/script/validator/types.d.ts +45 -0
- package/script/validator/types.d.ts.map +1 -1
- package/script/validator/types.js +131 -16
- package/script/validator/value_types.d.ts +8 -0
- package/script/validator/value_types.d.ts.map +1 -1
- package/script/validator/value_types.js +10 -2
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile/introspect
|
|
4
|
+
*
|
|
5
|
+
* Unified introspection API for profile chains. All discovery surfaces
|
|
6
|
+
* (CLI, MCP, LSP) consume this module instead of re-walking EffectiveProfile.
|
|
7
|
+
*
|
|
8
|
+
* Node-safe: no Deno.* APIs.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.buildProfileIntrospection = buildProfileIntrospection;
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Factory
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
/**
|
|
16
|
+
* Build a `ProfileIntrospection` from a profile chain (or `null` when
|
|
17
|
+
* no profile is configured for the project).
|
|
18
|
+
*
|
|
19
|
+
* The returned object is lazy — `overview()` caches after the first call.
|
|
20
|
+
*/
|
|
21
|
+
function buildProfileIntrospection(chain) {
|
|
22
|
+
if (!chain) {
|
|
23
|
+
return {
|
|
24
|
+
overview: () => ({
|
|
25
|
+
tiers: [
|
|
26
|
+
{ id: "(none)", version: "", summary: "No profile configured" },
|
|
27
|
+
],
|
|
28
|
+
elements: [],
|
|
29
|
+
}),
|
|
30
|
+
describe: () => undefined,
|
|
31
|
+
resolve: () => [],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// Capture non-null references so inner closures type-check.
|
|
35
|
+
const nonNullChain = chain;
|
|
36
|
+
const effective = nonNullChain.effective;
|
|
37
|
+
let cachedOverview;
|
|
38
|
+
function getOverview() {
|
|
39
|
+
if (cachedOverview)
|
|
40
|
+
return cachedOverview;
|
|
41
|
+
const tiers = nonNullChain.tiers.map((tier) => ({
|
|
42
|
+
id: tier.id,
|
|
43
|
+
version: tier.version,
|
|
44
|
+
summary: tier.manifest.description ?? tier.id,
|
|
45
|
+
}));
|
|
46
|
+
const elements = [];
|
|
47
|
+
// Types
|
|
48
|
+
for (const [name, entry] of effective.types) {
|
|
49
|
+
const tdef = entry.value;
|
|
50
|
+
const summary = tdef.description.value ?? tdef.extends;
|
|
51
|
+
elements.push({
|
|
52
|
+
kind: "type",
|
|
53
|
+
name,
|
|
54
|
+
summary,
|
|
55
|
+
ref: `type/${name}`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Universal attributes
|
|
59
|
+
for (const [name, entry] of effective.attributes) {
|
|
60
|
+
const decl = entry.value;
|
|
61
|
+
const summary = decl.description ??
|
|
62
|
+
`${decl.type}, ${formatCardinality(decl.cardinality)}`;
|
|
63
|
+
elements.push({
|
|
64
|
+
kind: "attribute",
|
|
65
|
+
name,
|
|
66
|
+
summary,
|
|
67
|
+
ref: `attribute/${name}`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// Relations (deduplicated across types)
|
|
71
|
+
const seenRelations = new Map();
|
|
72
|
+
for (const [, typeEntry] of effective.types) {
|
|
73
|
+
const tdef = typeEntry.value;
|
|
74
|
+
for (const [relName, ruleEntry] of tdef.traceability) {
|
|
75
|
+
const existing = seenRelations.get(relName);
|
|
76
|
+
const desc = tdef.relationDescriptions.get(relName);
|
|
77
|
+
if (!existing) {
|
|
78
|
+
seenRelations.set(relName, {
|
|
79
|
+
targets: new Set(ruleEntry.value.target.map(targetToString)),
|
|
80
|
+
description: desc?.value,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
for (const t of ruleEntry.value.target.map(targetToString)) {
|
|
85
|
+
existing.targets.add(t);
|
|
86
|
+
}
|
|
87
|
+
if (desc?.value !== undefined && existing.description === undefined) {
|
|
88
|
+
existing.description = desc.value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const [name, info] of seenRelations) {
|
|
94
|
+
const summary = info.description ??
|
|
95
|
+
`targets: ${[...info.targets].join(", ")}`;
|
|
96
|
+
elements.push({
|
|
97
|
+
kind: "relation",
|
|
98
|
+
name,
|
|
99
|
+
summary,
|
|
100
|
+
ref: `relation/${name}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Label concerns
|
|
104
|
+
for (const [name, entry] of effective.labels) {
|
|
105
|
+
const concern = entry.value;
|
|
106
|
+
const summary = concern.description ??
|
|
107
|
+
`${concern.kind}, ${concern.values.length} values`;
|
|
108
|
+
elements.push({
|
|
109
|
+
kind: "label-concern",
|
|
110
|
+
name,
|
|
111
|
+
summary,
|
|
112
|
+
ref: `label/${name}`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// Conventions
|
|
116
|
+
for (const [name, entry] of effective.conventions) {
|
|
117
|
+
const conv = entry.value;
|
|
118
|
+
const summary = conv.description ??
|
|
119
|
+
Object.entries(conv.settings).map(([k, v]) => `${k}=${v}`).join(" ");
|
|
120
|
+
elements.push({
|
|
121
|
+
kind: "convention",
|
|
122
|
+
name,
|
|
123
|
+
summary,
|
|
124
|
+
ref: `convention/${name}`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Sort by kind order, then name within kind.
|
|
128
|
+
const KIND_ORDER = {
|
|
129
|
+
"type": 0,
|
|
130
|
+
"attribute": 1,
|
|
131
|
+
"relation": 2,
|
|
132
|
+
"label-concern": 3,
|
|
133
|
+
"convention": 4,
|
|
134
|
+
};
|
|
135
|
+
elements.sort((a, b) => {
|
|
136
|
+
const kDiff = KIND_ORDER[a.kind] - KIND_ORDER[b.kind];
|
|
137
|
+
return kDiff !== 0 ? kDiff : a.name.localeCompare(b.name);
|
|
138
|
+
});
|
|
139
|
+
cachedOverview = { tiers, elements };
|
|
140
|
+
return cachedOverview;
|
|
141
|
+
}
|
|
142
|
+
function describe(kind, name) {
|
|
143
|
+
switch (kind) {
|
|
144
|
+
case "type":
|
|
145
|
+
return describeType(name, effective);
|
|
146
|
+
case "attribute":
|
|
147
|
+
return describeAttribute(name, effective);
|
|
148
|
+
case "relation":
|
|
149
|
+
return describeRelation(name, effective);
|
|
150
|
+
case "label-concern":
|
|
151
|
+
return describeLabelConcern(name, effective);
|
|
152
|
+
case "convention":
|
|
153
|
+
return describeConvention(name, effective);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function resolve(query) {
|
|
157
|
+
const tokens = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
158
|
+
if (tokens.length === 0)
|
|
159
|
+
return [];
|
|
160
|
+
const overview = getOverview();
|
|
161
|
+
return overview.elements.filter((ref) => {
|
|
162
|
+
const haystack = `${ref.kind} ${ref.name} ${ref.summary}`.toLowerCase();
|
|
163
|
+
return tokens.every((t) => haystack.includes(t));
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return { overview: getOverview, describe, resolve };
|
|
167
|
+
}
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Per-element describe helpers
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
function describeType(name, effective) {
|
|
172
|
+
const entry = effective.types.get(name);
|
|
173
|
+
if (!entry)
|
|
174
|
+
return undefined;
|
|
175
|
+
const tdef = entry.value;
|
|
176
|
+
const description = provenancedFromValue(tdef.description);
|
|
177
|
+
// Required attributes: those listed in tdef.required
|
|
178
|
+
const requiredAttributes = tdef.required.value
|
|
179
|
+
.map((attrName) => attrRef(attrName, effective, tdef));
|
|
180
|
+
// Allowed attributes: all declared attrs minus required
|
|
181
|
+
const requiredSet = new Set(tdef.required.value);
|
|
182
|
+
const allAttrNames = [
|
|
183
|
+
...tdef.attributes.keys(),
|
|
184
|
+
...effective.attributes.keys(),
|
|
185
|
+
].filter((attrName, i, arr) => arr.indexOf(attrName) === i); // dedupe
|
|
186
|
+
const allowedAttributes = allAttrNames
|
|
187
|
+
.filter((attrName) => !requiredSet.has(attrName))
|
|
188
|
+
.map((attrName) => attrRef(attrName, effective, tdef));
|
|
189
|
+
// Outgoing relations
|
|
190
|
+
const outgoingRelations = [
|
|
191
|
+
...tdef.traceability.keys(),
|
|
192
|
+
].map((relName) => {
|
|
193
|
+
const descEntry = tdef.relationDescriptions.get(relName);
|
|
194
|
+
const rule = tdef.traceability.get(relName);
|
|
195
|
+
const summary = descEntry?.value ??
|
|
196
|
+
`targets: ${rule.value.target.map(targetToString).join(", ")}`;
|
|
197
|
+
return {
|
|
198
|
+
kind: "relation",
|
|
199
|
+
name: relName,
|
|
200
|
+
summary,
|
|
201
|
+
ref: `relation/${relName}`,
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
// Incoming relations: types whose traceability targets this type by name
|
|
205
|
+
const incomingRelations = [];
|
|
206
|
+
const seenIn = new Set();
|
|
207
|
+
for (const [otherTypeName, otherEntry] of effective.types) {
|
|
208
|
+
if (otherTypeName === name)
|
|
209
|
+
continue;
|
|
210
|
+
for (const [relName, ruleEntry] of otherEntry.value.traceability) {
|
|
211
|
+
if (seenIn.has(relName))
|
|
212
|
+
continue;
|
|
213
|
+
const targets = ruleEntry.value.target;
|
|
214
|
+
const matches = targets.some((t) => typeof t === "string" ? t === name : false);
|
|
215
|
+
if (matches) {
|
|
216
|
+
seenIn.add(relName);
|
|
217
|
+
const relDesc = otherEntry.value.relationDescriptions.get(relName);
|
|
218
|
+
const summary = relDesc?.value ?? `from ${otherTypeName}`;
|
|
219
|
+
incomingRelations.push({
|
|
220
|
+
kind: "relation",
|
|
221
|
+
name: relName,
|
|
222
|
+
summary,
|
|
223
|
+
ref: `relation/${relName}`,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
kind: "type",
|
|
230
|
+
name,
|
|
231
|
+
description,
|
|
232
|
+
extendsTarget: tdef.extends,
|
|
233
|
+
shape: tdef.extends,
|
|
234
|
+
displayIdPattern: tdef.displayIdPattern.value,
|
|
235
|
+
color: tdef.color.value,
|
|
236
|
+
requiredAttributes,
|
|
237
|
+
allowedAttributes,
|
|
238
|
+
outgoingRelations,
|
|
239
|
+
incomingRelations,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function attrRef(attrName, effective, tdef) {
|
|
243
|
+
// Look in type-specific scope first, then universal.
|
|
244
|
+
const typeAttr = tdef.attributes.get(attrName)?.value;
|
|
245
|
+
const universalAttr = effective.attributes.get(attrName)?.value;
|
|
246
|
+
const attrDecl = typeAttr ?? universalAttr;
|
|
247
|
+
const attrDesc = tdef.attrDescriptions.get(attrName);
|
|
248
|
+
const summary = attrDesc?.value ??
|
|
249
|
+
attrDecl?.description ??
|
|
250
|
+
(attrDecl
|
|
251
|
+
? `${attrDecl.type}, ${formatCardinality(attrDecl.cardinality)}`
|
|
252
|
+
: attrName);
|
|
253
|
+
return {
|
|
254
|
+
kind: "attribute",
|
|
255
|
+
name: attrName,
|
|
256
|
+
summary,
|
|
257
|
+
ref: `attribute/${attrName}`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function describeAttribute(name, effective) {
|
|
261
|
+
const entry = effective.attributes.get(name);
|
|
262
|
+
if (!entry)
|
|
263
|
+
return undefined;
|
|
264
|
+
const decl = entry.value;
|
|
265
|
+
// Find which types also declare this attribute.
|
|
266
|
+
const declaredBy = ["universal"];
|
|
267
|
+
for (const [typeName, typeEntry] of effective.types) {
|
|
268
|
+
if (typeEntry.value.attributes.has(name)) {
|
|
269
|
+
declaredBy.push(typeName);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const description = {
|
|
273
|
+
text: decl.description,
|
|
274
|
+
origin: decl.description !== undefined ? entry.origin : undefined,
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
kind: "attribute",
|
|
278
|
+
name,
|
|
279
|
+
description,
|
|
280
|
+
valueType: decl.type,
|
|
281
|
+
cardinality: formatCardinality(decl.cardinality),
|
|
282
|
+
required: decl.required,
|
|
283
|
+
enumValues: decl.values,
|
|
284
|
+
inverse: decl.inverse,
|
|
285
|
+
declaredBy,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function describeRelation(name, effective) {
|
|
289
|
+
const declaredBy = [];
|
|
290
|
+
let bestDesc = {};
|
|
291
|
+
const targets = [];
|
|
292
|
+
let required = false;
|
|
293
|
+
let cardinality;
|
|
294
|
+
for (const [typeName, typeEntry] of effective.types) {
|
|
295
|
+
const tdef = typeEntry.value;
|
|
296
|
+
const ruleEntry = tdef.traceability.get(name);
|
|
297
|
+
if (!ruleEntry)
|
|
298
|
+
continue;
|
|
299
|
+
declaredBy.push(typeName);
|
|
300
|
+
const rule = ruleEntry.value;
|
|
301
|
+
for (const t of rule.target.map(targetToString)) {
|
|
302
|
+
if (!targets.includes(t))
|
|
303
|
+
targets.push(t);
|
|
304
|
+
}
|
|
305
|
+
if (rule.required)
|
|
306
|
+
required = true;
|
|
307
|
+
if (rule.cardinality) {
|
|
308
|
+
cardinality = formatCardinality(rule.cardinality);
|
|
309
|
+
}
|
|
310
|
+
const descEntry = tdef.relationDescriptions.get(name);
|
|
311
|
+
if (descEntry?.value !== undefined && bestDesc.text === undefined) {
|
|
312
|
+
bestDesc = {
|
|
313
|
+
text: descEntry.value,
|
|
314
|
+
origin: descEntry.origin,
|
|
315
|
+
overrides: descEntry.overrides ? [...descEntry.overrides] : undefined,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (declaredBy.length === 0)
|
|
320
|
+
return undefined;
|
|
321
|
+
return {
|
|
322
|
+
kind: "relation",
|
|
323
|
+
name,
|
|
324
|
+
description: bestDesc,
|
|
325
|
+
targets,
|
|
326
|
+
cardinality,
|
|
327
|
+
required,
|
|
328
|
+
declaredBy,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function describeLabelConcern(name, effective) {
|
|
332
|
+
const entry = effective.labels.get(name);
|
|
333
|
+
if (!entry)
|
|
334
|
+
return undefined;
|
|
335
|
+
const concern = entry.value;
|
|
336
|
+
const description = {
|
|
337
|
+
text: concern.description,
|
|
338
|
+
origin: concern.description !== undefined ? entry.origin : undefined,
|
|
339
|
+
overrides: entry.overrides ? [...entry.overrides] : undefined,
|
|
340
|
+
};
|
|
341
|
+
return {
|
|
342
|
+
kind: "label-concern",
|
|
343
|
+
name,
|
|
344
|
+
description,
|
|
345
|
+
concernKind: concern.kind,
|
|
346
|
+
values: concern.values,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function describeConvention(name, effective) {
|
|
350
|
+
const entry = effective.conventions.get(name);
|
|
351
|
+
if (!entry)
|
|
352
|
+
return undefined;
|
|
353
|
+
const conv = entry.value;
|
|
354
|
+
const description = {
|
|
355
|
+
text: conv.description,
|
|
356
|
+
origin: conv.description !== undefined ? entry.origin : undefined,
|
|
357
|
+
overrides: entry.overrides ? [...entry.overrides] : undefined,
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
kind: "convention",
|
|
361
|
+
name,
|
|
362
|
+
description,
|
|
363
|
+
settings: conv.settings,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
// ---------------------------------------------------------------------------
|
|
367
|
+
// Helpers
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
function provenancedFromValue(pv) {
|
|
370
|
+
return {
|
|
371
|
+
text: pv.value,
|
|
372
|
+
origin: pv.value !== undefined ? pv.origin : undefined,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function formatCardinality(card) {
|
|
376
|
+
const upper = card.upper === Infinity ? "N" : String(card.upper);
|
|
377
|
+
return `${card.lower}..${upper}`;
|
|
378
|
+
}
|
|
379
|
+
function targetToString(t) {
|
|
380
|
+
return typeof t === "string" ? t : `{shape:${t.shape}}`;
|
|
381
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/profile/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/profile/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIhE,yCAAyC;AACzC,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,2BAA2B,CAAC,CA4CtC"}
|
package/script/profile/load.js
CHANGED
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.loadProfileForCommand = loadProfileForCommand;
|
|
12
12
|
const path_1 = require("@std/path");
|
|
13
13
|
const markspec_js_1 = require("../config/markspec.js");
|
|
14
|
+
const mod_js_1 = require("../model/mod.js");
|
|
14
15
|
const chain_js_1 = require("./chain.js");
|
|
15
16
|
/**
|
|
16
17
|
* Load the active profile chain for the project at `projectRoot`.
|
|
@@ -49,5 +50,71 @@ async function loadProfileForCommand(projectRoot, readFile) {
|
|
|
49
50
|
}
|
|
50
51
|
const chainResult = await (0, chain_js_1.loadChain)(profiles[0], projectRoot, projectRoot, readFile);
|
|
51
52
|
diagnostics.push(...chainResult.diagnostics);
|
|
53
|
+
// MSL-A040 — profile must not redefine reserved core keys / types.
|
|
54
|
+
if (chainResult.chain) {
|
|
55
|
+
diagnostics.push(...checkReservedRedefinitions(chainResult.chain));
|
|
56
|
+
}
|
|
52
57
|
return { chain: chainResult.chain, diagnostics };
|
|
53
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Reserved attribute names a profile must never declare. Per spec
|
|
61
|
+
* §4.4 MSL-A040 and ADR-009 §6: the identity slot (`Id`) and the
|
|
62
|
+
* type attribute (`Type`) are the absolutely reserved keys; their
|
|
63
|
+
* meaning is fixed by the core and any profile redefinition would
|
|
64
|
+
* silently break shape discrimination or type resolution.
|
|
65
|
+
*/
|
|
66
|
+
const RESERVED_ATTRIBUTE_KEYS = new Set([
|
|
67
|
+
"Id",
|
|
68
|
+
"Type",
|
|
69
|
+
]);
|
|
70
|
+
/**
|
|
71
|
+
* Scan the loaded profile chain for declarations that shadow core
|
|
72
|
+
* reserved names and emit MSL-A040 diagnostics. The check inspects:
|
|
73
|
+
*
|
|
74
|
+
* - universal `attributes:` scope,
|
|
75
|
+
* - per-shape `identified.attributes:` and `referenced.attributes:`,
|
|
76
|
+
* - every per-type `attributes:` map under `types:`,
|
|
77
|
+
* - each declared type name itself (must not match a core type).
|
|
78
|
+
*/
|
|
79
|
+
function checkReservedRedefinitions(chain) {
|
|
80
|
+
const diagnostics = [];
|
|
81
|
+
const effective = chain.effective;
|
|
82
|
+
// Build origin → sourcePath index from the chain's tiers so diagnostics
|
|
83
|
+
// can point at the manifest file that introduced each declaration.
|
|
84
|
+
const originToPath = new Map();
|
|
85
|
+
for (const tier of chain.tiers) {
|
|
86
|
+
originToPath.set(tier.id, tier.sourcePath);
|
|
87
|
+
}
|
|
88
|
+
// Fallback file when an origin somehow isn't in the tier list.
|
|
89
|
+
const fallbackPath = chain.tiers[0]?.sourcePath ?? "<profile>";
|
|
90
|
+
function pathFor(origin) {
|
|
91
|
+
return originToPath.get(origin) ?? fallbackPath;
|
|
92
|
+
}
|
|
93
|
+
function checkAttrMap(map, scope) {
|
|
94
|
+
for (const [key, entry] of map) {
|
|
95
|
+
if (RESERVED_ATTRIBUTE_KEYS.has(key)) {
|
|
96
|
+
diagnostics.push({
|
|
97
|
+
code: "MSL-A040",
|
|
98
|
+
severity: "error",
|
|
99
|
+
message: `profile ${scope} attribute '${key}' shadows a core ` +
|
|
100
|
+
`reserved key (spec §4.4, ADR-009 §6); choose a different name`,
|
|
101
|
+
location: { file: pathFor(entry.origin), line: 1, column: 1 },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
checkAttrMap(effective.attributes, "universal");
|
|
107
|
+
for (const [typeName, typeEntry] of effective.types) {
|
|
108
|
+
checkAttrMap(typeEntry.value.attributes, `type '${typeName}'`);
|
|
109
|
+
if (mod_js_1.CORE_TYPES.has(typeName)) {
|
|
110
|
+
diagnostics.push({
|
|
111
|
+
code: "MSL-A040",
|
|
112
|
+
severity: "error",
|
|
113
|
+
message: `profile type '${typeName}' shadows a core type name ` +
|
|
114
|
+
`(spec §4.4); the 15-type core vocabulary is reserved`,
|
|
115
|
+
location: { file: pathFor(typeEntry.origin), line: 1, column: 1 },
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return diagnostics;
|
|
120
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA4EnE,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAo9BD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CA6KrB"}
|