@nocobase/plugin-workflow 0.7.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/esm/actions/flow_nodes.d.ts +3 -0
- package/esm/actions/flow_nodes.js +139 -0
- package/esm/actions/flow_nodes.js.map +1 -0
- package/esm/actions/index.d.ts +1 -0
- package/esm/actions/index.js +8 -0
- package/esm/actions/index.js.map +1 -0
- package/esm/calculators/index.d.ts +38 -0
- package/esm/calculators/index.js +128 -0
- package/esm/calculators/index.js.map +1 -0
- package/esm/collections/executions.d.ts +3 -0
- package/esm/collections/executions.js +38 -0
- package/esm/collections/executions.js.map +1 -0
- package/esm/collections/flow_nodes.d.ts +3 -0
- package/esm/collections/flow_nodes.js +72 -0
- package/esm/collections/flow_nodes.js.map +1 -0
- package/esm/collections/jobs.d.ts +3 -0
- package/esm/collections/jobs.js +47 -0
- package/esm/collections/jobs.js.map +1 -0
- package/esm/collections/workflows.d.ts +3 -0
- package/esm/collections/workflows.js +63 -0
- package/esm/collections/workflows.js.map +1 -0
- package/esm/constants.d.ts +17 -0
- package/esm/constants.js +18 -0
- package/esm/constants.js.map +1 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +6 -0
- package/esm/index.js.map +1 -0
- package/esm/instructions/calculation.d.ts +8 -0
- package/esm/instructions/calculation.js +55 -0
- package/esm/instructions/calculation.js.map +1 -0
- package/esm/instructions/condition.d.ts +5 -0
- package/esm/instructions/condition.js +99 -0
- package/esm/instructions/condition.js.map +1 -0
- package/esm/instructions/create.d.ts +8 -0
- package/esm/instructions/create.js +25 -0
- package/esm/instructions/create.js.map +1 -0
- package/esm/instructions/destroy.d.ts +8 -0
- package/esm/instructions/destroy.js +25 -0
- package/esm/instructions/destroy.js.map +1 -0
- package/esm/instructions/index.d.ts +15 -0
- package/esm/instructions/index.js +20 -0
- package/esm/instructions/index.js.map +1 -0
- package/esm/instructions/parallel.d.ts +13 -0
- package/esm/instructions/parallel.js +88 -0
- package/esm/instructions/parallel.js.map +1 -0
- package/esm/instructions/prompt.d.ts +7 -0
- package/esm/instructions/prompt.js +13 -0
- package/esm/instructions/prompt.js.map +1 -0
- package/esm/instructions/query.d.ts +8 -0
- package/esm/instructions/query.js +25 -0
- package/esm/instructions/query.js.map +1 -0
- package/esm/instructions/update.d.ts +8 -0
- package/esm/instructions/update.js +25 -0
- package/esm/instructions/update.js.map +1 -0
- package/esm/models/Execution.d.ts +50 -0
- package/esm/models/Execution.js +250 -0
- package/esm/models/Execution.js.map +1 -0
- package/esm/models/FlowNode.d.ts +17 -0
- package/esm/models/FlowNode.js +4 -0
- package/esm/models/FlowNode.js.map +1 -0
- package/esm/models/Job.d.ts +15 -0
- package/esm/models/Job.js +4 -0
- package/esm/models/Job.js.map +1 -0
- package/esm/models/Workflow.d.ts +27 -0
- package/esm/models/Workflow.js +72 -0
- package/esm/models/Workflow.js.map +1 -0
- package/esm/server.d.ts +5 -0
- package/esm/server.js +62 -0
- package/esm/server.js.map +1 -0
- package/esm/triggers/index.d.ts +9 -0
- package/esm/triggers/index.js +6 -0
- package/esm/triggers/index.js.map +1 -0
- package/esm/triggers/model.d.ts +12 -0
- package/esm/triggers/model.js +47 -0
- package/esm/triggers/model.js.map +1 -0
- package/lib/actions/flow_nodes.d.ts +3 -0
- package/lib/actions/flow_nodes.js +163 -0
- package/lib/actions/flow_nodes.js.map +1 -0
- package/lib/actions/index.d.ts +1 -0
- package/lib/actions/index.js +30 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/calculators/index.d.ts +38 -0
- package/lib/calculators/index.js +132 -0
- package/lib/calculators/index.js.map +1 -0
- package/lib/collections/executions.d.ts +3 -0
- package/lib/collections/executions.js +40 -0
- package/lib/collections/executions.js.map +1 -0
- package/lib/collections/flow_nodes.d.ts +3 -0
- package/lib/collections/flow_nodes.js +74 -0
- package/lib/collections/flow_nodes.js.map +1 -0
- package/lib/collections/jobs.d.ts +3 -0
- package/lib/collections/jobs.js +49 -0
- package/lib/collections/jobs.js.map +1 -0
- package/lib/collections/workflows.d.ts +3 -0
- package/lib/collections/workflows.js +65 -0
- package/lib/collections/workflows.js.map +1 -0
- package/lib/constants.d.ts +17 -0
- package/lib/constants.js +21 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +23 -0
- package/lib/index.js.map +1 -0
- package/lib/instructions/calculation.d.ts +8 -0
- package/lib/instructions/calculation.js +57 -0
- package/lib/instructions/calculation.js.map +1 -0
- package/lib/instructions/condition.d.ts +5 -0
- package/lib/instructions/condition.js +120 -0
- package/lib/instructions/condition.js.map +1 -0
- package/lib/instructions/create.d.ts +8 -0
- package/lib/instructions/create.js +27 -0
- package/lib/instructions/create.js.map +1 -0
- package/lib/instructions/destroy.d.ts +8 -0
- package/lib/instructions/destroy.js +27 -0
- package/lib/instructions/destroy.js.map +1 -0
- package/lib/instructions/index.d.ts +15 -0
- package/lib/instructions/index.js +26 -0
- package/lib/instructions/index.js.map +1 -0
- package/lib/instructions/parallel.d.ts +13 -0
- package/lib/instructions/parallel.js +91 -0
- package/lib/instructions/parallel.js.map +1 -0
- package/lib/instructions/prompt.d.ts +7 -0
- package/lib/instructions/prompt.js +15 -0
- package/lib/instructions/prompt.js.map +1 -0
- package/lib/instructions/query.d.ts +8 -0
- package/lib/instructions/query.js +27 -0
- package/lib/instructions/query.js.map +1 -0
- package/lib/instructions/update.d.ts +8 -0
- package/lib/instructions/update.js +27 -0
- package/lib/instructions/update.js.map +1 -0
- package/lib/models/Execution.d.ts +50 -0
- package/lib/models/Execution.js +256 -0
- package/lib/models/Execution.js.map +1 -0
- package/lib/models/FlowNode.d.ts +17 -0
- package/lib/models/FlowNode.js +7 -0
- package/lib/models/FlowNode.js.map +1 -0
- package/lib/models/Job.d.ts +15 -0
- package/lib/models/Job.js +7 -0
- package/lib/models/Job.js.map +1 -0
- package/lib/models/Workflow.d.ts +27 -0
- package/lib/models/Workflow.js +78 -0
- package/lib/models/Workflow.js.map +1 -0
- package/lib/server.d.ts +5 -0
- package/lib/server.js +68 -0
- package/lib/server.js.map +1 -0
- package/lib/triggers/index.d.ts +9 -0
- package/lib/triggers/index.js +12 -0
- package/lib/triggers/index.js.map +1 -0
- package/lib/triggers/model.d.ts +12 -0
- package/lib/triggers/model.js +49 -0
- package/lib/triggers/model.js.map +1 -0
- package/package.json +28 -0
- package/tsconfig.build.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Execution.js","sourceRoot":"","sources":["../../src/models/Execution.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAqD;AACrD,oEAAmC;AAEnC,4CAA4D;AAC5D,mEAA2C;AAI3C,iEAAyC;AAMzC,MAAqB,cAAe,SAAQ,gBAAK;IAAjD;;QAsBE,UAAK,GAAyB,EAAE,CAAC;QACjC,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC5C,YAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;QACtC,oBAAe,GAA2B,EAAE,CAAC;IA6P/C,CAAC;IApPC,yCAAyC;IACzC,SAAS,CAAC,KAAK,GAAG,EAAE;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aACpD;YAED,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,C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AAI,qBAAW,CAAC,WAAW,EAAE,EAAE;YAChD,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpC;QAED,OAAO,IAAA,wBAAK,EAAC,KAAK,CAAC,CAAC;YAClB,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,gBAAgB,EAAE,IAAI,CAAC,eAAe;YACtC,GAAG,EAAE,WAAW;SACjB,CAAC,CAAC;IACL,CAAC;;AArRH,iCAsRC;AA3PQ,wBAAS,GAAG;IACjB,CAAC,sBAAU,CAAC,OAAO,CAAC,EAAE,4BAAgB,CAAC,OAAO;IAC9C,CAAC,sBAAU,CAAC,QAAQ,CAAC,EAAE,4BAAgB,CAAC,QAAQ;IAChD,CAAC,sBAAU,CAAC,QAAQ,CAAC,EAAE,4BAAgB,CAAC,QAAQ;IAChD,CAAC,sBAAU,CAAC,SAAS,CAAC,EAAE,4BAAgB,CAAC,SAAS;CACnD,CAAC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport parse from 'json-templates';\nimport { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin, Transaction } from 'sequelize';\nimport { EXECUTION_STATUS, JOB_STATUS } from '../constants';\nimport instructions from '../instructions';\nimport WorkflowModel from './Workflow';\nimport FlowNodeModel from './FlowNode';\nimport JobModel from './Job';\nimport calculators from '../calculators';\n\nexport interface ExecutionOptions {\n transaction?: Transaction;\n}\n\nexport default class ExecutionModel extends Model {\n declare static readonly database: Database;\n\n declare id: number;\n declare title: string;\n declare context: any;\n declare status: number;\n // NOTE: this duplicated column is for transaction in preparing cycle from workflow\n declare useTransaction: boolean;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare workflow?: WorkflowModel;\n declare getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;\n\n declare jobs?: JobModel[];\n declare getJobs: HasManyGetAssociationsMixin<JobModel>;\n\n options: ExecutionOptions;\n transaction: Transaction;\n\n nodes: Array<FlowNodeModel> = [];\n nodesMap = new Map<number, FlowNodeModel>();\n jobsMap = new Map<number, JobModel>();\n jobsMapByNodeId: { [key: number]: any } = {};\n\n static StatusMap = {\n [JOB_STATUS.PENDING]: EXECUTION_STATUS.STARTED,\n [JOB_STATUS.RESOLVED]: EXECUTION_STATUS.RESOLVED,\n [JOB_STATUS.REJECTED]: EXECUTION_STATUS.REJECTED,\n [JOB_STATUS.CANCELLED]: EXECUTION_STATUS.CANCELLED,\n };\n\n // make dual linked nodes list then cache\n makeNodes(nodes = []) {\n this.nodes = nodes;\n\n nodes.forEach((node) => {\n this.nodesMap.set(node.id, node);\n });\n\n nodes.forEach((node) => {\n if (node.upstreamId) {\n node.upstream = this.nodesMap.get(node.upstreamId);\n }\n\n if (node.downstreamId) {\n node.downstream = this.nodesMap.get(node.downstreamId);\n }\n });\n }\n\n makeJobs(jobs: Array<JobModel>) {\n jobs.forEach((job) => {\n this.jobsMap.set(job.id, job);\n // TODO: should consider cycle, and from previous job\n this.jobsMapByNodeId[job.nodeId] = job.result;\n });\n }\n\n getTransaction() {\n const { sequelize } = (<typeof WorkflowModel>this.constructor).database;\n // @ts-ignore\n if (!this.useTransaction) {\n return undefined;\n }\n\n const { options } = this;\n\n // @ts-ignore\n return options.transaction && !options.transaction.finished\n ? options.transaction\n : sequelize.transaction();\n }\n\n async prepare(options, commit = false) {\n this.options = options || {};\n // @ts-ignore\n const transaction = await this.getTransaction()\n this.transaction = transaction;\n\n if (!this.workflow) {\n this.workflow = await this.getWorkflow({ transaction });\n }\n\n const nodes = await this.workflow.getNodes({ transaction });\n\n this.makeNodes(nodes);\n\n const jobs = await this.getJobs({\n order: [['id', 'ASC']],\n transaction,\n });\n\n this.makeJobs(jobs);\n\n if (commit) {\n await this.commit();\n }\n }\n\n public async start(options: ExecutionOptions) {\n if (this.status !== EXECUTION_STATUS.STARTED) {\n throw new Error(`execution was ended with status ${this.status}`);\n }\n await this.prepare(options);\n if (this.nodes.length) {\n const head = this.nodes.find(item => !item.upstream);\n await this.run(head, { result: this.context });\n } else {\n await this.exit(null);\n }\n await this.commit();\n }\n\n public async resume(job: JobModel, options: ExecutionOptions) {\n if (this.status !== EXECUTION_STATUS.STARTED) {\n throw new Error(`execution was ended with status ${this.status}`);\n }\n await this.prepare(options);\n const node = this.nodesMap.get(job.nodeId);\n await this.recall(node, job);\n await this.commit();\n }\n\n private async commit() {\n // @ts-ignore\n if (this.transaction && (!this.options.transaction || this.options.transaction.finished)) {\n await this.transaction.commit();\n }\n }\n\n private async exec(instruction: Function, node: FlowNodeModel, prevJob) {\n let job;\n try {\n // call instruction to get result and status\n job = await instruction.call(node, prevJob, this);\n if (!job) {\n return null;\n }\n } catch (err) {\n // for uncaught error, set to rejected\n job = {\n result: err instanceof Error\n ? { message: err.message, stack: process.env.NODE_ENV === 'production' ? [] : err.stack }\n : err,\n status: JOB_STATUS.REJECTED,\n };\n // if previous job is from resuming\n if (prevJob && prevJob.nodeId === node.id) {\n prevJob.set(job);\n job = prevJob;\n }\n }\n\n let savedJob;\n // TODO(optimize): many checking of resuming or new could be improved\n // could be implemented separately in exec() / resume()\n if (job instanceof Model) {\n savedJob = (await job.save({ transaction: this.transaction })) as unknown as JobModel;\n } else {\n const upstreamId = prevJob instanceof Model ? prevJob.get('id') : null;\n savedJob = await this.saveJob({\n nodeId: node.id,\n upstreamId,\n ...job,\n });\n }\n\n if (savedJob.status === JOB_STATUS.RESOLVED && node.downstream) {\n // run next node\n return this.run(node.downstream, savedJob);\n }\n\n // all nodes in scope have been executed\n return this.end(node, savedJob);\n }\n\n public async run(node, input?) {\n const { run } = instructions.get(node.type);\n if (typeof run !== 'function') {\n return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));\n }\n\n return this.exec(run, node, input);\n }\n\n // parent node should take over the control\n public end(node, job) {\n const parentNode = this.findBranchParentNode(node);\n // no parent, means on main flow\n if (parentNode) {\n return this.recall(parentNode, job);\n }\n\n // really done for all nodes\n // * should mark execution as done with last job status\n return this.exit(job);\n }\n\n async recall(node, job) {\n const { resume } = instructions.get(node.type);\n if (typeof resume !== 'function') {\n return Promise.reject(new Error('`resume` should be implemented because the node made branch'));\n }\n\n return this.exec(resume, node, job);\n }\n\n async exit(job: JobModel | null) {\n const status = job ? ExecutionModel.StatusMap[job.status] : EXECUTION_STATUS.RESOLVED;\n await this.update({ status }, { transaction: this.transaction });\n return null;\n }\n\n // TODO(optimize)\n async saveJob(payload) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { model } = database.getCollection('jobs');\n const [job] = (await model.upsert(\n {\n ...payload,\n executionId: this.id,\n },\n { transaction: this.transaction },\n )) as unknown as [JobModel, boolean | null];\n this.jobsMap.set(job.id, job);\n this.jobsMapByNodeId[job.nodeId] = job.result;\n\n return job;\n }\n\n // find the first node in current branch\n findBranchStartNode(node: FlowNodeModel): FlowNodeModel | null {\n for (let n = node; n; n = n.upstream) {\n if (n.branchIndex !== null) {\n return n;\n }\n }\n return null;\n }\n\n // find the node start current branch\n findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null {\n for (let n = node; n; n = n.upstream) {\n if (n.branchIndex !== null) {\n return n.upstream;\n }\n }\n return null;\n }\n\n findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null {\n for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {\n if (j.nodeId === node.id) {\n return j;\n }\n }\n return null;\n }\n\n public getParsedValue(value, node?) {\n const injectedFns = {};\n const scope = {\n execution: this,\n node\n };\n for (let [name, fn] of calculators.getEntities()) {\n injectedFns[name] = fn.bind(scope);\n }\n\n return parse(value)({\n $context: this.context,\n $jobsMapByNodeId: this.jobsMapByNodeId,\n $fn: injectedFns\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Database, Model } from '@nocobase/database';
|
|
2
|
+
import { BelongsToGetAssociationMixin } from 'sequelize';
|
|
3
|
+
import WorkflowModel from './Workflow';
|
|
4
|
+
export default class FlowNodeModel extends Model {
|
|
5
|
+
static readonly database: Database;
|
|
6
|
+
id: number;
|
|
7
|
+
title: string;
|
|
8
|
+
branchIndex: null | number;
|
|
9
|
+
type: string;
|
|
10
|
+
config: any;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
upstream: FlowNodeModel;
|
|
14
|
+
downstream: FlowNodeModel;
|
|
15
|
+
workflow?: WorkflowModel;
|
|
16
|
+
getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowNode.js","sourceRoot":"","sources":["../../src/models/FlowNode.ts"],"names":[],"mappings":";;AAAA,iDAAqD;AAKrD,MAAqB,aAAc,SAAQ,gBAAK;CAiB/C;AAjBD,gCAiBC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport WorkflowModel from './Workflow';\n\n\nexport default class FlowNodeModel extends Model {\n declare static readonly database: Database;\n\n declare id: number;\n declare title: string;\n declare branchIndex: null | number;\n declare type: string;\n declare config: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstream: FlowNodeModel;\n declare downstream: FlowNodeModel;\n\n declare workflow?: WorkflowModel;\n declare getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model } from '@nocobase/database';
|
|
2
|
+
import { BelongsToGetAssociationMixin } from 'sequelize';
|
|
3
|
+
import FlowNodeModel from './FlowNode';
|
|
4
|
+
export default class JobModel extends Model {
|
|
5
|
+
id: number;
|
|
6
|
+
status: number;
|
|
7
|
+
result: any;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
upstreamId: number;
|
|
11
|
+
upstream: JobModel;
|
|
12
|
+
nodeId: number;
|
|
13
|
+
node?: FlowNodeModel;
|
|
14
|
+
getNode: BelongsToGetAssociationMixin<FlowNodeModel>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../src/models/Job.ts"],"names":[],"mappings":";;AAAA,iDAA2C;AAI3C,MAAqB,QAAS,SAAQ,gBAAK;CAc1C;AAdD,2BAcC","sourcesContent":["import { Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport FlowNodeModel from './FlowNode';\n\nexport default class JobModel extends Model {\n declare id: number;\n declare status: number;\n declare result: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstreamId: number;\n declare upstream: JobModel;\n\n declare nodeId: number;\n declare node?: FlowNodeModel;\n declare getNode: BelongsToGetAssociationMixin<FlowNodeModel>;\n}"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Database, Model } from '@nocobase/database';
|
|
2
|
+
import { HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
|
|
3
|
+
import ExecutionModel from './Execution';
|
|
4
|
+
import FlowNodeModel from './FlowNode';
|
|
5
|
+
export default class WorkflowModel extends Model {
|
|
6
|
+
static database: Database;
|
|
7
|
+
id: number;
|
|
8
|
+
title: string;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
description?: string;
|
|
11
|
+
type: string;
|
|
12
|
+
config: any;
|
|
13
|
+
useTransaction: boolean;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
nodes: FlowNodeModel[];
|
|
17
|
+
getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;
|
|
18
|
+
createNode: HasManyCreateAssociationMixin<FlowNodeModel>;
|
|
19
|
+
executions: ExecutionModel[];
|
|
20
|
+
getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;
|
|
21
|
+
createExecution: HasManyCreateAssociationMixin<ExecutionModel>;
|
|
22
|
+
static mount(): Promise<void>;
|
|
23
|
+
getHookId(): string;
|
|
24
|
+
getTransaction(options: any): any;
|
|
25
|
+
toggle(enable?: boolean): Promise<void>;
|
|
26
|
+
trigger(context: Object, options: any): Promise<ExecutionModel>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const database_1 = require("@nocobase/database");
|
|
16
|
+
const triggers_1 = __importDefault(require("../triggers"));
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
class WorkflowModel extends database_1.Model {
|
|
19
|
+
static mount() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const collection = this.database.getCollection('workflows');
|
|
22
|
+
const workflows = yield collection.repository.find({
|
|
23
|
+
filter: { enabled: true },
|
|
24
|
+
});
|
|
25
|
+
workflows.forEach((workflow) => {
|
|
26
|
+
workflow.toggle();
|
|
27
|
+
});
|
|
28
|
+
this.addHook('afterCreate', (model) => model.toggle());
|
|
29
|
+
this.addHook('afterUpdate', (model) => model.toggle());
|
|
30
|
+
this.addHook('afterDestroy', (model) => model.toggle(false));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
getHookId() {
|
|
34
|
+
return `workflow-${this.get('id')}`;
|
|
35
|
+
}
|
|
36
|
+
getTransaction(options) {
|
|
37
|
+
if (!this.useTransaction) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return options.transaction && !options.transaction.finished
|
|
41
|
+
? options.transaction
|
|
42
|
+
: this.constructor.database.sequelize.transaction();
|
|
43
|
+
}
|
|
44
|
+
toggle(enable) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const type = this.get('type');
|
|
47
|
+
const { on, off } = triggers_1.default.get(type);
|
|
48
|
+
if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {
|
|
49
|
+
on.call(this, this.trigger.bind(this));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
off.call(this);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
trigger(context, options) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
// `null` means not to trigger
|
|
59
|
+
if (context === null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const transaction = yield this.getTransaction(options);
|
|
63
|
+
const execution = yield this.createExecution({
|
|
64
|
+
context,
|
|
65
|
+
status: constants_1.EXECUTION_STATUS.STARTED,
|
|
66
|
+
useTransaction: this.useTransaction
|
|
67
|
+
}, { transaction });
|
|
68
|
+
execution.workflow = this;
|
|
69
|
+
yield execution.start({ transaction });
|
|
70
|
+
if (transaction && (!options.transaction || options.transaction.finished)) {
|
|
71
|
+
yield transaction.commit();
|
|
72
|
+
}
|
|
73
|
+
return execution;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = WorkflowModel;
|
|
78
|
+
//# sourceMappingURL=Workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Workflow.js","sourceRoot":"","sources":["../../src/models/Workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAqD;AAGrD,2DAAmC;AACnC,4CA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,CAAC,CAAC;YAC9B,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,kBAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBAChE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACxC;iBAAM;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChB;QACH,CAAC;KAAA;IAEK,OAAO,CAAC,OAAe,EAAE,OAAO;;YACpC,8BAA8B;YAC9B,IAAI,OAAO,KAAK,IAAI,EAAE;gBACpB,OAAO;aACR;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAEvD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC;gBAC3C,OAAO;gBACP,MAAM,EAAE,4BAAgB,CAAC,OAAO;gBAChC,cAAc,EAAE,IAAI,CAAC,cAAc;aACpC,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;YAEpB,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;YAE1B,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;YAEvC,IAAI,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;gBACzE,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;aAC5B;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;CACF;AArFD,gCAqFC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';\n\nimport triggers from '../triggers';\nimport { EXECUTION_STATUS } from '../constants';\nimport ExecutionModel from './Execution';\nimport FlowNodeModel from './FlowNode';\n\nexport default class WorkflowModel extends Model {\n declare static database: Database;\n\n declare id: number;\n declare title: string;\n declare enabled: boolean;\n declare description?: string;\n declare type: string;\n declare config: any;\n declare useTransaction: boolean;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare nodes: FlowNodeModel[];\n declare getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;\n declare createNode: HasManyCreateAssociationMixin<FlowNodeModel>;\n\n declare executions: ExecutionModel[];\n declare getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;\n declare createExecution: HasManyCreateAssociationMixin<ExecutionModel>;\n\n static async mount() {\n const collection = this.database.getCollection('workflows');\n const workflows = await collection.repository.find({\n filter: { enabled: true },\n });\n\n workflows.forEach((workflow: WorkflowModel) => {\n workflow.toggle();\n });\n\n this.addHook('afterCreate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterUpdate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterDestroy', (model: WorkflowModel) => model.toggle(false));\n }\n\n getHookId() {\n return `workflow-${this.get('id')}`;\n }\n\n getTransaction(options) {\n if (!this.useTransaction) {\n return undefined;\n }\n\n return options.transaction && !options.transaction.finished\n ? options.transaction\n : (<typeof WorkflowModel>this.constructor).database.sequelize.transaction();\n }\n\n async toggle(enable?: boolean) {\n const type = this.get('type');\n const { on, off } = triggers.get(type);\n if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {\n on.call(this, this.trigger.bind(this));\n } else {\n off.call(this);\n }\n }\n\n async trigger(context: Object, options) {\n // `null` means not to trigger\n if (context === null) {\n return;\n }\n\n const transaction = await this.getTransaction(options);\n\n const execution = await this.createExecution({\n context,\n status: EXECUTION_STATUS.STARTED,\n useTransaction: this.useTransaction\n }, { transaction });\n\n execution.workflow = this;\n\n await execution.start({ transaction });\n\n if (transaction && (!options.transaction || options.transaction.finished)) {\n await transaction.commit();\n }\n\n return execution;\n }\n}\n"]}
|
package/lib/server.d.ts
ADDED
package/lib/server.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const server_1 = require("@nocobase/server");
|
|
17
|
+
const Workflow_1 = __importDefault(require("./models/Workflow"));
|
|
18
|
+
const Execution_1 = __importDefault(require("./models/Execution"));
|
|
19
|
+
const actions_1 = __importDefault(require("./actions"));
|
|
20
|
+
class WorkflowPlugin extends server_1.Plugin {
|
|
21
|
+
load(options = {}) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const { db } = this.app;
|
|
24
|
+
db.registerModels({
|
|
25
|
+
WorkflowModel: Workflow_1.default,
|
|
26
|
+
ExecutionModel: Execution_1.default,
|
|
27
|
+
});
|
|
28
|
+
yield db.import({
|
|
29
|
+
directory: path_1.default.resolve(__dirname, 'collections'),
|
|
30
|
+
});
|
|
31
|
+
(0, actions_1.default)(this.app);
|
|
32
|
+
// [Life Cycle]:
|
|
33
|
+
// * load all workflows in db
|
|
34
|
+
// * add all hooks for enabled workflows
|
|
35
|
+
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
36
|
+
this.app.on('beforeStart', () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { model } = db.getCollection('workflows');
|
|
38
|
+
yield model.mount();
|
|
39
|
+
}));
|
|
40
|
+
// [Life Cycle]: initialize all necessary seed data
|
|
41
|
+
this.app.on('db.init', () => __awaiter(this, void 0, void 0, function* () { }));
|
|
42
|
+
// const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
|
|
43
|
+
// Automation.addHook('afterCreate', async (model: AutomationModel) => {
|
|
44
|
+
// model.get('enabled') && await model.loadJobs();
|
|
45
|
+
// });
|
|
46
|
+
// Automation.addHook('afterUpdate', async (model: AutomationModel) => {
|
|
47
|
+
// if (!model.changed('enabled' as any)) {
|
|
48
|
+
// return;
|
|
49
|
+
// }
|
|
50
|
+
// model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
|
|
51
|
+
// });
|
|
52
|
+
// Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
|
|
53
|
+
// await model.cancelJobs();
|
|
54
|
+
// });
|
|
55
|
+
// AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
|
|
56
|
+
// await model.bootstrap();
|
|
57
|
+
// });
|
|
58
|
+
// AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
|
|
59
|
+
// await model.cancel();
|
|
60
|
+
// });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getName() {
|
|
64
|
+
return this.getPackageName(__dirname);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = WorkflowPlugin;
|
|
68
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,6CAA0C;AAE1C,iEAA8C;AAC9C,mEAAgD;AAChD,wDAAgC;AAEhC,M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models/Workflow';\nimport ExecutionModel from './models/Execution';\nimport actions from './actions';\n\nexport default class WorkflowPlugin extends Plugin {\n async load(options = {}) {\n const { db } = this.app;\n\n db.registerModels({\n WorkflowModel,\n ExecutionModel,\n });\n\n await db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n actions(this.app);\n\n // [Life Cycle]:\n // * load all workflows in db\n // * add all hooks for enabled workflows\n // * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks\n this.app.on('beforeStart', async () => {\n const { model } = db.getCollection('workflows');\n await (model as typeof WorkflowModel).mount();\n });\n\n // [Life Cycle]: initialize all necessary seed data\n this.app.on('db.init', async () => {});\n\n // const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);\n\n // Automation.addHook('afterCreate', async (model: AutomationModel) => {\n // model.get('enabled') && await model.loadJobs();\n // });\n\n // Automation.addHook('afterUpdate', async (model: AutomationModel) => {\n // if (!model.changed('enabled' as any)) {\n // return;\n // }\n // model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();\n // });\n\n // Automation.addHook('beforeDestroy', async (model: AutomationModel) => {\n // await model.cancelJobs();\n // });\n\n // AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {\n // await model.bootstrap();\n // });\n\n // AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {\n // await model.cancel();\n // });\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Registry } from '@nocobase/utils';
|
|
2
|
+
import WorkflowModel from '../models/Workflow';
|
|
3
|
+
export interface Trigger {
|
|
4
|
+
name: string;
|
|
5
|
+
on(this: WorkflowModel, callback: Function): void;
|
|
6
|
+
off(this: WorkflowModel): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const triggers: Registry<Trigger>;
|
|
9
|
+
export default triggers;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.triggers = void 0;
|
|
7
|
+
const utils_1 = require("@nocobase/utils");
|
|
8
|
+
const model_1 = __importDefault(require("./model"));
|
|
9
|
+
exports.triggers = new utils_1.Registry();
|
|
10
|
+
exports.default = exports.triggers;
|
|
11
|
+
exports.triggers.register(model_1.default.name, model_1.default);
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/triggers/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAE3C,oDAAmC;AAQtB,QAAA,QAAQ,GAAG,IAAI,gBAAQ,EAAW,CAAC;AAEhD,kBAAe,gBAAQ,CAAC;AAExB,gBAAQ,CAAC,QAAQ,CAAC,eAAY,CAAC,IAAI,EAAE,eAAY,CAAC,CAAC","sourcesContent":["import { Registry } from '@nocobase/utils';\nimport WorkflowModel from '../models/Workflow';\nimport modelTrigger from './model';\n\nexport interface Trigger {\n name: string;\n on(this: WorkflowModel, callback: Function): void;\n off(this: WorkflowModel): void;\n}\n\nexport const triggers = new Registry<Trigger>();\n\nexport default triggers;\n\ntriggers.register(modelTrigger.name, modelTrigger);\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import WorkflowModel from "../models/Workflow";
|
|
2
|
+
export interface ModelChangeTriggerConfig {
|
|
3
|
+
collection: string;
|
|
4
|
+
mode: number;
|
|
5
|
+
filter: any;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: {
|
|
8
|
+
name: string;
|
|
9
|
+
on(this: WorkflowModel, callback: Function): void;
|
|
10
|
+
off(this: WorkflowModel): void;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const MODE_BITMAP = {
|
|
4
|
+
CREATE: 1,
|
|
5
|
+
UPDATE: 2,
|
|
6
|
+
DESTROY: 4
|
|
7
|
+
};
|
|
8
|
+
const MODE_BITMAP_EVENTS = new Map();
|
|
9
|
+
MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
|
|
10
|
+
MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
|
|
11
|
+
MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
|
|
12
|
+
exports.default = {
|
|
13
|
+
name: 'model',
|
|
14
|
+
on(callback) {
|
|
15
|
+
const { database } = this.constructor;
|
|
16
|
+
const { collection, mode, filter } = this.config;
|
|
17
|
+
const Collection = database.getCollection(collection);
|
|
18
|
+
if (!Collection) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// async function, should return promise
|
|
22
|
+
const handler = (data, options) => {
|
|
23
|
+
if (filter) {
|
|
24
|
+
// TODO: check all conditions in filter against data
|
|
25
|
+
}
|
|
26
|
+
return callback({ data: data.get() }, options);
|
|
27
|
+
};
|
|
28
|
+
// TODO: duplication when mode change should be considered
|
|
29
|
+
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
30
|
+
if (mode & key) {
|
|
31
|
+
Collection.model.addHook(event, this.getHookId(), handler);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
off() {
|
|
36
|
+
const { database } = this.constructor;
|
|
37
|
+
const { collection, mode } = this.config;
|
|
38
|
+
const Collection = database.getCollection(collection);
|
|
39
|
+
if (!Collection) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
43
|
+
if (mode & key) {
|
|
44
|
+
Collection.model.removeHook(event, this.getHookId());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
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K,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;aAC5D;SACF;IACH,CAAC;IACD,GAAG;QACD,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;SACF;IACH,CAAC;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n filter: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode, filter } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // async function, should return promise\n const handler = (data: any, options) => {\n if (filter) {\n // TODO: check all conditions in filter against data\n }\n return callback({ data: data.get() }, options);\n };\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), handler);\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-workflow",
|
|
3
|
+
"version": "0.7.0-alpha.0",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"licenses": [
|
|
7
|
+
{
|
|
8
|
+
"type": "Apache-2.0",
|
|
9
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
|
|
14
|
+
"build:cjs": "tsc --project tsconfig.build.json",
|
|
15
|
+
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@nocobase/actions": "0.7.0-alpha.0",
|
|
19
|
+
"@nocobase/database": "0.7.0-alpha.0",
|
|
20
|
+
"@nocobase/server": "0.7.0-alpha.0",
|
|
21
|
+
"@nocobase/utils": "0.7.0-alpha.0",
|
|
22
|
+
"json-templates": "^4.2.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@nocobase/test": "0.7.0-alpha.0"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "82167c6c4781195ae536cbc35c3c0006f655e044"
|
|
28
|
+
}
|