@aestheticfunction/dspack-emit 0.4.0 → 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.
@@ -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
+ });
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Drift gate for the schema mirrors. The .json files are the reviewable
3
+ * schema documents (docs/PROFILES.md and the README link them); the TS
4
+ * mirror modules are what the runtime imports, because the library surface
5
+ * must bundle for the browser without filesystem access. Both are committed,
6
+ * so this test is what keeps them the same document: a failure here means
7
+ * one side was edited without the other.
8
+ */
9
+ import { readFileSync } from "node:fs";
10
+ import { fileURLToPath } from "node:url";
11
+ import { describe, expect, it } from "vitest";
12
+ import { catalogMetaSchemas } from "./validate/meta/catalog-meta.js";
13
+ import { profileSchema } from "./transform/profile-schema.js";
14
+
15
+ const doc = (rel: string): unknown =>
16
+ JSON.parse(readFileSync(fileURLToPath(new URL(rel, import.meta.url)), "utf8"));
17
+
18
+ describe("schema mirrors", () => {
19
+ it("catalog-meta mirror (0.9.1) equals a2ui-catalog.meta.0_9_1.json", () => {
20
+ expect(catalogMetaSchemas["0.9.1"]).toStrictEqual(doc("./validate/meta/a2ui-catalog.meta.0_9_1.json"));
21
+ });
22
+
23
+ it("catalog-meta mirror (1.0) equals a2ui-catalog.meta.1_0.json", () => {
24
+ expect(catalogMetaSchemas["1.0"]).toStrictEqual(doc("./validate/meta/a2ui-catalog.meta.1_0.json"));
25
+ });
26
+
27
+ it("profile-schema mirror equals profile.v1.schema.json", () => {
28
+ expect(profileSchema).toStrictEqual(doc("./transform/profile.v1.schema.json"));
29
+ });
30
+ });
@@ -12,12 +12,14 @@
12
12
  * convention as the catalog gates (src/validate/ajv.ts) and the dspack
13
13
  * harness.
14
14
  */
15
- import { readFileSync } from "node:fs";
16
- import { fileURLToPath } from "node:url";
17
15
  import Ajv2020, { type ValidateFunction } from "ajv/dist/2020.js";
18
16
  import addFormats from "ajv-formats";
17
+ import { profileSchema } from "./profile-schema.js";
19
18
  import type { Profile } from "./profiles.js";
20
19
 
20
+ /** The profile schema, as shipped (also exported for hosts that surface it in UI). */
21
+ export { profileSchema } from "./profile-schema.js";
22
+
21
23
  export interface ProfileLoadIssue {
22
24
  /** JSON path into the offending document (ajv instancePath). */
23
25
  path: string;
@@ -38,11 +40,6 @@ export class ProfileLoadError extends Error {
38
40
  }
39
41
  }
40
42
 
41
- const schemaPath = fileURLToPath(new URL("./profile.v1.schema.json", import.meta.url));
42
-
43
- /** The profile schema, as shipped (also exported for hosts that surface it in UI). */
44
- export const profileSchema: Record<string, unknown> = JSON.parse(readFileSync(schemaPath, "utf8"));
45
-
46
43
  let compiled: ValidateFunction | undefined;
47
44
 
