Commit 6306633d authored by nanahira's avatar nanahira

fix logger name problem and migrate to CallbackLayer

parent d92b143f
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"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.1.2", "koishi-decorators": "^2.1.6",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"minato-decorators": "^2.0.7", "minato-decorators": "^2.0.7",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
...@@ -4793,19 +4793,20 @@ ...@@ -4793,19 +4793,20 @@
} }
}, },
"node_modules/koishi-decorators": { "node_modules/koishi-decorators": {
"version": "2.1.2", "version": "2.1.6",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.2.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.6.tgz",
"integrity": "sha512-32pFPob5FBhAcQ6qz02hGFs6MLj3k+8mpki8HjG4PD8RF8WeuKhrWA7SlVg6Clw3NvfU/lEyqGcnIavwiUF2Tg==", "integrity": "sha512-G1NN31fCIOafKkDME4YBzgHZ6J3b/CjsKr2AszZw9rmH6j7qHbs3PxXrkEK7zFSvTJh1RLHR2gDMhxqC7A3zTQ==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mustache": "^4.2.0", "mustache": "^4.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.5.5",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.2" "koishi": "^4.7.4"
} }
}, },
"node_modules/leven": { "node_modules/leven": {
...@@ -5884,6 +5885,19 @@ ...@@ -5884,6 +5885,19 @@
"queue-microtask": "^1.2.2" "queue-microtask": "^1.2.2"
} }
}, },
"node_modules/rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/rxjs/node_modules/tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
"integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ=="
},
"node_modules/safe-buffer": { "node_modules/safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
...@@ -10598,15 +10612,16 @@ ...@@ -10598,15 +10612,16 @@
} }
}, },
"koishi-decorators": { "koishi-decorators": {
"version": "2.1.2", "version": "2.1.6",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.2.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.6.tgz",
"integrity": "sha512-32pFPob5FBhAcQ6qz02hGFs6MLj3k+8mpki8HjG4PD8RF8WeuKhrWA7SlVg6Clw3NvfU/lEyqGcnIavwiUF2Tg==", "integrity": "sha512-G1NN31fCIOafKkDME4YBzgHZ6J3b/CjsKr2AszZw9rmH6j7qHbs3PxXrkEK7zFSvTJh1RLHR2gDMhxqC7A3zTQ==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mustache": "^4.2.0", "mustache": "^4.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.5.5",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
} }
}, },
...@@ -11414,6 +11429,21 @@ ...@@ -11414,6 +11429,21 @@
"queue-microtask": "^1.2.2" "queue-microtask": "^1.2.2"
} }
}, },
"rxjs": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.5.tgz",
"integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==",
"requires": {
"tslib": "^2.1.0"
},
"dependencies": {
"tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
"integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ=="
}
}
},
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
......
...@@ -4,7 +4,6 @@ import { Metadata } from './meta/metadata.decorators'; ...@@ -4,7 +4,6 @@ import { Metadata } from './meta/metadata.decorators';
import { import {
Condition, Condition,
KoishiAddUsingList, KoishiAddUsingList,
KoishiPartialUsing,
KoishiServiceInjectSym, KoishiServiceInjectSym,
KoishiServiceInjectSymKeys, KoishiServiceInjectSymKeys,
KoishiServiceProvideSym, KoishiServiceProvideSym,
...@@ -15,7 +14,7 @@ import { ...@@ -15,7 +14,7 @@ import {
ServiceName, ServiceName,
SystemInjectFun, SystemInjectFun,
} from './def'; } from './def';
import { TopLevelAction } from 'koishi-decorators'; import { CallbackLayer, TopLevelAction } from 'koishi-decorators';
import { ModelClassType, ModelRegistrar } from 'minato-decorators'; import { ModelClassType, ModelRegistrar } from 'minato-decorators';
import { ClassType } from 'schemastery-gen'; import { ClassType } from 'schemastery-gen';
...@@ -98,7 +97,7 @@ export const InjectContext = (select?: Selection) => ...@@ -98,7 +97,7 @@ export const InjectContext = (select?: Selection) =>
export const InjectApp = () => InjectSystem((obj) => obj.__ctx.app); export const InjectApp = () => InjectSystem((obj) => obj.__ctx.app);
export const InjectConfig = () => InjectSystem((obj) => obj.__config); export const InjectConfig = () => InjectSystem((obj) => obj.__config);
export const InjectLogger = (name?: string) => export const InjectLogger = (name?: string) =>
InjectSystem((obj, cl) => obj.__ctx.logger(name || cl.name)); InjectSystem((obj) => obj.__ctx.logger(name || obj.constructor.name));
export const InjectParent = () => InjectSystem((obj) => obj.__ctx.__parent); export const InjectParent = () => InjectSystem((obj) => obj.__ctx.__parent);
export const Caller = () => export const Caller = () =>
InjectSystem((obj) => { InjectSystem((obj) => {
...@@ -109,13 +108,20 @@ export const Caller = () => ...@@ -109,13 +108,20 @@ export const Caller = () =>
export function UsingService( export function UsingService(
...services: ServiceName[] ...services: ServiceName[]
): ClassDecorator & MethodDecorator { ): ClassDecorator & MethodDecorator {
return (obj, key?) => { return (obj, key?, des?) => {
for (const service of services) { for (const service of services) {
if (!key) { if (!key) {
// fallback to KoishiAddUsingList // fallback to KoishiAddUsingList
Metadata.appendUnique(KoishiAddUsingList, service)(obj); Metadata.appendUnique(KoishiAddUsingList, service)(obj);
} else { } else {
Metadata.appendUnique(KoishiPartialUsing, service)(obj, key); const dec = CallbackLayer((ctx, cb) => {
ctx.plugin({
name: `${ctx.state.id}_${key.toString()}`,
using: services,
apply: cb,
});
});
dec(obj, key, des);
} }
} }
}; };
......
// metadatas // metadatas
import { Context, Schema } from 'koishi'; import { Schema } from 'koishi';
import { import {
ControlType, ControlType,
PluginClass, PluginClass,
...@@ -15,7 +15,6 @@ export const KoishiServiceProvideSym = 'KoishiServiceProvideSym'; ...@@ -15,7 +15,6 @@ export const KoishiServiceProvideSym = 'KoishiServiceProvideSym';
export const KoishiSystemInjectSym = 'KoishiSystemInjectSym'; export const KoishiSystemInjectSym = 'KoishiSystemInjectSym';
export const KoishiSystemInjectSymKeys = 'KoishiSystemInjectSymKeys'; export const KoishiSystemInjectSymKeys = 'KoishiSystemInjectSymKeys';
export const KoishiAddUsingList = 'KoishiAddUsingList'; export const KoishiAddUsingList = 'KoishiAddUsingList';
export const KoishiPartialUsing = 'KoishiPartialUsing';
// metadata map // metadata map
...@@ -24,7 +23,6 @@ export interface MetadataArrayMap { ...@@ -24,7 +23,6 @@ export interface MetadataArrayMap {
KoishiServiceInjectSymKeys: string; KoishiServiceInjectSymKeys: string;
KoishiSystemInjectSymKeys: string; KoishiSystemInjectSymKeys: string;
KoishiAddUsingList: ServiceName; KoishiAddUsingList: ServiceName;
KoishiPartialUsing: ServiceName;
KoishiControl: ControlType; KoishiControl: ControlType;
} }
......
import { Context, Plugin, Schema, WebSocketLayer } from 'koishi'; import { Context, Schema, WebSocketLayer } from 'koishi';
import { import {
ControlType, ControlType,
KoishiAddUsingList, KoishiAddUsingList,
KoishiPartialUsing,
KoishiServiceInjectSym, KoishiServiceInjectSym,
KoishiServiceInjectSymKeys, KoishiServiceInjectSymKeys,
KoishiServiceProvideSym, KoishiServiceProvideSym,
...@@ -171,23 +170,14 @@ export function DefinePlugin<T>( ...@@ -171,23 +170,14 @@ export function DefinePlugin<T>(
methodKey, methodKey,
false, false,
); );
const partialUsing = reflector.getArray( return this.__registrar
KoishiPartialUsing, .runLayers(
this, ctx,
methodKey, (innerCtx) =>
);
if (partialUsing.length) {
const name = `${newClass.name}-${methodKey}`;
const innerPlugin: Plugin.Object = {
name,
using: partialUsing,
apply: (innerCtx) =>
this._registerDeclarationsProcess(methodKey, innerCtx, view), this._registerDeclarationsProcess(methodKey, innerCtx, view),
}; methodKey,
ctx.plugin(innerPlugin); )
} else { .subscribe();
this._registerDeclarationsProcess(methodKey, ctx, view);
}
} }
_registerDeclarationsWithStack( _registerDeclarationsWithStack(
......
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