@aestheticfunction/dspack-emit 0.4.0 → 0.5.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 +16 -6
- package/dist/cli.js +56 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/targets/a2ui/diagnostics.d.ts +110 -0
- package/dist/targets/a2ui/diagnostics.js +94 -0
- package/dist/targets/a2ui/surface.d.ts +28 -9
- package/dist/targets/a2ui/surface.js +566 -224
- package/dist/transform/desugar.d.ts +32 -0
- package/dist/transform/desugar.js +156 -0
- package/dist/transform/emit.js +59 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/mapping.d.ts +0 -6
- package/dist/transform/mapping.js +50 -0
- package/dist/transform/model.d.ts +275 -0
- package/dist/transform/model.js +148 -0
- package/dist/transform/parse-v2.d.ts +78 -0
- package/dist/transform/parse-v2.js +305 -0
- package/dist/transform/profile-load.d.ts +8 -7
- package/dist/transform/profile-load.js +101 -24
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +430 -0
- package/dist/transform/profile-schema.d.ts +8 -0
- package/dist/transform/profile-schema.js +382 -0
- package/dist/transform/profiles.d.ts +31 -1
- package/dist/transform/scaffold.d.ts +29 -12
- package/dist/transform/scaffold.js +91 -31
- package/dist/transform/shadcn-v2-respelling.d.ts +12 -0
- package/dist/transform/shadcn-v2-respelling.js +49 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +100 -0
- package/dist/types.d.ts +19 -0
- package/dist/validate/ajv.js +98 -29
- package/dist/validate/meta/catalog-meta.d.ts +10 -0
- package/dist/validate/meta/catalog-meta.js +157 -0
- package/package.json +3 -3
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/browser-boundary.test.ts +47 -0
- package/src/byte-neutral.test.ts +246 -0
- package/src/cli.ts +60 -0
- package/src/dangling-ref.test.ts +118 -0
- package/src/desugar.test.ts +162 -0
- package/src/engine-boundary.test.ts +248 -0
- package/src/eval-fixture.test.ts +89 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +363 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +35 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +920 -242
- package/src/transform/desugar.ts +194 -0
- package/src/transform/emit.ts +65 -0
- package/src/transform/index.ts +5 -0
- package/src/transform/mapping.ts +42 -0
- package/src/transform/model.ts +325 -0
- package/src/transform/parse-v2.ts +397 -0
- package/src/transform/profile-load.ts +107 -28
- package/src/transform/profile-schema-v2.ts +430 -0
- package/src/transform/profile-schema.ts +382 -0
- package/src/transform/profile.v2.schema.json +422 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +61 -0
- package/src/transform/validate-v2.ts +138 -0
- package/src/types.ts +20 -0
- package/src/validate/ajv.ts +91 -32
- package/src/validate/meta/catalog-meta.ts +167 -0
- package/src/validate-v2.test.ts +173 -0
- package/dist/transform/profile.v1.schema.json +0 -153
- 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,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime mirror of profile.v1.schema.json. The .json file stays the
|
|
3
|
+
* reviewable schema document (docs/PROFILES.md links it); this constant
|
|
4
|
+
* exists because loadProfile must run in a browser bundle (dspack-studio
|
|
5
|
+
* composer), where readFileSync is not available. src/schema-mirrors.test.ts
|
|
6
|
+
* asserts mirror and JSON stay identical — edit both together.
|
|
7
|
+
*/
|
|
8
|
+
export const profileSchema = {
|
|
9
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
10
|
+
"$id": "https://aestheticfunction.github.io/dspack-emit/schema/profile.v1.schema.json",
|
|
11
|
+
"title": "dspack-emit a2ui Profile v1",
|
|
12
|
+
"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.",
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"patternProperties": {
|
|
16
|
+
"^x-": {}
|
|
17
|
+
},
|
|
18
|
+
"required": [
|
|
19
|
+
"profileVersion",
|
|
20
|
+
"catalogTitle",
|
|
21
|
+
"catalogDescription",
|
|
22
|
+
"catalogIdBase",
|
|
23
|
+
"instructions",
|
|
24
|
+
"primaryColorToken",
|
|
25
|
+
"components",
|
|
26
|
+
"synthesized",
|
|
27
|
+
"casualtyComponents",
|
|
28
|
+
"surfaceSynthesis"
|
|
29
|
+
],
|
|
30
|
+
"properties": {
|
|
31
|
+
"profileVersion": {
|
|
32
|
+
"const": "1"
|
|
33
|
+
},
|
|
34
|
+
"catalogTitle": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"minLength": 1
|
|
37
|
+
},
|
|
38
|
+
"catalogDescription": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"minLength": 1
|
|
41
|
+
},
|
|
42
|
+
"catalogIdBase": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"format": "uri",
|
|
45
|
+
"pattern": "^https://"
|
|
46
|
+
},
|
|
47
|
+
"instructions": {
|
|
48
|
+
"type": "string"
|
|
49
|
+
},
|
|
50
|
+
"primaryColorToken": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"additionalProperties": false,
|
|
53
|
+
"required": [
|
|
54
|
+
"category",
|
|
55
|
+
"name"
|
|
56
|
+
],
|
|
57
|
+
"properties": {
|
|
58
|
+
"category": {
|
|
59
|
+
"type": "string",
|
|
60
|
+
"minLength": 1
|
|
61
|
+
},
|
|
62
|
+
"name": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"minLength": 1
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"components": {
|
|
69
|
+
"type": "array",
|
|
70
|
+
"items": {
|
|
71
|
+
"$ref": "#/$defs/componentPlan"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"synthesized": {
|
|
75
|
+
"type": "array",
|
|
76
|
+
"items": {
|
|
77
|
+
"$ref": "#/$defs/componentPlan"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"casualtyComponents": {
|
|
81
|
+
"type": "array",
|
|
82
|
+
"items": {
|
|
83
|
+
"type": "object",
|
|
84
|
+
"additionalProperties": false,
|
|
85
|
+
"patternProperties": {
|
|
86
|
+
"^x-": {}
|
|
87
|
+
},
|
|
88
|
+
"required": [
|
|
89
|
+
"dspackId",
|
|
90
|
+
"attempted",
|
|
91
|
+
"class",
|
|
92
|
+
"reason"
|
|
93
|
+
],
|
|
94
|
+
"properties": {
|
|
95
|
+
"dspackId": {
|
|
96
|
+
"$ref": "#/$defs/dspackId"
|
|
97
|
+
},
|
|
98
|
+
"attempted": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"minLength": 1
|
|
101
|
+
},
|
|
102
|
+
"class": {
|
|
103
|
+
"enum": [
|
|
104
|
+
"maps-cleanly",
|
|
105
|
+
"synthesis-defaults",
|
|
106
|
+
"lossy",
|
|
107
|
+
"cannot-represent"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"reason": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"minLength": 1
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"intentionallyOmitted": {
|
|
118
|
+
"type": "array",
|
|
119
|
+
"items": {
|
|
120
|
+
"$ref": "#/$defs/dspackId"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"surfaceSynthesis": {
|
|
124
|
+
"type": "object",
|
|
125
|
+
"additionalProperties": false,
|
|
126
|
+
"required": [
|
|
127
|
+
"textComponent",
|
|
128
|
+
"textProp",
|
|
129
|
+
"wrapComponent",
|
|
130
|
+
"wrapChildrenProp"
|
|
131
|
+
],
|
|
132
|
+
"properties": {
|
|
133
|
+
"textComponent": {
|
|
134
|
+
"$ref": "#/$defs/a2uiName"
|
|
135
|
+
},
|
|
136
|
+
"textProp": {
|
|
137
|
+
"type": "string",
|
|
138
|
+
"minLength": 1
|
|
139
|
+
},
|
|
140
|
+
"wrapComponent": {
|
|
141
|
+
"$ref": "#/$defs/a2uiName"
|
|
142
|
+
},
|
|
143
|
+
"wrapChildrenProp": {
|
|
144
|
+
"type": "string",
|
|
145
|
+
"minLength": 1
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"$defs": {
|
|
151
|
+
"dspackId": {
|
|
152
|
+
"type": "string",
|
|
153
|
+
"pattern": "^[a-z][a-z0-9-]*$"
|
|
154
|
+
},
|
|
155
|
+
"a2uiName": {
|
|
156
|
+
"type": "string",
|
|
157
|
+
"pattern": "^[A-Z][A-Za-z0-9]*$"
|
|
158
|
+
},
|
|
159
|
+
"componentPlan": {
|
|
160
|
+
"type": "object",
|
|
161
|
+
"additionalProperties": false,
|
|
162
|
+
"patternProperties": {
|
|
163
|
+
"^x-": {}
|
|
164
|
+
},
|
|
165
|
+
"required": [
|
|
166
|
+
"a2ui",
|
|
167
|
+
"commons",
|
|
168
|
+
"structural",
|
|
169
|
+
"required"
|
|
170
|
+
],
|
|
171
|
+
"properties": {
|
|
172
|
+
"a2ui": {
|
|
173
|
+
"$ref": "#/$defs/a2uiName"
|
|
174
|
+
},
|
|
175
|
+
"dspackId": {
|
|
176
|
+
"$ref": "#/$defs/dspackId"
|
|
177
|
+
},
|
|
178
|
+
"description": {
|
|
179
|
+
"type": "string"
|
|
180
|
+
},
|
|
181
|
+
"commons": {
|
|
182
|
+
"type": "array",
|
|
183
|
+
"items": {
|
|
184
|
+
"type": "string",
|
|
185
|
+
"minLength": 1
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"structural": {
|
|
189
|
+
"type": "object",
|
|
190
|
+
"additionalProperties": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"additionalProperties": false,
|
|
193
|
+
"required": [
|
|
194
|
+
"schema",
|
|
195
|
+
"description",
|
|
196
|
+
"synthNote"
|
|
197
|
+
],
|
|
198
|
+
"properties": {
|
|
199
|
+
"schema": {},
|
|
200
|
+
"description": {
|
|
201
|
+
"type": "string",
|
|
202
|
+
"minLength": 1
|
|
203
|
+
},
|
|
204
|
+
"synthNote": {
|
|
205
|
+
"type": "string",
|
|
206
|
+
"minLength": 1
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"propMap": {
|
|
212
|
+
"type": "object",
|
|
213
|
+
"additionalProperties": {
|
|
214
|
+
"type": "object",
|
|
215
|
+
"additionalProperties": false,
|
|
216
|
+
"required": [
|
|
217
|
+
"a2ui",
|
|
218
|
+
"kind"
|
|
219
|
+
],
|
|
220
|
+
"properties": {
|
|
221
|
+
"a2ui": {
|
|
222
|
+
"type": "string",
|
|
223
|
+
"minLength": 1
|
|
224
|
+
},
|
|
225
|
+
"kind": {
|
|
226
|
+
"enum": [
|
|
227
|
+
"enum",
|
|
228
|
+
"string",
|
|
229
|
+
"boolean",
|
|
230
|
+
"number"
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
"targetEnum": {
|
|
234
|
+
"type": "array",
|
|
235
|
+
"items": {
|
|
236
|
+
"type": "string"
|
|
237
|
+
},
|
|
238
|
+
"minItems": 1
|
|
239
|
+
},
|
|
240
|
+
"valueMap": {
|
|
241
|
+
"type": "object",
|
|
242
|
+
"additionalProperties": {
|
|
243
|
+
"type": "string"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
"default": {
|
|
247
|
+
"type": "string"
|
|
248
|
+
},
|
|
249
|
+
"description": {
|
|
250
|
+
"type": "string"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"required": {
|
|
256
|
+
"type": "array",
|
|
257
|
+
"items": {
|
|
258
|
+
"type": "string"
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
"surfacePlan": {
|
|
262
|
+
"type": "object",
|
|
263
|
+
"additionalProperties": false,
|
|
264
|
+
"properties": {
|
|
265
|
+
"subText": {
|
|
266
|
+
"type": "object",
|
|
267
|
+
"additionalProperties": {
|
|
268
|
+
"type": "string"
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"subButtonText": {
|
|
272
|
+
"type": "object",
|
|
273
|
+
"additionalProperties": {
|
|
274
|
+
"type": "string"
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
"actionProp": {
|
|
278
|
+
"type": "string"
|
|
279
|
+
},
|
|
280
|
+
"textChildProp": {
|
|
281
|
+
"type": "string"
|
|
282
|
+
},
|
|
283
|
+
"textProp": {
|
|
284
|
+
"type": "string"
|
|
285
|
+
},
|
|
286
|
+
"childProp": {
|
|
287
|
+
"type": "string"
|
|
288
|
+
},
|
|
289
|
+
"childrenProp": {
|
|
290
|
+
"type": "string"
|
|
291
|
+
},
|
|
292
|
+
"structuralPassthrough": {
|
|
293
|
+
"type": "array",
|
|
294
|
+
"items": {
|
|
295
|
+
"type": "string"
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
"subTable": {
|
|
299
|
+
"type": "object",
|
|
300
|
+
"additionalProperties": false,
|
|
301
|
+
"required": [
|
|
302
|
+
"caption",
|
|
303
|
+
"header",
|
|
304
|
+
"headerCell",
|
|
305
|
+
"body",
|
|
306
|
+
"row",
|
|
307
|
+
"cell",
|
|
308
|
+
"targetCaption",
|
|
309
|
+
"targetColumns",
|
|
310
|
+
"targetRows",
|
|
311
|
+
"drops"
|
|
312
|
+
],
|
|
313
|
+
"properties": {
|
|
314
|
+
"caption": {
|
|
315
|
+
"type": "string"
|
|
316
|
+
},
|
|
317
|
+
"header": {
|
|
318
|
+
"type": "string"
|
|
319
|
+
},
|
|
320
|
+
"headerCell": {
|
|
321
|
+
"type": "string"
|
|
322
|
+
},
|
|
323
|
+
"body": {
|
|
324
|
+
"type": "string"
|
|
325
|
+
},
|
|
326
|
+
"row": {
|
|
327
|
+
"type": "string"
|
|
328
|
+
},
|
|
329
|
+
"cell": {
|
|
330
|
+
"type": "string"
|
|
331
|
+
},
|
|
332
|
+
"targetCaption": {
|
|
333
|
+
"type": "string"
|
|
334
|
+
},
|
|
335
|
+
"targetColumns": {
|
|
336
|
+
"type": "string"
|
|
337
|
+
},
|
|
338
|
+
"targetRows": {
|
|
339
|
+
"type": "string"
|
|
340
|
+
},
|
|
341
|
+
"drops": {
|
|
342
|
+
"type": "object",
|
|
343
|
+
"additionalProperties": {
|
|
344
|
+
"type": "string"
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
"subFlatten": {
|
|
350
|
+
"type": "object",
|
|
351
|
+
"additionalProperties": false,
|
|
352
|
+
"required": [
|
|
353
|
+
"transparent",
|
|
354
|
+
"asText"
|
|
355
|
+
],
|
|
356
|
+
"properties": {
|
|
357
|
+
"transparent": {
|
|
358
|
+
"type": "array",
|
|
359
|
+
"items": {
|
|
360
|
+
"$ref": "#/$defs/dspackId"
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
"asText": {
|
|
364
|
+
"type": "object",
|
|
365
|
+
"additionalProperties": {
|
|
366
|
+
"type": "string"
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
"subCoverage": {
|
|
374
|
+
"type": "object",
|
|
375
|
+
"additionalProperties": {
|
|
376
|
+
"type": "string"
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
@@ -46,6 +46,29 @@ export interface Profile {
|
|
|
46
46
|
wrapComponent: string;
|
|
47
47
|
wrapChildrenProp: string;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* A2UI catalog functions this profile declares (v2 language only), keyed by
|
|
51
|
+
* call name. Emitted into the catalog's `functions` section and enforced on
|
|
52
|
+
* every FunctionCall an instance makes: calling an undeclared function fails
|
|
53
|
+
* gate A3. Definitions are declarative schemas for the call's args — the
|
|
54
|
+
* implementations live in renderers, exactly as A2UI intends; nothing
|
|
55
|
+
* executable can be expressed here.
|
|
56
|
+
*/
|
|
57
|
+
functions?: Record<string, FunctionPlan>;
|
|
58
|
+
/**
|
|
59
|
+
* Which profile language this Profile was loaded from. Stamped by
|
|
60
|
+
* loadProfile ("v2" only); absent for v1 documents and TS-authored
|
|
61
|
+
* profiles. The transform layer keys fail-closed contract validation on it —
|
|
62
|
+
* v1 behaviour is frozen, v2 refuses what v1 merely warned about.
|
|
63
|
+
*/
|
|
64
|
+
language?: "v2";
|
|
65
|
+
}
|
|
66
|
+
/** One declared A2UI catalog function: the schema of its wire-level call. */
|
|
67
|
+
export interface FunctionPlan {
|
|
68
|
+
description: string;
|
|
69
|
+
returns: "string" | "number" | "boolean" | "array" | "object";
|
|
70
|
+
/** JSON Schema (object form) validating the call's `args`; omit when arg-less. */
|
|
71
|
+
args?: Record<string, unknown>;
|
|
49
72
|
}
|
|
50
73
|
export interface ComponentPlan {
|
|
51
74
|
a2ui: string;
|
|
@@ -61,8 +84,15 @@ export interface ComponentPlan {
|
|
|
61
84
|
propMap?: Record<string, PropPlan>;
|
|
62
85
|
/** A2UI required property names (the `component` const is added automatically). */
|
|
63
86
|
required: string[];
|
|
64
|
-
/** How the surface emitter projects a dspack-surface node onto this component. */
|
|
87
|
+
/** How the surface emitter projects a dspack-surface node onto this component (v1 language). */
|
|
65
88
|
surfacePlan?: SurfacePlanDirectives;
|
|
89
|
+
/**
|
|
90
|
+
* The v2 spelling of the same question, authored in the internal
|
|
91
|
+
* Identity / Route / Collect vocabulary (see parse-v2.ts). A plan carries
|
|
92
|
+
* one language or the other, never both — the schemas enforce it per
|
|
93
|
+
* document, and surfaceModelOf dispatches on which is present.
|
|
94
|
+
*/
|
|
95
|
+
surface?: import("./parse-v2.js").SurfaceV2;
|
|
66
96
|
/**
|
|
67
97
|
* Explicit per-sub-component disposition for compound components: every
|
|
68
98
|
* contract sub id -> one line naming how the surface emitter treats it
|
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* scaffoldProfile: a mechanical
|
|
2
|
+
* scaffoldProfile: a mechanical draft Profile from a dspack contract — in the
|
|
3
|
+
* v2 primitive language, honest about what it cannot decide.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The old scaffold had two measured failures. For props-based contracts it
|
|
6
|
+
* emitted no surface plan at all, so any surface with children hit a hard
|
|
7
|
+
* throw — catalog-valid, surface-unusable, for exactly the idiom the docs
|
|
8
|
+
* call typical. And for compounds it INVENTED the judgment it should have
|
|
9
|
+
* surfaced: every sub auto-classified transparent-or-asText from
|
|
10
|
+
* `acceptsChildren`, which is precisely the guess that is wrong for a
|
|
11
|
+
* repeated item like `radio-group-item` (the measured T2 gap).
|
|
8
12
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* This scaffold derives instead of guessing:
|
|
14
|
+
*
|
|
15
|
+
* - identity and verbatim prop projections, as before — provable 1:1;
|
|
16
|
+
* - a `children` route where the contract OBSERVABLY supports children:
|
|
17
|
+
* the component appears with child nodes in a worked example, or declares
|
|
18
|
+
* sub-components. Provenance lands in the synthNote;
|
|
19
|
+
* - a `text` route where a worked example shows the component carrying text;
|
|
20
|
+
* - sub-components are NOT decided. Each one is an explicit unresolved
|
|
21
|
+
* decision: listed in `notes`, recorded under `x-scaffold.unresolved`, and
|
|
22
|
+
* absent from the surface block — which the v2 contract gate then refuses
|
|
23
|
+
* to transform, per sub, until the author decides (route, collect,
|
|
24
|
+
* transparent, asText, or drop with a reason). A scaffold that transforms
|
|
25
|
+
* before those decisions exist would be inventing them.
|
|
26
|
+
*
|
|
27
|
+
* The result loads (loadProfile accepts it). For a contract with no compound
|
|
28
|
+
* sub-families it transforms immediately; for one with compounds, transform
|
|
29
|
+
* refuses with the exact per-sub checklist. That refusal is the deliverable:
|
|
30
|
+
* the scaffold's job is to make the remaining judgment explicit, not to
|
|
31
|
+
* pretend it has been exercised.
|
|
15
32
|
*/
|
|
16
33
|
import type { DspackDoc } from "../types.js";
|
|
17
34
|
export interface ScaffoldOptions {
|
|
@@ -32,7 +49,7 @@ export interface ScaffoldNote {
|
|
|
32
49
|
note: string;
|
|
33
50
|
}
|
|
34
51
|
export interface ScaffoldResult {
|
|
35
|
-
/** A
|
|
52
|
+
/** A v2 profile *document* (includes profileVersion; loadProfile accepts it). */
|
|
36
53
|
profile: Record<string, unknown>;
|
|
37
54
|
/** Everything that needs human judgment before the profile is trustworthy. */
|
|
38
55
|
notes: ScaffoldNote[];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { buildCatalogModel } from "../targets/json-render/model.js";
|
|
2
2
|
const DYN_STRING = { $ref: "#/$defs/DynamicString" };
|
|
3
3
|
const CHILD_LIST = { $ref: "#/$defs/ChildList" };
|
|
4
|
-
const COMP_ID = { $ref: "#/$defs/ComponentId" };
|
|
5
4
|
const TEXT_PLAN = {
|
|
6
5
|
a2ui: "Text",
|
|
7
6
|
commons: ["ComponentCommon"],
|
|
@@ -48,13 +47,44 @@ function subsOf(doc, id) {
|
|
|
48
47
|
}
|
|
49
48
|
return out;
|
|
50
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* What the contract's own worked examples show each component doing. The
|
|
52
|
+
* example corpus is the contract's definition of "expressible", which makes
|
|
53
|
+
* this measurement, not judgment: a component observed with children needs a
|
|
54
|
+
* children story; one observed with text needs a text story.
|
|
55
|
+
*/
|
|
56
|
+
function observeExamples(doc) {
|
|
57
|
+
const seen = new Map();
|
|
58
|
+
const examples = doc.examples ?? [];
|
|
59
|
+
const visit = (node, exampleId) => {
|
|
60
|
+
if (!node || typeof node !== "object")
|
|
61
|
+
return;
|
|
62
|
+
const n = node;
|
|
63
|
+
if (typeof n.component === "string") {
|
|
64
|
+
const entry = seen.get(n.component) ?? {};
|
|
65
|
+
const childNodes = [...(n.children ?? []), ...Object.values(n.slots ?? {}).flat()];
|
|
66
|
+
if (childNodes.length > 0 && entry.children === undefined)
|
|
67
|
+
entry.children = exampleId;
|
|
68
|
+
if (typeof n.text === "string" && entry.text === undefined)
|
|
69
|
+
entry.text = exampleId;
|
|
70
|
+
seen.set(n.component, entry);
|
|
71
|
+
for (const child of childNodes)
|
|
72
|
+
visit(child, exampleId);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
for (const ex of examples)
|
|
76
|
+
visit(ex.surface?.root, ex.id ?? "(unnamed example)");
|
|
77
|
+
return seen;
|
|
78
|
+
}
|
|
51
79
|
export function scaffoldProfile(doc, options) {
|
|
52
80
|
const notes = [];
|
|
53
81
|
const model = buildCatalogModel(doc, {});
|
|
54
82
|
const byId = new Map(model.components.map((c) => [c.dspackId, c]));
|
|
55
83
|
const topLevelIds = Object.keys(doc.components ?? {});
|
|
56
84
|
const name = (id) => byId.get(id)?.name ?? id;
|
|
85
|
+
const observed = observeExamples(doc);
|
|
57
86
|
const usedNames = new Set(topLevelIds.map((id) => name(id)));
|
|
87
|
+
const unresolvedByComponent = {};
|
|
58
88
|
const components = topLevelIds.map((id) => {
|
|
59
89
|
const entry = byId.get(id);
|
|
60
90
|
const contractProps = (doc.components?.[id]?.props ?? {});
|
|
@@ -82,43 +112,65 @@ export function scaffoldProfile(doc, options) {
|
|
|
82
112
|
.filter(([, p]) => p.required === true)
|
|
83
113
|
.map(([propName]) => propName)
|
|
84
114
|
.filter((propName) => propName in propMap);
|
|
115
|
+
const structural = {};
|
|
116
|
+
const routes = [];
|
|
117
|
+
const subs = subsOf(doc, id);
|
|
118
|
+
const seen = observed.get(id) ?? {};
|
|
119
|
+
// Children: only where the contract observably supports them — a worked
|
|
120
|
+
// example shows child nodes, or the component declares sub-components
|
|
121
|
+
// (whose instances arrive as its children in every surface).
|
|
122
|
+
const childrenBecause = seen.children
|
|
123
|
+
? `observed with child nodes in worked example '${seen.children}'`
|
|
124
|
+
: subs.length > 0
|
|
125
|
+
? `declares ${subs.length} sub-component(s), which arrive as its children in surfaces`
|
|
126
|
+
: undefined;
|
|
127
|
+
if (childrenBecause) {
|
|
128
|
+
structural.children = {
|
|
129
|
+
schema: CHILD_LIST,
|
|
130
|
+
description: "Child component IDs, in order.",
|
|
131
|
+
synthNote: `Scaffolded: ${childrenBecause}.`,
|
|
132
|
+
};
|
|
133
|
+
required.push("children");
|
|
134
|
+
routes.push({ from: ["children"], to: "slots:children" });
|
|
135
|
+
}
|
|
136
|
+
// Text: only where a worked example shows the component carrying it.
|
|
137
|
+
if (seen.text) {
|
|
138
|
+
structural.text = {
|
|
139
|
+
schema: DYN_STRING,
|
|
140
|
+
description: "The component's text content.",
|
|
141
|
+
synthNote: `Scaffolded: observed carrying text in worked example '${seen.text}'.`,
|
|
142
|
+
};
|
|
143
|
+
routes.push({ from: ["self.text"], to: "prop:text" });
|
|
144
|
+
}
|
|
145
|
+
if (!childrenBecause && !seen.text && Object.keys(propMap).length === 0) {
|
|
146
|
+
notes.push({
|
|
147
|
+
target: id,
|
|
148
|
+
note: "no declarative props, and never observed with children or text in a worked example; the contract likely needs enrichment before this mapping is useful.",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
85
151
|
const plan = {
|
|
86
152
|
a2ui: entry.name,
|
|
87
153
|
dspackId: id,
|
|
88
154
|
commons: ["ComponentCommon"],
|
|
89
|
-
structural
|
|
155
|
+
structural,
|
|
90
156
|
required,
|
|
91
157
|
};
|
|
92
158
|
if (Object.keys(propMap).length > 0)
|
|
93
159
|
plan.propMap = propMap;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
160
|
+
if (routes.length > 0)
|
|
161
|
+
plan.surface = { routes };
|
|
162
|
+
// Sub-components: explicit unresolved decisions, never guesses. The v2
|
|
163
|
+
// contract gate refuses to transform until each is decided — that refusal,
|
|
164
|
+
// with its per-sub checklist, is the scaffold handing judgment to its
|
|
165
|
+
// owner rather than exercising it.
|
|
100
166
|
if (subs.length > 0) {
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
});
|
|
167
|
+
unresolvedByComponent[id] = subs.map((s) => s.id);
|
|
168
|
+
for (const sub of subs) {
|
|
169
|
+
notes.push({
|
|
170
|
+
target: `${id}.${sub.id}`,
|
|
171
|
+
note: "unresolved sub-component: decide route (consume its text/label), collect (repeated items), transparent (dissolve), asText (re-identify), or drop (with a reason). transform() refuses until this is decided.",
|
|
172
|
+
});
|
|
173
|
+
}
|
|
122
174
|
}
|
|
123
175
|
return plan;
|
|
124
176
|
});
|
|
@@ -146,10 +198,10 @@ export function scaffoldProfile(doc, options) {
|
|
|
146
198
|
});
|
|
147
199
|
}
|
|
148
200
|
const profile = {
|
|
149
|
-
profileVersion: "
|
|
201
|
+
profileVersion: "2",
|
|
150
202
|
catalogTitle: options.catalogTitle ?? `${doc.name} — A2UI catalog (compiled from dspack)`,
|
|
151
203
|
catalogDescription: options.catalogDescription ??
|
|
152
|
-
`A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical
|
|
204
|
+
`A2UI catalog compiled from the ${doc.name} dspack contract by scaffoldProfile. Mechanical draft in the v2 primitive language: review the scaffold notes, and resolve every listed sub-component decision, before trusting any mapping.`,
|
|
153
205
|
catalogIdBase: options.catalogIdBase,
|
|
154
206
|
instructions: options.instructions ?? "For layout, use the Column component to organize other components.",
|
|
155
207
|
primaryColorToken,
|
|
@@ -162,6 +214,14 @@ export function scaffoldProfile(doc, options) {
|
|
|
162
214
|
wrapComponent: "Column",
|
|
163
215
|
wrapChildrenProp: "children",
|
|
164
216
|
},
|
|
217
|
+
...(Object.keys(unresolvedByComponent).length > 0
|
|
218
|
+
? {
|
|
219
|
+
"x-scaffold": {
|
|
220
|
+
unresolved: unresolvedByComponent,
|
|
221
|
+
note: "Every listed sub-component is an authoring decision the scaffold deliberately did not make. transform() refuses until each is resolved in the owning plan's surface block.",
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
: {}),
|
|
165
225
|
};
|
|
166
226
|
notes.push({
|
|
167
227
|
target: "casualtyComponents",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shadcn plans' v2 re-spelling — the six shipped v1 surface plans written
|
|
3
|
+
* in the primitive language. Byte-proven equivalent: src/profile-v2.test.ts
|
|
4
|
+
* emits every pinned artifact identically through these blocks.
|
|
5
|
+
*
|
|
6
|
+
* Shared by the keystone test and by eval/build-eval-profile.mjs, which
|
|
7
|
+
* transplants them onto a scaffold of the production v3 contract to build the
|
|
8
|
+
* reproducible coverage-evaluation fixture. One source, two consumers — the
|
|
9
|
+
* respelling is committed mapping evidence, not per-file copies.
|
|
10
|
+
*/
|
|
11
|
+
import type { SurfaceV2 } from "./parse-v2.js";
|
|
12
|
+
export declare const SHADCN_V2_SURFACES: Record<string, SurfaceV2>;
|