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
@@ -3,186 +3,219 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = CompensationEventDefinition;
6
+ exports.default = CompensateEventDefinition;
7
7
 
8
8
  var _shared = require("../shared");
9
9
 
10
10
  var _messageHelper = require("../messageHelper");
11
11
 
12
- function CompensationEventDefinition(activity, eventDefinition, context) {
12
+ const completedSymbol = Symbol.for('completed');
13
+ const executeMessageSymbol = Symbol.for('executeMessage');
14
+ const messageQSymbol = Symbol.for('messageQ');
15
+ const compensateQSymbol = Symbol.for('compensateQ');
16
+ const associationsSymbol = Symbol.for('associations');
17
+
18
+ function CompensateEventDefinition(activity, eventDefinition, context) {
13
19
  const {
14
20
  id,
15
21
  broker,
16
22
  environment,
17
23
  isThrowing
18
24
  } = activity;
19
- const {
20
- type
21
- } = eventDefinition;
22
- const {
23
- debug
24
- } = environment.Logger(type.toLowerCase());
25
- const compensationQueueName = `compensate-${(0, _shared.brokerSafeId)(id)}-q`;
26
- const associations = context.getOutboundAssociations(id) || [];
27
- if (!isThrowing) setupCatch();
28
- const source = {
29
- id,
30
- type,
31
- reference: {
32
- referenceType: 'compensate'
33
- },
34
- execute: isThrowing ? executeThrow : executeCatch
25
+ this.id = id;
26
+ const type = this.type = eventDefinition.type;
27
+ const reference = this.reference = {
28
+ referenceType: 'compensate'
35
29
  };
36
- return source;
37
-
38
- function executeCatch(executeMessage) {
39
- let completed;
40
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
41
- const {
42
- executionId,
43
- parent
44
- } = messageContent;
45
- const parentExecutionId = parent && parent.executionId;
46
- broker.consume(compensationQueueName, onCompensateApiMessage, {
47
- noAck: true,
48
- consumerTag: `_oncompensate-${executionId}`
49
- });
50
- if (completed) return;
51
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
52
- noAck: true,
53
- consumerTag: `_api-${executionId}`
30
+ this.isThrowing = isThrowing;
31
+ this.activity = activity;
32
+ this.broker = broker;
33
+ this.logger = environment.Logger(type.toLowerCase());
34
+
35
+ if (!isThrowing) {
36
+ this[completedSymbol] = false;
37
+ this[associationsSymbol] = context.getOutboundAssociations(id) || [];
38
+ const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-q`;
39
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {
40
+ autoDelete: false,
41
+ durable: true
54
42
  });
55
- if (completed) return stop();
56
- debug(`<${executionId} (${id})> expect compensate`);
57
- broker.assertExchange('compensate', 'topic');
58
- const compensateQ = broker.assertQueue('compensate-q', {
43
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
59
44
  durable: true,
60
- autoDelete: false
61
- });
62
- broker.subscribeTmp('compensate', 'execute.#', onCollect, {
63
- noAck: true,
64
- consumerTag: '_oncollect-messages'
65
- });
66
- broker.publish('execution', 'execute.detach', (0, _messageHelper.cloneContent)(messageContent, {
67
- bindExchange: 'compensate'
68
- }));
69
- broker.publish('event', 'activity.detach', { ...messageContent,
70
- executionId: parentExecutionId,
71
- parent: (0, _messageHelper.shiftParent)(parent),
72
- bindExchange: 'compensate'
45
+ priority: 400
73
46
  });
47
+ }
48
+ }
74
49
 
75
- function onCollect(routingKey, message) {
76
- switch (routingKey) {
77
- case 'execute.error':
78
- case 'execute.completed':
79
- {
80
- return compensateQ.queueMessage(message.fields, (0, _messageHelper.cloneContent)(message.content), message.properties);
81
- }
82
- }
83
- }
84
-
85
- function onCompensateApiMessage(routingKey, message) {
86
- const output = message.content.message;
87
- completed = true;
88
- stop();
89
- debug(`<${executionId} (${id})> caught compensate event`);
90
- broker.publish('event', 'activity.catch', { ...messageContent,
91
- message: { ...output
92
- },
93
- executionId: parentExecutionId,
94
- parent: (0, _messageHelper.shiftParent)(executeMessage.content.parent)
95
- }, {
96
- type: 'catch'
97
- });
98
- compensateQ.on('depleted', onDepleted);
99
- compensateQ.consume(onCollected, {
100
- noAck: true,
101
- consumerTag: '_convey-messages'
102
- });
103
- associations.forEach(association => {
104
- association.complete((0, _messageHelper.cloneMessage)(message));
105
- });
106
-
107
- function onDepleted() {
108
- compensateQ.off('depleted', onDepleted);
109
- return broker.publish('execution', 'execute.completed', { ...messageContent,
110
- output,
111
- state: 'catch'
112
- });
113
- }
114
- }
115
-
116
- function onCollected(routingKey, message) {
117
- associations.forEach(association => {
118
- association.take((0, _messageHelper.cloneMessage)(message));
119
- });
120
- }
121
-
122
- function onApiMessage(routingKey, message) {
123
- const messageType = message.properties.type;
124
-
125
- switch (messageType) {
126
- case 'compensate':
127
- {
128
- return onCompensateApiMessage(routingKey, message);
129
- }
130
-
131
- case 'discard':
132
- {
133
- completed = true;
134
- stop();
135
- associations.forEach(association => {
136
- association.discard((0, _messageHelper.cloneMessage)(message));
137
- });
138
- return broker.publish('execution', 'execute.discard', { ...messageContent
139
- });
140
- }
141
-
142
- case 'stop':
143
- {
144
- stop();
145
- break;
146
- }
50
+ const proto = CompensateEventDefinition.prototype;
51
+ Object.defineProperty(proto, 'executionId', {
52
+ get() {
53
+ const message = this[executeMessageSymbol];
54
+ return message && message.content.executionId;
55
+ }
56
+
57
+ });
58
+
59
+ proto.execute = function execute(executeMessage) {
60
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
61
+ };
62
+
63
+ proto.executeCatch = function executeCatch(executeMessage) {
64
+ this[executeMessageSymbol] = executeMessage;
65
+ this[completedSymbol] = false;
66
+ const executeContent = executeMessage.content;
67
+ const {
68
+ executionId,
69
+ parent
70
+ } = executeContent;
71
+
72
+ this._debug('expect compensate');
73
+
74
+ const broker = this.broker;
75
+ broker.assertExchange('compensate', 'topic');
76
+ this[compensateQSymbol] = broker.assertQueue('compensate-q', {
77
+ durable: true,
78
+ autoDelete: false
79
+ });
80
+ broker.subscribeTmp('compensate', 'execute.#', this._onCollect.bind(this), {
81
+ noAck: true,
82
+ consumerTag: '_oncollect-messages'
83
+ });
84
+ broker.publish('execution', 'execute.detach', (0, _messageHelper.cloneContent)(executeContent, {
85
+ sourceExchange: 'execution',
86
+ bindExchange: 'compensate'
87
+ }));
88
+ this[messageQSymbol].consume(this._onCompensateApiMessage.bind(this), {
89
+ noAck: true,
90
+ consumerTag: `_oncompensate-${executionId}`
91
+ });
92
+ if (this[completedSymbol]) return;
93
+
94
+ const onApiMessage = this._onApiMessage.bind(this);
95
+
96
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
97
+ noAck: true,
98
+ consumerTag: `_api-${executionId}`
99
+ });
100
+ const detachContent = (0, _messageHelper.cloneContent)(executeContent, {
101
+ executionId: parent.executionId,
102
+ bindExchange: 'compensate'
103
+ });
104
+ detachContent.parent = (0, _messageHelper.shiftParent)(parent);
105
+ broker.publish('event', 'activity.detach', detachContent);
106
+ };
107
+
108
+ proto.executeThrow = function executeThrow(executeMessage) {
109
+ const executeContent = executeMessage.content;
110
+ const {
111
+ executionId,
112
+ parent
113
+ } = executeContent;
114
+ const parentExecutionId = parent && parent.executionId;
115
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw compensate`);
116
+ const broker = this.broker;
117
+ const throwContent = (0, _messageHelper.cloneContent)(executeContent, {
118
+ executionId: parentExecutionId,
119
+ state: 'throw'
120
+ });
121
+ throwContent.parent = (0, _messageHelper.shiftParent)(parent);
122
+ broker.publish('event', 'activity.compensate', throwContent, {
123
+ type: 'compensate',
124
+ delegate: true
125
+ });
126
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
127
+ };
128
+
129
+ proto._onCollect = function onCollect(routingKey, message) {
130
+ switch (routingKey) {
131
+ case 'execute.error':
132
+ case 'execute.completed':
133
+ {
134
+ return this[compensateQSymbol].queueMessage(message.fields, (0, _messageHelper.cloneContent)(message.content), message.properties);
147
135
  }
148
- }
149
-
150
- function stop() {
151
- broker.cancel(`_api-${executionId}`);
152
- broker.cancel(`_oncompensate-${executionId}`);
153
- broker.cancel('_oncollect-messages');
154
- broker.cancel('_convey-messages');
155
- }
156
136
  }
137
+ };
157
138
 
158
- function executeThrow(executeMessage) {
159
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
160
- const {
161
- executionId,
162
- parent
163
- } = messageContent;
164
- const parentExecutionId = parent && parent.executionId;
165
- debug(`<${executionId} (${id})> throw compensate`);
166
- broker.publish('event', 'activity.compensate', { ...(0, _messageHelper.cloneContent)(messageContent),
167
- executionId: parentExecutionId,
168
- parent: (0, _messageHelper.shiftParent)(parent),
169
- state: 'throw'
170
- }, {
171
- type: 'compensate',
172
- delegate: true
173
- });
174
- return broker.publish('execution', 'execute.completed', { ...messageContent
175
- });
139
+ proto._onCompensateApiMessage = function onCompensateApiMessage(routingKey, message) {
140
+ const output = message.content.message;
141
+ this[completedSymbol] = true;
142
+
143
+ this._stop();
144
+
145
+ this._debug('caught compensate event');
146
+
147
+ const broker = this.broker;
148
+ const executeContent = this[executeMessageSymbol].content;
149
+ const catchContent = (0, _messageHelper.cloneContent)(executeContent, {
150
+ message: { ...output
151
+ },
152
+ executionId: executeContent.parent.executionId
153
+ });
154
+ catchContent.parent = (0, _messageHelper.shiftParent)(catchContent.parent);
155
+ broker.publish('event', 'activity.catch', catchContent, {
156
+ type: 'catch'
157
+ });
158
+ const compensateQ = this[compensateQSymbol];
159
+ compensateQ.on('depleted', onDepleted);
160
+ compensateQ.consume(this._onCollected.bind(this), {
161
+ noAck: true,
162
+ consumerTag: '_convey-messages'
163
+ });
164
+
165
+ for (const association of this[associationsSymbol]) association.complete((0, _messageHelper.cloneMessage)(message));
166
+
167
+ function onDepleted() {
168
+ compensateQ.off('depleted', onDepleted);
169
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
170
+ output,
171
+ state: 'catch'
172
+ }));
176
173
  }
174
+ };
177
175
 
