bpmn-elements 17.2.2 → 18.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 (155) hide show
  1. package/README.md +3 -1
  2. package/dist/Api.js +83 -0
  3. package/dist/Context.js +228 -22
  4. package/dist/Environment.js +111 -31
  5. package/dist/EventBroker.js +57 -1
  6. package/dist/Expressions.js +3 -4
  7. package/dist/MessageFormatter.js +29 -16
  8. package/dist/Timers.js +13 -9
  9. package/dist/Tracker.js +1 -0
  10. package/dist/activity/Activity.js +458 -254
  11. package/dist/activity/ActivityExecution.js +113 -40
  12. package/dist/activity/Dummy.js +6 -1
  13. package/dist/activity/Escalation.js +36 -24
  14. package/dist/activity/ExecutionScope.js +1 -1
  15. package/dist/activity/Message.js +36 -24
  16. package/dist/activity/Signal.js +36 -24
  17. package/dist/activity/outbound-evaluator.js +1 -1
  18. package/dist/condition.js +12 -6
  19. package/dist/constants.js +21 -0
  20. package/dist/definition/Definition.js +182 -64
  21. package/dist/definition/DefinitionExecution.js +195 -82
  22. package/dist/error/BpmnError.js +12 -1
  23. package/dist/error/Errors.js +50 -9
  24. package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
  25. package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
  26. package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
  27. package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
  28. package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
  29. package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
  30. package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
  31. package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
  32. package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
  33. package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
  34. package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
  35. package/dist/eventDefinitions/index.js +20 -21
  36. package/dist/events/BoundaryEvent.js +52 -40
  37. package/dist/events/EndEvent.js +22 -8
  38. package/dist/events/IntermediateCatchEvent.js +26 -8
  39. package/dist/events/IntermediateThrowEvent.js +24 -9
  40. package/dist/events/StartEvent.js +30 -14
  41. package/dist/events/index.js +10 -11
  42. package/dist/flows/Association.js +50 -7
  43. package/dist/flows/MessageFlow.js +49 -10
  44. package/dist/flows/SequenceFlow.js +93 -22
  45. package/dist/flows/index.js +6 -7
  46. package/dist/gateways/EventBasedGateway.js +29 -15
  47. package/dist/gateways/ExclusiveGateway.js +20 -5
  48. package/dist/gateways/InclusiveGateway.js +21 -5
  49. package/dist/gateways/ParallelGateway.js +253 -15
  50. package/dist/gateways/index.js +8 -9
  51. package/dist/getPropertyValue.js +2 -2
  52. package/dist/index.js +42 -43
  53. package/dist/io/BpmnIO.js +15 -1
  54. package/dist/io/EnvironmentDataObject.js +29 -1
  55. package/dist/io/EnvironmentDataStore.js +24 -1
  56. package/dist/io/EnvironmentDataStoreReference.js +24 -1
  57. package/dist/io/InputOutputSpecification.js +21 -11
  58. package/dist/io/Properties.js +28 -17
  59. package/dist/messageHelper.js +41 -4
  60. package/dist/process/Lane.js +15 -4
  61. package/dist/process/Process.js +174 -76
  62. package/dist/process/ProcessExecution.js +362 -177
  63. package/dist/shared.js +2 -0
  64. package/dist/tasks/CallActivity.js +19 -4
  65. package/dist/tasks/LoopCharacteristics.js +94 -9
  66. package/dist/tasks/ReceiveTask.js +36 -21
  67. package/dist/tasks/ScriptTask.js +22 -6
  68. package/dist/tasks/ServiceImplementation.js +7 -4
  69. package/dist/tasks/ServiceTask.js +19 -4
  70. package/dist/tasks/SignalTask.js +19 -4
  71. package/dist/tasks/StandardLoopCharacteristics.js +8 -4
  72. package/dist/tasks/SubProcess.js +44 -29
  73. package/dist/tasks/Task.js +19 -4
  74. package/dist/tasks/Transaction.js +8 -4
  75. package/dist/tasks/index.js +16 -18
  76. package/package.json +31 -13
  77. package/src/Api.js +70 -0
  78. package/src/Context.js +200 -19
  79. package/src/Environment.js +99 -30
  80. package/src/EventBroker.js +46 -1
  81. package/src/Expressions.js +2 -3
  82. package/src/MessageFormatter.js +24 -16
  83. package/src/Timers.js +12 -9
  84. package/src/Tracker.js +1 -0
  85. package/src/activity/Activity.js +388 -231
  86. package/src/activity/ActivityExecution.js +93 -42
  87. package/src/activity/Dummy.js +6 -1
  88. package/src/activity/Escalation.js +25 -18
  89. package/src/activity/ExecutionScope.js +1 -1
  90. package/src/activity/Message.js +25 -18
  91. package/src/activity/Signal.js +25 -18
  92. package/src/activity/outbound-evaluator.js +1 -1
  93. package/src/condition.js +11 -5
  94. package/src/constants.js +15 -0
  95. package/src/definition/Definition.js +157 -62
  96. package/src/definition/DefinitionExecution.js +161 -83
  97. package/src/error/BpmnError.js +11 -1
  98. package/src/error/Errors.js +44 -5
  99. package/src/eventDefinitions/CancelEventDefinition.js +27 -13
  100. package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
  101. package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
  102. package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
  103. package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
  104. package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
  105. package/src/eventDefinitions/LinkEventDefinition.js +34 -120
  106. package/src/eventDefinitions/MessageEventDefinition.js +42 -31
  107. package/src/eventDefinitions/SignalEventDefinition.js +43 -32
  108. package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
  109. package/src/eventDefinitions/TimerEventDefinition.js +53 -35
  110. package/src/eventDefinitions/index.js +10 -23
  111. package/src/events/BoundaryEvent.js +50 -39
  112. package/src/events/EndEvent.js +19 -7
  113. package/src/events/IntermediateCatchEvent.js +24 -8
  114. package/src/events/IntermediateThrowEvent.js +24 -8
  115. package/src/events/StartEvent.js +25 -14
  116. package/src/events/index.js +5 -18
  117. package/src/flows/Association.js +43 -9
  118. package/src/flows/MessageFlow.js +41 -10
  119. package/src/flows/SequenceFlow.js +82 -19
  120. package/src/flows/index.js +3 -4
  121. package/src/gateways/EventBasedGateway.js +27 -15
  122. package/src/gateways/ExclusiveGateway.js +16 -3
  123. package/src/gateways/InclusiveGateway.js +16 -3
  124. package/src/gateways/ParallelGateway.js +301 -10
  125. package/src/gateways/index.js +4 -4
  126. package/src/getPropertyValue.js +2 -2
  127. package/src/index.js +19 -19
  128. package/src/io/BpmnIO.js +13 -1
  129. package/src/io/EnvironmentDataObject.js +26 -1
  130. package/src/io/EnvironmentDataStore.js +22 -1
  131. package/src/io/EnvironmentDataStoreReference.js +22 -1
  132. package/src/io/InputOutputSpecification.js +17 -8
  133. package/src/io/Properties.js +23 -13
  134. package/src/messageHelper.js +36 -4
  135. package/src/process/Lane.js +14 -4
  136. package/src/process/Process.js +154 -72
  137. package/src/process/ProcessExecution.js +326 -175
  138. package/src/shared.js +1 -0
  139. package/src/tasks/CallActivity.js +16 -2
  140. package/src/tasks/LoopCharacteristics.js +77 -11
  141. package/src/tasks/ReceiveTask.js +33 -22
  142. package/src/tasks/ScriptTask.js +17 -3
  143. package/src/tasks/ServiceImplementation.js +6 -3
  144. package/src/tasks/ServiceTask.js +16 -2
  145. package/src/tasks/SignalTask.js +16 -2
  146. package/src/tasks/StandardLoopCharacteristics.js +7 -3
  147. package/src/tasks/SubProcess.js +37 -23
  148. package/src/tasks/Task.js +16 -2
  149. package/src/tasks/Transaction.js +7 -3
  150. package/src/tasks/index.js +8 -9
  151. package/types/bundle-errors.d.ts +1 -0
  152. package/types/bundle.d.ts +97 -0
  153. package/types/index.d.ts +2614 -84
  154. package/types/interfaces.d.ts +636 -0
  155. package/types/types.d.ts +0 -765
