48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { Middleware } from './compose';
|
|
export declare const HOOKS: string;
|
|
export declare type HookContextData = {
|
|
[key: string]: any;
|
|
};
|
|
/**
|
|
* The base hook context.
|
|
*/
|
|
export declare class BaseHookContext<C = any> {
|
|
self?: C;
|
|
[key: string]: any;
|
|
constructor(data?: HookContextData);
|
|
}
|
|
export interface HookContext<T = any, C = any> extends BaseHookContext<C> {
|
|
result?: T;
|
|
method?: string;
|
|
arguments: any[];
|
|
}
|
|
export declare type HookContextConstructor = new (data?: {
|
|
[key: string]: any;
|
|
}) => BaseHookContext;
|
|
export declare type HookDefaultsInitializer = (self?: any, args?: any[], context?: HookContext) => HookContextData;
|
|
export declare class HookManager {
|
|
_parent?: this | null;
|
|
_params: string[] | null;
|
|
_middleware: Middleware[] | null;
|
|
_props: HookContextData | null;
|
|
_defaults?: HookDefaultsInitializer;
|
|
parent(parent: this | null): this;
|
|
middleware(middleware?: Middleware[]): this;
|
|
getMiddleware(): Middleware[] | null;
|
|
collectMiddleware(self: any, _args: any[]): Middleware[];
|
|
props(props: HookContextData): this;
|
|
getProps(): HookContextData | null;
|
|
params(...params: string[]): this;
|
|
getParams(): string[] | null;
|
|
defaults(defaults: HookDefaultsInitializer): this;
|
|
getDefaults(self: any, args: any[], context: HookContext): HookContextData | null;
|
|
getContextClass(Base?: HookContextConstructor): HookContextConstructor;
|
|
initializeContext(self: any, args: any[], context: HookContext): HookContext;
|
|
}
|
|
export declare type HookOptions = HookManager | Middleware[] | null;
|
|
export declare function convertOptions(options?: HookOptions): HookManager;
|
|
export declare function getManager(target: any): HookManager | null;
|
|
export declare function setManager<T>(target: T, manager: HookManager): T;
|
|
export declare function getMiddleware(target: any): Middleware[] | null;
|
|
export declare function setMiddleware<T>(target: T, middleware: Middleware[]): T;
|