@jylups/flowable-bpmn-moddle 0.0.0 → 0.1.0-next.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 CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  Flowable moddle extensions for BPMN 2.0.
4
4
 
5
- > Work in progress. This package is being built in Phase 1 of the Flowable BPMN editor ([jylups/bpmn-js-env#7](https://github.com/jylups/bpmn-js-env/issues/7)). It is not published yet.
5
+ > Prerelease. Built in Phase 1 of the Flowable BPMN editor ([jylups/bpmn-js-env#7](https://github.com/jylups/bpmn-js-env/issues/7)).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @jylups/flowable-bpmn-moddle@next
11
+ ```
6
12
 
7
13
  ## Usage
8
14
 
@@ -20,7 +26,53 @@ const modeler = new BpmnModeler({
20
26
 
21
27
  The descriptor is also available as `@jylups/flowable-bpmn-moddle/resources/flowable.json`.
22
28
 
23
- The extensions it covers are listed in [docs/flowable-bpmn-extensions.md](https://github.com/jylups/bpmn-js-env/blob/main/docs/flowable-bpmn-extensions.md).
29
+ ## Activiti namespace
30
+
31
+ Flowable also reads its extensions in the Activiti namespace (`http://activiti.org/bpmn`). The descriptor registers only the Flowable namespace, so import such models through the migration helpers to get typed content that is written back as `flowable:`:
32
+
33
+ ```js
34
+ import { migrateActivitiXML, useFlowablePrefix } from '@jylups/flowable-bpmn-moddle';
35
+
36
+ const { rootElement } = await moddle.fromXML(migrateActivitiXML(xml), 'bpmn:Definitions');
37
+
38
+ // ... edit ...
39
+
40
+ const { xml: saved } = await moddle.toXML(useFlowablePrefix(rootElement));
41
+ ```
42
+
43
+ `migrateActivitiXML` only rewrites `xmlns` declarations. It also fixes models that bind the `flowable` prefix to the Activiti namespace, which otherwise fail to export.
44
+
45
+ Attributes Flowable reads without a namespace (listener, field, in/out and similar sub-attributes, the sequence flow `skipExpression`) are read whether or not they carry a prefix.
46
+
47
+ ## Covered extensions
48
+
49
+ | Area | Extensions |
50
+ |---|---|
51
+ | Flow nodes | `async`, `exclusive`, `asyncLeave`, `asyncLeaveExclusive` (`flowable:AsyncCapable`) |
52
+ | Extension elements | `failedJobRetryTimeCycle`, `element-name`, `jobCategory`, `includeInHistory`, `localization` with `documentation` |
53
+ | Listeners | `executionListener`, `taskListener` (shared `flowable:Listener`), `eventListener` |
54
+ | Process | `candidateStarterUsers`, `candidateStarterGroups`, `isEagerExecutionFetching`, `potentialStarter`, `historyLevel` |
55
+ | Start event | `initiator`, `formKey`, `formFieldValidation`, `sameDeployment` (`flowable:FormSupported`), `formProperty` with `value` |
56
+ | User task | `assignee`, `owner`, `candidateUsers`, `candidateGroups`, `dueDate`, `businessCalendarName`, `category`, `priority`, `extensionId`, `skipExpression`, `taskIdVariableName`, `taskCompleterVariableName` (`flowable:UserTask`), the form attributes (`flowable:FormSupported`), `customResource` |
57
+ | Service task | `class`, `expression`, `delegateExpression`, `resultVariableName` (and `resultVariable`), `useLocalScopeForResultVariable`, `storeResultVariableAsTransient`, `skipExpression`, `extensionId`, `triggerable`, `type`, http `parallelInSameTransaction`, the case attributes, external worker `topic` and `doNotIncludeVariables` (`flowable:ServiceTask`); `mapException`, `httpRequestHandler` / `httpResponseHandler`, `externalWorkerInParameter` / `externalWorkerOutParameter` |
58
+ | Script task | `resultVariable`, `resultVariableName`, `autoStoreVariables`, `doNotIncludeVariables`, `skipExpression` |
59
+ | Business rule task | `ruleVariablesInput`, `rules`, `resultVariable`, `class`, `exclude` |
60
+ | Send and receive tasks | send task `type` (with `field`), receive task `skipExpression` |
61
+ | Call activity | `calledElementType`, `processInstanceName`, `businessKey`, `inheritBusinessKey`, `inheritVariables`, `sameDeployment`, `calledElementBinding`, `useLocalScopeForOutParameters`, `completeAsync`, `fallbackToDefaultTenant`, `idVariableName` |
62
+ | In/out parameters | `in` and `out` (on `flowable:IOParameter`: `source`, `sourceExpression`, `target`, `targetExpression`, `sourceType`, `targetType`, `transient`; plus `variables`, `local`, `businessKey`) on call activities, start events, script tasks, case tasks and events |
63
+ | Multi-instance | `collection`, `elementVariable`, `elementIndexVariable`, `noWaitStatesAsyncLeave`; the `collection` handler (`class` / `delegateExpression` with `string` / `expression`); `variableAggregation` with `variable` children |
64
+ | Event definitions | timer `businessCalendarName`, `timeCycle` `endDate`, signal `signalExpression` and `async`, message `messageExpression`, error `errorVariableName` / `errorVariableTransient` / `errorVariableLocalScope`, terminate `terminateAll` / `terminateMultiInstance`, `variableListenerEventDefinition` |
65
+ | Event registry | `eventType`, `eventName`, `eventCorrelationParameter`, `eventInParameter`, `eventOutParameter`, `startEventCorrelationConfiguration`, `triggerEventType`, `sendSynchronously`, `triggerEventCorrelationParameter`, `channelKey`, `systemChannel` |
66
+ | Data objects, signals, sequence flows | data object `value` (`flowable:Value`), signal `scope`, sequence flow `skipExpression` |
67
+ | Fields and scripts | `field` with `stringValue`, `expression` (attribute) or `string` / `expression` children (`expressionElement`), `script` |
68
+
69
+ Listener, field and script attributes are written without a prefix, as Flowable's own exporter writes them; prefixed spellings such as `flowable:class` on a listener are read too.
70
+
71
+ With the descriptor registered, a `resourceAssignmentExpression` (in `potentialOwner`, `humanPerformer` and `flowable:potentialStarter`) is written with a `<formalExpression>` child, as Flowable expects, instead of bpmn-moddle's `<expression xsi:type="tFormalExpression">`.
72
+
73
+ The diagram interchange attributes Flowable writes (`sourceDockerX`/`Y` and `targetDockerX`/`Y` on `BPMNEdge`, `rotation` on `BPMNLabel`) are kept as unknown attributes and written back unchanged. They are not typed, because extending `bpmndi:BPMNEdge` or `bpmndi:BPMNLabel` from this package would make moddle write those tags as `bPMNEdge` / `bPMNLabel`.
74
+
75
+ The full list of Flowable extensions, and which ones are covered so far, is in the [coverage matrix](https://github.com/jylups/bpmn-js-env/blob/main/docs/coverage.md). The extensions themselves are listed in [docs/flowable-bpmn-extensions.md](https://github.com/jylups/bpmn-js-env/blob/main/docs/flowable-bpmn-extensions.md).
24
76
 
25
77
  ## Development
26
78
 
package/index.js CHANGED
@@ -7,3 +7,10 @@ import flowableDescriptor from './resources/flowable.json' with { type: 'json' }
7
7
  * Pass it to bpmn-js or bpmn-moddle as `moddleExtensions: { flowable }`.
8
8
  */
9
9
  export default flowableDescriptor;
10
+
11
+ export {
12
+ ACTIVITI_NS,
13
+ FLOWABLE_NS,
14
+ migrateActivitiXML,
15
+ useFlowablePrefix
16
+ } from './lib/migrate.js';
package/lib/migrate.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Helpers for models written with the Activiti namespace.
3
+ *
4
+ * Flowable reads its extensions in the Flowable namespace
5
+ * (http://flowable.org/bpmn) and, for compatibility, in the Activiti
6
+ * namespace (http://activiti.org/bpmn). The descriptor only registers the
7
+ * Flowable namespace, so Activiti spellings would stay generic, untyped
8
+ * content. These helpers move a model to the Flowable namespace so that
9
+ * everything is typed and written as flowable:.
10
+ */
11
+
12
+ export const FLOWABLE_NS = 'http://flowable.org/bpmn';
13
+
14
+ export const ACTIVITI_NS = 'http://activiti.org/bpmn';
15
+
16
+ const ACTIVITI_DECLARATION = /(\sxmlns(?::[A-Za-z_][\w.-]*)?\s*=\s*)(["'])http:\/\/activiti\.org\/bpmn\2/g;
17
+
18
+ /**
19
+ * Rewrites namespace declarations of the Activiti namespace to the Flowable
20
+ * namespace. Only xmlns declarations change, so element names, attribute
21
+ * names and text stay as they are; prefixes bound to the Activiti namespace
22
+ * then resolve to the Flowable descriptor when the XML is imported.
23
+ *
24
+ * @param {string} xml
25
+ *
26
+ * @return {string}
27
+ */
28
+ export function migrateActivitiXML(xml) {
29
+ return xml.replace(ACTIVITI_DECLARATION, `$1$2${ FLOWABLE_NS }$2`);
30
+ }
31
+
32
+ /**
33
+ * Removes namespace declarations on the definitions that bind another prefix
34
+ * (for example activiti) to the Flowable namespace, so that the writer uses
35
+ * the flowable prefix. Call it after importing XML that went through
36
+ * migrateActivitiXML, before saving.
37
+ *
38
+ * @param {Object} definitions - the imported bpmn:Definitions
39
+ *
40
+ * @return {Object} the definitions
41
+ */
42
+ export function useFlowablePrefix(definitions) {
43
+ const attrs = definitions.$attrs || {};
44
+
45
+ for (const name of Object.keys(attrs)) {
46
+ if (name.startsWith('xmlns:') && name !== 'xmlns:flowable' && attrs[name] === FLOWABLE_NS) {
47
+ delete attrs[name];
48
+ }
49
+ }
50
+
51
+ if (attrs['xmlns:flowable'] && attrs['xmlns:flowable'] !== FLOWABLE_NS) {
52
+ delete attrs['xmlns:flowable'];
53
+ }
54
+
55
+ return definitions;
56
+ }
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@jylups/flowable-bpmn-moddle",
3
- "version": "0.0.0",
3
+ "version": "0.1.0-next.0",
4
4
  "description": "Flowable moddle extensions for BPMN 2.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./index.js",
8
+ "./lib/migrate.js": "./lib/migrate.js",
8
9
  "./resources/flowable.json": "./resources/flowable.json",
9
10
  "./package.json": "./package.json"
10
11
  },
11
12
  "files": [
12
13
  "index.js",
14
+ "lib",
13
15
  "resources"
14
16
  ],
15
17
  "scripts": {
@@ -42,6 +44,7 @@
42
44
  },
43
45
  "devDependencies": {
44
46
  "@eslint/js": "^10.0.1",
47
+ "@xmldom/xmldom": "^0.9.12",
45
48
  "bpmn-moddle": "^10.3.1",
46
49
  "eslint": "^10.15.0",
47
50
  "globals": "^17.14.0",