Commit d6d3d2b4 authored by nanahira's avatar nanahira

bump version

parent 4bdd6d17
This diff is collapsed.
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"author": "Nanahira <nanahira@momobako.com>", "author": "Nanahira <nanahira@momobako.com>",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@koishijs/plugin-adapter-onebot": "^4.1.5", "@koishijs/plugin-adapter-onebot": "^4.2.4",
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/lodash": "^4.14.177", "@types/lodash": "^4.14.177",
"@types/node": "^16.11.9", "@types/node": "^16.11.9",
...@@ -44,15 +44,15 @@ ...@@ -44,15 +44,15 @@
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"supertest": "^6.1.6", "supertest": "^6.1.6",
"ts-jest": "^27.0.7", "ts-jest": "^27.0.7",
"typescript": "^4.5.2", "typescript": "^4.6.4",
"ws": "^8.2.3" "ws": "^8.2.3"
}, },
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"koishi-decorators": "^2.0.4", "koishi-decorators": "^2.1.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"minato-decorators": "^2.0.6", "minato-decorators": "^2.0.7",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"schemastery-gen": "^3.1.13", "schemastery-gen": "^3.1.13",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
"testEnvironment": "node" "testEnvironment": "node"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.0", "koishi": "^4.7.1",
"schemastery": "^3.1.0" "schemastery": "^3.4.3"
} }
} }
...@@ -12,7 +12,6 @@ import { ...@@ -12,7 +12,6 @@ import {
KoishiSystemInjectSymKeys, KoishiSystemInjectSymKeys,
ProvideOptions, ProvideOptions,
SystemInjectFun, SystemInjectFun,
TypedMethodDecorator,
} from './def'; } from './def';
import { TopLevelAction } from 'koishi-decorators'; import { TopLevelAction } from 'koishi-decorators';
import { ModelClassType, ModelRegistrar } from 'minato-decorators'; import { ModelClassType, ModelRegistrar } from 'minato-decorators';
...@@ -27,14 +26,14 @@ export { PluginDef } from 'koishi-decorators'; ...@@ -27,14 +26,14 @@ export { PluginDef } from 'koishi-decorators';
// Service API // Service API
export function Inject( export function Inject(
name?: keyof Context.Services, name?: ServiceName,
addUsing?: boolean, addUsing?: boolean,
): PropertyDecorator; ): PropertyDecorator;
export function Inject(addUsing?: boolean): PropertyDecorator; export function Inject(addUsing?: boolean): PropertyDecorator;
export function Inject( export function Inject(
...args: [(keyof Context.Services | boolean)?, boolean?] ...args: [(ServiceName | boolean)?, boolean?]
): PropertyDecorator { ): PropertyDecorator {
let name: keyof Context.Services; let name: ServiceName;
let addUsing = false; let addUsing = false;
if (args.length === 1) { if (args.length === 1) {
if (typeof args[0] === 'boolean') { if (typeof args[0] === 'boolean') {
...@@ -43,7 +42,7 @@ export function Inject( ...@@ -43,7 +42,7 @@ export function Inject(
name = args[0]; name = args[0];
} }
} else if (args.length >= 2) { } else if (args.length >= 2) {
name = args[0] as keyof Context.Services; name = args[0] as ServiceName;
addUsing = args[1]; addUsing = args[1];
} }
return (obj, key) => { return (obj, key) => {
...@@ -59,7 +58,7 @@ export function Inject( ...@@ -59,7 +58,7 @@ export function Inject(
return dec(obj, key); return dec(obj, key);
} }
} }
const serviceName = name || (key as keyof Context.Services); const serviceName = name || (key as ServiceName);
if (addUsing) { if (addUsing) {
Metadata.appendUnique(KoishiAddUsingList, serviceName)(obj.constructor); Metadata.appendUnique(KoishiAddUsingList, serviceName)(obj.constructor);
} }
...@@ -73,10 +72,10 @@ export function Inject( ...@@ -73,10 +72,10 @@ export function Inject(
} }
export function Provide( export function Provide(
name: keyof Context.Services, name: ServiceName,
options?: ProvideOptions, options?: ProvideOptions,
): ClassDecorator { ): ClassDecorator {
Context.service(name); Context.service(name, options);
return Metadata.append(KoishiServiceProvideSym, { return Metadata.append(KoishiServiceProvideSym, {
...options, ...options,
serviceName: name, serviceName: name,
...@@ -105,7 +104,7 @@ export const Caller = () => ...@@ -105,7 +104,7 @@ export const Caller = () =>
}); });
export function UsingService( export function UsingService(
...services: (keyof Context.Services)[] ...services: ServiceName[]
): ClassDecorator & MethodDecorator { ): ClassDecorator & MethodDecorator {
return (obj, key?) => { return (obj, key?) => {
for (const service of services) { for (const service of services) {
......
// metadatas // metadatas
import { Context, Schema } from 'koishi'; import { Context, Schema } from 'koishi';
import { import { ControlType, ProvideDefinition, SystemInjectFun } from './interfaces';
Condition,
ControlType,
ControlTypeMap,
ProvideDefinition,
SystemInjectFun,
} from './interfaces';
import { ClassType } from 'schemastery-gen'; import { ClassType } from 'schemastery-gen';
export const KoishiServiceInjectSym = 'KoishiServiceInjectSym'; export const KoishiServiceInjectSym = 'KoishiServiceInjectSym';
...@@ -23,13 +17,13 @@ export interface MetadataArrayMap { ...@@ -23,13 +17,13 @@ export interface MetadataArrayMap {
KoishiServiceProvideSym: ProvideDefinition; KoishiServiceProvideSym: ProvideDefinition;
KoishiServiceInjectSymKeys: string; KoishiServiceInjectSymKeys: string;
KoishiSystemInjectSymKeys: string; KoishiSystemInjectSymKeys: string;
KoishiAddUsingList: keyof Context.Services; KoishiAddUsingList: ServiceName;
KoishiPartialUsing: keyof Context.Services; KoishiPartialUsing: ServiceName;
KoishiControl: ControlType; KoishiControl: ControlType;
} }
export interface MetadataMap { export interface MetadataMap {
KoishiServiceInjectSym: keyof Context.Services; KoishiServiceInjectSym: ServiceName;
KoishiSystemInjectSym: SystemInjectFun; KoishiSystemInjectSym: SystemInjectFun;
KoishiPredefineSchema: Schema | ClassType<any>; KoishiPredefineSchema: Schema | ClassType<any>;
KoishiPredefineName: string; KoishiPredefineName: string;
......
...@@ -7,12 +7,14 @@ export * from 'koishi-decorators/dist/src/def/interfaces'; ...@@ -7,12 +7,14 @@ export * from 'koishi-decorators/dist/src/def/interfaces';
export type SystemInjectFun = <T = any>(obj: PluginMeta<T>) => any; export type SystemInjectFun = <T = any>(obj: PluginMeta<T>) => any;
export interface ProvideOptions { export type ServiceName = keyof Context;
export interface ProvideOptions extends Context.ServiceOptions {
immediate?: boolean; immediate?: boolean;
} }
export interface ProvideDefinition extends ProvideOptions { export interface ProvideDefinition extends ProvideOptions {
serviceName: keyof Context.Services; serviceName: ServiceName;
} }
export type Condition<R, T = any, Ext extends any[] = []> = ( export type Condition<R, T = any, Ext extends any[] = []> = (
......
import { MapPluginToConfig, PluginClass } from '../def'; import { MapPluginToConfig, PluginClass } from '../def';
import { Dict } from 'koishi'; import { Dict } from 'koishi';
import { AnyClass, ClassType, Mixin } from 'schemastery-gen'; import { ClassType, Mixin } from 'schemastery-gen';
import { MappingPluginBase } from './mapping-base'; import { MappingPluginBase } from './mapping-base';
import { CreatePluginFactory } from '../plugin-factory'; import { CreatePluginFactory } from '../plugin-factory';
import _ from 'lodash'; import _ from 'lodash';
......
...@@ -69,9 +69,7 @@ export function MultiInstancePlugin< ...@@ -69,9 +69,7 @@ export function MultiInstancePlugin<
const plugin = factory(outerConfig); const plugin = factory(outerConfig);
if (innerPlugin['using']) { if (innerPlugin['using']) {
UsingService(...(innerPlugin['using'] as (keyof Context.Services)[]))( UsingService(...(innerPlugin['using'] as ServiceName[]))(plugin);
plugin,
);
} }
return plugin; return plugin;
......
import { Context, Plugin, Schema, WebSocketLayer } from 'koishi'; import { Context, Plugin, Schema, WebSocketLayer } from 'koishi';
import { import {
Condition,
ControlType, ControlType,
KoishiAddUsingList, KoishiAddUsingList,
KoishiPartialUsing, KoishiPartialUsing,
...@@ -22,7 +21,7 @@ export interface KoishiPluginRegistrationOptions<T = any> { ...@@ -22,7 +21,7 @@ export interface KoishiPluginRegistrationOptions<T = any> {
name?: string; name?: string;
schema?: Schema<T> | Type<T>; schema?: Schema<T> | Type<T>;
Config?: Schema<T> | Type<T>; Config?: Schema<T> | Type<T>;
using?: (keyof Context.Services)[]; using?: ServiceName[];
} }
export interface PluginMeta<T = any> { export interface PluginMeta<T = any> {
...@@ -124,6 +123,8 @@ export function DefinePlugin<T>( ...@@ -124,6 +123,8 @@ export function DefinePlugin<T>(
return this.__ctx[name]; return this.__ctx[name];
}, },
set: (val: any) => { set: (val: any) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.__ctx[name] = val; this.__ctx[name] = val;
}, },
}); });
...@@ -234,6 +235,8 @@ export function DefinePlugin<T>( ...@@ -234,6 +235,8 @@ export function DefinePlugin<T>(
(serviceDef) => !serviceDef.immediate === !immediate, (serviceDef) => !serviceDef.immediate === !immediate,
); );
for (const key of providingServices) { for (const key of providingServices) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.__ctx[key.serviceName] = this as any; this.__ctx[key.serviceName] = this as any;
} }
} }
...@@ -242,6 +245,8 @@ export function DefinePlugin<T>( ...@@ -242,6 +245,8 @@ export function DefinePlugin<T>(
const providingServices = this._getProvidingServices(); const providingServices = this._getProvidingServices();
for (const key of providingServices) { for (const key of providingServices) {
if (this.__ctx[key.serviceName] === (this as never)) { if (this.__ctx[key.serviceName] === (this as never)) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.__ctx[key.serviceName] = null; this.__ctx[key.serviceName] = null;
} }
} }
......
...@@ -28,7 +28,7 @@ describe('InjectUsing', () => { ...@@ -28,7 +28,7 @@ describe('InjectUsing', () => {
it('Should include injected using services', () => { it('Should include injected using services', () => {
expect(MyPlugin.name).toBe('foo-plugin'); expect(MyPlugin.name).toBe('foo-plugin');
expect(MyPlugin['Config']).toEqual(Config); expect(MyPlugin['Config']).toEqual(Config);
const usingList = (MyPlugin as any).using as (keyof Context.Services)[]; const usingList = (MyPlugin as any).using as ServiceName[];
expect(usingList).toBeInstanceOf(Array); expect(usingList).toBeInstanceOf(Array);
expect(usingList.length).toEqual(5); expect(usingList.length).toEqual(5);
expect(usingList.includes('database')).toEqual(true); expect(usingList.includes('database')).toEqual(true);
......
...@@ -35,7 +35,7 @@ describe('Scope', () => { ...@@ -35,7 +35,7 @@ describe('Scope', () => {
} as Session; } as Session;
app.plugin(MyClass); app.plugin(MyClass);
const methodCtx = app.command('foo').context; const methodCtx = app.command('foo').ctx;
expect(methodCtx.filter(correctSession)).toBe(true); expect(methodCtx.filter(correctSession)).toBe(true);
expect(methodCtx.filter(wrongSession1)).toBe(false); expect(methodCtx.filter(wrongSession1)).toBe(false);
......
...@@ -60,7 +60,7 @@ class MyConsumer { ...@@ -60,7 +60,7 @@ class MyConsumer {
eagerPongResult: string; eagerPongResult: string;
@UseEvent('service') @UseEvent('service')
async onService(name: keyof Context.Services) { async onService(name: ServiceName) {
if (name === 'myProvider') { if (name === 'myProvider') {
this.pongResult = this.myProvider.ping(); this.pongResult = this.myProvider.ping();
} else if (name === 'myEagerProvider') { } else if (name === 'myEagerProvider') {
...@@ -83,7 +83,7 @@ class MyUsingConsumer { ...@@ -83,7 +83,7 @@ class MyUsingConsumer {
eagerPongResult: string; eagerPongResult: string;
@UseEvent('service') @UseEvent('service')
async onService(name: keyof Context.Services) { async onService(name: ServiceName) {
if (name === 'myProvider') { if (name === 'myProvider') {
this.pongResult = this.myProvider.ping(); this.pongResult = this.myProvider.ping();
} else if (name === 'myEagerProvider') { } else if (name === 'myEagerProvider') {
......
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