Commit f8e998c1 authored by nanahira's avatar nanahira

auto register schema

parent 5e678ce0
......@@ -13,7 +13,7 @@ npm install koishi-thirdeye koishi@next
可以简单定义类以快速开发 Koishi 插件。
```ts
import { KoishiPlugin, DefineSchema, CommandUsage, PutOption, UseCommand OnApply } from 'koishi-thirdeye'
import { KoishiPlugin, DefineSchema, CommandUsage, PutOption, UseCommand, OnApply } from 'koishi-thirdeye'
export class MyPluginConfig {
@DefineSchema({ default: 'bar' })
......@@ -24,7 +24,7 @@ export class MyPluginConfig {
export default class MyPlugin implements OnApply {
constructor(private ctx: Context, private config: Partial<MyPluginConfig>) {
}
onApply() {
// 该方法会在插件加载时调用,用于在上下文中注册事件等操作。
}
......@@ -47,7 +47,7 @@ export default class MyPlugin implements OnApply {
* `schema` 插件的配置描述模式。可以是 Schema 描述模式,也可以是由 `schemastery-gen` 生成的 Schema 类。
koishi-thirdeye 内建了 `schemastery-gen` 的支持。只需要导入这1个包即可。
koishi-thirdeye 内建了 `schemastery-gen` 的支持。只需要导入这1个包即可。另外,系统会自动进行 `@RegisterSchema` 的配置描述的注册。
## API
......
......@@ -17,6 +17,7 @@ import {
} from './def';
import { reflector } from './meta/meta-fetch';
import { applySelector } from './utility/utility';
import { RegisterSchema } from 'schemastery-gen';
export interface KoishiPluginRegistrationOptions<T = any> {
name?: string;
......@@ -56,7 +57,9 @@ export function KoishiPlugin<T = any>(
C extends { new (...args: any[]): any; schema?: Schema; name?: string }
>(originalClass: C) {
const newClass = class extends originalClass implements PluginClass {
static schema = options.schema;
static schema = (options.schema as Schema).type
? options.schema
: RegisterSchema()(options.schema);
__ctx: Context;
__config: T;
__pluginOptions: KoishiPluginRegistrationOptions<T>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment