import { Binding } from './binding'; import { BindingSelector } from './binding-filter'; import { Context } from './context'; import { Injection, InjectionMetadata } from './inject'; import { BoundValue, ValueOrPromise } from './value-promise'; /** * A function to be executed with the resolution session */ export declare type ResolutionAction = (session: ResolutionSession) => ValueOrPromise; /** * Wrapper for bindings tracked by resolution sessions */ export interface BindingElement { type: 'binding'; value: Readonly; } /** * Wrapper for injections tracked by resolution sessions */ export interface InjectionElement { type: 'injection'; value: Readonly; } export interface InjectionDescriptor { targetName: string; bindingSelector: BindingSelector; metadata: InjectionMetadata; } /** * Binding or injection elements tracked by resolution sessions */ export declare type ResolutionElement = BindingElement | InjectionElement; /** * Object to keep states for a session to resolve bindings and their * dependencies within a context */ export declare class ResolutionSession { /** * A stack of bindings for the current resolution session. It's used to track * the path of dependency resolution and detect circular dependencies. */ readonly stack: ResolutionElement[]; /** * Fork the current session so that a new one with the same stack can be used * in parallel or future resolutions, such as multiple method arguments, * multiple properties, or a getter function * @param session - The current session */ static fork(session?: ResolutionSession): ResolutionSession | undefined; /** * Run the given action with the given binding and session * @param action - A function to do some work with the resolution session * @param binding - The current binding * @param session - The current resolution session */ static runWithBinding(action: ResolutionAction, binding: Readonly, session?: ResolutionSession): any; /** * Run the given action with the given injection and session * @param action - A function to do some work with the resolution session * @param binding - The current injection * @param session - The current resolution session */ static runWithInjection(action: ResolutionAction, injection: Readonly, session?: ResolutionSession): any; /** * Describe the injection for debugging purpose * @param injection - Injection object */ static describeInjection(injection: Readonly): InjectionDescriptor; /** * Push the injection onto the session * @param injection - Injection The current injection */ pushInjection(injection: Readonly): void; /** * Pop the last injection */ popInjection(): Readonly>; /** * Getter for the current injection */ get currentInjection(): Readonly | undefined; /** * Getter for the current binding */ get currentBinding(): Readonly | undefined; /** * Enter the resolution of the given binding. If * @param binding - Binding */ pushBinding(binding: Readonly): void; /** * Exit the resolution of a binding */ popBinding(): Readonly; /** * Getter for bindings on the stack */ get bindingStack(): Readonly[]; /** * Getter for injections on the stack */ get injectionStack(): Readonly[]; /** * Get the binding path as `bindingA --> bindingB --> bindingC`. */ getBindingPath(): string; /** * Get the injection path as `injectionA --> injectionB --> injectionC`. */ getInjectionPath(): string; /** * Get the resolution path including bindings and injections, for example: * `bindingA --> @ClassA[0] --> bindingB --> @ClassB.prototype.prop1 * --> bindingC`. */ getResolutionPath(): string; toString(): string; } /** * Options for binding/dependency resolution */ export interface ResolutionOptions { /** * A session to track bindings and injections */ session?: ResolutionSession; /** * A boolean flag to indicate if the dependency is optional. If it's set to * `true` and the binding is not bound in a context, the resolution * will return `undefined` instead of throwing an error. */ optional?: boolean; /** * A boolean flag to control if a proxy should be created to apply * interceptors for the resolved value. It's only honored for bindings backed * by a class. */ asProxyWithInterceptors?: boolean; } /** * Resolution options or session */ export declare type ResolutionOptionsOrSession = ResolutionOptions | ResolutionSession; /** * Normalize ResolutionOptionsOrSession to ResolutionOptions * @param optionsOrSession - resolution options or session */ export declare function asResolutionOptions(optionsOrSession?: ResolutionOptionsOrSession): ResolutionOptions; /** * Contextual metadata for resolution */ export interface ResolutionContext { /** * The context for resolution */ readonly context: Context; /** * The binding to be resolved */ readonly binding: Readonly>; /** * The options used for resolution */ readonly options: ResolutionOptions; } /** * Error for context binding resolutions and dependency injections */ export declare class ResolutionError extends Error { readonly resolutionCtx: Partial; constructor(message: string, resolutionCtx: Partial); private static buildDetails; /** * Build the error message for the resolution to include more contextual data * @param reason - Cause of the error * @param resolutionCtx - Resolution context */ private static buildMessage; private static describeResolutionContext; }