Skip to content

Commit

Permalink
use [email protected] and make smqp peer
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Oct 22, 2024
1 parent 25f4849 commit f80bde3
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 63 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 23.0.2

- move `smqp` to peerDependencies since it's included in `bpmn-elements`
- patch [`[email protected]`](https://github.com/paed01/bpmn-elements/blob/master/CHANGELOG.md)
- use optional chaining and remove futile object creations

## 23.0.1

- patch [`[email protected]`](https://github.com/paed01/bpmn-elements/blob/master/CHANGELOG.md)
Expand Down
8 changes: 4 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- version -->

# 23.0.1 API Reference
# 23.0.2 API Reference

<!-- versionstop -->

Expand Down Expand Up @@ -354,7 +354,7 @@ const engine = new Engine({
</definitions>
`);

async function getContext(source, options = {}) {
async function getContext(source, options) {
const moddleContext = await getModdleContext(source, options);

if (moddleContext.warnings) {
Expand All @@ -366,10 +366,10 @@ async function getContext(source, options = {}) {

const types = TypeResolver({
...elements,
...options.elements,
...options?.elements,
});

return Serializer(moddleContext, types, options.extendFn);
return Serializer(moddleContext, types, options?.extendFn);
}

function getModdleContext(source, options) {
Expand Down
2 changes: 1 addition & 1 deletion docs/Upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function upgradeStateToVersion14(state) {
}

function polyfillProcessEnvironment(state) {
if (!state.definitions && state.definitions.length) return state;
if (!state.definitions?.length) return state;

const polyfilledState = JSON.parse(JSON.stringify(state));
for (const definition of polyfilledState.definitions) {
Expand Down
18 changes: 8 additions & 10 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,27 @@ const rules = {
export default [
js.configs.recommended,
{
rules,
},
{
files: ['src/**/*.js', 'scripts/**/*.js'],
languageOptions: {
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
},
},
rules,
},
{
files: ['src/**/*.js', 'scripts/**/*.js'],
languageOptions: {
globals: {
...globals.node,
...globals.es6,
...globals.nodeBuiltin,
},
},
},
{
files: ['test/**/*.js'],
languageOptions: {
parserOptions: {
ecmaVersion: 2022,
},
globals: {
...globals.node,
...globals.nodeBuiltin,
...globals.mocha,
expect: 'readonly',
beforeEachScenario: 'readonly',
Expand Down
36 changes: 17 additions & 19 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,19 @@ Object.defineProperties(ProcessOutputDataObject.prototype, {
ProcessOutputDataObject.prototype.read = function readDataObject(broker, exchange, routingKeyPrefix, messageProperties) {
const environment = this.environment;
const { id, name, type } = this;
const value = environment.variables.data && environment.variables.data[this.id];
const value = environment.variables.data?.[this.id];
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
};

ProcessOutputDataObject.prototype.write = function writeDataObject(broker, exchange, routingKeyPrefix, value, messageProperties) {
const environment = this.environment;
const { id, name, type } = this;

environment.variables.data = environment.variables.data || {};
environment.variables.data[id] = value;
const data = (environment.variables.data = environment.variables.data || {});
data[id] = value;

environment.output.data = environment.output.data || {};
environment.output.data[id] = value;
const outputData = (environment.output.data = environment.output.data || {});
outputData[id] = value;
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
};

Expand All @@ -175,14 +175,14 @@ const kState = Symbol.for('state');
const kStopped = Symbol.for('stopped');
const kTypeResolver = Symbol.for('type resolver');

function Engine(options = {}) {
function Engine(options) {
if (!(this instanceof Engine)) return new Engine(options);

node_events.EventEmitter.call(this);

const opts = (this.options = {
Logger: Logger,
scripts: new Scripts(options.disableDummyScript),
scripts: new Scripts(options?.disableDummyScript),
...options,
});

Expand Down Expand Up @@ -334,11 +334,11 @@ Engine.prototype.resume = async function resume(...args) {
return execution._resume(resumeOptions, callback);
};

Engine.prototype.addSource = function addSource({ sourceContext: addContext } = {}) {
if (!addContext) return;
Engine.prototype.addSource = function addSource(options) {
if (!options?.sourceContext) return;
const loadedDefinitions = this[kLoadedDefinitions];
if (loadedDefinitions) loadedDefinitions.splice(0);
this[kPendingSources].add(addContext);
this[kPendingSources].add(options.sourceContext);
};

Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
Expand Down Expand Up @@ -382,9 +382,7 @@ Engine.prototype._loadDefinitions = async function loadDefinitions(executeOption
return loadedDefinitions;
};

Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions = {}) {
const { settings, variables } = executeOptions;

Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions) {
const environment = this.environment;
const context = new Elements__namespace.Context(
serializedContext,
Expand All @@ -393,11 +391,11 @@ Engine.prototype._loadDefinition = function loadDefinition(serializedContext, ex
...executeOptions,
settings: {
...environment.settings,
...settings,
...executeOptions?.settings,
},
variables: {
...environment.variables,
...variables,
...executeOptions?.variables,
},
source: serializedContext,
})
Expand Down Expand Up @@ -570,8 +568,8 @@ Execution.prototype.stop = async function stop() {
return result;
};

Execution.prototype._setup = function setup(setupOptions = {}) {
const listener = setupOptions.listener || this.options.listener;
Execution.prototype._setup = function setup(setupOptions) {
const listener = setupOptions?.listener || this.options.listener;
if (listener && typeof listener.emit !== 'function') throw new Error('listener.emit is not a function');

const onChildMessage = this._onChildMessage.bind(this);
Expand Down Expand Up @@ -717,9 +715,9 @@ Execution.prototype.getPostponed = function getPostponed() {
return result;
};

Execution.prototype.signal = function signal(payload, { ignoreSameDefinition } = {}) {
Execution.prototype.signal = function signal(payload, signalOptions) {
for (const definition of this[kExecuting]) {
if (ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
if (signalOptions?.ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
definition.signal(payload);
}
};
Expand Down
10 changes: 6 additions & 4 deletions 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": "23.0.1",
"version": "23.0.2",
"type": "module",
"module": "./src/index.js",
"main": "./lib/index.cjs",
Expand Down Expand Up @@ -69,10 +69,12 @@
"texample": "^0.0.6"
},
"dependencies": {
"bpmn-elements": "^16.1.0",
"bpmn-elements": "^16.2.1",
"bpmn-moddle": "^9.0.1",
"debug": "^4.3.7",
"moddle-context-serializer": "^4.2.1",
"smqp": "^9.0.2"
"moddle-context-serializer": "^4.2.1"
},
"peerDependencies": {
"smqp": ">=9"
}
}
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
import commonjs from '@rollup/plugin-commonjs';

const nodeRequire = createRequire(fileURLToPath(import.meta.url));
const { module, main, dependencies } = nodeRequire('./package.json');
const { module, main, dependencies, peerDependencies } = nodeRequire('./package.json');

export default {
input: module,
Expand All @@ -21,5 +21,5 @@ export default {
footer: 'module.exports = Object.assign(exports.default, exports);',
},
],
external: ['node:module', 'node:url', 'node:vm', 'node:events', ...Object.keys(dependencies)],
external: ['node:module', 'node:url', 'node:vm', 'node:events', ...Object.keys({ ...dependencies, ...peerDependencies })],
};
10 changes: 5 additions & 5 deletions src/extensions/ProcessOutputDataObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ Object.defineProperties(ProcessOutputDataObject.prototype, {
ProcessOutputDataObject.prototype.read = function readDataObject(broker, exchange, routingKeyPrefix, messageProperties) {
const environment = this.environment;
const { id, name, type } = this;
const value = environment.variables.data && environment.variables.data[this.id];
const value = environment.variables.data?.[this.id];
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
};

ProcessOutputDataObject.prototype.write = function writeDataObject(broker, exchange, routingKeyPrefix, value, messageProperties) {
const environment = this.environment;
const { id, name, type } = this;

environment.variables.data = environment.variables.data || {};
environment.variables.data[id] = value;
const data = (environment.variables.data = environment.variables.data || {});
data[id] = value;

environment.output.data = environment.output.data || {};
environment.output.data[id] = value;
const outputData = (environment.output.data = environment.output.data || {});
outputData[id] = value;
return broker.publish(exchange, `${routingKeyPrefix}response`, { id, name, type, value }, messageProperties);
};
26 changes: 12 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const kTypeResolver = Symbol.for('type resolver');
export default Engine;
export { JavaScripts };

export function Engine(options = {}) {
export function Engine(options) {
if (!(this instanceof Engine)) return new Engine(options);

EventEmitter.call(this);

const opts = (this.options = {
Logger: DebugLogger,
scripts: new JavaScripts(options.disableDummyScript),
scripts: new JavaScripts(options?.disableDummyScript),
...options,
});

Expand Down Expand Up @@ -188,11 +188,11 @@ Engine.prototype.resume = async function resume(...args) {
return execution._resume(resumeOptions, callback);
};

Engine.prototype.addSource = function addSource({ sourceContext: addContext } = {}) {
if (!addContext) return;
Engine.prototype.addSource = function addSource(options) {
if (!options?.sourceContext) return;
const loadedDefinitions = this[kLoadedDefinitions];
if (loadedDefinitions) loadedDefinitions.splice(0);
this[kPendingSources].add(addContext);
this[kPendingSources].add(options.sourceContext);
};

Engine.prototype.getDefinitions = function getDefinitions(executeOptions) {
Expand Down Expand Up @@ -236,9 +236,7 @@ Engine.prototype._loadDefinitions = async function loadDefinitions(executeOption
return loadedDefinitions;
};

Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions = {}) {
const { settings, variables } = executeOptions;

Engine.prototype._loadDefinition = function loadDefinition(serializedContext, executeOptions) {
const environment = this.environment;
const context = new Elements.Context(
serializedContext,
Expand All @@ -247,11 +245,11 @@ Engine.prototype._loadDefinition = function loadDefinition(serializedContext, ex
...executeOptions,
settings: {
...environment.settings,
...settings,
...executeOptions?.settings,
},
variables: {
...environment.variables,
...variables,
...executeOptions?.variables,
},
source: serializedContext,
})
Expand Down Expand Up @@ -424,8 +422,8 @@ Execution.prototype.stop = async function stop() {
return result;
};

Execution.prototype._setup = function setup(setupOptions = {}) {
const listener = setupOptions.listener || this.options.listener;
Execution.prototype._setup = function setup(setupOptions) {
const listener = setupOptions?.listener || this.options.listener;
if (listener && typeof listener.emit !== 'function') throw new Error('listener.emit is not a function');

const onChildMessage = this._onChildMessage.bind(this);
Expand Down Expand Up @@ -571,9 +569,9 @@ Execution.prototype.getPostponed = function getPostponed() {
return result;
};

Execution.prototype.signal = function signal(payload, { ignoreSameDefinition } = {}) {
Execution.prototype.signal = function signal(payload, signalOptions) {
for (const definition of this[kExecuting]) {
if (ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
if (signalOptions?.ignoreSameDefinition && payload?.parent?.id === definition.id) continue;
definition.signal(payload);
}
};
Expand Down
2 changes: 1 addition & 1 deletion test/feature/backward-compatibility-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function upgradeStateToVersion14(state) {
}

function polyfillProcessEnvironment(state) {
if (!state.definitions && state.definitions.length) return state;
if (!state.definitions?.length) return state;

const polyfilledState = JSON.parse(JSON.stringify(state));
for (const definition of polyfilledState.definitions) {
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import serializer, { TypeResolver } from 'moddle-context-serializer';
const nodeRequire = createRequire(fileURLToPath(import.meta.url));
export const camundaBpmnModdle = nodeRequire('camunda-bpmn-moddle/resources/camunda.json');

export async function context(source, options = {}) {
export async function context(source, options) {
const logger = Logger('test-helpers:context');
const moddleCtx = await moddleContext(source, options);

Expand All @@ -22,10 +22,10 @@ export async function context(source, options = {}) {

const types = TypeResolver({
...Elements,
...options.elements,
...options?.elements,
});

return serializer(moddleCtx, types, options.extendFn);
return serializer(moddleCtx, types, options?.extendFn);
}

export function moddleContext(source, options) {
Expand Down

0 comments on commit f80bde3

Please sign in to comment.