@bpmnkit/core 0.0.8
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 +185 -0
- package/dist/bpmn/auto-layout.d.ts +10 -0
- package/dist/bpmn/auto-layout.js +203 -0
- package/dist/bpmn/bpmn-builder.d.ts +381 -0
- package/dist/bpmn/bpmn-builder.js +1223 -0
- package/dist/bpmn/bpmn-model.d.ts +403 -0
- package/dist/bpmn/bpmn-model.js +2 -0
- package/dist/bpmn/bpmn-parser.d.ts +4 -0
- package/dist/bpmn/bpmn-parser.js +642 -0
- package/dist/bpmn/bpmn-serializer.d.ts +4 -0
- package/dist/bpmn/bpmn-serializer.js +515 -0
- package/dist/bpmn/compact.d.ts +91 -0
- package/dist/bpmn/compact.js +349 -0
- package/dist/bpmn/di-color.d.ts +9 -0
- package/dist/bpmn/di-color.js +32 -0
- package/dist/bpmn/index.d.ts +105 -0
- package/dist/bpmn/index.js +176 -0
- package/dist/bpmn/optimize/feel.d.ts +4 -0
- package/dist/bpmn/optimize/feel.js +186 -0
- package/dist/bpmn/optimize/flow.d.ts +4 -0
- package/dist/bpmn/optimize/flow.js +323 -0
- package/dist/bpmn/optimize/index.d.ts +5 -0
- package/dist/bpmn/optimize/index.js +51 -0
- package/dist/bpmn/optimize/naming.d.ts +8 -0
- package/dist/bpmn/optimize/naming.js +145 -0
- package/dist/bpmn/optimize/tasks.d.ts +4 -0
- package/dist/bpmn/optimize/tasks.js +273 -0
- package/dist/bpmn/optimize/types.d.ts +44 -0
- package/dist/bpmn/optimize/types.js +2 -0
- package/dist/bpmn/optimize/utils.d.ts +23 -0
- package/dist/bpmn/optimize/utils.js +129 -0
- package/dist/bpmn/rest-connector.d.ts +48 -0
- package/dist/bpmn/rest-connector.js +69 -0
- package/dist/bpmn/svg.d.ts +35 -0
- package/dist/bpmn/svg.js +557 -0
- package/dist/bpmn/type-guards.d.ts +136 -0
- package/dist/bpmn/type-guards.js +211 -0
- package/dist/bpmn/utils.d.ts +88 -0
- package/dist/bpmn/utils.js +207 -0
- package/dist/bpmn/zeebe-extensions.d.ts +72 -0
- package/dist/bpmn/zeebe-extensions.js +96 -0
- package/dist/dmn/compact.d.ts +44 -0
- package/dist/dmn/compact.js +125 -0
- package/dist/dmn/dmn-builder.d.ts +59 -0
- package/dist/dmn/dmn-builder.js +144 -0
- package/dist/dmn/dmn-layout.d.ts +57 -0
- package/dist/dmn/dmn-layout.js +256 -0
- package/dist/dmn/dmn-model.d.ts +158 -0
- package/dist/dmn/dmn-model.js +2 -0
- package/dist/dmn/dmn-parser.d.ts +4 -0
- package/dist/dmn/dmn-parser.js +275 -0
- package/dist/dmn/dmn-serializer.d.ts +4 -0
- package/dist/dmn/dmn-serializer.js +296 -0
- package/dist/dmn/index.d.ts +28 -0
- package/dist/dmn/index.js +51 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.js +66 -0
- package/dist/form/compact.d.ts +20 -0
- package/dist/form/compact.js +146 -0
- package/dist/form/form-builder.d.ts +111 -0
- package/dist/form/form-builder.js +347 -0
- package/dist/form/form-model.d.ts +221 -0
- package/dist/form/form-model.js +2 -0
- package/dist/form/form-parser.d.ts +4 -0
- package/dist/form/form-parser.js +514 -0
- package/dist/form/form-serializer.d.ts +4 -0
- package/dist/form/form-serializer.js +240 -0
- package/dist/form/index.d.ts +27 -0
- package/dist/form/index.js +43 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +19 -0
- package/dist/layout/bench.d.ts +86 -0
- package/dist/layout/bench.js +225 -0
- package/dist/layout/coordinates.d.ts +62 -0
- package/dist/layout/coordinates.js +868 -0
- package/dist/layout/crossing.d.ts +8 -0
- package/dist/layout/crossing.js +60 -0
- package/dist/layout/graph.d.ts +28 -0
- package/dist/layout/graph.js +126 -0
- package/dist/layout/index.d.ts +7 -0
- package/dist/layout/index.js +5 -0
- package/dist/layout/layers.d.ts +13 -0
- package/dist/layout/layers.js +49 -0
- package/dist/layout/layout-engine.d.ts +21 -0
- package/dist/layout/layout-engine.js +191 -0
- package/dist/layout/overlap.d.ts +10 -0
- package/dist/layout/overlap.js +70 -0
- package/dist/layout/routing.d.ts +26 -0
- package/dist/layout/routing.js +439 -0
- package/dist/layout/subprocess.d.ts +14 -0
- package/dist/layout/subprocess.js +77 -0
- package/dist/layout/types.d.ts +72 -0
- package/dist/layout/types.js +37 -0
- package/dist/types/id-generator.d.ts +8 -0
- package/dist/types/id-generator.js +31 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +2 -0
- package/dist/types/xml-element.d.ts +12 -0
- package/dist/types/xml-element.js +2 -0
- package/dist/xml/index.d.ts +2 -0
- package/dist/xml/index.js +2 -0
- package/dist/xml/xml-parser.d.ts +13 -0
- package/dist/xml/xml-parser.js +271 -0
- package/package.json +38 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { serializeXml } from "../xml/xml-parser.js";
|
|
2
|
+
function textElement(text) {
|
|
3
|
+
return { name: "text", attributes: {}, children: [], text };
|
|
4
|
+
}
|
|
5
|
+
function serializeInput(input) {
|
|
6
|
+
const exprAttrs = { id: input.inputExpression.id };
|
|
7
|
+
if (input.inputExpression.typeRef) {
|
|
8
|
+
exprAttrs.typeRef = input.inputExpression.typeRef;
|
|
9
|
+
}
|
|
10
|
+
const exprChildren = [];
|
|
11
|
+
if (input.inputExpression.text) {
|
|
12
|
+
exprChildren.push(textElement(input.inputExpression.text));
|
|
13
|
+
}
|
|
14
|
+
const inputAttrs = { id: input.id };
|
|
15
|
+
if (input.label)
|
|
16
|
+
inputAttrs.label = input.label;
|
|
17
|
+
return {
|
|
18
|
+
name: "input",
|
|
19
|
+
attributes: inputAttrs,
|
|
20
|
+
children: [
|
|
21
|
+
{
|
|
22
|
+
name: "inputExpression",
|
|
23
|
+
attributes: exprAttrs,
|
|
24
|
+
children: exprChildren,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function serializeOutput(output) {
|
|
30
|
+
const attrs = { id: output.id };
|
|
31
|
+
if (output.label)
|
|
32
|
+
attrs.label = output.label;
|
|
33
|
+
if (output.name)
|
|
34
|
+
attrs.name = output.name;
|
|
35
|
+
if (output.typeRef)
|
|
36
|
+
attrs.typeRef = output.typeRef;
|
|
37
|
+
return { name: "output", attributes: attrs, children: [] };
|
|
38
|
+
}
|
|
39
|
+
function serializeRule(rule) {
|
|
40
|
+
const children = [];
|
|
41
|
+
if (rule.description) {
|
|
42
|
+
children.push({
|
|
43
|
+
name: "description",
|
|
44
|
+
attributes: {},
|
|
45
|
+
children: [],
|
|
46
|
+
text: rule.description,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
for (const entry of rule.inputEntries) {
|
|
50
|
+
children.push({
|
|
51
|
+
name: "inputEntry",
|
|
52
|
+
attributes: { id: entry.id },
|
|
53
|
+
children: [textElement(entry.text)],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
for (const entry of rule.outputEntries) {
|
|
57
|
+
children.push({
|
|
58
|
+
name: "outputEntry",
|
|
59
|
+
attributes: { id: entry.id },
|
|
60
|
+
children: [textElement(entry.text)],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: "rule",
|
|
65
|
+
attributes: { id: rule.id },
|
|
66
|
+
children,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function serializeDecisionTable(table) {
|
|
70
|
+
const attrs = { id: table.id };
|
|
71
|
+
if (table.hitPolicy && table.hitPolicy !== "UNIQUE") {
|
|
72
|
+
attrs.hitPolicy = table.hitPolicy;
|
|
73
|
+
}
|
|
74
|
+
if (table.aggregation)
|
|
75
|
+
attrs.aggregation = table.aggregation;
|
|
76
|
+
const children = [
|
|
77
|
+
...table.inputs.map(serializeInput),
|
|
78
|
+
...table.outputs.map(serializeOutput),
|
|
79
|
+
...table.rules.map(serializeRule),
|
|
80
|
+
];
|
|
81
|
+
return { name: "decisionTable", attributes: attrs, children };
|
|
82
|
+
}
|
|
83
|
+
function serializeInformationRequirements(decision) {
|
|
84
|
+
return decision.informationRequirements.map((req) => {
|
|
85
|
+
const child = req.requiredDecision
|
|
86
|
+
? { name: "requiredDecision", attributes: { href: `#${req.requiredDecision}` }, children: [] }
|
|
87
|
+
: { name: "requiredInput", attributes: { href: `#${req.requiredInput}` }, children: [] };
|
|
88
|
+
return {
|
|
89
|
+
name: "informationRequirement",
|
|
90
|
+
attributes: { id: req.id },
|
|
91
|
+
children: [child],
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function serializeKnowledgeRequirements(reqs) {
|
|
96
|
+
return reqs.map((req) => ({
|
|
97
|
+
name: "knowledgeRequirement",
|
|
98
|
+
attributes: { id: req.id },
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
name: "requiredKnowledge",
|
|
102
|
+
attributes: { href: `#${req.requiredKnowledge}` },
|
|
103
|
+
children: [],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
function serializeAuthorityRequirements(reqs) {
|
|
109
|
+
return reqs.map((req) => {
|
|
110
|
+
let child;
|
|
111
|
+
if (req.requiredDecision) {
|
|
112
|
+
child = {
|
|
113
|
+
name: "requiredDecision",
|
|
114
|
+
attributes: { href: `#${req.requiredDecision}` },
|
|
115
|
+
children: [],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else if (req.requiredInput) {
|
|
119
|
+
child = {
|
|
120
|
+
name: "requiredInput",
|
|
121
|
+
attributes: { href: `#${req.requiredInput}` },
|
|
122
|
+
children: [],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
child = {
|
|
127
|
+
name: "requiredAuthority",
|
|
128
|
+
attributes: { href: `#${req.requiredAuthority ?? ""}` },
|
|
129
|
+
children: [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
name: "authorityRequirement",
|
|
134
|
+
attributes: { id: req.id },
|
|
135
|
+
children: [child],
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function serializeDecision(decision) {
|
|
140
|
+
const children = [];
|
|
141
|
+
if (decision.extensionElements && decision.extensionElements.length > 0) {
|
|
142
|
+
children.push({
|
|
143
|
+
name: "extensionElements",
|
|
144
|
+
attributes: {},
|
|
145
|
+
children: decision.extensionElements,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
children.push(...serializeInformationRequirements(decision));
|
|
149
|
+
children.push(...serializeKnowledgeRequirements(decision.knowledgeRequirements));
|
|
150
|
+
children.push(...serializeAuthorityRequirements(decision.authorityRequirements));
|
|
151
|
+
if (decision.decisionTable) {
|
|
152
|
+
children.push(serializeDecisionTable(decision.decisionTable));
|
|
153
|
+
}
|
|
154
|
+
const attrs = { id: decision.id };
|
|
155
|
+
if (decision.name)
|
|
156
|
+
attrs.name = decision.name;
|
|
157
|
+
return { name: "decision", attributes: attrs, children };
|
|
158
|
+
}
|
|
159
|
+
function serializeInputData(inputData) {
|
|
160
|
+
const attrs = { id: inputData.id };
|
|
161
|
+
if (inputData.name)
|
|
162
|
+
attrs.name = inputData.name;
|
|
163
|
+
return { name: "inputData", attributes: attrs, children: [] };
|
|
164
|
+
}
|
|
165
|
+
function serializeKnowledgeSource(ks) {
|
|
166
|
+
const attrs = { id: ks.id };
|
|
167
|
+
if (ks.name)
|
|
168
|
+
attrs.name = ks.name;
|
|
169
|
+
return {
|
|
170
|
+
name: "knowledgeSource",
|
|
171
|
+
attributes: attrs,
|
|
172
|
+
children: serializeAuthorityRequirements(ks.authorityRequirements),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function serializeBusinessKnowledgeModel(bkm) {
|
|
176
|
+
const attrs = { id: bkm.id };
|
|
177
|
+
if (bkm.name)
|
|
178
|
+
attrs.name = bkm.name;
|
|
179
|
+
return {
|
|
180
|
+
name: "businessKnowledgeModel",
|
|
181
|
+
attributes: attrs,
|
|
182
|
+
children: [
|
|
183
|
+
...serializeKnowledgeRequirements(bkm.knowledgeRequirements),
|
|
184
|
+
...serializeAuthorityRequirements(bkm.authorityRequirements),
|
|
185
|
+
],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function serializeTextAnnotation(ann) {
|
|
189
|
+
const children = [];
|
|
190
|
+
if (ann.text) {
|
|
191
|
+
children.push(textElement(ann.text));
|
|
192
|
+
}
|
|
193
|
+
return { name: "textAnnotation", attributes: { id: ann.id }, children };
|
|
194
|
+
}
|
|
195
|
+
function serializeAssociation(assoc) {
|
|
196
|
+
return {
|
|
197
|
+
name: "association",
|
|
198
|
+
attributes: {
|
|
199
|
+
id: assoc.id,
|
|
200
|
+
sourceRef: `#${assoc.sourceRef}`,
|
|
201
|
+
targetRef: `#${assoc.targetRef}`,
|
|
202
|
+
},
|
|
203
|
+
children: [],
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function serializeDiagram(diagram) {
|
|
207
|
+
const shapes = diagram.shapes.map((shape) => ({
|
|
208
|
+
name: "dmndi:DMNShape",
|
|
209
|
+
attributes: { dmnElementRef: shape.dmnElementRef },
|
|
210
|
+
children: [
|
|
211
|
+
{
|
|
212
|
+
name: "dc:Bounds",
|
|
213
|
+
attributes: {
|
|
214
|
+
height: String(shape.bounds.height),
|
|
215
|
+
width: String(shape.bounds.width),
|
|
216
|
+
x: String(shape.bounds.x),
|
|
217
|
+
y: String(shape.bounds.y),
|
|
218
|
+
},
|
|
219
|
+
children: [],
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
}));
|
|
223
|
+
const edges = diagram.edges.map((edge) => ({
|
|
224
|
+
name: "dmndi:DMNEdge",
|
|
225
|
+
attributes: { dmnElementRef: edge.dmnElementRef },
|
|
226
|
+
children: edge.waypoints.map((wp) => ({
|
|
227
|
+
name: "di:waypoint",
|
|
228
|
+
attributes: { x: String(wp.x), y: String(wp.y) },
|
|
229
|
+
children: [],
|
|
230
|
+
})),
|
|
231
|
+
}));
|
|
232
|
+
return {
|
|
233
|
+
name: "dmndi:DMNDI",
|
|
234
|
+
attributes: {},
|
|
235
|
+
children: [
|
|
236
|
+
{
|
|
237
|
+
name: "dmndi:DMNDiagram",
|
|
238
|
+
attributes: {},
|
|
239
|
+
children: [...shapes, ...edges],
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Serialize a DmnDefinitions model to a DMN XML string. */
|
|
245
|
+
export function serializeDmn(definitions) {
|
|
246
|
+
const attrs = {};
|
|
247
|
+
// Namespace declarations
|
|
248
|
+
for (const [prefix, uri] of Object.entries(definitions.namespaces)) {
|
|
249
|
+
if (prefix === "") {
|
|
250
|
+
attrs.xmlns = uri;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
attrs[`xmlns:${prefix}`] = uri;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
attrs.id = definitions.id;
|
|
257
|
+
attrs.name = definitions.name;
|
|
258
|
+
attrs.namespace = definitions.namespace;
|
|
259
|
+
if (definitions.exporter)
|
|
260
|
+
attrs.exporter = definitions.exporter;
|
|
261
|
+
if (definitions.exporterVersion)
|
|
262
|
+
attrs.exporterVersion = definitions.exporterVersion;
|
|
263
|
+
// Modeler attributes
|
|
264
|
+
for (const [key, value] of Object.entries(definitions.modelerAttributes)) {
|
|
265
|
+
attrs[`modeler:${key}`] = value;
|
|
266
|
+
}
|
|
267
|
+
const children = [];
|
|
268
|
+
for (const decision of definitions.decisions) {
|
|
269
|
+
children.push(serializeDecision(decision));
|
|
270
|
+
}
|
|
271
|
+
for (const id of definitions.inputData) {
|
|
272
|
+
children.push(serializeInputData(id));
|
|
273
|
+
}
|
|
274
|
+
for (const ks of definitions.knowledgeSources) {
|
|
275
|
+
children.push(serializeKnowledgeSource(ks));
|
|
276
|
+
}
|
|
277
|
+
for (const bkm of definitions.businessKnowledgeModels) {
|
|
278
|
+
children.push(serializeBusinessKnowledgeModel(bkm));
|
|
279
|
+
}
|
|
280
|
+
for (const ann of definitions.textAnnotations) {
|
|
281
|
+
children.push(serializeTextAnnotation(ann));
|
|
282
|
+
}
|
|
283
|
+
for (const assoc of definitions.associations) {
|
|
284
|
+
children.push(serializeAssociation(assoc));
|
|
285
|
+
}
|
|
286
|
+
if (definitions.diagram) {
|
|
287
|
+
children.push(serializeDiagram(definitions.diagram));
|
|
288
|
+
}
|
|
289
|
+
const root = {
|
|
290
|
+
name: "definitions",
|
|
291
|
+
attributes: attrs,
|
|
292
|
+
children,
|
|
293
|
+
};
|
|
294
|
+
return serializeXml(root);
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=dmn-serializer.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { compactifyDmn, expandDmn } from "./compact.js";
|
|
2
|
+
import { DecisionTableBuilder } from "./dmn-builder.js";
|
|
3
|
+
import type { DmnDefinitions } from "./dmn-model.js";
|
|
4
|
+
export { layoutDmn, benchmarkDmnLayout } from "./dmn-layout.js";
|
|
5
|
+
export type { DmnBenchmarkResult, DmnElementPosition } from "./dmn-layout.js";
|
|
6
|
+
export { compactifyDmn, expandDmn } from "./compact.js";
|
|
7
|
+
export type { CompactDmn, CompactDmnDecision, CompactDmnInput, CompactDmnOutput, CompactDmnRule, } from "./compact.js";
|
|
8
|
+
/** Entry point for DMN decision table operations. */
|
|
9
|
+
export declare const Dmn: {
|
|
10
|
+
/** Create a new DMN decision table using the fluent builder API. */
|
|
11
|
+
readonly createDecisionTable: (decisionId: string) => DecisionTableBuilder;
|
|
12
|
+
/** Parse a DMN XML string into a typed model. */
|
|
13
|
+
readonly parse: (xml: string) => DmnDefinitions;
|
|
14
|
+
/** Export a typed DMN model to XML string. */
|
|
15
|
+
readonly export: (definitions: DmnDefinitions) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a minimal valid DMN definitions object with one empty decision table.
|
|
18
|
+
* Useful for "New Decision" actions.
|
|
19
|
+
*/
|
|
20
|
+
readonly makeEmpty: () => DmnDefinitions;
|
|
21
|
+
/** Auto-layout a DMN definitions object, assigning DMNDI positions. */
|
|
22
|
+
readonly layout: (definitions: DmnDefinitions) => DmnDefinitions;
|
|
23
|
+
/** Convert a DmnDefinitions to a token-efficient compact representation. */
|
|
24
|
+
readonly compactify: (definitions: DmnDefinitions) => ReturnType<typeof compactifyDmn>;
|
|
25
|
+
/** Convert a compact DMN representation back to DmnDefinitions with auto-layout. */
|
|
26
|
+
readonly expand: (compact: Parameters<typeof expandDmn>[0]) => DmnDefinitions;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { compactifyDmn, expandDmn } from "./compact.js";
|
|
2
|
+
import { DecisionTableBuilder } from "./dmn-builder.js";
|
|
3
|
+
import { layoutDmn } from "./dmn-layout.js";
|
|
4
|
+
import { parseDmn } from "./dmn-parser.js";
|
|
5
|
+
import { serializeDmn } from "./dmn-serializer.js";
|
|
6
|
+
export { layoutDmn, benchmarkDmnLayout } from "./dmn-layout.js";
|
|
7
|
+
export { compactifyDmn, expandDmn } from "./compact.js";
|
|
8
|
+
/** Entry point for DMN decision table operations. */
|
|
9
|
+
export const Dmn = {
|
|
10
|
+
/** Create a new DMN decision table using the fluent builder API. */
|
|
11
|
+
createDecisionTable(decisionId) {
|
|
12
|
+
return new DecisionTableBuilder(decisionId);
|
|
13
|
+
},
|
|
14
|
+
/** Parse a DMN XML string into a typed model. */
|
|
15
|
+
parse(xml) {
|
|
16
|
+
return parseDmn(xml);
|
|
17
|
+
},
|
|
18
|
+
/** Export a typed DMN model to XML string. */
|
|
19
|
+
export(definitions) {
|
|
20
|
+
return serializeDmn(definitions);
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Returns a minimal valid DMN definitions object with one empty decision table.
|
|
24
|
+
* Useful for "New Decision" actions.
|
|
25
|
+
*/
|
|
26
|
+
makeEmpty() {
|
|
27
|
+
const id = Math.random().toString(36).slice(2, 9);
|
|
28
|
+
return parseDmn(`<?xml version="1.0" encoding="UTF-8"?>
|
|
29
|
+
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/"
|
|
30
|
+
id="Definitions_${id}" name="New Decision" namespace="http://bpmn.io/schema/dmn">
|
|
31
|
+
<decision id="Decision_${id}" name="Decision 1">
|
|
32
|
+
<decisionTable id="decisionTable_${id}" hitPolicy="UNIQUE">
|
|
33
|
+
<output id="output_${id}" label="Result" name="result" typeRef="string"/>
|
|
34
|
+
</decisionTable>
|
|
35
|
+
</decision>
|
|
36
|
+
</definitions>`);
|
|
37
|
+
},
|
|
38
|
+
/** Auto-layout a DMN definitions object, assigning DMNDI positions. */
|
|
39
|
+
layout(definitions) {
|
|
40
|
+
return layoutDmn(definitions);
|
|
41
|
+
},
|
|
42
|
+
/** Convert a DmnDefinitions to a token-efficient compact representation. */
|
|
43
|
+
compactify(definitions) {
|
|
44
|
+
return compactifyDmn(definitions);
|
|
45
|
+
},
|
|
46
|
+
/** Convert a compact DMN representation back to DmnDefinitions with auto-layout. */
|
|
47
|
+
expand(compact) {
|
|
48
|
+
return expandDmn(compact);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error codes for all errors thrown by `@bpmnkit/core`.
|
|
3
|
+
*
|
|
4
|
+
* Use these values to programmatically distinguish error causes:
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { ParseError, ErrorCode } from "@bpmnkit/core"
|
|
7
|
+
*
|
|
8
|
+
* try {
|
|
9
|
+
* const defs = Bpmn.parse(xml)
|
|
10
|
+
* } catch (err) {
|
|
11
|
+
* if (err instanceof ParseError) {
|
|
12
|
+
* console.error(err.code, err.message)
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type ErrorCode =
|
|
18
|
+
/** XML could not be parsed or a required attribute was missing. */
|
|
19
|
+
"parse-error"
|
|
20
|
+
/** A builder received an invalid combination of options. */
|
|
21
|
+
| "validation-error";
|
|
22
|
+
/**
|
|
23
|
+
* Base class for all errors thrown by `@bpmnkit/core`.
|
|
24
|
+
*
|
|
25
|
+
* Always use `instanceof ParseError` or `instanceof ValidationError` rather
|
|
26
|
+
* than catching the base class, so you can handle each case precisely.
|
|
27
|
+
*/
|
|
28
|
+
export declare class BpmnSdkError extends Error {
|
|
29
|
+
/** Machine-readable error code. */
|
|
30
|
+
readonly code: ErrorCode;
|
|
31
|
+
constructor(message: string, code: ErrorCode);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Thrown when BPMN or DMN XML cannot be parsed, or when a required attribute
|
|
35
|
+
* is missing from an element.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { Bpmn, ParseError } from "@bpmnkit/core"
|
|
40
|
+
*
|
|
41
|
+
* try {
|
|
42
|
+
* const defs = Bpmn.parse("<invalid>")
|
|
43
|
+
* } catch (err) {
|
|
44
|
+
* if (err instanceof ParseError) {
|
|
45
|
+
* // err.code === "parse-error"
|
|
46
|
+
* console.error("Bad BPMN XML:", err.message)
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class ParseError extends BpmnSdkError {
|
|
52
|
+
constructor(message: string);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Thrown when a builder receives an invalid combination of options, such as a
|
|
56
|
+
* DMN rule with the wrong number of input or output entries.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { Dmn, ValidationError } from "@bpmnkit/core"
|
|
61
|
+
*
|
|
62
|
+
* try {
|
|
63
|
+
* Dmn.createDecisionTable("decide")
|
|
64
|
+
* .input({ expression: "age" })
|
|
65
|
+
* .rule({ inputs: [], outputs: ["adult"] }) // ← wrong count
|
|
66
|
+
* .build()
|
|
67
|
+
* } catch (err) {
|
|
68
|
+
* if (err instanceof ValidationError) {
|
|
69
|
+
* console.error("Builder error:", err.message)
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare class ValidationError extends BpmnSdkError {
|
|
75
|
+
constructor(message: string);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all errors thrown by `@bpmnkit/core`.
|
|
3
|
+
*
|
|
4
|
+
* Always use `instanceof ParseError` or `instanceof ValidationError` rather
|
|
5
|
+
* than catching the base class, so you can handle each case precisely.
|
|
6
|
+
*/
|
|
7
|
+
export class BpmnSdkError extends Error {
|
|
8
|
+
/** Machine-readable error code. */
|
|
9
|
+
code;
|
|
10
|
+
constructor(message, code) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "BpmnSdkError";
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when BPMN or DMN XML cannot be parsed, or when a required attribute
|
|
18
|
+
* is missing from an element.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { Bpmn, ParseError } from "@bpmnkit/core"
|
|
23
|
+
*
|
|
24
|
+
* try {
|
|
25
|
+
* const defs = Bpmn.parse("<invalid>")
|
|
26
|
+
* } catch (err) {
|
|
27
|
+
* if (err instanceof ParseError) {
|
|
28
|
+
* // err.code === "parse-error"
|
|
29
|
+
* console.error("Bad BPMN XML:", err.message)
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class ParseError extends BpmnSdkError {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message, "parse-error");
|
|
37
|
+
this.name = "ParseError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Thrown when a builder receives an invalid combination of options, such as a
|
|
42
|
+
* DMN rule with the wrong number of input or output entries.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { Dmn, ValidationError } from "@bpmnkit/core"
|
|
47
|
+
*
|
|
48
|
+
* try {
|
|
49
|
+
* Dmn.createDecisionTable("decide")
|
|
50
|
+
* .input({ expression: "age" })
|
|
51
|
+
* .rule({ inputs: [], outputs: ["adult"] }) // ← wrong count
|
|
52
|
+
* .build()
|
|
53
|
+
* } catch (err) {
|
|
54
|
+
* if (err instanceof ValidationError) {
|
|
55
|
+
* console.error("Builder error:", err.message)
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export class ValidationError extends BpmnSdkError {
|
|
61
|
+
constructor(message) {
|
|
62
|
+
super(message, "validation-error");
|
|
63
|
+
this.name = "ValidationError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FormDefinition, FormValueOption } from "./form-model.js";
|
|
2
|
+
export interface CompactFormField {
|
|
3
|
+
type: string;
|
|
4
|
+
id: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
values?: FormValueOption[];
|
|
9
|
+
/** Nested fields for group and dynamiclist components */
|
|
10
|
+
fields?: CompactFormField[];
|
|
11
|
+
}
|
|
12
|
+
export interface CompactForm {
|
|
13
|
+
id: string;
|
|
14
|
+
fields: CompactFormField[];
|
|
15
|
+
}
|
|
16
|
+
/** Convert a FormDefinition to a token-efficient CompactForm representation. */
|
|
17
|
+
export declare function compactifyForm(def: FormDefinition): CompactForm;
|
|
18
|
+
/** Convert a CompactForm back to a full FormDefinition. */
|
|
19
|
+
export declare function expandForm(compact: CompactForm): FormDefinition;
|
|
20
|
+
//# sourceMappingURL=compact.d.ts.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { generateId } from "../types/id-generator.js";
|
|
2
|
+
// ── Compactify ────────────────────────────────────────────────────────────────
|
|
3
|
+
function compactifyComponent(c) {
|
|
4
|
+
const base = { type: c.type, id: c.id };
|
|
5
|
+
const any = c;
|
|
6
|
+
if (typeof any.label === "string" && any.label)
|
|
7
|
+
base.label = any.label;
|
|
8
|
+
if (typeof any.key === "string" && any.key)
|
|
9
|
+
base.key = any.key;
|
|
10
|
+
if (any.validate && typeof any.validate === "object") {
|
|
11
|
+
const validate = any.validate;
|
|
12
|
+
if (validate.required === true)
|
|
13
|
+
base.required = true;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(any.values))
|
|
16
|
+
base.values = any.values;
|
|
17
|
+
// Nested components
|
|
18
|
+
if (c.type === "group" || c.type === "dynamiclist") {
|
|
19
|
+
const nested = "components" in c ? c.components : [];
|
|
20
|
+
if (nested.length > 0) {
|
|
21
|
+
base.fields = nested.map(compactifyComponent);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return base;
|
|
25
|
+
}
|
|
26
|
+
/** Convert a FormDefinition to a token-efficient CompactForm representation. */
|
|
27
|
+
export function compactifyForm(def) {
|
|
28
|
+
return {
|
|
29
|
+
id: def.id,
|
|
30
|
+
fields: def.components.map(compactifyComponent),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// ── Expand ────────────────────────────────────────────────────────────────────
|
|
34
|
+
function expandField(f) {
|
|
35
|
+
switch (f.type) {
|
|
36
|
+
case "text":
|
|
37
|
+
return { type: "text", id: f.id, text: f.label ?? "" };
|
|
38
|
+
case "textfield":
|
|
39
|
+
return {
|
|
40
|
+
type: "textfield",
|
|
41
|
+
id: f.id,
|
|
42
|
+
label: f.label ?? "",
|
|
43
|
+
key: f.key ?? generateId("field"),
|
|
44
|
+
validate: f.required ? { required: true } : undefined,
|
|
45
|
+
};
|
|
46
|
+
case "textarea":
|
|
47
|
+
return {
|
|
48
|
+
type: "textarea",
|
|
49
|
+
id: f.id,
|
|
50
|
+
label: f.label ?? "",
|
|
51
|
+
key: f.key ?? generateId("field"),
|
|
52
|
+
validate: f.required ? { required: true } : undefined,
|
|
53
|
+
};
|
|
54
|
+
case "number":
|
|
55
|
+
return {
|
|
56
|
+
type: "number",
|
|
57
|
+
id: f.id,
|
|
58
|
+
label: f.label ?? "",
|
|
59
|
+
key: f.key ?? generateId("field"),
|
|
60
|
+
validate: f.required ? { required: true } : undefined,
|
|
61
|
+
};
|
|
62
|
+
case "select":
|
|
63
|
+
return {
|
|
64
|
+
type: "select",
|
|
65
|
+
id: f.id,
|
|
66
|
+
label: f.label ?? "",
|
|
67
|
+
key: f.key ?? generateId("field"),
|
|
68
|
+
values: f.values,
|
|
69
|
+
validate: f.required ? { required: true } : undefined,
|
|
70
|
+
};
|
|
71
|
+
case "radio":
|
|
72
|
+
return {
|
|
73
|
+
type: "radio",
|
|
74
|
+
id: f.id,
|
|
75
|
+
label: f.label ?? "",
|
|
76
|
+
key: f.key ?? generateId("field"),
|
|
77
|
+
values: f.values ?? [],
|
|
78
|
+
validate: f.required ? { required: true } : undefined,
|
|
79
|
+
};
|
|
80
|
+
case "checkbox":
|
|
81
|
+
return {
|
|
82
|
+
type: "checkbox",
|
|
83
|
+
id: f.id,
|
|
84
|
+
label: f.label ?? "",
|
|
85
|
+
key: f.key ?? generateId("field"),
|
|
86
|
+
validate: f.required ? { required: true } : undefined,
|
|
87
|
+
};
|
|
88
|
+
case "checklist":
|
|
89
|
+
return {
|
|
90
|
+
type: "checklist",
|
|
91
|
+
id: f.id,
|
|
92
|
+
label: f.label ?? "",
|
|
93
|
+
key: f.key ?? generateId("field"),
|
|
94
|
+
values: f.values ?? [],
|
|
95
|
+
validate: f.required ? { required: true } : undefined,
|
|
96
|
+
};
|
|
97
|
+
case "taglist":
|
|
98
|
+
return {
|
|
99
|
+
type: "taglist",
|
|
100
|
+
id: f.id,
|
|
101
|
+
label: f.label ?? "",
|
|
102
|
+
key: f.key ?? generateId("field"),
|
|
103
|
+
values: f.values,
|
|
104
|
+
validate: f.required ? { required: true } : undefined,
|
|
105
|
+
};
|
|
106
|
+
case "datetime":
|
|
107
|
+
return {
|
|
108
|
+
type: "datetime",
|
|
109
|
+
id: f.id,
|
|
110
|
+
key: f.key ?? generateId("field"),
|
|
111
|
+
validate: f.required ? { required: true } : undefined,
|
|
112
|
+
};
|
|
113
|
+
case "button":
|
|
114
|
+
return { type: "button", id: f.id, label: f.label ?? "Submit" };
|
|
115
|
+
case "separator":
|
|
116
|
+
return { type: "separator", id: f.id };
|
|
117
|
+
case "spacer":
|
|
118
|
+
return { type: "spacer", id: f.id };
|
|
119
|
+
case "group":
|
|
120
|
+
return {
|
|
121
|
+
type: "group",
|
|
122
|
+
id: f.id,
|
|
123
|
+
label: f.label ?? "",
|
|
124
|
+
components: (f.fields ?? []).map(expandField),
|
|
125
|
+
};
|
|
126
|
+
case "dynamiclist":
|
|
127
|
+
return {
|
|
128
|
+
type: "dynamiclist",
|
|
129
|
+
id: f.id,
|
|
130
|
+
label: f.label,
|
|
131
|
+
components: (f.fields ?? []).map(expandField),
|
|
132
|
+
};
|
|
133
|
+
default:
|
|
134
|
+
return { type: f.type, id: f.id };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Convert a CompactForm back to a full FormDefinition. */
|
|
138
|
+
export function expandForm(compact) {
|
|
139
|
+
return {
|
|
140
|
+
id: compact.id,
|
|
141
|
+
type: "default",
|
|
142
|
+
schemaVersion: 16,
|
|
143
|
+
components: compact.fields.map(expandField),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=compact.js.map
|