@aestheticfunction/dspack-emit 0.4.1 → 0.6.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 +1004 -222
- 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 +66 -2
- package/dist/transform/model.d.ts +368 -0
- package/dist/transform/model.js +169 -0
- package/dist/transform/parse-v2.d.ts +109 -0
- package/dist/transform/parse-v2.js +479 -0
- package/dist/transform/profile-load.d.ts +7 -6
- package/dist/transform/profile-load.js +99 -20
- package/dist/transform/profile-schema-v2.d.ts +9 -0
- package/dist/transform/profile-schema-v2.js +608 -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 +77 -0
- package/dist/transform/shadcn-v2-respelling.js +456 -0
- package/dist/transform/validate-v2.d.ts +36 -0
- package/dist/transform/validate-v2.js +136 -0
- package/dist/types.d.ts +23 -0
- package/dist/validate/ajv.js +96 -25
- package/dist/validate/meta/a2ui-catalog.meta.0_9_1.json +39 -0
- package/dist/validate/meta/a2ui-catalog.meta.1_0.json +34 -0
- package/package.json +2 -2
- package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
- package/src/a0.test.ts +235 -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 +102 -0
- package/src/functions.test.ts +182 -0
- package/src/index.ts +4 -1
- package/src/layered-dissolution.test.ts +139 -0
- package/src/profile-load.test.ts +99 -1
- package/src/profile-v2.test.ts +369 -0
- package/src/review-findings.test.ts +292 -0
- package/src/schema-mirrors.test.ts +5 -0
- package/src/surface-fidelity.test.ts +213 -0
- package/src/t1.test.ts +369 -0
- package/src/t2.test.ts +222 -0
- package/src/t3.test.ts +304 -0
- package/src/t4.test.ts +278 -0
- package/src/targets/a2ui/diagnostics.ts +136 -0
- package/src/targets/a2ui/surface.ts +1468 -235
- 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 +60 -2
- package/src/transform/model.ts +427 -0
- package/src/transform/parse-v2.ts +608 -0
- package/src/transform/profile-load.ts +104 -22
- package/src/transform/profile-schema-v2.ts +608 -0
- package/src/transform/profile.v2.schema.json +600 -0
- package/src/transform/profiles.ts +32 -1
- package/src/transform/scaffold.ts +124 -47
- package/src/transform/shadcn-v2-respelling.ts +475 -0
- package/src/transform/validate-v2.ts +174 -0
- package/src/types.ts +32 -0
- package/src/validate/ajv.ts +89 -26
- package/src/validate-v2.test.ts +173 -0
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
* Profile-as-data: load a mapping Profile from JSON.
|
|
3
3
|
*
|
|
4
4
|
* The Profile has always been pure data (profiles.ts); this module makes it
|
|
5
|
-
* *reachable* as data. `loadProfile`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* *reachable* as data. `loadProfile` dispatches EXPLICITLY on the document's
|
|
6
|
+
* `profileVersion`:
|
|
7
|
+
*
|
|
8
|
+
* "1" — the original surface-plan directive language, validated against
|
|
9
|
+
* profile.v1.schema.json. Frozen: v1 documents keep loading and
|
|
10
|
+
* emitting byte-identically, indefinitely.
|
|
11
|
+
* "2" — the primitive language, validated against profile.v2.schema.json,
|
|
12
|
+
* then every plan's `surface` block is parsed and statically checked
|
|
13
|
+
* (parse-v2.ts) so that a v2 profile that loads is a profile the
|
|
14
|
+
* engine can emit. The returned Profile is stamped `language: "v2"`,
|
|
15
|
+
* which is what keys the transform layer's fail-closed contract
|
|
16
|
+
* validation — no document is ever silently interpreted under the
|
|
17
|
+
* wrong version.
|
|
18
|
+
*
|
|
19
|
+
* Anything else refuses with a pathed finding naming the supported versions.
|
|
20
|
+
* Validation gates shape and coherence only — every judgment call (valueMaps,
|
|
21
|
+
* casualties, routes) stays with the profile's author.
|
|
10
22
|
*
|
|
11
23
|
* Toolchain: ajv draft 2020-12, `strict: false`, ajv-formats — the same
|
|
12
24
|
* convention as the catalog gates (src/validate/ajv.ts) and the dspack
|
|
@@ -15,10 +27,13 @@
|
|
|
15
27
|
import Ajv2020, { type ValidateFunction } from "ajv/dist/2020.js";
|
|
16
28
|
import addFormats from "ajv-formats";
|
|
17
29
|
import { profileSchema } from "./profile-schema.js";
|
|
18
|
-
import
|
|
30
|
+
import { profileSchemaV2 } from "./profile-schema-v2.js";
|
|
31
|
+
import { ProfileParseError, parseSurfaceV2 } from "./parse-v2.js";
|
|
32
|
+
import type { ComponentPlan, Profile } from "./profiles.js";
|
|
19
33
|
|
|
20
|
-
/** The profile
|
|
34
|
+
/** The profile schemas, as shipped (also exported for hosts that surface them in UI). */
|
|
21
35
|
export { profileSchema } from "./profile-schema.js";
|
|
36
|
+
export { profileSchemaV2 } from "./profile-schema-v2.js";
|
|
22
37
|
|
|
23
38
|
export interface ProfileLoadIssue {
|
|
24
39
|
/** JSON path into the offending document (ajv instancePath). */
|
|
@@ -27,9 +42,12 @@ export interface ProfileLoadIssue {
|
|
|
27
42
|
}
|
|
28
43
|
|
|
29
44
|
export class ProfileLoadError extends Error {
|
|
30
|
-
constructor(
|
|
45
|
+
constructor(
|
|
46
|
+
readonly issues: ProfileLoadIssue[],
|
|
47
|
+
schemaName = "profile.v1.schema.json",
|
|
48
|
+
) {
|
|
31
49
|
super(
|
|
32
|
-
`profile does not conform to
|
|
50
|
+
`profile does not conform to ${schemaName} (${issues.length} issue${issues.length === 1 ? "" : "s"}): ` +
|
|
33
51
|
issues
|
|
34
52
|
.slice(0, 3)
|
|
35
53
|
.map((i) => `${i.path || "$"}: ${i.message}`)
|
|
@@ -40,31 +58,95 @@ export class ProfileLoadError extends Error {
|
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
const compiled = new Map<string, ValidateFunction>();
|
|
44
62
|
|
|
45
|
-
function validator(): ValidateFunction {
|
|
46
|
-
|
|
63
|
+
function validator(version: "1" | "2"): ValidateFunction {
|
|
64
|
+
let v = compiled.get(version);
|
|
65
|
+
if (!v) {
|
|
47
66
|
const ajv = new Ajv2020({ strict: false, allErrors: true, validateFormats: true });
|
|
48
67
|
addFormats(ajv);
|
|
49
|
-
|
|
68
|
+
v = ajv.compile(version === "1" ? profileSchema : profileSchemaV2);
|
|
69
|
+
compiled.set(version, v);
|
|
50
70
|
}
|
|
51
|
-
return
|
|
71
|
+
return v;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ajvIssues(validate: ValidateFunction): ProfileLoadIssue[] {
|
|
75
|
+
const errors = (validate.errors ?? []) as Array<{ instancePath?: string; message?: string }>;
|
|
76
|
+
return errors.map((e) => ({ path: e.instancePath ?? "", message: e.message ?? "invalid" }));
|
|
52
77
|
}
|
|
53
78
|
|
|
54
79
|
/**
|
|
55
|
-
* Validate `json` as a
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
80
|
+
* Validate `json` as a profile document and return the engine-ready `Profile`.
|
|
81
|
+
* The `profileVersion` envelope field is stripped — it belongs to the document
|
|
82
|
+
* format, not the engine. Top-level `x-` extension keys are preserved (the
|
|
83
|
+
* engine ignores them; provenance tools may not).
|
|
59
84
|
*/
|
|
60
85
|
export function loadProfile(json: unknown): Profile {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
const errors = (validate.errors ?? []) as Array<{ instancePath?: string; message?: string }>;
|
|
86
|
+
const version = (json as { profileVersion?: unknown } | null)?.profileVersion;
|
|
87
|
+
if (version !== "1" && version !== "2") {
|
|
64
88
|
throw new ProfileLoadError(
|
|
65
|
-
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
path: "/profileVersion",
|
|
92
|
+
message: `unknown profile version ${JSON.stringify(version)} — this loader speaks "1" (surface-plan directives) and "2" (the primitive language)`,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
"any supported profile schema",
|
|
66
96
|
);
|
|
67
97
|
}
|
|
98
|
+
|
|
99
|
+
const validate = validator(version);
|
|
100
|
+
if (!validate(json)) {
|
|
101
|
+
throw new ProfileLoadError(ajvIssues(validate), `profile.v${version}.schema.json`);
|
|
102
|
+
}
|
|
103
|
+
|
|
68
104
|
const { profileVersion: _envelope, ...profile } = json as Record<string, unknown> & { profileVersion: string };
|
|
105
|
+
|
|
106
|
+
if (version === "2") {
|
|
107
|
+
// Declared function args must be SELF-CONTAINED schemas. A $ref inside
|
|
108
|
+
// them couples the function's signature to emit internals at best and, at
|
|
109
|
+
// worst, is a dangling reference that ajv defers past gate A1's compile
|
|
110
|
+
// and then throws raw out of gate A3 — pass-or-crash, never a finding.
|
|
111
|
+
// Refuse the whole class at load, with the path.
|
|
112
|
+
const functions = (profile as { functions?: Record<string, { args?: unknown }> }).functions ?? {};
|
|
113
|
+
const refIssues: ProfileLoadIssue[] = [];
|
|
114
|
+
const findRefs = (value: unknown, at: string): void => {
|
|
115
|
+
if (Array.isArray(value)) value.forEach((v, i) => findRefs(v, `${at}/${i}`));
|
|
116
|
+
else if (value && typeof value === "object") {
|
|
117
|
+
for (const [k, v] of Object.entries(value)) {
|
|
118
|
+
if (k === "$ref") refIssues.push({ path: at, message: `function args must be self-contained schemas; '$ref' is refused (found ${JSON.stringify(v)})` });
|
|
119
|
+
else findRefs(v, `${at}/${k}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
for (const [name, fn] of Object.entries(functions)) {
|
|
124
|
+
if (fn?.args) findRefs(fn.args, `/functions/${name}/args`);
|
|
125
|
+
}
|
|
126
|
+
if (refIssues.length > 0) throw new ProfileLoadError(refIssues, "profile.v2.schema.json (functions)");
|
|
127
|
+
|
|
128
|
+
// Parse every plan's surface block now, so a v2 profile that LOADS is a
|
|
129
|
+
// profile the engine can EMIT — grammar errors surface at load with
|
|
130
|
+
// pathed findings, not mid-emission.
|
|
131
|
+
const collections: Array<["components" | "synthesized", ComponentPlan[]]> = [
|
|
132
|
+
["components", (profile.components as ComponentPlan[]) ?? []],
|
|
133
|
+
["synthesized", (profile.synthesized as ComponentPlan[]) ?? []],
|
|
134
|
+
];
|
|
135
|
+
for (const [key, plans] of collections) {
|
|
136
|
+
for (const [i, plan] of plans.entries()) {
|
|
137
|
+
if (!plan.surface) continue;
|
|
138
|
+
try {
|
|
139
|
+
parseSurfaceV2(plan.surface, plan, `/${key}/${i}/surface`);
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (e instanceof ProfileParseError) {
|
|
142
|
+
throw new ProfileLoadError(e.issues, "profile.v2.schema.json (surface syntax)");
|
|
143
|
+
}
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
(profile as Record<string, unknown>).language = "v2";
|
|
149
|
+
}
|
|
150
|
+
|
|
69
151
|
return profile as unknown as Profile;
|
|
70
152
|
}
|