bpmn-elements 17.2.2 → 18.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 +3 -1
- package/dist/Api.js +83 -0
- package/dist/Context.js +228 -22
- package/dist/Environment.js +111 -31
- package/dist/EventBroker.js +57 -1
- package/dist/Expressions.js +3 -4
- package/dist/MessageFormatter.js +29 -16
- package/dist/Timers.js +13 -9
- package/dist/Tracker.js +1 -0
- package/dist/activity/Activity.js +458 -254
- package/dist/activity/ActivityExecution.js +113 -40
- package/dist/activity/Dummy.js +6 -1
- package/dist/activity/Escalation.js +36 -24
- package/dist/activity/ExecutionScope.js +1 -1
- package/dist/activity/Message.js +36 -24
- package/dist/activity/Signal.js +36 -24
- package/dist/activity/outbound-evaluator.js +1 -1
- package/dist/condition.js +12 -6
- package/dist/constants.js +21 -0
- package/dist/definition/Definition.js +182 -64
- package/dist/definition/DefinitionExecution.js +195 -82
- package/dist/error/BpmnError.js +12 -1
- package/dist/error/Errors.js +50 -9
- package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
- package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
- package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
- package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
- package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
- package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
- package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
- package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
- package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
- package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
- package/dist/eventDefinitions/index.js +20 -21
- package/dist/events/BoundaryEvent.js +52 -40
- package/dist/events/EndEvent.js +22 -8
- package/dist/events/IntermediateCatchEvent.js +26 -8
- package/dist/events/IntermediateThrowEvent.js +24 -9
- package/dist/events/StartEvent.js +30 -14
- package/dist/events/index.js +10 -11
- package/dist/flows/Association.js +50 -7
- package/dist/flows/MessageFlow.js +49 -10
- package/dist/flows/SequenceFlow.js +93 -22
- package/dist/flows/index.js +6 -7
- package/dist/gateways/EventBasedGateway.js +29 -15
- package/dist/gateways/ExclusiveGateway.js +20 -5
- package/dist/gateways/InclusiveGateway.js +21 -5
- package/dist/gateways/ParallelGateway.js +253 -15
- package/dist/gateways/index.js +8 -9
- package/dist/getPropertyValue.js +2 -2
- package/dist/index.js +42 -43
- package/dist/io/BpmnIO.js +15 -1
- package/dist/io/EnvironmentDataObject.js +29 -1
- package/dist/io/EnvironmentDataStore.js +24 -1
- package/dist/io/EnvironmentDataStoreReference.js +24 -1
- package/dist/io/InputOutputSpecification.js +21 -11
- package/dist/io/Properties.js +28 -17
- package/dist/messageHelper.js +41 -4
- package/dist/process/Lane.js +15 -4
- package/dist/process/Process.js +174 -76
- package/dist/process/ProcessExecution.js +362 -177
- package/dist/shared.js +2 -0
- package/dist/tasks/CallActivity.js +19 -4
- package/dist/tasks/LoopCharacteristics.js +94 -9
- package/dist/tasks/ReceiveTask.js +36 -21
- package/dist/tasks/ScriptTask.js +22 -6
- package/dist/tasks/ServiceImplementation.js +7 -4
- package/dist/tasks/ServiceTask.js +19 -4
- package/dist/tasks/SignalTask.js +19 -4
- package/dist/tasks/StandardLoopCharacteristics.js +8 -4
- package/dist/tasks/SubProcess.js +44 -29
- package/dist/tasks/Task.js +19 -4
- package/dist/tasks/Transaction.js +8 -4
- package/dist/tasks/index.js +16 -18
- package/package.json +31 -13
- package/src/Api.js +70 -0
- package/src/Context.js +200 -19
- package/src/Environment.js +99 -30
- package/src/EventBroker.js +46 -1
- package/src/Expressions.js +2 -3
- package/src/MessageFormatter.js +24 -16
- package/src/Timers.js +12 -9
- package/src/Tracker.js +1 -0
- package/src/activity/Activity.js +388 -231
- package/src/activity/ActivityExecution.js +93 -42
- package/src/activity/Dummy.js +6 -1
- package/src/activity/Escalation.js +25 -18
- package/src/activity/ExecutionScope.js +1 -1
- package/src/activity/Message.js +25 -18
- package/src/activity/Signal.js +25 -18
- package/src/activity/outbound-evaluator.js +1 -1
- package/src/condition.js +11 -5
- package/src/constants.js +15 -0
- package/src/definition/Definition.js +157 -62
- package/src/definition/DefinitionExecution.js +161 -83
- package/src/error/BpmnError.js +11 -1
- package/src/error/Errors.js +44 -5
- package/src/eventDefinitions/CancelEventDefinition.js +27 -13
- package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
- package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
- package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
- package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
- package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
- package/src/eventDefinitions/LinkEventDefinition.js +34 -120
- package/src/eventDefinitions/MessageEventDefinition.js +42 -31
- package/src/eventDefinitions/SignalEventDefinition.js +43 -32
- package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
- package/src/eventDefinitions/TimerEventDefinition.js +53 -35
- package/src/eventDefinitions/index.js +10 -23
- package/src/events/BoundaryEvent.js +50 -39
- package/src/events/EndEvent.js +19 -7
- package/src/events/IntermediateCatchEvent.js +24 -8
- package/src/events/IntermediateThrowEvent.js +24 -8
- package/src/events/StartEvent.js +25 -14
- package/src/events/index.js +5 -18
- package/src/flows/Association.js +43 -9
- package/src/flows/MessageFlow.js +41 -10
- package/src/flows/SequenceFlow.js +82 -19
- package/src/flows/index.js +3 -4
- package/src/gateways/EventBasedGateway.js +27 -15
- package/src/gateways/ExclusiveGateway.js +16 -3
- package/src/gateways/InclusiveGateway.js +16 -3
- package/src/gateways/ParallelGateway.js +301 -10
- package/src/gateways/index.js +4 -4
- package/src/getPropertyValue.js +2 -2
- package/src/index.js +19 -19
- package/src/io/BpmnIO.js +13 -1
- package/src/io/EnvironmentDataObject.js +26 -1
- package/src/io/EnvironmentDataStore.js +22 -1
- package/src/io/EnvironmentDataStoreReference.js +22 -1
- package/src/io/InputOutputSpecification.js +17 -8
- package/src/io/Properties.js +23 -13
- package/src/messageHelper.js +36 -4
- package/src/process/Lane.js +14 -4
- package/src/process/Process.js +154 -72
- package/src/process/ProcessExecution.js +326 -175
- package/src/shared.js +1 -0
- package/src/tasks/CallActivity.js +16 -2
- package/src/tasks/LoopCharacteristics.js +77 -11
- package/src/tasks/ReceiveTask.js +33 -22
- package/src/tasks/ScriptTask.js +17 -3
- package/src/tasks/ServiceImplementation.js +6 -3
- package/src/tasks/ServiceTask.js +16 -2
- package/src/tasks/SignalTask.js +16 -2
- package/src/tasks/StandardLoopCharacteristics.js +7 -3
- package/src/tasks/SubProcess.js +37 -23
- package/src/tasks/Task.js +16 -2
- package/src/tasks/Transaction.js +7 -3
- package/src/tasks/index.js +8 -9
- package/types/bundle-errors.d.ts +1 -0
- package/types/bundle.d.ts +97 -0
- package/types/index.d.ts +2614 -84
- package/types/interfaces.d.ts +636 -0
- package/types/types.d.ts +0 -765
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import type { Broker, BrokerState, Consumer, MessageEnvelope, MessageFields, MessageProperties } from 'smqp';
|
|
2
|
+
import type { SerializableContext, SerializableElement } from 'moddle-context-serializer';
|
|
3
|
+
import type { Activity } from '../src/activity/Activity.js';
|
|
4
|
+
import type { ActivityExecution } from '../src/activity/ActivityExecution.js';
|
|
5
|
+
import type { ContextInstance } from '../src/Context.js';
|
|
6
|
+
import type { Definition } from '../src/definition/Definition.js';
|
|
7
|
+
import type { DefinitionExecution } from '../src/definition/DefinitionExecution.js';
|
|
8
|
+
import type { Environment } from '../src/Environment.js';
|
|
9
|
+
import type { Lane } from '../src/process/Lane.js';
|
|
10
|
+
import type { Process } from '../src/process/Process.js';
|
|
11
|
+
import type { ProcessExecution } from '../src/process/ProcessExecution.js';
|
|
12
|
+
import type { SequenceFlow } from '../src/flows/SequenceFlow.js';
|
|
13
|
+
import type { Formatter } from '../src/MessageFormatter.js';
|
|
14
|
+
import type { ActivityError } from '../src/error/Errors.js';
|
|
15
|
+
|
|
16
|
+
export type { Activity, ActivityExecution, ContextInstance, Definition, Environment, Lane, Process, SequenceFlow };
|
|
17
|
+
export type { Consumer, MessageFields, MessageProperties, SerializableContext, SerializableElement };
|
|
18
|
+
|
|
19
|
+
// `Object.defineProperties(<Class>.prototype, …)` is opaque to tsc inference,
|
|
20
|
+
// so we declare the getters here as augmentations and TS merges them with each
|
|
21
|
+
// class at emit time.
|
|
22
|
+
declare module '../src/activity/Activity.js' {
|
|
23
|
+
interface Activity {
|
|
24
|
+
get counters(): { taken: number; discarded: number };
|
|
25
|
+
get execution(): ActivityExecution | undefined;
|
|
26
|
+
get executionId(): string | undefined;
|
|
27
|
+
get extensions(): IExtension;
|
|
28
|
+
get bpmnIo(): IExtension | undefined;
|
|
29
|
+
get formatter(): Formatter;
|
|
30
|
+
get isRunning(): boolean;
|
|
31
|
+
get outbound(): SequenceFlow[];
|
|
32
|
+
get inbound(): SequenceFlow[];
|
|
33
|
+
get isEnd(): boolean;
|
|
34
|
+
get isStart(): boolean;
|
|
35
|
+
get isSubProcess(): boolean;
|
|
36
|
+
get isTransaction(): boolean;
|
|
37
|
+
get isMultiInstance(): boolean;
|
|
38
|
+
get isThrowing(): boolean;
|
|
39
|
+
get isCatching(): boolean;
|
|
40
|
+
get isForCompensation(): boolean;
|
|
41
|
+
get isParallelJoin(): boolean;
|
|
42
|
+
get isParallelGateway(): boolean;
|
|
43
|
+
get isStartEvent(): boolean;
|
|
44
|
+
get triggeredByEvent(): boolean;
|
|
45
|
+
get attachedTo(): Activity | null;
|
|
46
|
+
get lane(): Lane | undefined;
|
|
47
|
+
get eventDefinitions(): EventDefinition[] | undefined;
|
|
48
|
+
get parentElement(): Activity | Process;
|
|
49
|
+
get initialized(): boolean;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare module '../src/definition/Definition.js' {
|
|
54
|
+
interface Definition {
|
|
55
|
+
get counters(): { completed: number; discarded: number };
|
|
56
|
+
get execution(): DefinitionExecution | undefined;
|
|
57
|
+
get executionId(): string | undefined;
|
|
58
|
+
get isRunning(): boolean;
|
|
59
|
+
get status(): DefinitionStatus | undefined;
|
|
60
|
+
get stopped(): boolean;
|
|
61
|
+
get activityStatus(): ActivityStatus;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module '../src/process/Process.js' {
|
|
66
|
+
interface Process {
|
|
67
|
+
get counters(): { completed: number; discarded: number };
|
|
68
|
+
get lanes(): Lane[] | undefined;
|
|
69
|
+
get extensions(): IExtension | undefined;
|
|
70
|
+
get stopped(): boolean;
|
|
71
|
+
get isRunning(): boolean;
|
|
72
|
+
get executionId(): string | undefined;
|
|
73
|
+
get execution(): ProcessExecution | undefined;
|
|
74
|
+
get status(): ProcessStatus | undefined;
|
|
75
|
+
get activityStatus(): ActivityStatus;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare module '../src/process/ProcessExecution.js' {
|
|
80
|
+
interface ProcessExecution {
|
|
81
|
+
get stopped(): boolean;
|
|
82
|
+
get completed(): boolean;
|
|
83
|
+
get status(): ProcessStatus;
|
|
84
|
+
get postponedCount(): number;
|
|
85
|
+
get isRunning(): boolean;
|
|
86
|
+
get activityStatus(): ActivityStatus;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare module '../src/definition/DefinitionExecution.js' {
|
|
91
|
+
interface DefinitionExecution {
|
|
92
|
+
get stopped(): boolean;
|
|
93
|
+
get completed(): boolean;
|
|
94
|
+
get status(): DefinitionStatus;
|
|
95
|
+
get processes(): Process[];
|
|
96
|
+
get postponedCount(): number;
|
|
97
|
+
get isRunning(): boolean;
|
|
98
|
+
get activityStatus(): ActivityStatus;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// --- Broker / message contracts -----------------------------------------------
|
|
103
|
+
|
|
104
|
+
export interface ElementBroker<T> extends Broker {
|
|
105
|
+
get owner(): T;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Wrapper returned by `ActivityBroker`, `ProcessBroker`, `DefinitionBroker`,
|
|
110
|
+
* `MessageFlowBroker`, and `new EventBroker(owner, options)`. Owns an underlying
|
|
111
|
+
* smqp Broker and exposes bound, prefixed event helpers.
|
|
112
|
+
*
|
|
113
|
+
* @template T Broker owner element type (Activity, Process, Definition, ...).
|
|
114
|
+
*/
|
|
115
|
+
export interface EventBroker<T> {
|
|
116
|
+
options: { prefix: string; autoDelete?: boolean; durable?: boolean };
|
|
117
|
+
eventPrefix: string;
|
|
118
|
+
broker: ElementBroker<T>;
|
|
119
|
+
on(eventName: string, callback: CallableFunction, eventOptions?: { once?: boolean; [x: string]: any }): Consumer;
|
|
120
|
+
once(eventName: string, callback: CallableFunction, eventOptions?: { [x: string]: any }): Consumer;
|
|
121
|
+
waitFor(eventName: string, onMessage?: (routingKey: string, message: ElementBrokerMessage, owner: T) => boolean): Promise<IApi<T>>;
|
|
122
|
+
emit(eventName: string, content?: Record<string, any>, props?: any): void;
|
|
123
|
+
emitFatal(error: Error, content?: Record<string, any>): void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type signalMessage = {
|
|
127
|
+
/**
|
|
128
|
+
* Optional signal id
|
|
129
|
+
* - Activity id
|
|
130
|
+
* - Signal-, Message-, Escalation id, etc
|
|
131
|
+
*/
|
|
132
|
+
id?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Optional execution id
|
|
135
|
+
* e.g. excutionId of a parallel multi instance user task
|
|
136
|
+
*/
|
|
137
|
+
executionId?: string;
|
|
138
|
+
/** Any other input that will be added to completed activity output */
|
|
139
|
+
[x: string]: any;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export interface ElementMessageContent {
|
|
143
|
+
/** Element id */
|
|
144
|
+
id?: string;
|
|
145
|
+
/** Element type */
|
|
146
|
+
type?: string;
|
|
147
|
+
/** Element execution id */
|
|
148
|
+
executionId?: string;
|
|
149
|
+
parent?: ElementParent;
|
|
150
|
+
[x: string]: any;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ElementBrokerMessage extends MessageEnvelope {
|
|
154
|
+
content: ElementMessageContent;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface ElementParent {
|
|
158
|
+
id: string;
|
|
159
|
+
type: string;
|
|
160
|
+
executionId: string;
|
|
161
|
+
path?: Omit<ElementParent, 'path'>[];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// --- Shake results ------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
/** A single hop (activity or sequence flow) recorded during a shake walk. */
|
|
167
|
+
export interface ShakeSequenceItem {
|
|
168
|
+
id: string;
|
|
169
|
+
type: string;
|
|
170
|
+
count?: number;
|
|
171
|
+
sourceId?: string;
|
|
172
|
+
targetId?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** A single end-to-end sequence discovered while shaking an activity graph. */
|
|
176
|
+
export interface ShakenSequence extends ElementMessageContent {
|
|
177
|
+
/** The activity- and flow-id steps that were walked, in order. */
|
|
178
|
+
sequence: ShakeSequenceItem[];
|
|
179
|
+
/** true when the walk revisited an already-seen activity. */
|
|
180
|
+
isLooped: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Result of shaking an activity graph, keyed by the starting activity id. */
|
|
184
|
+
export type ShakeResult = Record<string, ShakenSequence[]>;
|
|
185
|
+
|
|
186
|
+
// --- Element abstract bases ---------------------------------------------------
|
|
187
|
+
|
|
188
|
+
export abstract class ElementBase {
|
|
189
|
+
get id(): string;
|
|
190
|
+
get type(): string;
|
|
191
|
+
get name(): string;
|
|
192
|
+
get parent(): ElementParent;
|
|
193
|
+
get behaviour(): SerializableElement;
|
|
194
|
+
get broker(): Broker;
|
|
195
|
+
get environment(): Environment;
|
|
196
|
+
/** Per-execution context registry (see `Context`/`ContextInstance` from src). */
|
|
197
|
+
get context(): ContextInstance;
|
|
198
|
+
get logger(): ILogger;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// --- Event definitions --------------------------------------------------------
|
|
202
|
+
|
|
203
|
+
export interface EventReference {
|
|
204
|
+
id?: string;
|
|
205
|
+
name?: string;
|
|
206
|
+
referenceType: string;
|
|
207
|
+
[x: string]: any;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Common ancestor for the typed event definitions; concrete types live in src/eventDefinitions.
|
|
211
|
+
export class EventDefinition {
|
|
212
|
+
constructor(activity: Activity, eventDefinitionElement: SerializableElement, context?: ContextInstance, index?: number);
|
|
213
|
+
get id(): string;
|
|
214
|
+
get type(): string;
|
|
215
|
+
get executionId(): string;
|
|
216
|
+
get isThrowing(): boolean;
|
|
217
|
+
get activity(): Activity;
|
|
218
|
+
get broker(): Broker;
|
|
219
|
+
get logger(): ILogger;
|
|
220
|
+
get reference(): EventReference;
|
|
221
|
+
[x: string]: any;
|
|
222
|
+
execute(executeMessage: ElementBrokerMessage): void;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Supported BPMN timer event definition types. */
|
|
226
|
+
export const enum TimerTypeValue {
|
|
227
|
+
TimeCycle = 'timeCycle',
|
|
228
|
+
TimeDuration = 'timeDuration',
|
|
229
|
+
TimeDate = 'timeDate',
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Accepts either a `TimerTypeValue` enum member or its underlying string literal. */
|
|
233
|
+
export type TimerType = TimerTypeValue | `${TimerTypeValue}`;
|
|
234
|
+
|
|
235
|
+
export type parsedTimer = {
|
|
236
|
+
/** Expires at date time */
|
|
237
|
+
expireAt?: Date;
|
|
238
|
+
/** Repeat number of times */
|
|
239
|
+
repeat?: number;
|
|
240
|
+
/** Delay in milliseconds */
|
|
241
|
+
delay?: number;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// --- Conditions ---------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
export interface ICondition {
|
|
247
|
+
/** Condition type */
|
|
248
|
+
get type(): string;
|
|
249
|
+
[x: string]: any;
|
|
250
|
+
/**
|
|
251
|
+
* Execute condition
|
|
252
|
+
* @param message Source element execution message
|
|
253
|
+
* @param callback Callback with truthy result if flow should be taken
|
|
254
|
+
*/
|
|
255
|
+
execute(message: ElementBrokerMessage, callback: CallableFunction): void;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// --- Activity behaviour & extensions ------------------------------------------
|
|
259
|
+
|
|
260
|
+
export interface IActivityBehaviour {
|
|
261
|
+
id: string;
|
|
262
|
+
type: string;
|
|
263
|
+
activity: Activity;
|
|
264
|
+
environment: Environment;
|
|
265
|
+
new (activity: Activity, context: ContextInstance): IActivityBehaviour;
|
|
266
|
+
execute(executeMessage: ElementBrokerMessage): void;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export type Extension = (activity: any, context: any) => IExtension;
|
|
270
|
+
|
|
271
|
+
export interface IExtension {
|
|
272
|
+
activate(message: ElementBrokerMessage): void;
|
|
273
|
+
deactivate(message: ElementBrokerMessage): void;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface IExpressions {
|
|
277
|
+
resolveExpression(templatedString: string, context?: any, expressionFnContext?: any): any;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// --- Environment --------------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
export interface EnvironmentSettings {
|
|
283
|
+
/** true returns dummy service function for service task if not found */
|
|
284
|
+
enableDummyService?: boolean;
|
|
285
|
+
/** true forces activity runs to go forward in steps, defaults to false */
|
|
286
|
+
step?: boolean;
|
|
287
|
+
/** strict mode, see documentation, defaults to false */
|
|
288
|
+
strict?: boolean;
|
|
289
|
+
/** positive integer to control parallel loop batch size, defaults to 50 */
|
|
290
|
+
batchSize?: number;
|
|
291
|
+
/**
|
|
292
|
+
* disable tracking state between recover and resume
|
|
293
|
+
* true will only return state for elements that are actually running
|
|
294
|
+
* Defaults to falsy
|
|
295
|
+
*/
|
|
296
|
+
disableTrackState?: boolean;
|
|
297
|
+
[x: string]: any;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface EnvironmentOptions {
|
|
301
|
+
settings?: EnvironmentSettings;
|
|
302
|
+
variables?: Record<string, any>;
|
|
303
|
+
services?: Record<string, CallableFunction>;
|
|
304
|
+
Logger?: LoggerFactory;
|
|
305
|
+
timers?: ITimers;
|
|
306
|
+
scripts?: IScripts;
|
|
307
|
+
extensions?: Record<string, Extension>;
|
|
308
|
+
/**
|
|
309
|
+
* optional override expressions handler
|
|
310
|
+
*/
|
|
311
|
+
expressions?: IExpressions;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// --- Filter / callback shapes -------------------------------------------------
|
|
315
|
+
|
|
316
|
+
export type startActivityFilterOptions = {
|
|
317
|
+
/** Event definition id, i.e. Message, Signal, Error, etc */
|
|
318
|
+
referenceId?: string;
|
|
319
|
+
/** Event definition type, i.e. message, signal, error, etc */
|
|
320
|
+
referenceType?: string;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export type filterPostponed = (elementApi: any) => boolean;
|
|
324
|
+
|
|
325
|
+
export type runCallback = (err: Error, definitionApi: any) => void;
|
|
326
|
+
|
|
327
|
+
// --- Run-status enums ---------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Definition status values. Covers both the entity (`Definition.status`) and
|
|
331
|
+
* the execution (`DefinitionExecution.status`) lifecycles.
|
|
332
|
+
*/
|
|
333
|
+
export const enum DefinitionStatusValue {
|
|
334
|
+
/** DefinitionExecution constructed, not yet started */
|
|
335
|
+
Init = 'init',
|
|
336
|
+
/** Definition run entered */
|
|
337
|
+
Entered = 'entered',
|
|
338
|
+
/** Definition run started */
|
|
339
|
+
Start = 'start',
|
|
340
|
+
/** Definition is executing */
|
|
341
|
+
Executing = 'executing',
|
|
342
|
+
/** Definition run ended */
|
|
343
|
+
End = 'end',
|
|
344
|
+
/** Definition run discarded */
|
|
345
|
+
Discarded = 'discarded',
|
|
346
|
+
/** Definition execution completed successfully */
|
|
347
|
+
Completed = 'completed',
|
|
348
|
+
/** Definition execution failed */
|
|
349
|
+
Error = 'error',
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Accepts either a `DefinitionStatusValue` enum member or its string literal. */
|
|
353
|
+
export type DefinitionStatus = DefinitionStatusValue | `${DefinitionStatusValue}`;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Process status values. Covers both the entity (`Process.status`) and the
|
|
357
|
+
* execution (`ProcessExecution.status`) lifecycles.
|
|
358
|
+
*/
|
|
359
|
+
export const enum ProcessStatusValue {
|
|
360
|
+
/** ProcessExecution constructed, not yet started */
|
|
361
|
+
Init = 'init',
|
|
362
|
+
/** Process run entered */
|
|
363
|
+
Entered = 'entered',
|
|
364
|
+
/** Process run started */
|
|
365
|
+
Start = 'start',
|
|
366
|
+
/** Process is executing */
|
|
367
|
+
Executing = 'executing',
|
|
368
|
+
/** Process run errored */
|
|
369
|
+
Errored = 'errored',
|
|
370
|
+
/** Process run ended */
|
|
371
|
+
End = 'end',
|
|
372
|
+
/** Process run discarded */
|
|
373
|
+
Discarded = 'discarded',
|
|
374
|
+
/** Process execution discard in progress */
|
|
375
|
+
Discard = 'discard',
|
|
376
|
+
/** Process execution cancelled */
|
|
377
|
+
Cancel = 'cancel',
|
|
378
|
+
/** Process execution completed successfully */
|
|
379
|
+
Completed = 'completed',
|
|
380
|
+
/** Process execution failed */
|
|
381
|
+
Error = 'error',
|
|
382
|
+
/** Process execution terminated by a terminate end event */
|
|
383
|
+
Terminated = 'terminated',
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Accepts either a `ProcessStatusValue` enum member or its string literal. */
|
|
387
|
+
export type ProcessStatus = ProcessStatusValue | `${ProcessStatusValue}`;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Activity status values. Covers both the per-activity run lifecycle and the
|
|
391
|
+
* rollup states surfaced by Process/Definition `activityStatus` getters. Save
|
|
392
|
+
* point candidates are `Timer` and `Wait`.
|
|
393
|
+
*/
|
|
394
|
+
export const enum ActivityStatusValue {
|
|
395
|
+
/** Idle, not running anything */
|
|
396
|
+
Idle = 'idle',
|
|
397
|
+
/** Run entered, triggered by taken inbound flow */
|
|
398
|
+
Entered = 'entered',
|
|
399
|
+
/** Run started */
|
|
400
|
+
Started = 'started',
|
|
401
|
+
/**
|
|
402
|
+
* At least one activity is executing,
|
|
403
|
+
* e.g. a service task making a asynchronous request
|
|
404
|
+
*/
|
|
405
|
+
Executing = 'executing',
|
|
406
|
+
/** Activity behaviour execution completed successfully */
|
|
407
|
+
Executed = 'executed',
|
|
408
|
+
/** Run end, take outbound flows */
|
|
409
|
+
End = 'end',
|
|
410
|
+
/** Entering discard run, triggered by discarded inbound flow */
|
|
411
|
+
Discard = 'discard',
|
|
412
|
+
/** Run was discarded, discard outbound flows */
|
|
413
|
+
Discarded = 'discarded',
|
|
414
|
+
/** Activity behaviour execution failed, discard run */
|
|
415
|
+
Error = 'error',
|
|
416
|
+
/** Formatting next run message */
|
|
417
|
+
Formatting = 'formatting',
|
|
418
|
+
/**
|
|
419
|
+
* At least one activity is waiting for a timer to complete,
|
|
420
|
+
* usually only TimerEventDefinition's
|
|
421
|
+
*/
|
|
422
|
+
Timer = 'timer',
|
|
423
|
+
/**
|
|
424
|
+
* At least one activity is waiting for a signal of some sort,
|
|
425
|
+
* e.g. user tasks, intermediate catch events, etc
|
|
426
|
+
*/
|
|
427
|
+
Wait = 'wait',
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Accepts either an `ActivityStatusValue` enum member or its underlying string
|
|
432
|
+
* literal, so JSDoc-typed assignments like `this.status = 'entered'` keep
|
|
433
|
+
* type-checking.
|
|
434
|
+
*/
|
|
435
|
+
export type ActivityStatus = ActivityStatusValue | `${ActivityStatusValue}`;
|
|
436
|
+
|
|
437
|
+
// --- State snapshots ----------------------------------------------------------
|
|
438
|
+
|
|
439
|
+
export interface ElementState {
|
|
440
|
+
id: string;
|
|
441
|
+
type: string;
|
|
442
|
+
broker?: BrokerState;
|
|
443
|
+
[x: string]: any;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export interface EnvironmentState {
|
|
447
|
+
settings: EnvironmentSettings;
|
|
448
|
+
variables: Record<string, any>;
|
|
449
|
+
output: Record<string, any>;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export type completedCounters = { completed: number; discarded: number };
|
|
453
|
+
|
|
454
|
+
export interface ActivityExecutionState {
|
|
455
|
+
completed: boolean;
|
|
456
|
+
[x: string]: any;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface ActivityState extends ElementState {
|
|
460
|
+
status?: ActivityStatus;
|
|
461
|
+
executionId: string;
|
|
462
|
+
stopped: boolean;
|
|
463
|
+
counters: { taken: number; discarded: number };
|
|
464
|
+
execution?: ActivityExecutionState;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export interface SequenceFlowState extends ElementState {
|
|
468
|
+
counters: { take: number; discard: number; looped: number };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface MessageFlowState extends ElementState {
|
|
472
|
+
counters: { messages: number };
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface AssociationState extends ElementState {
|
|
476
|
+
counters: { take: number; discard: number };
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export interface ProcessExecutionState {
|
|
480
|
+
executionId: string;
|
|
481
|
+
stopped: boolean;
|
|
482
|
+
completed: boolean;
|
|
483
|
+
status: ProcessStatus;
|
|
484
|
+
children: ActivityState[];
|
|
485
|
+
flows?: SequenceFlowState[];
|
|
486
|
+
messageFlows?: MessageFlowState[];
|
|
487
|
+
associations?: AssociationState[];
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export interface ProcessState extends ElementState {
|
|
491
|
+
status: ProcessStatus;
|
|
492
|
+
stopped: boolean;
|
|
493
|
+
executionId?: string;
|
|
494
|
+
counters: completedCounters;
|
|
495
|
+
environment: EnvironmentState;
|
|
496
|
+
execution?: ProcessExecutionState;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface DefinitionExecutionState {
|
|
500
|
+
executionId: string;
|
|
501
|
+
stopped: boolean;
|
|
502
|
+
completed: boolean;
|
|
503
|
+
status: DefinitionStatus;
|
|
504
|
+
processes: ProcessState[];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export interface DefinitionState extends ElementState {
|
|
508
|
+
status: DefinitionStatus;
|
|
509
|
+
stopped: boolean;
|
|
510
|
+
executionId?: string;
|
|
511
|
+
counters: completedCounters;
|
|
512
|
+
environment: EnvironmentState;
|
|
513
|
+
execution?: DefinitionExecutionState;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// --- Logging ------------------------------------------------------------------
|
|
517
|
+
|
|
518
|
+
export type LoggerFactory = (scope: string) => ILogger;
|
|
519
|
+
|
|
520
|
+
export interface ILogger {
|
|
521
|
+
debug(...args: any[]): void;
|
|
522
|
+
error(...args: any[]): void;
|
|
523
|
+
warn(...args: any[]): void;
|
|
524
|
+
[x: string]: any;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// --- Timers -------------------------------------------------------------------
|
|
528
|
+
|
|
529
|
+
export type wrappedSetTimeout = (handler: CallableFunction, delay: number, ...args: any[]) => Timer;
|
|
530
|
+
export type wrappedClearTimeout = (ref: any) => void;
|
|
531
|
+
|
|
532
|
+
export interface Timer {
|
|
533
|
+
/** The function to call when the timer elapses */
|
|
534
|
+
readonly callback: CallableFunction;
|
|
535
|
+
/** The number of milliseconds to wait before calling the callback */
|
|
536
|
+
readonly delay: number;
|
|
537
|
+
/** Optional arguments to pass when the callback is called */
|
|
538
|
+
readonly args?: any[];
|
|
539
|
+
/** Timer owner if any */
|
|
540
|
+
readonly owner?: any;
|
|
541
|
+
/** Timer Id */
|
|
542
|
+
readonly timerId: string;
|
|
543
|
+
/** Timeout, return from setTimeout */
|
|
544
|
+
readonly timerRef: any;
|
|
545
|
+
[x: string]: any;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export interface RegisteredTimer {
|
|
549
|
+
owner?: any;
|
|
550
|
+
get setTimeout(): wrappedSetTimeout;
|
|
551
|
+
get clearTimeout(): wrappedClearTimeout;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export interface ITimers {
|
|
555
|
+
get setTimeout(): wrappedSetTimeout;
|
|
556
|
+
get clearTimeout(): wrappedClearTimeout;
|
|
557
|
+
register(owner?: any): RegisteredTimer;
|
|
558
|
+
[x: string]: any;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export interface TimersOptions {
|
|
562
|
+
/** Defaults to builtin setTimeout */
|
|
563
|
+
setTimeout?: typeof setTimeout;
|
|
564
|
+
/** Defaults to builtin clearTimeout */
|
|
565
|
+
clearTimeout?: typeof clearTimeout;
|
|
566
|
+
[x: string]: any;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// --- Scripts ------------------------------------------------------------------
|
|
570
|
+
|
|
571
|
+
export interface IScripts {
|
|
572
|
+
register(activity: Activity): Script | undefined;
|
|
573
|
+
getScript(language: string, identifier: { id: string; [x: string]: any }): Script;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export interface Script {
|
|
577
|
+
execute(executionContext: ExecutionScope, callback: CallableFunction): void;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// --- Generic api shape; constructed via Activity/Process/Definition/Flow Api factories.
|
|
581
|
+
|
|
582
|
+
export interface IApi<T> extends ElementBrokerMessage {
|
|
583
|
+
get id(): string;
|
|
584
|
+
get type(): string;
|
|
585
|
+
get name(): string;
|
|
586
|
+
get executionId(): string;
|
|
587
|
+
get environment(): Environment;
|
|
588
|
+
get broker(): ElementBroker<T>;
|
|
589
|
+
get owner(): T;
|
|
590
|
+
cancel(message?: signalMessage, options?: any): void;
|
|
591
|
+
discard(): void;
|
|
592
|
+
fail(error: Error): void;
|
|
593
|
+
signal(message?: signalMessage, options?: any): void;
|
|
594
|
+
stop(): void;
|
|
595
|
+
resolveExpression(expression: string): any;
|
|
596
|
+
sendApiMessage(action: string, content?: signalMessage, options?: any): void;
|
|
597
|
+
getPostponed(...args: any[]): any[];
|
|
598
|
+
createMessage(content?: Record<string, any>): any;
|
|
599
|
+
getExecuting(): IApi<T>[];
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// --- Scope passed to user scripts/services -----------------------------------
|
|
603
|
+
|
|
604
|
+
export interface ExecutionScope extends ElementBrokerMessage {
|
|
605
|
+
/** Calling element id */
|
|
606
|
+
id: string;
|
|
607
|
+
/** Calling element type */
|
|
608
|
+
type: string;
|
|
609
|
+
environment: Environment;
|
|
610
|
+
/** Calling element logger instance */
|
|
611
|
+
logger?: ILogger;
|
|
612
|
+
/**
|
|
613
|
+
* Resolve expression with the current scope
|
|
614
|
+
* @param expression expression string
|
|
615
|
+
* @returns Whatever the expression returns
|
|
616
|
+
*/
|
|
617
|
+
resolveExpression: (expression: string) => any;
|
|
618
|
+
ActivityError: ActivityError;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// --- Context --
|
|
622
|
+
export interface IExtensionsMapper {
|
|
623
|
+
get(activity: any): IExtensions[];
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export interface IExtensions extends IExtension {
|
|
627
|
+
readonly count: number;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// --- IO ---
|
|
631
|
+
|
|
632
|
+
export interface IIOData {
|
|
633
|
+
[x: string]: any;
|
|
634
|
+
read(broker: Broker, exchange: string, routingKeyPrefix: string, messageProperties?: Record<string, any>): void;
|
|
635
|
+
write(broker: Broker, exchange: string, routingKeyPrefix: string, value: any, messageProperties?: Record<string, any>): void;
|
|
636
|
+
}
|