@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
@@ -14,6 +14,7 @@ import { applyTemplateToElement, messageRefOf } from "./apply-element.js";
14
14
  import { evalCondition, resolveValues } from "./apply.js";
15
15
  import { connectorAlias, connectorCards, templateIdForAlias } from "./cards.js";
16
16
  import { allTemplates, getTemplate, isSecretField, propertyKey } from "./catalog.js";
17
+ import { appliedDeployProblems } from "./deployability.js";
17
18
  /**
18
19
  * How to write `with` lines — the system prompt of the connect pass, which
19
20
  * configures the connectors of a diagram that already has its shape. The
@@ -442,9 +443,13 @@ function applyApiService(service, values, written, out) {
442
443
  *
443
444
  * Pass `parseProcessText(text).connectors` with the expanded diagram, or the
444
445
  * lines of a change script with the ids they resolve to.
446
+ *
447
+ * Unless `validate: false`, the configured elements are then checked with Zeebe's
448
+ * deploy rules; each error is a problem on the line that configured the element.
445
449
  */
446
450
  export function applyConnectorLines(definitions, lines, options = {}) {
447
451
  const out = { definitions, problems: [], fixes: [], questions: [] };
452
+ const lineOf = new Map();
448
453
  for (const line of lines) {
449
454
  const resolved = resolveConnectorLine(line, options);
450
455
  for (const message of resolved.problems)
@@ -459,10 +464,11 @@ export function applyConnectorLines(definitions, lines, options = {}) {
459
464
  const kept = current?.unknownAttributes["zeebe:modelerTemplate"] === template.id
460
465
  ? readValues(out.definitions, current, template)
461
466
  : {};
462
- const applied = applyTemplateToElement(out.definitions, line.elementId, template, {
463
- ...kept,
464
- ...resolved.values,
465
- });
467
+ const applied = applyTemplateToElement(out.definitions, line.elementId, template, { ...kept, ...resolved.values },
468
+ // Checked once below, when every line has been applied.
469
+ { validate: false });
470
+ if (!lineOf.has(line.elementId))
471
+ lineOf.set(line.elementId, line.line);
466
472
  out.definitions = applied.definitions;
467
473
  const card = resolved.card;
468
474
  const head = `with ${line.id}: ${card.alias}${card.operation ? ` ${card.operation}` : ""}`;
@@ -490,6 +496,9 @@ export function applyConnectorLines(definitions, lines, options = {}) {
490
496
  }
491
497
  }
492
498
  }
499
+ for (const problem of appliedDeployProblems(out.definitions, [...lineOf.keys()], options)) {
500
+ out.problems.push({ line: lineOf.get(problem.elementId) ?? 0, message: problem.message });
501
+ }
493
502
  return out;
494
503
  }
