@sentropic/design-system-elements 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/LICENSE.THIRD-PARTY.md +4734 -0
- package/README.md +189 -2
- package/catalog.json +1234 -0
- package/dist/browser/assets/bpmn-CZlEAdL6.ttf +0 -0
- package/dist/browser/assets/bpmn-DaGVGZ7K.woff +0 -0
- package/dist/browser/assets/bpmn-DaJ2be00.woff2 +0 -0
- package/dist/browser/chunks/BpmnRenderUtil-WMCgqGDs.js +1 -0
- package/dist/browser/chunks/BpmnUpdater-C-UNbzXl.js +1 -0
- package/dist/browser/chunks/LabelUtil-7QpE43Ed.js +1 -0
- package/dist/browser/chunks/LayoutUtil-hAMJmJFU.js +1 -0
- package/dist/browser/chunks/ModelUtil-CMh7LuN4.js +1 -0
- package/dist/browser/chunks/Modeler-BfAmwsmK.js +389 -0
- package/dist/browser/chunks/Viewer-eYLzc3fD.js +4 -0
- package/dist/browser/chunks/bpmn-canvas-DeAWdJFy.js +2207 -0
- package/dist/browser/chunks/colored-CSIQaGsQ.js +1 -0
- package/dist/browser/chunks/dist-Co2MgHWm.js +1 -0
- package/dist/browser/chunks/dist-O6_2ByYB.js +1 -0
- package/dist/browser/chunks/dist-kvAYI1vo.js +1 -0
- package/dist/browser/chunks/entropic-CM5BHERN.js +2173 -0
- package/dist/browser/chunks/focus-renderer-0elVToA2.js +10 -0
- package/dist/browser/chunks/forge-B8hrW4lA.js +2173 -0
- package/dist/browser/chunks/layout-q0TR9-aY.js +1 -0
- package/dist/browser/chunks/legend-CXdfCBh6.js +1 -0
- package/dist/browser/chunks/textMetrics-BrMS6-sA.js +2 -0
- package/dist/browser/chunks/tokens-DFPpCvf1.js +1 -0
- package/dist/browser/elements.js +2221 -0
- package/dist/browser/sri.json +166 -0
- package/dist/contracts/bar-chart.d.ts +158 -0
- package/dist/contracts/bar-chart.js +117 -0
- package/dist/contracts/bpmn-canvas.d.ts +39 -0
- package/dist/contracts/bpmn-canvas.js +77 -0
- package/dist/contracts/decision-dossier.d.ts +43 -0
- package/dist/contracts/decision-dossier.js +133 -0
- package/dist/contracts/index.d.ts +28 -0
- package/dist/contracts/index.js +35 -0
- package/dist/contracts/types.d.ts +129 -0
- package/dist/contracts/types.js +16 -0
- package/dist/element/f1/f1-to-xml.d.ts +51 -0
- package/dist/element/f1/f1-to-xml.js +220 -0
- package/dist/element/markdown/minimal-markdown.d.ts +31 -0
- package/dist/element/markdown/minimal-markdown.js +98 -0
- package/dist/element/theme/theme-scoping.d.ts +27 -0
- package/dist/element/theme/theme-scoping.js +39 -0
- package/dist/generated/a2ui-common-types.d.ts +25 -0
- package/dist/generated/a2ui-common-types.js +367 -0
- package/dist/generator/canonical.d.ts +21 -0
- package/dist/generator/canonical.js +36 -0
- package/dist/generator/emit.d.ts +48 -0
- package/dist/generator/emit.js +400 -0
- package/dist/generator/main.d.ts +19 -0
- package/dist/generator/main.js +67 -0
- package/dist/generator/parity.d.ts +55 -0
- package/dist/generator/parity.js +223 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/ports/bpmn-canvas.d.ts +34 -0
- package/dist/ports/bpmn-canvas.js +36 -0
- package/dist/ports/focus.d.ts +40 -0
- package/dist/ports/focus.js +49 -0
- package/dist/ports/types.d.ts +36 -0
- package/dist/ports/types.js +12 -0
- package/dist/structure/ajv.d.ts +41 -0
- package/dist/structure/ajv.js +108 -0
- package/dist/structure/interpreter.d.ts +47 -0
- package/dist/structure/interpreter.js +576 -0
- package/dist/validate/diagnostics.d.ts +63 -0
- package/dist/validate/diagnostics.js +56 -0
- package/dist/validate/envelope.d.ts +92 -0
- package/dist/validate/envelope.js +306 -0
- package/dist/validate/index.d.ts +22 -0
- package/dist/validate/index.js +24 -0
- package/dist/validate/structure.d.ts +32 -0
- package/dist/validate/structure.js +13 -0
- package/envelope.json +43 -0
- package/package.json +54 -4
- package/schemas/BarChart.v1.json +556 -0
- package/schemas/BpmnCanvas.v1.json +139 -0
- package/schemas/DecisionDossier.v1.json +635 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalogue emitter (§5.1, §5.2): generates every committed artifact in
|
|
3
|
+
* memory from the contract modules.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline per component: ts-json-schema-generator turns the contract's
|
|
6
|
+
* props interface into an inlined fragment (functions "fail" — no function
|
|
7
|
+
* type may slip through, §4.1); the fragment is reduced to the A2UI basic
|
|
8
|
+
* catalogue entry form (`allOf` the two references, `unevaluatedProperties:
|
|
9
|
+
* false`, the local object with the `component` const); the parity guard
|
|
10
|
+
* compares the result against React, Vue and Angular; the `x-sentropic`
|
|
11
|
+
* block is assembled. The catalogue, the envelope schema and the standalone
|
|
12
|
+
* schemas are then assembled and canonically ordered (§5.1), so a
|
|
13
|
+
* regeneration without a type change produces no diff.
|
|
14
|
+
*
|
|
15
|
+
* The A2UI v0.9.1 common-types document is vendored as a generated
|
|
16
|
+
* TypeScript module (src/generated), beside a BUILT sibling `catalog.json`
|
|
17
|
+
* stub whose `anyFunction` is the empty-function-set union (`{ "not": {} }`,
|
|
18
|
+
* §5.2 `functions: {}`) — the installed SDK ships no v0_9_1 schema set, the
|
|
19
|
+
* validator needs the `ComponentCommon` graph registered under the v0.9.1
|
|
20
|
+
* URI without reading files, and no A2UI basic-catalogue function or
|
|
21
|
+
* component may validate inside an envelope (§4.1, §4.2).
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { createGenerator } from "ts-json-schema-generator";
|
|
27
|
+
import { A2UI_COMMON_TYPES_ID, CATALOG_ID, ENVELOPE_ID, contracts, standaloneId, } from "../contracts/index.js";
|
|
28
|
+
import { canonicalize, stableStringify } from "./canonical.js";
|
|
29
|
+
import { runParityGuard } from "./parity.js";
|
|
30
|
+
const JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
31
|
+
const COMPONENT_COMMON_REF = `${A2UI_COMMON_TYPES_ID}#/$defs/ComponentCommon`;
|
|
32
|
+
const CATALOG_TITLE = "Sentropic design system elements catalogue";
|
|
33
|
+
const CATALOG_DESCRIPTION = "A2UI v0.9.1 basic catalogue of the Sentropic design system elements (JSON render standard, " +
|
|
34
|
+
"spec/SPEC_EVOL_DS_JSON_RENDER_STANDARD.md §5.2). Each component carries its x-sentropic contract version, " +
|
|
35
|
+
"element name, engine, events, fallback and standalone schema id; semantic documents are validated by their " +
|
|
36
|
+
"owning runtimes (§4.3).";
|
|
37
|
+
const ENVELOPE_TITLE = "Sentropic render envelope";
|
|
38
|
+
const ENVELOPE_DESCRIPTION = "The render envelope of the JSON render standard (§4.2): one A2UI v0.9.1 component object under `root`, " +
|
|
39
|
+
"with the targeted component's contract version and an optional mode. The root interior is validated by the " +
|
|
40
|
+
"targeted component's catalogue entry, not by this schema.";
|
|
41
|
+
const CATALOG_COMPONENT_COMMON_DESCRIPTION = "The relative weight of this component within a Row or Column. This is similar to the CSS 'flex-grow' " +
|
|
42
|
+
"property. Note: this may ONLY be set when the component is a direct descendant of a Row or Column.";
|
|
43
|
+
/**
|
|
44
|
+
* The sibling `catalog.json` URI the vendored common types reference
|
|
45
|
+
* `anyFunction` by (common_types.json has exactly one reference into it,
|
|
46
|
+
* measured: `catalog.json#/$defs/anyFunction` from `FunctionCall`).
|
|
47
|
+
*/
|
|
48
|
+
const A2UI_SDK_CATALOG_ID = `${A2UI_COMMON_TYPES_ID.slice(0, A2UI_COMMON_TYPES_ID.lastIndexOf("/"))}/catalog.json`;
|
|
49
|
+
/**
|
|
50
|
+
* The literal-only override of A2UI `ComponentCommon`'s `accessibility`
|
|
51
|
+
* (§4.1, §4.2). `ComponentCommon` types it as `DynamicString`
|
|
52
|
+
* (`string | DataBinding | FunctionCall`); v1 carries data only — every
|
|
53
|
+
* property value is a literal, the envelope never carries a function, and
|
|
54
|
+
* data binding is not used — so each entry's LOCAL allOf branch closes it
|
|
55
|
+
* to literal strings with no other keys, while the two §5.2 `allOf`
|
|
56
|
+
* references stay in place.
|
|
57
|
+
*/
|
|
58
|
+
const LITERAL_ACCESSIBILITY = {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
label: { type: "string" },
|
|
62
|
+
description: { type: "string" },
|
|
63
|
+
},
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
};
|
|
66
|
+
function kebab(name) {
|
|
67
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
function sha256(bytes) {
|
|
70
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
71
|
+
}
|
|
72
|
+
/** ts-json-schema-generator on one contract module (functions "fail": §4.1 enforced mechanically). */
|
|
73
|
+
export function generateFragment(packageDir, contract) {
|
|
74
|
+
const config = {
|
|
75
|
+
path: join(packageDir, "src", "contracts", `${kebab(contract.component)}.ts`),
|
|
76
|
+
type: contract.propsTypeName,
|
|
77
|
+
tsconfig: join(packageDir, "tsconfig.json"),
|
|
78
|
+
expose: "none",
|
|
79
|
+
topRef: false,
|
|
80
|
+
jsDoc: "extended",
|
|
81
|
+
skipTypeCheck: false,
|
|
82
|
+
functions: "fail",
|
|
83
|
+
};
|
|
84
|
+
return createGenerator(config).createSchema(contract.propsTypeName);
|
|
85
|
+
}
|
|
86
|
+
/** Marker property key for embedded owner schemas (see DecisionDossierDocumentRef). */
|
|
87
|
+
const EMBEDDED_MARKER = "$sentropic.embedded";
|
|
88
|
+
/**
|
|
89
|
+
* Embeds an owner schema under `$defs.<name>` of a host document.
|
|
90
|
+
*
|
|
91
|
+
* The sha256-verified FILE is the pinned source; the EMBEDDED COPY is a
|
|
92
|
+
* documented transform of it, because both consumers of the catalogue
|
|
93
|
+
* resolve a `#/...` fragment against the HOST document, not against the
|
|
94
|
+
* embedded schema's own base:
|
|
95
|
+
* - the A2UI SDK's zod converter resolves every local ref against the entry's
|
|
96
|
+
* root document (measured: `Unresolvable schema reference: '#/$defs/...'`,
|
|
97
|
+
* and the affected entry is rebuilt from the SDK's model, losing
|
|
98
|
+
* `x-sentropic` in `toJson`);
|
|
99
|
+
* - ajv would re-base the refs on the embedded `$id`, which would break the
|
|
100
|
+
* rewritten pointers.
|
|
101
|
+
*
|
|
102
|
+
* So every internal `#/$defs/X` becomes `#/$defs/<name>/$defs/X` (valid in the
|
|
103
|
+
* catalogue AND in the standalone schema, which both carry the def at the
|
|
104
|
+
* same pointer), and the source `$id` is dropped — the schema identity stays
|
|
105
|
+
* recorded in the entry's `x-sentropic.semantic` block (schemaId + sha256).
|
|
106
|
+
*/
|
|
107
|
+
function embedOwnerSchema(name, schema) {
|
|
108
|
+
const prefix = `#/$defs/${name}/$defs/`;
|
|
109
|
+
const rewrite = (node) => {
|
|
110
|
+
if (Array.isArray(node))
|
|
111
|
+
return node.map((child) => rewrite(child));
|
|
112
|
+
if (node !== null && typeof node === "object") {
|
|
113
|
+
const copy = {};
|
|
114
|
+
for (const [key, value] of Object.entries(node)) {
|
|
115
|
+
if (key === "$ref" && typeof value === "string" && value.startsWith("#/$defs/")) {
|
|
116
|
+
copy[key] = `${prefix}${value.slice("#/$defs/".length)}`;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
copy[key] = rewrite(value);
|
|
120
|
+
}
|
|
121
|
+
return copy;
|
|
122
|
+
}
|
|
123
|
+
return node;
|
|
124
|
+
};
|
|
125
|
+
const rewritten = rewrite(schema);
|
|
126
|
+
// Only the ROOT $id is dropped: it names the source asset (kept in
|
|
127
|
+
// x-sentropic.semantic.schemaId); nested $ids, if any, stay untouched.
|
|
128
|
+
if (rewritten !== null && typeof rewritten === "object" && !Array.isArray(rewritten) && "$id" in rewritten) {
|
|
129
|
+
const copy = { ...rewritten };
|
|
130
|
+
delete copy.$id;
|
|
131
|
+
return { name, schema: copy };
|
|
132
|
+
}
|
|
133
|
+
return { name, schema: rewritten };
|
|
134
|
+
}
|
|
135
|
+
/** The pinned focus v1 schema, sha256-verified against the contract's pin. */
|
|
136
|
+
function loadEmbeddedDossierSchema(repoRoot, contract) {
|
|
137
|
+
if (contract.semantic?.sha256 === undefined) {
|
|
138
|
+
throw new Error(`${contract.component}: no semantic sha256 pin to verify the embedded schema against`);
|
|
139
|
+
}
|
|
140
|
+
const path = join(repoRoot, "node_modules", "@sentropic", "focus", "schemas", "decision-dossier-document.v1.schema.json");
|
|
141
|
+
const bytes = readFileSync(path);
|
|
142
|
+
const actual = sha256(bytes);
|
|
143
|
+
if (actual !== contract.semantic.sha256) {
|
|
144
|
+
throw new Error(`${contract.component}: the installed focus schema ${path} has sha256 ${actual}, ` +
|
|
145
|
+
`but the contract pins ${contract.semantic.sha256} — the pin or the dependency must be updated deliberately.`);
|
|
146
|
+
}
|
|
147
|
+
return embedOwnerSchema("DecisionDossierDocument", JSON.parse(bytes.toString("utf8")));
|
|
148
|
+
}
|
|
149
|
+
/** Reduce one fragment to the local object of the basic-catalogue entry form. */
|
|
150
|
+
function reduceFragment(contract, fragment, embedded, repoRoot) {
|
|
151
|
+
if (fragment === null || typeof fragment !== "object" || Array.isArray(fragment)) {
|
|
152
|
+
throw new Error(`${contract.component}: the generated fragment is not an object schema`);
|
|
153
|
+
}
|
|
154
|
+
const record = fragment;
|
|
155
|
+
const fragmentProperties = record.properties;
|
|
156
|
+
if (fragmentProperties === null || typeof fragmentProperties !== "object" || Array.isArray(fragmentProperties)) {
|
|
157
|
+
throw new Error(`${contract.component}: the generated fragment has no properties`);
|
|
158
|
+
}
|
|
159
|
+
const properties = {
|
|
160
|
+
component: { const: contract.component },
|
|
161
|
+
...fragmentProperties,
|
|
162
|
+
};
|
|
163
|
+
const requiredProps = Array.isArray(record.required)
|
|
164
|
+
? record.required.filter((name) => typeof name === "string")
|
|
165
|
+
: [];
|
|
166
|
+
// The DecisionDossier marker property is replaced by the embedded owner schema ref.
|
|
167
|
+
if (embedded !== undefined) {
|
|
168
|
+
const document = properties.document;
|
|
169
|
+
const marker = document !== null && typeof document === "object" && !Array.isArray(document)
|
|
170
|
+
? document.properties?.[EMBEDDED_MARKER]
|
|
171
|
+
: undefined;
|
|
172
|
+
if (marker === undefined) {
|
|
173
|
+
throw new Error(`${contract.component}: expected the ${EMBEDDED_MARKER} marker on the document property`);
|
|
174
|
+
}
|
|
175
|
+
properties.document = { $ref: `#/$defs/${embedded.name}` };
|
|
176
|
+
}
|
|
177
|
+
const parity = runParityGuard(contract, fragmentProperties, requiredProps, repoRoot);
|
|
178
|
+
return {
|
|
179
|
+
contract,
|
|
180
|
+
properties,
|
|
181
|
+
required: ["component", ...requiredProps],
|
|
182
|
+
parity,
|
|
183
|
+
...(embedded !== undefined ? { embedded } : {}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The basic-catalogue entry (§5.2) with its x-sentropic block. The local
|
|
188
|
+
* `allOf` branch carries the literal-only `accessibility` override (§4.1,
|
|
189
|
+
* §4.2 — see LITERAL_ACCESSIBILITY) beside the component's own props.
|
|
190
|
+
*/
|
|
191
|
+
function buildEntry(fragment) {
|
|
192
|
+
const { contract } = fragment;
|
|
193
|
+
const xSentropic = {
|
|
194
|
+
contract: contract.metadata.contract,
|
|
195
|
+
element: contract.metadata.element,
|
|
196
|
+
engine: contract.metadata.engine,
|
|
197
|
+
events: [...contract.metadata.events],
|
|
198
|
+
fallback: contract.metadata.fallback,
|
|
199
|
+
parity: fragment.parity,
|
|
200
|
+
schema: standaloneId(contract.component),
|
|
201
|
+
example: contract.example,
|
|
202
|
+
};
|
|
203
|
+
if (contract.status !== undefined)
|
|
204
|
+
xSentropic.status = contract.status;
|
|
205
|
+
if (contract.semantic !== undefined) {
|
|
206
|
+
xSentropic.semantic = {
|
|
207
|
+
source: contract.semantic.source,
|
|
208
|
+
runtimePackage: contract.semantic.runtimePackage,
|
|
209
|
+
...(contract.semantic.schemaSubpath !== undefined ? { schemaSubpath: contract.semantic.schemaSubpath } : {}),
|
|
210
|
+
...(contract.semantic.schemaId !== undefined ? { schemaId: contract.semantic.schemaId } : {}),
|
|
211
|
+
...(contract.semantic.sha256 !== undefined ? { sha256: contract.semantic.sha256 } : {}),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
type: "object",
|
|
216
|
+
allOf: [
|
|
217
|
+
{ $ref: COMPONENT_COMMON_REF },
|
|
218
|
+
{ $ref: "#/$defs/CatalogComponentCommon" },
|
|
219
|
+
{
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: { ...fragment.properties, accessibility: LITERAL_ACCESSIBILITY },
|
|
222
|
+
required: [...fragment.required],
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
unevaluatedProperties: false,
|
|
226
|
+
"x-sentropic": xSentropic,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Vendor the SDK's v0_9 common-types schema and BUILD the sibling
|
|
231
|
+
* `catalog.json` stub as the generated module under src/generated (§5.1:
|
|
232
|
+
* the generator is the single source of the committed artifacts).
|
|
233
|
+
*
|
|
234
|
+
* Only common_types.json is vendored: the catalogue's entries reference
|
|
235
|
+
* `ComponentCommon`, whose reachable graph ends at `anyFunction`, which
|
|
236
|
+
* lives in the sibling `catalog.json`. The SDK's basic catalogue that
|
|
237
|
+
* occupies that URI is deliberately NOT vendored: it would register the
|
|
238
|
+
* A2UI basic components and their 14 client-side functions, letting
|
|
239
|
+
* `FunctionCall` and `DataBinding` objects validate inside
|
|
240
|
+
* `root.accessibility` against §4.1 (the envelope never carries a
|
|
241
|
+
* function), §4.2 (literal-only values) and §5.2 (`functions: {}`). The
|
|
242
|
+
* stub carries the one `anyFunction` definition the graph needs, as the
|
|
243
|
+
* SDK itself serialises an empty function set: the empty union
|
|
244
|
+
* `{ "not": {} }` refuses every function call.
|
|
245
|
+
*/
|
|
246
|
+
function vendorA2uiSchemas(repoRoot) {
|
|
247
|
+
const sdkPackage = JSON.parse(readFileSync(join(repoRoot, "node_modules", "@a2ui", "web_core", "package.json"), "utf8"));
|
|
248
|
+
const sdkSchemasDir = join(repoRoot, "node_modules", "@a2ui", "web_core", "src", "v0_9", "schemas");
|
|
249
|
+
const commonTypesBytes = readFileSync(join(sdkSchemasDir, "common_types.json"));
|
|
250
|
+
const commonTypesOriginal = JSON.parse(commonTypesBytes.toString("utf8"));
|
|
251
|
+
const commonTypesOriginalId = commonTypesOriginal.$id;
|
|
252
|
+
if (typeof commonTypesOriginalId !== "string") {
|
|
253
|
+
throw new Error(`common_types.json from @a2ui/web_core has no $id to record`);
|
|
254
|
+
}
|
|
255
|
+
const commonTypesSha = sha256(commonTypesBytes);
|
|
256
|
+
const commonTypes = canonicalize({ ...commonTypesOriginal, $id: A2UI_COMMON_TYPES_ID });
|
|
257
|
+
const sdkCatalog = canonicalize({
|
|
258
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
259
|
+
$id: A2UI_SDK_CATALOG_ID,
|
|
260
|
+
$defs: {
|
|
261
|
+
anyFunction: { not: {} },
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
const header = [
|
|
265
|
+
"/**",
|
|
266
|
+
" * GENERATED FILE — do not edit. Regenerate with `npm run catalog:generate` in",
|
|
267
|
+
" * packages/elements (the generator is the single source, §5.1).",
|
|
268
|
+
" *",
|
|
269
|
+
" * 1. common_types.json, vendored from @a2ui/web_core@" + sdkPackage.version,
|
|
270
|
+
" * (src/v0_9/schemas — the installed SDK ships no v0_9_1 schema set; only",
|
|
271
|
+
" * v0_8, v0_9 and v1_0 exist, measured). Original $id " + commonTypesOriginalId + ",",
|
|
272
|
+
" * sha256 " + commonTypesSha + "; $id rewritten to",
|
|
273
|
+
" * " + A2UI_COMMON_TYPES_ID + " — the URI the catalogue's entries",
|
|
274
|
+
" * reference ComponentCommon by (§5.2).",
|
|
275
|
+
" *",
|
|
276
|
+
" * 2. catalog.json, BUILT (not vendored): the sibling URI common_types",
|
|
277
|
+
" * references anyFunction by (" + A2UI_SDK_CATALOG_ID + "), carrying",
|
|
278
|
+
" * the single anyFunction definition of an EMPTY function set (§5.2",
|
|
279
|
+
' * `functions: {}`): the empty union `{ "not": {} }`, exactly as the',
|
|
280
|
+
" * SDK serialises one (schema_serializer.js EMPTY_UNION). The A2UI",
|
|
281
|
+
" * basic catalogue is deliberately NOT vendored — no A2UI function or",
|
|
282
|
+
" * basic component may validate inside an envelope (§4.1, §4.2).",
|
|
283
|
+
" *",
|
|
284
|
+
" * The validator registers both documents under their $ids so every entry",
|
|
285
|
+
" * reference resolves without network or file access.",
|
|
286
|
+
" */",
|
|
287
|
+
"export const a2uiCommonTypes: Record<string, unknown> = ",
|
|
288
|
+
].join("\n");
|
|
289
|
+
const moduleText = `${header}${stableStringify(commonTypes).trimEnd()};\n\n` +
|
|
290
|
+
`export const a2uiSdkCatalogSchema: Record<string, unknown> = ${stableStringify(sdkCatalog).trimEnd()};\n`;
|
|
291
|
+
return { commonTypes, sdkCatalog, moduleText };
|
|
292
|
+
}
|
|
293
|
+
/** Generate every artifact in memory (the `--check` mode diffs these against the committed files). */
|
|
294
|
+
export function buildArtifacts(repoRoot, packageDir) {
|
|
295
|
+
const dossierContract = contracts.find((contract) => contract.component === "DecisionDossier");
|
|
296
|
+
if (dossierContract === undefined)
|
|
297
|
+
throw new Error("the DecisionDossier contract module is missing from the registry");
|
|
298
|
+
const embedded = loadEmbeddedDossierSchema(repoRoot, dossierContract);
|
|
299
|
+
const fragments = contracts.map((contract) => reduceFragment(contract, generateFragment(packageDir, contract), contract === dossierContract ? embedded : undefined, repoRoot));
|
|
300
|
+
const components = {};
|
|
301
|
+
for (const fragment of fragments)
|
|
302
|
+
components[fragment.contract.component] = buildEntry(fragment);
|
|
303
|
+
const defs = {
|
|
304
|
+
CatalogComponentCommon: {
|
|
305
|
+
type: "object",
|
|
306
|
+
properties: { weight: { type: "number", description: CATALOG_COMPONENT_COMMON_DESCRIPTION } },
|
|
307
|
+
},
|
|
308
|
+
anyComponent: { oneOf: contracts.map((contract) => ({ $ref: `#/components/${contract.component}` })) },
|
|
309
|
+
theme: { type: "object", properties: { themeId: { type: "string" } } },
|
|
310
|
+
DecisionDossierDocument: embedded.schema,
|
|
311
|
+
};
|
|
312
|
+
const catalog = {
|
|
313
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
314
|
+
$id: CATALOG_ID,
|
|
315
|
+
title: CATALOG_TITLE,
|
|
316
|
+
description: CATALOG_DESCRIPTION,
|
|
317
|
+
catalogId: CATALOG_ID,
|
|
318
|
+
components,
|
|
319
|
+
functions: {},
|
|
320
|
+
$defs: defs,
|
|
321
|
+
};
|
|
322
|
+
const envelope = {
|
|
323
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
324
|
+
$id: ENVELOPE_ID,
|
|
325
|
+
title: ENVELOPE_TITLE,
|
|
326
|
+
description: ENVELOPE_DESCRIPTION,
|
|
327
|
+
type: "object",
|
|
328
|
+
properties: {
|
|
329
|
+
catalogId: { type: "string" },
|
|
330
|
+
contract: { type: "string", pattern: "^[0-9]+\\.[0-9]+$" },
|
|
331
|
+
mode: { type: "string", enum: ["snapshot", "preview"] },
|
|
332
|
+
root: {
|
|
333
|
+
type: "object",
|
|
334
|
+
required: ["id", "component"],
|
|
335
|
+
properties: { id: { const: "root" }, component: { type: "string" } },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
required: ["contract", "root"],
|
|
339
|
+
unevaluatedProperties: false,
|
|
340
|
+
};
|
|
341
|
+
const files = [
|
|
342
|
+
{ path: "catalog.json", text: stableStringify(catalog) },
|
|
343
|
+
{ path: "envelope.json", text: stableStringify(envelope) },
|
|
344
|
+
];
|
|
345
|
+
for (const fragment of fragments) {
|
|
346
|
+
const { contract } = fragment;
|
|
347
|
+
const catalogComponentCommon = defs.CatalogComponentCommon;
|
|
348
|
+
if (catalogComponentCommon === undefined) {
|
|
349
|
+
throw new Error(`${contract.component}: cannot assemble its standalone schema (missing shared definitions)`);
|
|
350
|
+
}
|
|
351
|
+
// Built INDEPENDENTLY of the catalogue's entry object (§5.2): the
|
|
352
|
+
// standalone's component part must be EQUAL, after canonical sorting,
|
|
353
|
+
// to catalog.json#/components/<Name> — never the same in-memory
|
|
354
|
+
// reference, which would make the equivalence check a tautology.
|
|
355
|
+
const standaloneComponent = buildEntry(fragment);
|
|
356
|
+
const standaloneDefs = {
|
|
357
|
+
CatalogComponentCommon: catalogComponentCommon,
|
|
358
|
+
component: standaloneComponent,
|
|
359
|
+
};
|
|
360
|
+
if (fragment.embedded !== undefined)
|
|
361
|
+
standaloneDefs[fragment.embedded.name] = fragment.embedded.schema;
|
|
362
|
+
const standalone = {
|
|
363
|
+
$schema: JSON_SCHEMA_2020_12,
|
|
364
|
+
$id: standaloneId(contract.component),
|
|
365
|
+
title: `${contract.component} standalone envelope schema`,
|
|
366
|
+
description: `The envelope schema specialised to one component (§5.2): the §4.2 render envelope ` +
|
|
367
|
+
`(optional catalogId, contract, optional mode, root) whose root is the ${contract.component} ` +
|
|
368
|
+
`component object; its component part ($defs.component) is equivalent, after canonical sorting, ` +
|
|
369
|
+
`to catalog.json#/components/${contract.component}. Requires the A2UI common types under ` +
|
|
370
|
+
`${A2UI_COMMON_TYPES_ID}.`,
|
|
371
|
+
type: "object",
|
|
372
|
+
properties: {
|
|
373
|
+
catalogId: {
|
|
374
|
+
type: "string",
|
|
375
|
+
const: CATALOG_ID,
|
|
376
|
+
description: "Optional catalogue identifier; absent = the renderer's catalogue (§4.2).",
|
|
377
|
+
},
|
|
378
|
+
contract: {
|
|
379
|
+
type: "string",
|
|
380
|
+
pattern: "^[0-9]+\\.[0-9]+$",
|
|
381
|
+
description: "Component-contract version the producer targets (§4.2, §4.4).",
|
|
382
|
+
},
|
|
383
|
+
mode: {
|
|
384
|
+
type: "string",
|
|
385
|
+
enum: ["snapshot", "preview"],
|
|
386
|
+
description: '"snapshot" (default) | "preview" (reserved, §10.3).',
|
|
387
|
+
},
|
|
388
|
+
root: { $ref: "#/$defs/component" },
|
|
389
|
+
},
|
|
390
|
+
required: ["contract", "root"],
|
|
391
|
+
unevaluatedProperties: false,
|
|
392
|
+
$defs: standaloneDefs,
|
|
393
|
+
};
|
|
394
|
+
files.push({ path: `schemas/${contract.component}.v1.json`, text: stableStringify(standalone) });
|
|
395
|
+
}
|
|
396
|
+
const vendored = vendorA2uiSchemas(repoRoot);
|
|
397
|
+
files.push({ path: "src/generated/a2ui-common-types.ts", text: vendored.moduleText });
|
|
398
|
+
return { files };
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalogue generator CLI (§5.1).
|
|
3
|
+
*
|
|
4
|
+
* node dist/generator/main.js regenerate and write every artifact
|
|
5
|
+
* node dist/generator/main.js --check regenerate in memory and fail on
|
|
6
|
+
* any diff with the committed files
|
|
7
|
+
* (the freshness guard, run by
|
|
8
|
+
* scripts/run-script-guards.mjs)
|
|
9
|
+
* node dist/generator/main.js --check --root <dir> same check against a copy of
|
|
10
|
+
* the artifacts rooted at <dir> —
|
|
11
|
+
* the negative-test path: a mutated
|
|
12
|
+
* copy exits non-zero without
|
|
13
|
+
* touching the committed files
|
|
14
|
+
*
|
|
15
|
+
* `--root` moves only where the committed artifacts are read and written;
|
|
16
|
+
* generation always reads this package's contract modules.
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=main.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalogue generator CLI (§5.1).
|
|
3
|
+
*
|
|
4
|
+
* node dist/generator/main.js regenerate and write every artifact
|
|
5
|
+
* node dist/generator/main.js --check regenerate in memory and fail on
|
|
6
|
+
* any diff with the committed files
|
|
7
|
+
* (the freshness guard, run by
|
|
8
|
+
* scripts/run-script-guards.mjs)
|
|
9
|
+
* node dist/generator/main.js --check --root <dir> same check against a copy of
|
|
10
|
+
* the artifacts rooted at <dir> —
|
|
11
|
+
* the negative-test path: a mutated
|
|
12
|
+
* copy exits non-zero without
|
|
13
|
+
* touching the committed files
|
|
14
|
+
*
|
|
15
|
+
* `--root` moves only where the committed artifacts are read and written;
|
|
16
|
+
* generation always reads this package's contract modules.
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { mkdirSync } from "node:fs";
|
|
20
|
+
import { dirname, join, resolve } from "node:path";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { buildArtifacts } from "./emit.js";
|
|
23
|
+
const packageDir = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
24
|
+
const repoRoot = join(packageDir, "..", "..");
|
|
25
|
+
function main() {
|
|
26
|
+
const argv = process.argv.slice(2);
|
|
27
|
+
const check = argv.includes("--check");
|
|
28
|
+
const rootIndex = argv.indexOf("--root");
|
|
29
|
+
const rootArgument = rootIndex === -1 ? undefined : argv[rootIndex + 1];
|
|
30
|
+
if (rootIndex !== -1 && (rootArgument === undefined || rootArgument.startsWith("--"))) {
|
|
31
|
+
console.error("catalog: --root requires a directory argument");
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
const artifactsRoot = rootArgument === undefined ? packageDir : resolve(rootArgument);
|
|
35
|
+
const artifacts = buildArtifacts(repoRoot, packageDir);
|
|
36
|
+
if (check) {
|
|
37
|
+
const stale = [];
|
|
38
|
+
for (const file of artifacts.files) {
|
|
39
|
+
const path = join(artifactsRoot, file.path);
|
|
40
|
+
if (!existsSync(path)) {
|
|
41
|
+
stale.push(`${file.path}: missing (regenerate with "npm run catalog:generate")`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (readFileSync(path, "utf8") !== file.text) {
|
|
45
|
+
stale.push(`${file.path}: differs from the regeneration (out-of-band edit or stale artifact)`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (stale.length > 0) {
|
|
49
|
+
console.error("catalog --check: the committed artifacts are not fresh:");
|
|
50
|
+
for (const entry of stale)
|
|
51
|
+
console.error(` - ${entry}`);
|
|
52
|
+
console.error('Regenerate with "npm run catalog:generate" and commit the result.');
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
console.log(`catalog --check: ${artifacts.files.length} artifact(s) fresh.`);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
for (const file of artifacts.files) {
|
|
59
|
+
const path = join(artifactsRoot, file.path);
|
|
60
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
61
|
+
writeFileSync(path, file.text, "utf8");
|
|
62
|
+
console.log(`written: ${file.path}`);
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
process.exit(main());
|
|
67
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four-framework parity guard (§5.1): for each catalogued component, the
|
|
3
|
+
* names and JSON types of the catalogued props are compared against the
|
|
4
|
+
* public props types of the React, Vue and Angular packages. A mismatch
|
|
5
|
+
* FAILS generation (the stronger arm of §5.1); the outcome is recorded in
|
|
6
|
+
* `x-sentropic.parity` either way.
|
|
7
|
+
*
|
|
8
|
+
* React's `BarChartProps` intersects `React.HTMLAttributes<HTMLDivElement>`,
|
|
9
|
+
* so the guard first derives that DOM passthrough base mechanically (via the
|
|
10
|
+
* committed bridge `packages/elements/parity/react-html-attributes.ts`) and
|
|
11
|
+
* subtracts it: what remains must be the component's own members. The style
|
|
12
|
+
* hook is `class` everywhere except React, where the same hook is `className`
|
|
13
|
+
* — the alias is applied before the exclusion list is enforced.
|
|
14
|
+
*/
|
|
15
|
+
import type { ContractModule } from "../contracts/types.js";
|
|
16
|
+
import { type Json } from "./canonical.js";
|
|
17
|
+
export interface PropDrop {
|
|
18
|
+
readonly prop: string;
|
|
19
|
+
readonly members: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
export interface CompareOptions {
|
|
22
|
+
/** Props the contract excludes (callbacks, style hook), by source name. */
|
|
23
|
+
readonly excluded: readonly {
|
|
24
|
+
readonly prop: string;
|
|
25
|
+
}[];
|
|
26
|
+
/** Declared narrowing drops, e.g. dataLabels.format. */
|
|
27
|
+
readonly drops: readonly PropDrop[];
|
|
28
|
+
/** Top-level required props of the catalogued contract (compared too). */
|
|
29
|
+
readonly catalogRequired: readonly string[];
|
|
30
|
+
/** Top-level required props of the framework adapter, unfiltered. */
|
|
31
|
+
readonly frameworkRequired: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
export interface CompareResult {
|
|
34
|
+
readonly status: "match" | "mismatch";
|
|
35
|
+
readonly differences: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/** The guard's comparison rule, exported for its unit tests. */
|
|
38
|
+
export declare function compareJsonProps(catalogProps: Record<string, Json>, frameworkPropsInput: Record<string, Json>, options: CompareOptions): CompareResult;
|
|
39
|
+
/** The `x-sentropic.parity` row for one framework. */
|
|
40
|
+
export interface ParityRow {
|
|
41
|
+
readonly status: "match" | "mismatch" | "source-of-truth" | "no-counterpart";
|
|
42
|
+
readonly file: string;
|
|
43
|
+
readonly type?: string;
|
|
44
|
+
readonly comparedProps?: number;
|
|
45
|
+
readonly note?: string;
|
|
46
|
+
readonly differences?: readonly string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Runs the whole guard for one contract module against the committed catalog
|
|
50
|
+
* entry's props (names, JSON types AND required-ness), and returns the
|
|
51
|
+
* `x-sentropic.parity` rows. Throws on any mismatch (§5.1: the guard fails)
|
|
52
|
+
* or on a stale contract declaration.
|
|
53
|
+
*/
|
|
54
|
+
export declare function runParityGuard(contract: ContractModule, catalogProps: Record<string, Json>, catalogRequired: readonly string[], repoRoot: string): Record<string, ParityRow>;
|
|
55
|
+
//# sourceMappingURL=parity.d.ts.map
|