@aurelia/kernel
Advanced tools
Comparing version 2.0.1-dev.202404171154 to 2.0.1-dev.202404281254
@@ -14,5 +14,5 @@ import { Constructable, IDisposable } from './interfaces'; | ||
resolve(handler: C, requestor: C): Resolved<K>; | ||
getFactory?(container: C): (K extends Constructable ? IFactory<K> : never) | null; | ||
getFactory?<T extends K extends Constructable ? IFactory<K> : IFactory<Constructable>>(container: C): T | null; | ||
} | ||
export interface IResolver<K = any> extends IResolverLike<IContainer, K> { | ||
export interface IResolver<K = any> extends IResolverLike<IContainer, K>, Partial<IDisposable> { | ||
} | ||
@@ -22,3 +22,3 @@ export interface IDisposableResolver<K = any> extends IResolver<K> { | ||
} | ||
export interface IRegistration<K = any> { | ||
export interface IRegistration<K = any> extends IResolver<K> { | ||
register(container: IContainer, key?: Key): IResolver<K>; | ||
@@ -57,3 +57,3 @@ } | ||
register(...params: any[]): IContainer; | ||
registerResolver<K extends Key, T = K>(key: K, resolver: IResolver<T>, isDisposable?: boolean): IResolver<T>; | ||
registerResolver<K extends Key, T extends IResolver<K>>(key: K, resolver: T, isDisposable?: boolean): T; | ||
registerTransformer<K extends Key, T = K>(key: K, transformer: Transformer<T>): boolean; | ||
@@ -248,3 +248,3 @@ getResolver<K extends Key, T = K>(key: K | Key, autoRegister?: boolean): IResolver<T> | null; | ||
export declare function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext): T & RegisterSelf<T>; | ||
export declare class InstanceProvider<K extends Key> implements IDisposableResolver<K | null> { | ||
export declare class InstanceProvider<K extends Key> implements IDisposableResolver<K> { | ||
get friendlyName(): string | undefined; | ||
@@ -259,4 +259,4 @@ constructor(name?: string, | ||
get $isResolver(): true; | ||
resolve(): Resolved<K> | null; | ||
getFactory(container: IContainer): (K extends Constructable ? IFactory<K> : never) | null; | ||
resolve(): Resolved<K>; | ||
getFactory<T extends K extends Constructable ? IFactory<K> : IFactory<Constructable>>(container: IContainer): T | null; | ||
dispose(): void; | ||
@@ -263,0 +263,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { type Key, IRegistration, type ResolveCallback, type Resolved, type IRegistry } from './di'; | ||
import { type Key, IRegistration, type ResolveCallback, type Resolved, type IRegistry, type IContainer, InterfaceSymbol } from './di'; | ||
import { Constructable } from './interfaces'; | ||
@@ -95,2 +95,3 @@ /** | ||
}; | ||
export declare const createImplementationRegister: <T extends Key>(key: InterfaceSymbol<T>) => <C extends Constructable>(this: C, container: IContainer) => void; | ||
//# sourceMappingURL=di.registration.d.ts.map |
export { IPlatform, } from './platform'; | ||
export { DI, IContainer, type IFactory, inject, type IRegistration, type IRegistry, type IResolver, IServiceLocator, type Key, type RegisterSelf, type ResolveCallback, singleton, transient, type AbstractInjectable, type Injectable, type InterfaceSymbol, InstanceProvider, type Resolved, type Transformer, type IContainerConfiguration, } from './di'; | ||
export { resolve, type IResolvedInjection, Registrable, ContainerConfiguration, DefaultResolver, } from './di.container'; | ||
export { Registration, } from './di.registration'; | ||
export { Registration, createImplementationRegister, } from './di.registration'; | ||
export { createResolver, all, factory, type IAllResolver, type IFactoryResolver, type IOptionalResolver, type IResolvedFactory, type INewInstanceResolver, lazy, type ILazyResolver, type IResolvedLazy, optional, ignore, newInstanceForScope, newInstanceOf, type ICallableResolver, allResources, optionalResource, own, resource, } from './di.resolvers'; | ||
@@ -6,0 +6,0 @@ export { type Class, type Constructable, type ConstructableClass, type IDisposable, type IIndexable, type Overwrite, type Primitive, type Writable, } from './interfaces'; |
{ | ||
"name": "@aurelia/kernel", | ||
"version": "2.0.1-dev.202404171154", | ||
"version": "2.0.1-dev.202404281254", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -56,4 +56,4 @@ "module": "dist/esm/index.mjs", | ||
"dependencies": { | ||
"@aurelia/metadata": "2.0.1-dev.202404171154", | ||
"@aurelia/platform": "2.0.1-dev.202404171154" | ||
"@aurelia/metadata": "2.0.1-dev.202404281254", | ||
"@aurelia/platform": "2.0.1-dev.202404281254" | ||
}, | ||
@@ -60,0 +60,0 @@ "devDependencies": { |
@@ -11,3 +11,2 @@ /* eslint-disable @typescript-eslint/no-this-alias */ | ||
type IContainerConfiguration, | ||
type IDisposableResolver, | ||
type IFactory, | ||
@@ -33,3 +32,3 @@ type IRegistry, | ||
import { isNativeFunction } from './functions'; | ||
import { type Class, type Constructable, type IDisposable } from './interfaces'; | ||
import { type Class, type Constructable } from './interfaces'; | ||
import { emptyArray } from './platform'; | ||
@@ -116,3 +115,3 @@ import { ResourceDefinition, StaticResourceType, resourceBaseName, type ResourceType } from './resource'; | ||
*/ | ||
private readonly _resolvers: Map<Key, IResolver | IDisposableResolver>; | ||
private readonly _resolvers: Map<Key, IResolver>; | ||
/** | ||
@@ -130,6 +129,6 @@ * A map of Factory per Constructor (Type) of this container tree. | ||
*/ | ||
private res: Record<string, IResolver | IDisposableResolver | undefined>; | ||
private res: Record<string, IResolver | undefined>; | ||
/** @internal */ | ||
private readonly _disposableResolvers: Map<Key, IDisposableResolver> = new Map<Key, IDisposableResolver>(); | ||
private readonly _disposableResolvers = new Map<Key, IResolver>(); | ||
@@ -249,3 +248,3 @@ public get parent(): IContainer | null { | ||
public registerResolver<K extends Key, T = K>(key: K, resolver: IResolver<T>, isDisposable: boolean = false): IResolver<T> { | ||
public registerResolver<K extends Key, T extends IResolver<K>>(key: K, resolver: T, isDisposable: boolean = false): T { | ||
validateKey(key); | ||
@@ -267,7 +266,7 @@ | ||
} else { | ||
resolvers.set(key, new Resolver(key, ResolverStrategy.array, [result, resolver])); | ||
resolvers.set(key, new Resolver(key, ResolverStrategy.array, [result, resolver]) as IResolver<K>); | ||
} | ||
if (isDisposable) { | ||
this._disposableResolvers.set(key, resolver as IDisposableResolver<T>); | ||
this._disposableResolvers.set(key, resolver); | ||
} | ||
@@ -523,7 +522,7 @@ | ||
let disposable: IDisposable; | ||
let disposable: IResolver; | ||
let key: Key; | ||
for ([key, disposable] of disposableResolvers.entries()) { | ||
disposable.dispose(); | ||
disposable.dispose?.(); | ||
resolvers.delete(key); | ||
@@ -530,0 +529,0 @@ } |
@@ -12,2 +12,3 @@ import { | ||
ParameterizedRegistry, | ||
InterfaceSymbol, | ||
} from './di'; | ||
@@ -155,1 +156,10 @@ import { Constructable } from './interfaces'; | ||
}; | ||
export const createImplementationRegister = function<T extends Key>(key: InterfaceSymbol<T>) { | ||
return function register<C extends Constructable>(this: C, container: IContainer) { | ||
container.register( | ||
singletonRegistration(this, this), | ||
aliasToRegistration(this, key), | ||
); | ||
}; | ||
}; |
@@ -34,6 +34,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
resolve(handler: C, requestor: C): Resolved<K>; | ||
getFactory?(container: C): (K extends Constructable ? IFactory<K> : never) | null; | ||
getFactory?<T extends K extends Constructable ? IFactory<K> : IFactory<Constructable>>(container: C): T | null; | ||
} | ||
export interface IResolver<K = any> extends IResolverLike<IContainer, K> { } | ||
export interface IResolver<K = any> extends IResolverLike<IContainer, K>, Partial<IDisposable> { } | ||
export interface IDisposableResolver<K = any> extends IResolver<K> { | ||
@@ -43,3 +43,3 @@ dispose(): void; | ||
export interface IRegistration<K = any> { | ||
export interface IRegistration<K = any> extends IResolver<K> { | ||
register(container: IContainer, key?: Key): IResolver<K>; | ||
@@ -83,3 +83,3 @@ } | ||
register(...params: any[]): IContainer; | ||
registerResolver<K extends Key, T = K>(key: K, resolver: IResolver<T>, isDisposable?: boolean): IResolver<T>; | ||
registerResolver<K extends Key, T extends IResolver<K>>(key: K, resolver: T, isDisposable?: boolean): T; | ||
// deregisterResolverFor<K extends Key>(key: K, searchAncestors: boolean): void; | ||
@@ -139,3 +139,3 @@ registerTransformer<K extends Key, T = K>(key: K, transformer: Transformer<T>): boolean; | ||
this._container = this._key = (void 0)!; | ||
return container.registerResolver(key, new Resolver(key, strategy, state)); | ||
return container.registerResolver(key, new Resolver(key, strategy, state)) as IResolver<K>; | ||
} | ||
@@ -527,3 +527,3 @@ } | ||
/** @internal */ | ||
export class Resolver implements IResolver, IRegistration { | ||
export class Resolver<K extends Key = any> implements IResolver<K> { | ||
/** @internal */ | ||
@@ -542,3 +542,3 @@ public _key: Key; | ||
public constructor( | ||
key: Key, | ||
key: K, | ||
strategy: ResolverStrategy, | ||
@@ -560,3 +560,3 @@ state: any, | ||
public register(container: IContainer, key?: Key): IResolver { | ||
return container.registerResolver(key || this._key, this); | ||
return container.registerResolver(key || this._key, this as IResolver<K>); | ||
} | ||
@@ -587,3 +587,3 @@ | ||
case ResolverStrategy.callback: | ||
return (this._state as ResolveCallback)(handler, requestor, this); | ||
return (this._state as ResolveCallback)(handler, requestor, this as IResolver<K>); | ||
case ResolverStrategy.array: | ||
@@ -598,11 +598,11 @@ return (this._state as IResolver[])[0].resolve(handler, requestor); | ||
public getFactory(container: IContainer): IFactory | null { | ||
public getFactory<T extends K extends Constructable ? IFactory<K> : IFactory<Constructable>>(container: IContainer): T | null { | ||
switch (this._strategy) { | ||
case ResolverStrategy.singleton: | ||
case ResolverStrategy.transient: | ||
return container.getFactory(this._state as Constructable); | ||
return container.getFactory(this._state as Constructable) as T; | ||
case ResolverStrategy.alias: | ||
return container.getResolver(this._state)?.getFactory?.(container) ?? null; | ||
case ResolverStrategy.instance: | ||
return this._cachedFactory; | ||
return this._cachedFactory as T; | ||
default: | ||
@@ -625,3 +625,3 @@ return null; | ||
export class InstanceProvider<K extends Key> implements IDisposableResolver<K | null> { | ||
export class InstanceProvider<K extends Key> implements IDisposableResolver<K> { | ||
/** @internal */ private _instance: Resolved<K> | null; | ||
@@ -655,3 +655,3 @@ /** @internal */ private readonly _name?: string; | ||
public resolve(): Resolved<K> | null { | ||
public resolve(): Resolved<K> { | ||
if (this._instance == null) { | ||
@@ -663,4 +663,4 @@ throw createMappedError(ErrorNames.no_instance_provided, this._name); | ||
public getFactory(container: IContainer): (K extends Constructable ? IFactory<K> : never) | null { | ||
return this._Type == null ? null : container.getFactory(this._Type) as (K extends Constructable ? IFactory<K> : never) | null; | ||
public getFactory<T extends K extends Constructable ? IFactory<K> : IFactory<Constructable>>(container: IContainer): T | null { | ||
return this._Type == null ? null : container.getFactory(this._Type) as T; | ||
} | ||
@@ -667,0 +667,0 @@ |
@@ -38,2 +38,3 @@ export { | ||
Registration, | ||
createImplementationRegister, | ||
} from './di.registration'; | ||
@@ -40,0 +41,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1076444
18598
+ Added@aurelia/metadata@2.0.1-dev.202404281254(transitive)
+ Added@aurelia/platform@2.0.1-dev.202404281254(transitive)
- Removed@aurelia/metadata@2.0.1-dev.202404171154(transitive)
- Removed@aurelia/platform@2.0.1-dev.202404171154(transitive)