import { GlobWithOptions } from './list-modules'; import { LoadModulesOptions } from './load-modules'; import { Resolver, Constructor, BuildResolverOptions } from './resolvers'; import { InjectionModeType } from './injection-mode'; /** * 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. */ has(name: string | symbol): boolean; /** * 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 declare type NameAndRegistrationPair = { [U in keyof T]?: Resolver; }; /** * Function that returns T. */ export declare type FunctionReturning = (...args: Array) => T; /** * A class or function returning T. */ export declare type ClassOrFunctionReturning = FunctionReturning | Constructor; /** * The options for the createContainer function. * @interface ContainerOptions */ export interface ContainerOptions { require?: (id: string) => any; injectionMode?: InjectionModeType; } /** * Contains a hash of registrations where the name is the key. */ export declare type RegistrationHash = Record>; /** * Resolution stack. */ export interface ResolutionStack extends Array { } /** * 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'. * * @return {object} * The container. */ export declare function createContainer(options?: ContainerOptions, parentContainer?: AwilixContainer): AwilixContainer;