Skip to content

Commit 9daa848

Browse files
committed
feat!: provide variables used in feel expressions
Related to camunda/camunda-modeler#5639 BREAKING CHANGE: getVariables now also returns variables without scope. I.e.: scope is now optional in ProcessVariables
1 parent 28caa87 commit 9daa848

19 files changed

+4611
-61
lines changed

README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
[![CI](https://github.com/bpmn-io/variable-resolver/actions/workflows/CI.yml/badge.svg)](https://github.com/bpmn-io/variable-resolver/actions/workflows/CI.yml)
44

5-
A bpmn-js extension to add and manage additional variable extractors in bpmn diagrams.
5+
An extension for [bpmn-js](https://github.com/bpmn-io/bpmn-js) that makes the data model of the diagram available to other components.
6+
7+
> [!NOTE]
8+
> As of version `v3` this library exposes both written and consumed variables, you can filter them via options.
69
710
## Usage
811

@@ -30,19 +33,56 @@ const modeler = new BpmnModeler({
3033

3134
### Retrieving variables
3235

33-
To retrieve the variables from a diagram, use one of the following methods of the `variableResolver` service:
36+
Retrieve the variables from a diagram using the `variableResolver` service:
3437

3538
```javascript
36-
const elementRegistry = modeler.get('elementRegistry');
3739
const variableResolver = modeler.get('variableResolver');
40+
const elementRegistry = modeler.get('elementRegistry');
3841

42+
// retrieve variables relevant to an element
3943
const task = elementRegistry.get('Task_1');
40-
const process = elementRegistry.get('Process_1');
4144

42-
await variableResolver.getVariablesForElement(task); // returns variables in the scope of the element
43-
await variableResolver.getProcessVariables(process); // returns all variables for the process, not filtering by scope
45+
// default: variables relevant to <task> in its visible scopes
46+
await variableResolver.getVariablesForElement(task);
47+
48+
// variables read by <task> only
49+
await variableResolver.getVariablesForElement(task, {
50+
read: true,
51+
written: false
52+
});
53+
54+
// all variables written by <task>
55+
await variableResolver.getVariablesForElement(task, { written: true, read: false });
56+
57+
// local variables only (scope === queried element)
58+
await variableResolver.getVariablesForElement(task, {
59+
local: true,
60+
external: false
61+
});
62+
63+
// non-local variables only (scope !== queried element)
64+
await variableResolver.getVariablesForElement(task, {
65+
local: false,
66+
external: true
67+
});
68+
69+
// retrieve all variables defined in a process
70+
const processElement = elementRegistry.get('Process_1');
71+
72+
// returns all variables for the process (unfiltered), for local processing
73+
await variableResolver.getProcessVariables(processElement);
4474
```
4575

76+
`getVariablesForElement(element, options)` supports five filter switches:
77+
78+
| Option | Default | Description |
79+
| --- | --- | --- |
80+
| `read` | `true` | Include variables consumed by the queried element |
81+
| `written` | `true` | Include variables written/created by the queried element |
82+
| `local` | `true` | Include variables local to the queried element scope |
83+
| `external` | `true` | Include variables outside the queried element scope |
84+
| `outputMappings` | `true` | Count output-mapping reads as reads |
85+
4686
### Adding a variable extractor
4787

4888
To add your own variables, extend the `variableProvider` class in your extension. It only needs to implement the `getVariables` method, which takes an element as an argument and returns an array of variables you want to add to the scope of the element. The function can be asynchronous.
@@ -76,11 +116,9 @@ export const MyExtension = {
76116

77117
### Advanced use-cases
78118

79-
By default, `getVariablesForElement` and `getProcessVariables` will attempt to merge variables with the same name and scope into
80-
one. Entry structure and types are then mixed.
119+
By default, `getVariablesForElement` and `getProcessVariables` merge variables with the same name and scope into one - entry structure and types are mixed in the merged representation.
81120

82-
In some cases, you might want access to the raw data, e.g. to run lint rules to detect potential schema mismatches between providers.
83-
For this, you can use
121+
In some cases, you might want access to the raw data, e.g. to run lint rules to detect potential schema mismatches between providers. For this, you can use `getRawVariables`:
84122

85123
```javascript
86124
const variableResolver = modeler.get('variableResolver');

0 commit comments

Comments
 (0)