import { DIKey, Callable } from '../../distage/model/DIKey.js'; import { AnyBinding } from '../../distage/model/Binding.js'; import { BindingTags, Axis, AxisPoint } from '../../distage/model/Activation.js'; import { Functoid } from '../../distage/core/Functoid.js'; /** * Helper type to extract instance types from a tuple of constructor types. * Maps [typeof Database, typeof Config] -> [Database, Config] */ type InstanceTypes = T extends readonly [infer First, ...infer Rest] ? [ First extends abstract new (...args: any[]) => infer R ? R : First, ...InstanceTypes ] : []; /** * Builder for specifying the source of a binding (like izumi-chibi-py's .using()) */ export declare class BindingFromBuilder { private readonly bindingBuilder; private readonly constructorTypes?; constructor(bindingBuilder: BindingBuilder, constructorTypes?: any[] | undefined); /** * Bind to a specific class type (will be instantiated via constructor injection) */ type(implementation: new (...args: any[]) => T): ModuleDef; /** * Bind to a specific value instance */ value(instance: T): ModuleDef; /** * Bind to a factory function or Functoid */ factory(factory: (...args: any[]) => R): ModuleDef; factory(functoid: Functoid): ModuleDef; /** * Bind to a pre-constructed Functoid * * Example: * const myFunctoid = Functoid.fromFunction([Database, Config], (db, cfg) => ...); * module.make(UserService).from().functoid(myFunctoid) */ functoid(functoid: Functoid): ModuleDef; /** * Bind to a type-safe factory function with explicit parameter types. * This is a shorthand for Functoid.fromFunction(). * * Supports both synchronous and asynchronous factories. * * Example: * // Synchronous * module.make(UserService).from().func( * [Database, Config], * (db, cfg) => new UserService(db, cfg) * ) * * // Asynchronous * module.make(Database).from().func( * [], * async () => { * const db = new Database(); * await db.connect(); * return db; * } * ) */ func any)[], R extends T>(types: Args, fn: (...params: InstanceTypes) => R | Promise): ModuleDef; /** * Create an alias to another binding * Can accept either a type with optional ID, or a DIKey directly */ alias(target: Callable | DIKey, targetId?: string): ModuleDef; /** * Create an assisted factory binding (for runtime parameters + DI) */ assistedFactory(assistedParams?: string[]): ModuleDef; } /** * Builder for creating a single binding with fluent API */ export declare class BindingBuilder { private readonly type; private readonly module; private currentId?; private currentTags; private constructorTypes?; constructor(type: Callable | symbol, module: ModuleDef); /** * Add a named identifier to this binding */ named(id: string): this; /** * Specify constructor parameter types explicitly (required without reflect-metadata) * * Example: * module.make(UserService).withDeps([Database, Config]).from().type(UserService) */ withDeps(types: any[]): this; /** * Tag this binding with an axis point for conditional selection */ tagged(axis: Axis, choice: string): this; tagged(point: AxisPoint): this; /** * Start specifying where the binding comes from (izumi-chibi-py style) */ from(): BindingFromBuilder; /** * Get the DIKey for this binding */ private getKey; /** * Internal method to finalize the binding * @internal */ finalize(createBinding: (key: DIKey, tags: BindingTags) => AnyBinding): ModuleDef; } /** * Builder for specifying the source of a set element binding */ export declare class SetBindingFromBuilder { private readonly setBuilder; constructor(setBuilder: SetBindingBuilder); /** * Add a class type to the set (will be instantiated) */ type(implementation: new (...args: any[]) => T): ModuleDef; /** * Add a value instance to the set */ value(instance: T): ModuleDef; /** * Add a factory to the set */ factory(factory: (...args: any[]) => R): ModuleDef; factory(functoid: Functoid): ModuleDef; /** * Add a pre-constructed Functoid to the set * * Example: * const myFunctoid = Functoid.fromFunction([Database], (db) => new Plugin(db)); * module.many(Plugin).from().functoid(myFunctoid) */ functoid(functoid: Functoid): ModuleDef; /** * Add a type-safe factory function to the set with explicit parameter types. * This is a shorthand for Functoid.fromFunction(). * * Example: * module.many(Plugin).from().func( * [Database], * (db) => new AuthPlugin(db) * ) */ func any)[], R extends T>(types: Args, fn: (...params: InstanceTypes) => R): ModuleDef; } /** * Builder for set bindings */ export declare class SetBindingBuilder { private readonly elementType; private readonly module; private currentId?; private currentTags; private weak; constructor(elementType: Callable | symbol, module: ModuleDef); /** * Add a named identifier to this set binding */ named(id: string): this; /** * Tag this set binding */ tagged(axis: Axis, choice: string): this; tagged(point: AxisPoint): this; /** * Mark this as a weak set binding (only included if dependencies are satisfied) */ makeWeak(): this; /** * Start specifying where the set element comes from */ from(): SetBindingFromBuilder; private getSetKey; private getElementKey; /** * Internal method to finalize a set element binding * @internal */ finalizeElement(createBinding: (setKey: DIKey>, elementKey: DIKey, tags: BindingTags, weak: boolean) => AnyBinding): ModuleDef; } /** * Main DSL for defining dependency injection modules. * Provides a fluent API for declaring bindings, inspired by izumi-chibi-py. * * Example: * const module = new ModuleDef() * .make(Database).from().type(PostgresDatabase) * .make(UserService).from().type(UserService) * .make(Config).named('db').from().value(dbConfig) * .many(Plugin).from().type(AuthPlugin) * .many(Plugin).from().type(LoggingPlugin); * * The .from() method returns a builder that supports: * - .type(Class) - bind to a class (constructor injection) * - .value(instance) - bind to a specific instance * - .factory(fn) - bind to a factory function * - .alias(TargetClass) - create an alias to another binding */ export declare class ModuleDef { private bindings; /** * Start defining a binding for a type or symbol token */ make(type: Callable | symbol): BindingBuilder; /** * Start defining a set binding for a type or symbol token */ many(elementType: Callable | symbol): SetBindingBuilder; /** * Add a binding directly (internal use) */ addBinding(binding: AnyBinding): void; /** * Get all bindings defined in this module */ getBindings(): readonly AnyBinding[]; /** * Merge this module with another, combining bindings */ append(other: ModuleDef): ModuleDef; /** * Override bindings in this module with those from another module. * Later bindings take precedence. */ overriddenBy(other: ModuleDef): ModuleDef; /** * Get the number of bindings in this module */ size(): number; } export {}; //# sourceMappingURL=ModuleDef.d.ts.map