@onify/flow-extensions 5.0.2 → 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.
- package/CHANGELOG.md +15 -0
- package/dist/FlowScripts.js +0 -1
- package/dist/OnifyBoundaryEventExtensions.js +86 -0
- package/dist/OnifyElementExtensions.js +64 -84
- package/dist/OnifySubProcessExtensions.js +50 -0
- package/dist/OnifyTimerEventDefinition.js +33 -0
- package/dist/formatters.js +2 -0
- package/dist/index.js +20 -2
- package/index.d.ts +4 -1
- package/package.json +17 -13
- package/src/OnifyBoundaryEventExtensions.js +65 -0
- package/src/OnifyElementExtensions.js +43 -52
- package/src/OnifySubProcessExtensions.js +46 -0
- package/src/OnifyTimerEventDefinition.js +25 -0
- package/src/formatters.js +1 -0
- package/src/index.js +19 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
# 7.0.0
|
|
5
|
+
|
|
6
|
+
Attempting to mitigate Boundary Event formatting interrupting normal execution flow. Asynchronous formatting prevents catching events from attached task. Should probably be done in bpmn-elements but the developer is busy.
|
|
7
|
+
|
|
8
|
+
## Breaking
|
|
9
|
+
|
|
10
|
+
- No async formatting on boundary events before end
|
|
11
|
+
- Boundary event start execution listener will be executed but _without_ formatting capabilities and detached from execution. Occasional error will just be logged
|
|
12
|
+
- Boundary event end execution listener is still executed _with_ formatting capabilities
|
|
13
|
+
|
|
14
|
+
# 6.0.0
|
|
15
|
+
|
|
16
|
+
- Require peer dependency `bpmn-elements >= 8`
|
|
17
|
+
- Support timer event definition cron time cycle by overloading parse function. Requires `bpmn-elements >= 10`
|
|
18
|
+
|
|
4
19
|
# 5.0.2
|
|
5
20
|
|
|
6
21
|
- Correct package module file...
|
package/dist/FlowScripts.js
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OnifyBoundaryEventExtensions = void 0;
|
|
7
|
+
var _OnifyElementExtensions = require("./OnifyElementExtensions.js");
|
|
8
|
+
class OnifyBoundaryEventExtensions extends _OnifyElementExtensions.OnifyElementExtensions {
|
|
9
|
+
constructor(activity, context) {
|
|
10
|
+
super(activity, context);
|
|
11
|
+
this._syncFormatOnEnter = this._syncFormatOnEnter.bind(this);
|
|
12
|
+
}
|
|
13
|
+
activate(message) {
|
|
14
|
+
const activity = this.activity;
|
|
15
|
+
const formatQ = activity.broker.getQueue('format-run-q');
|
|
16
|
+
const executionListeners = this.extensions.listeners;
|
|
17
|
+
if (message.fields.redelivered && message.fields.routingKey === 'run.start') {
|
|
18
|
+
activity.on('start', this._syncFormatOnEnter, {
|
|
19
|
+
consumerTag: '_onify-extension-on-enter'
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
activity.on('enter', this._syncFormatOnEnter, {
|
|
23
|
+
consumerTag: '_onify-extension-on-enter'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
activity.on('activity.execution.completed', elementApi => {
|
|
27
|
+
return this._onExecutionCompleted(elementApi, formatQ);
|
|
28
|
+
}, {
|
|
29
|
+
consumerTag: '_onify-extension-on-executed'
|
|
30
|
+
});
|
|
31
|
+
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onStart) {
|
|
32
|
+
activity.on('start', async elementApi => {
|
|
33
|
+
try {
|
|
34
|
+
await executionListeners.execute('start', elementApi);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return activity.logger.error(`<${activity.id}> execution listener error`, err);
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
consumerTag: '_onify-extension-on-listenerstart'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onEnd) {
|
|
43
|
+
activity.on('end', elementApi => {
|
|
44
|
+
this._executeExecutionListener('end', elementApi, formatQ);
|
|
45
|
+
}, {
|
|
46
|
+
consumerTag: '_onify-extension-on-listenerend'
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_syncFormatOnEnter(elementApi) {
|
|
51
|
+
try {
|
|
52
|
+
var format = this._onEnterSync(elementApi);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return elementApi.broker.publish('format', 'run.enter.error', {
|
|
55
|
+
error: err
|
|
56
|
+
}, {
|
|
57
|
+
persistent: false
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
elementApi.broker.publish('format', 'run.enter.complete', format, {
|
|
61
|
+
persistent: false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
_onEnterSync(elementApi) {
|
|
65
|
+
var _io$output;
|
|
66
|
+
const {
|
|
67
|
+
format,
|
|
68
|
+
properties,
|
|
69
|
+
io
|
|
70
|
+
} = this.extensions;
|
|
71
|
+
const result = {};
|
|
72
|
+
Object.assign(result, format.resolve(elementApi));
|
|
73
|
+
Object.assign(elementApi.content, result);
|
|
74
|
+
if (properties) {
|
|
75
|
+
Object.assign(result, {
|
|
76
|
+
properties: properties.resolve(elementApi)
|
|
77
|
+
});
|
|
78
|
+
Object.assign(elementApi.content, result);
|
|
79
|
+
}
|
|
80
|
+
if (io !== null && io !== void 0 && (_io$output = io.output) !== null && _io$output !== void 0 && _io$output.length) {
|
|
81
|
+
result.assignToOutput = true;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.OnifyBoundaryEventExtensions = OnifyBoundaryEventExtensions;
|
|
@@ -9,6 +9,8 @@ class OnifyElementExtensions {
|
|
|
9
9
|
constructor(activity, context) {
|
|
10
10
|
this.activity = activity;
|
|
11
11
|
this.context = context;
|
|
12
|
+
this.formatQ = activity.broker.getQueue('format-run-q');
|
|
13
|
+
this._asyncFormatOnEnter = this._asyncFormatOnEnter.bind(this);
|
|
12
14
|
const {
|
|
13
15
|
Service
|
|
14
16
|
} = this.extensions = (0, _getExtensions.getExtensions)(activity, context);
|
|
@@ -18,100 +20,31 @@ class OnifyElementExtensions {
|
|
|
18
20
|
}
|
|
19
21
|
activate(message) {
|
|
20
22
|
const activity = this.activity;
|
|
21
|
-
const broker = activity.broker;
|
|
22
|
-
const formatQ = activity.broker.getQueue('format-run-q');
|
|
23
23
|
const executionListeners = this.extensions.listeners;
|
|
24
24
|
if (message.fields.redelivered && message.fields.routingKey === 'run.start') {
|
|
25
|
-
activity.on('start',
|
|
26
|
-
this._formatOnEnter(broker, formatQ, elementApi);
|
|
27
|
-
}, {
|
|
25
|
+
activity.on('start', this._asyncFormatOnEnter, {
|
|
28
26
|
consumerTag: '_onify-extension-on-enter'
|
|
29
27
|
});
|
|
30
28
|
} else {
|
|
31
|
-
activity.on('enter',
|
|
32
|
-
this._formatOnEnter(broker, formatQ, elementApi);
|
|
33
|
-
}, {
|
|
29
|
+
activity.on('enter', this._asyncFormatOnEnter, {
|
|
34
30
|
consumerTag: '_onify-extension-on-enter'
|
|
35
31
|
});
|
|
36
32
|
}
|
|
37
|
-
activity.on('activity.execution.completed',
|
|
38
|
-
|
|
39
|
-
formatQ.queueMessage({
|
|
40
|
-
routingKey: 'run.end.format'
|
|
41
|
-
}, {
|
|
42
|
-
endRoutingKey: 'run.end.complete'
|
|
43
|
-
}, {
|
|
44
|
-
persistent: false
|
|
45
|
-
});
|
|
46
|
-
try {
|
|
47
|
-
var format = await this._onExecuted(elementApi);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
return broker.publish('format', 'run.end.error', {
|
|
50
|
-
error: err
|
|
51
|
-
}, {
|
|
52
|
-
persistent: false
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
broker.publish('format', 'run.end.complete', {
|
|
56
|
-
...format
|
|
57
|
-
}, {
|
|
58
|
-
persistent: false
|
|
59
|
-
});
|
|
33
|
+
activity.on('activity.execution.completed', elementApi => {
|
|
34
|
+
return this._onExecutionCompleted(elementApi);
|
|
60
35
|
}, {
|
|
61
36
|
consumerTag: '_onify-extension-on-executed'
|
|
62
37
|
});
|
|
63
38
|
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onStart) {
|
|
64
|
-
activity.on('start',
|
|
65
|
-
|
|
66
|
-
formatQ.queueMessage({
|
|
67
|
-
routingKey: 'run.listener.start'
|
|
68
|
-
}, {
|
|
69
|
-
endRoutingKey: 'run.listener.start.complete'
|
|
70
|
-
}, {
|
|
71
|
-
persistent: false
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
var format = await executionListeners.execute('start', elementApi);
|
|
75
|
-
} catch (err) {
|
|
76
|
-
return broker.publish('format', 'run.listener.start.error', {
|
|
77
|
-
error: err
|
|
78
|
-
}, {
|
|
79
|
-
persistent: false
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
broker.publish('format', 'run.listener.start.complete', {
|
|
83
|
-
...format
|
|
84
|
-
}, {
|
|
85
|
-
persistent: false
|
|
86
|
-
});
|
|
39
|
+
activity.on('start', elementApi => {
|
|
40
|
+
this._executeExecutionListener('start', elementApi);
|
|
87
41
|
}, {
|
|
88
42
|
consumerTag: '_onify-extension-on-listenerstart'
|
|
89
43
|
});
|
|
90
44
|
}
|
|
91
45
|
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onEnd) {
|
|
92
|
-
activity.on('end',
|
|
93
|
-
|
|
94
|
-
formatQ.queueMessage({
|
|
95
|
-
routingKey: 'run.listener.end'
|
|
96
|
-
}, {
|
|
97
|
-
endRoutingKey: 'run.listener.end.complete'
|
|
98
|
-
}, {
|
|
99
|
-
persistent: false
|
|
100
|
-
});
|
|
101
|
-
try {
|
|
102
|
-
var format = await executionListeners.execute('end', elementApi);
|
|
103
|
-
} catch (err) {
|
|
104
|
-
return broker.publish('format', 'run.listener.end.error', {
|
|
105
|
-
error: err
|
|
106
|
-
}, {
|
|
107
|
-
persistent: false
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
broker.publish('format', 'run.listener.end.complete', {
|
|
111
|
-
...format
|
|
112
|
-
}, {
|
|
113
|
-
persistent: false
|
|
114
|
-
});
|
|
46
|
+
activity.on('end', elementApi => {
|
|
47
|
+
this._executeExecutionListener('end', elementApi);
|
|
115
48
|
}, {
|
|
116
49
|
consumerTag: '_onify-extension-on-listenerend'
|
|
117
50
|
});
|
|
@@ -124,9 +57,8 @@ class OnifyElementExtensions {
|
|
|
124
57
|
broker.cancel('_onify-extension-on-listenerstart');
|
|
125
58
|
broker.cancel('_onify-extension-on-listenerend');
|
|
126
59
|
}
|
|
127
|
-
async
|
|
128
|
-
|
|
129
|
-
formatQ.queueMessage({
|
|
60
|
+
async _asyncFormatOnEnter(elementApi) {
|
|
61
|
+
this.formatQ.queueMessage({
|
|
130
62
|
routingKey: 'run.enter.format'
|
|
131
63
|
}, {
|
|
132
64
|
endRoutingKey: 'run.enter.complete'
|
|
@@ -134,19 +66,42 @@ class OnifyElementExtensions {
|
|
|
134
66
|
persistent: false
|
|
135
67
|
});
|
|
136
68
|
try {
|
|
137
|
-
var format = await this.
|
|
69
|
+
var format = await this._onEnterAsync(elementApi);
|
|
138
70
|
} catch (err) {
|
|
139
|
-
return broker.publish('format', 'run.enter.error', {
|
|
71
|
+
return elementApi.broker.publish('format', 'run.enter.error', {
|
|
140
72
|
error: err
|
|
141
73
|
}, {
|
|
142
74
|
persistent: false
|
|
143
75
|
});
|
|
144
76
|
}
|
|
145
|
-
broker.publish('format', 'run.enter.complete', format, {
|
|
77
|
+
elementApi.broker.publish('format', 'run.enter.complete', format, {
|
|
146
78
|
persistent: false
|
|
147
79
|
});
|
|
148
80
|
}
|
|
149
|
-
async
|
|
81
|
+
async _onExecutionCompleted(elementApi) {
|
|
82
|
+
this.formatQ.queueMessage({
|
|
83
|
+
routingKey: 'run.end.format'
|
|
84
|
+
}, {
|
|
85
|
+
endRoutingKey: 'run.end.complete'
|
|
86
|
+
}, {
|
|
87
|
+
persistent: false
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
var format = await this._onExecuted(elementApi);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
return elementApi.broker.publish('format', 'run.end.error', {
|
|
93
|
+
error: err
|
|
94
|
+
}, {
|
|
95
|
+
persistent: false
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
elementApi.broker.publish('format', 'run.end.complete', {
|
|
99
|
+
...format
|
|
100
|
+
}, {
|
|
101
|
+
persistent: false
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async _onEnterAsync(elementApi) {
|
|
150
105
|
const {
|
|
151
106
|
format,
|
|
152
107
|
properties,
|
|
@@ -220,5 +175,30 @@ class OnifyElementExtensions {
|
|
|
220
175
|
}
|
|
221
176
|
return result;
|
|
222
177
|
}
|
|
178
|
+
async _executeExecutionListener(eventName, elementApi) {
|
|
179
|
+
const routingKey = 'run.listener.' + eventName;
|
|
180
|
+
const endRoutingKey = routingKey + '.complete';
|
|
181
|
+
this.formatQ.queueMessage({
|
|
182
|
+
routingKey
|
|
183
|
+
}, {
|
|
184
|
+
endRoutingKey
|
|
185
|
+
}, {
|
|
186
|
+
persistent: false
|
|
187
|
+
});
|
|
188
|
+
try {
|
|
189
|
+
var format = await this.extensions.listeners.execute(eventName, elementApi);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
return elementApi.broker.publish('format', routingKey + '.error', {
|
|
192
|
+
error: err
|
|
193
|
+
}, {
|
|
194
|
+
persistent: false
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
elementApi.broker.publish('format', endRoutingKey, {
|
|
198
|
+
...format
|
|
199
|
+
}, {
|
|
200
|
+
persistent: false
|
|
201
|
+
});
|
|
202
|
+
}
|
|
223
203
|
}
|
|
224
204
|
exports.OnifyElementExtensions = OnifyElementExtensions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OnifySubProcessExtensions = void 0;
|
|
7
|
+
var _OnifyElementExtensions = require("./OnifyElementExtensions.js");
|
|
8
|
+
class OnifySubProcessExtensions extends _OnifyElementExtensions.OnifyElementExtensions {
|
|
9
|
+
constructor(activity, context) {
|
|
10
|
+
super(activity, context);
|
|
11
|
+
}
|
|
12
|
+
activate(runMessage) {
|
|
13
|
+
const activity = this.activity;
|
|
14
|
+
const broker = activity.broker;
|
|
15
|
+
const executionListeners = this.extensions.listeners;
|
|
16
|
+
if (runMessage.fields.redelivered && runMessage.fields.routingKey === 'run.start') {
|
|
17
|
+
this._setupListener(broker, 'activity.start', elementApi => {
|
|
18
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
19
|
+
}, '_onify-extension-on-enter');
|
|
20
|
+
} else {
|
|
21
|
+
this._setupListener(broker, 'activity.enter', elementApi => {
|
|
22
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
23
|
+
}, '_onify-extension-on-enter');
|
|
24
|
+
}
|
|
25
|
+
this._setupListener(broker, 'activity.execution.completed', elementApi => {
|
|
26
|
+
return this._onExecutionCompleted(elementApi);
|
|
27
|
+
}, '_onify-extension-on-executed');
|
|
28
|
+
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onStart) {
|
|
29
|
+
this._setupListener(broker, 'activity.start', elementApi => {
|
|
30
|
+
this._executeExecutionListener('start', elementApi);
|
|
31
|
+
}, '_onify-extension-on-listenerstart');
|
|
32
|
+
}
|
|
33
|
+
if (executionListeners !== null && executionListeners !== void 0 && executionListeners.onEnd) {
|
|
34
|
+
this._setupListener(broker, 'activity.end', elementApi => {
|
|
35
|
+
this._executeExecutionListener('end', elementApi);
|
|
36
|
+
}, '_onify-extension-on-listenerend');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_setupListener(broker, routingKey, callback, consumerTag) {
|
|
40
|
+
const activity = this.activity;
|
|
41
|
+
broker.subscribeTmp('event', routingKey, (_, message) => {
|
|
42
|
+
if (activity.id !== message.content.id) return;
|
|
43
|
+
return callback(activity.getApi(message));
|
|
44
|
+
}, {
|
|
45
|
+
noAck: true,
|
|
46
|
+
consumerTag
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.OnifySubProcessExtensions = OnifySubProcessExtensions;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OnifyTimerEventDefinition = void 0;
|
|
7
|
+
var _bpmnElements = require("bpmn-elements");
|
|
8
|
+
var _cronParser = _interopRequireDefault(require("cron-parser"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
|
|
11
|
+
constructor(activity, def) {
|
|
12
|
+
super(activity, def);
|
|
13
|
+
Object.defineProperty(this, 'supports', {
|
|
14
|
+
value: ['cron']
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
parse(timerType, value) {
|
|
18
|
+
let cron;
|
|
19
|
+
if (timerType === 'timeCycle' && (cron = _cronParser.default.parseString(value))) {
|
|
20
|
+
var _cron$expressions;
|
|
21
|
+
if ((_cron$expressions = cron.expressions) !== null && _cron$expressions !== void 0 && _cron$expressions.length) {
|
|
22
|
+
// cronParser.parseString expressions disregards seconds, so we have to parse again
|
|
23
|
+
const expireAt = _cronParser.default.parseExpression(value).next().toDate();
|
|
24
|
+
return {
|
|
25
|
+
expireAt,
|
|
26
|
+
delay: expireAt - Date.now()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return super.parse(timerType, value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.OnifyTimerEventDefinition = OnifyTimerEventDefinition;
|
package/dist/formatters.js
CHANGED
|
@@ -14,6 +14,8 @@ class FormatActivity {
|
|
|
14
14
|
let timeCycles;
|
|
15
15
|
if (activity.eventDefinitions) {
|
|
16
16
|
for (const ed of activity.eventDefinitions.filter(e => e.type === 'bpmn:TimerEventDefinition')) {
|
|
17
|
+
var _ed$supports;
|
|
18
|
+
if ((_ed$supports = ed.supports) !== null && _ed$supports !== void 0 && _ed$supports.includes('cron')) continue;
|
|
17
19
|
if (!('timeCycle' in ed)) continue;
|
|
18
20
|
timeCycles = timeCycles || [];
|
|
19
21
|
timeCycles.push(ed.timeCycle);
|
package/dist/index.js
CHANGED
|
@@ -9,14 +9,32 @@ Object.defineProperty(exports, "OnifySequenceFlow", {
|
|
|
9
9
|
return _OnifySequenceFlow.OnifySequenceFlow;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "OnifyTimerEventDefinition", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _OnifyTimerEventDefinition.OnifyTimerEventDefinition;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
exports.extendFn = extendFn;
|
|
13
19
|
exports.extensions = extensions;
|
|
14
20
|
var _OnifyProcessExtensions = require("./OnifyProcessExtensions.js");
|
|
15
21
|
var _OnifyElementExtensions = require("./OnifyElementExtensions.js");
|
|
22
|
+
var _OnifyBoundaryEventExtensions = require("./OnifyBoundaryEventExtensions.js");
|
|
23
|
+
var _OnifySubProcessExtensions = require("./OnifySubProcessExtensions.js");
|
|
16
24
|
var _OnifySequenceFlow = require("./OnifySequenceFlow.js");
|
|
25
|
+
var _OnifyTimerEventDefinition = require("./OnifyTimerEventDefinition.js");
|
|
17
26
|
function extensions(element, context) {
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
switch (element.type) {
|
|
28
|
+
case 'bpmn:Process':
|
|
29
|
+
return new _OnifyProcessExtensions.OnifyProcessExtensions(element, context);
|
|
30
|
+
case 'bpmn:SubProcess':
|
|
31
|
+
case 'bpmn:Transaction':
|
|
32
|
+
return new _OnifySubProcessExtensions.OnifySubProcessExtensions(element, context);
|
|
33
|
+
case 'bpmn:BoundaryEvent':
|
|
34
|
+
return new _OnifyBoundaryEventExtensions.OnifyBoundaryEventExtensions(element, context);
|
|
35
|
+
default:
|
|
36
|
+
return new _OnifyElementExtensions.OnifyElementExtensions(element, context);
|
|
37
|
+
}
|
|
20
38
|
}
|
|
21
39
|
function extendFn(behaviour, context) {
|
|
22
40
|
var _behaviour$extensionE;
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
declare module '@onify/flow-extensions' {
|
|
2
|
-
import { SequenceFlow, ElementBase, Context, IExtension } from 'bpmn-elements';
|
|
2
|
+
import { SequenceFlow, TimerEventDefinition, ElementBase, Context, IExtension } from 'bpmn-elements';
|
|
3
3
|
import { extendFn as extendFunction } from 'moddle-context-serializer';
|
|
4
4
|
|
|
5
5
|
export class OnifySequenceFlow extends SequenceFlow {}
|
|
6
|
+
export class OnifyTimerEventDefinition extends TimerEventDefinition {
|
|
7
|
+
readonly supports: string[];
|
|
8
|
+
}
|
|
6
9
|
export function extensions(element: ElementBase, context: Context): IExtension;
|
|
7
10
|
export const extendFn: extendFunction;
|
|
8
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onify/flow-extensions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Onify Flow extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -38,26 +38,30 @@
|
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@aircall/expression-parser": "^1.0.4",
|
|
41
|
-
"@babel/cli": "^7.
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/preset-env": "^7.
|
|
44
|
-
"@babel/register": "^7.
|
|
41
|
+
"@babel/cli": "^7.23.4",
|
|
42
|
+
"@babel/core": "^7.23.6",
|
|
43
|
+
"@babel/preset-env": "^7.23.6",
|
|
44
|
+
"@babel/register": "^7.22.15",
|
|
45
45
|
"bpmn-elements-8-1": "npm:bpmn-elements@8.1",
|
|
46
|
-
"bpmn-engine": "^
|
|
46
|
+
"bpmn-engine": "^18.0.0",
|
|
47
47
|
"bpmn-engine-14": "npm:bpmn-engine@14",
|
|
48
|
-
"bpmn-moddle": "^8.0
|
|
49
|
-
"c8": "^
|
|
48
|
+
"bpmn-moddle": "^8.1.0",
|
|
49
|
+
"c8": "^8.0.1",
|
|
50
50
|
"camunda-bpmn-moddle": "^7.0.1",
|
|
51
|
-
"chai": "^4.3.
|
|
52
|
-
"chronokinesis": "^
|
|
51
|
+
"chai": "^4.3.10",
|
|
52
|
+
"chronokinesis": "^6.0.0",
|
|
53
53
|
"debug": "^4.3.4",
|
|
54
|
-
"eslint": "^8.
|
|
54
|
+
"eslint": "^8.56.0",
|
|
55
|
+
"eslint-plugin-import": "^2.29.1",
|
|
55
56
|
"mocha": "^10.2.0",
|
|
56
57
|
"mocha-cakes-2": "^3.3.0",
|
|
57
|
-
"moddle-context-serializer": "^
|
|
58
|
+
"moddle-context-serializer": "^4.1.1"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"bpmn-elements": ">=8"
|
|
58
62
|
},
|
|
59
63
|
"dependencies": {
|
|
60
|
-
"cron-parser": "^4.
|
|
64
|
+
"cron-parser": "^4.9.0"
|
|
61
65
|
},
|
|
62
66
|
"files": [
|
|
63
67
|
"src",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OnifyElementExtensions } from './OnifyElementExtensions.js';
|
|
2
|
+
|
|
3
|
+
export class OnifyBoundaryEventExtensions extends OnifyElementExtensions {
|
|
4
|
+
constructor(activity, context) {
|
|
5
|
+
super(activity, context);
|
|
6
|
+
this._syncFormatOnEnter = this._syncFormatOnEnter.bind(this);
|
|
7
|
+
}
|
|
8
|
+
activate(message) {
|
|
9
|
+
const activity = this.activity;
|
|
10
|
+
const formatQ = activity.broker.getQueue('format-run-q');
|
|
11
|
+
const executionListeners = this.extensions.listeners;
|
|
12
|
+
|
|
13
|
+
if (message.fields.redelivered && message.fields.routingKey === 'run.start') {
|
|
14
|
+
activity.on('start', this._syncFormatOnEnter, { consumerTag: '_onify-extension-on-enter' });
|
|
15
|
+
} else {
|
|
16
|
+
activity.on('enter', this._syncFormatOnEnter, { consumerTag: '_onify-extension-on-enter' });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
activity.on('activity.execution.completed', (elementApi) => {
|
|
20
|
+
return this._onExecutionCompleted(elementApi, formatQ);
|
|
21
|
+
}, { consumerTag: '_onify-extension-on-executed' });
|
|
22
|
+
|
|
23
|
+
if (executionListeners?.onStart) {
|
|
24
|
+
activity.on('start', async (elementApi) => {
|
|
25
|
+
try {
|
|
26
|
+
await executionListeners.execute('start', elementApi);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return activity.logger.error(`<${activity.id}> execution listener error`, err);
|
|
29
|
+
}
|
|
30
|
+
}, { consumerTag: '_onify-extension-on-listenerstart' });
|
|
31
|
+
}
|
|
32
|
+
if (executionListeners?.onEnd) {
|
|
33
|
+
activity.on('end', (elementApi) => {
|
|
34
|
+
this._executeExecutionListener('end', elementApi, formatQ);
|
|
35
|
+
}, { consumerTag: '_onify-extension-on-listenerend' });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_syncFormatOnEnter(elementApi) {
|
|
39
|
+
try {
|
|
40
|
+
var format = this._onEnterSync(elementApi);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return elementApi.broker.publish('format', 'run.enter.error', { error: err }, { persistent: false });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
elementApi.broker.publish('format', 'run.enter.complete', format, { persistent: false });
|
|
46
|
+
}
|
|
47
|
+
_onEnterSync(elementApi) {
|
|
48
|
+
const {format, properties, io} = this.extensions;
|
|
49
|
+
|
|
50
|
+
const result = {};
|
|
51
|
+
Object.assign(result, format.resolve(elementApi));
|
|
52
|
+
Object.assign(elementApi.content, result);
|
|
53
|
+
|
|
54
|
+
if (properties) {
|
|
55
|
+
Object.assign(result, { properties: properties.resolve(elementApi) });
|
|
56
|
+
Object.assign(elementApi.content, result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (io?.output?.length) {
|
|
60
|
+
result.assignToOutput = true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -4,69 +4,37 @@ export class OnifyElementExtensions {
|
|
|
4
4
|
constructor(activity, context) {
|
|
5
5
|
this.activity = activity;
|
|
6
6
|
this.context = context;
|
|
7
|
-
|
|
7
|
+
this.formatQ = activity.broker.getQueue('format-run-q');
|
|
8
|
+
this._asyncFormatOnEnter = this._asyncFormatOnEnter.bind(this);
|
|
9
|
+
|
|
10
|
+
const { Service } = this.extensions = getExtensions(activity, context);
|
|
8
11
|
if (Service) {
|
|
9
12
|
activity.behaviour.Service = Service;
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
activate(message) {
|
|
13
16
|
const activity = this.activity;
|
|
14
|
-
const broker = activity.broker;
|
|
15
|
-
const formatQ = activity.broker.getQueue('format-run-q');
|
|
16
17
|
const executionListeners = this.extensions.listeners;
|
|
17
18
|
|
|
18
19
|
if (message.fields.redelivered && message.fields.routingKey === 'run.start') {
|
|
19
|
-
activity.on('start',
|
|
20
|
-
this._formatOnEnter(broker, formatQ, elementApi);
|
|
21
|
-
}, {consumerTag: '_onify-extension-on-enter'});
|
|
20
|
+
activity.on('start', this._asyncFormatOnEnter, {consumerTag: '_onify-extension-on-enter'});
|
|
22
21
|
} else {
|
|
23
|
-
activity.on('enter',
|
|
24
|
-
this._formatOnEnter(broker, formatQ, elementApi);
|
|
25
|
-
}, {consumerTag: '_onify-extension-on-enter'});
|
|
22
|
+
activity.on('enter', this._asyncFormatOnEnter, {consumerTag: '_onify-extension-on-enter'});
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
activity.on('activity.execution.completed',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
formatQ.queueMessage({routingKey: 'run.end.format'}, {endRoutingKey: 'run.end.complete'}, {persistent: false});
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
var format = await this._onExecuted(elementApi);
|
|
35
|
-
} catch (err) {
|
|
36
|
-
return broker.publish('format', 'run.end.error', {error: err}, {persistent: false});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
broker.publish('format', 'run.end.complete', {...format}, {persistent: false});
|
|
25
|
+
activity.on('activity.execution.completed', (elementApi) => {
|
|
26
|
+
return this._onExecutionCompleted(elementApi);
|
|
40
27
|
}, {consumerTag: '_onify-extension-on-executed'});
|
|
41
28
|
|
|
42
29
|
if (executionListeners?.onStart) {
|
|
43
|
-
activity.on('start',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
formatQ.queueMessage({routingKey: 'run.listener.start'}, {endRoutingKey: 'run.listener.start.complete'}, {persistent: false});
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
var format = await executionListeners.execute('start', elementApi);
|
|
50
|
-
} catch (err) {
|
|
51
|
-
return broker.publish('format', 'run.listener.start.error', {error: err}, {persistent: false});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
broker.publish('format', 'run.listener.start.complete', {...format}, {persistent: false});
|
|
30
|
+
activity.on('start', (elementApi) => {
|
|
31
|
+
this._executeExecutionListener('start', elementApi);
|
|
55
32
|
}, {consumerTag: '_onify-extension-on-listenerstart'});
|
|
56
33
|
}
|
|
57
|
-
if (executionListeners?.onEnd) {
|
|
58
|
-
activity.on('end', async (elementApi) => {
|
|
59
|
-
if (activity.isSubProcess && activity.id !== elementApi.id) return;
|
|
60
|
-
|
|
61
|
-
formatQ.queueMessage({routingKey: 'run.listener.end'}, {endRoutingKey: 'run.listener.end.complete'}, {persistent: false});
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
var format = await executionListeners.execute('end', elementApi);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
return broker.publish('format', 'run.listener.end.error', {error: err}, {persistent: false});
|
|
67
|
-
}
|
|
68
34
|
|
|
69
|
-
|
|
35
|
+
if (executionListeners?.onEnd) {
|
|
36
|
+
activity.on('end', (elementApi) => {
|
|
37
|
+
this._executeExecutionListener('end', elementApi);
|
|
70
38
|
}, {consumerTag: '_onify-extension-on-listenerend'});
|
|
71
39
|
}
|
|
72
40
|
}
|
|
@@ -77,20 +45,29 @@ export class OnifyElementExtensions {
|
|
|
77
45
|
broker.cancel('_onify-extension-on-listenerstart');
|
|
78
46
|
broker.cancel('_onify-extension-on-listenerend');
|
|
79
47
|
}
|
|
80
|
-
async
|
|
81
|
-
|
|
48
|
+
async _asyncFormatOnEnter(elementApi) {
|
|
49
|
+
this.formatQ.queueMessage({routingKey: 'run.enter.format'}, {endRoutingKey: 'run.enter.complete'}, {persistent: false});
|
|
82
50
|
|
|
83
|
-
|
|
51
|
+
try {
|
|
52
|
+
var format = await this._onEnterAsync(elementApi);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return elementApi.broker.publish('format', 'run.enter.error', {error: err}, {persistent: false});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
elementApi.broker.publish('format', 'run.enter.complete', format, {persistent: false});
|
|
58
|
+
}
|
|
59
|
+
async _onExecutionCompleted(elementApi) {
|
|
60
|
+
this.formatQ.queueMessage({routingKey: 'run.end.format'}, { endRoutingKey: 'run.end.complete' }, { persistent: false });
|
|
84
61
|
|
|
85
62
|
try {
|
|
86
|
-
var format = await this.
|
|
63
|
+
var format = await this._onExecuted(elementApi);
|
|
87
64
|
} catch (err) {
|
|
88
|
-
return broker.publish('format', 'run.
|
|
65
|
+
return elementApi.broker.publish('format', 'run.end.error', { error: err }, {persistent: false});
|
|
89
66
|
}
|
|
90
67
|
|
|
91
|
-
broker.publish('format', 'run.
|
|
68
|
+
elementApi.broker.publish('format', 'run.end.complete', { ...format }, {persistent: false});
|
|
92
69
|
}
|
|
93
|
-
async
|
|
70
|
+
async _onEnterAsync(elementApi) {
|
|
94
71
|
const {format, properties, io, form} = this.extensions;
|
|
95
72
|
|
|
96
73
|
const result = {};
|
|
@@ -147,4 +124,18 @@ export class OnifyElementExtensions {
|
|
|
147
124
|
|
|
148
125
|
return result;
|
|
149
126
|
}
|
|
127
|
+
async _executeExecutionListener(eventName, elementApi) {
|
|
128
|
+
const routingKey = 'run.listener.' + eventName;
|
|
129
|
+
const endRoutingKey = routingKey + '.complete';
|
|
130
|
+
|
|
131
|
+
this.formatQ.queueMessage({ routingKey }, { endRoutingKey }, { persistent: false });
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
var format = await this.extensions.listeners.execute(eventName, elementApi);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
return elementApi.broker.publish('format', routingKey + '.error', { error: err }, { persistent: false });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
elementApi.broker.publish('format', endRoutingKey, { ...format }, { persistent: false });
|
|
140
|
+
}
|
|
150
141
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OnifyElementExtensions } from './OnifyElementExtensions.js';
|
|
2
|
+
|
|
3
|
+
export class OnifySubProcessExtensions extends OnifyElementExtensions {
|
|
4
|
+
constructor(activity, context) {
|
|
5
|
+
super(activity, context);
|
|
6
|
+
}
|
|
7
|
+
activate(runMessage) {
|
|
8
|
+
const activity = this.activity;
|
|
9
|
+
const broker = activity.broker;
|
|
10
|
+
const executionListeners = this.extensions.listeners;
|
|
11
|
+
|
|
12
|
+
if (runMessage.fields.redelivered && runMessage.fields.routingKey === 'run.start') {
|
|
13
|
+
this._setupListener(broker, 'activity.start', (elementApi) => {
|
|
14
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
15
|
+
}, '_onify-extension-on-enter');
|
|
16
|
+
} else {
|
|
17
|
+
this._setupListener(broker, 'activity.enter', (elementApi) => {
|
|
18
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
19
|
+
}, '_onify-extension-on-enter');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this._setupListener(broker, 'activity.execution.completed', (elementApi) => {
|
|
23
|
+
return this._onExecutionCompleted(elementApi);
|
|
24
|
+
}, '_onify-extension-on-executed');
|
|
25
|
+
|
|
26
|
+
if (executionListeners?.onStart) {
|
|
27
|
+
this._setupListener(broker, 'activity.start', (elementApi) => {
|
|
28
|
+
this._executeExecutionListener('start', elementApi);
|
|
29
|
+
}, '_onify-extension-on-listenerstart');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (executionListeners?.onEnd) {
|
|
33
|
+
this._setupListener(broker, 'activity.end', (elementApi) => {
|
|
34
|
+
this._executeExecutionListener('end', elementApi);
|
|
35
|
+
}, '_onify-extension-on-listenerend');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_setupListener(broker, routingKey, callback, consumerTag) {
|
|
39
|
+
const activity = this.activity;
|
|
40
|
+
broker.subscribeTmp('event', routingKey, (_, message) => {
|
|
41
|
+
if (activity.id !== message.content.id) return;
|
|
42
|
+
|
|
43
|
+
return callback(activity.getApi(message));
|
|
44
|
+
}, { noAck: true, consumerTag });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TimerEventDefinition } from 'bpmn-elements';
|
|
2
|
+
import cronParser from 'cron-parser';
|
|
3
|
+
|
|
4
|
+
export class OnifyTimerEventDefinition extends TimerEventDefinition {
|
|
5
|
+
constructor(activity, def) {
|
|
6
|
+
super(activity, def);
|
|
7
|
+
Object.defineProperty(this, 'supports', {
|
|
8
|
+
value: ['cron'],
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
parse(timerType, value) {
|
|
12
|
+
let cron;
|
|
13
|
+
if (timerType === 'timeCycle' && (cron = cronParser.parseString(value))) {
|
|
14
|
+
if (cron.expressions?.length) {
|
|
15
|
+
// cronParser.parseString expressions disregards seconds, so we have to parse again
|
|
16
|
+
const expireAt = cronParser.parseExpression(value).next().toDate();
|
|
17
|
+
return {
|
|
18
|
+
expireAt,
|
|
19
|
+
delay: expireAt - Date.now(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return super.parse(timerType, value);
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/formatters.js
CHANGED
|
@@ -10,6 +10,7 @@ export class FormatActivity {
|
|
|
10
10
|
let timeCycles;
|
|
11
11
|
if (activity.eventDefinitions) {
|
|
12
12
|
for (const ed of activity.eventDefinitions.filter((e) => e.type === 'bpmn:TimerEventDefinition')) {
|
|
13
|
+
if (ed.supports?.includes('cron')) continue;
|
|
13
14
|
if (!('timeCycle' in ed)) continue;
|
|
14
15
|
timeCycles = timeCycles || [];
|
|
15
16
|
timeCycles.push(ed.timeCycle);
|
package/src/index.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {OnifyProcessExtensions} from './OnifyProcessExtensions.js';
|
|
2
|
-
import {OnifyElementExtensions} from './OnifyElementExtensions.js';
|
|
3
|
-
import {
|
|
1
|
+
import { OnifyProcessExtensions } from './OnifyProcessExtensions.js';
|
|
2
|
+
import { OnifyElementExtensions } from './OnifyElementExtensions.js';
|
|
3
|
+
import { OnifyBoundaryEventExtensions } from './OnifyBoundaryEventExtensions.js';
|
|
4
|
+
import { OnifySubProcessExtensions } from './OnifySubProcessExtensions.js';
|
|
4
5
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
extendFn,
|
|
8
|
-
OnifySequenceFlow,
|
|
9
|
-
};
|
|
6
|
+
export { OnifySequenceFlow } from './OnifySequenceFlow.js';
|
|
7
|
+
export { OnifyTimerEventDefinition } from './OnifyTimerEventDefinition.js';
|
|
10
8
|
|
|
11
|
-
function extensions(element, context) {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export function extensions(element, context) {
|
|
10
|
+
switch (element.type) {
|
|
11
|
+
case 'bpmn:Process':
|
|
12
|
+
return new OnifyProcessExtensions(element, context);
|
|
13
|
+
case 'bpmn:SubProcess':
|
|
14
|
+
case 'bpmn:Transaction':
|
|
15
|
+
return new OnifySubProcessExtensions(element, context);
|
|
16
|
+
case 'bpmn:BoundaryEvent':
|
|
17
|
+
return new OnifyBoundaryEventExtensions(element, context);
|
|
18
|
+
default:
|
|
19
|
+
return new OnifyElementExtensions(element, context);
|
|
20
|
+
}
|
|
14
21
|
}
|
|
15
22
|
|
|
16
|
-
function extendFn(behaviour, context) {
|
|
23
|
+
export function extendFn(behaviour, context) {
|
|
17
24
|
if (behaviour.$type === 'bpmn:StartEvent' && behaviour.eventDefinitions) {
|
|
18
25
|
const timer = behaviour.eventDefinitions.find(({type, behaviour: edBehaviour}) => edBehaviour && type === 'bpmn:TimerEventDefinition');
|
|
19
26
|
if (timer && timer.behaviour.timeCycle) Object.assign(behaviour, {scheduledStart: timer.behaviour.timeCycle});
|