bpmn-elements 6.0.1 → 8.0.1

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 (116) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +52 -44
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +176 -172
  6. package/dist/src/Environment.js +110 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/activity/Activity.js +1105 -916
  12. package/dist/src/activity/ActivityExecution.js +342 -297
  13. package/dist/src/activity/Dummy.js +3 -3
  14. package/dist/src/definition/Definition.js +498 -444
  15. package/dist/src/definition/DefinitionExecution.js +710 -408
  16. package/dist/src/error/Errors.js +17 -7
  17. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  18. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  19. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  20. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  21. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  22. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  23. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  24. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  25. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  26. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  27. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  28. package/dist/src/events/BoundaryEvent.js +180 -144
  29. package/dist/src/events/EndEvent.js +18 -23
  30. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  31. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  32. package/dist/src/events/StartEvent.js +109 -94
  33. package/dist/src/flows/Association.js +94 -100
  34. package/dist/src/flows/MessageFlow.js +86 -103
  35. package/dist/src/flows/SequenceFlow.js +173 -182
  36. package/dist/src/gateways/EventBasedGateway.js +88 -84
  37. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  38. package/dist/src/gateways/InclusiveGateway.js +11 -14
  39. package/dist/src/gateways/ParallelGateway.js +11 -14
  40. package/dist/src/getPropertyValue.js +34 -34
  41. package/dist/src/io/BpmnIO.js +17 -14
  42. package/dist/src/io/EnvironmentDataObject.js +33 -29
  43. package/dist/src/io/EnvironmentDataStore.js +33 -29
  44. package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
  45. package/dist/src/io/InputOutputSpecification.js +177 -168
  46. package/dist/src/io/Properties.js +117 -124
  47. package/dist/src/messageHelper.js +1 -1
  48. package/dist/src/process/Process.js +439 -362
  49. package/dist/src/process/ProcessExecution.js +748 -646
  50. package/dist/src/shared.js +2 -2
  51. package/dist/src/tasks/CallActivity.js +160 -0
  52. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  53. package/dist/src/tasks/ReceiveTask.js +233 -182
  54. package/dist/src/tasks/ScriptTask.js +35 -41
  55. package/dist/src/tasks/ServiceImplementation.js +13 -20
  56. package/dist/src/tasks/ServiceTask.js +82 -75
  57. package/dist/src/tasks/SignalTask.js +97 -93
  58. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  59. package/dist/src/tasks/SubProcess.js +193 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +16 -16
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +145 -140
  65. package/src/Environment.js +116 -100
  66. package/src/EventBroker.js +67 -68
  67. package/src/ExtensionsMapper.js +2 -2
  68. package/src/MessageFormatter.js +132 -74
  69. package/src/activity/Activity.js +914 -776
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +437 -401
  73. package/src/definition/DefinitionExecution.js +598 -340
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
  77. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  78. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  79. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  80. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  81. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  82. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  83. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  84. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  85. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  86. package/src/events/BoundaryEvent.js +156 -115
  87. package/src/events/EndEvent.js +15 -18
  88. package/src/events/IntermediateCatchEvent.js +40 -44
  89. package/src/events/IntermediateThrowEvent.js +15 -18
  90. package/src/events/StartEvent.js +84 -50
  91. package/src/flows/Association.js +98 -112
  92. package/src/flows/MessageFlow.js +81 -97
  93. package/src/flows/SequenceFlow.js +146 -160
  94. package/src/gateways/EventBasedGateway.js +75 -68
  95. package/src/gateways/ExclusiveGateway.js +8 -13
  96. package/src/gateways/InclusiveGateway.js +8 -13
  97. package/src/gateways/ParallelGateway.js +8 -13
  98. package/src/getPropertyValue.js +34 -33
  99. package/src/io/BpmnIO.js +20 -15
  100. package/src/io/EnvironmentDataObject.js +29 -18
  101. package/src/io/EnvironmentDataStore.js +29 -18
  102. package/src/io/EnvironmentDataStoreReference.js +31 -20
  103. package/src/io/InputOutputSpecification.js +154 -157
  104. package/src/io/Properties.js +95 -97
  105. package/src/process/Process.js +378 -333
  106. package/src/process/ProcessExecution.js +603 -553
  107. package/src/tasks/CallActivity.js +130 -0
  108. package/src/tasks/LoopCharacteristics.js +290 -289
  109. package/src/tasks/ReceiveTask.js +174 -107
  110. package/src/tasks/ScriptTask.js +27 -30
  111. package/src/tasks/ServiceImplementation.js +13 -18
  112. package/src/tasks/ServiceTask.js +67 -60
  113. package/src/tasks/SignalTask.js +77 -52
  114. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  115. package/src/tasks/SubProcess.js +184 -157
  116. package/src/tasks/Task.js +15 -19
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = StartEvent;
7
6
  exports.StartEventBehaviour = StartEventBehaviour;
