bpmn-elements 5.1.3 → 7.0.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 (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -2,136 +2,192 @@ import getPropertyValue from '../getPropertyValue';
2
2
  import {brokerSafeId} from '../shared';
3
3
  import {cloneContent, shiftParent} from '../messageHelper';
4
4
 
5
+ const completedSymbol = Symbol.for('completed');
6
+ const messageQSymbol = Symbol.for('messageQ');
7
+ const executeMessageSymbol = Symbol.for('executeMessage');
8
+ const referenceElementSymbol = Symbol.for('referenceElement');
9
+ const referenceInfoSymbol = Symbol.for('referenceInfo');
10
+
5
11
  export default function SignalEventDefinition(activity, eventDefinition) {
6
- const {id, broker, environment, isStart, isThrowing, getActivityById} = activity;
12
+ const {id, broker, environment, isStart, isThrowing} = activity;
7
13
  const {type, behaviour = {}} = eventDefinition;
8
- const {debug} = environment.Logger(type.toLowerCase());
9
- const reference = behaviour.signalRef || {name: 'anonymous'};
10
- const referenceElement = reference.id && getActivityById(reference.id);
11
- const signalId = referenceElement ? referenceElement.id : 'anonymous';
12
- const signalQueueName = `signal-${brokerSafeId(id)}-${brokerSafeId(signalId)}-q`;
13
14
 
14
- if (!isThrowing && isStart) setupCatch();
15
+ this.id = id;
16
+ this.type = type;
15
17
 
16
- const source = {
17
- id,
18
- type,
19
- reference: {...reference, referenceType: 'signal'},
20
- execute: isThrowing ? executeThrow : executeCatch,
18
+ const reference = this.reference = {
19
+ name: 'anonymous',
20
+ ...behaviour.signalRef,
21
+ referenceType: 'signal',
21
22
  };
22
23
 
23
- return source;
24
+ this.isThrowing = isThrowing;
25
+ this.activity = activity;
26
+ this.broker = broker;
27
+ this.logger = environment.Logger(type.toLowerCase());
28
+
29
+ const referenceElement = this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
30
+ if (!isThrowing && isStart) {
31
+ this[completedSymbol] = false;
32
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
33
+ const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
34
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
35
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true});
36
+ }
37
+ }
24
38
 
