From 094ba1598435b5cf6c15a7cf906960078e79fed9 Mon Sep 17 00:00:00 2001 From: Daniel Duarte Date: Sat, 9 Sep 2023 20:58:17 -0300 Subject: [PATCH] chore: fixed code smells --- README.md | 6 +++--- src/engine/flow-run-status.ts | 5 +++-- src/engine/flow-state/flow-state.ts | 6 +++--- test/edge-cases.ts | 3 +-- test/examples-inline/microservices.ts | 5 ++--- test/examples-inline/pythagoras.ts | 3 +-- test/examples/apparent-circular-deps.ts | 3 +-- test/examples/dependencies.ts | 3 +-- test/examples/microservices.ts | 5 ++--- test/examples/pythagoras.ts | 3 +-- test/examples/sync-async.ts | 3 +-- test/flow-manager.ts | 4 +--- test/flow-pausing.ts | 3 +-- test/flow-stopping.ts | 3 +-- test/resolver-library-builtin.ts | 3 +-- test/resolver-library.ts | 4 +--- test/serialization.ts | 3 +-- test/task-repeater.ts | 3 +-- 18 files changed, 26 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 17ec798..515cc76 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -

Flowed Logo

-

A fast and reliable flow engine for orchestration and more uses in Node.js, Deno and the browser.

-

+

Flowed Logo

+

A fast and reliable flow engine for orchestration and more uses in Node.js, Deno and the browser.

+

