@aestheticfunction/dspack-emit 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -3
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +34 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/targets/a2ui/surface.js +159 -5
- package/dist/targets/json-render/profile.d.ts +10 -0
- package/dist/targets/json-render/profile.js +12 -0
- package/dist/transform/profile-load.d.ts +19 -0
- package/dist/transform/profile-load.js +58 -0
- package/dist/transform/profile.v1.schema.json +153 -0
- package/dist/transform/profiles.d.ts +41 -0
- package/dist/transform/profiles.js +60 -7
- package/dist/transform/scaffold.d.ts +40 -0
- package/dist/transform/scaffold.js +171 -0
- package/package.json +5 -2
- package/src/cli.ts +35 -9
- package/src/index.ts +2 -0
- package/src/json-render-emit.test.ts +48 -1
- package/src/profile-load.test.ts +144 -0
- package/src/profile-parity.test.ts +96 -0
- package/src/targets/a2ui/surface.ts +160 -5
- package/src/targets/json-render/profile.ts +13 -0
- package/src/transform/profile-load.ts +73 -0
- package/src/transform/profile.v1.schema.json +153 -0
- package/src/transform/profiles.ts +101 -7
- package/src/transform/scaffold.ts +229 -0
package/README.md
CHANGED
|
@@ -7,6 +7,12 @@ governed dspack surfaces into protocol targets — an
|
|
|
7
7
|
**[json-render](https://github.com/vercel-labs/json-render) catalog/registry
|
|
8
8
|
modules + specs**.
|
|
9
9
|
|
|
10
|
+
> Part of the [dspack ecosystem](https://github.com/aestheticfunction) — the organization profile has the full map of how the repositories fit together.
|
|
11
|
+
>
|
|
12
|
+
> **Kind:** library (npm `@aestheticfunction/dspack-emit`) · **Audience:** engineers wiring dspack contracts and surfaces to rendering protocols · **Neighbors:** consumes [dspack](https://github.com/aestheticfunction/dspack) contracts; consumed by [dspack-gen](https://github.com/aestheticfunction/dspack-gen) and [dspack-studio](https://github.com/aestheticfunction/dspack-studio) ([hosted replay](https://studio.aesthetic-function.com)); pairs with [ds-mcp](https://github.com/aestheticfunction/ds-mcp) in the demo
|
|
13
|
+
>
|
|
14
|
+
> **Mapping your own design system?** Profiles are pure data you author in your own codebase against this package — the walkthrough is [docs/PROFILES.md](docs/PROFILES.md); the broader adoption journey starts at [ADOPTING.md](https://github.com/aestheticfunction/dspack/blob/main/ADOPTING.md).
|
|
15
|
+
|
|
10
16
|
> **Naming note:** this repo was renamed from `dspack-to-a2ui` to `dspack-emit`
|
|
11
17
|
> when the second target landed (ADR-D2; the old GitHub URL redirects). The
|
|
12
18
|
> npm package is **`@aestheticfunction/dspack-emit`** from `0.3.0`; the last
|
|
@@ -44,7 +50,7 @@ https://github.com/user-attachments/assets/510a781b-4214-49b3-b997-9cbecdc36961
|
|
|
44
50
|
|
|
45
51
|
| Path | What |
|
|
46
52
|
| --- | --- |
|
|
47
|
-
| `input/shadcn-ui.dspack.json` | Example input: a dspack v0.
|
|
53
|
+
| `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). |
|
|
48
54
|
| `src/` | The transformer: source-agnostic engine + data-only profile + versioned emitter + validator. |
|
|
49
55
|
| `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components. |
|
|
50
56
|
| `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (no external `$ref`, versioned `catalogId`). |
|
|
@@ -80,6 +86,28 @@ Or directly:
|
|
|
80
86
|
npm run transform -- --in input/shadcn-ui.dspack.json --a2ui-version 1.0 --out out
|
|
81
87
|
```
|
|
82
88
|
|
|
89
|
+
### Profiles as JSON (`--profile`, `loadProfile`, `scaffoldProfile`)
|
|
90
|
+
|
|
91
|
+
The `Profile` has always been pure data; it is now also *reachable* as data.
|
|
92
|
+
A `*.profile.json` document (schema:
|
|
93
|
+
[`src/transform/profile.v1.schema.json`](src/transform/profile.v1.schema.json),
|
|
94
|
+
a 1:1 mirror of the `Profile` type plus a `profileVersion: "1"` envelope)
|
|
95
|
+
drives the engine byte-identically to a TypeScript profile. The package
|
|
96
|
+
installs a `dspack-emit` bin, so out-of-repo contracts emit from any CI:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
dspack-emit --in acme-ui.dspack.json --a2ui-version 0.9.1 --out out \
|
|
100
|
+
--profile acme.profile.json --emit-surface surfaces/status-report.dsurface.json
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
A malformed profile is refused before the engine runs (`ProfileLoadError`
|
|
104
|
+
with pathed findings; CLI exit 2). `scaffoldProfile(doc, { catalogIdBase })`
|
|
105
|
+
produces a mechanical 1:1 starting draft plus `notes` naming every judgment
|
|
106
|
+
call it deliberately did not make — see
|
|
107
|
+
[docs/PROFILES.md](docs/PROFILES.md). With `--profile` and no `--surface`,
|
|
108
|
+
the repo-relative sample-surface default is skipped (gate A3 then covers
|
|
109
|
+
`--emit-surface` output only).
|
|
110
|
+
|
|
83
111
|
### Versioned emitter (`--a2ui-version 0.9.1 | 1.0`)
|
|
84
112
|
|
|
85
113
|
The mapper targets and validates the **v1.0** catalog schema as the primary line, and
|
|
@@ -116,10 +144,10 @@ before anything reaches this emitter.
|
|
|
116
144
|
|
|
117
145
|
## Surface emission (dspack surface → A2UI)
|
|
118
146
|
|
|
119
|
-
The input contract is now **dspack v0.
|
|
147
|
+
The input contract is now **dspack v0.4**, whose `examples[]` embed *dspack
|
|
120
148
|
surface* documents — a protocol-neutral component tree in dspack vocabulary
|
|
121
149
|
(schema: `dspack.surface.v0_1.schema.json` in the dspack repo). This repo
|
|
122
|
-
compiles those surfaces to A2UI v0.9 messages:
|
|
150
|
+
compiles those surfaces to A2UI v0.9.1 messages:
|
|
123
151
|
|
|
124
152
|
```bash
|
|
125
153
|
npm run transform -- --in input/shadcn-ui.dspack.json --a2ui-version 0.9.1 --out out \
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* dspack-emit CLI.
|
|
3
|
+
* dspack-emit CLI (also installed as the `dspack-emit` bin).
|
|
4
4
|
*
|
|
5
5
|
* tsx src/cli.ts --in <dspack.json> --a2ui-version <0.9.1|1.0> --out <dir> [--surface <surface.json>]
|
|
6
|
-
* [--emit-surface <surface.dsurface.json>]
|
|
6
|
+
* [--profile <profile.json>] [--emit-surface <surface.dsurface.json>]
|
|
7
7
|
* tsx src/cli.ts --target json-render --in <dspack.json> --out <dir>
|
|
8
8
|
* [--emit-surface <surface.dsurface.json>]
|
|
9
9
|
*
|
|
10
|
+
* --profile loads a JSON mapping profile (validated against
|
|
11
|
+
* profile.v1.schema.json via loadProfile) instead of the built-in shadcn
|
|
12
|
+
* profile — the flag that makes out-of-repo contracts emittable from CI.
|
|
13
|
+
* When --profile is given and --surface is not, the sample-surface default
|
|
14
|
+
* (a repo-relative fixture) is skipped and gate A3 runs on --emit-surface
|
|
15
|
+
* output only.
|
|
16
|
+
*
|
|
10
17
|
* Default target (a2ui): emits a versioned A2UI catalog + a
|
|
11
18
|
* validation/fidelity report. Exits non-zero if the hard gate (catalog schema
|
|
12
19
|
* validation) fails, so it is CI-friendly. With --emit-surface, additionally
|
|
@@ -24,6 +31,8 @@
|
|
|
24
31
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
25
32
|
import { basename, join, resolve } from "node:path";
|
|
26
33
|
import { transform } from "./transform/index.js";
|
|
34
|
+
import { shadcnProfile } from "./transform/profiles.js";
|
|
35
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
27
36
|
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
28
37
|
import { generateJsonRenderModules } from "./targets/json-render/codegen.js";
|
|
29
38
|
import { emitJsonRenderSpec, EmitJsonRenderError, validateSpecAgainstModel } from "./targets/json-render/emit.js";
|
|
@@ -65,12 +74,16 @@ function parseArgs(argv) {
|
|
|
65
74
|
const input = m.get("in");
|
|
66
75
|
if (!input)
|
|
67
76
|
fail("--in <dspack.json> is required");
|
|
77
|
+
const profile = m.get("profile");
|
|
68
78
|
return {
|
|
69
79
|
target,
|
|
70
80
|
in: input,
|
|
71
81
|
version: (version ?? "0.9.1"),
|
|
72
82
|
out: m.get("out") ?? "out",
|
|
73
|
-
|
|
83
|
+
// The sample-surface default is a repo-relative fixture; external callers
|
|
84
|
+
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
85
|
+
surface: m.get("surface") ?? (profile ? undefined : "surface/settings-card.surface.json"),
|
|
86
|
+
profile,
|
|
74
87
|
emitSurface: m.get("emit-surface"),
|
|
75
88
|
strictCoverage: m.get("strict-coverage") === "true",
|
|
76
89
|
};
|
|
@@ -131,8 +144,21 @@ function main() {
|
|
|
131
144
|
jsonRenderMain(args, doc);
|
|
132
145
|
return;
|
|
133
146
|
}
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
let profile = shadcnProfile;
|
|
148
|
+
if (args.profile) {
|
|
149
|
+
try {
|
|
150
|
+
profile = loadProfile(JSON.parse(readFileSync(resolve(args.profile), "utf8")));
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
if (e instanceof ProfileLoadError) {
|
|
154
|
+
console.error(`error: --profile ${args.profile}: ${e.message}`);
|
|
155
|
+
process.exit(2);
|
|
156
|
+
}
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const surface = args.surface ? JSON.parse(readFileSync(resolve(args.surface), "utf8")) : { messages: [] };
|
|
161
|
+
const { catalog, mapping, validation, report } = transform(doc, args.version, surface, profile);
|
|
136
162
|
mkdirSync(resolve(args.out), { recursive: true });
|
|
137
163
|
const base = resolve(args.out);
|
|
138
164
|
writeFileSync(join(base, `catalog.${seg}.json`), JSON.stringify(catalog, null, 2) + "\n");
|
|
@@ -156,7 +182,7 @@ function main() {
|
|
|
156
182
|
const csr = JSON.parse(readFileSync(resolve(args.emitSurface), "utf8"));
|
|
157
183
|
let emitted;
|
|
158
184
|
try {
|
|
159
|
-
emitted = emitSurface(csr, doc);
|
|
185
|
+
emitted = emitSurface(csr, doc, { profile });
|
|
160
186
|
}
|
|
161
187
|
catch (e) {
|
|
162
188
|
if (e instanceof EmitSurfaceError) {
|
|
@@ -172,7 +198,7 @@ function main() {
|
|
|
172
198
|
console.log(`${tag} note ${w.code}: ${w.message}`);
|
|
173
199
|
// Gate A3 over the emitted surface: its instances must validate against the
|
|
174
200
|
// catalog generated in this same run.
|
|
175
|
-
const check = transform(doc, args.version, { messages: emitted.messages });
|
|
201
|
+
const check = transform(doc, args.version, { messages: emitted.messages }, profile);
|
|
176
202
|
const instanceGate = check.validation.gates.find((g) => g.name === "instance");
|
|
177
203
|
console.log(`${tag} emitted surface -> ${outPath}`);
|
|
178
204
|
console.log(`${tag} ${instanceGate?.pass ? "PASS" : "FAIL"} instance (emitted surface vs generated catalog)`);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { transform, transformFromJson, type TransformOutput } from "./transform/index.js";
|
|
9
9
|
export { shadcnProfile, type Profile, type ComponentPlan, type SurfacePlanDirectives } from "./transform/profiles.js";
|
|
10
|
+
export { loadProfile, profileSchema, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
|
|
11
|
+
export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
|
|
10
12
|
export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
|
|
11
13
|
export { emitSurface, slug, EmitSurfaceError, type EmitSurfaceResult, type EmitSurfaceOptions, } from "./targets/a2ui/surface.js";
|
|
12
14
|
export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, type EmitJsonRenderResult, type EmitJsonRenderOptions, type JsonRenderSpec, type JsonRenderElement, type SpecFinding, } from "./targets/json-render/emit.js";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { transform, transformFromJson } from "./transform/index.js";
|
|
9
9
|
export { shadcnProfile } from "./transform/profiles.js";
|
|
10
|
+
export { loadProfile, profileSchema, ProfileLoadError } from "./transform/profile-load.js";
|
|
11
|
+
export { scaffoldProfile } from "./transform/scaffold.js";
|
|
10
12
|
export { validateCatalog, extractInstances } from "./validate/ajv.js";
|
|
11
13
|
export { emitSurface, slug, EmitSurfaceError, } from "./targets/a2ui/surface.js";
|
|
12
14
|
export { emitJsonRenderSpec, validateSpecAgainstModel, EmitJsonRenderError, } from "./targets/json-render/emit.js";
|
|
@@ -72,6 +72,13 @@ class SurfaceEmitter {
|
|
|
72
72
|
emitNode(node, path) {
|
|
73
73
|
const plan = this.byDspackId.get(node.component);
|
|
74
74
|
if (!plan) {
|
|
75
|
+
// A declared casualty refuses with its authored reason — the refusal is
|
|
76
|
+
// the profile author's decision, and the message should say so.
|
|
77
|
+
const casualty = this.profile.casualtyComponents.find((c) => c.dspackId === node.component);
|
|
78
|
+
if (casualty) {
|
|
79
|
+
throw new EmitSurfaceError(`component '${node.component}' is a declared casualty (${casualty.class}) of the ` +
|
|
80
|
+
`'${this.profile.catalogTitle}' profile: ${casualty.reason}`, path);
|
|
81
|
+
}
|
|
75
82
|
throw new EmitSurfaceError(`unknown component '${node.component}': not a mapped component of the '${this.profile.catalogTitle}' profile ` +
|
|
76
83
|
`(sub-components are consumed by their compound parent and cannot be emitted standalone)`, path);
|
|
77
84
|
}
|
|
@@ -84,7 +91,7 @@ class SurfaceEmitter {
|
|
|
84
91
|
const instance = { id, component: plan.a2ui };
|
|
85
92
|
this.applyPropMap(node, plan, instance, path);
|
|
86
93
|
const sp = plan.surfacePlan ?? {};
|
|
87
|
-
const consumesSubtree = Boolean(sp.subText || sp.subButtonText);
|
|
94
|
+
const consumesSubtree = Boolean(sp.subText || sp.subButtonText || sp.subTable);
|
|
88
95
|
if (sp.structuralPassthrough) {
|
|
89
96
|
for (const key of sp.structuralPassthrough) {
|
|
90
97
|
const value = node.props?.[key];
|
|
@@ -94,6 +101,8 @@ class SurfaceEmitter {
|
|
|
94
101
|
}
|
|
95
102
|
if (sp.subText || sp.subButtonText)
|
|
96
103
|
this.applySubContent(node, sp.subText ?? {}, sp.subButtonText ?? {}, instance, path);
|
|
104
|
+
if (sp.subTable)
|
|
105
|
+
this.applySubTable(node, sp.subTable, instance, path);
|
|
97
106
|
if (sp.textProp && node.text !== undefined)
|
|
98
107
|
instance[sp.textProp] = node.text;
|
|
99
108
|
if (sp.textChildProp && node.text !== undefined) {
|
|
@@ -108,9 +117,11 @@ class SurfaceEmitter {
|
|
|
108
117
|
});
|
|
109
118
|
}
|
|
110
119
|
if (!consumesSubtree) {
|
|
111
|
-
const childNodes = collectChildren(node);
|
|
120
|
+
const childNodes = sp.subFlatten ? this.flattenSubs(node, sp.subFlatten, path) : collectChildren(node);
|
|
112
121
|
if (childNodes.length > 0) {
|
|
113
|
-
const childIds = childNodes.map((child, i) =>
|
|
122
|
+
const childIds = childNodes.map((child, i) => "textVariant" in child
|
|
123
|
+
? this.emitTextPrimitive(child.text, `${id}_${slug(child.textVariant)}`, path, child.textVariant)
|
|
124
|
+
: this.emitNode(child.node, `${path}${child.suffix}[${i}]`));
|
|
114
125
|
if (sp.childrenProp) {
|
|
115
126
|
instance[sp.childrenProp] = childIds;
|
|
116
127
|
}
|
|
@@ -208,16 +219,159 @@ class SurfaceEmitter {
|
|
|
208
219
|
message: `${path}: compound '${node.component}' subtree flattened onto emitted props (documented casualty; nested props beyond text are not carried).`,
|
|
209
220
|
});
|
|
210
221
|
}
|
|
211
|
-
emitTextPrimitive(text, preferredId, path) {
|
|
222
|
+
emitTextPrimitive(text, preferredId, path, variant) {
|
|
212
223
|
const { textComponent, textProp } = this.profile.surfaceSynthesis;
|
|
213
224
|
const id = this.allocateId(preferredId, path);
|
|
214
|
-
|
|
225
|
+
const instance = { id, component: textComponent, [textProp]: text };
|
|
226
|
+
if (variant !== undefined)
|
|
227
|
+
instance.variant = variant;
|
|
228
|
+
this.components.push(instance);
|
|
215
229
|
this.warnings.push({
|
|
216
230
|
code: "surface-synthesized-text",
|
|
217
231
|
message: `${path}: node text projected as a synthesized ${textComponent} child ('${id}') — the surface format has no text primitive.`,
|
|
218
232
|
});
|
|
219
233
|
return id;
|
|
220
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Named parent strategy "subFlatten" (e.g. Card): grouping sub-components
|
|
237
|
+
* splice their children inline in document order (their own structure is a
|
|
238
|
+
* warned, documented loss); text-bearing sub-components synthesize the
|
|
239
|
+
* profile's text primitive with the declared variant. Everything else
|
|
240
|
+
* passes through to ordinary child emission.
|
|
241
|
+
*/
|
|
242
|
+
flattenSubs(node, spec, path) {
|
|
243
|
+
const out = [];
|
|
244
|
+
const visit = (n, suffix) => {
|
|
245
|
+
if (spec.transparent.includes(n.component)) {
|
|
246
|
+
this.warnings.push({
|
|
247
|
+
code: "surface-sub-flattened",
|
|
248
|
+
message: `${path}: grouping sub-component '${n.component}' spliced inline (subFlatten strategy); its own structure is not carried.`,
|
|
249
|
+
});
|
|
250
|
+
if (n.text !== undefined && n.text !== "")
|
|
251
|
+
out.push({ text: n.text, textVariant: "body" });
|
|
252
|
+
for (const child of collectChildren(n))
|
|
253
|
+
visit(child.node, child.suffix);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const variant = spec.asText[n.component];
|
|
257
|
+
if (variant !== undefined) {
|
|
258
|
+
const text = this.subtreeText(n);
|
|
259
|
+
if (text !== "") {
|
|
260
|
+
out.push({ text, textVariant: variant });
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
this.warnings.push({
|
|
264
|
+
code: "surface-sub-dropped",
|
|
265
|
+
message: `${path}: '${n.component}' carried no text to synthesize; dropped.`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
out.push({ node: n, suffix });
|
|
271
|
+
};
|
|
272
|
+
for (const child of collectChildren(node))
|
|
273
|
+
visit(child.node, child.suffix);
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Named parent strategy "subTable": consume the tabular sub tree into the
|
|
278
|
+
* synthesized caption/columns/rows shape. Domain-neutral: a cell is its
|
|
279
|
+
* subtree's text in document order — nested component structure and props
|
|
280
|
+
* are a per-cell warned loss, never re-interpreted into semantic fields.
|
|
281
|
+
* structuralPassthrough values (the props path) win over consumed ones.
|
|
282
|
+
*/
|
|
283
|
+
applySubTable(node, spec, instance, path) {
|
|
284
|
+
const columns = [];
|
|
285
|
+
const rows = [];
|
|
286
|
+
let caption;
|
|
287
|
+
const cellText = (cell, cellPath) => {
|
|
288
|
+
const nested = collectChildren(cell);
|
|
289
|
+
const text = this.subtreeText(cell);
|
|
290
|
+
if (nested.length > 0) {
|
|
291
|
+
const names = nested.map((c) => `'${c.node.component}'`).join(", ");
|
|
292
|
+
this.warnings.push({
|
|
293
|
+
code: "surface-table-cell-flattened",
|
|
294
|
+
message: `${cellPath}: nested ${names} flattened to cell text; component structure and props are not carried by the synthesized table shape.`,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return text;
|
|
298
|
+
};
|
|
299
|
+
const consumeRow = (row, rowPath, into) => {
|
|
300
|
+
for (const child of collectChildren(row)) {
|
|
301
|
+
const c = child.node.component;
|
|
302
|
+
if (c === spec.cell || c === spec.headerCell) {
|
|
303
|
+
into.push(cellText(child.node, `${rowPath}${child.suffix}`));
|
|
304
|
+
}
|
|
305
|
+
else if (spec.drops[c] !== undefined) {
|
|
306
|
+
this.warnings.push({ code: "surface-sub-dropped", message: `${rowPath}: '${c}' dropped: ${spec.drops[c]}.` });
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this.warnings.push({
|
|
310
|
+
code: "surface-sub-dropped",
|
|
311
|
+
message: `${rowPath}: '${c}' has no slot in a synthesized table row; dropped (its text is not lifted).`,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
for (const child of collectChildren(node)) {
|
|
317
|
+
const c = child.node.component;
|
|
318
|
+
const childPath = `${path}${child.suffix}`;
|
|
319
|
+
if (c === spec.caption) {
|
|
320
|
+
caption ??= cellText(child.node, childPath);
|
|
321
|
+
}
|
|
322
|
+
else if (c === spec.header) {
|
|
323
|
+
for (const inner of collectChildren(child.node)) {
|
|
324
|
+
if (inner.node.component === spec.row)
|
|
325
|
+
consumeRow(inner.node, `${childPath}${inner.suffix}`, columns);
|
|
326
|
+
else
|
|
327
|
+
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.header}' has no slot; dropped.` });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else if (c === spec.body) {
|
|
331
|
+
for (const inner of collectChildren(child.node)) {
|
|
332
|
+
if (inner.node.component === spec.row) {
|
|
333
|
+
const cells = [];
|
|
334
|
+
consumeRow(inner.node, `${childPath}${inner.suffix}`, cells);
|
|
335
|
+
rows.push({ cells });
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${inner.node.component}' inside '${spec.body}' has no slot; dropped.` });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
else if (spec.drops[c] !== undefined) {
|
|
343
|
+
this.warnings.push({ code: "surface-sub-dropped", message: `${childPath}: '${c}' dropped: ${spec.drops[c]}.` });
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
this.warnings.push({
|
|
347
|
+
code: "surface-sub-dropped",
|
|
348
|
+
message: `${childPath}: '${c}' has no slot in the synthesized table shape; dropped.`,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (instance[spec.targetCaption] === undefined && caption !== undefined)
|
|
353
|
+
instance[spec.targetCaption] = caption;
|
|
354
|
+
if (instance[spec.targetColumns] === undefined && columns.length > 0)
|
|
355
|
+
instance[spec.targetColumns] = columns;
|
|
356
|
+
if (instance[spec.targetRows] === undefined && rows.length > 0)
|
|
357
|
+
instance[spec.targetRows] = rows;
|
|
358
|
+
this.warnings.push({
|
|
359
|
+
code: "surface-composition-flattened",
|
|
360
|
+
message: `${path}: compound '${node.component}' subtree consumed into the synthesized table shape (documented casualty; cell content beyond text is not carried).`,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
/** All text in a node's subtree, document order, space-joined. */
|
|
364
|
+
subtreeText(node) {
|
|
365
|
+
const parts = [];
|
|
366
|
+
const visit = (n) => {
|
|
367
|
+
if (n.text !== undefined && n.text !== "")
|
|
368
|
+
parts.push(n.text);
|
|
369
|
+
for (const child of collectChildren(n))
|
|
370
|
+
visit(child.node);
|
|
371
|
+
};
|
|
372
|
+
visit(node);
|
|
373
|
+
return parts.join(" ");
|
|
374
|
+
}
|
|
221
375
|
wrapInColumn(childIds, parentId, path) {
|
|
222
376
|
const { wrapComponent, wrapChildrenProp } = this.profile.surfaceSynthesis;
|
|
223
377
|
const id = this.allocateId(`${parentId}_col`, path);
|
|
@@ -21,3 +21,13 @@ export interface JsonRenderProfile {
|
|
|
21
21
|
intentionallyOmitted?: string[];
|
|
22
22
|
}
|
|
23
23
|
export declare const shadcnJsonRenderProfile: JsonRenderProfile;
|
|
24
|
+
/**
|
|
25
|
+
* Astryx (facebook/astryx @ v0.1.4, nine-component slice). Also empty — the
|
|
26
|
+
* asymmetry finding's prediction held for a SECOND contract with a different
|
|
27
|
+
* idiom: nothing needs projecting, because the catalog carries the contract's
|
|
28
|
+
* own vocabulary. Astryx's data-driven array props (table.data/columns,
|
|
29
|
+
* dropdown-menu.items) are EXCLUDED by the codegen's prop typing with
|
|
30
|
+
* documented reasons — the lossy edge of the "lossless" target, visible in
|
|
31
|
+
* the generated catalog header and the model's excluded-props record.
|
|
32
|
+
*/
|
|
33
|
+
export declare const astryxJsonRenderProfile: JsonRenderProfile;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
export const shadcnJsonRenderProfile = {
|
|
2
2
|
intentionallyOmitted: [],
|
|
3
3
|
};
|
|
4
|
+
/**
|
|
5
|
+
* Astryx (facebook/astryx @ v0.1.4, nine-component slice). Also empty — the
|
|
6
|
+
* asymmetry finding's prediction held for a SECOND contract with a different
|
|
7
|
+
* idiom: nothing needs projecting, because the catalog carries the contract's
|
|
8
|
+
* own vocabulary. Astryx's data-driven array props (table.data/columns,
|
|
9
|
+
* dropdown-menu.items) are EXCLUDED by the codegen's prop typing with
|
|
10
|
+
* documented reasons — the lossy edge of the "lossless" target, visible in
|
|
11
|
+
* the generated catalog header and the model's excluded-props record.
|
|
12
|
+
*/
|
|
13
|
+
export const astryxJsonRenderProfile = {
|
|
14
|
+
intentionallyOmitted: [],
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Profile } from "./profiles.js";
|
|
2
|
+
export interface ProfileLoadIssue {
|
|
3
|
+
/** JSON path into the offending document (ajv instancePath). */
|
|
4
|
+
path: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ProfileLoadError extends Error {
|
|
8
|
+
readonly issues: ProfileLoadIssue[];
|
|
9
|
+
constructor(issues: ProfileLoadIssue[]);
|
|
10
|
+
}
|
|
11
|
+
/** The profile schema, as shipped (also exported for hosts that surface it in UI). */
|
|
12
|
+
export declare const profileSchema: Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Validate `json` as a v1 profile document and return the engine-ready
|
|
15
|
+
* `Profile`. The `profileVersion` envelope field is stripped — it belongs to
|
|
16
|
+
* the document format, not the engine. Top-level `x-` extension keys are
|
|
17
|
+
* preserved (the engine ignores them; provenance tools may not).
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadProfile(json: unknown): Profile;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile-as-data: load a mapping Profile from JSON.
|
|
3
|
+
*
|
|
4
|
+
* The Profile has always been pure data (profiles.ts); this module makes it
|
|
5
|
+
* *reachable* as data. `loadProfile` validates an untrusted JSON value against
|
|
6
|
+
* schema `profile.v1.schema.json` (a one-to-one mirror of the TypeScript
|
|
7
|
+
* `Profile` interface plus a `profileVersion` envelope const) and returns the
|
|
8
|
+
* engine-ready `Profile`. Validation gates shape only — every judgment call
|
|
9
|
+
* (valueMaps, casualties, surface plans) stays with the profile's author.
|
|
10
|
+
*
|
|
11
|
+
* Toolchain: ajv draft 2020-12, `strict: false`, ajv-formats — the same
|
|
12
|
+
* convention as the catalog gates (src/validate/ajv.ts) and the dspack
|
|
13
|
+
* harness.
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import Ajv2020 from "ajv/dist/2020.js";
|
|
18
|
+
import addFormats from "ajv-formats";
|
|
19
|
+
export class ProfileLoadError extends Error {
|
|
20
|
+
issues;
|
|
21
|
+
constructor(issues) {
|
|
22
|
+
super(`profile does not conform to profile.v1.schema.json (${issues.length} issue${issues.length === 1 ? "" : "s"}): ` +
|
|
23
|
+
issues
|
|
24
|
+
.slice(0, 3)
|
|
25
|
+
.map((i) => `${i.path || "$"}: ${i.message}`)
|
|
26
|
+
.join("; ") +
|
|
27
|
+
(issues.length > 3 ? "; …" : ""));
|
|
28
|
+
this.issues = issues;
|
|
29
|
+
this.name = "ProfileLoadError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const schemaPath = fileURLToPath(new URL("./profile.v1.schema.json", import.meta.url));
|
|
33
|
+
/** The profile schema, as shipped (also exported for hosts that surface it in UI). */
|
|
34
|
+
export const profileSchema = JSON.parse(readFileSync(schemaPath, "utf8"));
|
|
35
|
+
let compiled;
|
|
36
|
+
function validator() {
|
|
37
|
+
if (!compiled) {
|
|
38
|
+
const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
|
|
39
|
+
addFormats(ajv);
|
|
40
|
+
compiled = ajv.compile(profileSchema);
|
|
41
|
+
}
|
|
42
|
+
return compiled;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate `json` as a v1 profile document and return the engine-ready
|
|
46
|
+
* `Profile`. The `profileVersion` envelope field is stripped — it belongs to
|
|
47
|
+
* the document format, not the engine. Top-level `x-` extension keys are
|
|
48
|
+
* preserved (the engine ignores them; provenance tools may not).
|
|
49
|
+
*/
|
|
50
|
+
export function loadProfile(json) {
|
|
51
|
+
const validate = validator();
|
|
52
|
+
if (!validate(json)) {
|
|
53
|
+
const errors = (validate.errors ?? []);
|
|
54
|
+
throw new ProfileLoadError(errors.map((e) => ({ path: e.instancePath ?? "", message: e.message ?? "invalid" })));
|
|
55
|
+
}
|
|
56
|
+
const { profileVersion: _envelope, ...profile } = json;
|
|
57
|
+
return profile;
|
|
58
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://aestheticfunction.github.io/dspack-emit/schema/profile.v1.schema.json",
|
|
4
|
+
"title": "dspack-emit a2ui Profile v1",
|
|
5
|
+
"description": "JSON form of the a2ui target's mapping Profile. Mirrors the TypeScript Profile interface in src/transform/profiles.ts one to one; loadProfile() validates against this schema before the engine runs.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"patternProperties": { "^x-": {} },
|
|
9
|
+
"required": [
|
|
10
|
+
"profileVersion",
|
|
11
|
+
"catalogTitle",
|
|
12
|
+
"catalogDescription",
|
|
13
|
+
"catalogIdBase",
|
|
14
|
+
"instructions",
|
|
15
|
+
"primaryColorToken",
|
|
16
|
+
"components",
|
|
17
|
+
"synthesized",
|
|
18
|
+
"casualtyComponents",
|
|
19
|
+
"surfaceSynthesis"
|
|
20
|
+
],
|
|
21
|
+
"properties": {
|
|
22
|
+
"profileVersion": { "const": "1" },
|
|
23
|
+
"catalogTitle": { "type": "string", "minLength": 1 },
|
|
24
|
+
"catalogDescription": { "type": "string", "minLength": 1 },
|
|
25
|
+
"catalogIdBase": { "type": "string", "format": "uri", "pattern": "^https://" },
|
|
26
|
+
"instructions": { "type": "string" },
|
|
27
|
+
"primaryColorToken": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": false,
|
|
30
|
+
"required": ["category", "name"],
|
|
31
|
+
"properties": {
|
|
32
|
+
"category": { "type": "string", "minLength": 1 },
|
|
33
|
+
"name": { "type": "string", "minLength": 1 }
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"components": { "type": "array", "items": { "$ref": "#/$defs/componentPlan" } },
|
|
37
|
+
"synthesized": { "type": "array", "items": { "$ref": "#/$defs/componentPlan" } },
|
|
38
|
+
"casualtyComponents": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"items": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"patternProperties": { "^x-": {} },
|
|
44
|
+
"required": ["dspackId", "attempted", "class", "reason"],
|
|
45
|
+
"properties": {
|
|
46
|
+
"dspackId": { "$ref": "#/$defs/dspackId" },
|
|
47
|
+
"attempted": { "type": "string", "minLength": 1 },
|
|
48
|
+
"class": { "enum": ["maps-cleanly", "synthesis-defaults", "lossy", "cannot-represent"] },
|
|
49
|
+
"reason": { "type": "string", "minLength": 1 }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"intentionallyOmitted": { "type": "array", "items": { "$ref": "#/$defs/dspackId" } },
|
|
54
|
+
"surfaceSynthesis": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"additionalProperties": false,
|
|
57
|
+
"required": ["textComponent", "textProp", "wrapComponent", "wrapChildrenProp"],
|
|
58
|
+
"properties": {
|
|
59
|
+
"textComponent": { "$ref": "#/$defs/a2uiName" },
|
|
60
|
+
"textProp": { "type": "string", "minLength": 1 },
|
|
61
|
+
"wrapComponent": { "$ref": "#/$defs/a2uiName" },
|
|
62
|
+
"wrapChildrenProp": { "type": "string", "minLength": 1 }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"$defs": {
|
|
67
|
+
"dspackId": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
|
68
|
+
"a2uiName": { "type": "string", "pattern": "^[A-Z][A-Za-z0-9]*$" },
|
|
69
|
+
"componentPlan": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"additionalProperties": false,
|
|
72
|
+
"patternProperties": { "^x-": {} },
|
|
73
|
+
"required": ["a2ui", "commons", "structural", "required"],
|
|
74
|
+
"properties": {
|
|
75
|
+
"a2ui": { "$ref": "#/$defs/a2uiName" },
|
|
76
|
+
"dspackId": { "$ref": "#/$defs/dspackId" },
|
|
77
|
+
"description": { "type": "string" },
|
|
78
|
+
"commons": { "type": "array", "items": { "type": "string", "minLength": 1 } },
|
|
79
|
+
"structural": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"additionalProperties": {
|
|
82
|
+
"type": "object",
|
|
83
|
+
"additionalProperties": false,
|
|
84
|
+
"required": ["schema", "description", "synthNote"],
|
|
85
|
+
"properties": {
|
|
86
|
+
"schema": {},
|
|
87
|
+
"description": { "type": "string", "minLength": 1 },
|
|
88
|
+
"synthNote": { "type": "string", "minLength": 1 }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"propMap": {
|
|
93
|
+
"type": "object",
|
|
94
|
+
"additionalProperties": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"additionalProperties": false,
|
|
97
|
+
"required": ["a2ui", "kind"],
|
|
98
|
+
"properties": {
|
|
99
|
+
"a2ui": { "type": "string", "minLength": 1 },
|
|
100
|
+
"kind": { "enum": ["enum", "string", "boolean", "number"] },
|
|
101
|
+
"targetEnum": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
|
|
102
|
+
"valueMap": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
103
|
+
"default": { "type": "string" },
|
|
104
|
+
"description": { "type": "string" }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"required": { "type": "array", "items": { "type": "string" } },
|
|
109
|
+
"surfacePlan": {
|
|
110
|
+
"type": "object",
|
|
111
|
+
"additionalProperties": false,
|
|
112
|
+
"properties": {
|
|
113
|
+
"subText": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
114
|
+
"subButtonText": { "type": "object", "additionalProperties": { "type": "string" } },
|
|
115
|
+
"actionProp": { "type": "string" },
|
|
116
|
+
"textChildProp": { "type": "string" },
|
|
117
|
+
"textProp": { "type": "string" },
|
|
118
|
+
"childProp": { "type": "string" },
|
|
119
|
+
"childrenProp": { "type": "string" },
|
|
120
|
+
"structuralPassthrough": { "type": "array", "items": { "type": "string" } },
|
|
121
|
+
"subTable": {
|
|
122
|
+
"type": "object",
|
|
123
|
+
"additionalProperties": false,
|
|
124
|
+
"required": ["caption", "header", "headerCell", "body", "row", "cell", "targetCaption", "targetColumns", "targetRows", "drops"],
|
|
125
|
+
"properties": {
|
|
126
|
+
"caption": { "type": "string" },
|
|
127
|
+
"header": { "type": "string" },
|
|
128
|
+
"headerCell": { "type": "string" },
|
|
129
|
+
"body": { "type": "string" },
|
|
130
|
+
"row": { "type": "string" },
|
|
131
|
+
"cell": { "type": "string" },
|
|
132
|
+
"targetCaption": { "type": "string" },
|
|
133
|
+
"targetColumns": { "type": "string" },
|
|
134
|
+
"targetRows": { "type": "string" },
|
|
135
|
+
"drops": { "type": "object", "additionalProperties": { "type": "string" } }
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
"subFlatten": {
|
|
139
|
+
"type": "object",
|
|
140
|
+
"additionalProperties": false,
|
|
141
|
+
"required": ["transparent", "asText"],
|
|
142
|
+
"properties": {
|
|
143
|
+
"transparent": { "type": "array", "items": { "$ref": "#/$defs/dspackId" } },
|
|
144
|
+
"asText": { "type": "object", "additionalProperties": { "type": "string" } }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"subCoverage": { "type": "object", "additionalProperties": { "type": "string" } }
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|