@@ -1,69 +1,77 @@
1
- import getPropertyValue from '../getPropertyValue.js';
1
+ import { getPropertyValue } from '../getPropertyValue.js';
2
2
  import { brokerSafeId } from '../shared.js';
3
3
  import { cloneContent, shiftParent } from '../messageHelper.js';
4
-
5
- const kCompleted = Symbol.for('completed');
6
- const kMessageQ = Symbol.for('messageQ');
7
- const kExecuteMessage = Symbol.for('executeMessage');
8
- const kReferenceElement = Symbol.for('referenceElement');
9
- const kReferenceInfo = Symbol.for('referenceInfo');
10
-
11
- export default function SignalEventDefinition(activity, eventDefinition) {
4
+ import { K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_Q, K_REFERENCE_ELEMENT, K_REFERENCE_INFO } from '../constants.js';
5
+
6
+ /**
7
+ * Signal event definition
8
+ * @param {import('#types').Activity} activity
9
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
10
+ */
11
+ export function SignalEventDefinition(activity, eventDefinition) {
12
12
  const { id, broker, environment, isStart, isThrowing } = activity;
13
13
  const { type, behaviour = {} } = eventDefinition;
14
14
 
15
15
  this.id = id;
16
16
  this.type = type;
17
17
 
18
- const reference = (this.reference = {
18
+ /** @type {import('#types').EventReference} */
19
+ this.reference = {
19
20
  name: 'anonymous',
20
21
  ...behaviour.signalRef,
21
22
  referenceType: 'signal',
22
- });
23
+ };
23
24
 
24
25
  this.isThrowing = isThrowing;
25
26
  this.activity = activity;
26
27
  this.broker = broker;
27
28
  this.logger = environment.Logger(type.toLowerCase());
28
29
 
29
- const referenceElement = (this[kReferenceElement] = reference.id && activity.getActivityById(reference.id));
30
+ const referenceElement = (this[K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id));
30
31
  if (!isThrowing && isStart) {
31
- this[kCompleted] = false;
32
+ this[K_COMPLETED] = false;
32
33
  const referenceId = referenceElement ? referenceElement.id : 'anonymous';
33
- const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
34
- this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
35
- broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true });
34
+ const messageQueueName = `${this.reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
35
+ this[K_MESSAGE_Q] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
36
+ broker.bindQueue(messageQueueName, 'api', `*.${this.reference.referenceType}.#`, { durable: true });
36
37
  }
