@aestheticfunction/dspack-emit 0.7.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 +18 -12
- package/dist/cli.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- 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 +7 -0
- package/dist/validate/ajv.js +73 -11
- 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 +1 -1
- package/src/byte-neutral.test.ts +6 -3
- package/src/cli.ts +5 -2
- package/src/functions.test.ts +48 -1
- package/src/index.ts +1 -1
- package/src/profile-v2.test.ts +1 -1
- 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 +74 -11
- 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
|
@@ -83,11 +83,12 @@ export const catalogMetaSchemas = {
|
|
|
83
83
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
84
84
|
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
|
|
85
85
|
"title": "A2UI catalog shape (v1.0)",
|
|
86
|
-
"description": "
|
|
86
|
+
"description": "dspack's own invariants for an A2UI v1.0 catalog, checked alongside the official catalog definition (fixtures/a2ui/catalog_definition.v1_0.json, pinned in fixtures/a2ui/PIN.md): it declares protocolVersion 1.0, carries neither the 0.9 theme nor the pre-release surfaceProperties, and never wraps a component in ComponentCommon, which the envelope composes.",
|
|
87
87
|
"type": "object",
|
|
88
88
|
"required": [
|
|
89
89
|
"$schema",
|
|
90
90
|
"$id",
|
|
91
|
+
"protocolVersion",
|
|
91
92
|
"catalogId",
|
|
92
93
|
"title",
|
|
93
94
|
"description",
|
|
@@ -95,6 +96,9 @@ export const catalogMetaSchemas = {
|
|
|
95
96
|
"$defs"
|
|
96
97
|
],
|
|
97
98
|
"properties": {
|
|
99
|
+
"protocolVersion": {
|
|
100
|
+
"const": "1.0"
|
|
101
|
+
},
|
|
98
102
|
"catalogId": {
|
|
99
103
|
"type": "string",
|
|
100
104
|
"format": "uri"
|
|
@@ -111,17 +115,23 @@ export const catalogMetaSchemas = {
|
|
|
111
115
|
"minProperties": 1,
|
|
112
116
|
"additionalProperties": {
|
|
113
117
|
"type": "object",
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
"not": {
|
|
119
|
+
"required": [
|
|
120
|
+
"allOf"
|
|
121
|
+
],
|
|
122
|
+
"properties": {
|
|
123
|
+
"allOf": {
|
|
124
|
+
"contains": {
|
|
125
|
+
"required": [
|
|
126
|
+
"$ref"
|
|
127
|
+
],
|
|
128
|
+
"properties": {
|
|
129
|
+
"$ref": {
|
|
130
|
+
"pattern": "ComponentCommon$"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
}
|
|
@@ -130,11 +140,20 @@ export const catalogMetaSchemas = {
|
|
|
130
140
|
"type": "object",
|
|
131
141
|
"required": [
|
|
132
142
|
"anyComponent",
|
|
133
|
-
"
|
|
143
|
+
"anyFunction"
|
|
134
144
|
],
|
|
135
145
|
"not": {
|
|
136
|
-
"
|
|
137
|
-
|
|
146
|
+
"anyOf": [
|
|
147
|
+
{
|
|
148
|
+
"required": [
|
|
149
|
+
"theme"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"required": [
|
|
154
|
+
"surfaceProperties"
|
|
155
|
+
]
|
|
156
|
+
}
|
|
138
157
|
]
|
|
139
158
|
},
|
|
140
159
|
"properties": {
|
|
@@ -143,12 +162,6 @@ export const catalogMetaSchemas = {
|
|
|
143
162
|
"required": [
|
|
144
163
|
"oneOf"
|
|
145
164
|
]
|
|
146
|
-
},
|
|
147
|
-
"surfaceProperties": {
|
|
148
|
-
"type": "object",
|
|
149
|
-
"required": [
|
|
150
|
-
"properties"
|
|
151
|
-
]
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
167
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
package/src/byte-neutral.test.ts
CHANGED
|
@@ -52,15 +52,18 @@ const CATALOGS: Record<string, string> = {
|
|
|
52
52
|
// only credible if authoring a profile as a file changes nothing.
|
|
53
53
|
"shadcn/ts/0.9.1": "7c1b72dfd83dde14",
|
|
54
54
|
"shadcn/json/0.9.1": "7c1b72dfd83dde14",
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// INTENTIONAL MOVE (P1a, A2UI 1.0 catalog conformance): the 1.0 catalog now follows the pinned upstream 1.0
|
|
56
|
+
// specification (src/transform/emit-v1_0.ts): protocolVersion, common_types references, flat components,
|
|
57
|
+
// anyFunction, no surfaceProperties. Every 0.9.1 pin above and below is unchanged.
|
|
58
|
+
"shadcn/ts/1.0": "4512c002e8e5d25b",
|
|
59
|
+
"shadcn/json/1.0": "4512c002e8e5d25b",
|
|
57
60
|
// INTENTIONAL MOVE (scaffold rewrite): the scaffold now emits the v2
|
|
58
61
|
// primitive language and derives children/text routes from the contract's
|
|
59
62
|
// worked examples, so scaffolded catalogs carry the slots the old scaffold
|
|
60
63
|
// omitted. The old digests described a scaffold that was surface-unusable
|
|
61
64
|
// for props-based contracts; these describe one that emits.
|
|
62
65
|
"astryx-scaffold/0.9.1": "ffb8fd24891bedfc",
|
|
63
|
-
"astryx-scaffold/1.0": "
|
|
66
|
+
"astryx-scaffold/1.0": "0e38fc1fed8f31ed", // INTENTIONAL MOVE (P1a), as for shadcn/1.0 above
|
|
64
67
|
};
|
|
65
68
|
|
|
66
69
|
const SURFACES: Record<string, string> = {
|
package/src/cli.ts
CHANGED
|
@@ -107,9 +107,12 @@ function parseArgs(argv: string[]): Args {
|
|
|
107
107
|
in: input!,
|
|
108
108
|
version: (version ?? "0.9.1") as A2uiVersion,
|
|
109
109
|
out: m.get("out") ?? "out",
|
|
110
|
-
// The sample-surface default is a repo-relative fixture
|
|
110
|
+
// The sample-surface default is a repo-relative fixture, one per A2UI
|
|
111
|
+
// version (the 1.0 sample is in 1.0 message form); external callers
|
|
111
112
|
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
112
|
-
surface:
|
|
113
|
+
surface:
|
|
114
|
+
m.get("surface") ??
|
|
115
|
+
(profile ? undefined : version === "1.0" ? "surface/settings-card.v1_0.surface.json" : "surface/settings-card.surface.json"),
|
|
113
116
|
profile,
|
|
114
117
|
emitSurface: m.get("emit-surface"),
|
|
115
118
|
strictCoverage: m.get("strict-coverage") === "true",
|
package/src/functions.test.ts
CHANGED
|
@@ -111,8 +111,55 @@ const okSurface = (call: object) => ({
|
|
|
111
111
|
],
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
+
/** The same instance in the A2UI 1.0 spelling: the trait is `@checks`, a call is `{"@call": …}`. */
|
|
115
|
+
const okSurfaceV1_0 = (call: object) => ({
|
|
116
|
+
messages: [
|
|
117
|
+
{
|
|
118
|
+
updateComponents: {
|
|
119
|
+
surfaceId: "s",
|
|
120
|
+
components: [{ id: "root", component: "TextField", label: "Email", "@checks": [{ condition: call, message: "Required." }] }],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
114
126
|
describe("declared functions reach the catalog and constrain every call", () => {
|
|
115
|
-
|
|
127
|
+
it("the 1.0 catalog declares each function as a call-validation schema, and anyFunction lists them (a2ui 1.0)", () => {
|
|
128
|
+
const out = transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: "1.0" });
|
|
129
|
+
const catalog = out.catalog as unknown as {
|
|
130
|
+
functions?: Record<string, { returnType: string; properties: Record<string, { const?: string }>; required: string[] }>;
|
|
131
|
+
$defs: Record<string, { oneOf?: Array<{ $ref: string }> }>;
|
|
132
|
+
};
|
|
133
|
+
expect(Object.keys(catalog.functions ?? {})).toEqual(["checkRequired", "matchesRegexp"]);
|
|
134
|
+
expect(catalog.functions!.checkRequired.returnType).toBe("boolean");
|
|
135
|
+
expect(catalog.functions!.checkRequired.properties["@call"]).toEqual({ const: "checkRequired" });
|
|
136
|
+
expect(catalog.functions!.matchesRegexp.required).toEqual(["@call", "args"]);
|
|
137
|
+
expect(catalog.$defs.anyFunction?.oneOf).toEqual([{ $ref: "#/functions/checkRequired" }, { $ref: "#/functions/matchesRegexp" }]);
|
|
138
|
+
// 1.0 references the standard FunctionCall in common_types.json; the catalog carries no copy of it.
|
|
139
|
+
expect(Object.keys(catalog.$defs)).toEqual(["anyComponent", "anyFunction"]);
|
|
140
|
+
expect(out.validation.gates.find((g) => g.name === "schema-compile + no-external-ref")?.pass).toBe(true);
|
|
141
|
+
expect(out.validation.gates.find((g) => g.name === "catalog-shape")?.pass).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("1.0: a declared call passes, an undeclared one and a missing required argument are refused", () => {
|
|
145
|
+
const gate = (call: object) =>
|
|
146
|
+
transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: "1.0", surface: okSurfaceV1_0(call) }).validation.gates.find((g) => g.name === "instance")?.pass;
|
|
147
|
+
expect(gate({ "@call": "checkRequired" })).toBe(true);
|
|
148
|
+
expect(gate({ "@call": "matchesRegexp", args: { pattern: "^.+@.+$" } })).toBe(true);
|
|
149
|
+
expect(gate({ "@call": "checkVibes" })).toBe(false);
|
|
150
|
+
expect(gate({ "@call": "matchesRegexp" })).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("1.0 closes the 0.9.1 hole: with no functions declared, anyFunction admits no call at all", () => {
|
|
154
|
+
const bare = profileDoc();
|
|
155
|
+
delete bare.functions;
|
|
156
|
+
const out = transformFromJson(doc, { profile: loadProfile(bare), a2uiVersion: "1.0", surface: okSurfaceV1_0({ "@call": "checkVibes" }) });
|
|
157
|
+
expect((out.catalog as { $defs: Record<string, unknown> }).$defs.anyFunction).toEqual({ not: {} });
|
|
158
|
+
expect(out.validation.gates.find((g) => g.name === "catalog-shape")?.pass).toBe(true);
|
|
159
|
+
expect(out.validation.gates.find((g) => g.name === "instance")?.pass).toBe(false);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
for (const version of ["0.9.1"] as const) {
|
|
116
163
|
it(`the catalog carries the functions section and the call constraint (a2ui ${version})`, () => {
|
|
117
164
|
const out = transformFromJson(doc, { profile: loadProfile(profileDoc()), a2uiVersion: version });
|
|
118
165
|
const catalog = out.catalog as unknown as {
|
package/src/index.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 {
|
|
17
17
|
emitSurface,
|
|
18
18
|
slug,
|
package/src/profile-v2.test.ts
CHANGED
|
@@ -62,7 +62,7 @@ const VERSIONS: A2uiVersion[] = ["0.9.1", "1.0"];
|
|
|
62
62
|
/** The v1 pins this file must reproduce — same values as byte-neutral.test.ts. */
|
|
63
63
|
const V1_CATALOG_DIGESTS: Record<string, string> = {
|
|
64
64
|
"0.9.1": "7c1b72dfd83dde14",
|
|
65
|
-
"1.0": "
|
|
65
|
+
"1.0": "4512c002e8e5d25b", // moved with byte-neutral.test.ts (P1a, A2UI 1.0 catalog conformance)
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
describe("the v2 re-spelling emits byte-identically to the v1 profile", () => {
|
|
@@ -0,0 +1,215 @@
|
|
|
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, Json } from "../types.js";
|
|
26
|
+
import type { MappingResult } from "./mapping.js";
|
|
27
|
+
import type { Profile } from "./profiles.js";
|
|
28
|
+
|
|
29
|
+
/** The standard types a 1.0 catalog may reference in common_types.json (rule 3), in the specification's order. */
|
|
30
|
+
export const COMMON_TYPES_V1_0 = [
|
|
31
|
+
"ComponentId",
|
|
32
|
+
"Child",
|
|
33
|
+
"ChildList",
|
|
34
|
+
"DynamicString",
|
|
35
|
+
"DynamicNumber",
|
|
36
|
+
"DynamicBoolean",
|
|
37
|
+
"DynamicStringList",
|
|
38
|
+
"DynamicValue",
|
|
39
|
+
"AccessibilityAttributes",
|
|
40
|
+
"CheckRule",
|
|
41
|
+
"Checkable",
|
|
42
|
+
"Action",
|
|
43
|
+
"DataBinding",
|
|
44
|
+
"FunctionCall",
|
|
45
|
+
] as const;
|
|
46
|
+
const COMMON = new Set<string>(COMMON_TYPES_V1_0);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Design-system properties named after an ARIA attribute, and the `@accessibility` attribute that carries the same
|
|
50
|
+
* meaning on a 1.0 component instance (common_types.json AccessibilityAttributes: label, description, live, hidden).
|
|
51
|
+
*/
|
|
52
|
+
export const ARIA_TO_ACCESSIBILITY: Readonly<Record<string, "label" | "description" | "live" | "hidden">> = {
|
|
53
|
+
"aria-label": "label",
|
|
54
|
+
"aria-description": "description",
|
|
55
|
+
"aria-live": "live",
|
|
56
|
+
"aria-hidden": "hidden",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** The catalog-level extension that carries the design tokens (a product-prefixed UAX #31 name). */
|
|
60
|
+
export const TOKEN_EXTENSION = "dspack_tokens";
|
|
61
|
+
/**
|
|
62
|
+
* The component-level extension that records which design-system properties the envelope now carries:
|
|
63
|
+
* `{ properties: { "<aria-name>": { carriedBy: "@accessibility.<attribute>", schema: <the property's own schema> } } }`.
|
|
64
|
+
*/
|
|
65
|
+
export const ACCESSIBILITY_EXTENSION = "dspack_accessibility";
|
|
66
|
+
|
|
67
|
+
/** UAX #31 (`^[\p{XID_Start}_][\p{XID_Continue}]*$`), the rule for every catalog entity name in 1.0. */
|
|
68
|
+
const IDENTIFIER = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
|
|
69
|
+
|
|
70
|
+
class V1Refusal extends Error {}
|
|
71
|
+
|
|
72
|
+
/** Re-target a schema's standard-type references at common_types.json; refuse any other #/$defs reference. */
|
|
73
|
+
function retarget(node: Json, at: string): Json {
|
|
74
|
+
if (Array.isArray(node)) return node.map((n, i) => retarget(n as Json, `${at}/${i}`)) as unknown as Json;
|
|
75
|
+
if (!node || typeof node !== "object") return node;
|
|
76
|
+
const out: Json = {};
|
|
77
|
+
for (const [k, v] of Object.entries(node)) {
|
|
78
|
+
if (k === "$ref" && typeof v === "string" && v.startsWith("#/$defs/")) {
|
|
79
|
+
const type = v.slice("#/$defs/".length);
|
|
80
|
+
if (!COMMON.has(type)) {
|
|
81
|
+
throw new V1Refusal(`${at}: '${v}' has no A2UI 1.0 counterpart in common_types.json (allowed: ${COMMON_TYPES_V1_0.join(", ")})`);
|
|
82
|
+
}
|
|
83
|
+
out[k] = `common_types.json#/$defs/${type}`;
|
|
84
|
+
} else {
|
|
85
|
+
out[k] = retarget(v as Json, `${at}/${k}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function component(name: string, emitted: Json): Json {
|
|
92
|
+
const parts = (emitted.allOf ?? []) as Json[];
|
|
93
|
+
const own = parts.find((p) => !("$ref" in p));
|
|
94
|
+
if (!own) throw new V1Refusal(`components.${name}: no component schema to emit`);
|
|
95
|
+
const traits = parts
|
|
96
|
+
.filter((p) => "$ref" in p)
|
|
97
|
+
.map((p) => String(p.$ref).slice("#/$defs/".length))
|
|
98
|
+
.filter((t) => t !== "ComponentCommon"); // composed by the envelope (rule 5)
|
|
99
|
+
|
|
100
|
+
const schema = retarget(own, `components.${name}`);
|
|
101
|
+
const properties = (schema.properties ?? {}) as Record<string, Json>;
|
|
102
|
+
const required = ((schema.required ?? []) as string[]).slice();
|
|
103
|
+
const carried: Record<string, Json> = {};
|
|
104
|
+
for (const prop of Object.keys(properties)) {
|
|
105
|
+
const attribute = ARIA_TO_ACCESSIBILITY[prop];
|
|
106
|
+
if (attribute) {
|
|
107
|
+
if (required.includes(prop)) {
|
|
108
|
+
throw new V1Refusal(`components.${name}.${prop}: a required ARIA property cannot move to the optional @accessibility.${attribute}`);
|
|
109
|
+
}
|
|
110
|
+
// The design system's own guidance for the property (its description, a default such as "Loading", its source)
|
|
111
|
+
// stays in the catalog beside the mapping, so an agent reading the 1.0 catalog still learns when and how to set it.
|
|
112
|
+
carried[prop] = { carriedBy: `@accessibility.${attribute}`, schema: properties[prop]! };
|
|
113
|
+
delete properties[prop];
|
|
114
|
+
} else if (!IDENTIFIER.test(prop)) {
|
|
115
|
+
throw new V1Refusal(`components.${name}.${prop}: not a UAX #31 identifier, and no 1.0 mapping is defined for it`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const flat: Json = { ...schema, properties };
|
|
119
|
+
if (Object.keys(carried).length > 0) {
|
|
120
|
+
flat.metadata = { extensions: { [ACCESSIBILITY_EXTENSION]: { properties: carried } } };
|
|
121
|
+
}
|
|
122
|
+
if (traits.length === 0) return flat;
|
|
123
|
+
// A trait keeps upstream's basic-catalog form: { type, allOf: [trait, component] }.
|
|
124
|
+
const { metadata, ...body } = flat;
|
|
125
|
+
return {
|
|
126
|
+
type: "object",
|
|
127
|
+
allOf: [...traits.map((t) => ({ $ref: retarget({ $ref: `#/$defs/${t}` } as Json, `components.${name}`).$ref })), body],
|
|
128
|
+
...(metadata ? { metadata } : {}),
|
|
129
|
+
} as Json;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function functions(profile: Profile): { section?: Record<string, Json>; anyFunction: Json } {
|
|
133
|
+
const declared = profile.functions;
|
|
134
|
+
const names = declared ? Object.keys(declared).sort() : [];
|
|
135
|
+
if (names.length === 0) return { anyFunction: { not: {} } };
|
|
136
|
+
const section: Record<string, Json> = {};
|
|
137
|
+
for (const name of names) {
|
|
138
|
+
if (!IDENTIFIER.test(name)) throw new V1Refusal(`functions.${name}: not a UAX #31 identifier`);
|
|
139
|
+
const fn = declared![name];
|
|
140
|
+
const args = fn.args ? retarget(fn.args as Json, `functions.${name}.args`) : undefined;
|
|
141
|
+
const requiresArgs = Array.isArray((fn.args as { required?: unknown } | undefined)?.required) && ((fn.args as { required: unknown[] }).required.length > 0);
|
|
142
|
+
section[name] = {
|
|
143
|
+
type: "object",
|
|
144
|
+
description: fn.description,
|
|
145
|
+
returnType: fn.returns,
|
|
146
|
+
properties: { "@call": { const: name }, ...(args ? { args } : {}) },
|
|
147
|
+
required: requiresArgs ? ["@call", "args"] : ["@call"],
|
|
148
|
+
// No unevaluatedProperties here: the FunctionCall envelope (common_types.json) composes FunctionCommon with this
|
|
149
|
+
// schema and closes the object itself, as upstream's basic catalog relies on.
|
|
150
|
+
} as Json;
|
|
151
|
+
}
|
|
152
|
+
return { section, anyFunction: { oneOf: names.map((n) => ({ $ref: `#/functions/${n}` })) } as Json };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** The 1.0 catalog. Throws, with the reason, when the mapping holds something 1.0 cannot represent. */
|
|
156
|
+
export function emitCatalogV1_0(result: MappingResult, profile: Profile, id: string): A2uiCatalog {
|
|
157
|
+
try {
|
|
158
|
+
const components: Record<string, Json> = {};
|
|
159
|
+
for (const name of result.componentOrder) {
|
|
160
|
+
if (!IDENTIFIER.test(name)) throw new V1Refusal(`components.${name}: not a UAX #31 identifier`);
|
|
161
|
+
if (name === "Surface") throw new V1Refusal("components.Surface: the name is reserved by the protocol");
|
|
162
|
+
components[name] = component(name, result.components[name] as Json);
|
|
163
|
+
}
|
|
164
|
+
const fns = functions(profile);
|
|
165
|
+
const tokens: Json = {
|
|
166
|
+
...(result.primaryColorHex ? { primaryColor: { value: result.primaryColorHex, source: result.primaryColorSource } } : {}),
|
|
167
|
+
palette: (result.tokenExtension as Json)["x-dspack-tokens"] ?? {},
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
171
|
+
$id: id,
|
|
172
|
+
protocolVersion: "1.0",
|
|
173
|
+
title: profile.catalogTitle,
|
|
174
|
+
description: profile.catalogDescription,
|
|
175
|
+
catalogId: id,
|
|
176
|
+
...(profile.instructions !== undefined ? { instructions: profile.instructions } : {}),
|
|
177
|
+
metadata: { extensions: { [TOKEN_EXTENSION]: tokens } },
|
|
178
|
+
components,
|
|
179
|
+
...(fns.section ? { functions: fns.section } : {}),
|
|
180
|
+
$defs: {
|
|
181
|
+
anyComponent: {
|
|
182
|
+
oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
|
|
183
|
+
discriminator: { propertyName: "component" },
|
|
184
|
+
},
|
|
185
|
+
anyFunction: fns.anyFunction,
|
|
186
|
+
},
|
|
187
|
+
} as unknown as A2uiCatalog;
|
|
188
|
+
} catch (e) {
|
|
189
|
+
if (e instanceof V1Refusal) throw new Error(`A2UI 1.0 catalog refused: ${e.message}`);
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The mapping's fidelity entries as they read for the 1.0 catalog: where tokens and ARIA properties actually go. */
|
|
195
|
+
export function fidelityV1_0(result: MappingResult): FidelityEntry[] {
|
|
196
|
+
const out: FidelityEntry[] = [];
|
|
197
|
+
for (const f of result.fidelity) {
|
|
198
|
+
if (/theme|surfaceProperties/.test(f.target)) {
|
|
199
|
+
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)") });
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const aria = /^components\.([^.]+)\.properties\.(.+)$/.exec(f.target);
|
|
203
|
+
if (aria && ARIA_TO_ACCESSIBILITY[aria[2]!]) {
|
|
204
|
+
out.push({
|
|
205
|
+
...f,
|
|
206
|
+
target: `components.${aria[1]} instance @accessibility.${ARIA_TO_ACCESSIBILITY[aria[2]!]}`,
|
|
207
|
+
class: "synthesis-defaults",
|
|
208
|
+
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}.`,
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
out.push(f);
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
package/src/transform/emit.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
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, Json } from "../types.js";
|
|
13
10
|
import { INLINED_DEFS } from "./inline-defs.js";
|
|
14
11
|
import type { MappingResult } from "./mapping.js";
|
|
15
12
|
import type { Profile } from "./profiles.js";
|
|
13
|
+
import { emitCatalogV1_0 } from "./emit-v1_0.js";
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* The catalog's function surface, from the profile's declared FunctionPlans:
|
|
@@ -68,6 +66,8 @@ export function emitCatalog(
|
|
|
68
66
|
): A2uiCatalog {
|
|
69
67
|
const seg = VER_SEGMENT[version];
|
|
70
68
|
const id = `${profile.catalogIdBase}/${seg}/catalog.json`;
|
|
69
|
+
// A2UI 1.0 has its own catalog rules (emit-v1_0.ts); everything below is the 0.9.1 catalog, unchanged.
|
|
70
|
+
if (version === "1.0") return emitCatalogV1_0(result, profile, id);
|
|
71
71
|
|
|
72
72
|
const anyComponent: Json = {
|
|
73
73
|
oneOf: result.componentOrder.map((n) => ({ $ref: `#/components/${n}` })),
|
|
@@ -100,11 +100,7 @@ export function emitCatalog(
|
|
|
100
100
|
fc.oneOf = [{ $ref: "#/$defs/anyFunction" } as Json];
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
$defs.theme = themeDef(result);
|
|
105
|
-
} else {
|
|
106
|
-
$defs.surfaceProperties = surfacePropertiesDef(result);
|
|
107
|
-
}
|
|
103
|
+
$defs.theme = themeDef(result);
|
|
108
104
|
|
|
109
105
|
const catalog: A2uiCatalog = {
|
|
110
106
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
@@ -117,21 +113,6 @@ export function emitCatalog(
|
|
|
117
113
|
$defs,
|
|
118
114
|
};
|
|
119
115
|
|
|
120
|
-
if (version === "1.0") {
|
|
121
|
-
// Insert `instructions` right after description, mirroring the v1.0 fixture order.
|
|
122
|
-
return {
|
|
123
|
-
$schema: catalog.$schema,
|
|
124
|
-
$id: catalog.$id,
|
|
125
|
-
title: catalog.title,
|
|
126
|
-
description: catalog.description,
|
|
127
|
-
instructions: profile.instructions,
|
|
128
|
-
catalogId: catalog.catalogId,
|
|
129
|
-
components: catalog.components,
|
|
130
|
-
...(catalog.functions ? { functions: catalog.functions } : {}),
|
|
131
|
-
$defs: catalog.$defs,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
116
|
return catalog;
|
|
136
117
|
}
|
|
137
118
|
|
|
@@ -166,28 +147,3 @@ function themeDef(result: MappingResult): Json {
|
|
|
166
147
|
...result.tokenExtension,
|
|
167
148
|
};
|
|
168
149
|
}
|
|
169
|
-
|
|
170
|
-
/** v1.0 — shape from fixtures/a2ui/basic-catalog.v1_0.json#/$defs/surfaceProperties. */
|
|
171
|
-
function surfacePropertiesDef(result: MappingResult): Json {
|
|
172
|
-
const def: Json = {
|
|
173
|
-
type: "object",
|
|
174
|
-
properties: {
|
|
175
|
-
iconUrl: {
|
|
176
|
-
type: "string",
|
|
177
|
-
format: "uri",
|
|
178
|
-
description: "A URL for an image that identifies the agent or tool associated with the surface.",
|
|
179
|
-
},
|
|
180
|
-
agentDisplayName: {
|
|
181
|
-
type: "string",
|
|
182
|
-
description: "Text displayed next to the surface to identify the agent or tool that created it.",
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
additionalProperties: true,
|
|
186
|
-
...result.tokenExtension,
|
|
187
|
-
};
|
|
188
|
-
// v1.0 basic surfaceProperties has no primaryColor field; carry it as an extension.
|
|
189
|
-
if (result.primaryColorHex) {
|
|
190
|
-
def["x-dspack-primaryColor"] = { value: result.primaryColorHex, source: result.primaryColorSource };
|
|
191
|
-
}
|
|
192
|
-
return def;
|
|
193
|
-
}
|
package/src/transform/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { shadcnProfile, type Profile } from "./profiles.js";
|
|
|
6
6
|
import { mapDspack, type MappingResult } from "./mapping.js";
|
|
7
7
|
import { validateProfileAgainstContract } from "./validate-v2.js";
|
|
8
8
|
import { emitCatalog } from "./emit.js";
|
|
9
|
+
import { fidelityV1_0 } from "./emit-v1_0.js";
|
|
9
10
|
import { buildReport, type ReportBundle } from "./report.js";
|
|
10
11
|
import { validateCatalog, type ValidationReport } from "../validate/ajv.js";
|
|
11
12
|
|
|
@@ -35,7 +36,8 @@ export function transform(
|
|
|
35
36
|
const mapping = mapDspack(doc, profile);
|
|
36
37
|
const catalog = emitCatalog(mapping, version, profile);
|
|
37
38
|
const validation = validateCatalog(catalog, version, surface);
|
|
38
|
-
|
|
39
|
+
// The 1.0 report says where tokens and ARIA properties go in a 1.0 catalog; the 0.9.1 report is unchanged.
|
|
40
|
+
const report = buildReport(version, version === "1.0" ? { ...mapping, fidelity: fidelityV1_0(mapping) } : mapping, validation);
|
|
39
41
|
|
|
40
42
|
return { catalog, mapping, validation, report };
|
|
41
43
|
}
|
package/src/transform.test.ts
CHANGED
|
@@ -70,10 +70,25 @@ describe("profile mapping", () => {
|
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The same hand-authored surface with its bindings in the A2UI 1.0 spelling (`{"@path": …}`; a plain `{path}` is a
|
|
75
|
+
* literal object in 1.0). Only the instances' data bindings differ between the versions in this surface. Emitting 1.0
|
|
76
|
+
* messages is P1b; this fixture only lets the 1.0 catalog be checked against genuine 1.0 instances.
|
|
77
|
+
*/
|
|
78
|
+
function asV1_0Instances(node: unknown): unknown {
|
|
79
|
+
if (Array.isArray(node)) return node.map(asV1_0Instances);
|
|
80
|
+
if (node && typeof node === "object") {
|
|
81
|
+
const o = node as Record<string, unknown>;
|
|
82
|
+
if (Object.keys(o).length === 1 && typeof o.path === "string") return { "@path": o.path };
|
|
83
|
+
return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, asV1_0Instances(v)]));
|
|
84
|
+
}
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
|
|
73
88
|
describe("validation gates", () => {
|
|
74
89
|
it("passes all three gates for both emitted versions", () => {
|
|
75
90
|
for (const v of ["0.9.1", "1.0"] as const) {
|
|
76
|
-
const { validation } = transform(doc, v, surface);
|
|
91
|
+
const { validation } = transform(doc, v, v === "1.0" ? asV1_0Instances(surface) : surface);
|
|
77
92
|
expect(validation.pass, `v${v} should pass`).toBe(true);
|
|
78
93
|
expect(validation.gates.map((g) => g.name)).toEqual([
|
|
79
94
|
"schema-compile + no-external-ref",
|
|
@@ -83,6 +98,23 @@ describe("validation gates", () => {
|
|
|
83
98
|
}
|
|
84
99
|
});
|
|
85
100
|
|
|
101
|
+
it("catalog conformance is not message conformance: a 0.9-spelled binding is not a valid 1.0 instance", () => {
|
|
102
|
+
const { validation } = transform(doc, "1.0", surface);
|
|
103
|
+
const instance = validation.gates.find((g) => g.name === "instance")!;
|
|
104
|
+
expect(validation.gates.find((g) => g.name === "catalog-shape")!.pass).toBe(true);
|
|
105
|
+
expect(instance.pass).toBe(false);
|
|
106
|
+
expect(instance.errors?.join("\n")).toMatch(/required property '@path'/);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("the 1.0 instance gate closes the component the way the envelope does: an unknown property is refused", () => {
|
|
110
|
+
const v1 = asV1_0Instances(surface) as { messages: Array<{ updateComponents?: { components: Array<Record<string, unknown>> } }> };
|
|
111
|
+
const update = v1.messages.find((m) => m.updateComponents)!;
|
|
112
|
+
update.updateComponents!.components[0]!.notAProperty = true;
|
|
113
|
+
const instance = transform(doc, "1.0", v1).validation.gates.find((g) => g.name === "instance")!;
|
|
114
|
+
expect(instance.pass).toBe(false);
|
|
115
|
+
expect(instance.errors?.join("\n")).toMatch(/unevaluated properties \('notAProperty'\)|notAProperty/);
|
|
116
|
+
});
|
|
117
|
+
|
|
86
118
|
it("the instance gate is not vacuous: rejects an invalid Button instance", () => {
|
|
87
119
|
const { catalog } = transform(doc, "0.9.1", surface);
|
|
88
120
|
const bad = {
|
package/src/types.ts
CHANGED
|
@@ -97,7 +97,11 @@ export interface A2uiCatalog extends Json {
|
|
|
97
97
|
title: string;
|
|
98
98
|
description: string;
|
|
99
99
|
catalogId: string;
|
|
100
|
+
/** A2UI 1.0 only: the specification version the catalog targets. Never written for 0.9.1. */
|
|
101
|
+
protocolVersion?: string;
|
|
100
102
|
instructions?: string;
|
|
103
|
+
/** A2UI 1.0 only: catalog-level metadata (`metadata.extensions`). Never written for 0.9.1. */
|
|
104
|
+
metadata?: Json;
|
|
101
105
|
components: Record<string, Json>;
|
|
102
106
|
functions?: Record<string, Json>;
|
|
103
107
|
$defs: Record<string, Json>;
|