import { Response } from "./Response.mjs"; import { RouterConfig } from "../types/basic.mjs"; import { Request } from "./Request.mjs"; import { BindToken, BindValue, BindingOptions, Container } from "./bindings.mjs"; //#region src/core/plugins.d.ts type PluginSetupResult = void | Promise; interface ClearRouterPluginRequestContext { ctx: HttpContext; request: Request; response: Response; getBindings: () => Record; [key: string]: any; } interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext { target?: object; method?: PropertyKey; handler?: object; metadata?: object; tokens: BindToken[]; designTokens: BindToken[]; } type PluginBindFactory = (ctx: ClearRouterPluginRequestContext) => T | Promise; type PluginBindValue = BindValue | PluginBindFactory; type PluginBind = (token: BindToken, value: PluginBindValue, options?: BindingOptions) => void; type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise; interface ClearRouterPluginContext { /** * The service container */ container: Container; /** * Register service container bindings */ bind: PluginBind; /** * Replace all controller method arguments * @param resolver * @returns */ resolveArguments: (resolver: PluginArgumentsResolver) => void; /** * Use the current http context */ useHttpContext: (resolver: PluginArgumentsResolver) => void; /** * All registered service container bindings */ bindings: Record; /** * Configures the router with the given options, such as method override settings * * @param options * @returns */ configure: (options: RouterConfig) => void; /** * Default configuration used for everytime the router is reset * * @param options */ configureDefaults: (options: RouterConfig) => void; /** * The current Request instance */ readonly request?: Request; /** * The current Response instance * @returns */ readonly response?: Response; /** * Get the current Request instance * @returns */ getRequest: () => Request | undefined; /** * Get the current Response instance * @returns */ getResponse: () => Response | undefined; /** * Plugin configuration options */ options: Options; } interface ClearRouterPlugin { /** * The name of the plugin */ name?: string; /** * Plugin setup an implemnetation * * @param ctx * @returns */ setup: (ctx: ClearRouterPluginContext) => PluginSetupResult; } type ClearRouterPluginInput = ClearRouterPlugin | ((ctx: ClearRouterPluginContext) => PluginSetupResult); /** * Creates a new plugin * * @param plugin * @returns */ declare function definePlugin(plugin: ClearRouterPlugin): ClearRouterPlugin; //#endregion export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin };