@aestheticfunction/dspack-emit 0.3.2 → 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 +29 -1
- 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 +7 -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/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/profile-load.test.ts +144 -0
- package/src/targets/a2ui/surface.ts +10 -0
- package/src/transform/profile-load.ts +73 -0
- package/src/transform/profile.v1.schema.json +153 -0
- 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
|
|
@@ -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
|
|
@@ -119,7 +147,7 @@ before anything reaches this emitter.
|
|
|
119
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
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scaffoldProfile: a mechanical 1:1 draft Profile from a dspack contract.
|
|
3
|
+
*
|
|
4
|
+
* Seeded from the json-render CatalogModel (the judgment-free 1:1 IR): every
|
|
5
|
+
* top-level contract component becomes a ComponentPlan with verbatim prop
|
|
6
|
+
* projections; compound sub-components get subFlatten directives derived from
|
|
7
|
+
* their *declared* `acceptsChildren` (text → asText, otherwise transparent).
|
|
8
|
+
*
|
|
9
|
+
* The scaffold invents no judgment: no valueMaps, no casualties, no lossy
|
|
10
|
+
* projections. Everything a human must review is returned as `notes` — the
|
|
11
|
+
* scaffold's analog of dspack-export's `awaitingAuthorship`. The result is a
|
|
12
|
+
* valid v1 profile document (loadProfile accepts it) whose transform passes
|
|
13
|
+
* gates A1/A2 with full coverage; whether each mapping is *right* is the
|
|
14
|
+
* author's call.
|
|
15
|
+
*/
|
|
16
|
+
import type { DspackDoc } from "../types.js";
|
|
17
|
+
export interface ScaffoldOptions {
|
|
18
|
+
/** Required: the project's catalog identity root (https URI). */
|
|
19
|
+
catalogIdBase: string;
|
|
20
|
+
catalogTitle?: string;
|
|
21
|
+
catalogDescription?: string;
|
|
22
|
+
instructions?: string;
|
|
23
|
+
/** Which token supplies theme.primaryColor; auto-detects color.primary when omitted. */
|
|
24
|
+
primaryColorToken?: {
|
|
25
|
+
category: string;
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ScaffoldNote {
|
|
30
|
+
/** What the note is about: a component id, "<id>.<prop>", or a profile field. */
|
|
31
|
+
target: string;
|
|
32
|
+
note: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ScaffoldResult {
|
|
35
|
+
/** A v1 profile *document* (includes profileVersion; loadProfile accepts it). */
|
|
36
|
+
profile: Record<string, unknown>;
|
|
37
|
+
/** Everything that needs human judgment before the profile is trustworthy. */
|
|
38
|
+
notes: ScaffoldNote[];
|
|
39
|
+
}
|
|
40
|
+
export declare function scaffoldProfile(doc: DspackDoc, options: ScaffoldOptions): ScaffoldResult;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { buildCatalogModel } from "../targets/json-render/model.js";
|
|
2
|
+
const DYN_STRING = { $ref: "#/$defs/DynamicString" };
|
|
3
|
+
const CHILD_LIST = { $ref: "#/$defs/ChildList" };
|
|
4
|
+
const COMP_ID = { $ref: "#/$defs/ComponentId" };
|
|
5
|
+
const TEXT_PLAN = {
|
|
6
|
+
a2ui: "Text",
|
|
7
|
+
commons: ["ComponentCommon"],
|
|
8
|
+
description: "Displays text content. Synthesized A2UI content primitive (not in the contract).",
|
|
9
|
+
structural: {
|
|
10
|
+
text: {
|
|
11
|
+
schema: DYN_STRING,
|
|
12
|
+
description: "The text content to display.",
|
|
13
|
+
synthNote: "A2UI content primitive required to render labels/titles in a surface.",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
propMap: {
|
|
17
|
+
variant: {
|
|
18
|
+
a2ui: "variant",
|
|
19
|
+
kind: "enum",
|
|
20
|
+
targetEnum: ["h1", "h2", "h3", "h4", "h5", "caption", "body"],
|
|
21
|
+
default: "body",
|
|
22
|
+
description: "A hint for the base text style.",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["text"],
|
|
26
|
+
};
|
|
27
|
+
const COLUMN_PLAN = {
|
|
28
|
+
a2ui: "Column",
|
|
29
|
+
commons: ["ComponentCommon"],
|
|
30
|
+
description: "Arranges children vertically. Synthesized A2UI structural primitive (the contract has no layout component).",
|
|
31
|
+
structural: {
|
|
32
|
+
children: {
|
|
33
|
+
schema: CHILD_LIST,
|
|
34
|
+
description: "Child component IDs (or a template).",
|
|
35
|
+
synthNote: "A2UI structural primitive required to compose multiple children.",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["children"],
|
|
39
|
+
};
|
|
40
|
+
function subsOf(doc, id) {
|
|
41
|
+
const composition = (doc.components?.[id]?.composition ?? {});
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const raw of composition.subComponents ?? []) {
|
|
44
|
+
if (typeof raw === "string")
|
|
45
|
+
out.push({ id: raw });
|
|
46
|
+
else if (raw && typeof raw === "object" && typeof raw.id === "string")
|
|
47
|
+
out.push(raw);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
export function scaffoldProfile(doc, options) {
|
|
52
|
+
const notes = [];
|
|
53
|
+
const model = buildCatalogModel(doc, {});
|
|
54
|
+
const byId = new Map(model.components.map((c) => [c.dspackId, c]));
|
|
55
|
+
const topLevelIds = Object.keys(doc.components ?? {});
|
|
56
|
+
const name = (id) => byId.get(id)?.name ?? id;
|
|
57
|
+
const usedNames = new Set(topLevelIds.map((id) => name(id)));
|
|
58
|
+
const components = topLevelIds.map((id) => {
|
|
59
|
+
const entry = byId.get(id);
|
|
60
|
+
const contractProps = (doc.components?.[id]?.props ?? {});
|
|
61
|
+
const propMap = {};
|
|
62
|
+
for (const prop of entry.props) {
|
|
63
|
+
if (prop.synthesized)
|
|
64
|
+
continue; // the model's universal text prop belongs to json-render, not here
|
|
65
|
+
const plan = { a2ui: prop.name, kind: prop.kind };
|
|
66
|
+
if (prop.kind === "enum")
|
|
67
|
+
plan.targetEnum = prop.values;
|
|
68
|
+
const dflt = contractProps[prop.name]?.default;
|
|
69
|
+
if (typeof dflt === "string")
|
|
70
|
+
plan.default = dflt;
|
|
71
|
+
if (prop.description)
|
|
72
|
+
plan.description = prop.description;
|
|
73
|
+
propMap[prop.name] = plan;
|
|
74
|
+
}
|
|
75
|
+
for (const excluded of entry.excludedProps) {
|
|
76
|
+
notes.push({
|
|
77
|
+
target: `${id}.${excluded.name}`,
|
|
78
|
+
note: `prop not scaffolded (${excluded.reason}); map it via a structural slot, or declare the component a casualty if it cannot be represented.`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const required = Object.entries(contractProps)
|
|
82
|
+
.filter(([, p]) => p.required === true)
|
|
83
|
+
.map(([propName]) => propName)
|
|
84
|
+
.filter((propName) => propName in propMap);
|
|
85
|
+
const plan = {
|
|
86
|
+
a2ui: entry.name,
|
|
87
|
+
dspackId: id,
|
|
88
|
+
commons: ["ComponentCommon"],
|
|
89
|
+
structural: {},
|
|
90
|
+
required,
|
|
91
|
+
};
|
|
92
|
+
if (Object.keys(propMap).length > 0)
|
|
93
|
+
plan.propMap = propMap;
|
|
94
|
+
else
|
|
95
|
+
notes.push({
|
|
96
|
+
target: id,
|
|
97
|
+
note: "no declarative props were scaffolded; the contract likely needs prop enrichment before this mapping is useful.",
|
|
98
|
+
});
|
|
99
|
+
const subs = subsOf(doc, id);
|
|
100
|
+
if (subs.length > 0) {
|
|
101
|
+
const transparent = subs.filter((s) => s.acceptsChildren !== "text").map((s) => s.id);
|
|
102
|
+
const asText = Object.fromEntries(subs.filter((s) => s.acceptsChildren === "text").map((s) => [s.id, "body"]));
|
|
103
|
+
plan.structural = {
|
|
104
|
+
child: {
|
|
105
|
+
schema: COMP_ID,
|
|
106
|
+
description: "The ID of the single child component. Wrap multiple elements in a Column and pass its ID.",
|
|
107
|
+
synthNote: "Scaffolded: the compound's sub-components flatten (subFlatten) and collapse to a single, possibly Column-wrapped, child slot.",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
plan.required.push("child");
|
|
111
|
+
plan.surfacePlan = { childProp: "child", subFlatten: { transparent, asText } };
|
|
112
|
+
plan.subCoverage = Object.fromEntries(subs.map((s) => [
|
|
113
|
+
s.id,
|
|
114
|
+
s.acceptsChildren === "text"
|
|
115
|
+
? "text -> synthesized Text (variant body) [scaffolded from acceptsChildren: text — review]"
|
|
116
|
+
: "transparent grouping: children splice inline, in order [scaffolded — review]",
|
|
117
|
+
]));
|
|
118
|
+
notes.push({
|
|
119
|
+
target: id,
|
|
120
|
+
note: `compound scaffolded from declared acceptsChildren (${subs.length} sub-components: ${transparent.length} transparent, ${Object.keys(asText).length} asText); review each subCoverage line and pick text variants.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return plan;
|
|
124
|
+
});
|
|
125
|
+
const synthesized = [];
|
|
126
|
+
for (const primitive of [TEXT_PLAN, COLUMN_PLAN]) {
|
|
127
|
+
if (usedNames.has(primitive.a2ui)) {
|
|
128
|
+
notes.push({
|
|
129
|
+
target: primitive.a2ui,
|
|
130
|
+
note: `contract already has a component named '${primitive.a2ui}'; the synthesized primitive was skipped — verify surfaceSynthesis points at a component with the expected '${primitive.a2ui === "Text" ? "text" : "children"}' prop.`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
synthesized.push(structuredClone(primitive));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let primaryColorToken = options.primaryColorToken;
|
|
138
|
+
if (!primaryColorToken) {
|
|
139
|
+
const hasColorPrimary = Boolean(doc.tokens?.color?.values?.primary);
|
|
140
|
+
primaryColorToken = { category: "color", name: "primary" };
|
|
141
|
+
notes.push({
|
|
142
|
+
target: "primaryColorToken",
|
|
143
|
+
note: hasColorPrimary
|
|
144
|
+
? "auto-detected color.primary; verify it is the intended theme primary."
|
|
145
|
+
: "defaulted to color.primary, which this contract does not define — theme.primaryColor will emit null with a warning until you point this at a real token.",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const profile = {
|
|
149
|
+
profileVersion: "1",
|
|
150
|
+
catalogTitle: options.catalogTitle ?? `${doc.name} — A2UI catalog (compiled from dspack)`,
|
|
151
|
+
catalogDescription: options.catalogDescription ??
|
|
152
|
+
`A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical 1:1 draft: review the scaffold notes before trusting any mapping.`,
|
|
153
|
+
catalogIdBase: options.catalogIdBase,
|
|
154
|
+
instructions: options.instructions ?? "For layout, use the Column component to organize other components.",
|
|
155
|
+
primaryColorToken,
|
|
156
|
+
components,
|
|
157
|
+
synthesized,
|
|
158
|
+
casualtyComponents: [],
|
|
159
|
+
surfaceSynthesis: {
|
|
160
|
+
textComponent: "Text",
|
|
161
|
+
textProp: "text",
|
|
162
|
+
wrapComponent: "Column",
|
|
163
|
+
wrapChildrenProp: "children",
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
notes.push({
|
|
167
|
+
target: "casualtyComponents",
|
|
168
|
+
note: "scaffolds never declare casualties; components that cannot be represented must be moved here by the author, with a reason.",
|
|
169
|
+
});
|
|
170
|
+
return { profile, notes };
|
|
171
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"transform": "tsx src/cli.ts",
|
|
21
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/validate/meta && cp src/validate/meta/*.json dist/validate/meta/",
|
|
21
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/validate/meta && cp src/validate/meta/*.json dist/validate/meta/ && cp src/transform/profile.v1.schema.json dist/transform/",
|
|
22
22
|
"prepare": "npm run build",
|
|
23
23
|
"build:catalogs": "tsx src/cli.ts --in input/shadcn-ui.dspack.json --a2ui-version 0.9.1 --out out && tsx src/cli.ts --in input/shadcn-ui.dspack.json --a2ui-version 1.0 --out out",
|
|
24
24
|
"test": "vitest run",
|
|
@@ -37,5 +37,8 @@
|
|
|
37
37
|
"typescript": "^5.7.2",
|
|
38
38
|
"vitest": "^2.1.8",
|
|
39
39
|
"zod": "3.25.76"
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"dspack-emit": "dist/cli.js"
|
|
40
43
|
}
|
|
41
44
|
}
|