7
+ exports.default = StartEvent;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -14,108 +14,123 @@ var _messageHelper = require("../messageHelper");
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
+ const kExecuteMessage = Symbol.for('executeMessage');
18
+ const kExecution = Symbol.for('execution');
19
+
17
20
  function StartEvent(activityDef, context) {
18
- return (0, _Activity.default)(StartEventBehaviour, activityDef, context);
21
+ return new _Activity.default(StartEventBehaviour, activityDef, context);
19
22
  }
20
23
 
21
24
  function StartEventBehaviour(activity) {
22
- const {
23
- id,
24
- type = 'startevent',
25
- broker,
26
- eventDefinitions
27
- } = activity;
28
- const eventDefinitionExecution = eventDefinitions && (0, _EventDefinitionExecution.default)(activity, eventDefinitions);
29
- const event = {
30
- id,
31
- type,
32
- execute
33
- };
34
- return event;
25
+ this.id = activity.id;
26
+ this.type = activity.type;
27
+ this.activity = activity;
28
+ this.broker = activity.broker;
29
+ this[kExecution] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions);
30
+ }
35
31
 
36
- function execute(executeMessage) {
37
- if (eventDefinitionExecution) {
38
- return eventDefinitionExecution.execute(executeMessage);
39
- }
32
+ const proto = StartEventBehaviour.prototype;
33
+ Object.defineProperty(proto, 'executionId', {
34
+ get() {
35
+ const message = this[kExecuteMessage];
36
+ return message && message.content.executionId;
37
+ }
40
38
 
41
- const content = (0, _messageHelper.cloneContent)(executeMessage.content);
39
+ });
42
40
 
43
- if (!content.form) {
44
- return broker.publish('execution', 'execute.completed', content);
45
- }
41
+ proto.execute = function execute(executeMessage) {
42
+ const execution = this[kExecution];
46
43
 
47
- const {
48
- executionId
49
- } = content;
50
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
51
- noAck: true,
52
- consumerTag: `_api-${executionId}`,
53
- priority: 300
54
- });
55
- broker.subscribeTmp('api', '#.signal.*', onDelegatedApiMessage, {
56
- noAck: true,
57
- consumerTag: `_api-delegated-${executionId}`
58
- });
59
- broker.publish('event', 'activity.wait', { ...content,
60
- executionId,
61
- state: 'wait'
62
- });
63
-
64
- function onDelegatedApiMessage(routingKey, message) {
65
- if (!message.properties.delegate) return;
66
- const {
67
- content: delegateContent
68
- } = message;
69
- if (!delegateContent || !delegateContent.message) return;
70
- const {
71
- id: signalId,
72
- executionId: signalExecutionId
73
- } = delegateContent.message;
74
- if (signalId !== id && signalExecutionId !== executionId) return;
75
- const {
76
- type: messageType,
77
- correlationId
78
- } = message.properties;
79
- broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(content, {
80
- message: { ...delegateContent.message
81
- }
82
- }), {
83
- correlationId,
84
- type: messageType
85
- });
86
- return onApiMessage(routingKey, message);
87
- }
44
+ if (execution) {
45
+ return execution.execute(executeMessage);
46
+ }
47
+
48
+ const content = (0, _messageHelper.cloneContent)(executeMessage.content);
49
+ const broker = this.broker;
88
50
 
