export type ValueType = 'value'; export type FactoryType = 'factory'; export type TypeType = 'type'; export type ProviderType = ValueType | FactoryType | TypeType; export type InjectAnnotated = { $inject?: string[]; }; export type ScopeAnnotated = { $scope?: string[]; }; export type Annotated = InjectAnnotated & ScopeAnnotated; export type Constructor = ( { new (...args: any[]): T } | { (...args: any[]): T } ); export type InitializerFunction = { (...args: any[]): unknown } & Annotated; export type FactoryFunction = { (...args: any[]): T; } & Annotated; export type ArrayArgs = [ ...string[], T ]; export type ArrayFunc = [ ...string[], FactoryFunction ]; export type ArrayConstructor = [ ...string[], Constructor ]; export type ServiceProvider = { (name: string): T; }; export type Initializer = InitializerFunction | ArrayArgs; export type FactoryDefinition = FactoryFunction | ArrayArgs>; export type TypeDefinition = Constructor | ArrayArgs>; export type ValueDefinition = T; export type ServiceDefinition = FactoryDefinition | TypeDefinition | ValueDefinition; export type TypedDeclaration = [ T, D ] | [ T, D, 'private' ]; export type ServiceDeclaration = TypedDeclaration> | TypedDeclaration> | TypedDeclaration>; export type ModuleDeclaration = { [name: string]: ServiceDeclaration | unknown; __init__?: Array; __depends__?: Array; __exports__?: Array; __modules__?: Array; }; // injector.js export type InjectionContext = unknown; export type LocalsMap = { [name: string]: unknown }; export type ModuleDefinition = ModuleDeclaration; export class Injector< ServiceMap = null > { /** * Create an injector from a set of modules. */ constructor(modules: ModuleDefinition[], parent?: InjectorContext); /** * Return a named service, looked up from the existing service map. */ get(name: Name): ServiceMap[Name]; /** * Return a named service, and throws if it is not found. */ get(name: string): T; /** * Return a named service. */ get(name: string, strict: true): T; /** * Return a named service or `null`. */ get(name: string, strict: boolean): T | null; /** * Invoke the given function, injecting dependencies. Return the result. * * @example * * ```javascript * injector.invoke(function(car) { * console.log(car.started); * }); * ``` */ invoke(func: FactoryFunction, context?: InjectionContext, locals?: LocalsMap): T; /** * Invoke the given function, injecting dependencies provided in * array notation. Return the result. * * @example * * ```javascript * injector.invoke([ 'car', function(car) { * console.log(car.started); * } ]); * ``` */ invoke(func: ArrayFunc, context?: InjectionContext, locals?: LocalsMap): T; /** * Instantiate the given type, injecting dependencies. * * @example * * ```javascript * injector.instantiate(Car); * ``` */ instantiate(constructor: Constructor): T; /** * Instantiate the given type, injecting dependencies provided in array notation. * * @example * * ```javascript * injector.instantiate([ 'hifi', Car ]); * ``` */ instantiate(constructor: ArrayConstructor): T; /** * Create a child injector. */ createChild(modules: ModuleDefinition[], forceNewInstances?: string[]): Injector; /** * Initializes the injector once, calling `__init__` * hooks on registered injector modules. */ init(): void; /** * @internal */ _providers: object; } export type InjectorContext = { get(name: string, strict?: boolean): T; /** * @internal */ _providers?: object }; // annotation.js export function annotate(...args: unknown[]): T & InjectAnnotated; export function parseAnnotations(fn: unknown) : string[];