bpmn-elements 5.1.3 → 7.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 (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -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/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -9,53 +9,54 @@ function getPropertyValue(inputContext, propertyPath, fnScope) {
9
9
  if (!inputContext) return;
10
10
 
11
11
  let resultValue;
12
- let next = iterateProps(inputContext, inputContext, propertyPath.trim());
12
+ let next = iterateProps(inputContext, inputContext, propertyPath.trim(), fnScope);
13
13
  while (next) {
14
14
  resultValue = next.getResult();
15
15
  next = next();
16
16
  }
17
17
  return resultValue;
18
+ }
18
19
 
19
- function iterateProps(base, iterateContext, iteratePropertyPath) {
20
- let result;
21
- const rest = iteratePropertyPath.replace(propertyPattern, (match, fnName, args, p, prop) => {
22
- if (fnName) {
23
- result = executeFn(getNamedValue(iterateContext, fnName), args, base);
24
- } else {
25
- result = getNamedValue(iterateContext, prop);
26
- }
27
- return '';
28
- });
20
+ function iterateProps(base, iterateContext, iteratePropertyPath, fnScope) {
21
+ let result;
22
+ const rest = iteratePropertyPath.replace(propertyPattern, (match, fnName, args, p, prop) => {
23
+ if (fnName) {
24
+ result = executeFn(getNamedValue(iterateContext, fnName), args, base, fnScope);
25
+ } else {
26
+ result = getNamedValue(iterateContext, prop);
27
+ }
28
+ return '';
29
+ });
29
30
 
30
- if (rest === iteratePropertyPath) return;
31
- if (result === undefined || result === null) return;
31
+ if (rest === iteratePropertyPath) return;
32
+ if (result === undefined || result === null) return;
32
33
 
33
- const iterateNext = () => iterateProps(base, result, rest);
34
- iterateNext.getResult = () => {
35
- if (rest !== '') return;
36
- return result;
37
- };
34
+ const iterateNext = () => iterateProps(base, result, rest, fnScope);
35
+ iterateNext.getResult = () => {
36
+ if (rest !== '') return;
37
+ return result;
38
+ };
38
39
 
39
- return iterateNext;
40
- }
40
+ return iterateNext;
41
+ }
41
42
 
42
- function executeFn(fn, args, base) {
43
- if (!fn) return;
43
+ function executeFn(fn, args, base, fnScope) {
44
+ if (!fn) return;
44
45
 
45
- let callArguments = [];
46
- if (args) {
47
- callArguments = splitArguments(args, base, fnScope);
48
- } else {
49
- callArguments.push(base);
50
- }
46
+ let callArguments = [];
47
+ if (args) {
48
+ callArguments = splitArguments(args, base, fnScope);
49
+ } else {
50
+ callArguments.push(base);
51
+ }
51
52
 
52
- if (!fnScope) return fn.apply(null, callArguments);
53
+ if (!fnScope) return fn.apply(null, callArguments);
53
54
 
54
- return (function ScopedIIFE() { // eslint-disable-line no-extra-parens
55
- return fn.apply(this, callArguments);
56
- }).call(fnScope);
57
- }
55
+ return (function ScopedIIFE() { // eslint-disable-line no-extra-parens
56
+ return fn.apply(this, callArguments);
57
+ }).call(fnScope);
58
58
  }
59
+
59
60
  function splitArguments(args, base, fnScope) {
60
61
  let insideString = false;
61
62
  let delimiter = '';
@@ -0,0 +1,20 @@
1
+ export default function BpmnIO(activity, context) {
2
+ this.activity = activity;
3
+ this.context = context;
4
+
5
+ const {ioSpecification: ioSpecificationDef, properties: propertiesDef} = activity.behaviour;
6
+ this.specification = ioSpecificationDef && new ioSpecificationDef.Behaviour(activity, ioSpecificationDef, context);
7
+ this.properties = propertiesDef && new propertiesDef.Behaviour(activity, propertiesDef, context);
8
+ }
9
+
10
+ BpmnIO.prototype.activate = function activate(message) {
11
+ const properties = this.properties, specification = this.specification;
12
+ if (properties) properties.activate(message);
13
+ if (specification) specification.activate(message);
14
+ };
15
+
16
+ BpmnIO.prototype.deactivate = function deactivate(message) {
17
+ const properties = this.properties, specification = this.specification;
18
+ if (properties) properties.deactivate(message);
19
+ if (specification) specification.deactivate(message);
20
+ };
@@ -1,22 +1,33 @@
1
1
  export default function EnvironmentDataObject(dataObjectDef, {environment}) {
2
2
  const {id, type, name, behaviour, parent} = dataObjectDef;
3
+ this.id = id;
4
+ this.type = type;
5
+ this.name = name;
6
+ this.behaviour = behaviour;
7
+ this.parent = parent;
8
+ this.environment = environment;
9
+ }
3
10
 
4
- const source = {
5
- id,
6
- name,
7
- type,
8
- behaviour,
9
- parent,
10
- read(broker, exchange, routingKeyPrefix, messageProperties) {
11
- const value = environment.variables._data && environment.variables._data[id];
12
- return broker.publish(exchange, `${routingKeyPrefix}response`, {id, name, type, value}, messageProperties);
13
- },
14
- write(broker, exchange, routingKeyPrefix, value, messageProperties) {
15
- environment.variables._data = environment.variables._data || {};
16
- environment.variables._data[id] = value;
17
- return broker.publish(exchange, `${routingKeyPrefix}response`, {id, name, type, value}, messageProperties);
18
- },
19
- };
11
+ EnvironmentDataObject.prototype.read = function read(broker, exchange, routingKeyPrefix, messageProperties) {
12
+ const environment = this.environment;
13
+ const value = environment.variables._data && environment.variables._data[this.id];
14
+ const content = this._createContent(value);
15
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
16
+ };
20
17
 
21
- return source;
22
- }
18
+ EnvironmentDataObject.prototype.write = function write(broker, exchange, routingKeyPrefix, value, messageProperties) {
19
+ const environment = this.environment;
20
+ environment.variables._data = environment.variables._data || {};
21
+ environment.variables._data[this.id] = value;
22
+ const content = this._createContent(value);
23
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
24
+ };
25
+
26
+ EnvironmentDataObject.prototype._createContent = function createContent(value) {
27
+ return {
28
+ id: this.id,
29
+ type: this.type,
30
+ name: this.name,
31
+ value,
32
+ };
33
+ };
@@ -0,0 +1,33 @@
1
+ export default function EnvironmentDataStore(dataStoreDef, {environment}) {
2
+ const {id, type, name, behaviour, parent} = dataStoreDef;
3
+ this.id = id;
4
+ this.type = type;
5
+ this.name = name;
6
+ this.behaviour = behaviour;
7
+ this.parent = parent;
8
+ this.environment = environment;
9
+ }
10
+
11
+ EnvironmentDataStore.prototype.read = function read(broker, exchange, routingKeyPrefix, messageProperties) {
12
+ const environment = this.environment;
13
+ const value = environment.variables._data && environment.variables._data[this.id];
14
+ const content = this._createContent(value);
15
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
16
+ };
17
+
18
+ EnvironmentDataStore.prototype.write = function write(broker, exchange, routingKeyPrefix, value, messageProperties) {
19
+ const environment = this.environment;
20
+ environment.variables._data = environment.variables._data || {};
21
+ environment.variables._data[this.id] = value;
22
+ const content = this._createContent(value);
23
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
24
+ };
25
+
26
+ EnvironmentDataStore.prototype._createContent = function createContent(value) {
27
+ return {
28
+ id: this.id,
29
+ type: this.type,
30
+ name: this.name,
31
+ value,
32
+ };
33
+ };
@@ -0,0 +1,33 @@
1
+ export default function EnvironmentDataStoreReference(dataObjectDef, {environment}) {
2
+ const {id, type, name, behaviour, parent} = dataObjectDef;
3
+ this.id = id;
4
+ this.type = type;
5
+ this.name = name;
6
+ this.behaviour = behaviour;
7
+ this.parent = parent;
8
+ this.environment = environment;
9
+ }
10
+
11
+ EnvironmentDataStoreReference.prototype.read = function read(broker, exchange, routingKeyPrefix, messageProperties) {
12
+ const environment = this.environment;
13
+ const value = environment.variables._data && environment.variables._data[this.id];
14
+ const content = this._createContent(value);
15
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
16
+ };
17
+
18
+ EnvironmentDataStoreReference.prototype.write = function write(broker, exchange, routingKeyPrefix, value, messageProperties) {
19
+ const environment = this.environment;
20
+ environment.variables._data = environment.variables._data || {};
21
+ environment.variables._data[this.id] = value;
22
+ const content = this._createContent(value);
23
+ return broker.publish(exchange, `${routingKeyPrefix}response`, content, messageProperties);
24
+ };
25
+
26
+ EnvironmentDataStoreReference.prototype._createContent = function createContent(value) {
27
+ return {
28
+ id: this.id,
29
+ type: this.type,
30
+ name: this.name,
31
+ value,
32
+ };
33
+ };
@@ -1,186 +1,184 @@
1
1
  import getPropertyValue from '../getPropertyValue';
2
2
  import {brokerSafeId} from '../shared';
3
3
 
4
+ const consumingSymbol = Symbol.for('consuming');
5
+
4
6
  export default function IoSpecification(activity, ioSpecificationDef, context) {
5
7
  const {id, type = 'iospecification', behaviour = {}} = ioSpecificationDef;
6
- const {broker} = activity;
7
-
8
- const safeType = brokerSafeId(type).toLowerCase();
9
- let activityConsumer;
10
-
11
- const {dataInputs, dataOutputs} = behaviour;
8
+ this.id = id;
9
+ this.type = type;
10
+ this.behaviour = behaviour;
11
+ this.activity = activity;
12
+ this.broker = activity.broker;
13
+ this.context = context;
14
+ }
12
15
 
13
- const ioApi = {
14
- id,
15
- type,
16
- behaviour,
17
- activate,
18
- deactivate,
19
- };
16
+ const proto = IoSpecification.prototype;
20
17
 
21
- return ioApi;
18
+ proto.activate = function activate() {
19
+ if (this[consumingSymbol]) return;
20
+ this[consumingSymbol] = this.broker.subscribeTmp('event', 'activity.#', this._onActivityEvent.bind(this), {noAck: true});
21
+ };
22
22
 
23
- function activate() {
24
- if (activityConsumer) return;
25
- activityConsumer = broker.subscribeTmp('event', 'activity.#', onActivityEvent, {noAck: true});
26
- }
23
+ proto.deactivate = function deactivate() {
24
+ if (this[consumingSymbol]) this[consumingSymbol] = this[consumingSymbol].cancel();
25
+ };
27
26
 
28
- function deactivate() {
29
- if (activityConsumer) activityConsumer = activityConsumer.cancel();
27
+ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
28
+ const {dataInputs, dataOutputs} = this.behaviour;
29
+ if ((dataInputs || dataOutputs) && routingKey === 'activity.enter') {
30
+ return this._onFormatEnter();
30
31
  }
31
32
 
32
- function onActivityEvent(routingKey, message) {
33
- if ((dataInputs || dataOutputs) && routingKey === 'activity.enter') {
34
- return formatOnEnter();
35
- }
36
-
37
- if (dataOutputs && routingKey === 'activity.execution.completed') {
38
- formatOnComplete(message);
39
- }
33
+ if (dataOutputs && routingKey === 'activity.execution.completed') {
34
+ this._onFormatComplete(message);
40
35
  }
41
-
42
- function formatOnEnter() {
43
- const startRoutingKey = `run.onstart.${safeType}`;
44
- if (!dataInputs) {
45
- return broker.publish('format', startRoutingKey, {
46
- ioSpecification: {
47
- dataOutputs: getDataOutputs(),
48
- },
49
- });
50
- }
51
-
52
- const {dataObjects, sources} = dataInputs.reduce((result, ioSource, index) => {
53
- const source = {
54
- id: ioSource.id,
55
- type: ioSource.type,
56
- name: ioSource.name,
57
- };
58
- result.sources.push(source);
59
-
60
- const dataObjectId = getPropertyValue(ioSource, 'behaviour.association.source.dataObject.id');
61
- if (!dataObjectId) return result;
62
- const dataObject = context.getDataObjectById(dataObjectId);
63
- if (!dataObject) return result;
64
- result.dataObjects.push({index, dataObject});
65
- return result;
66
- }, {
67
- dataObjects: [],
68
- sources: [],
69
- });
70
-
71
- if (!dataObjects.length) {
72
- return broker.publish('format', startRoutingKey, {
73
- ioSpecification: {
74
- dataInputs: sources,
75
- dataOutputs: getDataOutputs(),
76
- },
77
- });
78
- }
79
-
80
- const endRoutingKey = `run.onstart.${safeType}.end`;
81
- broker.publish('format', `${startRoutingKey}.begin`, {
82
- endRoutingKey,
36
+ };
37
+
38
+ proto._onFormatEnter = function onFormatOnEnter() {
39
+ const safeType = brokerSafeId(this.type).toLowerCase();
40
+ const startRoutingKey = `run.onstart.${safeType}`;
41
+ const {dataInputs, dataOutputs} = this.behaviour;
42
+ const broker = this.broker;
43
+ if (!dataInputs) {
44
+ return broker.publish('format', startRoutingKey, {
83
45
  ioSpecification: {
84
- dataInputs: sources.map((source) => {
85
- return {...source};
86
- }),
87
- dataOutputs: getDataOutputs(),
46
+ dataOutputs: this._getDataOutputs(dataOutputs),
88
47
  },
89
48
  });
90
-
91
- return read(broker, dataObjects, (_, responses) => {
92
- responses.forEach((response) => {
93
- sources[response.index].value = response.value;
94
- });
95
-
96
- broker.publish('format', endRoutingKey, {
97
- ioSpecification: {
98
- dataInputs: sources,
99
- dataOutputs: getDataOutputs(),
100
- },
101
- });
102
- });
103
49
  }
104
50
 
105
- function formatOnComplete(message) {
106
- const messageInputs = getPropertyValue(message, 'content.ioSpecification.dataInputs');
107
- const messageOutputs = getPropertyValue(message, 'content.output.ioSpecification.dataOutputs') || [];
108
-
109
- const {dataObjects, sources} = dataOutputs.reduce((result, ioSource, index) => {
110
- const {value} = messageOutputs.find((output) => output.id === ioSource.id) || {};
111
- const source = {
112
- id: ioSource.id,
113
- type: ioSource.type,
114
- name: ioSource.name,
115
- value,
116
- };
117
- result.sources.push(source);
118
-
119
- const dataObjectId = getPropertyValue(ioSource, 'behaviour.association.target.dataObject.id');
120
- if (!dataObjectId) return result;
121
- const dataObject = context.getDataObjectById(dataObjectId);
122
- if (!dataObject) return result;
123
- result.dataObjects.push({index, dataObject, value});
124
- return result;
125
- }, {
126
- dataObjects: [],
127
- sources: [],
51
+ const {dataObjects, sources} = dataInputs.reduce((result, ioSource, index) => {
52
+ const source = {
53
+ id: ioSource.id,
54
+ type: ioSource.type,
55
+ name: ioSource.name,
56
+ };
57
+ result.sources.push(source);
58
+
59
+ const dataObjectId = getPropertyValue(ioSource, 'behaviour.association.source.dataObject.id');
60
+ if (!dataObjectId) return result;
61
+ const dataObject = this.context.getDataObjectById(dataObjectId);
62
+ if (!dataObject) return result;
63
+ result.dataObjects.push({index, dataObject});
64
+ return result;
65
+ }, {
66
+ dataObjects: [],
67
+ sources: [],
68
+ });
69
+
70
+ if (!dataObjects.length) {
71
+ return broker.publish('format', startRoutingKey, {
72
+ ioSpecification: {
73
+ dataInputs: sources,
74
+ dataOutputs: this._getDataOutputs(dataOutputs),
75
+ },
128
76
  });
77
+ }
129
78
 
130
- const startRoutingKey = `run.onend.${safeType}`;
131
- if (!dataObjects.length) {
132
- return broker.publish('format', startRoutingKey, {
133
- ioSpecification: {
134
- dataInputs: messageInputs,
135
- dataOutputs: sources,
136
- },
137
- });
138
- }
139
-
140
- const endRoutingKey = `run.onend.${safeType}.end`;
141
- broker.publish('format', `${startRoutingKey}.begin`, {
142
- endRoutingKey,
79
+ const endRoutingKey = `run.onstart.${safeType}.end`;
80
+ broker.publish('format', `${startRoutingKey}.begin`, {
81
+ endRoutingKey,
82
+ ioSpecification: {
83
+ dataInputs: sources.map((source) => {
84
+ return {...source};
85
+ }),
86
+ dataOutputs: this._getDataOutputs(dataOutputs),
87
+ },
88
+ });
89
+
90
+ return read(broker, dataObjects, (_, responses) => {
91
+ for (const response of responses) sources[response.index].value = response.value;
92
+
93
+ broker.publish('format', endRoutingKey, {
143
94
  ioSpecification: {
144
- dataInputs: sources.map((input) => {
145
- return {...input};
146
- }),
147
- dataOutputs: getDataOutputs(),
95
+ dataInputs: sources,
96
+ dataOutputs: this._getDataOutputs(dataOutputs),
148
97
  },
149
98
  });
150
-
151
- return write(broker, dataObjects, (_, responses) => {
152
- responses.forEach((response) => {
153
- sources[response.index].value = response.value;
154
- });
155
-
156
- broker.publish('format', endRoutingKey, {
157
- ioSpecification: {
158
- dataInputs: sources,
159
- dataOutputs: getDataOutputs(),
160
- },
161
- });
99
+ });
100
+ };
101
+
102
+ proto._onFormatComplete = function formatOnComplete(message) {
103
+ const safeType = brokerSafeId(this.type).toLowerCase();
104
+ const messageInputs = getPropertyValue(message, 'content.ioSpecification.dataInputs');
105
+ const messageOutputs = getPropertyValue(message, 'content.output.ioSpecification.dataOutputs') || [];
106
+ const dataOutputs = this.behaviour.dataOutputs;
107
+ const broker = this.broker;
108
+ const context = this.context;
109
+
110
+ const {dataObjects, sources} = dataOutputs.reduce((result, ioSource, index) => {
111
+ const {value} = messageOutputs.find((output) => output.id === ioSource.id) || {};
112
+ const source = {
113
+ id: ioSource.id,
114
+ type: ioSource.type,
115
+ name: ioSource.name,
116
+ value,
117
+ };
118
+ result.sources.push(source);
119
+
120
+
121
+ const dataObjectId = getPropertyValue(ioSource, 'behaviour.association.target.dataObject.id');
122
+ if (!dataObjectId) return result;
123
+ const dataObject = context.getDataObjectById(dataObjectId);
124
+ if (!dataObject) return result;
125
+ result.dataObjects.push({index, dataObject, value});
126
+ return result;
127
+ }, {
128
+ dataObjects: [],
129
+ sources: [],
130
+ });
131
+
132
+ const startRoutingKey = `run.onend.${safeType}`;
133
+ if (!dataObjects.length) {
134
+ return broker.publish('format', startRoutingKey, {
135
+ ioSpecification: {
136
+ dataInputs: messageInputs,
137
+ dataOutputs: sources,
138
+ },
162
139
  });
163
140
  }
164
141
 
165
- function getDataOutputs() {
166
- if (!dataOutputs) return;
167
- return dataOutputs.map((dataOutput) => {
168
- return {
169
- id: dataOutput.id,
170
- type: dataOutput.type,
171
- name: dataOutput.name,
172
- };
142
+ const endRoutingKey = `run.onend.${safeType}.end`;
143
+ broker.publish('format', `${startRoutingKey}.begin`, {
144
+ endRoutingKey,
145
+ ioSpecification: {
146
+ dataInputs: sources.map((input) => {
147
+ return {...input};
148
+ }),
149
+ dataOutputs: this._getDataOutputs(dataOutputs),
150
+ },
151
+ });
152
+
153
+ return write(broker, dataObjects, (_, responses) => {
154
+ for (const response of responses) sources[response.index].value = response.value;
155
+
156
+ broker.publish('format', endRoutingKey, {
157
+ ioSpecification: {
158
+ dataInputs: sources,
159
+ dataOutputs: this._getDataOutputs(dataOutputs),
160
+ },
173
161
  });
174
- }
175
- }
162
+ });
163
+ };
164
+
165
+ proto._getDataOutputs = function getDataOutputs(dataOutputs) {
166
+ if (!dataOutputs) return;
167
+ return dataOutputs.map((dataOutput) => {
168
+ return {
169
+ id: dataOutput.id,
170
+ type: dataOutput.type,
171
+ name: dataOutput.name,
172
+ };
173
+ });
174
+ };
176
175
 
177
176
  function read(broker, dataObjectRefs, callback) {
178
177
  const responses = [];
179
178
  let count = 0;
180
179
  const dataReadConsumer = broker.subscribeTmp('data', 'data.read.#', onDataObjectResponse, {noAck: true});
181
180
 
182
- for (let i = 0; i < dataObjectRefs.length; i++) {
183
- const {dataObject} = dataObjectRefs[i];
181
+ for (const {dataObject} of dataObjectRefs) {
184
182
  dataObject.read(broker, 'data', 'data.read.');
185
183
  }
186
184
 
@@ -200,22 +198,21 @@ function read(broker, dataObjectRefs, callback) {
200
198
  function write(broker, dataObjectRefs, callback) {
201
199
  const responses = [];
202
200
  let count = 0;
203
- const dataWriteConsumer = broker.subscribeTmp('data', 'data.write.#', onDataObjectResponse, {noAck: true});
201
+ broker.subscribeTmp('data', 'data.write.#', onDataObjectResponse, {noAck: true});
204
202
 
205
- for (let i = 0; i < dataObjectRefs.length; i++) {
206
- const {dataObject, value} = dataObjectRefs[i];
203
+ for (const {dataObject, value} of dataObjectRefs) {
207
204
  dataObject.write(broker, 'data', 'data.write.', value);
208
205
  }
209
206
 
210
207
  function onDataObjectResponse(routingKey, message) {
211
- const idx = dataObjectRefs.findIndex((dobj) => dobj.id === message.content.id);
212
- responses[idx] = message.content;
208
+ const idx = dataObjectRefs.findIndex(({dataObject}) => dataObject.id === message.content.id);
209
+ responses[idx] = {index: idx, ...message.content};
213
210
 
214
211
  ++count;
215
212
 
216
213
  if (count < dataObjectRefs.length) return;
217
214
 
218
- dataWriteConsumer.cancel();
215
+ broker.cancel(message.fields.consumerTag);
219
216
  return callback(null, responses);
220
217
  }
221
218
  }