@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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE.THIRD-PARTY.md +4734 -0
  3. package/README.md +189 -2
  4. package/catalog.json +1234 -0
  5. package/dist/browser/assets/bpmn-CZlEAdL6.ttf +0 -0
  6. package/dist/browser/assets/bpmn-DaGVGZ7K.woff +0 -0
  7. package/dist/browser/assets/bpmn-DaJ2be00.woff2 +0 -0
  8. package/dist/browser/chunks/BpmnRenderUtil-WMCgqGDs.js +1 -0
  9. package/dist/browser/chunks/BpmnUpdater-C-UNbzXl.js +1 -0
  10. package/dist/browser/chunks/LabelUtil-7QpE43Ed.js +1 -0
  11. package/dist/browser/chunks/LayoutUtil-hAMJmJFU.js +1 -0
  12. package/dist/browser/chunks/ModelUtil-CMh7LuN4.js +1 -0
  13. package/dist/browser/chunks/Modeler-BfAmwsmK.js +389 -0
  14. package/dist/browser/chunks/Viewer-eYLzc3fD.js +4 -0
  15. package/dist/browser/chunks/bpmn-canvas-DeAWdJFy.js +2207 -0
  16. package/dist/browser/chunks/colored-CSIQaGsQ.js +1 -0
  17. package/dist/browser/chunks/dist-Co2MgHWm.js +1 -0
  18. package/dist/browser/chunks/dist-O6_2ByYB.js +1 -0
  19. package/dist/browser/chunks/dist-kvAYI1vo.js +1 -0
  20. package/dist/browser/chunks/entropic-CM5BHERN.js +2173 -0
  21. package/dist/browser/chunks/focus-renderer-0elVToA2.js +10 -0
  22. package/dist/browser/chunks/forge-B8hrW4lA.js +2173 -0
  23. package/dist/browser/chunks/layout-q0TR9-aY.js +1 -0
  24. package/dist/browser/chunks/legend-CXdfCBh6.js +1 -0
  25. package/dist/browser/chunks/textMetrics-BrMS6-sA.js +2 -0
  26. package/dist/browser/chunks/tokens-DFPpCvf1.js +1 -0
  27. package/dist/browser/elements.js +2221 -0
  28. package/dist/browser/sri.json +166 -0
  29. package/dist/contracts/bar-chart.d.ts +158 -0
  30. package/dist/contracts/bar-chart.js +117 -0
  31. package/dist/contracts/bpmn-canvas.d.ts +39 -0
  32. package/dist/contracts/bpmn-canvas.js +77 -0
  33. package/dist/contracts/decision-dossier.d.ts +43 -0
  34. package/dist/contracts/decision-dossier.js +133 -0
  35. package/dist/contracts/index.d.ts +28 -0
  36. package/dist/contracts/index.js +35 -0
  37. package/dist/contracts/types.d.ts +129 -0
  38. package/dist/contracts/types.js +16 -0
  39. package/dist/element/f1/f1-to-xml.d.ts +51 -0
  40. package/dist/element/f1/f1-to-xml.js +220 -0
  41. package/dist/element/markdown/minimal-markdown.d.ts +31 -0
  42. package/dist/element/markdown/minimal-markdown.js +98 -0
  43. package/dist/element/theme/theme-scoping.d.ts +27 -0
  44. package/dist/element/theme/theme-scoping.js +39 -0
  45. package/dist/generated/a2ui-common-types.d.ts +25 -0
  46. package/dist/generated/a2ui-common-types.js +367 -0
  47. package/dist/generator/canonical.d.ts +21 -0
  48. package/dist/generator/canonical.js +36 -0
  49. package/dist/generator/emit.d.ts +48 -0
  50. package/dist/generator/emit.js +400 -0
  51. package/dist/generator/main.d.ts +19 -0
  52. package/dist/generator/main.js +67 -0
  53. package/dist/generator/parity.d.ts +55 -0
  54. package/dist/generator/parity.js +223 -0
  55. package/dist/index.d.ts +11 -0
  56. package/dist/index.js +10 -0
  57. package/dist/ports/bpmn-canvas.d.ts +34 -0
  58. package/dist/ports/bpmn-canvas.js +36 -0
  59. package/dist/ports/focus.d.ts +40 -0
  60. package/dist/ports/focus.js +49 -0
  61. package/dist/ports/types.d.ts +36 -0
  62. package/dist/ports/types.js +12 -0
  63. package/dist/structure/ajv.d.ts +41 -0
  64. package/dist/structure/ajv.js +108 -0
  65. package/dist/structure/interpreter.d.ts +47 -0
  66. package/dist/structure/interpreter.js +576 -0
  67. package/dist/validate/diagnostics.d.ts +63 -0
  68. package/dist/validate/diagnostics.js +56 -0
  69. package/dist/validate/envelope.d.ts +92 -0
  70. package/dist/validate/envelope.js +306 -0
  71. package/dist/validate/index.d.ts +22 -0
  72. package/dist/validate/index.js +24 -0
  73. package/dist/validate/structure.d.ts +32 -0
  74. package/dist/validate/structure.js +13 -0
  75. package/envelope.json +43 -0
  76. package/package.json +54 -4
  77. package/schemas/BarChart.v1.json +556 -0
  78. package/schemas/BpmnCanvas.v1.json +139 -0
  79. package/schemas/DecisionDossier.v1.json +635 -0
