diff --git a/.vscode/launch.json b/.vscode/launch.json index d39f5a171..32b0b4193 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,14 +14,14 @@ { "type": "node", "request": "launch", - "name": "Debug Jest Tests", + "name": "Debug Tests", "runtimeExecutable": "yarn", - "runtimeArgs": ["run", "--inspect-brk", "test", "--runInBand", "${file}"], + "runtimeArgs": ["run", "--inspect-brk", "test", "${file}"], "skipFiles": ["/**"], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "windows": { - "runtimeArgs": ["run", "--inspect-brk", "test", "--runInBand", "/${fileBasename}"] + "runtimeArgs": ["run", "--inspect-brk", "test", "/${fileBasename}"] } }, { diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json b/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json index 22e85732f..a7363a5af 100644 --- a/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0", "main": "./dist/server/index.js", "devDependencies": { + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/package.json b/packages/plugins/@nocobase/plugin-workflow-delay/package.json index 925d9201c..5ecdb37e8 100644 --- a/packages/plugins/@nocobase/plugin-workflow-delay/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-delay/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0", "main": "./dist/server/index.js", "devDependencies": { + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/package.json b/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/package.json index 9bc64bf13..e6f8a3e0b 100644 --- a/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/package.json @@ -12,6 +12,7 @@ "@formily/antd-v5": "1.x", "@formily/core": "2.x", "@formily/react": "2.x", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "lodash": "4.17.21", "react": "18.x", @@ -24,7 +25,6 @@ "@nocobase/evaluators": "0.x", "@nocobase/plugin-collection-manager": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x", "@nocobase/utils": "0.x" diff --git a/packages/plugins/@nocobase/plugin-workflow-form-trigger/package.json b/packages/plugins/@nocobase/plugin-workflow-form-trigger/package.json index 4b4ccbd72..56d0e77a4 100644 --- a/packages/plugins/@nocobase/plugin-workflow-form-trigger/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-form-trigger/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0", "main": "./dist/server/index.js", "devDependencies": { + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-loop/package.json b/packages/plugins/@nocobase/plugin-workflow-loop/package.json index 920ee14c4..781749311 100644 --- a/packages/plugins/@nocobase/plugin-workflow-loop/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-loop/package.json @@ -9,6 +9,7 @@ "main": "./dist/server/index.js", "devDependencies": { "@ant-design/icons": "5.x", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "react": "18.x", "react-i18next": "^11.15.1" }, @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-loop/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow-loop/src/locale/zh-CN.json index 0c57ff062..19b014bd4 100644 --- a/packages/plugins/@nocobase/plugin-workflow-loop/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow-loop/src/locale/zh-CN.json @@ -4,6 +4,5 @@ "Loop index": "当前索引", "Loop length": "循环长度", "By using a loop node, you can perform the same operation on multiple sets of data. The source of these sets can be either multiple records from a query node or multiple associated records of a single record. Loop node can also be used for iterating a certain number of times or for looping through each character in a string. However, excessive looping may cause performance issues, so use with caution.": "使用循环节点可以对多条数据进行同样的操作,多条数据的来源可以是查询节点的多条结果,或者一条数据的多条关系数据。也可以用于一定次数的循环,或者对字符串中每一个字符的循环处理。循环次数过高可能引起性能问题,请谨慎使用。", - "Scope variables": "局域变量", "A single number will be treated as a loop count, a single string will be treated as an array of characters, and other non-array values will be converted to arrays. The loop node ends when the loop count is reached, or when the array loop is completed. You can also add condition nodes to the loop to terminate it.": "单一数字值将被视为循环次数,单一字符串值将被视为字符数组,其他非数组值将被转换为数组。达到循环次数,或者将数组循环完成后,循环节点结束。你也可以在循环中添加条件节点,以终止循环。" } diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/package.json b/packages/plugins/@nocobase/plugin-workflow-manual/package.json index 75b29517b..83f8da3e6 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-manual/package.json @@ -12,6 +12,7 @@ "@formily/antd-v5": "1.x", "@formily/core": "2.x", "@formily/react": "2.x", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "lodash": "4.17.21", "react": "18.x", @@ -24,7 +25,6 @@ "@nocobase/plugin-collection-manager": "0.x", "@nocobase/plugin-users": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x", "@nocobase/utils": "0.x" diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/instruction.test.ts index 28a1dc22a..85af40aae 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/instruction.test.ts @@ -1,5 +1,4 @@ import Database from '@nocobase/database'; -import UserPlugin from '@nocobase/plugin-users'; import { MockServer } from '@nocobase/test'; import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow'; import { getApp, sleep } from '@nocobase/plugin-workflow-test'; @@ -38,7 +37,6 @@ describe('workflow > instructions > manual', () => { { id: 2, nickname: 'b' }, ]); - const userPlugin = app.getPlugin('users') as UserPlugin; userAgents = users.map((user) => app.agent().login(user)); workflow = await WorkflowModel.create({ diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/actions.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/actions.ts index bc06a4f40..97d87f38f 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/actions.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/actions.ts @@ -12,7 +12,7 @@ export async function submit(context: Context, next) { return context.throw(401); } - const plugin: WorkflowPlugin = context.app.pm.get('workflow') as WorkflowPlugin; + const plugin: WorkflowPlugin = context.app.getPlugin(WorkflowPlugin); const instruction = plugin.instructions.get('manual') as ManualInstruction; const userJob = await repository.findOne({ diff --git a/packages/plugins/@nocobase/plugin-workflow-parallel/package.json b/packages/plugins/@nocobase/plugin-workflow-parallel/package.json index 28355e729..f390ee9a9 100644 --- a/packages/plugins/@nocobase/plugin-workflow-parallel/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-parallel/package.json @@ -9,6 +9,7 @@ "main": "./dist/server/index.js", "devDependencies": { "@ant-design/icons": "5.x", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -17,7 +18,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-request/package.json b/packages/plugins/@nocobase/plugin-workflow-request/package.json index 386520264..5064bf8c1 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-request/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0", "main": "./dist/server/index.js", "devDependencies": { + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/package.json b/packages/plugins/@nocobase/plugin-workflow-sql/package.json index ffa8b3fe3..dcaf5dc9e 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-sql/package.json @@ -8,6 +8,7 @@ "license": "AGPL-3.0", "main": "./dist/server/index.js", "devDependencies": { + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "antd": "5.x", "react": "18.x", "react-i18next": "^11.15.1" @@ -16,7 +17,6 @@ "@nocobase/client": "0.x", "@nocobase/database": "0.x", "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/server": "0.x", "@nocobase/test": "0.x" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-test/src/server/index.ts b/packages/plugins/@nocobase/plugin-workflow-test/src/server/index.ts index 59ea309fa..e29b200b1 100644 --- a/packages/plugins/@nocobase/plugin-workflow-test/src/server/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow-test/src/server/index.ts @@ -55,24 +55,24 @@ export async function getApp({ ...options, autoStart, cleanDb, - plugins: ['workflow', 'workflow-test', ...plugins], + plugins: [ + [ + 'workflow', + { + instructions, + functions, + }, + ], + WorkflowTestPlugin, + ...plugins, + ], }); } -export default class extends Plugin { +export default class WorkflowTestPlugin extends Plugin { async load() { await this.db.import({ directory: path.resolve(__dirname, 'collections'), }); - - const workflow = this.app.getPlugin('workflow'); - - for (const [key, instruction] of Object.entries(instructions)) { - workflow.instructions.register(key, instruction); - } - - for (const [key, func] of Object.entries(functions)) { - workflow.functions.register(key, func); - } } } diff --git a/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts b/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts index b3466026c..69fd116c8 100644 --- a/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts +++ b/packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts @@ -13,6 +13,7 @@ export default { error: { run(node, input, processor) { throw new Error('definite error'); + return null; }, }, @@ -45,6 +46,7 @@ export default { }, resume(node, input, processor) { throw new Error('input failed'); + return null; }, }, diff --git a/packages/plugins/@nocobase/plugin-workflow/package.json b/packages/plugins/@nocobase/plugin-workflow/package.json index df5a9cd41..18816e68b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/package.json +++ b/packages/plugins/@nocobase/plugin-workflow/package.json @@ -13,6 +13,7 @@ "@formily/core": "2.x", "@formily/react": "2.x", "@types/ejs": "^3.1.1", + "@nocobase/plugin-workflow-test": ">= 0.18.0-alpha.2", "antd": "5.x", "axios": "^0.26.1", "classnames": "^2.3.1", @@ -24,8 +25,7 @@ "react-i18next": "^11.15.1", "react-js-cron": "^3.1.0", "react-router-dom": "^6.11.2", - "sequelize": "^6.26.0", - "winston": "^3.8.2" + "sequelize": "^6.26.0" }, "peerDependencies": { "@nocobase/actions": "0.x", @@ -36,11 +36,10 @@ "@nocobase/plugin-collection-manager": "0.x", "@nocobase/plugin-error-handler": "0.x", "@nocobase/plugin-users": "0.x", - "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", "@nocobase/resourcer": "0.x", "@nocobase/server": "0.x", - "@nocobase/test": "0.x", - "@nocobase/utils": "0.x" + "@nocobase/utils": "0.x", + "@nocobase/test": "0.x" }, "gitHead": "ce588eefb0bfc50f7d5bbee575e0b5e843bf6644" } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx index b40331d8e..dd2e2333c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx @@ -162,7 +162,7 @@ function Calculation({ calculator, operands = [], onChange }) { aria-label="select-operator-calc" value={calculator} onChange={(v) => onChange({ operands, calculator: v })} - placeholder={lang('Calculator')} + placeholder={lang('Operator')} popupMatchSelectWidth={false} > {calculatorGroups diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx index 32f80ec3b..2ee005acb 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx @@ -88,13 +88,15 @@ export function useNodeContext() { return useContext(NodeContext); } -export function useAvailableUpstreams(node) { +export function useAvailableUpstreams(node, filter?) { const stack: any[] = []; if (!node) { return []; } for (let current = node.upstream; current; current = current.upstream) { - stack.push(current); + if (typeof filter !== 'function' || filter(current)) { + stack.push(current); + } } return stack; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json index 27ef21b6d..ac0cbc6ae 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json @@ -58,7 +58,7 @@ "Null": "Null", "Boolean": "Boolean", "String": "String", - "Calculator": "Calculator", + "Operator": "Operator", "Arithmetic calculation": "Arithmetic calculation", "String operation": "String operation", "Executed at": "Executed at", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json index fddb324d6..d0ffb375f 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json @@ -58,7 +58,7 @@ "Null": "Null", "Boolean": "Booleano", "String": "Cadena", - "Calculator": "Calculadora", + "Operator": "Calculadora", "Arithmetic calculation": "Cálculo aritmético", "String operation": "Operación de Cadena", "Executed at": "Ejecutado en", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json index e38a851f3..2c4fc9278 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json @@ -58,7 +58,7 @@ "Null": "Null", "Boolean": "Booléen", "String": "Chaîne de caractères", - "Calculator": "Calculatrice", + "Operator": "Calculatrice", "Arithmetic calculation": "Calcul arithmétique", "String operation": "Opération sur les chaînes de caractères", "Executed at": "Exécuté à", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json index 425455a49..7ff7e6509 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json @@ -58,7 +58,7 @@ "Null": "Nulo", "Boolean": "Booleano", "String": "String", - "Calculator": "Calculadora", + "Operator": "Calculadora", "Arithmetic calculation": "Cálculo aritmético", "String operation": "Operação de string", "Executed at": "Executado em", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json index b55bdaf4d..a1cecee00 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json @@ -83,7 +83,9 @@ "End": "结束", "Node result": "节点数据", "Variable key of node": "节点变量标识", - "Calculator": "运算", + "Scope variables": "局域变量", + + "Operator": "运算符", "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression can be static or dynamic one from an expression collections.": "基于计算引擎对一个表达式进行计算,并获得一个值作为结果。表达式中可以使用上游节点里的变量。表达式可以是静态的,也可以是表达式表中的动态表达式。", "String operation": "字符串", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts index 1e2d14dc7..d13c914e2 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts @@ -1,13 +1,12 @@ import path from 'path'; import LRUCache from 'lru-cache'; -import winston from 'winston'; import { Op } from '@nocobase/database'; import { Plugin } from '@nocobase/server'; import { Registry } from '@nocobase/utils'; -import { createLogger, getLoggerFilePath, getLoggerLevel, Logger, LoggerOptions } from '@nocobase/logger'; +import { Logger, LoggerOptions } from '@nocobase/logger'; import Processor from './Processor'; import initActions from './actions'; import { EXECUTION_STATUS } from './constants'; @@ -15,7 +14,7 @@ import initFunctions, { CustomFunction } from './functions'; import Trigger from './triggers'; import CollectionTrigger from './triggers/CollectionTrigger'; import ScheduleTrigger from './triggers/ScheduleTrigger'; -import Instruction from './instructions'; +import { Instruction, InstructionInterface } from './instructions'; import CalculationInstruction from './instructions/CalculationInstruction'; import ConditionInstruction from './instructions/ConditionInstruction'; import CreateInstruction from './instructions/CreateInstruction'; @@ -32,7 +31,7 @@ type Pending = [ExecutionModel, JobModel?]; type CachedEvent = [WorkflowModel, any, { context?: any }]; export default class WorkflowPlugin extends Plugin { - instructions: Registry = new Registry(); + instructions: Registry = new Registry(); triggers: Registry = new Registry(); functions: Registry = new Registry(); @@ -118,7 +117,7 @@ export default class WorkflowPlugin extends Plugin { } } - registerInstruction(type: string, instruction: T | { new (p: Plugin): T }) { + registerInstruction(type: string, instruction: InstructionInterface | { new (p: Plugin): InstructionInterface }) { if (typeof instruction === 'function') { this.instructions.register(type, new instruction(this)); } else if (instruction) { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts index 9e742c05d..b790c5fb7 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts @@ -6,22 +6,14 @@ import { JOB_STATUS } from '../constants'; import type { FlowNodeModel } from '../types'; export interface CalculationConfig { - dynamic?: boolean | string; engine?: string; expression?: string; } export class CalculationInstruction extends Instruction { async run(node: FlowNodeModel, prevJob, processor: Processor) { - const { dynamic = false } = node.config || {}; - let { engine = 'math.js', expression = '' } = node.config; - let scope = processor.getScope(node.id); - if (dynamic) { - const parsed = parse(dynamic)(scope) ?? {}; - engine = parsed.engine; - expression = parsed.expression; - scope = parse(node.config.scope ?? '')(scope) ?? {}; - } + const { engine = 'math.js', expression = '' } = node.config; + const scope = processor.getScope(node.id); const evaluator = evaluators.get(engine); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts index ffb648f29..b8a08c97d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts @@ -15,18 +15,19 @@ export type InstructionResult = IJob | Promise | null; export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult; +export type InstructionInterface = { + run: Runner; + resume?: Runner; + getScope?: (node: FlowNodeModel, data: any, processor: Processor) => any; + duplicateConfig?: (node: FlowNodeModel, options: Transactionable) => object | Promise; +}; + // what should a instruction do? // - base on input and context, do any calculations or system call (io), and produce a result or pending. -export abstract class Instruction { +export abstract class Instruction implements InstructionInterface { constructor(public workflow: Plugin) {} abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult; - - resume?(node: FlowNodeModel, input: any, processor: Processor): InstructionResult; - - getScope?(node: FlowNodeModel, data: any, processor: Processor): any; - - duplicateConfig?(node: FlowNodeModel, options: Transactionable): object | Promise; } export default Instruction;