import type { z, ZodType } from 'zod/v4' import type { BoundInjectionToken, ClassType, ClassTypeWithArgument, FactoryInjectionToken, InjectionToken, InjectionTokenSchemaType, } from '../token/injection-token.mjs' import type { Join, UnionToArray } from '../utils/types.mjs' import type { Factorable } from './factory.interface.mjs' /** * Interface for dependency injection containers. * Both Container and ScopedContainer implement this interface, * allowing them to be used interchangeably in factory contexts. */ export interface IContainer { /** * Gets an instance from the container. */ // #1 Simple class get( token: T, ): InstanceType extends Factorable ? Promise : Promise> // #1.1 Simple class with args get, R>( token: T, args: R, ): Promise> // #2 Token with required Schema get( token: InjectionToken, args: z.input, ): Promise // #3 Token with optional Schema get( token: InjectionToken, ): R extends false ? Promise : S extends ZodType ? `Error: Your token requires args: ${Join< UnionToArray, ', ' >}` : 'Error: Your token requires args' // #4 Token with no Schema get(token: InjectionToken): Promise get(token: BoundInjectionToken): Promise get(token: FactoryInjectionToken): Promise /** * Invalidates a service and its dependencies. */ invalidate(service: unknown): Promise /** * Checks if a service is registered in the container. */ isRegistered(token: any): boolean /** * Adds an instance to the container. * Accepts class types, InjectionTokens, and BoundInjectionTokens. * Rejects InjectionTokens with required schemas (use BoundInjectionToken instead). * * @param token The class type, InjectionToken, or BoundInjectionToken to register the instance for * @param instance The instance to store */ addInstance( token: ClassType | InjectionToken | BoundInjectionToken, instance: T, ): void /** * Disposes the container and cleans up all resources. */ dispose(): Promise /** * Waits for all pending operations to complete. */ ready(): Promise /** * @internal * Attempts to get an instance synchronously if it already exists. * Returns null if the instance doesn't exist or is not ready. * Used internally by the inject system for synchronous property initialization. */ tryGetSync(token: any, args?: any): T | null }