89
- function onApiMessage(routingKey, message) {
90
- const {
91
- type: messageType,
92
- correlationId
93
- } = message.properties;
94
-
95
- switch (messageType) {
96
- case 'stop':
97
- return stop();
98
-
99
- case 'signal':
100
- stop();
101
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
102
- output: message.content.message,
103
- state: 'signal'
104
- }), {
105
- correlationId
106
- });
107
-
108
- case 'discard':
109
- stop();
110
- return broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(content), {
111
- correlationId
112
- });
51
+ if (!content.form) {
52
+ return broker.publish('execution', 'execute.completed', content);
53
+ }
54
+
55
+ const executionId = content.executionId;
56
+ this[kExecuteMessage] = executeMessage;
57
+ broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(...args), {
58
+ noAck: true,
59
+ consumerTag: `_api-${executionId}`,
60
+ priority: 300
61
+ });
62
+ broker.subscribeTmp('api', '#.signal.*', (...args) => this._onDelegatedApiMessage(...args), {
63
+ noAck: true,
64
+ consumerTag: `_api-delegated-${executionId}`
65
+ });
66
+ broker.publish('event', 'activity.wait', { ...content,
67
+ executionId,
68
+ state: 'wait'
69
+ });
70
+ };
71
+
72
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
73
+ const {
74
+ type: messageType,
75
+ correlationId
76
+ } = message.properties;
77
+
78
+ switch (messageType) {
79
+ case 'stop':
80
+ return this._stop();
81
+
82
+ case 'signal':
83
+ {
84
+ this._stop();
85
+
86
+ const content = this[kExecuteMessage].content;
87
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
88
+ output: message.content.message,
89
+ state: 'signal'
90
+ }), {
91
+ correlationId
92
+ });
113
93
  }
114
- }
115
94
 
116
- function stop() {
117
- broker.cancel(`_api-${executionId}`);
118
- broker.cancel(`_api-delegated-${executionId}`);
119
- }
95
+ case 'discard':
96
+ {
97
+ this._stop();
98
+
99
+ const content = this[kExecuteMessage].content;
100
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(content), {
101
+ correlationId
102
+ });
103
+ }
120
104
  }
121
- }
105
+ };
106
+
107
+ proto._onDelegatedApiMessage = function onDelegatedApiMessage(routingKey, message) {
108
+ if (!message.properties.delegate) return;
109
+ const content = message.content;
110
+ if (!content.message) return;
111
+ const {
112
+ id: signalId,
113
+ executionId: signalExecutionId
114
+ } = content.message;
115
+ if (signalId !== this.id && signalExecutionId !== this.executionId) return;
116
+ const {
117
+ type,
118
+ correlationId
119
+ } = message.properties;
120
+ const executeContent = this[kExecuteMessage].content;
121
+ this.broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(executeContent, {
122
+ message: { ...content.message
123
+ }
124
+ }), {
125
+ correlationId,
126
+ type
127
+ });
128
+ return this._onApiMessage(routingKey, message);
129
+ };
130
+
131
+ proto._stop = function stop() {
132
+ const broker = this.broker,
133
+ executionId = this.executionId;
134
+ broker.cancel(`_api-${executionId}`);
135
+ broker.cancel(`_api-delegated-${executionId}`);
136
+ };
@@ -13,6 +13,8 @@ var _Api = require("../Api");
13
13
 
14
14
  var _shared = require("../shared");
15
15
 
