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
@@ -3,16 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = SignalEventDefinition;
7
- var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
6
+ exports.SignalEventDefinition = SignalEventDefinition;
7
+ var _getPropertyValue = require("../getPropertyValue.js");
8
8
  var _shared = require("../shared.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const kCompleted = Symbol.for('completed');
12
- const kMessageQ = Symbol.for('messageQ');
13
- const kExecuteMessage = Symbol.for('executeMessage');
14
- const kReferenceElement = Symbol.for('referenceElement');
15
- const kReferenceInfo = Symbol.for('referenceInfo');
10
+ var _constants = require("../constants.js");
11
+ /**
12
+ * Signal event definition
13
+ * @param {import('#types').Activity} activity
14
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
15
+ */
16
16
  function SignalEventDefinition(activity, eventDefinition) {
17
17
  const {
18
18
  id,
@@ -27,7 +27,9 @@ function SignalEventDefinition(activity, eventDefinition) {
27
27
  } = eventDefinition;
28
28
  this.id = id;
29
29
  this.type = type;
30
- const reference = this.reference = {
30
+
31
+ /** @type {import('#types').EventReference} */
32
+ this.reference = {
31
33
  name: 'anonymous',
32
34
  ...behaviour.signalRef,
33
35
  referenceType: 'signal'
@@ -36,46 +38,55 @@ function SignalEventDefinition(activity, eventDefinition) {
36
38
  this.activity = activity;
37
39
  this.broker = broker;
38
40
  this.logger = environment.Logger(type.toLowerCase());
39
- const referenceElement = this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
41
+ const referenceElement = this[_constants.K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id);
40
42
  if (!isThrowing && isStart) {
41
- this[kCompleted] = false;
43
+ this[_constants.K_COMPLETED] = false;
42
44
  const referenceId = referenceElement ? referenceElement.id : 'anonymous';
43
- const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
44
- this[kMessageQ] = broker.assertQueue(messageQueueName, {
45
+ const messageQueueName = `${this.reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
46
+ this[_constants.K_MESSAGE_Q] = broker.assertQueue(messageQueueName, {
45
47
  autoDelete: false,
46
48
  durable: true
47
49
  });
48
- broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
50
+ broker.bindQueue(messageQueueName, 'api', `*.${this.reference.referenceType}.#`, {
49
51
  durable: true
50
52
  });
51
53
  }
52
54
  }
53
55
  Object.defineProperty(SignalEventDefinition.prototype, 'executionId', {
56
+ /** @returns {string} */
54
57
  get() {
55
- return this[kExecuteMessage]?.content.executionId;
58
+ return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
56
59
  }
57
60
  });
61
+
62
+ /**
63
+ * @param {import('#types').ElementBrokerMessage} executeMessage
64
+ */
58
65
  SignalEventDefinition.prototype.execute = function execute(executeMessage) {
59
66
  return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
60
67
  };
68
+
69
+ /**
70
+ * @param {import('#types').ElementBrokerMessage} executeMessage
71
+ */
61
72
  SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
62
- this[kExecuteMessage] = executeMessage;
63
- this[kCompleted] = false;
73
+ this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
74
+ this[_constants.K_COMPLETED] = false;
64
75
  const executeContent = executeMessage.content;
65
76
  const {
66
77
  executionId,
67
78
  parent
68
79
  } = executeContent;
69
80
  const parentExecutionId = parent?.executionId;
70
- const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
81
+ const info = this[_constants.K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage);
71
82
  const broker = this.broker;
72
83
  const onCatchMessage = this._onCatchMessage.bind(this);
73
84
  if (this.activity.isStart) {
74
- this[kMessageQ].consume(onCatchMessage, {
85
+ this[_constants.K_MESSAGE_Q].consume(onCatchMessage, {
75
86
  noAck: true,
76
87
  consumerTag: `_api-signal-${executionId}`
77
88
  });
78
- if (this[kCompleted]) return;
89
+ if (this[_constants.K_COMPLETED]) return;
79
90
  }
80
91
  const onApiMessage = this._onApiMessage.bind(this);
81
92
  broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
@@ -100,6 +111,10 @@ SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMess
100
111
  waitContent.parent = (0, _messageHelper.shiftParent)(parent);
101
112
  broker.publish('event', 'activity.wait', waitContent);
102
113
  };
114
+
115
+ /**
116
+ * @param {import('#types').ElementBrokerMessage} executeMessage
117
+ */
103
118
  SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
104
119
  const executeContent = executeMessage.content;
105
120
  const {
@@ -125,15 +140,15 @@ SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMess
125
140
  return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
126
141
  };
127
142
  SignalEventDefinition.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
128
- const info = this[kReferenceInfo];
129
- if ((0, _getPropertyValue.default)(message, 'content.message.id') !== info.message.id) return;
130
- this[kCompleted] = true;
143
+ const info = this[_constants.K_REFERENCE_INFO];
144
+ if ((0, _getPropertyValue.getPropertyValue)(message, 'content.message.id') !== info.message.id) return;
145
+ this[_constants.K_COMPLETED] = true;
131
146
  this._stop();
132
147
  const {
133
148
  type,
134
149
  correlationId
135
150
  } = message.properties;
136
- this.broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
151
+ this.broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
137
152
  message: {
138
153
  ...message.content.message
139
154
  }
@@ -157,9 +172,9 @@ SignalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
157
172
  }
158
173
  case 'discard':
159
174
  {
160
- this[kCompleted] = true;
175
+ this[_constants.K_COMPLETED] = true;
161
176
  this._stop();
162
- return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content), {
177
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content), {
163
178
  correlationId
164
179
  });
165
180
  }
@@ -171,10 +186,10 @@ SignalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
171
186
  }
172
187
  };
173
188
  SignalEventDefinition.prototype._complete = function complete(output, options) {
174
- this[kCompleted] = true;
189
+ this[_constants.K_COMPLETED] = true;
175
190
  this._stop();
176
- this._debug(`signaled with ${this[kReferenceInfo].description}`);
177
- return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
191
+ this._debug(`signaled with ${this[_constants.K_REFERENCE_INFO].description}`);
192
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
178
193
  output,
179
194
  state: 'signal'
180
195
  }), options);
