@aestheticfunction/dspack-emit 0.4.1 → 0.6.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 +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +1004 -222
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +66 -2
- package/dist/transform/model.d.ts +368 -0
- package/dist/transform/model.js +169 -0
- package/dist/transform/parse-v2.d.ts +109 -0
- package/dist/transform/parse-v2.js +479 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +608 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +77 -0
- package/dist/transform/shadcn-v2-respelling.js +456 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +136 -0
- package/dist/types.d.ts +23 -0
- package/dist/validate/ajv.js +96 -25
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/a0.test.ts +235 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +102 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +369 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/t1.test.ts +369 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +1468 -235
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +60 -2
- package/src/transform/model.ts +427 -0
- package/src/transform/parse-v2.ts +608 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +608 -0
- package/src/transform/profile.v2.schema.json +600 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +475 -0
- package/src/transform/validate-v2.ts +174 -0
- package/src/types.ts +32 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1 surface-plan directives -> the internal transformation model.
|
|
3
|
+
*
|
|
4
|
+
* Every authored directive is surface syntax for one or more Identity / Route /
|
|
5
|
+
* Collect facts. This module is the whole of that translation, and it is the
|
|
6
|
+
* only place in the package that knows the v1 directive names: past here, the
|
|
7
|
+
* engine sees primitives.
|
|
8
|
+
*
|
|
9
|
+
* The translation must be EXACT, not approximate — v1 profiles keep emitting
|
|
10
|
+
* byte-identically (src/byte-neutral.test.ts is the gate), so every quirk of
|
|
11
|
+
* the original directives is reproduced here deliberately, with the quirk named:
|
|
12
|
+
*
|
|
13
|
+
* - `subText` visits the node itself, not only its descendants;
|
|
14
|
+
* - `subButtonText` accepts only label-bearing components, then falls back to
|
|
15
|
+
* an audited lift of the first direct text under the sub;
|
|
16
|
+
* - `textProp`/`textChildProp` overwrite, while everything else is first-wins;
|
|
17
|
+
* - `subTable` accepts a header-cell wherever a cell is expected, concatenates
|
|
18
|
+
* multiple header rows into one flat column list, and takes the first caption;
|
|
19
|
+
* - `structuralPassthrough` wins over any consumed value.
|
|
20
|
+
*
|
|
21
|
+
* Reading this file top to bottom is also the v1 -> internal mapping table.
|
|
22
|
+
*/
|
|
23
|
+
import type { ComponentPlan, SurfacePlanDirectives } from "./profiles.js";
|
|
24
|
+
import { type SurfaceModel } from "./model.js";
|
|
25
|
+
/**
|
|
26
|
+
* The internal model for a plan, whichever language it is written in: a v2
|
|
27
|
+
* `surface` block parses directly; v1 directives desugar. Both languages meet
|
|
28
|
+
* the engine only as this model — the engine cannot tell them apart, which is
|
|
29
|
+
* the compatibility guarantee.
|
|
30
|
+
*/
|
|
31
|
+
export declare function surfaceModelOf(plan: ComponentPlan): SurfaceModel;
|
|
32
|
+
export declare function desugar(sp: SurfacePlanDirectives): SurfaceModel;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { parseSurfaceV2 } from "./parse-v2.js";
|
|
2
|
+
import { emptySurfaceModel, WriteOrder } from "./model.js";
|
|
3
|
+
/** Cache: a plan's model is derived once, not per emitted node. */
|
|
4
|
+
const cache = new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* The internal model for a plan, whichever language it is written in: a v2
|
|
7
|
+
* `surface` block parses directly; v1 directives desugar. Both languages meet
|
|
8
|
+
* the engine only as this model — the engine cannot tell them apart, which is
|
|
9
|
+
* the compatibility guarantee.
|
|
10
|
+
*/
|
|
11
|
+
export function surfaceModelOf(plan) {
|
|
12
|
+
const hit = cache.get(plan);
|
|
13
|
+
if (hit)
|
|
14
|
+
return hit;
|
|
15
|
+
const model = plan.surface ? parseSurfaceV2(plan.surface, plan, "/surface") : desugar(plan.surfacePlan ?? {});
|
|
16
|
+
cache.set(plan, model);
|
|
17
|
+
return model;
|
|
18
|
+
}
|
|
19
|
+
export function desugar(sp) {
|
|
20
|
+
const model = emptySurfaceModel();
|
|
21
|
+
const route = (r) => model.routes.push(r);
|
|
22
|
+
// structuralPassthrough: CSR props copied verbatim into same-named slots.
|
|
23
|
+
// Listed first because it wins over consumed values, and the engine applies
|
|
24
|
+
// routes in order with first-write-wins.
|
|
25
|
+
for (const key of sp.structuralPassthrough ?? []) {
|
|
26
|
+
route({
|
|
27
|
+
order: WriteOrder.Verbatim,
|
|
28
|
+
from: [{ kind: "self-prop", prop: key }],
|
|
29
|
+
to: { kind: "prop", name: key },
|
|
30
|
+
origin: "structuralPassthrough",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// subText: descendant text -> a named prop. One route per target prop; the
|
|
34
|
+
// selector names every sub that feeds it, which is also how two sub ids
|
|
35
|
+
// sharing one destination stay a single first-wins decision.
|
|
36
|
+
const bySubTextTarget = new Map();
|
|
37
|
+
for (const [sub, prop] of Object.entries(sp.subText ?? {})) {
|
|
38
|
+
bySubTextTarget.set(prop, [...(bySubTextTarget.get(prop) ?? []), sub]);
|
|
39
|
+
}
|
|
40
|
+
for (const [prop, subs] of bySubTextTarget) {
|
|
41
|
+
route({ order: WriteOrder.Consume, from: [{ kind: "sub-text", subs }], to: { kind: "prop", name: prop }, origin: "subText" });
|
|
42
|
+
}
|
|
43
|
+
// subButtonText: the label of a label-bearing component inside the sub, else
|
|
44
|
+
// an audited lift of the first direct text under it. One route, two ordered
|
|
45
|
+
// selectors — the fallback that motivated Selector[].
|
|
46
|
+
for (const [sub, prop] of Object.entries(sp.subButtonText ?? {})) {
|
|
47
|
+
route({
|
|
48
|
+
order: WriteOrder.Consume,
|
|
49
|
+
from: [
|
|
50
|
+
{ kind: "sub-label", subs: [sub] },
|
|
51
|
+
{ kind: "sub-text-lift", subs: [sub] },
|
|
52
|
+
],
|
|
53
|
+
to: { kind: "prop", name: prop },
|
|
54
|
+
origin: "subButtonText",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// subTable: three nested collects plus a caption route. Nothing here is
|
|
58
|
+
// table-shaped except the sub ids the profile names — the depth is nesting,
|
|
59
|
+
// the record key is an item field name, and the drops are ordinary drops.
|
|
60
|
+
if (sp.subTable) {
|
|
61
|
+
const t = sp.subTable;
|
|
62
|
+
route({
|
|
63
|
+
order: WriteOrder.CollectLead,
|
|
64
|
+
from: [{ kind: "subtree-text", subs: [t.caption] }],
|
|
65
|
+
to: { kind: "prop", name: t.targetCaption },
|
|
66
|
+
origin: "subTable.caption",
|
|
67
|
+
});
|
|
68
|
+
/** A row's cells: one flat scalar list. A header-cell counts as a cell. */
|
|
69
|
+
const cells = (origin) => ({
|
|
70
|
+
order: WriteOrder.Collect,
|
|
71
|
+
flatten: false,
|
|
72
|
+
of: [t.row],
|
|
73
|
+
as: { kind: "inline" },
|
|
74
|
+
scalar: {
|
|
75
|
+
order: WriteOrder.Collect,
|
|
76
|
+
from: [{ kind: "subtree-text", subs: [t.cell, t.headerCell] }],
|
|
77
|
+
to: { kind: "prop", name: "cells" },
|
|
78
|
+
origin,
|
|
79
|
+
},
|
|
80
|
+
origin,
|
|
81
|
+
});
|
|
82
|
+
// Header: every header row's cells concatenate into ONE flat column list —
|
|
83
|
+
// v1 passes the same array to each header row, so two header rows append.
|
|
84
|
+
model.collects.push({
|
|
85
|
+
order: WriteOrder.Collect,
|
|
86
|
+
flatten: true,
|
|
87
|
+
of: [t.header],
|
|
88
|
+
as: { kind: "prop", name: t.targetColumns },
|
|
89
|
+
item: { cells: cells("subTable.header") },
|
|
90
|
+
origin: "subTable.header",
|
|
91
|
+
});
|
|
92
|
+
// Body: one record per row, its cells under the `cells` field. That field
|
|
93
|
+
// name was a literal in the v1 emitter; here it is data.
|
|
94
|
+
model.collects.push({
|
|
95
|
+
order: WriteOrder.Collect,
|
|
96
|
+
flatten: false,
|
|
97
|
+
of: [t.body],
|
|
98
|
+
as: { kind: "prop", name: t.targetRows },
|
|
99
|
+
item: { cells: cells("subTable.body") },
|
|
100
|
+
origin: "subTable.body",
|
|
101
|
+
});
|
|
102
|
+
Object.assign(model.drops, t.drops);
|
|
103
|
+
}
|
|
104
|
+
// textProp / textChildProp: the node's own text. Both OVERWRITE, unlike every
|
|
105
|
+
// consuming directive — v1's one asymmetry, kept explicit.
|
|
106
|
+
if (sp.textProp) {
|
|
107
|
+
route({
|
|
108
|
+
order: WriteOrder.SelfText,
|
|
109
|
+
from: [{ kind: "self-text" }],
|
|
110
|
+
to: { kind: "prop", name: sp.textProp },
|
|
111
|
+
overwrite: true,
|
|
112
|
+
origin: "textProp",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (sp.textChildProp) {
|
|
116
|
+
route({
|
|
117
|
+
order: WriteOrder.SelfTextChild,
|
|
118
|
+
from: [{ kind: "self-text" }],
|
|
119
|
+
to: { kind: "text-child", name: sp.textChildProp },
|
|
120
|
+
overwrite: true,
|
|
121
|
+
origin: "textChildProp",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// actionProp: no source in the subtree; the event name is a deterministic
|
|
125
|
+
// slug the engine derives. Ordered after the text routes because v1 reads a
|
|
126
|
+
// prop those routes may have written when naming the event.
|
|
127
|
+
if (sp.actionProp) {
|
|
128
|
+
route({
|
|
129
|
+
order: WriteOrder.Action,
|
|
130
|
+
from: [{ kind: "synthesized-action" }],
|
|
131
|
+
to: { kind: "action", name: sp.actionProp },
|
|
132
|
+
origin: "actionProp",
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// subFlatten: the two halves are Identity decisions about named subs —
|
|
136
|
+
// dissolve, or become the synthesized text primitive with a variant.
|
|
137
|
+
for (const sub of sp.subFlatten?.transparent ?? []) {
|
|
138
|
+
model.subIdentity[sub] = { kind: "transparent" };
|
|
139
|
+
}
|
|
140
|
+
for (const [sub, variant] of Object.entries(sp.subFlatten?.asText ?? {})) {
|
|
141
|
+
model.subIdentity[sub] = { kind: "as-text", variant };
|
|
142
|
+
}
|
|
143
|
+
// childProp / childrenProp: children as instance references.
|
|
144
|
+
if (sp.childrenProp) {
|
|
145
|
+
route({ order: WriteOrder.Children, from: [{ kind: "children" }], to: { kind: "slots", name: sp.childrenProp }, origin: "childrenProp" });
|
|
146
|
+
}
|
|
147
|
+
else if (sp.childProp) {
|
|
148
|
+
route({ order: WriteOrder.Children, from: [{ kind: "children" }], to: { kind: "slot", name: sp.childProp }, origin: "childProp" });
|
|
149
|
+
}
|
|
150
|
+
// Derived, never authored: a plan that absorbs its subtree into props does
|
|
151
|
+
// not also emit that subtree as children. v1 computed this from the presence
|
|
152
|
+
// of subText/subButtonText/subTable — the same three, now expressed as the
|
|
153
|
+
// routes and collects that consume descendants.
|
|
154
|
+
model.consumesSubtree = Boolean(sp.subText || sp.subButtonText || sp.subTable);
|
|
155
|
+
return model;
|
|
156
|
+
}
|
package/dist/transform/emit.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
1
|
import { INLINED_DEFS } from "./inline-defs.js";
|
|
2
|
+
/**
|
|
3
|
+
* The catalog's function surface, from the profile's declared FunctionPlans:
|
|
4
|
+
* a documentation section, the name enum for FunctionCall.call, and the
|
|
5
|
+
* per-function anyFunction branches that validate each call's args shape.
|
|
6
|
+
* Definitions are declarative schemas — implementations live in renderers,
|
|
7
|
+
* exactly as A2UI intends; nothing executable exists here.
|
|
8
|
+
*/
|
|
9
|
+
function buildFunctions(profile) {
|
|
10
|
+
const declared = profile.functions;
|
|
11
|
+
if (!declared || Object.keys(declared).length === 0)
|
|
12
|
+
return null;
|
|
13
|
+
const names = Object.keys(declared).sort();
|
|
14
|
+
const section = {};
|
|
15
|
+
const branches = [];
|
|
16
|
+
for (const name of names) {
|
|
17
|
+
const fn = declared[name];
|
|
18
|
+
section[name] = {
|
|
19
|
+
description: fn.description,
|
|
20
|
+
returnType: fn.returns,
|
|
21
|
+
...(fn.args ? { args: fn.args } : {}),
|
|
22
|
+
};
|
|
23
|
+
const requiredArgs = fn.args && Array.isArray(fn.args.required) &&
|
|
24
|
+
(fn.args.required.length > 0);
|
|
25
|
+
branches.push({
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
call: { const: name },
|
|
29
|
+
...(fn.args ? { args: fn.args } : { args: { type: "object", maxProperties: 0 } }),
|
|
30
|
+
returnType: { const: fn.returns },
|
|
31
|
+
},
|
|
32
|
+
// A function whose declared args carry required params cannot be called
|
|
33
|
+
// without them — the args object itself becomes required.
|
|
34
|
+
required: requiredArgs ? ["call", "args"] : ["call"],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return { section, names, anyFunction: { oneOf: branches } };
|
|
38
|
+
}
|
|
2
39
|
const VER_SEGMENT = {
|
|
3
40
|
"0.9.1": "v0_9_1",
|
|
4
41
|
"1.0": "v1_0",
|
|
@@ -14,6 +51,26 @@ export function emitCatalog(result, version, profile) {
|
|
|
14
51
|
...structuredClone(INLINED_DEFS),
|
|
15
52
|
anyComponent,
|
|
16
53
|
};
|
|
54
|
+
// Declared functions: the profile's function vocabulary becomes the
|
|
55
|
+
// catalog's `functions` section, and — the fail-closed half — FunctionCall
|
|
56
|
+
// regains the upstream anyFunction constraint our inlined copy dropped
|
|
57
|
+
// (inline-defs.ts) back when no catalog declared any functions to call.
|
|
58
|
+
// With the constraint restored, an instance calling an UNDECLARED function
|
|
59
|
+
// fails gate A3 instead of passing silently. Profiles that declare no
|
|
60
|
+
// functions (every v1 profile) emit byte-identically to before.
|
|
61
|
+
const functions = buildFunctions(profile);
|
|
62
|
+
if (functions) {
|
|
63
|
+
$defs.anyFunction = functions.anyFunction;
|
|
64
|
+
const fc = $defs.FunctionCall;
|
|
65
|
+
fc.properties.call = {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "The name of the function to call. Must be declared in this catalog's functions section.",
|
|
68
|
+
enum: functions.names,
|
|
69
|
+
};
|
|
70
|
+
// The upstream shape our inline copy dropped: the whole call object must
|
|
71
|
+
// match one declared function's branch (name AND args shape together).
|
|
72
|
+
fc.oneOf = [{ $ref: "#/$defs/anyFunction" }];
|
|
73
|
+
}
|
|
17
74
|
if (version === "0.9.1") {
|
|
18
75
|
$defs.theme = themeDef(result);
|
|
19
76
|
}
|
|
@@ -27,6 +84,7 @@ export function emitCatalog(result, version, profile) {
|
|
|
27
84
|
description: profile.catalogDescription,
|
|
28
85
|
catalogId: id,
|
|
29
86
|
components: result.components,
|
|
87
|
+
...(functions ? { functions: functions.section } : {}),
|
|
30
88
|
$defs,
|
|
31
89
|
};
|
|
32
90
|
if (version === "1.0") {
|
|
@@ -39,6 +97,7 @@ export function emitCatalog(result, version, profile) {
|
|
|
39
97
|
instructions: profile.instructions,
|
|
40
98
|
catalogId: catalog.catalogId,
|
|
41
99
|
components: catalog.components,
|
|
100
|
+
...(catalog.functions ? { functions: catalog.functions } : {}),
|
|
42
101
|
$defs: catalog.$defs,
|
|
43
102
|
};
|
|
44
103
|
}
|
package/dist/transform/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { shadcnProfile } from "./profiles.js";
|
|
2
2
|
import { mapDspack } from "./mapping.js";
|
|
3
|
+
import { validateProfileAgainstContract } from "./validate-v2.js";
|
|
3
4
|
import { emitCatalog } from "./emit.js";
|
|
4
5
|
import { buildReport } from "./report.js";
|
|
5
6
|
import { validateCatalog } from "../validate/ajv.js";
|
|
@@ -9,6 +10,9 @@ export function transform(doc, version, surface, profile = shadcnProfile) {
|
|
|
9
10
|
if (major !== "0") {
|
|
10
11
|
throw new Error(`Unsupported dspack major version '${doc.dspack}'. This PoC targets dspack 0.x.`);
|
|
11
12
|
}
|
|
13
|
+
// v2 profiles fail closed against the contract before anything emits;
|
|
14
|
+
// v1 behaviour is frozen (report + --strict-coverage instead).
|
|
15
|
+
validateProfileAgainstContract(profile, doc);
|
|
12
16
|
const mapping = mapDspack(doc, profile);
|
|
13
17
|
const catalog = emitCatalog(mapping, version, profile);
|
|
14
18
|
const validation = validateCatalog(catalog, version, surface);
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Source-agnostic mapping engine. Given a dspack document and a mapping Profile,
|
|
3
|
-
* it produces the A2UI component schemas, a fidelity record (per field), warnings
|
|
4
|
-
* for unsupported constructs, and the design-token projection. It reads only the
|
|
5
|
-
* dspack JSON and the profile — never framework code.
|
|
6
|
-
*/
|
|
7
1
|
import type { CoverageEntry, DspackDoc, FidelityEntry, Json, Warning } from "../types.js";
|
|
8
2
|
import type { Profile } from "./profiles.js";
|
|
9
3
|
export interface MappingResult {
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source-agnostic mapping engine. Given a dspack document and a mapping Profile,
|
|
3
|
+
* it produces the A2UI component schemas, a fidelity record (per field), warnings
|
|
4
|
+
* for unsupported constructs, and the design-token projection. It reads only the
|
|
5
|
+
* dspack JSON and the profile — never framework code.
|
|
6
|
+
*/
|
|
7
|
+
import { surfaceModelOf } from "./desugar.js";
|
|
8
|
+
import { deriveSubCoverage } from "./model.js";
|
|
1
9
|
import { toHex6 } from "./color.js";
|
|
2
10
|
export function mapDspack(doc, profile) {
|
|
3
11
|
const components = {};
|
|
@@ -5,6 +13,18 @@ export function mapDspack(doc, profile) {
|
|
|
5
13
|
const fidelity = [];
|
|
6
14
|
const warnings = [];
|
|
7
15
|
const addComponent = (plan) => {
|
|
16
|
+
// T1: a transparent plan emits no catalog entry — nothing can instantiate
|
|
17
|
+
// a component that dissolves at emission. Its disposition is recorded in
|
|
18
|
+
// coverage; its absence from anyComponent is what keeps A3 honest.
|
|
19
|
+
if (surfaceModelOf(plan).transparent) {
|
|
20
|
+
fidelity.push({
|
|
21
|
+
source: `plan.${plan.dspackId ?? plan.a2ui}`,
|
|
22
|
+
target: "(no catalog entry)",
|
|
23
|
+
class: "synthesis-defaults",
|
|
24
|
+
note: "transparent identity: dissolves at emission; children rise to the parent's destination.",
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
8
28
|
const dspackComp = plan.dspackId ? doc.components?.[plan.dspackId] : undefined;
|
|
9
29
|
if (plan.dspackId && !dspackComp) {
|
|
10
30
|
warnings.push({
|
|
@@ -57,10 +77,13 @@ export function mapDspack(doc, profile) {
|
|
|
57
77
|
}
|
|
58
78
|
function computeCoverage(doc, profile, warnings, fidelity) {
|
|
59
79
|
const mapped = new Map(); // dspackId -> A2UI name
|
|
80
|
+
const byId = new Map();
|
|
60
81
|
// Both `components` and any `synthesized` plan that declares a `dspackId` count as mapped.
|
|
61
82
|
for (const p of [...profile.components, ...profile.synthesized]) {
|
|
62
|
-
if (p.dspackId)
|
|
83
|
+
if (p.dspackId) {
|
|
63
84
|
mapped.set(p.dspackId, p.a2ui);
|
|
85
|
+
byId.set(p.dspackId, p);
|
|
86
|
+
}
|
|
64
87
|
}
|
|
65
88
|
const casualties = new Map();
|
|
66
89
|
for (const c of profile.casualtyComponents)
|
|
@@ -69,7 +92,11 @@ function computeCoverage(doc, profile, warnings, fidelity) {
|
|
|
69
92
|
const coverage = [];
|
|
70
93
|
for (const id of Object.keys(doc.components ?? {})) {
|
|
71
94
|
if (mapped.has(id)) {
|
|
72
|
-
coverage.push({
|
|
95
|
+
coverage.push({
|
|
96
|
+
id,
|
|
97
|
+
disposition: "mapped",
|
|
98
|
+
detail: byId.get(id) && surfaceModelOf(byId.get(id)).transparent ? "-> (transparent: dissolves at emission)" : `-> ${mapped.get(id)}`,
|
|
99
|
+
});
|
|
73
100
|
}
|
|
74
101
|
else if (omitted.has(id)) {
|
|
75
102
|
coverage.push({ id, disposition: "omitted", detail: "declared in profile.intentionallyOmitted" });
|
|
@@ -97,6 +124,43 @@ function computeCoverage(doc, profile, warnings, fidelity) {
|
|
|
97
124
|
});
|
|
98
125
|
}
|
|
99
126
|
}
|
|
127
|
+
// Sub-component coverage, DERIVED from each mapped compound's transformation
|
|
128
|
+
// model rather than authored prose (the old `subCoverage` field is v1
|
|
129
|
+
// documentation the engine never read; the model is what actually happens).
|
|
130
|
+
// An unresolved sub is an unclassified coverage entry: for v1 profiles this
|
|
131
|
+
// reports (and fails under --strict-coverage); v2 profiles never get here —
|
|
132
|
+
// validateProfileAgainstContract refuses them at entry. Measured before
|
|
133
|
+
// enforcement: pinned shadcn v2.3.0, astryx and acme all derive zero
|
|
134
|
+
// unresolved subs, so no shipped artifact changes.
|
|
135
|
+
for (const [id, component] of Object.entries(doc.components ?? {})) {
|
|
136
|
+
const subs = component.composition?.subComponents ?? [];
|
|
137
|
+
if (subs.length === 0)
|
|
138
|
+
continue;
|
|
139
|
+
const plan = byId.get(id);
|
|
140
|
+
if (!plan)
|
|
141
|
+
continue; // unmapped/casualty parents: the parent entry above carries the family
|
|
142
|
+
const model = surfaceModelOf(plan);
|
|
143
|
+
const derived = deriveSubCoverage(model, subs.map((s) => s.id));
|
|
144
|
+
for (const sub of subs) {
|
|
145
|
+
const how = derived.get(sub.id);
|
|
146
|
+
if (how) {
|
|
147
|
+
coverage.push({ id: `${id}.${sub.id}`, disposition: "mapped", detail: how });
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
coverage.push({ id: `${id}.${sub.id}`, disposition: "unclassified" });
|
|
151
|
+
warnings.push({
|
|
152
|
+
code: `unresolved-sub:${id}.${sub.id}`,
|
|
153
|
+
message: `sub-component '${sub.id}' of mapped compound '${id}' is unresolved: no route consumes it, no collect gathers it, no disposition dissolves or drops it.`,
|
|
154
|
+
});
|
|
155
|
+
fidelity.push({
|
|
156
|
+
source: `components.${id}.composition.${sub.id}`,
|
|
157
|
+
target: "(silently dropped)",
|
|
158
|
+
class: "cannot-represent",
|
|
159
|
+
note: "Unresolved by the compound's transformation model. This is a coverage gap, not a deliberate casualty.",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
100
164
|
return coverage;
|
|
101
165
|
}
|
|
102
166
|
function buildComponent(plan, dspackComp, fidelity, warnings) {
|