@blackbelt-technology/pi-dashboard-forms-bpmn 0.7.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/.pi/skills/bpmn-package-explorer/SKILL.md +120 -0
- package/.pi/skills/bpmn-package-explorer/assets/LICENSE.bpmn-io.txt +23 -0
- package/.pi/skills/bpmn-package-explorer/assets/VENDORED.md +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-codes.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-embedded.css +166 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn.css +164 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.svg +224 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-navigated-viewer.production.min.js +22 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn.css +145 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/diagram-js.css +1249 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/diagram-js.css +1133 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-codes.css +41 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-embedded.css +98 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn.css +97 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.svg +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-decision-table.css +580 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-drd.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-literal-expression.css +165 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-shared.css +221 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-viewer.production.min.js +16 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/bpmn-pipeline.mjs +6981 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/yaml.mjs +7372 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g1-identical-bounds.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g2-zero-size.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g3-child-outside.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g4-negative-coord.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g5-overlap.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/1-linear.bpmn +12 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/2-gateway.bpmn +19 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/3-boundary.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/4-subprocess.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/5-pools.bpmn +21 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/6-lanes-only.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/7-loop.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/8-long-chain.bpmn +32 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/nesting/expanded-subprocess-ok.bpmn +25 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/call-activity.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-catch.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-throw.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/manual-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/multi-boundary.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/parallel-gateway.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/receive-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/rule-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/script-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/send-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/references/authoring-envelope.md +52 -0
- package/.pi/skills/bpmn-package-explorer/references/identifiers.md +102 -0
- package/.pi/skills/bpmn-package-explorer/references/layout-envelope.md +105 -0
- package/.pi/skills/bpmn-package-explorer/references/licensing.md +48 -0
- package/.pi/skills/bpmn-package-explorer/references/package-manifest.md +104 -0
- package/.pi/skills/bpmn-package-explorer/scripts/build-fixtures.mjs +299 -0
- package/.pi/skills/bpmn-package-explorer/scripts/demo.mjs +128 -0
- package/.pi/skills/bpmn-package-explorer/scripts/diagnostics.mjs +37 -0
- package/.pi/skills/bpmn-package-explorer/scripts/envelope.mjs +160 -0
- package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +140 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +31 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate.mjs +103 -0
- package/.pi/skills/bpmn-package-explorer/scripts/guard.mjs +335 -0
- package/.pi/skills/bpmn-package-explorer/scripts/harness.mjs +12 -0
- package/.pi/skills/bpmn-package-explorer/scripts/identifiers.mjs +117 -0
- package/.pi/skills/bpmn-package-explorer/scripts/ingest.mjs +95 -0
- package/.pi/skills/bpmn-package-explorer/scripts/manifest.mjs +374 -0
- package/.pi/skills/bpmn-package-explorer/scripts/pipeline.mjs +49 -0
- package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +130 -0
- package/.pi/skills/bpmn-package-explorer/scripts/runguard.mjs +38 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-e2e.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-guard.mjs +99 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-manifest.mjs +170 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-more.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +73 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest.mjs +57 -0
- package/.pi/skills/bpmn-package-explorer/scripts/vendor.mjs +141 -0
- package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +19 -0
- package/.pi/skills/bpmn-package-explorer/templates/shell.html +141 -0
- package/.pi/skills/bpmn-package-explorer/templates/viewer.js +301 -0
- package/.pi/skills/canvas-webapp/SKILL.md +104 -0
- package/.pi/skills/openforms-mui/SKILL.md +187 -0
- package/.pi/skills/openforms-mui/references/a11y.md +68 -0
- package/.pi/skills/openforms-mui/references/field-widget-map.md +64 -0
- package/.pi/skills/openforms-mui/references/hu-locale.md +45 -0
- package/.pi/skills/openforms-mui/references/logic.md +94 -0
- package/.pi/skills/openforms-mui/references/schema.md +94 -0
- package/.pi/skills/openforms-mui/references/theme-bridge.md +65 -0
- package/.pi/skills/openforms-mui/tools/canvas-serve.mjs +51 -0
- package/.pi/skills/openforms-mui/tools/demo-schema.json +80 -0
- package/.pi/skills/openforms-mui/tools/mockups/tokens.css +27 -0
- package/.pi/skills/openforms-mui/tools/mockups/ui-contract.tokens.json +16 -0
- package/.pi/skills/openforms-mui/tools/package-lock.json +5919 -0
- package/.pi/skills/openforms-mui/tools/package.json +61 -0
- package/.pi/skills/openforms-mui/tools/preview/RenderPanel.tsx +105 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-app.tsx +66 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-index.html +16 -0
- package/.pi/skills/openforms-mui/tools/preview/cli.ts +99 -0
- package/.pi/skills/openforms-mui/tools/preview/index.html +17 -0
- package/.pi/skills/openforms-mui/tools/preview/main.tsx +228 -0
- package/.pi/skills/openforms-mui/tools/preview/vite-plugin.ts +41 -0
- package/.pi/skills/openforms-mui/tools/scripts/assert-peer-deps.mjs +39 -0
- package/.pi/skills/openforms-mui/tools/src/OpenFormsMui.tsx +391 -0
- package/.pi/skills/openforms-mui/tools/src/css.d.ts +2 -0
- package/.pi/skills/openforms-mui/tools/src/fields/ErrorSummary.tsx +72 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +328 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldShell.tsx +50 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FileField.tsx +91 -0
- package/.pi/skills/openforms-mui/tools/src/fields/MatrixField.tsx +146 -0
- package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/src/fields/SignatureCanvas.tsx +121 -0
- package/.pi/skills/openforms-mui/tools/src/fields/context.tsx +34 -0
- package/.pi/skills/openforms-mui/tools/src/fields/index.ts +7 -0
- package/.pi/skills/openforms-mui/tools/src/fields/label.ts +42 -0
- package/.pi/skills/openforms-mui/tools/src/fonts.ts +8 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/dictionary.ts +58 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/hu.ts +56 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/index.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/index.ts +27 -0
- package/.pi/skills/openforms-mui/tools/src/logic/cnf.ts +206 -0
- package/.pi/skills/openforms-mui/tools/src/logic/formula.ts +285 -0
- package/.pi/skills/openforms-mui/tools/src/logic/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/logic/operators.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/logic/state.ts +183 -0
- package/.pi/skills/openforms-mui/tools/src/payload.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/provenance.ts +21 -0
- package/.pi/skills/openforms-mui/tools/src/schema/diagnose.ts +256 -0
- package/.pi/skills/openforms-mui/tools/src/schema/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/schema/normalize.ts +163 -0
- package/.pi/skills/openforms-mui/tools/src/schema/types.ts +299 -0
- package/.pi/skills/openforms-mui/tools/src/schema/walk.ts +68 -0
- package/.pi/skills/openforms-mui/tools/src/theme/from-tokens.ts +102 -0
- package/.pi/skills/openforms-mui/tools/src/theme/index.ts +1 -0
- package/.pi/skills/openforms-mui/tools/src/validation/constrain.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/validation/diagnostics.ts +62 -0
- package/.pi/skills/openforms-mui/tools/src/validation/empty.ts +53 -0
- package/.pi/skills/openforms-mui/tools/src/validation/index.ts +5 -0
- package/.pi/skills/openforms-mui/tools/src/validation/resolver.ts +14 -0
- package/.pi/skills/openforms-mui/tools/src/validation/zod-from-schema.ts +169 -0
- package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +74 -0
- package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +295 -0
- package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +163 -0
- package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +45 -0
- package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +175 -0
- package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +105 -0
- package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +131 -0
- package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +158 -0
- package/.pi/skills/openforms-mui/tools/tests/setup.ts +16 -0
- package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +31 -0
- package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +65 -0
- package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +33 -0
- package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +222 -0
- package/.pi/skills/openforms-mui/tools/tsconfig.json +21 -0
- package/.pi/skills/openforms-mui/tools/vite.canvas.config.ts +21 -0
- package/.pi/skills/openforms-mui/tools/vitest.config.ts +17 -0
- package/NOTICE +46 -0
- package/README.md +62 -0
- package/package.json +46 -0
- package/scripts/ensure-openforms-deps.mjs +38 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// Package manifest contract and validation (§5).
|
|
2
|
+
//
|
|
3
|
+
// package.yaml is the single source of the link graph. The .bpmn/.dmn/.form
|
|
4
|
+
// files stay vendor-neutral; all bindings and roles live here. Validation is a
|
|
5
|
+
// manifest-to-artifact JOIN, independent of any BPMN dialect.
|
|
6
|
+
|
|
7
|
+
import { readFileSync, existsSync, realpathSync, statSync } from 'node:fs';
|
|
8
|
+
import { join, resolve, isAbsolute, dirname } from 'node:path';
|
|
9
|
+
import { parseDocument, stringify } from '../assets/lib/yaml.mjs';
|
|
10
|
+
import { parse } from './pipeline.mjs';
|
|
11
|
+
import { writeFileSync } from 'node:fs';
|
|
12
|
+
|
|
13
|
+
const REQUIRED_TYPE = {
|
|
14
|
+
decision: 'businessRuleTask',
|
|
15
|
+
form: 'userTask',
|
|
16
|
+
process: 'callActivity',
|
|
17
|
+
participant: null, // file-scoped
|
|
18
|
+
};
|
|
19
|
+
const KINDS = Object.keys(REQUIRED_TYPE);
|
|
20
|
+
|
|
21
|
+
// ── manifest loading ────────────────────────────────────────────────────
|
|
22
|
+
/** Parse package.yaml with duplicate-key detection. Returns { manifest, errors }. */
|
|
23
|
+
export function loadManifest(pkgDir) {
|
|
24
|
+
const p = join(pkgDir, 'package.yaml');
|
|
25
|
+
if (!existsSync(p)) return { manifest: null, errors: [{ code: 'NO-MANIFEST', message: `no package.yaml in ${pkgDir}` }] };
|
|
26
|
+
const doc = parseDocument(readFileSync(p, 'utf8'), { uniqueKeys: true });
|
|
27
|
+
const errors = [];
|
|
28
|
+
for (const e of doc.errors) {
|
|
29
|
+
errors.push({ code: e.code === 'DUPLICATE_KEY' ? 'DUP-KEY' : 'YAML', message: e.message });
|
|
30
|
+
}
|
|
31
|
+
if (errors.length) return { manifest: null, errors };
|
|
32
|
+
return { manifest: doc.toJS() || {}, errors: [] };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── path resolution + containment (5.5) ─────────────────────────────────
|
|
36
|
+
/** Resolve a manifest-relative path, enforcing containment after realpath. */
|
|
37
|
+
export function resolveContained(pkgDir, rel) {
|
|
38
|
+
if (isAbsolute(rel)) return { error: `absolute path '${rel}' is not allowed; manifest paths are relative to the package root` };
|
|
39
|
+
const target = resolve(pkgDir, rel);
|
|
40
|
+
const rootReal = realpathSync(pkgDir);
|
|
41
|
+
let real;
|
|
42
|
+
try { real = existsSync(target) ? realpathSync(target) : target; }
|
|
43
|
+
catch { real = target; }
|
|
44
|
+
// physical containment: realpath(target) must sit within realpath(root)
|
|
45
|
+
const within = real === rootReal || real.startsWith(rootReal + '/');
|
|
46
|
+
if (!within) return { error: `path '${rel}' resolves outside the package root (after following symlinks)` };
|
|
47
|
+
return { path: target, real };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ── artifact structural checks (5.10) ───────────────────────────────────
|
|
51
|
+
export function checkDmn(text) {
|
|
52
|
+
if (!/xmlns(:\w+)?="https?:\/\/www\.omg\.org\/spec\/DMN\//.test(text) && !/<(\w+:)?definitions[^>]*DMN/i.test(text)) {
|
|
53
|
+
return { ok: false, reason: 'does not parse as DMN (no DMN namespace)' };
|
|
54
|
+
}
|
|
55
|
+
const decisions = (text.match(/<(\w+:)?decision\b/g) || []).length;
|
|
56
|
+
const hasDrdDI = /<(\w+:)?DMNDI\b/.test(text) || /<dmndi:/.test(text);
|
|
57
|
+
if (decisions > 1 && !hasDrdDI) {
|
|
58
|
+
return { ok: false, reason: `declares ${decisions} decisions but carries no DRD DI; the decision-table view cannot render a multi-decision DRD without layout` };
|
|
59
|
+
}
|
|
60
|
+
return { ok: true, decisions, hasDrdDI };
|
|
61
|
+
}
|
|
62
|
+
export function checkForm(text) {
|
|
63
|
+
let v;
|
|
64
|
+
try { v = JSON.parse(text); } catch { return { ok: false, reason: 'is not valid JSON' }; }
|
|
65
|
+
if (v === null || typeof v !== 'object' || Array.isArray(v)) return { ok: false, reason: 'is not a JSON object' };
|
|
66
|
+
return { ok: true, structuralOnly: true };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ── element resolution ──────────────────────────────────────────────────
|
|
70
|
+
async function elementsOf(pkgDir, relFile, cache) {
|
|
71
|
+
if (cache.has(relFile)) return cache.get(relFile);
|
|
72
|
+
const r = resolveContained(pkgDir, relFile);
|
|
73
|
+
if (r.error || !existsSync(r.path)) { cache.set(relFile, null); return null; }
|
|
74
|
+
const { rootElement } = await parse(readFileSync(r.path, 'utf8'));
|
|
75
|
+
const map = new Map(); // id -> { type, name }
|
|
76
|
+
for (const root of rootElement.rootElements || []) walk(root, map);
|
|
77
|
+
cache.set(relFile, map);
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
function walk(node, map) {
|
|
81
|
+
for (const fe of node.flowElements || []) {
|
|
82
|
+
const type = fe.$type.replace('bpmn:', '');
|
|
83
|
+
map.set(fe.id, { type: type.charAt(0).toLowerCase() + type.slice(1), name: fe.name || null });
|
|
84
|
+
if (fe.flowElements) walk(fe, map);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── similarity for reconciliation (5.18) ────────────────────────────────
|
|
89
|
+
function deburrLower(s) {
|
|
90
|
+
return (s || '').normalize('NFKD').replace(/[\u0300-\u036f]/g, '').replace(/[^\x00-\x7f]/g, '').toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
function levenshtein(a, b) {
|
|
93
|
+
const m = a.length, n = b.length;
|
|
94
|
+
const d = Array.from({ length: m + 1 }, (_, i) => [i, ...Array(n).fill(0)]);
|
|
95
|
+
for (let j = 0; j <= n; j++) d[0][j] = j;
|
|
96
|
+
for (let i = 1; i <= m; i++) for (let j = 1; j <= n; j++) {
|
|
97
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
98
|
+
}
|
|
99
|
+
return d[m][n];
|
|
100
|
+
}
|
|
101
|
+
export function similarity(a, b) {
|
|
102
|
+
const x = deburrLower(a), y = deburrLower(b);
|
|
103
|
+
if (!x && !y) return 1;
|
|
104
|
+
const max = Math.max(x.length, y.length) || 1;
|
|
105
|
+
return 1 - levenshtein(x, y) / max;
|
|
106
|
+
}
|
|
107
|
+
export const SIMILARITY_THRESHOLD = 0.6;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Reconcile a dangling entry against survivors of the required type.
|
|
111
|
+
* Returns { kind: 'suggestion'|'ambiguous'|'none', candidates:[{id,name,score}] }.
|
|
112
|
+
* Pure — never writes.
|
|
113
|
+
*/
|
|
114
|
+
export function reconcile(recordedName, requiredType, survivors) {
|
|
115
|
+
const scored = survivors
|
|
116
|
+
.filter((s) => !requiredType || s.type === requiredType)
|
|
117
|
+
.map((s) => ({ id: s.id, name: s.name, score: similarity(recordedName, s.name) }))
|
|
118
|
+
.filter((s) => s.score >= SIMILARITY_THRESHOLD)
|
|
119
|
+
.sort((a, b) => b.score - a.score);
|
|
120
|
+
if (!scored.length) return { kind: 'none', candidates: [] };
|
|
121
|
+
const top = scored[0].score;
|
|
122
|
+
const tied = scored.filter((s) => s.score === top);
|
|
123
|
+
if (tied.length > 1) return { kind: 'ambiguous', candidates: tied };
|
|
124
|
+
return { kind: 'suggestion', candidates: [scored[0]] };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Persist refreshed recorded-names back to package.yaml (5.17a). This is the
|
|
129
|
+
* ONLY permitted manifest write in a non-interactive context: it changes only
|
|
130
|
+
* the `name` a still-resolving binding records, never re-points/drops/creates a
|
|
131
|
+
* binding. Returns true if a write occurred.
|
|
132
|
+
*/
|
|
133
|
+
export function persistRefreshedNames(pkgDir, validation) {
|
|
134
|
+
if (!validation.refreshes || !validation.refreshes.length || !validation.updatedManifest) return false;
|
|
135
|
+
writeFileSync(join(pkgDir, 'package.yaml'), stringify(validation.updatedManifest));
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ── full validation (5.1–5.20) ──────────────────────────────────────────
|
|
140
|
+
/**
|
|
141
|
+
* Validate a package. Returns:
|
|
142
|
+
* { ok, errors, warnings, diagnostics, refreshes, updatedManifest, reconciliations }
|
|
143
|
+
* `opts.interactive` (default false) gates reconciliation writes; the recorded-
|
|
144
|
+
* name refresh happens regardless (5.17a exemption).
|
|
145
|
+
* `opts.generatedFiles` — set of rel paths this run generated (vendor-attr rule).
|
|
146
|
+
*/
|
|
147
|
+
export async function validatePackage(pkgDir, opts = {}) {
|
|
148
|
+
const interactive = !!opts.interactive;
|
|
149
|
+
const generatedFiles = opts.generatedFiles || new Set();
|
|
150
|
+
const errors = [], warnings = [], diagnostics = [], refreshes = [], reconciliations = [];
|
|
151
|
+
const { manifest, errors: loadErr } = loadManifest(pkgDir);
|
|
152
|
+
if (loadErr.length) return { ok: false, errors: loadErr, warnings, diagnostics, refreshes, updatedManifest: null, reconciliations };
|
|
153
|
+
|
|
154
|
+
if (!manifest.name) errors.push({ code: 'NO-NAME', message: 'manifest is missing required `name`' });
|
|
155
|
+
if (!manifest.entry) errors.push({ code: 'NO-ENTRY', message: 'manifest is missing required `entry`' });
|
|
156
|
+
const entry = manifest.entry;
|
|
157
|
+
const cache = new Map();
|
|
158
|
+
|
|
159
|
+
// entry must resolve to an existing .bpmn
|
|
160
|
+
if (entry) {
|
|
161
|
+
const er = resolveContained(pkgDir, entry);
|
|
162
|
+
if (er.error) errors.push({ code: 'ENTRY-PATH', message: er.error });
|
|
163
|
+
else if (!existsSync(er.path)) errors.push({ code: 'ENTRY-MISSING', message: `entry '${entry}' does not exist` });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const bindings = manifest.bindings || [];
|
|
167
|
+
const roles = manifest.roles || [];
|
|
168
|
+
const updatedBindings = bindings.map((b) => ({ ...b }));
|
|
169
|
+
const updatedRoles = roles.map((r) => ({ ...r }));
|
|
170
|
+
|
|
171
|
+
// ── bindings ──
|
|
172
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
173
|
+
const b = bindings[i];
|
|
174
|
+
const label = `binding[${i}]`;
|
|
175
|
+
if (!KINDS.includes(b.kind)) { errors.push({ code: 'BAD-KIND', message: `${label} kind '${b.kind}' is not one of: ${KINDS.join(', ')}` }); continue; }
|
|
176
|
+
|
|
177
|
+
// 5.5 ref path
|
|
178
|
+
if (!b.ref) { errors.push({ code: 'NO-REF', message: `${label} has no ref` }); continue; }
|
|
179
|
+
const rr = resolveContained(pkgDir, b.ref);
|
|
180
|
+
if (rr.error) { errors.push({ code: 'REF-PATH', message: `${label}: ${rr.error}` }); continue; }
|
|
181
|
+
|
|
182
|
+
// 5.9 participant is file-scoped
|
|
183
|
+
if (b.kind === 'participant') {
|
|
184
|
+
if (b.element || b.in) errors.push({ code: 'PARTICIPANT-SCOPE', message: `${label} kind: participant is file-scoped; remove element/in` });
|
|
185
|
+
if (!b.name) errors.push({ code: 'PARTICIPANT-NAME', message: `${label} kind: participant requires a name for the switcher label` });
|
|
186
|
+
// duplicate of entry (viewer 7.15)
|
|
187
|
+
if (entry && b.ref === entry) errors.push({ code: 'PARTICIPANT-DUP-ENTRY', message: `${label} references the entry file as a participant; the entry is already in the switcher` });
|
|
188
|
+
// ref must parse as BPMN + exist
|
|
189
|
+
if (!existsSync(rr.path)) errors.push({ code: 'REF-MISSING', message: `${label} ref '${b.ref}' does not exist` });
|
|
190
|
+
else if (!/<(\w+:)?definitions/.test(readFileSync(rr.path, 'utf8'))) errors.push({ code: 'REF-CONTENT', message: `${label} ref '${b.ref}' does not parse as BPMN` });
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// element-scoped kinds
|
|
195
|
+
if (!b.element) { errors.push({ code: 'NO-ELEMENT', message: `${label} kind: ${b.kind} requires an element` }); continue; }
|
|
196
|
+
const owner = b.in || entry;
|
|
197
|
+
|
|
198
|
+
// ref existence + kind-appropriate content (5.10)
|
|
199
|
+
if (!existsSync(rr.path)) { errors.push({ code: 'REF-MISSING', message: `${label} ref '${b.ref}' does not resolve to an existing file` }); }
|
|
200
|
+
else {
|
|
201
|
+
const text = readFileSync(rr.path, 'utf8');
|
|
202
|
+
if (b.kind === 'decision') {
|
|
203
|
+
const c = checkDmn(text);
|
|
204
|
+
if (!c.ok) errors.push({ code: 'REF-CONTENT', message: `${label} ref '${b.ref}' ${c.reason}` });
|
|
205
|
+
} else if (b.kind === 'process') {
|
|
206
|
+
if (!/<(\w+:)?definitions/.test(text)) errors.push({ code: 'REF-CONTENT', message: `${label} ref '${b.ref}' does not parse as BPMN` });
|
|
207
|
+
} else if (b.kind === 'form') {
|
|
208
|
+
const c = checkForm(text);
|
|
209
|
+
if (!c.ok) errors.push({ code: 'REF-CONTENT', message: `${label} ref '${b.ref}' ${c.reason}` });
|
|
210
|
+
else diagnostics.push({ code: 'FORM-STRUCTURAL-ONLY', message: `${label}: form '${b.ref}' validated for structural validity only; the OpenForms schema contract is unavailable, so schema conformance was not checked` });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// element resolution + type match (5.8) + dangling (5.13) + reconciliation (5.18)
|
|
215
|
+
const elems = await elementsOf(pkgDir, owner, cache);
|
|
216
|
+
const required = REQUIRED_TYPE[b.kind];
|
|
217
|
+
if (!elems) { errors.push({ code: 'OWNER-MISSING', message: `${label} in '${owner}' cannot be read` }); continue; }
|
|
218
|
+
const el = elems.get(b.element);
|
|
219
|
+
if (!el) {
|
|
220
|
+
// dangling — try reconciliation on recorded name
|
|
221
|
+
const survivors = [...elems].map(([id, m]) => ({ id, ...m }));
|
|
222
|
+
const rec = reconcile(b.name || '', required, survivors);
|
|
223
|
+
if (rec.kind === 'none') {
|
|
224
|
+
errors.push({ code: 'DANGLING', message: `${label} element '${b.element}' absent from '${owner}' (ref → ${b.ref}); no plausible surviving ${required} matches the recorded name '${b.name || ''}'` });
|
|
225
|
+
} else {
|
|
226
|
+
reconciliations.push({ label, kind: rec.kind, recordedName: b.name || '', requiredType: required, candidates: rec.candidates, applied: false });
|
|
227
|
+
errors.push({ code: 'DANGLING-RECONCILE', message: `${label} element '${b.element}' absent from '${owner}'; ${rec.kind === 'ambiguous' ? 'ambiguous match' : 'suggested'} ${rec.candidates.map((c) => `${c.id} ('${c.name}', ${c.score.toFixed(2)})`).join(', ')} — confirm before re-pointing` });
|
|
228
|
+
}
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
// type match
|
|
232
|
+
if (required && el.type !== required) {
|
|
233
|
+
errors.push({ code: 'TYPE-MISMATCH', message: `${label} kind: ${b.kind} requires a ${required} but '${b.element}' is a ${el.type}` });
|
|
234
|
+
}
|
|
235
|
+
// 4.5 — unnamed elements are not bindable
|
|
236
|
+
if (!el.name) errors.push({ code: 'UNNAMED-TARGET', message: `${label} targets '${b.element}', which has no name; only named elements are bindable` });
|
|
237
|
+
|
|
238
|
+
// 5.17 / 5.17a — record + refresh the target name
|
|
239
|
+
if (el.name) {
|
|
240
|
+
if (b.name !== el.name) { refreshes.push({ label, from: b.name || null, to: el.name }); updatedBindings[i].name = el.name; }
|
|
241
|
+
// 5.19 stale-name report when id intact but recorded name differs
|
|
242
|
+
if (b.name && b.name !== el.name) warnings.push({ code: 'STALE-NAME', message: `${label} recorded name '${b.name}' is stale; element '${b.element}' is now named '${el.name}' — refreshed` });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ── roles (5.12, 5.13, 5.17, 5.18a) ──
|
|
247
|
+
const roleByElement = new Map(); // `${owner}\u0000${element}` -> role
|
|
248
|
+
for (let i = 0; i < roles.length; i++) {
|
|
249
|
+
const r = roles[i];
|
|
250
|
+
const owner = r.in || entry;
|
|
251
|
+
if (!r.element || !r.role) { errors.push({ code: 'ROLE-INCOMPLETE', message: `roles[${i}] requires element and role` }); continue; }
|
|
252
|
+
const key = `${owner}\u0000${r.element}`;
|
|
253
|
+
if (roleByElement.has(key)) errors.push({ code: 'ROLE-DOUBLE', message: `element '${r.element}' in '${owner}' is assigned two roles: '${roleByElement.get(key)}' and '${r.role}'` });
|
|
254
|
+
else roleByElement.set(key, r.role);
|
|
255
|
+
|
|
256
|
+
const elems = await elementsOf(pkgDir, owner, cache);
|
|
257
|
+
if (!elems) { errors.push({ code: 'OWNER-MISSING', message: `roles[${i}] in '${owner}' cannot be read` }); continue; }
|
|
258
|
+
const el = elems.get(r.element);
|
|
259
|
+
if (!el) {
|
|
260
|
+
const survivors = [...elems].map(([id, m]) => ({ id, ...m }));
|
|
261
|
+
const rec = reconcile(r.name || '', null, survivors);
|
|
262
|
+
if (rec.kind === 'none') errors.push({ code: 'ROLE-DANGLING', message: `roles[${i}] element '${r.element}' absent from '${owner}'` });
|
|
263
|
+
else { reconciliations.push({ label: `roles[${i}]`, kind: rec.kind, recordedName: r.name || '', candidates: rec.candidates, applied: false }); errors.push({ code: 'ROLE-DANGLING-RECONCILE', message: `roles[${i}] element '${r.element}' absent; suggested ${rec.candidates.map((c) => `${c.id} ('${c.name}')`).join(', ')}` }); }
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (el.name) {
|
|
267
|
+
if (r.name !== el.name) { refreshes.push({ label: `roles[${i}]`, from: r.name || null, to: el.name }); updatedRoles[i].name = el.name; }
|
|
268
|
+
if (r.name && r.name !== el.name) warnings.push({ code: 'STALE-NAME', message: `roles[${i}] recorded name '${r.name}' is stale; element is now '${el.name}' — refreshed` });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ── orphan + unbound reporting (5.14) ──
|
|
273
|
+
await reportOrphansAndUnbound(pkgDir, manifest, entry, cache, warnings);
|
|
274
|
+
|
|
275
|
+
// ── composition boundaries (5.15 nested pkg, 5.16 cycle) ──
|
|
276
|
+
await checkComposition(pkgDir, manifest, entry, errors, warnings);
|
|
277
|
+
|
|
278
|
+
// ── vendor-attribute handling (5.11) ──
|
|
279
|
+
await checkVendorAttributes(pkgDir, manifest, entry, generatedFiles, errors, warnings, cache);
|
|
280
|
+
|
|
281
|
+
const ok = errors.length === 0;
|
|
282
|
+
return {
|
|
283
|
+
ok, errors, warnings, diagnostics, refreshes, reconciliations,
|
|
284
|
+
updatedManifest: { ...manifest, bindings: updatedBindings, roles: updatedRoles },
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function reportOrphansAndUnbound(pkgDir, manifest, entry, cache, warnings) {
|
|
289
|
+
const bindings = manifest.bindings || [];
|
|
290
|
+
const referenced = new Set([entry, ...bindings.map((b) => b.ref)].filter(Boolean));
|
|
291
|
+
// orphan artifact files
|
|
292
|
+
const { readdirSync } = await import('node:fs');
|
|
293
|
+
const walkDir = (dir, base = '') => {
|
|
294
|
+
for (const f of readdirSync(dir, { withFileTypes: true })) {
|
|
295
|
+
const rel = base ? `${base}/${f.name}` : f.name;
|
|
296
|
+
if (f.isDirectory()) walkDir(join(dir, f.name), rel);
|
|
297
|
+
else if (/\.(dmn|form|bpmn)$/.test(f.name)) {
|
|
298
|
+
if (!referenced.has(rel) && rel !== entry) warnings.push({ code: 'ORPHAN', message: `artifact '${rel}' is referenced by no binding` });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
try { walkDir(pkgDir); } catch { /* ignore */ }
|
|
303
|
+
// unbound bindable elements in the entry
|
|
304
|
+
const boundElems = new Set(bindings.filter((b) => b.element).map((b) => `${b.in || entry}\u0000${b.element}`));
|
|
305
|
+
const elems = await elementsOf(pkgDir, entry, cache);
|
|
306
|
+
if (elems) for (const [id, m] of elems) {
|
|
307
|
+
if (['userTask', 'businessRuleTask', 'callActivity'].includes(m.type) && !boundElems.has(`${entry}\u0000${id}`)) {
|
|
308
|
+
warnings.push({ code: 'UNBOUND', message: `${m.type} '${id}' in the entry process is covered by no binding` });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function checkComposition(pkgDir, manifest, entry, errors, warnings) {
|
|
314
|
+
const bindings = manifest.bindings || [];
|
|
315
|
+
// 5.15 nested package: a package.yaml beside a referenced .bpmn
|
|
316
|
+
for (const b of bindings) {
|
|
317
|
+
if ((b.kind === 'process' || b.kind === 'participant') && b.ref) {
|
|
318
|
+
const rr = resolveContained(pkgDir, b.ref);
|
|
319
|
+
if (rr.path && existsSync(rr.path)) {
|
|
320
|
+
const sibling = join(dirname(rr.path), 'package.yaml');
|
|
321
|
+
if (existsSync(sibling) && dirname(rr.path) !== realpathSync(pkgDir)) {
|
|
322
|
+
errors.push({ code: 'NESTED-PACKAGE', message: `ref '${b.ref}' sits beside its own package.yaml; nested packages are not supported in this change` });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// 5.16 cycle detection as WARNING
|
|
328
|
+
const graph = new Map(); // file -> [files]
|
|
329
|
+
const fileFor = (b) => b.ref;
|
|
330
|
+
const owners = new Set([entry]);
|
|
331
|
+
for (const b of bindings) if (b.kind === 'process' || b.kind === 'participant') owners.add(b.in || entry);
|
|
332
|
+
for (const b of bindings) {
|
|
333
|
+
if (b.kind === 'process') {
|
|
334
|
+
const from = b.in || entry, to = fileFor(b);
|
|
335
|
+
if (!graph.has(from)) graph.set(from, []);
|
|
336
|
+
graph.get(from).push(to);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const cycle = findCycle(graph);
|
|
340
|
+
if (cycle) warnings.push({ code: 'CYCLE', message: `binding graph has a cycle: ${cycle.join(' → ')}; recursion is legal BPMN and the package is still served (the viewer bounds navigation)` });
|
|
341
|
+
}
|
|
342
|
+
function findCycle(graph) {
|
|
343
|
+
const visiting = new Set(), done = new Set();
|
|
344
|
+
let found = null;
|
|
345
|
+
const dfs = (n, stack) => {
|
|
346
|
+
if (found) return;
|
|
347
|
+
visiting.add(n); stack.push(n);
|
|
348
|
+
for (const m of graph.get(n) || []) {
|
|
349
|
+
if (visiting.has(m)) { found = [...stack, m]; return; }
|
|
350
|
+
if (!done.has(m)) dfs(m, stack);
|
|
351
|
+
}
|
|
352
|
+
visiting.delete(n); done.add(n); stack.pop();
|
|
353
|
+
};
|
|
354
|
+
for (const n of graph.keys()) if (!done.has(n)) dfs(n, []);
|
|
355
|
+
return found;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function checkVendorAttributes(pkgDir, manifest, entry, generatedFiles, errors, warnings, cache) {
|
|
359
|
+
const bindings = manifest.bindings || [];
|
|
360
|
+
const files = new Set([entry, ...bindings.map((b) => b.ref).filter((r) => r && r.endsWith('.bpmn'))].filter(Boolean));
|
|
361
|
+
const linkAttrRe = /\b(camunda|zeebe|activiti|flowable):(decisionRef|formKey|formDefinition|calledElement|calledDecisionId)\b/;
|
|
362
|
+
for (const rel of files) {
|
|
363
|
+
const rr = resolveContained(pkgDir, rel);
|
|
364
|
+
if (!rr.path || !existsSync(rr.path)) continue;
|
|
365
|
+
const text = readFileSync(rr.path, 'utf8');
|
|
366
|
+
if (linkAttrRe.test(text)) {
|
|
367
|
+
if (generatedFiles.has(rel)) {
|
|
368
|
+
errors.push({ code: 'VENDOR-ATTR', message: `generated file '${rel}' carries a vendor link attribute duplicating a binding; link information belongs in package.yaml, not in a vendor extension` });
|
|
369
|
+
} else {
|
|
370
|
+
warnings.push({ code: 'VENDOR-ATTR-INGESTED', message: `ingested file '${rel}' carries a vendor link attribute; tolerated (link information is authoritative in the manifest)` });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Pipeline primitives: parse, DI detection, layout invocation.
|
|
2
|
+
//
|
|
3
|
+
// Wraps the vendored self-contained Node bundle. No install / bundler / network
|
|
4
|
+
// at use time.
|
|
5
|
+
|
|
6
|
+
import { layoutProcess, BpmnModdle } from '../assets/lib/bpmn-pipeline.mjs';
|
|
7
|
+
|
|
8
|
+
export { BpmnModdle };
|
|
9
|
+
|
|
10
|
+
/** Parse BPMN XML into a moddle tree. Returns { rootElement, warnings }. */
|
|
11
|
+
export async function parse(xml) {
|
|
12
|
+
const m = new BpmnModdle();
|
|
13
|
+
return m.fromXML(xml);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Serialise a moddle tree back to XML. */
|
|
17
|
+
export async function serialise(rootElement) {
|
|
18
|
+
const m = new BpmnModdle();
|
|
19
|
+
const { xml } = await m.toXML(rootElement, { format: true });
|
|
20
|
+
return xml;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Does this document already carry Diagram Interchange?
|
|
25
|
+
* A document with even a partial `<bpmndi:BPMNDiagram>` counts as "has DI":
|
|
26
|
+
* per the layout-guard spec, partial DI is treated as present and is NOT
|
|
27
|
+
* re-laid out.
|
|
28
|
+
*/
|
|
29
|
+
export function hasDI(rootElement) {
|
|
30
|
+
return Array.isArray(rootElement.diagrams) && rootElement.diagrams.length > 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Cheap textual DI probe for raw XML, before a full parse. */
|
|
34
|
+
export function xmlHasDI(xml) {
|
|
35
|
+
return /<(\w+:)?BPMNDiagram[\s>]/.test(xml) || /<bpmndi:/.test(xml);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Lay out a semantics-only document. Throws if the input already carries DI —
|
|
40
|
+
* the caller is responsible for the "layout only when DI absent" rule and must
|
|
41
|
+
* not call this on a DI-bearing document.
|
|
42
|
+
*/
|
|
43
|
+
export async function layout(xml) {
|
|
44
|
+
if (xmlHasDI(xml)) {
|
|
45
|
+
throw new Error('layout() called on a document that already carries DI; ' +
|
|
46
|
+
'existing layout must be preserved, never re-laid out');
|
|
47
|
+
}
|
|
48
|
+
return layoutProcess(xml);
|
|
49
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Render-root assembly (§7.1) and display workflow (§8.3).
|
|
2
|
+
//
|
|
3
|
+
// Builds a directory that presents the shell, the package artifacts and the
|
|
4
|
+
// single shared asset root under ONE origin — the asset root as a SYMLINK, so
|
|
5
|
+
// the multi-megabyte payload is never duplicated per package (serve_mockup
|
|
6
|
+
// follows symlinks). Asset URLs in the shell are RELATIVE, so they survive an
|
|
7
|
+
// ephemeral port not known at generation time.
|
|
8
|
+
//
|
|
9
|
+
// node scripts/render.mjs <packageDir> [outDir]
|
|
10
|
+
// → assembles a render root and prints its path (serve it with serve_mockup)
|
|
11
|
+
|
|
12
|
+
import { mkdtempSync, mkdirSync, readdirSync, copyFileSync, writeFileSync, readFileSync, existsSync, symlinkSync, statSync, rmSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join, dirname, relative, extname } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { loadManifest, validatePackage } from './manifest.mjs';
|
|
17
|
+
import { writeDiagnostics, DIAGNOSTICS_FILE } from './diagnostics.mjs';
|
|
18
|
+
import { prepareStandalone } from './generate.mjs';
|
|
19
|
+
import { basename } from 'node:path';
|
|
20
|
+
|
|
21
|
+
const SKILL = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
22
|
+
const ASSETS = join(SKILL, 'assets');
|
|
23
|
+
const SHELL = join(SKILL, 'templates', 'shell.html');
|
|
24
|
+
|
|
25
|
+
function walkFiles(dir, base = '') {
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const f of readdirSync(dir, { withFileTypes: true })) {
|
|
28
|
+
const rel = base ? `${base}/${f.name}` : f.name;
|
|
29
|
+
if (f.isDirectory()) out.push(...walkFiles(join(dir, f.name), rel));
|
|
30
|
+
else out.push(rel);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Assemble a render root for a package directory.
|
|
37
|
+
* @returns { renderRoot, data, validation }
|
|
38
|
+
*/
|
|
39
|
+
export async function assembleRenderRoot(pkgDir, outDir) {
|
|
40
|
+
const { manifest } = loadManifest(pkgDir);
|
|
41
|
+
if (!manifest) throw new Error(`no valid package.yaml in ${pkgDir}`);
|
|
42
|
+
const validation = await validatePackage(pkgDir);
|
|
43
|
+
|
|
44
|
+
const renderRoot = outDir || mkdtempSync(join(tmpdir(), 'bpmn-render-'));
|
|
45
|
+
mkdirSync(renderRoot, { recursive: true });
|
|
46
|
+
|
|
47
|
+
// 1) shared asset root as a symlink (no payload duplication)
|
|
48
|
+
const assetLink = join(renderRoot, 'assets');
|
|
49
|
+
if (existsSync(assetLink)) rmSync(assetLink, { recursive: true, force: true });
|
|
50
|
+
symlinkSync(ASSETS, assetLink, 'dir');
|
|
51
|
+
|
|
52
|
+
// 2) package artifacts, symlinked into the render root preserving structure
|
|
53
|
+
for (const rel of walkFiles(pkgDir)) {
|
|
54
|
+
if (rel === DIAGNOSTICS_FILE) continue;
|
|
55
|
+
const src = join(pkgDir, rel);
|
|
56
|
+
const dst = join(renderRoot, rel);
|
|
57
|
+
mkdirSync(dirname(dst), { recursive: true });
|
|
58
|
+
if (existsSync(dst)) rmSync(dst, { force: true });
|
|
59
|
+
symlinkSync(src, dst);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 3) shell + viewer script
|
|
63
|
+
copyFileSync(SHELL, join(renderRoot, 'index.html'));
|
|
64
|
+
copyFileSync(join(SKILL, 'templates', 'viewer.js'), join(renderRoot, 'viewer.js'));
|
|
65
|
+
|
|
66
|
+
// 4) package-data.json — everything the shell needs, no filesystem walk in JS
|
|
67
|
+
writeDiagnostics(renderRoot, validation);
|
|
68
|
+
const data = {
|
|
69
|
+
name: manifest.name,
|
|
70
|
+
entry: manifest.entry,
|
|
71
|
+
bindings: (validation.updatedManifest || manifest).bindings || [],
|
|
72
|
+
roles: (validation.updatedManifest || manifest).roles || [],
|
|
73
|
+
diagnostics: readJson(join(renderRoot, DIAGNOSTICS_FILE)),
|
|
74
|
+
// §7.19 — only load the form renderer when it is actually vendored, so an
|
|
75
|
+
// absent renderer never produces a 404 / console error.
|
|
76
|
+
formsRenderer: existsSync(join(ASSETS, 'openforms', 'openforms-mui.iife.js')),
|
|
77
|
+
};
|
|
78
|
+
writeFileSync(join(renderRoot, 'package-data.json'), JSON.stringify(data, null, 2));
|
|
79
|
+
|
|
80
|
+
return { renderRoot, data, validation };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readJson(p) { try { return JSON.parse(readFileSync(p, 'utf8')); } catch { return null; } }
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Assemble a render root for a STANDALONE .bpmn/.dmn with no manifest (§8.4–8.6).
|
|
87
|
+
* The source file is NEVER overwritten: a DI-less .bpmn is laid out into a
|
|
88
|
+
* separate render artifact written only inside the render root.
|
|
89
|
+
* @returns { renderRoot } or { refused, diagnostics }
|
|
90
|
+
*/
|
|
91
|
+
export async function assembleStandalone(srcPath, outDir) {
|
|
92
|
+
const prep = await prepareStandalone(srcPath);
|
|
93
|
+
if (prep.refused) return { refused: true, diagnostics: prep.diagnostics };
|
|
94
|
+
|
|
95
|
+
const renderRoot = outDir || mkdtempSync(join(tmpdir(), 'bpmn-standalone-'));
|
|
96
|
+
mkdirSync(renderRoot, { recursive: true });
|
|
97
|
+
const assetLink = join(renderRoot, 'assets');
|
|
98
|
+
if (existsSync(assetLink)) rmSync(assetLink, { recursive: true, force: true });
|
|
99
|
+
symlinkSync(ASSETS, assetLink, 'dir');
|
|
100
|
+
|
|
101
|
+
const isDmn = srcPath.endsWith('.dmn');
|
|
102
|
+
const entry = isDmn ? 'entry.dmn' : 'entry.bpmn';
|
|
103
|
+
writeFileSync(join(renderRoot, entry), prep.renderXml); // separate render artifact
|
|
104
|
+
copyFileSync(SHELL, join(renderRoot, 'index.html'));
|
|
105
|
+
copyFileSync(join(SKILL, 'templates', 'viewer.js'), join(renderRoot, 'viewer.js'));
|
|
106
|
+
|
|
107
|
+
const data = {
|
|
108
|
+
name: basename(srcPath),
|
|
109
|
+
entry,
|
|
110
|
+
entryKind: isDmn ? 'dmn' : 'bpmn',
|
|
111
|
+
bindings: [], roles: [],
|
|
112
|
+
formsRenderer: existsSync(join(ASSETS, 'openforms', 'openforms-mui.iife.js')),
|
|
113
|
+
diagnostics: { errors: [], warnings: (prep.warnings || []).map((w) => ({ code: w.code, message: w.detail ? w.detail : w.message })), notes: [] },
|
|
114
|
+
};
|
|
115
|
+
writeFileSync(join(renderRoot, 'package-data.json'), JSON.stringify(data, null, 2));
|
|
116
|
+
return { renderRoot };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// CLI
|
|
120
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
121
|
+
const [pkgDir, outDir] = process.argv.slice(2);
|
|
122
|
+
if (!pkgDir) { console.error('usage: node scripts/render.mjs <packageDir> [outDir]'); process.exit(1); }
|
|
123
|
+
const { renderRoot, validation } = await assembleRenderRoot(pkgDir, outDir);
|
|
124
|
+
if (!validation.ok) {
|
|
125
|
+
console.error('VALIDATION FAILED — not serving:');
|
|
126
|
+
for (const e of validation.errors) console.error(` [${e.code}] ${e.message}`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
console.log(renderRoot);
|
|
130
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Run-mode orchestration for the layout guard (§6.1–6.3b).
|
|
2
|
+
//
|
|
3
|
+
// Decides — by a COMPUTABLE rule, not document history — whether geometry is
|
|
4
|
+
// strict (produced by this run) or advisory (already on disk):
|
|
5
|
+
// * no DI on input → geometry about to exist is ours → STRICT after layout.
|
|
6
|
+
// An INGESTED DI-less file containing a rejected construct
|
|
7
|
+
// is REFUSED rather than laid out (measured corruption).
|
|
8
|
+
// * DI on input → geometry is on-disk input → ADVISORY, never re-laid out.
|
|
9
|
+
// Partial DI surfaces shapeless elements as warnings.
|
|
10
|
+
|
|
11
|
+
import { parse, layout, xmlHasDI } from './pipeline.mjs';
|
|
12
|
+
import { runGuard } from './guard.mjs';
|
|
13
|
+
import { rejectedConstructIn } from './envelope.mjs';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param xml the .bpmn source
|
|
17
|
+
* @param opts.provenance 'generated' | 'ingested'
|
|
18
|
+
* @returns one of:
|
|
19
|
+
* { refused:true, diagnostics:[{code,message}] } (6.3b refusal)
|
|
20
|
+
* { refused:false, mode, laidOut, result } (verified)
|
|
21
|
+
*/
|
|
22
|
+
export async function guardXml(xml, { provenance = 'ingested' } = {}) {
|
|
23
|
+
if (!xmlHasDI(xml)) {
|
|
24
|
+
// DI-less. The geometry about to be produced is this run's own → strict.
|
|
25
|
+
if (provenance === 'ingested') {
|
|
26
|
+
const rej = rejectedConstructIn(xml);
|
|
27
|
+
if (rej) return { refused: true, diagnostics: rej };
|
|
28
|
+
}
|
|
29
|
+
const laidOut = await layout(xml);
|
|
30
|
+
const { rootElement } = await parse(laidOut);
|
|
31
|
+
const result = runGuard(rootElement, { mode: 'strict' });
|
|
32
|
+
return { refused: false, mode: 'strict', laidOut, result };
|
|
33
|
+
}
|
|
34
|
+
// Has DI (possibly partial): never re-layout. On-disk geometry → advisory.
|
|
35
|
+
const { rootElement } = await parse(xml);
|
|
36
|
+
const result = runGuard(rootElement, { mode: 'advisory' });
|
|
37
|
+
return { refused: false, mode: 'advisory', laidOut: xml, result };
|
|
38
|
+
}
|