@prostojs/mate
Version:
MATE is TS Metadata Organizer
85 lines (66 loc) • 5.35 kB
TypeScript
declare type ArrayElementType<T> = T extends (infer E)[] ? E : never;
export declare function getConstructor<T = TAny>(instance: T): TFunction;
export declare function isConstructor<T = TAny>(v: T): v is (T & TClassConstructor);
export declare class Mate<TClass extends TObject = TMateClassMeta<TMateParamMeta>, TProp extends {
params: TMateParamMeta[];
} = Required<TMatePropMeta<TMateParamMeta>>> {
protected workspace: string;
protected options: TMateOptions<TClass, TProp>;
protected logger: TConsoleBase;
constructor(workspace: string, options?: TMateOptions<TClass, TProp>);
_cleanup(): void;
set<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>>(args: TMergedDecoratorArgs, cb: (meta: T, level: TLevels, propKey?: string | symbol, index?: number) => T): void;
set<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>, K extends keyof T = keyof T>(args: TMergedDecoratorArgs, key: keyof T, value: T[K]): void;
set<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>, K extends keyof T = keyof T>(args: TMergedDecoratorArgs, key: keyof T, value: T[K], isArray: boolean | undefined): void;
read<PK>(target: TFunction | TObject, propKey?: PK): PK extends PropertyKey ? (TClass & TProp & TCommonMate<TProp['params'][0]>) | undefined : TClass | undefined;
apply(...decorators: (MethodDecorator | ClassDecorator | ParameterDecorator | PropertyDecorator)[]): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorate<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>>(cb: (meta: T, level: TLevels, propKey?: string | symbol, index?: number) => T): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorate<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>, K extends keyof T = keyof T>(key: K, value: T[K]): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorate<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>, K extends keyof T = keyof T, TIsArray extends boolean = false>(key: K, value: TIsArray extends true ? ArrayElementType<T[K]> : T[K], isArray: TIsArray): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorate<T = TClass & TProp & TCommonMateWithParam<TProp['params'][0]>, K extends keyof T = keyof T, TIsArray extends boolean = false>(key: K | ((meta: T, level: TLevels, propKey?: string | symbol, index?: number) => T), value: TIsArray extends true ? ArrayElementType<T[K]> : T[K], isArray: TIsArray, level: TMergedDecoratorArgs['level']): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorateConditional(ccb: (level: TLevels) => (MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator) | void | undefined): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorateClass<T = TClass>(cb: (meta: T, level: TLevels, propKey?: string | symbol, index?: number) => T): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorateClass<T = TClass, K extends keyof T = keyof T, TIsArray extends boolean = false>(key: K, value: TIsArray extends true ? ArrayElementType<T[K]> : T[K]): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
decorateClass<T = TClass, K extends keyof T = keyof T, TIsArray extends boolean = false>(key: K, value: TIsArray extends true ? ArrayElementType<T[K]> : T[K], isArray: boolean | undefined): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
}
declare type TAny = any;
declare type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
declare type TCommonMate<TParam extends TObject> = TMateClassMeta<TParam> & TMatePropMeta<TParam>;
declare type TCommonMateWithParam<TParam extends TObject> = TMateClassMeta<TParam> & TMatePropMeta<TParam> & TParam;
declare interface TConsoleBase {
error: ((...args: any) => void);
}
declare interface TEmpty {
}
declare type TFunction = Function;
declare type TLevels = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
export declare interface TMateClassMeta<TParam> {
properties?: (string | symbol)[];
type?: TFunction;
returnType?: TFunction;
params?: (TParam & TMateParamMeta)[];
}
export declare interface TMateOptions<TClass extends TObject = TMateClassMeta<TMateParamMeta>, TProp extends {
params: TMateParamMeta[];
} = Required<TMatePropMeta<TMateParamMeta>>> {
logger?: TConsoleBase;
readReturnType?: boolean;
readType?: boolean;
collectPropKeys?: boolean;
inherit?: boolean | ((classMeta: TClass & TMateClassMeta<TMateParamMeta>, targetMeta: (TMatePropMeta<TProp['params'][0]> & TProp) | (TMateParamMeta & TProp['params'][0]), level: 'CLASS' | 'PROP' | 'PARAM', key?: string) => boolean);
}
export declare interface TMateParamMeta {
type?: TFunction;
}
export declare interface TMatePropMeta<TParam extends TObject = TEmpty> {
params?: (TParam & TMateParamMeta)[];
}
export declare interface TMergedDecoratorArgs {
target: TFunction | TObject;
propKey?: string | symbol;
descriptor?: TypedPropertyDescriptor<TAny>;
index?: number;
level?: TLevels;
}
declare type TObject = object;
export { }