bpmn-elements 6.0.0 → 8.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 (116) hide show
  1. package/CHANGELOG.md +335 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +52 -44
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +176 -172
  6. package/dist/src/Environment.js +110 -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/activity/Activity.js +1106 -916
  12. package/dist/src/activity/ActivityExecution.js +342 -297
  13. package/dist/src/activity/Dummy.js +3 -3
  14. package/dist/src/definition/Definition.js +498 -444
  15. package/dist/src/definition/DefinitionExecution.js +710 -408
  16. package/dist/src/error/Errors.js +17 -7
  17. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  18. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  19. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  20. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  21. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  22. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  23. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  24. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  25. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  26. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  27. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  28. package/dist/src/events/BoundaryEvent.js +180 -144
  29. package/dist/src/events/EndEvent.js +18 -23
  30. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  31. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  32. package/dist/src/events/StartEvent.js +109 -94
  33. package/dist/src/flows/Association.js +94 -100
  34. package/dist/src/flows/MessageFlow.js +86 -103
  35. package/dist/src/flows/SequenceFlow.js +173 -182
  36. package/dist/src/gateways/EventBasedGateway.js +88 -84
  37. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  38. package/dist/src/gateways/InclusiveGateway.js +11 -14
  39. package/dist/src/gateways/ParallelGateway.js +11 -14
  40. package/dist/src/getPropertyValue.js +34 -34
  41. package/dist/src/io/BpmnIO.js +17 -14
  42. package/dist/src/io/EnvironmentDataObject.js +33 -29
  43. package/dist/src/io/EnvironmentDataStore.js +33 -29
  44. package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
  45. package/dist/src/io/InputOutputSpecification.js +177 -168
  46. package/dist/src/io/Properties.js +117 -124
  47. package/dist/src/messageHelper.js +1 -1
  48. package/dist/src/process/Process.js +439 -362
  49. package/dist/src/process/ProcessExecution.js +748 -646
  50. package/dist/src/shared.js +2 -2
  51. package/dist/src/tasks/CallActivity.js +160 -0
  52. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  53. package/dist/src/tasks/ReceiveTask.js +233 -182
  54. package/dist/src/tasks/ScriptTask.js +35 -41
  55. package/dist/src/tasks/ServiceImplementation.js +13 -20
  56. package/dist/src/tasks/ServiceTask.js +82 -75
  57. package/dist/src/tasks/SignalTask.js +97 -93
  58. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  59. package/dist/src/tasks/SubProcess.js +193 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +15 -15
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +145 -140
  65. package/src/Environment.js +116 -100
  66. package/src/EventBroker.js +67 -68
  67. package/src/ExtensionsMapper.js +2 -2
  68. package/src/MessageFormatter.js +132 -74
  69. package/src/activity/Activity.js +915 -775
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +437 -401
  73. package/src/definition/DefinitionExecution.js +598 -340
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
  77. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  78. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  79. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  80. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  81. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  82. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  83. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  84. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  85. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  86. package/src/events/BoundaryEvent.js +156 -115
  87. package/src/events/EndEvent.js +15 -18
  88. package/src/events/IntermediateCatchEvent.js +40 -44
  89. package/src/events/IntermediateThrowEvent.js +15 -18
  90. package/src/events/StartEvent.js +84 -50
  91. package/src/flows/Association.js +98 -112
  92. package/src/flows/MessageFlow.js +81 -97
  93. package/src/flows/SequenceFlow.js +146 -160
  94. package/src/gateways/EventBasedGateway.js +75 -68
  95. package/src/gateways/ExclusiveGateway.js +8 -13
  96. package/src/gateways/InclusiveGateway.js +8 -13
  97. package/src/gateways/ParallelGateway.js +8 -13
  98. package/src/getPropertyValue.js +34 -33
  99. package/src/io/BpmnIO.js +20 -15
  100. package/src/io/EnvironmentDataObject.js +29 -18
  101. package/src/io/EnvironmentDataStore.js +29 -18
  102. package/src/io/EnvironmentDataStoreReference.js +31 -20
  103. package/src/io/InputOutputSpecification.js +154 -157
  104. package/src/io/Properties.js +95 -97
  105. package/src/process/Process.js +378 -333
  106. package/src/process/ProcessExecution.js +603 -553
  107. package/src/tasks/CallActivity.js +130 -0
  108. package/src/tasks/LoopCharacteristics.js +290 -289
  109. package/src/tasks/ReceiveTask.js +174 -107
  110. package/src/tasks/ScriptTask.js +27 -30
  111. package/src/tasks/ServiceImplementation.js +13 -18
  112. package/src/tasks/ServiceTask.js +67 -60
  113. package/src/tasks/SignalTask.js +77 -52
  114. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  115. package/src/tasks/SubProcess.js +184 -157
  116. package/src/tasks/Task.js +15 -19
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.RunError = exports.BpmnError = exports.ActivityError = void 0;
6
7
  exports.makeErrorFromMessage = makeErrorFromMessage;
