Skip to content

Commit

Permalink
fix ignored options.extendFn
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Jun 19, 2024
1 parent 4aca3d5 commit 0858135
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# 22.0.1

- for a number of years the `extendFn` option has been accepted, but never passed to moddle-context-serializer. Now it is
- fix type declaration for options `extendFn` and `TypeResolver`
- type declare that a generic listener instance with an emit function works just as well as a full blown new EventEmitter

# 22.0.0

Performance tweaks.
Expand Down
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- version -->

# 22.0.0 API Reference
# 22.0.1 API Reference

<!-- versionstop -->

Expand Down
2 changes: 1 addition & 1 deletion lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ Engine.prototype._serializeSource = async function serializeSource(source) {
};

Engine.prototype._serializeModdleContext = function serializeModdleContext(moddleContext) {
return serializer(moddleContext, this[kTypeResolver]);
return serializer(moddleContext, this[kTypeResolver], this.options.extendFn);
};

Engine.prototype._getModdleContext = function getModdleContext(source) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bpmn-engine",
"description": "BPMN 2.0 execution engine. Open source javascript workflow engine.",
"version": "22.0.0",
"version": "22.0.1",
"type": "module",
"module": "./src/index.js",
"main": "./lib/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Engine.prototype._serializeSource = async function serializeSource(source) {
};

Engine.prototype._serializeModdleContext = function serializeModdleContext(moddleContext) {
return serializer(moddleContext, this[kTypeResolver]);
return serializer(moddleContext, this[kTypeResolver], this.options.extendFn);
};

Engine.prototype._getModdleContext = function getModdleContext(source) {
Expand Down
39 changes: 39 additions & 0 deletions test/feature/extend-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,45 @@ Feature('extending behaviour', () => {
});
});

Scenario('Extend function option', () => {
let engine, source;
Given('a bpmn source', () => {
source = `
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<process id="theProcess" isExecutable="true">
<scriptTask id="task1">
<script>Placeholder</script>
</scriptTask>
</process>
</definitions>`;
});

const fnCalls = [];
And('an engine loaded with extendFn', () => {
engine = Engine({
name: 'Scripts feature',
source,
extendFn(...args) {
fnCalls.push(args);
},
});
});

let api;
When('source is executed', async () => {
api = await engine.execute();
});

Then('engine comletes run', () => {
expect(api.state).to.equal('idle');
});

And('extendFn has been called', () => {
expect(fnCalls.length).to.be.above(0);
});
});

Scenario('End event with extension (issue #25)', () => {
let source;
Given('a source with extension elements on end event', () => {
Expand Down
19 changes: 16 additions & 3 deletions types/bpmn-engine.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import { EventEmitter } from 'node:events';
import { Definitions as BpmnModdleDefinitions } from 'bpmn-moddle';
import { extendFn, SerializableContext } from 'moddle-context-serializer';
import {
extendFn,
SerializableContext,
TypeResolver,
} from 'moddle-context-serializer';
import {
ActivityStatus,
ElementBroker,
Expand Down Expand Up @@ -68,8 +72,12 @@ declare module 'bpmn-engine' {
[name: string]: any;
}

export interface IListenerEmitter {
emit(eventName: string, ...args: any[]): void;
}

export interface BpmnEngineExecuteOptions extends EnvironmentOptions {
listener?: EventEmitter;
listener?: EventEmitter | IListenerEmitter;
}

export interface BpmnEngineOptions extends BpmnEngineExecuteOptions {
Expand All @@ -89,15 +97,20 @@ declare module 'bpmn-engine' {
* optional override of BPMN Elements behaviors, defaults to bpmn-elements
*/
elements?: Record<string, any>;
/**
* Passed to moddle-context-serializer as TypeResolver
*/
typeResolver?: typeof TypeResolver;
/**
* Passed to moddle-context-serializer as extendFn
*/
typeResolver?: extendFn;
extendFn?: extendFn;
/**
* optional bpmn-moddle options to be passed to bpmn-moddle
*/
moddleOptions?: any;
moddleContext?: BpmnModdleDefinitions;
[x: string]: any;
}

const enum BpmnEngineRunningStatus {
Expand Down

0 comments on commit 0858135

Please sign in to comment.