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