@aurelia/kernel
Advanced tools
Comparing version 2.0.1-dev.202304181031 to 2.0.1-dev.202306161507
@@ -6,2 +6,47 @@ # Change Log | ||
<a name="2.0.0-beta.7"></a> | ||
# 2.0.0-beta.7 (2023-06-16) | ||
### Features: | ||
* **build:** add a development entry point (#1770) ([69ff445](https://github.com/aurelia/aurelia/commit/69ff445)) | ||
### Bug Fixes: | ||
* **resolver:** mark private as internal ([07689bf](https://github.com/aurelia/aurelia/commit/07689bf)) | ||
### Refactorings: | ||
* **runtime:** cleanup, extract error to const enums (#1775) ([07689bf](https://github.com/aurelia/aurelia/commit/07689bf)) | ||
* **runtime-html:** cleanup errors, remove unused code. (#1771) ([750210d](https://github.com/aurelia/aurelia/commit/750210d)) | ||
<a name="2.0.0-beta.6"></a> | ||
# 2.0.0-beta.6 (2023-05-21) | ||
### Features: | ||
* **di:** ability to use newInstance()/forScope() with interface (#1767) ([a0d39e9](https://github.com/aurelia/aurelia/commit/a0d39e9)) | ||
* **bindable:** support getter/setter (#1753) ([4279851](https://github.com/aurelia/aurelia/commit/4279851)) | ||
### Refactorings: | ||
* ***:** rename resolveAll -> onResolveAll (#1764) ([fdf0747](https://github.com/aurelia/aurelia/commit/fdf0747)) | ||
* ***:** cleanup up unused code & decouple interface from default impl (#1761) ([7a71d43](https://github.com/aurelia/aurelia/commit/7a71d43)) | ||
<a name="2.0.0-beta.5"></a> | ||
# 2.0.0-beta.5 (2023-04-27) | ||
### Features: | ||
* **di:** property injection with `resolve` (#1748) ([a22826a](https://github.com/aurelia/aurelia/commit/a22826a)) | ||
* **aurelia:** ability to inject with `Aurelia` export beside `IAurelia` ([a22826a](https://github.com/aurelia/aurelia/commit/a22826a)) | ||
### Refactorings: | ||
* **build:** preserve pure annotation for better tree shaking (#1745) ([0bc5cd6](https://github.com/aurelia/aurelia/commit/0bc5cd6)) | ||
<a name="2.0.0-beta.4"></a> | ||
@@ -8,0 +53,0 @@ # 2.0.0-beta.4 (2023-04-13) |
@@ -1,2 +0,10 @@ | ||
export {}; | ||
import { type Key, type IResolver, type Resolved, type IFactoryResolver, type ILazyResolver, type INewInstanceResolver, type IResolvedFactory, type IResolvedLazy, type IAllResolver, type IOptionalResolver } from './di'; | ||
export type IResolvedInjection<K extends Key> = K extends IAllResolver<infer R> ? readonly Resolved<R>[] : K extends INewInstanceResolver<infer R> ? Resolved<R> : K extends ILazyResolver<infer R> ? IResolvedLazy<R> : K extends IOptionalResolver<infer R> ? Resolved<R> | undefined : K extends IFactoryResolver<infer R> ? IResolvedFactory<R> : K extends IResolver<infer R> ? Resolved<R> : K extends [infer R1 extends Key, ...infer R2] ? [IResolvedInjection<R1>, ...IResolvedInjection<R2>] : Resolved<K>; | ||
/** | ||
* Retrieve the resolved value of a key, or values of a list of keys from the currently active container. | ||
* | ||
* Calling this without an active container will result in an error. | ||
*/ | ||
export declare function resolve<K extends Key>(key: K): IResolvedInjection<K>; | ||
export declare function resolve<K extends Key[]>(...keys: K): IResolvedInjection<K>; | ||
//# sourceMappingURL=di.container.d.ts.map |
@@ -27,4 +27,6 @@ import { Constructable, IDisposable } from './interfaces'; | ||
has<K extends Key>(key: K | Key, searchAncestors: boolean): boolean; | ||
get<K extends Key>(key: IAllResolver<K>): readonly Resolved<K>[]; | ||
get<K extends Key>(key: INewInstanceResolver<K>): Resolved<K>; | ||
get<K extends Key>(key: ILazyResolver<K>): IResolvedLazy<K>; | ||
get<K extends Key>(key: IOptionalResolver<K>): Resolved<K> | undefined; | ||
get<K extends Key>(key: IFactoryResolver<K>): IResolvedFactory<K>; | ||
@@ -51,2 +53,3 @@ get<K extends Key>(key: IResolver<K>): Resolved<K>; | ||
invoke<T extends {}, TDeps extends unknown[] = unknown[]>(key: Constructable<T>, dynamicDependencies?: TDeps): T; | ||
hasFactory<T extends Constructable>(key: any): boolean; | ||
getFactory<T extends Constructable>(key: T): IFactory<T>; | ||
@@ -244,4 +247,11 @@ createChild(config?: IContainerConfiguration): IContainer; | ||
export declare function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>; | ||
export declare const all: (key: any, searchAncestors?: boolean) => ReturnType<typeof DI.inject>; | ||
/** | ||
* Create a resolver that will resolve all values of a key from resolving container | ||
*/ | ||
export declare const all: <T extends Key>(key: T, searchAncestors?: boolean) => IAllResolver<T>; | ||
export type IAllResolver<T> = IResolver<readonly Resolved<T>[]> & { | ||
__isAll: undefined; | ||
(...args: unknown[]): any; | ||
}; | ||
/** | ||
* Lazily inject a dependency depending on whether the [[`Key`]] is present at the time of function call. | ||
@@ -273,4 +283,4 @@ * | ||
*/ | ||
export declare const lazy: (key: any) => any; | ||
export type ILazyResolver<K = any> = IResolver<K> & { | ||
export declare const lazy: <K extends Key>(key: K) => ILazyResolver<K>; | ||
export type ILazyResolver<K extends Key = Key> = IResolver<() => K> & { | ||
__isLazy: undefined; | ||
@@ -301,3 +311,7 @@ } & ((...args: unknown[]) => any); | ||
*/ | ||
export declare const optional: (key: any) => any; | ||
export declare const optional: <K extends Key>(key: K) => IOptionalResolver<K>; | ||
export type IOptionalResolver<K extends Key = Key> = IResolver<K | undefined> & { | ||
__isOptional: undefined; | ||
(...args: unknown[]): any; | ||
}; | ||
/** | ||
@@ -345,21 +359,16 @@ * ignore tells the container not to try to inject a dependency | ||
export type IResolvedFactory<K> = (...args: unknown[]) => Resolved<K>; | ||
/** | ||
* Create a resolver that will resolve a new instance of a key, and register the newly created instance with the requestor container | ||
*/ | ||
export declare const newInstanceForScope: <K>(key: K) => INewInstanceResolver<K>; | ||
/** | ||
* Create a resolver that will resolve a new instance of a key | ||
*/ | ||
export declare const newInstanceOf: <K>(key: K) => INewInstanceResolver<K>; | ||
export type INewInstanceResolver<T> = { | ||
export type INewInstanceResolver<T> = IResolver<T> & { | ||
__newInstance: undefined; | ||
(...args: unknown[]): any; | ||
}; | ||
export declare const enum ResolverStrategy { | ||
instance = 0, | ||
singleton = 1, | ||
transient = 2, | ||
callback = 3, | ||
array = 4, | ||
alias = 5 | ||
} | ||
export declare class Resolver implements IResolver, IRegistration { | ||
_key: Key; | ||
_strategy: ResolverStrategy; | ||
_state: any; | ||
constructor(_key: Key, _strategy: ResolverStrategy, _state: any); | ||
constructor(key: Key, strategy: ResolverStrategy, state: any); | ||
get $isResolver(): true; | ||
@@ -371,3 +380,2 @@ private resolving; | ||
} | ||
export declare function containerGetKey(this: IContainer, d: Key): any; | ||
/** | ||
@@ -374,0 +382,0 @@ * An implementation of IRegistry that delegates registration to a |
@@ -55,2 +55,15 @@ import { Constructable, Overwrite } from './interfaces'; | ||
export declare const firstDefined: <T>(...values: readonly (T | undefined)[]) => T; | ||
/** | ||
* Get the prototypes of a class hierarchy. Es6 classes have their parent class as prototype | ||
* so this will return a list of constructors | ||
* | ||
* @example | ||
* ```ts | ||
* class A {} | ||
* class B extends A {} | ||
* | ||
* assert.deepStrictEqual(getPrototypeChain(A), [A]) | ||
* assert.deepStrictEqual(getPrototypeChain(B), [B, A]) | ||
* ``` | ||
*/ | ||
export declare const getPrototypeChain: <T extends Constructable>(Type: T) => readonly [T, ...Constructable[]]; | ||
@@ -86,4 +99,4 @@ export declare function toLookup<T1 extends {}>(obj1: T1): T1; | ||
*/ | ||
export declare const resolveAll: (...maybePromises: (void | Promise<void>)[]) => void | Promise<void>; | ||
export declare const onResolveAll: (...maybePromises: (void | Promise<void>)[]) => void | Promise<void>; | ||
export {}; | ||
//# sourceMappingURL=functions.d.ts.map |
export { IPlatform, } from './platform'; | ||
export { all, factory, type IFactoryResolver, type IResolvedFactory, DI, IContainer, type IFactory, inject, type IRegistration, type IRegistry, type IResolver, IServiceLocator, type Key, lazy, type ILazyResolver, type IResolvedLazy, optional, ignore, type RegisterSelf, Registration, type ResolveCallback, singleton, transient, type AbstractInjectable, type Injectable, type InterfaceSymbol, InstanceProvider, type Resolved, type Transformer, newInstanceForScope, newInstanceOf, ContainerConfiguration, DefaultResolver, type IContainerConfiguration, } from './di'; | ||
export { all, factory, type IAllResolver, type IFactoryResolver, type IOptionalResolver, type IResolvedFactory, type INewInstanceResolver, DI, IContainer, type IFactory, inject, type IRegistration, type IRegistry, type IResolver, IServiceLocator, type Key, lazy, type ILazyResolver, type IResolvedLazy, optional, ignore, type RegisterSelf, Registration, type ResolveCallback, singleton, transient, type AbstractInjectable, type Injectable, type InterfaceSymbol, InstanceProvider, type Resolved, type Transformer, newInstanceForScope, newInstanceOf, ContainerConfiguration, DefaultResolver, type IContainerConfiguration, } from './di'; | ||
export { resolve, type IResolvedInjection, } from './di.container'; | ||
export { type Class, type Constructable, type ConstructableClass, type IDisposable, type IIndexable, type Overwrite, type Primitive, type Writable, } from './interfaces'; | ||
@@ -9,4 +10,4 @@ export { LogLevel, type IConsoleLike, ColorOptions, ILogConfig, type ILogEvent, ILogEventFactory, ISink, ILogger, LogConfig, DefaultLogEvent, DefaultLogEventFactory, DefaultLogger, ConsoleSink, LoggerConfiguration, format, sink, } from './logger'; | ||
export { EventAggregator, IEventAggregator, } from './eventaggregator'; | ||
export { isArrayIndex, camelCase, kebabCase, pascalCase, toArray, bound, mergeArrays, firstDefined, getPrototypeChain, isNativeFunction, onResolve, resolveAll, } from './functions'; | ||
export { isArrayIndex, camelCase, kebabCase, pascalCase, toArray, bound, mergeArrays, firstDefined, getPrototypeChain, isNativeFunction, onResolve, onResolveAll, } from './functions'; | ||
export { type AnyFunction, type FunctionPropNames, type MaybePromise, } from './utilities'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -203,3 +203,2 @@ import { IContainer, IRegistry } from './di'; | ||
readonly config: ILogConfig; | ||
constructor(config: ILogConfig); | ||
createLogEvent(logger: ILogger, level: LogLevel, message: string, optionalParams: unknown[]): ILogEvent; | ||
@@ -210,3 +209,3 @@ } | ||
readonly handleEvent: (event: ILogEvent) => void; | ||
constructor(p: IPlatform); | ||
constructor(p?: IPlatform); | ||
} | ||
@@ -236,3 +235,3 @@ export declare class DefaultLogger { | ||
*/ | ||
config: ILogConfig, factory: ILogEventFactory, sinks: ISink[], | ||
config?: ILogConfig, factory?: ILogEventFactory, sinks?: readonly ISink[], | ||
/** | ||
@@ -239,0 +238,0 @@ * The scopes that this logger was created for, if any. |
{ | ||
"name": "@aurelia/kernel", | ||
"version": "2.0.1-dev.202304181031", | ||
"version": "2.0.1-dev.202306161507", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -9,3 +9,4 @@ "module": "dist/esm/index.mjs", | ||
"require": "./dist/cjs/index.cjs", | ||
"import": "./dist/esm/index.mjs" | ||
"import": "./dist/esm/index.mjs", | ||
"development": "./dist/esm/index.dev.mjs" | ||
}, | ||
@@ -52,4 +53,4 @@ "types": "dist/types/index.d.ts", | ||
"dependencies": { | ||
"@aurelia/metadata": "2.0.1-dev.202304181031", | ||
"@aurelia/platform": "2.0.1-dev.202304181031" | ||
"@aurelia/metadata": "2.0.1-dev.202306161507", | ||
"@aurelia/platform": "2.0.1-dev.202306161507" | ||
}, | ||
@@ -56,0 +57,0 @@ "devDependencies": { |
@@ -0,9 +1,34 @@ | ||
/* eslint-disable @typescript-eslint/no-this-alias */ | ||
/* eslint-disable @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any */ | ||
import { isObject } from '@aurelia/metadata'; | ||
import { isNativeFunction } from './functions'; | ||
import { Class, Constructable, IDisposable } from './interfaces'; | ||
import { type Class, type Constructable, type IDisposable } from './interfaces'; | ||
import { emptyArray } from './platform'; | ||
import { IResourceKind, ResourceDefinition, ResourceType, getAllResources, hasResources } from './resource'; | ||
import { createError, createObject, getOwnMetadata, isFunction, isString, safeString } from './utilities'; | ||
import { IContainer, type Key, type IResolver, type IDisposableResolver, Factory, ContainerConfiguration, type IRegistry, Registration, Resolver, ResolverStrategy, Transformer, type RegisterSelf, type Resolved, getDependencies, containerGetKey, IFactory, IContainerConfiguration } from './di'; | ||
import { type IResourceKind, type ResourceDefinition, type ResourceType, getAllResources, hasResources } from './resource'; | ||
import { createObject, getOwnMetadata, isFunction, isString } from './utilities'; | ||
import { | ||
IContainer, | ||
type Key, | ||
type IResolver, | ||
type IDisposableResolver, | ||
ContainerConfiguration, | ||
type IRegistry, | ||
Registration, | ||
Resolver, | ||
ResolverStrategy, | ||
type Transformer, | ||
type RegisterSelf, | ||
type Resolved, | ||
getDependencies, | ||
type IFactory, | ||
type IContainerConfiguration, | ||
type IFactoryResolver, | ||
type ILazyResolver, | ||
type INewInstanceResolver, | ||
type IResolvedFactory, | ||
type IResolvedLazy, | ||
type IAllResolver, | ||
type IOptionalResolver, | ||
} from './di'; | ||
import { ErrorNames, createMappedError } from './errors'; | ||
@@ -14,2 +39,5 @@ const InstrinsicTypeNames = new Set<string>('Array ArrayBuffer Boolean DataView Date Error EvalError Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Number Object Promise RangeError ReferenceError RegExp Set SharedArrayBuffer String SyntaxError TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array URIError WeakMap WeakSet'.split(' ')); | ||
let containerId = 0; | ||
let currentContainer: IContainer | null = null; | ||
/** @internal */ | ||
@@ -82,3 +110,3 @@ export class Container implements IContainer { | ||
if (++this._registerDepth === 100) { | ||
throw registrationError(params); | ||
throw createMappedError(ErrorNames.unable_auto_register, ...params); | ||
} | ||
@@ -148,3 +176,3 @@ let current: IRegistry | Record<string, IRegistry>; | ||
if (this.res[key] !== void 0) { | ||
throw resourceExistError(key); | ||
throw createMappedError(ErrorNames.resource_already_exists, key); | ||
} | ||
@@ -224,20 +252,27 @@ this.res[key] = resolver; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
let current: Container = this; | ||
const previousContainer = currentContainer; | ||
let current: Container = currentContainer = this; | ||
let resolver: IResolver | undefined; | ||
let handler: Container; | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
try { | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
if (resolver == null) { | ||
if (current.parent == null) { | ||
handler = (isRegisterInRequester(key as unknown as RegisterSelf<Constructable>)) ? this : current; | ||
return autoRegister ? this._jitRegister(key, handler) : null; | ||
if (resolver == null) { | ||
if (current.parent == null) { | ||
handler = (isRegisterInRequester(key as unknown as RegisterSelf<Constructable>)) ? this : current; | ||
if (autoRegister) { | ||
return this._jitRegister(key, handler); | ||
} | ||
return null; | ||
} | ||
current = current.parent; | ||
} else { | ||
return resolver; | ||
} | ||
current = current.parent; | ||
} else { | ||
return resolver; | ||
} | ||
} finally { | ||
currentContainer = previousContainer; | ||
} | ||
@@ -263,24 +298,26 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
let current: Container = this; | ||
const previousContainer = currentContainer; | ||
let current: Container = currentContainer = this; | ||
let resolver: IResolver | undefined; | ||
let handler: Container; | ||
try { | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
if (resolver == null) { | ||
if (current.parent == null) { | ||
handler = (isRegisterInRequester(key as unknown as RegisterSelf<Constructable>)) ? this : current; | ||
resolver = this._jitRegister(key, handler); | ||
if (resolver == null) { | ||
if (current.parent == null) { | ||
handler = (isRegisterInRequester(key as unknown as RegisterSelf<Constructable>)) ? this : current; | ||
resolver = this._jitRegister(key, handler); | ||
return resolver.resolve(current, this); | ||
} | ||
current = current.parent; | ||
} else { | ||
return resolver.resolve(current, this); | ||
} | ||
current = current.parent; | ||
} else { | ||
return resolver.resolve(current, this); | ||
} | ||
} finally { | ||
currentContainer = previousContainer; | ||
} | ||
throw cantResolveKeyError(key); | ||
throw createMappedError(ErrorNames.unable_resolve_key, key); | ||
} | ||
@@ -291,18 +328,20 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const requestor = this; | ||
const previousContainer = currentContainer; | ||
const requestor = currentContainer = this; | ||
let current: Container | null = requestor; | ||
let resolver: IResolver | undefined; | ||
let resolutions: Resolved<K>[] = emptyArray; | ||
if (searchAncestors) { | ||
let resolutions: Resolved<K>[] = emptyArray; | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
if (resolver != null) { | ||
resolutions = resolutions.concat(buildAllResponse(resolver, current, requestor)); | ||
try { | ||
if (searchAncestors) { | ||
while (current != null) { | ||
resolver = current._resolvers.get(key); | ||
if (resolver != null) { | ||
resolutions = resolutions.concat(buildAllResponse(resolver, current, requestor)); | ||
} | ||
current = current.parent; | ||
} | ||
current = current.parent; | ||
return resolutions; | ||
} | ||
return resolutions; | ||
} else { | ||
while (current != null) { | ||
@@ -321,2 +360,4 @@ resolver = current._resolvers.get(key); | ||
} | ||
} finally { | ||
currentContainer = previousContainer; | ||
} | ||
@@ -328,12 +369,20 @@ | ||
public invoke<T extends {}, TDeps extends unknown[] = unknown[]>(Type: Constructable<T>, dynamicDependencies?: TDeps): T { | ||
if (isNativeFunction(Type)) { | ||
throw createNativeInvocationError(Type); | ||
const previousContainer = currentContainer; | ||
currentContainer = this; | ||
try { | ||
if (isNativeFunction(Type)) { | ||
throw createMappedError(ErrorNames.no_construct_native_fn, Type); | ||
} | ||
return dynamicDependencies === void 0 | ||
? new Type(...getDependencies(Type).map(containerGetKey, this)) | ||
: new Type(...getDependencies(Type).map(containerGetKey, this), ...dynamicDependencies); | ||
} finally { | ||
currentContainer = previousContainer; | ||
} | ||
if (dynamicDependencies === void 0) { | ||
return new Type(...getDependencies(Type).map(containerGetKey, this)); | ||
} else { | ||
return new Type(...getDependencies(Type).map(containerGetKey, this), ...dynamicDependencies); | ||
} | ||
} | ||
public hasFactory<T extends Constructable>(key: T): boolean { | ||
return this._factories.has(key); | ||
} | ||
public getFactory<K extends Constructable>(Type: K): IFactory<K> { | ||
@@ -343,3 +392,3 @@ let factory = this._factories.get(Type); | ||
if (isNativeFunction(Type)) { | ||
throw createNativeInvocationError(Type); | ||
throw createMappedError(ErrorNames.no_construct_native_fn, Type); | ||
} | ||
@@ -441,6 +490,7 @@ this._factories.set(Type, factory = new Factory<K>(Type, getDependencies(Type))); | ||
if (!isFunction(keyAsValue)) { | ||
throw jitRegisterNonFunctionError(keyAsValue); | ||
throw createMappedError(ErrorNames.unable_jit_non_constructor, keyAsValue); | ||
} | ||
if (InstrinsicTypeNames.has(keyAsValue.name)) { | ||
throw jitInstrinsicTypeError(keyAsValue); | ||
throw createMappedError(ErrorNames.no_jit_intrinsic_type, keyAsValue); | ||
} | ||
@@ -455,6 +505,8 @@ | ||
} | ||
throw invalidResolverFromRegisterError(); | ||
throw createMappedError(ErrorNames.null_resolver_from_register, keyAsValue); | ||
} | ||
return registrationResolver as IResolver; | ||
} else if (hasResources(keyAsValue)) { | ||
} | ||
if (hasResources(keyAsValue)) { | ||
const defs = getAllResources(keyAsValue); | ||
@@ -474,30 +526,104 @@ if (defs.length === 1) { | ||
} | ||
throw invalidResolverFromRegisterError(); | ||
} else if (keyAsValue.$isInterface) { | ||
throw jitInterfaceError(keyAsValue.friendlyName); | ||
} else { | ||
const resolver = this.config.defaultResolver(keyAsValue, handler); | ||
handler._resolvers.set(keyAsValue, resolver); | ||
return resolver; | ||
throw createMappedError(ErrorNames.null_resolver_from_register, keyAsValue); | ||
} | ||
if (keyAsValue.$isInterface) { | ||
throw createMappedError(ErrorNames.no_jit_interface, keyAsValue.friendlyName); | ||
} | ||
const resolver = this.config.defaultResolver(keyAsValue, handler); | ||
handler._resolvers.set(keyAsValue, resolver); | ||
return resolver; | ||
} | ||
} | ||
/** @internal */ | ||
class Factory<T extends Constructable = any> implements IFactory<T> { | ||
private transformers: ((instance: any) => any)[] | null = null; | ||
public constructor( | ||
public Type: T, | ||
private readonly dependencies: Key[], | ||
) {} | ||
public construct(container: IContainer, dynamicDependencies?: unknown[]): Resolved<T> { | ||
const previousContainer = currentContainer; | ||
currentContainer = container; | ||
let instance: Resolved<T>; | ||
try { | ||
if (dynamicDependencies === void 0) { | ||
instance = new this.Type(...this.dependencies.map(containerGetKey, container)) as Resolved<T>; | ||
} else { | ||
instance = new this.Type(...this.dependencies.map(containerGetKey, container), ...dynamicDependencies) as Resolved<T>; | ||
} | ||
if (this.transformers == null) { | ||
return instance; | ||
} | ||
return this.transformers.reduce(transformInstance, instance); | ||
} finally { | ||
currentContainer = previousContainer; | ||
} | ||
} | ||
public registerTransformer(transformer: (instance: any) => any): void { | ||
(this.transformers ??= []).push(transformer); | ||
} | ||
} | ||
function transformInstance<T>(inst: Resolved<T>, transform: (instance: any) => any) { | ||
return transform(inst); | ||
} | ||
function validateKey(key: any): void { | ||
if (key === null || key === void 0) { | ||
if (__DEV__) { | ||
throw createError(`AUR0014: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?`); | ||
} else { | ||
throw createError(`AUR0014`); | ||
} | ||
throw createMappedError(ErrorNames.null_undefined_key); | ||
} | ||
} | ||
function containerGetKey(this: IContainer, d: Key) { | ||
return this.get(d); | ||
} | ||
export type IResolvedInjection<K extends Key> = | ||
K extends IAllResolver<infer R> | ||
? readonly Resolved<R>[] | ||
: K extends INewInstanceResolver<infer R> | ||
? Resolved<R> | ||
: K extends ILazyResolver<infer R> | ||
? IResolvedLazy<R> | ||
: K extends IOptionalResolver<infer R> | ||
? Resolved<R> | undefined | ||
: K extends IFactoryResolver<infer R> | ||
? IResolvedFactory<R> | ||
: K extends IResolver<infer R> | ||
? Resolved<R> | ||
: K extends [infer R1 extends Key, ...infer R2] | ||
? [IResolvedInjection<R1>, ...IResolvedInjection<R2>] | ||
: Resolved<K>; | ||
/** | ||
* Retrieve the resolved value of a key, or values of a list of keys from the currently active container. | ||
* | ||
* Calling this without an active container will result in an error. | ||
*/ | ||
export function resolve<K extends Key>(key: K): IResolvedInjection<K>; | ||
export function resolve<K extends Key[]>(...keys: K): IResolvedInjection<K>; | ||
export function resolve<K extends Key, A extends K[]>(...keys: A): Resolved<K> | Resolved<K>[] { | ||
if (currentContainer == null) { | ||
throw createMappedError(ErrorNames.no_active_container_for_resolve, ...keys); | ||
} | ||
return keys.length === 1 | ||
? currentContainer.get(keys[0]) | ||
: keys.map(containerGetKey, currentContainer); | ||
} | ||
const buildAllResponse = (resolver: IResolver, handler: IContainer, requestor: IContainer): any[] => { | ||
if (resolver instanceof Resolver && resolver._strategy === ResolverStrategy.array) { | ||
const state = resolver._state as IResolver[]; | ||
let i = state.length; | ||
const results = new Array(i); | ||
const ii = state.length; | ||
const results = Array(ii); | ||
let i = 0; | ||
while (i--) { | ||
for (; i < ii; ++i) { | ||
results[i] = state[i].resolve(handler, requestor); | ||
@@ -533,37 +659,1 @@ } | ||
isString(key) && key.indexOf(':') > 0; | ||
const registrationError = (deps: Key[]) => | ||
// TODO: change to reporter.error and add various possible causes in description. | ||
// Most likely cause is trying to register a plain object that does not have a | ||
// register method and is not a class constructor | ||
__DEV__ | ||
? createError(`AUR0006: Unable to autoregister dependency: [${deps.map(safeString)}]`) | ||
: createError(`AUR0006:${deps.map(safeString)}`); | ||
const resourceExistError = (key: Key) => | ||
__DEV__ | ||
? createError(`AUR0007: Resource key "${safeString(key)}" already registered`) | ||
: createError(`AUR0007:${safeString(key)}`); | ||
const cantResolveKeyError = (key: Key) => | ||
__DEV__ | ||
? createError(`AUR0008: Unable to resolve key: ${safeString(key)}`) | ||
: createError(`AUR0008:${safeString(key)}`); | ||
const jitRegisterNonFunctionError = (keyAsValue: Key) => | ||
__DEV__ | ||
? createError(`AUR0009: Attempted to jitRegister something that is not a constructor: '${safeString(keyAsValue)}'. Did you forget to register this resource?`) | ||
: createError(`AUR0009:${safeString(keyAsValue)}`); | ||
const jitInstrinsicTypeError = (keyAsValue: any) => | ||
__DEV__ | ||
? createError(`AUR0010: Attempted to jitRegister an intrinsic type: ${keyAsValue.name}. Did you forget to add @inject(Key)`) | ||
: createError(`AUR0010:${keyAsValue.name}`); | ||
const invalidResolverFromRegisterError = () => | ||
__DEV__ | ||
? createError(`AUR0011: Invalid resolver returned from the static register method`) | ||
: createError(`AUR0011`); | ||
const jitInterfaceError = (name: string) => | ||
__DEV__ | ||
? createError(`AUR0012: Attempted to jitRegister an interface: ${name}`) | ||
: createError(`AUR0012:${name}`); | ||
const createNativeInvocationError = (Type: Constructable): Error => | ||
__DEV__ | ||
? createError(`AUR0015: ${Type.name} is a native function and therefore cannot be safely constructed by DI. If this is intentional, please use a callback or cachedCallback resolver.`) | ||
: createError(`AUR0015:${Type.name}`); |
199
src/di.ts
@@ -5,3 +5,2 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { applyMetadataPolyfill } from '@aurelia/metadata'; | ||
@@ -13,9 +12,11 @@ | ||
import { Container } from './di.container'; | ||
import { Constructable, IDisposable, Writable } from './interfaces'; | ||
import { Constructable, IDisposable } from './interfaces'; | ||
import { appendAnnotation, getAnnotationKeyFor, IResourceKind, ResourceDefinition, ResourceType } from './resource'; | ||
import { createError, defineMetadata, getOwnMetadata, isFunction, isString, safeString } from './utilities'; | ||
import { defineMetadata, getOwnMetadata, isFunction, isString, safeString } from './utilities'; | ||
import { instanceRegistration, singletonRegistration, transientRegistation, callbackRegistration, cachedCallbackRegistration, aliasToRegistration, deferRegistration, cacheCallbackResult } from './di.registration'; | ||
import { ErrorNames, createMappedError } from './errors'; | ||
export type ResolveCallback<T = any> = (handler: IContainer, requestor: IContainer, resolver: IResolver<T>) => T; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export type InterfaceSymbol<K = any> = (target: Injectable | AbstractInjectable, property: string | symbol | undefined, index?: number) => void; | ||
@@ -51,4 +52,6 @@ | ||
has<K extends Key>(key: K | Key, searchAncestors: boolean): boolean; | ||
get<K extends Key>(key: IAllResolver<K>): readonly Resolved<K>[]; | ||
get<K extends Key>(key: INewInstanceResolver<K>): Resolved<K>; | ||
get<K extends Key>(key: ILazyResolver<K>): IResolvedLazy<K>; | ||
get<K extends Key>(key: IOptionalResolver<K>): Resolved<K> | undefined; | ||
get<K extends Key>(key: IFactoryResolver<K>): IResolvedFactory<K>; | ||
@@ -78,2 +81,4 @@ get<K extends Key>(key: IResolver<K>): Resolved<K>; | ||
invoke<T extends {}, TDeps extends unknown[] = unknown[]>(key: Constructable<T>, dynamicDependencies?: TDeps): T; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
hasFactory<T extends Constructable>(key: any): boolean; | ||
getFactory<T extends Constructable>(key: T): IFactory<T>; | ||
@@ -174,3 +179,3 @@ createChild(config?: IContainerConfiguration): IContainer; | ||
none(key: Key): IResolver { | ||
throw noResolverForKeyError(key); | ||
throw createMappedError(ErrorNames.none_resolver_found, key); | ||
}, | ||
@@ -181,7 +186,2 @@ singleton: (key: Key): IResolver => new Resolver(key, ResolverStrategy.singleton, key), | ||
const noResolverForKeyError = (key: Key) => | ||
__DEV__ | ||
? createError(`AUR0002: ${safeString(key)} not registered, did you forget to add @singleton()?`) | ||
: createError(`AUR0002:${safeString(key)}`); | ||
export class ContainerConfiguration implements IContainerConfiguration { | ||
@@ -315,3 +315,3 @@ public static readonly DEFAULT: ContainerConfiguration = ContainerConfiguration.from({}); | ||
if (target == null || new.target !== undefined) { | ||
throw createNoRegistrationError(friendlyName); | ||
throw createMappedError(ErrorNames.no_registration_for_interface, friendlyName); | ||
} | ||
@@ -333,6 +333,2 @@ const annotationParamtypes = getOrCreateAnnotationParamTypes(target as Injectable); | ||
}; | ||
const createNoRegistrationError = (name: string) => | ||
__DEV__ | ||
? createError(`AUR0001: No registration for interface: '${name}'`) | ||
: createError(`AUR0001:${name}`); | ||
@@ -484,3 +480,3 @@ export const DI = { | ||
return function (key: any): ReturnType<typeof DI.inject> { | ||
const resolver: ReturnType<typeof DI.inject> & Partial<Pick<IResolver, 'resolve'>> & { $isResolver: true} = function (target: Injectable, property?: string | number, descriptor?: PropertyDescriptor | number): void { | ||
const resolver = function (target: Injectable, property?: string | number, descriptor?: PropertyDescriptor | number): void { | ||
inject(resolver)(target, property, descriptor); | ||
@@ -513,2 +509,3 @@ }; | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function transient<T extends Constructable>(): typeof transientDecorator; | ||
@@ -547,3 +544,5 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function singleton<T extends Constructable>(): typeof singletonDecorator; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function singleton<T extends Constructable>(options?: SingletonOptions): typeof singletonDecorator; | ||
@@ -571,35 +570,22 @@ /** | ||
const createAllResolver = ( | ||
getter: (key: any, handler: IContainer, requestor: IContainer, searchAncestors: boolean) => readonly any[] | ||
): (key: any, searchAncestors?: boolean) => ReturnType<typeof DI.inject> => { | ||
return (key: any, searchAncestors?: boolean): ReturnType<typeof DI.inject> => { | ||
searchAncestors = !!searchAncestors; | ||
const resolver: ReturnType<typeof DI.inject> | ||
& Required<Pick<IResolver, 'resolve'>> | ||
& { $isResolver: true} | ||
= function ( | ||
target: Injectable, | ||
property?: string | number, | ||
descriptor?: PropertyDescriptor | number | ||
): void { | ||
inject(resolver)(target, property, descriptor); | ||
}; | ||
/** | ||
* Create a resolver that will resolve all values of a key from resolving container | ||
*/ | ||
export const all = <T extends Key>(key: T, searchAncestors: boolean = false): IAllResolver<T> => { | ||
function resolver(target: Injectable, property?: string | number, descriptor?: PropertyDescriptor | number): void { | ||
inject(resolver)(target, property, descriptor); | ||
} | ||
resolver.$isResolver = true; | ||
resolver.resolve = function (handler: IContainer, requestor: IContainer): any { | ||
return getter(key, handler, requestor, searchAncestors!); | ||
}; | ||
resolver.$isResolver = true; | ||
resolver.resolve = (handler: IContainer, requestor: IContainer) => requestor.getAll(key, searchAncestors); | ||
return resolver; | ||
}; | ||
return resolver as IAllResolver<T>; | ||
}; | ||
export type IAllResolver<T> = IResolver<readonly Resolved<T>[]> & { | ||
// type only hack | ||
__isAll: undefined; | ||
// any for decorator | ||
(...args: unknown[]): any; | ||
}; | ||
export const all = /*@__PURE__*/createAllResolver( | ||
(key: any, | ||
handler: IContainer, | ||
requestor: IContainer, | ||
searchAncestors: boolean | ||
) => requestor.getAll(key, searchAncestors) | ||
); | ||
/** | ||
@@ -634,4 +620,4 @@ * Lazily inject a dependency depending on whether the [[`Key`]] is present at the time of function call. | ||
return () => requestor.get(key); | ||
}); | ||
export type ILazyResolver<K = any> = IResolver<K> | ||
}) as <K extends Key>(key: K) => ILazyResolver<K>; | ||
export type ILazyResolver<K extends Key = Key> = IResolver<() => K> | ||
// type only hack | ||
@@ -671,3 +657,10 @@ & { __isLazy: undefined } | ||
} | ||
}); | ||
}) as <K extends Key>(key: K) => IOptionalResolver<K>; | ||
export type IOptionalResolver<K extends Key = Key> = IResolver<K | undefined> & { | ||
// type only hack | ||
__isOptional: undefined; | ||
// any is needed for decorator usages | ||
(...args: unknown[]): any; | ||
}; | ||
/** | ||
@@ -721,6 +714,9 @@ * ignore tells the container not to try to inject a dependency | ||
/** | ||
* Create a resolver that will resolve a new instance of a key, and register the newly created instance with the requestor container | ||
*/ | ||
export const newInstanceForScope = /*@__PURE__*/createResolver( | ||
(key: any, handler: IContainer, requestor: IContainer) => { | ||
const instance = createNewInstance(key, handler, requestor); | ||
const instanceProvider: InstanceProvider<any> = new InstanceProvider<any>(safeString(key), instance); | ||
const instanceProvider = new InstanceProvider<{}>(safeString(key), instance); | ||
/** | ||
@@ -735,2 +731,5 @@ * By default the new instances for scope are disposable. | ||
/** | ||
* Create a resolver that will resolve a new instance of a key | ||
*/ | ||
export const newInstanceOf = /*@__PURE__*/createResolver( | ||
@@ -740,3 +739,4 @@ (key: any, handler: IContainer, requestor: IContainer) => createNewInstance(key, handler, requestor) | ||
export type INewInstanceResolver<T> = { | ||
export type INewInstanceResolver<T> = IResolver<T> & { | ||
// type only hack | ||
__newInstance: undefined; | ||
@@ -748,2 +748,19 @@ // any is needed for decorator usage | ||
const createNewInstance = (key: any, handler: IContainer, requestor: IContainer) => { | ||
// 1. if there's a factory registration for the key | ||
if (handler.hasFactory(key)) { | ||
return handler.getFactory(key).construct(requestor); | ||
} | ||
// 2. if key is an interface | ||
if (isInterface(key)) { | ||
const hasDefault = isFunction((key as unknown as IRegistry).register); | ||
const resolver = handler.getResolver(key, hasDefault) as IResolver<Constructable<typeof key>>; | ||
const factory = resolver?.getFactory?.(handler); | ||
// 2.1 and has factory | ||
if (factory != null) { | ||
return factory.construct(requestor); | ||
} | ||
// 2.2 cannot instantiate a dummy interface | ||
throw createMappedError(ErrorNames.invalid_new_instance_on_interface, key); | ||
} | ||
// 3. jit factory, in case of newInstanceOf(SomeClass) | ||
return handler.getFactory(key).construct(requestor); | ||
@@ -753,2 +770,3 @@ }; | ||
_START_CONST_ENUM(); | ||
/** @internal */ | ||
export const enum ResolverStrategy { | ||
@@ -765,7 +783,18 @@ instance = 0, | ||
export class Resolver implements IResolver, IRegistration { | ||
/** @internal */ | ||
public _key: Key; | ||
/** @internal */ | ||
public _strategy: ResolverStrategy; | ||
/** @internal */ | ||
public _state: any; | ||
public constructor( | ||
public _key: Key, | ||
public _strategy: ResolverStrategy, | ||
public _state: any, | ||
) {} | ||
key: Key, | ||
strategy: ResolverStrategy, | ||
state: any, | ||
) { | ||
this._key = key; | ||
this._strategy = strategy; | ||
this._state = state; | ||
} | ||
@@ -786,3 +815,3 @@ public get $isResolver(): true { return true; } | ||
if (this.resolving) { | ||
throw cyclicDependencyError(this._state.name); | ||
throw createMappedError(ErrorNames.cyclic_dependency, this._state.name); | ||
} | ||
@@ -799,3 +828,3 @@ this.resolving = true; | ||
if (factory === null) { | ||
throw nullFactoryError(this._key); | ||
throw createMappedError(ErrorNames.no_factory, this._key); | ||
} | ||
@@ -811,3 +840,3 @@ return factory.construct(requestor); | ||
default: | ||
throw invalidResolverStrategyError(this._strategy); | ||
throw createMappedError(ErrorNames.invalid_resolver_strategy, this._strategy); | ||
} | ||
@@ -828,14 +857,2 @@ } | ||
} | ||
const cyclicDependencyError = (name: string) => | ||
__DEV__ | ||
? createError(`AUR0003: Cyclic dependency found: ${name}`) | ||
: createError(`AUR0003:${name}`); | ||
const nullFactoryError = (key: Key) => | ||
__DEV__ | ||
? createError(`AUR0004: Resolver for ${safeString(key)} returned a null factory`) | ||
: createError(`AUR0004:${safeString(key)}`); | ||
const invalidResolverStrategyError = (strategy: ResolverStrategy) => | ||
__DEV__ | ||
? createError(`AUR0005: Invalid resolver strategy specified: ${strategy}.`) | ||
: createError(`AUR0005:${strategy}`); | ||
@@ -853,38 +870,2 @@ /** @internal */ | ||
export function containerGetKey(this: IContainer, d: Key) { | ||
return this.get(d); | ||
} | ||
function transformInstance<T>(inst: Resolved<T>, transform: (instance: any) => any) { | ||
return transform(inst); | ||
} | ||
/** @internal */ | ||
export class Factory<T extends Constructable = any> implements IFactory<T> { | ||
private transformers: ((instance: any) => any)[] | null = null; | ||
public constructor( | ||
public Type: T, | ||
private readonly dependencies: Key[], | ||
) {} | ||
public construct(container: IContainer, dynamicDependencies?: unknown[]): Resolved<T> { | ||
let instance: Resolved<T>; | ||
if (dynamicDependencies === void 0) { | ||
instance = new this.Type(...this.dependencies.map(containerGetKey, container)) as Resolved<T>; | ||
} else { | ||
instance = new this.Type(...this.dependencies.map(containerGetKey, container), ...dynamicDependencies) as Resolved<T>; | ||
} | ||
if (this.transformers == null) { | ||
return instance; | ||
} | ||
return this.transformers.reduce(transformInstance, instance); | ||
} | ||
public registerTransformer(transformer: (instance: any) => any): void { | ||
(this.transformers ??= []).push(transformer); | ||
} | ||
} | ||
/** | ||
@@ -1034,3 +1015,3 @@ * An implementation of IRegistry that delegates registration to a | ||
if (this._instance == null) { | ||
throw noInstanceError(this._name); | ||
throw createMappedError(ErrorNames.no_instance_provided, this._name); | ||
} | ||
@@ -1045,8 +1026,2 @@ return this._instance; | ||
const noInstanceError = (name?: string) => { | ||
if (__DEV__) { | ||
return createError(`AUR0013: Cannot call resolve ${name} before calling prepare or after calling dispose.`); | ||
} else { | ||
return createError(`AUR0013:${name}`); | ||
} | ||
}; | ||
const isInterface = <K>(key: any): key is InterfaceSymbol<K> => isFunction(key) && key.$isInterface === true; |
import { createInterface } from './di'; | ||
import { ErrorNames, createMappedError } from './errors'; | ||
import { Constructable, IDisposable } from './interfaces'; | ||
import { createError, isString } from './utilities'; | ||
import { isString } from './utilities'; | ||
@@ -57,3 +58,3 @@ /** | ||
if (!channelOrInstance) { | ||
throw createError(`Invalid channel name or instance: ${channelOrInstance}.`); | ||
throw createMappedError(ErrorNames.event_aggregator_publish_invalid_event_name, channelOrInstance); | ||
} | ||
@@ -107,3 +108,3 @@ | ||
if (!channelOrType) { | ||
throw createError(`Invalid channel name or type: ${channelOrType}.`); | ||
throw createMappedError(ErrorNames.event_aggregator_subscribe_invalid_event_name, channelOrType); | ||
} | ||
@@ -110,0 +111,0 @@ |
@@ -0,3 +1,4 @@ | ||
import { ErrorNames, createMappedError } from './errors'; | ||
import { Constructable, Overwrite } from './interfaces'; | ||
import { createError, createObject } from './utilities'; | ||
import { createObject } from './utilities'; | ||
@@ -285,5 +286,18 @@ const isNumericLookup: Record<string, boolean> = {}; | ||
} | ||
throw createError(`No default value found`); | ||
throw createMappedError(ErrorNames.first_defined_no_value); | ||
}; | ||
/** | ||
* Get the prototypes of a class hierarchy. Es6 classes have their parent class as prototype | ||
* so this will return a list of constructors | ||
* | ||
* @example | ||
* ```ts | ||
* class A {} | ||
* class B extends A {} | ||
* | ||
* assert.deepStrictEqual(getPrototypeChain(A), [A]) | ||
* assert.deepStrictEqual(getPrototypeChain(B), [B, A]) | ||
* ``` | ||
*/ | ||
export const getPrototypeChain = /*@__PURE__*/(function () { | ||
@@ -438,3 +452,3 @@ const functionPrototype = Function.prototype; | ||
*/ | ||
export const resolveAll = ( | ||
export const onResolveAll = ( | ||
...maybePromises: (void | Promise<void>)[] | ||
@@ -441,0 +455,0 @@ ): void | Promise<void> => { |
@@ -8,4 +8,7 @@ export { | ||
factory, | ||
type IAllResolver, | ||
type IFactoryResolver, | ||
type IOptionalResolver, | ||
type IResolvedFactory, | ||
type INewInstanceResolver, | ||
DI, | ||
@@ -44,2 +47,7 @@ IContainer, | ||
export { | ||
resolve, | ||
type IResolvedInjection, | ||
} from './di.container'; | ||
export { | ||
type Class, | ||
@@ -115,3 +123,3 @@ type Constructable, | ||
onResolve, | ||
resolveAll, | ||
onResolveAll, | ||
} from './functions'; | ||
@@ -118,0 +126,0 @@ |
import { Metadata } from '@aurelia/metadata'; | ||
import { all, createInterface, IContainer, ignore, IRegistry, optional } from './di'; | ||
import { all, createInterface, IContainer, IRegistry, optional } from './di'; | ||
import { instanceRegistration, singletonRegistration } from './di.registration'; | ||
@@ -9,2 +9,3 @@ import { bound, toLookup } from './functions'; | ||
import { createObject, defineMetadata, isFunction } from './utilities'; | ||
import { resolve } from './di.container'; | ||
@@ -318,5 +319,3 @@ export const enum LogLevel { | ||
export class DefaultLogEventFactory implements ILogEventFactory { | ||
public constructor( | ||
@ILogConfig public readonly config: ILogConfig, | ||
) {} | ||
public readonly config = resolve(ILogConfig); | ||
@@ -336,3 +335,3 @@ public createLogEvent(logger: ILogger, level: LogLevel, message: string, optionalParams: unknown[]): ILogEvent { | ||
public constructor( | ||
@IPlatform p: IPlatform, | ||
p = resolve(IPlatform), | ||
) { | ||
@@ -421,2 +420,3 @@ const $console = p.console as { | ||
/* eslint-disable default-param-last */ | ||
public constructor( | ||
@@ -426,11 +426,12 @@ /** | ||
*/ | ||
@ILogConfig config: ILogConfig, | ||
@ILogEventFactory factory: ILogEventFactory, | ||
@all(ISink) sinks: ISink[], | ||
config = resolve(ILogConfig), | ||
factory = resolve(ILogEventFactory), | ||
sinks = resolve(all(ISink)), | ||
/** | ||
* The scopes that this logger was created for, if any. | ||
*/ | ||
@optional(ILogScopes) public readonly scope: string[] = [], | ||
@ignore parent: DefaultLogger | null = null, | ||
public readonly scope: string[] = resolve(optional(ILogScopes)) ?? [], | ||
parent: DefaultLogger | null = null, | ||
) { | ||
/* eslint-enable default-param-last */ | ||
let traceSinks: ISink[]; | ||
@@ -681,3 +682,3 @@ let debugSinks: ISink[]; | ||
if (scopedLogger === void 0) { | ||
scopedLogger = scopedLoggers[name] = new DefaultLogger(this.config, this._factory, (void 0)!, this.scope.concat(name), this); | ||
scopedLogger = scopedLoggers[name] = new DefaultLogger(this.config, this._factory, null!, this.scope.concat(name), this); | ||
} | ||
@@ -684,0 +685,0 @@ return scopedLogger; |
import { createInterface } from './di'; | ||
import { emptyArray } from './platform'; | ||
import { getAllResources } from './resource'; | ||
import { createError, isFunction } from './utilities'; | ||
import { isFunction } from './utilities'; | ||
@@ -9,2 +9,3 @@ import type { IRegistry } from './di'; | ||
import type { ResourceDefinition } from './resource'; | ||
import { ErrorNames, createMappedError } from './errors'; | ||
@@ -40,3 +41,3 @@ export interface IModule { | ||
} else { | ||
throw createError(`Invalid input: ${String(objOrPromise)}. Expected Promise or Object.`); | ||
throw createMappedError(ErrorNames.invalid_module_transform_input, objOrPromise); | ||
} | ||
@@ -81,3 +82,3 @@ } | ||
private _analyze(m: TMod): AnalyzedModule<TMod> { | ||
if (m == null) throw new Error(`Invalid input: ${String(m)}. Expected Object.`); | ||
if (m == null) throw createMappedError(ErrorNames.invalid_module_transform_input, m); | ||
if (typeof m !== 'object') return new AnalyzedModule(m, []); | ||
@@ -84,0 +85,0 @@ let value: unknown; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
746024
39
14815
+ Added@aurelia/metadata@2.0.1-dev.202306161507(transitive)
+ Added@aurelia/platform@2.0.1-dev.202306161507(transitive)
- Removed@aurelia/metadata@2.0.1-dev.202304181031(transitive)
- Removed@aurelia/platform@2.0.1-dev.202304181031(transitive)