From f80bde3a1f4b5300d42c5cc0bde113bc1f4b0cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l=20Edman?= Date: Tue, 22 Oct 2024 08:27:29 +0200 Subject: [PATCH] use bpmn-element@16.2 and make smqp peer --- CHANGELOG.md | 6 ++++ docs/API.md | 8 ++--- docs/Upgrade.md | 2 +- eslint.config.js | 18 +++++----- lib/index.cjs | 36 +++++++++---------- package.json | 10 +++--- rollup.config.js | 4 +-- src/extensions/ProcessOutputDataObject.js | 10 +++--- src/index.js | 26 +++++++------- .../feature/backward-compatibility-feature.js | 2 +- test/helpers/testHelpers.js | 6 ++-- 11 files changed, 65 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46360a5..a7e14d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 23.0.2 + +- move `smqp` to peerDependencies since it's included in `bpmn-elements` +- patch [`bpmn-elements@16.2.1`](https://github.com/paed01/bpmn-elements/blob/master/CHANGELOG.md) +- use optional chaining and remove futile object creations + ## 23.0.1 - patch [`bpmn-elements@16.1.0`](https://github.com/paed01/bpmn-elements/blob/master/CHANGELOG.md) diff --git a/docs/API.md b/docs/API.md index 6a045fe..9f7e86c 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1,6 +1,6 @@ -# 23.0.1 API Reference +# 23.0.2 API Reference @@ -354,7 +354,7 @@ const engine = new Engine({ `); -async function getContext(source, options = {}) { +async function getContext(source, options) { const moddleContext = await getModdleContext(source, options); if (moddleContext.warnings) { @@ -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) { diff --git a/docs/Upgrade.md b/docs/Upgrade.md index 49db25b..67c6012 100644 --- a/docs/Upgrade.md +++ b/docs/Upgrade.md @@ -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) { diff --git a/eslint.config.js b/eslint.config.js index 31767c1..dd44adb 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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', diff --git a/lib/index.cjs b/lib/index.cjs index bc51d44..3c52a2b 100644 --- a/lib/index.cjs +++ b/lib/index.cjs @@ -145,7 +145,7 @@ 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); }; @@ -153,11 +153,11 @@ ProcessOutputDataObject.prototype.write = function writeDataObject(broker, excha 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); }; @@ -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, }); @@ -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) { @@ -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, @@ -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, }) @@ -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); @@ -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); } }; diff --git a/package.json b/package.json index 5579554..5e6a952 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/rollup.config.js b/rollup.config.js index 3a66d67..677fb1f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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, @@ -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 })], }; diff --git a/src/extensions/ProcessOutputDataObject.js b/src/extensions/ProcessOutputDataObject.js index 0dcd151..e41a77a 100644 --- a/src/extensions/ProcessOutputDataObject.js +++ b/src/extensions/ProcessOutputDataObject.js @@ -24,7 +24,7 @@ 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); }; @@ -32,10 +32,10 @@ ProcessOutputDataObject.prototype.write = function writeDataObject(broker, excha 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); }; diff --git a/src/index.js b/src/index.js index ff64c70..93df6a5 100644 --- a/src/index.js +++ b/src/index.js @@ -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, }); @@ -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) { @@ -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, @@ -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, }) @@ -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); @@ -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); } }; diff --git a/test/feature/backward-compatibility-feature.js b/test/feature/backward-compatibility-feature.js index c0447be..98f361b 100644 --- a/test/feature/backward-compatibility-feature.js +++ b/test/feature/backward-compatibility-feature.js @@ -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) { diff --git a/test/helpers/testHelpers.js b/test/helpers/testHelpers.js index 16097b3..fabc45c 100644 --- a/test/helpers/testHelpers.js +++ b/test/helpers/testHelpers.js @@ -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); @@ -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) {