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,21 +1,39 @@
1
1
  import { cloneMessage } from '../messageHelper.js';
2
2
 
3
3
  export class ActivityError extends Error {
4
+ /**
5
+ * @param {string} description
6
+ * @param {import('#types').ElementBrokerMessage} [sourceMessage]
7
+ * @param {Error | { name?: string; code?: string | number }} [inner]
8
+ */
4
9
  constructor(description, sourceMessage, inner) {
5
10
  super(description);
11
+ /** @type {string} */
6
12
  this.type = 'ActivityError';
13
+ /** @type {string} */
7
14
  this.name = this.constructor.name;
15
+ /** @type {string} */
8
16
  this.description = description;
9
- if (sourceMessage) this.source = cloneMessage(sourceMessage, sourceMessage.content?.error && { error: undefined });
17
+ if (sourceMessage) {
18
+ /** @type {Pick<import('#types').ElementBrokerMessage, 'fields' | 'content' | 'properties'> | undefined} */
19
+ this.source = cloneMessage(sourceMessage, sourceMessage.content?.error && { error: undefined });
20
+ }
10
21
  if (inner) {
22
+ /** @type {Error | { name?: string; code?: string | number } | undefined} */
11
23
  this.inner = inner;
12
24
  if (inner.name) this.name = inner.name;
13
- if (inner.code) this.code = inner.code;
25
+ if ('code' in inner && inner.code) {
26
+ /** @type {string | number | undefined} */
27
+ this.code = inner.code;
28
+ }
14
29
  }
15
30
  }
16
31
  }
17
32
 
