@aestheticfunction/dspack-emit 0.3.2 → 0.4.1
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 +56 -0
- package/dist/transform/profile-schema.d.ts +8 -0
- package/dist/transform/profile-schema.js +382 -0
- package/dist/transform/scaffold.d.ts +40 -0
- package/dist/transform/scaffold.js +171 -0
- package/dist/validate/ajv.js +2 -4
- package/dist/validate/meta/catalog-meta.d.ts +10 -0
- package/dist/validate/meta/catalog-meta.js +157 -0
- package/package.json +5 -2
- package/src/browser-boundary.test.ts +47 -0
- package/src/cli.ts +35 -9
- package/src/index.ts +2 -0
- package/src/profile-load.test.ts +144 -0
- package/src/schema-mirrors.test.ts +30 -0
- package/src/targets/a2ui/surface.ts +10 -0
- package/src/transform/profile-load.ts +70 -0
- package/src/transform/profile-schema.ts +382 -0
- package/src/transform/profile.v1.schema.json +153 -0
- package/src/transform/scaffold.ts +229 -0
- package/src/validate/ajv.ts +2 -6
- package/src/validate/meta/catalog-meta.ts +167 -0
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +0 -39
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +0 -34
|
@@ -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/dist/validate/ajv.js
CHANGED
|
@@ -12,11 +12,9 @@
|
|
|
12
12
|
* 3. instance: every component instance in the hand-authored surface validates
|
|
13
13
|
* against the catalog's own #/$defs/anyComponent.
|
|
14
14
|
*/
|
|
15
|
-
import { readFileSync } from "node:fs";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
15
|
import Ajv2020 from "ajv/dist/2020.js";
|
|
18
16
|
import addFormats from "ajv-formats";
|
|
19
|
-
|
|
17
|
+
import { catalogMetaSchemas } from "./meta/catalog-meta.js";
|
|
20
18
|
function newAjv() {
|
|
21
19
|
const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
|
|
22
20
|
addFormats(ajv);
|
|
@@ -77,7 +75,7 @@ export function validateCatalog(catalog, version, surface) {
|
|
|
77
75
|
errors: exts.length ? [...new Set(exts)] : undefined,
|
|
78
76
|
});
|
|
79
77
|
// Gate 2 — catalog shape.
|
|
80
|
-
const meta =
|
|
78
|
+
const meta = catalogMetaSchemas[version];
|
|
81
79
|
const validateShape = newAjv().compile(meta);
|
|
82
80
|
const shapeOk = validateShape(catalog);
|
|
83
81
|
gates.push({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime mirrors of the catalog-shape meta-schemas. The .json files beside
|
|
3
|
+
* this module stay the reviewable documents (README points reviewers at
|
|
4
|
+
* src/validate/meta/); these constants exist because validateCatalog must run
|
|
5
|
+
* in a browser bundle (dspack-studio composer), where readFileSync is not
|
|
6
|
+
* available. src/schema-mirrors.test.ts asserts mirror and JSON stay
|
|
7
|
+
* identical — edit both together.
|
|
8
|
+
*/
|
|
9
|
+
import type { A2uiVersion, Json } from "../../types.js";
|
|
10
|
+
export declare const catalogMetaSchemas: Record<A2uiVersion, Json>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const catalogMetaSchemas = {
|
|
2
|
+
"0.9.1": {
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4
|
+
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v0_9_1.json",
|
|
5
|
+
"title": "A2UI catalog shape (v0.9.1)",
|
|
6
|
+
"description": "Structural invariants an A2UI v0.9.1 catalog must satisfy, derived from the checked-in basic catalog fixture. The version-distinguishing requirement is $defs.theme (with primaryColor).",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"required": [
|
|
9
|
+
"$schema",
|
|
10
|
+
"$id",
|
|
11
|
+
"catalogId",
|
|
12
|
+
"title",
|
|
13
|
+
"description",
|
|
14
|
+
"components",
|
|
15
|
+
"$defs"
|
|
16
|
+
],
|
|
17
|
+
"properties": {
|
|
18
|
+
"catalogId": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"format": "uri"
|
|
21
|
+
},
|
|
22
|
+
"$id": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"format": "uri"
|
|
25
|
+
},
|
|
26
|
+
"components": {
|
|
27
|
+
"type": "object",
|
|
28
|
+
"minProperties": 1,
|
|
29
|
+
"additionalProperties": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"required": [
|
|
32
|
+
"allOf",
|
|
33
|
+
"unevaluatedProperties"
|
|
34
|
+
],
|
|
35
|
+
"properties": {
|
|
36
|
+
"allOf": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"minItems": 1
|
|
39
|
+
},
|
|
40
|
+
"unevaluatedProperties": {
|
|
41
|
+
"const": false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"$defs": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"required": [
|
|
49
|
+
"anyComponent",
|
|
50
|
+
"theme"
|
|
51
|
+
],
|
|
52
|
+
"not": {
|
|
53
|
+
"required": [
|
|
54
|
+
"surfaceProperties"
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
"properties": {
|
|
58
|
+
"anyComponent": {
|
|
59
|
+
"type": "object",
|
|
60
|
+
"required": [
|
|
61
|
+
"oneOf"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"theme": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"required": [
|
|
67
|
+
"properties"
|
|
68
|
+
],
|
|
69
|
+
"properties": {
|
|
70
|
+
"properties": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"required": [
|
|
73
|
+
"primaryColor"
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"1.0": {
|
|
83
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
84
|
+
"$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
|
|
85
|
+
"title": "A2UI catalog shape (v1.0)",
|
|
86
|
+
"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).",
|
|
87
|
+
"type": "object",
|
|
88
|
+
"required": [
|
|
89
|
+
"$schema",
|
|
90
|
+
"$id",
|
|
91
|
+
"catalogId",
|
|
92
|
+
"title",
|
|
93
|
+
"description",
|
|
94
|
+
"components",
|
|
95
|
+
"$defs"
|
|
96
|
+
],
|
|
97
|
+
"properties": {
|
|
98
|
+
"catalogId": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"format": "uri"
|
|
101
|
+
},
|
|
102
|
+
"$id": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"format": "uri"
|
|
105
|
+
},
|
|
106
|
+
"instructions": {
|
|
107
|
+
"type": "string"
|
|
108
|
+
},
|
|
109
|
+
"components": {
|
|
110
|
+
"type": "object",
|
|
111
|
+
"minProperties": 1,
|
|
112
|
+
"additionalProperties": {
|
|
113
|
+
"type": "object",
|
|
114
|
+
"required": [
|
|
115
|
+
"allOf",
|
|
116
|
+
"unevaluatedProperties"
|
|
117
|
+
],
|
|
118
|
+
"properties": {
|
|
119
|
+
"allOf": {
|
|
120
|
+
"type": "array",
|
|
121
|
+
"minItems": 1
|
|
122
|
+
},
|
|
123
|
+
"unevaluatedProperties": {
|
|
124
|
+
"const": false
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"$defs": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"required": [
|
|
132
|
+
"anyComponent",
|
|
133
|
+
"surfaceProperties"
|
|
134
|
+
],
|
|
135
|
+
"not": {
|
|
136
|
+
"required": [
|
|
137
|
+
"theme"
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"properties": {
|
|
141
|
+
"anyComponent": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"required": [
|
|
144
|
+
"oneOf"
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
"surfaceProperties": {
|
|
148
|
+
"type": "object",
|
|
149
|
+
"required": [
|
|
150
|
+
"properties"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aestheticfunction/dspack-emit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
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
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safety boundary gate (mirrors dspack-gen's core-boundary test):
|
|
3
|
+
* the library surface — src/transform, src/validate, src/targets — must be
|
|
4
|
+
* bundleable for the browser, because the dspack-studio composer runs
|
|
5
|
+
* `transformFromJson`, `validateCatalog`, and `loadProfile` in-page for live
|
|
6
|
+
* fidelity feedback. No module in these directories may import a Node
|
|
7
|
+
* built-in (`node:*` or bare-specifier form); schema documents reach the
|
|
8
|
+
* runtime through committed TS mirrors, not readFileSync.
|
|
9
|
+
*
|
|
10
|
+
* src/cli.ts is deliberately out of scope: it is the Node CLI and owns all
|
|
11
|
+
* filesystem I/O. Tests may use node:fs freely (they run under vitest).
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { describe, expect, it } from "vitest";
|
|
16
|
+
|
|
17
|
+
const BOUNDARY_DIRS = ["src/transform", "src/validate", "src/targets"];
|
|
18
|
+
|
|
19
|
+
// Bare-specifier built-ins that would slip past a `node:` prefix check.
|
|
20
|
+
const BARE_BUILTINS = new Set([
|
|
21
|
+
"fs", "path", "url", "os", "crypto", "util", "stream", "buffer",
|
|
22
|
+
"http", "https", "net", "tls", "child_process", "worker_threads",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const files = BOUNDARY_DIRS.flatMap((dir) =>
|
|
26
|
+
readdirSync(dir, { recursive: true })
|
|
27
|
+
.map(String)
|
|
28
|
+
.filter((f) => f.endsWith(".ts") && !f.endsWith(".test.ts"))
|
|
29
|
+
.map((f) => join(dir, f)),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
describe("browser boundary", () => {
|
|
33
|
+
it("covers the library modules", () => {
|
|
34
|
+
expect(files.length).toBeGreaterThanOrEqual(10);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.each(files)("%s imports no Node built-ins", (file) => {
|
|
38
|
+
const source = readFileSync(file, "utf8");
|
|
39
|
+
const imports = [...source.matchAll(/from\s+"([^"]+)"|import\s*\(\s*"([^"]+)"\s*\)|require\s*\(\s*"([^"]+)"\s*\)/g)].map(
|
|
40
|
+
(m) => m[1] ?? m[2] ?? m[3],
|
|
41
|
+
);
|
|
42
|
+
for (const specifier of imports) {
|
|
43
|
+
expect(specifier.startsWith("node:"), `${file} imports ${specifier}`).toBe(false);
|
|
44
|
+
expect(BARE_BUILTINS.has(specifier), `${file} imports Node built-in ${specifier}`).toBe(false);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/cli.ts
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
|
|
@@ -25,6 +32,8 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
25
32
|
import { basename, join, resolve } from "node:path";
|
|
26
33
|
import type { A2uiVersion, DspackDoc, DspackSurface } from "./types.js";
|
|
27
34
|
import { transform } from "./transform/index.js";
|
|
35
|
+
import { shadcnProfile, type Profile } from "./transform/profiles.js";
|
|
36
|
+
import { loadProfile, ProfileLoadError } from "./transform/profile-load.js";
|
|
28
37
|
import { emitSurface, EmitSurfaceError } from "./targets/a2ui/surface.js";
|
|
29
38
|
import { generateJsonRenderModules } from "./targets/json-render/codegen.js";
|
|
30
39
|
import { emitJsonRenderSpec, EmitJsonRenderError, validateSpecAgainstModel } from "./targets/json-render/emit.js";
|
|
@@ -34,7 +43,8 @@ interface Args {
|
|
|
34
43
|
in: string;
|
|
35
44
|
version: A2uiVersion;
|
|
36
45
|
out: string;
|
|
37
|
-
surface
|
|
46
|
+
surface?: string;
|
|
47
|
+
profile?: string;
|
|
38
48
|
emitSurface?: string;
|
|
39
49
|
strictCoverage: boolean;
|
|
40
50
|
}
|
|
@@ -73,12 +83,16 @@ function parseArgs(argv: string[]): Args {
|
|
|
73
83
|
}
|
|
74
84
|
const input = m.get("in");
|
|
75
85
|
if (!input) fail("--in <dspack.json> is required");
|
|
86
|
+
const profile = m.get("profile");
|
|
76
87
|
return {
|
|
77
88
|
target,
|
|
78
89
|
in: input!,
|
|
79
90
|
version: (version ?? "0.9.1") as A2uiVersion,
|
|
80
91
|
out: m.get("out") ?? "out",
|
|
81
|
-
|
|
92
|
+
// The sample-surface default is a repo-relative fixture; external callers
|
|
93
|
+
// (--profile) get a vacuous A3 unless they pass --surface/--emit-surface.
|
|
94
|
+
surface: m.get("surface") ?? (profile ? undefined : "surface/settings-card.surface.json"),
|
|
95
|
+
profile,
|
|
82
96
|
emitSurface: m.get("emit-surface"),
|
|
83
97
|
strictCoverage: m.get("strict-coverage") === "true",
|
|
84
98
|
};
|
|
@@ -141,9 +155,21 @@ function main(): void {
|
|
|
141
155
|
jsonRenderMain(args, doc);
|
|
142
156
|
return;
|
|
143
157
|
}
|
|
144
|
-
|
|
158
|
+
let profile: Profile = shadcnProfile;
|
|
159
|
+
if (args.profile) {
|
|
160
|
+
try {
|
|
161
|
+
profile = loadProfile(JSON.parse(readFileSync(resolve(args.profile), "utf8")));
|
|
162
|
+
} catch (e) {
|
|
163
|
+
if (e instanceof ProfileLoadError) {
|
|
164
|
+
console.error(`error: --profile ${args.profile}: ${e.message}`);
|
|
165
|
+
process.exit(2);
|
|
166
|
+
}
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const surface = args.surface ? JSON.parse(readFileSync(resolve(args.surface), "utf8")) : { messages: [] };
|
|
145
171
|
|
|
146
|
-
const { catalog, mapping, validation, report } = transform(doc, args.version, surface);
|
|
172
|
+
const { catalog, mapping, validation, report } = transform(doc, args.version, surface, profile);
|
|
147
173
|
|
|
148
174
|
mkdirSync(resolve(args.out), { recursive: true });
|
|
149
175
|
const base = resolve(args.out);
|
|
@@ -169,7 +195,7 @@ function main(): void {
|
|
|
169
195
|
const csr = JSON.parse(readFileSync(resolve(args.emitSurface), "utf8")) as DspackSurface;
|
|
170
196
|
let emitted;
|
|
171
197
|
try {
|
|
172
|
-
emitted = emitSurface(csr, doc);
|
|
198
|
+
emitted = emitSurface(csr, doc, { profile });
|
|
173
199
|
} catch (e) {
|
|
174
200
|
if (e instanceof EmitSurfaceError) {
|
|
175
201
|
console.error(`${tag} EMIT-SURFACE FAILED: ${e.message}`);
|
|
@@ -183,7 +209,7 @@ function main(): void {
|
|
|
183
209
|
for (const w of emitted.warnings) console.log(`${tag} note ${w.code}: ${w.message}`);
|
|
184
210
|
// Gate A3 over the emitted surface: its instances must validate against the
|
|
185
211
|
// catalog generated in this same run.
|
|
186
|
-
const check = transform(doc, args.version, { messages: emitted.messages });
|
|
212
|
+
const check = transform(doc, args.version, { messages: emitted.messages }, profile);
|
|
187
213
|
const instanceGate = check.validation.gates.find((g) => g.name === "instance");
|
|
188
214
|
console.log(`${tag} emitted surface -> ${outPath}`);
|
|
189
215
|
console.log(`${tag} ${instanceGate?.pass ? "PASS" : "FAIL"} instance (emitted surface vs generated catalog)`);
|
package/src/index.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 {
|
|
12
14
|
emitSurface,
|