37
38
  }
38
39
 
39
40
  Object.defineProperty(SignalEventDefinition.prototype, 'executionId', {
41
+ /** @returns {string} */
40
42
  get() {
41
- return this[kExecuteMessage]?.content.executionId;
43
+ return this[K_EXECUTE_MESSAGE]?.content.executionId;
42
44
  },
43
45
  });
44
46
 
47
+ /**
48
+ * @param {import('#types').ElementBrokerMessage} executeMessage
49
+ */
45
50
  SignalEventDefinition.prototype.execute = function execute(executeMessage) {
46
51
  return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
47
52
  };
48
53
 
54
+ /**
55
+ * @param {import('#types').ElementBrokerMessage} executeMessage
56
+ */
49
57
  SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
50
- this[kExecuteMessage] = executeMessage;
51
- this[kCompleted] = false;
58
+ this[K_EXECUTE_MESSAGE] = executeMessage;
59
+ this[K_COMPLETED] = false;
52
60
 
53
61
  const executeContent = executeMessage.content;
54
62
  const { executionId, parent } = executeContent;
55
63
  const parentExecutionId = parent?.executionId;
56
64
 
57
- const info = (this[kReferenceInfo] = this._getReferenceInfo(executeMessage));
65
+ const info = (this[K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage));
58
66
  const broker = this.broker;
59
67
 
60
68
  const onCatchMessage = this._onCatchMessage.bind(this);
61
69
  if (this.activity.isStart) {
62
- this[kMessageQ].consume(onCatchMessage, {
70
+ this[K_MESSAGE_Q].consume(onCatchMessage, {
63
71
  noAck: true,
64
72
  consumerTag: `_api-signal-${executionId}`,
65
73
  });
66
- if (this[kCompleted]) return;
74
+ if (this[K_COMPLETED]) return;
67
75
  }
68
76
 
69
77
  const onApiMessage = this._onApiMessage.bind(this);
@@ -91,6 +99,9 @@ SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMess
91
99
  broker.publish('event', 'activity.wait', waitContent);
92
100
  };
93
101
 
102
+ /**
103
+ * @param {import('#types').ElementBrokerMessage} executeMessage
104
+ */
94
105
  SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
95
106
  const executeContent = executeMessage.content;
96
107
  const { executionId, parent } = executeContent;
@@ -113,16 +124,16 @@ SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMess
113
124
  };
114
125
 
115
126
  SignalEventDefinition.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
116
- const info = this[kReferenceInfo];
127
+ const info = this[K_REFERENCE_INFO];
117
128
  if (getPropertyValue(message, 'content.message.id') !== info.message.id) return;
118
- this[kCompleted] = true;
129
+ this[K_COMPLETED] = true;
119
130
  this._stop();
120
131
 
121
132
  const { type, correlationId } = message.properties;
122
133
  this.broker.publish(
123
134
  'event',
124
135
  'activity.consumed',
125
- cloneContent(this[kExecuteMessage].content, {
136
+ cloneContent(this[K_EXECUTE_MESSAGE].content, {
126
137
  message: { ...message.content.message },
127
138
  }),
128
139
  {
@@ -142,9 +153,9 @@ SignalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
142
153
  return this._complete(message.content.message, { correlationId });
143
154
  }
144
155
  case 'discard': {
145
- this[kCompleted] = true;
156
+ this[K_COMPLETED] = true;
146
157
  this._stop();
147
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), { correlationId });
158
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content), { correlationId });
148
159
  }
