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,132 +3,173 @@ import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecuti
3
3
  import {cloneContent, cloneMessage} from '../messageHelper';
4
4
  import {brokerSafeId} from '../shared';
5
5
 
6
+ const attachedTagsSymbol = Symbol.for('attachedConsumers');
7
+ const completeContentSymbol = Symbol.for('completeContent');
8
+ const executeMessageSymbol = Symbol.for('executeMessage');
9
+ const executionSymbol = Symbol.for('execution');
10
+ const shovelsSymbol = Symbol.for('shovels');
11
+
6
12
  export default function BoundaryEvent(activityDef, context) {
7
- return Activity(BoundaryEventBehaviour, activityDef, context);
13
+ return new Activity(BoundaryEventBehaviour, activityDef, context);
8
14
  }
9
15
 
10
16
  export function BoundaryEventBehaviour(activity) {
11
- const {id, type = 'BoundaryEvent', broker, environment, attachedTo, behaviour = {}, eventDefinitions, logger} = activity;
12
- const attachedToId = attachedTo.id;
13
-
14
- const cancelActivity = 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
15
- const eventDefinitionExecution = eventDefinitions && EventDefinitionExecution(activity, eventDefinitions, 'execute.bound.completed');
16
-
17
- return {
18
- id,
19
- type,
20
- attachedTo,
21
- cancelActivity,
22
- execute,
23
- };
24
-
25
- function execute(executeMessage) {
26
- const executeContent = cloneContent(executeMessage.content);
27
- const {isRootScope, executionId, inbound} = executeContent;
28
-
29
- let parentExecutionId, completeContent;
30
- const errorConsumerTags = [];
31
- const shovels = [];
32
- if (isRootScope) {
33
- parentExecutionId = executionId;
34
- if (eventDefinitionExecution && !environment.settings.strict) {
35
- broker.subscribeTmp('execution', 'execute.expect', onExpectMessage, {noAck: true, consumerTag: '_expect-tag'});
36
- }
37
-
38
- attachedTo.broker.subscribeTmp('event', 'activity.leave', onAttachedLeave, {noAck: true, consumerTag: `_bound-listener-${parentExecutionId}`, priority: 300});
39
-
40
- broker.subscribeOnce('execution', 'execute.detach', onDetachMessage, {consumerTag: '_detach-tag'});
41
- broker.subscribeOnce('api', `activity.#.${parentExecutionId}`, onApiMessage, {consumerTag: `_api-${parentExecutionId}`});
42
- broker.subscribeOnce('execution', 'execute.bound.completed', onCompleted, {consumerTag: `_execution-completed-${parentExecutionId}`});
43
- }
44
-
45
- if (eventDefinitionExecution) eventDefinitionExecution.execute(executeMessage);
46
-
47
- function onCompleted(_, message) {
48
- if (!cancelActivity && !message.content.cancelActivity) {
49
- stop();
50
- return broker.publish('execution', 'execute.completed', cloneContent(message.content));
51
- }
52
-
53
- completeContent = message.content;
54
-
55
- const attachedToContent = inbound && inbound[0];
56
- logger.debug(`<${executionId} (id)> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
57
-
58
- attachedTo.getApi({content: attachedToContent}).discard();
59
- }
60
-
61
- function onAttachedLeave(routingKey, message) {
62
- if (message.content.id !== attachedToId) return;
63
- stop();
64
- if (!completeContent) return broker.publish('execution', 'execute.discard', executeContent);
65
- return broker.publish('execution', 'execute.completed', completeContent);
66
- }
67
-
68
- function onExpectMessage(_, message) {
69
- const errorConsumerTag = `_bound-error-listener-${message.content.executionId}`;
70
- errorConsumerTags.push(errorConsumerTag);
71
- attachedTo.broker.subscribeTmp('event', 'activity.error', attachedErrorHandler(message.content.expectRoutingKey), {noAck: true, consumerTag: errorConsumerTag, priority: 300});
72
- }
17
+ this.id = activity.id;
18
+ this.type = activity.type;
19
+ this.attachedTo = activity.attachedTo;
20
+ this.activity = activity;
21
+ this.environment = activity.environment;
22
+ this.broker = activity.broker;
23
+ this[executionSymbol] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions, 'execute.bound.completed');
24
+ this[shovelsSymbol] = [];
25
+ this[attachedTagsSymbol] = [];
26
+ }
73
27
 
74
- function attachedErrorHandler(routingKey) {
75
- return function onAttachedError(_, message) {
76
- if (message.content.id !== attachedToId) return;
77
- broker.publish('execution', routingKey, cloneContent(message.content));
78
- };
28
+ const proto = BoundaryEventBehaviour.prototype;
29
+
30
+ Object.defineProperty(proto, 'executionId', {
31
+ get() {
32
+ const message = this[executeMessageSymbol];
33
+ return message && message.content.executionId;
34
+ },
35
+ });
36
+
37
+ Object.defineProperty(proto, 'cancelActivity', {
38
+ enumerable: true,
39
+ get() {
40
+ const behaviour = this.activity.behaviour || {};
41
+ return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
42
+ },
43
+ });
44
+
45
+ proto.execute = function execute(executeMessage) {
46
+ const {isRootScope, executionId} = executeMessage.content;
47
+
48
+ const eventDefinitionExecution = this[executionSymbol];
49
+ if (isRootScope) {
50
+ this[executeMessageSymbol] = executeMessage;
51
+
52
+ const broker = this.broker;
53
+ if (eventDefinitionExecution && !this.environment.settings.strict) {
54
+ broker.subscribeTmp('execution', 'execute.expect', this._onExpectMessage.bind(this), {
55
+ noAck: true,
56
+ consumerTag: '_expect-tag',
57
+ });
79
58
  }
80
59
 
81
- function onDetachMessage(_, {content}) {
82
- logger.debug(`<${parentExecutionId} (${id})> detach from activity <${attachedTo.id}>`);
83
- stop(true);
84
-
85
- const {executionId: detachId, bindExchange, sourceExchange = 'execution', sourcePattern} = content;
86
-
87
- const shovelName = `_detached-${brokerSafeId(id)}_${detachId}`;
88
- shovels.push(shovelName);
89
- attachedTo.broker.createShovel(shovelName, {
90
- exchange: sourceExchange,
91
- pattern: sourcePattern,
92
- }, {
93
- broker,
94
- exchange: bindExchange,
95
- }, {
96
- cloneMessage,
97
- });
60
+ const consumerTag = `_bound-listener-${executionId}`;
61
+ this.attachedTo.broker.subscribeTmp('event', 'activity.leave', this._onAttachedLeave.bind(this), {
62
+ noAck: true,
63
+ consumerTag,
64
+ priority: 300,
65
+ });
66
+ this[attachedTagsSymbol].push(consumerTag);
67
+
68
+ broker.subscribeOnce('execution', 'execute.detach', this._onDetachMessage.bind(this), {
69
+ consumerTag: '_detach-tag',
70
+ });
71
+ broker.subscribeOnce('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
72
+ consumerTag: `_api-${executionId}`,
73
+ });
74
+ broker.subscribeOnce('execution', 'execute.bound.completed', this._onCompleted.bind(this), {
75
+ consumerTag: `_execution-completed-${executionId}`,
76
+ });
77
+ }
98
78
 
99
- broker.subscribeOnce('execution', 'execute.bound.completed', onDetachedCompleted, {consumerTag: `_execution-completed-${parentExecutionId}`});
100
- }
79
+ if (eventDefinitionExecution) {
80
+ return eventDefinitionExecution.execute(executeMessage);
81
+ }
82
+ };
101
83
 
102
- function onDetachedCompleted(_, message) {
103
- stop();
104
- return broker.publish('execution', 'execute.completed', cloneContent(message.content));
105
- }
84
+ proto._onCompleted = function onCompleted(_, {content}) {
85
+ if (!this.cancelActivity && !content.cancelActivity) {
86
+ this._stop();
87
+ return this.broker.publish('execution', 'execute.completed', cloneContent(content));
88
+ }
106
89
 
107
- function onApiMessage(_, message) {
108
- const messageType = message.properties.type;
109
- switch (messageType) {
110
- case 'discard':
111
- stop();
112
- break;
113
- case 'stop':
114
- stop();
115
- break;
116
- }
117
- }
90
+ this[completeContentSymbol] = content;
91
+
92
+ const {inbound} = this[executeMessageSymbol].content;
93
+ const attachedToContent = inbound && inbound[0];
94
+ const attachedTo = this.attachedTo;
95
+ this.activity.logger.debug(`<${this.executionId} (${this.id})> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
96
+
97
+ attachedTo.getApi({content: attachedToContent}).discard();
98
+ };
99
+
100
+ proto._onAttachedLeave = function onAttachedLeave(_, {content}) {
101
+ if (content.id !== this.attachedTo.id) return;
102
+ this._stop();
103
+ const completeContent = this[completeContentSymbol];
104
+ if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[executeMessageSymbol].content);
105
+ return this.broker.publish('execution', 'execute.completed', cloneContent(completeContent));
106
+ };
107
+
108
+ proto._onExpectMessage = function onExpectMessage(_, {content}) {
109
+ const {executionId, expectRoutingKey} = content;
110
+ const attachedTo = this.attachedTo;
111
+
112
+ const errorConsumerTag = `_bound-error-listener-${executionId}`;
113
+ this[attachedTagsSymbol].push(errorConsumerTag);
114
+
115
+ attachedTo.broker.subscribeTmp('event', 'activity.error', (__, errorMessage) => {
116
+ if (errorMessage.content.id !== attachedTo.id) return;
117
+ this.broker.publish('execution', expectRoutingKey, cloneContent(errorMessage.content));
118
+ }, {
119
+ noAck: true,
120
+ consumerTag: errorConsumerTag,
121
+ priority: 300,
122
+ });
123
+ };
124
+
125
+ proto._onDetachMessage = function onDetachMessage(_, {content}) {
126
+ const id = this.id, executionId = this.executionId, attachedTo = this.attachedTo;
127
+ this.activity.logger.debug(`<${executionId} (${id})> detach from activity <${attachedTo.id}>`);
128
+ this._stop(true);
129
+
130
+ const {executionId: detachId, bindExchange, sourceExchange, sourcePattern} = content;
131
+
132
+ const shovelName = `_detached-${brokerSafeId(id)}_${detachId}`;
133
+ this[shovelsSymbol].push(shovelName);
134
+
135
+ const broker = this.broker;
136
+ attachedTo.broker.createShovel(shovelName, {
137
+ exchange: sourceExchange,
138
+ pattern: sourcePattern,
139
+ }, {
140
+ broker,
141
+ exchange: bindExchange,
142
+ }, {
143
+ cloneMessage,
144
+ });
145
+
146
+ broker.subscribeOnce('execution', 'execute.bound.completed', (__, {content: completeContent}) => {
147
+ this._stop();
148
+ this.broker.publish('execution', 'execute.completed', cloneContent(completeContent));
149
+ }, {
150
+ consumerTag: `_execution-completed-${executionId}`,
151
+ });
152
+ };
153
+
154
+ proto._onApiMessage = function onApiMessage(_, message) {
155
+ switch (message.properties.type) {
156
+ case 'discard':
157
+ case 'stop':
158
+ this._stop();
159
+ break;
160
+ }
161
+ };
118
162
 
119
- function stop(detach) {
120
- attachedTo.broker.cancel(`_bound-listener-${parentExecutionId}`);
121
- attachedTo.broker.cancel(`_bound-error-listener-${parentExecutionId}`);
122
- errorConsumerTags.splice(0).forEach((tag) => attachedTo.broker.cancel(tag));
123
- shovels.splice(0).forEach((shovelName) => attachedTo.broker.closeShovel(shovelName));
163
+ proto._stop = function stop(detach) {
164
+ const attachedTo = this.attachedTo, broker = this.broker, executionId = this.executionId;
165
+ for (const tag of this[attachedTagsSymbol].splice(0)) attachedTo.broker.cancel(tag);
166
+ for (const shovelName of this[shovelsSymbol].splice(0)) attachedTo.broker.closeShovel(shovelName);
124
167
 
125
- broker.cancel('_expect-tag');
126
- broker.cancel('_detach-tag');
127
- broker.cancel(`_execution-completed-${parentExecutionId}`);
168
+ broker.cancel('_expect-tag');
169
+ broker.cancel('_detach-tag');
170
+ broker.cancel(`_execution-completed-${executionId}`);
128
171
 
129
- if (detach) return;
172
+ if (detach) return;
130
173
 
131
- broker.cancel(`_api-${parentExecutionId}`);
132
- }
133
- }
134
- }
174
+ broker.cancel(`_api-${executionId}`);
175
+ };
@@ -2,27 +2,24 @@ import Activity from '../activity/Activity';
2
2
  import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution';
