bpmn-elements 9.2.0 → 10.1.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/CHANGELOG.md +13 -0
- package/README.md +4 -0
- package/dist/Context.js +21 -4
- package/dist/Environment.js +1 -1
- package/dist/Timers.js +63 -43
- package/dist/activity/Activity.js +17 -1
- package/dist/definition/DefinitionExecution.js +14 -10
- package/dist/eventDefinitions/TimerEventDefinition.js +51 -41
- package/dist/index.js +19 -0
- package/dist/iso-duration.js +88 -0
- package/dist/process/Lane.js +38 -0
- package/dist/process/Process.js +16 -0
- package/dist/tasks/SubProcess.js +2 -2
- package/package.json +13 -13
- package/src/Context.js +27 -4
- package/src/Environment.js +1 -1
- package/src/Timers.js +71 -40
- package/src/activity/Activity.js +18 -0
- package/src/definition/DefinitionExecution.js +11 -15
- package/src/eventDefinitions/TimerEventDefinition.js +49 -40
- package/src/index.js +6 -0
- package/src/iso-duration.js +91 -0
- package/src/process/Lane.js +27 -0
- package/src/process/Process.js +18 -0
- package/src/tasks/SubProcess.js +2 -2
- package/types/index.d.ts +117 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
# 10.1.0
|
|
5
|
+
|
|
6
|
+
- introduce Lane behaviour
|
|
7
|
+
- add process `lanes` property with Lane instances
|
|
8
|
+
- add activity `lane` property containing a reference to the process lane instance
|
|
9
|
+
- add activity `parentElement` property referencing parent process or sub process
|
|
10
|
+
|
|
11
|
+
# 10.0.0
|
|
12
|
+
|
|
13
|
+
- drop iso8601-duration dependency and copy source (with licence). Export as `ISODuration`. Extend with repeat pattern parsing, e.g. `R3/PT1H` that corresponds to three repetitions every one hour
|
|
14
|
+
- expose `TimerEventDefinition.parse(timerType, value)` function for extension purposes
|
|
15
|
+
- prototype and export built-in `Timers`
|
|
16
|
+
|
|
4
17
|
# 9.2.0
|
|
5
18
|
|
|
6
19
|
- move outbound sequence flow evaluation logic from activity to sequence flow, where it belongs
|
package/README.md
CHANGED
|
@@ -77,3 +77,7 @@ The following elements are tested and supported.
|
|
|
77
77
|
- Transaction
|
|
78
78
|
|
|
79
79
|
All activities share the same [base](/docs/Activity.md) and and [api](/docs/SharedApi.md).
|
|
80
|
+
|
|
81
|
+
# Acknowledgments
|
|
82
|
+
|
|
83
|
+
ISO 8601 duration parser [iso8601-duration](https://www.npmjs.com/package/iso8601-duration) source is copied and extended with repeat pattern. License [MIT @ tolu](https://tolu.mit-license.org/)
|
package/dist/Context.js
CHANGED
|
@@ -9,11 +9,12 @@ var _Environment = _interopRequireDefault(require("./Environment.js"));
|
|
|
9
9
|
var _ExtensionsMapper = _interopRequireDefault(require("./ExtensionsMapper.js"));
|
|
10
10
|
var _shared = require("./shared.js");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const kOwner = Symbol.for('owner');
|
|
12
13
|
function Context(definitionContext, environment) {
|
|
13
14
|
environment = environment ? environment.clone() : new _Environment.default();
|
|
14
15
|
return new ContextInstance(definitionContext, environment);
|
|
15
16
|
}
|
|
16
|
-
function ContextInstance(definitionContext, environment) {
|
|
17
|
+
function ContextInstance(definitionContext, environment, owner) {
|
|
17
18
|
const {
|
|
18
19
|
id = 'Def',
|
|
19
20
|
name,
|
|
@@ -38,7 +39,13 @@ function ContextInstance(definitionContext, environment) {
|
|
|
38
39
|
sequenceFlowRefs: {},
|
|
39
40
|
sequenceFlows: []
|
|
40
41
|
};
|
|
42
|
+
this[kOwner] = owner;
|
|
41
43
|
}
|
|
44
|
+
Object.defineProperty(ContextInstance.prototype, 'owner', {
|
|
45
|
+
get() {
|
|
46
|
+
return this[kOwner];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
42
49
|
ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
|
|
43
50
|
const activityInstance = this.refs.activityRefs[activityId];
|
|
44
51
|
if (activityInstance) return activityInstance;
|
|
@@ -95,8 +102,8 @@ ContextInstance.prototype.upsertAssociation = function upsertAssociation(associa
|
|
|
95
102
|
instance = refs[associationDefinition.id] = new associationDefinition.Behaviour(associationDefinition, this);
|
|
96
103
|
return instance;
|
|
97
104
|
};
|
|
98
|
-
ContextInstance.prototype.clone = function clone(newEnvironment) {
|
|
99
|
-
return new ContextInstance(this.definitionContext, newEnvironment || this.environment);
|
|
105
|
+
ContextInstance.prototype.clone = function clone(newEnvironment, newOwner) {
|
|
106
|
+
return new ContextInstance(this.definitionContext, newEnvironment || this.environment, newOwner);
|
|
100
107
|
};
|
|
101
108
|
ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
102
109
|
const refs = this.refs.processRefs;
|
|
@@ -106,13 +113,16 @@ ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
|
106
113
|
if (!processDefinition) return null;
|
|
107
114
|
const bpContext = this.clone(this.environment.clone());
|
|
108
115
|
bp = refs[processId] = new processDefinition.Behaviour(processDefinition, bpContext);
|
|
116
|
+
bpContext[kOwner] = bp;
|
|
109
117
|
this.refs.processes.push(bp);
|
|
110
118
|
return bp;
|
|
111
119
|
};
|
|
112
120
|
ContextInstance.prototype.getNewProcessById = function getNewProcessById(processId) {
|
|
113
121
|
if (!this.getProcessById(processId)) return null;
|
|
114
122
|
const bpDef = this.definitionContext.getProcessById(processId);
|
|
115
|
-
const
|
|
123
|
+
const bpContext = this.clone(this.environment.clone());
|
|
124
|
+
const bp = new bpDef.Behaviour(bpDef, bpContext);
|
|
125
|
+
bpContext[kOwner] = bp;
|
|
116
126
|
return bp;
|
|
117
127
|
};
|
|
118
128
|
ContextInstance.prototype.getProcesses = function getProcesses() {
|
|
@@ -175,4 +185,11 @@ ContextInstance.prototype.loadExtensions = function loadExtensions(activity) {
|
|
|
175
185
|
if (io.hasIo) extensions.extensions.push(io);
|
|
176
186
|
if (!extensions.extensions.length) return;
|
|
177
187
|
return extensions;
|
|
188
|
+
};
|
|
189
|
+
ContextInstance.prototype.getActivityParentById = function getActivityParentById(activityId) {
|
|
190
|
+
const owner = this[kOwner];
|
|
191
|
+
if (owner) return owner;
|
|
192
|
+
const activity = this.getActivityById(activityId);
|
|
193
|
+
const parentId = activity.parent.id;
|
|
194
|
+
return this.getProcessById(parentId) || this.getActivityById(parentId);
|
|
178
195
|
};
|
package/dist/Environment.js
CHANGED
|
@@ -17,7 +17,7 @@ function Environment(options = {}) {
|
|
|
17
17
|
this.extensions = options.extensions;
|
|
18
18
|
this.output = options.output || {};
|
|
19
19
|
this.scripts = options.scripts || (0, _Scripts.Scripts)();
|
|
20
|
-
this.timers = options.timers ||
|
|
20
|
+
this.timers = options.timers || new _Timers.Timers();
|
|
21
21
|
this.settings = {
|
|
22
22
|
...options.settings
|
|
23
23
|
};
|
package/dist/Timers.js
CHANGED
|
@@ -4,57 +4,77 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Timers = Timers;
|
|
7
|
+
const kExecuting = Symbol.for('executing');
|
|
8
|
+
const kTimerApi = Symbol.for('timers api');
|
|
9
|
+
const MAX_DELAY = 2147483647;
|
|
7
10
|
function Timers(options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options = {
|
|
11
|
+
this.count = 0;
|
|
12
|
+
this.options = {
|
|
11
13
|
setTimeout,
|
|
12
14
|
clearTimeout,
|
|
13
15
|
...options
|
|
14
16
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
return timersApi;
|
|
24
|
-
function register(owner) {
|
|
25
|
-
return {
|
|
26
|
-
setTimeout: registerTimeout(owner),
|
|
27
|
-
clearTimeout: timersApi.clearTimeout
|
|
28
|
-
};
|
|
17
|
+
this[kExecuting] = [];
|
|
18
|
+
this.setTimeout = this.setTimeout.bind(this);
|
|
19
|
+
this.clearTimeout = this.clearTimeout.bind(this);
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(Timers.prototype, 'executing', {
|
|
22
|
+
get() {
|
|
23
|
+
return this[kExecuting].slice();
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
});
|
|
26
|
+
Timers.prototype.register = function register(owner) {
|
|
27
|
+
return new RegisteredTimers(this, owner);
|
|
28
|
+
};
|
|
29
|
+
Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...args) {
|
|
30
|
+
return this._setTimeout(null, callback, delay, ...args);
|
|
31
|
+
};
|
|
32
|
+
Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
|
|
33
|
+
const executing = this[kExecuting];
|
|
34
|
+
const idx = executing.indexOf(ref);
|
|
35
|
+
if (idx > -1) {
|
|
36
|
+
executing.splice(idx, 1);
|
|
37
|
+
ref.timerRef = this.options.clearTimeout(ref.timerRef);
|
|
38
|
+
return;
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
executing.push(ref);
|
|
44
|
-
ref.timerRef = options.setTimeout.call(null, onTimeout, delay, ...args);
|
|
45
|
-
return ref;
|
|
46
|
-
function onTimeout(...rargs) {
|
|
47
|
-
const idx = executing.indexOf(ref);
|
|
48
|
-
if (idx > -1) executing.splice(idx, 1);
|
|
49
|
-
return callback(...rargs);
|
|
50
|
-
}
|
|
40
|
+
return this.options.clearTimeout(ref);
|
|
41
|
+
};
|
|
42
|
+
Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
|
|
43
|
+
const executing = this[kExecuting];
|
|
44
|
+
const ref = this._getReference(owner, callback, delay, args);
|
|
45
|
+
executing.push(ref);
|
|
46
|
+
if (delay < MAX_DELAY) {
|
|
47
|
+
ref.timerRef = this.options.setTimeout(onTimeout, ref.delay, ...ref.args);
|
|
51
48
|
}
|
|
52
|
-
|
|
49
|
+
return ref;
|
|
50
|
+
function onTimeout(...rargs) {
|
|
53
51
|
const idx = executing.indexOf(ref);
|
|
54
|
-
if (idx > -1)
|
|
55
|
-
|
|
56
|
-
return options.clearTimeout.call(null, ref.timerRef);
|
|
57
|
-
}
|
|
58
|
-
return options.clearTimeout.call(null, ref);
|
|
52
|
+
if (idx > -1) executing.splice(idx, 1);
|
|
53
|
+
return callback(...rargs);
|
|
59
54
|
}
|
|
55
|
+
};
|
|
56
|
+
Timers.prototype._getReference = function getReference(owner, callback, delay, args) {
|
|
57
|
+
return new Timer(owner, `timer_${this.count++}`, callback, delay, args);
|
|
58
|
+
};
|
|
59
|
+
function RegisteredTimers(timersApi, owner) {
|
|
60
|
+
this[kTimerApi] = timersApi;
|
|
61
|
+
this.owner = owner;
|
|
62
|
+
this.setTimeout = this.setTimeout.bind(this);
|
|
63
|
+
this.clearTimeout = this.clearTimeout.bind(this);
|
|
64
|
+
}
|
|
65
|
+
RegisteredTimers.prototype.setTimeout = function registeredSetTimeout(callback, delay, ...args) {
|
|
66
|
+
const timersApi = this[kTimerApi];
|
|
67
|
+
return timersApi._setTimeout(this.owner, callback, delay, ...args);
|
|
68
|
+
};
|
|
69
|
+
RegisteredTimers.prototype.clearTimeout = function registeredClearTimeout(ref) {
|
|
70
|
+
this[kTimerApi].clearTimeout(ref);
|
|
71
|
+
};
|
|
72
|
+
function Timer(owner, timerId, callback, delay, args) {
|
|
73
|
+
this.callback = callback;
|
|
74
|
+
this.delay = delay;
|
|
75
|
+
this.args = args;
|
|
76
|
+
this.owner = owner;
|
|
77
|
+
this.timerId = timerId;
|
|
78
|
+
this.expireAt = new Date(Date.now() + delay);
|
|
79
|
+
this.timerRef = null;
|
|
60
80
|
}
|
|
@@ -102,7 +102,8 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
102
102
|
attachedTo,
|
|
103
103
|
isTransaction: activityDef.isTransaction,
|
|
104
104
|
isParallelJoin,
|
|
105
|
-
isThrowing: activityDef.isThrowing
|
|
105
|
+
isThrowing: activityDef.isThrowing,
|
|
106
|
+
lane: activityDef.lane && activityDef.lane.id
|
|
106
107
|
};
|
|
107
108
|
this[kExec] = {};
|
|
108
109
|
this[kMessageHandlers] = {
|
|
@@ -236,12 +237,27 @@ Object.defineProperty(Activity.prototype, 'attachedTo', {
|
|
|
236
237
|
return this.getActivityById(attachedToId);
|
|
237
238
|
}
|
|
238
239
|
});
|
|
240
|
+
Object.defineProperty(Activity.prototype, 'lane', {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get() {
|
|
243
|
+
const laneId = this[kFlags].lane;
|
|
244
|
+
if (!laneId) return undefined;
|
|
245
|
+
const parent = this.parentElement;
|
|
246
|
+
return parent.getLaneById && parent.getLaneById(laneId);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
239
249
|
Object.defineProperty(Activity.prototype, 'eventDefinitions', {
|
|
240
250
|
enumerable: true,
|
|
241
251
|
get() {
|
|
242
252
|
return this[kEventDefinitions];
|
|
243
253
|
}
|
|
244
254
|
});
|
|
255
|
+
Object.defineProperty(Activity.prototype, 'parentElement', {
|
|
256
|
+
enumerable: true,
|
|
257
|
+
get() {
|
|
258
|
+
return this.context.getActivityParentById(this.id);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
245
261
|
Activity.prototype.activate = function activate() {
|
|
246
262
|
this[kActivated] = true;
|
|
247
263
|
this.addInboundListeners();
|
|
@@ -294,31 +294,36 @@ DefinitionExecution.prototype._activate = function activate(processList) {
|
|
|
294
294
|
};
|
|
295
295
|
DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
296
296
|
const handlers = this[kMessageHandlers];
|
|
297
|
-
|
|
297
|
+
const broker = bp.broker;
|
|
298
|
+
broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
298
299
|
noAck: true,
|
|
299
300
|
consumerTag: '_definition-outbound-message-consumer'
|
|
300
301
|
});
|
|
301
|
-
|
|
302
|
+
const delegateEventQ = broker.assertQueue('_delegate-event-q', {
|
|
303
|
+
autoDelete: false,
|
|
304
|
+
durable: false
|
|
305
|
+
});
|
|
306
|
+
delegateEventQ.consume(handlers.onDelegateMessage, {
|
|
302
307
|
noAck: true,
|
|
303
|
-
consumerTag: '_definition-signal-consumer'
|
|
308
|
+
consumerTag: '_definition-signal-consumer'
|
|
309
|
+
});
|
|
310
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', {
|
|
304
311
|
priority: 200
|
|
305
312
|
});
|
|
306
|
-
|
|
307
|
-
noAck: true,
|
|
308
|
-
consumerTag: '_definition-message-consumer',
|
|
313
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.message', {
|
|
309
314
|
priority: 200
|
|
310
315
|
});
|
|
311
|
-
|
|
316
|
+
broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
|
|
312
317
|
noAck: true,
|
|
313
318
|
consumerTag: '_definition-call-consumer',
|
|
314
319
|
priority: 200
|
|
315
320
|
});
|
|
316
|
-
|
|
321
|
+
broker.subscribeTmp('event', 'activity.call.cancel', handlers.onCancelCallActivity, {
|
|
317
322
|
noAck: true,
|
|
318
323
|
consumerTag: '_definition-call-cancel-consumer',
|
|
319
324
|
priority: 200
|
|
320
325
|
});
|
|
321
|
-
|
|
326
|
+
broker.subscribeTmp('event', '#', handlers.onChildEvent, {
|
|
322
327
|
noAck: true,
|
|
323
328
|
consumerTag: '_definition-activity-consumer',
|
|
324
329
|
priority: 100
|
|
@@ -351,7 +356,6 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
|
|
|
351
356
|
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
352
357
|
bp.broker.cancel('_definition-activity-consumer');
|
|
353
358
|
bp.broker.cancel('_definition-signal-consumer');
|
|
354
|
-
bp.broker.cancel('_definition-message-consumer');
|
|
355
359
|
bp.broker.cancel('_definition-call-consumer');
|
|
356
360
|
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
357
361
|
};
|
|
@@ -5,13 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = TimerEventDefinition;
|
|
7
7
|
var _messageHelper = require("../messageHelper.js");
|
|
8
|
-
var
|
|
8
|
+
var _isoDuration = require("../iso-duration.js");
|
|
9
9
|
const kStopped = Symbol.for('stopped');
|
|
10
10
|
const kTimerContent = Symbol.for('timerContent');
|
|
11
11
|
const kTimer = Symbol.for('timer');
|
|
12
|
-
const repeatPattern = /^\s*R(\d+)\//;
|
|
13
12
|
function TimerEventDefinition(activity, eventDefinition) {
|
|
14
|
-
const type = this.type = eventDefinition.type || 'TimerEventDefinition
|
|
13
|
+
const type = this.type = eventDefinition.type || 'TimerEventDefinition';
|
|
15
14
|
this.activity = activity;
|
|
16
15
|
const environment = this.environment = activity.environment;
|
|
17
16
|
this.eventDefinition = eventDefinition;
|
|
@@ -85,12 +84,14 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
|
85
84
|
if (timerContent.timeout === undefined) return this._debug(`waiting for ${timerContent.timerType || 'signal'}`);
|
|
86
85
|
if (timerContent.timeout <= 0) return this._completed();
|
|
87
86
|
const timers = this.environment.timers.register(timerContent);
|
|
88
|
-
|
|
87
|
+
const delay = timerContent.timeout;
|
|
88
|
+
this[kTimer] = timers.setTimeout(this._completed.bind(this), delay, {
|
|
89
89
|
id: content.id,
|
|
90
90
|
type: this.type,
|
|
91
91
|
executionId,
|
|
92
92
|
state: 'timeout'
|
|
93
93
|
});
|
|
94
|
+
this._debug(`set timeout with delay ${delay}`);
|
|
94
95
|
};
|
|
95
96
|
TimerEventDefinition.prototype.stop = function stopTimer() {
|
|
96
97
|
const timer = this[kTimer];
|
|
@@ -188,75 +189,84 @@ TimerEventDefinition.prototype._stop = function stop() {
|
|
|
188
189
|
broker.cancel(`_api-${this.executionId}`);
|
|
189
190
|
broker.cancel(`_api-delegated-${this.executionId}`);
|
|
190
191
|
};
|
|
192
|
+
TimerEventDefinition.prototype.parse = function parse(timerType, value) {
|
|
193
|
+
let repeat, delay, expireAt;
|
|
194
|
+
switch (timerType) {
|
|
195
|
+
case 'timeCycle':
|
|
196
|
+
case 'timeDuration':
|
|
197
|
+
{
|
|
198
|
+
const parsed = (0, _isoDuration.parse)(value);
|
|
199
|
+
if (parsed.repeat) repeat = parsed.repeat;
|
|
200
|
+
delay = (0, _isoDuration.toSeconds)(parsed) * 1000;
|
|
201
|
+
expireAt = new Date(Date.now() + delay);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'timeDate':
|
|
205
|
+
{
|
|
206
|
+
const ms = Date.parse(value);
|
|
207
|
+
if (!isNaN(ms)) {
|
|
208
|
+
expireAt = new Date(ms);
|
|
209
|
+
delay = Date.now() - expireAt;
|
|
210
|
+
} else {
|
|
211
|
+
throw new TypeError(`invalid timeDate >${value}<`);
|
|
212
|
+
}
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
expireAt,
|
|
218
|
+
repeat,
|
|
219
|
+
delay
|
|
220
|
+
};
|
|
221
|
+
};
|
|
191
222
|
TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
192
223
|
const content = executeMessage.content;
|
|
193
|
-
const now = Date.now();
|
|
194
224
|
const result = {
|
|
195
225
|
...('expireAt' in content && {
|
|
196
226
|
expireAt: new Date(content.expireAt)
|
|
197
227
|
})
|
|
198
228
|
};
|
|
229
|
+
let parseErr;
|
|
199
230
|
for (const t of ['timeDuration', 'timeDate', 'timeCycle']) {
|
|
200
231
|
if (t in content) result[t] = content[t];else if (t in this) result[t] = this.environment.resolveExpression(this[t], executeMessage);else continue;
|
|
201
232
|
let expireAtDate, repeat;
|
|
202
233
|
const timerStr = result[t];
|
|
203
234
|
if (timerStr) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (delay !== undefined) expireAtDate = new Date(now + delay);
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
case 'timeDate':
|
|
217
|
-
{
|
|
218
|
-
const dateStr = result[t];
|
|
219
|
-
const ms = Date.parse(dateStr);
|
|
220
|
-
if (!isNaN(ms)) {
|
|
221
|
-
expireAtDate = new Date(ms);
|
|
222
|
-
} else {
|
|
223
|
-
this._warn(`invalid timeDate >${dateStr}<`);
|
|
224
|
-
}
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
235
|
+
try {
|
|
236
|
+
const {
|
|
237
|
+
repeat: parsedRepeat,
|
|
238
|
+
expireAt: parsedExpireAt
|
|
239
|
+
} = this.parse(t, timerStr);
|
|
240
|
+
repeat = parsedRepeat;
|
|
241
|
+
expireAtDate = parsedExpireAt;
|
|
242
|
+
} catch (err) {
|
|
243
|
+
parseErr = err;
|
|
227
244
|
}
|
|
228
245
|
} else {
|
|
229
|
-
expireAtDate = new Date(
|
|
246
|
+
expireAtDate = new Date();
|
|
230
247
|
}
|
|
231
248
|
if (!expireAtDate) continue;
|
|
232
249
|
if (!('expireAt' in result) || result.expireAt > expireAtDate) {
|
|
233
250
|
result.timerType = t;
|
|
234
251
|
result.expireAt = expireAtDate;
|
|
235
|
-
|
|
252
|
+
result.repeat = repeat;
|
|
236
253
|
}
|
|
237
254
|
}
|
|
238
255
|
if ('expireAt' in result) {
|
|
239
|
-
result.timeout = result.expireAt - now;
|
|
256
|
+
result.timeout = result.expireAt - Date.now();
|
|
240
257
|
} else if ('timeout' in content) {
|
|
241
258
|
result.timeout = content.timeout;
|
|
242
259
|
} else if (!Object.keys(result).length) {
|
|
243
260
|
result.timeout = 0;
|
|
244
261
|
}
|
|
262
|
+
if (!('timeout' in result) && parseErr) {
|
|
263
|
+
this.logger.warn(`<${this.activity.id}> failed to parse timer: ${parseErr.message}`);
|
|
264
|
+
}
|
|
245
265
|
if (content.inbound && 'repeat' in content.inbound[0]) {
|
|
246
266
|
result.repeat = content.inbound[0].repeat;
|
|
247
267
|
}
|
|
248
268
|
return result;
|
|
249
269
|
};
|
|
250
|
-
TimerEventDefinition.prototype._getDurationInMilliseconds = function getDurationInMilliseconds(duration) {
|
|
251
|
-
try {
|
|
252
|
-
return (0, _iso8601Duration.toSeconds)((0, _iso8601Duration.parse)(duration)) * 1000;
|
|
253
|
-
} catch (err) {
|
|
254
|
-
this._warn(`failed to parse ${this.timerType} >${duration}<: ${err.message}`);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
270
|
TimerEventDefinition.prototype._debug = function debug(msg) {
|
|
258
271
|
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
259
|
-
};
|
|
260
|
-
TimerEventDefinition.prototype._warn = function debug(msg) {
|
|
261
|
-
this.logger.warn(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
262
272
|
};
|
package/dist/index.js
CHANGED
|
@@ -147,6 +147,7 @@ Object.defineProperty(exports, "Group", {
|
|
|
147
147
|
return _Dummy.default;
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
+
exports.ISODuration = void 0;
|
|
150
151
|
Object.defineProperty(exports, "InclusiveGateway", {
|
|
151
152
|
enumerable: true,
|
|
152
153
|
get: function () {
|
|
@@ -171,6 +172,12 @@ Object.defineProperty(exports, "IntermediateThrowEvent", {
|
|
|
171
172
|
return _IntermediateThrowEvent.default;
|
|
172
173
|
}
|
|
173
174
|
});
|
|
175
|
+
Object.defineProperty(exports, "Lane", {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function () {
|
|
178
|
+
return _Lane.default;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
174
181
|
Object.defineProperty(exports, "LinkEventDefinition", {
|
|
175
182
|
enumerable: true,
|
|
176
183
|
get: function () {
|
|
@@ -321,6 +328,12 @@ Object.defineProperty(exports, "TimerEventDefinition", {
|
|
|
321
328
|
return _TimerEventDefinition.default;
|
|
322
329
|
}
|
|
323
330
|
});
|
|
331
|
+
Object.defineProperty(exports, "Timers", {
|
|
332
|
+
enumerable: true,
|
|
333
|
+
get: function () {
|
|
334
|
+
return _Timers.Timers;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
324
337
|
Object.defineProperty(exports, "Transaction", {
|
|
325
338
|
enumerable: true,
|
|
326
339
|
get: function () {
|
|
@@ -358,6 +371,7 @@ var _InclusiveGateway = _interopRequireDefault(require("./gateways/InclusiveGate
|
|
|
358
371
|
var _InputOutputSpecification = _interopRequireDefault(require("./io/InputOutputSpecification.js"));
|
|
359
372
|
var _IntermediateCatchEvent = _interopRequireDefault(require("./events/IntermediateCatchEvent.js"));
|
|
360
373
|
var _IntermediateThrowEvent = _interopRequireDefault(require("./events/IntermediateThrowEvent.js"));
|
|
374
|
+
var _Lane = _interopRequireDefault(require("./process/Lane.js"));
|
|
361
375
|
var _LinkEventDefinition = _interopRequireDefault(require("./eventDefinitions/LinkEventDefinition.js"));
|
|
362
376
|
var _LoopCharacteristics = _interopRequireDefault(require("./tasks/LoopCharacteristics.js"));
|
|
363
377
|
var _Message = _interopRequireDefault(require("./activity/Message.js"));
|
|
@@ -381,4 +395,9 @@ var _Task = _interopRequireDefault(require("./tasks/Task.js"));
|
|
|
381
395
|
var _TerminateEventDefinition = _interopRequireDefault(require("./eventDefinitions/TerminateEventDefinition.js"));
|
|
382
396
|
var _TimerEventDefinition = _interopRequireDefault(require("./eventDefinitions/TimerEventDefinition.js"));
|
|
383
397
|
var _Transaction = _interopRequireDefault(require("./tasks/Transaction.js"));
|
|
398
|
+
var _Timers = require("./Timers.js");
|
|
399
|
+
var ISODuration = _interopRequireWildcard(require("./iso-duration.js"));
|
|
400
|
+
exports.ISODuration = ISODuration;
|
|
401
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
402
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
384
403
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.end = end;
|
|
7
|
+
exports.parse = parse;
|
|
8
|
+
exports.toSeconds = toSeconds;
|
|
9
|
+
// License MIT @ https://tolu.mit-license.org/
|
|
10
|
+
|
|
11
|
+
const numbers = '\\d+';
|
|
12
|
+
const fractionalNumbers = ''.concat(numbers, '(?:[\\.,]').concat(numbers, ')?');
|
|
13
|
+
const datePattern = '('.concat(numbers, 'Y)?(').concat(numbers, 'M)?(').concat(numbers, 'W)?(').concat(fractionalNumbers, 'D)?');
|
|
14
|
+
const timePattern = 'T('.concat(fractionalNumbers, 'H)?(').concat(fractionalNumbers, 'M)?(').concat(fractionalNumbers, 'S)?');
|
|
15
|
+
const rPattern = '(?:R('.concat(numbers).concat(')/)?');
|
|
16
|
+
const iso8601 = rPattern.concat('P(?:').concat(datePattern, '(?:').concat(timePattern, ')?)');
|
|
17
|
+
const objMap = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds'];
|
|
18
|
+
const defaultDuration = Object.freeze({
|
|
19
|
+
years: 0,
|
|
20
|
+
months: 0,
|
|
21
|
+
weeks: 0,
|
|
22
|
+
days: 0,
|
|
23
|
+
hours: 0,
|
|
24
|
+
minutes: 0,
|
|
25
|
+
seconds: 0
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The ISO8601 regex for matching / testing durations
|
|
30
|
+
*/
|
|
31
|
+
const pattern = new RegExp(iso8601);
|
|
32
|
+
|
|
33
|
+
/** Parse PnYnMnDTnHnMnS format to object */
|
|
34
|
+
function parse(durationString) {
|
|
35
|
+
const matches = durationString.replace(/,/g, '.').match(pattern);
|
|
36
|
+
if (!matches) {
|
|
37
|
+
throw new RangeError('invalid duration: ' + durationString);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Slice away repeat and first entry in match-array (the input string)
|
|
41
|
+
const slicedMatches = matches.slice(2);
|
|
42
|
+
if (slicedMatches.filter(Boolean).length === 0) {
|
|
43
|
+
throw new RangeError('invalid duration: ' + durationString);
|
|
44
|
+
}
|
|
45
|
+
// Check only one fraction is used
|
|
46
|
+
if (slicedMatches.filter(v => {
|
|
47
|
+
return /\./.test(v || '');
|
|
48
|
+
}).length > 1) {
|
|
49
|
+
throw new RangeError('Fractions are allowed on the smallest unit in the string, e.g. P0.5D or PT1.0001S but not PT0.5M0.1S: ' + durationString);
|
|
50
|
+
}
|
|
51
|
+
const result = {};
|
|
52
|
+
if (matches[1]) result.repeat = Number(matches[1]);
|
|
53
|
+
return slicedMatches.reduce((prev, next, idx) => {
|
|
54
|
+
prev[objMap[idx]] = parseFloat(next || '0') || 0;
|
|
55
|
+
return prev;
|
|
56
|
+
}, result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Convert ISO8601 duration object to an end Date. */
|
|
60
|
+
function end(durationInput, startDate) {
|
|
61
|
+
const duration = Object.assign({}, defaultDuration, durationInput);
|
|
62
|
+
// Create two equal timestamps, add duration to 'then' and return time difference
|
|
63
|
+
const timestamp = startDate.getTime();
|
|
64
|
+
const then = new Date(timestamp);
|
|
65
|
+
then.setFullYear(then.getFullYear() + duration.years);
|
|
66
|
+
then.setMonth(then.getMonth() + duration.months);
|
|
67
|
+
then.setDate(then.getDate() + duration.days);
|
|
68
|
+
// set time as milliseconds to get fractions working for minutes/hours
|
|
69
|
+
const hoursInMs = duration.hours * 3600 * 1000;
|
|
70
|
+
const minutesInMs = duration.minutes * 60 * 1000;
|
|
71
|
+
then.setMilliseconds(then.getMilliseconds() + duration.seconds * 1000 + hoursInMs + minutesInMs);
|
|
72
|
+
// Special case weeks
|
|
73
|
+
then.setDate(then.getDate() + duration.weeks * 7);
|
|
74
|
+
return then;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Convert ISO8601 duration object to seconds */
|
|
78
|
+
function toSeconds(durationInput, startDate) {
|
|
79
|
+
if (startDate === void 0) {
|
|
80
|
+
startDate = new Date();
|
|
81
|
+
}
|
|
82
|
+
const duration = Object.assign({}, defaultDuration, durationInput);
|
|
83
|
+
const timestamp = startDate.getTime();
|
|
84
|
+
const now = new Date(timestamp);
|
|
85
|
+
const then = end(duration, now);
|
|
86
|
+
const seconds = (then.getTime() - now.getTime()) / 1000;
|
|
87
|
+
return seconds;
|
|
88
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Lane;
|
|
7
|
+
const kProcess = Symbol.for('process');
|
|
8
|
+
function Lane(process, laneDefinition) {
|
|
9
|
+
const {
|
|
10
|
+
broker,
|
|
11
|
+
environment
|
|
12
|
+
} = process;
|
|
13
|
+
const {
|
|
14
|
+
id,
|
|
15
|
+
type,
|
|
16
|
+
behaviour
|
|
17
|
+
} = laneDefinition;
|
|
18
|
+
this[kProcess] = process;
|
|
19
|
+
this.id = id;
|
|
20
|
+
this.type = type;
|
|
21
|
+
this.name = behaviour.name;
|
|
22
|
+
this.parent = {
|
|
23
|
+
id: process.id,
|
|
24
|
+
type: process.type
|
|
25
|
+
};
|
|
26
|
+
this.behaviour = {
|
|
27
|
+
...behaviour
|
|
28
|
+
};
|
|
29
|
+
this.environment = environment;
|
|
30
|
+
this.broker = broker;
|
|
31
|
+
this.context = process.context;
|
|
32
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(Lane.prototype, 'process', {
|
|
35
|
+
get() {
|
|
36
|
+
return this[kProcess];
|
|
37
|
+
}
|
|
38
|
+
});
|