@bpmnkit/core 1.9.0 → 1.10.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 (108) hide show
  1. package/agent-cards/bpmn.md +3 -3
  2. package/builder-reference.md +11 -9
  3. package/dist/bpmn/auto-layout.js +82 -26
  4. package/dist/bpmn/bpmn-builder.d.ts +84 -7
  5. package/dist/bpmn/bpmn-builder.js +313 -78
  6. package/dist/bpmn/bpmn-model.d.ts +2 -0
  7. package/dist/bpmn/bpmn-parser.js +68 -76
  8. package/dist/bpmn/bpmn-serializer.js +60 -19
  9. package/dist/bpmn/bpmnlint.js +4 -69
  10. package/dist/bpmn/builder-rules.d.ts +20 -0
  11. package/dist/bpmn/builder-rules.js +120 -0
  12. package/dist/bpmn/camunda-compat-data.d.ts +10 -148
  13. package/dist/bpmn/camunda-compat-data.js +16 -407
  14. package/dist/bpmn/camunda-compat-feel.d.ts +3 -0
  15. package/dist/bpmn/camunda-compat-feel.js +1 -1
  16. package/dist/bpmn/camunda-compat.js +7 -6
  17. package/dist/bpmn/camunda7/export.js +4 -1
  18. package/dist/bpmn/camunda7/juel.js +2 -1
  19. package/dist/bpmn/camunda7/migrate.d.ts +23 -0
  20. package/dist/bpmn/camunda7/migrate.js +75 -3
  21. package/dist/bpmn/compact-stream.js +2 -1
  22. package/dist/bpmn/compact.d.ts +80 -4
  23. package/dist/bpmn/compact.js +220 -38
  24. package/dist/bpmn/feel-condition.d.ts +9 -0
  25. package/dist/bpmn/feel-condition.js +19 -0
  26. package/dist/bpmn/full-operations.js +31 -4
  27. package/dist/bpmn/index.d.ts +13 -3
  28. package/dist/bpmn/index.js +16 -15
  29. package/dist/bpmn/operations.d.ts +4 -4
  30. package/dist/bpmn/operations.js +14 -2
  31. package/dist/bpmn/optimize/bpmnlint-rules.js +7 -40
  32. package/dist/bpmn/optimize/index.js +15 -1
  33. package/dist/bpmn/optimize/tasks.js +12 -3
  34. package/dist/bpmn/process-delta.d.ts +18 -0
  35. package/dist/bpmn/process-delta.js +20 -2
  36. package/dist/bpmn/process-text-writer.js +27 -1
  37. package/dist/bpmn/process-text.d.ts +9 -3
  38. package/dist/bpmn/process-text.js +122 -16
  39. package/dist/bpmn/stable-ids.d.ts +2 -0
  40. package/dist/bpmn/stable-ids.js +8 -0
  41. package/dist/bpmn/zeebe-extensions.js +2 -1
  42. package/dist/bpmn/zeebe-placement.js +6 -129
  43. package/dist/bpmn/zeebe-validate/context.d.ts +132 -0
  44. package/dist/bpmn/zeebe-validate/context.js +241 -0
  45. package/dist/bpmn/zeebe-validate/gate.d.ts +87 -0
  46. package/dist/bpmn/zeebe-validate/gate.js +492 -0
  47. package/dist/bpmn/zeebe-validate/index.d.ts +37 -0
  48. package/dist/bpmn/zeebe-validate/index.js +106 -0
  49. package/dist/bpmn/zeebe-validate/rules/events.d.ts +4 -0
  50. package/dist/bpmn/zeebe-validate/rules/events.js +580 -0
  51. package/dist/bpmn/zeebe-validate/rules/extensions.d.ts +4 -0
  52. package/dist/bpmn/zeebe-validate/rules/extensions.js +411 -0
  53. package/dist/bpmn/zeebe-validate/rules/gateways.d.ts +3 -0
  54. package/dist/bpmn/zeebe-validate/rules/gateways.js +296 -0
  55. package/dist/bpmn/zeebe-validate/rules/references.d.ts +3 -0
  56. package/dist/bpmn/zeebe-validate/rules/references.js +495 -0
  57. package/dist/bpmn/zeebe-validate/rules/structure.d.ts +3 -0
  58. package/dist/bpmn/zeebe-validate/rules/structure.js +629 -0
  59. package/dist/bpmn/zeebe-validate/rules/tasks.d.ts +4 -0
  60. package/dist/bpmn/zeebe-validate/rules/tasks.js +446 -0
  61. package/dist/bpmn/zeebe-validate/xml.d.ts +15 -0
  62. package/dist/bpmn/zeebe-validate/xml.js +1062 -0
  63. package/dist/bpmn/zeebe-validate/xsd.d.ts +19 -0
  64. package/dist/bpmn/zeebe-validate/xsd.js +350 -0
  65. package/dist/connectors/apply-element.d.ts +5 -2
  66. package/dist/connectors/apply-element.js +6 -0
  67. package/dist/connectors/apply-many.d.ts +9 -2
  68. package/dist/connectors/apply-many.js +17 -2
  69. package/dist/connectors/apply.d.ts +4 -2
  70. package/dist/connectors/deployability.d.ts +27 -0
  71. package/dist/connectors/deployability.js +41 -0
  72. package/dist/connectors/index.d.ts +1 -0
  73. package/dist/connectors/lines.d.ts +10 -0
  74. package/dist/connectors/lines.js +13 -4
  75. package/dist/dmn/dmn-model.d.ts +24 -4
  76. package/dist/dmn/dmn-parser.js +37 -3
  77. package/dist/dmn/dmn-serializer.js +48 -47
  78. package/dist/dmn/lint.js +4 -11
  79. package/dist/errors.d.ts +30 -1
  80. package/dist/errors.js +31 -0
  81. package/dist/form/form-model.d.ts +11 -0
  82. package/dist/form/form-parser.d.ts +1 -0
  83. package/dist/form/form-parser.js +48 -12
  84. package/dist/form/form-serializer.js +40 -17
  85. package/dist/form/lint.js +6 -40
  86. package/dist/generated/bpmn-elements.d.ts +5 -0
  87. package/dist/generated/bpmn-elements.js +151 -0
  88. package/dist/generated/camunda-compat-data.d.ts +148 -0
  89. package/dist/generated/camunda-compat-data.js +371 -0
  90. package/dist/generated/dmn-elements.d.ts +12 -0
  91. package/dist/generated/dmn-elements.js +45 -0
  92. package/dist/generated/form-elements.d.ts +5 -0
  93. package/dist/generated/form-elements.js +45 -0
  94. package/dist/generated/lint-rules.d.ts +17 -0
  95. package/dist/generated/lint-rules.js +116 -0
  96. package/dist/generated/zeebe-elements.d.ts +10 -0
  97. package/dist/generated/zeebe-elements.js +168 -0
  98. package/dist/generated/zeebe-rules.d.ts +25 -0
  99. package/dist/generated/zeebe-rules.js +202 -0
  100. package/dist/index.d.ts +10 -4
  101. package/dist/index.js +4 -1
  102. package/dist/layout/annotations.js +21 -1
  103. package/dist/layout/orthogonal.js +9 -3
  104. package/dist/plan/compile.d.ts +26 -1
  105. package/dist/plan/compile.js +48 -6
  106. package/dist/plan/merge.d.ts +2 -1
  107. package/dist/plan/merge.js +13 -5
  108. package/package.json +2 -2
