@onify/flow-extensions 7.0.0 → 8.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/README.md +9 -10
- package/dist/Connector.js +1 -1
- package/dist/ExecutionListeners.js +1 -1
- package/dist/FlowScripts.js +1 -1
- package/dist/OnifyBoundaryEventExtensions.js +3 -4
- package/dist/OnifyElementExtensions.js +5 -6
- package/dist/OnifyScriptTask.js +3 -0
- package/dist/OnifySequenceFlow.js +13 -4
- package/dist/OnifySubProcessExtensions.js +2 -2
- package/dist/OnifyTimerEventDefinition.js +2 -3
- package/dist/formatters.js +14 -26
- package/dist/getExtensions.js +3 -4
- package/dist/index.js +47 -10
- package/package.json +15 -14
- package/src/Connector.js +3 -3
- package/src/Errors.js +2 -2
- package/src/ExecutionListeners.js +8 -12
- package/src/IO.js +13 -13
- package/src/IOForm.js +4 -4
- package/src/IOProperties.js +1 -1
- package/src/OnifyBoundaryEventExtensions.js +77 -65
- package/src/OnifyElementExtensions.js +153 -141
- package/src/OnifyProcessExtensions.js +49 -40
- package/src/OnifySequenceFlow.js +23 -7
- package/src/OnifySubProcessExtensions.js +76 -46
- package/src/OnifyTimerEventDefinition.js +3 -1
- package/src/ServiceExpression.js +1 -1
- package/src/formatters.js +76 -98
- package/src/getExtensions.js +57 -57
- package/src/index.js +45 -10
- package/CHANGELOG.md +0 -70
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
Onify Flow Extensions
|
|
2
|
-
=====================
|
|
1
|
+
# Onify Flow Extensions
|
|
3
2
|
|
|
4
3
|
[](https://github.com/onify/flow-extensions/actions/workflows/build-latest.yaml)[](https://coveralls.io/github/onify/flow-extensions?branch=default)
|
|
5
4
|
|
|
@@ -13,8 +12,8 @@ Onify Flow Extensions
|
|
|
13
12
|
## Bpmn engine example
|
|
14
13
|
|
|
15
14
|
```js
|
|
16
|
-
const {Engine} = require('bpmn-engine');
|
|
17
|
-
const {extensions} = require('@onify/flow-extensions');
|
|
15
|
+
const { Engine } = require('bpmn-engine');
|
|
16
|
+
const { extensions } = require('@onify/flow-extensions');
|
|
18
17
|
const FlowScripts = require('@onify/flow-extensions/dist/src/FlowScripts');
|
|
19
18
|
|
|
20
19
|
const source = `
|
|
@@ -41,8 +40,8 @@ const engine = new Engine({
|
|
|
41
40
|
},
|
|
42
41
|
services: {
|
|
43
42
|
serviceFn(scope, callback) {
|
|
44
|
-
callback(null, {data: 1});
|
|
45
|
-
}
|
|
43
|
+
callback(null, { data: 1 });
|
|
44
|
+
},
|
|
46
45
|
},
|
|
47
46
|
extensions: {
|
|
48
47
|
onify: extensions,
|
|
@@ -63,11 +62,11 @@ engine.execute((err, instance) => {
|
|
|
63
62
|
## Extract scripts with extend function
|
|
64
63
|
|
|
65
64
|
```js
|
|
66
|
-
const {extendFn} = require('@onify/flow-extensions');
|
|
65
|
+
const { extendFn } = require('@onify/flow-extensions');
|
|
67
66
|
|
|
68
67
|
const BpmnModdle = require('bpmn-moddle');
|
|
69
68
|
const Elements = require('bpmn-elements');
|
|
70
|
-
const {default: Serializer, TypeResolver} = require('moddle-context-serializer');
|
|
69
|
+
const { default: Serializer, TypeResolver } = require('moddle-context-serializer');
|
|
71
70
|
|
|
72
71
|
const source = `
|
|
73
72
|
<definitions id="Def_0" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
@@ -124,9 +123,9 @@ function getModdleContext(source, options) {
|
|
|
124
123
|
## Extend sequence flow with properties and take listeners
|
|
125
124
|
|
|
126
125
|
```js
|
|
127
|
-
const {OnifySequenceFlow, extensions} = require('@onify/flow-extensions');
|
|
126
|
+
const { OnifySequenceFlow, extensions } = require('@onify/flow-extensions');
|
|
128
127
|
const FlowScripts = require('@onify/flow-extensions/dist/src/FlowScripts');
|
|
129
|
-
const {Engine} = require('bpmn-engine');
|
|
128
|
+
const { Engine } = require('bpmn-engine');
|
|
130
129
|
const Elements = require('bpmn-elements');
|
|
131
130
|
|
|
132
131
|
const source = `
|
package/dist/Connector.js
CHANGED
|
@@ -30,7 +30,7 @@ Connector.prototype.execute = async function execute(...args) {
|
|
|
30
30
|
}
|
|
31
31
|
async function formatCallback(serviceErr, result) {
|
|
32
32
|
if (serviceErr) return callback(serviceErr);
|
|
33
|
-
if (!
|
|
33
|
+
if (!io?.output.length) return callback(null, result);
|
|
34
34
|
try {
|
|
35
35
|
const formattedResult = await io.getOutput(activity, {
|
|
36
36
|
...executionMessage,
|
package/dist/FlowScripts.js
CHANGED
|
@@ -105,7 +105,7 @@ FlowScripts.prototype.getScript = function getScript(scriptType, {
|
|
|
105
105
|
function JavaScript(flowName, scriptBody, runContext, options) {
|
|
106
106
|
this.flowName = flowName;
|
|
107
107
|
this._runContext = runContext;
|
|
108
|
-
this.timeout = options
|
|
108
|
+
this.timeout = options?.timeout;
|
|
109
109
|
try {
|
|
110
110
|
this.script = new _vm.Script(scriptBody, options);
|
|
111
111
|
} catch (err) {
|
|
@@ -28,7 +28,7 @@ class OnifyBoundaryEventExtensions extends _OnifyElementExtensions.OnifyElementE
|
|
|
28
28
|
}, {
|
|
29
29
|
consumerTag: '_onify-extension-on-executed'
|
|
30
30
|
});
|
|
31
|
-
if (executionListeners
|
|
31
|
+
if (executionListeners?.onStart) {
|
|
32
32
|
activity.on('start', async elementApi => {
|
|
33
33
|
try {
|
|
34
34
|
await executionListeners.execute('start', elementApi);
|
|
@@ -39,7 +39,7 @@ class OnifyBoundaryEventExtensions extends _OnifyElementExtensions.OnifyElementE
|
|
|
39
39
|
consumerTag: '_onify-extension-on-listenerstart'
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
if (executionListeners
|
|
42
|
+
if (executionListeners?.onEnd) {
|
|
43
43
|
activity.on('end', elementApi => {
|
|
44
44
|
this._executeExecutionListener('end', elementApi, formatQ);
|
|
45
45
|
}, {
|
|
@@ -62,7 +62,6 @@ class OnifyBoundaryEventExtensions extends _OnifyElementExtensions.OnifyElementE
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
_onEnterSync(elementApi) {
|
|
65
|
-
var _io$output;
|
|
66
65
|
const {
|
|
67
66
|
format,
|
|
68
67
|
properties,
|
|
@@ -77,7 +76,7 @@ class OnifyBoundaryEventExtensions extends _OnifyElementExtensions.OnifyElementE
|
|
|
77
76
|
});
|
|
78
77
|
Object.assign(elementApi.content, result);
|
|
79
78
|
}
|
|
80
|
-
if (io
|
|
79
|
+
if (io?.output?.length) {
|
|
81
80
|
result.assignToOutput = true;
|
|
82
81
|
}
|
|
83
82
|
return result;
|
|
@@ -35,14 +35,14 @@ class OnifyElementExtensions {
|
|
|
35
35
|
}, {
|
|
36
36
|
consumerTag: '_onify-extension-on-executed'
|
|
37
37
|
});
|
|
38
|
-
if (executionListeners
|
|
38
|
+
if (executionListeners?.onStart) {
|
|
39
39
|
activity.on('start', elementApi => {
|
|
40
40
|
this._executeExecutionListener('start', elementApi);
|
|
41
41
|
}, {
|
|
42
42
|
consumerTag: '_onify-extension-on-listenerstart'
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
if (executionListeners
|
|
45
|
+
if (executionListeners?.onEnd) {
|
|
46
46
|
activity.on('end', elementApi => {
|
|
47
47
|
this._executeExecutionListener('end', elementApi);
|
|
48
48
|
}, {
|
|
@@ -118,15 +118,14 @@ class OnifyElementExtensions {
|
|
|
118
118
|
Object.assign(elementApi.content, result);
|
|
119
119
|
}
|
|
120
120
|
if (io) {
|
|
121
|
-
|
|
122
|
-
if ((_io$input = io.input) !== null && _io$input !== void 0 && _io$input.length) {
|
|
121
|
+
if (io.input?.length) {
|
|
123
122
|
const input = await io.getInput(this.activity, elementApi);
|
|
124
123
|
Object.assign(result, {
|
|
125
124
|
input
|
|
126
125
|
});
|
|
127
126
|
Object.assign(elementApi.content, result);
|
|
128
127
|
}
|
|
129
|
-
if (
|
|
128
|
+
if (io.output?.length) {
|
|
130
129
|
result.assignToOutput = true;
|
|
131
130
|
}
|
|
132
131
|
}
|
|
@@ -143,7 +142,7 @@ class OnifyElementExtensions {
|
|
|
143
142
|
io
|
|
144
143
|
} = this.extensions;
|
|
145
144
|
const result = {};
|
|
146
|
-
if (io
|
|
145
|
+
if (io?.output.length) {
|
|
147
146
|
const output = await io.getOutput(this.activity, elementApi);
|
|
148
147
|
Object.assign(result, {
|
|
149
148
|
output
|
|
@@ -13,8 +13,7 @@ class OnifySequenceFlow extends _bpmnElements.SequenceFlow {
|
|
|
13
13
|
this._activate();
|
|
14
14
|
}
|
|
15
15
|
_activate() {
|
|
16
|
-
|
|
17
|
-
if (!((_this$extensions$list = this.extensions.listeners) !== null && _this$extensions$list !== void 0 && _this$extensions$list.onTake)) return;
|
|
16
|
+
if (!this.extensions.listeners?.onTake) return;
|
|
18
17
|
this.broker.subscribeTmp('event', 'flow.take', (_, msg) => {
|
|
19
18
|
this._executeListeners(msg);
|
|
20
19
|
}, {
|
|
@@ -32,14 +31,24 @@ class OnifySequenceFlow extends _bpmnElements.SequenceFlow {
|
|
|
32
31
|
evaluate(fromMessage, callback) {
|
|
33
32
|
const properties = this.extensions.properties;
|
|
34
33
|
if (!properties) return super.evaluate(fromMessage, callback);
|
|
35
|
-
|
|
34
|
+
try {
|
|
35
|
+
const preProperties = properties.resolve(this.getApi(fromMessage));
|
|
36
|
+
var evaluateMessage = fromMessage;
|
|
37
|
+
evaluateMessage.content.properties = {
|
|
38
|
+
...fromMessage.content.properties,
|
|
39
|
+
...preProperties
|
|
40
|
+
};
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return callback(err);
|
|
43
|
+
}
|
|
44
|
+
super.evaluate(evaluateMessage, (err, result) => {
|
|
36
45
|
if (err) return callback(err);
|
|
37
46
|
try {
|
|
38
47
|
let overriddenResult = result ? {} : false;
|
|
39
48
|
if (result) {
|
|
40
49
|
overriddenResult = {
|
|
41
50
|
...(typeof result === 'object' && result),
|
|
42
|
-
properties: properties.resolve(this.getApi(
|
|
51
|
+
properties: properties.resolve(this.getApi(evaluateMessage))
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
return callback(err, overriddenResult);
|
|
@@ -25,12 +25,12 @@ class OnifySubProcessExtensions extends _OnifyElementExtensions.OnifyElementExte
|
|
|
25
25
|
this._setupListener(broker, 'activity.execution.completed', elementApi => {
|
|
26
26
|
return this._onExecutionCompleted(elementApi);
|
|
27
27
|
}, '_onify-extension-on-executed');
|
|
28
|
-
if (executionListeners
|
|
28
|
+
if (executionListeners?.onStart) {
|
|
29
29
|
this._setupListener(broker, 'activity.start', elementApi => {
|
|
30
30
|
this._executeExecutionListener('start', elementApi);
|
|
31
31
|
}, '_onify-extension-on-listenerstart');
|
|
32
32
|
}
|
|
33
|
-
if (executionListeners
|
|
33
|
+
if (executionListeners?.onEnd) {
|
|
34
34
|
this._setupListener(broker, 'activity.end', elementApi => {
|
|
35
35
|
this._executeExecutionListener('end', elementApi);
|
|
36
36
|
}, '_onify-extension-on-listenerend');
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.OnifyTimerEventDefinition = void 0;
|
|
7
|
-
var _bpmnElements = require("bpmn-elements");
|
|
8
7
|
var _cronParser = _interopRequireDefault(require("cron-parser"));
|
|
8
|
+
var _bpmnElements = require("bpmn-elements");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
|
|
11
11
|
constructor(activity, def) {
|
|
@@ -17,8 +17,7 @@ class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
|
|
|
17
17
|
parse(timerType, value) {
|
|
18
18
|
let cron;
|
|
19
19
|
if (timerType === 'timeCycle' && (cron = _cronParser.default.parseString(value))) {
|
|
20
|
-
|
|
21
|
-
if ((_cron$expressions = cron.expressions) !== null && _cron$expressions !== void 0 && _cron$expressions.length) {
|
|
20
|
+
if (cron.expressions?.length) {
|
|
22
21
|
// cronParser.parseString expressions disregards seconds, so we have to parse again
|
|
23
22
|
const expireAt = _cronParser.default.parseExpression(value).next().toDate();
|
|
24
23
|
return {
|
package/dist/formatters.js
CHANGED
|
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FormatProcess = exports.FormatActivity = void 0;
|
|
7
|
-
var _cronParser = _interopRequireDefault(require("cron-parser"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const iso8601cycle = /^\s*(R\d+\/)?P\w+/i;
|
|
10
7
|
class FormatActivity {
|
|
11
8
|
constructor(activity) {
|
|
12
9
|
this.activity = activity;
|
|
@@ -14,8 +11,7 @@ class FormatActivity {
|
|
|
14
11
|
let timeCycles;
|
|
15
12
|
if (activity.eventDefinitions) {
|
|
16
13
|
for (const ed of activity.eventDefinitions.filter(e => e.type === 'bpmn:TimerEventDefinition')) {
|
|
17
|
-
|
|
18
|
-
if ((_ed$supports = ed.supports) !== null && _ed$supports !== void 0 && _ed$supports.includes('cron')) continue;
|
|
14
|
+
if (!ed.supports?.includes('cron')) continue;
|
|
19
15
|
if (!('timeCycle' in ed)) continue;
|
|
20
16
|
timeCycles = timeCycles || [];
|
|
21
17
|
timeCycles.push(ed.timeCycle);
|
|
@@ -24,7 +20,6 @@ class FormatActivity {
|
|
|
24
20
|
this.timeCycles = timeCycles;
|
|
25
21
|
}
|
|
26
22
|
resolve(elementApi) {
|
|
27
|
-
var _documentation$, _user, _groups;
|
|
28
23
|
let user, groups, assigneeValue, description;
|
|
29
24
|
const activity = this.activity;
|
|
30
25
|
const {
|
|
@@ -37,17 +32,7 @@ class FormatActivity {
|
|
|
37
32
|
if (candidateUsers) user = resolveAndSplit(elementApi, candidateUsers);
|
|
38
33
|
if (candidateGroups) groups = resolveAndSplit(elementApi, candidateGroups);
|
|
39
34
|
if (assignee) assigneeValue = elementApi.resolveExpression(assignee);
|
|
40
|
-
if (documentation) description =
|
|
41
|
-
let expireAt;
|
|
42
|
-
const timeCycles = this.timeCycles;
|
|
43
|
-
if (timeCycles) {
|
|
44
|
-
for (const cycle of timeCycles) {
|
|
45
|
-
const cron = elementApi.resolveExpression(cycle);
|
|
46
|
-
if (!cron || iso8601cycle.test(cron)) continue;
|
|
47
|
-
const expireAtDt = _cronParser.default.parseExpression(cron).next().toDate();
|
|
48
|
-
if (!expireAt || expireAtDt < expireAt) expireAt = expireAtDt;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
35
|
+
if (documentation) description = documentation[0]?.text;
|
|
51
36
|
return {
|
|
52
37
|
...(this.resultVariable && {
|
|
53
38
|
resultVariable: this.resultVariable
|
|
@@ -55,18 +40,15 @@ class FormatActivity {
|
|
|
55
40
|
...(scheduledStart && activity.parent.type === 'bpmn:Process' && {
|
|
56
41
|
scheduledStart
|
|
57
42
|
}),
|
|
58
|
-
...(
|
|
43
|
+
...(user?.length && {
|
|
59
44
|
candidateUsers: user
|
|
60
45
|
}),
|
|
61
|
-
...(
|
|
46
|
+
...(groups?.length && {
|
|
62
47
|
candidateGroups: groups
|
|
63
48
|
}),
|
|
64
49
|
...(!elementApi.content.description && description && {
|
|
65
50
|
description: elementApi.resolveExpression(description)
|
|
66
51
|
}),
|
|
67
|
-
...(expireAt && {
|
|
68
|
-
expireAt
|
|
69
|
-
}),
|
|
70
52
|
...(assigneeValue && {
|
|
71
53
|
assignee: assigneeValue
|
|
72
54
|
})
|
|
@@ -77,9 +59,12 @@ exports.FormatActivity = FormatActivity;
|
|
|
77
59
|
class FormatProcess {
|
|
78
60
|
constructor(bp) {
|
|
79
61
|
this.process = bp;
|
|
62
|
+
this._historyTTL = undefined;
|
|
63
|
+
if (bp.behaviour.historyTimeToLive) {
|
|
64
|
+
this._historyTTL = bp.context.definitionContext.getTimersByElementId(bp.id).find(t => t.timer.type === 'historyTimeToLive');
|
|
65
|
+
}
|
|
80
66
|
}
|
|
81
67
|
resolve(elementApi) {
|
|
82
|
-
var _documentation$2, _user2, _groups2;
|
|
83
68
|
let user, groups, description;
|
|
84
69
|
const bp = this.process;
|
|
85
70
|
const {
|
|
@@ -89,16 +74,19 @@ class FormatProcess {
|
|
|
89
74
|
} = bp.behaviour;
|
|
90
75
|
if (candidateStarterUsers) user = resolveAndSplit(elementApi, candidateStarterUsers);
|
|
91
76
|
if (candidateStarterGroups) groups = resolveAndSplit(elementApi, candidateStarterGroups);
|
|
92
|
-
if (documentation) description =
|
|
77
|
+
if (documentation) description = documentation[0]?.text;
|
|
93
78
|
return {
|
|
94
|
-
...(
|
|
79
|
+
...(user?.length && {
|
|
95
80
|
candidateStarterUsers: user
|
|
96
81
|
}),
|
|
97
|
-
...(
|
|
82
|
+
...(groups?.length && {
|
|
98
83
|
candidateStarterGroups: groups
|
|
99
84
|
}),
|
|
100
85
|
...(!elementApi.content.description && description && {
|
|
101
86
|
description: elementApi.resolveExpression(description)
|
|
87
|
+
}),
|
|
88
|
+
...(this._historyTTL && {
|
|
89
|
+
historyTimeToLive: this._historyTTL.timer.value
|
|
102
90
|
})
|
|
103
91
|
};
|
|
104
92
|
}
|
package/dist/getExtensions.js
CHANGED
|
@@ -13,7 +13,6 @@ var _IOProperties = _interopRequireDefault(require("./IOProperties.js"));
|
|
|
13
13
|
var _ServiceExpression = _interopRequireDefault(require("./ServiceExpression.js"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
function getExtensions(element, context) {
|
|
16
|
-
var _element$behaviour$ex, _ext$values, _ext$fields;
|
|
17
16
|
const result = {};
|
|
18
17
|
switch (element.type) {
|
|
19
18
|
case 'bpmn:SequenceFlow':
|
|
@@ -28,18 +27,18 @@ function getExtensions(element, context) {
|
|
|
28
27
|
const listeners = new _ExecutionListeners.default(element, context);
|
|
29
28
|
const expression = element.behaviour.expression;
|
|
30
29
|
if (expression) result.Service = _ServiceExpression.default;
|
|
31
|
-
const extensions =
|
|
30
|
+
const extensions = element.behaviour.extensionElements?.values;
|
|
32
31
|
if (extensions) {
|
|
33
32
|
for (const ext of extensions) {
|
|
34
33
|
switch (ext.$type) {
|
|
35
34
|
case 'camunda:Properties':
|
|
36
|
-
if (
|
|
35
|
+
if (ext.values?.length) result.properties = new _IOProperties.default(element, ext);
|
|
37
36
|
break;
|
|
38
37
|
case 'camunda:InputOutput':
|
|
39
38
|
result.io = new _IO.InputOutput(element.id, ext, context);
|
|
40
39
|
break;
|
|
41
40
|
case 'camunda:FormData':
|
|
42
|
-
if (
|
|
41
|
+
if (ext.fields?.length) result.form = new _IOForm.default(element, ext);
|
|
43
42
|
break;
|
|
44
43
|
case 'camunda:Connector':
|
|
45
44
|
{
|
package/dist/index.js
CHANGED
|
@@ -37,17 +37,33 @@ function extensions(element, context) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
function extendFn(behaviour, context) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
switch (behaviour.$type) {
|
|
41
|
+
case 'bpmn:StartEvent':
|
|
42
|
+
{
|
|
43
|
+
if (!behaviour.eventDefinitions) break;
|
|
44
|
+
const timer = behaviour.eventDefinitions.find(({
|
|
45
|
+
type,
|
|
46
|
+
behaviour: edBehaviour
|
|
47
|
+
}) => edBehaviour && type === 'bpmn:TimerEventDefinition');
|
|
48
|
+
if (timer && timer.behaviour.timeCycle) Object.assign(behaviour, {
|
|
49
|
+
scheduledStart: timer.behaviour.timeCycle
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'bpmn:Process':
|
|
54
|
+
{
|
|
55
|
+
if (!behaviour.isExecutable) break;
|
|
56
|
+
const {
|
|
57
|
+
historyTimeToLive,
|
|
58
|
+
isExecutable
|
|
59
|
+
} = behaviour;
|
|
60
|
+
if (historyTimeToLive && isExecutable) {
|
|
61
|
+
context.addTimer(behaviour.id + ':historyTimeToLive', getHistoryTimeToLiveTimer(behaviour));
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
|
-
if (!Array.isArray(
|
|
66
|
+
if (!Array.isArray(behaviour.extensionElements?.values)) return;
|
|
51
67
|
let listener = 0;
|
|
52
68
|
for (const extension of behaviour.extensionElements.values) {
|
|
53
69
|
switch (extension.$type) {
|
|
@@ -109,4 +125,25 @@ function registerListenerScript(parentId, context, type, listener, pos) {
|
|
|
109
125
|
resource: script.resource
|
|
110
126
|
})
|
|
111
127
|
});
|
|
128
|
+
}
|
|
129
|
+
function getHistoryTimeToLiveTimer(behaviour) {
|
|
130
|
+
const {
|
|
131
|
+
id,
|
|
132
|
+
$type: type,
|
|
133
|
+
historyTimeToLive
|
|
134
|
+
} = behaviour;
|
|
135
|
+
let value = historyTimeToLive;
|
|
136
|
+
if (/^\d+$/.test(historyTimeToLive)) {
|
|
137
|
+
value = `P${historyTimeToLive}D`;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
id: `${type}/${id}:historyTimeToLive`,
|
|
141
|
+
type: 'historyTimeToLive',
|
|
142
|
+
timerType: 'timeDuration',
|
|
143
|
+
value,
|
|
144
|
+
parent: {
|
|
145
|
+
id,
|
|
146
|
+
type
|
|
147
|
+
}
|
|
148
|
+
};
|
|
112
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onify/flow-extensions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Onify Flow extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "mocha -R dot",
|
|
16
16
|
"posttest": "npm run lint && npm run dist",
|
|
17
|
-
"lint": "eslint . --cache",
|
|
17
|
+
"lint": "eslint . --cache && prettier . --check --cache",
|
|
18
18
|
"prepare": "npm run dist",
|
|
19
19
|
"dist": "babel src -d dist && babel test/helpers/FlowScripts.js -d dist",
|
|
20
20
|
"test:lcov": "c8 -r lcov mocha && npm run lint",
|
|
@@ -38,29 +38,30 @@
|
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@aircall/expression-parser": "^1.0.4",
|
|
41
|
-
"@babel/cli": "^7.23.
|
|
42
|
-
"@babel/core": "^7.23.
|
|
43
|
-
"@babel/preset-env": "^7.23.
|
|
44
|
-
"@babel/register": "^7.
|
|
41
|
+
"@babel/cli": "^7.23.9",
|
|
42
|
+
"@babel/core": "^7.23.9",
|
|
43
|
+
"@babel/preset-env": "^7.23.9",
|
|
44
|
+
"@babel/register": "^7.23.7",
|
|
45
45
|
"bpmn-elements-8-1": "npm:bpmn-elements@8.1",
|
|
46
|
-
"bpmn-engine": "^
|
|
46
|
+
"bpmn-engine": "^20.0.1",
|
|
47
47
|
"bpmn-engine-14": "npm:bpmn-engine@14",
|
|
48
|
-
"bpmn-moddle": "^
|
|
49
|
-
"c8": "^
|
|
48
|
+
"bpmn-moddle": "^9.0.1",
|
|
49
|
+
"c8": "^9.1.0",
|
|
50
50
|
"camunda-bpmn-moddle": "^7.0.1",
|
|
51
|
-
"chai": "^
|
|
51
|
+
"chai": "^5.0.3",
|
|
52
52
|
"chronokinesis": "^6.0.0",
|
|
53
53
|
"debug": "^4.3.4",
|
|
54
|
-
"eslint": "^
|
|
55
|
-
"eslint-plugin-import": "^2.29.1",
|
|
54
|
+
"eslint": "^9.0.0",
|
|
56
55
|
"mocha": "^10.2.0",
|
|
57
56
|
"mocha-cakes-2": "^3.3.0",
|
|
58
|
-
"moddle-context-serializer": "^4.1.1"
|
|
57
|
+
"moddle-context-serializer": "^4.1.1",
|
|
58
|
+
"prettier": "^3.2.4"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"bpmn-elements": "
|
|
61
|
+
"bpmn-elements": "^14.0.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
+
"@0dep/piso": "^0.1.3",
|
|
64
65
|
"cron-parser": "^4.9.0"
|
|
65
66
|
},
|
|
66
67
|
"files": [
|
package/src/Connector.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {NotImplemented} from './Errors.js';
|
|
1
|
+
import { NotImplemented } from './Errors.js';
|
|
2
2
|
|
|
3
3
|
export default function Connector(connectorId, io, activity, executionMessage) {
|
|
4
4
|
if (!(this instanceof Connector)) return new Connector(connectorId, io, activity, executionMessage);
|
|
@@ -22,7 +22,7 @@ Connector.prototype.execute = async function execute(...args) {
|
|
|
22
22
|
if (!serviceFunction) return callback(new NotImplemented(connectorId));
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
const input = io && await io.getInput(activity, executionMessage);
|
|
25
|
+
const input = io && (await io.getInput(activity, executionMessage));
|
|
26
26
|
await serviceFunction.call(activity, input, ...args);
|
|
27
27
|
} catch (err) {
|
|
28
28
|
return callback(err);
|
|
@@ -33,7 +33,7 @@ Connector.prototype.execute = async function execute(...args) {
|
|
|
33
33
|
if (!io?.output.length) return callback(null, result);
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
|
-
const formattedResult = await io.getOutput(activity, {...executionMessage, ...result});
|
|
36
|
+
const formattedResult = await io.getOutput(activity, { ...executionMessage, ...result });
|
|
37
37
|
return callback(null, formattedResult);
|
|
38
38
|
} catch (err) {
|
|
39
39
|
return callback(err);
|
package/src/Errors.js
CHANGED
|
@@ -2,7 +2,7 @@ export class NotImplemented extends Error {
|
|
|
2
2
|
constructor(serviceId) {
|
|
3
3
|
super(`${serviceId} service function not found`);
|
|
4
4
|
this.code = 'EFLOW_NOT_IMPLEMENTED';
|
|
5
|
-
this.output = {statusCode: 501};
|
|
5
|
+
this.output = { statusCode: 501 };
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -10,6 +10,6 @@ export class FormatError extends Error {
|
|
|
10
10
|
constructor(elementId, err) {
|
|
11
11
|
super(`<${elementId}> ${err.message}`);
|
|
12
12
|
this.code = 'EFLOW_FORMAT';
|
|
13
|
-
this.output = {statusCode: 500};
|
|
13
|
+
this.output = { statusCode: 500 };
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -10,7 +10,7 @@ class Listener {
|
|
|
10
10
|
_getScope(message, extend) {
|
|
11
11
|
const environment = this.environment;
|
|
12
12
|
|
|
13
|
-
const {fields, content, properties} = message;
|
|
13
|
+
const { fields, content, properties } = message;
|
|
14
14
|
const scope = {
|
|
15
15
|
...extend,
|
|
16
16
|
type: this.type,
|
|
@@ -33,7 +33,7 @@ class Listener {
|
|
|
33
33
|
const fields = this.extension.fields;
|
|
34
34
|
if (!fields?.length) return;
|
|
35
35
|
const result = {};
|
|
36
|
-
for (const {name, expression, string} of fields) {
|
|
36
|
+
for (const { name, expression, string } of fields) {
|
|
37
37
|
result['' + name] = expression ? environment.resolveExpression(expression, scope) : string;
|
|
38
38
|
}
|
|
39
39
|
return result;
|
|
@@ -43,15 +43,15 @@ class Listener {
|
|
|
43
43
|
class ScriptListener extends Listener {
|
|
44
44
|
constructor(activity, context, extension, pos) {
|
|
45
45
|
super(activity, context, extension);
|
|
46
|
-
const id = this.id = `${activity.id}/${extension.script.$type}/${this.event}/${pos}
|
|
46
|
+
const id = (this.id = `${activity.id}/${extension.script.$type}/${this.event}/${pos}`);
|
|
47
47
|
this._register(context, id, extension.script);
|
|
48
48
|
}
|
|
49
49
|
execute(api) {
|
|
50
50
|
const environment = this.environment;
|
|
51
|
-
const scope = this._getScope(api, {id: this.id, resolveExpression});
|
|
51
|
+
const scope = this._getScope(api, { id: this.id, resolveExpression });
|
|
52
52
|
const listenerFields = this._getFields(environment, scope);
|
|
53
53
|
if (listenerFields) scope.listener.fields = listenerFields;
|
|
54
|
-
const script = this.environment.scripts.getScript(this.extension.scriptFormat, {id: this.id});
|
|
54
|
+
const script = this.environment.scripts.getScript(this.extension.scriptFormat, { id: this.id });
|
|
55
55
|
|
|
56
56
|
return new Promise((resolve, reject) => {
|
|
57
57
|
return script.execute(scope, (err, result) => {
|
|
@@ -65,11 +65,7 @@ class ScriptListener extends Listener {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
_register(context, id, script) {
|
|
68
|
-
const {
|
|
69
|
-
scriptFormat,
|
|
70
|
-
value,
|
|
71
|
-
resource,
|
|
72
|
-
} = script;
|
|
68
|
+
const { scriptFormat, value, resource } = script;
|
|
73
69
|
|
|
74
70
|
context.environment.scripts.register({
|
|
75
71
|
id,
|
|
@@ -90,7 +86,7 @@ class ScriptListener extends Listener {
|
|
|
90
86
|
class ExpressionListener extends Listener {
|
|
91
87
|
execute(message) {
|
|
92
88
|
const scope = this._getScope(message);
|
|
93
|
-
return {expression: this.environment.resolveExpression(this.extension.expression, scope)};
|
|
89
|
+
return { expression: this.environment.resolveExpression(this.extension.expression, scope) };
|
|
94
90
|
}
|
|
95
91
|
}
|
|
96
92
|
|
|
@@ -113,7 +109,7 @@ export default class ExecutionListeners {
|
|
|
113
109
|
return this.listeners.some((l) => l.event === 'take');
|
|
114
110
|
}
|
|
115
111
|
add(extension, pos) {
|
|
116
|
-
const {script, expression} = extension;
|
|
112
|
+
const { script, expression } = extension;
|
|
117
113
|
if (!script && !expression) return;
|
|
118
114
|
|
|
119
115
|
const list = this.listeners;
|