import { S as Signal } from './types-CxOJPpKX.js'; import { a as Scope } from './types-jkBBq3Lp.js'; /** * Base service type which is implemented by controllers */ type BaseService = Record | ((...args: any[]) => any); /** * Effects and business logic controller. * * Implementation of the controller must provide `destroy()` method. It should * be used for closing subscriptions and disposing resources. * * @example * ```ts * type LoggerController = Controller<{ * log: (message: string) => void; * }>; * ``` */ type Controller = TService & { /** Dispose the controller and clean its resources */ destroy: () => void; }; /** * @internal */ type PartialController = TService & { /** Dispose the controller and clean its resources */ destroy?: () => void; }; /** * Parameters for a controller */ type ControllerParams = Record; /** * Base context for a controller */ type BaseControllerContext = { scope: Scope; params?: unknown; }; /** * Context with parameters for a controller */ type ControllerParamsContext = BaseControllerContext & { params: TParams; }; /** * An error thrown when a controller is failed to be created */ declare class ControllerConstructorError extends Error { constructor(message: string); } /** * Parameters for an extension */ type ExtensionParams = Record; /** * Extension function for a controller * * It extends a controller context with additional data * * @param sourceContext The source context * @param extensionParams Additional parameters for the extension * * @returns The extended context */ type ExtensionFn = (sourceContext: TSourceContext, extensionParams?: ExtensionParams) => TSourceContext & TContextExtension; /** * Provider for arbitrary extension parameters * * It extends extension parameters with additional data and returns them. * An extension can use this data during creation of a controller context. */ type ExtensionParamsProvider = (params: ExtensionParams) => ExtensionParams; /** * Base declaration for a controller */ type ControllerDeclaration = TContext extends ControllerParamsContext ? { /** @internal Keep the type for inference */ readonly __contextType?: TContext; /** @internal Keep the type for inference */ readonly __paramsType?: TParams; /** @internal Keep the type for inference */ readonly __serviceType?: TService; /** * Creates a new controller with the given parameters */ new (params: TParams): Controller; /** * Creates a new controller with the given providers */ new (providers: ReadonlyArray): Controller; } : { /** @internal Keep the type for inference */ readonly __contextType?: TContext; /** @internal Keep the type for inference */ readonly __serviceType?: TService; /** * Creates a new controller */ new (): Controller; /** * Creates a new controller with the given providers */ new (providers: ReadonlyArray): Controller; }; /** * @internal * * Base class for controllers */ declare abstract class BaseController { protected readonly context: ControllerContext; protected readonly scope: Scope; protected readonly params: TContext['params']; protected readonly onCreateSignal: Signal; protected readonly onDestroySignal: Signal; protected constructor(paramsOrProviders?: TContext['params'] | ReadonlyArray, extensions?: ReadonlyArray>); /** * Called when the controller is created. * * This callback is called in a next microtask as soon as the controller is created. */ protected onCreated(): void; /** * Called when the controller is destroyed synchronously. */ protected onDestroy(): void; /** * Destroys the controller */ destroy(): void; } /** * Base class declaration for controllers */ type ControllerClassDeclaration = TContext extends ControllerParamsContext ? { /** @internal Keep the type for inference */ readonly __contextType?: TContext; /** @internal Keep the type for inference */ readonly __paramsType?: TParams; /** * Creates a new controller with the given parameters */ new (params: TParams): BaseController; /** * Creates a new controller with the given providers */ new (providers: ReadonlyArray): BaseController; } : { /** @internal Keep the type for inference */ readonly __contextType?: TContext; /** * Creates a new controller */ new (): BaseController; /** * Creates a new controller with the given providers */ new (providers: ReadonlyArray): BaseController; }; /** * Utility type to infer the params type from a controller */ type InferContextParams = TContext extends ControllerParamsContext ? InferredParams : ElseType; type ControllerContext = TContext & { create(declaration: ControllerDeclaration): Controller; create>(declaration: ControllerDeclaration, params: TParams): Controller; }; /** * Factory function for a controller */ type ControllerFactory = (context: ControllerContext) => PartialController | undefined | void; /** * @internal * * Builder for controller declarations */ declare class ControllerDeclarationBuilder { /** * Extensions that should be applied to the controller */ readonly extensions: Array>; /** * Creates a new builder * * @param extensions Extensions that should be applied to the controller */ constructor(extensions?: Array>); /** * Declares the controller with the given parameters */ params(): ControllerDeclarationBuilder>; /** * Declares the controller with the given extension */ extend(extension: ExtensionFn): ControllerDeclarationBuilder; /** * Creates the controller declaration using declared context and the given factory */ apply(factory: ControllerFactory): ControllerDeclaration; /** * Returns the base class for the controller using the declared context */ getBaseClass(): ControllerClassDeclaration; } /** * Returns a new controller declaration using the given factory */ declare function declareController(factory: ControllerFactory): ControllerDeclaration; /** * Returns the builder of controller declaration */ declare function declareController(): ControllerDeclarationBuilder; /** * Provides the controller parameters */ declare function provideControllerParams, TContext extends TDeclaration extends ControllerDeclaration ? InferredContext : never>(params: TContext['params']): ExtensionParamsProvider; /** * Provides arbitrary extension parameters */ declare function provideExtensionParams(params: ExtensionParams): ExtensionParamsProvider; export { type BaseControllerContext as B, type Controller as C, type ExtensionFn as E, type BaseService as a, type ControllerContext as b, type ControllerDeclaration as c, type ControllerClassDeclaration as d, type ControllerFactory as e, type ControllerParams as f, type ControllerParamsContext as g, type ExtensionParams as h, type ExtensionParamsProvider as i, ControllerConstructorError as j, declareController as k, provideControllerParams as l, BaseController as m, provideExtensionParams as p };