@deepkit/injector
Advanced tools
Comparing version 1.0.1-alpha.122 to 1.0.1-alpha.123
@@ -6,2 +6,8 @@ # Change Log | ||
## [1.0.1-alpha.123](https://github.com/deepkit/deepkit-framework/compare/v1.0.1-alpha.122...v1.0.1-alpha.123) (2024-02-02) | ||
### Bug Fixes | ||
- **injector:** resolve deps of exported providers correctly ([c185b38](https://github.com/deepkit/deepkit-framework/commit/c185b383c3314f08c92b65c76776864a2065a2b8)) | ||
## [1.0.1-alpha.122](https://github.com/deepkit/deepkit-framework/compare/v1.0.1-alpha.121...v1.0.1-alpha.122) (2024-01-31) | ||
@@ -8,0 +14,0 @@ |
import { NormalizedProvider, ProviderWithScope, TagProvider, TagRegistry, Token } from './provider.js'; | ||
import { AbstractClassType, ClassType, CompilerContext, CustomError } from '@deepkit/core'; | ||
import { InjectorModule, ConfigurationProviderRegistry } from './module.js'; | ||
import { ConfigurationProviderRegistry, InjectorModule } from './module.js'; | ||
import { ReceiveType, Type } from '@deepkit/type'; | ||
@@ -5,0 +5,0 @@ export declare class InjectorError extends CustomError { |
@@ -349,3 +349,2 @@ "use strict"; | ||
buildProvider(buildContext, compiler, name, accessor, scope, token, provider, resolveDependenciesFrom) { | ||
var _a; | ||
let transient = false; | ||
@@ -385,3 +384,3 @@ let factory = { code: '', dependencies: 0 }; | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'factoryDependencyNotFound')); | ||
@@ -395,3 +394,6 @@ } | ||
const configureProvider = []; | ||
const configurations = (_a = resolveDependenciesFrom[0].configurationProviderRegistry) === null || _a === void 0 ? void 0 : _a.get(token); | ||
const configurations = []; | ||
for (const module of resolveDependenciesFrom) { | ||
configurations.push(...module.configurationProviderRegistry.get(token)); | ||
} | ||
configurations.push(...buildContext.globalConfigurationProviderRegistry.get(token)); | ||
@@ -411,3 +413,3 @@ if (configurations === null || configurations === void 0 ? void 0 : configurations.length) { | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'functionParameterNotFound')); | ||
@@ -464,3 +466,3 @@ } | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, (0, core_1.getClassName)(classType), args.length, 'constructorParameterNotFound')); | ||
@@ -478,3 +480,3 @@ } | ||
type: tokenType, | ||
optional: !property.isValueRequired() | ||
optional: !property.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, (0, core_1.getClassName)(classType), -1, 'propertyParameterNotFound'); | ||
@@ -489,3 +491,3 @@ propertyAssignment.push(`${resolvedName}.${String(property.getName())} = ${resolveProperty};`); | ||
code: `${resolvedName} = new ${classTypeVar}(${args.join(',')});\n${propertyAssignment.join('\n')}`, | ||
dependencies | ||
dependencies, | ||
}; | ||
@@ -516,4 +518,8 @@ } | ||
} | ||
if (options.type.kind === type_1.ReflectionKind.class && resolveDependenciesFrom[0] instanceof options.type.classType) { | ||
return compiler.reserveConst(resolveDependenciesFrom[0], 'module'); | ||
if (options.type.kind === type_1.ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof options.type.classType) { | ||
return compiler.reserveConst(module, 'module'); | ||
} | ||
} | ||
} | ||
@@ -655,4 +661,7 @@ if (options.type.kind === type_1.ReflectionKind.class && (0, core_1.isPrototypeOfBase)(options.type.classType, provider_js_1.Tag)) { | ||
return () => this.buildContext.tagRegistry; | ||
if (type.kind === type_1.ReflectionKind.class && resolveDependenciesFrom[0] instanceof type.classType) { | ||
return () => resolveDependenciesFrom[0]; | ||
if (type.kind === type_1.ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof type.classType) | ||
return () => module; | ||
} | ||
} | ||
@@ -659,0 +668,0 @@ if (type.kind === type_1.ReflectionKind.class && (0, core_1.isPrototypeOfBase)(type.classType, provider_js_1.Tag)) { |
@@ -546,3 +546,5 @@ "use strict"; | ||
else { | ||
parentProviders.push({ token: preparedProvider.token, modules: [this], providers: preparedProvider.providers.slice() }); | ||
// [this, to] is used so that this service resolves dependencies from the target first (so it can overwrite them) | ||
// and falls back to the module it was defined in. This includes configureProvider() calls. | ||
parentProviders.push({ token: preparedProvider.token, modules: [to, this], providers: preparedProvider.providers.slice() }); | ||
} | ||
@@ -549,0 +551,0 @@ }; |
import { NormalizedProvider, ProviderWithScope, TagProvider, TagRegistry, Token } from './provider.js'; | ||
import { AbstractClassType, ClassType, CompilerContext, CustomError } from '@deepkit/core'; | ||
import { InjectorModule, ConfigurationProviderRegistry } from './module.js'; | ||
import { ConfigurationProviderRegistry, InjectorModule } from './module.js'; | ||
import { ReceiveType, Type } from '@deepkit/type'; | ||
@@ -5,0 +5,0 @@ export declare class InjectorError extends CustomError { |
@@ -16,3 +16,3 @@ const __ΩReturnType = ['T', 'args', '', 'ReturnType', 'l>e"!R"RPde#!P"@2"h"!/#qk#\'QRb!Pde"!p)w$y']; | ||
import { CompilerContext, CustomError, getClassName, getPathValue, isArray, isClass, isFunction, isPrototypeOfBase } from '@deepkit/core'; | ||
import { findModuleForConfig, getScope, InjectorModule, ConfigurationProviderRegistry } from './module.js'; | ||
import { ConfigurationProviderRegistry, findModuleForConfig, getScope, InjectorModule } from './module.js'; | ||
import { isOptional, isType, isWithAnnotations, metaAnnotation, reflect, ReflectionClass, ReflectionFunction, ReflectionKind, resolveReceiveType, stringifyType, } from '@deepkit/type'; | ||
@@ -338,3 +338,2 @@ export class InjectorError extends CustomError { | ||
buildProvider(buildContext, compiler, name, accessor, scope, token, provider, resolveDependenciesFrom) { | ||
var _a; | ||
let transient = false; | ||
@@ -374,3 +373,3 @@ let factory = { code: '', dependencies: 0 }; | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'factoryDependencyNotFound')); | ||
@@ -384,3 +383,6 @@ } | ||
const configureProvider = []; | ||
const configurations = (_a = resolveDependenciesFrom[0].configurationProviderRegistry) === null || _a === void 0 ? void 0 : _a.get(token); | ||
const configurations = []; | ||
for (const module of resolveDependenciesFrom) { | ||
configurations.push(...module.configurationProviderRegistry.get(token)); | ||
} | ||
configurations.push(...buildContext.globalConfigurationProviderRegistry.get(token)); | ||
@@ -400,3 +402,3 @@ if (configurations === null || configurations === void 0 ? void 0 : configurations.length) { | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'functionParameterNotFound')); | ||
@@ -453,3 +455,3 @@ } | ||
type: tokenType || parameter.getType(), | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, getClassName(classType), args.length, 'constructorParameterNotFound')); | ||
@@ -467,3 +469,3 @@ } | ||
type: tokenType, | ||
optional: !property.isValueRequired() | ||
optional: !property.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, getClassName(classType), -1, 'propertyParameterNotFound'); | ||
@@ -478,3 +480,3 @@ propertyAssignment.push(`${resolvedName}.${String(property.getName())} = ${resolveProperty};`); | ||
code: `${resolvedName} = new ${classTypeVar}(${args.join(',')});\n${propertyAssignment.join('\n')}`, | ||
dependencies | ||
dependencies, | ||
}; | ||
@@ -505,4 +507,8 @@ } | ||
} | ||
if (options.type.kind === ReflectionKind.class && resolveDependenciesFrom[0] instanceof options.type.classType) { | ||
return compiler.reserveConst(resolveDependenciesFrom[0], 'module'); | ||
if (options.type.kind === ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof options.type.classType) { | ||
return compiler.reserveConst(module, 'module'); | ||
} | ||
} | ||
} | ||
@@ -644,4 +650,7 @@ if (options.type.kind === ReflectionKind.class && isPrototypeOfBase(options.type.classType, Tag)) { | ||
return () => this.buildContext.tagRegistry; | ||
if (type.kind === ReflectionKind.class && resolveDependenciesFrom[0] instanceof type.classType) { | ||
return () => resolveDependenciesFrom[0]; | ||
if (type.kind === ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof type.classType) | ||
return () => module; | ||
} | ||
} | ||
@@ -648,0 +657,0 @@ if (type.kind === ReflectionKind.class && isPrototypeOfBase(type.classType, Tag)) { |
@@ -539,3 +539,5 @@ /*@ts-ignore*/ | ||
else { | ||
parentProviders.push({ token: preparedProvider.token, modules: [this], providers: preparedProvider.providers.slice() }); | ||
// [this, to] is used so that this service resolves dependencies from the target first (so it can overwrite them) | ||
// and falls back to the module it was defined in. This includes configureProvider() calls. | ||
parentProviders.push({ token: preparedProvider.token, modules: [to, this], providers: preparedProvider.providers.slice() }); | ||
} | ||
@@ -542,0 +544,0 @@ }; |
{ | ||
"name": "@deepkit/injector", | ||
"version": "1.0.1-alpha.122", | ||
"version": "1.0.1-alpha.123", | ||
"description": "Deepkit Dependency Injection", | ||
@@ -30,4 +30,4 @@ "type": "commonjs", | ||
"devDependencies": { | ||
"@deepkit/core": "^1.0.1-alpha.121", | ||
"@deepkit/type": "^1.0.1-alpha.121", | ||
"@deepkit/core": "^1.0.1-alpha.123", | ||
"@deepkit/type": "^1.0.1-alpha.123", | ||
"benchmark": "^2.1.4" | ||
@@ -52,3 +52,3 @@ }, | ||
}, | ||
"gitHead": "a7d2818b9a8ac097ca8e9c17c34f69acbd5488df" | ||
"gitHead": "49731fdb4786e50a54c4c6639374851ee9389a3a" | ||
} |
@@ -14,5 +14,4 @@ import { | ||
import { AbstractClassType, ClassType, CompilerContext, CustomError, getClassName, getPathValue, isArray, isClass, isFunction, isPrototypeOfBase } from '@deepkit/core'; | ||
import { findModuleForConfig, getScope, InjectorModule, PreparedProvider, ConfigurationProviderRegistry } from './module.js'; | ||
import { ConfigurationProviderRegistry, ConfigureProviderEntry, findModuleForConfig, getScope, InjectorModule, PreparedProvider } from './module.js'; | ||
import { | ||
isExtendable, | ||
isOptional, | ||
@@ -62,3 +61,3 @@ isType, | ||
throw new DependenciesUnmetError( | ||
`Unknown function argument '${name}: ${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.` | ||
`Unknown function argument '${name}: ${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.`, | ||
); | ||
@@ -73,3 +72,3 @@ } | ||
throw new DependenciesUnmetError( | ||
`Unknown constructor argument '${name}: ${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.` | ||
`Unknown constructor argument '${name}: ${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.`, | ||
); | ||
@@ -80,3 +79,3 @@ } | ||
throw new ServiceNotFoundError( | ||
`Service '${tokenLabel(token)}' in ${moduleName} not found. Make sure it is provided.` | ||
`Service '${tokenLabel(token)}' in ${moduleName} not found. Make sure it is provided.`, | ||
); | ||
@@ -92,3 +91,3 @@ } | ||
throw new DependenciesUnmetError( | ||
`Unknown factory dependency argument '${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.` | ||
`Unknown factory dependency argument '${tokenLabel(token)}' of ${ofName}(${argsCheck.join(', ')}). Make sure '${tokenLabel(token)}' is provided.`, | ||
); | ||
@@ -100,3 +99,3 @@ } | ||
throw new DependenciesUnmetError( | ||
`Unknown property parameter ${name} of ${ofName}. Make sure '${tokenLabel(token)}' is provided.` | ||
`Unknown property parameter ${name} of ${ofName}. Make sure '${tokenLabel(token)}' is provided.`, | ||
); | ||
@@ -107,3 +106,3 @@ } | ||
throw new DependenciesUnmetError( | ||
`${TransientInjectionTarget.name} is not available for ${name} of ${ofName}. ${TransientInjectionTarget.name} is only available when injecting into other providers` | ||
`${TransientInjectionTarget.name} is not available for ${name} of ${ofName}. ${TransientInjectionTarget.name} is only available when injecting into other providers`, | ||
); | ||
@@ -432,3 +431,3 @@ } | ||
type: tokenType || parameter.getType() as Type, | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'factoryDependencyNotFound')); | ||
@@ -444,3 +443,6 @@ } | ||
const configurations = resolveDependenciesFrom[0].configurationProviderRegistry?.get(token); | ||
const configurations: ConfigureProviderEntry[] = []; | ||
for (const module of resolveDependenciesFrom) { | ||
configurations.push(...module.configurationProviderRegistry.get(token)); | ||
} | ||
configurations.push(...buildContext.globalConfigurationProviderRegistry.get(token)); | ||
@@ -463,3 +465,3 @@ | ||
type: tokenType || parameter.getType() as Type, | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, ofName, args.length, 'functionParameterNotFound')); | ||
@@ -509,3 +511,3 @@ } | ||
classType: ClassType, | ||
resolveDependenciesFrom: InjectorModule[] | ||
resolveDependenciesFrom: InjectorModule[], | ||
): { code: string, dependencies: number } { | ||
@@ -528,3 +530,3 @@ if (!classType) throw new Error('Can not create factory for undefined ClassType'); | ||
type: tokenType || parameter.getType() as Type, | ||
optional: !parameter.isValueRequired() | ||
optional: !parameter.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, getClassName(classType), args.length, 'constructorParameterNotFound')); | ||
@@ -543,3 +545,3 @@ } | ||
type: tokenType, | ||
optional: !property.isValueRequired() | ||
optional: !property.isValueRequired(), | ||
}, provider, compiler, resolveDependenciesFrom, getClassName(classType), -1, 'propertyParameterNotFound'); | ||
@@ -554,3 +556,3 @@ propertyAssignment.push(`${resolvedName}.${String(property.getName())} = ${resolveProperty};`); | ||
code: `${resolvedName} = new ${classTypeVar}(${args.join(',')});\n${propertyAssignment.join('\n')}`, | ||
dependencies | ||
dependencies, | ||
}; | ||
@@ -566,3 +568,3 @@ } | ||
argPosition: number, | ||
notFoundFunction: string | ||
notFoundFunction: string, | ||
): string { | ||
@@ -593,4 +595,8 @@ let of = `${ofName}.${options.name}`; | ||
if (options.type.kind === ReflectionKind.class && resolveDependenciesFrom[0] instanceof options.type.classType) { | ||
return compiler.reserveConst(resolveDependenciesFrom[0], 'module'); | ||
if (options.type.kind === ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof options.type.classType) { | ||
return compiler.reserveConst(module, 'module'); | ||
} | ||
} | ||
} | ||
@@ -702,3 +708,3 @@ | ||
throw new DependenciesUnmetError( | ||
`Undefined dependency "${options.name}: ${type}" of ${of}. Type has no provider${fromScope ? ' in scope ' + fromScope : ''}.` | ||
`Undefined dependency "${options.name}: ${type}" of ${of}. Type has no provider${fromScope ? ' in scope ' + fromScope : ''}.`, | ||
); | ||
@@ -716,3 +722,3 @@ } | ||
`Dependency '${options.name}: ${t}' of ${of} can not be injected into ${fromScope ? 'scope ' + fromScope : 'no scope'}, ` + | ||
`since ${foundProviderLabel} only exists in scope${allPossibleScopes.length === 1 ? '' : 's'} ${allPossibleScopes.join(', ')}.` | ||
`since ${foundProviderLabel} only exists in scope${allPossibleScopes.length === 1 ? '' : 's'} ${allPossibleScopes.join(', ')}.`, | ||
); | ||
@@ -751,4 +757,6 @@ } | ||
if (type.kind === ReflectionKind.class && resolveDependenciesFrom[0] instanceof type.classType) { | ||
return () => resolveDependenciesFrom[0]; | ||
if (type.kind === ReflectionKind.class) { | ||
for (const module of resolveDependenciesFrom) { | ||
if (module instanceof type.classType) return () => module; | ||
} | ||
} | ||
@@ -849,3 +857,3 @@ | ||
throw new ServiceNotFoundError( | ||
`Undefined service "${label ? label + ': ' : ''}${t}". Type has no matching provider in ${fromScope ? 'scope ' + fromScope : 'no scope'}.` | ||
`Undefined service "${label ? label + ': ' : ''}${t}". Type has no matching provider in ${fromScope ? 'scope ' + fromScope : 'no scope'}.`, | ||
); | ||
@@ -852,0 +860,0 @@ } |
@@ -608,3 +608,5 @@ import { NormalizedProvider, ProviderWithScope, TagProvider, Token } from './provider.js'; | ||
} else { | ||
parentProviders.push({ token: preparedProvider.token, modules: [this], providers: preparedProvider.providers.slice() }); | ||
// [this, to] is used so that this service resolves dependencies from the target first (so it can overwrite them) | ||
// and falls back to the module it was defined in. This includes configureProvider() calls. | ||
parentProviders.push({ token: preparedProvider.token, modules: [to, this], providers: preparedProvider.providers.slice() }); | ||
} | ||
@@ -611,0 +613,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
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
502648
6606