149
160
  case 'stop': {
150
161
  this._stop();
@@ -154,13 +165,13 @@ SignalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
154
165
  };
155
166
 
156
167
  SignalEventDefinition.prototype._complete = function complete(output, options) {
157
- this[kCompleted] = true;
168
+ this[K_COMPLETED] = true;
158
169
  this._stop();
159
- this._debug(`signaled with ${this[kReferenceInfo].description}`);
170
+ this._debug(`signaled with ${this[K_REFERENCE_INFO].description}`);
160
171
  return this.broker.publish(
161
172
  'execution',
162
173
  'execute.completed',
163
- cloneContent(this[kExecuteMessage].content, {
174
+ cloneContent(this[K_EXECUTE_MESSAGE].content, {
164
175
  output,
165
176
  state: 'signal',
166
177
  }),
@@ -175,11 +186,11 @@ SignalEventDefinition.prototype._stop = function stop() {
175
186
  broker.cancel(`_api-parent-${executionId}`);
176
187
  broker.cancel(`_api-${executionId}`);
177
188
  broker.cancel(`_api-delegated-${executionId}`);
178
- if (this.activity.isStart) this[kMessageQ].purge();
189
+ if (this.activity.isStart) this[K_MESSAGE_Q].purge();
179
190
  };
180
191
 
181
192
  SignalEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
182
- const referenceElement = this[kReferenceElement];
193
+ const referenceElement = this[K_REFERENCE_ELEMENT];
183
194
  if (!referenceElement) {
184
195
  return {
185
196
  message: { ...this.reference },
@@ -1,6 +1,11 @@
1
1
  import { cloneContent, shiftParent } from '../messageHelper.js';
2
2
 
3
- export default function TerminateEventDefinition(activity, eventDefinition) {
3
+ /**
4
+ * Terminate event definition
5
+ * @param {import('#types').Activity} activity
6
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
7
+ */
8
+ export function TerminateEventDefinition(activity, eventDefinition) {
4
9
  const { id, broker, environment } = activity;
5
10
  const { type = 'TerminateEventDefinition' } = eventDefinition;
6
11
 
@@ -11,6 +16,9 @@ export default function TerminateEventDefinition(activity, eventDefinition) {
11
16
  this.logger = environment.Logger(type.toLowerCase());
12
17
  }
13
18
 
19
+ /**
20
+ * @param {import('#types').ElementBrokerMessage} executeMessage
21
+ */
14
22
  TerminateEventDefinition.prototype.execute = function execute(executeMessage) {
15
23
  const executeContent = executeMessage.content;
16
24
 
@@ -1,58 +1,69 @@
1
1
  import { ISOInterval, getDate } from '@0dep/piso';
2
2
  import { cloneContent } from '../messageHelper.js';
3
3
  import { RunError } from '../error/Errors.js';
4
+ import { K_STOPPED } from '../constants.js';
4
5
 
5
- const kStopped = Symbol.for('stopped');
6
- const kTimerContent = Symbol.for('timerContent');
7
- const kTimer = Symbol.for('timer');
6
+ const K_TIMER_CONTENT = Symbol.for('timerContent');
7
+ const K_TIMER = Symbol.for('timer');
8
8
 
9
9
  const timerTypes = new Set(['timeDuration', 'timeDate', 'timeCycle']);
10
10
 
11
- export default function TimerEventDefinition(activity, eventDefinition) {
11
+ /**
12
+ * Timer event definition
13
+ * @param {import('#types').Activity} activity
14
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
15
+ */
16
+ export function TimerEventDefinition(activity, eventDefinition) {
12
17
  const type = (this.type = eventDefinition.type || 'TimerEventDefinition');
13
18
  this.activity = activity;
14
19
  const environment = (this.environment = activity.environment);
15
20
  this.eventDefinition = eventDefinition;
16
21
 
17
22
  const { timeDuration, timeCycle, timeDate } = eventDefinition.behaviour || {};
18
- if (timeDuration) this.timeDuration = timeDuration;
19
- if (timeCycle) this.timeCycle = timeCycle;
20
- if (timeDate) this.timeDate = timeDate;
23
+ if (timeDuration) this.timeDuration = /** @type {string} */ (timeDuration);
24
+ if (timeCycle) this.timeCycle = /** @type {string} */ (timeCycle);
25
+ if (timeDate) this.timeDate = /** @type {string} */ (timeDate);
21
26
 
22
27
  this.broker = activity.broker;
23
28
  this.logger = environment.Logger(type.toLowerCase());
24
29
 
25
- this[kStopped] = false;
26
- this[kTimer] = null;
30
+ this[K_STOPPED] = false;
31
+ this[K_TIMER] = null;
27
32
  }
28
33
 
29
- Object.defineProperties(TimerEventDefinition.prototype, {
30
- executionId: {
31
- get() {
32
- return this[kTimerContent]?.executionId;
33
- },
34
+ Object.defineProperty(TimerEventDefinition.prototype, 'executionId', {
35
+ /** @returns {string} */
36
+ get() {
37
+ return this[K_TIMER_CONTENT]?.executionId;
34
38
  },
35
- stopped: {
36
- get() {
37
- return this[kStopped];
38
- },
39
+ });
40
+
41
+ Object.defineProperty(TimerEventDefinition.prototype, 'stopped', {
42
+ /** @returns {boolean} */
43
+ get() {
44
+ return this[K_STOPPED];
39
45
  },
40
- timer: {
41
- get() {
42
- return this[kTimer];
43
- },
46
+ });
47
+
48
+ Object.defineProperty(TimerEventDefinition.prototype, 'timer', {
49
+ /** @returns {import('#types').Timer | null} */
50
+ get() {
51
+ return this[K_TIMER];
44
52
  },
45
53
  });
46
54
 
55
+ /**
56
+ * @param {import('#types').ElementBrokerMessage} executeMessage
57
+ */
47
58
  TimerEventDefinition.prototype.execute = function execute(executeMessage) {
48
59
  const { routingKey: executeKey, redelivered: isResumed } = executeMessage.fields;
49
- const timer = this[kTimer];
60
+ const timer = this[K_TIMER];
50
61
  if (timer && executeKey === 'execute.timer') {
51
62
  return;
52
63
  }
53
64
 
54
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
55
- this[kStopped] = false;
65
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
66
+ this[K_STOPPED] = false;
56
67
 
57
68
  const content = executeMessage.content;
58
69
  const executionId = content.executionId;
@@ -66,7 +77,7 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
66
77
  throw new RunError(err.message, executeMessage, err);
67
78
  }
68
79
 
69
- const timerContent = (this[kTimerContent] = cloneContent(content, {
80
+ const timerContent = (this[K_TIMER_CONTENT] = cloneContent(content, {
70
81
  ...resolvedTimer,
71
82
  ...(isResumed && { isResumed }),
72
83
  startedAt,
@@ -93,7 +104,7 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
93
104
 
94
105
  const timers = this.environment.timers.register(timerContent);
95
106
  const delay = timerContent.timeout;
96
- this[kTimer] = timers.setTimeout(this._completed.bind(this), delay, {
107
+ this[K_TIMER] = timers.setTimeout(this._completed.bind(this), delay, {
97
108
  id: content.id,
98
109
  type: this.type,
99
110
  executionId,
@@ -103,8 +114,8 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
103
114
  };
104
115
 
105
116
  TimerEventDefinition.prototype.stop = function stopTimer() {
106
- const timer = this[kTimer];
107
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
117
+ const timer = this[K_TIMER];
118
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
108
119
  };
109
120
 
110
121
  TimerEventDefinition.prototype._completed = function completed(completeContent, options) {
@@ -115,7 +126,7 @@ TimerEventDefinition.prototype._completed = function completed(completeContent,
115
126
  const runningTime = stoppedAt.getTime() - this.startedAt.getTime();
116
127
  this._debug(`completed in ${runningTime}ms`);
117
128
 
118
- const timerContent = this[kTimerContent];
129
+ const timerContent = this[K_TIMER_CONTENT];
119
130
  const content = { stoppedAt, runningTime, state: 'timeout', ...completeContent };
120
131
 
121
132
  const broker = this.broker;
@@ -148,7 +159,7 @@ TimerEventDefinition.prototype._onDelegatedApiMessage = function onDelegatedApiM
148
159
  this.broker.publish(
149
160
  'event',
150
161
  'activity.consumed',
151
- cloneContent(this[kTimerContent], {
162
+ cloneContent(this[K_TIMER_CONTENT], {
152
163
  message: {
153
164
  ...content.message,
154
165
  },
@@ -180,22 +191,29 @@ TimerEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
180
191
  case 'discard': {
181
192
  this._stop();
182
193
  this._debug('discarded');
183
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kTimerContent], { state: 'discard' }), {
194
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_TIMER_CONTENT], { state: 'discard' }), {
184
195
  correlationId,
185
196
  });
186
197
  }
187
198
  }
188
199
  };
189
200
 
201
+ /** @private */
190
202
  TimerEventDefinition.prototype._stop = function stop() {
191
- this[kStopped] = true;
192
- const timer = this[kTimer];
193
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
203
+ this[K_STOPPED] = true;
204
+ const timer = this[K_TIMER];
205
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
194
206
  const broker = this.broker;
195
207
  broker.cancel(`_api-${this.executionId}`);
196
208
  broker.cancel(`_api-delegated-${this.executionId}`);
197
209
  };
198
210
 
211
+ /**
212
+ * Parse timer
213
+ * @param {import('#types').TimerType} timerType
214
+ * @param {string} value
215
+ * @returns {import('#types').parsedTimer}
216
+ */
199
217
  TimerEventDefinition.prototype.parse = function parse(timerType, value) {
200
218
  let repeat, delay, expireAt;
201
219
  const now = new Date();
@@ -1,23 +1,10 @@
1
- import CancelEventDefinition from './CancelEventDefinition.js';
2
- import CompensateEventDefinition from './CompensateEventDefinition.js';
3
- import ConditionalEventDefinition from './ConditionalEventDefinition.js';
4
- import ErrorEventDefinition from './ErrorEventDefinition.js';
5
- import EscalationEventDefinition from './EscalationEventDefinition.js';
6
- import LinkEventDefinition from './LinkEventDefinition.js';
7
- import MessageEventDefinition from './MessageEventDefinition.js';
8
- import SignalEventDefinition from './SignalEventDefinition.js';
9
- import TerminateEventDefinition from './TerminateEventDefinition.js';
10
- import TimerEventDefinition from './TimerEventDefinition.js';
11
-
12
- export {
13
- CancelEventDefinition,
14
- CompensateEventDefinition,
15
- ConditionalEventDefinition,
16
- ErrorEventDefinition,
17
- EscalationEventDefinition,
18
- LinkEventDefinition,
19
- MessageEventDefinition,
20
- SignalEventDefinition,
21
- TerminateEventDefinition,
22
- TimerEventDefinition,
23
- };
1
+ export { CancelEventDefinition } from './CancelEventDefinition.js';
2
+ export { CompensateEventDefinition } from './CompensateEventDefinition.js';
3
+ export { ConditionalEventDefinition } from './ConditionalEventDefinition.js';
4
+ export { ErrorEventDefinition } from './ErrorEventDefinition.js';
5
+ export { EscalationEventDefinition } from './EscalationEventDefinition.js';
6
+ export { LinkEventDefinition } from './LinkEventDefinition.js';
7
+ export { MessageEventDefinition } from './MessageEventDefinition.js';
8
+ export { SignalEventDefinition } from './SignalEventDefinition.js';
9
+ export { TerminateEventDefinition } from './TerminateEventDefinition.js';
10
+ export { TimerEventDefinition } from './TimerEventDefinition.js';
@@ -1,18 +1,26 @@
1
- import Activity from '../activity/Activity.js';
2
- import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution.js';
1
+ import { Activity } from '../activity/Activity.js';
2
+ import { EventDefinitionExecution } from '../eventDefinitions/EventDefinitionExecution.js';
3
3
  import { cloneContent, cloneMessage } from '../messageHelper.js';
4
4
  import { brokerSafeId } from '../shared.js';
5
-
6
- const kAttachedTags = Symbol.for('attachedConsumers');
7
- const kCompleteContent = Symbol.for('completeContent');
8
- const kExecuteMessage = Symbol.for('executeMessage');
9
- const kExecution = Symbol.for('execution');
10
- const kShovels = Symbol.for('shovels');
11
-
12
- export default function BoundaryEvent(activityDef, context) {
5
+ import { K_EXECUTE_MESSAGE, K_EXECUTION } from '../constants.js';
6
+
7
+ const K_ATTACHED_TAGS = Symbol.for('attachedConsumers');
8
+ const K_COMPLETE_CONTENT = Symbol.for('completeContent');
9
+ const K_SHOVELS = Symbol.for('shovels');
10
+
11
+ /**
12
+ * Boundary event
13
+ * @param {import('moddle-context-serializer').Activity} activityDef
14
+ * @param {import('#types').ContextInstance} context
15
+ */
16
+ export function BoundaryEvent(activityDef, context) {
13
17
  return new Activity(BoundaryEventBehaviour, activityDef, context);
14
18
  }
15
19
 
20
+ /**
21
+ * Boundary event behaviour
22
+ * @param {import('#types').Activity} activity
23
+ */
16
24
  export function BoundaryEventBehaviour(activity) {
17
25
  this.id = activity.id;
18
26
  this.type = activity.type;
@@ -20,32 +28,35 @@ export function BoundaryEventBehaviour(activity) {
20
28
  this.activity = activity;
21
29
  this.environment = activity.environment;
22
30
  this.broker = activity.broker;
23
- this[kExecution] =
31
+ this[K_EXECUTION] =
24
32
  activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions, 'execute.bound.completed');
25
- this[kShovels] = new Set();
26
- this[kAttachedTags] = new Set();
33
+ this[K_SHOVELS] = new Set();
34
+ this[K_ATTACHED_TAGS] = new Set();
27
35
  }
28
36
 
29
- Object.defineProperties(BoundaryEventBehaviour.prototype, {
30
- executionId: {
31
- get() {
32
- return this[kExecuteMessage]?.content.executionId;
33
- },
37
+ Object.defineProperty(BoundaryEventBehaviour.prototype, 'executionId', {
38
+ get() {
39
+ return this[K_EXECUTE_MESSAGE]?.content.executionId;
34
40
  },
35
- cancelActivity: {
36
- get() {
37
- const behaviour = this.activity.behaviour || {};
38
- return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
39
- },
41
+ });
42
+
43
+ Object.defineProperty(BoundaryEventBehaviour.prototype, 'cancelActivity', {
44
+ get() {
45
+ const behaviour = this.activity.behaviour || {};
46
+ return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
40
47
  },
41
48
  });
42
49
 
50
+ /**
51
+ * @param {import('#types').ElementBrokerMessage} executeMessage
52
+ * @returns {void}
53
+ */
43
54
  BoundaryEventBehaviour.prototype.execute = function execute(executeMessage) {
44
55
  const { isRootScope, executionId } = executeMessage.content;
45
56
 
46
- const eventDefinitionExecution = this[kExecution];
57
+ const eventDefinitionExecution = this[K_EXECUTION];
47
58
  if (isRootScope && executeMessage.content.id === this.id) {
48
- this[kExecuteMessage] = executeMessage;
59
+ this[K_EXECUTE_MESSAGE] = executeMessage;
49
60
 
50
61
  const broker = this.broker;
51
62
  if (executeMessage.fields.routingKey === 'execute.bound.completed') {
@@ -59,7 +70,7 @@ BoundaryEventBehaviour.prototype.execute = function execute(executeMessage) {
59
70
  consumerTag,
60
71
  priority: 300,
61
72
  });
62
- this[kAttachedTags].add(consumerTag);
73
+ this[K_ATTACHED_TAGS].add(consumerTag);
63
74
 
64
75
  broker.subscribeOnce('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
65
76
  consumerTag: `_api-${executionId}`,
@@ -109,9 +120,9 @@ BoundaryEventBehaviour.prototype._onCompleted = function onCompleted(_, { conten
109
120
  );
110
121
  }
111
122
 
112
- this[kCompleteContent] = content;
123
+ this[K_COMPLETE_CONTENT] = content;
113
124
 
114
- const { inbound, executionId } = this[kExecuteMessage].content;
125
+ const { inbound, executionId } = this[K_EXECUTE_MESSAGE].content;
115
126
  const attachedToContent = inbound?.[0];
116
127
  const attachedTo = this.attachedTo;
117
128
 
@@ -121,7 +132,7 @@ BoundaryEventBehaviour.prototype._onCompleted = function onCompleted(_, { conten
121
132
 
122
133
  if (content.isRecovered && !attachedTo.isRunning) {
123
134
  const attachedExecuteTag = `_on-attached-execute-${executionId}`;
124
- this[kAttachedTags].add(attachedExecuteTag);
135
+ this[K_ATTACHED_TAGS].add(attachedExecuteTag);
125
136
  attachedTo.broker.subscribeOnce(
126
137
  'execution',
127
138
  '#',
@@ -139,8 +150,8 @@ BoundaryEventBehaviour.prototype._onAttachedLeave = function onAttachedLeave(_,
139
150
  if (content.id !== this.attachedTo.id) return;
140
151
 
141
152
  this._stop();
142
- const completeContent = this[kCompleteContent];
143
- if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[kExecuteMessage].content);
153
+ const completeContent = this[K_COMPLETE_CONTENT];
154
+ if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[K_EXECUTE_MESSAGE].content);
144
155
  return this.broker.publish('execution', 'execute.completed', cloneContent(completeContent));
145
156
  };
146
157
 
@@ -149,7 +160,7 @@ BoundaryEventBehaviour.prototype._onExpectMessage = function onExpectMessage(_,
149
160
  const attachedTo = this.attachedTo;
150
161
 
151
162
  const errorConsumerTag = `_bound-error-listener-${executionId}`;
152
- this[kAttachedTags].add(errorConsumerTag);
163
+ this[K_ATTACHED_TAGS].add(errorConsumerTag);
153
164
 
154
165
  attachedTo.broker.subscribeTmp(
155
166
  'event',
@@ -171,7 +182,7 @@ BoundaryEventBehaviour.prototype._onExpectMessage = function onExpectMessage(_,
171
182
 
172
183
  BoundaryEventBehaviour.prototype._onDetachMessage = function onDetachMessage(_, message) {
173
184
  const content = message.content;
174
- const { executionId, parent } = this[kExecuteMessage].content;
185
+ const { executionId, parent } = this[K_EXECUTE_MESSAGE].content;
175
186
  const id = this.id,
176
187
  attachedTo = this.attachedTo;
177
188
  this.activity.logger.debug(`<${executionId} (${id})> detach from activity <${attachedTo.id}>`);
@@ -180,7 +191,7 @@ BoundaryEventBehaviour.prototype._onDetachMessage = function onDetachMessage(_,
180
191
  const { executionId: detachId, bindExchange, sourceExchange, sourcePattern } = content;
181
192
 
182
193
  const shovelName = `_detached-${brokerSafeId(id)}_${detachId}`;
183
- this[kShovels].add(shovelName);
194
+ this[K_SHOVELS].add(shovelName);
184
195
 
185
196
  const broker = this.broker;
186
197
  attachedTo.broker.createShovel(
@@ -229,7 +240,7 @@ BoundaryEventBehaviour.prototype._onApiMessage = function onApiMessage(_, messag
229
240
  };
230
241
 
231
242
  BoundaryEventBehaviour.prototype._onRepeatMessage = function onRepeatMessage(_, message) {
232
- const executeMessage = this[kExecuteMessage];
243
+ const executeMessage = this[K_EXECUTE_MESSAGE];
233
244
  const repeat = message.content.repeat;
234
245
  this.broker
235
246
  .getQueue('inbound-q')
@@ -240,10 +251,10 @@ BoundaryEventBehaviour.prototype._stop = function stop(detach) {
240
251
  const attachedTo = this.attachedTo,
241
252
  broker = this.broker,
242
253
  executionId = this.executionId;
243
- for (const tag of this[kAttachedTags]) attachedTo.broker.cancel(tag);
244
- this[kAttachedTags].clear();
245
- for (const shovelName of this[kShovels]) attachedTo.broker.closeShovel(shovelName);
246
- this[kShovels].clear();
254
+ for (const tag of this[K_ATTACHED_TAGS]) attachedTo.broker.cancel(tag);
255
+ this[K_ATTACHED_TAGS].clear();
256
+ for (const shovelName of this[K_SHOVELS]) attachedTo.broker.closeShovel(shovelName);
257
+ this[K_SHOVELS].clear();
247
258
 
248
259
  broker.cancel('_execution-tag');
249
260
  broker.cancel(`_execution-completed-${executionId}`);
@@ -1,22 +1,34 @@
1
- import Activity from '../activity/Activity.js';
2
- import EventDefinitionExecution from '../eventDefinitions/EventDefinitionExecution.js';
1
+ import { Activity } from '../activity/Activity.js';
2
+ import { EventDefinitionExecution } from '../eventDefinitions/EventDefinitionExecution.js';
3
3
  import { cloneContent } from '../messageHelper.js';
4
+ import { K_EXECUTION } from '../constants.js';
4
5
 
5
- const kExecution = Symbol.for('execution');
6
-
7
- export default function EndEvent(activityDef, context) {
6
+ /**
7
+ * End event
8
+ * @param {import('moddle-context-serializer').Activity} activityDef
9
+ * @param {import('#types').ContextInstance} context
10
+ */
11
+ export function EndEvent(activityDef, context) {
8
12
  return new Activity(EndEventBehaviour, { ...activityDef, isThrowing: true }, context);
9
13
  }
10
14
 
15
+ /**
16
+ * End event behaviour
17
+ * @param {import('#types').Activity} activity
18
+ */
11
19
  export function EndEventBehaviour(activity) {
12
20
  this.id = activity.id;
13
21
  this.type = activity.type;
14
22
  this.broker = activity.broker;
15
- this[kExecution] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
23
+ this[K_EXECUTION] = activity.eventDefinitions && new EventDefinitionExecution(activity, activity.eventDefinitions);
16
24
  }
17
25
 
26
+ /**
27
+ * @param {import('#types').ElementBrokerMessage} executeMessage
28
+ * @returns {void}
29
+ */
18
30
  EndEventBehaviour.prototype.execute = function execute(executeMessage) {
19
- const execution = this[kExecution];
31
+ const execution = this[K_EXECUTION];
20
32
  if (execution) {
21
33
  return execution.execute(executeMessage);
22
34
  }