//#region src/provider/provider.d.ts /** * The symbol used to identify providable classes. * * @category Provider */ declare const provide: unique symbol; /** * An object which contains provider information. * * @param TValue The value type provided by the Providable. * @category Provider */ type Providable = { readonly [provide]: ProviderInfo; }; /** * The provider information used to resolve a value. * * @param TValue The value type provided by the provider. * @category Provider */ type ProviderInfo = { readonly async?: undefined | false; getValue: (ctx: Context) => TValue; } | { readonly async: true; getValue: (ctx: Context) => Promise | TValue; }; /** * Infer the value type provided by a {@link ProvidableClass}. * * @param T The class to infer the value type from. * @category Provider */ type ProvidedValue = T extends ProvidableClass ? TValue : never; /** * A class which provides a value and conforms to {@link Providable}. * * @param TValue The value type provided by the class. * @param TArgs The arguments of the class. * @category Provider */ type ProvidableClass = Class>; //#endregion //#region src/types.d.ts /** * A representation of a class type. * * @param TArgs The arguments of the class. * @param TInstance The instance type of the class. * @category Utility Type */ type Class = abstract new (...args: TArgs) => TInstance; /** * Extracts properties from a type `T` whose types match `V` exactly. * * @param T The source type. * @param V The value type to extract. * @category Utility Type */ type ExtractProperties = { [K in keyof T as T[K] extends V ? (V extends T[K] ? K : never) : never]: T[K] }; /** * A type representing a postconstruct function for a class. * * This can be: * - A function that returns a void promise and is bound to the instance. * - A function that returns another function which is bound to the instance and returns a void promise. * - A key of a method on the instance that returns a void promise. */ type Postcontructable = ((this: InstanceType) => void | Promise) | (() => (this: InstanceType) => void | Promise) | keyof ExtractProperties, (() => Promise) | (() => void)>; /** * The resolved instance of a class when {@link tap} or {@link tapAsync} is called. * * It is similar to the {@link InstanceType} utility type, but resolves {@link Providable} classes. * * @param TClass The class to resolve. * @category Utility Type */ type ResolvedInstance = ProvidedValue extends never ? InstanceType : ProvidedValue; /** * The resolved instances of multiple classes in an array. * * It is similar to the {@link ResolvedInstance} type, but for multiple classes. * * @category Utility Type */ type ResolvedInstances = TClasses extends never[] ? readonly [] : { readonly [TKey in keyof TClasses]: ResolvedInstance }; /** * The context which is provided inside preconstructors and providers. * * @param TOrigin The origin class of the context. * @category Utility Type */ type Context = { /** * The circuit which is currently resolving the target. */ circuit: Circuit; /** * The target class which is currently being resolved. */ target: TOrigin; /** * The class which depends on the target and the reason why it is being resolved. * * This can be `undefined` if the target is being resolved directly using {@link tap} or {@link tapAsync}. */ dependent?: Class; }; //#endregion //#region src/circuit.d.ts /** * A circuit is a container which is responsible for managing the instances by holding and initializing them. * * Only one instance of a class can exist in a circuit. * * @category Core */ declare class Circuit { #private; constructor(); tap(target: TTarget): ResolvedInstance; tapAsync(target: TTarget): Promise>; /** * Installing means to manually add an instance to the circuit. * The installed instance class also doesn't need to be wired * because you are responsible for initializing it. * * For example, when a circuit is created, it installs itself as an instance. * With this, it is possible to use the circuit class as an input. * * You can use this to manually add instances you already have initialized. * * @param target The class of the instance to install. * @param instance The instance to install. * @returns The instance that was installed. */ install(target: TTarget, instance: InstanceType): InstanceType; /** * Uninstalling means to manually remove an instance from the circuit. * * This method should be used with caution! * * @param target The class of the instance to uninstall. * @returns The instance that was uninstalled, or undefined if not found. */ uninstall(target: TTarget): InstanceType | undefined; /** * Check if the given class is installed (initialized) in this circuit. * * @param target The class to check. * @returns True if the class is installed (initialized), false otherwise. */ isInstalled(target: Class): boolean; /** * Get the instance of the given class. * * NOTICE: This method is a low-level operation as it does not instantiate classes or resolve providable classes. Use it with caution. * * @param target The class to get the instance for. * @returns The instance of the class, or undefined if not found. */ get(target: TTarget): ResolvedInstance | undefined; /** * Check if the given class has async initializer * or provides an async value. * * Classes without an async initializer will be instantiated * if not yet initialized in the circuit. This is necessary to * receive possible provider info. * * @param target The class to check. * @returns True if the class has async initializer or provides an async value, false otherwise. */ isAsync(target: Class): boolean; static getDefault(): Circuit; } /** * @category Core */ declare const tap: (target: TTarget, circuit?: Circuit) => ResolvedInstance; /** * @category Core */ declare const tapAsync: (target: TTarget, circuit?: Circuit) => Promise>; /** * @category Core */ declare const getContext: () => Context; /** * @category Core */ declare const getCircuit: () => Circuit; /** * @category Core */ declare const link: (target: T) => ResolvedInstance; //#endregion //#region src/definition/decorators.d.ts /** * @category Definition */ declare const unwire: (target: Class) => boolean; /** * @category Definition */ declare const isWired: (target: Class) => boolean; /** * @category Definition Decorator */ declare const singleton: (circuit?: Circuit) => (target: T) => void; /** * @category Definition Function */ declare const defineSingleton: (target: T, circuit?: Circuit) => void; /** * @category Definition Decorator */ declare const requires: >, const TDeps extends readonly Class[]>(dependencies: () => TDeps) => (target: TTarget) => void; /** * @category Definition Function */ declare const defineRequires: >, const TDeps extends readonly Class[]>(target: TTarget, dependencies: () => TDeps) => void; /** * @category Definition Decorator */ declare const standalone: >() => (target: T) => void; /** * @category Definition Function */ declare const defineStandalone: >(target: T) => void; /** * @category Definition Decorator */ declare const preconstruct: (preconstruct: (dependencies: ResolvedInstances, context: Context) => InstanceType, dependencies?: () => TDeps) => (target: T) => void; /** * @category Definition Function */ declare const definePreconstruct: (target: T, preconstruct: (dependencies: ResolvedInstances, context: Context) => InstanceType, dependencies?: () => TDeps) => void; /** * @category Definition Decorator */ declare const preconstructAsync: (preconstructAsync: (dependencies: ResolvedInstances, context: Context) => Promise<() => InstanceType>, dependencies?: () => TDeps) => (target: T) => void; /** * @category Definition Function */ declare const definePreconstructAsync: , const TDeps extends readonly Class[] = readonly []>(target: T, preconstructAsync: (dependencies: ResolvedInstances, context: Context) => Promise<() => InstanceType>, dependencies?: () => TDeps) => void; /** * @category Definition Decorator */ declare const postconstructAsync: >(setup: TSetup) => (target: T) => void; /** * @category Definition Function */ declare const definePostconstructAsync: >(target: T, setup: TSetup) => void; /** * @category Definition Decorator */ declare const preloads: (preloads: () => readonly Class[]) => (target: T) => void; /** * @category Definition Function */ declare const definePreloads: (target: T, preloads: () => readonly Class[]) => void; //#endregion //#region src/definition/definition.d.ts /** * @category Definition */ declare class WireDefinition { readonly target: Class; private constructor(); singleton?: Circuit; dependencies?: () => readonly Class[]; preloads?: () => readonly Class[]; preconstructAsync?: (dependencies: readonly unknown[], context: Context) => Promise<() => unknown>; preconstruct?: (dependencies: readonly unknown[], context: Context) => unknown; postconstructAsync?: (() => void | Promise) | (() => () => void | Promise); isValid(): boolean; remove(): boolean; static from(target: Class, createIfNotExists?: false): WireDefinition | undefined; static from(target: Class, createIfNotExists: true): WireDefinition; static define(target: Class, options?: Partial): WireDefinition; } //#endregion //#region src/errors.d.ts /** * The base class for all Wirebox errors. * * @category Error */ declare class WireboxError extends Error {} /** * Thrown when a class is not set up for wiring. * * @category Error */ declare class UnwiredError extends WireboxError { readonly target: Class; /** * @param target The target class. */ constructor(target: Class); } /** * Thrown when a class is already initialized. * * @category Error */ declare class AlreadyInitializedError extends WireboxError { readonly target: Class; /** * @param target The target class. */ constructor(target: Class); } /** * Thrown when an async dependency is used in a sync context. * * @category Error */ declare class AsyncDependencyError extends WireboxError { readonly target: Class; /** * @param target The target class. * @param initializing Whether the class is currently initializing. */ constructor(target: Class, initializing: boolean); } /** * Thrown when the circuit context is not available. * * @category Error */ declare class NoCircuitContextError extends WireboxError { constructor(); } /** * Thrown when a class with an {@link provide} implementation is not a valid {@link Providable}. * * @category Error */ declare class InvalidProvidableError extends WireboxError { readonly target: Class; /** * @param target The target class. */ constructor(target: Class); } //#endregion //#region src/provider/common.d.ts /** * @category Common Provider */ declare class BasicValueProvider implements Providable { readonly value: T; constructor(value: T); [provide]: { getValue: () => T; }; } /** * @category Common Provider */ declare const createProvider: (getValue: (ctx: Context) => T) => ProvidableClass; /** * @category Common Provider */ declare const createAsyncProvider: (getValue: (ctx: Context) => Promise) => ProvidableClass; /** * @category Common Provider */ declare const createStaticProvider: (value: T) => ProvidableClass; /** * @category Common Provider */ declare const createAsyncStaticProvider: (value: Promise) => ProvidableClass; /** * @category Common Provider */ declare const createDynamicProvider: (getValue: (ctx: Context) => T) => ProvidableClass; /** * @category Common Provider */ declare const createAsyncDynamicProvider: (getValue: (ctx: Context) => Promise) => ProvidableClass; //#endregion //#region src/utilities/combine.d.ts /** * Converts a record of classes to a record of resolved instances. * * @category Utility: Combine */ type ResolvedCombine> = { [Key in keyof TTargets]: ResolvedInstance }; /** * Combines multiple classes into a single value by resolving a record * of classes to a record of resolved instances. * * @param getTargets A function which returns the record of classes to resolve. * @returns A value provider which returns with a record of resolved instances. * @category Utility: Combine */ declare const combine: >(getTargets: () => TTargets) => ProvidableClass, [circuit: Circuit]>; //#endregion //#region src/utilities/conditional.d.ts /** * A target that a conditional decorator can resolve to, either a class * extending `T` or a providable class providing an instance of `T`. */ type ConditionalTarget = Class> | ProvidableClass>; /** * @category Utility: Conditional */ declare const conditional: (resolve: (dependencies: ResolvedInstances, context: Context) => ConditionalTarget>, dependencies?: () => TDeps) => (target: T) => void; /** * @category Utility: Conditional */ declare const defineConditional: (target: T, resolve: (dependencies: ResolvedInstances, context: Context) => ConditionalTarget>, dependencies?: () => TDeps) => void; /** * @category Utility: Conditional */ declare const conditionalAsync: (resolveAsync: (dependencies: ResolvedInstances, context: Context) => Promise>> | ConditionalTarget>, dependencies?: () => TDeps) => (target: T) => void; /** * @category Utility: Conditional */ declare const defineConditionalAsync: (target: T, resolveAsync: (dependencies: ResolvedInstances, context: Context) => Promise>> | ConditionalTarget>, dependencies?: () => TDeps) => void; //#endregion //#region src/utilities/lazy.d.ts /** * Creates a lazy loaded class provider for a named export. * * @param loadModule The function which loads the module (most likely via dynamic import) * @param exportName The optional name of the export to load (defaults to default export ["default"]) * @category Utility: Lazy */ declare const lazy: , TExport extends string = "default">(loadModule: () => Promise, exportName?: TExport) => ProvidableClass>; //#endregion //#region src/utilities/with-circuit.d.ts /** * Bind a {@link Circuit} to a given class. * * This is useful when forced to use a specific circuit but can't or don't want to use singletons. * * Internally, this creates a custom provider which uses the given circuit to resolve the class. * * @param circuit The circuit to instantiate the class from. * @param getTarget The class getter of the target class which should be accessed from the circuit. * @returns An (async) value provider which provides the class instance from the given circuit. * @category Utility: With Circuit */ declare const withCircuit: (circuit: Circuit, getTarget: () => TTarget) => ProvidableClass>; //#endregion export { AlreadyInitializedError, AsyncDependencyError, BasicValueProvider, Circuit, type Class, type Context, InvalidProvidableError, NoCircuitContextError, type Providable, type ProvidableClass, type ProvidedValue, type ProviderInfo, type ResolvedCombine, type ResolvedInstance, type ResolvedInstances, UnwiredError, WireDefinition, WireboxError, combine, conditional, conditionalAsync, createAsyncDynamicProvider, createAsyncProvider, createAsyncStaticProvider, createDynamicProvider, createProvider, createStaticProvider, defineConditional, defineConditionalAsync, definePostconstructAsync, definePreconstruct, definePreconstructAsync, definePreloads, defineRequires, defineSingleton, defineStandalone, getCircuit, getContext, isWired, lazy, link, postconstructAsync, preconstruct, preconstructAsync, preloads, provide, requires, singleton, standalone, tap, tapAsync, unwire, withCircuit };