bpmn-engine 21.1.0 → 22.0.1
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/lib/index.cjs +50 -50
- package/package.json +8 -9
- package/src/JavaScripts.js +6 -6
- package/src/index.js +40 -40
- package/types/bpmn-engine.d.ts +21 -4
package/lib/index.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var node_module = require('node:module');
|
|
6
|
+
var node_events = require('node:events');
|
|
7
|
+
var node_url = require('node:url');
|
|
8
8
|
var BpmnModdle = require('bpmn-moddle');
|
|
9
9
|
var Elements = require('bpmn-elements');
|
|
10
10
|
var smqp = require('smqp');
|
|
11
11
|
var serializer = require('moddle-context-serializer');
|
|
12
12
|
var Debug = require('debug');
|
|
13
|
-
var
|
|
13
|
+
var node_vm = require('node:vm');
|
|
14
14
|
|
|
15
15
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
16
|
function _interopNamespaceDefault(e) {
|
|
@@ -42,7 +42,7 @@ function Logger(scope) {
|
|
|
42
42
|
|
|
43
43
|
function Scripts(disableDummy) {
|
|
44
44
|
if (!(this instanceof Scripts)) return new Scripts(disableDummy);
|
|
45
|
-
this.scripts =
|
|
45
|
+
this.scripts = new Map();
|
|
46
46
|
this.disableDummy = disableDummy;
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -67,25 +67,25 @@ Scripts.prototype.register = function register({ id, type, behaviour, logger, en
|
|
|
67
67
|
if (!language || !scriptBody) {
|
|
68
68
|
if (this.disableDummy) return;
|
|
69
69
|
const script = new DummyScript(language, filename, logger);
|
|
70
|
-
this.scripts
|
|
70
|
+
this.scripts.set(id, script);
|
|
71
71
|
return script;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
if (!/^javascript$/i.test(language)) return;
|
|
74
|
+
if (!/^(javascript|js)$/i.test(language)) return;
|
|
75
75
|
|
|
76
76
|
const script = new JavaScript(language, filename, scriptBody, environment);
|
|
77
|
-
this.scripts
|
|
77
|
+
this.scripts.set(id, script);
|
|
78
78
|
|
|
79
79
|
return script;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
Scripts.prototype.getScript = function getScript(language, { id }) {
|
|
83
|
-
return this.scripts
|
|
83
|
+
return this.scripts.get(id);
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
function JavaScript(language, filename, scriptBody, environment) {
|
|
87
87
|
this.id = filename;
|
|
88
|
-
this.script = new
|
|
88
|
+
this.script = new node_vm.Script(scriptBody, { filename });
|
|
89
89
|
this.language = language;
|
|
90
90
|
this.environment = environment;
|
|
91
91
|
}
|
|
@@ -161,7 +161,7 @@ ProcessOutputDataObject.prototype.write = function writeDataObject(broker, excha
|
|
|
161
161
|
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
162
162
|
};
|
|
163
163
|
|
|
164
|
-
const nodeRequire =
|
|
164
|
+
const nodeRequire = node_module.createRequire(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
165
165
|
const { version: engineVersion } = nodeRequire('../package.json');
|
|
166
166
|
|
|
167
167
|
const kEngine = Symbol.for('engine');
|
|
@@ -171,7 +171,6 @@ const kExecution = Symbol.for('execution');
|
|
|
171
171
|
const kLoadedDefinitions = Symbol.for('loaded definitions');
|
|
172
172
|
const kOnBrokerReturn = Symbol.for('onBrokerReturn');
|
|
173
173
|
const kPendingSources = Symbol.for('pending sources');
|
|
174
|
-
const kSources = Symbol.for('sources');
|
|
175
174
|
const kState = Symbol.for('state');
|
|
176
175
|
const kStopped = Symbol.for('stopped');
|
|
177
176
|
const kTypeResolver = Symbol.for('type resolver');
|
|
@@ -179,7 +178,7 @@ const kTypeResolver = Symbol.for('type resolver');
|
|
|
179
178
|
function Engine(options = {}) {
|
|
180
179
|
if (!(this instanceof Engine)) return new Engine(options);
|
|
181
180
|
|
|
182
|
-
|
|
181
|
+
node_events.EventEmitter.call(this);
|
|
183
182
|
|
|
184
183
|
const opts = (this.options = {
|
|
185
184
|
Logger: Logger,
|
|
@@ -204,12 +203,11 @@ function Engine(options = {}) {
|
|
|
204
203
|
|
|
205
204
|
this[kExecution] = null;
|
|
206
205
|
this[kLoadedDefinitions] = null;
|
|
207
|
-
this[kSources] = [];
|
|
208
206
|
|
|
209
|
-
const pendingSources = (this[kPendingSources] =
|
|
210
|
-
if (opts.source) pendingSources.
|
|
211
|
-
if (opts.moddleContext) pendingSources.
|
|
212
|
-
if (opts.sourceContext) pendingSources.
|
|
207
|
+
const pendingSources = (this[kPendingSources] = new Set());
|
|
208
|
+
if (opts.source) pendingSources.add(this._serializeSource(opts.source));
|
|
209
|
+
if (opts.moddleContext) pendingSources.add(this._serializeModdleContext(opts.moddleContext));
|
|
210
|
+
if (opts.sourceContext) pendingSources.add(opts.sourceContext);
|
|
213
211
|
}
|
|
214
212
|
|
|
215
213
|
function defaultTypeResolver(elementTypes) {
|
|
@@ -217,7 +215,7 @@ function defaultTypeResolver(elementTypes) {
|
|
|
217
215
|
elementTypes['bpmn:DataStoreReference'] = ProcessOutputDataObject;
|
|
218
216
|
}
|
|
219
217
|
|
|
220
|
-
Engine.prototype = Object.create(
|
|
218
|
+
Engine.prototype = Object.create(node_events.EventEmitter.prototype);
|
|
221
219
|
|
|
222
220
|
Object.defineProperties(Engine.prototype, {
|
|
223
221
|
name: {
|
|
@@ -295,7 +293,8 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
295
293
|
if (!savedState.definitions) return this;
|
|
296
294
|
|
|
297
295
|
const pendingSources = this[kPendingSources];
|
|
298
|
-
const preSources = pendingSources
|
|
296
|
+
const preSources = [...pendingSources];
|
|
297
|
+
pendingSources.clear();
|
|
299
298
|
|
|
300
299
|
const typeResolver = this[kTypeResolver];
|
|
301
300
|
const loadedDefinitions = (this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
|
|
@@ -303,7 +302,7 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
303
302
|
if (dState.source) source = serializer.deserialize(JSON.parse(dState.source), typeResolver);
|
|
304
303
|
else source = preSources.find((s) => s.id === dState.id);
|
|
305
304
|
|
|
306
|
-
pendingSources.
|
|
305
|
+
pendingSources.add(source);
|
|
307
306
|
|
|
308
307
|
this.logger.debug(`<${name}> recover ${dState.type} <${dState.id}>`);
|
|
309
308
|
|
|
@@ -339,7 +338,7 @@ Engine.prototype.addSource = function addSource({ sourceContext: addContext } =
|
|
|
339
338
|
if (!addContext) return;
|
|
340
339
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
341
340
|
if (loadedDefinitions) loadedDefinitions.splice(0);
|
|
342
|
-
this[kPendingSources].
|
|
341
|
+
this[kPendingSources].add(addContext);
|
|
343
342
|
};
|
|
344
343
|
|
|
345
344
|
Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
|
|
@@ -413,9 +412,7 @@ Engine.prototype._serializeSource = async function serializeSource(source) {
|
|
|
413
412
|
};
|
|
414
413
|
|
|
415
414
|
Engine.prototype._serializeModdleContext = function serializeModdleContext(moddleContext) {
|
|
416
|
-
|
|
417
|
-
this[kSources].push(serialized);
|
|
418
|
-
return serialized;
|
|
415
|
+
return serializer(moddleContext, this[kTypeResolver], this.options.extendFn);
|
|
419
416
|
};
|
|
420
417
|
|
|
421
418
|
Engine.prototype._getModdleContext = function getModdleContext(source) {
|
|
@@ -431,7 +428,7 @@ function Execution(engine, definitions, options, isRecovered = false) {
|
|
|
431
428
|
this[kStopped] = isRecovered;
|
|
432
429
|
this[kEnvironment] = engine.environment;
|
|
433
430
|
this[kEngine] = engine;
|
|
434
|
-
this[kExecuting] =
|
|
431
|
+
this[kExecuting] = new Set();
|
|
435
432
|
const onBrokerReturn = (this[kOnBrokerReturn] = this._onBrokerReturn.bind(this));
|
|
436
433
|
engine.broker.on('return', onBrokerReturn);
|
|
437
434
|
}
|
|
@@ -462,6 +459,14 @@ Object.defineProperties(Execution.prototype, {
|
|
|
462
459
|
return this._getActivityStatus();
|
|
463
460
|
},
|
|
464
461
|
},
|
|
462
|
+
isRunning: {
|
|
463
|
+
get() {
|
|
464
|
+
for (const definition of this[kExecuting]) {
|
|
465
|
+
if (definition.isRunning) return true;
|
|
466
|
+
}
|
|
467
|
+
return false;
|
|
468
|
+
},
|
|
469
|
+
},
|
|
465
470
|
});
|
|
466
471
|
|
|
467
472
|
Execution.prototype._execute = function execute(executeOptions, callback) {
|
|
@@ -492,7 +497,7 @@ Execution.prototype._resume = function resume(resumeOptions, callback) {
|
|
|
492
497
|
this._debug('resume');
|
|
493
498
|
this._addConsumerCallbacks(callback);
|
|
494
499
|
|
|
495
|
-
this[kExecuting].
|
|
500
|
+
this[kExecuting].clear();
|
|
496
501
|
this.definitions.forEach((definition) => definition.resume());
|
|
497
502
|
|
|
498
503
|
return this;
|
|
@@ -554,9 +559,11 @@ Execution.prototype.stop = async function stop() {
|
|
|
554
559
|
this[kStopped] = true;
|
|
555
560
|
const timers = engine.environment.timers;
|
|
556
561
|
|
|
557
|
-
timers.executing.
|
|
562
|
+
timers.executing.forEach((ref) => timers.clearTimeout(ref));
|
|
558
563
|
|
|
559
|
-
this[kExecuting]
|
|
564
|
+
const executing = new Set(this[kExecuting]);
|
|
565
|
+
this[kExecuting].clear();
|
|
566
|
+
for (const definition of executing) definition.stop();
|
|
560
567
|
|
|
561
568
|
const result = await prom;
|
|
562
569
|
this[kState] = 'stopped';
|
|
@@ -590,17 +597,13 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
590
597
|
switch (routingKey) {
|
|
591
598
|
case 'definition.resume':
|
|
592
599
|
case 'definition.enter': {
|
|
593
|
-
|
|
594
|
-
const idx = executing.indexOf(owner);
|
|
595
|
-
if (idx > -1) break;
|
|
596
|
-
executing.push(owner);
|
|
600
|
+
this[kExecuting].add(owner);
|
|
597
601
|
break;
|
|
598
602
|
}
|
|
599
603
|
case 'definition.stop': {
|
|
600
604
|
this._teardownDefinition(owner);
|
|
601
605
|
|
|
602
|
-
|
|
603
|
-
if (executing.some((d) => d.isRunning)) break;
|
|
606
|
+
if (this.isRunning) break;
|
|
604
607
|
|
|
605
608
|
newState = 'stopped';
|
|
606
609
|
this[kStopped] = true;
|
|
@@ -609,7 +612,7 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
609
612
|
case 'definition.leave':
|
|
610
613
|
this._teardownDefinition(owner);
|
|
611
614
|
|
|
612
|
-
if (this
|
|
615
|
+
if (this.isRunning) break;
|
|
613
616
|
|
|
614
617
|
newState = 'idle';
|
|
615
618
|
break;
|
|
@@ -660,10 +663,7 @@ Execution.prototype._complete = function complete(eventType, content, messagePro
|
|
|
660
663
|
};
|
|
661
664
|
|
|
662
665
|
Execution.prototype._teardownDefinition = function teardownDefinition(definition) {
|
|
663
|
-
|
|
664
|
-
const idx = executing.indexOf(definition);
|
|
665
|
-
if (idx > -1) executing.splice(idx, 1);
|
|
666
|
-
|
|
666
|
+
this[kExecuting].delete(definition);
|
|
667
667
|
definition.broker.cancel('_engine_definition');
|
|
668
668
|
};
|
|
669
669
|
|
|
@@ -709,11 +709,12 @@ Execution.prototype.getActivityById = function getActivityById(activityId) {
|
|
|
709
709
|
};
|
|
710
710
|
|
|
711
711
|
Execution.prototype.getPostponed = function getPostponed() {
|
|
712
|
-
const
|
|
713
|
-
|
|
712
|
+
const definitions = this.stopped ? this.definitions : this[kExecuting];
|
|
713
|
+
let result = [];
|
|
714
|
+
for (const definition of definitions) {
|
|
714
715
|
result = result.concat(definition.getPostponed());
|
|
715
|
-
|
|
716
|
-
|
|
716
|
+
}
|
|
717
|
+
return result;
|
|
717
718
|
};
|
|
718
719
|
|
|
719
720
|
Execution.prototype.signal = function signal(payload, { ignoreSameDefinition } = {}) {
|
|
@@ -745,13 +746,12 @@ Execution.prototype._debug = function debug(msg) {
|
|
|
745
746
|
|
|
746
747
|
Execution.prototype._getActivityStatus = function getActivityStatus() {
|
|
747
748
|
let status = 'idle';
|
|
748
|
-
const
|
|
749
|
-
if (!
|
|
750
|
-
else if (running.length === 1) return running[0].activityStatus;
|
|
749
|
+
const executing = this[kExecuting];
|
|
750
|
+
if (!executing.size) return status;
|
|
751
751
|
|
|
752
|
-
for (const
|
|
753
|
-
const bpStatus =
|
|
754
|
-
switch (
|
|
752
|
+
for (const definition of executing) {
|
|
753
|
+
const bpStatus = definition.activityStatus;
|
|
754
|
+
switch (definition.activityStatus) {
|
|
755
755
|
case 'executing':
|
|
756
756
|
return bpStatus;
|
|
757
757
|
case 'timer':
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bpmn-engine",
|
|
3
3
|
"description": "BPMN 2.0 execution engine. Open source javascript workflow engine.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "22.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.js",
|
|
7
7
|
"main": "./lib/index.cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "https://github.com/paed01"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">=18"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"lib/",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "mocha -p -R @bonniernews/hot-bev",
|
|
28
|
-
"posttest": "npm run lint && npm run toc",
|
|
28
|
+
"posttest": "npm run lint && npm run toc && npm run dist",
|
|
29
29
|
"lint": "eslint . --cache && prettier . -c --cache",
|
|
30
30
|
"wintest": "mocha",
|
|
31
31
|
"cov:html": "c8 -r html -r text mocha -p -R @bonniernews/hot-bev",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
],
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@bonniernews/hot-bev": "^0.4.0",
|
|
55
|
-
"@rollup/plugin-commonjs": "^
|
|
55
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
56
56
|
"@types/bpmn-moddle": "^5.1.6",
|
|
57
57
|
"@types/node": "^18.19.31",
|
|
58
58
|
"bent": "^7.3.12",
|
|
59
|
-
"c8": "^
|
|
59
|
+
"c8": "^10.0.0",
|
|
60
60
|
"camunda-bpmn-moddle": "^7.0.1",
|
|
61
61
|
"chai": "^5.1.0",
|
|
62
62
|
"chronokinesis": "^6.0.0",
|
|
@@ -64,16 +64,15 @@
|
|
|
64
64
|
"markdown-toc": "^1.2.0",
|
|
65
65
|
"mocha": "^10.2.0",
|
|
66
66
|
"mocha-cakes-2": "^3.3.0",
|
|
67
|
-
"nock": "^13.3.2",
|
|
68
67
|
"prettier": "^3.2.5",
|
|
69
68
|
"rollup": "^4.10.0",
|
|
70
|
-
"texample": "^0.0.
|
|
69
|
+
"texample": "^0.0.5"
|
|
71
70
|
},
|
|
72
71
|
"dependencies": {
|
|
73
|
-
"bpmn-elements": "^
|
|
72
|
+
"bpmn-elements": "^15.0.1",
|
|
74
73
|
"bpmn-moddle": "^9.0.1",
|
|
75
74
|
"debug": "^4.3.4",
|
|
76
75
|
"moddle-context-serializer": "^4.2.0",
|
|
77
|
-
"smqp": "^
|
|
76
|
+
"smqp": "^9.0.2"
|
|
78
77
|
}
|
|
79
78
|
}
|
package/src/JavaScripts.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Script } from 'vm';
|
|
1
|
+
import { Script } from 'node:vm';
|
|
2
2
|
|
|
3
3
|
export default function Scripts(disableDummy) {
|
|
4
4
|
if (!(this instanceof Scripts)) return new Scripts(disableDummy);
|
|
5
|
-
this.scripts =
|
|
5
|
+
this.scripts = new Map();
|
|
6
6
|
this.disableDummy = disableDummy;
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -27,20 +27,20 @@ Scripts.prototype.register = function register({ id, type, behaviour, logger, en
|
|
|
27
27
|
if (!language || !scriptBody) {
|
|
28
28
|
if (this.disableDummy) return;
|
|
29
29
|
const script = new DummyScript(language, filename, logger);
|
|
30
|
-
this.scripts
|
|
30
|
+
this.scripts.set(id, script);
|
|
31
31
|
return script;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (!/^javascript$/i.test(language)) return;
|
|
34
|
+
if (!/^(javascript|js)$/i.test(language)) return;
|
|
35
35
|
|
|
36
36
|
const script = new JavaScript(language, filename, scriptBody, environment);
|
|
37
|
-
this.scripts
|
|
37
|
+
this.scripts.set(id, script);
|
|
38
38
|
|
|
39
39
|
return script;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
Scripts.prototype.getScript = function getScript(language, { id }) {
|
|
43
|
-
return this.scripts
|
|
43
|
+
return this.scripts.get(id);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
function JavaScript(language, filename, scriptBody, environment) {
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
5
|
import BpmnModdle from 'bpmn-moddle';
|
|
6
6
|
import * as Elements from 'bpmn-elements';
|
|
@@ -22,7 +22,6 @@ const kExecution = Symbol.for('execution');
|
|
|
22
22
|
const kLoadedDefinitions = Symbol.for('loaded definitions');
|
|
23
23
|
const kOnBrokerReturn = Symbol.for('onBrokerReturn');
|
|
24
24
|
const kPendingSources = Symbol.for('pending sources');
|
|
25
|
-
const kSources = Symbol.for('sources');
|
|
26
25
|
const kState = Symbol.for('state');
|
|
27
26
|
const kStopped = Symbol.for('stopped');
|
|
28
27
|
const kTypeResolver = Symbol.for('type resolver');
|
|
@@ -58,12 +57,11 @@ export function Engine(options = {}) {
|
|
|
58
57
|
|
|
59
58
|
this[kExecution] = null;
|
|
60
59
|
this[kLoadedDefinitions] = null;
|
|
61
|
-
this[kSources] = [];
|
|
62
60
|
|
|
63
|
-
const pendingSources = (this[kPendingSources] =
|
|
64
|
-
if (opts.source) pendingSources.
|
|
65
|
-
if (opts.moddleContext) pendingSources.
|
|
66
|
-
if (opts.sourceContext) pendingSources.
|
|
61
|
+
const pendingSources = (this[kPendingSources] = new Set());
|
|
62
|
+
if (opts.source) pendingSources.add(this._serializeSource(opts.source));
|
|
63
|
+
if (opts.moddleContext) pendingSources.add(this._serializeModdleContext(opts.moddleContext));
|
|
64
|
+
if (opts.sourceContext) pendingSources.add(opts.sourceContext);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
function defaultTypeResolver(elementTypes) {
|
|
@@ -149,7 +147,8 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
149
147
|
if (!savedState.definitions) return this;
|
|
150
148
|
|
|
151
149
|
const pendingSources = this[kPendingSources];
|
|
152
|
-
const preSources = pendingSources
|
|
150
|
+
const preSources = [...pendingSources];
|
|
151
|
+
pendingSources.clear();
|
|
153
152
|
|
|
154
153
|
const typeResolver = this[kTypeResolver];
|
|
155
154
|
const loadedDefinitions = (this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
|
|
@@ -157,7 +156,7 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
157
156
|
if (dState.source) source = deserialize(JSON.parse(dState.source), typeResolver);
|
|
158
157
|
else source = preSources.find((s) => s.id === dState.id);
|
|
159
158
|
|
|
160
|
-
pendingSources.
|
|
159
|
+
pendingSources.add(source);
|
|
161
160
|
|
|
162
161
|
this.logger.debug(`<${name}> recover ${dState.type} <${dState.id}>`);
|
|
163
162
|
|
|
@@ -193,7 +192,7 @@ Engine.prototype.addSource = function addSource({ sourceContext: addContext } =
|
|
|
193
192
|
if (!addContext) return;
|
|
194
193
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
195
194
|
if (loadedDefinitions) loadedDefinitions.splice(0);
|
|
196
|
-
this[kPendingSources].
|
|
195
|
+
this[kPendingSources].add(addContext);
|
|
197
196
|
};
|
|
198
197
|
|
|
199
198
|
Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
|
|
@@ -267,9 +266,7 @@ Engine.prototype._serializeSource = async function serializeSource(source) {
|
|
|
267
266
|
};
|
|
268
267
|
|
|
269
268
|
Engine.prototype._serializeModdleContext = function serializeModdleContext(moddleContext) {
|
|
270
|
-
|
|
271
|
-
this[kSources].push(serialized);
|
|
272
|
-
return serialized;
|
|
269
|
+
return serializer(moddleContext, this[kTypeResolver], this.options.extendFn);
|
|
273
270
|
};
|
|
274
271
|
|
|
275
272
|
Engine.prototype._getModdleContext = function getModdleContext(source) {
|
|
@@ -285,7 +282,7 @@ export function Execution(engine, definitions, options, isRecovered = false) {
|
|
|
285
282
|
this[kStopped] = isRecovered;
|
|
286
283
|
this[kEnvironment] = engine.environment;
|
|
287
284
|
this[kEngine] = engine;
|
|
288
|
-
this[kExecuting] =
|
|
285
|
+
this[kExecuting] = new Set();
|
|
289
286
|
const onBrokerReturn = (this[kOnBrokerReturn] = this._onBrokerReturn.bind(this));
|
|
290
287
|
engine.broker.on('return', onBrokerReturn);
|
|
291
288
|
}
|
|
@@ -316,6 +313,14 @@ Object.defineProperties(Execution.prototype, {
|
|
|
316
313
|
return this._getActivityStatus();
|
|
317
314
|
},
|
|
318
315
|
},
|
|
316
|
+
isRunning: {
|
|
317
|
+
get() {
|
|
318
|
+
for (const definition of this[kExecuting]) {
|
|
319
|
+
if (definition.isRunning) return true;
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
},
|
|
323
|
+
},
|
|
319
324
|
});
|
|
320
325
|
|
|
321
326
|
Execution.prototype._execute = function execute(executeOptions, callback) {
|
|
@@ -346,7 +351,7 @@ Execution.prototype._resume = function resume(resumeOptions, callback) {
|
|
|
346
351
|
this._debug('resume');
|
|
347
352
|
this._addConsumerCallbacks(callback);
|
|
348
353
|
|
|
349
|
-
this[kExecuting].
|
|
354
|
+
this[kExecuting].clear();
|
|
350
355
|
this.definitions.forEach((definition) => definition.resume());
|
|
351
356
|
|
|
352
357
|
return this;
|
|
@@ -408,9 +413,11 @@ Execution.prototype.stop = async function stop() {
|
|
|
408
413
|
this[kStopped] = true;
|
|
409
414
|
const timers = engine.environment.timers;
|
|
410
415
|
|
|
411
|
-
timers.executing.
|
|
416
|
+
timers.executing.forEach((ref) => timers.clearTimeout(ref));
|
|
412
417
|
|
|
413
|
-
this[kExecuting]
|
|
418
|
+
const executing = new Set(this[kExecuting]);
|
|
419
|
+
this[kExecuting].clear();
|
|
420
|
+
for (const definition of executing) definition.stop();
|
|
414
421
|
|
|
415
422
|
const result = await prom;
|
|
416
423
|
this[kState] = 'stopped';
|
|
@@ -444,17 +451,13 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
444
451
|
switch (routingKey) {
|
|
445
452
|
case 'definition.resume':
|
|
446
453
|
case 'definition.enter': {
|
|
447
|
-
|
|
448
|
-
const idx = executing.indexOf(owner);
|
|
449
|
-
if (idx > -1) break;
|
|
450
|
-
executing.push(owner);
|
|
454
|
+
this[kExecuting].add(owner);
|
|
451
455
|
break;
|
|
452
456
|
}
|
|
453
457
|
case 'definition.stop': {
|
|
454
458
|
this._teardownDefinition(owner);
|
|
455
459
|
|
|
456
|
-
|
|
457
|
-
if (executing.some((d) => d.isRunning)) break;
|
|
460
|
+
if (this.isRunning) break;
|
|
458
461
|
|
|
459
462
|
newState = 'stopped';
|
|
460
463
|
this[kStopped] = true;
|
|
@@ -463,7 +466,7 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
463
466
|
case 'definition.leave':
|
|
464
467
|
this._teardownDefinition(owner);
|
|
465
468
|
|
|
466
|
-
if (this
|
|
469
|
+
if (this.isRunning) break;
|
|
467
470
|
|
|
468
471
|
newState = 'idle';
|
|
469
472
|
break;
|
|
@@ -514,10 +517,7 @@ Execution.prototype._complete = function complete(eventType, content, messagePro
|
|
|
514
517
|
};
|
|
515
518
|
|
|
516
519
|
Execution.prototype._teardownDefinition = function teardownDefinition(definition) {
|
|
517
|
-
|
|
518
|
-
const idx = executing.indexOf(definition);
|
|
519
|
-
if (idx > -1) executing.splice(idx, 1);
|
|
520
|
-
|
|
520
|
+
this[kExecuting].delete(definition);
|
|
521
521
|
definition.broker.cancel('_engine_definition');
|
|
522
522
|
};
|
|
523
523
|
|
|
@@ -563,11 +563,12 @@ Execution.prototype.getActivityById = function getActivityById(activityId) {
|
|
|
563
563
|
};
|
|
564
564
|
|
|
565
565
|
Execution.prototype.getPostponed = function getPostponed() {
|
|
566
|
-
const
|
|
567
|
-
|
|
566
|
+
const definitions = this.stopped ? this.definitions : this[kExecuting];
|
|
567
|
+
let result = [];
|
|
568
|
+
for (const definition of definitions) {
|
|
568
569
|
result = result.concat(definition.getPostponed());
|
|
569
|
-
|
|
570
|
-
|
|
570
|
+
}
|
|
571
|
+
return result;
|
|
571
572
|
};
|
|
572
573
|
|
|
573
574
|
Execution.prototype.signal = function signal(payload, { ignoreSameDefinition } = {}) {
|
|
@@ -599,13 +600,12 @@ Execution.prototype._debug = function debug(msg) {
|
|
|
599
600
|
|
|
600
601
|
Execution.prototype._getActivityStatus = function getActivityStatus() {
|
|
601
602
|
let status = 'idle';
|
|
602
|
-
const
|
|
603
|
-
if (!
|
|
604
|
-
else if (running.length === 1) return running[0].activityStatus;
|
|
603
|
+
const executing = this[kExecuting];
|
|
604
|
+
if (!executing.size) return status;
|
|
605
605
|
|
|
606
|
-
for (const
|
|
607
|
-
const bpStatus =
|
|
608
|
-
switch (
|
|
606
|
+
for (const definition of executing) {
|
|
607
|
+
const bpStatus = definition.activityStatus;
|
|
608
|
+
switch (definition.activityStatus) {
|
|
609
609
|
case 'executing':
|
|
610
610
|
return bpStatus;
|
|
611
611
|
case 'timer':
|
package/types/bpmn-engine.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// Author : Saeed Tabrizi
|
|
2
2
|
// Refactored by : Pål Edman
|
|
3
3
|
|
|
4
|
-
import { EventEmitter } from 'events';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { Definitions as BpmnModdleDefinitions } from 'bpmn-moddle';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
extendFn,
|
|
8
|
+
SerializableContext,
|
|
9
|
+
TypeResolver,
|
|
10
|
+
} from 'moddle-context-serializer';
|
|
7
11
|
import {
|
|
8
12
|
ActivityStatus,
|
|
9
13
|
ElementBroker,
|
|
@@ -68,8 +72,12 @@ declare module 'bpmn-engine' {
|
|
|
68
72
|
[name: string]: any;
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
export interface IListenerEmitter {
|
|
76
|
+
emit(eventName: string, ...args: any[]): void;
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
export interface BpmnEngineExecuteOptions extends EnvironmentOptions {
|
|
72
|
-
listener?: EventEmitter;
|
|
80
|
+
listener?: EventEmitter | IListenerEmitter;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
export interface BpmnEngineOptions extends BpmnEngineExecuteOptions {
|
|
@@ -89,15 +97,20 @@ declare module 'bpmn-engine' {
|
|
|
89
97
|
* optional override of BPMN Elements behaviors, defaults to bpmn-elements
|
|
90
98
|
*/
|
|
91
99
|
elements?: Record<string, any>;
|
|
100
|
+
/**
|
|
101
|
+
* Passed to moddle-context-serializer as TypeResolver
|
|
102
|
+
*/
|
|
103
|
+
typeResolver?: typeof TypeResolver;
|
|
92
104
|
/**
|
|
93
105
|
* Passed to moddle-context-serializer as extendFn
|
|
94
106
|
*/
|
|
95
|
-
|
|
107
|
+
extendFn?: extendFn;
|
|
96
108
|
/**
|
|
97
109
|
* optional bpmn-moddle options to be passed to bpmn-moddle
|
|
98
110
|
*/
|
|
99
111
|
moddleOptions?: any;
|
|
100
112
|
moddleContext?: BpmnModdleDefinitions;
|
|
113
|
+
[x: string]: any;
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
const enum BpmnEngineRunningStatus {
|
|
@@ -267,6 +280,10 @@ declare module 'bpmn-engine' {
|
|
|
267
280
|
*/
|
|
268
281
|
readonly definitions: Definition[];
|
|
269
282
|
get activityStatus(): ActivityStatus;
|
|
283
|
+
/**
|
|
284
|
+
* Are any definition running
|
|
285
|
+
*/
|
|
286
|
+
get isRunning(): boolean;
|
|
270
287
|
|
|
271
288
|
/**
|
|
272
289
|
* Get activity/element by id. Loops the definitions and returns the first found activity with id.
|