bpmn-elements 6.0.1 → 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 (116) hide show
  1. package/CHANGELOG.md +322 -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 +169 -175
  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/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 +722 -409
  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 +433 -359
  49. package/dist/src/process/ProcessExecution.js +744 -645
  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 +195 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +13 -13
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +138 -141
  65. package/src/Environment.js +88 -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 +436 -401
  73. package/src/definition/DefinitionExecution.js +603 -343
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +158 -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 +16 -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 +374 -333
  106. package/src/process/ProcessExecution.js +606 -554
  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,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
+ };