bpmnlint-plugin-camunda-compat 2.20.2 → 2.21.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/LICENSE +20 -20
- package/README.md +39 -39
- package/index.js +224 -223
- package/package.json +53 -53
- package/rules/camunda-cloud/called-element.js +42 -42
- package/rules/camunda-cloud/collapsed-subprocess.js +40 -40
- package/rules/camunda-cloud/connector-properties/config.js +90 -90
- package/rules/camunda-cloud/connector-properties/index.js +47 -47
- package/rules/camunda-cloud/duplicate-task-headers.js +58 -58
- package/rules/camunda-cloud/element-type/config.js +66 -66
- package/rules/camunda-cloud/element-type/index.js +133 -133
- package/rules/camunda-cloud/error-reference.js +71 -71
- package/rules/camunda-cloud/escalation-boundary-event-attached-to-ref.js +48 -48
- package/rules/camunda-cloud/escalation-reference.js +66 -66
- package/rules/camunda-cloud/event-based-gateway-target.js +38 -38
- package/rules/camunda-cloud/executable-process.js +61 -61
- package/rules/camunda-cloud/feel.js +82 -82
- package/rules/camunda-cloud/implementation/config.js +16 -16
- package/rules/camunda-cloud/implementation/index.js +218 -218
- package/rules/camunda-cloud/inclusive-gateway.js +35 -35
- package/rules/camunda-cloud/link-event.js +142 -142
- package/rules/camunda-cloud/loop-characteristics.js +66 -66
- package/rules/camunda-cloud/message-reference.js +60 -60
- package/rules/camunda-cloud/no-candidate-users.js +38 -38
- package/rules/camunda-cloud/no-expression.js +173 -173
- package/rules/camunda-cloud/no-loop.js +145 -145
- package/rules/camunda-cloud/no-multiple-none-start-events.js +41 -41
- package/rules/camunda-cloud/no-propagate-all-parent-variables.js +44 -44
- package/rules/camunda-cloud/no-signal-event-sub-process.js +45 -45
- package/rules/camunda-cloud/no-task-schedule.js +18 -18
- package/rules/camunda-cloud/no-template.js +23 -23
- package/rules/camunda-cloud/no-zeebe-properties.js +18 -18
- package/rules/camunda-cloud/no-zeebe-user-task.js +27 -27
- package/rules/camunda-cloud/secrets.js +119 -119
- package/rules/camunda-cloud/sequence-flow-condition.js +56 -56
- package/rules/camunda-cloud/signal-reference.js +64 -64
- package/rules/camunda-cloud/start-event-form.js +97 -97
- package/rules/camunda-cloud/subscription.js +65 -65
- package/rules/camunda-cloud/task-schedule.js +67 -67
- package/rules/camunda-cloud/timer/config.js +46 -46
- package/rules/camunda-cloud/timer/index.js +183 -183
- package/rules/camunda-cloud/user-task-definition.js +24 -24
- package/rules/camunda-cloud/user-task-form.js +142 -142
- package/rules/camunda-cloud/wait-for-completion.js +46 -46
- package/rules/camunda-platform/history-time-to-live.js +19 -19
- package/rules/utils/cron.js +95 -95
- package/rules/utils/element.js +484 -484
- package/rules/utils/error-types.js +24 -24
- package/rules/utils/iso8601.js +52 -52
- package/rules/utils/reporter.js +37 -37
- package/rules/utils/rule.js +46 -46
- package/rules/utils/version.js +4 -4
@@ -1,173 +1,173 @@
|
|
1
|
-
const {
|
2
|
-
is
|
3
|
-
} = require('bpmnlint-utils');
|
4
|
-
|
5
|
-
const { getPath } = require('@bpmn-io/moddle-utils');
|
6
|
-
|
7
|
-
const {
|
8
|
-
ERROR_TYPES,
|
9
|
-
getEventDefinition
|
10
|
-
} = require('../utils/element');
|
11
|
-
|
12
|
-
const { reportErrors } = require('../utils/reporter');
|
13
|
-
|
14
|
-
const { skipInNonExecutableProcess } = require('../utils/rule');
|
15
|
-
|
16
|
-
const handlersMap = {
|
17
|
-
'1.0': [
|
18
|
-
checkErrorCode
|
19
|
-
],
|
20
|
-
'1.1': [
|
21
|
-
checkErrorCode
|
22
|
-
],
|
23
|
-
'1.2': [
|
24
|
-
checkErrorCode
|
25
|
-
],
|
26
|
-
'1.3': [
|
27
|
-
checkErrorCode
|
28
|
-
],
|
29
|
-
'8.0': [
|
30
|
-
checkErrorCode
|
31
|
-
],
|
32
|
-
'8.1': [
|
33
|
-
checkErrorCode
|
34
|
-
],
|
35
|
-
'8.2': [
|
36
|
-
checkErrorCatchEvent,
|
37
|
-
checkEscalationCatchEvent
|
38
|
-
],
|
39
|
-
'8.3': [
|
40
|
-
checkErrorCatchEvent,
|
41
|
-
checkEscalationCatchEvent
|
42
|
-
]
|
43
|
-
};
|
44
|
-
|
45
|
-
module.exports = skipInNonExecutableProcess(noExpressionRule);
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Make sure that certain properties do not contain expressions in older versions.
|
49
|
-
* @param {{ version: string }} config
|
50
|
-
*/
|
51
|
-
function noExpressionRule({ version }) {
|
52
|
-
function check(node, reporter) {
|
53
|
-
const errors = checkForVersion(node, version);
|
54
|
-
|
55
|
-
if (errors && errors.length) {
|
56
|
-
reportErrors(node, reporter, errors);
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
return {
|
61
|
-
check
|
62
|
-
};
|
63
|
-
}
|
64
|
-
|
65
|
-
function checkForVersion(node, version) {
|
66
|
-
const handlers = handlersMap[version];
|
67
|
-
|
68
|
-
if (!handlers) {
|
69
|
-
return [];
|
70
|
-
}
|
71
|
-
|
72
|
-
return handlers.reduce((errors, handler) => {
|
73
|
-
const handlerErrors = handler(node) || [];
|
74
|
-
return errors.concat(handlerErrors);
|
75
|
-
}, []);
|
76
|
-
}
|
77
|
-
|
78
|
-
function noExpression(node, propertyName, parentNode, allowedVersion) {
|
79
|
-
const path = getPath(node, parentNode),
|
80
|
-
propertyValue = node.get(propertyName);
|
81
|
-
|
82
|
-
if (!isExpression(propertyValue)) {
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
|
86
|
-
let message = `Expression statement <${ truncate(propertyValue) }> not supported`;
|
87
|
-
|
88
|
-
let data = {
|
89
|
-
type: ERROR_TYPES.EXPRESSION_NOT_ALLOWED,
|
90
|
-
node,
|
91
|
-
parentNode: parentNode == node ? null : parentNode,
|
92
|
-
property: propertyName
|
93
|
-
};
|
94
|
-
|
95
|
-
if (allowedVersion) {
|
96
|
-
message = `Expression statement <${ truncate(propertyValue) }> only supported by Camunda ${allowedVersion} or newer`;
|
97
|
-
|
98
|
-
data = {
|
99
|
-
...data,
|
100
|
-
allowedVersion
|
101
|
-
};
|
102
|
-
}
|
103
|
-
|
104
|
-
return {
|
105
|
-
message,
|
106
|
-
path: path
|
107
|
-
? [ ...path, propertyName ]
|
108
|
-
: [ propertyName ],
|
109
|
-
data
|
110
|
-
};
|
111
|
-
}
|
112
|
-
|
113
|
-
function isExpression(value) {
|
114
|
-
return value && value.startsWith('=');
|
115
|
-
}
|
116
|
-
|
117
|
-
function checkErrorCode(node) {
|
118
|
-
if (!is(node, 'bpmn:Event')) {
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
|
122
|
-
const eventDefinition = getEventDefinition(node);
|
123
|
-
|
124
|
-
if (!eventDefinition || !is(eventDefinition, 'bpmn:ErrorEventDefinition')) {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
|
128
|
-
const errorRef = eventDefinition.get('errorRef');
|
129
|
-
|
130
|
-
if (!errorRef) {
|
131
|
-
return;
|
132
|
-
}
|
133
|
-
|
134
|
-
if (is(node, 'bpmn:CatchEvent')) {
|
135
|
-
return noExpression(errorRef, 'errorCode', node, null);
|
136
|
-
} else {
|
137
|
-
return noExpression(errorRef, 'errorCode', node, '8.2');
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
function checkErrorCatchEvent(node) {
|
142
|
-
if (!is(node, 'bpmn:CatchEvent')) {
|
143
|
-
return;
|
144
|
-
}
|
145
|
-
|
146
|
-
return checkErrorCode(node);
|
147
|
-
}
|
148
|
-
|
149
|
-
function checkEscalationCatchEvent(node) {
|
150
|
-
if (!is(node, 'bpmn:CatchEvent')) {
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
|
154
|
-
const eventDefinition = getEventDefinition(node);
|
155
|
-
|
156
|
-
if (!eventDefinition || !is(eventDefinition, 'bpmn:EscalationEventDefinition')) {
|
157
|
-
return;
|
158
|
-
}
|
159
|
-
|
160
|
-
const escalationRef = eventDefinition.get('escalationRef');
|
161
|
-
|
162
|
-
if (!escalationRef) {
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
|
166
|
-
return noExpression(escalationRef, 'escalationCode', node, null);
|
167
|
-
}
|
168
|
-
|
169
|
-
function truncate(string, maxLength = 10) {
|
170
|
-
const stringified = `${ string }`;
|
171
|
-
|
172
|
-
return stringified.length > maxLength ? `${ stringified.slice(0, maxLength) }...` : stringified;
|
173
|
-
}
|
1
|
+
const {
|
2
|
+
is
|
3
|
+
} = require('bpmnlint-utils');
|
4
|
+
|
5
|
+
const { getPath } = require('@bpmn-io/moddle-utils');
|
6
|
+
|
7
|
+
const {
|
8
|
+
ERROR_TYPES,
|
9
|
+
getEventDefinition
|
10
|
+
} = require('../utils/element');
|
11
|
+
|
12
|
+
const { reportErrors } = require('../utils/reporter');
|
13
|
+
|
14
|
+
const { skipInNonExecutableProcess } = require('../utils/rule');
|
15
|
+
|
16
|
+
const handlersMap = {
|
17
|
+
'1.0': [
|
18
|
+
checkErrorCode
|
19
|
+
],
|
20
|
+
'1.1': [
|
21
|
+
checkErrorCode
|
22
|
+
],
|
23
|
+
'1.2': [
|
24
|
+
checkErrorCode
|
25
|
+
],
|
26
|
+
'1.3': [
|
27
|
+
checkErrorCode
|
28
|
+
],
|
29
|
+
'8.0': [
|
30
|
+
checkErrorCode
|
31
|
+
],
|
32
|
+
'8.1': [
|
33
|
+
checkErrorCode
|
34
|
+
],
|
35
|
+
'8.2': [
|
36
|
+
checkErrorCatchEvent,
|
37
|
+
checkEscalationCatchEvent
|
38
|
+
],
|
39
|
+
'8.3': [
|
40
|
+
checkErrorCatchEvent,
|
41
|
+
checkEscalationCatchEvent
|
42
|
+
]
|
43
|
+
};
|
44
|
+
|
45
|
+
module.exports = skipInNonExecutableProcess(noExpressionRule);
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Make sure that certain properties do not contain expressions in older versions.
|
49
|
+
* @param {{ version: string }} config
|
50
|
+
*/
|
51
|
+
function noExpressionRule({ version }) {
|
52
|
+
function check(node, reporter) {
|
53
|
+
const errors = checkForVersion(node, version);
|
54
|
+
|
55
|
+
if (errors && errors.length) {
|
56
|
+
reportErrors(node, reporter, errors);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return {
|
61
|
+
check
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
function checkForVersion(node, version) {
|
66
|
+
const handlers = handlersMap[version];
|
67
|
+
|
68
|
+
if (!handlers) {
|
69
|
+
return [];
|
70
|
+
}
|
71
|
+
|
72
|
+
return handlers.reduce((errors, handler) => {
|
73
|
+
const handlerErrors = handler(node) || [];
|
74
|
+
return errors.concat(handlerErrors);
|
75
|
+
}, []);
|
76
|
+
}
|
77
|
+
|
78
|
+
function noExpression(node, propertyName, parentNode, allowedVersion) {
|
79
|
+
const path = getPath(node, parentNode),
|
80
|
+
propertyValue = node.get(propertyName);
|
81
|
+
|
82
|
+
if (!isExpression(propertyValue)) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
let message = `Expression statement <${ truncate(propertyValue) }> not supported`;
|
87
|
+
|
88
|
+
let data = {
|
89
|
+
type: ERROR_TYPES.EXPRESSION_NOT_ALLOWED,
|
90
|
+
node,
|
91
|
+
parentNode: parentNode == node ? null : parentNode,
|
92
|
+
property: propertyName
|
93
|
+
};
|
94
|
+
|
95
|
+
if (allowedVersion) {
|
96
|
+
message = `Expression statement <${ truncate(propertyValue) }> only supported by Camunda ${allowedVersion} or newer`;
|
97
|
+
|
98
|
+
data = {
|
99
|
+
...data,
|
100
|
+
allowedVersion
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
return {
|
105
|
+
message,
|
106
|
+
path: path
|
107
|
+
? [ ...path, propertyName ]
|
108
|
+
: [ propertyName ],
|
109
|
+
data
|
110
|
+
};
|
111
|
+
}
|
112
|
+
|
113
|
+
function isExpression(value) {
|
114
|
+
return value && value.startsWith('=');
|
115
|
+
}
|
116
|
+
|
117
|
+
function checkErrorCode(node) {
|
118
|
+
if (!is(node, 'bpmn:Event')) {
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
|
122
|
+
const eventDefinition = getEventDefinition(node);
|
123
|
+
|
124
|
+
if (!eventDefinition || !is(eventDefinition, 'bpmn:ErrorEventDefinition')) {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
|
128
|
+
const errorRef = eventDefinition.get('errorRef');
|
129
|
+
|
130
|
+
if (!errorRef) {
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
|
134
|
+
if (is(node, 'bpmn:CatchEvent')) {
|
135
|
+
return noExpression(errorRef, 'errorCode', node, null);
|
136
|
+
} else {
|
137
|
+
return noExpression(errorRef, 'errorCode', node, '8.2');
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
function checkErrorCatchEvent(node) {
|
142
|
+
if (!is(node, 'bpmn:CatchEvent')) {
|
143
|
+
return;
|
144
|
+
}
|
145
|
+
|
146
|
+
return checkErrorCode(node);
|
147
|
+
}
|
148
|
+
|
149
|
+
function checkEscalationCatchEvent(node) {
|
150
|
+
if (!is(node, 'bpmn:CatchEvent')) {
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
|
154
|
+
const eventDefinition = getEventDefinition(node);
|
155
|
+
|
156
|
+
if (!eventDefinition || !is(eventDefinition, 'bpmn:EscalationEventDefinition')) {
|
157
|
+
return;
|
158
|
+
}
|
159
|
+
|
160
|
+
const escalationRef = eventDefinition.get('escalationRef');
|
161
|
+
|
162
|
+
if (!escalationRef) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
|
166
|
+
return noExpression(escalationRef, 'escalationCode', node, null);
|
167
|
+
}
|
168
|
+
|
169
|
+
function truncate(string, maxLength = 10) {
|
170
|
+
const stringified = `${ string }`;
|
171
|
+
|
172
|
+
return stringified.length > maxLength ? `${ stringified.slice(0, maxLength) }...` : stringified;
|
173
|
+
}
|
@@ -1,146 +1,146 @@
|
|
1
|
-
const { isString } = require('min-dash');
|
2
|
-
|
3
|
-
const { is } = require('bpmnlint-utils');
|
4
|
-
|
5
|
-
const {
|
6
|
-
findExtensionElement,
|
7
|
-
findParent,
|
8
|
-
isAnyExactly
|
9
|
-
} = require('../utils/element');
|
10
|
-
|
11
|
-
const { reportErrors } = require('../utils/reporter');
|
12
|
-
|
13
|
-
const { ERROR_TYPES } = require('../utils/error-types');
|
14
|
-
|
15
|
-
const { skipInNonExecutableProcess } = require('../utils/rule');
|
16
|
-
|
17
|
-
const LOOP_REQUIRED_ELEMENT_TYPES = [
|
18
|
-
'bpmn:CallActivity',
|
19
|
-
'bpmn:ManualTask',
|
20
|
-
'bpmn:Task'
|
21
|
-
];
|
22
|
-
|
23
|
-
const LOOP_ELEMENT_TYPES = [
|
24
|
-
...LOOP_REQUIRED_ELEMENT_TYPES,
|
25
|
-
'bpmn:StartEvent',
|
26
|
-
'bpmn:EndEvent',
|
27
|
-
'bpmn:ManualTask',
|
28
|
-
'bpmn:ExclusiveGateway',
|
29
|
-
'bpmn:InclusiveGateway',
|
30
|
-
'bpmn:ParallelGateway',
|
31
|
-
'bpmn:SubProcess',
|
32
|
-
'bpmn:Task'
|
33
|
-
];
|
34
|
-
|
35
|
-
module.exports = skipInNonExecutableProcess(function() {
|
36
|
-
function check(node, reporter) {
|
37
|
-
if (!is(node, 'bpmn:Process')) {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
|
41
|
-
const error = getFlowElements(node)
|
42
|
-
.filter(flowElement => {
|
43
|
-
return isAnyExactly(flowElement, LOOP_ELEMENT_TYPES);
|
44
|
-
})
|
45
|
-
.reduce((error, flowElement) => {
|
46
|
-
return error || findLoop(flowElement, node);
|
47
|
-
}, null);
|
48
|
-
|
49
|
-
if (error) {
|
50
|
-
reportErrors(node, reporter, error);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
return {
|
55
|
-
check
|
56
|
-
};
|
57
|
-
});
|
58
|
-
|
59
|
-
function findLoop(flowElement, parentElement, visitedFlowElements = []) {
|
60
|
-
|
61
|
-
// (1.1) is not a loop
|
62
|
-
if (!isAnyExactly(flowElement, LOOP_ELEMENT_TYPES)) {
|
63
|
-
return null;
|
64
|
-
}
|
65
|
-
|
66
|
-
const nextFlowElements = getNextFlowElements(flowElement);
|
67
|
-
|
68
|
-
// (1.2) is not a loop
|
69
|
-
if (!nextFlowElements.length) {
|
70
|
-
return null;
|
71
|
-
}
|
72
|
-
|
73
|
-
// (2) may be a loop
|
74
|
-
if (!visitedFlowElements.includes(flowElement)) {
|
75
|
-
return nextFlowElements.reduce((error, nextFlowElement) => {
|
76
|
-
return error || findLoop(nextFlowElement, parentElement, [ ...visitedFlowElements, flowElement ]);
|
77
|
-
}, null);
|
78
|
-
}
|
79
|
-
|
80
|
-
// (3) is a loop but ignored
|
81
|
-
if (isIgnoredLoop(visitedFlowElements)) {
|
82
|
-
return null;
|
83
|
-
}
|
84
|
-
|
85
|
-
const elements = visitedFlowElements.slice(visitedFlowElements.indexOf(flowElement));
|
86
|
-
|
87
|
-
// (4) is a loop
|
88
|
-
return {
|
89
|
-
message: `Loop detected: ${ elements.map(({ id }) => id).join(' -> ') } -> ${ flowElement.id }`,
|
90
|
-
path: null,
|
91
|
-
data: {
|
92
|
-
type: ERROR_TYPES.LOOP_NOT_ALLOWED,
|
93
|
-
node: parentElement,
|
94
|
-
parentNode: null,
|
95
|
-
elements: elements.map(({ id }) => id)
|
96
|
-
}
|
97
|
-
};
|
98
|
-
}
|
99
|
-
|
100
|
-
function getFlowElements(node) {
|
101
|
-
return node.get('flowElements').reduce((flowElements, flowElement) => {
|
102
|
-
if (is(flowElement, 'bpmn:FlowElementsContainer')) {
|
103
|
-
return [ ...flowElements, ...getFlowElements(flowElement) ];
|
104
|
-
}
|
105
|
-
|
106
|
-
return [ ...flowElements, flowElement ];
|
107
|
-
}, []);
|
108
|
-
}
|
109
|
-
|
110
|
-
function getNextFlowElements(flowElement) {
|
111
|
-
if (is(flowElement, 'bpmn:CallActivity')) {
|
112
|
-
const calledElement = findExtensionElement(flowElement, 'zeebe:CalledElement');
|
113
|
-
|
114
|
-
if (calledElement) {
|
115
|
-
const processId = calledElement.get('processId');
|
116
|
-
|
117
|
-
if (isString(processId) && !isFeel(processId)) {
|
118
|
-
const process = findParent(flowElement, 'bpmn:Process');
|
119
|
-
|
120
|
-
if (process && process.get('id') === processId) {
|
121
|
-
return process.get('flowElements').filter(flowElement => is(flowElement, 'bpmn:StartEvent'));
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
} else if (is(flowElement, 'bpmn:SubProcess')) {
|
126
|
-
return flowElement
|
127
|
-
.get('flowElements').filter(flowElement => is(flowElement, 'bpmn:StartEvent'));
|
128
|
-
} else if (is(flowElement, 'bpmn:EndEvent')) {
|
129
|
-
const parent = flowElement.$parent;
|
130
|
-
|
131
|
-
if (is(parent, 'bpmn:SubProcess')) {
|
132
|
-
flowElement = parent;
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
return flowElement
|
137
|
-
.get('outgoing').filter(outgoing => is(outgoing, 'bpmn:SequenceFlow')).map(sequenceFlow => sequenceFlow.get('targetRef'));
|
138
|
-
}
|
139
|
-
|
140
|
-
function isIgnoredLoop(elements) {
|
141
|
-
return !elements.some(element => isAnyExactly(element, LOOP_REQUIRED_ELEMENT_TYPES));
|
142
|
-
}
|
143
|
-
|
144
|
-
function isFeel(value) {
|
145
|
-
return isString(value) && value.startsWith('=');
|
1
|
+
const { isString } = require('min-dash');
|
2
|
+
|
3
|
+
const { is } = require('bpmnlint-utils');
|
4
|
+
|
5
|
+
const {
|
6
|
+
findExtensionElement,
|
7
|
+
findParent,
|
8
|
+
isAnyExactly
|
9
|
+
} = require('../utils/element');
|
10
|
+
|
11
|
+
const { reportErrors } = require('../utils/reporter');
|
12
|
+
|
13
|
+
const { ERROR_TYPES } = require('../utils/error-types');
|
14
|
+
|
15
|
+
const { skipInNonExecutableProcess } = require('../utils/rule');
|
16
|
+
|
17
|
+
const LOOP_REQUIRED_ELEMENT_TYPES = [
|
18
|
+
'bpmn:CallActivity',
|
19
|
+
'bpmn:ManualTask',
|
20
|
+
'bpmn:Task'
|
21
|
+
];
|
22
|
+
|
23
|
+
const LOOP_ELEMENT_TYPES = [
|
24
|
+
...LOOP_REQUIRED_ELEMENT_TYPES,
|
25
|
+
'bpmn:StartEvent',
|
26
|
+
'bpmn:EndEvent',
|
27
|
+
'bpmn:ManualTask',
|
28
|
+
'bpmn:ExclusiveGateway',
|
29
|
+
'bpmn:InclusiveGateway',
|
30
|
+
'bpmn:ParallelGateway',
|
31
|
+
'bpmn:SubProcess',
|
32
|
+
'bpmn:Task'
|
33
|
+
];
|
34
|
+
|
35
|
+
module.exports = skipInNonExecutableProcess(function() {
|
36
|
+
function check(node, reporter) {
|
37
|
+
if (!is(node, 'bpmn:Process')) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
const error = getFlowElements(node)
|
42
|
+
.filter(flowElement => {
|
43
|
+
return isAnyExactly(flowElement, LOOP_ELEMENT_TYPES);
|
44
|
+
})
|
45
|
+
.reduce((error, flowElement) => {
|
46
|
+
return error || findLoop(flowElement, node);
|
47
|
+
}, null);
|
48
|
+
|
49
|
+
if (error) {
|
50
|
+
reportErrors(node, reporter, error);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
return {
|
55
|
+
check
|
56
|
+
};
|
57
|
+
});
|
58
|
+
|
59
|
+
function findLoop(flowElement, parentElement, visitedFlowElements = []) {
|
60
|
+
|
61
|
+
// (1.1) is not a loop
|
62
|
+
if (!isAnyExactly(flowElement, LOOP_ELEMENT_TYPES)) {
|
63
|
+
return null;
|
64
|
+
}
|
65
|
+
|
66
|
+
const nextFlowElements = getNextFlowElements(flowElement);
|
67
|
+
|
68
|
+
// (1.2) is not a loop
|
69
|
+
if (!nextFlowElements.length) {
|
70
|
+
return null;
|
71
|
+
}
|
72
|
+
|
73
|
+
// (2) may be a loop
|
74
|
+
if (!visitedFlowElements.includes(flowElement)) {
|
75
|
+
return nextFlowElements.reduce((error, nextFlowElement) => {
|
76
|
+
return error || findLoop(nextFlowElement, parentElement, [ ...visitedFlowElements, flowElement ]);
|
77
|
+
}, null);
|
78
|
+
}
|
79
|
+
|
80
|
+
// (3) is a loop but ignored
|
81
|
+
if (isIgnoredLoop(visitedFlowElements)) {
|
82
|
+
return null;
|
83
|
+
}
|
84
|
+
|
85
|
+
const elements = visitedFlowElements.slice(visitedFlowElements.indexOf(flowElement));
|
86
|
+
|
87
|
+
// (4) is a loop
|
88
|
+
return {
|
89
|
+
message: `Loop detected: ${ elements.map(({ id }) => id).join(' -> ') } -> ${ flowElement.id }`,
|
90
|
+
path: null,
|
91
|
+
data: {
|
92
|
+
type: ERROR_TYPES.LOOP_NOT_ALLOWED,
|
93
|
+
node: parentElement,
|
94
|
+
parentNode: null,
|
95
|
+
elements: elements.map(({ id }) => id)
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|
99
|
+
|
100
|
+
function getFlowElements(node) {
|
101
|
+
return node.get('flowElements').reduce((flowElements, flowElement) => {
|
102
|
+
if (is(flowElement, 'bpmn:FlowElementsContainer')) {
|
103
|
+
return [ ...flowElements, ...getFlowElements(flowElement) ];
|
104
|
+
}
|
105
|
+
|
106
|
+
return [ ...flowElements, flowElement ];
|
107
|
+
}, []);
|
108
|
+
}
|
109
|
+
|
110
|
+
function getNextFlowElements(flowElement) {
|
111
|
+
if (is(flowElement, 'bpmn:CallActivity')) {
|
112
|
+
const calledElement = findExtensionElement(flowElement, 'zeebe:CalledElement');
|
113
|
+
|
114
|
+
if (calledElement) {
|
115
|
+
const processId = calledElement.get('processId');
|
116
|
+
|
117
|
+
if (isString(processId) && !isFeel(processId)) {
|
118
|
+
const process = findParent(flowElement, 'bpmn:Process');
|
119
|
+
|
120
|
+
if (process && process.get('id') === processId) {
|
121
|
+
return process.get('flowElements').filter(flowElement => is(flowElement, 'bpmn:StartEvent'));
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
} else if (is(flowElement, 'bpmn:SubProcess')) {
|
126
|
+
return flowElement
|
127
|
+
.get('flowElements').filter(flowElement => is(flowElement, 'bpmn:StartEvent'));
|
128
|
+
} else if (is(flowElement, 'bpmn:EndEvent')) {
|
129
|
+
const parent = flowElement.$parent;
|
130
|
+
|
131
|
+
if (is(parent, 'bpmn:SubProcess')) {
|
132
|
+
flowElement = parent;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
return flowElement
|
137
|
+
.get('outgoing').filter(outgoing => is(outgoing, 'bpmn:SequenceFlow')).map(sequenceFlow => sequenceFlow.get('targetRef'));
|
138
|
+
}
|
139
|
+
|
140
|
+
function isIgnoredLoop(elements) {
|
141
|
+
return !elements.some(element => isAnyExactly(element, LOOP_REQUIRED_ELEMENT_TYPES));
|
142
|
+
}
|
143
|
+
|
144
|
+
function isFeel(value) {
|
145
|
+
return isString(value) && value.startsWith('=');
|
146
146
|
}
|