18
33
  export class RunError extends ActivityError {
34
+ /**
35
+ * @param {ConstructorParameters<typeof ActivityError>} args
36
+ */
19
37
  constructor(...args) {
20
38
  super(...args);
21
39
  this.type = 'RunError';
@@ -23,18 +41,35 @@ export class RunError extends ActivityError {
23
41
  }
24
42
 
25
43
  export class BpmnError extends Error {
26
- constructor(description, behaviour, sourceMessage, inner) {
44
+ /**
45
+ * @param {string} description
46
+ * @param {{ id?: string; name?: string; errorCode?: string | number; code?: string }} [behaviour]
47
+ * @param {import('#types').ElementBrokerMessage} [sourceMessage]
48
+ */
49
+ constructor(description, behaviour, sourceMessage) {
27
50
  super(description);
51
+ /** @type {string} */
28
52
  this.type = 'BpmnError';
53
+ /** @type {string} */
29
54
  this.name = behaviour?.name ?? this.constructor.name;
55
+ /** @type {string} */
30
56
  this.description = description;
57
+ /** @type {string | undefined} */
31
58
  this.code = behaviour?.errorCode?.toString() ?? behaviour?.code;
59
+ /** @type {string | undefined} */
32
60
  this.id = behaviour?.id;
33
- if (sourceMessage) this.source = cloneMessage(sourceMessage, sourceMessage.content?.error && { error: undefined });
34
- if (inner) this.inner = inner;
61
+ if (sourceMessage) {
62
+ /** @type {Pick<import('#types').ElementBrokerMessage, 'fields' | 'content' | 'properties'> | undefined} */
63
+ this.source = cloneMessage(sourceMessage, sourceMessage.content?.error && { error: undefined });
64
+ }
35
65
  }
36
66
  }
37
67
 
68
+ /**
69
+ * Get an Error from an error message.
70
+ * @param {import('#types').ElementBrokerMessage} errorMessage
71
+ * @returns {Error | ActivityError | RunError | BpmnError}
72
+ */
38
73
  export function makeErrorFromMessage(errorMessage) {
39
74
  const { content } = errorMessage;
40
75
 
@@ -65,6 +100,10 @@ export function makeErrorFromMessage(errorMessage) {
65
100
  return error;
66
101
  }
67
102
 
103
+ /**
104
+ * @param {any} test
105
+ * @returns {Error | undefined}
106
+ */
68
107
  function isKnownError(test) {
69
108
  if (test instanceof ActivityError) return test;
70
109
  if (test instanceof BpmnError) return test;
@@ -1,14 +1,18 @@
1
1
  import { cloneContent, shiftParent } from '../messageHelper.js';
2
-
3
- const kCompleted = Symbol.for('completed');
4
- const kExecuteMessage = Symbol.for('executeMessage');
5
-
6
- export default function CancelEventDefinition(activity, eventDefinition) {
2
+ import { K_COMPLETED, K_EXECUTE_MESSAGE } from '../constants.js';
3
+
4
+ /**
5
+ * Cancel event definition
6
+ * @param {import('#types').Activity} activity
7
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
8
+ */
9
+ export function CancelEventDefinition(activity, eventDefinition) {
7
10
  const { id, broker, environment, isThrowing } = activity;
8
11
  const type = eventDefinition.type;
9
12
 
10
13
  this.id = id;
11
14
  this.type = type;
15
+ /** @type {import('#types').EventReference} */
12
16
  this.reference = { referenceType: 'cancel' };
13
17
  this.isThrowing = isThrowing;
14
18
  this.activity = activity;
@@ -18,18 +22,25 @@ export default function CancelEventDefinition(activity, eventDefinition) {
18
22
  }
19
23
 
20
24
  Object.defineProperty(CancelEventDefinition.prototype, 'executionId', {
25
+ /** @returns {string} */
21
26
  get() {
22
- return this[kExecuteMessage]?.content.executionId;
27
+ return this[K_EXECUTE_MESSAGE]?.content.executionId;
23
28
  },
24
29
  });
25
30
 
31
+ /**
32
+ * @param {import('#types').ElementBrokerMessage} executeMessage
33
+ */
26
34
  CancelEventDefinition.prototype.execute = function execute(executeMessage) {
27
35
  return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
28
36
  };
29
37
 
38
+ /**
39
+ * @param {import('#types').ElementBrokerMessage} executeMessage
40
+ */
30
41
  CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
31
- this[kExecuteMessage] = executeMessage;
32
- this[kCompleted] = false;
42
+ this[K_EXECUTE_MESSAGE] = executeMessage;
43
+ this[K_COMPLETED] = false;
33
44
 
34
45
  const executeContent = executeMessage.content;
35
46
  const { executionId, parent } = executeContent;
@@ -69,6 +80,9 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
69
80
  broker.publish('event', 'activity.wait', waitContent);
70
81
  };
71
82
 
83
+ /**
84
+ * @param {import('#types').ElementBrokerMessage} executeMessage
85
+ */
72
86
  CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
73
87
  const executeContent = executeMessage.content;
74
88
  const { executionId, parent } = executeContent;
@@ -84,7 +98,7 @@ CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMess
84
98
 
85
99
  broker.publish('event', 'activity.cancel', cancelContent, { type: 'cancel' });
86
100
 
87
- return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
101
+ broker.publish('execution', 'execute.completed', cloneContent(executeContent));
88
102
  };
89
103
 
90
104
  CancelEventDefinition.prototype._onCatchMessage = function onCatchMessage(_, message) {
@@ -94,10 +108,10 @@ CancelEventDefinition.prototype._onCatchMessage = function onCatchMessage(_, mes
94
108
  };
95
109
 
96
110
  CancelEventDefinition.prototype._complete = function complete(output) {
97
- this[kCompleted] = true;
111
+ this[K_COMPLETED] = true;
98
112
  this._stop();
99
113
  this._debug('completed');
100
- const content = cloneContent(this[kExecuteMessage].content, {
114
+ const content = cloneContent(this[K_EXECUTE_MESSAGE].content, {
101
115
  output,
102
116
  state: 'cancel',
103
117
  });
@@ -107,9 +121,9 @@ CancelEventDefinition.prototype._complete = function complete(output) {
107
121
  CancelEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
108
122
  switch (message.properties.type) {
109
123
  case 'discard': {
110
- this[kCompleted] = true;
124
+ this[K_COMPLETED] = true;
111
125
  this._stop();
112
- const content = cloneContent(this[kExecuteMessage].content);
126
+ const content = cloneContent(this[K_EXECUTE_MESSAGE].content);
113
127
  return this.broker.publish('execution', 'execute.discard', content);
114
128
  }
115
129
  case 'stop': {
@@ -1,49 +1,62 @@
1
1
  import { brokerSafeId } from '../shared.js';
2
2
  import { cloneContent, cloneMessage, shiftParent } from '../messageHelper.js';
3
-
4
- const kCompleted = Symbol.for('completed');
5
- const kExecuteMessage = Symbol.for('executeMessage');
6
- const kMessageQ = Symbol.for('messageQ');
7
- const kCompensateQ = Symbol.for('compensateQ');
8
- const kAssociations = Symbol.for('associations');
9
-
10
- export default function CompensateEventDefinition(activity, eventDefinition, context) {
3
+ import { K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_Q } from '../constants.js';
4
+
5
+ const K_COMPENSATE_Q = Symbol.for('compensateQ');
6
+ const K_ASSOCIATIONS = Symbol.for('associations');
7
+
8
+ /**
9
+ * Compensate event definition
10
+ * @param {import('#types').Activity} activity
11
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
12
+ * @param {import('#types').ContextInstance} context
13
+ */
14
+ export function CompensateEventDefinition(activity, eventDefinition, context) {
11
15
  const { id, broker, environment, isThrowing } = activity;
12
16
 
13
17
  this.id = id;
14
18
  const type = (this.type = eventDefinition.type);
15
- const reference = (this.reference = { referenceType: 'compensate' });
19
+ const referenceType = 'compensate';
20
+ /** @type {import('#types').EventReference} */
21
+ this.reference = { referenceType };
16
22
  this.isThrowing = isThrowing;
17
23
  this.activity = activity;
18
24
  this.broker = broker;
19
25
  this.logger = environment.Logger(type.toLowerCase());
20
26
 
21
27
  if (!isThrowing) {
22
- this[kCompleted] = false;
23
- this[kAssociations] = context.getOutboundAssociations(id);
24
- const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
25
- this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
26
- this[kCompensateQ] = broker.assertQueue('compensate-q', { autoDelete: false, durable: true });
27
- broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true, priority: 400 });
28
+ this[K_COMPLETED] = false;
29
+ this[K_ASSOCIATIONS] = context.getOutboundAssociations(id);
30
+ const messageQueueName = `${referenceType}-${brokerSafeId(id)}-q`;
31
+ this[K_MESSAGE_Q] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
32
+ this[K_COMPENSATE_Q] = broker.assertQueue('compensate-q', { autoDelete: false, durable: true });
33
+ broker.bindQueue(messageQueueName, 'api', `*.${referenceType}.#`, { durable: true, priority: 400 });
28
34
  }
29
35
  }
30
36
 
31
37
  Object.defineProperty(CompensateEventDefinition.prototype, 'executionId', {
38
+ /** @returns {string} */
32
39
  get() {
33
- return this[kExecuteMessage]?.content.executionId;
40
+ return this[K_EXECUTE_MESSAGE]?.content.executionId;
34
41
  },
35
42
  });
36
43
 
44
+ /**
45
+ * @param {import('#types').ElementBrokerMessage} executeMessage
46
+ */
37
47
  CompensateEventDefinition.prototype.execute = function execute(executeMessage) {
38
48
  return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
39
49
  };
40
50
 
51
+ /**
52
+ * @param {import('#types').ElementBrokerMessage} executeMessage
53
+ */
41
54
  CompensateEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
42
- this[kExecuteMessage] = executeMessage;
43
- this[kCompleted] = false;
55
+ this[K_EXECUTE_MESSAGE] = executeMessage;
56
+ this[K_COMPLETED] = false;
44
57
  if (executeMessage.fields.routingKey === 'execute.compensating') {
45
58
  this._debug('resumed at compensating');
46
- this[kCompleted] = true;
59
+ this[K_COMPLETED] = true;
47
60
  return this._compensate();
48
61
  }
49
62
 
@@ -60,12 +73,12 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
60
73
  consumerTag: '_oncollect-messages',
61
74
  });
62
75
 
63
- this[kMessageQ].consume(this._onCompensateApiMessage.bind(this), {
76
+ this[K_MESSAGE_Q].consume(this._onCompensateApiMessage.bind(this), {
64
77
  noAck: true,
65
78
  consumerTag: `_oncompensate-${executionId}`,
66
79
  });
67
80
 
68
- if (this[kCompleted]) return;
81
+ if (this[K_COMPLETED]) return;
69
82
 
70
83
  broker.subscribeTmp('api', `activity.#.${parent.executionId}#`, this._onApiMessage.bind(this), {
71
84
  noAck: true,
@@ -83,6 +96,9 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
83
96
  );
84
97
  };
85
98
 
99
+ /**
100
+ * @param {import('#types').ElementBrokerMessage} executeMessage
101
+ */
86
102
  CompensateEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
87
103
  const executeContent = executeMessage.content;
88
104
  const { parent } = executeContent;
@@ -105,16 +121,16 @@ CompensateEventDefinition.prototype._onCollect = function onCollect(routingKey,
105
121
  switch (routingKey) {
106
122
  case 'execute.error':
107
123
  case 'execute.completed': {
108
- return this[kCompensateQ].queueMessage(message.fields, cloneContent(message.content), message.properties);
124
+ return this[K_COMPENSATE_Q].queueMessage(message.fields, cloneContent(message.content), message.properties);
109
125
  }
110
126
  }
111
127
  };
112
128
 
113
129
  CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompensateApiMessage(routingKey, message) {
114
- this[kCompleted] = true;
130
+ this[K_COMPLETED] = true;
115
131
  const output = message.content.message;
116
132
  const broker = this.broker;
117
- const executeContent = this[kExecuteMessage].content;
133
+ const executeContent = this[K_EXECUTE_MESSAGE].content;
118
134
 
119
135
  this._stopCollect();
120
136
 
@@ -126,7 +142,7 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
126
142
  });
127
143
  catchContent.parent = shiftParent(catchContent.parent);
128
144
 
129
- this[kCompensateQ].queueMessage({ routingKey: 'execute.compensated' }, cloneContent(executeContent));
145
+ this[K_COMPENSATE_Q].queueMessage({ routingKey: 'execute.compensated' }, cloneContent(executeContent));
130
146
 
131
147
  broker.publish('execution', 'execute.compensating', cloneContent(executeContent, { message: { ...output } }));
132
148
  broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
@@ -135,7 +151,7 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
135
151
  };
136
152
 
137
153
  CompensateEventDefinition.prototype._compensate = function compensate() {
138
- return this[kCompensateQ].consume(this._onCollected.bind(this), { noAck: true, consumerTag: '_convey-messages' });
154
+ return this[K_COMPENSATE_Q].consume(this._onCollected.bind(this), { noAck: true, consumerTag: '_convey-messages' });
139
155
  };
140
156
 
141
157
  CompensateEventDefinition.prototype._onCollected = function onCollected(routingKey, message) {
@@ -144,15 +160,15 @@ CompensateEventDefinition.prototype._onCollected = function onCollected(routingK
144
160
  broker.cancel('_convey-messages');
145
161
  return this.broker.publish('execution', 'execute.completed', cloneContent(message.content, { cancelActivity: false }));
146
162
  }
147
- for (const association of this[kAssociations]) association.take(cloneMessage(message));
163
+ for (const association of this[K_ASSOCIATIONS]) association.take(cloneMessage(message));
148
164
  };
149
165
 
150
166
  CompensateEventDefinition.prototype._onDiscardApiMessage = function onDiscardApiMessage(routingKey, message) {
151
- this[kCompleted] = true;
167
+ this[K_COMPLETED] = true;
152
168
  this._stop();
153
- this[kCompensateQ].purge();
154
- for (const association of this[kAssociations]) association.discard(cloneMessage(message));
155
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content));
169
+ this[K_COMPENSATE_Q].purge();
170
+ for (const association of this[K_ASSOCIATIONS]) association.discard(cloneMessage(message));
171
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content));
156
172
  };
157
173
 
158
174
  CompensateEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
@@ -176,7 +192,7 @@ CompensateEventDefinition.prototype._stopCollect = function stopCollect() {
176
192
  broker.cancel(`_api-${executionId}`);
177
193
  broker.cancel(`_oncompensate-${executionId}`);
178
194
  broker.cancel('_oncollect-messages');
179
- this[kMessageQ].purge();
195
+ this[K_MESSAGE_Q].purge();
180
196
  };
181
197
 
182
198
  CompensateEventDefinition.prototype._stop = function stop() {
@@ -1,10 +1,16 @@
1
1
  import { cloneContent, shiftParent } from '../messageHelper.js';
2
2
  import { ActivityError } from '../error/Errors.js';
3
3
  import { ScriptCondition, ExpressionCondition } from '../condition.js';
4
+ import { K_EXECUTE_MESSAGE } from '../constants.js';
4
5
 
5
- const kExecuteMessage = Symbol.for('executeMessage');
6
-
7
- export default function ConditionalEventDefinition(activity, eventDefinition, _context, index) {
6
+ /**
7
+ * Conditional event definition
8
+ * @param {import('#types').Activity} activity
9
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
10
+ * @param {import('#types').ContextInstance} _context
11
+ * @param {number} index event definition index
12
+ */
13
+ export function ConditionalEventDefinition(activity, eventDefinition, _context, index) {
8
14
  const { id, broker, environment } = activity;
9
15
 
10
16
  const { type = 'ConditionalEventDefinition', behaviour = {} } = eventDefinition;
@@ -19,13 +25,17 @@ export default function ConditionalEventDefinition(activity, eventDefinition, _c
19
25
  }
20
26
 
21
27
  Object.defineProperty(ConditionalEventDefinition.prototype, 'executionId', {
28
+ /** @returns {string} */
22
29
  get() {
23
- return this[kExecuteMessage]?.content.executionId;
30
+ return this[K_EXECUTE_MESSAGE]?.content.executionId;
24
31
  },
25
32
  });
26
33
 
34
+ /**
35
+ * @param {import('#types').ElementBrokerMessage} executeMessage
36
+ */
27
37
  ConditionalEventDefinition.prototype.execute = function execute(executeMessage) {
28
- this[kExecuteMessage] = executeMessage;
38
+ this[K_EXECUTE_MESSAGE] = executeMessage;
29
39
 
30
40
  if (!this.condition) return this._setup(executeMessage);
31
41
 
@@ -68,7 +78,7 @@ ConditionalEventDefinition.prototype._setup = function setup(executeMessage) {
68
78
 
69
79
  /**
70
80
  * Evaluate condition
71
- * @param {import('types').ElementBrokerMessage} message
81
+ * @param {import('#types').ElementBrokerMessage} message
72
82
  * @param {CallableFunction} callback
73
83
  */
74
84
  ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callback) {
@@ -88,7 +98,7 @@ ConditionalEventDefinition.prototype.evaluate = function evaluate(message, callb
88
98
  */
89
99
  ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallback(err, result) {
90
100
  const broker = this.broker;
91
- const executeMessage = this[kExecuteMessage];
101
+ const executeMessage = this[K_EXECUTE_MESSAGE];
92
102
  const executeContent = executeMessage.content;
93
103
 
94
104
  if (err) {
@@ -104,7 +114,7 @@ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallbac
104
114
  this.broker.publish(
105
115
  'event',
106
116
  'activity.condition',
107
- cloneContent(this[kExecuteMessage].content, {
117
+ cloneContent(this[K_EXECUTE_MESSAGE].content, {
108
118
  conditionResult: result,
109
119
  })
110
120
  );
@@ -118,7 +128,7 @@ ConditionalEventDefinition.prototype.evaluateCallback = function evaluateCallbac
118
128
  /**
119
129
  * Get condition
120
130
  * @param {number} index Eventdefinition sequence number, used to name registered script
121
- * @returns {ExpressionCondition|ScriptCondition|null}
131
+ * @returns {import('#types').ICondition | null}
122
132
  */
123
133
  ConditionalEventDefinition.prototype.getCondition = function getCondition(index) {
124
134
  const behaviour = this.behaviour;
@@ -164,7 +174,7 @@ ConditionalEventDefinition.prototype._onApiMessage = function onApiMessage(routi
164
174
  case 'discard': {
165
175
  this._stop();
166
176
  this._debug('discarded');
167
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content, { state: 'discard' }));
177
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content, { state: 'discard' }));
168
178
  }
169
179
  case 'stop': {
170
180
  this._stop();
@@ -1,24 +1,25 @@
1
1
  import { brokerSafeId } from '../shared.js';
2
2
  import { cloneContent, shiftParent } from '../messageHelper.js';
3
-
4
- const kCompleted = Symbol.for('completed');
5
- const kMessageQ = Symbol.for('messageQ');
6
- const kExecuteMessage = Symbol.for('executeMessage');
7
- const kReferenceElement = Symbol.for('referenceElement');
8
- const kReferenceInfo = Symbol.for('referenceInfo');
9
-
10
- export default function ErrorEventDefinition(activity, eventDefinition) {
3
+ import { K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_Q, K_REFERENCE_ELEMENT, K_REFERENCE_INFO } from '../constants.js';
4
+
5
+ /**
6
+ * Error event definition
7
+ * @param {import('#types').Activity} activity
8
+ * @param {import('moddle-context-serializer').EventDefinition} eventDefinition
9
+ */
10
+ export function ErrorEventDefinition(activity, eventDefinition) {
11
11
  const { id, broker, environment, isThrowing } = activity;
12
12
  const { type = 'ErrorEventDefinition', behaviour = {} } = eventDefinition;
13
13
 
14
14
  this.id = id;
15
15
  this.type = type;
16
16
 
17
- const reference = (this.reference = {
17
+ /** @type {import('#types').EventReference} */
18
+ this.reference = {
18
19
  name: 'anonymous',
19
20
  ...behaviour.errorRef,
20
21
  referenceType: 'throw',
21
- });
22
+ };
22
23
 
23
24
  this.isThrowing = isThrowing;
24
25
  this.activity = activity;
@@ -26,42 +27,49 @@ export default function ErrorEventDefinition(activity, eventDefinition) {
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) {
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, priority: 300 });
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, priority: 300 });
36
37
  }
37
38
  }
38
39
 
39
40
  Object.defineProperty(ErrorEventDefinition.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
  ErrorEventDefinition.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
  ErrorEventDefinition.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
 
59
- this[kMessageQ].consume(this._onThrowApiMessage.bind(this), {
67
+ this[K_MESSAGE_Q].consume(this._onThrowApiMessage.bind(this), {
60
68
  noAck: true,
61
69
  consumerTag: `_onthrow-${executionId}`,
62
70
  });
63
71
 
64
- if (this[kCompleted]) return;
72
+ if (this[K_COMPLETED]) return;
65
73
 
66
74
  this._debug(`expect ${info.description}`);
67
75
 
@@ -88,7 +96,7 @@ ErrorEventDefinition.prototype.executeCatch = function executeCatch(executeMessa
88
96
  })
89
97
  );
90
98
 
91
- if (this[kCompleted]) return this._stop();
99
+ if (this[K_COMPLETED]) return this._stop();
92
100
  }
93
101
 
94
102
  const waitContent = cloneContent(executeContent, {
@@ -100,6 +108,9 @@ ErrorEventDefinition.prototype.executeCatch = function executeCatch(executeMessa
100
108
  broker.publish('event', 'activity.wait', waitContent);
101
109
  };
102
110
 
111
+ /**
112
+ * @param {import('#types').ElementBrokerMessage} executeMessage
113
+ */
103
114
  ErrorEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
104
115
  const executeContent = executeMessage.content;
105
116
  const { executionId, parent } = executeContent;
@@ -129,11 +140,11 @@ ErrorEventDefinition.prototype.executeThrow = function executeThrow(executeMessa
129
140
 
130
141
  ErrorEventDefinition.prototype._onErrorMessage = function onErrorMessage(routingKey, message) {
131
142
  const error = message.content.error;
132
- if (!this[kReferenceElement]) return this._catchError(routingKey, message, error);
143
+ if (!this[K_REFERENCE_ELEMENT]) return this._catchError(routingKey, message, error);
133
144
 
134
145
  if (!error) return;
135
146
 
136
- const info = this[kReferenceInfo];
147
+ const info = this[K_REFERENCE_INFO];
137
148
  if ('' + error.code !== '' + info.message.code) return;
138
149
 
139
150
  return this._catchError(routingKey, message, error);
@@ -141,21 +152,21 @@ ErrorEventDefinition.prototype._onErrorMessage = function onErrorMessage(routing
141
152
 
142
153
  ErrorEventDefinition.prototype._onThrowApiMessage = function onThrowApiMessage(routingKey, message) {
143
154
  const error = message.content.message;
144
- if (!this[kReferenceElement]) return this._catchError(routingKey, message, error);
155
+ if (!this[K_REFERENCE_ELEMENT]) return this._catchError(routingKey, message, error);
145
156
 
146
- const info = this[kReferenceInfo];
157
+ const info = this[K_REFERENCE_INFO];
147
158
  if (info.message.id !== error?.id) return;
148
159
  return this._catchError(routingKey, message, error);
149
160
  };
150
161
 
151
162
  ErrorEventDefinition.prototype._catchError = function catchError(routingKey, message, error) {
152
- this[kCompleted] = true;
163
+ this[K_COMPLETED] = true;
153
164
 
154
165
  this._stop();
155
166
 
156
- this._debug(`caught ${this[kReferenceInfo].description}`);
167
+ this._debug(`caught ${this[K_REFERENCE_INFO].description}`);
157
168
 
158
- const executeContent = this[kExecuteMessage].content;
169
+ const executeContent = this[K_EXECUTE_MESSAGE].content;
159
170
  const parent = executeContent.parent;
160
171
  const catchContent = cloneContent(executeContent, {
161
172
  source: {
@@ -187,9 +198,9 @@ ErrorEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
187
198
 
188
199
  switch (messageType) {
189
200
  case 'discard': {
190
- this[kCompleted] = true;
201
+ this[K_COMPLETED] = true;
191
202
  this._stop();
192
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content));
203
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content));
193
204
  }
194
205
  case 'stop': {
195
206
  this._stop();
@@ -204,11 +215,11 @@ ErrorEventDefinition.prototype._stop = function stop() {
204
215
  broker.cancel(`_onthrow-${executionId}`);
205
216
  broker.cancel(`_onerror-${executionId}`);
206
217
  broker.cancel(`_api-${executionId}`);
207
- this[kMessageQ].purge();
218
+ this[K_MESSAGE_Q].purge();
208
219
  };
209
220
 
210
221
  ErrorEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
211
- const referenceElement = this[kReferenceElement];
222
+ const referenceElement = this[K_REFERENCE_ELEMENT];
212
223
  if (!referenceElement) {
213
224
  return {
214
225
  message: { ...this.reference },