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
@@ -9,197 +9,239 @@ var _shared = require("../shared");
9
9
 
10
10
  var _messageHelper = require("../messageHelper");
11
11
 
12
+ const completedSymbol = Symbol.for('completed');
13
+ const messageQSymbol = Symbol.for('messageQ');
14
+ const executeMessageSymbol = Symbol.for('executeMessage');
15
+ const referenceElementSymbol = Symbol.for('referenceElement');
16
+ const referenceInfoSymbol = Symbol.for('referenceInfo');
17
+
12
18
  function ErrorEventDefinition(activity, eventDefinition) {
13
19
  const {
14
20
  id,
15
21
  broker,
16
22
  environment,
17
- getActivityById,
18
23
  isThrowing
19
24
  } = activity;
20
25
  const {
21
26
  type = 'ErrorEventDefinition',
22
27
  behaviour = {}
23
28
  } = eventDefinition;
24
- const {
25
- debug
26
- } = environment.Logger(type.toLowerCase());
27
- const reference = behaviour.errorRef || {
28
- name: 'anonymous'
29
- };
30
- const referenceElement = reference.id && getActivityById(reference.id);
31
- const errorId = referenceElement ? referenceElement.id : 'anonymous';
32
- const errorQueueName = `error-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(errorId)}-q`;
33
- if (!isThrowing) setupCatch();
34
- const source = {
35
- type,
36
- reference: { ...reference,
37
- referenceType: 'throw'
38
- },
39
- execute: isThrowing ? executeThrow : executeCatch
29
+ this.id = id;
30
+ this.type = type;
31
+ const reference = this.reference = {
32
+ name: 'anonymous',
33
+ ...behaviour.errorRef,
34
+ referenceType: 'throw'
40
35
  };
41
- return source;
42
-
43
- function executeCatch(executeMessage) {
44
- let completed;
45
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
46
- const {
47
- executionId,
48
- parent
49
- } = messageContent;
50
- const parentExecutionId = parent && parent.executionId;
51
- const {
52
- message: referenceMessage,
53
- description
54
- } = resolveMessage(executeMessage);
55
- broker.consume(errorQueueName, onThrowApiMessage, {
56
- noAck: true,
57
- consumerTag: `_onthrow-${executionId}`
36
+ this.isThrowing = isThrowing;
37
+ this.activity = activity;
38
+ this.environment = environment;
39
+ this.broker = broker;
40
+ this.logger = environment.Logger(type.toLowerCase());
41
+ const referenceElement = this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
42
+
43
+ if (!isThrowing) {
44
+ this[completedSymbol] = false;
45
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
46
+ const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
47
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {
48
+ autoDelete: false,
49
+ durable: true
58
50
  });
59
- if (completed) return;
60
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
61
- noAck: true,
62
- consumerTag: `_api-${executionId}`
51
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
52
+ durable: true,
53
+ priority: 300
63
54
  });
55
+ }
56
+ }
64
57
 
65
- if (!environment.settings.strict) {
66
- const expectRoutingKey = `execute.throw.${executionId}`;
67
- broker.publish('execution', 'execute.expect', { ...(0, _messageHelper.cloneContent)(messageContent),
68
- expectRoutingKey,
69
- expect: { ...referenceMessage
70
- }
71
- });
72
- broker.subscribeOnce('execution', expectRoutingKey, onErrorMessage, {
73
- consumerTag: `_onerror-${executionId}`
74
- });
75
- }
58
+ const proto = ErrorEventDefinition.prototype;
59
+ Object.defineProperty(proto, 'executionId', {
60
+ get() {
61
+ const message = this[executeMessageSymbol];
62
+ return message && message.content.executionId;
63
+ }
76
64
 
77
- if (completed) return stop();
78
- debug(`<${executionId} (${id})> expect ${description}`);
79
- broker.publish('event', 'activity.wait', { ...messageContent,
80
- executionId: parentExecutionId,
81
- parent: (0, _messageHelper.shiftParent)(parent),
82
- expect: { ...referenceMessage
83
- }
65
+ });
66
+
67
+ proto.execute = function execute(executeMessage) {
68
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
69
+ };
70
+
71
+ proto.executeCatch = function executeCatch(executeMessage) {
72
+ this[executeMessageSymbol] = executeMessage;
73
+ this[completedSymbol] = false;
74
+ const executeContent = executeMessage.content;
75
+ const {
76
+ executionId,
77
+ parent
78
+ } = executeContent;
79
+ const parentExecutionId = parent && parent.executionId;
80
+
81
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
82
+
83
+ this[messageQSymbol].consume(this._onThrowApiMessage.bind(this), {
84
+ noAck: true,
85
+ consumerTag: `_onthrow-${executionId}`
86
+ });
87
+ if (this[completedSymbol]) return;
88
+
89
+ this._debug(`expect ${info.description}`);
90
+
91
+ const broker = this.broker;
92
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
93
+ noAck: true,
94
+ consumerTag: `_api-${executionId}`
95
+ });
96
+
97
+ if (!this.environment.settings.strict) {
98
+ const expectRoutingKey = `execute.throw.${executionId}`;
99
+ broker.subscribeTmp('execution', expectRoutingKey, this._onErrorMessage.bind(this), {
100
+ noAck: true,
101
+ consumerTag: `_onerror-${executionId}`
84
102
  });
103
+ broker.publish('execution', 'execute.expect', (0, _messageHelper.cloneContent)(executeContent, {
104
+ expectRoutingKey,
105
+ expect: { ...info.message
106
+ }
107
+ }));
108
+ if (this[completedSymbol]) return this._stop();
109
+ }
85
110
 
86
- function onErrorMessage(routingKey, message) {
87
- const error = message.content.error;
88
- if (!referenceElement) return catchError(routingKey, message, error);
89
- if (!error) return;
90
- if ('' + error.code !== '' + referenceMessage.code) return;
91
- return catchError(routingKey, message, error);
111
+ const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
112
+ executionId: parentExecutionId,
113
+ expect: { ...info.message
92
114
  }
115
+ });
116
+ waitContent.parent = (0, _messageHelper.shiftParent)(parent);
117
+ broker.publish('event', 'activity.wait', waitContent);
118
+ };
93
119
 
