import { Context } from "./base-context.mjs"; //#region ../@warlock.js/context/src/context-manager.d.ts /** * Context Manager - Orchestrates multiple contexts together * * Allows running multiple AsyncLocalStorage contexts in a single operation, * making it easy to link request, storage, database, and other contexts. * * @example * ```typescript * // Register contexts * contextManager * .register('request', requestContext) * .register('storage', storageDriverContext) * .register('database', databaseDataSourceContext); * * // Run all contexts together * await contextManager.runAll({ * request: { request, response, user }, * storage: { driver, metadata: { tenantId: '123' } }, * database: { dataSource: 'primary' }, * }, async () => { * // All contexts active! * await handleRequest(); * }); * ``` */ declare class ContextManager { private contexts; /** * Register a context * * @param name - Unique context name * @param context - Context instance * @returns This instance for chaining */ register(name: string, context: Context): this; /** * Run all registered contexts together * * Nests all context.run() calls, ensuring all contexts are active * for the duration of the callback. * * @param stores - Context stores keyed by context name * @param callback - Async function to execute * @returns Result of the callback */ runAll(stores: Record, callback: () => Promise): Promise; /** * Enter all contexts at once (for middleware) * * @param stores - Context stores keyed by context name */ enterAll(stores: Record): void; /** * Clear all contexts */ clearAll(): void; /** * Get a specific registered context * * @param name - Context name * @returns Context instance or undefined */ getContext>(name: string): T | undefined; /** * Check if a context is registered * * @param name - Context name * @returns True if context is registered */ hasContext(name: string): boolean; /** * Build all context stores by calling each context's buildStore() method * * This is the immutable pattern - returns a new record of stores. * Each context defines its own initialization logic. * * @param payload - Payload passed to each buildStore() (e.g., { request, response }) * @returns Record of context name -> store data * * @example * ```typescript * const httpContextStore = contextManager.buildStores({ request, response }); * await contextManager.runAll(httpContextStore, async () => { ... }); * ``` */ buildStores(payload?: Record): Record; /** * Unregister a context * * @param name - Context name to remove * @returns True if context was removed */ unregister(name: string): boolean; } /** * Global context manager instance * * Use this singleton to register and manage all framework contexts. */ declare const contextManager: ContextManager; //#endregion export { ContextManager, contextManager }; //# sourceMappingURL=context-manager.d.mts.map