bpmn-elements 13.0.0 → 13.1.1

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 CHANGED
@@ -1,6 +1,18 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ # 13.1.1
5
+
6
+ - found the real reason for massive state size - `activity.leave` messages where not acked by process execution. Doh!
7
+
8
+ # 13.1.0
9
+
10
+ - introduce `disableTrackState` setting. Tracking of elements is done by counters, e.g. activity taken or discarded, sequence flow taken and discarded. Counters are saved when getting state. If you run really big flows the state will keep all elements just to be able to recover the number of times an element has been touched. Needless to say it the state will grow out of it's comfort zone. Setting `disableTrackState` to true will only return state for elements that are actually running
11
+
12
+ ## Breaking
13
+
14
+ - `getState()` can return undefined
15
+
4
16
  # 13.0.0
5
17
 
6
18
  - export task-, events-, and gateway activity behaviors through `bpmn-elements/tasks`, `bpmn-elements/events`, and `bpmn-elements/gateways` respectively
@@ -279,6 +279,8 @@ Activity.prototype.run = function run(runContent) {
279
279
  Activity.prototype.getState = function getState() {
280
280
  const status = this.status;
281
281
  const exec = this[kExec];
282
+ const brokerState = this.broker.getState(true);
283
+ if (!brokerState && this.environment.settings.disableTrackState) return;
282
284
  return {
283
285
  id: this.id,
284
286
  type: this.type,
@@ -288,7 +290,7 @@ Activity.prototype.getState = function getState() {
288
290
  executionId: exec.executionId,
289
291
  stopped: this.stopped,
290
292
  counters: this.counters,
291
- broker: this.broker.getState(true),
293
+ broker: brokerState,
292
294
  execution: exec.execution && exec.execution.getState()
293
295
  };
294
296
  };
@@ -71,11 +71,13 @@ Association.prototype.discard = function discard(content = {}) {
71
71
  return true;
72
72
  };
73
73
  Association.prototype.getState = function getState() {
74
+ const brokerState = this.broker.getState(true);
75
+ if (!brokerState && this.environment.settings.disableTrackState) return;
74
76
  return {
75
77
  id: this.id,
76
78
  type: this.type,
77
79
  counters: this.counters,
78
- broker: this.broker.getState(true)
80
+ broker: brokerState
79
81
  };
80
82
  };
81
83
  Association.prototype.recover = function recover(state) {
@@ -55,11 +55,13 @@ Object.defineProperty(MessageFlow.prototype, 'counters', {
55
55
  }
56
56
  });
57
57
  MessageFlow.prototype.getState = function getState() {
58
+ const brokerState = this.broker.getState(true);
59
+ if (!brokerState && this.environment.settings.disableTrackState) return;
58
60
  return {
59
61
  id: this.id,
60
62
  type: this.type,
61
63
  counters: this.counters,
62
- broker: this.broker.getState(true)
64
+ broker: brokerState
63
65
  };
64
66
  };
65
67
  MessageFlow.prototype.recover = function recover(state) {
@@ -92,11 +92,13 @@ SequenceFlow.prototype.discard = function discard(content = {}) {
92
92
  this._publishEvent('discard', content);
93
93
  };
94
94
  SequenceFlow.prototype.getState = function getState() {
95
+ const brokerState = this.broker.getState(true);
96
+ if (!brokerState && this.environment.settings.disableTrackState) return;
95
97
  return {
96
98
  id: this.id,
97
99
  type: this.type,
98
100
  counters: this.counters,
99
- broker: this.broker.getState(true)
101
+ broker: brokerState
100
102
  };
101
103
  };
102
104
  SequenceFlow.prototype.recover = function recover(state) {
@@ -162,6 +162,11 @@ ProcessExecution.prototype.getState = function getState() {
162
162
  outboundMessageFlows,
163
163
  associations
164
164
  } = this[kElements];
165
+ const flowStates = flows.reduce((result, flow) => {
166
+ const elmState = flow.getState();
167
+ if (elmState) result.push(elmState);
168
+ return result;
169
+ }, []);
165
170
  return {
166
171
  executionId: this.executionId,
167
172
  stopped: this[kStopped],
@@ -169,17 +174,18 @@ ProcessExecution.prototype.getState = function getState() {
169
174
  status: this.status,
170
175
  children: children.reduce((result, activity) => {
171
176
  if (activity.placeholder) return result;
172
- result.push(activity.getState());
177
+ const elmState = activity.getState();
178
+ if (elmState) result.push(elmState);
173
179
  return result;
174
180
  }, []),
175
181
  ...(flows.length && {
176
- flows: flows.map(f => f.getState())
182
+ flows: flowStates
177
183
  }),
178
184
  ...(outboundMessageFlows.length && {
179
- messageFlows: outboundMessageFlows.length && outboundMessageFlows.map(f => f.getState())
185
+ messageFlows: outboundMessageFlows.length && outboundMessageFlows.map(f => f.getState()).filter(Boolean)
180
186
  }),
181
187
  ...(associations.length && {
182
- associations: associations.map(f => f.getState())
188
+ associations: associations.map(f => f.getState()).filter(Boolean)
183
189
  })
184
190
  };
185
191
  };
@@ -635,6 +641,7 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
635
641
  message.ack();
636
642
  return this._complete('completed');
637
643
  }
644
+ message.ack();
638
645
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map(a => a.content.id).join(',')}`);
639
646
  if (postponedCount && postponedCount === detachedActivities.length) {
640
647
  return this[kActivityQ].queueMessage({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-elements",
3
- "version": "13.0.0",
3
+ "version": "13.1.1",
4
4
  "description": "Executable workflow elements based on BPMN 2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -69,7 +69,7 @@
69
69
  "@babel/preset-env": "^7.23.9",
70
70
  "@babel/register": "^7.23.7",
71
71
  "@bonniernews/hot-bev": "^0.4.0",
72
- "@types/node": "^16.18.79",
72
+ "@types/node": "^16.18.80",
73
73
  "bpmn-moddle": "^8.1.0",
74
74
  "c8": "^9.1.0",
75
75
  "camunda-bpmn-moddle": "^7.0.1",
@@ -78,13 +78,13 @@
78
78
  "debug": "^4.3.4",
79
79
  "eslint": "^8.56.0",
80
80
  "eslint-plugin-import": "^2.29.1",
81
- "got": "^14.1.0",
82
- "mocha": "^10.1.0",
81
+ "got": "^14.2.0",
82
+ "mocha": "^10.3.0",
83
83
  "mocha-cakes-2": "^3.3.0",
84
- "moddle-context-serializer": "^4.0.0",
84
+ "moddle-context-serializer": "^4.1.2",
85
85
  "nock": "^13.5.1"
86
86
  },
87
87
  "dependencies": {
88
- "smqp": "^8.0.0"
88
+ "smqp": "^8.2.2"
89
89
  }
90
90
  }
@@ -269,6 +269,9 @@ Activity.prototype.run = function run(runContent) {
269
269
  Activity.prototype.getState = function getState() {
270
270
  const status = this.status;
271
271
  const exec = this[kExec];
272
+ const brokerState = this.broker.getState(true);
273
+ if (!brokerState && this.environment.settings.disableTrackState) return;
274
+
272
275
  return {
273
276
  id: this.id,
274
277
  type: this.type,
@@ -276,7 +279,7 @@ Activity.prototype.getState = function getState() {
276
279
  executionId: exec.executionId,
277
280
  stopped: this.stopped,
278
281
  counters: this.counters,
279
- broker: this.broker.getState(true),
282
+ broker: brokerState,
280
283
  execution: exec.execution && exec.execution.getState(),
281
284
  };
282
285
  };
@@ -58,11 +58,14 @@ Association.prototype.discard = function discard(content = {}) {
58
58
  };
59
59
 
60
60
  Association.prototype.getState = function getState() {
61
+ const brokerState = this.broker.getState(true);
62
+ if (!brokerState && this.environment.settings.disableTrackState) return;
63
+
61
64
  return {
62
65
  id: this.id,
63
66
  type: this.type,
64
67
  counters: this.counters,
65
- broker: this.broker.getState(true),
68
+ broker: brokerState,
66
69
  };
67
70
  };
68
71
 
@@ -41,11 +41,14 @@ Object.defineProperty(MessageFlow.prototype, 'counters', {
41
41
  });
42
42
 
43
43
  MessageFlow.prototype.getState = function getState() {
44
+ const brokerState = this.broker.getState(true);
45
+ if (!brokerState && this.environment.settings.disableTrackState) return;
46
+
44
47
  return {
45
48
  id: this.id,
46
49
  type: this.type,
47
50
  counters: this.counters,
48
- broker: this.broker.getState(true),
51
+ broker: brokerState,
49
52
  };
50
53
  };
51
54
 
@@ -74,11 +74,14 @@ SequenceFlow.prototype.discard = function discard(content = {}) {
74
74
  };
75
75
 
76
76
  SequenceFlow.prototype.getState = function getState() {
77
+ const brokerState = this.broker.getState(true);
78
+ if (!brokerState && this.environment.settings.disableTrackState) return;
79
+
77
80
  return {
78
81
  id: this.id,
79
82
  type: this.type,
80
83
  counters: this.counters,
81
- broker: this.broker.getState(true),
84
+ broker: brokerState,
82
85
  };
83
86
  };
84
87
 
@@ -165,6 +165,13 @@ ProcessExecution.prototype.resume = function resume() {
165
165
 
166
166
  ProcessExecution.prototype.getState = function getState() {
167
167
  const {children, flows, outboundMessageFlows, associations} = this[kElements];
168
+
169
+ const flowStates = flows.reduce((result, flow) => {
170
+ const elmState = flow.getState();
171
+ if (elmState) result.push(elmState);
172
+ return result;
173
+ }, []);
174
+
168
175
  return {
169
176
  executionId: this.executionId,
170
177
  stopped: this[kStopped],
@@ -172,12 +179,13 @@ ProcessExecution.prototype.getState = function getState() {
172
179
  status: this.status,
173
180
  children: children.reduce((result, activity) => {
174
181
  if (activity.placeholder) return result;
175
- result.push(activity.getState());
182
+ const elmState = activity.getState();
183
+ if (elmState) result.push(elmState);
176
184
  return result;
177
185
  }, []),
178
- ...(flows.length && {flows: flows.map((f) => f.getState())}),
179
- ...(outboundMessageFlows.length && {messageFlows: outboundMessageFlows.length && outboundMessageFlows.map((f) => f.getState())}),
180
- ...(associations.length && {associations: associations.map((f) => f.getState())}),
186
+ ...(flows.length && { flows: flowStates }),
187
+ ...(outboundMessageFlows.length && { messageFlows: outboundMessageFlows.length && outboundMessageFlows.map((f) => f.getState()).filter(Boolean) }),
188
+ ...(associations.length && { associations: associations.map((f) => f.getState()).filter(Boolean) }),
181
189
  };
182
190
  };
183
191
 
@@ -627,6 +635,7 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
627
635
  return this._complete('completed');
628
636
  }
629
637
 
638
+ message.ack();
630
639
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map((a) => a.content.id).join(',')}`);
631
640
 
632
641
  if (postponedCount && postponedCount === detachedActivities.length) {
package/types/types.d.ts CHANGED
@@ -96,12 +96,18 @@ declare interface IExpressions {
96
96
  declare interface EnvironmentSettings {
97
97
  /** true returns dummy service function for service task if not found */
98
98
  enableDummyService?: boolean;
99
- /** true makes activity runs to go forward in steps, defaults to false */
99
+ /** true forces activity runs to go forward in steps, defaults to false */
100
100
  step?: boolean;
101
101
  /** strict mode, see documentation, defaults to false */
102
102
  strict?: boolean;
103
103
  /** positive integer to control parallel loop batch size, defaults to 50 */
104
104
  batchSize?: number;
105
+ /**
106
+ * disable tracking state between recover and resume
107
+ * true will only return state for elements that are actually running
108
+ * Defaults to falsy
109
+ */
110
+ disableTrackState?: boolean;
105
111
  [x: string]: any;
106
112
  }
107
113
 
@@ -229,7 +235,7 @@ declare interface IActivityBehaviour {
229
235
  type: string;
230
236
  activity: Activity;
231
237
  environment: Environment;
232
- new(acttivity: Activity, context: ContextInstance): IActivityBehaviour
238
+ new(activity: Activity, context: ContextInstance): IActivityBehaviour
233
239
  execute(executeMessage: ElementBrokerMessage): void;
234
240
  }
235
241
 
@@ -530,6 +536,7 @@ declare interface ISequenceFlowCondition {
530
536
  }
531
537
 
532
538
  declare class SequenceFlow extends Element<SequenceFlow> {
539
+ constructor(flowDef: SerializableElement, context: ContextInstance)
533
540
  get sourceId(): string;
534
541
  get targetId(): string;
535
542
  get isDefault(): boolean;
@@ -547,6 +554,7 @@ declare class SequenceFlow extends Element<SequenceFlow> {
547
554
  * @param {evaluateCallback} callback Callback with evaluation result, if truthy flow should be taken
548
555
  */
549
556
  evaluate(fromMessage: ElementBrokerMessage, callback: (err: Error, result: any) => void): void;
557
+ getState(): SequenceFlowState | undefined;
550
558
  }
551
559
 
552
560
  declare interface MessageFlowReference {
@@ -556,20 +564,24 @@ declare interface MessageFlowReference {
556
564
  }
557
565
 
558
566
  declare class MessageFlow extends Element<MessageFlow> {
567
+ constructor(flowDef: SerializableElement, context: ContextInstance)
559
568
  get source(): MessageFlowReference;
560
569
  get target(): MessageFlowReference;
561
570
  get counters(): { messages: number };
562
571
  activate(): void;
563
572
  deactivate(): void;
573
+ getState(): MessageFlowState | undefined;
564
574
  }
565
575
 
566
576
  declare class Association extends Element<Association> {
577
+ constructor(associationDef: SerializableElement, context: ContextInstance)
567
578
  get sourceId(): string;
568
579
  get targetId(): string;
569
580
  get isAssociation(): boolean;
570
581
  get counters(): {take: number, discard: number };
571
582
  take(content?: any): boolean;
572
583
  discard(content?: any): boolean;
584
+ getState(): AssociationState | undefined;
573
585
  }
574
586
 
575
587
  declare type LoggerFactory = (scope: string) => ILogger;
@@ -635,10 +647,12 @@ declare interface IScripts {
635
647
  getScript(language: string, identifier: {id: string, [x: string]: any}): Script;
636
648
  }
637
649
 
638
- declare interface Activity extends Element<Activity> {
650
+ declare class Activity extends Element<Activity> {
651
+ constructor(behaviour: IActivityBehaviour, activityDef: SerializableElement, context: ContextInstance)
639
652
  get Behaviour(): IActivityBehaviour;
640
653
  get stopped(): boolean;
641
654
  get status(): ActivityRunStatus | undefined;
655
+ get context(): ContextInstance;
642
656
  get counters(): { taken: number, discarded: number };
643
657
  get execution(): ActivityExecution;
644
658
  get executionId(): string;
@@ -665,6 +679,7 @@ declare interface Activity extends Element<Activity> {
665
679
  next(): ElementBrokerMessage;
666
680
  shake(): void;
667
681
  evaluateOutbound(fromMessage: ElementBrokerMessage, discardRestAtTake: boolean, callback: (err: Error, evaluationResult: any) => void): void;
682
+ getState(): ActivityState | undefined;
668
683
  }
669
684
 
670
685
  declare class ActivityError extends Error {