feat: support features (#1189)
Co-authored-by: sealday <sealday@gmail.com> Reviewed-on: daoyoucloud/tachybase#1189
This commit is contained in:
parent
5acee2f57f
commit
4d6371b119
@ -404,6 +404,10 @@ export class PluginManager {
|
|||||||
}
|
}
|
||||||
this.app.logger.debug(`before load plugin [${name}]`, { submodule: 'plugin-manager', method: 'load', name });
|
this.app.logger.debug(`before load plugin [${name}]`, { submodule: 'plugin-manager', method: 'load', name });
|
||||||
await plugin.beforeLoad();
|
await plugin.beforeLoad();
|
||||||
|
// beforeLoad features
|
||||||
|
for (const feature of plugin.featureInstances) {
|
||||||
|
await feature.beforeLoad();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
current = 0;
|
current = 0;
|
||||||
@ -426,6 +430,10 @@ export class PluginManager {
|
|||||||
await plugin.load();
|
await plugin.load();
|
||||||
plugin.state.loaded = true;
|
plugin.state.loaded = true;
|
||||||
await this.app.emitAsync('afterLoadPlugin', plugin, options);
|
await this.app.emitAsync('afterLoadPlugin', plugin, options);
|
||||||
|
// load features
|
||||||
|
for (const feature of plugin.featureInstances) {
|
||||||
|
await feature.load();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.setMaintainingMessage('loaded plugins');
|
this.app.setMaintainingMessage('loaded plugins');
|
||||||
@ -463,6 +471,10 @@ export class PluginManager {
|
|||||||
plugin.installed = true;
|
plugin.installed = true;
|
||||||
this.app.setMaintainingMessage(`after install plugin [${name}], ${current}/${total}`);
|
this.app.setMaintainingMessage(`after install plugin [${name}], ${current}/${total}`);
|
||||||
await this.app.emitAsync('afterInstallPlugin', plugin, options);
|
await this.app.emitAsync('afterInstallPlugin', plugin, options);
|
||||||
|
// install features
|
||||||
|
for (const feature of plugin.featureInstances) {
|
||||||
|
await feature.install(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await this.repository.update({
|
await this.repository.update({
|
||||||
filter: {
|
filter: {
|
||||||
|
@ -35,6 +35,8 @@ export interface PluginOptions {
|
|||||||
export abstract class Plugin<O = any> implements PluginInterface {
|
export abstract class Plugin<O = any> implements PluginInterface {
|
||||||
options: any;
|
options: any;
|
||||||
app: Application;
|
app: Application;
|
||||||
|
features: (typeof Plugin)[];
|
||||||
|
featureInstances: Plugin[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -54,6 +56,13 @@ export abstract class Plugin<O = any> implements PluginInterface {
|
|||||||
constructor(app: Application, options?: any) {
|
constructor(app: Application, options?: any) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.setOptions(options);
|
this.setOptions(options);
|
||||||
|
this.features = [];
|
||||||
|
this.featureInstances = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
addFeature<T extends Plugin>(plugin: new (app: Application, options?: any) => T) {
|
||||||
|
this.features.push(plugin);
|
||||||
|
this.featureInstances.push(new plugin(this.app, this.options));
|
||||||
}
|
}
|
||||||
|
|
||||||
get log() {
|
get log() {
|
||||||
|
@ -60,41 +60,24 @@ export default class PluginWorkflowServer extends Plugin {
|
|||||||
private loggerCache: LRUCache<string, Logger>;
|
private loggerCache: LRUCache<string, Logger>;
|
||||||
private meter = null;
|
private meter = null;
|
||||||
|
|
||||||
pluginSql: PluginSql;
|
|
||||||
pluginRequest: PluginRequest;
|
|
||||||
pluginParallel: PluginParallel;
|
|
||||||
pluginManual: PluginManual;
|
|
||||||
pluginLoop: PluginLoop;
|
|
||||||
pluginDynamicCalculation: PluginDynamicCalculation;
|
|
||||||
pluginDelay: PluginDelay;
|
|
||||||
pluginAggregate: PluginAggregate;
|
|
||||||
pluginActionTrigger: PluginActionTrigger;
|
|
||||||
pluginJSONParse: PluginWorkflowJSONParseServer;
|
|
||||||
pluginJSParse: PluginWorkflowJSParseServer;
|
|
||||||
pluginAPIRegular: PluginWorkflowAPIRegularServer;
|
|
||||||
pluginInterception: PluginInterception;
|
|
||||||
pluginVariables: PluginVariables;
|
|
||||||
pluginResponse: PluginResponse;
|
|
||||||
pluginOmni: PluginOmniTrigger;
|
|
||||||
|
|
||||||
constructor(app: Application, options?: PluginOptions) {
|
constructor(app: Application, options?: PluginOptions) {
|
||||||
super(app, options);
|
super(app, options);
|
||||||
this.pluginSql = new PluginSql(app, options);
|
this.addFeature(PluginSql);
|
||||||
this.pluginRequest = new PluginRequest(app, options);
|
this.addFeature(PluginRequest);
|
||||||
this.pluginParallel = new PluginParallel(app, options);
|
this.addFeature(PluginParallel);
|
||||||
this.pluginManual = new PluginManual(app, options);
|
this.addFeature(PluginManual);
|
||||||
this.pluginLoop = new PluginLoop(app, options);
|
this.addFeature(PluginLoop);
|
||||||
this.pluginDynamicCalculation = new PluginDynamicCalculation(app, options);
|
this.addFeature(PluginDynamicCalculation);
|
||||||
this.pluginDelay = new PluginDelay(app, options);
|
this.addFeature(PluginDelay);
|
||||||
this.pluginAggregate = new PluginAggregate(app, options);
|
this.addFeature(PluginAggregate);
|
||||||
this.pluginActionTrigger = new PluginActionTrigger(app, options);
|
this.addFeature(PluginActionTrigger);
|
||||||
this.pluginJSONParse = new PluginWorkflowJSONParseServer(app, options);
|
this.addFeature(PluginWorkflowJSONParseServer);
|
||||||
this.pluginJSParse = new PluginWorkflowJSParseServer(app, options);
|
this.addFeature(PluginWorkflowJSParseServer);
|
||||||
this.pluginAPIRegular = new PluginWorkflowAPIRegularServer(app, options);
|
this.addFeature(PluginWorkflowAPIRegularServer);
|
||||||
this.pluginInterception = new PluginInterception(app, options);
|
this.addFeature(PluginInterception);
|
||||||
this.pluginVariables = new PluginVariables(app, options);
|
this.addFeature(PluginVariables);
|
||||||
this.pluginResponse = new PluginResponse(app, options);
|
this.addFeature(PluginResponse);
|
||||||
this.pluginOmni = new PluginOmniTrigger(app, options);
|
this.addFeature(PluginOmniTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger(workflowId: ID): Logger {
|
getLogger(workflowId: ID): Logger {
|
||||||
@ -309,22 +292,6 @@ export default class PluginWorkflowServer extends Plugin {
|
|||||||
await this.executing;
|
await this.executing;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await this.pluginSql.load();
|
|
||||||
await this.pluginActionTrigger.load();
|
|
||||||
await this.pluginAggregate.load();
|
|
||||||
await this.pluginDelay.load();
|
|
||||||
await this.pluginDynamicCalculation.load();
|
|
||||||
await this.pluginLoop.load();
|
|
||||||
await this.pluginManual.load();
|
|
||||||
await this.pluginParallel.load();
|
|
||||||
await this.pluginRequest.load();
|
|
||||||
await this.pluginJSONParse.load();
|
|
||||||
await this.pluginJSParse.load();
|
|
||||||
await this.pluginAPIRegular.load();
|
|
||||||
await this.pluginInterception.load();
|
|
||||||
await this.pluginVariables.load();
|
|
||||||
await this.pluginResponse.load();
|
|
||||||
await this.pluginOmni.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle(workflow: WorkflowModel, enable?: boolean) {
|
toggle(workflow: WorkflowModel, enable?: boolean) {
|
||||||
|
Loading…
Reference in New Issue
Block a user