Skip to content

Commit 3fd2349

Browse files
committed
add support for ad-hoc subprocess
1 parent 8332c6f commit 3fd2349

File tree

8 files changed

+137
-4
lines changed

8 files changed

+137
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## [17.1.0] - 2025-04-30
6+
7+
- add support for ad-hoc subprocess. The behavior is the same as for an ordinary subprocess
8+
59
## [17.0.0] - 2025-02-08
610

711
- refactor message formatting, not sure if it breaking or not, but now it behaves as expected when formatting with multiple listeners

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The following elements are tested and supported.
1414

1515
- [Definition](/docs/Definition.md): Executable BPMN 2 definition
1616
- [Process](/docs/Process.md): Executes and keeps track of activity elements
17+
- AdHocSubProcess
1718
- BpmnError
1819
- BoundaryEvent
1920
- [CallActivity](/docs/CallActivity.md)

dist/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "ActivityError", {
1515
return _Errors.ActivityError;
1616
}
1717
});
18+
Object.defineProperty(exports, "AdHocSubProcess", {
19+
enumerable: true,
20+
get: function () {
21+
return _index4.SubProcess;
22+
}
23+
});
1824
Object.defineProperty(exports, "Association", {
1925
enumerable: true,
2026
get: function () {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bpmn-elements",
3-
"version": "17.0.0",
3+
"version": "17.1.0",
44
"description": "Executable workflow elements based on BPMN 2.0",
55
"type": "module",
66
"main": "./dist/index.js",
@@ -100,7 +100,7 @@
100100
"moddle-context-serializer": "^4.2.1",
101101
"nock": "^14.0.0",
102102
"prettier": "^3.2.5",
103-
"texample": "^0.0.7"
103+
"texample": "^0.0.8"
104104
},
105105
"dependencies": {
106106
"@0dep/piso": "^2.4.0",

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Timers } from './Timers.js';
3838
export { ActivityError, RunError } from './error/Errors.js';
3939

4040
export {
41+
SubProcess as AdHocSubProcess,
4142
Association,
4243
Activity,
4344
BoundaryEvent,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Definition from '../../src/definition/Definition.js';
2+
import testHelpers from '../helpers/testHelpers.js';
3+
import factory from '../helpers/factory.js';
4+
5+
Feature('Ad-hoc subprocess', () => {
6+
Scenario('Running ad-hoc subprocess', () => {
7+
let context, definition;
8+
Given('a process mathching feature', async () => {
9+
const source = factory.resource('ad-hoc-subprocess.bpmn');
10+
context = await testHelpers.context(source);
11+
});
12+
13+
let leave;
14+
const completedActivities = [];
15+
When('running definition', () => {
16+
definition = new Definition(context);
17+
18+
definition.broker.subscribeTmp(
19+
'event',
20+
'activity.end',
21+
(_, msg) => {
22+
completedActivities.push({ id: msg.content.id, parent: msg.content.parent.id });
23+
},
24+
{ noAck: true }
25+
);
26+
27+
leave = definition.waitFor('leave');
28+
29+
definition.run();
30+
});
31+
32+
Then('definition completes', () => {
33+
return leave;
34+
});
35+
36+
And('all ad-hoc subprocess activities were taken', () => {
37+
expect(completedActivities).to.deep.equal([
38+
{ id: 'start', parent: 'process_0' },
39+
{ id: 'task1', parent: 'adhoc' },
40+
{ id: 'throw', parent: 'adhoc' },
41+
{ id: 'task2', parent: 'adhoc' },
42+
{ id: 'task3', parent: 'adhoc' },
43+
{ id: 'adhoc', parent: 'process_0' },
44+
{ id: 'end', parent: 'process_0' },
45+
]);
46+
});
47+
});
48+
});
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0k9d1hm" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.34.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.23.0">
3+
<bpmn:process id="process_0" isExecutable="true">
4+
<bpmn:startEvent id="start">
5+
<bpmn:outgoing>to-adhoc</bpmn:outgoing>
6+
</bpmn:startEvent>
7+
<bpmn:sequenceFlow id="to-adhoc" sourceRef="start" targetRef="adhoc" />
8+
<bpmn:adHocSubProcess id="adhoc">
9+
<bpmn:incoming>to-adhoc</bpmn:incoming>
10+
<bpmn:outgoing>to-end</bpmn:outgoing>
11+
<bpmn:task id="task1">
12+
<bpmn:outgoing>to-throw1</bpmn:outgoing>
13+
</bpmn:task>
14+
<bpmn:task id="task2">
15+
<bpmn:outgoing>to-task3</bpmn:outgoing>
16+
</bpmn:task>
17+
<bpmn:task id="task3">
18+
<bpmn:incoming>to-task3</bpmn:incoming>
19+
</bpmn:task>
20+
<bpmn:sequenceFlow id="to-task3" sourceRef="task2" targetRef="task3" />
21+
<bpmn:sequenceFlow id="to-throw1" sourceRef="task1" targetRef="throw" />
22+
<bpmn:intermediateThrowEvent id="throw">
23+
<bpmn:incoming>to-throw1</bpmn:incoming>
24+
<bpmn:signalEventDefinition id="SignalEventDefinition_0x1gapz" />
25+
</bpmn:intermediateThrowEvent>
26+
</bpmn:adHocSubProcess>
27+
<bpmn:endEvent id="end">
28+
<bpmn:incoming>to-end</bpmn:incoming>
29+
</bpmn:endEvent>
30+
<bpmn:sequenceFlow id="to-end" sourceRef="adhoc" targetRef="end" />
31+
</bpmn:process>
32+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
33+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="process_0">
34+
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="start">
35+
<dc:Bounds x="182" y="82" width="36" height="36" />
36+
</bpmndi:BPMNShape>
37+
<bpmndi:BPMNShape id="Event_0pvnfrv_di" bpmnElement="end">
38+
<dc:Bounds x="792" y="82" width="36" height="36" />
39+
</bpmndi:BPMNShape>
40+
<bpmndi:BPMNShape id="Activity_0appjps_di" bpmnElement="adhoc" isExpanded="true">
41+
<dc:Bounds x="330" y="90" width="350" height="320" />
42+
</bpmndi:BPMNShape>
43+
<bpmndi:BPMNShape id="Activity_06bggfw_di" bpmnElement="task2">
44+
<dc:Bounds x="370" y="270" width="100" height="80" />
45+
</bpmndi:BPMNShape>
46+
<bpmndi:BPMNShape id="Activity_0ih83i0_di" bpmnElement="task3">
47+
<dc:Bounds x="520" y="270" width="100" height="80" />
48+
</bpmndi:BPMNShape>
49+
<bpmndi:BPMNShape id="Activity_1y2u83i_di" bpmnElement="task1">
50+
<dc:Bounds x="370" y="110" width="100" height="80" />
51+
</bpmndi:BPMNShape>
52+
<bpmndi:BPMNShape id="Event_0ljlhwm_di" bpmnElement="throw">
53+
<dc:Bounds x="522" y="132" width="36" height="36" />
54+
</bpmndi:BPMNShape>
55+
<bpmndi:BPMNEdge id="Flow_13mf53l_di" bpmnElement="to-throw1">
56+
<di:waypoint x="470" y="150" />
57+
<di:waypoint x="522" y="150" />
58+
</bpmndi:BPMNEdge>
59+
<bpmndi:BPMNEdge id="Flow_0wbv0z8_di" bpmnElement="to-task3">
60+
<di:waypoint x="470" y="310" />
61+
<di:waypoint x="520" y="310" />
62+
</bpmndi:BPMNEdge>
63+
<bpmndi:BPMNEdge id="Flow_1j2i43f_di" bpmnElement="to-adhoc">
64+
<di:waypoint x="218" y="100" />
65+
<di:waypoint x="330" y="100" />
66+
</bpmndi:BPMNEdge>
67+
<bpmndi:BPMNEdge id="Flow_16bqx9r_di" bpmnElement="to-end">
68+
<di:waypoint x="680" y="100" />
69+
<di:waypoint x="792" y="100" />
70+
</bpmndi:BPMNEdge>
71+
</bpmndi:BPMNPlane>
72+
</bpmndi:BPMNDiagram>
73+
</bpmn:definitions>

test/tasks/SubProcess-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('SubProcess', () => {
8080
subProcess.broker.subscribeTmp(
8181
'event',
8282
'activity.*',
83-
(routingKey, message) => {
83+
(_routingKey, message) => {
8484
messages.push(message);
8585
},
8686
{ noAck: true }
@@ -126,7 +126,7 @@ describe('SubProcess', () => {
126126
subProcess.broker.subscribeTmp(
127127
'event',
128128
'activity.*',
129-
(routingKey, message) => {
129+
(_routingKey, message) => {
130130
messages.push(message);
131131
},
132132
{ noAck: true }

0 commit comments

Comments
 (0)