@onify/flow-extensions 7.0.0 → 7.1.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 +7 -2
- package/README.md +9 -10
- package/dist/formatters.js +7 -0
- package/dist/index.js +46 -8
- package/package.json +9 -8
- 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 +10 -5
- package/src/OnifySubProcessExtensions.js +76 -46
- package/src/ServiceExpression.js +1 -1
- package/src/formatters.js +93 -98
- package/src/getExtensions.js +57 -57
- package/src/index.js +45 -10
package/src/formatters.js
CHANGED
|
@@ -1,98 +1,93 @@
|
|
|
1
|
-
import cronParser from 'cron-parser';
|
|
2
|
-
|
|
3
|
-
const iso8601cycle = /^\s*(R\d+\/)?P\w+/i;
|
|
4
|
-
|
|
5
|
-
export class FormatActivity {
|
|
6
|
-
constructor(activity) {
|
|
7
|
-
this.activity = activity;
|
|
8
|
-
this.resultVariable = activity.behaviour.resultVariable;
|
|
9
|
-
|
|
10
|
-
let timeCycles;
|
|
11
|
-
if (activity.eventDefinitions) {
|
|
12
|
-
for (const ed of activity.eventDefinitions.filter((e) => e.type === 'bpmn:TimerEventDefinition')) {
|
|
13
|
-
if (ed.supports?.includes('cron')) continue;
|
|
14
|
-
if (!('timeCycle' in ed)) continue;
|
|
15
|
-
timeCycles = timeCycles || [];
|
|
16
|
-
timeCycles.push(ed.timeCycle);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
this.timeCycles = timeCycles;
|
|
20
|
-
}
|
|
21
|
-
resolve(elementApi) {
|
|
22
|
-
let user, groups, assigneeValue, description;
|
|
23
|
-
const activity = this.activity;
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return resolved
|
|
95
|
-
.split(',')
|
|
96
|
-
.map((g) => g.trim && g.trim().toLowerCase())
|
|
97
|
-
.filter(Boolean);
|
|
98
|
-
}
|
|
1
|
+
import cronParser from 'cron-parser';
|
|
2
|
+
|
|
3
|
+
const iso8601cycle = /^\s*(R\d+\/)?P\w+/i;
|
|
4
|
+
|
|
5
|
+
export class FormatActivity {
|
|
6
|
+
constructor(activity) {
|
|
7
|
+
this.activity = activity;
|
|
8
|
+
this.resultVariable = activity.behaviour.resultVariable;
|
|
9
|
+
|
|
10
|
+
let timeCycles;
|
|
11
|
+
if (activity.eventDefinitions) {
|
|
12
|
+
for (const ed of activity.eventDefinitions.filter((e) => e.type === 'bpmn:TimerEventDefinition')) {
|
|
13
|
+
if (ed.supports?.includes('cron')) continue;
|
|
14
|
+
if (!('timeCycle' in ed)) continue;
|
|
15
|
+
timeCycles = timeCycles || [];
|
|
16
|
+
timeCycles.push(ed.timeCycle);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
this.timeCycles = timeCycles;
|
|
20
|
+
}
|
|
21
|
+
resolve(elementApi) {
|
|
22
|
+
let user, groups, assigneeValue, description;
|
|
23
|
+
const activity = this.activity;
|
|
24
|
+
const { documentation, candidateUsers, candidateGroups, scheduledStart, assignee } = activity.behaviour;
|
|
25
|
+
|
|
26
|
+
if (candidateUsers) user = resolveAndSplit(elementApi, candidateUsers);
|
|
27
|
+
if (candidateGroups) groups = resolveAndSplit(elementApi, candidateGroups);
|
|
28
|
+
if (assignee) assigneeValue = elementApi.resolveExpression(assignee);
|
|
29
|
+
if (documentation) description = documentation[0]?.text;
|
|
30
|
+
|
|
31
|
+
let expireAt;
|
|
32
|
+
const timeCycles = this.timeCycles;
|
|
33
|
+
if (timeCycles) {
|
|
34
|
+
for (const cycle of timeCycles) {
|
|
35
|
+
const cron = elementApi.resolveExpression(cycle);
|
|
36
|
+
if (!cron || iso8601cycle.test(cron)) continue;
|
|
37
|
+
|
|
38
|
+
const expireAtDt = cronParser.parseExpression(cron).next().toDate();
|
|
39
|
+
if (!expireAt || expireAtDt < expireAt) expireAt = expireAtDt;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
...(this.resultVariable && { resultVariable: this.resultVariable }),
|
|
45
|
+
...(scheduledStart && activity.parent.type === 'bpmn:Process' && { scheduledStart }),
|
|
46
|
+
...(user?.length && { candidateUsers: user }),
|
|
47
|
+
...(groups?.length && { candidateGroups: groups }),
|
|
48
|
+
...(!elementApi.content.description && description && { description: elementApi.resolveExpression(description) }),
|
|
49
|
+
...(expireAt && { expireAt }),
|
|
50
|
+
...(assigneeValue && { assignee: assigneeValue }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class FormatProcess {
|
|
56
|
+
constructor(bp) {
|
|
57
|
+
this.process = bp;
|
|
58
|
+
this._historyTTL = undefined;
|
|
59
|
+
if (bp.behaviour.historyTimeToLive) {
|
|
60
|
+
this._historyTTL = bp.context.definitionContext.getTimersByElementId(bp.id).find((t) => t.timer.type === 'historyTimeToLive');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
resolve(elementApi) {
|
|
64
|
+
let user, groups, description;
|
|
65
|
+
const bp = this.process;
|
|
66
|
+
const { documentation, candidateStarterUsers, candidateStarterGroups } = bp.behaviour;
|
|
67
|
+
|
|
68
|
+
if (candidateStarterUsers) user = resolveAndSplit(elementApi, candidateStarterUsers);
|
|
69
|
+
if (candidateStarterGroups) groups = resolveAndSplit(elementApi, candidateStarterGroups);
|
|
70
|
+
if (documentation) description = documentation[0]?.text;
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...(user?.length && { candidateStarterUsers: user }),
|
|
74
|
+
...(groups?.length && { candidateStarterGroups: groups }),
|
|
75
|
+
...(!elementApi.content.description && description && { description: elementApi.resolveExpression(description) }),
|
|
76
|
+
...(this._historyTTL && { historyTimeToLive: this._historyTTL.timer.value }),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function resolveAndSplit(elementApi, str) {
|
|
82
|
+
if (Array.isArray(str)) return str.filter(Boolean);
|
|
83
|
+
if (typeof str !== 'string') return;
|
|
84
|
+
|
|
85
|
+
const resolved = elementApi.resolveExpression(str);
|
|
86
|
+
if (Array.isArray(resolved)) return resolved.filter(Boolean);
|
|
87
|
+
if (typeof resolved !== 'string') return;
|
|
88
|
+
|
|
89
|
+
return resolved
|
|
90
|
+
.split(',')
|
|
91
|
+
.map((g) => g.trim && g.trim().toLowerCase())
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
}
|
package/src/getExtensions.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import {FormatActivity, FormatProcess} from './formatters.js';
|
|
2
|
-
import {InputOutput} from './IO.js';
|
|
3
|
-
import Connector from './Connector.js';
|
|
4
|
-
import ExecutionListeners from './ExecutionListeners.js';
|
|
5
|
-
import IOForm from './IOForm.js';
|
|
6
|
-
import IOProperties from './IOProperties.js';
|
|
7
|
-
import ServiceExpression from './ServiceExpression.js';
|
|
8
|
-
|
|
9
|
-
export function getExtensions(element, context) {
|
|
10
|
-
const result = {};
|
|
11
|
-
|
|
12
|
-
switch (element.type) {
|
|
13
|
-
case 'bpmn:SequenceFlow':
|
|
14
|
-
break;
|
|
15
|
-
case 'bpmn:Process':
|
|
16
|
-
result.format = new FormatProcess(element);
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
result.format = new FormatActivity(element);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let listenerPosition = 0;
|
|
23
|
-
const listeners = new ExecutionListeners(element, context);
|
|
24
|
-
|
|
25
|
-
const expression = element.behaviour.expression;
|
|
26
|
-
if (expression) result.Service = ServiceExpression;
|
|
27
|
-
|
|
28
|
-
const extensions = element.behaviour.extensionElements?.values;
|
|
29
|
-
if (extensions) {
|
|
30
|
-
for (const ext of extensions) {
|
|
31
|
-
switch (ext.$type) {
|
|
32
|
-
case 'camunda:Properties':
|
|
33
|
-
if (ext.values?.length) result.properties = new IOProperties(element, ext);
|
|
34
|
-
break;
|
|
35
|
-
case 'camunda:InputOutput':
|
|
36
|
-
result.io = new InputOutput(element.id, ext, context);
|
|
37
|
-
break;
|
|
38
|
-
case 'camunda:FormData':
|
|
39
|
-
if (ext.fields?.length) result.form = new IOForm(element, ext);
|
|
40
|
-
break;
|
|
41
|
-
case 'camunda:Connector': {
|
|
42
|
-
const {connectorId, inputOutput} = ext;
|
|
43
|
-
const io = inputOutput && new InputOutput(`${element.id}/${ext.$type.toLowerCase()}`, inputOutput, context);
|
|
44
|
-
result.Service = Connector.bind(Connector, connectorId, io);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
case 'camunda:ExecutionListener':
|
|
48
|
-
listeners.add(ext, listenerPosition++);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (listeners.length) result.listeners = listeners;
|
|
55
|
-
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
1
|
+
import { FormatActivity, FormatProcess } from './formatters.js';
|
|
2
|
+
import { InputOutput } from './IO.js';
|
|
3
|
+
import Connector from './Connector.js';
|
|
4
|
+
import ExecutionListeners from './ExecutionListeners.js';
|
|
5
|
+
import IOForm from './IOForm.js';
|
|
6
|
+
import IOProperties from './IOProperties.js';
|
|
7
|
+
import ServiceExpression from './ServiceExpression.js';
|
|
8
|
+
|
|
9
|
+
export function getExtensions(element, context) {
|
|
10
|
+
const result = {};
|
|
11
|
+
|
|
12
|
+
switch (element.type) {
|
|
13
|
+
case 'bpmn:SequenceFlow':
|
|
14
|
+
break;
|
|
15
|
+
case 'bpmn:Process':
|
|
16
|
+
result.format = new FormatProcess(element);
|
|
17
|
+
break;
|
|
18
|
+
default:
|
|
19
|
+
result.format = new FormatActivity(element);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let listenerPosition = 0;
|
|
23
|
+
const listeners = new ExecutionListeners(element, context);
|
|
24
|
+
|
|
25
|
+
const expression = element.behaviour.expression;
|
|
26
|
+
if (expression) result.Service = ServiceExpression;
|
|
27
|
+
|
|
28
|
+
const extensions = element.behaviour.extensionElements?.values;
|
|
29
|
+
if (extensions) {
|
|
30
|
+
for (const ext of extensions) {
|
|
31
|
+
switch (ext.$type) {
|
|
32
|
+
case 'camunda:Properties':
|
|
33
|
+
if (ext.values?.length) result.properties = new IOProperties(element, ext);
|
|
34
|
+
break;
|
|
35
|
+
case 'camunda:InputOutput':
|
|
36
|
+
result.io = new InputOutput(element.id, ext, context);
|
|
37
|
+
break;
|
|
38
|
+
case 'camunda:FormData':
|
|
39
|
+
if (ext.fields?.length) result.form = new IOForm(element, ext);
|
|
40
|
+
break;
|
|
41
|
+
case 'camunda:Connector': {
|
|
42
|
+
const { connectorId, inputOutput } = ext;
|
|
43
|
+
const io = inputOutput && new InputOutput(`${element.id}/${ext.$type.toLowerCase()}`, inputOutput, context);
|
|
44
|
+
result.Service = Connector.bind(Connector, connectorId, io);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'camunda:ExecutionListener':
|
|
48
|
+
listeners.add(ext, listenerPosition++);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (listeners.length) result.listeners = listeners;
|
|
55
|
+
|
|
56
|
+
return result;
|
|
57
|
+
}
|
package/src/index.js
CHANGED
|
@@ -21,9 +21,28 @@ export function extensions(element, context) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function extendFn(behaviour, context) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
switch (behaviour.$type) {
|
|
25
|
+
case 'bpmn:StartEvent': {
|
|
26
|
+
if (!behaviour.eventDefinitions) break;
|
|
27
|
+
|
|
28
|
+
const timer = behaviour.eventDefinitions.find(
|
|
29
|
+
({ type, behaviour: edBehaviour }) => edBehaviour && type === 'bpmn:TimerEventDefinition',
|
|
30
|
+
);
|
|
31
|
+
if (timer && timer.behaviour.timeCycle) Object.assign(behaviour, { scheduledStart: timer.behaviour.timeCycle });
|
|
32
|
+
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'bpmn:Process': {
|
|
36
|
+
if (!behaviour.isExecutable) break;
|
|
37
|
+
|
|
38
|
+
const { historyTimeToLive, isExecutable } = behaviour;
|
|
39
|
+
|
|
40
|
+
if (historyTimeToLive && isExecutable) {
|
|
41
|
+
context.addTimer(behaviour.id + ':historyTimeToLive', getHistoryTimeToLiveTimer(behaviour));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
27
46
|
}
|
|
28
47
|
|
|
29
48
|
if (!Array.isArray(behaviour.extensionElements?.values)) return;
|
|
@@ -47,8 +66,8 @@ export function extendFn(behaviour, context) {
|
|
|
47
66
|
function registerIOScripts(parentId, context, type, ioBehaviour) {
|
|
48
67
|
if (!ioBehaviour) return;
|
|
49
68
|
|
|
50
|
-
const {inputParameters = [], outputParameters = []} = ioBehaviour;
|
|
51
|
-
for (const {$type, name, definition} of inputParameters.concat(outputParameters)) {
|
|
69
|
+
const { inputParameters = [], outputParameters = [] } = ioBehaviour;
|
|
70
|
+
for (const { $type, name, definition } of inputParameters.concat(outputParameters)) {
|
|
52
71
|
if (!definition) continue;
|
|
53
72
|
if (definition.$type !== 'camunda:Script') continue;
|
|
54
73
|
|
|
@@ -59,14 +78,14 @@ function registerIOScripts(parentId, context, type, ioBehaviour) {
|
|
|
59
78
|
id: filename,
|
|
60
79
|
scriptFormat: definition.scriptFormat,
|
|
61
80
|
type: ioType,
|
|
62
|
-
...(definition.value && {body: definition.value}),
|
|
63
|
-
...(definition.resource && {resource: definition.resource}),
|
|
81
|
+
...(definition.value && { body: definition.value }),
|
|
82
|
+
...(definition.resource && { resource: definition.resource }),
|
|
64
83
|
});
|
|
65
84
|
}
|
|
66
85
|
}
|
|
67
86
|
|
|
68
87
|
function registerListenerScript(parentId, context, type, listener, pos) {
|
|
69
|
-
const {event, script} = listener;
|
|
88
|
+
const { event, script } = listener;
|
|
70
89
|
if (!script) return;
|
|
71
90
|
|
|
72
91
|
const id = `${parentId}/${type}/${event}/${pos}`;
|
|
@@ -74,7 +93,23 @@ function registerListenerScript(parentId, context, type, listener, pos) {
|
|
|
74
93
|
id,
|
|
75
94
|
scriptFormat: script.scriptFormat,
|
|
76
95
|
type,
|
|
77
|
-
...(script.value && {body: script.value}),
|
|
78
|
-
...(script.resource && {resource: script.resource}),
|
|
96
|
+
...(script.value && { body: script.value }),
|
|
97
|
+
...(script.resource && { resource: script.resource }),
|
|
79
98
|
});
|
|
80
99
|
}
|
|
100
|
+
|
|
101
|
+
function getHistoryTimeToLiveTimer(behaviour) {
|
|
102
|
+
const { id, $type: type, historyTimeToLive } = behaviour;
|
|
103
|
+
|
|
104
|
+
let value = historyTimeToLive;
|
|
105
|
+
if (/^\d+$/.test(historyTimeToLive)) {
|
|
106
|
+
value = `P${historyTimeToLive}D`;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
id: `${type}/${id}:historyTimeToLive`,
|
|
110
|
+
type: 'historyTimeToLive',
|
|
111
|
+
timerType: 'timeDuration',
|
|
112
|
+
value,
|
|
113
|
+
parent: { id, type },
|
|
114
|
+
};
|
|
115
|
+
}
|