7
- exports.BpmnError = exports.ActivityError = void 0;
8
8
 
9
9
  var _messageHelper = require("../messageHelper");
10
10
 
@@ -29,6 +29,10 @@ class ActivityError extends Error {
29
29
 
30
30
  exports.ActivityError = ActivityError;
31
31
 
32
+ class RunError extends ActivityError {}
33
+
34
+ exports.RunError = RunError;
35
+
32
36
  class BpmnError extends Error {
33
37
  constructor(description, behaviour = {}, sourceMessage, inner) {
34
38
  const {
@@ -58,7 +62,7 @@ function makeErrorFromMessage(errorMessage) {
58
62
  const {
59
63
  error
60
64
  } = content;
61
- if (!error) return;
65
+ if (!error) return new Error(`Malformatted error message with routing key ${errorMessage.fields && errorMessage.fields.routingKey}`);
62
66
  if (isKnownError(error)) return error;
63
67
 
64
68
  switch (error.type) {
@@ -68,15 +72,21 @@ function makeErrorFromMessage(errorMessage) {
68
72
  name: error.name
69
73
  });
70
74
 
75
+ case 'RunError':
76
+ return new RunError(error.message || error.description, error.source, error.inner ? error.inner : {
77
+ code: error.code,
78
+ name: error.name
79
+ });
80
+
71
81
  case 'BpmnError':
72
82
  return new BpmnError(error.message || error.description, error, error.source);
73
83
  }
74
84
 
75
85
  return error;
86
+ }
76
87
 
77
- function isKnownError(test) {
78
- if (test instanceof Error) return test;
79
- if (test instanceof ActivityError) return test;
80
- if (test instanceof BpmnError) return test;
81
- }
88
+ function isKnownError(test) {
89
+ if (test instanceof ActivityError) return test;
90
+ if (test instanceof BpmnError) return test;
91
+ if (test instanceof Error) return test;
82
92
  }
@@ -9,6 +9,10 @@ var _shared = require("../shared");
9
9
 
10
10
  var _messageHelper = require("../messageHelper");
11
11
 
12
+ const kMessageQ = Symbol.for('cancelQ');
13
+ const kCompleted = Symbol.for('completed');
14
+ const kExecuteMessage = Symbol.for('executeMessage');
15
+
12
16
  function CancelEventDefinition(activity, eventDefinition) {
13
17
  const {
14
18
  id,
@@ -16,162 +20,198 @@ function CancelEventDefinition(activity, eventDefinition) {
16
20
  environment,
17
21
  isThrowing
18
22
  } = activity;
19
- const {
20
- type
21
- } = eventDefinition;
22
- const {
23
- debug
24
- } = environment.Logger(type.toLowerCase());
25
- const cancelQueueName = `cancel-${(0, _shared.brokerSafeId)(id)}-q`;
26
- if (!isThrowing) setupCatch();
27
- const source = {
28
- id,
29
- type,
30
- reference: {
31
- referenceType: 'cancel'
32
- },
33
- execute: isThrowing ? executeThrow : executeCatch
23
+ const type = eventDefinition.type;
24
+ this.id = id;
25
+ this.type = type;
26
+ const reference = this.reference = {
27
+ referenceType: 'cancel'
34
28
  };
35
- return source;
36
-
37
- function executeCatch(executeMessage) {
38
- let completed;
39
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
40
- const {
41
- executionId,
42
- parent,
43
- attachedTo
44
- } = messageContent;
45
- const parentExecutionId = parent && parent.executionId;
46
- broker.consume(cancelQueueName, onCatchMessage, {
47
- noAck: true,
48
- consumerTag: `_oncancel-${executionId}`
49
- });
50
- if (completed) return;
51
- broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
52
- noAck: true,
53
- consumerTag: `_api-parent-${parentExecutionId}`
54
- });
55
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
56
- noAck: true,
57
- consumerTag: `_api-${executionId}`
58
- });
59
- debug(`<${executionId} (${id})> expect cancel`);
60
- const exchangeKey = `execute.canceled.${executionId}`;
61
- broker.subscribeOnce('execution', exchangeKey, onCatchMessage, {
62
- consumerTag: `_onattached-cancel-${executionId}`
63
- });
64
- broker.publish('execution', 'execute.expect', (0, _messageHelper.cloneContent)(messageContent, {
65
- pattern: '#.cancel',
66
- exchange: 'execution',
67
- exchangeKey
68
- }));
69
-
70
- function onCatchMessage(_, message) {
71
- if (message.content && message.content.isTransaction) return onCancelTransaction(_, message);
72
- debug(`<${executionId} (${id})> cancel caught from <${message.content.id}>`);
73
- return complete(message.content.message);
74
- }
75
-
76
- function onCancelTransaction(_, message) {
77
- broker.cancel(`_oncancel-${executionId}`);
78
- debug(`<${executionId} (${id})> cancel transaction thrown by <${message.content.id}>`);
79
- broker.assertExchange('cancel', 'topic');
80
- broker.publish('execution', 'execute.detach', (0, _messageHelper.cloneContent)(messageContent, {
81
- pattern: '#',
82
- bindExchange: 'cancel',
83
- sourceExchange: 'event',
84
- sourcePattern: '#'
85
- }));
86
- broker.publish('event', 'activity.compensate', (0, _messageHelper.cloneContent)(message.content, {
87
- state: 'throw'
88
- }), {
89
- type: 'compensate',
90
- delegate: true
91
- });
92
- broker.subscribeTmp('cancel', 'activity.leave', (__, {
93
- content: msg
94
- }) => {
95
- if (msg.id !== attachedTo) return;
96
- return complete(message.content.message);
97
- }, {
98
- noAck: true,
99
- consumerTag: `_oncancelend-${executionId}`
100
- });
101
- }
102
-
103
- function complete(output) {
104
- completed = true;
105
- stop();
106
- debug(`<${executionId} (${id})> completed`);
107
- return broker.publish('execution', 'execute.completed', { ...messageContent,
108
- output,
109
- state: 'cancel'
110
- });
111
- }
112
-
113
- function onApiMessage(routingKey, message) {
114
- const messageType = message.properties.type;
115
-
116
- switch (messageType) {
117
- case 'discard':
118
- {
119
- completed = true;
120
- stop();
121
- return broker.publish('execution', 'execute.discard', { ...messageContent
122
- });
123
- }
124
-
125
- case 'stop':
126
- {
127
- stop();
128
- break;
129
- }
130
- }
131
- }
132
-
133
- function stop() {
134
- broker.cancel(`_api-parent-${parentExecutionId}`);
135
- broker.cancel(`_api-${executionId}`);
136
- broker.cancel(`_oncancel-${executionId}`);
137
- broker.cancel(`_oncancelend-${executionId}`);
138
- broker.cancel(`_onattached-cancel-${executionId}`);
139
- broker.purgeQueue(cancelQueueName);
140
- }
141
- }
29
+ this.isThrowing = isThrowing;
30
+ this.activity = activity;
31
+ this.environment = environment;
32
+ this.broker = broker;
33
+ this.logger = environment.Logger(type.toLowerCase());
142
34
 
143
- function executeThrow(executeMessage) {
144
- const {
145
- isTransaction
146
- } = environment.variables.content || {};
147
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
148
- const {
149
- executionId,
150
- parent
151
- } = messageContent;
152
- const parentExecutionId = parent && parent.executionId;
153
- debug(`<${executionId} (${id})> throw cancel${isTransaction ? ' transaction' : ''}`);
154
- broker.publish('event', 'activity.cancel', { ...(0, _messageHelper.cloneContent)(messageContent),
155
- isTransaction,
156
- executionId: parentExecutionId,
157
- parent: (0, _messageHelper.shiftParent)(parent),
158
- state: 'throw'
159
- }, {
160
- type: 'cancel',
161
- delegate: isTransaction
162
- });
163
- return broker.publish('execution', 'execute.completed', { ...messageContent
164
- });
165
- }
166
-
167
- function setupCatch() {
168
- broker.assertQueue(cancelQueueName, {
35
+ if (!isThrowing) {
36
+ this[kCompleted] = false;
37
+ const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-q`;
38
+ this[kMessageQ] = broker.assertQueue(messageQueueName, {
169
39
  autoDelete: false,
170
40
  durable: true
171
41
  });
172
- broker.bindQueue(cancelQueueName, 'api', '*.cancel.#', {
42
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
173
43
  durable: true,
174
44
  priority: 400
175
45
  });
176
46
  }
177
- }
47
+ }
48
+
49
+ const proto = CancelEventDefinition.prototype;
50
+ Object.defineProperty(proto, 'executionId', {
51
+ get() {
52
+ const message = this[kExecuteMessage];
53
+ return message && message.content.executionId;
54
+ }
55
+
56
+ });
57
+
58
+ proto.execute = function execute(executeMessage) {
59
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
60
+ };
61
+
62
+ proto.executeCatch = function executeCatch(executeMessage) {
63
+ this[kExecuteMessage] = executeMessage;
64
+ this[kCompleted] = false;
65
+ const executeContent = executeMessage.content;
66
+ const {
67
+ executionId,
68
+ parent
69
+ } = executeContent;
70
+ const parentExecutionId = parent.executionId;
71
+ const broker = this.broker;
72
+
73
+ const onCatchMessage = this._onCatchMessage.bind(this);
74
+
75
+ this[kMessageQ].consume(onCatchMessage, {
76
+ noAck: true,
77
+ consumerTag: `_oncancel-${executionId}`
78
+ });
79
+ if (this[kCompleted]) return;
80
+
81
+ const onApiMessage = this._onApiMessage.bind(this);
82
+
83
+ broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
84
+ noAck: true,
85
+ consumerTag: `_api-parent-${executionId}`
86
+ });
87
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
88
+ noAck: true,
89
+ consumerTag: `_api-${executionId}`
90
+ });
91
+
92
+ this._debug('expect cancel');
93
+
94
+ const exchangeKey = `execute.canceled.${executionId}`;
95
+ broker.subscribeOnce('execution', exchangeKey, onCatchMessage, {
96
+ consumerTag: `_onattached-cancel-${executionId}`
97
+ });
98
+ broker.publish('execution', 'execute.expect', (0, _messageHelper.cloneContent)(executeContent, {
99
+ pattern: '#.cancel',
100
+ exchange: 'execution',
101
+ exchangeKey
102
+ }));
103
+ };
104
+
105
+ proto.executeThrow = function executeThrow(executeMessage) {
106
+ const {
107
+ isTransaction
108
+ } = this.environment.variables.content || {};
109
+ const executeContent = executeMessage.content;
110
+ const {
111
+ executionId,
112
+ parent
113
+ } = executeContent;
114
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw cancel${isTransaction ? ' transaction' : ''}`);
115
+ const broker = this.broker;
116
+ const cancelContent = (0, _messageHelper.cloneContent)(executeContent, {
117
+ isTransaction,
118
+ executionId: parent.executionId,
119
+ state: 'throw'
120
+ });
121
+ cancelContent.parent = (0, _messageHelper.shiftParent)(parent);
122
+ broker.publish('event', 'activity.cancel', cancelContent, {
123
+ type: 'cancel',
124
+ delegate: isTransaction
125
+ });
126
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
127
+ };
128
+
129
+ proto._onCatchMessage = function onCatchMessage(_, message) {
130
+ if (message.content && message.content.isTransaction) return this._onCancelTransaction(_, message);
131
+
132
+ this._debug(`cancel caught from <${message.content.id}>`);
133
+
134
+ return this._complete(message.content.message);
135
+ };
136
+
137
+ proto._onCancelTransaction = function onCancelTransaction(_, message) {
138
+ const broker = this.broker,
139
+ executionId = this.executionId;
140
+ const executeContent = this[kExecuteMessage].content;
141
+ broker.cancel(`_oncancel-${executionId}`);
142
+
143
+ this._debug(`cancel transaction thrown by <${message.content.id}>`);
144
+
145
+ broker.assertExchange('cancel', 'topic');
146
+ broker.publish('execution', 'execute.detach', (0, _messageHelper.cloneContent)(executeContent, {
147
+ pattern: '#',
148
+ bindExchange: 'cancel',
149
+ sourceExchange: 'event',
150
+ sourcePattern: '#'
151
+ }));
152
+ broker.publish('event', 'activity.compensate', (0, _messageHelper.cloneContent)(message.content, {
153
+ state: 'throw'
154
+ }), {
155
+ type: 'compensate',
156
+ delegate: true
157
+ });
158
+ broker.subscribeTmp('cancel', 'activity.leave', (__, {
159
+ content: msg
160
+ }) => {
161
+ if (msg.id !== executeContent.attachedTo) return;
162
+ return this._complete(message.content.message);
163
+ }, {
164
+ noAck: true,
165
+ consumerTag: `_oncancelend-${executionId}`
166
+ });
167
+ };
168
+
169
+ proto._complete = function complete(output) {
170
+ this[kCompleted] = true;
171
+
172
+ this._stop();
173
+
174
+ this._debug('completed');
175
+
176
+ const content = (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
177
+ output,
178
+ state: 'cancel'
179
+ });
180
+ return this.broker.publish('execution', 'execute.completed', content);
181
+ };
182
+
183
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
184
+ switch (message.properties.type) {
185
+ case 'discard':
186
+ {
187
+ this[kCompleted] = true;
188
+
189
+ this._stop();
190
+
191
+ const content = (0, _messageHelper.cloneContent)(this[kExecuteMessage].content);
192
+ return this.broker.publish('execution', 'execute.discard', content);
193
+ }
194
+
195
+ case 'stop':
196
+ {
197
+ this._stop();
198
+
199
+ break;
200
+ }
201
+ }
202
+ };
203
+
204
+ proto._stop = function stop() {
205
+ const broker = this.broker,
206
+ executionId = this.executionId;
207
+ broker.cancel(`_api-parent-${executionId}`);
208
+ broker.cancel(`_api-${executionId}`);
209
+ broker.cancel(`_oncancel-${executionId}`);
210
+ broker.cancel(`_oncancelend-${executionId}`);
211
+ broker.cancel(`_onattached-cancel-${executionId}`);
212
+ this[kMessageQ].purge();
213
+ };
214
+
215
+ proto._debug = function debug(msg) {
216
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
217
+ };