/// import { AsyncLocalStorage } from "async_hooks"; export declare enum ContainerScope { Value = "VALUE", Contextual = "CONTEXTUAL", Singleton = "SINGLETON", Transient = "TRANSIENT" } interface IClass { new (...args: any): T; } export type ContainerIdentifer = string | symbol; export type ContainerValueIdentifier = string | symbol | CallableFunction | IClass; export type ContainerValue = IContainerValue | IContainerFactory; export interface IContainerValue { id: ContainerValueIdentifier; scope: ContainerScope; value: any; } export interface IContainerFactory { id: ContainerValueIdentifier; scope: ContainerScope; factory: CallableFunction; deps: Array; } export declare class Container { protected asyncLocalStorage?: AsyncLocalStorage | undefined; readonly id: ContainerIdentifer; static contextRegistryKey: string; protected registry: Map, ContainerValue>; protected resolvedRegistry: Map, any>; constructor(id: ContainerIdentifer, asyncLocalStorage?: AsyncLocalStorage | undefined); findRegistryValue(id: ContainerValueIdentifier): ContainerValue | undefined; putRegistryValue(value: ContainerValue): void; cloneWith(id: ContainerIdentifer, ...args: ContainerValueIdentifier[]): Container; /** * create error with identifier * @param id container id * @param message error message * @returns */ createErrorWithIdentifier(id: ContainerValueIdentifier, message: string): Error; /** * add or replace * @param {ContainerValue} data * @param {boolean} replace */ register(data: ContainerValue, replace?: boolean): void; delete(id: ContainerValueIdentifier): void; has(id: ContainerValueIdentifier): boolean; /** * only set if not exists * @param data * @returns */ set(data: ContainerValue): void; /** * set or replace * @param data * @returns */ put(data: ContainerValue): void; /** * value scope, for static values * @param id * @returns */ value(id: ContainerValueIdentifier): T; /** * check if container already have resolved value * @param id * @returns */ hasResolved(id: ContainerValueIdentifier): boolean; protected valueResolver(data: ContainerValue): any; /** * unused * @param data * @returns */ protected factoryResolver(data: ContainerValue): any; /** * use to resolve async deps * @param id * @returns */ resolveAsync(id: ContainerIdentifer): Promise; /** * resolve service with given identifier * @param id * @returns */ resolve(id: ContainerValueIdentifier): T; /** * does not consider/respect scope, always return fresh value if possible, * as static value will be always be stale * @param id * @returns */ fresh(id: ContainerValueIdentifier): T; /** * call a function with given deps * @param cb * @param deps * @returns */ call(cb: Function, deps?: Array): any; /** * call a async function or when you have async deps * @param cb * @param deps * @returns */ callAsync(cb: Function, deps?: Array): Promise; /** * pre-resolve all Singleton deps */ preresolve(): void; /** * each context will have different registry * @returns */ protected ctxRegistry(): Map; setAsyncLocalStorage(asyncLocalStorage: AsyncLocalStorage): void; contextStore(): T; contextStoreSet(k: string, v: any): void; contextStoreGet(k: string): T | undefined; asyncLocalRun(store: any, cb: CallableFunction): unknown; } export {};