knifecycle
Advanced tools
Comparing version 11.0.0-beta.3 to 11.0.0-beta.4
@@ -1,2 +0,2 @@ | ||
# [11.0.0-beta.3](https://github.com/nfroidure/knifecycle/compare/v10.0.3...v11.0.0-beta.3) (2020-11-21) | ||
# [11.0.0-beta.4](https://github.com/nfroidure/knifecycle/compare/v10.0.3...v11.0.0-beta.4) (2020-11-21) | ||
@@ -3,0 +3,0 @@ |
@@ -25,4 +25,11 @@ import { SPECIAL_PROPS, SPECIAL_PROPS_PREFIX, DECLARATION_SEPARATOR, OPTIONAL_FLAG, ALLOWED_INITIALIZER_TYPES, ALLOWED_SPECIAL_PROPS, parseInjections, readFunctionName, reuseSpecialProps, parseName, name, autoName, inject, useInject, mergeInject, autoInject, alsoInject, type, extra, singleton, initializer, constant, service, autoService, provider, autoProvider, wrapInitializer, handler, autoHandler, parseDependencyDeclaration, stringifyDependencyDeclaration } from './util'; | ||
}; | ||
export declare type InternalService<S> = S | FatalErrorService | Disposer | Knifecycle<S> | Injector<InternalService<S>> | Autoloader<InternalService<S>> | SiloContext<InternalService<S>>; | ||
declare class Knifecycle<S extends Service, AS extends InternalService<S> = InternalService<S>> { | ||
export declare type InternalDependencies<D extends Dependencies> = { | ||
$dispose: Disposer; | ||
$autoload: Autoloader<D[string]>; | ||
$injector: Injector<D>; | ||
$instance: Knifecycle<D>; | ||
$siloContext: SiloContext<D[string]>; | ||
$fatalError: FatalErrorService; | ||
} & D; | ||
declare class Knifecycle<D extends Dependencies, AD extends InternalDependencies<D> = InternalDependencies<D>, AS extends Service = AD[string]> { | ||
private _silosCounter; | ||
@@ -54,3 +61,3 @@ private _silosContexts; | ||
*/ | ||
register<D extends Dependencies = Dependencies<AS>>(initializer: Initializer<AS, D>): Knifecycle<S>; | ||
register(initializer: Initializer<AS, AD>): Knifecycle<D, AD, AS>; | ||
_lookupCircularDependencies(rootServiceName: ServiceName, dependencyDeclaration: DependencyDeclaration, declarationsStacks?: DependencyDeclaration[]): void; | ||
@@ -118,3 +125,3 @@ /** | ||
*/ | ||
run(dependenciesDeclarations: DependencyDeclaration[]): Promise<Dependencies<AS>>; | ||
run<D = Partial<AD>>(dependenciesDeclarations: DependencyDeclaration[]): Promise<D>; | ||
/** | ||
@@ -121,0 +128,0 @@ * Destroy the Knifecycle instance |
{ | ||
"name": "knifecycle", | ||
"version": "11.0.0-beta.3", | ||
"version": "11.0.0-beta.4", | ||
"description": "Manage your NodeJS processes's lifecycle automatically with an unobtrusive dependency injection implementation.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
@@ -60,3 +60,6 @@ import assert from 'assert'; | ||
it('should build an initialization module', async () => { | ||
const $ = new Knifecycle<BuildInitializer | string>(); | ||
const $ = new Knifecycle<{ | ||
buildInitializer: BuildInitializer; | ||
PWD: string; | ||
}>(); | ||
@@ -67,5 +70,3 @@ $.register(constant('PWD', '~/my-project')); | ||
const { buildInitializer } = (await $.run(['buildInitializer'])) as { | ||
buildInitializer: BuildInitializer; | ||
}; | ||
const { buildInitializer } = await $.run(['buildInitializer']); | ||
@@ -72,0 +73,0 @@ const content = await buildInitializer(['dep1', 'finalMappedDep>dep3']); |
@@ -119,11 +119,12 @@ /* eslint max-len: ["warn", { "ignoreComments": true }] @typescript-eslint/no-this-alias: "warn" */ | ||
}; | ||
export type InternalService<S> = | ||
| S | ||
| FatalErrorService | ||
| Disposer | ||
| Knifecycle<S> | ||
| Injector<InternalService<S>> | ||
| Autoloader<InternalService<S>> | ||
| SiloContext<InternalService<S>>; | ||
export type InternalDependencies<D extends Dependencies> = { | ||
$dispose: Disposer; | ||
$autoload: Autoloader<D[string]>; | ||
$injector: Injector<D>; | ||
$instance: Knifecycle<D>; | ||
$siloContext: SiloContext<D[string]>; | ||
$fatalError: FatalErrorService; | ||
} & D; | ||
const debug = initDebug('knifecycle'); | ||
@@ -184,11 +185,12 @@ | ||
class Knifecycle< | ||
S extends Service, | ||
AS extends InternalService<S> = InternalService<S> | ||
D extends Dependencies, | ||
AD extends InternalDependencies<D> = InternalDependencies<D>, | ||
AS extends Service = AD[string] | ||
> { | ||
private _silosCounter: number; | ||
private _silosContexts: Set<SiloContext<AS>>; | ||
private _initializers: Map<string, ProviderInitializer<Dependencies<AS>, AS>>; | ||
private _silosContexts: Set<AD['$siloContext']>; | ||
private _initializers: Map<string, ProviderInitializer<AD, AS>>; | ||
private _initializerResolvers: Map< | ||
string, | ||
Promise<ProviderInitializer<Dependencies<AS>, AS>> | ||
Promise<ProviderInitializer<AD, AS>> | ||
>; | ||
@@ -254,3 +256,3 @@ private _singletonsServicesHandles: Map<string, Set<string>>; | ||
this.register(initInjectorProvider); | ||
this.register(initInjectorProvider as ProviderInitializer<AD, AS>); | ||
} | ||
@@ -290,5 +292,3 @@ | ||
*/ | ||
register<D extends Dependencies = Dependencies<AS>>( | ||
initializer: Initializer<AS, D>, | ||
): Knifecycle<S> { | ||
register(initializer: Initializer<AS, AD>): Knifecycle<D, AD, AS> { | ||
if (this.shutdownPromise) { | ||
@@ -358,5 +358,5 @@ throw new YError(E_INSTANCE_DESTROYED); | ||
initializer = reuseSpecialProps( | ||
initializer as ServiceInitializer<AS, D>, | ||
initializer as ServiceInitializer<Dependencies<AS>, AS>, | ||
serviceAdapter.bind(null, initializer[SPECIAL_PROPS.NAME], initializer), | ||
) as Initializer<AS, D>; | ||
) as Initializer<AS, Dependencies<AS>>; | ||
initializer[SPECIAL_PROPS.TYPE] = 'provider'; | ||
@@ -600,5 +600,5 @@ } | ||
*/ | ||
async run( | ||
async run<D = Partial<AD>>( | ||
dependenciesDeclarations: DependencyDeclaration[], | ||
): Promise<Dependencies<AS>> { | ||
): Promise<D> { | ||
const _this = this; | ||
@@ -655,3 +655,3 @@ const internalDependencies = [ | ||
this._silosContexts.delete(siloContext); | ||
this._silosContexts.delete(siloContext as AD['$siloContext']); | ||
@@ -730,3 +730,3 @@ // Shutdown services in their instanciation order | ||
this._silosContexts.add(siloContext); | ||
this._silosContexts.add(siloContext as AD['$siloContext']); | ||
@@ -733,0 +733,0 @@ const servicesHash = await this._initializeDependencies( |
@@ -529,4 +529,4 @@ /* eslint @typescript-eslint/ban-types:0 */ | ||
wrapper: ProviderInitializerWrapper<S, D> | ServiceInitializerWrapper<S, D>, | ||
baseInitializer: ServiceInitializer<D, S> | ProviderInitializer<D, S>, | ||
): ServiceInitializer<D, S> | ProviderInitializer<D, S> { | ||
baseInitializer: ProviderInitializer<D, S> | ServiceInitializer<D, S>, | ||
): ProviderInitializer<D, S> | ServiceInitializer<D, S> { | ||
return reuseSpecialProps(baseInitializer, async (services: D) => { | ||
@@ -533,0 +533,0 @@ const baseInstance = await baseInitializer(services); |
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
1161032
12778
102
2
2
4