3
3
  import {cloneContent} from '../messageHelper';
4
4
 
5
+ const executionSymbol = Symbol.for('execution');
6
+
5
7
  export default function EndEvent(activityDef, context) {
6
- return Activity(EndEventBehaviour, {...activityDef, isThrowing: true}, context);
8
+ return new Activity(EndEventBehaviour, {...activityDef, isThrowing: true}, context);
7
9
  }
8
10
 
9
11
  export function EndEventBehaviour(activity) {
10
- const {id, type, broker, eventDefinitions} = activity;
11
- const eventDefinitionExecution = eventDefinitions && EventDefinitionExecution(activity, eventDefinitions);
12
-
13
- const source = {
14
- id,
15
- type,
16
- execute,
17
- };
18
-
19
- return source;
20
-
21
- function execute(executeMessage) {
22
- if (eventDefinitionExecution) {
23
- return eventDefinitionExecution.execute(executeMessage);
24
- }
12
+ this.id = activity.id;
13
+ this.type = activity.type;
14
+ this.broker = activity.broker;
15
+ this[executionSymbol] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
16
+ }
25
17
 
26
- return broker.publish('execution', 'execute.completed', cloneContent(executeMessage.content));
18
+ EndEventBehaviour.prototype.execute = function execute(executeMessage) {
19
+ const execution = this[executionSymbol];
20
+ if (execution) {
21
+ return execution.execute(executeMessage);
27
22
  }
28
- }
23
+
24
+ return this.broker.publish('execution', 'execute.completed', cloneContent(executeMessage.content));
25
+ };
@@ -2,57 +2,53 @@ import Activity from '../activity/Activity';
2
2
  import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution';