495
504
  function elementOf(definitions, id) {
@@ -1,8 +1,9 @@
1
+ import type { DMN_ATTRIBUTE_VALUES } from "../generated/dmn-elements.js";
1
2
  import type { XmlElement } from "../types/xml-element.js";
2
- /** DMN hit policy for decision tables. */
3
- export type HitPolicy = "UNIQUE" | "FIRST" | "ANY" | "COLLECT" | "RULE ORDER" | "OUTPUT ORDER" | "PRIORITY";
4
- /** DMN collect aggregation for COLLECT hit policy. */
5
- export type DmnAggregation = "SUM" | "MIN" | "MAX" | "COUNT";
3
+ /** DMN hit policy for decision tables (`spec/elements/dmn.json`). */
4
+ export type HitPolicy = (typeof DMN_ATTRIBUTE_VALUES)["decisionTable.hitPolicy"][number];
5
+ /** DMN collect aggregation for COLLECT hit policy (`spec/elements/dmn.json`). */
6
+ export type DmnAggregation = (typeof DMN_ATTRIBUTE_VALUES)["decisionTable.aggregation"][number];
6
7
  /** DMN type reference for inputs/outputs. */
7
8
  export type DmnTypeRef = "string" | "boolean" | "number" | "date";
8
9
  /** A single input column in a decision table. */
@@ -21,6 +22,12 @@ export interface DmnOutput {
21
22
  label?: string;
22
23
  name?: string;
23
24
  typeRef?: DmnTypeRef;
25
+ /**
26
+ * Allowed output values, the text of `<outputValues><text>`: a comma-separated
27
+ * list of FEEL literals in decreasing priority (`"high","medium","low"`).
28
+ * PRIORITY and OUTPUT ORDER rank by it.
29
+ */
30
+ outputValues?: string;
24
31
  }
25
32
  /** An input entry (unary test) within a rule. */
26
33
  export interface DmnInputEntry {
@@ -70,12 +77,25 @@ export interface DmnAuthorityRequirement {
70
77
  /** Ref to knowledge source id. */
71
78
  requiredAuthority?: string;
72
79
  }
80
+ /**
81
+ * A decision's `<literalExpression>`: the FEEL expression of a decision without
82
+ * a table. Only the attributes below and `<text>` are modelled; other children
83
+ * (such as `importedValues`) are not kept.
84
+ */
85
+ export interface DmnLiteralExpression {
86
+ id?: string;
87
+ typeRef?: string;
88
+ expressionLanguage?: string;
89
+ text?: string;
90
+ }
73
91
  /** A top-level decision element. */
74
92
  export interface DmnDecision {
75
93
  id: string;
76
94
  name?: string;
77
95
  /** Decision table (optional — a decision may contain a literal expression instead). */
78
96
  decisionTable?: DmnDecisionTable;
97
+ /** Literal expression (a decision has either this or a decision table). */
98
+ literalExpression?: DmnLiteralExpression;
79
99
  informationRequirements: DmnInformationRequirement[];
80
100
  knowledgeRequirements: DmnKnowledgeRequirement[];
81
101
  authorityRequirements: DmnAuthorityRequirement[];
@@ -49,6 +49,7 @@ function parseHitPolicy(value) {
49
49
  return undefined;
50
50
  return value;
51
51
  }
52
+ const EMPTY = { name: "", attributes: {}, children: [] };
52
53
  function parseInputExpression(el) {
53
54
  const textEl = findChild(el, "text");
54
55
  return {
@@ -74,6 +75,7 @@ function parseOutput(el) {
74
75
  label: attr(el, "label"),
75
76
  name: attr(el, "name"),
76
77
  typeRef: parseTypeRef(attr(el, "typeRef")),
78
+ outputValues: findChild(findChild(el, "outputValues") ?? EMPTY, "text")?.text,
77
79
  };
78
80
  }
79
81
  function parseInputEntry(el) {
@@ -136,26 +138,58 @@ function parseAuthorityRequirement(el) {
136
138
  requiredAuthority: deref(attr(reqAuthEl ?? { name: "", attributes: {}, children: [] }, "href")),
137
139
  };
138
140
  }
141
+ function parseLiteralExpression(el) {
142
+ return {
143
+ id: attr(el, "id"),
144
+ typeRef: attr(el, "typeRef"),
145
+ expressionLanguage: attr(el, "expressionLanguage"),
146
+ text: findChild(el, "text")?.text,
147
+ };
148
+ }
149
+ /**
150
+ * Whitespace between the children of kept foreign content is formatting. Kept as
151
+ * text of the parent it was written back indented again, so every export added a
152
+ * blank line.
153
+ */
154
+ function withoutLayoutWhitespace(el) {
155
+ const out = {
156
+ name: el.name,
157
+ attributes: el.attributes,
158
+ children: el.children.map(withoutLayoutWhitespace),
159
+ };
160
+ const keep = el.text !== undefined && (el.children.length === 0 || el.text.trim() !== "");
161
+ if (keep)
162
+ out.text = el.text;
163
+ return out;
164
+ }
139
165
  function parseDecision(el) {
140
166
  const tableEl = findChild(el, "decisionTable");
141
- const extensionEls = findChild(el, "extensionElements");
167
+ // An empty <extensionElements/> carries nothing, and an empty list would not
168
+ // survive an export (the serializer omits it), so it counts as absent.
169
+ const extensionFound = findChild(el, "extensionElements");
170
+ const extensionEls = extensionFound && extensionFound.children.length > 0 ? extensionFound : undefined;
142
171
  const knownLocalNames = new Set([
143
172
  "decisionTable",
173
+ "literalExpression",
144
174
  "extensionElements",
145
175
  "informationRequirement",
146
176
  "knowledgeRequirement",
147
177
  "authorityRequirement",
148
178
  ]);
149
- const unknownChildren = el.children.filter((c) => !knownLocalNames.has(localName(c.name)));
179
+ const literalEl = findChild(el, "literalExpression");
180
+ const unknownChildren = el.children
181
+ .filter((c) => !knownLocalNames.has(localName(c.name)))
182
+ .map(withoutLayoutWhitespace);
150
183
  return {
151
184
  id: requiredAttr(el, "id"),
152
185
  name: attr(el, "name"),
153
186
  decisionTable: tableEl ? parseDecisionTable(tableEl) : undefined,
187
+ literalExpression: literalEl ? parseLiteralExpression(literalEl) : undefined,
154
188
  informationRequirements: findChildren(el, "informationRequirement").map(parseInformationRequirement),
155
189
  knowledgeRequirements: findChildren(el, "knowledgeRequirement").map(parseKnowledgeRequirement),
156
190
  authorityRequirements: findChildren(el, "authorityRequirement").map(parseAuthorityRequirement),
157
191
  extensionElements: extensionEls
158
- ? extensionEls.children
192
+ ? extensionEls.children.map(withoutLayoutWhitespace)
159
193
  : unknownChildren.length > 0
160
194
  ? unknownChildren
161
195
  : undefined,
@@ -34,7 +34,15 @@ function serializeOutput(output) {
34
34
  attrs.name = output.name;
35
35
  if (output.typeRef)
36
36
  attrs.typeRef = output.typeRef;
37
- return { name: "output", attributes: attrs, children: [] };
37
+ const children = [];
38
+ if (output.outputValues) {
39
+ children.push({
40
+ name: "outputValues",
41
+ attributes: {},
42
+ children: [textElement(output.outputValues)],
43
+ });
44
+ }
45
+ return { name: "output", attributes: attrs, children };
38
46
  }
39
47
  function serializeRule(rule) {
40
48
  const children = [];
@@ -85,61 +93,51 @@ function serializeDecisionTable(table) {
85
93
  ];
86
94
  return { name: "decisionTable", attributes: attrs, children };
87
95
  }
96
+ function refElement(name, target) {
97
+ // A reference that parsed to nothing stays nothing: \`href="#undefined"\` would
98
+ // read back as a reference to an element with that id.
99
+ return target ? [{ name, attributes: { href: `#${target}` }, children: [] }] : [];
100
+ }
88
101
  function serializeInformationRequirements(decision) {
89
- return decision.informationRequirements.map((req) => {
90
- const child = req.requiredDecision
91
- ? { name: "requiredDecision", attributes: { href: `#${req.requiredDecision}` }, children: [] }
92
- : { name: "requiredInput", attributes: { href: `#${req.requiredInput}` }, children: [] };
93
- return {
94
- name: "informationRequirement",
95
- attributes: { id: req.id },
96
- children: [child],
97
- };
98
- });
102
+ return decision.informationRequirements.map((req) => ({
103
+ name: "informationRequirement",
104
+ attributes: { id: req.id },
105
+ children: req.requiredDecision
106
+ ? refElement("requiredDecision", req.requiredDecision)
107
+ : refElement("requiredInput", req.requiredInput),
108
+ }));
99
109
  }
100
110
  function serializeKnowledgeRequirements(reqs) {
101
111
  return reqs.map((req) => ({
102
112
  name: "knowledgeRequirement",
103
113
  attributes: { id: req.id },
104
- children: [
105
- {
106
- name: "requiredKnowledge",
107
- attributes: { href: `#${req.requiredKnowledge}` },
108
- children: [],
109
- },
110
- ],
114
+ children: refElement("requiredKnowledge", req.requiredKnowledge),
111
115
  }));
112
116
  }
113
117
  function serializeAuthorityRequirements(reqs) {
114
- return reqs.map((req) => {
115
- let child;
116
- if (req.requiredDecision) {
117
- child = {
118
- name: "requiredDecision",
119
- attributes: { href: `#${req.requiredDecision}` },
120
- children: [],
121
- };
122
- }
123
- else if (req.requiredInput) {
124
- child = {
125
- name: "requiredInput",
126
- attributes: { href: `#${req.requiredInput}` },
127
- children: [],
128
- };
129
- }
130
- else {
131
- child = {
132
- name: "requiredAuthority",
133
- attributes: { href: `#${req.requiredAuthority ?? ""}` },
134
- children: [],
135
- };
136
- }
137
- return {
138
- name: "authorityRequirement",
139
- attributes: { id: req.id },
140
- children: [child],
141
- };
142
- });
118
+ return reqs.map((req) => ({
119
+ name: "authorityRequirement",
120
+ attributes: { id: req.id },
121
+ children: req.requiredDecision
122
+ ? refElement("requiredDecision", req.requiredDecision)
123
+ : req.requiredInput
124
+ ? refElement("requiredInput", req.requiredInput)
125
+ : refElement("requiredAuthority", req.requiredAuthority),
126
+ }));
127
+ }
128
+ function serializeLiteralExpression(literal) {
129
+ const attrs = {};
130
+ if (literal.id)
131
+ attrs.id = literal.id;
132
+ if (literal.typeRef)
133
+ attrs.typeRef = literal.typeRef;
134
+ if (literal.expressionLanguage)
135
+ attrs.expressionLanguage = literal.expressionLanguage;
136
+ return {
137
+ name: "literalExpression",
138
+ attributes: attrs,
139
+ children: literal.text ? [textElement(literal.text)] : [],
140
+ };
143
141
  }
144
142
  function serializeDecision(decision) {
145
143
  const children = [];
@@ -156,6 +154,9 @@ function serializeDecision(decision) {
156
154
  if (decision.decisionTable) {
157
155
  children.push(serializeDecisionTable(decision.decisionTable));
158
156
  }
157
+ if (decision.literalExpression) {
158
+ children.push(serializeLiteralExpression(decision.literalExpression));
159
+ }
159
160
  const attrs = { id: decision.id };
160
161
  if (decision.name)
161
162
  attrs.name = decision.name;
package/dist/dmn/lint.js CHANGED
@@ -1,16 +1,9 @@
1
1
  import { parseExpression, parseUnaryTests } from "@bpmnkit/feel";
2
2
  import { withCardHint } from "../check-finding.js";
3
+ import { DMN_ATTRIBUTE_VALUES } from "../generated/dmn-elements.js";
3
4
  import { parseXml } from "../xml/xml-parser.js";
4
- const HIT_POLICIES = [
5
- "UNIQUE",
6
- "FIRST",
7
- "PRIORITY",
8
- "ANY",
9
- "COLLECT",
10
- "RULE ORDER",
11
- "OUTPUT ORDER",
12
- ];
13
- const AGGREGATIONS = ["SUM", "MIN", "MAX", "COUNT"];
5
+ const HIT_POLICIES = DMN_ATTRIBUTE_VALUES["decisionTable.hitPolicy"];
6
+ const AGGREGATIONS = DMN_ATTRIBUTE_VALUES["decisionTable.aggregation"];
14
7
  /** The type names Camunda's DMN engine resolves; anything else is silently treated as `Any`. */
15
8
  const TYPE_REFS = new Set([
16
9
  "string",
@@ -378,7 +371,7 @@ function checkDecision(decision, findings) {
378
371
  }
379
372
  for (const output of outputs) {
380
373
  const outputId = output.attributes.id;
381
- checkTypeRef(output, outputId, `Output "${output.attributes.name ?? outputId}"`, findings);
374
+ checkTypeRef(output, outputId, `Output "${output.attributes.name ?? outputId ?? "?"}"`, findings);
382
375
  if (outputs.length > 1 && (output.attributes.name ?? "") === "") {
383
376
  findings.push({
384
377
  rule: "dmn/missing-output-name",
package/dist/errors.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { OptimizationFinding } from "./bpmn/optimize/types.js";
1
2
  import type { SemanticDiff } from "./bpmn/semantic-hash.js";
2
3
  /**
3
4
  * Typed error codes for all errors thrown by `@bpmnkit/core`.
@@ -23,7 +24,9 @@ export type ErrorCode =
23
24
  /** Serialising a model and reading it back did not reproduce the model. */
24
25
  | "write-verification-error"
25
26
  /** The output file could not be written. */
26
- | "write-error";
27
+ | "write-error"
28
+ /** Zeebe would reject the model on deploy. */
29
+ | "deployability-error";
27
30
  /**
28
31
  * Base class for all errors thrown by `@bpmnkit/core`.
29
32
  *
@@ -113,4 +116,30 @@ export declare class WriteVerificationError extends BpmnSdkError {
113
116
  export declare class WriteError extends BpmnSdkError {
114
117
  constructor(message: string);
115
118
  }
119
+ /**
120
+ * Thrown when Zeebe would reject a model on deploy (see `assertDeployable`).
121
+ *
122
+ * The message names the Camunda version and lists one line per error finding,
123
+ * `- <elementId>: <Zeebe's message> (zeebe/<rule>)`; {@link findings} has them all.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * import { assertDeployable, DeployabilityError } from "@bpmnkit/core"
128
+ *
129
+ * try {
130
+ * assertDeployable(definitions)
131
+ * } catch (err) {
132
+ * if (err instanceof DeployabilityError) {
133
+ * for (const f of err.findings) console.error(f.elementIds[0], f.message)
134
+ * }
135
+ * }
136
+ * ```
137
+ */
138
+ export declare class DeployabilityError extends BpmnSdkError {
139
+ /** The findings of severity `error`, in the validator's order. */
140
+ readonly findings: OptimizationFinding[];
141
+ /** The `major.minor` Camunda version the model was checked for. */
142
+ readonly camundaVersion: string;
143
+ constructor(message: string, findings: OptimizationFinding[], camundaVersion: string);
144
+ }
116
145
  //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js CHANGED
@@ -104,4 +104,35 @@ export class WriteError extends BpmnSdkError {
104
104
  this.name = "WriteError";
105
105
  }
106
106
  }
107
+ /**
108
+ * Thrown when Zeebe would reject a model on deploy (see `assertDeployable`).
109
+ *
110
+ * The message names the Camunda version and lists one line per error finding,
111
+ * `- <elementId>: <Zeebe's message> (zeebe/<rule>)`; {@link findings} has them all.
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * import { assertDeployable, DeployabilityError } from "@bpmnkit/core"
116
+ *
117
+ * try {
118
+ * assertDeployable(definitions)
119
+ * } catch (err) {
120
+ * if (err instanceof DeployabilityError) {
121
+ * for (const f of err.findings) console.error(f.elementIds[0], f.message)
122
+ * }
123
+ * }
124
+ * ```
125
+ */
126
+ export class DeployabilityError extends BpmnSdkError {
127
+ /** The findings of severity `error`, in the validator's order. */
128
+ findings;
129
+ /** The `major.minor` Camunda version the model was checked for. */
130
+ camundaVersion;
131
+ constructor(message, findings, camundaVersion) {
132
+ super(message, "deployability-error");
133
+ this.name = "DeployabilityError";
134
+ this.findings = findings;
135
+ this.camundaVersion = camundaVersion;
136
+ }
137
+ }
107
138
  //# sourceMappingURL=errors.js.map
@@ -2,6 +2,8 @@
2
2
  export interface FormLayout {
3
3
  row?: string;
4
4
  columns?: number | null;
5
+ /** Keys the model does not know (or whose value had an unexpected type), kept verbatim. */
6
+ extraProps?: Record<string, unknown>;
5
7
  }
6
8
  /**
7
9
  * A layout as a caller hands it to the builder. Both fields accept `null`, and
@@ -24,11 +26,20 @@ export interface FormValidation {
24
26
  required?: boolean;
25
27
  minLength?: number;
26
28
  maxLength?: number;
29
+ min?: number;
30
+ max?: number;
31
+ pattern?: string;
32
+ /** form-js preset such as "email" or "phone", or "custom" together with `pattern`. */
33
+ validationType?: string;
34
+ /** Keys the model does not know (or whose value had an unexpected type), kept verbatim. */
35
+ extraProps?: Record<string, unknown>;
27
36
  }
28
37
  /** A label/value option used by select, radio, and checklist components. */
29
38
  export interface FormValueOption {
30
39
  label: string;
31
40
  value: string;
41
+ /** Keys the model does not know, kept verbatim. */
42
+ extraProps?: Record<string, unknown>;
32
43
  }
33
44
  /** form-js `conditional` block: the component is hidden while the FEEL expression is true. */
34
45
  export interface FormConditional {
@@ -1,4 +1,5 @@
1
1
  import type { FormDefinition } from "./form-model.js";
2
+ export declare const KNOWN_COMPONENT_TYPES: Set<string>;
2
3
  /** Parses a Camunda Form JSON string into a typed FormDefinition. */
3
4
  export declare function parseForm(json: string): FormDefinition;
4
5
  //# sourceMappingURL=form-parser.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { ParseError } from "../errors.js";
2
- const KNOWN_COMPONENT_TYPES = new Set([
2
+ export const KNOWN_COMPONENT_TYPES = new Set([
3
3
  "text",
4
4
  "textfield",
5
5
  "textarea",
@@ -166,6 +166,15 @@ function parseKnownComponent(raw, path) {
166
166
  return parseUnknownComponent(obj, layout);
167
167
  }
168
168
  }
169
+ /**
170
+ * The entries of `obj` that the model did not take. A key whose value had the wrong type
171
+ * for its modelled field is left out of `used`, so it stays here instead of vanishing.
172
+ */
173
+ function leftover(obj, used) {
174
+ // fromEntries defines own properties, so a "__proto__" key survives as data.
175
+ const rest = Object.fromEntries(Object.entries(obj).filter(([k]) => !used.includes(k)));
176
+ return Object.keys(rest).length > 0 ? { extraProps: rest } : {};
177
+ }
169
178
  function parseLayout(raw, path) {
170
179
  if (raw === undefined || raw === null)
171
180
  return undefined;
@@ -174,15 +183,20 @@ function parseLayout(raw, path) {
174
183
  }
175
184
  const obj = raw;
176
185
  const layout = {};
177
- if (typeof obj.row === "string")
186
+ const used = [];
187
+ if (typeof obj.row === "string") {
178
188
  layout.row = obj.row;
189
+ used.push("row");
190
+ }
179
191
  if (obj.columns === null) {
180
192
  layout.columns = null;
193
+ used.push("columns");
181
194
  }
182
195
  else if (typeof obj.columns === "number") {
183
196
  layout.columns = obj.columns;
197
+ used.push("columns");
184
198
  }
185
- return layout;
199
+ return Object.assign(layout, leftover(obj, used));
186
200
  }
187
201
  function parseValidation(raw, path) {
188
202
  if (raw === undefined || raw === null)
@@ -192,13 +206,24 @@ function parseValidation(raw, path) {
192
206
  }
193
207
  const obj = raw;
194
208
  const v = {};
195
- if (typeof obj.required === "boolean")
209
+ const used = [];
210
+ if (typeof obj.required === "boolean") {
196
211
  v.required = obj.required;
197
- if (typeof obj.minLength === "number")
198
- v.minLength = obj.minLength;
199
- if (typeof obj.maxLength === "number")
200
- v.maxLength = obj.maxLength;
201
- return v;
212
+ used.push("required");
213
+ }
214
+ for (const key of ["minLength", "maxLength", "min", "max"]) {
215
+ if (typeof obj[key] === "number") {
216
+ v[key] = obj[key];
217
+ used.push(key);
218
+ }
219
+ }
220
+ for (const key of ["pattern", "validationType"]) {
221
+ if (typeof obj[key] === "string") {
222
+ v[key] = obj[key];
223
+ used.push(key);
224
+ }
225
+ }
226
+ return Object.assign(v, leftover(obj, used));
202
227
  }
203
228
  function parseValues(raw, path) {
204
229
  if (!Array.isArray(raw)) {
@@ -212,6 +237,8 @@ function parseValues(raw, path) {
212
237
  return {
213
238
  label: String(vo.label ?? ""),
214
239
  value: String(vo.value ?? ""),
240
+ // An array passes the check above but has no keys of its own to keep.
241
+ ...(Array.isArray(vo) ? {} : leftover(vo, ["label", "value"])),
215
242
  };
216
243
  });
217
244
  }
@@ -366,7 +393,7 @@ function parseNumberComponent(obj, path, layout) {
366
393
  c.layout = layout;
367
394
  return c;
368
395
  }
369
- function parseDatetimeComponent(obj, _path, layout) {
396
+ function parseDatetimeComponent(obj, path, layout) {
370
397
  const c = { type: "datetime", id: obj.id, key: String(obj.key ?? "") };
371
398
  if (typeof obj.subtype === "string")
372
399
  c.subtype = obj.subtype;
@@ -374,6 +401,9 @@ function parseDatetimeComponent(obj, _path, layout) {
374
401
  c.dateLabel = obj.dateLabel;
375
402
  if (typeof obj.timeLabel === "string")
376
403
  c.timeLabel = obj.timeLabel;
404
+ const validate = parseValidation(obj.validate, path);
405
+ if (validate)
406
+ c.validate = validate;
377
407
  if (layout)
378
408
  c.layout = layout;
379
409
  return c;
@@ -403,11 +433,14 @@ function parseTaglistComponent(obj, path, layout) {
403
433
  c.values = parseValues(obj.values, path);
404
434
  if (typeof obj.valuesKey === "string")
405
435
  c.valuesKey = obj.valuesKey;
436
+ const validate = parseValidation(obj.validate, path);
437
+ if (validate)
438
+ c.validate = validate;
406
439
  if (layout)
407
440
  c.layout = layout;
408
441
  return c;
409
442
  }
410
- function parseTableComponent(obj, _path, layout) {
443
+ function parseTableComponent(obj, path, layout) {
411
444
  const c = { type: "table", id: obj.id };
412
445
  if (typeof obj.label === "string")
413
446
  c.label = obj.label;
@@ -416,7 +449,10 @@ function parseTableComponent(obj, _path, layout) {
416
449
  if (typeof obj.rowCount === "number")
417
450
  c.rowCount = obj.rowCount;
418
451
  if (Array.isArray(obj.columns)) {
419
- c.columns = obj.columns.map((col) => {
452
+ c.columns = obj.columns.map((col, i) => {
453
+ // Reading `.label` off null would surface as a TypeError instead of bad input.
454
+ if (col === null)
455
+ throw new ParseError(`${path}.columns[${i}]: must be an object`);
420
456
  const co = col;
421
457
  return { label: String(co.label ?? ""), key: String(co.key ?? "") };
422
458
  });