@@ -186,10 +201,10 @@ SignalEventDefinition.prototype._stop = function stop() {
186
201
  broker.cancel(`_api-parent-${executionId}`);
187
202
  broker.cancel(`_api-${executionId}`);
188
203
  broker.cancel(`_api-delegated-${executionId}`);
189
- if (this.activity.isStart) this[kMessageQ].purge();
204
+ if (this.activity.isStart) this[_constants.K_MESSAGE_Q].purge();
190
205
  };
191
206
  SignalEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
192
- const referenceElement = this[kReferenceElement];
207
+ const referenceElement = this[_constants.K_REFERENCE_ELEMENT];
193
208
  if (!referenceElement) {
194
209
  return {
195
210
  message: {
@@ -3,8 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = TerminateEventDefinition;
6
+ exports.TerminateEventDefinition = TerminateEventDefinition;
7
7
  var _messageHelper = require("../messageHelper.js");
8
+ /**
9
+ * Terminate event definition
10
+ * @param {import('#types').Activity} activity
11
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
12
+ */
8
13
  function TerminateEventDefinition(activity, eventDefinition) {
9
14
  const {
10
15
  id,
@@ -20,6 +25,10 @@ function TerminateEventDefinition(activity, eventDefinition) {
20
25
  this.broker = broker;
21
26
  this.logger = environment.Logger(type.toLowerCase());
22
27
  }
28
+
29
+ /**
30
+ * @param {import('#types').ElementBrokerMessage} executeMessage
31
+ */
23
32
  TerminateEventDefinition.prototype.execute = function execute(executeMessage) {
24
33
  const executeContent = executeMessage.content;
25
34
  const throwContent = (0, _messageHelper.cloneContent)(executeContent, {
@@ -3,14 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = TimerEventDefinition;
6
+ exports.TimerEventDefinition = TimerEventDefinition;
7
7
  var _piso = require("@0dep/piso");
8
8
  var _messageHelper = require("../messageHelper.js");
9
9
  var _Errors = require("../error/Errors.js");
10
- const kStopped = Symbol.for('stopped');
11
- const kTimerContent = Symbol.for('timerContent');
12
- const kTimer = Symbol.for('timer');
10
+ var _constants = require("../constants.js");
11
+ const K_TIMER_CONTENT = Symbol.for('timerContent');
12
+ const K_TIMER = Symbol.for('timer');
13
13
  const timerTypes = new Set(['timeDuration', 'timeDate', 'timeCycle']);
14
+
15
+ /**
16
+ * Timer event definition
17
+ * @param {import('#types').Activity} activity
18
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
19
+ */
14
20
  function TimerEventDefinition(activity, eventDefinition) {
15
21
  const type = this.type = eventDefinition.type || 'TimerEventDefinition';
16
22
  this.activity = activity;
@@ -21,42 +27,47 @@ function TimerEventDefinition(activity, eventDefinition) {
21
27
  timeCycle,
22
28
  timeDate
23
29
  } = eventDefinition.behaviour || {};
24
- if (timeDuration) this.timeDuration = timeDuration;
25
- if (timeCycle) this.timeCycle = timeCycle;
26
- if (timeDate) this.timeDate = timeDate;
30
+ if (timeDuration) this.timeDuration = /** @type {string} */timeDuration;
31
+ if (timeCycle) this.timeCycle = /** @type {string} */timeCycle;
32
+ if (timeDate) this.timeDate = /** @type {string} */timeDate;
27
33
  this.broker = activity.broker;
28
34
  this.logger = environment.Logger(type.toLowerCase());
29
- this[kStopped] = false;
30
- this[kTimer] = null;
35
+ this[_constants.K_STOPPED] = false;
36
+ this[K_TIMER] = null;
31
37
  }
32
- Object.defineProperties(TimerEventDefinition.prototype, {
33
- executionId: {
34
- get() {
35
- return this[kTimerContent]?.executionId;
36
- }
37
- },
38
- stopped: {
39
- get() {
40
- return this[kStopped];
41
- }
42
- },
43
- timer: {
44
- get() {
45
- return this[kTimer];
46
- }
38
+ Object.defineProperty(TimerEventDefinition.prototype, 'executionId', {
39
+ /** @returns {string} */
40
+ get() {
41
+ return this[K_TIMER_CONTENT]?.executionId;
42
+ }
43
+ });
44
+ Object.defineProperty(TimerEventDefinition.prototype, 'stopped', {
45
+ /** @returns {boolean} */
46
+ get() {
47
+ return this[_constants.K_STOPPED];
47
48
  }
48
49
  });
50
+ Object.defineProperty(TimerEventDefinition.prototype, 'timer', {
51
+ /** @returns {import('#types').Timer | null} */
52
+ get() {
53
+ return this[K_TIMER];
54
+ }
55
+ });
56
+
57
+ /**
58
+ * @param {import('#types').ElementBrokerMessage} executeMessage
59
+ */
49
60
  TimerEventDefinition.prototype.execute = function execute(executeMessage) {
50
61
  const {
51
62
  routingKey: executeKey,
52
63
  redelivered: isResumed
53
64
  } = executeMessage.fields;
54
- const timer = this[kTimer];
65
+ const timer = this[K_TIMER];
55
66
  if (timer && executeKey === 'execute.timer') {
56
67
  return;
57
68
  }
58
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
59
- this[kStopped] = false;
69
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
70
+ this[_constants.K_STOPPED] = false;
60
71
  const content = executeMessage.content;
61
72
  const executionId = content.executionId;
62
73
  const startedAt = this.startedAt = 'startedAt' in content ? new Date(content.startedAt) : new Date();
@@ -67,7 +78,7 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
67
78
  this.logger.error(`<${executionId} (${this.activity.id})> failed to get timeout delay: ${err}`);
68
79
  throw new _Errors.RunError(err.message, executeMessage, err);
69
80
  }
70
- const timerContent = this[kTimerContent] = (0, _messageHelper.cloneContent)(content, {
81
+ const timerContent = this[K_TIMER_CONTENT] = (0, _messageHelper.cloneContent)(content, {
71
82
  ...resolvedTimer,
72
83
  ...(isResumed && {
73
84
  isResumed
@@ -91,7 +102,7 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
91
102
  if (timerContent.timeout <= 0) return this._completed();
92
103
  const timers = this.environment.timers.register(timerContent);
93
104
  const delay = timerContent.timeout;
94
- this[kTimer] = timers.setTimeout(this._completed.bind(this), delay, {
105
+ this[K_TIMER] = timers.setTimeout(this._completed.bind(this), delay, {
95
106
  id: content.id,
96
107
  type: this.type,
97
108
  executionId,
@@ -100,15 +111,15 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
100
111
  this._debug(`set timeout with delay ${delay}`);
101
112
  };
102
113
  TimerEventDefinition.prototype.stop = function stopTimer() {
103
- const timer = this[kTimer];
104
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
114
+ const timer = this[K_TIMER];
115
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
105
116
  };
106
117
  TimerEventDefinition.prototype._completed = function completed(completeContent, options) {
107
118
  this._stop();
108
119
  const stoppedAt = new Date();
109
120
  const runningTime = stoppedAt.getTime() - this.startedAt.getTime();
110
121
  this._debug(`completed in ${runningTime}ms`);
111
- const timerContent = this[kTimerContent];
122
+ const timerContent = this[K_TIMER_CONTENT];
112
123
  const content = {
113
124
  stoppedAt,
114
125
  runningTime,
@@ -144,7 +155,7 @@ TimerEventDefinition.prototype._onDelegatedApiMessage = function onDelegatedApiM
144
155
  type,
145
156
  correlationId
146
157
  } = message.properties;
147
- this.broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(this[kTimerContent], {
158
+ this.broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(this[K_TIMER_CONTENT], {
148
159
  message: {
149
160
  ...content.message
150
161
  }
@@ -181,7 +192,7 @@ TimerEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
181
192
  {
182
193
  this._stop();
183
194
  this._debug('discarded');
184
- return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kTimerContent], {
195
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[K_TIMER_CONTENT], {
185
196
  state: 'discard'
186
197
  }), {
187
198
  correlationId
@@ -189,14 +200,23 @@ TimerEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
189
200
  }
190
201
  }
191
202
  };
203
+
204
+ /** @private */
192
205
  TimerEventDefinition.prototype._stop = function stop() {
193
- this[kStopped] = true;
194
- const timer = this[kTimer];
195
- if (timer) this[kTimer] = this.environment.timers.clearTimeout(timer);
206
+ this[_constants.K_STOPPED] = true;
207
+ const timer = this[K_TIMER];
208
+ if (timer) this[K_TIMER] = this.environment.timers.clearTimeout(timer);
196
209
  const broker = this.broker;
197
210
  broker.cancel(`_api-${this.executionId}`);
198
211
  broker.cancel(`_api-delegated-${this.executionId}`);
199
212
  };
213
+
214
+ /**
215
+ * Parse timer
216
+ * @param {import('#types').TimerType} timerType
217
+ * @param {string} value
218
+ * @returns {import('#types').parsedTimer}
219
+ */
200
220
  TimerEventDefinition.prototype.parse = function parse(timerType, value) {
201
221
  let repeat, delay, expireAt;
202
222
  const now = new Date();
@@ -6,71 +6,70 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "CancelEventDefinition", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _CancelEventDefinition.default;
9
+ return _CancelEventDefinition.CancelEventDefinition;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "CompensateEventDefinition", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _CompensateEventDefinition.default;
15
+ return _CompensateEventDefinition.CompensateEventDefinition;
16
16
  }
17
17
  });
18
18
  Object.defineProperty(exports, "ConditionalEventDefinition", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _ConditionalEventDefinition.default;
21
+ return _ConditionalEventDefinition.ConditionalEventDefinition;
22
22
  }
23
23
  });
24
24
  Object.defineProperty(exports, "ErrorEventDefinition", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _ErrorEventDefinition.default;
27
+ return _ErrorEventDefinition.ErrorEventDefinition;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "EscalationEventDefinition", {
31
31
  enumerable: true,
32
32
  get: function () {
33
- return _EscalationEventDefinition.default;
33
+ return _EscalationEventDefinition.EscalationEventDefinition;
34
34
  }
35
35
  });
36
36
  Object.defineProperty(exports, "LinkEventDefinition", {
37
37
  enumerable: true,
38
38
  get: function () {
39
- return _LinkEventDefinition.default;
39
+ return _LinkEventDefinition.LinkEventDefinition;
40
40
  }
41
41
  });
42
42
  Object.defineProperty(exports, "MessageEventDefinition", {
43
43
  enumerable: true,
44
44
  get: function () {
45
- return _MessageEventDefinition.default;
45
+ return _MessageEventDefinition.MessageEventDefinition;
46
46
  }
47
47
  });
48
48
  Object.defineProperty(exports, "SignalEventDefinition", {
49
49
  enumerable: true,
50
50
  get: function () {
51
- return _SignalEventDefinition.default;
51
+ return _SignalEventDefinition.SignalEventDefinition;
52
52
  }
53
53
  });
54
54
  Object.defineProperty(exports, "TerminateEventDefinition", {
55
55
  enumerable: true,
56
56
  get: function () {
57
- return _TerminateEventDefinition.default;
57
+ return _TerminateEventDefinition.TerminateEventDefinition;
58
58
  }
59
59
  });
60
60
  Object.defineProperty(exports, "TimerEventDefinition", {
61
61
  enumerable: true,
62
62
  get: function () {
63
- return _TimerEventDefinition.default;
63
+ return _TimerEventDefinition.TimerEventDefinition;
64
64
  }
65
65
  });
66
- var _CancelEventDefinition = _interopRequireDefault(require("./CancelEventDefinition.js"));
67
- var _CompensateEventDefinition = _interopRequireDefault(require("./CompensateEventDefinition.js"));
68
- var _ConditionalEventDefinition = _interopRequireDefault(require("./ConditionalEventDefinition.js"));
69
- var _ErrorEventDefinition = _interopRequireDefault(require("./ErrorEventDefinition.js"));
70
- var _EscalationEventDefinition = _interopRequireDefault(require("./EscalationEventDefinition.js"));
71
- var _LinkEventDefinition = _interopRequireDefault(require("./LinkEventDefinition.js"));
72
- var _MessageEventDefinition = _interopRequireDefault(require("./MessageEventDefinition.js"));
73
- var _SignalEventDefinition = _interopRequireDefault(require("./SignalEventDefinition.js"));
74
- var _TerminateEventDefinition = _interopRequireDefault(require("./TerminateEventDefinition.js"));
75
- var _TimerEventDefinition = _interopRequireDefault(require("./TimerEventDefinition.js"));
76
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
66
+ var _CancelEventDefinition = require("./CancelEventDefinition.js");
67
+ var _CompensateEventDefinition = require("./CompensateEventDefinition.js");
68
+ var _ConditionalEventDefinition = require("./ConditionalEventDefinition.js");
69
+ var _ErrorEventDefinition = require("./ErrorEventDefinition.js");
70
+ var _EscalationEventDefinition = require("./EscalationEventDefinition.js");
71
+ var _LinkEventDefinition = require("./LinkEventDefinition.js");
72
+ var _MessageEventDefinition = require("./MessageEventDefinition.js");
73
+ var _SignalEventDefinition = require("./SignalEventDefinition.js");
74
+ var _TerminateEventDefinition = require("./TerminateEventDefinition.js");
75
+ var _TimerEventDefinition = require("./TimerEventDefinition.js");
@@ -3,21 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.BoundaryEvent = BoundaryEvent;
6
7
  exports.BoundaryEventBehaviour = BoundaryEventBehaviour;
7
- exports.default = BoundaryEvent;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
- var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
+ var _EventDefinitionExecution = require("../eventDefinitions/EventDefinitionExecution.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
11
  var _shared = require("../shared.js");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- const kAttachedTags = Symbol.for('attachedConsumers');
14
- const kCompleteContent = Symbol.for('completeContent');
15
- const kExecuteMessage = Symbol.for('executeMessage');
16
- const kExecution = Symbol.for('execution');
17
- const kShovels = Symbol.for('shovels');
12
+ var _constants = require("../constants.js");
13
+ const K_ATTACHED_TAGS = Symbol.for('attachedConsumers');
14
+ const K_COMPLETE_CONTENT = Symbol.for('completeContent');
15
+ const K_SHOVELS = Symbol.for('shovels');
16
+
17
+ /**
18
+ * Boundary event
19
+ * @param {import('moddle-context-serializer').Activity} activityDef
20
+ * @param {import('#types').ContextInstance} context
21
+ */
18
22
  function BoundaryEvent(activityDef, context) {
19
- return new _Activity.default(BoundaryEventBehaviour, activityDef, context);
23
+ return new _Activity.Activity(BoundaryEventBehaviour, activityDef, context);
20
24
  }
25
+
26
+ /**
27
+ * Boundary event behaviour
28
+ * @param {import('#types').Activity} activity
29
+ */
21
30
  function BoundaryEventBehaviour(activity) {
22
31
  this.id = activity.id;
23
32
  this.type = activity.type;
@@ -25,31 +34,34 @@ function BoundaryEventBehaviour(activity) {
25
34
  this.activity = activity;
26
35
  this.environment = activity.environment;
27
36
  this.broker = activity.broker;
28
- this[kExecution] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions, 'execute.bound.completed');
29
- this[kShovels] = new Set();
30
- this[kAttachedTags] = new Set();
37
+ this[_constants.K_EXECUTION] = activity.eventDefinitions && new _EventDefinitionExecution.EventDefinitionExecution(activity, activity.eventDefinitions, 'execute.bound.completed');
38
+ this[K_SHOVELS] = new Set();
39
+ this[K_ATTACHED_TAGS] = new Set();
31
40
  }
32
- Object.defineProperties(BoundaryEventBehaviour.prototype, {
33
- executionId: {
34
- get() {
35
- return this[kExecuteMessage]?.content.executionId;
36
- }
37
- },
38
- cancelActivity: {
39
- get() {
40
- const behaviour = this.activity.behaviour || {};
41
- return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
42
- }
41
+ Object.defineProperty(BoundaryEventBehaviour.prototype, 'executionId', {
42
+ get() {
43
+ return this[_constants.K_EXECUTE_MESSAGE]?.content.executionId;
43
44
  }
44
45
  });
46
+ Object.defineProperty(BoundaryEventBehaviour.prototype, 'cancelActivity', {
47
+ get() {
48
+ const behaviour = this.activity.behaviour || {};
49
+ return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
50
+ }
51
+ });
52
+
53
+ /**
54
+ * @param {import('#types').ElementBrokerMessage} executeMessage
55
+ * @returns {void}
56
+ */
45
57
  BoundaryEventBehaviour.prototype.execute = function execute(executeMessage) {
46
58
  const {
47
59
  isRootScope,
48
60
  executionId
49
61
  } = executeMessage.content;
50
- const eventDefinitionExecution = this[kExecution];
62
+ const eventDefinitionExecution = this[_constants.K_EXECUTION];
51
63
  if (isRootScope && executeMessage.content.id === this.id) {
52
- this[kExecuteMessage] = executeMessage;
64
+ this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
53
65
  const broker = this.broker;
54
66
  if (executeMessage.fields.routingKey === 'execute.bound.completed') {
55
67
  this._stop();
@@ -61,7 +73,7 @@ BoundaryEventBehaviour.prototype.execute = function execute(executeMessage) {
61
73
  consumerTag,
62
74
  priority: 300
63
75
  });
64
- this[kAttachedTags].add(consumerTag);
76
+ this[K_ATTACHED_TAGS].add(consumerTag);
65
77
  broker.subscribeOnce('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
66
78
  consumerTag: `_api-${executionId}`
67
79
  });
@@ -108,17 +120,17 @@ BoundaryEventBehaviour.prototype._onCompleted = function onCompleted(_, {
108
120
  cancelActivity: false
109
121
  }));
110
122
  }
111
- this[kCompleteContent] = content;
123
+ this[K_COMPLETE_CONTENT] = content;
112
124
  const {
113
125
  inbound,
114
126
  executionId
115
- } = this[kExecuteMessage].content;
127
+ } = this[_constants.K_EXECUTE_MESSAGE].content;
116
128
  const attachedToContent = inbound?.[0];
117
129
  const attachedTo = this.attachedTo;
118
130
  this.activity.logger.debug(`<${executionId} (${this.id})> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
119
131
  if (content.isRecovered && !attachedTo.isRunning) {
120
132
  const attachedExecuteTag = `_on-attached-execute-${executionId}`;
121
- this[kAttachedTags].add(attachedExecuteTag);
133
+ this[K_ATTACHED_TAGS].add(attachedExecuteTag);
122
134
  attachedTo.broker.subscribeOnce('execution', '#', () => {
123
135
  attachedTo.getApi({
124
136
  content: attachedToContent
@@ -137,8 +149,8 @@ BoundaryEventBehaviour.prototype._onAttachedLeave = function onAttachedLeave(_,
137
149
  }) {
138
150
  if (content.id !== this.attachedTo.id) return;
139
151
  this._stop();
140
- const completeContent = this[kCompleteContent];
141
- if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[kExecuteMessage].content);
152
+ const completeContent = this[K_COMPLETE_CONTENT];
153
+ if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[_constants.K_EXECUTE_MESSAGE].content);
142
154
  return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(completeContent));
143
155
  };
144
156
  BoundaryEventBehaviour.prototype._onExpectMessage = function onExpectMessage(_, {
@@ -152,7 +164,7 @@ BoundaryEventBehaviour.prototype._onExpectMessage = function onExpectMessage(_,
152
164
  } = content;
153
165
  const attachedTo = this.attachedTo;
154
166
  const errorConsumerTag = `_bound-error-listener-${executionId}`;
155
- this[kAttachedTags].add(errorConsumerTag);
167
+ this[K_ATTACHED_TAGS].add(errorConsumerTag);
156
168
  attachedTo.broker.subscribeTmp('event', pattern, (__, message) => {
157
169
  if (message.content.id !== attachedTo.id) return;
158
170
  this.broker.publish(exchange, expectRoutingKey, (0, _messageHelper.cloneContent)(message.content, {
@@ -172,7 +184,7 @@ BoundaryEventBehaviour.prototype._onDetachMessage = function onDetachMessage(_,
172
184
  const {
173
185
  executionId,
174
186
  parent
175
- } = this[kExecuteMessage].content;
187
+ } = this[_constants.K_EXECUTE_MESSAGE].content;
176
188
  const id = this.id,
177
189
  attachedTo = this.attachedTo;
178
190
  this.activity.logger.debug(`<${executionId} (${id})> detach from activity <${attachedTo.id}>`);
@@ -184,7 +196,7 @@ BoundaryEventBehaviour.prototype._onDetachMessage = function onDetachMessage(_,
184
196
  sourcePattern
185
197
  } = content;
186
198
  const shovelName = `_detached-${(0, _shared.brokerSafeId)(id)}_${detachId}`;
187
- this[kShovels].add(shovelName);
199
+ this[K_SHOVELS].add(shovelName);
188
200
  const broker = this.broker;
189
201
  attachedTo.broker.createShovel(shovelName, {
190
202
  exchange: sourceExchange,
@@ -219,7 +231,7 @@ BoundaryEventBehaviour.prototype._onApiMessage = function onApiMessage(_, messag
219
231
  }
220
232
  };
221
233
  BoundaryEventBehaviour.prototype._onRepeatMessage = function onRepeatMessage(_, message) {
222
- const executeMessage = this[kExecuteMessage];
234
+ const executeMessage = this[_constants.K_EXECUTE_MESSAGE];
223
235
  const repeat = message.content.repeat;
224
236
  this.broker.getQueue('inbound-q').queueMessage({
225
237
  routingKey: 'activity.restart'
@@ -231,10 +243,10 @@ BoundaryEventBehaviour.prototype._stop = function stop(detach) {
231
243
  const attachedTo = this.attachedTo,
232
244
  broker = this.broker,
233
245
  executionId = this.executionId;
234
- for (const tag of this[kAttachedTags]) attachedTo.broker.cancel(tag);
235
- this[kAttachedTags].clear();
236
- for (const shovelName of this[kShovels]) attachedTo.broker.closeShovel(shovelName);
237
- this[kShovels].clear();
246
+ for (const tag of this[K_ATTACHED_TAGS]) attachedTo.broker.cancel(tag);
247
+ this[K_ATTACHED_TAGS].clear();
248
+ for (const shovelName of this[K_SHOVELS]) attachedTo.broker.closeShovel(shovelName);
249
+ this[K_SHOVELS].clear();
238
250
  broker.cancel('_execution-tag');
239
251
  broker.cancel(`_execution-completed-${executionId}`);
240
252
  if (detach) return;