3
3
  import {cloneContent} from '../messageHelper';
4
4
 
5
+ const executionSymbol = Symbol.for('execution');
6
+
5
7
  export default function IntermediateCatchEvent(activityDef, context) {
6
- return Activity(IntermediateCatchEventBehaviour, activityDef, context);
8
+ return new Activity(IntermediateCatchEventBehaviour, activityDef, context);
7
9
  }
8
10
 
9
11
  export function IntermediateCatchEventBehaviour(activity) {
10
- const {id, type, broker, eventDefinitions} = activity;
11
- const eventDefinitionExecution = eventDefinitions && EventDefinitionExecution(activity, eventDefinitions);
12
-
13
- const source = {
14
- id,
15
- type,
16
- execute,
17
- };
18
-
19
- return source;
20
-
21
- function execute(executeMessage) {
22
- if (eventDefinitionExecution) {
23
- return eventDefinitionExecution.execute(executeMessage);
24
- }
25
-
26
- const content = cloneContent(executeMessage.content);
27
- const {executionId} = content;
28
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`});
12
+ this.id = activity.id;
13
+ this.type = activity.type;
14
+ this.broker = activity.broker;
15
+ this[executionSymbol] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
16
+ }
29
17
 
30
- return broker.publish('event', 'activity.wait', cloneContent(content));
18
+ IntermediateCatchEventBehaviour.prototype.execute = function execute(executeMessage) {
19
+ const execution = this[executionSymbol];
20
+ if (execution) {
21
+ return execution.execute(executeMessage);
22
+ }
31
23
 
32
- function onApiMessage(routingKey, message) {
33
- const messageType = message.properties.type;
34
- switch (messageType) {
35
- case 'message':
36
- case 'signal': {
37
- return complete(message.content.message);
38
- }
39
- case 'discard': {
40
- stop();
41
- return broker.publish('execution', 'execute.discard', cloneContent(content));
42
- }
43
- case 'stop': {
44
- return stop();
45
- }
46
- }
24
+ const executeContent = executeMessage.content;
25
+ const executionId = executeContent.executionId;
26
+ const broker = this.broker;
27
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this, executeMessage), {
28
+ noAck: true,
29
+ consumerTag: '_api-behaviour-execution',
30
+ });
31
+
32
+ return broker.publish('event', 'activity.wait', cloneContent(executeContent));
33
+ };
34
+
35
+ IntermediateCatchEventBehaviour.prototype._onApiMessage = function onApiMessage(executeMessage, routingKey, message) {
36
+ switch (message.properties.type) {
37
+ case 'message':
38
+ case 'signal': {
39
+ const broker = this.broker;
40
+ broker.cancel('_api-behaviour-execution');
41
+ return broker.publish('execution', 'execute.completed', cloneContent(executeMessage.content, {
42
+ output: message.content.message,
43
+ }));
47
44
  }
48
-
49
- function complete(output) {
50
- stop();
51
- return broker.publish('execution', 'execute.completed', cloneContent(content, {output}));
45
+ case 'discard': {
46
+ const broker = this.broker;
47
+ broker.cancel('_api-behaviour-execution');
48
+ return broker.publish('execution', 'execute.discard', cloneContent(executeMessage.content));
52
49
  }
53
-
54
- function stop() {
55
- broker.cancel(`_api-${executionId}`);
50
+ case 'stop': {
51
+ return this.broker.cancel('_api-behaviour-execution');
56
52
  }
57
53
  }
58
- }
54
+ };
@@ -2,27 +2,24 @@ import Activity from '../activity/Activity';
2
2
  import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution';
3
3
  import {cloneContent} from '../messageHelper';
4
4
 
5
+ const executionSymbol = Symbol.for('execution');
6
+
5
7
  export default function IntermediateThrowEvent(activityDef, context) {
6
- return Activity(IntermediateThrowEventBehaviour, {...activityDef, isThrowing: true}, context);
8
+ return new Activity(IntermediateThrowEventBehaviour, {...activityDef, isThrowing: true}, context);
7
9
  }
8
10
 
9
11
  export function IntermediateThrowEventBehaviour(activity) {
10
- const {id, type, broker, eventDefinitions} = activity;
11
- const eventDefinitionExecution = eventDefinitions && EventDefinitionExecution(activity, eventDefinitions);
12
-
13
- const source = {
14
- id,
15
- type,
16
- execute,
17
- };
18
-
19
- return source;
20
-
21
- function execute(executeMessage) {
22
- if (eventDefinitionExecution) {
23
- return eventDefinitionExecution.execute(executeMessage);
24
- }
12
+ this.id = activity.id;
13
+ this.type = activity.type;
14
+ this.broker = activity.broker;
15
+ this[executionSymbol] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
16
+ }
25
17
 
26
- return broker.publish('execution', 'execute.completed', cloneContent(executeMessage.content));
18
+ IntermediateThrowEventBehaviour.prototype.execute = function execute(executeMessage) {
19
+ const execution = this[executionSymbol];
20
+ if (execution) {
21
+ return execution.execute(executeMessage);
27
22
  }
28
- }
23
+
24
+ return this.broker.publish('execution', 'execute.completed', cloneContent(executeMessage.content));
25
+ };
@@ -2,68 +2,102 @@ import Activity from '../activity/Activity';
2
2
  import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution';
3
3
  import {cloneContent} from '../messageHelper';
4
4
 
5
+ const executeMessageSymbol = Symbol.for('executeMessage');
6
+ const executionSymbol = Symbol.for('execution');
7
+
5
8
  export default function StartEvent(activityDef, context) {
6
- return Activity(StartEventBehaviour, activityDef, context);
9
+ return new Activity(StartEventBehaviour, activityDef, context);
7
10
  }
8
11
 
9
12
  export function StartEventBehaviour(activity) {
10
- const {id, type = 'startevent', broker, eventDefinitions} = activity;
11
- const eventDefinitionExecution = eventDefinitions && EventDefinitionExecution(activity, eventDefinitions);
13
+ this.id = activity.id;
14
+ this.type = activity.type;
15
+ this.activity = activity;
16
+ this.broker = activity.broker;
17
+ this[executionSymbol] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
18
+ }
12
19
 
13
- const event = {
14
- id,
15
- type,
16
- execute,
17
- };
20
+ const proto = StartEventBehaviour.prototype;
18
21
 
19
- return event;
22
+ Object.defineProperty(proto, 'executionId', {
23
+ get() {
24
+ const message = this[executeMessageSymbol];
25
+ return message && message.content.executionId;
26
+ },
27
+ });
20
28
 
21
- function execute(executeMessage) {
22
- if (eventDefinitionExecution) {
23
- return eventDefinitionExecution.execute(executeMessage);
24
- }
29
+ proto.execute = function execute(executeMessage) {
30
+ const execution = this[executionSymbol];
31
+ if (execution) {
32
+ return execution.execute(executeMessage);
33
+ }
25
34
 
26
- const content = cloneContent(executeMessage.content);
27
- if (!content.form) {
28
- return broker.publish('execution', 'execute.completed', content);
29
- }
35
+ const content = cloneContent(executeMessage.content);
36
+ const broker = this.broker;
37
+ if (!content.form) {
38
+ return broker.publish('execution', 'execute.completed', content);
39
+ }
30
40
 
31
- const {executionId} = content;
32
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`, priority: 300});
33
- broker.subscribeTmp('api', '#.signal.*', onDelegatedApiMessage, {noAck: true, consumerTag: `_api-delegated-${executionId}`});
34
- broker.publish('event', 'activity.wait', {...content, executionId, state: 'wait'});
41
+ const executionId = content.executionId;
42
+ this[executeMessageSymbol] = executeMessage;
43
+ broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(...args), {
44
+ noAck: true,
45
+ consumerTag: `_api-${executionId}`,
46
+ priority: 300,
47
+ });
48
+ broker.subscribeTmp('api', '#.signal.*', (...args) => this._onDelegatedApiMessage(...args), {
49
+ noAck: true,
50
+ consumerTag: `_api-delegated-${executionId}`,
51
+ });
52
+ broker.publish('event', 'activity.wait', {...content, executionId, state: 'wait'});
53
+ };
35
54
 
