import { ServiceCollection } from './serviceCollection' ; import * as descriptors from './descriptors' ; internal export namespace _util { export const serviceIds = new Map < string , ServiceIdentifier < any > > ( ) ; export const DI_TARGET = '$di$target' ; export const DI_DEPENDENCIES = '$di$dependencies' ; export function getServiceDependencies ( ctor ) { return ctor [ DI_DEPENDENCIES ] || [ ] ; } } export type BrandedService = { _serviceBrand : undefined ; } ; export interface IConstructorSignature0 < T > { new ( ... services ) : T ; } export interface IConstructorSignature1 < A1 , T > { new ( first , ... services ) : T ; } export interface IConstructorSignature2 < A1 , A2 , T > { new ( first , second , ... services ) : T ; } export interface IConstructorSignature3 < A1 , A2 , A3 , T > { new ( first , second , third , ... services ) : T ; } export interface IConstructorSignature4 < A1 , A2 , A3 , A4 , T > { new ( first , second , third , fourth , ... services ) : T ; } export interface IConstructorSignature5 < A1 , A2 , A3 , A4 , A5 , T > { new ( first , second , third , fourth , fifth , ... services ) : T ; } export interface IConstructorSignature6 < A1 , A2 , A3 , A4 , A5 , A6 , T > { new ( first , second , third , fourth , fifth , sixth , ... services ) : T ; } export interface IConstructorSignature7 < A1 , A2 , A3 , A4 , A5 , A6 , A7 , T > { new ( first , second , third , fourth , fifth , sixth , seventh , ... services ) : T ; } export interface IConstructorSignature8 < A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 , T > { new ( first , second , third , fourth , fifth , sixth , seventh , eigth , ... services ) : T ; } export interface ServicesAccessor { get < T > ( id ) : T ; get < T > ( id , isOptional ) : T | undefined ; } export const IInstantiationService = createDecorator < IInstantiationService > ( 'instantiationService' ) ; /**
 * Given a list of arguments as a tuple, attempt to extract the leading, non-service arguments
 * to their own tuple.
 */ type GetLeadingNonServiceArgs < Args > = Args extends [ ... BrandedService [ ] ] ? [ ] : Args extends [ infer A1 , ... BrandedService [ ] ] ? [ A1 ] : Args extends [ infer A1 , infer A2 , ... BrandedService [ ] ] ? [ A1 , A2 ] : Args extends [ infer A1 , infer A2 , infer A3 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 ] : Args extends [ infer A1 , infer A2 , infer A3 , infer A4 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 , A4 ] : Args extends [ infer A1 , infer A2 , infer A3 , infer A4 , infer A5 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 , A4 , A5 ] : Args extends [ infer A1 , infer A2 , infer A3 , infer A4 , infer A5 , infer A6 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 , A4 , A5 , A6 ] : Args extends [ infer A1 , infer A2 , infer A3 , infer A4 , infer A5 , infer A6 , infer A7 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 , A4 , A5 , A6 , A7 ] : Args extends [ infer A1 , infer A2 , infer A3 , infer A4 , infer A5 , infer A6 , infer A7 , infer A8 , ... BrandedService [ ] ] ? [ A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 ] : never ; export interface IInstantiationService { _serviceBrand : undefined ; /**
     * Synchronously creates an instance that is denoted by
     * the descriptor
     */ createInstance < T > ( descriptor ) : T ; createInstance < A1 , T > ( descriptor , a1 ) : T ; createInstance < A1 , A2 , T > ( descriptor , a1 , a2 ) : T ; createInstance < A1 , A2 , A3 , T > ( descriptor , a1 , a2 , a3 ) : T ; createInstance < A1 , A2 , A3 , A4 , T > ( descriptor , a1 , a2 , a3 , a4 ) : T ; createInstance < A1 , A2 , A3 , A4 , A5 , T > ( descriptor , a1 , a2 , a3 , a4 , a5 ) : T ; createInstance < A1 , A2 , A3 , A4 , A5 , A6 , T > ( descriptor , a1 , a2 , a3 , a4 , a5 , a6 ) : T ; createInstance < A1 , A2 , A3 , A4 , A5 , A6 , A7 , T > ( descriptor , a1 , a2 , a3 , a4 , a5 , a6 , a7 ) : T ; createInstance < A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 , T > ( descriptor , a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 ) : T ; createInstance < Ctor extends new ( ... args ) => any , R extends InstanceType < Ctor > > ( t , ... args ) : R ; createInstance < Services extends BrandedService [ ] , Ctor extends new ( ... services ) => any , R extends InstanceType < Ctor > > ( t ) : R ; /**
     *
     */ invokeFunction < R , TS extends any [ ] = [ ] > ( fn , ... args ) : R ; /**
     * Creates a child of this service which inherts all current services
     * and adds/overwrites the given services
     */ createChild ( services ) : IInstantiationService ; } /**
 * Identifies a service of type T
 */ export interface ServiceIdentifier < T > { ( ... args ) : void ; type : T ; } function storeServiceDependency ( id , target , index , optional ) { if ( ( target as any ) [ _util . DI_TARGET ] === target ) { ( target as any ) [ _util . DI_DEPENDENCIES ] . push ( { id , index , optional } ) ; } else { ( target as any ) [ _util . DI_DEPENDENCIES ] = [ { id , index , optional } ] ; ( target as any ) [ _util . DI_TARGET ] = target ; } } /**
 * A *only* valid way to create a {{ServiceIdentifier}}.
 */ export function createDecorator < T > ( serviceId ) { if ( _util . serviceIds . has ( serviceId ) ) { return _util . serviceIds . get ( serviceId ) ! ; } const id = < any > function ( target , key , index ) : any { if ( arguments . length !== 3 ) { throw new Error ( '@IServiceName-decorator can only be used to decorate a parameter' ) ; } storeServiceDependency ( id , target , index , false ) ; } ; id . toString = ( ) => serviceId ; _util . serviceIds . set ( serviceId , id ) ; return id ; } /**
 * Mark a service dependency as optional.
 */ export function optional < T > ( serviceIdentifier ) { return function ( target , key , index ) { if ( arguments . length !== 3 ) { throw new Error ( '@optional-decorator can only be used to decorate a parameter' ) ; } storeServiceDependency ( serviceIdentifier , target , index , true ) ; } ; }