Merge pull request #190 from nocobase/plugin-workflow

Refactor(plugin-workflow): upgrade plugin to use abstract plugin class and fix types
This commit is contained in:
Junyi 2022-02-13 22:56:48 +08:00 committed by GitHub
commit be489996c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 18 deletions

View File

@ -4,6 +4,11 @@
"main": "lib/index.js",
"private": true,
"license": "MIT",
"scripts": {
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --project tsconfig.build.json",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
},
"dependencies": {
},
"devDependencies": {

View File

@ -15,7 +15,7 @@
// }
// }
import Sequelize = require('sequelize');
import Sequelize from 'sequelize';
import { getValue, Operand } from "../utils/getter";
import { getCalculator } from "../utils/calculators";
import { JOB_STATUS } from "../constants";

View File

@ -1,7 +1,6 @@
import {
Model,
BelongsToGetAssociationMixin,
Optional,
HasManyGetAssociationsMixin,
Transaction
} from 'sequelize';
@ -14,23 +13,11 @@ import WorkflowModel from './Workflow';
import FlowNodeModel from './FlowNode';
import JobModel from './Job';
interface ExecutionAttributes {
id: number;
title: string;
context: any;
status: number;
}
interface ExecutionCreationAttributes extends Optional<ExecutionAttributes, 'id'> {}
export interface ExecutionOptions {
transaction?: Transaction;
}
export default class ExecutionModel
extends Model<ExecutionAttributes, ExecutionCreationAttributes>
implements ExecutionAttributes {
export default class ExecutionModel extends Model {
declare static readonly database: Database;
declare id: number;

View File

@ -1,10 +1,11 @@
import path from 'path';
import { Plugin } from '@nocobase/server';
import WorkflowModel from './models/Workflow';
import ExecutionModel from './models/Execution';
export default {
name: 'workflow',
export default class WorkflowPlugin extends Plugin {
async load(options = {}) {
const { db } = this.app;
@ -23,7 +24,7 @@ export default {
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
this.app.on('beforeStart', async () => {
const { model } = db.getCollection('workflows');
await model.mount();
await (model as typeof WorkflowModel).mount();
})
// [Life Cycle]: initialize all necessary seed data

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "./lib",
"declaration": true
},
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["./src/__tests__/*", "./esm/*", "./lib/*"]
}

View File

@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["./esm/*", "./lib/*"]
}