36
- function onDelegatedApiMessage(routingKey, message) {
37
- if (!message.properties.delegate) return;
38
- const {content: delegateContent} = message;
39
- if (!delegateContent || !delegateContent.message) return;
55
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
56
+ const {type: messageType, correlationId} = message.properties;
57
+ switch (messageType) {
58
+ case 'stop':
59
+ return this._stop();
60
+ case 'signal': {
61
+ this._stop();
62
+ const content = this[executeMessageSymbol].content;
63
+ return this.broker.publish('execution', 'execute.completed', cloneContent(content, {
64
+ output: message.content.message,
65
+ state: 'signal',
66
+ }), {correlationId});
67
+ }
68
+ case 'discard': {
69
+ this._stop();
70
+ const content = this[executeMessageSymbol].content;
71
+ return this.broker.publish('execution', 'execute.discard', cloneContent(content), {correlationId});
72
+ }
73
+ }
74
+ };
40
75
 
41
- const {id: signalId, executionId: signalExecutionId} = delegateContent.message;
42
- if (signalId !== id && signalExecutionId !== executionId) return;
76
+ proto._onDelegatedApiMessage = function onDelegatedApiMessage(routingKey, message) {
77
+ if (!message.properties.delegate) return;
43
78
 
44
- const {type: messageType, correlationId} = message.properties;
45
- broker.publish('event', 'activity.consumed', cloneContent(content, {message: {...delegateContent.message}}), {correlationId, type: messageType});
46
- return onApiMessage(routingKey, message);
47
- }
79
+ const content = message.content;
80
+ if (!content.message) return;
48
81
 
