Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): add type DecoratorMetaData for custom decorator #2693

Merged
merged 4 commits into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/core/src/interface.ts
Expand Up @@ -328,6 +328,13 @@ export type PipeTransformFunction<T = any, R = any> = (value: T) => R;

export type PipeUnionTransform<T = any, R = any> = PipeTransform<T, R> | (new (...args) => PipeTransform<T, R>) | PipeTransformFunction<T, R>;

export interface DecoratorMetaData<T = any> {
propertyName: string
waitingsong marked this conversation as resolved.
Show resolved Hide resolved
/** decorator key */
key: string
metadata: T
options: MethodDecoratorOptions
}
export interface MethodDecoratorOptions {
impl?: boolean;
}
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/service/decoratorService.ts
Expand Up @@ -11,14 +11,14 @@ import {
transformTypeFromTSDesign,
} from '../decorator';
import {
DecoratorMetaData,
HandlerFunction,
IMidwayContainer,
MethodHandlerFunction,
ParameterHandlerFunction,
JoinPoint,
ScopeEnum,
ParamDecoratorOptions,
MethodDecoratorOptions,
PipeUnionTransform,
PipeTransform,
} from '../interface';
Expand Down Expand Up @@ -48,12 +48,10 @@ export class MidwayDecoratorService {
// add custom method decorator listener
this.applicationContext.onBeforeBind(Clzz => {
// find custom method decorator metadata, include method decorator information array
const methodDecoratorMetadataList: Array<{
propertyName: string;
key: string;
metadata: any;
options: MethodDecoratorOptions;
}> = getClassMetadata(INJECT_CUSTOM_METHOD, Clzz);
const methodDecoratorMetadataList: DecoratorMetaData[] = getClassMetadata(
INJECT_CUSTOM_METHOD,
Clzz
);

if (methodDecoratorMetadataList) {
// loop it, save this order for decorator run
Expand Down