import { Store } from "@tsed/core/types/Store.js"; import type { AbstractType, Type } from "@tsed/core/types/Type.js"; import type { ProviderOpts } from "../interfaces/ProviderOpts.js"; import type { TokenProvider } from "../interfaces/TokenProvider.js"; import { ProviderScope } from "./ProviderScope.js"; import { ProviderType } from "./ProviderType.js"; /** * Middleware configuration for a controller. * * Defines middleware tokens to be applied at different stages of request processing. * * @public */ export interface ControllerMiddlewares { useBefore: TokenProvider[]; use: TokenProvider[]; useAfter: TokenProvider[]; } /** * Callback function type for provider lifecycle hooks. * * @typeParam T - The type of provider instance * @public */ export type ProviderHookCallback = (instance: T, ...args: unknown[]) => Promise | void; /** * Provider metadata class managing dependency injection configuration. * * Encapsulates all information needed to create, configure, and manage a provider instance * within the DI container. Tracks dependencies, lifecycle hooks, creation strategies, and metadata. * * ### Usage * * ```typescript * import {Provider, ProviderType} from "@tsed/di"; * * const provider = new Provider(MyService); * provider.type = ProviderType.PROVIDER; * provider.deps = [DatabaseService, LoggerService]; * ``` * * @typeParam T - The type of instance this provider creates * @public */ export declare class Provider implements ProviderOpts { #private; /** * Global registry for storing all providers in the dependency injection system. * Maps provider tokens to their Provider instances. */ static readonly Registry: Map>; /** * Token group provider to retrieve all providers from the same type */ type: ProviderType | TokenProvider; /** * Array of token providers that this provider depends on */ deps: TokenProvider[]; /** * Array of providers or provider arrays to be imported */ imports: (TokenProvider | [TokenProvider])[]; /** * Alternative name/alias for this provider */ alias: string; /** * Priority value affecting the order of provider initialization */ priority: number; /** * Optional factory function to create provider instances */ useFactory?: Function; /** * Optional async factory function to create provider instances */ useAsyncFactory?: Function; /** * Optional static value to use instead of creating instances */ useValue?: unknown; /** * Map of lifecycle hook callbacks for this provider */ hooks: Record>; /** * Router token for routing-related providers */ tokenRouter: string; [key: string]: any; /** * Creates a new Provider instance * @param token - The token used to identify this provider * @param options - Optional configuration options for the provider */ constructor(token: TokenProvider, options?: Partial); /** * Get the provider's token */ get token(): TokenProvider; /** * Set the provider's token and initialize stores * @param value - The token to set */ set token(value: TokenProvider); /** * @deprecated */ get provide(): TokenProvider; /** * @deprecated * @param value */ set provide(value: TokenProvider); /** * Gets the class type used to instantiate this provider */ get useClass(): Type; /** * Sets the class type and initializes store/hooks for this provider * @param value - The class type to use for instantiation */ set useClass(value: Type | AbstractType); get className(): string; get name(): string; get store(): Store; get path(): string; set path(path: string); /** * Get the scope of the provider. * * ::: tip Note * Async provider is always a SINGLETON * ::: * * @returns {boolean} */ get scope(): ProviderScope; /** * Change the scope value of the provider. * @param scope */ set scope(scope: ProviderScope); /** * Gets the provider configuration settings */ get configuration(): Partial; /** * Sets the provider configuration settings * @param configuration - The configuration object to set */ set configuration(configuration: Partial); get children(): TokenProvider[]; set children(children: TokenProvider[]); /** * Gets the configured middleware stack for this provider */ get middlewares(): Partial; /** * Sets middleware configuration, merging with existing middlewares * @param middlewares - The middleware configuration to apply */ set middlewares(middlewares: Partial); getArgOpts(index: number): any; /** * Retrieves a value from the provider's store. * @param key The key to look up * @returns The value if found, undefined otherwise */ get(key: string): Type | undefined; /** * Retrieves a value from the provider's store with a default fallback. * @param key The key to look up * @param defaultValue The value to return if key is not found * @returns The found value or defaultValue */ get(key: string, defaultValue: Type): Type; isAsync(): boolean; clone(): Provider; /** * Checks if this provider has any child controllers * @returns True if provider has children, false otherwise */ hasChildren(): boolean; /** * Checks if this provider has a parent controller * @returns True if provider has a parent, false otherwise */ hasParent(): boolean; /** * Returns a string representation of this provider * @returns A string containing the provider's token, class and factory information */ toString(): string; /** * Resets the provider's factory configuration * Clears useValue, useFactory and useAsyncFactory * @returns This provider instance */ reset(): this; }