@aestheticfunction/dspack-emit 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +285 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +186 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/targets/a2ui/surface.d.ts +43 -0
- package/dist/targets/a2ui/surface.js +219 -0
- package/dist/targets/csr.d.ts +15 -0
- package/dist/targets/csr.js +9 -0
- package/dist/targets/json-render/codegen.d.ts +35 -0
- package/dist/targets/json-render/codegen.js +91 -0
- package/dist/targets/json-render/emit.d.ts +66 -0
- package/dist/targets/json-render/emit.js +142 -0
- package/dist/targets/json-render/model.d.ts +57 -0
- package/dist/targets/json-render/model.js +99 -0
- package/dist/targets/json-render/profile.d.ts +23 -0
- package/dist/targets/json-render/profile.js +3 -0
- package/dist/transform/color.d.ts +11 -0
- package/dist/transform/color.js +53 -0
- package/dist/transform/emit.d.ts +15 -0
- package/dist/transform/emit.js +100 -0
- package/dist/transform/index.d.ts +26 -0
- package/dist/transform/index.js +26 -0
- package/dist/transform/inline-defs.d.ts +22 -0
- package/dist/transform/inline-defs.js +172 -0
- package/dist/transform/mapping.d.ts +24 -0
- package/dist/transform/mapping.js +322 -0
- package/dist/transform/profiles.d.ts +120 -0
- package/dist/transform/profiles.js +282 -0
- package/dist/transform/report.d.ts +13 -0
- package/dist/transform/report.js +76 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.js +6 -0
- package/dist/validate/ajv.d.ts +15 -0
- package/dist/validate/ajv.js +132 -0
- 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 +41 -0
- package/src/cli.ts +197 -0
- package/src/index.ts +39 -0
- package/src/ingestion.test.ts +156 -0
- package/src/json-render-emit.test.ts +196 -0
- package/src/surface-emit.test.ts +184 -0
- package/src/targets/a2ui/surface.ts +287 -0
- package/src/targets/csr.ts +23 -0
- package/src/targets/json-render/codegen.ts +135 -0
- package/src/targets/json-render/emit.ts +227 -0
- package/src/targets/json-render/model.ts +170 -0
- package/src/targets/json-render/profile.ts +26 -0
- package/src/transform/color.ts +52 -0
- package/src/transform/emit.ts +128 -0
- package/src/transform/index.ts +54 -0
- package/src/transform/inline-defs.ts +209 -0
- package/src/transform/mapping.ts +391 -0
- package/src/transform/profiles.ts +425 -0
- package/src/transform/report.ts +105 -0
- package/src/transform.test.ts +112 -0
- package/src/types.ts +145 -0
- package/src/validate/ajv.ts +151 -0
- package/src/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/src/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
const DynStr = { $ref: "#/$defs/DynamicString" };
|
|
2
|
+
const CompId = { $ref: "#/$defs/ComponentId" };
|
|
3
|
+
export const shadcnProfile = {
|
|
4
|
+
catalogTitle: "shadcn/ui — A2UI catalog (compiled from dspack)",
|
|
5
|
+
catalogDescription: "A2UI catalog compiled from the shadcn/ui dspack v0.2 contract. Component shapes, " +
|
|
6
|
+
"variant enums, and the primary design token are projected onto the A2UI basic " +
|
|
7
|
+
"component vocabulary. See MAPPING.md for per-field fidelity.",
|
|
8
|
+
catalogIdBase: "https://rdombrowski.dev/catalogs/shadcn-ui",
|
|
9
|
+
instructions: "For layout, use the Column component to organize other components.",
|
|
10
|
+
primaryColorToken: { category: "color", name: "primary" },
|
|
11
|
+
surfaceSynthesis: {
|
|
12
|
+
textComponent: "Text",
|
|
13
|
+
textProp: "text",
|
|
14
|
+
wrapComponent: "Column",
|
|
15
|
+
wrapChildrenProp: "children",
|
|
16
|
+
},
|
|
17
|
+
components: [
|
|
18
|
+
{
|
|
19
|
+
a2ui: "Button",
|
|
20
|
+
dspackId: "button",
|
|
21
|
+
commons: ["ComponentCommon", "Checkable"],
|
|
22
|
+
structural: {
|
|
23
|
+
child: {
|
|
24
|
+
schema: CompId,
|
|
25
|
+
description: "The ID of the child component to render inside the button (e.g. a Text). " +
|
|
26
|
+
"Referenced by ID; not defined inline.",
|
|
27
|
+
synthNote: "A2UI Buttons render a child component by ID; dspack Button has no equivalent " +
|
|
28
|
+
"slot (children are arbitrary React nodes).",
|
|
29
|
+
},
|
|
30
|
+
action: {
|
|
31
|
+
schema: { $ref: "#/$defs/Action" },
|
|
32
|
+
description: "The interaction dispatched when the button is activated.",
|
|
33
|
+
synthNote: "A2UI requires a declarative action; dspack expresses this as an onClick handler prop, " +
|
|
34
|
+
"which is not representable in a declarative catalog.",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
propMap: {
|
|
38
|
+
variant: {
|
|
39
|
+
a2ui: "variant",
|
|
40
|
+
kind: "enum",
|
|
41
|
+
targetEnum: ["default", "primary", "borderless"],
|
|
42
|
+
valueMap: {
|
|
43
|
+
default: "primary",
|
|
44
|
+
destructive: "default",
|
|
45
|
+
outline: "default",
|
|
46
|
+
secondary: "default",
|
|
47
|
+
ghost: "borderless",
|
|
48
|
+
link: "borderless",
|
|
49
|
+
},
|
|
50
|
+
default: "primary",
|
|
51
|
+
description: "Button style hint, projected from shadcn variants onto the A2UI basic vocabulary.",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
required: ["child", "action"],
|
|
55
|
+
surfacePlan: { textChildProp: "child", actionProp: "action" },
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
a2ui: "Card",
|
|
59
|
+
dspackId: "card",
|
|
60
|
+
commons: ["ComponentCommon"],
|
|
61
|
+
structural: {
|
|
62
|
+
child: {
|
|
63
|
+
schema: CompId,
|
|
64
|
+
description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
|
|
65
|
+
synthNote: "A2UI Card takes exactly one child by ID; dspack Card composes via sub-components " +
|
|
66
|
+
"(CardHeader/CardContent/CardFooter), which collapse to a single child slot.",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
required: ["child"],
|
|
70
|
+
surfacePlan: { childProp: "child" },
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
a2ui: "TextField",
|
|
74
|
+
dspackId: "input",
|
|
75
|
+
commons: ["ComponentCommon", "Checkable"],
|
|
76
|
+
structural: {
|
|
77
|
+
label: {
|
|
78
|
+
schema: DynStr,
|
|
79
|
+
description: "The text label for the input field.",
|
|
80
|
+
synthNote: "A2UI TextField owns its label; dspack Input relies on an external <label> element, " +
|
|
81
|
+
"so the label is synthesized.",
|
|
82
|
+
},
|
|
83
|
+
value: {
|
|
84
|
+
schema: DynStr,
|
|
85
|
+
description: "The bound value of the text field.",
|
|
86
|
+
synthNote: "A2UI two-way-binds value; dspack Input has no value prop in the contract.",
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
propMap: {
|
|
90
|
+
type: {
|
|
91
|
+
a2ui: "variant",
|
|
92
|
+
kind: "enum",
|
|
93
|
+
targetEnum: ["shortText", "longText", "number", "obscured"],
|
|
94
|
+
valueMap: {
|
|
95
|
+
text: "shortText",
|
|
96
|
+
email: "shortText",
|
|
97
|
+
search: "shortText",
|
|
98
|
+
password: "obscured",
|
|
99
|
+
number: "number",
|
|
100
|
+
},
|
|
101
|
+
default: "shortText",
|
|
102
|
+
description: "Input kind, projected from the HTML input type onto A2UI TextField variants.",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
required: ["label"],
|
|
106
|
+
surfacePlan: { textProp: "label" },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
// shadcn Badge -> a real A2UI Badge component shape (variant enum carried verbatim).
|
|
110
|
+
a2ui: "Badge",
|
|
111
|
+
dspackId: "badge",
|
|
112
|
+
commons: ["ComponentCommon"],
|
|
113
|
+
structural: {
|
|
114
|
+
label: {
|
|
115
|
+
schema: DynStr,
|
|
116
|
+
description: "The badge text.",
|
|
117
|
+
synthNote: "A2UI has no Badge; the label is synthesized from the badge's text child.",
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
propMap: {
|
|
121
|
+
variant: {
|
|
122
|
+
a2ui: "variant",
|
|
123
|
+
kind: "enum",
|
|
124
|
+
targetEnum: ["default", "secondary", "outline", "destructive"],
|
|
125
|
+
default: "default",
|
|
126
|
+
description: "Badge visual treatment (carried verbatim from shadcn; the React visual honors all four).",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
required: ["label"],
|
|
130
|
+
surfacePlan: { textProp: "label" },
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
// shadcn Table -> a synthesized presentational A2UI Table shape (caption/columns/rows).
|
|
134
|
+
// The dspack sub-component composition (header/body/row/cell) cannot be represented and
|
|
135
|
+
// is recorded as a casualty by the per-component composition handling.
|
|
136
|
+
a2ui: "Table",
|
|
137
|
+
dspackId: "table",
|
|
138
|
+
commons: ["ComponentCommon"],
|
|
139
|
+
structural: {
|
|
140
|
+
caption: {
|
|
141
|
+
schema: DynStr,
|
|
142
|
+
description: "Accessible caption naming the table.",
|
|
143
|
+
synthNote: "A2UI has no Table; caption synthesized from TableCaption.",
|
|
144
|
+
},
|
|
145
|
+
columns: {
|
|
146
|
+
schema: { type: "array", items: { type: "string" } },
|
|
147
|
+
description: "Header labels for the data columns (a trailing status column is rendered separately).",
|
|
148
|
+
synthNote: "Static column labels; A2UI has no table-header primitive.",
|
|
149
|
+
},
|
|
150
|
+
rows: {
|
|
151
|
+
schema: { type: "array", items: { type: "object" } },
|
|
152
|
+
description: "Row records, each { cells: string[], status?: { label, variant } }.",
|
|
153
|
+
synthNote: "Row data carried as a static array; A2UI has no tabular data model.",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
required: ["columns", "rows"],
|
|
157
|
+
surfacePlan: { structuralPassthrough: ["caption", "columns", "rows"] },
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
// shadcn AlertDialog -> a synthesized non-dismissible confirmation. Preserves the
|
|
161
|
+
// defining distinction from Dialog; the rich composition is a documented casualty.
|
|
162
|
+
a2ui: "AlertDialog",
|
|
163
|
+
dspackId: "alert-dialog",
|
|
164
|
+
commons: ["ComponentCommon"],
|
|
165
|
+
structural: {
|
|
166
|
+
triggerLabel: {
|
|
167
|
+
schema: DynStr,
|
|
168
|
+
description: "Label of the button that opens the confirmation.",
|
|
169
|
+
synthNote: "Trigger modeled as a label, not an AlertDialogTrigger sub-component.",
|
|
170
|
+
},
|
|
171
|
+
title: {
|
|
172
|
+
schema: DynStr,
|
|
173
|
+
description: "Confirmation title.",
|
|
174
|
+
synthNote: "From AlertDialogTitle.",
|
|
175
|
+
},
|
|
176
|
+
description: {
|
|
177
|
+
schema: DynStr,
|
|
178
|
+
description: "Consequence description shown in the confirmation.",
|
|
179
|
+
synthNote: "From AlertDialogDescription.",
|
|
180
|
+
},
|
|
181
|
+
confirmLabel: {
|
|
182
|
+
schema: DynStr,
|
|
183
|
+
description: "Label of the destructive confirm action.",
|
|
184
|
+
synthNote: "From AlertDialogAction.",
|
|
185
|
+
},
|
|
186
|
+
cancelLabel: {
|
|
187
|
+
schema: DynStr,
|
|
188
|
+
description: "Label of the cancel action.",
|
|
189
|
+
synthNote: "From AlertDialogCancel.",
|
|
190
|
+
},
|
|
191
|
+
action: {
|
|
192
|
+
schema: { $ref: "#/$defs/Action" },
|
|
193
|
+
description: "Event dispatched when the user confirms the destructive action.",
|
|
194
|
+
synthNote: "A2UI declarative action; dspack expresses this as an onClick handler.",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
required: ["triggerLabel", "title", "action"],
|
|
198
|
+
surfacePlan: {
|
|
199
|
+
subText: {
|
|
200
|
+
"alert-dialog-title": "title",
|
|
201
|
+
"alert-dialog-description": "description",
|
|
202
|
+
"alert-dialog-cancel": "cancelLabel",
|
|
203
|
+
"alert-dialog-action": "confirmLabel",
|
|
204
|
+
},
|
|
205
|
+
subButtonText: { "alert-dialog-trigger": "triggerLabel" },
|
|
206
|
+
actionProp: "action",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
synthesized: [
|
|
211
|
+
{
|
|
212
|
+
a2ui: "Text",
|
|
213
|
+
commons: ["ComponentCommon"],
|
|
214
|
+
description: "Displays text content. Synthesized A2UI content primitive (not in dspack).",
|
|
215
|
+
structural: {
|
|
216
|
+
text: {
|
|
217
|
+
schema: DynStr,
|
|
218
|
+
description: "The text content to display.",
|
|
219
|
+
synthNote: "A2UI content primitive required to render labels/titles in a surface.",
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
propMap: {
|
|
223
|
+
// No dspack source; declared directly as an A2UI-native enum.
|
|
224
|
+
variant: {
|
|
225
|
+
a2ui: "variant",
|
|
226
|
+
kind: "enum",
|
|
227
|
+
targetEnum: ["h1", "h2", "h3", "h4", "h5", "caption", "body"],
|
|
228
|
+
default: "body",
|
|
229
|
+
description: "A hint for the base text style.",
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
required: ["text"],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
a2ui: "Column",
|
|
236
|
+
commons: ["ComponentCommon"],
|
|
237
|
+
description: "Arranges children vertically. Synthesized A2UI structural primitive (dspack has no " +
|
|
238
|
+
"layout component; its `layout` block is descriptive only).",
|
|
239
|
+
structural: {
|
|
240
|
+
children: {
|
|
241
|
+
schema: { $ref: "#/$defs/ChildList" },
|
|
242
|
+
description: "Child component IDs (or a template).",
|
|
243
|
+
synthNote: "A2UI structural primitive required to compose multiple children.",
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
propMap: {
|
|
247
|
+
justify: {
|
|
248
|
+
a2ui: "justify",
|
|
249
|
+
kind: "enum",
|
|
250
|
+
targetEnum: ["start", "center", "end", "spaceBetween", "spaceAround", "spaceEvenly", "stretch"],
|
|
251
|
+
default: "start",
|
|
252
|
+
description: "Arrangement of children along the vertical main axis.",
|
|
253
|
+
},
|
|
254
|
+
align: {
|
|
255
|
+
a2ui: "align",
|
|
256
|
+
kind: "enum",
|
|
257
|
+
targetEnum: ["center", "end", "start", "stretch"],
|
|
258
|
+
default: "stretch",
|
|
259
|
+
description: "Alignment of children along the horizontal cross axis.",
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
required: ["children"],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
casualtyComponents: [
|
|
266
|
+
{
|
|
267
|
+
dspackId: "dialog",
|
|
268
|
+
attempted: "Modal",
|
|
269
|
+
class: "cannot-represent",
|
|
270
|
+
reason: "dspack Dialog is a compound component (DialogTrigger/Content/Header/Title/Description/" +
|
|
271
|
+
"Footer/Close) with required-children composition rules, focus management, and a11y roles. " +
|
|
272
|
+
"A2UI Modal exposes only trigger+content; the composition contract cannot be represented.",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
dspackId: "dropdown-menu",
|
|
276
|
+
attempted: "(none)",
|
|
277
|
+
class: "cannot-represent",
|
|
278
|
+
reason: "No A2UI basic component corresponds to a dropdown menu (items, checkbox/radio items, " +
|
|
279
|
+
"sub-menus, separators). Omitted.",
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the validation + fidelity report (Markdown + JSON) for one emitted catalog.
|
|
3
|
+
*/
|
|
4
|
+
import type { A2uiVersion } from "../types.js";
|
|
5
|
+
import type { MappingResult } from "./mapping.js";
|
|
6
|
+
import type { ValidationReport } from "../validate/ajv.js";
|
|
7
|
+
export interface ReportBundle {
|
|
8
|
+
md: string;
|
|
9
|
+
json: Json;
|
|
10
|
+
}
|
|
11
|
+
type Json = Record<string, unknown>;
|
|
12
|
+
export declare function buildReport(version: A2uiVersion, mapping: MappingResult, validation: ValidationReport): ReportBundle;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const CLASS_ORDER = ["maps-cleanly", "synthesis-defaults", "lossy", "cannot-represent"];
|
|
2
|
+
const CLASS_LABEL = {
|
|
3
|
+
"maps-cleanly": "maps cleanly",
|
|
4
|
+
"synthesis-defaults": "requires synthesis / defaults",
|
|
5
|
+
lossy: "currently lossy",
|
|
6
|
+
"cannot-represent": "cannot be represented",
|
|
7
|
+
};
|
|
8
|
+
export function buildReport(version, mapping, validation) {
|
|
9
|
+
const counts = countByClass(mapping.fidelity);
|
|
10
|
+
const json = {
|
|
11
|
+
a2uiVersion: version,
|
|
12
|
+
generatedAt: new Date().toISOString(),
|
|
13
|
+
validation: { pass: validation.pass, gates: validation.gates },
|
|
14
|
+
fidelity: {
|
|
15
|
+
summary: counts,
|
|
16
|
+
entries: mapping.fidelity,
|
|
17
|
+
},
|
|
18
|
+
warnings: mapping.warnings,
|
|
19
|
+
emittedComponents: mapping.componentOrder,
|
|
20
|
+
primaryColor: { hex: mapping.primaryColorHex, source: mapping.primaryColorSource },
|
|
21
|
+
coverage: {
|
|
22
|
+
unclassified: mapping.coverage.filter((c) => c.disposition === "unclassified").map((c) => c.id),
|
|
23
|
+
entries: mapping.coverage,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const md = [
|
|
27
|
+
`# Validation & fidelity report — A2UI v${version}`,
|
|
28
|
+
"",
|
|
29
|
+
`Emitted components: ${mapping.componentOrder.map((c) => "`" + c + "`").join(", ")}`,
|
|
30
|
+
`Primary color token: ${mapping.primaryColorSource ?? "(none)"} → \`${mapping.primaryColorHex ?? "—"}\``,
|
|
31
|
+
"",
|
|
32
|
+
`## Validation — ${validation.pass ? "✅ PASS" : "❌ FAIL"} (hard gate)`,
|
|
33
|
+
"",
|
|
34
|
+
"| Gate | Result | Detail |",
|
|
35
|
+
"| --- | --- | --- |",
|
|
36
|
+
...validation.gates.map((g) => `| ${g.name} | ${g.pass ? "✅ pass" : "❌ fail"} | ${escapePipes(g.detail)} |`),
|
|
37
|
+
"",
|
|
38
|
+
...validation.gates
|
|
39
|
+
.filter((g) => g.errors?.length)
|
|
40
|
+
.flatMap((g) => [`### ${g.name} — details`, "", ...g.errors.map((e) => `- ${escapePipes(e)}`), ""]),
|
|
41
|
+
`## Fidelity summary`,
|
|
42
|
+
"",
|
|
43
|
+
"| Class | Count |",
|
|
44
|
+
"| --- | --- |",
|
|
45
|
+
...CLASS_ORDER.map((c) => `| ${CLASS_LABEL[c]} | ${counts[c]} |`),
|
|
46
|
+
"",
|
|
47
|
+
`## Fidelity — per field`,
|
|
48
|
+
"",
|
|
49
|
+
"| Source (dspack) | Target (A2UI) | Class | Note |",
|
|
50
|
+
"| --- | --- | --- | --- |",
|
|
51
|
+
...mapping.fidelity.map((f) => `| \`${f.source}\` | \`${f.target}\` | ${CLASS_LABEL[f.class]} | ${escapePipes(f.note)} |`),
|
|
52
|
+
"",
|
|
53
|
+
`## Component coverage (every input dspack component accounted for)`,
|
|
54
|
+
"",
|
|
55
|
+
"| dspack component | Disposition | Detail |",
|
|
56
|
+
"| --- | --- | --- |",
|
|
57
|
+
...mapping.coverage.map((c) => `| \`${c.id}\` | ${c.disposition === "unclassified" ? "⚠️ **unclassified**" : c.disposition} | ${escapePipes(c.detail ?? "")} |`),
|
|
58
|
+
"",
|
|
59
|
+
`## Warnings (unsupported dspack constructs)`,
|
|
60
|
+
"",
|
|
61
|
+
mapping.warnings.length === 0
|
|
62
|
+
? "_None._"
|
|
63
|
+
: mapping.warnings.map((w) => `- **${w.code}** — ${escapePipes(w.message)}`).join("\n"),
|
|
64
|
+
"",
|
|
65
|
+
].join("\n");
|
|
66
|
+
return { md, json };
|
|
67
|
+
}
|
|
68
|
+
function countByClass(entries) {
|
|
69
|
+
const counts = { "maps-cleanly": 0, "synthesis-defaults": 0, lossy: 0, "cannot-represent": 0 };
|
|
70
|
+
for (const e of entries)
|
|
71
|
+
counts[e.class]++;
|
|
72
|
+
return counts;
|
|
73
|
+
}
|
|
74
|
+
function escapePipes(s) {
|
|
75
|
+
return s.replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
76
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal types for the dspack input and the A2UI catalog output.
|
|
3
|
+
* Only the fields the transformer reads/writes are modeled; dspack documents
|
|
4
|
+
* may carry more (we ignore unknown properties per dspack conformance rules).
|
|
5
|
+
*/
|
|
6
|
+
export interface DspackDoc {
|
|
7
|
+
dspack: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
version?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
tokens?: Record<string, DspackTokenCategory>;
|
|
13
|
+
components?: Record<string, DspackComponent>;
|
|
14
|
+
patterns?: unknown[];
|
|
15
|
+
antiPatterns?: unknown[];
|
|
16
|
+
frameworkBindings?: Record<string, unknown>;
|
|
17
|
+
themes?: Record<string, unknown>;
|
|
18
|
+
layout?: Record<string, unknown>;
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface DspackTokenCategory {
|
|
22
|
+
description?: string;
|
|
23
|
+
tier?: string;
|
|
24
|
+
values: Record<string, DspackToken>;
|
|
25
|
+
}
|
|
26
|
+
export interface DspackToken {
|
|
27
|
+
value: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
[k: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface DspackComponent {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
status?: unknown;
|
|
36
|
+
whenToUse?: string;
|
|
37
|
+
whenNotToUse?: string;
|
|
38
|
+
props?: Record<string, DspackProp>;
|
|
39
|
+
tokens?: string[];
|
|
40
|
+
tags?: string[];
|
|
41
|
+
accessibility?: unknown;
|
|
42
|
+
composition?: unknown;
|
|
43
|
+
constraints?: unknown[];
|
|
44
|
+
relatedComponents?: string[];
|
|
45
|
+
[k: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface DspackProp {
|
|
48
|
+
type: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
values?: Array<string | number | boolean | {
|
|
51
|
+
value: unknown;
|
|
52
|
+
description?: string;
|
|
53
|
+
deprecated?: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
default?: unknown;
|
|
56
|
+
required?: boolean;
|
|
57
|
+
propRole?: string;
|
|
58
|
+
[k: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface DspackSurface {
|
|
61
|
+
dspackSurface: string;
|
|
62
|
+
system: string;
|
|
63
|
+
intent: string;
|
|
64
|
+
root: SurfaceNode;
|
|
65
|
+
}
|
|
66
|
+
export interface SurfaceNode {
|
|
67
|
+
component: string;
|
|
68
|
+
id?: string;
|
|
69
|
+
props?: Record<string, unknown>;
|
|
70
|
+
text?: string;
|
|
71
|
+
children?: SurfaceNode[];
|
|
72
|
+
slots?: Record<string, SurfaceNode[]>;
|
|
73
|
+
}
|
|
74
|
+
export type Json = Record<string, unknown>;
|
|
75
|
+
export interface A2uiCatalog extends Json {
|
|
76
|
+
$schema: string;
|
|
77
|
+
$id: string;
|
|
78
|
+
title: string;
|
|
79
|
+
description: string;
|
|
80
|
+
catalogId: string;
|
|
81
|
+
instructions?: string;
|
|
82
|
+
components: Record<string, Json>;
|
|
83
|
+
functions?: Record<string, Json>;
|
|
84
|
+
$defs: Record<string, Json>;
|
|
85
|
+
}
|
|
86
|
+
export type A2uiVersion = "0.9.1" | "1.0";
|
|
87
|
+
export type FidelityClass = "maps-cleanly" | "synthesis-defaults" | "lossy" | "cannot-represent";
|
|
88
|
+
export interface FidelityEntry {
|
|
89
|
+
source: string;
|
|
90
|
+
target: string;
|
|
91
|
+
class: FidelityClass;
|
|
92
|
+
note: string;
|
|
93
|
+
}
|
|
94
|
+
export interface Warning {
|
|
95
|
+
code: string;
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
98
|
+
export type Disposition = "mapped" | "adapted" | "omitted" | "unsupported" | "unclassified";
|
|
99
|
+
export interface CoverageEntry {
|
|
100
|
+
id: string;
|
|
101
|
+
disposition: Disposition;
|
|
102
|
+
detail?: string;
|
|
103
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { A2uiCatalog, A2uiVersion, Json } from "../types.js";
|
|
2
|
+
export interface GateResult {
|
|
3
|
+
name: string;
|
|
4
|
+
pass: boolean;
|
|
5
|
+
detail: string;
|
|
6
|
+
errors?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ValidationReport {
|
|
9
|
+
version: A2uiVersion;
|
|
10
|
+
pass: boolean;
|
|
11
|
+
gates: GateResult[];
|
|
12
|
+
}
|
|
13
|
+
/** Pull every component instance (object with string `component` + `id`) from a surface. */
|
|
14
|
+
export declare function extractInstances(surface: unknown, acc?: Json[]): Json[];
|
|
15
|
+
export declare function validateCatalog(catalog: A2uiCatalog, version: A2uiVersion, surface?: unknown): ValidationReport;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A2UI catalog schema validation — three executable gates, mirroring the ajv
|
|
3
|
+
* approach A2UI uses in specification/scripts/validate.py
|
|
4
|
+
* (draft 2020-12, strict:false, ajv-formats):
|
|
5
|
+
*
|
|
6
|
+
* 1. schema-compile + no-external-ref: ajv compiles the catalog AS a JSON Schema.
|
|
7
|
+
* Compilation fails on any unresolved `$ref`, proving the catalog is a valid,
|
|
8
|
+
* fully self-contained schema with zero external references.
|
|
9
|
+
* 2. catalog-shape: the catalog validates against the version-specific
|
|
10
|
+
* a2ui-catalog.meta.<ver>.json (the literal "catalog schema" check; this is what
|
|
11
|
+
* makes v0.9.1 vs v1.0 conformance distinct — theme vs surfaceProperties).
|
|
12
|
+
* 3. instance: every component instance in the hand-authored surface validates
|
|
13
|
+
* against the catalog's own #/$defs/anyComponent.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import Ajv2020 from "ajv/dist/2020.js";
|
|
18
|
+
import addFormats from "ajv-formats";
|
|
19
|
+
const metaPath = (ver) => fileURLToPath(new URL(`./meta/a2ui-catalog.meta.${ver === "0.9.1" ? "0_9_1" : "1_0"}.json`, import.meta.url));
|
|
20
|
+
function newAjv() {
|
|
21
|
+
const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
|
|
22
|
+
addFormats(ajv);
|
|
23
|
+
return ajv;
|
|
24
|
+
}
|
|
25
|
+
/** Collect every external `$ref` (a $ref whose value does not start with '#'). */
|
|
26
|
+
function externalRefs(node, acc = []) {
|
|
27
|
+
if (Array.isArray(node)) {
|
|
28
|
+
for (const n of node)
|
|
29
|
+
externalRefs(n, acc);
|
|
30
|
+
}
|
|
31
|
+
else if (node && typeof node === "object") {
|
|
32
|
+
for (const [k, v] of Object.entries(node)) {
|
|
33
|
+
if (k === "$ref" && typeof v === "string" && !v.startsWith("#"))
|
|
34
|
+
acc.push(v);
|
|
35
|
+
else
|
|
36
|
+
externalRefs(v, acc);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
}
|
|
41
|
+
/** Pull every component instance (object with string `component` + `id`) from a surface. */
|
|
42
|
+
export function extractInstances(surface, acc = []) {
|
|
43
|
+
if (Array.isArray(surface)) {
|
|
44
|
+
for (const n of surface)
|
|
45
|
+
extractInstances(n, acc);
|
|
46
|
+
}
|
|
47
|
+
else if (surface && typeof surface === "object") {
|
|
48
|
+
const o = surface;
|
|
49
|
+
if (typeof o.component === "string" && typeof o.id === "string")
|
|
50
|
+
acc.push(o);
|
|
51
|
+
for (const v of Object.values(o))
|
|
52
|
+
extractInstances(v, acc);
|
|
53
|
+
}
|
|
54
|
+
return acc;
|
|
55
|
+
}
|
|
56
|
+
export function validateCatalog(catalog, version, surface) {
|
|
57
|
+
const gates = [];
|
|
58
|
+
// Gate 1 — schema compile + no external $ref.
|
|
59
|
+
const exts = externalRefs(catalog);
|
|
60
|
+
let compiled = false;
|
|
61
|
+
let compileErr = "";
|
|
62
|
+
try {
|
|
63
|
+
newAjv().compile(catalog);
|
|
64
|
+
compiled = true;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
compileErr = e instanceof Error ? e.message : String(e);
|
|
68
|
+
}
|
|
69
|
+
gates.push({
|
|
70
|
+
name: "schema-compile + no-external-ref",
|
|
71
|
+
pass: compiled && exts.length === 0,
|
|
72
|
+
detail: compiled && exts.length === 0
|
|
73
|
+
? "Catalog compiles as a draft-2020-12 JSON Schema with only internal $refs."
|
|
74
|
+
: !compiled
|
|
75
|
+
? `ajv failed to compile the catalog as a schema: ${compileErr}`
|
|
76
|
+
: `Catalog contains external $refs: ${[...new Set(exts)].join(", ")}`,
|
|
77
|
+
errors: exts.length ? [...new Set(exts)] : undefined,
|
|
78
|
+
});
|
|
79
|
+
// Gate 2 — catalog shape.
|
|
80
|
+
const meta = JSON.parse(readFileSync(metaPath(version), "utf8"));
|
|
81
|
+
const validateShape = newAjv().compile(meta);
|
|
82
|
+
const shapeOk = validateShape(catalog);
|
|
83
|
+
gates.push({
|
|
84
|
+
name: "catalog-shape",
|
|
85
|
+
pass: shapeOk,
|
|
86
|
+
detail: shapeOk
|
|
87
|
+
? `Catalog satisfies the A2UI v${version} catalog-shape meta-schema.`
|
|
88
|
+
: `Catalog violates the v${version} catalog-shape meta-schema.`,
|
|
89
|
+
errors: shapeOk ? undefined : (validateShape.errors ?? []).map(fmtErr),
|
|
90
|
+
});
|
|
91
|
+
// Gate 3 — instances (only if compilable and a surface was supplied).
|
|
92
|
+
if (surface !== undefined) {
|
|
93
|
+
if (!compiled) {
|
|
94
|
+
gates.push({
|
|
95
|
+
name: "instance",
|
|
96
|
+
pass: false,
|
|
97
|
+
detail: "Skipped: catalog did not compile, so instances cannot be checked.",
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const ajv = newAjv();
|
|
102
|
+
ajv.addSchema(catalog, catalog.$id);
|
|
103
|
+
const validateAny = ajv.getSchema(`${catalog.$id}#/$defs/anyComponent`);
|
|
104
|
+
const instances = extractInstances(surface);
|
|
105
|
+
const failures = [];
|
|
106
|
+
if (!validateAny) {
|
|
107
|
+
failures.push("Could not resolve #/$defs/anyComponent from the catalog.");
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
for (const inst of instances) {
|
|
111
|
+
if (!validateAny(inst)) {
|
|
112
|
+
const where = `${inst.component}#${inst.id}`;
|
|
113
|
+
for (const e of validateAny.errors ?? [])
|
|
114
|
+
failures.push(`${where}: ${fmtErr(e)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
gates.push({
|
|
119
|
+
name: "instance",
|
|
120
|
+
pass: failures.length === 0,
|
|
121
|
+
detail: failures.length === 0
|
|
122
|
+
? `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
|
|
123
|
+
: `${failures.length} instance validation error(s).`,
|
|
124
|
+
errors: failures.length ? failures : undefined,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { version, pass: gates.every((g) => g.pass), gates };
|
|
129
|
+
}
|
|
130
|
+
function fmtErr(e) {
|
|
131
|
+
return `${e.instancePath || "(root)"} ${e.message ?? ""}`.trim();
|
|
132
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v0_9_1.json",
|
|
4
|
+
"title": "A2UI catalog shape (v0.9.1)",
|
|
5
|
+
"description": "Structural invariants an A2UI v0.9.1 catalog must satisfy, derived from the checked-in basic catalog fixture. The version-distinguishing requirement is $defs.theme (with primaryColor).",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["$schema", "$id", "catalogId", "title", "description", "components", "$defs"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"catalogId": { "type": "string", "format": "uri" },
|
|
10
|
+
"$id": { "type": "string", "format": "uri" },
|
|
11
|
+
"components": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"minProperties": 1,
|
|
14
|
+
"additionalProperties": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"required": ["allOf", "unevaluatedProperties"],
|
|
17
|
+
"properties": {
|
|
18
|
+
"allOf": { "type": "array", "minItems": 1 },
|
|
19
|
+
"unevaluatedProperties": { "const": false }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"$defs": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"required": ["anyComponent", "theme"],
|
|
26
|
+
"not": { "required": ["surfaceProperties"] },
|
|
27
|
+
"properties": {
|
|
28
|
+
"anyComponent": { "type": "object", "required": ["oneOf"] },
|
|
29
|
+
"theme": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"required": ["properties"],
|
|
32
|
+
"properties": {
|
|
33
|
+
"properties": { "type": "object", "required": ["primaryColor"] }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|