@aestheticfunction/dspack-emit 0.3.1 → 0.4.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 +31 -3
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +34 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/targets/a2ui/surface.js +159 -5
- package/dist/targets/json-render/profile.d.ts +10 -0
- package/dist/targets/json-render/profile.js +12 -0
- package/dist/transform/profile-load.d.ts +19 -0
- package/dist/transform/profile-load.js +58 -0
- package/dist/transform/profile.v1.schema.json +153 -0
- package/dist/transform/profiles.d.ts +41 -0
- package/dist/transform/profiles.js +60 -7
- package/dist/transform/scaffold.d.ts +40 -0
- package/dist/transform/scaffold.js +171 -0
- package/package.json +5 -2
- package/src/cli.ts +35 -9
- package/src/index.ts +2 -0
- package/src/json-render-emit.test.ts +48 -1
- package/src/profile-load.test.ts +144 -0
- package/src/profile-parity.test.ts +96 -0
- package/src/targets/a2ui/surface.ts +160 -5
- package/src/targets/json-render/profile.ts +13 -0
- package/src/transform/profile-load.ts +73 -0
- package/src/transform/profile.v1.schema.json +153 -0
- package/src/transform/profiles.ts +101 -7
- package/src/transform/scaffold.ts +229 -0
|
@@ -63,6 +63,15 @@ export interface ComponentPlan {
|
|
|
63
63
|
required: string[];
|
|
64
64
|
/** How the surface emitter projects a dspack-surface node onto this component. */
|
|
65
65
|
surfacePlan?: SurfacePlanDirectives;
|
|
66
|
+
/**
|
|
67
|
+
* Explicit per-sub-component disposition for compound components: every
|
|
68
|
+
* contract sub id -> one line naming how the surface emitter treats it
|
|
69
|
+
* (which prop consumes it, "transparent grouping", or "dropped: <why>").
|
|
70
|
+
* The profile-parity suite fails any mapped compound whose sub-family is
|
|
71
|
+
* not fully classified here — a parent mapping alone never implies its
|
|
72
|
+
* subs are supported.
|
|
73
|
+
*/
|
|
74
|
+
subCoverage?: Record<string, string>;
|
|
66
75
|
}
|
|
67
76
|
/**
|
|
68
77
|
* Data-only directives for projecting a dspack-surface (CSR) node onto an
|
|
@@ -95,6 +104,38 @@ export interface SurfacePlanDirectives {
|
|
|
95
104
|
childrenProp?: string;
|
|
96
105
|
/** CSR props copied verbatim into same-named structural slots (e.g. Table columns/rows). */
|
|
97
106
|
structuralPassthrough?: string[];
|
|
107
|
+
/**
|
|
108
|
+
* Named parent strategy "tableSubs": consume a tabular sub-component
|
|
109
|
+
* subtree into the synthesized caption/columns/rows shape. Domain-neutral
|
|
110
|
+
* by construction: cells flatten to their subtree TEXT in document order —
|
|
111
|
+
* nested component structure and props (whatever the component) are a
|
|
112
|
+
* documented loss, warned per cell, never re-interpreted into semantic
|
|
113
|
+
* fields. Sub ids listed in `drops` are skipped with a warning carrying
|
|
114
|
+
* the declared reason. structuralPassthrough-provided values win over
|
|
115
|
+
* consumed ones (the props path, where a contract expresses one).
|
|
116
|
+
*/
|
|
117
|
+
subTable?: {
|
|
118
|
+
caption: string;
|
|
119
|
+
header: string;
|
|
120
|
+
headerCell: string;
|
|
121
|
+
body: string;
|
|
122
|
+
row: string;
|
|
123
|
+
cell: string;
|
|
124
|
+
targetCaption: string;
|
|
125
|
+
targetColumns: string;
|
|
126
|
+
targetRows: string;
|
|
127
|
+
drops: Record<string, string>;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Named parent strategy "subFlatten": grouping sub-components in
|
|
131
|
+
* `transparent` splice their children inline (structure dropped, order
|
|
132
|
+
* kept, warned); text-bearing sub-components in `asText` synthesize the
|
|
133
|
+
* profile's text primitive with the given variant.
|
|
134
|
+
*/
|
|
135
|
+
subFlatten?: {
|
|
136
|
+
transparent: string[];
|
|
137
|
+
asText: Record<string, string>;
|
|
138
|
+
};
|
|
98
139
|
}
|
|
99
140
|
export interface StructuralSlot {
|
|
100
141
|
schema: Json;
|
|
@@ -2,7 +2,7 @@ const DynStr = { $ref: "#/$defs/DynamicString" };
|
|
|
2
2
|
const CompId = { $ref: "#/$defs/ComponentId" };
|
|
3
3
|
export const shadcnProfile = {
|
|
4
4
|
catalogTitle: "shadcn/ui — A2UI catalog (compiled from dspack)",
|
|
5
|
-
catalogDescription: "A2UI catalog compiled from the shadcn/ui dspack v0.
|
|
5
|
+
catalogDescription: "A2UI catalog compiled from the shadcn/ui dspack v0.4 contract. Component shapes, " +
|
|
6
6
|
"variant enums, and the primary design token are projected onto the A2UI basic " +
|
|
7
7
|
"component vocabulary. See MAPPING.md for per-field fidelity.",
|
|
8
8
|
catalogIdBase: "https://rdombrowski.dev/catalogs/shadcn-ui",
|
|
@@ -63,11 +63,26 @@ export const shadcnProfile = {
|
|
|
63
63
|
schema: CompId,
|
|
64
64
|
description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
|
|
65
65
|
synthNote: "A2UI Card takes exactly one child by ID; dspack Card composes via sub-components " +
|
|
66
|
-
"(CardHeader/CardContent/CardFooter), which
|
|
66
|
+
"(CardHeader/CardContent/CardFooter), which flatten (subFlatten strategy: grouping " +
|
|
67
|
+
"subs splice their children inline; title/description synthesize Text) and collapse " +
|
|
68
|
+
"to a single, possibly Column-wrapped, child slot.",
|
|
67
69
|
},
|
|
68
70
|
},
|
|
69
71
|
required: ["child"],
|
|
70
|
-
surfacePlan: {
|
|
72
|
+
surfacePlan: {
|
|
73
|
+
childProp: "child",
|
|
74
|
+
subFlatten: {
|
|
75
|
+
transparent: ["card-header", "card-content", "card-footer"],
|
|
76
|
+
asText: { "card-title": "h3", "card-description": "caption" },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
subCoverage: {
|
|
80
|
+
"card-header": "transparent grouping: children splice inline, in order (subFlatten strategy)",
|
|
81
|
+
"card-title": "text -> synthesized Text (variant h3)",
|
|
82
|
+
"card-description": "text -> synthesized Text (variant caption)",
|
|
83
|
+
"card-content": "transparent grouping: children splice inline, in order",
|
|
84
|
+
"card-footer": "transparent grouping: children splice inline, in order",
|
|
85
|
+
},
|
|
71
86
|
},
|
|
72
87
|
{
|
|
73
88
|
a2ui: "TextField",
|
|
@@ -131,8 +146,11 @@ export const shadcnProfile = {
|
|
|
131
146
|
},
|
|
132
147
|
{
|
|
133
148
|
// shadcn Table -> a synthesized presentational A2UI Table shape (caption/columns/rows).
|
|
134
|
-
// The
|
|
135
|
-
//
|
|
149
|
+
// The contract's table is purely sub-component-composed (it has no props), so the
|
|
150
|
+
// surface emitter consumes the sub tree via the `subTable` strategy: caption text,
|
|
151
|
+
// header-cell texts as columns, body rows as cells-of-text. Nested component
|
|
152
|
+
// structure inside cells flattens to its text with a per-cell warning — the
|
|
153
|
+
// documented loss; nothing is re-interpreted into semantic fields.
|
|
136
154
|
a2ui: "Table",
|
|
137
155
|
dspackId: "table",
|
|
138
156
|
commons: ["ComponentCommon"],
|
|
@@ -149,12 +167,37 @@ export const shadcnProfile = {
|
|
|
149
167
|
},
|
|
150
168
|
rows: {
|
|
151
169
|
schema: { type: "array", items: { type: "object" } },
|
|
152
|
-
description: "Row records, each { cells: string[]
|
|
170
|
+
description: "Row records, each { cells: string[] }.",
|
|
153
171
|
synthNote: "Row data carried as a static array; A2UI has no tabular data model.",
|
|
154
172
|
},
|
|
155
173
|
},
|
|
156
174
|
required: ["columns", "rows"],
|
|
157
|
-
surfacePlan: {
|
|
175
|
+
surfacePlan: {
|
|
176
|
+
structuralPassthrough: ["caption", "columns", "rows"],
|
|
177
|
+
subTable: {
|
|
178
|
+
caption: "table-caption",
|
|
179
|
+
header: "table-header",
|
|
180
|
+
headerCell: "table-head",
|
|
181
|
+
body: "table-body",
|
|
182
|
+
row: "table-row",
|
|
183
|
+
cell: "table-cell",
|
|
184
|
+
targetCaption: "caption",
|
|
185
|
+
targetColumns: "columns",
|
|
186
|
+
targetRows: "rows",
|
|
187
|
+
drops: {
|
|
188
|
+
"table-footer": "summary rows have no slot in the synthesized caption/columns/rows shape",
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
subCoverage: {
|
|
193
|
+
"table-caption": "text -> the synthesized `caption` (subTable strategy)",
|
|
194
|
+
"table-header": "structural grouping; its rows' header-cell texts -> `columns` (subTable)",
|
|
195
|
+
"table-head": "text -> a `columns` label (in the header) or a plain row cell string (as a body row header)",
|
|
196
|
+
"table-body": "structural grouping; its rows -> `rows` (subTable)",
|
|
197
|
+
"table-row": "one `rows` record (header row feeds `columns` instead)",
|
|
198
|
+
"table-cell": "subtree text, document order, -> one `rows[].cells` string; nested component structure/props are a warned loss",
|
|
199
|
+
"table-footer": "dropped with warning: summary rows have no slot in the synthesized shape",
|
|
200
|
+
},
|
|
158
201
|
},
|
|
159
202
|
{
|
|
160
203
|
// shadcn AlertDialog -> a synthesized non-dismissible confirmation. Preserves the
|
|
@@ -205,6 +248,16 @@ export const shadcnProfile = {
|
|
|
205
248
|
subButtonText: { "alert-dialog-trigger": "triggerLabel" },
|
|
206
249
|
actionProp: "action",
|
|
207
250
|
},
|
|
251
|
+
subCoverage: {
|
|
252
|
+
"alert-dialog-trigger": "label-bearing text under it -> `triggerLabel` (subButtonText; audited lift when no label-bearer)",
|
|
253
|
+
"alert-dialog-content": "transparent grouping, traversed by the subtree text consumer",
|
|
254
|
+
"alert-dialog-header": "transparent grouping, traversed by the subtree text consumer",
|
|
255
|
+
"alert-dialog-title": "text -> `title` (subText)",
|
|
256
|
+
"alert-dialog-description": "text -> `description` (subText)",
|
|
257
|
+
"alert-dialog-footer": "transparent grouping, traversed by the subtree text consumer",
|
|
258
|
+
"alert-dialog-action": "text -> `confirmLabel` (subText); its action is the synthesized confirm event",
|
|
259
|
+
"alert-dialog-cancel": "text -> `cancelLabel` (subText)",
|
|
260
|
+
},
|
|
208
261
|
},
|
|
209
262
|
],
|
|
210
263
|
synthesized: [
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scaffoldProfile: a mechanical 1:1 draft Profile from a dspack contract.
|
|
3
|
+
*
|
|
4
|
+
* Seeded from the json-render CatalogModel (the judgment-free 1:1 IR): every
|
|
5
|
+
* top-level contract component becomes a ComponentPlan with verbatim prop
|
|
6
|
+
* projections; compound sub-components get subFlatten directives derived from
|
|
7
|
+
* their *declared* `acceptsChildren` (text → asText, otherwise transparent).
|
|
8
|
+
*
|
|
9
|
+
* The scaffold invents no judgment: no valueMaps, no casualties, no lossy
|
|
10
|
+
* projections. Everything a human must review is returned as `notes` — the
|
|
11
|
+
* scaffold's analog of dspack-export's `awaitingAuthorship`. The result is a
|
|
12
|
+
* valid v1 profile document (loadProfile accepts it) whose transform passes
|
|
13
|
+
* gates A1/A2 with full coverage; whether each mapping is *right* is the
|
|
14
|
+
* author's call.
|
|
15
|
+
*/
|
|
16
|
+
import type { DspackDoc } from "../types.js";
|
|
17
|
+
export interface ScaffoldOptions {
|
|
18
|
+
/** Required: the project's catalog identity root (https URI). */
|
|
19
|
+
catalogIdBase: string;
|
|
20
|
+
catalogTitle?: string;
|
|
21
|
+
catalogDescription?: string;
|
|
22
|
+
instructions?: string;
|
|
23
|
+
/** Which token supplies theme.primaryColor; auto-detects color.primary when omitted. */
|
|
24
|
+
primaryColorToken?: {
|
|
25
|
+
category: string;
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ScaffoldNote {
|
|
30
|
+
/** What the note is about: a component id, "<id>.<prop>", or a profile field. */
|
|
31
|
+
target: string;
|
|
32
|
+
note: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ScaffoldResult {
|
|
35
|
+
/** A v1 profile *document* (includes profileVersion; loadProfile accepts it). */
|
|
36
|
+
profile: Record<string, unknown>;
|
|
37
|
+
/** Everything that needs human judgment before the profile is trustworthy. */
|
|
38
|
+
notes: ScaffoldNote[];
|
|
39
|
+
}
|
|
40
|
+
export declare function scaffoldProfile(doc: DspackDoc, options: ScaffoldOptions): ScaffoldResult;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { buildCatalogModel } from "../targets/json-render/model.js";
|
|
2
|
+
const DYN_STRING = { $ref: "#/$defs/DynamicString" };
|
|
3
|
+
const CHILD_LIST = { $ref: "#/$defs/ChildList" };
|
|
4
|
+
const COMP_ID = { $ref: "#/$defs/ComponentId" };
|
|
5
|
+
const TEXT_PLAN = {
|
|
6
|
+
a2ui: "Text",
|
|
7
|
+
commons: ["ComponentCommon"],
|
|
8
|
+
description: "Displays text content. Synthesized A2UI content primitive (not in the contract).",
|
|
9
|
+
structural: {
|
|
10
|
+
text: {
|
|
11
|
+
schema: DYN_STRING,
|
|
12
|
+
description: "The text content to display.",
|
|
13
|
+
synthNote: "A2UI content primitive required to render labels/titles in a surface.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
propMap: {
|
|
17
|
+
variant: {
|
|
18
|
+
a2ui: "variant",
|
|
19
|
+
kind: "enum",
|
|
20
|
+
targetEnum: ["h1", "h2", "h3", "h4", "h5", "caption", "body"],
|
|
21
|
+
default: "body",
|
|
22
|
+
description: "A hint for the base text style.",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["text"],
|
|
26
|
+
};
|
|
27
|
+
const COLUMN_PLAN = {
|
|
28
|
+
a2ui: "Column",
|
|
29
|
+
commons: ["ComponentCommon"],
|
|
30
|
+
description: "Arranges children vertically. Synthesized A2UI structural primitive (the contract has no layout component).",
|
|
31
|
+
structural: {
|
|
32
|
+
children: {
|
|
33
|
+
schema: CHILD_LIST,
|
|
34
|
+
description: "Child component IDs (or a template).",
|
|
35
|
+
synthNote: "A2UI structural primitive required to compose multiple children.",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["children"],
|
|
39
|
+
};
|
|
40
|
+
function subsOf(doc, id) {
|
|
41
|
+
const composition = (doc.components?.[id]?.composition ?? {});
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const raw of composition.subComponents ?? []) {
|
|
44
|
+
if (typeof raw === "string")
|
|
45
|
+
out.push({ id: raw });
|
|
46
|
+
else if (raw && typeof raw === "object" && typeof raw.id === "string")
|
|
47
|
+
out.push(raw);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
export function scaffoldProfile(doc, options) {
|
|
52
|
+
const notes = [];
|
|
53
|
+
const model = buildCatalogModel(doc, {});
|
|
54
|
+
const byId = new Map(model.components.map((c) => [c.dspackId, c]));
|
|
55
|
+
const topLevelIds = Object.keys(doc.components ?? {});
|
|
56
|
+
const name = (id) => byId.get(id)?.name ?? id;
|
|
57
|
+
const usedNames = new Set(topLevelIds.map((id) => name(id)));
|
|
58
|
+
const components = topLevelIds.map((id) => {
|
|
59
|
+
const entry = byId.get(id);
|
|
60
|
+
const contractProps = (doc.components?.[id]?.props ?? {});
|
|
61
|
+
const propMap = {};
|
|
62
|
+
for (const prop of entry.props) {
|
|
63
|
+
if (prop.synthesized)
|
|
64
|
+
continue; // the model's universal text prop belongs to json-render, not here
|
|
65
|
+
const plan = { a2ui: prop.name, kind: prop.kind };
|
|
66
|
+
if (prop.kind === "enum")
|
|
67
|
+
plan.targetEnum = prop.values;
|
|
68
|
+
const dflt = contractProps[prop.name]?.default;
|
|
69
|
+
if (typeof dflt === "string")
|
|
70
|
+
plan.default = dflt;
|
|
71
|
+
if (prop.description)
|
|
72
|
+
plan.description = prop.description;
|
|
73
|
+
propMap[prop.name] = plan;
|
|
74
|
+
}
|
|
75
|
+
for (const excluded of entry.excludedProps) {
|
|
76
|
+
notes.push({
|
|
77
|
+
target: `${id}.${excluded.name}`,
|
|
78
|
+
note: `prop not scaffolded (${excluded.reason}); map it via a structural slot, or declare the component a casualty if it cannot be represented.`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const required = Object.entries(contractProps)
|
|
82
|
+
.filter(([, p]) => p.required === true)
|
|
83
|
+
.map(([propName]) => propName)
|
|
84
|
+
.filter((propName) => propName in propMap);
|
|
85
|
+
const plan = {
|
|
86
|
+
a2ui: entry.name,
|
|
87
|
+
dspackId: id,
|
|
88
|
+
commons: ["ComponentCommon"],
|
|
89
|
+
structural: {},
|
|
90
|
+
required,
|
|
91
|
+
};
|
|
92
|
+
if (Object.keys(propMap).length > 0)
|
|
93
|
+
plan.propMap = propMap;
|
|
94
|
+
else
|
|
95
|
+
notes.push({
|
|
96
|
+
target: id,
|
|
97
|
+
note: "no declarative props were scaffolded; the contract likely needs prop enrichment before this mapping is useful.",
|
|
98
|
+
});
|
|
99
|
+
const subs = subsOf(doc, id);
|
|
100
|
+
if (subs.length > 0) {
|
|
101
|
+
const transparent = subs.filter((s) => s.acceptsChildren !== "text").map((s) => s.id);
|
|
102
|
+
const asText = Object.fromEntries(subs.filter((s) => s.acceptsChildren === "text").map((s) => [s.id, "body"]));
|
|
103
|
+
plan.structural = {
|
|
104
|
+
child: {
|
|
105
|
+
schema: COMP_ID,
|
|
106
|
+
description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
|
|
107
|
+
synthNote: "Scaffolded: the compound's sub-components flatten (subFlatten) and collapse to a single, possibly Column-wrapped, child slot.",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
plan.required.push("child");
|
|
111
|
+
plan.surfacePlan = { childProp: "child", subFlatten: { transparent, asText } };
|
|
112
|
+
plan.subCoverage = Object.fromEntries(subs.map((s) => [
|
|
113
|
+
s.id,
|
|
114
|
+
s.acceptsChildren === "text"
|
|
115
|
+
? "text -> synthesized Text (variant body) [scaffolded from acceptsChildren: text — review]"
|
|
116
|
+
: "transparent grouping: children splice inline, in order [scaffolded — review]",
|
|
117
|
+
]));
|
|
118
|
+
notes.push({
|
|
119
|
+
target: id,
|
|
120
|
+
note: `compound scaffolded from declared acceptsChildren (${subs.length} sub-components: ${transparent.length} transparent, ${Object.keys(asText).length} asText); review each subCoverage line and pick text variants.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return plan;
|
|
124
|
+
});
|
|
125
|
+
const synthesized = [];
|
|
126
|
+
for (const primitive of [TEXT_PLAN, COLUMN_PLAN]) {
|
|
127
|
+
if (usedNames.has(primitive.a2ui)) {
|
|
128
|
+
notes.push({
|
|
129
|
+
target: primitive.a2ui,
|
|
130
|
+
note: `contract already has a component named '${primitive.a2ui}'; the synthesized primitive was skipped — verify surfaceSynthesis points at a component with the expected '${primitive.a2ui === "Text" ? "text" : "children"}' prop.`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
synthesized.push(structuredClone(primitive));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let primaryColorToken = options.primaryColorToken;
|
|
138
|
+
if (!primaryColorToken) {
|
|
139
|
+
const hasColorPrimary = Boolean(doc.tokens?.color?.values?.primary);
|
|
140
|
+
primaryColorToken = { category: "color", name: "primary" };
|
|
141
|
+
notes.push({
|
|
142
|
+
target: "primaryColorToken",
|
|
143
|
+
note: hasColorPrimary
|
|
144
|
+
? "auto-detected color.primary; verify it is the intended theme primary."
|
|
145
|
+
: "defaulted to color.primary, which this contract does not define — theme.primaryColor will emit null with a warning until you point this at a real token.",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const profile = {
|
|
149
|
+
profileVersion: "1",
|
|
150
|
+
catalogTitle: options.catalogTitle ?? `${doc.name} — A2UI catalog (compiled from dspack)`,
|
|
151
|
+
catalogDescription: options.catalogDescription ??
|
|
152
|
+
`A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical 1:1 draft: review the scaffold notes before trusting any mapping.`,
|
|
153
|
+
catalogIdBase: options.catalogIdBase,
|
|
154
|
+
instructions: options.instructions ?? "For layout, use the Column component to organize other components.",
|
|
155
|
+
primaryColorToken,
|
|
156
|
+
components,
|
|
157
|
+
synthesized,
|
|
158
|
+
casualtyComponents: [],
|
|
159
|
+
surfaceSynthesis: {
|
|
160
|
+
textComponent: "Text",
|
|
161
|
+
textProp: "text",
|
|
162
|
+
wrapComponent: "Column",
|
|
163
|
+
wrapChildrenProp: "children",
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
notes.push({
|
|
167
|
+
target: "casualtyComponents",
|
|
168
|
+
note: "scaffolds never declare casualties; components that cannot be represented must be moved here by the author, with a reason.",
|
|
169
|
+
});
|
|
170
|
+
return { profile, notes };
|
|
171
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "dspack emitters: compile a dspack design-system contract and dspack surfaces into protocol targets — an A2UI catalog + surface messages (gates A1-A3) and json-render catalog/registry modules + specs (gates J1-J3).",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"transform": "tsx src/cli.ts",
|
|
21
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/validate/meta && cp src/validate/meta/*.json dist/validate/meta/",
|
|
21
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/validate/meta && cp src/validate/meta/*.json dist/validate/meta/ && cp src/transform/profile.v1.schema.json dist/transform/",
|
|
22
22
|
"prepare": "npm run build",
|
|
23
23
|
"build:catalogs": "tsx src/cli.ts --in input/shadcn-ui.dspack.json --a2ui-version 0.9.1 --out out && tsx src/cli.ts --in input/shadcn-ui.dspack.json --a2ui-version 1.0 --out out",
|
|
24
24
|
"test": "vitest run",
|
|
@@ -37,5 +37,8 @@
|
|
|
37
37
|
"typescript": "^5.7.2",
|
|
38
38
|
"vitest": "^2.1.8",
|
|
39
39
|
"zod": "3.25.76"
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"dspack-emit": "dist/cli.js"
|
|
40
43
|
}
|
|
41
44
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* dspack-emit CLI.
|
|
3
|
+
* dspack-emit CLI (also installed as the `dspack-emit` bin).
|
|
4
4
|
*
|
|
5
5
|
* tsx src/cli.ts --in <dspack.json> --a2ui-version <0.9.1|1.0> --out <dir> [--surface <surface.json>]
|
|
6
|
-
* [--emit-surface <surface.dsurface.json>]
|
|
6
|
+
* [--profile <profile.json>] [--emit-surface <surface.dsurface.json>]
|
|
7
7
|
* tsx src/cli.ts --target json-render --in <dspack.json> --out <dir>
|
|
8
8
|
* [--emit-surface <surface.dsurface.json>]
|
|
9
9
|
*
|
|
10
|
+
* --profile loads a JSON mapping profile (validated against
|
|
11
|
+
* profile.v1.schema.json via loadProfile) instead of the built-in shadcn
|
|
12
|
+
* profile — the flag that makes out-of-repo contracts emittable from CI.
|
|
13
|
+
* When --profile is given and --surface is not, the sample-surface default
|
|
14
|
+
* (a repo-relative fixture) is skipped and gate A3 runs on --emit-surface
|
|
15
|
+
* output only.
|
|
16
|
+
*
|
|
10
17
|
* Default target (a2ui): emits a versioned A2UI catalog + a
|
|
11
18
|
* validation/fidelity report. Exits non-zero if the hard gate (catalog schema
|
|
12
19
|
* validation) fails, so it is CI-friendly. With --emit-surface, additionally
|
|
@@ -25,6 +32,8 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
25
32
|
import { basename, join, resolve } from "node:path";
|
|
26
33
|
import type { A2uiVersion, DspackDoc, DspackSurface } from "./types.js";
|
|
27
34
|
import { transform } from "./transform/index.js";
|
|
35
|
+
import { shadcnProfile, type Profile } from "./transform/profiles.js";
|
|
36
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
28
37
|
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
29
38
|
import { generateJsonRenderModules } from "./targets/json-render/codegen.js";
|
|
30
39
|
import { emitJsonRenderSpec, EmitJsonRenderError, validateSpecAgainstModel } from "./targets/json-render/emit.js";
|
|
@@ -34,7 +43,8 @@ interface Args {
|
|
|
34
43
|
in: string;
|
|
35
44
|
version: A2uiVersion;
|
|
36
45
|
out: string;
|
|
37
|
-
surface
|
|
46
|
+
surface?: string;
|
|
47
|
+
profile?: string;
|
|
38
48
|
emitSurface?: string;
|
|
39
49
|
strictCoverage: boolean;
|
|
40
50
|
}
|
|
@@ -73,12 +83,16 @@ function parseArgs(argv: string[]): Args {
|
|
|
73
83
|
}
|
|
74
84
|
const input = m.get("in");
|
|
75
85
|
if (!input) fail("--in <dspack.json> is required");
|
|
86
|
+
const profile = m.get("profile");
|
|
76
87
|
return {
|
|
77
88
|
target,
|
|
78
89
|
in: input!,
|
|
79
90
|
version: (version ?? "0.9.1") as A2uiVersion,
|
|
80
91
|
out: m.get("out") ?? "out",
|
|
81
|
-
|
|
92
|
+
// The sample-surface default is a repo-relative fixture; external callers
|
|
93
|
+
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
94
|
+
surface: m.get("surface") ?? (profile ? undefined : "surface/settings-card.surface.json"),
|
|
95
|
+
profile,
|
|
82
96
|
emitSurface: m.get("emit-surface"),
|
|
83
97
|
strictCoverage: m.get("strict-coverage") === "true",
|
|
84
98
|
};
|
|
@@ -141,9 +155,21 @@ function main(): void {
|
|
|
141
155
|
jsonRenderMain(args, doc);
|
|
142
156
|
return;
|
|
143
157
|
}
|
|
144
|
-
|
|
158
|
+
let profile: Profile = shadcnProfile;
|
|
159
|
+
if (args.profile) {
|
|
160
|
+
try {
|
|
161
|
+
profile = loadProfile(JSON.parse(readFileSync(resolve(args.profile), "utf8")));
|
|
162
|
+
} catch (e) {
|
|
163
|
+
if (e instanceof ProfileLoadError) {
|
|
164
|
+
console.error(`error: --profile ${args.profile}: ${e.message}`);
|
|
165
|
+
process.exit(2);
|
|
166
|
+
}
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const surface = args.surface ? JSON.parse(readFileSync(resolve(args.surface), "utf8")) : { messages: [] };
|
|
145
171
|
|
|
146
|
-
const { catalog, mapping, validation, report } = transform(doc, args.version, surface);
|
|
172
|
+
const { catalog, mapping, validation, report } = transform(doc, args.version, surface, profile);
|
|
147
173
|
|
|
148
174
|
mkdirSync(resolve(args.out), { recursive: true });
|
|
149
175
|
const base = resolve(args.out);
|
|
@@ -169,7 +195,7 @@ function main(): void {
|
|
|
169
195
|
const csr = JSON.parse(readFileSync(resolve(args.emitSurface), "utf8")) as DspackSurface;
|
|
170
196
|
let emitted;
|
|
171
197
|
try {
|
|
172
|
-
emitted = emitSurface(csr, doc);
|
|
198
|
+
emitted = emitSurface(csr, doc, { profile });
|
|
173
199
|
} catch (e) {
|
|
174
200
|
if (e instanceof EmitSurfaceError) {
|
|
175
201
|
console.error(`${tag} EMIT-SURFACE FAILED: ${e.message}`);
|
|
@@ -183,7 +209,7 @@ function main(): void {
|
|
|
183
209
|
for (const w of emitted.warnings) console.log(`${tag} note ${w.code}: ${w.message}`);
|
|
184
210
|
// Gate A3 over the emitted surface: its instances must validate against the
|
|
185
211
|
// catalog generated in this same run.
|
|
186
|
-
const check = transform(doc, args.version, { messages: emitted.messages });
|
|
212
|
+
const check = transform(doc, args.version, { messages: emitted.messages }, profile);
|
|
187
213
|
const instanceGate = check.validation.gates.find((g) => g.name === "instance");
|
|
188
214
|
console.log(`${tag} emitted surface -> ${outPath}`);
|
|
189
215
|
console.log(`${tag} ${instanceGate?.pass ? "PASS" : "FAIL"} instance (emitted surface vs generated catalog)`);
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { transform, transformFromJson, type TransformOutput } from "./transform/index.js";
|
|
9
9
|
export { shadcnProfile, type Profile, type ComponentPlan, type SurfacePlanDirectives } from "./transform/profiles.js";
|
|
10
|
+
export { loadProfile, profileSchema, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
|
|
11
|
+
export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
|
|
10
12
|
export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
11
13
|
export {
|
|
12
14
|
emitSurface,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* @a2ui/web_core pins the root tree to zod v3 while json-render requires
|
|
17
17
|
* zod v4. This file asserts everything that is assertable offline.
|
|
18
18
|
*/
|
|
19
|
-
import { readFileSync } from "node:fs";
|
|
19
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
20
20
|
import { describe, expect, it } from "vitest";
|
|
21
21
|
import type { DspackDoc, DspackSurface, SurfaceNode } from "./types.js";
|
|
22
22
|
import { transform } from "./transform/index.js";
|
|
@@ -194,3 +194,50 @@ describe("codegen: generated modules match the reviewed goldens", () => {
|
|
|
194
194
|
expect(excluded).toEqual(["alert-dialog.onOpenChange", "dialog.onOpenChange", "dropdown-menu.onOpenChange"]);
|
|
195
195
|
});
|
|
196
196
|
});
|
|
197
|
+
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// PR-20: the SECOND contract through the json-render target. The asymmetry
|
|
200
|
+
// finding's prediction is the test: an empty profile suffices, the catalog
|
|
201
|
+
// carries Astryx's own (props-based) vocabulary, and the only losses are the
|
|
202
|
+
// data-driven array props — excluded loudly with documented reasons, never
|
|
203
|
+
// silently dropped.
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
import { astryxJsonRenderProfile } from "./targets/json-render/profile.js";
|
|
206
|
+
|
|
207
|
+
const astryxDoc = JSON.parse(readFileSync("input/astryx.dspack.json", "utf8")) as DspackDoc & {
|
|
208
|
+
examples: Array<{ id: string; surface: DspackSurface }>;
|
|
209
|
+
};
|
|
210
|
+
const deleteProjectFixture = JSON.parse(
|
|
211
|
+
readFileSync("surface/delete-project.dsurface.json", "utf8"),
|
|
212
|
+
) as DspackSurface;
|
|
213
|
+
|
|
214
|
+
describe("astryx through json-render (empty profile — the asymmetry prediction, contract n=2)", () => {
|
|
215
|
+
const { catalogTs, registryTsx, model } = generateJsonRenderModules(astryxDoc, astryxJsonRenderProfile);
|
|
216
|
+
|
|
217
|
+
it("catalog.ts equals golden", () => {
|
|
218
|
+
const goldenPath = "golden/json-render/astryx.catalog.ts.golden";
|
|
219
|
+
if (process.env.UPDATE_GOLDEN) writeFileSync(goldenPath, catalogTs);
|
|
220
|
+
expect(catalogTs).toBe(readFileSync(goldenPath, "utf8"));
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("registry.tsx equals golden", () => {
|
|
224
|
+
const goldenPath = "golden/json-render/astryx.registry.tsx.golden";
|
|
225
|
+
if (process.env.UPDATE_GOLDEN) writeFileSync(goldenPath, registryTsx);
|
|
226
|
+
expect(registryTsx).toBe(readFileSync(goldenPath, "utf8"));
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("data-driven array props are excluded LOUDLY (the lossy edge of the lossless target)", () => {
|
|
230
|
+
const table = model.components.find((c) => c.dspackId === "table")!;
|
|
231
|
+
const menu = model.components.find((c) => c.dspackId === "dropdown-menu")!;
|
|
232
|
+
expect(table.excludedProps.map((p) => p.name).sort()).toEqual(["columns", "data"]);
|
|
233
|
+
expect(menu.excludedProps.map((p) => p.name)).toContain("items");
|
|
234
|
+
for (const p of [...table.excludedProps, ...menu.excludedProps]) {
|
|
235
|
+
expect(p.reason).toMatch(/unsupported prop type 'array'/);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("the worked example emits and instance-validates against the generated model (offline J2/J3)", () => {
|
|
240
|
+
const { spec } = emitJsonRenderSpec(deleteProjectFixture, astryxDoc, astryxJsonRenderProfile);
|
|
241
|
+
expect(validateSpecAgainstModel(spec, model)).toEqual([]);
|
|
242
|
+
});
|
|
243
|
+
});
|