@aestheticfunction/dspack-emit 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/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 +566 -224
- 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 +50 -0
- package/dist/transform/model.d.ts +275 -0
- package/dist/transform/model.js +148 -0
- package/dist/transform/parse-v2.d.ts +78 -0
- package/dist/transform/parse-v2.js +305 -0
- package/dist/transform/profile-load.d.ts +8 -7
- package/dist/transform/profile-load.js +101 -24
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +430 -0
- package/dist/transform/profile-schema.d.ts +8 -0
- package/dist/transform/profile-schema.js +382 -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 +12 -0
- package/dist/transform/shadcn-v2-respelling.js +49 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +100 -0
- package/dist/types.d.ts +19 -0
- package/dist/validate/ajv.js +98 -29
- package/dist/validate/meta/catalog-meta.d.ts +10 -0
- package/dist/validate/meta/catalog-meta.js +157 -0
- package/package.json +3 -3
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/browser-boundary.test.ts +47 -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 +89 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +363 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +35 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +920 -242
- 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 +42 -0
- package/src/transform/model.ts +325 -0
- package/src/transform/parse-v2.ts +397 -0
- package/src/transform/profile-load.ts +107 -28
- package/src/transform/profile-schema-v2.ts +430 -0
- package/src/transform/profile-schema.ts +382 -0
- package/src/transform/profile.v2.schema.json +422 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +61 -0
- package/src/transform/validate-v2.ts +138 -0
- package/src/types.ts +20 -0
- package/src/validate/ajv.ts +91 -32
- package/src/validate/meta/catalog-meta.ts +167 -0
- package/src/validate-v2.test.ts +173 -0
- package/dist/transform/profile.v1.schema.json +0 -153
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +0 -39
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +0 -34
|
@@ -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 = {};
|
|
@@ -97,6 +105,48 @@ function computeCoverage(doc, profile, warnings, fidelity) {
|
|
|
97
105
|
});
|
|
98
106
|
}
|
|
99
107
|
}
|
|
108
|
+
// Sub-component coverage, DERIVED from each mapped compound's transformation
|
|
109
|
+
// model rather than authored prose (the old `subCoverage` field is v1
|
|
110
|
+
// documentation the engine never read; the model is what actually happens).
|
|
111
|
+
// An unresolved sub is an unclassified coverage entry: for v1 profiles this
|
|
112
|
+
// reports (and fails under --strict-coverage); v2 profiles never get here —
|
|
113
|
+
// validateProfileAgainstContract refuses them at entry. Measured before
|
|
114
|
+
// enforcement: pinned shadcn v2.3.0, astryx and acme all derive zero
|
|
115
|
+
// unresolved subs, so no shipped artifact changes.
|
|
116
|
+
const byId = new Map();
|
|
117
|
+
for (const p of [...profile.components, ...profile.synthesized]) {
|
|
118
|
+
if (p.dspackId)
|
|
119
|
+
byId.set(p.dspackId, p);
|
|
120
|
+
}
|
|
121
|
+
for (const [id, component] of Object.entries(doc.components ?? {})) {
|
|
122
|
+
const subs = component.composition?.subComponents ?? [];
|
|
123
|
+
if (subs.length === 0)
|
|
124
|
+
continue;
|
|
125
|
+
const plan = byId.get(id);
|
|
126
|
+
if (!plan)
|
|
127
|
+
continue; // unmapped/casualty parents: the parent entry above carries the family
|
|
128
|
+
const model = surfaceModelOf(plan);
|
|
129
|
+
const derived = deriveSubCoverage(model, subs.map((s) => s.id));
|
|
130
|
+
for (const sub of subs) {
|
|
131
|
+
const how = derived.get(sub.id);
|
|
132
|
+
if (how) {
|
|
133
|
+
coverage.push({ id: `${id}.${sub.id}`, disposition: "mapped", detail: how });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
coverage.push({ id: `${id}.${sub.id}`, disposition: "unclassified" });
|
|
137
|
+
warnings.push({
|
|
138
|
+
code: `unresolved-sub:${id}.${sub.id}`,
|
|
139
|
+
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.`,
|
|
140
|
+
});
|
|
141
|
+
fidelity.push({
|
|
142
|
+
source: `components.${id}.composition.${sub.id}`,
|
|
143
|
+
target: "(silently dropped)",
|
|
144
|
+
class: "cannot-represent",
|
|
145
|
+
note: "Unresolved by the compound's transformation model. This is a coverage gap, not a deliberate casualty.",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
100
150
|
return coverage;
|
|
101
151
|
}
|
|
102
152
|
function buildComponent(plan, dspackComp, fidelity, warnings) {
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The internal surface transformation model.
|
|
3
|
+
*
|
|
4
|
+
* Ten authored surface-plan directives accumulated one at a time, each named
|
|
5
|
+
* after the collision that produced it (`subText`, `subButtonText`, `subTable`,
|
|
6
|
+
* `subFlatten`, …). Measured against two design systems and a second emit
|
|
7
|
+
* target, that vocabulary does not generalize: only four directives are used by
|
|
8
|
+
* both shipped profiles, the second target reuses none of them, and the
|
|
9
|
+
* scaffolder can reach two. They are not a vocabulary for projecting design
|
|
10
|
+
* systems onto protocols — they are point-fixes for one collision, shadcn's
|
|
11
|
+
* compound sub-component composition meeting A2UI's fixed catalog vocabulary.
|
|
12
|
+
*
|
|
13
|
+
* Underneath, every one of them answers exactly one of three questions:
|
|
14
|
+
*
|
|
15
|
+
* Identity does this node become an instance, and as which component?
|
|
16
|
+
* Routing for each piece of this node's subtree, where does it land?
|
|
17
|
+
* Repetition when a sub-structure repeats, how does it become an array?
|
|
18
|
+
*
|
|
19
|
+
* This module is that answer as types. The authored directives become surface
|
|
20
|
+
* syntax that desugars here (see desugar.ts); the engine reads only this.
|
|
21
|
+
*
|
|
22
|
+
* THREE THINGS IMPLEMENTATION CONTACT ADDED, and why they are refinements of
|
|
23
|
+
* the model rather than escapes from it:
|
|
24
|
+
*
|
|
25
|
+
* 1. `Selector[]`, not `Selector`. The audited label lift — "take the sub's
|
|
26
|
+
* label, else the first direct text under it" — is a fallback chain, not a
|
|
27
|
+
* special case. Ordered selectors express it, and express nothing else.
|
|
28
|
+
* 2. `subs: string[]`, not `sub: string`. A table body accepts both a cell and
|
|
29
|
+
* a header-cell in the same row. One selector naming a set is honest; two
|
|
30
|
+
* collects racing for one destination is not.
|
|
31
|
+
* 3. First-write-wins as a uniform WRITE DISCIPLINE rather than per-directive
|
|
32
|
+
* `??=` scattered through the emitter. Every v1 directive already behaved
|
|
33
|
+
* this way; only `textProp`/`textChildProp` overwrote, and that asymmetry
|
|
34
|
+
* is preserved explicitly (see `Route.overwrite`) rather than silently.
|
|
35
|
+
*
|
|
36
|
+
* What is deliberately NOT here, and must not arrive later: JSON paths,
|
|
37
|
+
* expression evaluation, predicates, computed destination names, and writes to
|
|
38
|
+
* arbitrary other instances. Those would each buy generality at the cost of the
|
|
39
|
+
* property that makes emission auditable — that a plan can be checked against
|
|
40
|
+
* its contract before it runs.
|
|
41
|
+
*/
|
|
42
|
+
import type { Json } from "../types.js";
|
|
43
|
+
/**
|
|
44
|
+
* Whether a dspack node becomes an emitted instance, and under which catalog
|
|
45
|
+
* identity. `transparent` and `as-text` are v1's `subFlatten` halves: today
|
|
46
|
+
* they are declared by a compound about its own sub-family (subs have no plans
|
|
47
|
+
* of their own), which is why they live in `Plan.subIdentity` rather than on
|
|
48
|
+
* the node's plan. When plans gain identities of their own, that field becomes
|
|
49
|
+
* the narrower spelling of this same idea.
|
|
50
|
+
*/
|
|
51
|
+
export type Identity =
|
|
52
|
+
/** Emits one instance of the named A2UI component. */
|
|
53
|
+
{
|
|
54
|
+
kind: "mapped";
|
|
55
|
+
a2ui: string;
|
|
56
|
+
}
|
|
57
|
+
/** Emits nothing; its children rise to the destination its parent would use. */
|
|
58
|
+
| {
|
|
59
|
+
kind: "transparent";
|
|
60
|
+
}
|
|
61
|
+
/** Emits as the profile's synthesized text primitive, carrying its subtree text. */
|
|
62
|
+
| {
|
|
63
|
+
kind: "as-text";
|
|
64
|
+
variant: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Where information comes from. A closed enumeration: every selector is
|
|
68
|
+
* statically checkable against the contract before emission runs.
|
|
69
|
+
*/
|
|
70
|
+
export type Selector =
|
|
71
|
+
/** This node's own `text`. */
|
|
72
|
+
{
|
|
73
|
+
kind: "self-text";
|
|
74
|
+
}
|
|
75
|
+
/** One declared prop on this node, verbatim. */
|
|
76
|
+
| {
|
|
77
|
+
kind: "self-prop";
|
|
78
|
+
prop: string;
|
|
79
|
+
}
|
|
80
|
+
/** `text` of any descendant whose component is one of `subs`. */
|
|
81
|
+
| {
|
|
82
|
+
kind: "sub-text";
|
|
83
|
+
subs: string[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The label of a descendant inside one of `subs` — a component whose own plan
|
|
87
|
+
* projects text as a child label. Incidental text elsewhere never qualifies.
|
|
88
|
+
*/
|
|
89
|
+
| {
|
|
90
|
+
kind: "sub-label";
|
|
91
|
+
subs: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* First direct text under one of `subs`, document order, the sub's own text
|
|
95
|
+
* included. This is a LIFT: relocation of text that exists, never synthesis.
|
|
96
|
+
* Only ever reached as a fallback, and always recorded.
|
|
97
|
+
*/
|
|
98
|
+
| {
|
|
99
|
+
kind: "sub-text-lift";
|
|
100
|
+
subs: string[];
|
|
101
|
+
}
|
|
102
|
+
/** All text in a descendant's subtree, document order, space-joined. */
|
|
103
|
+
| {
|
|
104
|
+
kind: "subtree-text";
|
|
105
|
+
subs: string[];
|
|
106
|
+
}
|
|
107
|
+
/** This node's ordered children, emitted as instances. */
|
|
108
|
+
| {
|
|
109
|
+
kind: "children";
|
|
110
|
+
}
|
|
111
|
+
/** No source: a declarative A2UI action synthesized from a deterministic slug. */
|
|
112
|
+
| {
|
|
113
|
+
kind: "synthesized-action";
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Where information lands on the emitted instance. Names are literal — never
|
|
117
|
+
* computed — so a plan's destinations can be validated against its own
|
|
118
|
+
* `propMap`/`structural` at load time. This matters more than it looks: gate A3
|
|
119
|
+
* validates emitted messages against the catalog and so catches an OMITTED
|
|
120
|
+
* property, but an INVENTED one would pass. Load-time checking is the only
|
|
121
|
+
* place that asymmetry can be closed.
|
|
122
|
+
*/
|
|
123
|
+
export type Destination =
|
|
124
|
+
/** A scalar property. */
|
|
125
|
+
{
|
|
126
|
+
kind: "prop";
|
|
127
|
+
name: string;
|
|
128
|
+
}
|
|
129
|
+
/** A ComponentId property referencing a synthesized text primitive. */
|
|
130
|
+
| {
|
|
131
|
+
kind: "text-child";
|
|
132
|
+
name: string;
|
|
133
|
+
}
|
|
134
|
+
/** A single ComponentId property (>1 child is wrapped in the profile's wrap component). */
|
|
135
|
+
| {
|
|
136
|
+
kind: "slot";
|
|
137
|
+
name: string;
|
|
138
|
+
}
|
|
139
|
+
/** A ChildList property. */
|
|
140
|
+
| {
|
|
141
|
+
kind: "slots";
|
|
142
|
+
name: string;
|
|
143
|
+
}
|
|
144
|
+
/** An Action property. */
|
|
145
|
+
| {
|
|
146
|
+
kind: "action";
|
|
147
|
+
name: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Legacy write order. The engine applies routes and collects sorted by this,
|
|
151
|
+
* never by declaration index or traversal happenstance — the same discipline
|
|
152
|
+
* the diagnostics use, applied to output. Object key order is observable
|
|
153
|
+
* (artifacts are hashed), so "when a route writes" is part of the contract and
|
|
154
|
+
* belongs in data rather than in the shape of a method.
|
|
155
|
+
*/
|
|
156
|
+
export declare enum WriteOrder {
|
|
157
|
+
/** Props copied verbatim into same-named destinations; wins over consumption. */
|
|
158
|
+
Verbatim = 10,
|
|
159
|
+
/** Sub-scoped consumption. Resolved by ONE document-order walk (see below). */
|
|
160
|
+
Consume = 20,
|
|
161
|
+
/** Repetition, and the caption-style routes that belong to the same strategy. */
|
|
162
|
+
CollectLead = 30,
|
|
163
|
+
Collect = 31,
|
|
164
|
+
/** The node's own text. */
|
|
165
|
+
SelfText = 40,
|
|
166
|
+
SelfTextChild = 41,
|
|
167
|
+
/** Synthesis with no source in the subtree. */
|
|
168
|
+
Action = 50,
|
|
169
|
+
/** Children as instance references, once every value destination is settled. */
|
|
170
|
+
Children = 60
|
|
171
|
+
}
|
|
172
|
+
/** Moves one piece of information from a source to a destination. */
|
|
173
|
+
export interface Route {
|
|
174
|
+
/** When this route writes, relative to every other route and collect. */
|
|
175
|
+
order: WriteOrder;
|
|
176
|
+
/** Tried in order; the first that yields a value wins. */
|
|
177
|
+
from: Selector[];
|
|
178
|
+
to: Destination;
|
|
179
|
+
/**
|
|
180
|
+
* v1 asymmetry, preserved deliberately: `textProp`/`textChildProp` overwrite
|
|
181
|
+
* whatever is already there, while every consuming directive is first-wins.
|
|
182
|
+
* Making it a field rather than a code path keeps the difference reviewable.
|
|
183
|
+
*/
|
|
184
|
+
overwrite?: boolean;
|
|
185
|
+
/** Which authored directive produced this route — provenance for fidelity. */
|
|
186
|
+
origin: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Collects a repeated sub-structure into an array-valued destination. Item
|
|
190
|
+
* fields are themselves routes or nested collects, which is why a paired group
|
|
191
|
+
* (an options array whose value is a child reference) needs no separate
|
|
192
|
+
* primitive — and why `subTable`'s three-level shape is nesting rather than a
|
|
193
|
+
* grammar.
|
|
194
|
+
*/
|
|
195
|
+
export interface Collect {
|
|
196
|
+
/** When this collect writes, relative to every other route and collect. */
|
|
197
|
+
order: WriteOrder;
|
|
198
|
+
/**
|
|
199
|
+
* True when every repetition's cells concatenate into ONE flat list (v1's
|
|
200
|
+
* header semantics: two header rows append into a single column list);
|
|
201
|
+
* false when each repetition becomes its own record. Declared data — the
|
|
202
|
+
* engine must never infer this from names or origins.
|
|
203
|
+
*/
|
|
204
|
+
flatten: boolean;
|
|
205
|
+
/** Descendant components that open one repetition. */
|
|
206
|
+
of: string[];
|
|
207
|
+
/** Array-valued destination, or `inline` when nested into a parent's field. */
|
|
208
|
+
as: Destination | {
|
|
209
|
+
kind: "inline";
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Per-item fields. A collect whose item is a single unnamed scalar (a table
|
|
213
|
+
* row's cells) uses `scalar` instead.
|
|
214
|
+
*/
|
|
215
|
+
item?: Record<string, Route | Collect>;
|
|
216
|
+
/** The item IS one scalar, produced by this route. Mutually exclusive with `item`. */
|
|
217
|
+
scalar?: Route;
|
|
218
|
+
/** Declared join key for paired collections. Never inferred. Reserved for T3. */
|
|
219
|
+
joinOn?: string;
|
|
220
|
+
origin: string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Sub-components this plan explicitly discards, with the authored reason. v1
|
|
224
|
+
* spelled this inside `subTable.drops`; it is not a table concept.
|
|
225
|
+
*/
|
|
226
|
+
export type Drops = Record<string, string>;
|
|
227
|
+
/** The whole of how a plan projects a surface node. Replaces SurfacePlanDirectives. */
|
|
228
|
+
export interface SurfaceModel {
|
|
229
|
+
routes: Route[];
|
|
230
|
+
collects: Collect[];
|
|
231
|
+
/** Identity assigned to named sub-components met inside this node's subtree. */
|
|
232
|
+
subIdentity: Record<string, Identity>;
|
|
233
|
+
drops: Drops;
|
|
234
|
+
/**
|
|
235
|
+
* True when this plan absorbs its whole subtree into props, so children are
|
|
236
|
+
* not emitted as instances. Derived during desugaring from the presence of
|
|
237
|
+
* consuming routes/collects — never authored.
|
|
238
|
+
*/
|
|
239
|
+
consumesSubtree: boolean;
|
|
240
|
+
}
|
|
241
|
+
export declare const emptySurfaceModel: () => SurfaceModel;
|
|
242
|
+
/** Narrowing helper: a collect's field may be either shape. */
|
|
243
|
+
export declare const isCollect: (field: Route | Collect) => field is Collect;
|
|
244
|
+
/** Human-readable selector, for warnings and fidelity provenance. */
|
|
245
|
+
export declare function describeSelector(s: Selector): string;
|
|
246
|
+
/** Human-readable destination, for warnings and fidelity provenance. */
|
|
247
|
+
export declare const describeDestination: (d: Destination | {
|
|
248
|
+
kind: "inline";
|
|
249
|
+
}) => string;
|
|
250
|
+
/** Every destination a model writes, for load-time validation against the plan. */
|
|
251
|
+
export declare function destinationsOf(model: SurfaceModel): Destination[];
|
|
252
|
+
/**
|
|
253
|
+
* Every sub-component id this model accounts for, and how. This is what makes
|
|
254
|
+
* `subCoverage` derivable instead of authored: a sub is covered when the model
|
|
255
|
+
* consumes it, dissolves it, re-identifies it, or drops it with a reason —
|
|
256
|
+
* and anything else is an unclassified sub, which must fail closed.
|
|
257
|
+
*/
|
|
258
|
+
export declare function referencedSubs(model: SurfaceModel): Map<string, string>;
|
|
259
|
+
/**
|
|
260
|
+
* Derived sub-component coverage: the honest replacement for the authored
|
|
261
|
+
* `subCoverage` prose, which the engine never reads and which only a test in
|
|
262
|
+
* another repo enforces.
|
|
263
|
+
*
|
|
264
|
+
* A sub is covered when the model NAMES it, or — when the plan absorbs its
|
|
265
|
+
* whole subtree — when it is merely walked through on the way to a named one.
|
|
266
|
+
* That second case is not slack: `alert-dialog-content`, `-header` and
|
|
267
|
+
* `-footer` are real, and a derivation that only counted named subs would
|
|
268
|
+
* report them missing while the emitter handles them correctly.
|
|
269
|
+
*
|
|
270
|
+
* Anything else is unclassified, and must fail closed.
|
|
271
|
+
*/
|
|
272
|
+
export declare function deriveSubCoverage(model: SurfaceModel, contractSubs: string[]): Map<string, string>;
|
|
273
|
+
/** Subs the contract declares that the model cannot account for at all. */
|
|
274
|
+
export declare const unclassifiedSubs: (model: SurfaceModel, contractSubs: string[]) => string[];
|
|
275
|
+
export type { Json };
|