48
45
  function validator(): ValidateFunction {
@@ -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: Record<string, unknown> = {
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
+ };
@@ -12,10 +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";
17
+ import { catalogMetaSchemas } from "./meta/catalog-meta.js";
19
18
  import type { A2uiCatalog, A2uiVersion, Json } from "../types.js";
20
19
 
21
20
  export interface GateResult {
@@ -31,9 +30,6 @@ export interface ValidationReport {
31
30
  gates: GateResult[];
32
31
  }
33
32
 
34
- const metaPath = (ver: A2uiVersion): string =>
35
- fileURLToPath(new URL(`./meta/a2ui-catalog.meta.${ver === "0.9.1" ? "0_9_1" : "1_0"}.json`, import.meta.url));
36
-
37
33
  function newAjv(): Ajv2020 {
38
34
  const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
39
35
  addFormats(ajv);
@@ -95,7 +91,7 @@ export function validateCatalog(
95
91
  });
96
92
 
97
93
  // Gate 2 — catalog shape.
98
- const meta = JSON.parse(readFileSync(metaPath(version), "utf8")) as Json;
94
+ const meta = catalogMetaSchemas[version];
99
95
  const validateShape = newAjv().compile(meta);
100
96
  const shapeOk = validateShape(catalog) as boolean;
101
97
  gates.push({
@@ -0,0 +1,167 @@
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
+
11
+ export const catalogMetaSchemas: Record<A2uiVersion, Json> = {
12
+ "0.9.1": {
13
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
14
+ "$id": "https://rdombrowski.dev/meta/a2ui-catalog.v0_9_1.json",
15
+ "title": "A2UI catalog shape (v0.9.1)",
16
+ "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).",
17
+ "type": "object",
18
+ "required": [
19
+ "$schema",
20
+ "$id",
21
+ "catalogId",
22
+ "title",
23
+ "description",
24
+ "components",
25
+ "$defs"
26
+ ],
27
+ "properties": {
28
+ "catalogId": {
29
+ "type": "string",
30
+ "format": "uri"
31
+ },
32
+ "$id": {
33
+ "type": "string",
34
+ "format": "uri"
35
+ },
36
+ "components": {
37
+ "type": "object",
38
+ "minProperties": 1,
39
+ "additionalProperties": {
40
+ "type": "object",
41
+ "required": [
42
+ "allOf",
43
+ "unevaluatedProperties"
44
+ ],
45
+ "properties": {
46
+ "allOf": {
47
+ "type": "array",
48
+ "minItems": 1
49
+ },
50
+ "unevaluatedProperties": {
51
+ "const": false
52
+ }
53
+ }
54
+ }
55
+ },
56
+ "$defs": {
57
+ "type": "object",
58
+ "required": [
59
+ "anyComponent",
60
+ "theme"
61
+ ],
62
+ "not": {
63
+ "required": [
64
+ "surfaceProperties"
65
+ ]
66
+ },
67
+ "properties": {
68
+ "anyComponent": {
69
+ "type": "object",
70
+ "required": [
71
+ "oneOf"
72
+ ]
73
+ },
74
+ "theme": {
75
+ "type": "object",
76
+ "required": [
77
+ "properties"
78
+ ],
79
+ "properties": {
80
+ "properties": {
81
+ "type": "object",
82
+ "required": [
83
+ "primaryColor"
84
+ ]
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ },
92
+ "1.0": {
93
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
94
+ "$id": "https://rdombrowski.dev/meta/a2ui-catalog.v1_0.json",
95
+ "title": "A2UI catalog shape (v1.0)",
96
+ "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).",
97
+ "type": "object",
98
+ "required": [
99
+ "$schema",
100
+ "$id",
101
+ "catalogId",
102
+ "title",
103
+ "description",
104
+ "components",
105
+ "$defs"
106
+ ],
107
+ "properties": {
108
+ "catalogId": {
109
+ "type": "string",
110
+ "format": "uri"
111
+ },
112
+ "$id": {
113
+ "type": "string",
114
+ "format": "uri"
115
+ },
116
+ "instructions": {
117
+ "type": "string"
118
+ },
119
+ "components": {
120
+ "type": "object",
121
+ "minProperties": 1,
122
+ "additionalProperties": {
123
+ "type": "object",
124
+ "required": [
125
+ "allOf",
126
+ "unevaluatedProperties"
127
+ ],
128
+ "properties": {
129
+ "allOf": {
130
+ "type": "array",
131
+ "minItems": 1
132
+ },
133
+ "unevaluatedProperties": {
134
+ "const": false
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "$defs": {
140
+ "type": "object",
141
+ "required": [
142
+ "anyComponent",
143
+ "surfaceProperties"
144
+ ],
145
+ "not": {
146
+ "required": [
147
+ "theme"
148
+ ]
149
+ },
150
+ "properties": {
151
+ "anyComponent": {
152
+ "type": "object",
153
+ "required": [
154
+ "oneOf"
155
+ ]
156
+ },
157
+ "surfaceProperties": {
158
+ "type": "object",
159
+ "required": [
160
+ "properties"
161
+ ]
162
+ }
163
+ }
164
+ }
165
+ }
166
+ },
167
+ };