@onify/flow-extensions 6.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 +17 -2
- package/README.md +9 -10
- package/dist/OnifyBoundaryEventExtensions.js +86 -0
- package/dist/OnifyElementExtensions.js +64 -84
- package/dist/OnifySubProcessExtensions.js +50 -0
- package/dist/formatters.js +7 -0
- package/dist/index.js +59 -10
- package/package.json +13 -12
- 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 -0
- package/src/OnifyElementExtensions.js +153 -150
- package/src/OnifyProcessExtensions.js +49 -40
- package/src/OnifySequenceFlow.js +10 -5
- package/src/OnifySubProcessExtensions.js +76 -0
- package/src/ServiceExpression.js +1 -1
- package/src/formatters.js +93 -98
- package/src/getExtensions.js +57 -57
- package/src/index.js +59 -12
|
@@ -1,40 +1,49 @@
|
|
|
1
|
-
import {FormatError} from './Errors.js';
|
|
2
|
-
import {getExtensions} from './getExtensions.js';
|
|
3
|
-
|
|
4
|
-
export class OnifyProcessExtensions {
|
|
5
|
-
constructor(bp, context) {
|
|
6
|
-
this.process = bp;
|
|
7
|
-
this.context = context;
|
|
8
|
-
this.extensions = getExtensions(bp, context);
|
|
9
|
-
this._activate();
|
|
10
|
-
}
|
|
11
|
-
_activate() {
|
|
12
|
-
const bp = this.process;
|
|
13
|
-
bp.on(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import { FormatError } from './Errors.js';
|
|
2
|
+
import { getExtensions } from './getExtensions.js';
|
|
3
|
+
|
|
4
|
+
export class OnifyProcessExtensions {
|
|
5
|
+
constructor(bp, context) {
|
|
6
|
+
this.process = bp;
|
|
7
|
+
this.context = context;
|
|
8
|
+
this.extensions = getExtensions(bp, context);
|
|
9
|
+
this._activate();
|
|
10
|
+
}
|
|
11
|
+
_activate() {
|
|
12
|
+
const bp = this.process;
|
|
13
|
+
bp.on(
|
|
14
|
+
'process.enter',
|
|
15
|
+
(elementApi) => {
|
|
16
|
+
try {
|
|
17
|
+
const result = this._onEnter(elementApi);
|
|
18
|
+
const environment = elementApi.environment;
|
|
19
|
+
environment.assignVariables(result);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
elementApi.broker.publish(
|
|
22
|
+
'event',
|
|
23
|
+
'process.error',
|
|
24
|
+
{
|
|
25
|
+
...elementApi.content,
|
|
26
|
+
error: new FormatError(bp.id, err),
|
|
27
|
+
},
|
|
28
|
+
{ mandatory: true, type: 'error' },
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{ consumerTag: '_onify-extension-on-enter' },
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
_onEnter(elementApi) {
|
|
36
|
+
const { format, properties } = this.extensions;
|
|
37
|
+
const result = {};
|
|
38
|
+
|
|
39
|
+
Object.assign(result, format.resolve(elementApi));
|
|
40
|
+
Object.assign(elementApi.content, result);
|
|
41
|
+
|
|
42
|
+
if (properties) {
|
|
43
|
+
Object.assign(result, properties.resolve(elementApi));
|
|
44
|
+
Object.assign(elementApi.content, result);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/OnifySequenceFlow.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {SequenceFlow} from 'bpmn-elements';
|
|
2
|
-
import {getExtensions} from './getExtensions.js';
|
|
1
|
+
import { SequenceFlow } from 'bpmn-elements';
|
|
2
|
+
import { getExtensions } from './getExtensions.js';
|
|
3
3
|
|
|
4
4
|
export class OnifySequenceFlow extends SequenceFlow {
|
|
5
5
|
constructor(flowDef, context) {
|
|
@@ -10,9 +10,14 @@ export class OnifySequenceFlow extends SequenceFlow {
|
|
|
10
10
|
_activate() {
|
|
11
11
|
if (!this.extensions.listeners?.onTake) return;
|
|
12
12
|
|
|
13
|
-
this.broker.subscribeTmp(
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
this.broker.subscribeTmp(
|
|
14
|
+
'event',
|
|
15
|
+
'flow.take',
|
|
16
|
+
(_, msg) => {
|
|
17
|
+
this._executeListeners(msg);
|
|
18
|
+
},
|
|
19
|
+
{ noAck: true, consumerTag: '_onify-execution-listener' },
|
|
20
|
+
);
|
|
16
21
|
}
|
|
17
22
|
async _executeListeners(message) {
|
|
18
23
|
try {
|
|
@@ -0,0 +1,76 @@
|
|
|
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(
|
|
14
|
+
broker,
|
|
15
|
+
'activity.start',
|
|
16
|
+
(elementApi) => {
|
|
17
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
18
|
+
},
|
|
19
|
+
'_onify-extension-on-enter',
|
|
20
|
+
);
|
|
21
|
+
} else {
|
|
22
|
+
this._setupListener(
|
|
23
|
+
broker,
|
|
24
|
+
'activity.enter',
|
|
25
|
+
(elementApi) => {
|
|
26
|
+
return this._asyncFormatOnEnter(elementApi);
|
|
27
|
+
},
|
|
28
|
+
'_onify-extension-on-enter',
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this._setupListener(
|
|
33
|
+
broker,
|
|
34
|
+
'activity.execution.completed',
|
|
35
|
+
(elementApi) => {
|
|
36
|
+
return this._onExecutionCompleted(elementApi);
|
|
37
|
+
},
|
|
38
|
+
'_onify-extension-on-executed',
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (executionListeners?.onStart) {
|
|
42
|
+
this._setupListener(
|
|
43
|
+
broker,
|
|
44
|
+
'activity.start',
|
|
45
|
+
(elementApi) => {
|
|
46
|
+
this._executeExecutionListener('start', elementApi);
|
|
47
|
+
},
|
|
48
|
+
'_onify-extension-on-listenerstart',
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (executionListeners?.onEnd) {
|
|
53
|
+
this._setupListener(
|
|
54
|
+
broker,
|
|
55
|
+
'activity.end',
|
|
56
|
+
(elementApi) => {
|
|
57
|
+
this._executeExecutionListener('end', elementApi);
|
|
58
|
+
},
|
|
59
|
+
'_onify-extension-on-listenerend',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
_setupListener(broker, routingKey, callback, consumerTag) {
|
|
64
|
+
const activity = this.activity;
|
|
65
|
+
broker.subscribeTmp(
|
|
66
|
+
'event',
|
|
67
|
+
routingKey,
|
|
68
|
+
(_, message) => {
|
|
69
|
+
if (activity.id !== message.content.id) return;
|
|
70
|
+
|
|
71
|
+
return callback(activity.getApi(message));
|
|
72
|
+
},
|
|
73
|
+
{ noAck: true, consumerTag },
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/ServiceExpression.js
CHANGED
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
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
import { OnifyProcessExtensions } from './OnifyProcessExtensions.js';
|
|
2
2
|
import { OnifyElementExtensions } from './OnifyElementExtensions.js';
|
|
3
|
+
import { OnifyBoundaryEventExtensions } from './OnifyBoundaryEventExtensions.js';
|
|
4
|
+
import { OnifySubProcessExtensions } from './OnifySubProcessExtensions.js';
|
|
5
|
+
|
|
3
6
|
export { OnifySequenceFlow } from './OnifySequenceFlow.js';
|
|
4
7
|
export { OnifyTimerEventDefinition } from './OnifyTimerEventDefinition.js';
|
|
5
8
|
|
|
6
9
|
export function extensions(element, context) {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
}
|
|
9
21
|
}
|
|
10
22
|
|
|
11
23
|
export function extendFn(behaviour, context) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
|
15
46
|
}
|
|
16
47
|
|
|
17
48
|
if (!Array.isArray(behaviour.extensionElements?.values)) return;
|
|
@@ -35,8 +66,8 @@ export function extendFn(behaviour, context) {
|
|
|
35
66
|
function registerIOScripts(parentId, context, type, ioBehaviour) {
|
|
36
67
|
if (!ioBehaviour) return;
|
|
37
68
|
|
|
38
|
-
const {inputParameters = [], outputParameters = []} = ioBehaviour;
|
|
39
|
-
for (const {$type, name, definition} of inputParameters.concat(outputParameters)) {
|
|
69
|
+
const { inputParameters = [], outputParameters = [] } = ioBehaviour;
|
|
70
|
+
for (const { $type, name, definition } of inputParameters.concat(outputParameters)) {
|
|
40
71
|
if (!definition) continue;
|
|
41
72
|
if (definition.$type !== 'camunda:Script') continue;
|
|
42
73
|
|
|
@@ -47,14 +78,14 @@ function registerIOScripts(parentId, context, type, ioBehaviour) {
|
|
|
47
78
|
id: filename,
|
|
48
79
|
scriptFormat: definition.scriptFormat,
|
|
49
80
|
type: ioType,
|
|
50
|
-
...(definition.value && {body: definition.value}),
|
|
51
|
-
...(definition.resource && {resource: definition.resource}),
|
|
81
|
+
...(definition.value && { body: definition.value }),
|
|
82
|
+
...(definition.resource && { resource: definition.resource }),
|
|
52
83
|
});
|
|
53
84
|
}
|
|
54
85
|
}
|
|
55
86
|
|
|
56
87
|
function registerListenerScript(parentId, context, type, listener, pos) {
|
|
57
|
-
const {event, script} = listener;
|
|
88
|
+
const { event, script } = listener;
|
|
58
89
|
if (!script) return;
|
|
59
90
|
|
|
60
91
|
const id = `${parentId}/${type}/${event}/${pos}`;
|
|
@@ -62,7 +93,23 @@ function registerListenerScript(parentId, context, type, listener, pos) {
|
|
|
62
93
|
id,
|
|
63
94
|
scriptFormat: script.scriptFormat,
|
|
64
95
|
type,
|
|
65
|
-
...(script.value && {body: script.value}),
|
|
66
|
-
...(script.resource && {resource: script.resource}),
|
|
96
|
+
...(script.value && { body: script.value }),
|
|
97
|
+
...(script.resource && { resource: script.resource }),
|
|
67
98
|
});
|
|
68
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
|
+
}
|