bpmn-engine 19.0.0 → 20.0.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/README.md +20 -3
- package/lib/index.cjs +769 -0
- package/package.json +23 -13
- package/{lib → src}/JavaScripts.js +7 -11
- package/{lib → src}/Logger.js +3 -5
- package/src/extensions/ProcessOutputDataObject.js +41 -0
- package/{lib → src}/getOptionsAndCallback.js +2 -4
- package/{index.js → src/index.js} +121 -91
- package/types/bpmn-engine.d.ts +45 -12
- package/CHANGELOG.md +0 -363
- package/lib/extensions/ProcessOutputDataObject.js +0 -27
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bpmn-engine",
|
|
3
3
|
"description": "BPMN 2.0 execution engine. Open source javascript workflow engine.",
|
|
4
|
-
"version": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"version": "20.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./src/index.js",
|
|
7
|
+
"main": "./lib/index.cjs",
|
|
8
|
+
"types": "./types/bpmn-engine.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "git://github.com/paed01/bpmn-engine"
|
|
@@ -17,18 +20,20 @@
|
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
19
22
|
"lib/",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
23
|
+
"src/",
|
|
24
|
+
"types/"
|
|
22
25
|
],
|
|
23
26
|
"scripts": {
|
|
24
|
-
"test": "mocha -R
|
|
27
|
+
"test": "mocha -p -R @bonniernews/hot-bev",
|
|
25
28
|
"posttest": "npm run lint && npm run toc",
|
|
26
|
-
"lint": "eslint . --cache",
|
|
29
|
+
"lint": "eslint . --cache && prettier . -c --cache",
|
|
27
30
|
"wintest": "mocha",
|
|
28
|
-
"cov:html": "c8 -r html -r text mocha -R
|
|
31
|
+
"cov:html": "c8 -r html -r text mocha -p -R @bonniernews/hot-bev",
|
|
29
32
|
"test:lcov": "c8 -r lcov mocha && npm run lint",
|
|
30
33
|
"toc": "node scripts/generate-api-toc ./docs/API.md,./docs/Examples.md",
|
|
31
|
-
"test-md": "node scripts/test-markdown.js ./docs/API.md
|
|
34
|
+
"test-md": "node --experimental-vm-modules --no-warnings scripts/test-markdown.js ./docs/API.md,./docs/Examples.md,./docs/Upgrade.md",
|
|
35
|
+
"dist": "rollup -c",
|
|
36
|
+
"prepack": "npm run dist"
|
|
32
37
|
},
|
|
33
38
|
"keywords": [
|
|
34
39
|
"workflow",
|
|
@@ -46,20 +51,25 @@
|
|
|
46
51
|
}
|
|
47
52
|
],
|
|
48
53
|
"devDependencies": {
|
|
54
|
+
"@bonniernews/hot-bev": "^0.4.0",
|
|
55
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
56
|
+
"@types/bpmn-moddle": "^5.1.6",
|
|
49
57
|
"bent": "^7.3.12",
|
|
50
58
|
"c8": "^9.1.0",
|
|
51
59
|
"camunda-bpmn-moddle": "^7.0.1",
|
|
52
|
-
"chai": "^
|
|
60
|
+
"chai": "^5.1.0",
|
|
53
61
|
"chronokinesis": "^6.0.0",
|
|
54
62
|
"eslint": "^8.45.0",
|
|
63
|
+
"eslint-plugin-import": "^2.29.1",
|
|
55
64
|
"markdown-toc": "^1.2.0",
|
|
56
65
|
"mocha": "^10.2.0",
|
|
57
66
|
"mocha-cakes-2": "^3.3.0",
|
|
58
|
-
"nock": "^13.3.2"
|
|
67
|
+
"nock": "^13.3.2",
|
|
68
|
+
"prettier": "^3.2.5",
|
|
69
|
+
"rollup": "^4.10.0"
|
|
59
70
|
},
|
|
60
71
|
"dependencies": {
|
|
61
|
-
"
|
|
62
|
-
"bpmn-elements": "^13.1.1",
|
|
72
|
+
"bpmn-elements": "^13.1.2",
|
|
63
73
|
"bpmn-moddle": "^8.0.1",
|
|
64
74
|
"debug": "^4.3.4",
|
|
65
75
|
"moddle-context-serializer": "^4.0.0",
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { Script } from 'vm';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = Scripts;
|
|
6
|
-
|
|
7
|
-
function Scripts(disableDummy) {
|
|
3
|
+
export default function Scripts(disableDummy) {
|
|
8
4
|
if (!(this instanceof Scripts)) return new Scripts(disableDummy);
|
|
9
5
|
this.scripts = {};
|
|
10
6
|
this.disableDummy = disableDummy;
|
|
11
7
|
}
|
|
12
8
|
|
|
13
|
-
Scripts.prototype.register = function register({id, type, behaviour, logger, environment}) {
|
|
9
|
+
Scripts.prototype.register = function register({ id, type, behaviour, logger, environment }) {
|
|
14
10
|
let scriptBody, language;
|
|
15
11
|
|
|
16
12
|
switch (type) {
|
|
@@ -43,20 +39,20 @@ Scripts.prototype.register = function register({id, type, behaviour, logger, env
|
|
|
43
39
|
return script;
|
|
44
40
|
};
|
|
45
41
|
|
|
46
|
-
Scripts.prototype.getScript = function getScript(language, {id}) {
|
|
42
|
+
Scripts.prototype.getScript = function getScript(language, { id }) {
|
|
47
43
|
return this.scripts[id];
|
|
48
44
|
};
|
|
49
45
|
|
|
50
46
|
function JavaScript(language, filename, scriptBody, environment) {
|
|
51
47
|
this.id = filename;
|
|
52
|
-
this.script = new Script(scriptBody, {filename});
|
|
48
|
+
this.script = new Script(scriptBody, { filename });
|
|
53
49
|
this.language = language;
|
|
54
50
|
this.environment = environment;
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
JavaScript.prototype.execute = function execute(executionContext, callback) {
|
|
58
54
|
const timers = this.environment.timers.register(executionContext);
|
|
59
|
-
return this.script.runInNewContext({...executionContext, ...timers, next: callback});
|
|
55
|
+
return this.script.runInNewContext({ ...executionContext, ...timers, next: callback });
|
|
60
56
|
};
|
|
61
57
|
|
|
62
58
|
function DummyScript(language, filename, logger) {
|
|
@@ -67,7 +63,7 @@ function DummyScript(language, filename, logger) {
|
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
DummyScript.prototype.execute = function execute(executionContext, callback) {
|
|
70
|
-
const {id, executionId} = executionContext.content;
|
|
66
|
+
const { id, executionId } = executionContext.content;
|
|
71
67
|
this.logger.debug(`<${executionId} (${id})> passthrough dummy script ${this.language || 'esperanto'}`);
|
|
72
68
|
callback();
|
|
73
69
|
};
|
package/{lib → src}/Logger.js
RENAMED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import Debug from 'debug';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = function Logger(scope) {
|
|
3
|
+
export default function Logger(scope) {
|
|
6
4
|
return {
|
|
7
5
|
debug: Debug('bpmn-engine:' + scope),
|
|
8
6
|
error: Debug('bpmn-engine:error:' + scope),
|
|
9
7
|
warn: Debug('bpmn-engine:warn:' + scope),
|
|
10
8
|
};
|
|
11
|
-
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const kDataObjectDef = Symbol.for('data object definition');
|
|
2
|
+
|
|
3
|
+
export default function ProcessOutputDataObject(dataObjectDef, { environment }) {
|
|
4
|
+
this[kDataObjectDef] = dataObjectDef;
|
|
5
|
+
this.environment = environment;
|
|
6
|
+
this.behaviour = dataObjectDef.behaviour;
|
|
7
|
+
this.name = dataObjectDef.name;
|
|
8
|
+
this.parent = dataObjectDef.parent;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Object.defineProperties(ProcessOutputDataObject.prototype, {
|
|
12
|
+
id: {
|
|
13
|
+
get() {
|
|
14
|
+
return this[kDataObjectDef].id;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
type: {
|
|
18
|
+
get() {
|
|
19
|
+
return this[kDataObjectDef].type;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
ProcessOutputDataObject.prototype.read = function readDataObject(broker, exchange, routingKeyPrefix, messageProperties) {
|
|
25
|
+
const environment = this.environment;
|
|
26
|
+
const { id, name, type } = this;
|
|
27
|
+
const value = environment.variables.data && environment.variables.data[this.id];
|
|
28
|
+
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
ProcessOutputDataObject.prototype.write = function writeDataObject(broker, exchange, routingKeyPrefix, value, messageProperties) {
|
|
32
|
+
const environment = this.environment;
|
|
33
|
+
const { id, name, type } = this;
|
|
34
|
+
|
|
35
|
+
environment.variables.data = environment.variables.data || {};
|
|
36
|
+
environment.variables.data[id] = value;
|
|
37
|
+
|
|
38
|
+
environment.output.data = environment.output.data || {};
|
|
39
|
+
environment.output.data[id] = value;
|
|
40
|
+
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
41
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = function getOptionsAndCallback(optionsOrCallback, callback) {
|
|
1
|
+
export default function getOptionsAndCallback(optionsOrCallback, callback) {
|
|
4
2
|
let options;
|
|
5
3
|
if (typeof optionsOrCallback === 'function') {
|
|
6
4
|
callback = optionsOrCallback;
|
|
@@ -9,4 +7,4 @@ module.exports = function getOptionsAndCallback(optionsOrCallback, callback) {
|
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
return [options, callback];
|
|
12
|
-
}
|
|
10
|
+
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
import BpmnModdle from 'bpmn-moddle';
|
|
6
|
+
import * as Elements from 'bpmn-elements';
|
|
7
|
+
import { Broker } from 'smqp';
|
|
8
|
+
import serializer, { deserialize, TypeResolver } from 'moddle-context-serializer';
|
|
9
|
+
|
|
10
|
+
import DebugLogger from './Logger.js';
|
|
11
|
+
import JavaScripts from './JavaScripts.js';
|
|
12
|
+
import getOptionsAndCallback from './getOptionsAndCallback.js';
|
|
13
|
+
import ProcessOutputDataObject from './extensions/ProcessOutputDataObject.js';
|
|
14
|
+
|
|
15
|
+
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
|
|
16
|
+
const { version: engineVersion } = nodeRequire('../package.json');
|
|
13
17
|
|
|
14
18
|
const kEngine = Symbol.for('engine');
|
|
15
19
|
const kEnvironment = Symbol.for('environment');
|
|
@@ -23,36 +27,40 @@ const kState = Symbol.for('state');
|
|
|
23
27
|
const kStopped = Symbol.for('stopped');
|
|
24
28
|
const kTypeResolver = Symbol.for('type resolver');
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
export default Engine;
|
|
31
|
+
export { JavaScripts };
|
|
27
32
|
|
|
28
|
-
function Engine(options = {}) {
|
|
33
|
+
export function Engine(options = {}) {
|
|
29
34
|
if (!(this instanceof Engine)) return new Engine(options);
|
|
30
35
|
|
|
31
36
|
EventEmitter.call(this);
|
|
32
37
|
|
|
33
|
-
const opts = this.options = {
|
|
38
|
+
const opts = (this.options = {
|
|
34
39
|
Logger: DebugLogger,
|
|
35
40
|
scripts: new JavaScripts(options.disableDummyScript),
|
|
36
41
|
...options,
|
|
37
|
-
};
|
|
42
|
+
});
|
|
38
43
|
|
|
39
44
|
this.logger = opts.Logger('engine');
|
|
40
45
|
|
|
41
|
-
this[kTypeResolver] = TypeResolver(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
this[kTypeResolver] = TypeResolver(
|
|
47
|
+
{
|
|
48
|
+
...Elements,
|
|
49
|
+
...opts.elements,
|
|
50
|
+
},
|
|
51
|
+
opts.typeResolver || defaultTypeResolver
|
|
52
|
+
);
|
|
45
53
|
|
|
46
54
|
this[kEnvironment] = new Elements.Environment(opts);
|
|
47
55
|
|
|
48
|
-
const broker = this.broker = new Broker(this);
|
|
49
|
-
broker.assertExchange('event', 'topic', {autoDelete: false});
|
|
56
|
+
const broker = (this.broker = new Broker(this));
|
|
57
|
+
broker.assertExchange('event', 'topic', { autoDelete: false });
|
|
50
58
|
|
|
51
59
|
this[kExecution] = null;
|
|
52
60
|
this[kLoadedDefinitions] = null;
|
|
53
61
|
this[kSources] = [];
|
|
54
62
|
|
|
55
|
-
const pendingSources = this[kPendingSources] = [];
|
|
63
|
+
const pendingSources = (this[kPendingSources] = []);
|
|
56
64
|
if (opts.source) pendingSources.push(this._serializeSource(opts.source));
|
|
57
65
|
if (opts.moddleContext) pendingSources.push(this._serializeModdleContext(opts.moddleContext));
|
|
58
66
|
if (opts.sourceContext) pendingSources.push(opts.sourceContext);
|
|
@@ -117,7 +125,7 @@ Engine.prototype.execute = async function execute(...args) {
|
|
|
117
125
|
throw err;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
const execution = this[kExecution] = new Execution(this, definitions, this.options);
|
|
128
|
+
const execution = (this[kExecution] = new Execution(this, definitions, this.options));
|
|
121
129
|
return execution._execute(executeOptions, callback);
|
|
122
130
|
};
|
|
123
131
|
|
|
@@ -144,7 +152,7 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
144
152
|
const preSources = pendingSources.splice(0);
|
|
145
153
|
|
|
146
154
|
const typeResolver = this[kTypeResolver];
|
|
147
|
-
const loadedDefinitions = this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
|
|
155
|
+
const loadedDefinitions = (this[kLoadedDefinitions] = savedState.definitions.map((dState) => {
|
|
148
156
|
let source;
|
|
149
157
|
if (dState.source) source = deserialize(JSON.parse(dState.source), typeResolver);
|
|
150
158
|
else source = preSources.find((s) => s.id === dState.id);
|
|
@@ -157,7 +165,7 @@ Engine.prototype.recover = function recover(savedState, recoverOptions) {
|
|
|
157
165
|
definition.recover(dState);
|
|
158
166
|
|
|
159
167
|
return definition;
|
|
160
|
-
});
|
|
168
|
+
}));
|
|
161
169
|
|
|
162
170
|
this[kExecution] = new Execution(this, loadedDefinitions, {}, true);
|
|
163
171
|
|
|
@@ -181,16 +189,16 @@ Engine.prototype.resume = async function resume(...args) {
|
|
|
181
189
|
return execution._resume(resumeOptions, callback);
|
|
182
190
|
};
|
|
183
191
|
|
|
184
|
-
Engine.prototype.addSource = function addSource({sourceContext: addContext} = {}) {
|
|
192
|
+
Engine.prototype.addSource = function addSource({ sourceContext: addContext } = {}) {
|
|
185
193
|
if (!addContext) return;
|
|
186
194
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
187
195
|
if (loadedDefinitions) loadedDefinitions.splice(0);
|
|
188
196
|
this[kPendingSources].push(addContext);
|
|
189
197
|
};
|
|
190
198
|
|
|
191
|
-
Engine.prototype.getDefinitions =
|
|
199
|
+
Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
|
|
192
200
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
193
|
-
if (loadedDefinitions?.length) return loadedDefinitions;
|
|
201
|
+
if (loadedDefinitions?.length) return Promise.resolve(loadedDefinitions);
|
|
194
202
|
return this._loadDefinitions(executeOptions);
|
|
195
203
|
};
|
|
196
204
|
|
|
@@ -225,27 +233,30 @@ Engine.prototype.waitFor = function waitFor(eventName) {
|
|
|
225
233
|
|
|
226
234
|
Engine.prototype._loadDefinitions = async function loadDefinitions(executeOptions) {
|
|
227
235
|
const runSources = await Promise.all(this[kPendingSources]);
|
|
228
|
-
const loadedDefinitions = this[kLoadedDefinitions] = runSources.map((source) => this._loadDefinition(source, executeOptions));
|
|
236
|
+
const loadedDefinitions = (this[kLoadedDefinitions] = runSources.map((source) => this._loadDefinition(source, executeOptions)));
|
|
229
237
|
return loadedDefinitions;
|
|
230
238
|
};
|
|
231
239
|
|
|
232
240
|
Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions = {}) {
|
|
233
|
-
const {settings, variables} = executeOptions;
|
|
241
|
+
const { settings, variables } = executeOptions;
|
|
234
242
|
|
|
235
243
|
const environment = this.environment;
|
|
236
|
-
const context = new Elements.Context(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
...
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
const context = new Elements.Context(
|
|
245
|
+
serializedContext,
|
|
246
|
+
environment.clone({
|
|
247
|
+
listener: environment.options.listener,
|
|
248
|
+
...executeOptions,
|
|
249
|
+
settings: {
|
|
250
|
+
...environment.settings,
|
|
251
|
+
...settings,
|
|
252
|
+
},
|
|
253
|
+
variables: {
|
|
254
|
+
...environment.variables,
|
|
255
|
+
...variables,
|
|
256
|
+
},
|
|
257
|
+
source: serializedContext,
|
|
258
|
+
})
|
|
259
|
+
);
|
|
249
260
|
|
|
250
261
|
return new Elements.Definition(context);
|
|
251
262
|
};
|
|
@@ -266,7 +277,7 @@ Engine.prototype._getModdleContext = function getModdleContext(source) {
|
|
|
266
277
|
return bpmnModdle.fromXML(Buffer.isBuffer(source) ? source.toString() : source.trim());
|
|
267
278
|
};
|
|
268
279
|
|
|
269
|
-
function Execution(engine, definitions, options, isRecovered = false) {
|
|
280
|
+
export function Execution(engine, definitions, options, isRecovered = false) {
|
|
270
281
|
this.name = engine.name;
|
|
271
282
|
this.options = options;
|
|
272
283
|
this.definitions = definitions;
|
|
@@ -275,7 +286,7 @@ function Execution(engine, definitions, options, isRecovered = false) {
|
|
|
275
286
|
this[kEnvironment] = engine.environment;
|
|
276
287
|
this[kEngine] = engine;
|
|
277
288
|
this[kExecuting] = [];
|
|
278
|
-
const onBrokerReturn = this[kOnBrokerReturn] = this._onBrokerReturn.bind(this);
|
|
289
|
+
const onBrokerReturn = (this[kOnBrokerReturn] = this._onBrokerReturn.bind(this));
|
|
279
290
|
engine.broker.on('return', onBrokerReturn);
|
|
280
291
|
}
|
|
281
292
|
|
|
@@ -300,29 +311,10 @@ Object.defineProperties(Execution.prototype, {
|
|
|
300
311
|
return this[kEnvironment];
|
|
301
312
|
},
|
|
302
313
|
},
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
let status = 'idle';
|
|
308
|
-
const running = this[kExecuting];
|
|
309
|
-
if (!running.length) return status;
|
|
310
|
-
|
|
311
|
-
for (const def of running) {
|
|
312
|
-
const bpStatus = def.activityStatus;
|
|
313
|
-
switch (def.activityStatus) {
|
|
314
|
-
case 'executing':
|
|
315
|
-
return bpStatus;
|
|
316
|
-
case 'timer':
|
|
317
|
-
status = bpStatus;
|
|
318
|
-
break;
|
|
319
|
-
case 'wait':
|
|
320
|
-
if (status === 'idle') status = bpStatus;
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return status;
|
|
314
|
+
activityStatus: {
|
|
315
|
+
get() {
|
|
316
|
+
return this._getActivityStatus();
|
|
317
|
+
},
|
|
326
318
|
},
|
|
327
319
|
});
|
|
328
320
|
|
|
@@ -370,20 +362,35 @@ Execution.prototype._addConsumerCallbacks = function addConsumerCallbacks(callba
|
|
|
370
362
|
|
|
371
363
|
clearConsumers();
|
|
372
364
|
|
|
373
|
-
broker.subscribeOnce(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
broker.subscribeOnce(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
365
|
+
broker.subscribeOnce(
|
|
366
|
+
'event',
|
|
367
|
+
'engine.stop',
|
|
368
|
+
() => {
|
|
369
|
+
clearConsumers();
|
|
370
|
+
return callback(null, this);
|
|
371
|
+
},
|
|
372
|
+
{ consumerTag: 'ctag-cb-stop' }
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
broker.subscribeOnce(
|
|
376
|
+
'event',
|
|
377
|
+
'engine.end',
|
|
378
|
+
() => {
|
|
379
|
+
clearConsumers();
|
|
380
|
+
return callback(null, this);
|
|
381
|
+
},
|
|
382
|
+
{ consumerTag: 'ctag-cb-end' }
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
broker.subscribeOnce(
|
|
386
|
+
'event',
|
|
387
|
+
'engine.error',
|
|
388
|
+
(_, message) => {
|
|
389
|
+
clearConsumers();
|
|
390
|
+
return callback(message.content);
|
|
391
|
+
},
|
|
392
|
+
{ consumerTag: 'ctag-cb-error' }
|
|
393
|
+
);
|
|
387
394
|
|
|
388
395
|
return callback;
|
|
389
396
|
|
|
@@ -419,7 +426,7 @@ Execution.prototype._setup = function setup(setupOptions = {}) {
|
|
|
419
426
|
for (const definition of this.definitions) {
|
|
420
427
|
if (listener) definition.environment.options.listener = listener;
|
|
421
428
|
|
|
422
|
-
const {queueName} = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, {noAck: true, consumerTag: '_engine_definition'});
|
|
429
|
+
const { queueName } = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, { noAck: true, consumerTag: '_engine_definition' });
|
|
423
430
|
definition.broker.bindQueue(queueName, 'event', 'process.#');
|
|
424
431
|
definition.broker.bindQueue(queueName, 'event', 'activity.#');
|
|
425
432
|
definition.broker.bindQueue(queueName, 'event', 'flow.#');
|
|
@@ -427,7 +434,7 @@ Execution.prototype._setup = function setup(setupOptions = {}) {
|
|
|
427
434
|
};
|
|
428
435
|
|
|
429
436
|
Execution.prototype._onChildMessage = function onChildMessage(routingKey, message, owner) {
|
|
430
|
-
const {environment: ownerEnvironment} = owner;
|
|
437
|
+
const { environment: ownerEnvironment } = owner;
|
|
431
438
|
const listener = ownerEnvironment.options?.listener;
|
|
432
439
|
this[kState] = 'running';
|
|
433
440
|
|
|
@@ -476,7 +483,7 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
476
483
|
switch (key) {
|
|
477
484
|
case 'data': {
|
|
478
485
|
environment.output.data = environment.output.data || {};
|
|
479
|
-
environment.output.data = {...environment.output.data, ...message.content.output.data};
|
|
486
|
+
environment.output.data = { ...environment.output.data, ...message.content.output.data };
|
|
480
487
|
break;
|
|
481
488
|
}
|
|
482
489
|
default: {
|
|
@@ -491,7 +498,7 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
491
498
|
if (listener) listener.emit(routingKey, elementApi, this);
|
|
492
499
|
|
|
493
500
|
const broker = this.broker;
|
|
494
|
-
broker.publish('event', routingKey, {...message.content}, {...message.properties, mandatory: false});
|
|
501
|
+
broker.publish('event', routingKey, { ...message.content }, { ...message.properties, mandatory: false });
|
|
495
502
|
|
|
496
503
|
if (!newState) return;
|
|
497
504
|
|
|
@@ -500,13 +507,13 @@ Execution.prototype._onChildMessage = function onChildMessage(routingKey, messag
|
|
|
500
507
|
switch (newState) {
|
|
501
508
|
case 'stopped':
|
|
502
509
|
this._debug('stopped');
|
|
503
|
-
return this._complete('stop', {}, {type: 'stop'});
|
|
510
|
+
return this._complete('stop', {}, { type: 'stop' });
|
|
504
511
|
case 'idle':
|
|
505
512
|
this._debug('completed');
|
|
506
|
-
return this._complete('end', {}, {type: 'end'});
|
|
513
|
+
return this._complete('end', {}, { type: 'end' });
|
|
507
514
|
case 'error':
|
|
508
515
|
this._debug('error');
|
|
509
|
-
return this._complete('error', message.content.error, {type: 'error', mandatory: true});
|
|
516
|
+
return this._complete('error', message.content.error, { type: 'error', mandatory: true });
|
|
510
517
|
}
|
|
511
518
|
};
|
|
512
519
|
|
|
@@ -559,7 +566,7 @@ Execution.prototype.getPostponed = function getPostponed() {
|
|
|
559
566
|
}, []);
|
|
560
567
|
};
|
|
561
568
|
|
|
562
|
-
Execution.prototype.signal = function signal(payload, {ignoreSameDefinition} = {}) {
|
|
569
|
+
Execution.prototype.signal = function signal(payload, { ignoreSameDefinition } = {}) {
|
|
563
570
|
for (const definition of this[kExecuting]) {
|
|
564
571
|
if (ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
|
|
565
572
|
definition.signal(payload);
|
|
@@ -585,3 +592,26 @@ Execution.prototype._onBrokerReturn = function onBrokerReturn(message) {
|
|
|
585
592
|
Execution.prototype._debug = function debug(msg) {
|
|
586
593
|
this[kEngine].logger.debug(`<${this.name}> ${msg}`);
|
|
587
594
|
};
|
|
595
|
+
|
|
596
|
+
Execution.prototype._getActivityStatus = function getActivityStatus() {
|
|
597
|
+
let status = 'idle';
|
|
598
|
+
const running = this[kExecuting];
|
|
599
|
+
if (!running.length) return status;
|
|
600
|
+
else if (running.length === 1) return running[0].activityStatus;
|
|
601
|
+
|
|
602
|
+
for (const def of running) {
|
|
603
|
+
const bpStatus = def.activityStatus;
|
|
604
|
+
switch (def.activityStatus) {
|
|
605
|
+
case 'executing':
|
|
606
|
+
return bpStatus;
|
|
607
|
+
case 'timer':
|
|
608
|
+
status = bpStatus;
|
|
609
|
+
break;
|
|
610
|
+
case 'wait':
|
|
611
|
+
if (status === 'idle') status = bpStatus;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
return status;
|
|
617
|
+
};
|
package/types/bpmn-engine.d.ts
CHANGED
|
@@ -4,10 +4,21 @@
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { Definitions as BpmnModdleDefinitions } from 'bpmn-moddle';
|
|
6
6
|
import { extendFn, SerializableContext } from 'moddle-context-serializer';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ActivityStatus,
|
|
9
|
+
ElementBroker,
|
|
10
|
+
EnvironmentOptions,
|
|
11
|
+
Definition,
|
|
12
|
+
DefinitionState,
|
|
13
|
+
Environment,
|
|
14
|
+
Api,
|
|
15
|
+
ElementBase,
|
|
16
|
+
ILogger,
|
|
17
|
+
EnvironmentState,
|
|
18
|
+
IScripts,
|
|
19
|
+
} from 'bpmn-elements';
|
|
8
20
|
|
|
9
21
|
declare module 'bpmn-engine' {
|
|
10
|
-
|
|
11
22
|
/**
|
|
12
23
|
* Engine emits the following events:
|
|
13
24
|
|
|
@@ -30,7 +41,7 @@ declare module 'bpmn-engine' {
|
|
|
30
41
|
activity.error: An non-recoverable error has occurred
|
|
31
42
|
*/
|
|
32
43
|
export type BpmnActivityEvent =
|
|
33
|
-
'activity.enter'
|
|
44
|
+
| 'activity.enter'
|
|
34
45
|
| 'activity.start'
|
|
35
46
|
| 'activity.wait'
|
|
36
47
|
| 'wait'
|
|
@@ -45,14 +56,15 @@ declare module 'bpmn-engine' {
|
|
|
45
56
|
flow.discard: The sequence flow was discarded
|
|
46
57
|
flow.looped: The sequence is looped
|
|
47
58
|
*/
|
|
48
|
-
export type BpmnSequenceFlowEvent =
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
export type BpmnSequenceFlowEvent =
|
|
60
|
+
| 'flow.take'
|
|
61
|
+
| 'flow.discard'
|
|
62
|
+
| 'flow.looped';
|
|
51
63
|
|
|
52
64
|
export interface BpmnMessage {
|
|
53
|
-
id?: string
|
|
54
|
-
executionId?: string
|
|
55
|
-
[name: string]: any
|
|
65
|
+
id?: string;
|
|
66
|
+
executionId?: string;
|
|
67
|
+
[name: string]: any;
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
export interface BpmnEngineExecuteOptions extends EnvironmentOptions {
|
|
@@ -147,7 +159,10 @@ declare module 'bpmn-engine' {
|
|
|
147
159
|
*/
|
|
148
160
|
execute(): Promise<Execution>;
|
|
149
161
|
execute(options: BpmnEngineExecuteOptions): Promise<Execution>;
|
|
150
|
-
execute(
|
|
162
|
+
execute(
|
|
163
|
+
options: BpmnEngineExecuteOptions,
|
|
164
|
+
cb: (err: Error, execution?: Execution) => void
|
|
165
|
+
): Promise<Execution>;
|
|
151
166
|
execute(cb: (err: Error) => void): Promise<Execution>;
|
|
152
167
|
|
|
153
168
|
/**
|
|
@@ -178,7 +193,10 @@ declare module 'bpmn-engine' {
|
|
|
178
193
|
* @param options
|
|
179
194
|
* @param callback
|
|
180
195
|
*/
|
|
181
|
-
resume(
|
|
196
|
+
resume(
|
|
197
|
+
options?: BpmnEngineExecuteOptions,
|
|
198
|
+
callback?: (err: Error, execution?: Execution) => void
|
|
199
|
+
): Promise<Execution>;
|
|
182
200
|
|
|
183
201
|
/**
|
|
184
202
|
* Stop execution. The instance is terminated.
|
|
@@ -284,7 +302,10 @@ declare module 'bpmn-engine' {
|
|
|
284
302
|
* @param message {BpmnMessage}
|
|
285
303
|
* @param options
|
|
286
304
|
*/
|
|
287
|
-
signal(
|
|
305
|
+
signal(
|
|
306
|
+
message?: BpmnMessage,
|
|
307
|
+
options?: { ignoreSameDefinition?: boolean }
|
|
308
|
+
): void;
|
|
288
309
|
|
|
289
310
|
/**
|
|
290
311
|
* send cancel activity to execution, distributed to all definitions
|
|
@@ -299,4 +320,16 @@ declare module 'bpmn-engine' {
|
|
|
299
320
|
*/
|
|
300
321
|
waitFor<T>(event: BpmnEngineEvent): Promise<T>;
|
|
301
322
|
}
|
|
323
|
+
|
|
324
|
+
export class JavaScripts implements IScripts {
|
|
325
|
+
/**
|
|
326
|
+
* @param disableDummy Disable returning dummy scripts if script is not found. Dummy script will immediately call next function without error or return value
|
|
327
|
+
*/
|
|
328
|
+
constructor(disableDummy?: boolean);
|
|
329
|
+
register(activity: any): Script | undefined;
|
|
330
|
+
getScript(
|
|
331
|
+
language: string,
|
|
332
|
+
identifier: { id: string; [x: string]: any }
|
|
333
|
+
): Script;
|
|
334
|
+
}
|
|
302
335
|
}
|