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