178
- function setupCatch() {
179
- broker.assertQueue(compensationQueueName, {
180
- autoDelete: false,
181
- durable: true
182
- });
183
- broker.bindQueue(compensationQueueName, 'api', '*.compensate.#', {
184
- durable: true,
185
- priority: 400
186
- });
176
+ proto._onCollected = function onCollected(routingKey, message) {
177
+ for (const association of this[associationsSymbol]) association.take((0, _messageHelper.cloneMessage)(message));
178
+ };
179
+
180
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
181
+ const messageType = message.properties.type;
182
+
183
+ switch (messageType) {
184
+ case 'compensate':
185
+ {
186
+ return this._onCompensateApiMessage(routingKey, message);
187
+ }
188
+
189
+ case 'discard':
190
+ {
191
+ this[completedSymbol] = true;
192
+
193
+ this._stop();
194
+
195
+ for (const association of this[associationsSymbol]) association.discard((0, _messageHelper.cloneMessage)(message));
196
+
197
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
198
+ }
199
+
200
+ case 'stop':
201
+ {
202
+ this._stop();
203
+
204
+ break;
205
+ }
187
206
  }
188
- }
207
+ };
208
+
209
+ proto._stop = function stop() {
210
+ const broker = this.broker,
211
+ executionId = this.executionId;
212
+ broker.cancel(`_api-${executionId}`);
213
+ broker.cancel(`_oncompensate-${executionId}`);
214
+ broker.cancel('_oncollect-messages');
215
+ broker.cancel('_convey-messages');
216
+ this[messageQSymbol].purge();
217
+ };
218
+
219
+ proto._debug = function debug(msg) {
220
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
221
+ };