bpmn-engine 23.0.1 → 24.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/lib/index.cjs +22 -21
- package/package.json +8 -6
- package/src/extensions/ProcessOutputDataObject.js +5 -5
- package/src/index.js +16 -15
- package/types/bpmn-engine.d.ts +6 -25
package/lib/index.cjs
CHANGED
|
@@ -145,7 +145,7 @@ Object.defineProperties(ProcessOutputDataObject.prototype, {
|
|
|
145
145
|
ProcessOutputDataObject.prototype.read = function readDataObject(broker, exchange, routingKeyPrefix, messageProperties) {
|
|
146
146
|
const environment = this.environment;
|
|
147
147
|
const { id, name, type } = this;
|
|
148
|
-
const value = environment.variables.data
|
|
148
|
+
const value = environment.variables.data?.[this.id];
|
|
149
149
|
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
150
150
|
};
|
|
151
151
|
|
|
@@ -153,15 +153,15 @@ ProcessOutputDataObject.prototype.write = function writeDataObject(broker, excha
|
|
|
153
153
|
const environment = this.environment;
|
|
154
154
|
const { id, name, type } = this;
|
|
155
155
|
|
|
156
|
-
environment.variables.data = environment.variables.data || {};
|
|
157
|
-
|
|
156
|
+
const data = (environment.variables.data = environment.variables.data || {});
|
|
157
|
+
data[id] = value;
|
|
158
158
|
|
|
159
|
-
environment.output.data = environment.output.data || {};
|
|
160
|
-
|
|
159
|
+
const outputData = (environment.output.data = environment.output.data || {});
|
|
160
|
+
outputData[id] = value;
|
|
161
161
|
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
162
162
|
};
|
|
163
163
|
|
|
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))));
|
|
164
|
+
const nodeRequire = node_module.createRequire(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _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');
|
|
@@ -175,14 +175,14 @@ const kState = Symbol.for('state');
|
|
|
175
175
|
const kStopped = Symbol.for('stopped');
|
|
176
176
|
const kTypeResolver = Symbol.for('type resolver');
|
|
177
177
|
|
|
178
|
-
function Engine(options
|
|
178
|
+
function Engine(options) {
|
|
179
179
|
if (!(this instanceof Engine)) return new Engine(options);
|
|
180
180
|
|
|
181
181
|
node_events.EventEmitter.call(this);
|
|
182
182
|
|
|
183
183
|
const opts = (this.options = {
|
|
184
184
|
Logger: Logger,
|
|
185
|
-
scripts: new Scripts(options
|
|
185
|
+
scripts: new Scripts(options?.disableDummyScript),
|
|
186
186
|
...options,
|
|
187
187
|
});
|
|
188
188
|
|
|
@@ -334,11 +334,11 @@ Engine.prototype.resume = async function resume(...args) {
|
|
|
334
334
|
return execution._resume(resumeOptions, callback);
|
|
335
335
|
};
|
|
336
336
|
|
|
337
|
-
Engine.prototype.addSource = function addSource(
|
|
338
|
-
if (!
|
|
337
|
+
Engine.prototype.addSource = function addSource(options) {
|
|
338
|
+
if (!options?.sourceContext) return;
|
|
339
339
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
340
340
|
if (loadedDefinitions) loadedDefinitions.splice(0);
|
|
341
|
-
this[kPendingSources].add(
|
|
341
|
+
this[kPendingSources].add(options.sourceContext);
|
|
342
342
|
};
|
|
343
343
|
|
|
344
344
|
Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
|
|
@@ -382,9 +382,7 @@ Engine.prototype._loadDefinitions = async function loadDefinitions(executeOption
|
|
|
382
382
|
return loadedDefinitions;
|
|
383
383
|
};
|
|
384
384
|
|
|
385
|
-
Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions
|
|
386
|
-
const { settings, variables } = executeOptions;
|
|
387
|
-
|
|
385
|
+
Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions) {
|
|
388
386
|
const environment = this.environment;
|
|
389
387
|
const context = new Elements__namespace.Context(
|
|
390
388
|
serializedContext,
|
|
@@ -393,11 +391,11 @@ Engine.prototype._loadDefinition = function loadDefinition(serializedContext, ex
|
|
|
393
391
|
...executeOptions,
|
|
394
392
|
settings: {
|
|
395
393
|
...environment.settings,
|
|
396
|
-
...settings,
|
|
394
|
+
...executeOptions?.settings,
|
|
397
395
|
},
|
|
398
396
|
variables: {
|
|
399
397
|
...environment.variables,
|
|
400
|
-
...variables,
|
|
398
|
+
...executeOptions?.variables,
|
|
401
399
|
},
|
|
402
400
|
source: serializedContext,
|
|
403
401
|
})
|
|
@@ -570,8 +568,8 @@ Execution.prototype.stop = async function stop() {
|
|
|
570
568
|
return result;
|
|
571
569
|
};
|
|
572
570
|
|
|
573
|
-
Execution.prototype._setup = function setup(setupOptions
|
|
574
|
-
const listener = setupOptions
|
|
571
|
+
Execution.prototype._setup = function setup(setupOptions) {
|
|
572
|
+
const listener = setupOptions?.listener || this.options.listener;
|
|
575
573
|
if (listener && typeof listener.emit !== 'function') throw new Error('listener.emit is not a function');
|
|
576
574
|
|
|
577
575
|
const onChildMessage = this._onChildMessage.bind(this);
|
|
@@ -579,7 +577,10 @@ Execution.prototype._setup = function setup(setupOptions = {}) {
|
|
|
579
577
|
for (const definition of this.definitions) {
|
|
580
578
|
if (listener) definition.environment.options.listener = listener;
|
|
581
579
|
|
|
582
|
-
const { queueName } = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, {
|
|
580
|
+
const { queueName } = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, {
|
|
581
|
+
noAck: true,
|
|
582
|
+
consumerTag: '_engine_definition',
|
|
583
|
+
});
|
|
583
584
|
definition.broker.bindQueue(queueName, 'event', 'process.#');
|
|
584
585
|
definition.broker.bindQueue(queueName, 'event', 'activity.#');
|
|
585
586
|
definition.broker.bindQueue(queueName, 'event', 'flow.#');
|
|
@@ -717,9 +718,9 @@ Execution.prototype.getPostponed = function getPostponed() {
|
|
|
717
718
|
return result;
|
|
718
719
|
};
|
|
719
720
|
|
|
720
|
-
Execution.prototype.signal = function signal(payload,
|
|
721
|
+
Execution.prototype.signal = function signal(payload, signalOptions) {
|
|
721
722
|
for (const definition of this[kExecuting]) {
|
|
722
|
-
if (ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
|
|
723
|
+
if (signalOptions?.ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
|
|
723
724
|
definition.signal(payload);
|
|
724
725
|
}
|
|
725
726
|
};
|
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": "24.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./src/index.js",
|
|
7
7
|
"main": "./lib/index.cjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
],
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@bonniernews/hot-bev": "^0.4.0",
|
|
55
|
-
"@rollup/plugin-commonjs": "^
|
|
55
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
56
56
|
"@types/bpmn-moddle": "^5.1.6",
|
|
57
57
|
"@types/node": "^18.19.31",
|
|
58
58
|
"bent": "^7.3.12",
|
|
@@ -62,17 +62,19 @@
|
|
|
62
62
|
"chronokinesis": "^6.0.0",
|
|
63
63
|
"eslint": "^9.10.0",
|
|
64
64
|
"markdown-toc": "^1.2.0",
|
|
65
|
-
"mocha": "^
|
|
65
|
+
"mocha": "^11.0.1",
|
|
66
66
|
"mocha-cakes-2": "^3.3.0",
|
|
67
67
|
"prettier": "^3.2.5",
|
|
68
68
|
"rollup": "^4.10.0",
|
|
69
69
|
"texample": "^0.0.6"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"bpmn-elements": "^
|
|
72
|
+
"bpmn-elements": "^17.0.0",
|
|
73
73
|
"bpmn-moddle": "^9.0.1",
|
|
74
74
|
"debug": "^4.3.7",
|
|
75
|
-
"moddle-context-serializer": "^4.2.1"
|
|
76
|
-
|
|
75
|
+
"moddle-context-serializer": "^4.2.1"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"smqp": ">=9"
|
|
77
79
|
}
|
|
78
80
|
}
|
|
@@ -24,7 +24,7 @@ Object.defineProperties(ProcessOutputDataObject.prototype, {
|
|
|
24
24
|
ProcessOutputDataObject.prototype.read = function readDataObject(broker, exchange, routingKeyPrefix, messageProperties) {
|
|
25
25
|
const environment = this.environment;
|
|
26
26
|
const { id, name, type } = this;
|
|
27
|
-
const value = environment.variables.data
|
|
27
|
+
const value = environment.variables.data?.[this.id];
|
|
28
28
|
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
29
29
|
};
|
|
30
30
|
|
|
@@ -32,10 +32,10 @@ ProcessOutputDataObject.prototype.write = function writeDataObject(broker, excha
|
|
|
32
32
|
const environment = this.environment;
|
|
33
33
|
const { id, name, type } = this;
|
|
34
34
|
|
|
35
|
-
environment.variables.data = environment.variables.data || {};
|
|
36
|
-
|
|
35
|
+
const data = (environment.variables.data = environment.variables.data || {});
|
|
36
|
+
data[id] = value;
|
|
37
37
|
|
|
38
|
-
environment.output.data = environment.output.data || {};
|
|
39
|
-
|
|
38
|
+
const outputData = (environment.output.data = environment.output.data || {});
|
|
39
|
+
outputData[id] = value;
|
|
40
40
|
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
|
|
41
41
|
};
|
package/src/index.js
CHANGED
|
@@ -29,14 +29,14 @@ const kTypeResolver = Symbol.for('type resolver');
|
|
|
29
29
|
export default Engine;
|
|
30
30
|
export { JavaScripts };
|
|
31
31
|
|
|
32
|
-
export function Engine(options
|
|
32
|
+
export function Engine(options) {
|
|
33
33
|
if (!(this instanceof Engine)) return new Engine(options);
|
|
34
34
|
|
|
35
35
|
EventEmitter.call(this);
|
|
36
36
|
|
|
37
37
|
const opts = (this.options = {
|
|
38
38
|
Logger: DebugLogger,
|
|
39
|
-
scripts: new JavaScripts(options
|
|
39
|
+
scripts: new JavaScripts(options?.disableDummyScript),
|
|
40
40
|
...options,
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -188,11 +188,11 @@ Engine.prototype.resume = async function resume(...args) {
|
|
|
188
188
|
return execution._resume(resumeOptions, callback);
|
|
189
189
|
};
|
|
190
190
|
|
|
191
|
-
Engine.prototype.addSource = function addSource(
|
|
192
|
-
if (!
|
|
191
|
+
Engine.prototype.addSource = function addSource(options) {
|
|
192
|
+
if (!options?.sourceContext) return;
|
|
193
193
|
const loadedDefinitions = this[kLoadedDefinitions];
|
|
194
194
|
if (loadedDefinitions) loadedDefinitions.splice(0);
|
|
195
|
-
this[kPendingSources].add(
|
|
195
|
+
this[kPendingSources].add(options.sourceContext);
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
|
|
@@ -236,9 +236,7 @@ Engine.prototype._loadDefinitions = async function loadDefinitions(executeOption
|
|
|
236
236
|
return loadedDefinitions;
|
|
237
237
|
};
|
|
238
238
|
|
|
239
|
-
Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions
|
|
240
|
-
const { settings, variables } = executeOptions;
|
|
241
|
-
|
|
239
|
+
Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions) {
|
|
242
240
|
const environment = this.environment;
|
|
243
241
|
const context = new Elements.Context(
|
|
244
242
|
serializedContext,
|
|
@@ -247,11 +245,11 @@ Engine.prototype._loadDefinition = function loadDefinition(serializedContext, ex
|
|
|
247
245
|
...executeOptions,
|
|
248
246
|
settings: {
|
|
249
247
|
...environment.settings,
|
|
250
|
-
...settings,
|
|
248
|
+
...executeOptions?.settings,
|
|
251
249
|
},
|
|
252
250
|
variables: {
|
|
253
251
|
...environment.variables,
|
|
254
|
-
...variables,
|
|
252
|
+
...executeOptions?.variables,
|
|
255
253
|
},
|
|
256
254
|
source: serializedContext,
|
|
257
255
|
})
|
|
@@ -424,8 +422,8 @@ Execution.prototype.stop = async function stop() {
|
|
|
424
422
|
return result;
|
|
425
423
|
};
|
|
426
424
|
|
|
427
|
-
Execution.prototype._setup = function setup(setupOptions
|
|
428
|
-
const listener = setupOptions
|
|
425
|
+
Execution.prototype._setup = function setup(setupOptions) {
|
|
426
|
+
const listener = setupOptions?.listener || this.options.listener;
|
|
429
427
|
if (listener && typeof listener.emit !== 'function') throw new Error('listener.emit is not a function');
|
|
430
428
|
|
|
431
429
|
const onChildMessage = this._onChildMessage.bind(this);
|
|
@@ -433,7 +431,10 @@ Execution.prototype._setup = function setup(setupOptions = {}) {
|
|
|
433
431
|
for (const definition of this.definitions) {
|
|
434
432
|
if (listener) definition.environment.options.listener = listener;
|
|
435
433
|
|
|
436
|
-
const { queueName } = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, {
|
|
434
|
+
const { queueName } = definition.broker.subscribeTmp('event', 'definition.#', onChildMessage, {
|
|
435
|
+
noAck: true,
|
|
436
|
+
consumerTag: '_engine_definition',
|
|
437
|
+
});
|
|
437
438
|
definition.broker.bindQueue(queueName, 'event', 'process.#');
|
|
438
439
|
definition.broker.bindQueue(queueName, 'event', 'activity.#');
|
|
439
440
|
definition.broker.bindQueue(queueName, 'event', 'flow.#');
|
|
@@ -571,9 +572,9 @@ Execution.prototype.getPostponed = function getPostponed() {
|
|
|
571
572
|
return result;
|
|
572
573
|
};
|
|
573
574
|
|
|
574
|
-
Execution.prototype.signal = function signal(payload,
|
|
575
|
+
Execution.prototype.signal = function signal(payload, signalOptions) {
|
|
575
576
|
for (const definition of this[kExecuting]) {
|
|
576
|
-
if (ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
|
|
577
|
+
if (signalOptions?.ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
|
|
577
578
|
definition.signal(payload);
|
|
578
579
|
}
|
|
579
580
|
};
|
package/types/bpmn-engine.d.ts
CHANGED
|
@@ -3,11 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { Definitions as BpmnModdleDefinitions } from 'bpmn-moddle';
|
|
6
|
-
import {
|
|
7
|
-
extendFn,
|
|
8
|
-
SerializableContext,
|
|
9
|
-
TypeResolver,
|
|
10
|
-
} from 'moddle-context-serializer';
|
|
6
|
+
import { extendFn, SerializableContext, TypeResolver } from 'moddle-context-serializer';
|
|
11
7
|
import {
|
|
12
8
|
ActivityStatus,
|
|
13
9
|
ElementBroker,
|
|
@@ -61,10 +57,7 @@ declare module 'bpmn-engine' {
|
|
|
61
57
|
flow.discard: The sequence flow was discarded
|
|
62
58
|
flow.looped: The sequence is looped
|
|
63
59
|
*/
|
|
64
|
-
export type BpmnSequenceFlowEvent =
|
|
65
|
-
| 'flow.take'
|
|
66
|
-
| 'flow.discard'
|
|
67
|
-
| 'flow.looped';
|
|
60
|
+
export type BpmnSequenceFlowEvent = 'flow.take' | 'flow.discard' | 'flow.looped';
|
|
68
61
|
|
|
69
62
|
export interface BpmnMessage {
|
|
70
63
|
id?: string;
|
|
@@ -173,10 +166,7 @@ declare module 'bpmn-engine' {
|
|
|
173
166
|
*/
|
|
174
167
|
execute(): Promise<Execution>;
|
|
175
168
|
execute(options: BpmnEngineExecuteOptions): Promise<Execution>;
|
|
176
|
-
execute(
|
|
177
|
-
options: BpmnEngineExecuteOptions,
|
|
178
|
-
cb: (err: Error, execution?: Execution) => void
|
|
179
|
-
): Promise<Execution>;
|
|
169
|
+
execute(options: BpmnEngineExecuteOptions, cb: (err: Error, execution?: Execution) => void): Promise<Execution>;
|
|
180
170
|
execute(cb: (err: Error) => void): Promise<Execution>;
|
|
181
171
|
|
|
182
172
|
/**
|
|
@@ -207,10 +197,7 @@ declare module 'bpmn-engine' {
|
|
|
207
197
|
* @param options
|
|
208
198
|
* @param callback
|
|
209
199
|
*/
|
|
210
|
-
resume(
|
|
211
|
-
options?: BpmnEngineExecuteOptions,
|
|
212
|
-
callback?: (err: Error, execution?: Execution) => void
|
|
213
|
-
): Promise<Execution>;
|
|
200
|
+
resume(options?: BpmnEngineExecuteOptions, callback?: (err: Error, execution?: Execution) => void): Promise<Execution>;
|
|
214
201
|
|
|
215
202
|
/**
|
|
216
203
|
* Stop execution. The instance is terminated.
|
|
@@ -320,10 +307,7 @@ declare module 'bpmn-engine' {
|
|
|
320
307
|
* @param message {BpmnMessage}
|
|
321
308
|
* @param options
|
|
322
309
|
*/
|
|
323
|
-
signal(
|
|
324
|
-
message?: BpmnMessage,
|
|
325
|
-
options?: { ignoreSameDefinition?: boolean }
|
|
326
|
-
): void;
|
|
310
|
+
signal(message?: BpmnMessage, options?: { ignoreSameDefinition?: boolean }): void;
|
|
327
311
|
|
|
328
312
|
/**
|
|
329
313
|
* send cancel activity to execution, distributed to all definitions
|
|
@@ -345,9 +329,6 @@ declare module 'bpmn-engine' {
|
|
|
345
329
|
*/
|
|
346
330
|
constructor(disableDummy?: boolean);
|
|
347
331
|
register(activity: any): Script | undefined;
|
|
348
|
-
getScript(
|
|
349
|
-
language: string,
|
|
350
|
-
identifier: { id: string; [x: string]: any }
|
|
351
|
-
): Script;
|
|
332
|
+
getScript(language: string, identifier: { id: string; [x: string]: any }): Script;
|
|
352
333
|
}
|
|
353
334
|
}
|