import { InjectionModeType } from './injection-mode'; import { LifetimeType } from './lifetime'; import { GlobWithOptions } from './list-modules'; import { LoadModulesOptions } from './load-modules'; import { BuildResolverOptions, Constructor, Resolver } from './resolvers'; /** * The container returned from createContainer has some methods and properties. * @interface AwilixContainer */ export interface AwilixContainer { /** * Options the container was configured with. */ options: ContainerOptions; /** * The proxy injected when using `PROXY` injection mode. * Can be used as-is. */ readonly cradle: Cradle; /** * Getter for the rolled up registrations that merges the container family tree. */ readonly registrations: RegistrationHash; /** * Resolved modules cache. */ readonly cache: Map; /** * Creates a scoped container with this one as the parent. */ createScope(): AwilixContainer; /** * Used by `util.inspect`. */ inspect(depth: number, opts?: any): string; /** * Binds `lib/loadModules` to this container, and provides * real implementations of it's dependencies. * * Additionally, any modules using the `dependsOn` API * will be resolved. * * @see src/load-modules.ts documentation. */ loadModules(globPatterns: Array, options?: LoadModulesOptions): ESM extends false ? this : Promise; /** * Adds a single registration that using a pre-constructed resolver. */ register(name: string | symbol, registration: Resolver): this; /** * Pairs resolvers to registration names and registers them. */ register(nameAndRegistrationPair: NameAndRegistrationPair): this; /** * Resolves the registration with the given name. * * @param {string} name * The name of the registration to resolve. * * @return {*} * Whatever was resolved. */ resolve(name: K, resolveOptions?: ResolveOptions): Cradle[K]; /** * Resolves the registration with the given name. * * @param {string} name * The name of the registration to resolve. * * @return {*} * Whatever was resolved. */ resolve(name: string | symbol, resolveOptions?: ResolveOptions): T; /** * Checks if the registration with the given name exists. * * @param {string | symbol} name * The name of the registration to resolve. * * @return {boolean} * Whether or not the registration exists. */ hasRegistration(name: string | symbol): boolean; /** * Recursively gets a registration by name if it exists in the * current container or any of its' parents. * * @param name {string | symbol} The registration name. */ getRegistration(name: K): Resolver | null; /** * Recursively gets a registration by name if it exists in the * current container or any of its' parents. * * @param name {string | symbol} The registration name. */ getRegistration(name: string | symbol): Resolver | null; /** * Given a resolver, class or function, builds it up and returns it. * Does not cache it, this means that any lifetime configured in case of passing * a resolver will not be used. * * @param {Resolver|Class|Function} targetOrResolver * @param {ResolverOptions} opts */ build(targetOrResolver: ClassOrFunctionReturning | Resolver, opts?: BuildResolverOptions): T; /** * Disposes this container and it's children, calling the disposer * on all disposable registrations and clearing the cache. * Only applies to registrations with `SCOPED` or `SINGLETON` lifetime. */ dispose(): Promise; } /** * Optional resolve options. */ export interface ResolveOptions { /** * If `true` and `resolve` cannot find the requested dependency, * returns `undefined` rather than throwing an error. */ allowUnregistered?: boolean; } /** * Cache entry. */ export interface CacheEntry { /** * The resolver that resolved the value. */ resolver: Resolver; /** * The resolved value. */ value: T; } /** * Register a Registration * @interface NameAndRegistrationPair */ export type NameAndRegistrationPair = { [U in keyof T]?: Resolver; }; /** * Function that returns T. */ export type FunctionReturning = (...args: Array) => T; /** * A class or function returning T. */ export type ClassOrFunctionReturning = FunctionReturning | Constructor; /** * The options for the createContainer function. */ export interface ContainerOptions { require?: (id: string) => any; injectionMode?: InjectionModeType; strict?: boolean; } /** * Contains a hash of registrations where the name is the key. */ export type RegistrationHash = Record>; export type ResolutionStack = Array<{ name: string | symbol; lifetime: LifetimeType; }>; /** * Creates an Awilix container instance. * * @param {Function} options.require The require function to use. Defaults to require. * * @param {string} options.injectionMode The mode used by the container to resolve dependencies. * Defaults to 'Proxy'. * * @param {boolean} options.strict True if the container should run in strict mode with additional * validation for resolver configuration correctness. Defaults to false. * * @return {AwilixContainer} The container. */ export declare function createContainer(options?: ContainerOptions): AwilixContainer;