Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aurelia/kernel

Package Overview
Dependencies
Maintainers
1
Versions
1117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aurelia/kernel - npm Package Compare versions

Comparing version 2.1.0-dev.202404150648 to 2.1.0-dev.202405060015

27

CHANGELOG.md

@@ -6,2 +6,29 @@ # Change Log

<a name="2.0.0-beta.16"></a>
# 2.0.0-beta.16 (2024-05-03)
### Refactorings:
* **rendering:** correctly handle compilation cache (#1955) ([c11491b](https://github.com/aurelia/aurelia/commit/c11491b))
* ***:** extract template compiler into own package (#1954) ([ad7ae1e](https://github.com/aurelia/aurelia/commit/ad7ae1e))
* ***:** cleanup deco code (#1947) ([ca22bc8](https://github.com/aurelia/aurelia/commit/ca22bc8))
* **observers:** use static blocks, group related code ([ca22bc8](https://github.com/aurelia/aurelia/commit/ca22bc8))
<a name="2.0.0-beta.15"></a>
# 2.0.0-beta.15 (2024-04-17)
### Features:
* **resources:** support static `$au` property for definition (#1939) ([877a385](https://github.com/aurelia/aurelia/commit/877a385))
### Bug Fixes:
* ***:** residual decorator work (#1942) ([7e8c12f](https://github.com/aurelia/aurelia/commit/7e8c12f))
### Refactorings:
* ***:** migration to TC39 decorators + metadata simplification (#1932) ([22f90ad](https://github.com/aurelia/aurelia/commit/22f90ad))
<a name="2.0.0-beta.14"></a>

@@ -8,0 +35,0 @@ # 2.0.0-beta.14 (2024-04-03)

8

dist/types/di.container.d.ts

@@ -1,3 +0,3 @@

import { IContainer, type Key, type IResolver, type Resolved, type IContainerConfiguration } from './di';
import type { IAllResolver, INewInstanceResolver, ILazyResolver, IResolvedLazy, IOptionalResolver, IFactoryResolver, IResolvedFactory } from './di.resolvers';
import { IContainer, InterfaceSymbol, type IContainerConfiguration, type IResolver, type Key, type Resolved } from './di';
import type { IAllResolver, IFactoryResolver, ILazyResolver, INewInstanceResolver, IOptionalResolver, IResolvedFactory, IResolvedLazy } from './di.resolvers';
export declare const Registrable: Readonly<{

@@ -24,5 +24,3 @@ /**

}
export type IResolvedInjection<K extends Key> = K extends IAllResolver<infer R> ? 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>] : K extends {
__resolved__: infer T;
} ? T : Resolved<K>;
export type IResolvedInjection<K extends Key> = K extends IAllResolver<infer R> ? 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>] : K extends InterfaceSymbol<infer T> ? T : Resolved<K>;
/**

@@ -29,0 +27,0 @@ * Retrieve the resolved value of a key, or values of a list of keys from the currently active container.

@@ -5,9 +5,14 @@ import { Constructable, IDisposable } from './interfaces';

export type ResolveCallback<T = any> = (handler: IContainer, requestor: IContainer, resolver: IResolver<T>) => T;
export type InterfaceSymbol<K = any> = (target: Injectable | AbstractInjectable, property: string | symbol | undefined, index?: number) => void;
export interface InterfaceSymbol<K = any> {
$isInterface: boolean;
friendlyName?: string;
register?(container: IContainer, key?: K): IResolver<K>;
toString?(): string;
}
interface IResolverLike<C, K = any> {
readonly $isResolver: true;
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> {
}

@@ -17,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>;

@@ -52,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;

@@ -105,8 +110,6 @@ getResolver<K extends Key, T = K>(key: K | Key, autoRegister?: boolean): IResolver<T> | null;

}
export declare const inject: (...dependencies: Key[]) => (target: Injectable, key?: string | number, descriptor?: PropertyDescriptor | number) => void;
export declare const inject: (...dependencies: Key[]) => (decorated: unknown, context: DecoratorContext) => void;
export declare const DI: {
createContainer: (config?: Partial<IContainerConfiguration> | undefined) => IContainer;
getDesignParamtypes: (Type: Constructable | Injectable) => readonly Key[] | undefined;
getAnnotationParamtypes: (Type: Constructable | Injectable) => readonly Key[] | undefined;
getOrCreateAnnotationParamTypes: (Type: Constructable | Injectable) => Key[];
getDependencies: (Type: Constructable | Injectable) => Key[];

@@ -155,3 +158,3 @@ /**

createInterface: <K extends Key>(configureOrName?: string | ((builder: ResolverBuilder<K>) => IResolver<K>) | undefined, configuror?: ((builder: ResolverBuilder<K>) => IResolver<K>) | undefined) => InterfaceSymbol<K>;
inject: (...dependencies: Key[]) => (target: Injectable, key?: string | number, descriptor?: PropertyDescriptor | number) => void;
inject: (...dependencies: Key[]) => (decorated: unknown, context: DecoratorContext) => void;
/**

@@ -197,3 +200,3 @@ * Registers the `target` class as a transient dependency; each time the dependency is resolved

export declare const IServiceLocator: InterfaceSymbol<IServiceLocator>;
declare function transientDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
declare function transientDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext): T & RegisterSelf<T>;
/**

@@ -220,7 +223,7 @@ * Registers the decorated class as a transient dependency; each time the dependency is resolved

*/
export declare function transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
export declare function transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext): T & RegisterSelf<T>;
type SingletonOptions = {
scoped: boolean;
};
declare const singletonDecorator: <T extends Constructable>(target: T & Partial<RegisterSelf<T>>) => T & RegisterSelf<T>;
type SingletonDecorator = <T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext) => T & RegisterSelf<T>;
/**

@@ -235,4 +238,4 @@ * Registers the decorated class as a singleton dependency; the class will only be created once. Each

*/
export declare function singleton<T extends Constructable>(): typeof singletonDecorator;
export declare function singleton<T extends Constructable>(options?: SingletonOptions): typeof singletonDecorator;
export declare function singleton<T extends Constructable>(): SingletonDecorator;
export declare function singleton<T extends Constructable>(options?: SingletonOptions): SingletonDecorator;
/**

@@ -249,4 +252,4 @@ * Registers the `target` class as a singleton dependency; the class will only be created once. Each

*/
export declare function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
export declare class InstanceProvider<K extends Key> implements IDisposableResolver<K | 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> {
get friendlyName(): string | undefined;

@@ -261,4 +264,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;

@@ -265,0 +268,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

@@ -13,6 +13,3 @@ import { IContainer, IResolver, Key, Resolved } from './di';

export declare const all: <T extends Key>(key: T, searchAncestors?: boolean) => IAllResolver<T>;
export type IAllResolver<T> = IResolver<Resolved<T>[]> & {
__isAll: undefined;
(...args: unknown[]): any;
};
export type IAllResolver<T> = IResolver<readonly Resolved<T>[]> & ((decorated: unknown, context: DecoratorContext) => any);
/**

@@ -19,0 +16,0 @@ * Lazily inject a dependency depending on whether the [[`Key`]] is present at the time of function call.

@@ -52,3 +52,3 @@ import { Constructable, Overwrite } from './interfaces';

*/
export declare const bound: <T extends Function>(target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T>;
export declare const bound: <TThis extends object, TArgs extends unknown[], TReturn>(originalMethod: (this: TThis, ...args: TArgs) => TReturn, context: ClassMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>) => void;
export declare const mergeArrays: <T>(...arrays: (readonly T[] | undefined)[]) => T[];

@@ -55,0 +55,0 @@ export declare const firstDefined: <T>(...values: readonly (T | undefined)[]) => T;

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';

@@ -155,6 +155,6 @@ import { IContainer, IRegistry } from './di';

key: string;
define<TSink extends ISink>(target: Constructable<TSink>, definition: SinkDefinition): Constructable<TSink>;
getHandles<TSink_1 extends ISink>(target: TSink_1 | Constructable<TSink_1>): LogLevel[] | undefined;
define<TSink extends Constructable<ISink>>(target: TSink, definition: SinkDefinition): void;
getHandles<TSink_1 extends ISink>(target: TSink_1): Exclude<LogLevel, typeof none>[] | undefined;
}>;
export declare const sink: (definition: SinkDefinition) => <TSink extends ISink>(target: Constructable<TSink>) => Constructable<TSink>;
export declare const sink: (definition: SinkDefinition) => <TSink extends Constructable<ISink>>(_target: TSink, context: ClassDecoratorContext<TSink>) => void;
export interface IConsoleLike {

@@ -161,0 +161,0 @@ debug(message: string, ...optionalParams: unknown[]): void;

{
"name": "@aurelia/kernel",
"version": "2.1.0-dev.202404150648",
"version": "2.1.0-dev.202405060015",
"main": "dist/cjs/index.cjs",

@@ -56,4 +56,4 @@ "module": "dist/esm/index.mjs",

"dependencies": {
"@aurelia/metadata": "2.1.0-dev.202404150648",
"@aurelia/platform": "2.1.0-dev.202404150648"
"@aurelia/metadata": "2.1.0-dev.202405060015",
"@aurelia/platform": "2.1.0-dev.202405060015"
},

@@ -60,0 +60,0 @@ "devDependencies": {

@@ -20,5 +20,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */

class Def {
public constructor(@all(I) private readonly i: I) {}
}
// Not yet supported by TS, as the method-parameter decorator proposal is not in Stage 4 yet
// class Def {
// public constructor(@all(I) private readonly i: I) {}
// }

@@ -35,8 +36,10 @@ @inject(all(I))

class Def {
public constructor(@lazy(I) private readonly i: I) {}
}
// Not yet supported by TS, as the method-parameter decorator proposal is not in Stage 4 yet
// class Def {
// public constructor(@lazy(I) private readonly i: I) {}
// }
@inject(lazy(I))
class G {
private readonly foo = lazy(I);
public i = resolve(lazy(I));

@@ -55,5 +58,6 @@ public b: I = this.i();

class Def {
public constructor(@optional(I) private readonly i: I) { }
}
// Not yet supported by TS, as the method-parameter decorator proposal is not in Stage 4 yet
// class Def {
// public constructor(@optional(I) private readonly i: I) { }
// }

@@ -79,8 +83,9 @@ @inject(optional(I))

class Def {
public constructor(
@newInstanceOf(I) private readonly i: I,
@newInstanceForScope(I) private readonly j: I,
) { }
}
// Not yet supported by TS, as the method-parameter decorator proposal is not in Stage 4 yet
// class Def {
// public constructor(
// @newInstanceOf(I) private readonly i: I,
// @newInstanceForScope(I) private readonly j: I,
// ) { }
// }

@@ -87,0 +92,0 @@ @inject(newInstanceOf(I))

/* 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 { Metadata, isObject } from '@aurelia/metadata';
import { isNativeFunction } from './functions';
import { type Class, type Constructable, type IDisposable } from './interfaces';
import { emptyArray } from './platform';
import { resourceBaseName, ResourceDefinition, StaticResourceType, type ResourceType } from './resource';
import { isFunction, isString, objectFreeze } from './utilities';
import { isObject } from '@aurelia/metadata';
import {
IContainer,
type Key,
type IResolver,
type IDisposableResolver,
type IRegistry,
InterfaceSymbol,
Resolver,
ResolverStrategy,
type Transformer,
getDependencies,
type IContainerConfiguration,
type IFactory,
type IRegistry,
type IResolver,
type Key,
type RegisterSelf,
type Resolved,
getDependencies,
type IFactory,
type IContainerConfiguration,
type Transformer,
} from './di';
import { aliasToRegistration, singletonRegistration } from './di.registration';
import type {
IAllResolver,
IFactoryResolver,
ILazyResolver,
INewInstanceResolver,
IOptionalResolver,
IResolvedFactory,
IResolvedLazy,
} from './di.resolvers';
import { ErrorNames, createMappedError, logError, logWarn } from './errors';
import { aliasToRegistration, singletonRegistration } from './di.registration';
import type { IAllResolver, INewInstanceResolver, ILazyResolver, IResolvedLazy, IOptionalResolver, IFactoryResolver, IResolvedFactory } from './di.resolvers';
import { isNativeFunction } from './functions';
import { type Class, type Constructable } from './interfaces';
import { emptyArray } from './platform';
import { ResourceDefinition, StaticResourceType, resourceBaseName, type ResourceType } from './resource';
import { getMetadata, isFunction, isString, objectFreeze } from './utilities';

@@ -63,3 +71,3 @@ export const Registrable = /*@__PURE__*/(() => {

public readonly defaultResolver: (key: Key, handler: IContainer) => IResolver,
) {}
) { }

@@ -106,3 +114,3 @@ public static from(config?: IContainerConfiguration): ContainerConfiguration {

*/
private readonly _resolvers: Map<Key, IResolver | IDisposableResolver>;
private readonly _resolvers: Map<Key, IResolver>;
/**

@@ -120,6 +128,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>();

@@ -188,3 +196,3 @@ public get parent(): IContainer | null {

Registrable.get(current)!.call(current, this);
} else if ((def = Metadata.getOwn(resourceBaseName, current)) != null) {
} else if ((def = getMetadata(resourceBaseName, current)!) != null) {
def.register(this);

@@ -196,17 +204,25 @@ } else if (isClass<StaticResourceType>(current)) {

let key = `${resourceBaseName}:${$au.type}:${$au.name}`;
if (!this.has(key, false)) {
aliasToRegistration(current, key).register(this);
if (!this.has(current, false)) {
singletonRegistration(current, current).register(this);
if (this.has(key, false)) {
if (__DEV__) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(globalThis as any).console?.warn(createMappedError(ErrorNames.resource_already_exists, key));
}
j = 0;
jj = aliases.length;
for (; j < jj; ++j) {
key = `${resourceBaseName}:${$au.type}:${aliases[j]}`;
if (!this.has(key, false)) {
aliasToRegistration(current, key).register(this);
continue;
}
aliasToRegistration(current, key).register(this);
if (!this.has(current, false)) {
singletonRegistration(current, current).register(this);
}
j = 0;
jj = aliases.length;
for (; j < jj; ++j) {
key = `${resourceBaseName}:${$au.type}:${aliases[j]}`;
if (this.has(key, false)) {
if (__DEV__) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(globalThis as any).console?.warn(createMappedError(ErrorNames.resource_already_exists, key));
}
continue;
}
} else {
// dev message for registering static resources that the key already registered
aliasToRegistration(current, key).register(this);
}

@@ -241,3 +257,3 @@ } else {

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);

@@ -259,7 +275,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);
}

@@ -515,7 +531,7 @@

let disposable: IDisposable;
let disposable: IResolver;
let key: Key;
for ([key, disposable] of disposableResolvers.entries()) {
disposable.dispose();
disposable.dispose?.();
resolvers.delete(key);

@@ -562,3 +578,4 @@ }

private _jitRegister(keyAsValue: any, handler: Container): IResolver {
if (!isFunction(keyAsValue)) {
const $isRegistry = isRegistry(keyAsValue);
if (!isFunction(keyAsValue) && !$isRegistry) {
throw createMappedError(ErrorNames.unable_jit_non_constructor, keyAsValue);

@@ -571,3 +588,3 @@ }

if (isRegistry(keyAsValue)) {
if ($isRegistry) {
const registrationResolver = keyAsValue.register(handler, keyAsValue);

@@ -584,2 +601,3 @@ if (!(registrationResolver instanceof Object) || (registrationResolver as IResolver).resolve == null) {

// TODO(sayan): remove potential dead code
if (keyAsValue.$isInterface) {

@@ -601,3 +619,3 @@ throw createMappedError(ErrorNames.no_jit_interface, keyAsValue.friendlyName);

private readonly dependencies: Key[],
) {}
) { }

@@ -690,3 +708,3 @@ public construct(container: IContainer, dynamicDependencies?: unknown[]): Resolved<T> {

? [IResolvedInjection<R1>, ...IResolvedInjection<R2>]
: K extends { __resolved__: infer T }
: K extends InterfaceSymbol<infer T>
? T

@@ -693,0 +711,0 @@ : Resolved<K>;

@@ -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),
);
};
};
/* eslint-disable @typescript-eslint/no-explicit-any */
import { IContainer, IFactory, IRegistry, IResolver, Injectable, InstanceProvider, InterfaceSymbol, Key, Resolved, inject } from './di';
import { IContainer, IFactory, IRegistry, IResolver, InstanceProvider, InterfaceSymbol, Key, Resolved, inject } from './di';
import { createContainer } from './di.container';

@@ -17,4 +17,4 @@ import { ErrorNames, createMappedError } from './errors';

return function (key: any) {
function Resolver(target: any, property?: string | number, descriptor?: PropertyDescriptor | number): void {
inject(Resolver)(target, property, descriptor);
function Resolver(target: any, context: DecoratorContext): void {
inject(Resolver)(target, context);
}

@@ -35,4 +35,4 @@

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);
function resolver(decorated: unknown, context: DecoratorContext): void {
inject(resolver)(decorated, context);
}

@@ -45,8 +45,5 @@

};
export type IAllResolver<T> = IResolver<Resolved<T>[]> & {
// type only hack
__isAll: undefined;
export type IAllResolver<T> = IResolver<readonly Resolved<T>[]> &
// any for decorator
(...args: unknown[]): any;
};
((decorated: unknown, context: DecoratorContext) => any);

@@ -129,5 +126,5 @@ /**

*/
export const ignore: IResolver<undefined> = /*@__PURE__*/objectAssign((target: Injectable, property?: string | number, descriptor?: PropertyDescriptor | number): void => {
inject(ignore)(target, property, descriptor);
}, { $isResolver: true, resolve: () => void 0 } as const);
export const ignore: IResolver<undefined> = /*@__PURE__*/objectAssign((decorated: unknown, context: DecoratorContext): void => {
inject(ignore)(decorated, context);
}, {$isResolver: true, resolve: () => void 0} as const);

@@ -276,5 +273,4 @@ /**

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const isInterface = <K>(key: any): key is InterfaceSymbol<K> => isFunction(key) && key.$isInterface === true;
const isInterface = <K>(key: any): key is InterfaceSymbol<K> => (key as {$isInterface?: boolean})?.$isInterface === true;
let newInstanceContainer: IContainer;

@@ -5,5 +5,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { applyMetadataPolyfill } from '@aurelia/metadata';
import { initializeTC39Metadata } from '@aurelia/metadata';
applyMetadataPolyfill(Reflect, false, false);
initializeTC39Metadata();

@@ -13,4 +13,4 @@ import { isArrayIndex } from './functions';

import { Constructable, IDisposable } from './interfaces';
import { appendAnnotation, getAnnotationKeyFor, ResourceType } from './resource';
import { defineMetadata, getOwnMetadata, isFunction, isString } from './utilities';
import { getAnnotationKeyFor, ResourceType } from './resource';
import { defineMetadata, getMetadata, isFunction, isString } from './utilities';
import { singletonRegistration, cacheCallbackResult, transientRegistation } from './di.registration';

@@ -22,4 +22,10 @@ import { ErrorNames, createMappedError } from './errors';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type InterfaceSymbol<K = any> = (target: Injectable | AbstractInjectable, property: string | symbol | undefined, index?: number) => void;
export interface InterfaceSymbol<K = any> {
// We can activate decorator if the argument decorator proposal will be standardized by TC39 (https://github.com/tc39/proposal-class-method-parameter-decorators)
// (target: Injectable | AbstractInjectable, property: string | symbol | undefined, index?: number): void;
$isInterface: boolean;
friendlyName?: string;
register?(container: IContainer, key?: K): IResolver<K>;
toString?(): string;
}

@@ -31,6 +37,6 @@ // This interface exists only to break a circular type referencing issue in the IServiceLocator interface.

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> {

@@ -40,3 +46,3 @@ dispose(): void;

export interface IRegistration<K = any> {
export interface IRegistration<K = any> extends IResolver<K> {
register(container: IContainer, key?: Key): IResolver<K>;

@@ -80,3 +86,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;

@@ -136,3 +142,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>;
}

@@ -189,18 +195,12 @@ }

const diParamTypesKeys = getAnnotationKeyFor('di:paramtypes');
const getAnnotationParamtypes = (Type: Constructable | Injectable): readonly Key[] | undefined => {
const key = getAnnotationKeyFor('di:paramtypes');
return getOwnMetadata(key, Type);
return getMetadata(diParamTypesKeys, Type);
};
const getDesignParamtypes = (Type: Constructable | Injectable): readonly Key[] | undefined =>
getOwnMetadata('design:paramtypes', Type);
getMetadata('design:paramtypes', Type);
const getOrCreateAnnotationParamTypes = (Type: Constructable | Injectable): Key[] => {
const key = getAnnotationKeyFor('di:paramtypes');
let annotationParamtypes = getOwnMetadata(key, Type);
if (annotationParamtypes === void 0) {
defineMetadata(key, annotationParamtypes = [], Type);
appendAnnotation(Type, key);
}
return annotationParamtypes;
const getOrCreateAnnotationParamTypes = (context: DecoratorContext): Key[] => {
return (context.metadata[diParamTypesKeys] ??= []) as Key[];
};

@@ -215,3 +215,3 @@

const key = getAnnotationKeyFor('di:dependencies');
let dependencies = getOwnMetadata(key, Type) as Key[] | undefined;
let dependencies = getMetadata<Key[] | undefined>(key, Type);
if (dependencies === void 0) {

@@ -276,4 +276,3 @@ // Type.length is the number of constructor parameters. If this is 0, it could mean the class has an empty constructor

defineMetadata(key, dependencies, Type);
appendAnnotation(Type, key);
defineMetadata(dependencies, Type, key);
}

@@ -290,60 +289,53 @@

export const createInterface = <K extends Key>(configureOrName?: string | ((builder: ResolverBuilder<K>) => IResolver<K>), configuror?: (builder: ResolverBuilder<K>) => IResolver<K>): InterfaceSymbol<K> => {
const configure = isFunction(configureOrName) ? configureOrName : configuror;
const friendlyName = (isString(configureOrName) ? configureOrName : undefined) ?? '(anonymous)';
const configure = isFunction(configureOrName) ? configureOrName : configuror;
const friendlyName = (isString(configureOrName) ? configureOrName : undefined) ?? '(anonymous)';
const Interface = function (target: Injectable | AbstractInjectable, property: string | symbol | undefined, index: number | undefined): void {
if (target == null || new.target !== undefined) {
throw createMappedError(ErrorNames.no_registration_for_interface, friendlyName);
}
const annotationParamtypes = getOrCreateAnnotationParamTypes(target as Injectable);
annotationParamtypes[index!] = Interface;
};
Interface.$isInterface = true;
Interface.friendlyName = friendlyName;
if (configure != null) {
Interface.register = (container: IContainer, key?: Key): IResolver<K> =>
configure(new ResolverBuilder(container, key ?? Interface));
}
Interface.toString = (): string => `InterfaceSymbol<${friendlyName}>`;
return Interface;
const Interface = {
// Old code kept with the hope that the argument decorator proposal will be standardized by TC39 (https://github.com/tc39/proposal-class-method-parameter-decorators)
// function(_target: Injectable | AbstractInjectable, _property: string | symbol | undefined, _index: number | undefined): void {
// if (target == null || new.target !== undefined) {
// throw createMappedError(ErrorNames.no_registration_for_interface, friendlyName);
// }
// const annotationParamtypes = getOrCreateAnnotationParamTypes(target as Injectable);
// annotationParamtypes[index!] = Interface;
// },
$isInterface: true,
friendlyName: friendlyName,
toString: (): string => `InterfaceSymbol<${friendlyName}>`,
register: configure != null
? (container: IContainer, key?: Key): IResolver<K> => configure(new ResolverBuilder(container, key ?? Interface))
: void 0,
};
return Interface;
};
export const inject = (...dependencies: Key[]): (target: Injectable, key?: string | number, descriptor?: PropertyDescriptor | number) => void => {
return (target: Injectable, key?: string | number, descriptor?: PropertyDescriptor | number): void => {
if (typeof descriptor === 'number') { // It's a parameter decorator.
const annotationParamtypes = getOrCreateAnnotationParamTypes(target);
const dep = dependencies[0];
if (dep !== void 0) {
annotationParamtypes[descriptor] = dep;
}
} else if (key) { // It's a property decorator. Not supported by the container without plugins.
const annotationParamtypes = getOrCreateAnnotationParamTypes((target as unknown as { constructor: Injectable }).constructor);
const dep = dependencies[0];
if (dep !== void 0) {
annotationParamtypes[key as number] = dep;
}
} else if (descriptor) { // It's a function decorator (not a Class constructor)
const fn = descriptor.value;
const annotationParamtypes = getOrCreateAnnotationParamTypes(fn);
let dep: Key;
let i = 0;
for (; i < dependencies.length; ++i) {
dep = dependencies[i];
if (dep !== void 0) {
annotationParamtypes[i] = dep;
export const inject = (...dependencies: Key[]): (decorated: unknown, context: DecoratorContext) => void => {
return (decorated: unknown, context: DecoratorContext): void => {
switch (context.kind) {
case 'class': {
const annotationParamtypes = getOrCreateAnnotationParamTypes(context);
let dep: Key;
let i = 0;
for (; i < dependencies.length; ++i) {
dep = dependencies[i];
if (dep !== void 0) {
annotationParamtypes[i] = dep;
}
}
break;
}
} else { // It's a class decorator.
const annotationParamtypes = getOrCreateAnnotationParamTypes(target);
let dep: Key;
let i = 0;
for (; i < dependencies.length; ++i) {
dep = dependencies[i];
case 'field': {
const annotationParamtypes: any = getOrCreateAnnotationParamTypes(context);
const dep = dependencies[0];
if (dep !== void 0) {
annotationParamtypes[i] = dep;
annotationParamtypes[context.name] = dep;
}
break;
}
// TODO(sayan): support getter injection - new feature
// TODO:
// support method parameter injection when the class-method-parameter-decorators proposal (https://github.com/tc39/proposal-class-method-parameter-decorators)
// reaches stage 4 and/or implemented by TS.
default:
throw createMappedError(ErrorNames.invalid_inject_decorator_usage, String(context.name), context.kind);
}

@@ -356,4 +348,4 @@ };

getDesignParamtypes,
getAnnotationParamtypes,
getOrCreateAnnotationParamTypes,
// getAnnotationParamtypes,
// getOrCreateAnnotationParamTypes,
getDependencies: getDependencies,

@@ -460,3 +452,3 @@ /**

function transientDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>):
function transientDecorator<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext):
T & RegisterSelf<T> {

@@ -487,5 +479,5 @@ return DI.transient(target);

*/
export function transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
export function transient<T extends Constructable>(target?: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T> | typeof transientDecorator {
return target == null ? transientDecorator : transientDecorator(target);
export function transient<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext): T & RegisterSelf<T>;
export function transient<T extends Constructable>(target?: T & Partial<RegisterSelf<T>>, context?: ClassDecoratorContext): T & RegisterSelf<T> | typeof transientDecorator {
return target == null ? transientDecorator : transientDecorator(target, context!);
}

@@ -497,5 +489,3 @@

const singletonDecorator = <T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T> => {
return decorateSingleton(target);
};
type SingletonDecorator = <T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext) => T & RegisterSelf<T>;
/**

@@ -511,5 +501,5 @@ * Registers the decorated class as a singleton dependency; the class will only be created once. Each

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function singleton<T extends Constructable>(): typeof singletonDecorator;
export function singleton<T extends Constructable>(): SingletonDecorator;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function singleton<T extends Constructable>(options?: SingletonOptions): typeof singletonDecorator;
export function singleton<T extends Constructable>(options?: SingletonOptions): SingletonDecorator;
/**

@@ -526,10 +516,10 @@ * Registers the `target` class as a singleton dependency; the class will only be created once. Each

*/
export function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>): T & RegisterSelf<T>;
export function singleton<T extends Constructable>(targetOrOptions?: (T & Partial<RegisterSelf<T>>) | SingletonOptions): T & RegisterSelf<T> | typeof singletonDecorator {
if (isFunction(targetOrOptions)) {
return decorateSingleton(targetOrOptions);
}
return function <T extends Constructable>($target: T) {
return decorateSingleton($target, targetOrOptions);
};
export function singleton<T extends Constructable>(target: T & Partial<RegisterSelf<T>>, context: ClassDecoratorContext): T & RegisterSelf<T>;
export function singleton<T extends Constructable>(targetOrOptions?: (T & Partial<RegisterSelf<T>>) | SingletonOptions, _context?: ClassDecoratorContext): T & RegisterSelf<T> | SingletonDecorator {
return isFunction(targetOrOptions)
// The decorator is applied without options. Example: `@singleton()` or `@singleton`
? decorateSingleton(targetOrOptions)
: function <T extends Constructable>($target: T, _ctx: ClassDecoratorContext) {
return decorateSingleton($target, targetOrOptions);
};
}

@@ -550,3 +540,3 @@

/** @internal */
export class Resolver implements IResolver, IRegistration {
export class Resolver<K extends Key = any> implements IResolver<K> {
/** @internal */

@@ -565,3 +555,3 @@ public _key: Key;

public constructor(
key: Key,
key: K,
strategy: ResolverStrategy,

@@ -583,3 +573,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>);
}

@@ -610,3 +600,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:

@@ -621,11 +611,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:

@@ -648,3 +638,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;

@@ -678,3 +668,3 @@ /** @internal */ private readonly _name?: string;

public resolve(): Resolved<K> | null {
public resolve(): Resolved<K> {
if (this._instance == null) {

@@ -686,4 +676,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;
}

@@ -690,0 +680,0 @@

@@ -34,2 +34,4 @@ /* eslint-disable prefer-template */

invalid_module_transform_input = 21,
invalid_inject_decorator_usage = 22,
resource_key_already_registered = 23,
}

@@ -63,2 +65,4 @@ _END_CONST_ENUM();

// [ErrorNames.module_loader_received_null]: `Module loader received null/undefined input. Expected Object.`,
[ErrorNames.invalid_inject_decorator_usage]: `The @inject decorator on the target ('{{0}}') type '{{1}}' is not supported.`,
[ErrorNames.resource_key_already_registered]: `Resource key '{{0}}' has already been registered.`,
};

@@ -65,0 +69,0 @@

@@ -242,18 +242,18 @@ import { ErrorNames, createMappedError } from './errors';

*/
// eslint-disable-next-line @typescript-eslint/ban-types
export const bound = <T extends Function>(target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> => {
return {
configurable: true,
enumerable: descriptor.enumerable,
get(): T {
const boundFn = descriptor.value!.bind(this) as TypedPropertyDescriptor<T>;
Reflect.defineProperty(this, key, {
value: boundFn,
writable: true,
configurable: true,
enumerable: descriptor.enumerable,
});
return boundFn as T;
},
};
export const bound = <
TThis extends object,
TArgs extends unknown[],
TReturn>(
originalMethod: (this: TThis, ...args: TArgs) => TReturn,
context: ClassMethodDecoratorContext<TThis, (this: TThis, ...args: TArgs) => TReturn>,
): void => {
const methodName = context.name as string;
context.addInitializer(function (this: TThis) {
Reflect.defineProperty(this, methodName, {
value: originalMethod.bind(this),
writable: true,
configurable: true,
enumerable: false,
});
});
};

@@ -260,0 +260,0 @@

@@ -38,2 +38,3 @@ export {

Registration,
createImplementationRegister,
} from './di.registration';

@@ -40,0 +41,0 @@

@@ -1,2 +0,1 @@

import { Metadata } from '@aurelia/metadata';
import { createInterface, IContainer, IRegistry } from './di';

@@ -8,3 +7,3 @@ import { instanceRegistration, singletonRegistration } from './di.registration';

import { getAnnotationKeyFor } from './resource';
import { createObject, defineMetadata, isFunction, objectFreeze } from './utilities';
import { createObject, defineMetadata, getMetadata, isFunction, objectFreeze } from './utilities';
import { resolve } from './di.container';

@@ -180,8 +179,7 @@ import { all, optional } from './di.resolvers';

key: getAnnotationKeyFor('logger-sink-handles'),
define<TSink extends ISink>(target: Constructable<TSink>, definition: SinkDefinition) {
defineMetadata(this.key, definition.handles, target.prototype);
return target;
define<TSink extends Constructable<ISink>>(target: TSink, definition: SinkDefinition) {
defineMetadata(definition.handles, target, this.key);
},
getHandles<TSink extends ISink>(target: Constructable<TSink> | TSink) {
return Metadata.get(this.key, target) as LogLevel[] | undefined;
getHandles<TSink extends ISink>(target: TSink): Exclude<LogLevel, typeof none>[] | undefined {
return getMetadata(this.key, target.constructor);
},

@@ -191,4 +189,6 @@ });

export const sink = (definition: SinkDefinition) => {
return <TSink extends ISink>(target: Constructable<TSink>): Constructable<TSink> =>
LoggerSink.define(target, definition);
return <TSink extends Constructable<ISink>>(_target: TSink, context: ClassDecoratorContext<TSink>): void =>
context.addInitializer(function (this) {
LoggerSink.define(this, definition);
});
};

@@ -195,0 +195,0 @@

import { createInterface } from './di';
import { resourceBaseName } from './resource';
import { getOwnMetadata, isFunction } from './utilities';
import { getMetadata, isFunction } from './utilities';
import { ErrorNames, createMappedError } from './errors';

@@ -100,3 +100,3 @@

isConstructable = (value as Constructable).prototype !== void 0;
definition = getOwnMetadata(resourceBaseName, value) ?? null;
definition = getMetadata(resourceBaseName, value) ?? null;
break;

@@ -103,0 +103,0 @@ default:

import { IContainer } from './di';
import { Constructable } from './interfaces';
import { defineMetadata, getOwnMetadata, objectFreeze } from './utilities';
import { defineMetadata, getMetadata, objectFreeze } from './utilities';

@@ -68,5 +68,5 @@ export type StaticResourceType<TDef extends object = object> = {

export const appendAnnotation = (target: Constructable, key: string): void => {
const keys = getOwnMetadata(annoBaseName, target) as string[];
const keys = getMetadata<string[]>(annoBaseName, target);
if (keys === void 0) {
defineMetadata(annoBaseName, [key], target);
defineMetadata([key], target, annoBaseName);
} else {

@@ -81,9 +81,9 @@ keys.push(key);

set(target: Constructable, prop: string, value: unknown): void {
defineMetadata(getAnnotationKeyFor(prop), value, target);
defineMetadata(value, target, getAnnotationKeyFor(prop));
},
get: (target: Constructable, prop: string): unknown => getOwnMetadata(getAnnotationKeyFor(prop), target),
get: (target: Constructable, prop: string): unknown => getMetadata(getAnnotationKeyFor(prop), target),
getKeys(target: Constructable): readonly string[] {
let keys = getOwnMetadata(annoBaseName, target) as string[];
let keys = getMetadata<string[]>(annoBaseName, target);
if (keys === void 0) {
defineMetadata(annoBaseName, keys = [], target);
defineMetadata(keys = [], target, annoBaseName);
}

@@ -133,3 +133,3 @@ return keys;

): Required<TDef>[K] {
let value = getOwnMetadata(getAnnotationKeyFor(name as string), Type) as TDef[K] | undefined;
let value = getMetadata<TDef[K] | undefined>(getAnnotationKeyFor(name as string), Type);
if (value === void 0) {

@@ -160,3 +160,3 @@ value = def[name];

): V {
let value = getOwnMetadata(getAnnotationKeyFor(name as string), Type) as V;
let value = getMetadata<V>(getAnnotationKeyFor(name as string), Type);
if (value === void 0) {

@@ -163,0 +163,0 @@ value = Type[name] as unknown as V;

@@ -6,4 +6,4 @@ import { Metadata } from '@aurelia/metadata';

/** @internal */ export const safeString = String;
/** @internal */ export const getOwnMetadata = Metadata.getOwn;
/** @internal */ export const hasOwnMetadata = Metadata.hasOwn;
/** @internal */ export const getMetadata = Metadata.get;
/** @internal */ export const hasMetadata = Metadata.has;
/** @internal */ export const defineMetadata = Metadata.define;

@@ -10,0 +10,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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc