bpmn-elements 8.2.4 → 9.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/{src/Api.js → Api.js} +11 -12
  4. package/dist/{src/Context.js → Context.js} +26 -27
  5. package/dist/{src/Environment.js → Environment.js} +15 -16
  6. package/dist/{src/EventBroker.js → EventBroker.js} +5 -1
  7. package/dist/{src/Expressions.js → Expressions.js} +1 -1
  8. package/dist/{src/MessageFormatter.js → MessageFormatter.js} +3 -3
  9. package/dist/Tracker.js +89 -0
  10. package/dist/{src/activity → activity}/Activity.js +109 -120
  11. package/dist/{src/activity → activity}/ActivityExecution.js +28 -32
  12. package/dist/{src/activity → activity}/Dummy.js +1 -1
  13. package/dist/{src/activity → activity}/ExecutionScope.js +2 -2
  14. package/dist/{src/definition → definition}/Definition.js +64 -59
  15. package/dist/{src/definition → definition}/DefinitionExecution.js +68 -46
  16. package/dist/{src/error → error}/Errors.js +1 -1
  17. package/dist/eventDefinitions/CancelEventDefinition.js +127 -0
  18. package/dist/{src/eventDefinitions → eventDefinitions}/CompensateEventDefinition.js +64 -52
  19. package/dist/{src/eventDefinitions → eventDefinitions}/ConditionalEventDefinition.js +24 -16
  20. package/dist/{src/eventDefinitions → eventDefinitions}/ErrorEventDefinition.js +15 -14
  21. package/dist/{src/eventDefinitions → eventDefinitions}/EscalationEventDefinition.js +12 -13
  22. package/dist/{src/eventDefinitions → eventDefinitions}/EventDefinitionExecution.js +10 -11
  23. package/dist/{src/eventDefinitions → eventDefinitions}/LinkEventDefinition.js +14 -15
  24. package/dist/{src/eventDefinitions → eventDefinitions}/MessageEventDefinition.js +13 -14
  25. package/dist/{src/eventDefinitions → eventDefinitions}/SignalEventDefinition.js +13 -14
  26. package/dist/{src/eventDefinitions → eventDefinitions}/TerminateEventDefinition.js +1 -1
  27. package/dist/{src/eventDefinitions → eventDefinitions}/TimerEventDefinition.js +15 -16
  28. package/dist/{src/events → events}/BoundaryEvent.js +39 -25
  29. package/dist/{src/events → events}/EndEvent.js +3 -3
  30. package/dist/{src/events → events}/IntermediateCatchEvent.js +3 -3
  31. package/dist/{src/events → events}/IntermediateThrowEvent.js +3 -3
  32. package/dist/{src/events → events}/StartEvent.js +8 -9
  33. package/dist/{src/flows → flows}/Association.js +14 -22
  34. package/dist/{src/flows → flows}/MessageFlow.js +16 -14
  35. package/dist/{src/flows → flows}/SequenceFlow.js +16 -18
  36. package/dist/{src/gateways → gateways}/EventBasedGateway.js +3 -4
  37. package/dist/{src/gateways → gateways}/ExclusiveGateway.js +2 -2
  38. package/dist/{src/gateways → gateways}/InclusiveGateway.js +2 -2
  39. package/dist/{src/gateways → gateways}/ParallelGateway.js +2 -2
  40. package/dist/index.js +48 -48
  41. package/dist/{src/io → io}/InputOutputSpecification.js +8 -9
  42. package/dist/{src/io → io}/Properties.js +7 -8
  43. package/dist/package.json +3 -0
  44. package/dist/{src/process → process}/Process.js +44 -40
  45. package/dist/{src/process → process}/ProcessExecution.js +169 -78
  46. package/dist/{src/tasks → tasks}/CallActivity.js +7 -8
  47. package/dist/{src/tasks → tasks}/LoopCharacteristics.js +2 -2
  48. package/dist/{src/tasks → tasks}/ReceiveTask.js +14 -15
  49. package/dist/{src/tasks → tasks}/ScriptTask.js +4 -4
  50. package/dist/{src/tasks → tasks}/ServiceImplementation.js +1 -1
  51. package/dist/{src/tasks → tasks}/ServiceTask.js +6 -7
  52. package/dist/{src/tasks → tasks}/SignalTask.js +7 -8
  53. package/dist/{src/tasks → tasks}/StandardLoopCharacteristics.js +1 -1
  54. package/dist/{src/tasks → tasks}/SubProcess.js +19 -19
  55. package/dist/{src/tasks → tasks}/Task.js +2 -2
  56. package/dist/{src/tasks → tasks}/Transaction.js +1 -1
  57. package/package.json +31 -31
  58. package/src/Api.js +11 -13
  59. package/src/Context.js +26 -28
  60. package/src/Environment.js +15 -17
  61. package/src/EventBroker.js +2 -1
  62. package/src/Expressions.js +1 -1
  63. package/src/MessageFormatter.js +3 -3
  64. package/src/Tracker.js +73 -0
  65. package/src/activity/Activity.js +106 -114
  66. package/src/activity/ActivityExecution.js +28 -32
  67. package/src/activity/Dummy.js +1 -1
  68. package/src/activity/ExecutionScope.js +2 -2
  69. package/src/definition/Definition.js +65 -64
  70. package/src/definition/DefinitionExecution.js +71 -47
  71. package/src/error/Errors.js +1 -1
  72. package/src/eventDefinitions/CancelEventDefinition.js +32 -78
  73. package/src/eventDefinitions/CompensateEventDefinition.js +58 -52
  74. package/src/eventDefinitions/ConditionalEventDefinition.js +25 -17
  75. package/src/eventDefinitions/ErrorEventDefinition.js +15 -15
  76. package/src/eventDefinitions/EscalationEventDefinition.js +12 -14
  77. package/src/eventDefinitions/EventDefinitionExecution.js +10 -12
  78. package/src/eventDefinitions/LinkEventDefinition.js +14 -16
  79. package/src/eventDefinitions/MessageEventDefinition.js +13 -15
  80. package/src/eventDefinitions/SignalEventDefinition.js +13 -15
  81. package/src/eventDefinitions/TerminateEventDefinition.js +1 -1
  82. package/src/eventDefinitions/TimerEventDefinition.js +15 -17
  83. package/src/events/BoundaryEvent.js +34 -24
  84. package/src/events/EndEvent.js +3 -3
  85. package/src/events/IntermediateCatchEvent.js +3 -3
  86. package/src/events/IntermediateThrowEvent.js +3 -3
  87. package/src/events/StartEvent.js +8 -10
  88. package/src/flows/Association.js +14 -26
  89. package/src/flows/MessageFlow.js +14 -15
  90. package/src/flows/SequenceFlow.js +16 -20
  91. package/src/gateways/EventBasedGateway.js +3 -4
  92. package/src/gateways/ExclusiveGateway.js +2 -2
  93. package/src/gateways/InclusiveGateway.js +2 -2
  94. package/src/gateways/ParallelGateway.js +2 -2
  95. package/src/index.js +106 -0
  96. package/src/io/InputOutputSpecification.js +8 -10
  97. package/src/io/Properties.js +7 -9
  98. package/src/process/Process.js +45 -41
  99. package/src/process/ProcessExecution.js +167 -79
  100. package/src/tasks/CallActivity.js +7 -9
  101. package/src/tasks/LoopCharacteristics.js +2 -2
  102. package/src/tasks/ReceiveTask.js +215 -217
  103. package/src/tasks/ScriptTask.js +4 -4
  104. package/src/tasks/ServiceImplementation.js +1 -1
  105. package/src/tasks/ServiceTask.js +6 -8
  106. package/src/tasks/SignalTask.js +7 -9
  107. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  108. package/src/tasks/SubProcess.js +19 -20
  109. package/src/tasks/Task.js +2 -2
  110. package/src/tasks/Transaction.js +1 -1
  111. package/types/index.d.ts +520 -0
  112. package/dist/src/eventDefinitions/CancelEventDefinition.js +0 -184
  113. package/index.js +0 -106
  114. /package/dist/{src/ExtensionsMapper.js → ExtensionsMapper.js} +0 -0
  115. /package/dist/{src/Scripts.js → Scripts.js} +0 -0
  116. /package/dist/{src/Timers.js → Timers.js} +0 -0
  117. /package/dist/{src/activity → activity}/Escalation.js +0 -0
  118. /package/dist/{src/activity → activity}/Message.js +0 -0
  119. /package/dist/{src/activity → activity}/Signal.js +0 -0
  120. /package/dist/{src/error → error}/BpmnError.js +0 -0
  121. /package/dist/{src/getPropertyValue.js → getPropertyValue.js} +0 -0
  122. /package/dist/{src/io → io}/BpmnIO.js +0 -0
  123. /package/dist/{src/io → io}/EnvironmentDataObject.js +0 -0
  124. /package/dist/{src/io → io}/EnvironmentDataStore.js +0 -0
  125. /package/dist/{src/io → io}/EnvironmentDataStoreReference.js +0 -0
  126. /package/dist/{src/messageHelper.js → messageHelper.js} +0 -0
  127. /package/dist/{src/shared.js → shared.js} +0 -0
