c5f089d7b7
* test: skip bug test cases for ci passing * feat: add base structure of plugin-permissions * fix: user token parsing * Refactor action parameter for better mergeParams (#55) * refactor: add parameter types to handle parameters in action [WIP] * fix: action parameter * fix: test cases * test: try to fix build error * remove unused packages * fix: revert compatibility back Co-authored-by: chenos <chenlinxh@gmail.com> * 补充权限界面相关功能 * bugfix * fix: developer mode does not work * feat: add action scope and fields limitation in permission * 改进权限配置表单 * feat: get/update action for role.collection * add scope select component * add role users tabs * typings * test: temp skip Co-authored-by: chenos <chenlinxh@gmail.com>
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import Koa from 'koa';
|
|
import Database, { DatabaseOptions } from '@nocobase/database';
|
|
import Resourcer from '@nocobase/resourcer';
|
|
|
|
export interface ApplicationOptions {
|
|
database: DatabaseOptions;
|
|
resourcer?: any;
|
|
}
|
|
|
|
export class Application extends Koa {
|
|
|
|
public readonly database: Database;
|
|
|
|
public readonly resourcer: Resourcer;
|
|
|
|
protected plugins = new Map<string, any>();
|
|
|
|
constructor(options: ApplicationOptions) {
|
|
super();
|
|
this.database = new Database(options.database);
|
|
this.resourcer = new Resourcer();
|
|
// this.runHook('afterInit');
|
|
}
|
|
|
|
registerPlugin(key: string | object, plugin?: any) {
|
|
if (typeof key === 'object') {
|
|
Object.keys(key).forEach((k) => {
|
|
this.registerPlugin(k, key[k]);
|
|
});
|
|
} else {
|
|
const config = {};
|
|
if (Array.isArray(plugin)) {
|
|
const [entry, options = {}] = plugin;
|
|
Object.assign(config, { entry, options });
|
|
} else {
|
|
Object.assign(config, { entry: plugin, options: {} });
|
|
}
|
|
this.plugins.set(key, config);
|
|
}
|
|
}
|
|
|
|
getPluginInstance(key: string) {
|
|
const plugin = this.plugins.get(key);
|
|
return plugin && plugin.instance;
|
|
}
|
|
|
|
async loadPlugins() {
|
|
for (const plugin of this.plugins.values()) {
|
|
plugin.instance = await this.loadPlugin(plugin);
|
|
}
|
|
}
|
|
|
|
protected async loadPlugin({ entry, options = {} }: { entry: string | Function, options: any }) {
|
|
const main = typeof entry === 'function'
|
|
? entry
|
|
: require(`${entry}/${__filename.endsWith('.ts') ? 'src' : 'lib'}/server`).default;
|
|
|
|
return await main.call(this, options);
|
|
}
|
|
}
|
|
|
|
export default Application;
|