Commit 184cb41e authored by nanahira's avatar nanahira

rename KoishiPlugin to DefinePlugin

parent 3291f64e
Pipeline #8278 passed with stages
in 1 minute and 16 seconds
......@@ -13,7 +13,7 @@ npm install koishi-thirdeye koishi
可以简单定义类以快速开发 Koishi 插件。
```ts
import { KoishiPlugin, SchemaProperty, CommandUsage, PutOption, UseCommand, OnApply, KoaContext, UseMiddleware, UseEvent, Get } from 'koishi-thirdeye';
import { DefinePlugin, SchemaProperty, CommandUsage, PutOption, UseCommand, OnApply, KoaContext, UseMiddleware, UseEvent, Get } from 'koishi-thirdeye';
import { Context, Session } from 'koishi';
export class MyPluginConfig {
......@@ -21,7 +21,7 @@ export class MyPluginConfig {
foo: string;
}
@KoishiPlugin({ name: 'my-plugin', schema: MyPluginConfig })
@DefinePlugin({ name: 'my-plugin', schema: MyPluginConfig })
export default class MyPlugin implements OnApply {
constructor(private ctx: Context, private config: Partial<MyPluginConfig>) {
}
......@@ -55,7 +55,7 @@ export default class MyPlugin implements OnApply {
## 使用
使用 koishi-thirdeye 编写的插件,需要在插件类上使用 `@KoishiPlugin(options: KoishiPluginRegistrationOptions)` 装饰器。
使用 koishi-thirdeye 编写的插件,需要在插件类上使用 `@DefinePlugin(options: DefinePluginRegistrationOptions)` 装饰器。
您可以在参数中指定该插件的基本信息。
......@@ -68,7 +68,7 @@ koishi-thirdeye 内建了 `schemastery-gen` 的支持。只需要导入这1个
最基本的插件定义方式如下:
```ts
import { KoishiPlugin, SchemaProperty, InjectConfig } from 'koishi-thirdeye';
import { DefinePlugin, SchemaProperty, InjectConfig } from 'koishi-thirdeye';
import { Context, Session } from 'koishi';
export class MyPluginConfig {
......@@ -76,7 +76,7 @@ export class MyPluginConfig {
foo: string;
}
@KoishiPlugin({ name: 'my-plugin', schema: MyPluginConfig })
@DefinePlugin({ name: 'my-plugin', schema: MyPluginConfig })
export default class MyPlugin {
constructor(private ctx: Context, private config: Partial<MyPluginConfig>) {
}
......@@ -92,10 +92,10 @@ export default class MyPlugin {
您可以使用 `this.ctx` 以及 `this.config` 进行访问上下文对象以及插件配置。因此上面的例子可以简化为下面的代码:
> `@KoishiPlugin` 装饰器不可省略。
> `@DefinePlugin` 装饰器不可省略。
```ts
import { KoishiPlugin, SchemaProperty, BasePlugin } from 'koishi-thirdeye';
import { DefinePlugin, SchemaProperty, BasePlugin } from 'koishi-thirdeye';
import { Context, Session } from 'koishi';
export class MyPluginConfig {
......@@ -103,7 +103,7 @@ export class MyPluginConfig {
foo: string;
}
@KoishiPlugin({ name: 'my-plugin', schema: MyPluginConfig })
@DefinePlugin({ name: 'my-plugin', schema: MyPluginConfig })
export default class MyPlugin extends BasePlugin<MyPluginConfig> {
}
......@@ -235,7 +235,7 @@ koishi-thirdeye 使用一组装饰器进行描述指令的行为。这些装饰
import { Inject, UseEvent } from 'koishi-thirdeye';
import { Cache } from 'koishi';
@KoishiPlugin({ name: 'my-plugin' })
@DefinePlugin({ name: 'my-plugin' })
export class MyPlugin {
constructor(private ctx: Context, private config: any) {
}
......@@ -280,7 +280,7 @@ declare module 'koishi' {
// `@Provide(name)` 装饰器会自动完成 `Context.service(name)` 的声明操作
@Provide('myService')
@KoishiPlugin({ name: 'my-database' })
@DefinePlugin({ name: 'my-database' })
export class MyDatabasePlugin {
// 该类会作为 Koishi 的 Service 供其他 Koishi 插件进行引用
}
......
......@@ -59,7 +59,7 @@ function getContextFromFilters(ctx: Context, filters: OnContextFunction[]) {
return targetCtx;
}
export function KoishiPlugin<T = any>(
export function DefinePlugin<T = any>(
options: KoishiPluginRegistrationOptions<T> = {},
) {
return function <
......@@ -382,3 +382,5 @@ export function KoishiPlugin<T = any>(
return newClass;
};
}
export const KoishiPlugin = DefinePlugin;
import { App } from 'koishi';
import { KoishiPlugin } from '../src/register';
import { DefinePlugin } from '../src/register';
import { Get } from '../src/decorators';
import { KoaContext } from '../src/def';
import request from 'supertest';
@KoishiPlugin()
@DefinePlugin()
class MyPlugin {
@Get('ping')
async ping(ctx: KoaContext) {
......
import { Inject, KoishiPlugin } from '..';
import { Inject, DefinePlugin } from '..';
import { Cache, Assets, Bot, Context } from 'koishi';
describe('InjectUsing', () => {
@KoishiPlugin({ using: ['database'] })
@DefinePlugin({ using: ['database'] })
class MyPlugin {
@Inject(true)
cache: Cache;
......
import { App, Context } from 'koishi';
import {
KoishiPlugin,
DefinePlugin,
OnApply,
OnConnect,
OnDisconnect,
......@@ -19,15 +19,15 @@ declare module 'koishi' {
}
@Provide('immediateDependency', { immediate: true })
@KoishiPlugin()
@DefinePlugin()
class ImmediateDependency {}
@Provide('nonImmediateDependency')
@KoishiPlugin()
@DefinePlugin()
class NonImmediateDependency {}
@Provide('myPlugin', { immediate: true })
@KoishiPlugin()
@DefinePlugin()
class TestingBase implements OnConnect, OnDisconnect, OnApply {
@InjectContext()
ctx: Context;
......
import { App, Context } from 'koishi';
import { KoishiPlugin } from '../src/register';
import { DefinePlugin } from '../src/register';
import { Inject, Provide, UseEvent } from '../src/decorators';
declare module 'koishi' {
......@@ -15,7 +15,7 @@ declare module 'koishi' {
}
@Provide('myProvider')
@KoishiPlugin()
@DefinePlugin()
class MyProvider {
ping() {
return 'pong';
......@@ -23,7 +23,7 @@ class MyProvider {
}
@Provide('myEagerProvider', { immediate: true })
@KoishiPlugin()
@DefinePlugin()
class MyEagerProvider {
ping() {
return 'pong eager';
......@@ -31,7 +31,7 @@ class MyEagerProvider {
}
@Provide('myConsumer', { immediate: true })
@KoishiPlugin()
@DefinePlugin()
class MyConsumer {
@Inject()
myProvider: MyProvider;
......@@ -54,7 +54,7 @@ class MyConsumer {
}
@Provide('myUsingConsumer', { immediate: true })
@KoishiPlugin()
@DefinePlugin()
class MyUsingConsumer {
@Inject(true)
myProvider: MyProvider;
......
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