@onify/flow-extensions 8.0.0 → 8.0.2
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/FlowScripts.d.ts +1 -0
- package/README.md +110 -23
- package/dist/OnifyTimerEventDefinition.js +11 -4
- package/package.json +15 -4
- package/src/OnifyTimerEventDefinition.js +13 -4
- package/{index.d.ts → types/index.d.ts} +6 -1
package/FlowScripts.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './types/index.js';
|
package/README.md
CHANGED
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
## Bpmn engine example
|
|
13
13
|
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
```javascript
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { Engine } from 'bpmn-engine';
|
|
18
|
+
import { extensions } from '@onify/flow-extensions';
|
|
19
|
+
import { FlowScripts } from '@onify/flow-extensions/FlowScripts';
|
|
20
|
+
|
|
21
|
+
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
|
|
18
22
|
|
|
19
23
|
const source = `
|
|
20
24
|
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
@@ -23,7 +27,7 @@ const source = `
|
|
|
23
27
|
<process id="theProcess" isExecutable="true">
|
|
24
28
|
<serviceTask id="task1" camunda:expression="\${environment.services.serviceFn}" camunda:resultVariable="result" />
|
|
25
29
|
<sequenceFlow id="to-task2" sourceRef="task1" targetRef="task2" />
|
|
26
|
-
<scriptTask id="task2" camunda:resultVariable="out">
|
|
30
|
+
<scriptTask id="task2" camunda:resultVariable="out" scriptFormat="js">
|
|
27
31
|
<script>
|
|
28
32
|
next(null, myContextFn());
|
|
29
33
|
</script>
|
|
@@ -36,7 +40,7 @@ const engine = new Engine({
|
|
|
36
40
|
name,
|
|
37
41
|
source,
|
|
38
42
|
moddleOptions: {
|
|
39
|
-
camunda:
|
|
43
|
+
camunda: nodeRequire('camunda-bpmn-moddle/resources/camunda.json'),
|
|
40
44
|
},
|
|
41
45
|
services: {
|
|
42
46
|
serviceFn(scope, callback) {
|
|
@@ -61,12 +65,15 @@ engine.execute((err, instance) => {
|
|
|
61
65
|
|
|
62
66
|
## Extract scripts with extend function
|
|
63
67
|
|
|
64
|
-
```
|
|
65
|
-
|
|
68
|
+
```javascript
|
|
69
|
+
import { createRequire } from 'node:module';
|
|
70
|
+
import { fileURLToPath } from 'node:url';
|
|
71
|
+
import BpmnModdle from 'bpmn-moddle';
|
|
72
|
+
import * as Elements from 'bpmn-elements';
|
|
73
|
+
import { Serializer, TypeResolver } from 'moddle-context-serializer';
|
|
74
|
+
import { extendFn } from '@onify/flow-extensions';
|
|
66
75
|
|
|
67
|
-
const
|
|
68
|
-
const Elements = require('bpmn-elements');
|
|
69
|
-
const { default: Serializer, TypeResolver } = require('moddle-context-serializer');
|
|
76
|
+
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
|
|
70
77
|
|
|
71
78
|
const source = `
|
|
72
79
|
<definitions id="Def_0" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
@@ -97,7 +104,7 @@ const source = `
|
|
|
97
104
|
</extensionElements>
|
|
98
105
|
</serviceTask>
|
|
99
106
|
<sequenceFlow id="to-task2" sourceRef="task1" targetRef="task2" />
|
|
100
|
-
<scriptTask id="task2" camunda:resultVariable="out">
|
|
107
|
+
<scriptTask id="task2" camunda:resultVariable="out" scriptFormat="js">
|
|
101
108
|
<script>
|
|
102
109
|
next(null, 2);
|
|
103
110
|
</script>
|
|
@@ -105,14 +112,85 @@ const source = `
|
|
|
105
112
|
</process>
|
|
106
113
|
</definitions>`;
|
|
107
114
|
|
|
108
|
-
(
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
getScripts(source).then(console.log).catch(console.error);
|
|
116
|
+
|
|
117
|
+
async function getScripts(bpmnSource) {
|
|
118
|
+
const moddle = await getModdleContext(bpmnSource, {
|
|
119
|
+
camunda: nodeRequire('camunda-bpmn-moddle/resources/camunda.json'),
|
|
111
120
|
});
|
|
112
121
|
|
|
113
122
|
const serialized = Serializer(moddle, TypeResolver(Elements), extendFn);
|
|
114
|
-
|
|
115
|
-
}
|
|
123
|
+
return serialized.elements.scripts;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getModdleContext(source, options) {
|
|
127
|
+
const bpmnModdle = new BpmnModdle(options);
|
|
128
|
+
return bpmnModdle.fromXML(Buffer.isBuffer(source) ? source.toString() : source.trim());
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Extract timers
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
import { createRequire } from 'node:module';
|
|
136
|
+
import { fileURLToPath } from 'node:url';
|
|
137
|
+
import BpmnModdle from 'bpmn-moddle';
|
|
138
|
+
import * as Elements from 'bpmn-elements';
|
|
139
|
+
import { Serializer, TypeResolver } from 'moddle-context-serializer';
|
|
140
|
+
import { extendFn, OnifyTimerEventDefinition } from '@onify/flow-extensions';
|
|
141
|
+
|
|
142
|
+
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
|
|
143
|
+
|
|
144
|
+
const source = `
|
|
145
|
+
<definitions id="Def_0" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
146
|
+
xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
|
|
147
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
148
|
+
targetNamespace="http://bpmn.io/schema/bpmn">
|
|
149
|
+
<process id="cycle-1" name="Onify start at time cycle" isExecutable="true" camunda:historyTimeToLive="PT180M">
|
|
150
|
+
<startEvent id="start">
|
|
151
|
+
<timerEventDefinition>
|
|
152
|
+
<timeCycle xsi:type="tFormalExpression">0 1 * * *</timeCycle>
|
|
153
|
+
</timerEventDefinition>
|
|
154
|
+
</startEvent>
|
|
155
|
+
<sequenceFlow id="to-task" sourceRef="start" targetRef="task" />
|
|
156
|
+
<userTask id="task" />
|
|
157
|
+
<boundaryEvent id="bound-timer" cancelActivity="false" attachedToRef="task">
|
|
158
|
+
<timerEventDefinition>
|
|
159
|
+
<timeDuration xsi:type="tFormalExpression">R3/PT1M</timeDuration>
|
|
160
|
+
</timerEventDefinition>
|
|
161
|
+
</boundaryEvent>
|
|
162
|
+
<sequenceFlow id="to-wait" sourceRef="task" targetRef="wait" />
|
|
163
|
+
<intermediateThrowEvent id="timer">
|
|
164
|
+
<timerEventDefinition>
|
|
165
|
+
<timeCycle xsi:type="tFormalExpression">\${environment.settings.postpone}</timeCycle>
|
|
166
|
+
</timerEventDefinition>
|
|
167
|
+
</intermediateThrowEvent>
|
|
168
|
+
<sequenceFlow id="to-end" sourceRef="wait" targetRef="end" />
|
|
169
|
+
<endEvent id="end" />
|
|
170
|
+
</process>
|
|
171
|
+
</definitions>`;
|
|
172
|
+
|
|
173
|
+
getTimers(source).then(console.log).catch(console.error);
|
|
174
|
+
|
|
175
|
+
const dummyEventActivity = { broker: {}, environment: { Logger() {} } };
|
|
176
|
+
|
|
177
|
+
async function getTimers(bpmnSource) {
|
|
178
|
+
const moddle = await getModdleContext(bpmnSource, {
|
|
179
|
+
camunda: nodeRequire('camunda-bpmn-moddle/resources/camunda.json'),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const serialized = Serializer(moddle, TypeResolver(Elements), extendFn);
|
|
183
|
+
|
|
184
|
+
for (const t of serialized.elements.timers) {
|
|
185
|
+
const ed = new OnifyTimerEventDefinition(dummyEventActivity, t.timer);
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
t.parsed = ed.parse(t.timer.timerType, t.timer.value);
|
|
189
|
+
} catch {}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return serialized.elements.timers;
|
|
193
|
+
}
|
|
116
194
|
|
|
117
195
|
function getModdleContext(source, options) {
|
|
118
196
|
const bpmnModdle = new BpmnModdle(options);
|
|
@@ -122,11 +200,15 @@ function getModdleContext(source, options) {
|
|
|
122
200
|
|
|
123
201
|
## Extend sequence flow with properties and take listeners
|
|
124
202
|
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
203
|
+
```javascript
|
|
204
|
+
import { createRequire } from 'node:module';
|
|
205
|
+
import { fileURLToPath } from 'node:url';
|
|
206
|
+
import { Engine } from 'bpmn-engine';
|
|
207
|
+
import * as Elements from 'bpmn-elements';
|
|
208
|
+
import { OnifySequenceFlow, extensions } from '@onify/flow-extensions';
|
|
209
|
+
import { FlowScripts } from '@onify/flow-extensions/FlowScripts';
|
|
210
|
+
|
|
211
|
+
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
|
|
130
212
|
|
|
131
213
|
const source = `
|
|
132
214
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -191,7 +273,7 @@ const engine = new Engine({
|
|
|
191
273
|
name: 'sequence flow extension',
|
|
192
274
|
source,
|
|
193
275
|
moddleOptions: {
|
|
194
|
-
camunda:
|
|
276
|
+
camunda: nodeRequire('camunda-bpmn-moddle/resources/camunda.json'),
|
|
195
277
|
},
|
|
196
278
|
extensions: {
|
|
197
279
|
onify: extensions,
|
|
@@ -201,6 +283,11 @@ const engine = new Engine({
|
|
|
201
283
|
...Elements,
|
|
202
284
|
SequenceFlow: OnifySequenceFlow,
|
|
203
285
|
},
|
|
286
|
+
variables: {
|
|
287
|
+
required: {
|
|
288
|
+
input: true,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
204
291
|
});
|
|
205
292
|
|
|
206
293
|
engine.execute((err, instance) => {
|
|
@@ -7,6 +7,7 @@ exports.OnifyTimerEventDefinition = void 0;
|
|
|
7
7
|
var _cronParser = _interopRequireDefault(require("cron-parser"));
|
|
8
8
|
var _bpmnElements = require("bpmn-elements");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const invalidCronEntryPattern = /Invalid (characters|range)/i;
|
|
10
11
|
class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
|
|
11
12
|
constructor(activity, def) {
|
|
12
13
|
super(activity, def);
|
|
@@ -15,15 +16,21 @@ class OnifyTimerEventDefinition extends _bpmnElements.TimerEventDefinition {
|
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
parse(timerType, value) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (timerType === 'timeCycle') {
|
|
20
|
+
try {
|
|
21
|
+
return super.parse(timerType, value);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
var rangeError = err;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
22
26
|
const expireAt = _cronParser.default.parseExpression(value).next().toDate();
|
|
23
27
|
return {
|
|
24
28
|
expireAt,
|
|
25
29
|
delay: expireAt - Date.now()
|
|
26
30
|
};
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (invalidCronEntryPattern.test(err.message)) throw rangeError;
|
|
33
|
+
throw err;
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
return super.parse(timerType, value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onify/flow-extensions",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Onify Flow extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -8,8 +8,16 @@
|
|
|
8
8
|
"types": "./index.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"exports": {
|
|
11
|
-
"
|
|
12
|
-
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./types/index.d.ts",
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"import": "./src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./FlowScripts": {
|
|
17
|
+
"types": "./types/index.d.ts",
|
|
18
|
+
"require": "./dist/FlowScripts.js",
|
|
19
|
+
"import": "./dist/FlowScripts.js"
|
|
20
|
+
}
|
|
13
21
|
},
|
|
14
22
|
"scripts": {
|
|
15
23
|
"test": "mocha -R dot",
|
|
@@ -17,6 +25,7 @@
|
|
|
17
25
|
"lint": "eslint . --cache && prettier . --check --cache",
|
|
18
26
|
"prepare": "npm run dist",
|
|
19
27
|
"dist": "babel src -d dist && babel test/helpers/FlowScripts.js -d dist",
|
|
28
|
+
"test:md": "node --experimental-vm-modules --no-warnings scripts/test-markdown.js ./README.md",
|
|
20
29
|
"test:lcov": "c8 -r lcov mocha && npm run lint",
|
|
21
30
|
"cov:html": "c8 mocha -R dot && c8 report --reporter html"
|
|
22
31
|
},
|
|
@@ -55,6 +64,7 @@
|
|
|
55
64
|
"mocha": "^10.2.0",
|
|
56
65
|
"mocha-cakes-2": "^3.3.0",
|
|
57
66
|
"moddle-context-serializer": "^4.1.1",
|
|
67
|
+
"nock": "^13.5.4",
|
|
58
68
|
"prettier": "^3.2.4"
|
|
59
69
|
},
|
|
60
70
|
"peerDependencies": {
|
|
@@ -67,7 +77,8 @@
|
|
|
67
77
|
"files": [
|
|
68
78
|
"src",
|
|
69
79
|
"dist",
|
|
70
|
-
"
|
|
80
|
+
"types",
|
|
81
|
+
"FlowScripts.d.ts"
|
|
71
82
|
],
|
|
72
83
|
"c8": {
|
|
73
84
|
"exclude": [
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import cronParser from 'cron-parser';
|
|
2
2
|
import { TimerEventDefinition } from 'bpmn-elements';
|
|
3
3
|
|
|
4
|
+
const invalidCronEntryPattern = /Invalid (characters|range)/i;
|
|
5
|
+
|
|
4
6
|
export class OnifyTimerEventDefinition extends TimerEventDefinition {
|
|
5
7
|
constructor(activity, def) {
|
|
6
8
|
super(activity, def);
|
|
@@ -9,16 +11,23 @@ export class OnifyTimerEventDefinition extends TimerEventDefinition {
|
|
|
9
11
|
});
|
|
10
12
|
}
|
|
11
13
|
parse(timerType, value) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (timerType === 'timeCycle') {
|
|
15
|
+
try {
|
|
16
|
+
return super.parse(timerType, value);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
var rangeError = err;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
16
22
|
const expireAt = cronParser.parseExpression(value).next().toDate();
|
|
17
23
|
|
|
18
24
|
return {
|
|
19
25
|
expireAt,
|
|
20
26
|
delay: expireAt - Date.now(),
|
|
21
27
|
};
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (invalidCronEntryPattern.test(err.message)) throw rangeError;
|
|
30
|
+
throw err;
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
33
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare module '@onify/flow-extensions' {
|
|
2
|
-
import { SequenceFlow, TimerEventDefinition, ElementBase,
|
|
2
|
+
import { SequenceFlow, TimerEventDefinition, ElementBase, IExtension } from 'bpmn-elements';
|
|
3
3
|
import { extendFn as extendFunction } from 'moddle-context-serializer';
|
|
4
4
|
|
|
5
5
|
export class OnifySequenceFlow extends SequenceFlow {}
|
|
@@ -9,3 +9,8 @@ declare module '@onify/flow-extensions' {
|
|
|
9
9
|
export function extensions(element: ElementBase, context: Context): IExtension;
|
|
10
10
|
export const extendFn: extendFunction;
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
declare module '@onify/flow-extensions/FlowScripts' {
|
|
14
|
+
import { IScripts } from 'bpmn-elements';
|
|
15
|
+
export var FlowScripts: IScripts;
|
|
16
|
+
}
|