import { FactoryType } from "../utils/factory_type" ; namespace interfaces { export type DynamicValue < T > = ( context : interfaces . Context ) => T | Promise < T > ; export type ContainerResolution < T > = T | Promise < T > | ( T | Promise < T > ) [ ] ; type AsyncCallback < TCallback > = TCallback extends ( ... args : infer TArgs ) => infer TResult ? ( ... args : TArgs ) => Promise < TResult > : never ; export type BindingScope = "Singleton" | "Transient" | "Request" ; export type BindingType = "ConstantValue" | "Constructor" | "DynamicValue" | "Factory" | "Function" | "Instance" | "Invalid" | "Provider" ; export type TargetType = "ConstructorArgument" | "ClassProperty" | "Variable" ; export interface BindingScopeEnum { Request : interfaces . BindingScope ; Singleton : interfaces . BindingScope ; Transient : interfaces . BindingScope ; } export interface BindingTypeEnum { ConstantValue : interfaces . BindingType ; Constructor : interfaces . BindingType ; DynamicValue : interfaces . BindingType ; Factory : interfaces . BindingType ; Function : interfaces . BindingType ; Instance : interfaces . BindingType ; Invalid : interfaces . BindingType ; Provider : interfaces . BindingType ; } export interface TargetTypeEnum { ConstructorArgument : interfaces . TargetType ; ClassProperty : interfaces . TargetType ; Variable : interfaces . TargetType ; } export type Newable < T > = new ( ... args ) => T ; export interface Abstract < T > { prototype : T ; } export type ServiceIdentifier < T = unknown > = ( string | symbol | Newable < T > | Abstract < T > ) ; export interface Clonable < T > { clone ( ) : T ; } export type BindingActivation < T > = ( context : interfaces . Context , injectable : T ) => T | Promise < T > ; export type BindingDeactivation < T > = ( injectable : T ) => void | Promise < void > ; export interface Binding < TActivated > extends Clonable < Binding < TActivated > > { id : number ; moduleId : ContainerModuleBase [ "id" ] ; activated : boolean ; serviceIdentifier : ServiceIdentifier < TActivated > ; constraint : ConstraintFunction ; dynamicValue : DynamicValue < TActivated > | null ; scope : BindingScope ; type : BindingType ; implementationType : Newable < TActivated > | TActivated | null ; factory : FactoryCreator < unknown > | null ; provider : ProviderCreator < unknown > | null ; onActivation : BindingActivation < TActivated > | null ; onDeactivation : BindingDeactivation < TActivated > | null ; cache : null | TActivated | Promise < TActivated > ; } export type SimpleFactory < T , U extends unknown [ ] = unknown [ ] > = ( ... args : U ) => T ; export type MultiFactory < T , U extends unknown [ ] = unknown [ ] , V extends unknown [ ] = unknown [ ] > = ( ... args : U ) => SimpleFactory < T , V > ; export type Factory < T , U extends unknown [ ] = unknown [ ] , V extends unknown [ ] = unknown [ ] > = SimpleFactory < T , U > | MultiFactory < T , U , V > ; export type FactoryCreator < T , U extends unknown [ ] = unknown [ ] , V extends unknown [ ] = unknown [ ] > = ( context : Context ) => Factory < T , U , V > ; export type AutoNamedFactory < T > = SimpleFactory < T , [ string ] > ; export type AutoFactory < T > = SimpleFactory < T , [ ] > ; export type FactoryTypeFunction < T = unknown > = ( context : interfaces . Context ) => T | Promise < T > ; export interface FactoryDetails { factoryType : FactoryType ; factory : FactoryTypeFunction | null ; } ; export type Provider < T > = ( ... args : any [ ] ) => ( ( ( ... args : any [ ] ) => Promise < T > ) | Promise < T > ) ; export type ProviderCreator < T > = ( context : Context ) => Provider < T > ; export interface NextArgs < T = unknown > { avoidConstraints : boolean ; contextInterceptor : ( ( contexts : Context ) => Context ) ; isMultiInject : boolean ; targetType : TargetType ; serviceIdentifier : interfaces . ServiceIdentifier < T > ; key ? : string | number | symbol ; value ? : unknown ; } export type Next = ( args : NextArgs ) => ( any | any [ ] ) ; export type Middleware = ( next : Next ) => Next ; export type ContextInterceptor = ( context : interfaces . Context ) => interfaces . Context ; export interface Context { id : number ; container : Container ; plan : Plan ; currentRequest : Request ; addPlan ( plan ) : void ; setCurrentRequest ( request ) : void ; } export type MetadataOrMetadataArray = Metadata | Metadata [ ] ; export interface Metadata < TValue = unknown > { key : string | number | symbol ; value : TValue ; } export interface Plan { parentContext : Context ; rootRequest : Request ; } export interface QueryableString { startsWith ( searchString ) : boolean ; endsWith ( searchString ) : boolean ; contains ( searchString ) : boolean ; equals ( compareString ) : boolean ; value ( ) : string ; } export type ResolveRequestHandler = ( request : interfaces . Request ) => unknown ; export type RequestScope = Map < unknown , unknown > ; export interface Request { id : number ; serviceIdentifier : ServiceIdentifier ; parentContext : Context ; parentRequest : Request | null ; childRequests : Request [ ] ; target : Target ; bindings : Binding < unknown > [ ] ; requestScope : RequestScope | null ; addChildRequest ( serviceIdentifier , bindings , target ) : Request ; } export interface Target { id : number ; serviceIdentifier : ServiceIdentifier ; type : TargetType ; name : QueryableString ; identifier : string | symbol ; metadata : Metadata [ ] ; getNamedTag ( ) : interfaces . Metadata < string > | null ; getCustomTags ( ) : interfaces . Metadata [ ] | null ; hasTag ( key ) : boolean ; isArray ( ) : boolean ; matchesArray ( name ) : boolean ; isNamed ( ) : boolean ; isTagged ( ) : boolean ; isOptional ( ) : boolean ; matchesNamedTag ( name ) : boolean ; matchesTag ( key ) : ( value : unknown ) => boolean ; } export interface ContainerOptions { autoBindInjectable ? : boolean ; defaultScope ? : BindingScope ; skipBaseClassChecks ? : boolean ; } export interface Container { id : number ; parent : Container | null ; options : ContainerOptions ; bind < T > ( serviceIdentifier ) : BindingToSyntax < T > ; rebind < T > ( serviceIdentifier ) : interfaces . BindingToSyntax < T > ; rebindAsync < T > ( serviceIdentifier ) : Promise < interfaces . BindingToSyntax < T > > ; unbind ( serviceIdentifier ) : void ; unbindAsync ( serviceIdentifier ) : Promise < void > ; unbindAll ( ) : void ; unbindAllAsync ( ) : Promise < void > ; isBound ( serviceIdentifier ) : boolean ; isCurrentBound < T > ( serviceIdentifier ) : boolean ; isBoundNamed ( serviceIdentifier , named ) : boolean ; isBoundTagged ( serviceIdentifier , key , value ) : boolean ; get < T > ( serviceIdentifier ) : T ; getNamed < T > ( serviceIdentifier , named ) : T ; getTagged < T > ( serviceIdentifier , key , value ) : T ; getAll < T > ( serviceIdentifier ) : T [ ] ; getAllTagged < T > ( serviceIdentifier , key , value ) : T [ ] ; getAllNamed < T > ( serviceIdentifier , named ) : T [ ] ; getAsync < T > ( serviceIdentifier ) : Promise < T > ; getNamedAsync < T > ( serviceIdentifier , named ) : Promise < T > ; getTaggedAsync < T > ( serviceIdentifier , key , value ) : Promise < T > ; getAllAsync < T > ( serviceIdentifier ) : Promise < T [ ] > ; getAllTaggedAsync < T > ( serviceIdentifier , key , value ) : Promise < T [ ] > ; getAllNamedAsync < T > ( serviceIdentifier , named ) : Promise < T [ ] > ; onActivation < T > ( serviceIdentifier , onActivation ) : void ; onDeactivation < T > ( serviceIdentifier , onDeactivation ) : void ; resolve < T > ( constructorFunction ) : T ; load ( ... modules ) : void ; loadAsync ( ... modules ) : Promise < void > ; unload ( ... modules ) : void ; unloadAsync ( ... modules ) : Promise < void > ; applyCustomMetadataReader ( metadataReader ) : void ; applyMiddleware ( ... middleware ) : void ; snapshot ( ) : void ; restore ( ) : void ; createChild ( ) : Container ; } export type Bind = < T > ( serviceIdentifier : ServiceIdentifier < T > ) => BindingToSyntax < T > ; export type Rebind = < T > ( serviceIdentifier : ServiceIdentifier < T > ) => BindingToSyntax < T > ; export type Unbind = < T > ( serviceIdentifier : ServiceIdentifier < T > ) => void ; export type UnbindAsync = < T > ( serviceIdentifier : ServiceIdentifier < T > ) => Promise < void > ; export type IsBound = < T > ( serviceIdentifier : ServiceIdentifier < T > ) => boolean ; export interface ContainerModuleBase { id : number ; } export interface ContainerModule extends ContainerModuleBase { registry : ContainerModuleCallBack ; } export interface AsyncContainerModule extends ContainerModuleBase { registry : AsyncContainerModuleCallBack ; } export interface ModuleActivationHandlers { onActivations : Lookup < BindingActivation < unknown > > ; onDeactivations : Lookup < BindingDeactivation < unknown > > ; } export interface ModuleActivationStore extends Clonable < ModuleActivationStore > { addDeactivation ( moduleId , serviceIdentifier , onDeactivation ) : void ; addActivation ( moduleId , serviceIdentifier , onActivation ) : void ; remove ( moduleId ) : ModuleActivationHandlers ; } export type ContainerModuleCallBack = ( bind : interfaces . Bind , unbind : interfaces . Unbind , isBound : interfaces . IsBound , rebind : interfaces . Rebind , unbindAsync : interfaces . UnbindAsync , onActivation : interfaces . Container [ "onActivation" ] , onDeactivation : interfaces . Container [ "onDeactivation" ] ) => void ; export type AsyncContainerModuleCallBack = AsyncCallback < ContainerModuleCallBack > ; export interface ContainerSnapshot { bindings : Lookup < Binding < unknown > > ; activations : Lookup < BindingActivation < unknown > > ; deactivations : Lookup < BindingDeactivation < unknown > > ; middleware : Next | null ; moduleActivationStore : interfaces . ModuleActivationStore ; } export interface Lookup < T > extends Clonable < Lookup < T > > { add ( serviceIdentifier , value ) : void ; getMap ( ) : Map < interfaces . ServiceIdentifier , T [ ] > ; get ( serviceIdentifier ) : T [ ] ; remove ( serviceIdentifier ) : void ; removeByCondition ( condition ) : T [ ] ; removeIntersection ( lookup ) : void ; hasKey ( serviceIdentifier ) : boolean ; clone ( ) : Lookup < T > ; traverse ( func ) : void ; } export interface BindingOnSyntax < T > { onActivation ( fn ) : BindingWhenSyntax < T > ; onDeactivation ( fn ) : BindingWhenSyntax < T > ; } export interface BindingWhenSyntax < T > { when ( constraint ) : BindingOnSyntax < T > ; whenTargetNamed ( name ) : BindingOnSyntax < T > ; whenTargetIsDefault ( ) : BindingOnSyntax < T > ; whenTargetTagged ( tag , value ) : BindingOnSyntax < T > ; whenInjectedInto ( parent ) : BindingOnSyntax < T > ; whenParentNamed ( name ) : BindingOnSyntax < T > ; whenParentTagged ( tag , value ) : BindingOnSyntax < T > ; whenAnyAncestorIs ( ancestor ) : BindingOnSyntax < T > ; whenNoAncestorIs ( ancestor ) : BindingOnSyntax < T > ; whenAnyAncestorNamed ( name ) : BindingOnSyntax < T > ; whenAnyAncestorTagged ( tag , value ) : BindingOnSyntax < T > ; whenNoAncestorNamed ( name ) : BindingOnSyntax < T > ; whenNoAncestorTagged ( tag , value ) : BindingOnSyntax < T > ; whenAnyAncestorMatches ( constraint ) : BindingOnSyntax < T > ; whenNoAncestorMatches ( constraint ) : BindingOnSyntax < T > ; } export interface BindingWhenOnSyntax < T > extends BindingWhenSyntax < T > , BindingOnSyntax < T > { } export interface BindingInSyntax < T > { inSingletonScope ( ) : BindingWhenOnSyntax < T > ; inTransientScope ( ) : BindingWhenOnSyntax < T > ; inRequestScope ( ) : BindingWhenOnSyntax < T > ; } export interface BindingInWhenOnSyntax < T > extends BindingInSyntax < T > , BindingWhenOnSyntax < T > { } export interface BindingToSyntax < T > { to ( constructor ) : BindingInWhenOnSyntax < T > ; toSelf ( ) : BindingInWhenOnSyntax < T > ; toConstantValue ( value ) : BindingWhenOnSyntax < T > ; toDynamicValue ( func ) : BindingInWhenOnSyntax < T > ; toConstructor < T2 > ( constructor ) : BindingWhenOnSyntax < T > ; toFactory < T2 , T3 extends unknown [ ] = unknown [ ] , T4 extends unknown [ ] = unknown [ ] > ( factory ) : BindingWhenOnSyntax < T > ; toFunction ( func ) : BindingWhenOnSyntax < T > ; toAutoFactory < T2 > ( serviceIdentifier ) : BindingWhenOnSyntax < T > ; toAutoNamedFactory < T2 > ( serviceIdentifier ) : BindingWhenOnSyntax < T > ; toProvider < T2 > ( provider ) : BindingWhenOnSyntax < T > ; toService ( service ) : void ; } export interface ConstraintFunction { metaData ? : Metadata ; ( request ) : boolean ; } export interface MetadataReader { getConstructorMetadata ( constructorFunc ) : ConstructorMetadata ; getPropertiesMetadata ( constructorFunc ) : MetadataMap ; } export interface MetadataMap { [ propertyNameOrArgumentIndex ] : Metadata [ ] ; } export interface ConstructorMetadata { compilerGeneratedMetadata : NewableFunction [ ] | undefined ; userGeneratedMetadata : MetadataMap ; } } export { interfaces } ;