25
- function executeCatch(executeMessage) {
26
- let completed;
39
+ const proto = SignalEventDefinition.prototype;
27
40
 
28
- const messageContent = cloneContent(executeMessage.content);
29
- const {executionId, parent} = messageContent;
30
- const parentExecutionId = parent && parent.executionId;
41
+ Object.defineProperty(proto, 'executionId', {
42
+ get() {
43
+ const message = this[executeMessageSymbol];
44
+ return message && message.content.executionId;
45
+ },
46
+ });
31
47
 
32
- const {message: referenceMessage, description} = resolveMessage(executeMessage);
33
- if (isStart) broker.consume(signalQueueName, onCatchSignal, {noAck: true, consumerTag: `_api-signal-${executionId}`});
48
+ proto.execute = function execute(executeMessage) {
49
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
50
+ };
34
51
 
35
- if (completed) return;
52
+ proto.executeCatch = function executeCatch(executeMessage) {
53
+ this[executeMessageSymbol] = executeMessage;
54
+ this[completedSymbol] = false;
36
55
 
37
- broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {noAck: true, consumerTag: `_api-parent-${parentExecutionId}`});
38
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`});
39
- broker.subscribeTmp('api', '#.signal.*', onCatchSignal, {noAck: true, consumerTag: `_api-delegated-${executionId}`});
56
+ const executeContent = executeMessage.content;
57
+ const {executionId, parent} = executeContent;
58
+ const parentExecutionId = parent && parent.executionId;
40
59
 
41
- debug(`<${executionId} (${id})> expect ${description}`);
60
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
61
+ const broker = this.broker;
42
62
 
43
- broker.publish('event', 'activity.wait', {
44
- ...messageContent,
45
- executionId: parentExecutionId,
46
- parent: shiftParent(parent),
47
- signal: {...referenceMessage},
63
+ const onCatchMessage = this._onCatchMessage.bind(this);
64
+ if (this.activity.isStart) {
65
+ this[messageQSymbol].consume(onCatchMessage, {
66
+ noAck: true,
67
+ consumerTag: `_api-signal-${executionId}`,
48
68
  });
69
+ if (this[completedSymbol]) return;
70
+ }
49
71
 
50
- function onCatchSignal(routingKey, message) {
51
- if (getPropertyValue(message, 'content.message.id') !== referenceMessage.id) return;
52
- completed = true;
53
- stop();
72
+ const onApiMessage = this._onApiMessage.bind(this);
73
+ broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
74
+ noAck: true,
75
+ consumerTag: `_api-parent-${executionId}`,
76
+ });
77
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
78
+ noAck: true,
79
+ consumerTag: `_api-${executionId}`,
80
+ });
81
+ broker.subscribeTmp('api', '#.signal.*', onCatchMessage, {
82
+ noAck: true,
83
+ consumerTag: `_api-delegated-${executionId}`,
84
+ });
85
+
86
+ this._debug(`expect ${info.description}`);
87
+
88
+ const waitContent = cloneContent(executeContent, {
89
+ executionId: parent.executionId,
90
+ signal: {...info.message},
91
+ });
92
+ waitContent.parent = shiftParent(parent);
93
+
94
+ broker.publish('event', 'activity.wait', waitContent);
95
+ };
96
+
97
+ proto.executeThrow = function executeThrow(executeMessage) {
98
+ const executeContent = executeMessage.content;
99
+ const {executionId, parent} = executeContent;
100
+
101
+ const info = this._getReferenceInfo(executeMessage);
102
+
103
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw ${info.description}`);
104
+
105
+ const throwContent = cloneContent(executeContent, {
106
+ executionId: parent.executionId,
107
+ message: {...executeContent.input, ...info.message},
108
+ state: 'throw',
109
+ });
110
+ throwContent.parent = shiftParent(parent);
111
+
112
+ const broker = this.broker;
113
+ broker.publish('event', 'activity.signal', throwContent, {type: 'signal'});
114
+
115
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
116
+ };
117
+
118
+ proto._onCatchMessage = function onCatchMessage(routingKey, message) {
119
+ const info = this[referenceInfoSymbol];
120
+ if (getPropertyValue(message, 'content.message.id') !== info.message.id) return;
121
+ this[completedSymbol] = true;
122
+ this._stop();
123
+
124
+ const {type, correlationId} = message.properties;
125
+ this.broker.publish('event', 'activity.consumed', cloneContent(this[executeMessageSymbol].content, {
126
+ message: { ...message.content.message},
127
+ }), {
128
+ correlationId,
129
+ type,
130
+ });
54
131
 
55
- const {type: messageType, correlationId} = message.properties;
56
- broker.publish('event', 'activity.consumed', cloneContent(messageContent, {message: {...message.content.message}}), {correlationId, type: messageType});
132
+ return this._complete(message.content.message, message.properties);
133
+ };
57
134
 
58
- return complete(message.content.message, message.properties);
59
- }
135
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
136
+ const {type, correlationId} = message.properties;
60
137
 
