Comparing version 3.3.2 to 3.4.0-alpha-0.1
@@ -1,6 +0,6 @@ | ||
import { Constructor, Container, RegistrationType, AbstractConstructor, ImplementationType, ImplementationTypeWithInjection } from './types'; | ||
declare class ContainerImpl<RegisterTypeExtension = {}, RegisterInstanceExtension = {}> implements Container<RegisterTypeExtension, RegisterInstanceExtension> { | ||
protected singletons: Map<ImplementationTypeWithInjection<any>, Object>; | ||
protected instances: Map<RegistrationType<any>, any>; | ||
protected dependencies: Map<RegistrationType<any>, ImplementationTypeWithInjection<any> | Object>; | ||
import { Constructor, Container, RegistrationType, AbstractConstructor, ImplementationType, ImplementationTypeWithInjection, IHaveSingletons, IHaveInstances, IHaveDependencies } from './types'; | ||
declare class ContainerImpl<RegisterTypeExtension = {}, RegisterInstanceExtension = {}> implements Container<RegisterTypeExtension, RegisterInstanceExtension>, IHaveSingletons, IHaveInstances, IHaveDependencies { | ||
singletons: Map<ImplementationTypeWithInjection<any>, Object>; | ||
instances: Map<RegistrationType<any>, any>; | ||
dependencies: Map<RegistrationType<any>, ImplementationTypeWithInjection<any> | Object>; | ||
constructor(); | ||
@@ -22,3 +22,3 @@ /** register class */ | ||
} & RegisterTypeExtension; | ||
/** register any object as it constructor */ | ||
/** register any object as its constructor */ | ||
registerInstance<TInstance extends Object>(instance: TInstance): { | ||
@@ -33,9 +33,9 @@ /** or register the object as any class */ | ||
private internalResolve; | ||
protected getInstance<TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>): ImplementationTypeWithInjection<TInstance> | Object | undefined; | ||
protected getImplementation<TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>): ImplementationTypeWithInjection<TInstance> | Object | undefined; | ||
protected getSingletons(): Map<ImplementationTypeWithInjection<any>, Object>; | ||
getInstance<TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>): ImplementationTypeWithInjection<TInstance> | Object | undefined; | ||
getImplementation<TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>): ImplementationTypeWithInjection<TInstance> | Object | undefined; | ||
getSingletons(): Map<ImplementationTypeWithInjection<any>, Object>; | ||
private isRegisteredInstance; | ||
private isRegisteredType; | ||
} | ||
declare const container: Container; | ||
declare const container: ContainerImpl<{}, {}>; | ||
export { ContainerImpl, container, }; |
@@ -50,3 +50,3 @@ "use strict"; | ||
} | ||
/** register any object as it constructor */ | ||
/** register any object as its constructor */ | ||
registerInstance(instance) { | ||
@@ -113,3 +113,7 @@ const constructor = instance.constructor; | ||
let injectionParamsIndex = 0; | ||
const dependencies = (0, decorators_1.getDependencies)(implementation); | ||
let dependencies = (0, decorators_1.getDependencies)(implementation); | ||
if (!dependencies.length) { | ||
(0, decorators_1.di)(implementation); | ||
dependencies = (0, decorators_1.getDependencies)(implementation); | ||
} | ||
if (dependencies.length) { | ||
@@ -116,0 +120,0 @@ let has = true; |
import { Constructor, Dependency } from '../types'; | ||
declare type D<T> = Dependency<T>; | ||
declare type Return<TClass> = TClass extends new (...args: any[]) => infer TInstance ? (constructor: TClass) => TInstance : never; | ||
type D<T> = Dependency<T>; | ||
type Return<TClass> = TClass extends new (...args: any[]) => infer TInstance ? (constructor: TClass) => TInstance : never; | ||
declare function dependencies<A1, TClass extends new (a1: A1, ...args: any[]) => any>(a1: D<A1>): Return<TClass>; | ||
@@ -5,0 +5,0 @@ declare function dependencies<A1, A2, TClass extends new (a1: A1, a2: A2, ...args: any[]) => any>(a1: D<A1>, a2: D<A2>): Return<TClass>; |
import { singletonSymbol, dependenciesSymbol, injectionSymbol, inheritancePreserveSymbol } from './symbols'; | ||
declare type AbstractConstructor<T = any> = abstract new (...args: any[]) => T; | ||
declare type Constructor<T = any> = new (...args: any[]) => T; | ||
declare type Dependency<T = any> = (Constructor<T> | AbstractConstructor<T>); | ||
declare type ImplementationType<TClass> = Constructor<TClass> & { | ||
type AbstractConstructor<T = any> = abstract new (...args: any[]) => T; | ||
type Constructor<T = any> = new (...args: any[]) => T; | ||
type Dependency<T = any> = (Constructor<T> | AbstractConstructor<T>); | ||
type ImplementationType<TClass> = Constructor<TClass> & { | ||
[singletonSymbol]?: boolean; | ||
@@ -10,6 +10,6 @@ [dependenciesSymbol]?: Dependency[]; | ||
}; | ||
declare type ImplementationTypeWithInjection<TInstance> = ImplementationType<TInstance> & { | ||
type ImplementationTypeWithInjection<TInstance> = ImplementationType<TInstance> & { | ||
[injectionSymbol]?: any[]; | ||
}; | ||
declare type RegistrationType<TInstance> = Constructor<TInstance> | AbstractConstructor<TInstance>; | ||
type RegistrationType<TInstance> = Constructor<TInstance> | AbstractConstructor<TInstance>; | ||
interface WithInjectionParams { | ||
@@ -33,3 +33,3 @@ /** add parameters that will be passed to the class constructor */ | ||
} | ||
declare type Resolver = <TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>, ...args: any[]) => TInstance | undefined; | ||
type Resolver = <TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>, ...args: any[]) => TInstance | undefined; | ||
interface DependencyResolver { | ||
@@ -43,2 +43,11 @@ /** instantiate (or get instance for singleton) by class */ | ||
} | ||
export type { AbstractConstructor, Constructor, Container, Dependency, DependencyRegistrator, DependencyResolver, ImplementationType, ImplementationTypeWithInjection, RegistrationType, WithInjectionParams, }; | ||
interface IHaveSingletons { | ||
singletons: Map<ImplementationTypeWithInjection<any>, Object>; | ||
} | ||
interface IHaveInstances { | ||
instances: Map<RegistrationType<any>, any>; | ||
} | ||
interface IHaveDependencies { | ||
dependencies: Map<RegistrationType<any>, ImplementationTypeWithInjection<any> | Object>; | ||
} | ||
export type { AbstractConstructor, Constructor, Container, Dependency, DependencyRegistrator, DependencyResolver, ImplementationType, ImplementationTypeWithInjection, RegistrationType, WithInjectionParams, IHaveSingletons, IHaveInstances, IHaveDependencies, }; |
{ | ||
"name": "cheap-di", | ||
"version": "3.3.2", | ||
"version": "3.4.0-alpha-0.1", | ||
"description": "JavaScript dependency injection like Autofac in .Net", | ||
@@ -13,7 +13,7 @@ "scripts": { | ||
"devDependencies": { | ||
"@types/jest": "28.1.1", | ||
"jest": "28.1.1", | ||
"ts-jest": "28.0.5", | ||
"tslib": "2.4.0", | ||
"typescript": "4.7.3" | ||
"@types/jest": "29.2.5", | ||
"jest": "29.3.1", | ||
"ts-jest": "29.0.3", | ||
"tslib": "2.4.1", | ||
"typescript": "4.9.4" | ||
}, | ||
@@ -40,3 +40,3 @@ "files": [ | ||
], | ||
"packageManager": "yarn@3.2.1" | ||
"packageManager": "yarn@3.5.0" | ||
} |
@@ -5,4 +5,4 @@ # cheap-di | ||
* [Minimal Sample](#minimal-sample) | ||
* [How to use](#how-to-use) | ||
* [Minimal Sample (TypeScript)](#minimal-sample) | ||
* [How to use (JavaScript)](#how-to-use) | ||
* [TypeScript](#type-script) | ||
@@ -15,3 +15,3 @@ * [Decorators](#decorators) | ||
## <a name="minimal-sample"></a> Minimal Sample | ||
## <a name="minimal-sample"></a> Minimal Sample (TypeScript) | ||
@@ -56,3 +56,3 @@ ```ts | ||
## <a name="how-to-use"></a> How to use | ||
## <a name="how-to-use"></a> How to use (JavaScript) | ||
@@ -59,0 +59,0 @@ You have an interface (base/abstract class) and its implementation (derived class) |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
72799
560
1
1