@bpmnkit/core 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/dist/bpmn/bpmn-builder.d.ts +209 -3
- package/dist/bpmn/bpmn-builder.js +456 -16
- package/dist/bpmn/bpmn-model.d.ts +110 -0
- package/dist/bpmn/bpmn-parser.js +1413 -528
- package/dist/bpmn/bpmn-serializer.js +171 -19
- package/dist/bpmn/compact.d.ts +17 -2
- package/dist/bpmn/compact.js +3 -3
- package/dist/bpmn/diagram-diff.d.ts +71 -0
- package/dist/bpmn/diagram-diff.js +124 -0
- package/dist/bpmn/full-operations.d.ts +89 -0
- package/dist/bpmn/full-operations.js +478 -0
- package/dist/bpmn/index.d.ts +19 -0
- package/dist/bpmn/index.js +21 -0
- package/dist/bpmn/lint.d.ts +97 -0
- package/dist/bpmn/lint.js +135 -0
- package/dist/bpmn/optimize/feel.js +2 -2
- package/dist/bpmn/optimize/patterns.js +23 -16
- package/dist/bpmn/optimize/tasks.js +30 -7
- package/dist/bpmn/optimize/utils.js +2 -4
- package/dist/bpmn/optimize/variable-flow.js +58 -67
- package/dist/bpmn/preserving-writer.d.ts +64 -0
- package/dist/bpmn/preserving-writer.js +70 -0
- package/dist/bpmn/semantic-hash.d.ts +93 -0
- package/dist/bpmn/semantic-hash.js +155 -0
- package/dist/bpmn/sha256.d.ts +17 -0
- package/dist/bpmn/sha256.js +95 -0
- package/dist/bpmn/zeebe-extensions.d.ts +56 -0
- package/dist/bpmn/zeebe-extensions.js +79 -0
- package/dist/bpmn/zeebe-placement.d.ts +12 -0
- package/dist/bpmn/zeebe-placement.js +140 -0
- package/dist/dmn/dmn-serializer.js +7 -2
- package/dist/dmn/preserving-writer.d.ts +31 -0
- package/dist/dmn/preserving-writer.js +36 -0
- package/dist/errors.d.ts +40 -1
- package/dist/errors.js +41 -0
- package/dist/form/preserving-writer.d.ts +47 -0
- package/dist/form/preserving-writer.js +50 -0
- package/dist/index.d.ts +22 -5
- package/dist/index.js +14 -4
- package/dist/json/index.d.ts +5 -0
- package/dist/json/index.js +3 -0
- package/dist/json/json-patch.d.ts +65 -0
- package/dist/json/json-patch.js +416 -0
- package/dist/json/json-spans.d.ts +48 -0
- package/dist/json/json-spans.js +153 -0
- package/dist/layout/semantic/graph.d.ts +9 -1
- package/dist/layout/semantic/graph.js +42 -17
- package/dist/layout/semantic/route.js +102 -42
- package/dist/node/index.d.ts +10 -0
- package/dist/node/index.js +9 -0
- package/dist/node/write.d.ts +81 -0
- package/dist/node/write.js +167 -0
- package/dist/types/id-generator.js +11 -3
- package/dist/xml/index.d.ts +7 -1
- package/dist/xml/index.js +4 -1
- package/dist/xml/xml-parser.d.ts +71 -0
- package/dist/xml/xml-parser.js +437 -145
- package/dist/xml/xml-patch.d.ts +109 -0
- package/dist/xml/xml-patch.js +459 -0
- package/dist/xml/xml-spans.d.ts +45 -0
- package/dist/xml/xml-spans.js +74 -0
- package/package.json +8 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { optimize } from "./optimize/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Categories whose findings only mean something against a Camunda 8 engine.
|
|
4
|
+
*
|
|
5
|
+
* Measured rather than assumed: on a model with no execution platform and no
|
|
6
|
+
* Zeebe extensions, every other category either stays quiet or reports
|
|
7
|
+
* something structural that holds regardless, while `deploy` reports
|
|
8
|
+
* "serviceTask has no zeebe:taskDefinition type" as an **error** — a demand the
|
|
9
|
+
* author never signed up for. `connector` and `agentic` are the same kind of
|
|
10
|
+
* claim about the same engine.
|
|
11
|
+
*/
|
|
12
|
+
const ENGINE_CATEGORIES = ["deploy", "connector", "agentic"];
|
|
13
|
+
/**
|
|
14
|
+
* Reads the execution platform a model declares.
|
|
15
|
+
*
|
|
16
|
+
* @param definitions - The model to inspect.
|
|
17
|
+
*/
|
|
18
|
+
export function detectExecutionPlatform(definitions) {
|
|
19
|
+
const name = definitions.unknownAttributes["modeler:executionPlatform"];
|
|
20
|
+
const version = definitions.unknownAttributes["modeler:executionPlatformVersion"];
|
|
21
|
+
if (name === undefined || name === "")
|
|
22
|
+
return { id: "none" };
|
|
23
|
+
const normalised = name.toLowerCase();
|
|
24
|
+
const id = normalised.includes("cloud")
|
|
25
|
+
? "camunda-cloud"
|
|
26
|
+
: normalised.includes("camunda")
|
|
27
|
+
? "camunda-platform"
|
|
28
|
+
: "none";
|
|
29
|
+
return version === undefined ? { id, name } : { id, name, version };
|
|
30
|
+
}
|
|
31
|
+
/** Maps every element that carries diagram interchange to the plane drawing it. */
|
|
32
|
+
function planeIndex(definitions) {
|
|
33
|
+
const index = new Map();
|
|
34
|
+
for (const diagram of definitions.diagrams) {
|
|
35
|
+
const plane = diagram.plane.bpmnElement;
|
|
36
|
+
for (const shape of diagram.plane.shapes)
|
|
37
|
+
index.set(shape.bpmnElement, plane);
|
|
38
|
+
for (const edge of diagram.plane.edges)
|
|
39
|
+
index.set(edge.bpmnElement, plane);
|
|
40
|
+
}
|
|
41
|
+
return index;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runs the static analysis and returns it as plain, forwardable data.
|
|
45
|
+
*
|
|
46
|
+
* Two things this adds over calling {@link optimize} directly, both of them
|
|
47
|
+
* about handing findings to something that is not this process:
|
|
48
|
+
*
|
|
49
|
+
* - **The result is serialisable.** An `OptimizationFinding` carries an
|
|
50
|
+
* `applyFix` function, so it cannot cross a `postMessage` or a JSON boundary;
|
|
51
|
+
* a `LintDiagnostic` says `fixable: true` instead and leaves the fix where it
|
|
52
|
+
* can still be called.
|
|
53
|
+
* - **The rules match the model.** A diagram that names no execution platform
|
|
54
|
+
* is not judged against Camunda 8 deployability, so an engine-neutral file
|
|
55
|
+
* does not open covered in errors about extensions it was never going to
|
|
56
|
+
* have.
|
|
57
|
+
*
|
|
58
|
+
* @param definitions - The model to lint.
|
|
59
|
+
* @param options - Optimizer options, plus `forceEngineRules`.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const report = lintDiagram(Bpmn.parse(xml));
|
|
64
|
+
* for (const d of report.diagnostics) {
|
|
65
|
+
* console.log(`${d.severity} ${d.elementIds.join(",")}: ${d.message}`);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function lintDiagram(definitions, options = {}) {
|
|
70
|
+
const platform = detectExecutionPlatform(definitions);
|
|
71
|
+
const engineRules = options.forceEngineRules === true || platform.id !== "none";
|
|
72
|
+
const { forceEngineRules: _ignored, ...optimizeOptions } = options;
|
|
73
|
+
const report = optimize(definitions, optimizeOptions);
|
|
74
|
+
const requested = optimizeOptions.categories;
|
|
75
|
+
const findings = engineRules
|
|
76
|
+
? report.findings
|
|
77
|
+
: report.findings.filter((f) => !ENGINE_CATEGORIES.includes(f.category));
|
|
78
|
+
const planes = planeIndex(definitions);
|
|
79
|
+
const diagnostics = findings.map((finding) => {
|
|
80
|
+
const plane = finding.elementIds.map((id) => planes.get(id)).find((p) => p !== undefined);
|
|
81
|
+
const base = {
|
|
82
|
+
id: finding.id,
|
|
83
|
+
severity: finding.severity,
|
|
84
|
+
category: finding.category,
|
|
85
|
+
message: finding.message,
|
|
86
|
+
suggestion: finding.suggestion,
|
|
87
|
+
processId: finding.processId,
|
|
88
|
+
elementIds: finding.elementIds,
|
|
89
|
+
fixable: finding.applyFix !== undefined,
|
|
90
|
+
};
|
|
91
|
+
return plane === undefined ? base : { ...base, plane };
|
|
92
|
+
});
|
|
93
|
+
const counts = { error: 0, warning: 0, info: 0 };
|
|
94
|
+
for (const diagnostic of diagnostics)
|
|
95
|
+
counts[diagnostic.severity] += 1;
|
|
96
|
+
return {
|
|
97
|
+
diagnostics,
|
|
98
|
+
platform,
|
|
99
|
+
categories: lintCategories(definitions, options),
|
|
100
|
+
counts,
|
|
101
|
+
total: diagnostics.length,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Every category the optimizer knows, in the order it runs them. */
|
|
105
|
+
const ALL_CATEGORIES = [
|
|
106
|
+
"feel",
|
|
107
|
+
"feel-syntax",
|
|
108
|
+
"flow",
|
|
109
|
+
"naming",
|
|
110
|
+
"task-reuse",
|
|
111
|
+
"extract",
|
|
112
|
+
"pattern",
|
|
113
|
+
"data-flow",
|
|
114
|
+
"deploy",
|
|
115
|
+
"agentic",
|
|
116
|
+
"connector",
|
|
117
|
+
];
|
|
118
|
+
/**
|
|
119
|
+
* The categories that should run against a given model.
|
|
120
|
+
*
|
|
121
|
+
* Exported because more than one surface needs the same answer and they must
|
|
122
|
+
* not disagree: the canvas plugin lints through {@link lintDiagram}, while
|
|
123
|
+
* `casen lint` calls `optimize` directly so it can keep the `applyFix` closures
|
|
124
|
+
* that `LintDiagnostic` deliberately drops. Both ask here which rules apply.
|
|
125
|
+
*
|
|
126
|
+
* @param definitions - The model whose execution platform decides.
|
|
127
|
+
* @param options - `categories` to narrow to, and `forceEngineRules` to keep
|
|
128
|
+
* the engine layer on a model that names no platform.
|
|
129
|
+
*/
|
|
130
|
+
export function lintCategories(definitions, options = {}) {
|
|
131
|
+
const base = options.categories ?? ALL_CATEGORIES;
|
|
132
|
+
const engineRules = options.forceEngineRules === true || detectExecutionPlatform(definitions).id !== "none";
|
|
133
|
+
return engineRules ? [...base] : base.filter((c) => !ENGINE_CATEGORIES.includes(c));
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=lint.js.map
|
|
@@ -58,7 +58,7 @@ function scoreFeelExpression(expr, opts) {
|
|
|
58
58
|
// ---------------------------------------------------------------------------
|
|
59
59
|
export function analyzeFeel(p, opts) {
|
|
60
60
|
const findings = [];
|
|
61
|
-
const { bySource } = buildFlowIndex(p);
|
|
61
|
+
const { byId, bySource } = buildFlowIndex(p);
|
|
62
62
|
const processId = p.id;
|
|
63
63
|
// Track FEEL expressions across all sequence flows for duplicate detection
|
|
64
64
|
const exprToFlowIds = new Map();
|
|
@@ -66,7 +66,7 @@ export function analyzeFeel(p, opts) {
|
|
|
66
66
|
// Determine if source is an exclusive/inclusive gateway with more than one
|
|
67
67
|
// outgoing flow — a join (single outgoing flow) makes no decision, so its
|
|
68
68
|
// one outgoing flow needs neither a condition nor a default marker.
|
|
69
|
-
const srcEl =
|
|
69
|
+
const srcEl = byId.get(flow.sourceRef);
|
|
70
70
|
const srcIsDecisionGateway = srcEl !== undefined &&
|
|
71
71
|
(srcEl.type === "exclusiveGateway" || srcEl.type === "inclusiveGateway") &&
|
|
72
72
|
(bySource.get(srcEl.id)?.length ?? 0) > 1;
|
|
@@ -2,19 +2,25 @@ import { buildFlowIndex, readZeebeIoMapping, readZeebeTaskType } from "./utils.j
|
|
|
2
2
|
// ---------------------------------------------------------------------------
|
|
3
3
|
// Helpers
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
5
|
-
/**
|
|
6
|
-
function
|
|
5
|
+
/** hostId → event-definition types of the boundary events attached to it. */
|
|
6
|
+
function indexBoundaryTypes(p) {
|
|
7
|
+
const index = new Map();
|
|
7
8
|
for (const el of p.flowElements) {
|
|
8
9
|
if (el.type !== "boundaryEvent")
|
|
9
10
|
continue;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return true;
|
|
11
|
+
let types = index.get(el.attachedToRef);
|
|
12
|
+
if (!types) {
|
|
13
|
+
types = new Set();
|
|
14
|
+
index.set(el.attachedToRef, types);
|
|
15
15
|
}
|
|
16
|
+
for (const def of el.eventDefinitions)
|
|
17
|
+
types.add(def.type);
|
|
16
18
|
}
|
|
17
|
-
return
|
|
19
|
+
return index;
|
|
20
|
+
}
|
|
21
|
+
/** Returns true if the element has a boundary event of the given type attached. */
|
|
22
|
+
function hasBoundaryOf(elementId, eventType, boundaryTypes) {
|
|
23
|
+
return boundaryTypes.get(elementId)?.has(eventType) ?? false;
|
|
18
24
|
}
|
|
19
25
|
/** Returns true if the condition expression text appears to contain only literals (no variable names). */
|
|
20
26
|
function isLiteralOnlyCondition(text) {
|
|
@@ -36,7 +42,8 @@ function isLiteralOnlyCondition(text) {
|
|
|
36
42
|
export function analyzePatterns(p) {
|
|
37
43
|
const findings = [];
|
|
38
44
|
const processId = p.id;
|
|
39
|
-
const { bySource, byTarget } = buildFlowIndex(p);
|
|
45
|
+
const { byId, bySource, byTarget } = buildFlowIndex(p);
|
|
46
|
+
const boundaryTypes = indexBoundaryTypes(p);
|
|
40
47
|
// ── Rule 1: HTTP/REST service task without error boundary ───────────────
|
|
41
48
|
for (const el of p.flowElements) {
|
|
42
49
|
if (el.type !== "serviceTask")
|
|
@@ -47,7 +54,7 @@ export function analyzePatterns(p) {
|
|
|
47
54
|
jobType === "io.camunda.connector.HttpJson:1";
|
|
48
55
|
if (!isHttp)
|
|
49
56
|
continue;
|
|
50
|
-
if (!hasBoundaryOf(el.id, "error",
|
|
57
|
+
if (!hasBoundaryOf(el.id, "error", boundaryTypes)) {
|
|
51
58
|
findings.push({
|
|
52
59
|
id: "pattern/http-no-error-boundary",
|
|
53
60
|
category: "pattern",
|
|
@@ -82,7 +89,7 @@ export function analyzePatterns(p) {
|
|
|
82
89
|
for (const el of p.flowElements) {
|
|
83
90
|
if (el.type !== "subProcess" && el.type !== "adHocSubProcess" && el.type !== "transaction")
|
|
84
91
|
continue;
|
|
85
|
-
if (!hasBoundaryOf(el.id, "error",
|
|
92
|
+
if (!hasBoundaryOf(el.id, "error", boundaryTypes)) {
|
|
86
93
|
findings.push({
|
|
87
94
|
id: "pattern/subprocess-no-error-boundary",
|
|
88
95
|
category: "pattern",
|
|
@@ -98,7 +105,7 @@ export function analyzePatterns(p) {
|
|
|
98
105
|
for (const el of p.flowElements) {
|
|
99
106
|
if (el.type !== "callActivity")
|
|
100
107
|
continue;
|
|
101
|
-
if (!hasBoundaryOf(el.id, "error",
|
|
108
|
+
if (!hasBoundaryOf(el.id, "error", boundaryTypes)) {
|
|
102
109
|
findings.push({
|
|
103
110
|
id: "pattern/call-activity-no-error-boundary",
|
|
104
111
|
category: "pattern",
|
|
@@ -121,7 +128,7 @@ export function analyzePatterns(p) {
|
|
|
121
128
|
const branchTargets = [];
|
|
122
129
|
for (const flow of outflows) {
|
|
123
130
|
const targets = [];
|
|
124
|
-
const branchEl =
|
|
131
|
+
const branchEl = byId.get(flow.targetRef);
|
|
125
132
|
if (branchEl !== undefined) {
|
|
126
133
|
const io = readZeebeIoMapping(branchEl.extensionElements);
|
|
127
134
|
if (io !== null) {
|
|
@@ -158,7 +165,7 @@ export function analyzePatterns(p) {
|
|
|
158
165
|
for (const el of p.flowElements) {
|
|
159
166
|
if (el.type !== "userTask")
|
|
160
167
|
continue;
|
|
161
|
-
if (!hasBoundaryOf(el.id, "timer",
|
|
168
|
+
if (!hasBoundaryOf(el.id, "timer", boundaryTypes)) {
|
|
162
169
|
findings.push({
|
|
163
170
|
id: "pattern/user-task-no-timer",
|
|
164
171
|
category: "pattern",
|
|
@@ -200,7 +207,7 @@ export function analyzePatterns(p) {
|
|
|
200
207
|
continue;
|
|
201
208
|
const outflows = bySource.get(el.id) ?? [];
|
|
202
209
|
for (const flow of outflows) {
|
|
203
|
-
const target =
|
|
210
|
+
const target = byId.get(flow.targetRef);
|
|
204
211
|
if (target !== undefined && target.type === "endEvent") {
|
|
205
212
|
findings.push({
|
|
206
213
|
id: "pattern/catch-and-swallow",
|
|
@@ -348,7 +355,7 @@ export function analyzePatterns(p) {
|
|
|
348
355
|
if (cond === undefined || cond === "")
|
|
349
356
|
continue;
|
|
350
357
|
if (isLiteralOnlyCondition(cond)) {
|
|
351
|
-
const sourceEl =
|
|
358
|
+
const sourceEl = byId.get(flow.sourceRef);
|
|
352
359
|
findings.push({
|
|
353
360
|
id: "pattern/literal-condition",
|
|
354
361
|
category: "pattern",
|
|
@@ -53,21 +53,45 @@ function computeSimilarity(a, b) {
|
|
|
53
53
|
score += 0.15;
|
|
54
54
|
return score;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Cluster service tasks into connected components above the similarity
|
|
58
|
+
* threshold. Similarity requires an identical job type, so tasks are bucketed
|
|
59
|
+
* by type first and the pairwise comparison only runs within a bucket.
|
|
60
|
+
*/
|
|
57
61
|
function cluster(tasks, threshold) {
|
|
62
|
+
const byType = new Map();
|
|
63
|
+
const clusters = [];
|
|
64
|
+
for (const task of tasks) {
|
|
65
|
+
const type = readZeebeTaskType(task.extensionElements);
|
|
66
|
+
// Without a job type nothing is similar to this task; it stands alone.
|
|
67
|
+
if (type === null) {
|
|
68
|
+
clusters.push([task]);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const bucket = byType.get(type);
|
|
72
|
+
if (bucket)
|
|
73
|
+
bucket.push(task);
|
|
74
|
+
else
|
|
75
|
+
byType.set(type, [task]);
|
|
76
|
+
}
|
|
77
|
+
for (const bucket of byType.values())
|
|
78
|
+
clusterBucket(bucket, threshold, clusters);
|
|
79
|
+
// Report clusters in declaration order of their first member.
|
|
80
|
+
const order = new Map(tasks.map((task, index) => [task, index]));
|
|
81
|
+
clusters.sort((a, b) => (order.get(a[0]) ?? 0) - (order.get(b[0]) ?? 0));
|
|
82
|
+
return clusters;
|
|
83
|
+
}
|
|
84
|
+
function clusterBucket(tasks, threshold, clusters) {
|
|
58
85
|
const n = tasks.length;
|
|
59
86
|
const visited = new Array(n).fill(false);
|
|
60
|
-
const clusters = [];
|
|
61
87
|
for (let i = 0; i < n; i++) {
|
|
62
88
|
if (visited[i])
|
|
63
89
|
continue;
|
|
64
90
|
const group = [];
|
|
65
91
|
const queue = [i];
|
|
66
92
|
visited[i] = true;
|
|
67
|
-
|
|
68
|
-
const curr = queue
|
|
69
|
-
if (curr === undefined)
|
|
70
|
-
break;
|
|
93
|
+
for (let head = 0; head < queue.length; head++) {
|
|
94
|
+
const curr = queue[head];
|
|
71
95
|
const task = tasks[curr];
|
|
72
96
|
if (task === undefined)
|
|
73
97
|
break;
|
|
@@ -87,7 +111,6 @@ function cluster(tasks, threshold) {
|
|
|
87
111
|
}
|
|
88
112
|
clusters.push(group);
|
|
89
113
|
}
|
|
90
|
-
return clusters;
|
|
91
114
|
}
|
|
92
115
|
// ---------------------------------------------------------------------------
|
|
93
116
|
// Build the extracted BpmnDefinitions
|
|
@@ -70,10 +70,8 @@ export function buildFlowIndex(p) {
|
|
|
70
70
|
export function reachableFrom(startIds, bySource) {
|
|
71
71
|
const visited = new Set(startIds);
|
|
72
72
|
const queue = [...startIds];
|
|
73
|
-
|
|
74
|
-
const current = queue
|
|
75
|
-
if (current === undefined)
|
|
76
|
-
break;
|
|
73
|
+
for (let head = 0; head < queue.length; head++) {
|
|
74
|
+
const current = queue[head];
|
|
77
75
|
const outflows = bySource.get(current) ?? [];
|
|
78
76
|
for (const flow of outflows) {
|
|
79
77
|
if (!visited.has(flow.targetRef)) {
|
|
@@ -238,6 +238,58 @@ function readResultVariable(ext) {
|
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
240
|
// ---------------------------------------------------------------------------
|
|
241
|
+
// Scope propagation
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/**
|
|
244
|
+
* For every node in the flow graph, the variables produced by that node or by
|
|
245
|
+
* any node with a path to it. A worklist fixed point over the graph handles
|
|
246
|
+
* cycles and costs O((V + E) · vars), instead of one full graph walk per flow.
|
|
247
|
+
*/
|
|
248
|
+
function reachingProduces(flows, produces) {
|
|
249
|
+
const successors = new Map();
|
|
250
|
+
const scope = new Map();
|
|
251
|
+
for (const flow of flows) {
|
|
252
|
+
const out = successors.get(flow.sourceRef);
|
|
253
|
+
if (out)
|
|
254
|
+
out.push(flow.targetRef);
|
|
255
|
+
else
|
|
256
|
+
successors.set(flow.sourceRef, [flow.targetRef]);
|
|
257
|
+
if (!scope.has(flow.sourceRef)) {
|
|
258
|
+
scope.set(flow.sourceRef, new Set(produces.get(flow.sourceRef) ?? []));
|
|
259
|
+
}
|
|
260
|
+
if (!scope.has(flow.targetRef)) {
|
|
261
|
+
scope.set(flow.targetRef, new Set(produces.get(flow.targetRef) ?? []));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const queue = [...scope.keys()];
|
|
265
|
+
const queued = new Set(queue);
|
|
266
|
+
for (let head = 0; head < queue.length; head++) {
|
|
267
|
+
const id = queue[head];
|
|
268
|
+
queued.delete(id);
|
|
269
|
+
const own = scope.get(id);
|
|
270
|
+
const next = successors.get(id);
|
|
271
|
+
if (!own || own.size === 0 || !next)
|
|
272
|
+
continue;
|
|
273
|
+
for (const target of next) {
|
|
274
|
+
const targetScope = scope.get(target);
|
|
275
|
+
if (!targetScope)
|
|
276
|
+
continue;
|
|
277
|
+
let grew = false;
|
|
278
|
+
for (const v of own) {
|
|
279
|
+
if (!targetScope.has(v)) {
|
|
280
|
+
targetScope.add(v);
|
|
281
|
+
grew = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (grew && !queued.has(target)) {
|
|
285
|
+
queued.add(target);
|
|
286
|
+
queue.push(target);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return scope;
|
|
291
|
+
}
|
|
292
|
+
// ---------------------------------------------------------------------------
|
|
241
293
|
// Main analysis
|
|
242
294
|
// ---------------------------------------------------------------------------
|
|
243
295
|
export function analyzeVariableFlow(p) {
|
|
@@ -377,42 +429,10 @@ export function analyzeVariableFlow(p) {
|
|
|
377
429
|
});
|
|
378
430
|
}
|
|
379
431
|
// ── Per-edge scope findings (variables available at each sequence flow) ──
|
|
380
|
-
|
|
381
|
-
const reverseAdj = new Map();
|
|
432
|
+
const scopeAt = reachingProduces(p.sequenceFlows, elementProduces);
|
|
382
433
|
for (const flow of p.sequenceFlows) {
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
reverseAdj.set(flow.targetRef, set);
|
|
386
|
-
}
|
|
387
|
-
// Collect all transitive predecessors of an element (inclusive of start)
|
|
388
|
-
function allPredecessors(elementId) {
|
|
389
|
-
const visited = new Set();
|
|
390
|
-
const queue = [elementId];
|
|
391
|
-
while (queue.length > 0) {
|
|
392
|
-
const current = queue.shift();
|
|
393
|
-
if (current === undefined)
|
|
394
|
-
break;
|
|
395
|
-
const preds = reverseAdj.get(current);
|
|
396
|
-
if (preds === undefined)
|
|
397
|
-
continue;
|
|
398
|
-
for (const pred of preds) {
|
|
399
|
-
if (!visited.has(pred)) {
|
|
400
|
-
visited.add(pred);
|
|
401
|
-
queue.push(pred);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return visited;
|
|
406
|
-
}
|
|
407
|
-
for (const flow of p.sequenceFlows) {
|
|
408
|
-
const predIds = allPredecessors(flow.sourceRef);
|
|
409
|
-
predIds.add(flow.sourceRef);
|
|
410
|
-
const inScope = new Set();
|
|
411
|
-
for (const predId of predIds) {
|
|
412
|
-
for (const v of elementProduces.get(predId) ?? [])
|
|
413
|
-
inScope.add(v);
|
|
414
|
-
}
|
|
415
|
-
if (inScope.size === 0)
|
|
434
|
+
const inScope = scopeAt.get(flow.sourceRef);
|
|
435
|
+
if (inScope === undefined || inScope.size === 0)
|
|
416
436
|
continue;
|
|
417
437
|
const scopeVars = [...inScope].sort();
|
|
418
438
|
findings.push({
|
|
@@ -455,42 +475,13 @@ export function analyzeVariableFlow(p) {
|
|
|
455
475
|
}
|
|
456
476
|
}
|
|
457
477
|
}
|
|
458
|
-
// Build inner reverse adjacency for BFS
|
|
459
|
-
const innerReverseAdj = new Map();
|
|
460
|
-
for (const flow of sp.sequenceFlows) {
|
|
461
|
-
const set = innerReverseAdj.get(flow.targetRef) ?? new Set();
|
|
462
|
-
set.add(flow.sourceRef);
|
|
463
|
-
innerReverseAdj.set(flow.targetRef, set);
|
|
464
|
-
}
|
|
465
|
-
function innerAllPredecessors(elementId) {
|
|
466
|
-
const visited = new Set();
|
|
467
|
-
const queue = [elementId];
|
|
468
|
-
while (queue.length > 0) {
|
|
469
|
-
const current = queue.shift();
|
|
470
|
-
if (current === undefined)
|
|
471
|
-
break;
|
|
472
|
-
const preds = innerReverseAdj.get(current);
|
|
473
|
-
if (preds === undefined)
|
|
474
|
-
continue;
|
|
475
|
-
for (const pred of preds) {
|
|
476
|
-
if (!visited.has(pred)) {
|
|
477
|
-
visited.add(pred);
|
|
478
|
-
queue.push(pred);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return visited;
|
|
483
|
-
}
|
|
484
478
|
// Emit edge-scope findings for inner sequence flows
|
|
479
|
+
const innerScopeAt = reachingProduces(sp.sequenceFlows, innerProduces);
|
|
485
480
|
for (const flow of sp.sequenceFlows) {
|
|
486
|
-
const predIds = innerAllPredecessors(flow.sourceRef);
|
|
487
|
-
predIds.add(flow.sourceRef);
|
|
488
481
|
// Scope always includes the iteration variable, plus anything inner elements produce
|
|
489
482
|
const inScope = new Set([inputElement]);
|
|
490
|
-
for (const
|
|
491
|
-
|
|
492
|
-
inScope.add(v);
|
|
493
|
-
}
|
|
483
|
+
for (const v of innerScopeAt.get(flow.sourceRef) ?? [])
|
|
484
|
+
inScope.add(v);
|
|
494
485
|
const scopeVars = [...inScope].sort();
|
|
495
486
|
findings.push({
|
|
496
487
|
id: `data-flow/edge-scope:${flow.id}`,
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a model back over the file it came from, changing as little as
|
|
3
|
+
* possible.
|
|
4
|
+
*
|
|
5
|
+
* {@link serializeBpmn} writes a model the way this toolkit writes models. That
|
|
6
|
+
* is the right output for a new document and the wrong one for an existing
|
|
7
|
+
* file: the first visual edit reformats every line, and the commit says "the
|
|
8
|
+
* whole diagram" when it means "a box moved". These write the file that was
|
|
9
|
+
* already there, and change only what the model changed.
|
|
10
|
+
*
|
|
11
|
+
* ## Why order needs deciding, and why it is checked
|
|
12
|
+
*
|
|
13
|
+
* The model cannot represent the order a file writes its children in — a
|
|
14
|
+
* process holds `flowElements` and `sequenceFlows` as separate lists, a plane
|
|
15
|
+
* holds `shapes` and `edges` — so every serialization emits its own order, and
|
|
16
|
+
* a file written by another tool comes back reshuffled even when nothing
|
|
17
|
+
* changed. Keeping the original order is therefore worth more than keeping the
|
|
18
|
+
* indentation. The same goes for an attribute set to its schema default:
|
|
19
|
+
* `isExecutable="false"` disappears from a file that said it out loud.
|
|
20
|
+
*
|
|
21
|
+
* Neither is safe to assume in general, so neither is assumed. Each strategy is
|
|
22
|
+
* tried, the result is **parsed back and compared against a plain write**, and
|
|
23
|
+
* the first that reads the same is the one used. The plain write is the floor,
|
|
24
|
+
* so calling this is never worse than not.
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
import { type VerifiedPreserve } from "../xml/xml-patch.js";
|
|
29
|
+
import type { BpmnDefinitions } from "./bpmn-model.js";
|
|
30
|
+
export type { VerifiedPreserve as PreservingWriteResult };
|
|
31
|
+
/**
|
|
32
|
+
* Rewrites a document to say what a freshly serialized one says, keeping the
|
|
33
|
+
* original's formatting wherever a BPMN reader cannot tell the difference.
|
|
34
|
+
*
|
|
35
|
+
* Takes both sides as text, for a caller holding a serialized document rather
|
|
36
|
+
* than a model — an editor's `exportXml()`, say.
|
|
37
|
+
*
|
|
38
|
+
* @param original - The file's current contents.
|
|
39
|
+
* @param updated - The document as the serializer would write it now.
|
|
40
|
+
*/
|
|
41
|
+
export declare function preserveBpmnFormatting(original: string, updated: string): VerifiedPreserve;
|
|
42
|
+
/**
|
|
43
|
+
* Serializes a model over the document it came from, and reports what it
|
|
44
|
+
* managed to keep.
|
|
45
|
+
*
|
|
46
|
+
* @param original - The file's current contents.
|
|
47
|
+
* @param definitions - The model to write.
|
|
48
|
+
*/
|
|
49
|
+
export declare function exportPreservingResult(original: string, definitions: BpmnDefinitions): VerifiedPreserve;
|
|
50
|
+
/**
|
|
51
|
+
* Serializes a model over the document it came from.
|
|
52
|
+
*
|
|
53
|
+
* @param original - The file's current contents.
|
|
54
|
+
* @param definitions - The model to write.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const onDisk = await readFile("order.bpmn", "utf8");
|
|
59
|
+
* await writeFile("order.bpmn", exportPreserving(onDisk, edited));
|
|
60
|
+
* // Renaming one task changes one line, not the whole file.
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function exportPreserving(original: string, definitions: BpmnDefinitions): string;
|
|
64
|
+
//# sourceMappingURL=preserving-writer.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a model back over the file it came from, changing as little as
|
|
3
|
+
* possible.
|
|
4
|
+
*
|
|
5
|
+
* {@link serializeBpmn} writes a model the way this toolkit writes models. That
|
|
6
|
+
* is the right output for a new document and the wrong one for an existing
|
|
7
|
+
* file: the first visual edit reformats every line, and the commit says "the
|
|
8
|
+
* whole diagram" when it means "a box moved". These write the file that was
|
|
9
|
+
* already there, and change only what the model changed.
|
|
10
|
+
*
|
|
11
|
+
* ## Why order needs deciding, and why it is checked
|
|
12
|
+
*
|
|
13
|
+
* The model cannot represent the order a file writes its children in — a
|
|
14
|
+
* process holds `flowElements` and `sequenceFlows` as separate lists, a plane
|
|
15
|
+
* holds `shapes` and `edges` — so every serialization emits its own order, and
|
|
16
|
+
* a file written by another tool comes back reshuffled even when nothing
|
|
17
|
+
* changed. Keeping the original order is therefore worth more than keeping the
|
|
18
|
+
* indentation. The same goes for an attribute set to its schema default:
|
|
19
|
+
* `isExecutable="false"` disappears from a file that said it out loud.
|
|
20
|
+
*
|
|
21
|
+
* Neither is safe to assume in general, so neither is assumed. Each strategy is
|
|
22
|
+
* tried, the result is **parsed back and compared against a plain write**, and
|
|
23
|
+
* the first that reads the same is the one used. The plain write is the floor,
|
|
24
|
+
* so calling this is never worse than not.
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
import { preserveFormattingVerified } from "../xml/xml-patch.js";
|
|
29
|
+
import { parseBpmn } from "./bpmn-parser.js";
|
|
30
|
+
import { serializeBpmn } from "./bpmn-serializer.js";
|
|
31
|
+
/**
|
|
32
|
+
* Rewrites a document to say what a freshly serialized one says, keeping the
|
|
33
|
+
* original's formatting wherever a BPMN reader cannot tell the difference.
|
|
34
|
+
*
|
|
35
|
+
* Takes both sides as text, for a caller holding a serialized document rather
|
|
36
|
+
* than a model — an editor's `exportXml()`, say.
|
|
37
|
+
*
|
|
38
|
+
* @param original - The file's current contents.
|
|
39
|
+
* @param updated - The document as the serializer would write it now.
|
|
40
|
+
*/
|
|
41
|
+
export function preserveBpmnFormatting(original, updated) {
|
|
42
|
+
return preserveFormattingVerified(original, updated, parseBpmn);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serializes a model over the document it came from, and reports what it
|
|
46
|
+
* managed to keep.
|
|
47
|
+
*
|
|
48
|
+
* @param original - The file's current contents.
|
|
49
|
+
* @param definitions - The model to write.
|
|
50
|
+
*/
|
|
51
|
+
export function exportPreservingResult(original, definitions) {
|
|
52
|
+
return preserveBpmnFormatting(original, serializeBpmn(definitions));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Serializes a model over the document it came from.
|
|
56
|
+
*
|
|
57
|
+
* @param original - The file's current contents.
|
|
58
|
+
* @param definitions - The model to write.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const onDisk = await readFile("order.bpmn", "utf8");
|
|
63
|
+
* await writeFile("order.bpmn", exportPreserving(onDisk, edited));
|
|
64
|
+
* // Renaming one task changes one line, not the whole file.
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function exportPreserving(original, definitions) {
|
|
68
|
+
return exportPreservingResult(original, definitions).xml;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=preserving-writer.js.map
|