@onify/flow-extensions 10.0.0 → 10.0.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/README.md CHANGED
@@ -7,6 +7,42 @@
7
7
  - `extensions`: Flow extensions
8
8
  - `extendFn`: extend function to pass to [serializer](https://github.com/paed01/moddle-context-serializer/blob/master/API.md)
9
9
 
10
+ ## `extensions(element, context)`
11
+
12
+ Pass to the engine as `extensions: { onify: extensions }`. Returns an extension for elements with camunda extension data (`camunda:inputOutput`, properties, form data, execution listeners, connector, expression, or result variable).
13
+
14
+ For elements without any such data it returns `undefined`, so bpmn-elements runs them without this extension. Combined with bpmn-elements `settings.assignOutput` (`'auto'` or `'id'`, >= 18.0.22) the engine then attaches its built-in output extension, e.g. a plain user task's signal payload is assigned to `environment.output`:
15
+
16
+ ```javascript
17
+ import { EventEmitter } from 'node:events';
18
+ import { Engine } from 'bpmn-engine';
19
+ import { extensions } from '@onify/flow-extensions';
20
+
21
+ const source = `
22
+ <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
23
+ <process id="theProcess" isExecutable="true">
24
+ <startEvent id="start" />
25
+ <sequenceFlow id="to-task" sourceRef="start" targetRef="task" />
26
+ <userTask id="task" />
27
+ </process>
28
+ </definitions>`;
29
+
30
+ const listener = new EventEmitter();
31
+ listener.once('wait', (task) => task.signal({ plain: 1 }));
32
+
33
+ const engine = new Engine({
34
+ source,
35
+ listener,
36
+ settings: { assignOutput: 'auto' },
37
+ extensions: { onify: extensions },
38
+ });
39
+
40
+ engine.execute((err, instance) => {
41
+ if (err) throw err;
42
+ console.log(instance.environment.output); // { plain: 1 }
43
+ });
44
+ ```
45
+
10
46
  # Examples
11
47
 
12
48
  ## Bpmn engine example
@@ -28,6 +28,13 @@ class OnifyElementExtensions {
28
28
  this._formatOnEnter = Boolean(format?.hasFormatting || properties || form || io?.input.length || io?.output.length);
29
29
  this._formatOnEnd = Boolean(properties || io?.output.length || format?.resultVariable);
30
30
  }
31
+ /**
32
+ * No camunda extension data to act on — the element runs without this extension
33
+ * @returns {boolean}
34
+ */
35
+ get isEmpty() {
36
+ return !this._formatOnEnter && !this._formatOnEnd && !this.extensions.listeners && !this.extensions.Service;
37
+ }
31
38
  activate(message) {
32
39
  const activity = this.activity;
33
40
  const executionListeners = this.extensions.listeners;
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ var _OnifyTimerEventDefinition = require("./OnifyTimerEventDefinition.js");
27
27
  * Onify flow extensions factory, pass to the engine as `extensions: { onify: extensions }`
28
28
  * @param {import('bpmn-elements').ElementBase} element
29
29
  * @param {import('bpmn-elements').ContextInstance} context
30
- * @returns {import('bpmn-elements').IExtension}
30
+ * @returns {import('bpmn-elements').IExtension | undefined} undefined for an element without camunda extension data, letting bpmn-elements skip it (and e.g. attach its built-in `assignOutput` extension)
31
31
  */
32
32
  function extensions(element, context) {
33
33
  switch (element.type) {
@@ -40,7 +40,11 @@ function extensions(element, context) {
40
40
  case 'bpmn:BoundaryEvent':
41
41
  return new _OnifyBoundaryEventExtensions.OnifyBoundaryEventExtensions(element, context);
42
42
  default:
43
- return new _OnifyElementExtensions.OnifyElementExtensions(element, context);
43
+ {
44
+ const elementExtensions = new _OnifyElementExtensions.OnifyElementExtensions(element, context);
45
+ if (elementExtensions.isEmpty) return undefined;
46
+ return elementExtensions;
47
+ }
44
48
  }
45
49
  }
46
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onify/flow-extensions",
3
- "version": "10.0.0",
3
+ "version": "10.0.1",
4
4
  "description": "Onify Flow extensions",
5
5
  "type": "module",
6
6
  "module": "src/index.js",
@@ -53,7 +53,7 @@
53
53
  "@babel/register": "^7.23.7",
54
54
  "@eslint/js": "^10.0.1",
55
55
  "@types/node": "^26.2.0",
56
- "bpmn-elements": "^18.0.1",
56
+ "bpmn-elements": "^18.0.22",
57
57
  "bpmn-elements-17": "npm:bpmn-elements@^17",
58
58
  "bpmn-elements-8-1": "npm:bpmn-elements@8.1",
59
59
  "bpmn-engine": "^26.0.0",
@@ -19,6 +19,13 @@ export class OnifyElementExtensions {
19
19
  this._formatOnEnter = Boolean(format?.hasFormatting || properties || form || io?.input.length || io?.output.length);
20
20
  this._formatOnEnd = Boolean(properties || io?.output.length || format?.resultVariable);
21
21
  }
22
+ /**
23
+ * No camunda extension data to act on — the element runs without this extension
24
+ * @returns {boolean}
25
+ */
26
+ get isEmpty() {
27
+ return !this._formatOnEnter && !this._formatOnEnd && !this.extensions.listeners && !this.extensions.Service;
28
+ }
22
29
  activate(message) {
23
30
  const activity = this.activity;
24
31
  const executionListeners = this.extensions.listeners;
package/src/index.js CHANGED
@@ -10,7 +10,7 @@ export { OnifyTimerEventDefinition } from './OnifyTimerEventDefinition.js';
10
10
  * Onify flow extensions factory, pass to the engine as `extensions: { onify: extensions }`
11
11
  * @param {import('bpmn-elements').ElementBase} element
12
12
  * @param {import('bpmn-elements').ContextInstance} context
13
- * @returns {import('bpmn-elements').IExtension}
13
+ * @returns {import('bpmn-elements').IExtension | undefined} undefined for an element without camunda extension data, letting bpmn-elements skip it (and e.g. attach its built-in `assignOutput` extension)
14
14
  */
15
15
  export function extensions(element, context) {
16
16
  switch (element.type) {
@@ -22,8 +22,11 @@ export function extensions(element, context) {
22
22
  return new OnifySubProcessExtensions(element, context);
23
23
  case 'bpmn:BoundaryEvent':
24
24
  return new OnifyBoundaryEventExtensions(element, context);
25
- default:
26
- return new OnifyElementExtensions(element, context);
25
+ default: {
26
+ const elementExtensions = new OnifyElementExtensions(element, context);
27
+ if (elementExtensions.isEmpty) return undefined;
28
+ return elementExtensions;
29
+ }
27
30
  }
28
31
  }
29
32
 
package/types/index.d.ts CHANGED
@@ -2,8 +2,9 @@ declare module '@onify/flow-extensions' {
2
2
  import type { SequenceFlow, TimerEventDefinition } from 'bpmn-elements';
3
3
  /**
4
4
  * Onify flow extensions factory, pass to the engine as `extensions: { onify: extensions }`
5
- * */
6
- export function extensions(element: import("bpmn-elements").ElementBase, context: import("bpmn-elements").ContextInstance): import("bpmn-elements").IExtension;
5
+ * @returns undefined for an element without camunda extension data, letting bpmn-elements skip it (and e.g. attach its built-in `assignOutput` extension)
6
+ */
7
+ export function extensions(element: import("bpmn-elements").ElementBase, context: import("bpmn-elements").ContextInstance): import("bpmn-elements").IExtension | undefined;
7
8
  /**
8
9
  * Extend function for moddle-context-serializer, registers scripts and timers at serialize time
9
10
  * */
@@ -47,6 +47,6 @@
47
47
  null,
48
48
  null
49
49
  ],
50
- "mappings": ";;;;;iBAcgBA,UAAUA;;;;iBAoBVC,QAAQA;cC/BXC,iBAAiBA;;;;cCAjBC,yBAAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OCHzBC,cAAcA;;;;;;;;;;OAqDdC,aAAaA;;;;;;;;OCrDbC,MAAMA;;;;;;;;;;;;;OAoHNC,WAAWA;;;;;;;;;;;;;;;;;;OCpHXC,YAAYA;;;;;;;;;OCEZC,MAAMA;;;;;;;OCuHNC,kBAAkBA;;;;;;;;;;;;;;OAzDzBC,cAAcA;;;;;;;;;;;;;;;OAkDdC,kBAAkBA;;;;;OAlHlBC,QAAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCwEEC,WAAWA;cAAXA,WAAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+DXC,UAAUA;;;;cAAVA,UAAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6DVC,kBAAkBA;;;;cAAlBA,kBAAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA7LrBC,eAAeA;;;;cAuBfC,eAAeA;;;;cAuBfC,iBAAiBA;;;;;;OAhDxBC,UAAUA;OADVC,YAAYA",
50
+ "mappings": ";;;;;;iBAcgBA,UAAUA;;;;iBAuBVC,QAAQA;cClCXC,iBAAiBA;;;;cCAjBC,yBAAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OCHz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