49
- function onApiMessage(routingKey, message) {
50
- const {type: messageType, correlationId} = message.properties;
82
+ const {id: signalId, executionId: signalExecutionId} = content.message;
83
+ if (signalId !== this.id && signalExecutionId !== this.executionId) return;
51
84
 
52
- switch (messageType) {
53
- case 'stop':
54
- return stop();
55
- case 'signal':
56
- stop();
57
- return broker.publish('execution', 'execute.completed', cloneContent(content, {output: message.content.message, state: 'signal'}), {correlationId});
58
- case 'discard':
59
- stop();
60
- return broker.publish('execution', 'execute.discard', cloneContent(content), {correlationId});
61
- }
62
- }
85
+ const {type, correlationId} = message.properties;
86
+ const executeContent = this[executeMessageSymbol].content;
87
+ this.broker.publish('event', 'activity.consumed', cloneContent(executeContent, {
88
+ message: {
89
+ ...content.message,
90
+ },
91
+ }), {
92
+ correlationId,
93
+ type,
94
+ });
63
95
 
64
- function stop() {
65
- broker.cancel(`_api-${executionId}`);
66
- broker.cancel(`_api-delegated-${executionId}`);
67
- }
68
- }
69
- }
96
+ return this._onApiMessage(routingKey, message);
97
+ };
98
+
99
+ proto._stop = function stop() {
100
+ const broker = this.broker, executionId = this.executionId;
101
+ broker.cancel(`_api-${executionId}`);
102
+ broker.cancel(`_api-delegated-${executionId}`);
103
+ };