61
- function onApiMessage(routingKey, message) {
62
- const {type: messageType, correlationId} = message.properties;
63
-
64
- switch (messageType) {
65
- case 'signal': {
66
- return complete(message.content.message, {correlationId});
67
- }
68
- case 'discard': {
69
- completed = true;
70
- stop();
71
- return broker.publish('execution', 'execute.discard', {...messageContent}, {correlationId});
72
- }
73
- case 'stop': {
74
- stop();
75
- break;
76
- }
77
- }
138
+ switch (type) {
139
+ case 'signal': {
140
+ return this._complete(message.content.message, {correlationId});
78
141
  }
79
-
80
- function complete(output, options) {
81
- completed = true;
82
- stop();
83
- debug(`<${executionId} (${id})> signaled with`, description);
84
- return broker.publish('execution', 'execute.completed', {...messageContent, output, state: 'signal'}, options);
142
+ case 'discard': {
143
+ this[completedSymbol] = true;
144
+ this._stop();
145
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[executeMessageSymbol].content), {correlationId});
85
146
  }
86
-
87
- function stop() {
88
- broker.cancel(`_api-signal-${executionId}`);
89
- broker.cancel(`_api-parent-${parentExecutionId}`);
90
- broker.cancel(`_api-${executionId}`);
91
- broker.cancel(`_api-delegated-${executionId}`);
92
- if (isStart) broker.purgeQueue(signalQueueName);
147
+ case 'stop': {
148
+ this._stop();
149
+ break;
93
150
  }
94
151
  }
95
-
96
- function executeThrow(executeMessage) {
97
- const messageContent = cloneContent(executeMessage.content);
98
- const {executionId, parent} = messageContent;
99
- const parentExecutionId = parent && parent.executionId;
100
-
101
- const {message: referenceMessage, description} = resolveMessage(executeMessage);
102
-
103
- debug(`<${executionId} (${id})> throw ${description}`);
104
-
105
- broker.publish('event', 'activity.signal', {
106
- ...cloneContent(messageContent),
107
- executionId: parentExecutionId,
108
- parent: shiftParent(parent),
109
- message: {...messageContent.input, ...referenceMessage},
110
- state: 'throw',
111
- }, {type: 'signal'});
112
-
113
- return broker.publish('execution', 'execute.completed', messageContent);
152
+ };
153
+
154
+ proto._complete = function complete(output, options) {
155
+ this[completedSymbol] = true;
156
+ this._stop();
157
+ this._debug(`signaled with ${this[referenceInfoSymbol].description}`);
158
+ return this.broker.publish('execution', 'execute.completed', cloneContent(this[executeMessageSymbol].content, {
159
+ output,
160
+ state: 'signal',
161
+ }), options);
162
+ };
163
+
164
+ proto._stop = function stop() {
165
+ const broker = this.broker, executionId = this.executionId;
166
+ broker.cancel(`_api-signal-${executionId}`);
167
+ broker.cancel(`_api-parent-${executionId}`);
168
+ broker.cancel(`_api-${executionId}`);
169
+ broker.cancel(`_api-delegated-${executionId}`);
170
+ if (this.activity.isStart) this[messageQSymbol].purge();
171
+ };
172
+
173
+ proto._getReferenceInfo = function getReferenceInfo(message) {
174
+ const referenceElement = this[referenceElementSymbol];
175
+ if (!referenceElement) {
176
+ return {
177
+ message: {...this.reference},
178
+ description: 'anonymous signal',
179
+ };
114
180
  }
115
181
 
116
- function resolveMessage(message) {
117
- if (!referenceElement) {
118
- return {
119
- message: {...reference},
120
- description: 'anonymous signal',
121
- };
122
- }
123
-
124
- const result = {
125
- message: referenceElement.resolve(message),
126
- };
182
+ const result = {
183
+ message: referenceElement.resolve(message),
184
+ };
127
185
 
128
- result.description = `${result.message.name} <${result.message.id}>`;
186
+ result.description = `${result.message.name} <${result.message.id}>`;
129
187
 
130
- return result;
131
- }
188
+ return result;
189
+ };
132
190
 
133
- function setupCatch() {
134
- broker.assertQueue(signalQueueName, {autoDelete: false, durable: true});
135
- broker.bindQueue(signalQueueName, 'api', '*.signal.#', {durable: true});
136
- }
137
- }
191
+ proto._debug = function debug(msg) {
192
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
193
+ };
@@ -1,26 +1,26 @@
1
1
  import {cloneContent, shiftParent} from '../messageHelper';
2
2
 
3
- export default function TerminateEventDefinition(activity, eventDefinition = {}) {
3
+ export default function TerminateEventDefinition(activity, eventDefinition) {
4
4
  const {id, broker, environment} = activity;
5
- const {type = 'terminateeventdefinition'} = eventDefinition;
6
- const {debug} = environment.Logger(type.toLowerCase());
5
+ const {type = 'TerminateEventDefinition'} = eventDefinition;
7
6
 
8
- const source = {
9
- id,
10
- type,
11
- execute,
12
- };
7
+ this.id = id;
8
+ this.type = type;
9
+ this.activity = activity;
10
+ this.broker = broker;
11
+ this.logger = environment.Logger(type.toLowerCase());
12
+ }
13
13
 
14
- return source;
14
+ TerminateEventDefinition.prototype.execute = function execute(executeMessage) {
15
+ const executeContent = executeMessage.content;
15
16
 
16
- function execute(executeMessage) {
17
- const content = cloneContent(executeMessage.content);
18
- const terminateContent = cloneContent(content);
19
- terminateContent.parent = shiftParent(terminateContent.parent);
20
- terminateContent.state = 'terminate';
17
+ const throwContent = cloneContent(executeContent, {
18
+ state: 'terminate',
19
+ });
20
+ throwContent.parent = shiftParent(executeContent.parent);
21
21
 
22
- debug(`<${content.executionId} (${content.id})> terminate`);
23
- broker.publish('event', 'process.terminate', terminateContent, {type: 'terminate'});
24
- broker.publish('execution', 'execute.completed', content);
25
- }
26
- }
22
+ this.logger.debug(`<${executeContent.executionId} (${executeContent.id})> terminate`);
23
+ const broker = this.broker;
24
+ broker.publish('event', 'process.terminate', throwContent, {type: 'terminate'});
25
+ broker.publish('execution', 'execute.completed', cloneContent(executeContent));
26
+ };