16
+ const kCounters = Symbol.for('counters');
17
+
16
18
  function Association(associationDef, {
17
19
  environment
18
20
  }) {
@@ -20,131 +22,123 @@ function Association(associationDef, {
20
22
  id,
21
23
  type = 'association',
22
24
  name,
23
- parent: originalParent,
25
+ parent,
24
26
  targetId,
25
27
  sourceId,
26
28
  behaviour = {}
27
29
  } = associationDef;
28
- const parent = (0, _messageHelper.cloneParent)(originalParent);
29
- const logger = environment.Logger(type.toLowerCase());
30
- const counters = {
30
+ this.id = id;
31
+ this.type = type;
32
+ this.name = name;
33
+ this.parent = (0, _messageHelper.cloneParent)(parent);
34
+ this.behaviour = behaviour;
35
+ this.sourceId = sourceId;
36
+ this.targetId = targetId;
37
+ this.isAssociation = true;
38
+ this.environment = environment;
39
+ const logger = this.logger = environment.Logger(type.toLowerCase());
40
+ this[kCounters] = {
31
41
  complete: 0,
32
42
  take: 0,
33
43
  discard: 0
34
44
  };
35
- const associationApi = {
36
- id,
37
- type,
38
- name,
39
- parent,
40
- behaviour,
41
- sourceId,
42
- targetId,
43
- isAssociation: true,
44
- environment,
45
-
46
- get counters() {
47
- return { ...counters
48
- };
49
- },
50
-
51
- complete,
52
- discard,
53
- getApi,
54
- getState,
55
- recover,
56
- stop,
57
- take
58
- };
59
45
  const {
60
46
  broker,
61
47
  on,
62
48
  once,
63
49
  waitFor
64
- } = (0, _EventBroker.EventBroker)(associationApi, {
50
+ } = new _EventBroker.EventBroker(this, {
65
51
  prefix: 'association',
66
52
  durable: true,
67
53
  autoDelete: false
68
54
  });
69
- associationApi.on = on;
70
- associationApi.once = once;
71
- associationApi.waitFor = waitFor;
72
- Object.defineProperty(associationApi, 'broker', {
73
- enumerable: true,
74
- get: () => broker
75
- });
55
+ this.broker = broker;
56
+ this.on = on;
57
+ this.once = once;
58
+ this.waitFor = waitFor;
76
59
  logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
77
- return associationApi;
60
+ }
78
61
 
79
- function take(content = {}) {
80
- logger.debug(`<${id}> take target <${targetId}>`);
81
- ++counters.take;
82
- publishEvent('take', content);
83
- return true;
84
- }
62
+ const proto = Association.prototype;
63
+ Object.defineProperty(proto, 'counters', {
64
+ enumerable: true,
85
65
 
86
- function discard(content = {}) {
87
- logger.debug(`<${id}> discard target <${targetId}>`);
88
- ++counters.discard;
89
- publishEvent('discard', content);
90
- return true;
66
+ get() {
67
+ return { ...this[kCounters]
68
+ };
91
69
  }
92
70
 
93
- function complete(content = {}) {
94
- logger.debug(`<${id}> completed target <${targetId}>`);
95
- ++counters.complete;
96
- publishEvent('complete', content);
97
- return true;
98
- }
71
+ });
99
72
 
100
- function publishEvent(action, content) {
101
- const eventContent = createMessageContent({
102
- action,
103
- message: content,
104
- sequenceId: (0, _shared.getUniqueId)(id)
105
- });
106
- broker.publish('event', `association.${action}`, eventContent, {
107
- type: action
108
- });
109
- }
73
+ proto.take = function take(content = {}) {
74
+ this.logger.debug(`<${this.id}> take target <${this.targetId}>`);
75
+ ++this[kCounters].take;
110
76
 
111
- function createMessageContent(override = {}) {
112
- return { ...override,
113
- id,
114
- type,
115
- name,
116
- sourceId,
117
- targetId,
118
- isAssociation: true,
119
- parent: (0, _messageHelper.cloneParent)(parent)
120
- };
121
- }
77
+ this._publishEvent('take', content);
122
78
 
123
- function getState() {
124
- return {
125
- id,
126
- type,
127
- name,
128
- sourceId,
129
- targetId,
130
- counters: { ...counters
131
- },
132
- broker: broker.getState(true)
133
- };
134
- }
79
+ return true;
80
+ };
135
81
 
136
- function recover(state) {
137
- Object.assign(counters, state.counters);
138
- broker.recover(state.broker);
139
- }
82
+ proto.discard = function discard(content = {}) {
83
+ this.logger.debug(`<${this.id}> discard target <${this.targetId}>`);
84
+ ++this[kCounters].discard;
140
85
 
141
- function getApi(message) {
142
- return (0, _Api.FlowApi)(broker, message || {
143
- content: createMessageContent()
144
- });
145
- }
86
+ this._publishEvent('discard', content);
146
87
 
147
- function stop() {
148
- broker.stop();
149
- }
150
- }
88
+ return true;
89
+ };
90
+
91
+ proto.complete = function complete(content = {}) {
92
+ this.logger.debug(`<${this.id}> completed target <${this.targetId}>`);
93
+ ++this[kCounters].complete;
94
+
95
+ this._publishEvent('complete', content);
96
+
97
+ return true;
98
+ };
99
+
100
+ proto.getState = function getState() {
101
+ return this._createMessageContent({
102
+ counters: this.counters,
103
+ broker: this.broker.getState(true)
104
+ });
105
+ };
106
+
107
+ proto.recover = function recover(state) {
108
+ Object.assign(this[kCounters], state.counters);
109
+ this.broker.recover(state.broker);
110
+ };
111
+
112
+ proto.getApi = function getApi(message) {
113
+ return (0, _Api.FlowApi)(this.broker, message || {
114
+ content: this._createMessageContent()
115
+ });
116
+ };
117
+
118
+ proto.stop = function stop() {
119
+ this.broker.stop();
120
+ };
121
+
122
+ proto._publishEvent = function publishEvent(action, content) {
123
+ const eventContent = this._createMessageContent({
124
+ action,
125
+ message: content,
126
+ sequenceId: (0, _shared.getUniqueId)(this.id)
127
+ });
128
+
129
+ this.broker.publish('event', `association.${action}`, eventContent, {
130
+ type: action
131
+ });
132
+ };
133
+
134
+ proto._createMessageContent = function createMessageContent(override) {
135
+ return { ...override,
136
+ id: this.id,
137
+ type: this.type,
138
+ name: this.name,
139
+ sourceId: this.sourceId,
140
+ targetId: this.targetId,
141
+ isAssociation: true,
142
+ parent: (0, _messageHelper.cloneParent)(this.parent)
143
+ };
144
+ };
@@ -11,47 +11,30 @@ var _messageHelper = require("../messageHelper");
11
11
 
12
12
  var _EventBroker = require("../EventBroker");
13
13
 
14
+ const kCounters = Symbol.for('counters');
15
+ const kSourceElement = Symbol.for('sourceElement');
16
+
14
17
  function MessageFlow(flowDef, context) {
15
18
  const {
16
19
  id,
17
- type = 'message',
20
+ type = 'messageflow',
18
21
  name,
19
22
  target,
20
23
  source,
21
24
  behaviour,
22
25
  parent
23
26
  } = flowDef;
24
- const sourceElement = context.getActivityById(source.id) || context.getProcessById(source.processId);
25
- const sourceEndConsumerTag = `_message-on-end-${(0, _shared.brokerSafeId)(id)}`;
26
- const sourceMessageConsumerTag = `_message-on-message-${(0, _shared.brokerSafeId)(id)}`;
27
- const {
28
- debug
29
- } = context.environment.Logger(type.toLowerCase());
30
- if (!sourceElement) return;
31
- const counters = {
32
- messages: 0,
33
- discard: 0
34
- };
35
- const flowApi = {
36
- id,
37
- type,
38
- name,
39
- target,
40
- source,
41
- behaviour,
42
-
43
- get counters() {
44
- return { ...counters
45
- };
46
- },
47
-
48
- activate,
49
- deactivate,
50
- getApi,
51
- getState,
52
- recover,
53
- resume,
54
- stop
27
+ this.id = id;
28
+ this.type = type;
29
+ this.name = name;
30
+ this.parent = (0, _messageHelper.cloneParent)(parent);
31
+ this.source = source;
32
+ this.target = target;
33
+ this.behaviour = behaviour;
34
+ this.environment = context.environment;
35
+ this.context = context;
36
+ this[kCounters] = {
37
+ messages: 0
55
38
  };
56
39
  const {
57
40
  broker,
@@ -59,81 +42,81 @@ function MessageFlow(flowDef, context) {
59
42
  once,
60
43
  emit,
61
44
  waitFor
62
- } = (0, _EventBroker.MessageFlowBroker)(flowApi);
63
- flowApi.on = on;
64
- flowApi.once = once;
65
- flowApi.emit = emit;
66
- flowApi.waitFor = waitFor;
67
- Object.defineProperty(flowApi, 'broker', {
68
- enumerable: true,
69
- get: () => broker
70
- });
71
- return flowApi;
72
-
73
- function onSourceEnd({
74
- content
75
- }) {
76
- ++counters.messages;
77
- debug(`<${id}> sending message from <${source.processId}.${source.id}> to`, target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`);
78
- broker.publish('event', 'message.outbound', createMessage(content.message));
79
- }
80
-
81
- function onSourceMessage() {
82
- deactivate();
83
- }
84
-
85
- function createMessage(message) {
86
- return {
87
- id,
88
- type,
89
- name,
90
- source: { ...source
91
- },
92
- target: { ...target
93
- },
94
- parent: parent && (0, _messageHelper.cloneParent)(parent),
95
- message
45
+ } = (0, _EventBroker.MessageFlowBroker)(this);
46
+ this.broker = broker;
47
+ this.on = on;
48
+ this.once = once;
49
+ this.emit = emit;
50
+ this.waitFor = waitFor;
51
+ this[kSourceElement] = context.getActivityById(source.id) || context.getProcessById(source.processId);
52
+ this.logger = context.environment.Logger(type.toLowerCase());
53
+ }
54
+
55
+ const proto = MessageFlow.prototype;
56
+ Object.defineProperty(proto, 'counters', {
57
+ enumerable: true,
58
+
59
+ get() {
60
+ return { ...this[kCounters]
96
61
  };
97
62
  }
98
63
 
99
- function stop() {
100
- deactivate();
101
- broker.stop();
102
- }
103
-
104
- function getState() {
105
- return {
106
- id,
107
- type,
108
- counters: { ...counters
109
- }
110
- };
111
- }
112
-
113
- function recover(state) {
114
- Object.assign(counters, state.counters);
115
- broker.recover(state.broker);
116
- }
64
+ });
117
65
 
118
- function resume() {
119
- broker.resume();
120
- }
66
+ proto.getState = function getState() {
67
+ return {
68
+ id: this.id,
69
+ type: this.type,
70
+ counters: this.counters
71
+ };
72
+ };
121
73
 
122
- function getApi() {
123
- return flowApi;
124
- }
74
+ proto.recover = function recover(state) {
75
+ Object.assign(this[kCounters], state.counters);
76
+ };
125
77
 
126
- function activate() {
127
- sourceElement.on('message', onSourceMessage, {
128
- consumerTag: sourceMessageConsumerTag
129
- });
130
- sourceElement.on('end', onSourceEnd, {
131
- consumerTag: sourceEndConsumerTag
132
- });
133
- }
78
+ proto.getApi = function getApi() {
79
+ return this;
80
+ };
134
81
 
135
- function deactivate() {
136
- sourceElement.broker.cancel(sourceMessageConsumerTag);
137
- sourceElement.broker.cancel(sourceEndConsumerTag);
138
- }
139
- }
82
+ proto.activate = function activate() {
83
+ const sourceElement = this[kSourceElement];
84
+ const safeId = (0, _shared.brokerSafeId)(this.id);
85
+ sourceElement.on('message', this.deactivate.bind(this), {
86
+ consumerTag: `_message-on-message-${safeId}`
87
+ });
88
+ sourceElement.on('end', this._onSourceEnd.bind(this), {
89
+ consumerTag: `_message-on-end-${safeId}`
90
+ });
91
+ };
92
+
93
+ proto.deactivate = function deactivate() {
94
+ const sourceElement = this[kSourceElement];
95
+ const safeId = (0, _shared.brokerSafeId)(this.id);
96
+ sourceElement.broker.cancel(`_message-on-end-${safeId}`);
97
+ sourceElement.broker.cancel(`_message-on-message-${safeId}`);
98
+ };
99
+
100
+ proto._onSourceEnd = function onSourceEnd({
101
+ content
102
+ }) {
103
+ ++this[kCounters].messages;
104
+ const source = this.source;
105
+ const target = this.target;
106
+ this.logger.debug(`<${this.id}> sending message from <${source.processId}.${source.id}> to <${target.id ? `${target.processId}.${target.id}` : target.processId}>`);
107
+ this.broker.publish('event', 'message.outbound', this._createMessage(content.message));
108
+ };
109
+
110
+ proto._createMessage = function createMessage(message) {
111
+ return {
112
+ id: this.id,
113
+ type: this.type,
114
+ name: this.name,
115
+ source: { ...this.source
116
+ },
117
+ target: { ...this.target
118
+ },
119
+ parent: (0, _messageHelper.cloneParent)(this.parent),
120
+ message
121
+ };
122
+ };