@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.
@@ -0,0 +1,267 @@
1
+ /**
2
+ * The A2UI 1.0 catalog, discrepancy by discrepancy (dspack-studio docs/repositioning/protocol-check/p0/README.md,
3
+ * "1.0 discrepancies to close"), against the pinned upstream specification (fixtures/a2ui/PIN.md). The 0.9.1 catalog
4
+ * is pinned byte-for-byte in byte-neutral.test.ts; nothing here may move it.
5
+ */
6
+ import { readFileSync } from "node:fs";
7
+ import { describe, expect, it } from "vitest";
8
+ import { transformFromJson } from "./transform/index.js";
9
+ import { emitCatalogV1_0, fidelityV1_0, COMMON_TYPES_V1_0, ARIA_TO_ACCESSIBILITY } from "./transform/emit-v1_0.js";
10
+ import { scaffoldProfile } from "./transform/scaffold.js";
11
+ import { loadProfile } from "./transform/profile-load.js";
12
+ import { validateCatalog, catalogCompanionSchemas } from "./validate/ajv.js";
13
+ import Ajv2020 from "ajv/dist/2020.js";
14
+ import addFormats from "ajv-formats";
15
+ import { catalogDefinitionV1_0, commonTypesV1_0 } from "./validate/meta/a2ui-v1_0.js";
16
+ import type { A2uiCatalog, DspackDoc, Json } from "./types.js";
17
+ import type { MappingResult } from "./transform/mapping.js";
18
+ import { shadcnProfile } from "./transform/profiles.js";
19
+
20
+ const read = (rel: string) => JSON.parse(readFileSync(new URL(rel, import.meta.url), "utf8"));
21
+ const shadcnDoc = read("../input/shadcn-ui.dspack.json") as DspackDoc;
22
+ const astryxDoc = read("../input/astryx.dspack.json") as DspackDoc;
23
+ const IDENTIFIER = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
24
+ const ALLOWED_TOP_LEVEL = ["$schema", "$id", "protocolVersion", "title", "description", "catalogId", "instructions", "metadata", "components", "functions", "$defs"];
25
+
26
+ const catalogs: Record<string, () => A2uiCatalog> = {
27
+ "shadcn/ui": () => transformFromJson(shadcnDoc, { a2uiVersion: "1.0" }).catalog,
28
+ "Astryx (scaffolded)": () =>
29
+ transformFromJson(astryxDoc, {
30
+ a2uiVersion: "1.0",
31
+ profile: loadProfile(scaffoldProfile(astryxDoc, { catalogIdBase: "https://example.test/catalogs/astryx-scaffold" }).profile),
32
+ }).catalog,
33
+ };
34
+
35
+ function refs(node: unknown, acc: string[] = []): string[] {
36
+ if (Array.isArray(node)) node.forEach((n) => refs(n, acc));
37
+ else if (node && typeof node === "object") {
38
+ for (const [k, v] of Object.entries(node)) {
39
+ if (k === "$ref" && typeof v === "string") acc.push(v);
40
+ else refs(v, acc);
41
+ }
42
+ }
43
+ return acc;
44
+ }
45
+
46
+ function propertyNames(component: Json): string[] {
47
+ const own = (component.properties ?? {}) as Record<string, unknown>;
48
+ const nested = ((component.allOf ?? []) as Json[]).flatMap((p) => Object.keys((p.properties ?? {}) as object));
49
+ return [...Object.keys(own), ...nested];
50
+ }
51
+
52
+ for (const [name, build] of Object.entries(catalogs)) {
53
+ describe(`A2UI 1.0 catalog: ${name}`, () => {
54
+ const catalog = build();
55
+
56
+ it("declares protocolVersion 1.0, and uses only the root keys the specification allows", () => {
57
+ expect(catalog.protocolVersion).toBe("1.0");
58
+ for (const key of Object.keys(catalog)) expect(ALLOWED_TOP_LEVEL).toContain(key);
59
+ });
60
+
61
+ it("$defs holds anyComponent and anyFunction only; with no functions, anyFunction admits no call", () => {
62
+ expect(Object.keys(catalog.$defs).sort()).toEqual(["anyComponent", "anyFunction"]);
63
+ expect(catalog.functions).toBeUndefined();
64
+ expect(catalog.$defs.anyFunction).toEqual({ not: {} });
65
+ expect(catalog.$defs.surfaceProperties).toBeUndefined();
66
+ expect(catalog.$defs.theme).toBeUndefined();
67
+ });
68
+
69
+ it("references standard types in common_types.json only, and only the listed ones", () => {
70
+ for (const ref of refs(catalog.components)) {
71
+ if (ref.startsWith("#/")) continue;
72
+ const m = /^common_types\.json#\/\$defs\/(.+)$/.exec(ref);
73
+ expect(m, ref).not.toBeNull();
74
+ expect(COMMON_TYPES_V1_0 as readonly string[]).toContain(m![1]);
75
+ }
76
+ expect(refs(catalog).some((r) => r.includes("ComponentCommon"))).toBe(false);
77
+ });
78
+
79
+ it("components are flat, closed by the envelope rather than by themselves", () => {
80
+ for (const [cname, c] of Object.entries(catalog.components)) {
81
+ expect(IDENTIFIER.test(cname), cname).toBe(true);
82
+ expect(c.unevaluatedProperties, cname).toBeUndefined();
83
+ for (const part of (c.allOf ?? []) as Json[]) if ("$ref" in part) expect(String(part.$ref), cname).toMatch(/common_types\.json#\/\$defs\/Checkable$/);
84
+ const discriminator = ((c.properties ?? ((c.allOf as Json[]).find((p) => !("$ref" in p)) as Json).properties) as Record<string, Json>).component;
85
+ expect(discriminator, cname).toEqual({ const: cname });
86
+ }
87
+ });
88
+
89
+ it("every property name is a UAX #31 identifier", () => {
90
+ for (const [cname, c] of Object.entries(catalog.components)) {
91
+ for (const prop of propertyNames(c)) expect(IDENTIFIER.test(prop), `${cname}.${prop}`).toBe(true);
92
+ }
93
+ });
94
+
95
+ it("design tokens are catalog metadata, under a product-prefixed extension", () => {
96
+ const ext = (catalog.metadata as { extensions: Record<string, Json> }).extensions;
97
+ expect(Object.keys(ext)).toEqual(["dspack_tokens"]);
98
+ expect(ext.dspack_tokens.palette).toBeTypeOf("object");
99
+ });
100
+
101
+ it("passes gates A1 and A2, the second being the official catalog definition", () => {
102
+ const report = validateCatalog(catalog, "1.0");
103
+ for (const g of report.gates) expect(g.pass, `${g.name}: ${JSON.stringify(g.errors)}`).toBe(true);
104
+ });
105
+ });
106
+ }
107
+
108
+ describe("ARIA properties map onto the envelope's @accessibility", () => {
109
+ // dspack-emit's own shadcn/ui input declares no ARIA-named property; Composer's shadcn/ui v3 contract does (Spinner,
110
+ // Skeleton), and the conformance run over Composer's catalogs covers that real case. Here, a probe with the same
111
+ // shape goes through the same emitter and report.
112
+ const mapping = structuredClone(transformFromJson(shadcnDoc, { a2uiVersion: "0.9.1" }).mapping);
113
+ mapping.components.Spinner = {
114
+ type: "object",
115
+ allOf: [
116
+ { $ref: "#/$defs/ComponentCommon" },
117
+ {
118
+ type: "object",
119
+ properties: {
120
+ component: { const: "Spinner" },
121
+ className: { type: "string" },
122
+ "aria-label": { type: "string", default: "Loading" },
123
+ "aria-hidden": { type: "boolean" },
124
+ },
125
+ required: ["component"],
126
+ },
127
+ ],
128
+ unevaluatedProperties: false,
129
+ };
130
+ mapping.componentOrder = [...mapping.componentOrder, "Spinner"];
131
+ mapping.fidelity = [
132
+ ...mapping.fidelity,
133
+ { source: "components.spinner.props.aria-label", target: "components.Spinner.properties.aria-label", class: "maps-cleanly", note: "Property mapped onto the A2UI property." },
134
+ ];
135
+ const catalog = emitCatalogV1_0(mapping, shadcnProfile, "https://example.test/v1_0/catalog.json");
136
+ const spinner = (catalog.components as Record<string, Json>).Spinner;
137
+
138
+ it("the component no longer declares aria-* properties; the mapping is recorded on the component", () => {
139
+ expect(Object.keys(spinner.properties as object).sort()).toEqual(["className", "component"]);
140
+ expect(spinner.metadata).toEqual({
141
+ extensions: {
142
+ dspack_accessibility: {
143
+ properties: {
144
+ "aria-label": { carriedBy: "@accessibility.label", schema: { type: "string", default: "Loading" } },
145
+ "aria-hidden": { carriedBy: "@accessibility.hidden", schema: { type: "boolean" } },
146
+ },
147
+ },
148
+ },
149
+ });
150
+ expect(validateCatalog(catalog, "1.0").gates.every((g) => g.pass)).toBe(true);
151
+ });
152
+
153
+ it("an instance carries the accessible name in @accessibility, and the old property name is refused", () => {
154
+ const instance = (props: Record<string, unknown>) => ({ messages: [{ updateComponents: { components: [{ id: "spin", component: "Spinner", ...props }] } }] });
155
+ const gate = (props: Record<string, unknown>) => validateCatalog(catalog, "1.0", instance(props)).gates.find((g) => g.name === "instance")!.pass;
156
+ expect(gate({ "@accessibility": { label: "Loading results", hidden: false } })).toBe(true);
157
+ expect(gate({ "aria-label": "Loading results" })).toBe(false);
158
+ });
159
+
160
+ it("the mapping covers exactly the four AccessibilityAttributes of common_types.json", () => {
161
+ const attributes = Object.keys(((commonTypesV1_0.$defs as Record<string, Json>).AccessibilityAttributes.properties ?? {}) as object).sort();
162
+ expect([...new Set(Object.values(ARIA_TO_ACCESSIBILITY))].sort()).toEqual(attributes);
163
+ });
164
+
165
+ it("the 1.0 report says where each ARIA property goes, and nothing points at surfaceProperties", () => {
166
+ const entries = fidelityV1_0(mapping);
167
+ expect(entries.find((e) => e.source === "components.spinner.props.aria-label")?.target).toBe("components.Spinner instance @accessibility.label");
168
+ expect(entries.some((e) => /surfaceProperties|theme\./.test(e.target))).toBe(false);
169
+ });
170
+ });
171
+
172
+ describe("the 1.0 emitter refuses what 1.0 cannot represent", () => {
173
+ const base = () => transformFromJson(shadcnDoc, { a2uiVersion: "0.9.1" }).mapping;
174
+ const withComponent = (schema: Json): MappingResult => {
175
+ const m = structuredClone(base());
176
+ m.components.Probe = schema;
177
+ m.componentOrder = [...m.componentOrder, "Probe"];
178
+ return m;
179
+ };
180
+ const emit = (m: MappingResult) => () => emitCatalogV1_0(m, shadcnProfile, "https://example.test/v1_0/catalog.json");
181
+
182
+ it("a property name that is not an identifier and has no mapping", () => {
183
+ expect(emit(withComponent({ type: "object", allOf: [{ $ref: "#/$defs/ComponentCommon" }, { type: "object", properties: { component: { const: "Probe" }, "data-x": { type: "string" } } }] })))
184
+ .toThrow(/Probe\.data-x: not a UAX #31 identifier/);
185
+ });
186
+
187
+ it("a required ARIA property, which the optional @accessibility cannot carry", () => {
188
+ expect(emit(withComponent({ type: "object", allOf: [{ type: "object", properties: { component: { const: "Probe" }, "aria-label": { type: "string" } }, required: ["component", "aria-label"] }] })))
189
+ .toThrow(/required ARIA property/);
190
+ });
191
+
192
+ it("a reference to a definition common_types.json does not offer", () => {
193
+ expect(emit(withComponent({ type: "object", allOf: [{ type: "object", properties: { component: { const: "Probe" }, x: { $ref: "#/$defs/Theme" } } }] })))
194
+ .toThrow(/#\/\$defs\/Theme' has no A2UI 1.0 counterpart/);
195
+ });
196
+
197
+ it("the reserved component name Surface", () => {
198
+ const m = structuredClone(base());
199
+ m.components.Surface = m.components[m.componentOrder[0]!]!;
200
+ m.componentOrder = [...m.componentOrder, "Surface"];
201
+ expect(emit(m)).toThrow(/reserved/);
202
+ });
203
+ });
204
+
205
+ describe("gate A2 for 1.0 is the official catalog definition: controls", () => {
206
+ const good = () => structuredClone(catalogs["shadcn/ui"]!()) as Json;
207
+ const shape = (c: Json) => validateCatalog(c as unknown as A2uiCatalog, "1.0").gates.find((g) => g.name === "catalog-shape")!;
208
+
209
+ it("positive control: upstream's own pinned 1.0 basic catalog passes", () => {
210
+ const basic = read("../fixtures/a2ui/basic-catalog.v1_0.json") as Json;
211
+ // dspack's invariants require a description; upstream's basic catalog has one.
212
+ expect(shape(basic).pass, JSON.stringify(shape(basic).errors)).toBe(true);
213
+ });
214
+
215
+ const negatives: Record<string, (c: Json) => void> = {
216
+ "anyFunction missing": (c) => delete (c.$defs as Json).anyFunction,
217
+ "surfaceProperties present": (c) => ((c.$defs as Json).surfaceProperties = { type: "object" }),
218
+ "a component wrapped in ComponentCommon": (c) => {
219
+ const comps = c.components as Record<string, Json>;
220
+ comps.Badge = { type: "object", allOf: [{ $ref: "common_types.json#/$defs/ComponentCommon" }, comps.Badge] };
221
+ },
222
+ "protocolVersion missing": (c) => delete c.protocolVersion,
223
+ "a function in the 0.9 shape": (c) => {
224
+ c.functions = { f: { description: "x", returnType: "boolean" } };
225
+ },
226
+ "an unknown root key": (c) => (c.theme = {}),
227
+ };
228
+ for (const [label, mutate] of Object.entries(negatives)) {
229
+ it(`negative control: ${label} fails`, () => {
230
+ const c = good();
231
+ mutate(c);
232
+ expect(shape(c).pass).toBe(false);
233
+ });
234
+ }
235
+ });
236
+
237
+ describe("vendored 1.0 schema mirrors", () => {
238
+ it("the catalog definition mirror equals fixtures/a2ui/catalog_definition.v1_0.json", () => {
239
+ expect(catalogDefinitionV1_0).toStrictEqual(read("../fixtures/a2ui/catalog_definition.v1_0.json"));
240
+ });
241
+ it("the common_types mirror equals fixtures/a2ui/common_types.v1_0.json", () => {
242
+ expect(commonTypesV1_0).toStrictEqual(read("../fixtures/a2ui/common_types.v1_0.json"));
243
+ });
244
+ });
245
+
246
+ describe("catalogCompanionSchemas: what a consumer registers beside a catalog it compiles itself", () => {
247
+ const compile = (catalog: A2uiCatalog, companions: Json[]) => {
248
+ const ajv = new (Ajv2020 as unknown as new (o: object) => { addSchema(s: Json): void; compile(s: Json): unknown })({ strict: false });
249
+ (addFormats as unknown as (a: unknown) => void)(ajv);
250
+ for (const c of companions) ajv.addSchema(c);
251
+ ajv.addSchema(catalog as unknown as Json);
252
+ // As a consumer does: compile what instances are checked against (ajv resolves references lazily).
253
+ return () => ajv.compile({ $ref: `${catalog.$id}#/$defs/anyComponent` } as Json);
254
+ };
255
+
256
+ it("a 0.9.1 catalog is self-contained: no companions", () => {
257
+ expect(catalogCompanionSchemas(transformFromJson(shadcnDoc, { a2uiVersion: "0.9.1" }).catalog)).toEqual([]);
258
+ });
259
+
260
+ it("a 1.0 catalog needs the pinned common_types beside it, and compiles with it but not without it", () => {
261
+ const catalog = catalogs["shadcn/ui"]!();
262
+ const companions = catalogCompanionSchemas(catalog);
263
+ expect(companions.map((c) => c.$id)).toEqual([new URL("common_types.json", catalog.$id).href]);
264
+ expect(compile(catalog, [])).toThrow(/common_types\.json/);
265
+ expect(compile(catalog, companions)).not.toThrow();
266
+ });
267
+ });
@@ -20,6 +20,8 @@
20
20
  import Ajv2020 from "ajv/dist/2020.js";
21
21
  import addFormats from "ajv-formats";
22
22
  import { catalogMetaSchemas } from "./meta/catalog-meta.js";
23
+ import { catalogDefinitionV1_0, commonTypesV1_0 } from "./meta/a2ui-v1_0.js";
24
+ import { COMMON_TYPES_V1_0 } from "../transform/emit-v1_0.js";
23
25
  import type { A2uiCatalog, A2uiVersion, Json } from "../types.js";
24
26
 
25
27
  export interface GateResult {
@@ -73,6 +75,35 @@ function externalRefs(node: unknown, acc: string[] = []): string[] {
73
75
  return acc;
74
76
  }
75
77
 
78
+ /**
79
+ * A2UI 1.0: the one external reference a catalog may make is to a listed standard type in common_types.json, written
80
+ * relative (`common_types.json#/$defs/<Type>`); anything else makes the catalog invalid (specification rule 3).
81
+ */
82
+ const COMMON_REF = /^common_types\.json#\/\$defs\/([A-Za-z]+)$/;
83
+ function allowedV1_0Ref(ref: string): boolean {
84
+ const m = COMMON_REF.exec(ref);
85
+ return !!m && (COMMON_TYPES_V1_0 as readonly string[]).includes(m[1]!);
86
+ }
87
+
88
+ /**
89
+ * The vendored 1.0 common_types, registered where a catalog's relative `common_types.json` reference resolves (beside
90
+ * the catalog's own $id). Its `catalog.json#/$defs/anyFunction` then resolves to that same catalog, offline: the
91
+ * specification forbids fetching either over the network.
92
+ */
93
+ function commonTypesBeside(catalogId: string): Json {
94
+ return { ...(structuredClone(commonTypesV1_0) as Json), $id: new URL("common_types.json", catalogId).href };
95
+ }
96
+
97
+ /**
98
+ * The schemas a consumer must register beside a catalog before compiling it with its own JSON Schema validator.
99
+ * A 0.9.1 catalog is self-contained: none. A 1.0 catalog references the standard types as `common_types.json#/$defs/…`
100
+ * (specification rule 3), so it needs the pinned common_types at the URL that reference resolves to; the specification
101
+ * forbids fetching it. For example, with ajv: `for (const s of catalogCompanionSchemas(catalog)) ajv.addSchema(s)`.
102
+ */
103
+ export function catalogCompanionSchemas(catalog: A2uiCatalog): Json[] {
104
+ return catalog.protocolVersion === "1.0" ? [commonTypesBeside(catalog.$id)] : [];
105
+ }
106
+
76
107
  /**
77
108
  * Collect every INTERNAL `$ref` that does not resolve inside the catalog
78
109
  * document, with the JSON path of the offending `$ref` keyword.
@@ -141,13 +172,17 @@ export function validateCatalog(
141
172
  ): ValidationReport {
142
173
  const gates: GateResult[] = [];
143
174
 
144
- // Gate 1 — schema compile + no external $ref + every internal $ref resolves.
145
- const exts = externalRefs(catalog);
175
+ // Gate 1 — schema compile + no external $ref + every internal $ref resolves. In 1.0 the listed standard types in
176
+ // common_types.json are the one permitted external target, resolved against the vendored copy.
177
+ const v1 = version === "1.0";
178
+ const exts = externalRefs(catalog).filter((r) => !(v1 && allowedV1_0Ref(r)));
146
179
  const dangling = danglingInternalRefs(catalog);
147
180
  let compiled = false;
148
181
  let compileErr = "";
149
182
  try {
150
- newAjv().compile(catalog as unknown as Json);
183
+ const ajv = newAjv();
184
+ if (v1) ajv.addSchema(commonTypesBeside(catalog.$id));
185
+ ajv.compile(catalog as unknown as Json);
151
186
  compiled = true;
152
187
  } catch (e) {
153
188
  compileErr = e instanceof Error ? e.message : String(e);
@@ -157,7 +192,9 @@ export function validateCatalog(
157
192
  name: "schema-compile + no-external-ref",
158
193
  pass: selfContained,
159
194
  detail: selfContained
160
- ? "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal and resolves."
195
+ ? v1
196
+ ? "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal or a listed common_types.json type, and resolves."
197
+ : "Catalog compiles as a draft-2020-12 JSON Schema; every $ref is internal and resolves."
161
198
  : !compiled
162
199
  ? `ajv failed to compile the catalog as a schema: ${compileErr}`
163
200
  : exts.length
@@ -166,17 +203,32 @@ export function validateCatalog(
166
203
  errors: exts.length ? [...new Set(exts)] : dangling.length ? dangling : undefined,
167
204
  });
168
205
 
169
- // Gate 2 — catalog shape.
206
+ // Gate 2 — catalog shape. For 1.0 that is the official catalog definition (vendored, pinned) as well as dspack's own
207
+ // invariants; for 0.9.1, the derived meta-schema as before.
170
208
  const meta = catalogMetaSchemas[version];
171
209
  const validateShape = newAjv().compile(meta);
172
- const shapeOk = validateShape(catalog) as boolean;
210
+ let shapeOk = validateShape(catalog) as boolean;
211
+ const shapeErrors = shapeOk ? [] : (validateShape.errors ?? []).map(fmtErr);
212
+ if (v1) {
213
+ const official = newAjv();
214
+ official.addSchema(commonTypesV1_0);
215
+ const validateOfficial = official.compile(catalogDefinitionV1_0);
216
+ if (!validateOfficial(catalog)) {
217
+ shapeOk = false;
218
+ shapeErrors.push(...(validateOfficial.errors ?? []).map((e) => `catalog_definition: ${fmtErr(e)}`));
219
+ }
220
+ }
173
221
  gates.push({
174
222
  name: "catalog-shape",
175
223
  pass: shapeOk,
176
224
  detail: shapeOk
177
- ? `Catalog satisfies the A2UI v${version} catalog-shape meta-schema.`
178
- : `Catalog violates the v${version} catalog-shape meta-schema.`,
179
- errors: shapeOk ? undefined : (validateShape.errors ?? []).map(fmtErr),
225
+ ? v1
226
+ ? "Catalog satisfies the official A2UI v1.0 catalog definition and dspack's v1.0 invariants."
227
+ : `Catalog satisfies the A2UI v${version} catalog-shape meta-schema.`
228
+ : v1
229
+ ? "Catalog violates the official A2UI v1.0 catalog definition or dspack's v1.0 invariants."
230
+ : `Catalog violates the v${version} catalog-shape meta-schema.`,
231
+ errors: shapeOk ? undefined : shapeErrors,
180
232
  });
181
233
 
182
234
  // Gate 3 — instances (only if the catalog is usable and a surface was supplied).
@@ -197,6 +249,8 @@ export function validateCatalog(
197
249
  let instances: Json[] = [];
198
250
  try {
199
251
  const ajv = newAjv();
252
+ const commonTypes = v1 ? commonTypesBeside(catalog.$id) : undefined;
253
+ if (commonTypes) ajv.addSchema(commonTypes);
200
254
  ajv.addSchema(catalog as unknown as Json, catalog.$id);
201
255
  instances = extractInstances(surface);
202
256
  // Manual discrimination instead of the flat `#/$defs/anyComponent`
@@ -231,7 +285,14 @@ export function validateCatalog(
231
285
  });
232
286
  continue;
233
287
  }
234
- const validateBranch = ajv.getSchema(`${catalog.$id}#/components/${comp}`);
288
+ // A 1.0 component is validated the way the envelope composes it (agent_to_renderer.json `Component`):
289
+ // ComponentCommon plus the catalog component, with no other property. A 0.9.1 component carries its own.
290
+ const validateBranch = commonTypes
291
+ ? ajv.compile({
292
+ allOf: [{ $ref: `${commonTypes.$id}#/$defs/ComponentCommon` }, { $ref: `${catalog.$id}#/components/${comp}` }],
293
+ unevaluatedProperties: false,
294
+ })
295
+ : ajv.getSchema(`${catalog.$id}#/components/${comp}`);
235
296
  if (!validateBranch) {
236
297
  failures.push(`${where}: could not resolve #/components/${comp} from the catalog.`);
237
298
  continue;
@@ -261,7 +322,9 @@ export function validateCatalog(
261
322
  pass: failures.length === 0,
262
323
  detail:
263
324
  failures.length === 0
264
- ? `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
325
+ ? version === "1.0"
326
+ ? `All ${instances.length} surface component instance(s) validate as the 1.0 envelope composes them: common_types.json ComponentCommon with the catalog component, closed.`
327
+ : `All ${instances.length} surface component instance(s) validate against #/$defs/anyComponent.`
265
328
  : `${failures.length} instance validation error(s).`,
266
329
  errors: failures.length ? failures : undefined,
267
330
  ...(errorDetails.length ? { errorDetails } : {}),
@@ -2,32 +2,86 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
4
4
  "title": "A2UI catalog shape (v1.0)",
5
- "description": "Structural invariants an A2UI v1.0 catalog must satisfy, derived from the checked-in basic catalog fixture. The version-distinguishing requirement is $defs.surfaceProperties (and the absence of $defs.theme).",
5
+ "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.",
6
6
  "type": "object",
7
- "required": ["$schema", "$id", "catalogId", "title", "description", "components", "$defs"],
7
+ "required": [
8
+ "$schema",
9
+ "$id",
10
+ "protocolVersion",
11
+ "catalogId",
12
+ "title",
13
+ "description",
14
+ "components",
15
+ "$defs"
16
+ ],
8
17
  "properties": {
9
- "catalogId": { "type": "string", "format": "uri" },
10
- "$id": { "type": "string", "format": "uri" },
11
- "instructions": { "type": "string" },
18
+ "protocolVersion": {
19
+ "const": "1.0"
20
+ },
21
+ "catalogId": {
22
+ "type": "string",
23
+ "format": "uri"
24
+ },
25
+ "$id": {
26
+ "type": "string",
27
+ "format": "uri"
28
+ },
29
+ "instructions": {
30
+ "type": "string"
31
+ },
12
32
  "components": {
13
33
  "type": "object",
14
34
  "minProperties": 1,
15
35
  "additionalProperties": {
16
36
  "type": "object",
17
- "required": ["allOf", "unevaluatedProperties"],
18
- "properties": {
19
- "allOf": { "type": "array", "minItems": 1 },
20
- "unevaluatedProperties": { "const": false }
37
+ "not": {
38
+ "required": [
39
+ "allOf"
40
+ ],
41
+ "properties": {
42
+ "allOf": {
43
+ "contains": {
44
+ "required": [
45
+ "$ref"
46
+ ],
47
+ "properties": {
48
+ "$ref": {
49
+ "pattern": "ComponentCommon$"
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
21
55
  }
22
56
  }
23
57
  },
24
58
  "$defs": {
25
59
  "type": "object",
26
- "required": ["anyComponent", "surfaceProperties"],
27
- "not": { "required": ["theme"] },
60
+ "required": [
61
+ "anyComponent",
62
+ "anyFunction"
63
+ ],
64
+ "not": {
65
+ "anyOf": [
66
+ {
67
+ "required": [
68
+ "theme"
69
+ ]
70
+ },
71
+ {
72
+ "required": [
73
+ "surfaceProperties"
74
+ ]
75
+ }
76
+ ]
77
+ },
28
78
  "properties": {
29
- "anyComponent": { "type": "object", "required": ["oneOf"] },
30
- "surfaceProperties": { "type": "object", "required": ["properties"] }
79
+ "anyComponent": {
80
+ "type": "object",
81
+ "required": [
82
+ "oneOf"
83
+ ]
84
+ }
31
85
  }
32
86
  }
33
87
  }