94
- function onThrowApiMessage(routingKey, message) {
95
- const error = message.content.message;
96
- if (!referenceElement) return catchError(routingKey, message, error);
97
- if (referenceMessage.id !== (error && error.id)) return;
98
- return catchError(routingKey, message, error);
99
- }
120
+ proto.executeThrow = function executeThrow(executeMessage) {
121
+ const executeContent = executeMessage.content;
122
+ const {
123
+ executionId,
124
+ parent
125
+ } = executeContent;
100
126
 
101
- function catchError(routingKey, message, error) {
102
- completed = true;
103
- stop();
104
- debug(`<${executionId} (${id})> caught ${description}`);
105
- broker.publish('event', 'activity.catch', { ...messageContent,
106
- source: {
107
- id: message.content.id,
108
- type: message.content.type,
109
- executionId: message.content.executionId
110
- },
111
- error,
112
- executionId: parentExecutionId,
113
- parent: (0, _messageHelper.shiftParent)(executeMessage.content.parent)
114
- }, {
115
- type: 'catch'
116
- });
117
- return broker.publish('execution', 'execute.completed', { ...messageContent,
118
- output: error,
119
- cancelActivity: true,
120
- state: 'catch'
121
- });
122
- }
127
+ const info = this._getReferenceInfo(executeMessage);
123
128
 
124
- function onApiMessage(routingKey, message) {
125
- const messageType = message.properties.type;
126
-
127
- switch (messageType) {
128
- case 'discard':
129
- {
130
- completed = true;
131
- stop();
132
- return broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(messageContent));
133
- }
134
-
135
- case 'stop':
136
- {
137
- stop();
138
- break;
139
- }
140
- }
129
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw ${info.description}`);
130
+ const broker = this.broker;
131
+ const throwContent = (0, _messageHelper.cloneContent)(executeContent, {
132
+ executionId: parent.executionId,
133
+ message: { ...info.message
134
+ },
135
+ state: 'throw'
136
+ });
137
+ throwContent.parent = (0, _messageHelper.shiftParent)(parent);
138
+ this.broker.publish('event', 'activity.throw', throwContent, {
139
+ type: 'throw',
140
+ delegate: true
141
+ });
142
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
143
+ message: { ...info.message
141
144
  }
145
+ }));
146
+ };
147
+
148
+ proto._onErrorMessage = function onErrorMessage(routingKey, message) {
149
+ const error = message.content.error;
150
+ if (!this[referenceElementSymbol]) return this._catchError(routingKey, message, error);
151
+ if (!error) return;
152
+ const info = this[referenceInfoSymbol];
153
+ if ('' + error.code !== '' + info.message.code) return;
154
+ return this._catchError(routingKey, message, error);
155
+ };
156
+
157
+ proto._onThrowApiMessage = function onThrowApiMessage(routingKey, message) {
158
+ const error = message.content.message;
159
+ if (!this[referenceElementSymbol]) return this._catchError(routingKey, message, error);
160
+ const info = this[referenceInfoSymbol];
161
+ if (info.message.id !== (error && error.id)) return;
162
+ return this._catchError(routingKey, message, error);
163
+ };
164
+
165
+ proto._catchError = function catchError(routingKey, message, error) {
166
+ this[completedSymbol] = true;
167
+
168
+ this._stop();
169
+
170
+ this._debug(`caught ${this[referenceInfoSymbol].description}`);
171
+
172
+ const executeContent = this[executeMessageSymbol].content;
173
+ const parent = executeContent.parent;
174
+ const catchContent = (0, _messageHelper.cloneContent)(executeContent, {
175
+ source: {
176
+ id: message.content.id,
177
+ type: message.content.type,
178
+ executionId: message.content.executionId
179
+ },
180
+ error,
181
+ executionId: parent.executionId
182
+ });
183
+ catchContent.parent = (0, _messageHelper.shiftParent)(parent);
184
+ const broker = this.broker;
185
+ broker.publish('event', 'activity.catch', catchContent, {
186
+ type: 'catch'
187
+ });
188
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
189
+ output: error,
190
+ cancelActivity: true,
191
+ state: 'catch'
192
+ }));
193
+ };
194
+
195
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
196
+ const messageType = message.properties.type;
197
+
198
+ switch (messageType) {
199
+ case 'discard':
200
+ {
201
+ this[completedSymbol] = true;
202
+
203
+ this._stop();
204
+
205
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
206
+ }
142
207
 
143
- function stop() {
144
- broker.cancel(`_onthrow-${executionId}`);
145
- broker.cancel(`_onerror-${executionId}`);
146
- broker.cancel(`_api-${executionId}`);
147
- broker.purgeQueue(errorQueueName);
148
- }
149
- }
208
+ case 'stop':
209
+ {
210
+ this._stop();
150
211
 
151
- function executeThrow(executeMessage) {
152
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
153
- const {
154
- executionId,
155
- parent
156
- } = messageContent;
157
- const parentExecutionId = parent && parent.executionId;
158
- const {
159
- message: referenceMessage,
160
- description
161
- } = resolveMessage(executeMessage);
162
- debug(`<${executionId} (${id})> throw ${description}`);
163
- broker.publish('event', 'activity.throw', { ...(0, _messageHelper.cloneContent)(messageContent),
164
- executionId: parentExecutionId,
165
- parent: (0, _messageHelper.shiftParent)(parent),
166
- message: { ...referenceMessage
167
- },
168
- state: 'throw'
169
- }, {
170
- type: 'throw',
171
- delegate: true
172
- });
173
- return broker.publish('execution', 'execute.completed', { ...messageContent,
174
- message: referenceMessage
175
- });
212
+ break;
213
+ }
176
214
  }
177
-
178
- function resolveMessage(message) {
179
- if (!referenceElement) {
180
- return {
181
- message: { ...reference
182
- },
183
- description: 'anonymous error'
184
- };
185
- }
186
-
187
- const result = {
188
- message: referenceElement.resolve(message)
215
+ };
216
+
217
+ proto._stop = function stop() {
218
+ const broker = this.broker,
219
+ executionId = this.executionId;
220
+ broker.cancel(`_onthrow-${executionId}`);
221
+ broker.cancel(`_onerror-${executionId}`);
222
+ broker.cancel(`_api-${executionId}`);
223
+ this[messageQSymbol].purge();
224
+ };
225
+
226
+ proto._getReferenceInfo = function getReferenceInfo(message) {
227
+ const referenceElement = this[referenceElementSymbol];
228
+
229
+ if (!referenceElement) {
230
+ return {
231
+ message: { ...this.reference
232
+ },
233
+ description: 'anonymous error'
189
234
  };
190
- result.description = `${result.message.name} <${result.message.id}>`;
191
- if (result.message.code) result.description += ` code ${result.message.code}`;
192
- return result;
193
235
  }
194
236
 
195
- function setupCatch() {
196
- broker.assertQueue(errorQueueName, {
197
- autoDelete: false,
198
- durable: true
199
- });
200
- broker.bindQueue(errorQueueName, 'api', '*.throw.#', {
201
- durable: true,
202
- priority: 300
203
- });
204
- }
205
- }
237
+ const result = {
238
+ message: referenceElement.resolve(message)
239
+ };
240
+ result.description = `${result.message.name} <${result.message.id}>`;
241
+ if (result.message.code) result.description += ` code ${result.message.code}`;
242
+ return result;
243
+ };
244
+
245
+ proto._debug = function debug(msg) {
246
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
247
+ };