@@ -0,0 +1,576 @@
1
+ /**
2
+ * The eval-free structure seam (§4.3, §6.4): a JSON Schema 2020-12
3
+ * interpreter over the same registered documents as the ajv bridge
4
+ * (`src/structure/ajv.ts`), for hosts whose CSP forbids `eval` and the
5
+ * `Function` constructor — the browser core chunk (§6.2, §6.4).
6
+ *
7
+ * ajv materialises every compiled validator through `new Function`, so the
8
+ * DEFAULT seam cannot run under the pilot and strict CSP rows of §6.4: the
9
+ * compiled meta-schema itself trips the policy at validator creation, before
10
+ * any envelope is seen. This module validates the SAME documents — the
11
+ * committed catalogue, the envelope schema, the vendored A2UI common types
12
+ * and the built `catalog.json` stub (§5.2) — with a plain recursive
13
+ * interpreter: no code generation, no host-global trick, nothing the CSP can
14
+ * refuse. It implements exactly the keyword surface the committed documents
15
+ * use (measured: `$ref`, `type`, `enum`, `const`, `pattern`, `properties`,
16
+ * `required`, `additionalProperties`, `unevaluatedProperties`, `items`,
17
+ * `minItems`, `maxItems`, `allOf`, `anyOf`, `oneOf`, `not`) and REFUSES
18
+ * CONSTRUCTION when a registered document grows a standard 2020-12 keyword
19
+ * outside that set, or any UNKNOWN keyword at all, so a catalogue change
20
+ * cannot silently weaken the browser validation. The only allowed
21
+ * non-standard keys are the explicitly allowlisted annotation and
22
+ * catalogue-container keys (`ANNOTATION_KEYWORDS`, including `x-*`);
23
+ * anything else throws at construction (review 1, B3) — never silently
24
+ * ignored.
25
+ *
26
+ * Equivalence with the ajv bridge is pinned by `tests/structure-interpreter
27
+ * .test.ts` (issue-for-issue on the catalogue corpus) and by
28
+ * `tests/structure-differential.test.ts` (same verdicts and same failing
29
+ * pointer/keyword sets on both seams over the examples, the catalogue-test
30
+ * mutations, the B1–B6 reproductions and a seeded generated corpus).
31
+ */
32
+ import { a2uiSdkCatalogSchema } from "../generated/a2ui-common-types.js";
33
+ /** The keywords this interpreter implements (the committed documents' surface). */
34
+ const IMPLEMENTED_KEYWORDS = new Set([
35
+ "$ref",
36
+ "type",
37
+ "enum",
38
+ "const",
39
+ "pattern",
40
+ "properties",
41
+ "required",
42
+ "additionalProperties",
43
+ "unevaluatedProperties",
44
+ "items",
45
+ "minItems",
46
+ "maxItems",
47
+ "allOf",
48
+ "anyOf",
49
+ "oneOf",
50
+ "not",
51
+ ]);
52
+ /** Keys that never affect validation (identifiers and annotations). */
53
+ const ANNOTATION_KEYWORDS = new Set([
54
+ "$schema",
55
+ "$id",
56
+ "$defs",
57
+ "$anchor",
58
+ "$dynamicAnchor",
59
+ "$comment",
60
+ "$vocabulary",
61
+ "title",
62
+ "description",
63
+ "default",
64
+ "examples",
65
+ "example",
66
+ "note",
67
+ "deprecated",
68
+ "readOnly",
69
+ "writeOnly",
70
+ // A2UI catalogue container keys: the catalogue document's own shape
71
+ // (§5.2), never a JSON Schema validation keyword. Allowed here so the
72
+ // drift gate audits the schemas they CONTAIN without refusing the
73
+ // container itself; any other unknown key still throws (B3).
74
+ "catalogId",
75
+ "components",
76
+ "functions",
77
+ "x-sentropic",
78
+ ]);
79
+ /** Standard 2020-12 VALIDATION keywords this interpreter does not implement. */
80
+ const UNSUPPORTED_STANDARD_KEYWORDS = new Set([
81
+ "multipleOf",
82
+ "maximum",
83
+ "exclusiveMaximum",
84
+ "minimum",
85
+ "exclusiveMinimum",
86
+ "maxLength",
87
+ "minLength",
88
+ "maxProperties",
89
+ "minProperties",
90
+ "uniqueItems",
91
+ "contains",
92
+ "maxContains",
93
+ "minContains",
94
+ "patternProperties",
95
+ "dependentRequired",
96
+ "dependentSchemas",
97
+ "propertyNames",
98
+ "prefixItems",
99
+ "unevaluatedItems",
100
+ "if",
101
+ "then",
102
+ "else",
103
+ "definitions",
104
+ "$dynamicRef",
105
+ "$recursiveRef",
106
+ ]);
107
+ function isPlainObject(value) {
108
+ return typeof value === "object" && value !== null && !Array.isArray(value);
109
+ }
110
+ /** One RFC 6901 token, escaped (~ before /). */
111
+ function escapeToken(token) {
112
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
113
+ }
114
+ /** Deep equality over JSON values (enum and const payloads). */
115
+ function jsonEqual(left, right) {
116
+ if (left === right)
117
+ return true;
118
+ if (!isPlainObject(left) && !Array.isArray(left))
119
+ return false;
120
+ if (Array.isArray(left)) {
121
+ if (!Array.isArray(right) || left.length !== right.length)
122
+ return false;
123
+ return left.every((item, index) => jsonEqual(item, right[index]));
124
+ }
125
+ if (!isPlainObject(right))
126
+ return false;
127
+ const leftKeys = Object.keys(left);
128
+ const rightKeys = Object.keys(right);
129
+ if (leftKeys.length !== rightKeys.length)
130
+ return false;
131
+ return leftKeys.every((key) => Object.hasOwn(right, key) && jsonEqual(left[key], right[key]));
132
+ }
133
+ /** Whether `data` matches one declared `type` name (2020-12 semantics). */
134
+ function typeMatches(declared, data) {
135
+ switch (declared) {
136
+ case "object":
137
+ return isPlainObject(data);
138
+ case "array":
139
+ return Array.isArray(data);
140
+ case "string":
141
+ return typeof data === "string";
142
+ case "number":
143
+ return typeof data === "number";
144
+ case "integer":
145
+ return typeof data === "number" && Number.isInteger(data);
146
+ case "boolean":
147
+ return typeof data === "boolean";
148
+ case "null":
149
+ return data === null;
150
+ default:
151
+ return true;
152
+ }
153
+ }
154
+ /**
155
+ * The registered documents, each under its `$id` — the same registration
156
+ * set as the ajv bridge: common types, the built `catalog.json` stub
157
+ * (whose single `anyFunction` definition is the empty function set,
158
+ * `{ "not": {} }`), the catalogue, and the envelope schema.
159
+ */
160
+ class DocumentRegistry {
161
+ #documents = new Map();
162
+ register(schema, label) {
163
+ if (!isPlainObject(schema) || typeof schema.$id !== "string" || schema.$id.length === 0) {
164
+ throw new Error(`the ${label} must carry its $id so every $ref resolves without network access`);
165
+ }
166
+ this.#documents.set(schema.$id, schema);
167
+ return schema.$id;
168
+ }
169
+ /** Resolves one `$ref` against the base document it appears in. */
170
+ resolve(ref, baseId) {
171
+ const hashIndex = ref.indexOf("#");
172
+ const documentPart = hashIndex === -1 ? ref : ref.slice(0, hashIndex);
173
+ const pointerPart = hashIndex === -1 ? "" : ref.slice(hashIndex + 1);
174
+ let documentId = baseId;
175
+ if (documentPart.length > 0) {
176
+ documentId = /^[a-z][a-z0-9+.-]*:/i.test(documentPart)
177
+ ? documentPart
178
+ : joinSibling(baseId, documentPart);
179
+ }
180
+ const document = this.#documents.get(documentId);
181
+ if (document === undefined) {
182
+ throw new Error(`the $ref "${ref}" does not name a registered document (from ${baseId})`);
183
+ }
184
+ const schema = pointerPart.length === 0 ? document : pointerLookup(document, pointerPart, ref);
185
+ return { schema, baseId: documentId };
186
+ }
187
+ }
188
+ /** RFC 3986 same-directory join: the sibling of the base document's last segment. */
189
+ function joinSibling(baseId, relative) {
190
+ const slash = baseId.lastIndexOf("/");
191
+ if (slash === -1)
192
+ return relative;
193
+ return `${baseId.slice(0, slash + 1)}${relative}`;
194
+ }
195
+ /** Walks one unescaped JSON pointer into a registered document. */
196
+ function pointerLookup(document, pointer, ref) {
197
+ if (!pointer.startsWith("/")) {
198
+ throw new Error(`the $ref "${ref}" must use a JSON pointer (URI fragments are not used by the registered documents)`);
199
+ }
200
+ let node = document;
201
+ for (const rawToken of pointer.slice(1).split("/")) {
202
+ const token = rawToken.replace(/~1/g, "/").replace(/~0/g, "~");
203
+ if (Array.isArray(node)) {
204
+ const index = Number(token);
205
+ if (!Number.isInteger(index) || index < 0 || index >= node.length) {
206
+ throw new Error(`the $ref "${ref}" does not resolve: no array item ${token}`);
207
+ }
208
+ node = node[index];
209
+ continue;
210
+ }
211
+ if (!isPlainObject(node) || !Object.hasOwn(node, token)) {
212
+ throw new Error(`the $ref "${ref}" does not resolve: no property "${token}"`);
213
+ }
214
+ node = node[token];
215
+ }
216
+ return node;
217
+ }
218
+ /**
219
+ * The drift gate: walks one registered document and throws when a schema
220
+ * node carries a standard 2020-12 validation keyword outside the
221
+ * implemented surface, an unknown keyword, or a malformed subschema form
222
+ * (`items` tuple, non-boolean/non-object `items`/`not`/
223
+ * `additionalProperties`/`unevaluatedProperties`, non-array applicators).
224
+ */
225
+ function auditDocument(schema, label) {
226
+ if (typeof schema === "boolean")
227
+ return;
228
+ if (!isPlainObject(schema)) {
229
+ throw new Error(`the ${label} contains a schema that is neither a boolean nor an object`);
230
+ }
231
+ for (const key of Object.keys(schema)) {
232
+ if (key.startsWith("x-") || ANNOTATION_KEYWORDS.has(key) || IMPLEMENTED_KEYWORDS.has(key))
233
+ continue;
234
+ // B3: unknown keywords are refused loudly — never silently ignored.
235
+ // Supported-but-unimplemented 2020-12 keywords name the missing work;
236
+ // anything else names the typo or the foreign vocabulary.
237
+ if (UNSUPPORTED_STANDARD_KEYWORDS.has(key)) {
238
+ throw new Error(`the ${label} uses "${key}", outside the browser structure interpreter's keyword set (§6.4): extend src/structure/interpreter.ts and its oracle test`);
239
+ }
240
+ throw new Error(`the ${label} uses unknown keyword "${key}": extend src/structure/interpreter.ts and its oracle test, or allowlist it as an annotation`);
241
+ }
242
+ const items = schema.items;
243
+ if (Array.isArray(items)) {
244
+ throw new Error(`the ${label} uses "items" in its legacy tuple form, which the browser structure interpreter does not implement`);
245
+ }
246
+ if (items !== undefined && !isPlainObject(items) && typeof items !== "boolean") {
247
+ throw new Error(`the ${label} uses "items" in a non-schema form, which the browser structure interpreter does not implement`);
248
+ }
249
+ for (const container of ["additionalProperties", "unevaluatedProperties", "not"]) {
250
+ const value = schema[container];
251
+ if (value !== undefined && !isPlainObject(value) && typeof value !== "boolean") {
252
+ throw new Error(`the ${label} uses "${container}" in a non-schema form, which the browser structure interpreter does not implement`);
253
+ }
254
+ }
255
+ for (const container of ["allOf", "anyOf", "oneOf"]) {
256
+ const members = schema[container];
257
+ if (members !== undefined && !Array.isArray(members)) {
258
+ throw new Error(`the ${label} uses "${container}" in a non-array form, which the browser structure interpreter does not implement`);
259
+ }
260
+ }
261
+ const subschemas = [];
262
+ for (const container of ["$defs", "properties", "components"]) {
263
+ const map = schema[container];
264
+ if (isPlainObject(map)) {
265
+ for (const value of Object.values(map))
266
+ subschemas.push([`${container} entry`, value]);
267
+ }
268
+ }
269
+ if (items !== undefined)
270
+ subschemas.push(["items", items]);
271
+ for (const container of ["additionalProperties", "unevaluatedProperties", "not"]) {
272
+ const value = schema[container];
273
+ if (isPlainObject(value) || typeof value === "boolean")
274
+ subschemas.push([container, value]);
275
+ }
276
+ for (const container of ["allOf", "anyOf", "oneOf"]) {
277
+ const members = schema[container];
278
+ if (Array.isArray(members)) {
279
+ for (const member of members)
280
+ subschemas.push([container, member]);
281
+ }
282
+ }
283
+ for (const [where, subschema] of subschemas)
284
+ auditDocument(subschema, `${label} (${where})`);
285
+ }
286
+ const EMPTY_EVALUATED = new Set();
287
+ /** Validates `data` against one schema node, collecting issues ajv-style. */
288
+ function validateNode(schema, data, pointer, baseId, registry, issues) {
289
+ if (schema === true)
290
+ return { ok: true, evaluated: EMPTY_EVALUATED };
291
+ if (schema === false || schema === undefined || schema === null) {
292
+ issues.push({ pointer, message: "the schema is false here", keyword: "schema" });
293
+ return { ok: false, evaluated: EMPTY_EVALUATED };
294
+ }
295
+ if (!isPlainObject(schema)) {
296
+ issues.push({ pointer, message: "the schema node is neither a boolean nor an object", keyword: "schema" });
297
+ return { ok: false, evaluated: EMPTY_EVALUATED };
298
+ }
299
+ let ok = true;
300
+ const evaluated = new Set();
301
+ const fail = (issue) => {
302
+ ok = false;
303
+ issues.push(issue);
304
+ };
305
+ // $ref is transparent (2020-12): the referenced schema applies in its
306
+ // own base, and the keywords beside it apply too (the committed documents
307
+ // only pair $ref with annotations). Its evaluated names merge
308
+ // unconditionally, like allOf. The base change NEVER leaks to sibling
309
+ // keywords (B6): they resolve against the referencing node's own base.
310
+ const ref = schema.$ref;
311
+ const activeBaseId = baseId;
312
+ if (typeof ref === "string") {
313
+ const resolved = registry.resolve(ref, baseId);
314
+ const result = validateNode(resolved.schema, data, pointer, resolved.baseId, registry, issues);
315
+ for (const name of result.evaluated)
316
+ evaluated.add(name);
317
+ if (!result.ok)
318
+ ok = false;
319
+ }
320
+ // type, enum, const, pattern — applicable to any value.
321
+ const declaredType = schema.type;
322
+ if (declaredType !== undefined) {
323
+ const names = Array.isArray(declaredType) ? declaredType : [declaredType];
324
+ const validNames = names.filter((name) => typeof name === "string");
325
+ if (names.length > 0 &&
326
+ validNames.length === names.length &&
327
+ !validNames.some((name) => typeMatches(name, data))) {
328
+ fail({
329
+ pointer,
330
+ message: `must be ${validNames.join(",")}`,
331
+ keyword: "type",
332
+ });
333
+ }
334
+ }
335
+ const enumValues = schema.enum;
336
+ if (Array.isArray(enumValues) && !enumValues.some((allowed) => jsonEqual(allowed, data))) {
337
+ fail({ pointer, message: "must be equal to one of the allowed values", keyword: "enum" });
338
+ }
339
+ if (Object.hasOwn(schema, "const") && !jsonEqual(schema.const, data)) {
340
+ fail({ pointer, message: "must be equal to constant", keyword: "const" });
341
+ }
342
+ const pattern = schema.pattern;
343
+ // B5: ajv compiles patterns with the `u` flag (unicodeRegExp: true), so
344
+ // astral code points and \p{...} escapes behave identically here.
345
+ if (typeof pattern === "string" && typeof data === "string" && !new RegExp(pattern, "u").test(data)) {
346
+ fail({ pointer, message: `must match pattern "${pattern}"`, keyword: "pattern" });
347
+ }
348
+ // Object keywords run only for plain objects (ajv's applicability guards).
349
+ if (isPlainObject(data)) {
350
+ const keys = Object.keys(data);
351
+ const required = schema.required;
352
+ if (Array.isArray(required)) {
353
+ for (const name of required) {
354
+ if (typeof name === "string" && !Object.hasOwn(data, name)) {
355
+ fail({
356
+ pointer,
357
+ message: `must have required property '${name}'`,
358
+ keyword: "required",
359
+ missingProperty: name,
360
+ });
361
+ }
362
+ }
363
+ }
364
+ const properties = isPlainObject(schema.properties) ? schema.properties : {};
365
+ for (const [name, subschema] of Object.entries(properties)) {
366
+ if (!Object.hasOwn(data, name))
367
+ continue;
368
+ // A present key is evaluated when its subschema APPLIES, whatever the
369
+ // outcome — ajv's convention (probed: a failed subschema never turns
370
+ // its own key into an unevaluatedProperties row).
371
+ evaluated.add(name);
372
+ const result = validateNode(subschema, data[name], `${pointer}/${escapeToken(name)}`, activeBaseId, registry, issues);
373
+ if (!result.ok)
374
+ ok = false;
375
+ }
376
+ const additional = schema.additionalProperties;
377
+ const declared = new Set(Object.keys(properties));
378
+ // B4: every additional property is EVALUATED when `additionalProperties`
379
+ // is present — `true`, `false` or a schema all mark it evaluated for
380
+ // `unevaluatedProperties` (2020-12 §10.3.2.3; ajv sets `it.props = true`
381
+ // unconditionally). A failing schema still evaluates its key, so no
382
+ // `unevaluatedProperties` row duplicates the failure.
383
+ if (additional === false) {
384
+ for (const name of keys) {
385
+ if (declared.has(name))
386
+ continue;
387
+ evaluated.add(name);
388
+ fail({
389
+ pointer,
390
+ message: "must NOT have additional properties",
391
+ keyword: "additionalProperties",
392
+ additionalProperty: name,
393
+ });
394
+ }
395
+ }
396
+ else if (isPlainObject(additional) || additional === true) {
397
+ const schemaForm = isPlainObject(additional);
398
+ for (const name of keys) {
399
+ if (declared.has(name))
400
+ continue;
401
+ evaluated.add(name);
402
+ if (!schemaForm)
403
+ continue;
404
+ const result = validateNode(additional, data[name], `${pointer}/${escapeToken(name)}`, activeBaseId, registry, issues);
405
+ if (!result.ok)
406
+ ok = false;
407
+ }
408
+ }
409
+ }
410
+ // Array keywords run only for arrays.
411
+ if (Array.isArray(data)) {
412
+ const minItems = schema.minItems;
413
+ if (typeof minItems === "number" && data.length < minItems) {
414
+ fail({ pointer, message: `must NOT have fewer than ${minItems} items`, keyword: "minItems" });
415
+ }
416
+ const maxItems = schema.maxItems;
417
+ if (typeof maxItems === "number" && data.length > maxItems) {
418
+ fail({ pointer, message: `must NOT have more than ${maxItems} items`, keyword: "maxItems" });
419
+ }
420
+ const items = schema.items;
421
+ if (items !== undefined && !Array.isArray(items)) {
422
+ data.forEach((item, index) => {
423
+ const result = validateNode(items, item, `${pointer}/${index}`, activeBaseId, registry, issues);
424
+ if (!result.ok)
425
+ ok = false;
426
+ });
427
+ }
428
+ }
429
+ // In-place applicators — allOf feeds the evaluated set unconditionally
430
+ // (ajv merges every member's annotations, whatever the member's outcome);
431
+ // anyOf and oneOf feed it from their SUCCESSFUL branches only.
432
+ const allOf = schema.allOf;
433
+ if (Array.isArray(allOf)) {
434
+ for (const member of allOf) {
435
+ const result = validateNode(member, data, pointer, activeBaseId, registry, issues);
436
+ for (const name of result.evaluated)
437
+ evaluated.add(name);
438
+ if (!result.ok)
439
+ ok = false;
440
+ }
441
+ }
442
+ const anyOf = schema.anyOf;
443
+ if (Array.isArray(anyOf)) {
444
+ let anyOk = false;
445
+ const branchIssues = [];
446
+ for (const member of anyOf) {
447
+ const branch = [];
448
+ const result = validateNode(member, data, pointer, activeBaseId, registry, branch);
449
+ branchIssues.push(branch);
450
+ if (result.ok) {
451
+ anyOk = true;
452
+ for (const name of result.evaluated)
453
+ evaluated.add(name);
454
+ }
455
+ }
456
+ if (!anyOk) {
457
+ ok = false;
458
+ for (const branch of branchIssues)
459
+ issues.push(...branch);
460
+ issues.push({ pointer, message: "must match a schema in anyOf", keyword: "anyOf" });
461
+ }
462
+ }
463
+ const oneOf = schema.oneOf;
464
+ if (Array.isArray(oneOf)) {
465
+ const branchIssues = [];
466
+ const branchEvaluated = [];
467
+ let passes = 0;
468
+ let passIndex = -1;
469
+ oneOf.forEach((member, index) => {
470
+ const branch = [];
471
+ const result = validateNode(member, data, pointer, activeBaseId, registry, branch);
472
+ branchIssues.push(branch);
473
+ branchEvaluated.push(result.evaluated);
474
+ if (result.ok) {
475
+ passes += 1;
476
+ passIndex = index;
477
+ }
478
+ });
479
+ if (passes === 1 && passIndex >= 0) {
480
+ for (const name of branchEvaluated[passIndex] ?? [])
481
+ evaluated.add(name);
482
+ }
483
+ else {
484
+ ok = false;
485
+ for (const branch of branchIssues)
486
+ issues.push(...branch);
487
+ issues.push({ pointer, message: "must match exactly one schema in oneOf", keyword: "oneOf" });
488
+ }
489
+ }
490
+ // B2: `not` evaluates its subschema against a scratch issue list — inner
491
+ // failures must never leak into the caller's issues when `not` succeeds
492
+ // (ajv runs with createErrors: false here).
493
+ const not = schema.not;
494
+ if (not !== undefined) {
495
+ const scratch = [];
496
+ const result = validateNode(not, data, pointer, activeBaseId, registry, scratch);
497
+ if (result.ok) {
498
+ issues.push({ pointer, message: "must NOT be valid", keyword: "not" });
499
+ ok = false;
500
+ }
501
+ }
502
+ // unevaluatedProperties sees everything the node (and its successful
503
+ // branches) evaluated — the cross-allOf aggregation the committed
504
+ // component entries rely on for their closed property sets.
505
+ if (isPlainObject(data)) {
506
+ const unevaluated = schema.unevaluatedProperties;
507
+ if (unevaluated !== undefined) {
508
+ const remaining = Object.keys(data).filter((name) => !evaluated.has(name));
509
+ if (unevaluated === false) {
510
+ for (const name of remaining) {
511
+ fail({
512
+ pointer,
513
+ message: "must NOT have unevaluated properties",
514
+ keyword: "unevaluatedProperties",
515
+ additionalProperty: name,
516
+ });
517
+ }
518
+ }
519
+ else if (isPlainObject(unevaluated) || unevaluated === true) {
520
+ if (isPlainObject(unevaluated)) {
521
+ for (const name of remaining) {
522
+ const result = validateNode(unevaluated, data[name], `${pointer}/${escapeToken(name)}`, activeBaseId, registry, issues);
523
+ if (result.ok)
524
+ evaluated.add(name);
525
+ else
526
+ ok = false;
527
+ }
528
+ }
529
+ }
530
+ }
531
+ }
532
+ return { ok, evaluated };
533
+ }
534
+ /**
535
+ * Builds the eval-free structure validator for one catalogue, over the same
536
+ * documents the ajv bridge registers. Construction audits every document:
537
+ * a catalogue that grows past the implemented keyword surface fails loudly
538
+ * here, in the build and its tests — never as a silent browser weakening.
539
+ */
540
+ export function createInterpreterStructure(options) {
541
+ const registry = new DocumentRegistry();
542
+ const catalogId = registry.register(options.catalog, "catalogue document");
543
+ if (typeof options.catalog.catalogId !== "string" || options.catalog.catalogId.length === 0) {
544
+ throw new Error("the catalogue document must carry its catalogId (§5.2: $id = catalogId)");
545
+ }
546
+ const envelopeId = registry.register(options.envelopeSchema, "envelope schema");
547
+ registry.register(options.commonTypes, "A2UI common types");
548
+ registry.register(a2uiSdkCatalogSchema, "built catalog.json stub");
549
+ auditDocument(options.catalog, "catalogue document");
550
+ auditDocument(options.envelopeSchema, "envelope schema");
551
+ auditDocument(options.commonTypes, "A2UI common types");
552
+ auditDocument(a2uiSdkCatalogSchema, "built catalog.json stub");
553
+ return {
554
+ validateEnvelope(value) {
555
+ const issues = [];
556
+ validateNode(options.envelopeSchema, value, "", envelopeId, registry, issues);
557
+ return issues;
558
+ },
559
+ validateComponent(component, root) {
560
+ const entry = options.catalog.components[component];
561
+ if (entry === undefined) {
562
+ return [
563
+ {
564
+ pointer: "/component",
565
+ message: `no catalogued component is named ${component}`,
566
+ keyword: "$compile",
567
+ },
568
+ ];
569
+ }
570
+ const issues = [];
571
+ validateNode(entry, root, "", catalogId, registry, issues);
572
+ return issues;
573
+ },
574
+ };
575
+ }
576
+ //# sourceMappingURL=interpreter.js.map
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Diagnostics (§4.5): ONE shape for every refusal and warning the render
3
+ * pipeline can produce. `path` is an RFC 6901 JSON Pointer into the ENVELOPE
4
+ * (not into the component's own schema), so a host can always locate the
5
+ * offending value without knowing which layer produced the diagnostic.
6
+ *
7
+ * The ten codes are exactly the §4.5 list — nothing else may appear:
8
+ *
9
+ * unknown-component the envelope's root targets no catalogued entry
10
+ * component-unavailable the entry is a placeholder (x-sentropic.status)
11
+ * unsupported-contract envelope contract newer than the entry's (§4.4)
12
+ * unsupported-mode `preview` is reserved (§10.3)
13
+ * schema-violation structure: envelope or component did not conform
14
+ * semantic-invalid the owning runtime refused the payload (§4.3)
15
+ * payload-too-large over the 1 MiB UTF-8 budget (§4.3 item 3)
16
+ * host-capability-missing the host lacks an environment capability
17
+ * engine-load-failed a lazy engine chunk failed to load
18
+ * watermark-refused engine warning: rendered without the watermark
19
+ *
20
+ * `watermark-refused` is listed so the §4.5 set stays closed; engine
21
+ * warnings surface under their own engine code, and this is the one the
22
+ * spec names.
23
+ */
24
+ /** The closed set of §4.5 codes. */
25
+ export type DiagnosticCode = "unknown-component" | "component-unavailable" | "unsupported-contract" | "unsupported-mode" | "schema-violation" | "semantic-invalid" | "payload-too-large" | "host-capability-missing" | "engine-load-failed" | "watermark-refused";
26
+ /**
27
+ * Who produced the diagnostic: the catalogue itself, a host-environment
28
+ * fact, or an owning runtime through its semantic port (`diagram-core` is
29
+ * reserved for lot L8).
30
+ */
31
+ export type DiagnosticSource = "catalog" | "host" | "focus" | "bpmn-canvas" | "diagram-core";
32
+ /** The single diagnostic shape (§4.5). */
33
+ export interface Diagnostic {
34
+ /**
35
+ * The §4.5 code. Catalogue-side diagnostics are always one of the ten; an
36
+ * engine WARNING keeps its owning runtime's own stable code instead (the
37
+ * one §4.5 names is `watermark-refused`), so the field also accepts a
38
+ * string there.
39
+ */
40
+ readonly code: DiagnosticCode | (string & {});
41
+ /** RFC 6901 JSON Pointer into the envelope ("" for the envelope itself). */
42
+ readonly path: string;
43
+ readonly message: string;
44
+ readonly severity: "error" | "warning";
45
+ readonly source: DiagnosticSource;
46
+ /** Machine-readable extras, e.g. `{ expected, found }`, `{ limitBytes }`. */
47
+ readonly detail?: Readonly<Record<string, unknown>>;
48
+ }
49
+ /**
50
+ * A host-environment capability is missing (§4.5 `host-capability-missing`):
51
+ * the host calls this for facts it owns BEFORE the render pipeline runs
52
+ * (a missing canvas, a missing engine chunk before a port exists). The
53
+ * envelope validator produces the same code itself when an injected `lazy:`
54
+ * engine has no port.
55
+ */
56
+ export declare function hostCapabilityMissing(capability: string): Diagnostic;
57
+ /**
58
+ * A lazy engine chunk failed to load (§4.5 `engine-load-failed`): the host
59
+ * reports the chunk and the cause; the envelope validator produces the same
60
+ * code when an injected port throws instead of returning findings.
61
+ */
62
+ export declare function engineLoadFailed(chunk: string, cause: string): Diagnostic;
63
+ //# sourceMappingURL=diagnostics.d.ts.map