License NPM Package Version FOSSA Status diff --git a/src/engine/flow-run-status.ts b/src/engine/flow-run-status.ts index 7481e20..3f98209 100644 --- a/src/engine/flow-run-status.ts +++ b/src/engine/flow-run-status.ts @@ -104,7 +104,8 @@ export class FlowRunStatus { // To be used later to check if expectedResults can be fulfilled. this.taskProvisions = Array.from(new Set(provisions)); - this.options = Object.assign({}, this.spec.configs ?? {}, this.spec.options ?? {}); + this.options = { ...this.spec.configs, ...this.spec.options }; + if (Object.prototype.hasOwnProperty.call(this.spec, 'configs')) { this.flow.log({ m: "DEPRECATED: 'configs' field in flow spec. Use 'options' instead.", l: 'w' }); } @@ -174,7 +175,7 @@ export class FlowRunStatus { taskStatuses: {}, }; - const serializableContext = Object.assign({}, this.context); + const serializableContext = { ...this.context }; delete serializableContext.$flowed; serialized.context = JSON.parse(JSON.stringify(serializableContext)); diff --git a/src/engine/flow-state/flow-state.ts b/src/engine/flow-state/flow-state.ts index 434cc71..2ec4a58 100644 --- a/src/engine/flow-state/flow-state.ts +++ b/src/engine/flow-state/flow-state.ts @@ -365,10 +365,10 @@ export abstract class FlowState implements IFlow { public static formatDebugMessage({ n, m, l, e }: { n?: number; m: string; mp?: ValueMap; l?: string; e?: string }): string { const levelIcon = l === 'w' ? '⚠️ ' : ''; const eventIcons = { FS: '▶ ', FF: '✔ ', TS: ' ‣ ', TF: ' ✓ ', FC: ' ⓘ ', FT: '◼ ', FP: '⏸ ' }; - let eventIcon = (eventIcons as any)[e || ''] ?? ''; // eslint-disable-line @typescript-eslint/no-explicit-any - if (e === 'TF' && ['e', 'f'].includes(l || '')) { + let eventIcon = (eventIcons as any)[e ?? ''] ?? ''; // eslint-disable-line @typescript-eslint/no-explicit-any + if (e === 'TF' && ['e', 'f'].includes(l ?? '')) { eventIcon = ' ✗'; - } else if (e === 'FF' && ['e', 'f'].includes(l || '')) { + } else if (e === 'FF' && ['e', 'f'].includes(l ?? '')) { eventIcon = '✘'; } const icon = levelIcon + eventIcon; diff --git a/test/edge-cases.ts b/test/edge-cases.ts index bc5ccb7..575776d 100644 --- a/test/edge-cases.ts +++ b/test/edge-cases.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -import { FlowManager, ValueMap } from '../src'; -import { Task } from '../src'; +import { FlowManager, ValueMap, Task } from '../src'; describe('edge cases', () => { it('manually provide unexpected requirement to task must throw an error', async () => { diff --git a/test/examples-inline/microservices.ts b/test/examples-inline/microservices.ts index 7284fff..8472179 100644 --- a/test/examples-inline/microservices.ts +++ b/test/examples-inline/microservices.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from '../examples/types'; const callMicroservice = (params: ValueMap) => { @@ -23,7 +22,7 @@ const callMicroservice = (params: ValueMap) => { }; const simpleMerge = (params: ValueMap) => ({ - result: Object.assign({}, params.obj1, params.obj2), + result: { ...params.obj1, ...params.obj2 }, }); // noinspection JSUnusedGlobalSymbols diff --git a/test/examples-inline/pythagoras.ts b/test/examples-inline/pythagoras.ts index a151f6d..bb7510c 100644 --- a/test/examples-inline/pythagoras.ts +++ b/test/examples-inline/pythagoras.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from '../examples/types'; // Example of named function used as resolver diff --git a/test/examples/apparent-circular-deps.ts b/test/examples/apparent-circular-deps.ts index c932737..2ba293f 100644 --- a/test/examples/apparent-circular-deps.ts +++ b/test/examples/apparent-circular-deps.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from './types'; class DummyResolver { diff --git a/test/examples/dependencies.ts b/test/examples/dependencies.ts index c0bb156..cc6ed12 100644 --- a/test/examples/dependencies.ts +++ b/test/examples/dependencies.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from './types'; class DummyResolver { diff --git a/test/examples/microservices.ts b/test/examples/microservices.ts index 167b373..cd83c67 100644 --- a/test/examples/microservices.ts +++ b/test/examples/microservices.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from './types'; class CallMicroservice { @@ -27,7 +26,7 @@ class CallMicroservice { class SimpleMerge { public async exec(params: ValueMap): Promise { return { - result: Object.assign({}, params.obj1, params.obj2), + result: { ...params.obj1, ...params.obj2 }, }; } } diff --git a/test/examples/pythagoras.ts b/test/examples/pythagoras.ts index ec882d0..54c2412 100644 --- a/test/examples/pythagoras.ts +++ b/test/examples/pythagoras.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from './types'; class Sqr { diff --git a/test/examples/sync-async.ts b/test/examples/sync-async.ts index f5965cc..cb2e4c2 100644 --- a/test/examples/sync-async.ts +++ b/test/examples/sync-async.ts @@ -1,5 +1,4 @@ -import { ValueMap } from '../../src'; -import { FlowManager } from '../../src'; +import { ValueMap, FlowManager } from '../../src'; import { ExampleFunction } from './types'; class TimerResolver { diff --git a/test/flow-manager.ts b/test/flow-manager.ts index 537ebad..173f3ff 100644 --- a/test/flow-manager.ts +++ b/test/flow-manager.ts @@ -1,7 +1,5 @@ import { expect } from 'chai'; -import { TaskResolverMap, ValueMap } from '../src'; -import { FlowManager } from '../src'; -import { FlowSpec } from '../src'; +import { TaskResolverMap, ValueMap, FlowManager, FlowSpec } from '../src'; class DummyResolver { public async exec(): Promise { diff --git a/test/flow-pausing.ts b/test/flow-pausing.ts index fe4fe5c..1b1e743 100644 --- a/test/flow-pausing.ts +++ b/test/flow-pausing.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; import rawDebug from '../src/debug'; -import { ValueMap } from '../src'; -import { Flow, Task } from '../src'; +import { ValueMap, Flow, Task } from '../src'; const debug = rawDebug('test'); describe('the flow', () => { diff --git a/test/flow-stopping.ts b/test/flow-stopping.ts index 5f58290..df61323 100644 --- a/test/flow-stopping.ts +++ b/test/flow-stopping.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -import { ValueMap } from '../src'; -import { Flow, Task } from '../src'; +import { ValueMap, Flow, Task } from '../src'; describe('the flow', () => { const text1 = '(text1)'; diff --git a/test/resolver-library-builtin.ts b/test/resolver-library-builtin.ts index 44abbec..6fa624d 100644 --- a/test/resolver-library-builtin.ts +++ b/test/resolver-library-builtin.ts @@ -1,6 +1,5 @@ import { expect } from 'chai'; -import { ValueMap } from '../src'; -import { FlowManager } from '../src'; +import { ValueMap, FlowManager } from '../src'; describe('the ResolverLibrary', () => { it('runs noop resolver without mapping', () => { diff --git a/test/resolver-library.ts b/test/resolver-library.ts index 0a3a1d7..95ee0d9 100644 --- a/test/resolver-library.ts +++ b/test/resolver-library.ts @@ -1,8 +1,6 @@ import { expect } from 'chai'; -import { Task, ValueMap, WaitResolver } from '../src'; -import { FlowManager } from '../src'; +import { Task, ValueMap, WaitResolver, FlowManager, TaskResolver } from '../src'; import * as ResolverLibrary from '../src/resolver-library'; -import { TaskResolver } from '../src'; import rawDebug from '../src/debug'; const debug = rawDebug('test'); diff --git a/test/serialization.ts b/test/serialization.ts index afcd397..02a3546 100644 --- a/test/serialization.ts +++ b/test/serialization.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; import rawDebug from '../src/debug'; -import { Flow, ValueMap } from '../src'; -import { Task } from '../src'; +import { Flow, ValueMap, Task } from '../src'; const debug = rawDebug('test'); describe('a flow state can be', () => { diff --git a/test/task-repeater.ts b/test/task-repeater.ts index eeed36f..d6a0b64 100644 --- a/test/task-repeater.ts +++ b/test/task-repeater.ts @@ -1,7 +1,6 @@ import { expect } from 'chai'; import rawDebug from '../src/debug'; -import { ValueMap } from '../src'; -import { FlowManager } from '../src'; +import { ValueMap, FlowManager } from '../src'; import * as ResolverLibrary from '../src/resolver-library'; const debug = rawDebug('test');