@@ -1,6 +1,6 @@
1
- import Activity from '../activity/Activity';
2
- import ProcessExecution from '../process/ProcessExecution';
3
- import {cloneContent} from '../messageHelper';
1
+ import Activity from '../activity/Activity.js';
2
+ import ProcessExecution from '../process/ProcessExecution.js';
3
+ import {cloneContent} from '../messageHelper.js';
4
4
 
5
5
  const kExecutions = Symbol.for('executions');
6
6
  const kMessageHandlers = Symbol.for('messageHandlers');
@@ -44,21 +44,19 @@ export function SubProcessBehaviour(activity, context) {
44
44
  };
45
45
  }
46
46
 
47
- const proto = SubProcessBehaviour.prototype;
48
-
49
- Object.defineProperty(proto, 'execution', {
47
+ Object.defineProperty(SubProcessBehaviour.prototype, 'execution', {
50
48
  get() {
51
49
  return this[kExecutions][0];
52
50
  },
53
51
  });
54
52
 
55
- Object.defineProperty(proto, 'executions', {
53
+ Object.defineProperty(SubProcessBehaviour.prototype, 'executions', {
56
54
  get() {
57
55
  return this[kExecutions].slice();
58
56
  },
59
57
  });
60
58
 
61
- proto.execute = function execute(executeMessage) {
59
+ SubProcessBehaviour.prototype.execute = function execute(executeMessage) {
62
60
  const content = executeMessage.content;
63
61
 
64
62
  let executionId = this.executionId;
@@ -83,7 +81,7 @@ proto.execute = function execute(executeMessage) {
83
81
  return processExecution.execute(executeMessage);
84
82
  };
85
83
 
86
- proto.stop = function stop() {
84
+ SubProcessBehaviour.prototype.stop = function stop() {
87
85
  for (const execution of this[kExecutions]) {
88
86
  this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
89
87
  this.broker.cancel(`_sub-process-api-${execution.executionId}`);
@@ -91,7 +89,7 @@ proto.stop = function stop() {
91
89
  }
92
90
  };
93
91
 
94
- proto.discard = function discard() {
92
+ SubProcessBehaviour.prototype.discard = function discard() {
95
93
  for (const execution of this[kExecutions]) {
96
94
  this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
97
95
  this.broker.cancel(`_sub-process-api-${execution.executionId}`);
@@ -99,7 +97,7 @@ proto.discard = function discard() {
99
97
  }
100
98
  };
101
99
 
102
- proto.getState = function getState() {
100
+ SubProcessBehaviour.prototype.getState = function getState() {
103
101
  if (this.loopCharacteristics) {
104
102
  return {
105
103
  executions: this[kExecutions].map((pe) => {
@@ -118,7 +116,7 @@ proto.getState = function getState() {
118
116
  }
119
117
  };
120
118
 
121
- proto.recover = function recover(state) {
119
+ SubProcessBehaviour.prototype.recover = function recover(state) {
122
120
  if (!state) return;
123
121
 
124
122
  const executions = this[kExecutions];
@@ -145,14 +143,14 @@ proto.recover = function recover(state) {
145
143
  return execution;
146
144
  };
147
145
 
148
- proto.getPostponed = function getPostponed() {
146
+ SubProcessBehaviour.prototype.getPostponed = function getPostponed() {
149
147
  return this[kExecutions].reduce((result, pe) => {
150
148
  result = result.concat(pe.getPostponed());
151
149
  return result;
152
150
  }, []);
153
151
  };
154
152
 
155
- proto._onApiRootMessage = function onApiRootMessage(_, message) {
153
+ SubProcessBehaviour.prototype._onApiRootMessage = function onApiRootMessage(_, message) {
156
154
  const messageType = message.properties.type;
157
155
 
158
156
  switch (messageType) {
@@ -167,7 +165,7 @@ proto._onApiRootMessage = function onApiRootMessage(_, message) {
167
165
  }
168
166
  };
169
167
 
170
- proto._upsertExecution = function upsertExecution(executeMessage) {
168
+ SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(executeMessage) {
171
169
  const content = executeMessage.content;
172
170
  const executionId = content.executionId;
173
171
 
@@ -188,14 +186,14 @@ proto._upsertExecution = function upsertExecution(executeMessage) {
188
186
  return execution;
189
187
  };
190
188
 
191
- proto._addListeners = function addListeners(processExecution, executionId) {
189
+ SubProcessBehaviour.prototype._addListeners = function addListeners(processExecution, executionId) {
192
190
  this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kMessageHandlers].onExecutionCompleted, {
193
191
  noAck: true,
194
192
  consumerTag: `_sub-process-execution-${executionId}`,
195
193
  });
196
194
  };
197
195
 
198
- proto._onExecutionCompleted = function onExecutionCompleted(_, message) {
196
+ SubProcessBehaviour.prototype._onExecutionCompleted = function onExecutionCompleted(_, message) {
199
197
  if (message.fields.redelivered && message.properties.persistent === false) return;
200
198
 
201
199
  const content = message.content;
@@ -207,9 +205,10 @@ proto._onExecutionCompleted = function onExecutionCompleted(_, message) {
207
205
  broker.cancel(message.fields.consumerTag);
208
206
  break;
209
207
  }
208
+ case 'cancel':
210
209
  case 'discard': {
211
210
  broker.cancel(message.fields.consumerTag);
212
- broker.publish('execution', 'execute.discard', cloneContent(content));
211
+ broker.publish('execution', 'execute.' + messageType, cloneContent(content));
213
212
  break;
214
213
  }
215
214
  case 'completed': {
@@ -228,7 +227,7 @@ proto._onExecutionCompleted = function onExecutionCompleted(_, message) {
228
227
  }
229
228
  };
230
229
 
231
- proto.getApi = function getApi(apiMessage) {
230
+ SubProcessBehaviour.prototype.getApi = function getApi(apiMessage) {
232
231
  const content = apiMessage.content;
233
232
 
234
233
  if (content.id === this.id) return;
@@ -244,6 +243,6 @@ proto.getApi = function getApi(apiMessage) {
244
243
  }
245
244
  };
246
245
 
247
- proto._getExecutionById = function getExecutionById(executionId) {
246
+ SubProcessBehaviour.prototype._getExecutionById = function getExecutionById(executionId) {
248
247
  return this[kExecutions].find((pe) => pe.executionId === executionId);
249
248
  };
package/src/tasks/Task.js CHANGED
@@ -1,5 +1,5 @@
1
- import Activity from '../activity/Activity';
2
- import {cloneContent} from '../messageHelper';
1
+ import Activity from '../activity/Activity.js';
2
+ import {cloneContent} from '../messageHelper.js';
3
3
 
4
4
  export default function Task(activityDef, context) {
5
5
  return new Activity(TaskBehaviour, activityDef, context);
@@ -1,4 +1,4 @@
1
- import SubProcess from './SubProcess';
1
+ import SubProcess from './SubProcess.js';
2
2
 
3
3
  export default function Transaction(activityDef, context) {
4
4
  const transaction = {type: 'transaction', ...activityDef, isTransaction: true};
@@ -0,0 +1,520 @@
1
+ declare module 'bpmn-elements' {
2
+ import { Broker } from 'smqp';
3
+ import { Consumer } from 'smqp/types/Queue';
4
+ import { MessageMessage } from 'smqp/types/Message';
5
+ import { SerializableContext, SerializableElement } from 'moddle-context-serializer';
6
+
7
+ interface ElementBroker<T> extends Broker {
8
+ get owner(): T;
9
+ }
10
+
11
+ type signalMessage = {
12
+ /**
13
+ * Optional signal id
14
+ * - Activity id
15
+ * - Signal-, Message-, Escalation id, etc
16
+ */
17
+ id?: string,
18
+ /**
19
+ * Optional execution id
20
+ * e.g. excutionId of a parallel multi instance user task
21
+ */
22
+ executionId?: string,
23
+ /** Any other input that will be added to completed activity output */
24
+ [x: string]: any,
25
+ }
26
+
27
+ type elementContent = {
28
+ id?: string,
29
+ type?: string,
30
+ executionId?: string,
31
+ parent?: ElementParent,
32
+ [x: string]: any,
33
+ }
34
+
35
+ interface ElementBrokerMessage extends MessageMessage {
36
+ content: elementContent,
37
+ }
38
+
39
+ interface EventDefinition {
40
+ get id(): string;
41
+ get type(): string;
42
+ get executionId(): string;
43
+ get isThrowing(): boolean;
44
+ get activity(): Activity;
45
+ get broker(): Broker;
46
+ get logger(): Logger;
47
+ get reference(): {
48
+ id?: string,
49
+ name: string,
50
+ referenceType: string,
51
+ };
52
+ [x: string]: any;
53
+ execute(executeMessage: ElementBrokerMessage): void;
54
+ }
55
+
56
+ abstract class ElementBase {
57
+ get id(): string;
58
+ get type(): string;
59
+ get name(): string;
60
+ get parent(): ElementParent;
61
+ get behaviour(): SerializableElement;
62
+ get broker(): Broker;
63
+ get environment(): Environment;
64
+ get context(): Context;
65
+ get logger(): Logger;
66
+ }
67
+
68
+ abstract class Element<T> extends ElementBase {
69
+ get broker(): ElementBroker<T>;
70
+ getState(): any;
71
+ stop(): void;
72
+ recover(state?: any): T;
73
+ resume(): void;
74
+ getApi(message?: ElementBrokerMessage): Api<T>;
75
+ on(eventName: string, callback: CallableFunction, options?: any): Consumer;
76
+ once(eventName: string, callback: CallableFunction, options?: any): Consumer;
77
+ waitFor(eventName: string, options?: any): Promise<Api<T>>;
78
+ }
79
+
80
+ interface ElementParent {
81
+ get id(): string;
82
+ get type(): string;
83
+ get executionId(): string;
84
+ get path(): ElementParent[];
85
+ }
86
+
87
+ type Extension = (activity: ElementBase, context: Context) => IExtension;
88
+ interface IExtension {
89
+ activate(message: ElementBrokerMessage): void;
90
+ deactivate(message: ElementBrokerMessage): void;
91
+ }
92
+
93
+ interface IExpressions {
94
+ resolveExpression(templatedString: string, context?: any, expressionFnContext?: any): any;
95
+ }
96
+
97
+ interface EnvironmentSettings {
98
+ /** true returns dummy service function for service task if not found */
99
+ enableDummyService?: boolean;
100
+ /** true makes activity runs to go forward in steps, defaults to false */
101
+ step?: boolean;
102
+ /** strict mode, see documentation, defaults to false */
103
+ strict?: boolean;
104
+ /** positive integer to control parallel loop batch size, defaults to 50 */
105
+ batchSize?: number;
106
+ [x: string]: any;
107
+ }
108
+
109
+ interface EnvironmentOptions {
110
+ settings?: EnvironmentSettings;
111
+ variables?: Record<string, any>;
112
+ services?: Record<string, CallableFunction>;
113
+ logger?: Logger;
114
+ timers?: ITimers;
115
+ scripts?: IScripts;
116
+ extensions?: Record<string, Extension>;
117
+ expressions?: IExpressions;
118
+ }
119
+
120
+ type startActivityFilterOptions = {
121
+ /** Event definition id, i.e. Message, Signal, Error, etc */
122
+ referenceId?: string,
123
+ /** Event definition type, i.e. message, signal, error, etc */
124
+ referenceType?: string
125
+ };
126
+
127
+ type filterPostponed = (elementApi: Api<ElementBase>) => boolean;
128
+
129
+ /**
130
+ * Activity status
131
+ * Can be used to decide when to save states, Timer and Wait is recommended.
132
+ */
133
+ const enum ActivityStatus {
134
+ /** Idle, not running anything */
135
+ Idle = 'idle',
136
+ /**
137
+ * At least one activity is executing,
138
+ * e.g. a service task making a asynchronous request
139
+ */
140
+ Executing = 'executing',
141
+ /**
142
+ * At least one activity is waiting for a timer to complete,
143
+ * usually only TimerEventDefinition's
144
+ */
145
+ Timer = 'timer',
146
+ /**
147
+ * At least one activity is waiting for a signal of some sort,
148
+ * e.g. user tasks, intermediate catch events, etc
149
+ */
150
+ Wait = 'wait',
151
+ }
152
+
153
+ interface DefinitionExecution {
154
+ get id(): string;
155
+ get type(): string;
156
+ get broker(): Broker;
157
+ get environment(): Environment;
158
+ get context(): Context;
159
+ get executionId(): string;
160
+ get stopped(): boolean;
161
+ get completed(): boolean;
162
+ get status(): boolean;
163
+ get processes(): Process[];
164
+ get postponedCount(): number;
165
+ get isRunning(): boolean;
166
+ get isRunning(): boolean;
167
+ get activityStatus(): ActivityStatus;
168
+ execute(executeMessage: ElementBrokerMessage): void;
169
+ getProcesses(): Process[];
170
+ getProcessById(processId: string): Process;
171
+ getProcessesById(processId: string): Process[];
172
+ getProcessByExecutionId(processExecutionId: string): Process;
173
+ getRunningProcesses(): Process[];
174
+ getExecutableProcesses(): Process[];
175
+ getPostponed(filterFn: filterPostponed): Api<ElementBase>[];
176
+ }
177
+
178
+ interface ActivityExecution {
179
+ get completed(): boolean;
180
+ get executionId(): string;
181
+ get source(): ActivityBehaviour;
182
+ execute(executeMessage: ElementBrokerMessage): void;
183
+ }
184
+
185
+ function ActivityBehaviour(activityDef: SerializableElement, context: Context): Activity;
186
+ interface ActivityBehaviour {
187
+ id: string;
188
+ type: string;
189
+ activity: Activity;
190
+ environment: Environment;
191
+ execute(executeMessage: ElementBrokerMessage): void;
192
+ }
193
+
194
+ interface Api<T> extends ElementBrokerMessage {
195
+ get id(): string;
196
+ get type(): string;
197
+ get name(): string;
198
+ get executionId(): string;
199
+ get environment(): Environment;
200
+ get broker(): ElementBroker<T>;
201
+ get owner(): T;
202
+ cancel(message?: signalMessage, options?: any): void;
203
+ discard(): void;
204
+ fail(error: Error): void;
205
+ signal(message?: signalMessage, options?: any): void;
206
+ stop(): void;
207
+ resolveExpression(expression: string): any;
208
+ sendApiMessage(action: string, content?: signalMessage, options?: any): void;
209
+ getPostponed(...args: any[]): any[];
210
+ createMessage(content?: Record<string, any>): any;
211
+ }
212
+
213
+ interface Script {
214
+ execute(executionContext: any, callback: CallableFunction): void;
215
+ }
216
+
217
+ abstract class MessageElement {
218
+ get id(): string;
219
+ get type(): string;
220
+ get name(): string;
221
+ get parent(): ElementParent;
222
+ resolve(executionMessage: ElementBrokerMessage): {
223
+ parent: ElementParent;
224
+ name: string;
225
+ id: string;
226
+ type: string;
227
+ messageType: string;
228
+ };
229
+ }
230
+
231
+ class Environment {
232
+ constructor(options?: EnvironmentOptions);
233
+ options: Record<string, any>;
234
+ expressions: IExpressions;
235
+ extensions: Record<string, IExtension>;
236
+ scripts: IScripts;
237
+ timers: ITimers;
238
+ Logger: Logger;
239
+ get settings(): EnvironmentSettings;
240
+ get variables(): Record<string, any>;
241
+ get output(): Record<string, any>;
242
+ set services(arg: any);
243
+ get services(): any;
244
+ getState(): any;
245
+ recover(state?: any): Environment;
246
+ clone(overrideOptions?: EnvironmentOptions): Environment;
247
+ assignVariables(newVars: Record<string, any>): void;
248
+ assignSettings(newSettings: Record<string, any>): void;
249
+ registerScript(activity: any): Script;
250
+ getScript(language: string, identifier: {id: string, [x: string]: any}): Script;
251
+ getServiceByName(serviceName: string): CallableFunction;
252
+ resolveExpression(expression: string, message?: ElementBrokerMessage, expressionFnContext?: any): any;
253
+ addService(name: string, fn: CallableFunction): void;
254
+ }
255
+
256
+ function Context(definitionContext: SerializableContext, environment?: Environment): Context;
257
+ class Context {
258
+ constructor(definitionContext: SerializableContext, environment?: Environment);
259
+ get id(): string;
260
+ get name(): string;
261
+ get type(): string;
262
+ /** Unique context instance id */
263
+ get sid(): string;
264
+ get definitionContext(): SerializableContext;
265
+ get environment(): Environment;
266
+ getActivityById<T>(activityId: string): T;
267
+ getSequenceFlowById(sequenceFlowId: string): SequenceFlow;
268
+ getInboundSequenceFlows(activityId: string): SequenceFlow[];
269
+ getOutboundSequenceFlows(activityId: string): SequenceFlow[];
270
+ getInboundAssociations(activityId: string): Association[];
271
+ getOutboundAssociations(activityId: string): Association[];
272
+ getActivities(scopeId?: string): ElementBase[];
273
+ getSequenceFlows(scopeId?: string): SequenceFlow[];
274
+ getAssociations(scopeId?: string): Association[];
275
+ clone(newEnvironment?: Environment): Context;
276
+ getProcessById(processId: string): Process;
277
+ getNewProcessById(processId: string): Process;
278
+ getProcesses(): Process[];
279
+ getExecutableProcesses(): Process[];
280
+ getMessageFlows(sourceId: string): MessageFlow[];
281
+ getDataObjectById(referenceId: string): any;
282
+ getDataStoreById(referenceId: string): any;
283
+ getStartActivities(filterOptions?: startActivityFilterOptions, scopeId?: string): Activity[];
284
+ loadExtensions(activity: ElementBase): IExtension;
285
+ }
286
+
287
+ type runCallback = (err: Error, definitionApi: Api<Definition>) => void;
288
+ class Definition extends Element<Definition> {
289
+ constructor(context: Context, options?: EnvironmentOptions);
290
+ get counters(): { completed: number, discarded: number };
291
+ get execution(): DefinitionExecution;
292
+ get executionId(): string;
293
+ get isRunning(): boolean;
294
+ get status(): string;
295
+ get stopped(): boolean;
296
+ get activityStatus(): ActivityStatus;
297
+ run(): Definition;
298
+ run(runContent: Record<string, any>): Definition;
299
+ run(runContent: Record<string, any>, callback: runCallback): Definition;
300
+ run(callback: runCallback): Definition;
301
+ shake(startId?: string): object;
302
+ getProcesses(): Process[];
303
+ /** get processes marked with isExecutable=true */
304
+ getExecutableProcesses(): Process[];
305
+ getRunningProcesses(): Process[];
306
+ getProcessById(processId: string): Process;
307
+ getActivityById(childId: string): Activity;
308
+ getElementById<T>(elementId: string): Element<T>;
309
+ getPostponed(filterFn?: filterPostponed): Api<ElementBase>[];
310
+ /** Send delegated signal message */
311
+ signal(message: any): void;
312
+ cancelActivity(message: any): void;
313
+ sendMessage(message: any): void;
314
+ }
315
+
316
+ class Process extends Element<Process> {
317
+ constructor(processDef: SerializableElement, context: Context);
318
+ get isExecutable(): boolean;
319
+ get counters(): { completed: number, discarded: number };
320
+ get extensions(): IExtension;
321
+ get stopped(): boolean;
322
+ get isRunning(): boolean;
323
+ get executionId(): string;
324
+ get execution(): ProcessExecution;
325
+ get status(): string;
326
+ get activityStatus(): ActivityStatus;
327
+ init(useAsExecutionId?: string): void;
328
+ run(runContent?: Record<string, any>): void;
329
+ shake(startId?: string): void;
330
+ signal(message: any): any;
331
+ cancelActivity(message: any): any;
332
+ sendMessage(message: any): void;
333
+ getActivityById<T>(childId: string): T;
334
+ getActivities(): Activity[];
335
+ getStartActivities(filterOptions?: startActivityFilterOptions): Activity[];
336
+ getSequenceFlows(): SequenceFlow[];
337
+ getPostponed(filterFn: filterPostponed): Api<ElementBase>[];
338
+ }
339
+
340
+ interface ProcessExecution {
341
+ get isSubProcess(): boolean;
342
+ get broker(): Broker;
343
+ get environment(): Environment;
344
+ get context(): Context;
345
+ get executionId(): string;
346
+ get stopped(): boolean;
347
+ get completed(): boolean;
348
+ get status(): string;
349
+ get postponedCount(): number;
350
+ get isRunning(): boolean;
351
+ get activityStatus(): ActivityStatus;
352
+ execute(executeMessage: ElementBrokerMessage): void;
353
+ getPostponed(filterFn: filterPostponed): Api<ElementBase>[];
354
+ getActivities(): Activity[];
355
+ getActivityById<T>(activityId: string): T;
356
+ getSequenceFlows(): SequenceFlow[];
357
+ getApi(message?: ElementBrokerMessage): Api<ElementBase>;
358
+ }
359
+
360
+ class SequenceFlow extends Element<SequenceFlow> {
361
+ get sourceId(): string;
362
+ get targetId(): string;
363
+ get isDefault(): boolean;
364
+ get isSequenceFlow(): boolean;
365
+ get counters(): {take: number, discard: number, looped: number};
366
+ take(content?: any): boolean;
367
+ discard(content?: any): void;
368
+ shake(message: any): number;
369
+ getCondition(): any;
370
+ createMessage(override?: any): object;
371
+ }
372
+
373
+ interface MessageFlowReference {
374
+ /** activity id */
375
+ get id(): string;
376
+ get processId(): string;
377
+ }
378
+ class MessageFlow extends Element<MessageFlow> {
379
+ get source(): MessageFlowReference;
380
+ get target(): MessageFlowReference;
381
+ get counters(): { messages: number };
382
+ activate(): void;
383
+ deactivate(): void;
384
+ }
385
+
386
+ class Association extends Element<Association> {
387
+ get sourceId(): string;
388
+ get targetId(): string;
389
+ get isAssociation(): boolean;
390
+ get counters(): {take: number, discard: number };
391
+ take(content?: any): boolean;
392
+ discard(content?: any): boolean;
393
+ }
394
+
395
+ interface Logger {
396
+ debug(...args: any[]): void;
397
+ error(...args: any[]): void;
398
+ warn(...args: any[]): void;
399
+ [x: string]: any,
400
+ }
401
+
402
+ type wrappedSetTimeout = (handler: CallableFunction, timeout: number, ...args: unknown[]) => any;
403
+ type wrappedClearTimeout = (id?: any) => void;
404
+
405
+ interface ITimers {
406
+ get executing(): any[];
407
+ get setTimeout(): wrappedSetTimeout;
408
+ get clearTimeout(): wrappedClearTimeout;
409
+ register(owner?: any): { setTimeout: wrappedSetTimeout, clearTimeout: wrappedClearTimeout };
410
+ [x: string]: any,
411
+ }
412
+
413
+ interface IScripts {
414
+ register(activity: any): Script;
415
+ getScript(language: string, identifier: {id: string, [x: string]: any}): Script;
416
+ }
417
+
418
+ interface Activity extends Element<Activity> {
419
+ get Behaviour(): ActivityBehaviour;
420
+ get stopped(): boolean;
421
+ get status(): string;
422
+ get counters(): { taken: number, discarded: number };
423
+ get execution(): ActivityExecution;
424
+ get executionId(): string;
425
+ get extensions(): IExtension;
426
+ get isRunning(): boolean;
427
+ get outbound(): SequenceFlow[];
428
+ get inbound(): SequenceFlow[];
429
+ get isEnd(): boolean;
430
+ get isStart(): boolean;
431
+ get isSubProcess(): boolean;
432
+ get isMultiInstance(): boolean;
433
+ get isThrowing(): boolean;
434
+ get isForCompensation(): boolean;
435
+ get triggeredByEvent(): boolean;
436
+ get attachedTo(): Activity;
437
+ get eventDefinitions(): EventDefinition[];
438
+ activate(): void;
439
+ deactivate(): void;
440
+ init(initContent?: any): void;
441
+ run(runContent?: any): void;
442
+ discard(discardContent?: any): void;
443
+ next(): ElementBrokerMessage;
444
+ shake(): void;
445
+ evaluateOutbound(fromMessage: ElementBrokerMessage, discardRestAtTake: boolean, callback: (err: Error, evaluationResult: any) => void): void;
446
+ }
447
+
448
+ var BoundaryEvent: typeof ActivityBehaviour;
449
+ var CallActivity: typeof ActivityBehaviour;
450
+ var Dummy: typeof ActivityBehaviour;
451
+ var TextAnnotation: typeof Dummy;
452
+ var Group: typeof Dummy;
453
+ var Category: typeof Dummy;
454
+ var EndEvent: typeof ActivityBehaviour;
455
+ var EventBasedGateway: typeof ActivityBehaviour;
456
+ var ExclusiveGateway: typeof ActivityBehaviour;
457
+ var InclusiveGateway: typeof ActivityBehaviour;
458
+ var IntermediateCatchEvent: typeof ActivityBehaviour;
459
+ var IntermediateThrowEvent: typeof ActivityBehaviour;
460
+ var ParallelGateway: typeof ActivityBehaviour;
461
+ var ReceiveTask: typeof ActivityBehaviour;
462
+ var ScriptTask: typeof ActivityBehaviour;
463
+ var ServiceTask: typeof ActivityBehaviour;
464
+ var SendTask: typeof ServiceTask;
465
+ var BusinessRuleTask: typeof ServiceTask;
466
+ var SignalTask: typeof ActivityBehaviour;
467
+ var ManualTask: typeof SignalTask;
468
+ var UserTask: typeof SignalTask;
469
+ var StartEvent: typeof ActivityBehaviour;
470
+ var SubProcess: typeof ActivityBehaviour;
471
+ var Task: typeof ActivityBehaviour;
472
+ var Transaction: typeof ActivityBehaviour;
473
+
474
+ var CancelEventDefinition: EventDefinition;
475
+ var CompensateEventDefinition: EventDefinition;
476
+ var ConditionalEventDefinition: EventDefinition;
477
+ var ErrorEventDefinition: EventDefinition;
478
+ var EscalationEventDefinition: EventDefinition;
479
+ var LinkEventDefinition: EventDefinition;
480
+ var MessageEventDefinition: EventDefinition;
481
+ var SignalEventDefinition: EventDefinition;
482
+ var TerminateEventDefinition: EventDefinition;
483
+ var TimerEventDefinition: EventDefinition;
484
+
485
+ class BpmnError {
486
+ get id(): string;
487
+ get type(): string;
488
+ get name(): string;
489
+ get errorCode(): string;
490
+ resolve(executionMessage: ElementBrokerMessage, error: any): {
491
+ id: string;
492
+ type: string;
493
+ messageType: string;
494
+ name: string;
495
+ code: string;
496
+ inner?: any
497
+ };
498
+ }
499
+
500
+ class ServiceImplementation {
501
+ constructor(activity: Activity);
502
+ get type(): string;
503
+ get implementation(): string;
504
+ get activity(): Activity;
505
+ execute(executionMessage: ElementBrokerMessage, callback: CallableFunction): void;
506
+ }
507
+
508
+ class Message extends MessageElement {}
509
+ class Signal extends MessageElement {}
510
+ class Escalation extends MessageElement {}
511
+
512
+ interface ActivityError extends Error {
513
+ type: string;
514
+ description: string;
515
+ /** Activity that threw error */
516
+ source?: ElementBrokerMessage;
517
+ /** Original error */
518
+ inner?: Error;
519
+ }
520
+ }