@@ -50,9 +50,13 @@ function stubOf(port) {
50
50
  const [dx, dy] = DIRS[SIDE_DIR[port.side]] ?? [0, 0];
51
51
  return { x: port.point.x + dx * STUB, y: port.point.y + dy * STUB };
52
52
  }
53
+ /** Grid lines sit on half units, so coordinates are compared after this rounding. */
54
+ function half(v) {
55
+ return Math.round(v * 2) / 2;
56
+ }
53
57
  /** Sorted, de-duplicated coordinates. */
54
58
  function axis(values) {
55
- const sorted = values.map((v) => Math.round(v * 2) / 2).sort((a, b) => a - b);
59
+ const sorted = values.map(half).sort((a, b) => a - b);
56
60
  const out = [];
57
61
  for (const v of sorted)
58
62
  if (out[out.length - 1] !== v)
@@ -75,7 +79,7 @@ function segmentBlocked(a, b, obstacles) {
75
79
  }
76
80
  /** Index of `v` in a sorted array (exact match expected). */
77
81
  function indexOf(sorted, v) {
78
- const target = Math.round(v * 2) / 2;
82
+ const target = half(v);
79
83
  let lo = 0;
80
84
  let hi = sorted.length - 1;
81
85
  while (lo <= hi) {
@@ -269,7 +273,9 @@ function search(request, obstacles, margin) {
269
273
  if (!startPort)
270
274
  return null;
271
275
  const last = points[points.length - 1];
272
- const endPort = ends.find(({ stub }) => last && stub.x === last.x && stub.y === last.y);
276
+ // The path ends on a grid point, which is the stub rounded like the axes; an
277
+ // exact comparison would miss every stub at a fractional coordinate.
278
+ const endPort = ends.find(({ stub }) => last && half(stub.x) === last.x && half(stub.y) === last.y);
273
279
  if (!endPort)
274
280
  return null;
275
281
  return simplify([startPort.point, ...points, endPort.port.point]);
@@ -1,5 +1,6 @@
1
1
  import type { AdHocSubProcessOptions, BoundaryEventOptions, IntermediateCatchEventOptions, ServiceTaskOptions, StartEventOptions } from "../bpmn/bpmn-builder.js";
2
2
  import type { BpmnDefinitions } from "../bpmn/bpmn-model.js";
3
+ import { type PlaceholderFill } from "../bpmn/zeebe-validate/gate.js";
3
4
  import type { ProcessPlan } from "./types.js";
4
5
  export interface PlanProblem {
5
6
  /** A path into the plan, e.g. "steps[2].branches[0].condition", for pinpointing the offending field. */
@@ -8,8 +9,15 @@ export interface PlanProblem {
8
9
  }
9
10
  export interface SynthResult {
10
11
  defs?: BpmnDefinitions;
12
+ /**
13
+ * The BPMN XML, set only when the model deploys on Camunda 8 (or `validate: false`).
14
+ * When Zeebe would refuse it, this is `undefined` and each reason is a `problems`
15
+ * entry: `Not deployable on Camunda <version>: <message> (<rule>)`.
16
+ */
11
17
  xml?: string;
12
18
  problems: PlanProblem[];
19
+ /** The placeholder values written, with `placeholders: true`. */
20
+ placeholders?: PlaceholderFill[];
13
21
  }
14
22
  /** What a connector template resolves to — structurally matches `@bpmnkit/connectors`' `ApplyResult`. */
15
23
  export interface ConnectorApplyResult {
@@ -29,11 +37,28 @@ export interface CompilePlanOptions {
29
37
  resolveConnector?: ConnectorResolver;
30
38
  /** Skip auto-applying safe optimizer fixes (default false). */
31
39
  skipAutoFix?: boolean;
40
+ /**
41
+ * Gate the result with `assertDeployable` (default `true`): a model Zeebe would
42
+ * refuse returns no `xml`, with the reasons in `problems`. `false` returns the
43
+ * XML whatever it is.
44
+ */
45
+ validate?: boolean;
46
+ /** Fill the gate's documented placeholders instead of refusing; the fills are in `placeholders`. */
47
+ placeholders?: boolean;
48
+ /** The Camunda 8 version to gate for. Default: the model's `executionPlatformVersion`. */
49
+ camundaVersion?: string;
32
50
  }
51
+ /**
52
+ * The XML of a compiled plan, or no XML and one problem per reason Zeebe would
53
+ * refuse it. Shared by {@link compilePlan} and `mergePlan`.
54
+ */
55
+ export declare function gatePlan(defs: BpmnDefinitions, problems: PlanProblem[], opts: CompilePlanOptions): SynthResult;
33
56
  /**
34
57
  * Compiles a `ProcessPlan` into laid-out, validated BPMN XML. Deterministic:
35
58
  * the same plan always produces the same XML. Problems are collected, not
36
- * thrown — check `result.problems` before using `result.xml`.
59
+ * thrown — check `result.problems` before using `result.xml`. A model Zeebe
60
+ * would refuse on deploy returns no `xml` (unless `validate: false`); with
61
+ * `placeholders: true` the missing values are filled and listed instead.
37
62
  */
38
63
  export declare function compilePlan(plan: ProcessPlan, opts?: CompilePlanOptions): SynthResult;
39
64
  //# sourceMappingURL=compile.d.ts.map
@@ -3,7 +3,42 @@ import { buildAiAgentSubProcess } from "../bpmn/agentic.js";
3
3
  import { applyAutoLayout } from "../bpmn/auto-layout.js";
4
4
  import { Bpmn } from "../bpmn/index.js";
5
5
  import { optimize } from "../bpmn/optimize/index.js";
6
+ import { assertDeployable } from "../bpmn/zeebe-validate/gate.js";
7
+ import { DeployabilityError } from "../errors.js";
6
8
  import { slugify, uniqueId } from "./slug.js";
9
+ /**
10
+ * The XML of a compiled plan, or no XML and one problem per reason Zeebe would
11
+ * refuse it. Shared by {@link compilePlan} and `mergePlan`.
12
+ */
13
+ export function gatePlan(defs, problems, opts) {
14
+ // Gated here, with the problems channel, rather than by the export.
15
+ const exportXml = (d) => Bpmn.export(d, { validate: false });
16
+ if (opts.validate === false)
17
+ return { defs, xml: exportXml(defs), problems };
18
+ try {
19
+ const gated = assertDeployable(defs, {
20
+ camundaVersion: opts.camundaVersion ?? defs.unknownAttributes["modeler:executionPlatformVersion"],
21
+ placeholders: opts.placeholders === true,
22
+ });
23
+ return {
24
+ defs: gated.definitions,
25
+ xml: exportXml(gated.definitions),
26
+ problems,
27
+ placeholders: gated.placeholders,
28
+ };
29
+ }
30
+ catch (err) {
31
+ if (!(err instanceof DeployabilityError))
32
+ throw err;
33
+ for (const finding of err.findings) {
34
+ problems.push({
35
+ path: finding.elementIds.length > 0 ? `element:${finding.elementIds.join(",")}` : "process",
36
+ message: `Not deployable on Camunda ${err.camundaVersion}: ${finding.message} (${finding.id})`,
37
+ });
38
+ }
39
+ return { defs, problems };
40
+ }
41
+ }
7
42
  // ---------------------------------------------------------------------------
8
43
  // ID assignment — every step gets a stable id before any builder call is made,
9
44
  // so gateway branches can `connectTo()` the right target up front.
@@ -227,7 +262,11 @@ function emitStep(b, step, id, path, nextId, idOf, resolve, problems) {
227
262
  return;
228
263
  }
229
264
  case "subProcess":
230
- b.subProcess(id, (sb) => emitSteps(sb, step.steps, idOf, resolve, problems, `${path}.steps`), {
265
+ b.subProcess(id, (sb) => {
266
+ // Zeebe rejects an embedded sub-process without exactly one none start event.
267
+ sb.startEvent(`${id}_start`);
268
+ emitSteps(sb, step.steps, idOf, resolve, problems, `${path}.steps`);
269
+ }, {
231
270
  name: step.name,
232
271
  documentation: step.documentation,
233
272
  multiInstance: step.multiInstance
@@ -302,7 +341,9 @@ function emitSteps(b, steps, idOf, resolve, problems, path, indexOffset = 0) {
302
341
  /**
303
342
  * Compiles a `ProcessPlan` into laid-out, validated BPMN XML. Deterministic:
304
343
  * the same plan always produces the same XML. Problems are collected, not
305
- * thrown — check `result.problems` before using `result.xml`.
344
+ * thrown — check `result.problems` before using `result.xml`. A model Zeebe
345
+ * would refuse on deploy returns no `xml` (unless `validate: false`); with
346
+ * `placeholders: true` the missing values are filled and listed instead.
306
347
  */
307
348
  export function compilePlan(plan, opts = {}) {
308
349
  const problems = [];
@@ -345,10 +386,12 @@ export function compilePlan(plan, opts = {}) {
345
386
  messageName: firstStep.message?.name,
346
387
  zeebeProperties: startResult?.startEvent?.zeebeProperties,
347
388
  });
348
- emitSteps(builder, restSteps, idOf, opts.resolveConnector, problems, "steps", 1);
349
389
  let defs;
350
390
  try {
351
- defs = builder.build();
391
+ // The builder refuses some steps at the call (a message wait with no key): a problem, not a throw.
392
+ emitSteps(builder, restSteps, idOf, opts.resolveConnector, problems, "steps", 1);
393
+ // Gated once at the end, after the optimize pass has applied its fixes.
394
+ defs = builder.build({ validate: false });
352
395
  }
353
396
  catch (err) {
354
397
  problems.push({
@@ -374,7 +417,6 @@ export function compilePlan(plan, opts = {}) {
374
417
  });
375
418
  }
376
419
  }
377
- const xml = Bpmn.export(laidOut);
378
- return { defs: laidOut, xml, problems };
420
+ return gatePlan(laidOut, problems, opts);
379
421
  }
380
422
  //# sourceMappingURL=compile.js.map
@@ -7,7 +7,8 @@ import type { ProcessPlan } from "./types.js";
7
7
  * are appended). `delta.steps[0]` must still be a `start` step — the merge
8
8
  * only uses `delta`'s flow elements and sequence flows, and drops the
9
9
  * delta's own start/end events when a same-id start/end already exists in
10
- * `existing`.
10
+ * `existing`. As for `compilePlan`, a merged model Zeebe would refuse returns
11
+ * no `xml`, with the reasons in `problems`.
11
12
  */
12
13
  export declare function mergePlan(existing: BpmnDefinitions, delta: ProcessPlan, opts?: CompilePlanOptions): SynthResult;
13
14
  //# sourceMappingURL=merge.d.ts.map
@@ -6,19 +6,20 @@
6
6
  * their meaning but not necessarily their exact DI coordinates).
7
7
  */
8
8
  import { applyAutoLayout } from "../bpmn/auto-layout.js";
9
- import { Bpmn } from "../bpmn/index.js";
10
9
  import { optimize } from "../bpmn/optimize/index.js";
11
- import { compilePlan } from "./compile.js";
10
+ import { compilePlan, gatePlan } from "./compile.js";
12
11
  /**
13
12
  * Compiles `delta` standalone, then merges its elements/flows into
14
13
  * `existing`'s matching process by id (matching ids are replaced, new ids
15
14
  * are appended). `delta.steps[0]` must still be a `start` step — the merge
16
15
  * only uses `delta`'s flow elements and sequence flows, and drops the
17
16
  * delta's own start/end events when a same-id start/end already exists in
18
- * `existing`.
17
+ * `existing`. As for `compilePlan`, a merged model Zeebe would refuse returns
18
+ * no `xml`, with the reasons in `problems`.
19
19
  */
20
20
  export function mergePlan(existing, delta, opts = {}) {
21
- const deltaResult = compilePlan(delta, { ...opts, skipAutoFix: true });
21
+ // The delta alone need not deploy; the merged model is gated below.
22
+ const deltaResult = compilePlan(delta, { ...opts, skipAutoFix: true, validate: false });
22
23
  if (!deltaResult.defs)
23
24
  return deltaResult;
24
25
  const targetProcess = existing.processes.find((p) => p.id === delta.process.id) ?? existing.processes[0];
@@ -42,6 +43,13 @@ export function mergePlan(existing, delta, opts = {}) {
42
43
  const deltaElementIds = new Set(deltaProcess.flowElements.map((e) => e.id));
43
44
  targetProcess.sequenceFlows = targetProcess.sequenceFlows.filter((f) => !deltaElementIds.has(f.sourceRef) && !deltaElementIds.has(f.targetRef));
44
45
  targetProcess.sequenceFlows.push(...deltaProcess.sequenceFlows);
46
+ // An untouched element can lose a flow above; a stale <incoming>/<outgoing> id does not deploy.
47
+ for (const el of targetProcess.flowElements) {
48
+ if (!("incoming" in el))
49
+ continue;
50
+ el.incoming = targetProcess.sequenceFlows.filter((f) => f.targetRef === el.id).map((f) => f.id);
51
+ el.outgoing = targetProcess.sequenceFlows.filter((f) => f.sourceRef === el.id).map((f) => f.id);
52
+ }
45
53
  // Pull in any new root error/message/signal/escalation definitions the delta introduced.
46
54
  for (const err of deltaResult.defs.errors) {
47
55
  if (!existing.errors.some((e) => e.id === err.id))
@@ -75,6 +83,6 @@ export function mergePlan(existing, delta, opts = {}) {
75
83
  });
76
84
  }
77
85
  }
78
- return { defs: laidOut, xml: Bpmn.export(laidOut), problems };
86
+ return gatePlan(laidOut, problems, opts);
79
87
  }
80
88
  //# sourceMappingURL=merge.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmnkit/core",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "node": ">=20"
34
34
  },
35
35
  "dependencies": {
36
- "@bpmnkit/feel": "^1.1.1"
36
+ "@bpmnkit/feel": "^1.1.2"
37
37
  },
38
38
  "description": "TypeScript-first BPMN 2.0 SDK — parse, build, layout, and optimize diagrams",
39
39
  "keywords": [