@aestheticfunction/dspack-emit 0.6.0 → 0.8.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 +23 -15
- package/dist/cli.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/targets/a2ui/surface.js +108 -4
- package/dist/transform/emit-v1_0.d.ts +45 -0
- package/dist/transform/emit-v1_0.js +190 -0
- package/dist/transform/emit.d.ts +6 -9
- package/dist/transform/emit.js +5 -44
- package/dist/transform/index.js +3 -1
- package/dist/types.d.ts +4 -0
- package/dist/validate/ajv.d.ts +26 -0
- package/dist/validate/ajv.js +150 -23
- package/dist/validate/meta/a2ui-v1_0.d.ts +9 -0
- package/dist/validate/meta/a2ui-v1_0.js +811 -0
- package/dist/validate/meta/catalog-meta.js +34 -21
- package/package.json +6 -2
- package/src/byte-neutral.test.ts +6 -3
- package/src/cli.ts +5 -2
- package/src/engine-boundary.test.ts +10 -0
- package/src/functions.test.ts +48 -1
- package/src/index.ts +1 -1
- package/src/instance-diagnostics.test.ts +194 -0
- package/src/profile-v2.test.ts +1 -1
- package/src/review-findings.test.ts +4 -1
- package/src/surface-emit.test.ts +43 -11
- package/src/surface-fidelity.test.ts +12 -0
- package/src/t1.test.ts +9 -8
- package/src/targets/a2ui/surface.ts +124 -4
- package/src/transform/emit-v1_0.ts +215 -0
- package/src/transform/emit.ts +10 -54
- package/src/transform/index.ts +3 -1
- package/src/transform.test.ts +33 -1
- package/src/types.ts +4 -0
- package/src/v1_0-catalog.test.ts +267 -0
- package/src/validate/ajv.ts +169 -22
- package/src/validate/meta/a2ui-catalog.meta.1_0.json +67 -13
- package/src/validate/meta/a2ui-v1_0.ts +820 -0
- package/src/validate/meta/catalog-meta.ts +34 -21
- 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
package/README.md
CHANGED
|
@@ -52,8 +52,8 @@ https://github.com/user-attachments/assets/510a781b-4214-49b3-b997-9cbecdc36961
|
|
|
52
52
|
| --- | --- |
|
|
53
53
|
| `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). **Pinned to v2.3.0 (8 components) — not current shadcn coverage;** see [`docs/CONTRACT-PIN.md`](docs/CONTRACT-PIN.md). |
|
|
54
54
|
| `src/` | The transformer: source-agnostic engine + data-only profile + versioned emitter + validator. |
|
|
55
|
-
| `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components. |
|
|
56
|
-
| `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (
|
|
55
|
+
| `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components (`settings-card.v1_0.surface.json`: the same surface in 1.0 message form). |
|
|
56
|
+
| `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (versioned `catalogId`). The 0.9.1 catalog is self-contained; the 1.0 catalog references the pinned `common_types.json`, as the 1.0 specification requires. |
|
|
57
57
|
| `out/validation-report.*` | Validation + fidelity reports (Markdown + JSON). |
|
|
58
58
|
| `docs/MAPPING.md` | Per-field fidelity narrative and the deliberate casualties. |
|
|
59
59
|
| `demo/` | Standalone Vite + React 19 app rendering the surface via `@a2ui/react`. |
|
|
@@ -120,15 +120,18 @@ the repo-relative sample-surface default is skipped (gate A3 then covers
|
|
|
120
120
|
|
|
121
121
|
### Versioned emitter (`--a2ui-version 0.9.1 | 1.0`)
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
also emits **v0.9.1** for the renderer demo (maintained React renderers are stable on
|
|
125
|
-
v0.9.1). Confirmed against the checked-in fixtures, the only catalog-facing delta is:
|
|
123
|
+
Both versions are emitted from the same mapping result.
|
|
126
124
|
|
|
127
|
-
- **v0.9.1
|
|
128
|
-
|
|
125
|
+
- **v0.9.1**, for the renderer demo and today's consumers: self-contained, with every shared definition inlined and
|
|
126
|
+
`$defs.theme` carrying `primaryColor` (`#rrggbb`).
|
|
127
|
+
- **v1.0**, conformant with the pinned final specification (P1a): `protocolVersion: "1.0"`, flat components,
|
|
128
|
+
`common_types.json` references, `anyFunction`, design tokens in `metadata.extensions`, and ARIA-named properties
|
|
129
|
+
carried by the envelope's `@accessibility`. See [docs/A2UI-1.0-CATALOG.md](docs/A2UI-1.0-CATALOG.md) for each rule,
|
|
130
|
+
the mapping, the independent validator results and the limitations. A consumer that compiles a 1.0 catalog itself
|
|
131
|
+
registers `catalogCompanionSchemas(catalog)` beside it.
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
What "1.0" covers today: the **catalog** (validated against the official specification schema). Surfaces are still
|
|
134
|
+
emitted as 0.9.1 **messages**, and nothing here **renders** 1.0, so this is not complete A2UI 1.0 support.
|
|
132
135
|
|
|
133
136
|
## Validation (the hard gate)
|
|
134
137
|
|
|
@@ -136,11 +139,14 @@ v0.9.1). Confirmed against the checked-in fixtures, the only catalog-facing delt
|
|
|
136
139
|
(draft 2020-12, `strict:false`, `ajv-formats` — the same toolchain A2UI itself uses):
|
|
137
140
|
|
|
138
141
|
1. **schema-compile + no-external-ref** — ajv compiles the catalog *as a schema*;
|
|
139
|
-
fails on any unresolved `$ref`, proving it is a valid, fully self-contained schema
|
|
142
|
+
fails on any unresolved `$ref`, proving it is a valid, fully self-contained schema
|
|
143
|
+
(for 1.0: every external reference is one of the specification's listed `common_types.json` types).
|
|
140
144
|
2. **catalog-shape** — validates against a version-specific catalog-shape meta-schema
|
|
141
|
-
(`src/validate/meta/`), the check that makes v0.9.1 vs v1.0 conformance distinct.
|
|
145
|
+
(`src/validate/meta/`), the check that makes v0.9.1 vs v1.0 conformance distinct. For 1.0
|
|
146
|
+
this is the official `catalog_definition.json`, plus dspack's invariants.
|
|
142
147
|
3. **instance** — every component instance in the sample surface validates against the
|
|
143
|
-
catalog's own `#/$defs/anyComponent
|
|
148
|
+
catalog's own `#/$defs/anyComponent` (for 1.0: as the envelope composes it, `ComponentCommon`
|
|
149
|
+
with the catalog component, closed; instances must therefore be in 1.0 message form).
|
|
144
150
|
|
|
145
151
|
The CLI exits non-zero if any gate fails. Both emitted versions currently pass all
|
|
146
152
|
three. The instance gate is proven non-vacuous in the test suite (it rejects a
|
|
@@ -166,9 +172,11 @@ npm run transform -- --in input/shadcn-ui.dspack.json --a2ui-version 0.9.1 --out
|
|
|
166
172
|
|
|
167
173
|
emits `out/delete-account.surface.json` (createSurface with dspack-token theme +
|
|
168
174
|
updateComponents) and instance-validates it against the freshly generated catalog
|
|
169
|
-
(gate A3). Exit codes: `1` catalog gates failed, `
|
|
170
|
-
surface could not be emitted (unknown component /
|
|
171
|
-
|
|
175
|
+
(gate A3). Exit codes: `1` catalog gates failed, `2` usage or profile-load error,
|
|
176
|
+
`3` strict-coverage, `4` the surface could not be emitted (unknown component /
|
|
177
|
+
structure the profile cannot project), `5` `--strict-surface` (a surface emitted,
|
|
178
|
+
but with fidelity losses you asked to treat as failures — bare, or scoped as
|
|
179
|
+
`--strict-surface=lossy,synthesis-defaults`). The projection is data in the profile (`surfacePlan` directives in
|
|
172
180
|
`src/transform/profiles.ts`); the engine has no component-specific code.
|
|
173
181
|
|
|
174
182
|
**Honest scope:** compound composition flattens per the documented casualties in
|
package/dist/cli.js
CHANGED
|
@@ -97,9 +97,11 @@ function parseArgs(argv) {
|
|
|
97
97
|
in: input,
|
|
98
98
|
version: (version ?? "0.9.1"),
|
|
99
99
|
out: m.get("out") ?? "out",
|
|
100
|
-
// The sample-surface default is a repo-relative fixture
|
|
100
|
+
// The sample-surface default is a repo-relative fixture, one per A2UI
|
|
101
|
+
// version (the 1.0 sample is in 1.0 message form); external callers
|
|
101
102
|
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
102
|
-
surface: m.get("surface") ??
|
|
103
|
+
surface: m.get("surface") ??
|
|
104
|
+
(profile ? undefined : version === "1.0" ? "surface/settings-card.v1_0.surface.json" : "surface/settings-card.surface.json"),
|
|
103
105
|
profile,
|
|
104
106
|
emitSurface: m.get("emit-surface"),
|
|
105
107
|
strictCoverage: m.get("strict-coverage") === "true",
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { ProfileContractError, type ProfileContractIssue } from "./transform/val
|
|
|
12
12
|
export { ProfileParseError, type ParseIssue, type SurfaceV2 } from "./transform/parse-v2.js";
|
|
13
13
|
export type { SurfaceFidelityEntry } from "./types.js";
|
|
14
14
|
export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
|
|
15
|
-
export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
15
|
+
export { validateCatalog, extractInstances, catalogCompanionSchemas, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
16
16
|
export { emitSurface, slug, EmitSurfaceError, type EmitSurfaceResult, type EmitSurfaceOptions, } from "./targets/a2ui/surface.js";
|
|
17
17
|
export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, type EmitJsonRenderResult, type EmitJsonRenderOptions, type JsonRenderSpec, type JsonRenderElement, type SpecFinding, } from "./targets/json-render/emit.js";
|
|
18
18
|
export { generateJsonRenderModules, type JsonRenderModules } from "./targets/json-render/codegen.js";
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export { loadProfile, profileSchema, profileSchemaV2, ProfileLoadError } from ".
|
|
|
11
11
|
export { ProfileContractError } from "./transform/validate-v2.js";
|
|
12
12
|
export { ProfileParseError } from "./transform/parse-v2.js";
|
|
13
13
|
export { scaffoldProfile } from "./transform/scaffold.js";
|
|
14
|
-
export { validateCatalog, extractInstances } from "./validate/ajv.js";
|
|
14
|
+
export { validateCatalog, extractInstances, catalogCompanionSchemas } from "./validate/ajv.js";
|
|
15
15
|
export { emitSurface, slug, EmitSurfaceError, } from "./targets/a2ui/surface.js";
|
|
16
16
|
export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, } from "./targets/json-render/emit.js";
|
|
17
17
|
export { generateJsonRenderModules } from "./targets/json-render/codegen.js";
|
|
@@ -41,6 +41,11 @@ export function emitSurface(surface, doc, options = {}) {
|
|
|
41
41
|
const rootId = rootPlan && surfaceModelOf(rootPlan).transparent
|
|
42
42
|
? emitter.emitTransparentRoot(surface.root, "$.root")
|
|
43
43
|
: emitter.emitNode(surface.root, "$.root");
|
|
44
|
+
// Every instance is assembled; refuse the whole emission if any of them
|
|
45
|
+
// could not validate against the catalog this surface names (required
|
|
46
|
+
// presence + enum membership — the observed defect class; gate A3 keeps
|
|
47
|
+
// full-schema rigor downstream).
|
|
48
|
+
emitter.refuseCatalogInvalid();
|
|
44
49
|
const surfaceId = options.surfaceId ?? slug(surface.intent);
|
|
45
50
|
const theme = { agentDisplayName: `${doc.name} via dspack` };
|
|
46
51
|
const primaryHex = primaryColor(doc, profile);
|
|
@@ -81,6 +86,14 @@ class SurfaceEmitter {
|
|
|
81
86
|
components = [];
|
|
82
87
|
diagnostics = new Diagnostics();
|
|
83
88
|
usedIds = new Set();
|
|
89
|
+
/**
|
|
90
|
+
* Evidence channel for the final catalog-validity guard: authored props
|
|
91
|
+
* dropped per EMITTED instance — either the prop had no A2UI projection at
|
|
92
|
+
* all, or its value had no projection and no default. Keyed by instance
|
|
93
|
+
* object so a later missing-required refusal can cite its cause. This is
|
|
94
|
+
* bookkeeping alongside the (byte-frozen) warnings, never a new warning.
|
|
95
|
+
*/
|
|
96
|
+
droppedProps = new Map();
|
|
84
97
|
constructor(profile, byDspackId) {
|
|
85
98
|
this.profile = profile;
|
|
86
99
|
this.byDspackId = byDspackId;
|
|
@@ -389,8 +402,9 @@ class SurfaceEmitter {
|
|
|
389
402
|
}
|
|
390
403
|
case "sub-text-lift": {
|
|
391
404
|
// Audited lift: relocation of text that exists, never synthesis. If
|
|
392
|
-
// nothing exists to lift the destination stays missing
|
|
393
|
-
//
|
|
405
|
+
// nothing exists to lift the destination stays missing — refused at
|
|
406
|
+
// emission by the final catalog-validity guard when it is required,
|
|
407
|
+
// arbitrated by gate A3 otherwise. Either way, no fabrication.
|
|
394
408
|
const lift = (n, inside) => {
|
|
395
409
|
const here = inside || selector.subs.includes(n.component);
|
|
396
410
|
if (here && n.text !== undefined && n.text !== "")
|
|
@@ -442,6 +456,7 @@ class SurfaceEmitter {
|
|
|
442
456
|
continue;
|
|
443
457
|
const pp = plan.propMap?.[prop];
|
|
444
458
|
if (!pp) {
|
|
459
|
+
this.recordDrop(instance, { prop, raw, component: node.component, path, reason: "no-projection" });
|
|
445
460
|
this.diagnostics.push({
|
|
446
461
|
code: "surface-prop-dropped",
|
|
447
462
|
message: `${path}: prop '${prop}' on '${node.component}' has no A2UI projection; dropped.`,
|
|
@@ -452,6 +467,7 @@ class SurfaceEmitter {
|
|
|
452
467
|
const mapped = pp.valueMap ? pp.valueMap[String(raw)] : undefined;
|
|
453
468
|
const value = pp.valueMap ? (mapped ?? pp.default) : raw;
|
|
454
469
|
if (value === undefined) {
|
|
470
|
+
this.recordDrop(instance, { prop, dest: pp.a2ui, raw, component: node.component, path, reason: "no-value" });
|
|
455
471
|
this.diagnostics.push({
|
|
456
472
|
code: "surface-prop-value-dropped",
|
|
457
473
|
message: `${path}: value '${String(raw)}' of prop '${prop}' has no projection and no default; dropped.`,
|
|
@@ -470,6 +486,92 @@ class SurfaceEmitter {
|
|
|
470
486
|
}, treePath, Band.BeforeChildren, Phase.PropMap);
|
|
471
487
|
}
|
|
472
488
|
}
|
|
489
|
+
recordDrop(instance, entry) {
|
|
490
|
+
const list = this.droppedProps.get(instance);
|
|
491
|
+
if (list)
|
|
492
|
+
list.push(entry);
|
|
493
|
+
else
|
|
494
|
+
this.droppedProps.set(instance, [entry]);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Final guard (ratified 2026-08-10): never return a surface whose instances
|
|
498
|
+
* the emitted catalog itself refuses. Two checks per instance, against its
|
|
499
|
+
* own ComponentPlan:
|
|
500
|
+
*
|
|
501
|
+
* - every catalog-required prop carries a value (`plan.required` — the
|
|
502
|
+
* same list mapping.ts emits as `required: ["component", ...]`);
|
|
503
|
+
* - every propMap-projected prop with a `targetEnum` carries a member of
|
|
504
|
+
* that enum (without a valueMap the authored value passes through
|
|
505
|
+
* verbatim, so an off-vocabulary value used to land silently).
|
|
506
|
+
*
|
|
507
|
+
* On any violation the whole emission refuses with ONE aggregated message
|
|
508
|
+
* citing each violation and — where the node's recorded drop diagnostics
|
|
509
|
+
* recover it — the cause. This covers the observed defect class
|
|
510
|
+
* (required-presence + enum-membership); full-schema rigor stays gate A3's
|
|
511
|
+
* job, downstream, as defense in depth. Warnings and fidelity recording are
|
|
512
|
+
* untouched: a surface that emits, emits byte-identically to before.
|
|
513
|
+
*/
|
|
514
|
+
refuseCatalogInvalid() {
|
|
515
|
+
const byA2ui = new Map();
|
|
516
|
+
for (const plan of [...this.profile.components, ...this.profile.synthesized]) {
|
|
517
|
+
// Transparent plans dissolve at emission — no instance ever carries them.
|
|
518
|
+
if (!surfaceModelOf(plan).transparent)
|
|
519
|
+
byA2ui.set(plan.a2ui, plan);
|
|
520
|
+
}
|
|
521
|
+
const violations = [];
|
|
522
|
+
for (const inst of this.components) {
|
|
523
|
+
const plan = byA2ui.get(String(inst.component));
|
|
524
|
+
if (!plan)
|
|
525
|
+
continue; // no plan to check against: gate A3 arbitrates downstream
|
|
526
|
+
const where = `${inst.component}#${inst.id}`;
|
|
527
|
+
const drops = this.droppedProps.get(inst) ?? [];
|
|
528
|
+
for (const req of plan.required) {
|
|
529
|
+
if (inst[req] !== undefined)
|
|
530
|
+
continue;
|
|
531
|
+
violations.push(`${where}: required prop '${req}' has no value after emission${this.missingCause(plan, req, drops)}`);
|
|
532
|
+
}
|
|
533
|
+
for (const [src, pp] of Object.entries(plan.propMap ?? {})) {
|
|
534
|
+
if (!pp.targetEnum)
|
|
535
|
+
continue;
|
|
536
|
+
const value = inst[pp.a2ui];
|
|
537
|
+
if (value === undefined)
|
|
538
|
+
continue;
|
|
539
|
+
if (typeof value === "string" && pp.targetEnum.includes(value))
|
|
540
|
+
continue;
|
|
541
|
+
const cause = pp.valueMap ? "" : ` — authored 'props.${src}' passed through verbatim (this propMap declares no valueMap)`;
|
|
542
|
+
violations.push(`${where}: prop '${pp.a2ui}' value ${JSON.stringify(value)} is outside the catalog's enum (allowed: ${pp.targetEnum.join(", ")})${cause}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (violations.length > 0) {
|
|
546
|
+
throw new EmitSurfaceError(`refusing to emit: ${violations.length} instance value(s) would not validate against the emitted catalog ` +
|
|
547
|
+
`(gate A3 would refuse this surface downstream):\n` +
|
|
548
|
+
violations.map((v) => ` - ${v}`).join("\n"), "$");
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* The recoverable cause for a required prop with no value: the authored
|
|
553
|
+
* prop this node DID carry that was dropped (recorded at PropMap time),
|
|
554
|
+
* and/or where the plan's own routes expect the value to come from.
|
|
555
|
+
*/
|
|
556
|
+
missingCause(plan, req, drops) {
|
|
557
|
+
const model = surfaceModelOf(plan);
|
|
558
|
+
const feeders = model.routes.filter((r) => r.to.name === req);
|
|
559
|
+
const subs = [
|
|
560
|
+
...new Set(feeders.flatMap((r) => r.from.flatMap((s) => ("subs" in s ? [...s.subs] : [])))),
|
|
561
|
+
];
|
|
562
|
+
const source = subs.length > 0
|
|
563
|
+
? ` (${req} comes from the ${subs.map((s) => `'${s}'`).join(" / ")} sub-component${subs.length > 1 ? "s" : ""})`
|
|
564
|
+
: feeders.length > 0
|
|
565
|
+
? ` (${req} is fed by ${feeders.map((r) => r.from.map(describeSelector).join(" | ")).join(", ")})`
|
|
566
|
+
: "";
|
|
567
|
+
const drop = drops.find((d) => d.prop === req || d.dest === req);
|
|
568
|
+
if (!drop)
|
|
569
|
+
return source;
|
|
570
|
+
const why = drop.reason === "no-projection"
|
|
571
|
+
? `authored 'props.${drop.prop}' on '${drop.component}' has no A2UI projection`
|
|
572
|
+
: `authored 'props.${drop.prop}'=${JSON.stringify(drop.raw)} on '${drop.component}' has no projection for that value and no default`;
|
|
573
|
+
return ` — ${why}${source}`;
|
|
574
|
+
}
|
|
473
575
|
/**
|
|
474
576
|
* Refuse when a consumed subtree contains a component the profile declared a
|
|
475
577
|
* casualty. Consumption is how compounds fold their parts into props; it is
|
|
@@ -1073,8 +1175,10 @@ class SurfaceEmitter {
|
|
|
1073
1175
|
if (value !== undefined) {
|
|
1074
1176
|
pending.push({ prop: d.to.name, value, origin: d.origin, donorPath: `${path}${suffix}`, donorComponent });
|
|
1075
1177
|
}
|
|
1076
|
-
// Nothing to donate is not an error: the destination stays absent
|
|
1077
|
-
//
|
|
1178
|
+
// Nothing to donate is not an error: the destination stays absent —
|
|
1179
|
+
// refused at emission by the final catalog-validity guard when it is
|
|
1180
|
+
// required, arbitrated by gate A3 otherwise. Relocation, never
|
|
1181
|
+
// synthesis (the lift rule).
|
|
1078
1182
|
}
|
|
1079
1183
|
// The boundary's own text rises as body text unless a self.text
|
|
1080
1184
|
// donation claimed it (the plain transparent-sub behaviour otherwise).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The A2UI 1.0 catalog, built from the same mapping result as 0.9.1. Only the differences the 1.0 specification
|
|
3
|
+
* requires live here, each against the pinned upstream (fixtures/a2ui/PIN.md; specification/v1_0/docs/a2ui_protocol.md,
|
|
4
|
+
* "Catalog Schema Rules and Conventions"):
|
|
5
|
+
*
|
|
6
|
+
* - `protocolVersion: "1.0"` (required for catalogs targeting 1.0 and beyond).
|
|
7
|
+
* - Standard types are referenced as `common_types.json#/$defs/<Type>`, never copied into the catalog, and only the
|
|
8
|
+
* types the specification lists may be referenced (rule 3). The 0.9.1 catalog inlines its own copies; 1.0 must not.
|
|
9
|
+
* - Components are flat. `ComponentCommon` is composed by the envelope (agent_to_renderer.json `Component`), so it is
|
|
10
|
+
* not wrapped in per component, and the envelope, not the component, is where `unevaluatedProperties: false` holds
|
|
11
|
+
* (rule 5). A trait such as `Checkable` stays, as in upstream's basic catalog.
|
|
12
|
+
* - `$defs` holds `anyComponent`, `anyFunction` and leaf definitions only (rules 1 and 2). With no functions declared,
|
|
13
|
+
* `anyFunction` is `{"not": {}}`, which matches no call: the form upstream's own function-less 1.0 catalog uses
|
|
14
|
+
* (catalogs/vegachart/v1/catalog.json).
|
|
15
|
+
* - Functions are call-validation schemas: `properties["@call"].const`, optional `args`, `returnType` (rule 6). As with
|
|
16
|
+
* components, the envelope (`FunctionCall`, composing `FunctionCommon`) closes the object, not the function schema.
|
|
17
|
+
* - There is no `surfaceProperties`. Design tokens are catalog-level metadata, `metadata.extensions.dspack_tokens`
|
|
18
|
+
* (rule 7; extension names are UAX #31 identifiers with a product prefix).
|
|
19
|
+
* - Every component, function and property name is a UAX #31 identifier. A design-system property whose name is an
|
|
20
|
+
* ARIA attribute maps onto the envelope's `@accessibility` instead of being renamed, so the catalog never declares a
|
|
21
|
+
* second channel for the same accessible name ("Catalog-Agnostic Accessibility Requirements").
|
|
22
|
+
*
|
|
23
|
+
* Anything this module cannot represent faithfully is refused with a stated reason rather than emitted approximately.
|
|
24
|
+
*/
|
|
25
|
+
import type { A2uiCatalog, FidelityEntry } from "../types.js";
|
|
26
|
+
import type { MappingResult } from "./mapping.js";
|
|
27
|
+
import type { Profile } from "./profiles.js";
|
|
28
|
+
/** The standard types a 1.0 catalog may reference in common_types.json (rule 3), in the specification's order. */
|
|
29
|
+
export declare const COMMON_TYPES_V1_0: readonly ["ComponentId", "Child", "ChildList", "DynamicString", "DynamicNumber", "DynamicBoolean", "DynamicStringList", "DynamicValue", "AccessibilityAttributes", "CheckRule", "Checkable", "Action", "DataBinding", "FunctionCall"];
|
|
30
|
+
/**
|
|
31
|
+
* Design-system properties named after an ARIA attribute, and the `@accessibility` attribute that carries the same
|
|
32
|
+
* meaning on a 1.0 component instance (common_types.json AccessibilityAttributes: label, description, live, hidden).
|
|
33
|
+
*/
|
|
34
|
+
export declare const ARIA_TO_ACCESSIBILITY: Readonly<Record<string, "label" | "description" | "live" | "hidden">>;
|
|
35
|
+
/** The catalog-level extension that carries the design tokens (a product-prefixed UAX #31 name). */
|
|
36
|
+
export declare const TOKEN_EXTENSION = "dspack_tokens";
|
|
37
|
+
/**
|
|
38
|
+
* The component-level extension that records which design-system properties the envelope now carries:
|
|
39
|
+
* `{ properties: { "<aria-name>": { carriedBy: "@accessibility.<attribute>", schema: <the property's own schema> } } }`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const ACCESSIBILITY_EXTENSION = "dspack_accessibility";
|
|
42
|
+
/** The 1.0 catalog. Throws, with the reason, when the mapping holds something 1.0 cannot represent. */
|
|
43
|
+
export declare function emitCatalogV1_0(result: MappingResult, profile: Profile, id: string): A2uiCatalog;
|
|
44
|
+
/** The mapping's fidelity entries as they read for the 1.0 catalog: where tokens and ARIA properties actually go. */
|
|
45
|
+
export declare function fidelityV1_0(result: MappingResult): FidelityEntry[];
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** The standard types a 1.0 catalog may reference in common_types.json (rule 3), in the specification's order. */
|
|
2
|
+
export const COMMON_TYPES_V1_0 = [
|
|
3
|
+
"ComponentId",
|
|
4
|
+
"Child",
|
|
5
|
+
"ChildList",
|
|
6
|
+
"DynamicString",
|
|
7
|
+
"DynamicNumber",
|
|
8
|
+
"DynamicBoolean",
|
|
9
|
+
"DynamicStringList",
|
|
10
|
+
"DynamicValue",
|
|
11
|
+
"AccessibilityAttributes",
|
|
12
|
+
"CheckRule",
|
|
13
|
+
"Checkable",
|
|
14
|
+
"Action",
|
|
15
|
+
"DataBinding",
|
|
16
|
+
"FunctionCall",
|
|
17
|
+
];
|
|
18
|
+
const COMMON = new Set(COMMON_TYPES_V1_0);
|
|
19
|
+
/**
|
|
20
|
+
* Design-system properties named after an ARIA attribute, and the `@accessibility` attribute that carries the same
|
|
21
|
+
* meaning on a 1.0 component instance (common_types.json AccessibilityAttributes: label, description, live, hidden).
|
|
22
|
+
*/
|
|
23
|
+
export const ARIA_TO_ACCESSIBILITY = {
|
|
24
|
+
"aria-label": "label",
|
|
25
|
+
"aria-description": "description",
|
|
26
|
+
"aria-live": "live",
|
|
27
|
+
"aria-hidden": "hidden",
|
|
28
|
+
};
|
|
29
|
+
/** The catalog-level extension that carries the design tokens (a product-prefixed UAX #31 name). */
|
|
30
|
+
export const TOKEN_EXTENSION = "dspack_tokens";
|
|
31
|
+
/**
|
|
32
|
+
* The component-level extension that records which design-system properties the envelope now carries:
|
|
33
|
+
* `{ properties: { "<aria-name>": { carriedBy: "@accessibility.<attribute>", schema: <the property's own schema> } } }`.
|
|
34
|
+
*/
|
|
35
|
+
export const ACCESSIBILITY_EXTENSION = "dspack_accessibility";
|
|
36
|
+
/** UAX #31 (`^[\p{XID_Start}_][\p{XID_Continue}]*$`), the rule for every catalog entity name in 1.0. */
|
|
37
|
+
const IDENTIFIER = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
|
|
38
|
+
class V1Refusal extends Error {
|
|
39
|
+
}
|
|
40
|
+
/** Re-target a schema's standard-type references at common_types.json; refuse any other #/$defs reference. */
|
|
41
|
+
function retarget(node, at) {
|
|
42
|
+
if (Array.isArray(node))
|
|
43
|
+
return node.map((n, i) => retarget(n, `${at}/${i}`));
|
|
44
|
+
if (!node || typeof node !== "object")
|
|
45
|
+
return node;
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const [k, v] of Object.entries(node)) {
|
|
48
|
+
if (k === "$ref" && typeof v === "string" && v.startsWith("#/$defs/")) {
|
|
49
|
+
const type = v.slice("#/$defs/".length);
|
|
50
|
+
if (!COMMON.has(type)) {
|
|
51
|
+
throw new V1Refusal(`${at}: '${v}' has no A2UI 1.0 counterpart in common_types.json (allowed: ${COMMON_TYPES_V1_0.join(", ")})`);
|
|
52
|
+
}
|
|
53
|
+
out[k] = `common_types.json#/$defs/${type}`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
out[k] = retarget(v, `${at}/${k}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function component(name, emitted) {
|
|
62
|
+
const parts = (emitted.allOf ?? []);
|
|
63
|
+
const own = parts.find((p) => !("$ref" in p));
|
|
64
|
+
if (!own)
|
|
65
|
+
throw new V1Refusal(`components.${name}: no component schema to emit`);
|
|
66
|
+
const traits = parts
|
|
67
|
+
.filter((p) => "$ref" in p)
|
|
68
|
+
.map((p) => String(p.$ref).slice("#/$defs/".length))
|
|
69
|
+
.filter((t) => t !== "ComponentCommon"); // composed by the envelope (rule 5)
|
|
70
|
+
const schema = retarget(own, `components.${name}`);
|
|
71
|
+
const properties = (schema.properties ?? {});
|
|
72
|
+
const required = (schema.required ?? []).slice();
|
|
73
|
+
const carried = {};
|
|
74
|
+
for (const prop of Object.keys(properties)) {
|
|
75
|
+
const attribute = ARIA_TO_ACCESSIBILITY[prop];
|
|
76
|
+
if (attribute) {
|
|
77
|
+
if (required.includes(prop)) {
|
|
78
|
+
throw new V1Refusal(`components.${name}.${prop}: a required ARIA property cannot move to the optional @accessibility.${attribute}`);
|
|
79
|
+
}
|
|
80
|
+
// The design system's own guidance for the property (its description, a default such as "Loading", its source)
|
|
81
|
+
// stays in the catalog beside the mapping, so an agent reading the 1.0 catalog still learns when and how to set it.
|
|
82
|
+
carried[prop] = { carriedBy: `@accessibility.${attribute}`, schema: properties[prop] };
|
|
83
|
+
delete properties[prop];
|
|
84
|
+
}
|
|
85
|
+
else if (!IDENTIFIER.test(prop)) {
|
|
86
|
+
throw new V1Refusal(`components.${name}.${prop}: not a UAX #31 identifier, and no 1.0 mapping is defined for it`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const flat = { ...schema, properties };
|
|
90
|
+
if (Object.keys(carried).length > 0) {
|
|
91
|
+
flat.metadata = { extensions: { [ACCESSIBILITY_EXTENSION]: { properties: carried } } };
|
|
92
|
+
}
|
|
93
|
+
if (traits.length === 0)
|
|
94
|
+
return flat;
|
|
95
|
+
// A trait keeps upstream's basic-catalog form: { type, allOf: [trait, component] }.
|
|
96
|
+
const { metadata, ...body } = flat;
|
|
97
|
+
return {
|
|
98
|
+
type: "object",
|
|
99
|
+
allOf: [...traits.map((t) => ({ $ref: retarget({ $ref: `#/$defs/${t}` }, `components.${name}`).$ref })), body],
|
|
100
|
+
...(metadata ? { metadata } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function functions(profile) {
|
|
104
|
+
const declared = profile.functions;
|
|
105
|
+
const names = declared ? Object.keys(declared).sort() : [];
|
|
106
|
+
if (names.length === 0)
|
|
107
|
+
return { anyFunction: { not: {} } };
|
|
108
|
+
const section = {};
|
|
109
|
+
for (const name of names) {
|
|
110
|
+
if (!IDENTIFIER.test(name))
|
|
111
|
+
throw new V1Refusal(`functions.${name}: not a UAX #31 identifier`);
|
|
112
|
+
const fn = declared[name];
|
|
113
|
+
const args = fn.args ? retarget(fn.args, `functions.${name}.args`) : undefined;
|
|
114
|
+
const requiresArgs = Array.isArray(fn.args?.required) && (fn.args.required.length > 0);
|
|
115
|
+
section[name] = {
|
|
116
|
+
type: "object",
|
|
117
|
+
description: fn.description,
|
|
118
|
+
returnType: fn.returns,
|
|
119
|
+
properties: { "@call": { const: name }, ...(args ? { args } : {}) },
|
|
120
|
+
required: requiresArgs ? ["@call", "args"] : ["@call"],
|
|
121
|
+
// No unevaluatedProperties here: the FunctionCall envelope (common_types.json) composes FunctionCommon with this
|
|
122
|
+
// schema and closes the object itself, as upstream's basic catalog relies on.
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return { section, anyFunction: { oneOf: names.map((n) => ({ $ref: `#/functions/${n}` })) } };
|
|
126
|
+
}
|
|
127
|
+
/** The 1.0 catalog. Throws, with the reason, when the mapping holds something 1.0 cannot represent. */
|
|
128
|
+
export function emitCatalogV1_0(result, profile, id) {
|
|
129
|
+
try {
|
|
130
|
+
const components = {};
|
|
131
|
+
for (const name of result.componentOrder) {
|
|
132
|
+
if (!IDENTIFIER.test(name))
|
|
133
|
+
throw new V1Refusal(`components.${name}: not a UAX #31 identifier`);
|
|
134
|
+
if (name === "Surface")
|
|
135
|
+
throw new V1Refusal("components.Surface: the name is reserved by the protocol");
|
|
136
|
+
components[name] = component(name, result.components[name]);
|
|
137
|
+
}
|
|
138
|
+
const fns = functions(profile);
|
|
139
|
+
const tokens = {
|
|
140
|
+
...(result.primaryColorHex ? { primaryColor: { value: result.primaryColorHex, source: result.primaryColorSource } } : {}),
|
|
141
|
+
palette: result.tokenExtension["x-dspack-tokens"] ?? {},
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
145
|
+
$id: id,
|
|
146
|
+
protocolVersion: "1.0",
|
|
147
|
+
title: profile.catalogTitle,
|
|
148
|
+
description: profile.catalogDescription,
|
|
149
|
+
catalogId: id,
|
|
150
|
+
...(profile.instructions !== undefined ? { instructions: profile.instructions } : {}),
|
|
151
|
+
metadata: { extensions: { [TOKEN_EXTENSION]: tokens } },
|
|
152
|
+
components,
|
|
153
|
+
...(fns.section ? { functions: fns.section } : {}),
|
|
154
|
+
$defs: {
|
|
155
|
+
anyComponent: {
|
|
156
|
+
oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
|
|
157
|
+
discriminator: { propertyName: "component" },
|
|
158
|
+
},
|
|
159
|
+
anyFunction: fns.anyFunction,
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
if (e instanceof V1Refusal)
|
|
165
|
+
throw new Error(`A2UI 1.0 catalog refused: ${e.message}`);
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** The mapping's fidelity entries as they read for the 1.0 catalog: where tokens and ARIA properties actually go. */
|
|
170
|
+
export function fidelityV1_0(result) {
|
|
171
|
+
const out = [];
|
|
172
|
+
for (const f of result.fidelity) {
|
|
173
|
+
if (/theme|surfaceProperties/.test(f.target)) {
|
|
174
|
+
out.push({ ...f, target: `metadata.extensions.${TOKEN_EXTENSION}`, note: f.note.replace(/theme\.primaryColor's #rrggbb pattern/, "the token extension's primaryColor").replace("(additionalProperties allows it)", "(a catalog-level metadata extension)") });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const aria = /^components\.([^.]+)\.properties\.(.+)$/.exec(f.target);
|
|
178
|
+
if (aria && ARIA_TO_ACCESSIBILITY[aria[2]]) {
|
|
179
|
+
out.push({
|
|
180
|
+
...f,
|
|
181
|
+
target: `components.${aria[1]} instance @accessibility.${ARIA_TO_ACCESSIBILITY[aria[2]]}`,
|
|
182
|
+
class: "synthesis-defaults",
|
|
183
|
+
note: `In A2UI 1.0 the envelope's @accessibility.${ARIA_TO_ACCESSIBILITY[aria[2]]} carries '${aria[2]}' (an ARIA attribute name is not a UAX #31 identifier). The catalog keeps the mapping and the property's own guidance in metadata.extensions.${ACCESSIBILITY_EXTENSION}.`,
|
|
184
|
+
});
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
out.push(f);
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
}
|
package/dist/transform/emit.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Versioned catalog emitter.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* (fixtures/a2ui/basic-catalog.{v0_9_1,v1_0}.json) and confirmed in pre-flight.
|
|
9
|
-
* We additionally carry the resolved design tokens as a documented extension
|
|
10
|
-
* (`additionalProperties: true` on both shapes permits it).
|
|
2
|
+
* Versioned catalog emitter. This module writes the A2UI 0.9.1 catalog, whose
|
|
3
|
+
* `$defs.theme` shape is copied from the checked-in fixture
|
|
4
|
+
* (fixtures/a2ui/basic-catalog.v0_9_1.json); the resolved design tokens ride
|
|
5
|
+
* along as a documented extension (`additionalProperties: true` permits it).
|
|
6
|
+
* The A2UI 1.0 catalog follows different rules and is built from the same
|
|
7
|
+
* mapping result by emit-v1_0.ts.
|
|
11
8
|
*/
|
|
12
9
|
import type { A2uiCatalog, A2uiVersion } from "../types.js";
|
|
13
10
|
import type { MappingResult } from "./mapping.js";
|
package/dist/transform/emit.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { INLINED_DEFS } from "./inline-defs.js";
|
|
2
|
+
import { emitCatalogV1_0 } from "./emit-v1_0.js";
|
|
2
3
|
/**
|
|
3
4
|
* The catalog's function surface, from the profile's declared FunctionPlans:
|
|
4
5
|
* a documentation section, the name enum for FunctionCall.call, and the
|
|
@@ -43,6 +44,9 @@ const VER_SEGMENT = {
|
|
|
43
44
|
export function emitCatalog(result, version, profile) {
|
|
44
45
|
const seg = VER_SEGMENT[version];
|
|
45
46
|
const id = `${profile.catalogIdBase}/${seg}/catalog.json`;
|
|
47
|
+
// A2UI 1.0 has its own catalog rules (emit-v1_0.ts); everything below is the 0.9.1 catalog, unchanged.
|
|
48
|
+
if (version === "1.0")
|
|
49
|
+
return emitCatalogV1_0(result, profile, id);
|
|
46
50
|
const anyComponent = {
|
|
47
51
|
oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
|
|
48
52
|
discriminator: { propertyName: "component" },
|
|
@@ -71,12 +75,7 @@ export function emitCatalog(result, version, profile) {
|
|
|
71
75
|
// match one declared function's branch (name AND args shape together).
|
|
72
76
|
fc.oneOf = [{ $ref: "#/$defs/anyFunction" }];
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
$defs.theme = themeDef(result);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
$defs.surfaceProperties = surfacePropertiesDef(result);
|
|
79
|
-
}
|
|
78
|
+
$defs.theme = themeDef(result);
|
|
80
79
|
const catalog = {
|
|
81
80
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
82
81
|
$id: id,
|
|
@@ -87,20 +86,6 @@ export function emitCatalog(result, version, profile) {
|
|
|
87
86
|
...(functions ? { functions: functions.section } : {}),
|
|
88
87
|
$defs,
|
|
89
88
|
};
|
|
90
|
-
if (version === "1.0") {
|
|
91
|
-
// Insert `instructions` right after description, mirroring the v1.0 fixture order.
|
|
92
|
-
return {
|
|
93
|
-
$schema: catalog.$schema,
|
|
94
|
-
$id: catalog.$id,
|
|
95
|
-
title: catalog.title,
|
|
96
|
-
description: catalog.description,
|
|
97
|
-
instructions: profile.instructions,
|
|
98
|
-
catalogId: catalog.catalogId,
|
|
99
|
-
components: catalog.components,
|
|
100
|
-
...(catalog.functions ? { functions: catalog.functions } : {}),
|
|
101
|
-
$defs: catalog.$defs,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
89
|
return catalog;
|
|
105
90
|
}
|
|
106
91
|
/** v0.9.1 — shape from fixtures/a2ui/basic-catalog.v0_9_1.json#/$defs/theme. */
|
|
@@ -133,27 +118,3 @@ function themeDef(result) {
|
|
|
133
118
|
...result.tokenExtension,
|
|
134
119
|
};
|
|
135
120
|
}
|
|
136
|
-
/** v1.0 — shape from fixtures/a2ui/basic-catalog.v1_0.json#/$defs/surfaceProperties. */
|
|
137
|
-
function surfacePropertiesDef(result) {
|
|
138
|
-
const def = {
|
|
139
|
-
type: "object",
|
|
140
|
-
properties: {
|
|
141
|
-
iconUrl: {
|
|
142
|
-
type: "string",
|
|
143
|
-
format: "uri",
|
|
144
|
-
description: "A URL for an image that identifies the agent or tool associated with the surface.",
|
|
145
|
-
},
|
|
146
|
-
agentDisplayName: {
|
|
147
|
-
type: "string",
|
|
148
|
-
description: "Text displayed next to the surface to identify the agent or tool that created it.",
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
additionalProperties: true,
|
|
152
|
-
...result.tokenExtension,
|
|
153
|
-
};
|
|
154
|
-
// v1.0 basic surfaceProperties has no primaryColor field; carry it as an extension.
|
|
155
|
-
if (result.primaryColorHex) {
|
|
156
|
-
def["x-dspack-primaryColor"] = { value: result.primaryColorHex, source: result.primaryColorSource };
|
|
157
|
-
}
|
|
158
|
-
return def;
|
|
159
|
-
}
|
package/dist/transform/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { shadcnProfile } from "./profiles.js";
|
|
|
2
2
|
import { mapDspack } from "./mapping.js";
|
|
3
3
|
import { validateProfileAgainstContract } from "./validate-v2.js";
|
|
4
4
|
import { emitCatalog } from "./emit.js";
|
|
5
|
+
import { fidelityV1_0 } from "./emit-v1_0.js";
|
|
5
6
|
import { buildReport } from "./report.js";
|
|
6
7
|
import { validateCatalog } from "../validate/ajv.js";
|
|
7
8
|
export function transform(doc, version, surface, profile = shadcnProfile) {
|
|
@@ -16,7 +17,8 @@ export function transform(doc, version, surface, profile = shadcnProfile) {
|
|
|
16
17
|
const mapping = mapDspack(doc, profile);
|
|
17
18
|
const catalog = emitCatalog(mapping, version, profile);
|
|
18
19
|
const validation = validateCatalog(catalog, version, surface);
|
|
19
|
-
|
|
20
|
+
// The 1.0 report says where tokens and ARIA properties go in a 1.0 catalog; the 0.9.1 report is unchanged.
|
|
21
|
+
const report = buildReport(version, version === "1.0" ? { ...mapping, fidelity: fidelityV1_0(mapping) } : mapping, validation);
|
|
20
22
|
return { catalog, mapping, validation, report };
|
|
21
23
|
}
|
|
22
24
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -78,7 +78,11 @@ export interface A2uiCatalog extends Json {
|
|
|
78
78
|
title: string;
|
|
79
79
|
description: string;
|
|
80
80
|
catalogId: string;
|
|
81
|
+
/** A2UI 1.0 only: the specification version the catalog targets. Never written for 0.9.1. */
|
|
82
|
+
protocolVersion?: string;
|
|
81
83
|
instructions?: string;
|
|
84
|
+
/** A2UI 1.0 only: catalog-level metadata (`metadata.extensions`). Never written for 0.9.1. */
|
|
85
|
+
metadata?: Json;
|
|
82
86
|
components: Record<string, Json>;
|
|
83
87
|
functions?: Record<string, Json>;
|
|
84
88
|
$defs: Record<string, Json>;
|