@clawject/di
Advanced tools
Comparing version 0.0.0-alpha.0 to 0.0.0-alpha.1
@@ -11,2 +11,3 @@ "use strict"; | ||
const BeanExposingError_1 = require("../../compilation-context/messages/errors/BeanExposingError"); | ||
const filterSet_1 = require("../utils/filterSet"); | ||
const fillExposedBeans = (application) => { | ||
@@ -73,3 +74,3 @@ const exposedBeans = new Map(); | ||
exposedBeans.forEach((dependency, propertyName) => { | ||
const externalBeans = Array.from(application.beans).filter(it => it.getExternalValue()); | ||
const externalBeans = (0, filterSet_1.filterSet)(application.beans, it => it.getExternalValue() && !it.isLifecycle()); | ||
const resolvedDependency = DependencyResolver_1.DependencyResolver.resolveDependencies(dependency, externalBeans, null, application); | ||
@@ -76,0 +77,0 @@ application.exposedBeans.set(propertyName, resolvedDependency); |
@@ -10,7 +10,7 @@ "use strict"; | ||
const reportApplicationInfoAndWarnings_1 = require("./reportApplicationInfoAndWarnings"); | ||
const filterSet_1 = require("../utils/filterSet"); | ||
const processApplication = (application) => { | ||
const arrayApplicationBeans = Array.from(application.beans); | ||
(0, verifyBeans_1.verifyBeanNameUniqueness)(arrayApplicationBeans.filter(it => !it.isLifecycle()), application); | ||
(0, verifyBeans_1.verifyBeanNameUniqueness)((0, filterSet_1.filterSet)(application.beans, it => !it.isLifecycle()), application); | ||
(0, fillImports_1.fillImports)(application); | ||
(0, buildDependencyGraphAndFillQualifiedBeans_1.buildDependencyGraphAndFillQualifiedBeans)(application, arrayApplicationBeans); | ||
(0, buildDependencyGraphAndFillQualifiedBeans_1.buildDependencyGraphAndFillQualifiedBeans)(application, application.beans); | ||
(0, reportAboutCircularDependencies_1.reportAboutCircularDependencies)(application); | ||
@@ -17,0 +17,0 @@ (0, fillExposedBeans_1.fillExposedBeans)(application); |
@@ -5,30 +5,41 @@ "use strict"; | ||
const LifecycleKind_1 = require("../../../../runtime/types/LifecycleKind"); | ||
const filterAndMap_1 = require("../../utils/filterAndMap"); | ||
const lodash_1 = require("lodash"); | ||
class RuntimeMetadataBuilder { | ||
static metadata(configuration, application) { | ||
const beans = Array.from(configuration.beanRegister.elements); | ||
const imports = Array.from(configuration.importRegister.elements); | ||
const runtimeConfigurationMetadata = this.configuration(configuration, beans, imports); | ||
const runtimeConfigurationMetadata = this.configuration(configuration); | ||
const runtimeApplicationMetadata = application === null ? null : this.application(runtimeConfigurationMetadata, application); | ||
return runtimeApplicationMetadata !== null && runtimeApplicationMetadata !== void 0 ? runtimeApplicationMetadata : runtimeConfigurationMetadata; | ||
} | ||
static configuration(configuration, beans, imports) { | ||
static configuration(configuration) { | ||
var _a, _b, _c; | ||
const beans = configuration.beanRegister.elements; | ||
const imports = configuration.importRegister.elements; | ||
const lifecycleMetadata = { | ||
[LifecycleKind_1.LifecycleKind.POST_CONSTRUCT]: [], | ||
[LifecycleKind_1.LifecycleKind.PRE_DESTROY]: [], | ||
}; | ||
const importsMetadata = []; | ||
const beansMetadata = {}; | ||
beans.forEach(bean => { | ||
if (bean.lifecycle.includes(LifecycleKind_1.LifecycleKind.POST_CONSTRUCT)) { | ||
lifecycleMetadata[LifecycleKind_1.LifecycleKind.POST_CONSTRUCT].push(bean.classMemberName); | ||
} | ||
if (bean.lifecycle.includes(LifecycleKind_1.LifecycleKind.PRE_DESTROY)) { | ||
lifecycleMetadata[LifecycleKind_1.LifecycleKind.PRE_DESTROY].push(bean.classMemberName); | ||
} | ||
beansMetadata[bean.classMemberName] = { | ||
scope: bean.scopeExpression.getAndDisposeSafe(), | ||
lazy: bean.lazyExpression.getAndDisposeSafe(), | ||
kind: bean.kind, | ||
qualifiedName: bean.fullName, | ||
}; | ||
}); | ||
imports.forEach(it => { | ||
importsMetadata.push({ classPropertyName: it.classMemberName }); | ||
}); | ||
return { | ||
className: (_a = configuration.className) !== null && _a !== void 0 ? _a : '<anonymous>', | ||
lifecycle: { | ||
[LifecycleKind_1.LifecycleKind.POST_CONSTRUCT]: (0, filterAndMap_1.filterAndMap)(beans, bean => bean.lifecycle.includes(LifecycleKind_1.LifecycleKind.POST_CONSTRUCT), bean => bean.classMemberName), | ||
[LifecycleKind_1.LifecycleKind.PRE_DESTROY]: (0, filterAndMap_1.filterAndMap)(beans, bean => bean.lifecycle.includes(LifecycleKind_1.LifecycleKind.PRE_DESTROY), bean => bean.classMemberName) | ||
}, | ||
imports: imports.map(it => ({ classPropertyName: it.classMemberName })), | ||
beans: beans.reduce((acc, bean) => { | ||
acc[bean.classMemberName] = { | ||
scope: bean.scopeExpression.getAndDisposeSafe(), | ||
lazy: bean.lazyExpression.getAndDisposeSafe(), | ||
kind: bean.kind, | ||
qualifiedName: bean.fullName, | ||
}; | ||
return acc; | ||
}, {}), | ||
lifecycle: lifecycleMetadata, | ||
imports: importsMetadata, | ||
beans: beansMetadata, | ||
lazy: (_b = configuration.lazyExpression.getAndDisposeSafe()) !== null && _b !== void 0 ? _b : false, | ||
@@ -35,0 +46,0 @@ scope: (_c = configuration.scopeExpression.getAndDisposeSafe()) !== null && _c !== void 0 ? _c : 'singleton', |
@@ -13,3 +13,3 @@ "use strict"; | ||
// Needed because we're modifying an original collection | ||
const beans = Array.from(configuration.beanRegister.elements); | ||
const beans = new Set(configuration.beanRegister.elements); | ||
beans.forEach((rootBean) => { | ||
@@ -16,0 +16,0 @@ var _a, _b; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const addDoNotEditComment_1 = require("../application-mode/transformers/addDoNotEditComment"); | ||
const mapSetToArray_1 = require("../utils/mapSetToArray"); | ||
class DeclarationMetadataBuilder { | ||
@@ -22,3 +23,3 @@ static buildForConfiguration(configuration) { | ||
external: configuration.external, | ||
beans: Array.from(configuration.beanRegister.elements).map(bean => ({ | ||
beans: (0, mapSetToArray_1.mapSetToArray)(configuration.beanRegister.elements, bean => ({ | ||
kind: bean.kind, | ||
@@ -31,3 +32,3 @@ primary: bean.primary, | ||
})), | ||
imports: Array.from(configuration.importRegister.elements).map(imp => ({ | ||
imports: (0, mapSetToArray_1.mapSetToArray)(configuration.importRegister.elements, imp => ({ | ||
classPropertyName: imp.classMemberName, | ||
@@ -34,0 +35,0 @@ external: imp.external |
@@ -7,2 +7,3 @@ "use strict"; | ||
const DependencyResolver_1 = require("../dependency-resolver/DependencyResolver"); | ||
const filterSet_1 = require("../utils/filterSet"); | ||
const buildDependencyGraphAndFillQualifiedBeans = (application, beans) => { | ||
@@ -12,3 +13,3 @@ const compilationContext = (0, getCompilationContext_1.getCompilationContext)(); | ||
const beanParentConfiguration = bean.parentConfiguration; | ||
const beanCandidates = beans.filter(it => { | ||
const beanCandidates = (0, filterSet_1.filterSet)(beans, it => { | ||
//Filtering out the bean itself | ||
@@ -18,2 +19,5 @@ if (it === bean) { | ||
} | ||
if (it.isLifecycle()) { | ||
return false; | ||
} | ||
//Accepting all beans from the current configuration | ||
@@ -20,0 +24,0 @@ if (it.parentConfiguration === beanParentConfiguration) { |
@@ -10,2 +10,3 @@ "use strict"; | ||
static resolveDependencies(dependency, beansToSearch, relatedBean, relatedApplication) { | ||
const actualBeansToSearch = Array.from(beansToSearch); | ||
switch (true) { | ||
@@ -17,5 +18,5 @@ case dependency.cType.isEmptyValue(): | ||
case dependency.cType.isMapStringToAny(): | ||
return this.buildForCollectionOrArray(dependency, beansToSearch); | ||
return this.buildForCollectionOrArray(dependency, actualBeansToSearch); | ||
default: | ||
return this.buildForBaseType(dependency, beansToSearch, relatedBean, relatedApplication); | ||
return this.buildForBaseType(dependency, actualBeansToSearch, relatedBean, relatedApplication); | ||
} | ||
@@ -25,4 +26,3 @@ } | ||
const resolvedDependency = new MaybeResolvedDependency_1.MaybeResolvedDependency(dependency); | ||
const matchedByType = beansToSearch | ||
.filter(it => dependency.cType.isCompatibleToPossiblePromise(it.cType)); | ||
const matchedByType = beansToSearch.filter(it => dependency.cType.isCompatibleToPossiblePromise(it.cType)); | ||
if (matchedByType.length === 1) { | ||
@@ -32,6 +32,3 @@ resolvedDependency.qualifiedBean = matchedByType[0]; | ||
} | ||
const matchedByTypeAndName = matchedByType | ||
.filter(it => { | ||
return dependency.parameterName === it.fullName; | ||
}); | ||
const matchedByTypeAndName = matchedByType.filter(it => dependency.parameterName === it.fullName); | ||
if (matchedByTypeAndName.length === 1) { | ||
@@ -41,4 +38,3 @@ resolvedDependency.qualifiedBean = matchedByTypeAndName[0]; | ||
} | ||
const matchedByTypeAndPrimary = matchedByType | ||
.filter(it => it.primary); | ||
const matchedByTypeAndPrimary = matchedByType.filter(it => it.primary); | ||
if (matchedByTypeAndPrimary.length === 1) { | ||
@@ -45,0 +41,0 @@ resolvedDependency.qualifiedBean = matchedByTypeAndPrimary[0]; |
@@ -53,2 +53,50 @@ "use strict"; | ||
} | ||
static compareType(source, target) { | ||
const typeChecker = (0, getCompilationContext_1.getCompilationContext)().typeChecker; | ||
const isAssignableByTypescript = typeChecker.isTypeAssignableTo(source, target); | ||
if (ConfigLoader_1.ConfigLoader.get().typeSystem === 'structural') { | ||
return isAssignableByTypescript; | ||
} | ||
if (!isAssignableByTypescript) { | ||
return false; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Any) || this.checkFlag(target, typescript_1.TypeFlags.Any)) { | ||
return true; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Unknown) || this.checkFlag(target, typescript_1.TypeFlags.Unknown)) { | ||
return true; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Union)) { | ||
return false; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Intersection) && this.checkFlag(target, typescript_1.TypeFlags.Intersection)) { | ||
return target.types.every(targetType => { | ||
return source.types.some(sourceType => this.compareType(sourceType, targetType)); | ||
}); | ||
} | ||
if (this.checkFlag(target, typescript_1.TypeFlags.Union)) { | ||
return target.types.some(it => this.compareType(source, it)); | ||
} | ||
if (this.checkFlag(target, typescript_1.TypeFlags.Intersection)) { | ||
return target.types.every(it => this.compareType(source, it)); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Intersection)) { | ||
return source.types.some(it => this.compareType(it, target)); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Primitive) !== this.checkFlag(target, typescript_1.TypeFlags.Primitive)) { | ||
return false; | ||
} | ||
if (this.checkObjectFlag(source, typescript_1.ObjectFlags.Anonymous) || this.checkObjectFlag(target, typescript_1.ObjectFlags.Anonymous)) { | ||
return this.compareAnonymousAliasSymbols(source, target); | ||
} | ||
if (typeChecker.isTupleType(source) || typeChecker.isTupleType(target)) { | ||
return this.compareTupleTypes(source, target); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Object) && this.checkFlag(target, typescript_1.TypeFlags.Object)) { | ||
const expandedSourceTypes = this.getExpandedObjectType(source); | ||
const expandedTargetTypes = this.getExpandedObjectType(target); | ||
return this.compareObjectTypeWrappers(expandedSourceTypes, expandedTargetTypes); | ||
} | ||
return isAssignableByTypescript; | ||
} | ||
static getExpandedObjectType(type) { | ||
@@ -124,50 +172,2 @@ var _a; | ||
} | ||
static compareType(source, target) { | ||
const typeChecker = (0, getCompilationContext_1.getCompilationContext)().typeChecker; | ||
const isAssignableByTypescript = typeChecker.isTypeAssignableTo(source, target); | ||
if (ConfigLoader_1.ConfigLoader.get().typeSystem === 'structural') { | ||
return isAssignableByTypescript; | ||
} | ||
if (!isAssignableByTypescript) { | ||
return false; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Any) || this.checkFlag(target, typescript_1.TypeFlags.Any)) { | ||
return true; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Unknown) || this.checkFlag(target, typescript_1.TypeFlags.Unknown)) { | ||
return true; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Union)) { | ||
return false; | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Intersection) && this.checkFlag(target, typescript_1.TypeFlags.Intersection)) { | ||
return target.types.every(targetType => { | ||
return source.types.some(sourceType => this.compareType(sourceType, targetType)); | ||
}); | ||
} | ||
if (this.checkFlag(target, typescript_1.TypeFlags.Union)) { | ||
return target.types.some(it => this.compareType(source, it)); | ||
} | ||
if (this.checkFlag(target, typescript_1.TypeFlags.Intersection)) { | ||
return target.types.every(it => this.compareType(source, it)); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Intersection)) { | ||
return source.types.some(it => this.compareType(it, target)); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Primitive) !== this.checkFlag(target, typescript_1.TypeFlags.Primitive)) { | ||
return false; | ||
} | ||
if (this.checkObjectFlag(source, typescript_1.ObjectFlags.Anonymous) || this.checkObjectFlag(target, typescript_1.ObjectFlags.Anonymous)) { | ||
return this.compareAnonymousAliasSymbols(source, target); | ||
} | ||
if (typeChecker.isTupleType(source) || typeChecker.isTupleType(target)) { | ||
return this.compareTupleTypes(source, target); | ||
} | ||
if (this.checkFlag(source, typescript_1.TypeFlags.Object) && this.checkFlag(target, typescript_1.TypeFlags.Object)) { | ||
const expandedSourceTypes = this.getExpandedObjectType(source); | ||
const expandedTargetTypes = this.getExpandedObjectType(target); | ||
return this.compareObjectTypeWrappers(expandedSourceTypes, expandedTargetTypes); | ||
} | ||
return isAssignableByTypescript; | ||
} | ||
static compareObjectTypes(source, target) { | ||
@@ -174,0 +174,0 @@ var _a, _b, _c, _d; |
@@ -16,3 +16,9 @@ "use strict"; | ||
const ClawjectApplicationContextImpl_1 = require("../ClawjectApplicationContextImpl"); | ||
/** @public */ | ||
/** | ||
* It's a factory class that creates a {@link ClawjectApplicationContext} instance. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/clawject-factory | ||
* | ||
* @public | ||
* */ | ||
class ClawjectFactory { | ||
@@ -19,0 +25,0 @@ static createApplicationContext(clawjectApplication, constructorParameters) { |
@@ -7,5 +7,6 @@ "use strict"; | ||
/** | ||
* Indicates that a method/property produces/contains a bean to be managed by the Clawject container. | ||
* Indicates that a method/property produces/contains a bean or a bean constructor | ||
* to be managed by the Clawject container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/bean | ||
* @docs https://clawject.com/docs/fundamentals/bean | ||
* | ||
@@ -12,0 +13,0 @@ * @public |
@@ -5,3 +5,9 @@ "use strict"; | ||
const ErrorBuilder_1 = require("../../ErrorBuilder"); | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a {@link Configuration @Configuration} class and an entry point for the Clawject application. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
const ClawjectApplication = () => { | ||
@@ -11,12 +17,1 @@ throw ErrorBuilder_1.ErrorBuilder.usageWithoutConfiguredDI('@ClawjectApplication'); | ||
exports.ClawjectApplication = ClawjectApplication; | ||
// ClawjectApplication.copyMetadata = (source, target) => { | ||
// const applicationMetadata = MetadataStorage.getApplicationMetadata(source); | ||
// | ||
// if (applicationMetadata === null) { | ||
// throw new RuntimeErrors.NoClassMetadataFoundError('No application metadata found on source class'); | ||
// } | ||
// | ||
// MetadataStorage.setApplicationMetadata(target, applicationMetadata); | ||
// | ||
// return target; | ||
// }; |
@@ -5,16 +5,11 @@ "use strict"; | ||
const ErrorBuilder_1 = require("../../ErrorBuilder"); | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a Configuration class, and can contains bean definitions, configuration imports. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
exports.Configuration = (() => { | ||
throw ErrorBuilder_1.ErrorBuilder.usageWithoutConfiguredDI('@Configuration'); | ||
}); | ||
// Configuration.copyMetadata = (source, target) => { | ||
// const applicationMetadata = MetadataStorage.getConfigurationMetadata(source); | ||
// | ||
// if (applicationMetadata === null) { | ||
// throw new RuntimeErrors.NoClassMetadataFoundError('No configuration metadata found on source class'); | ||
// } | ||
// | ||
// MetadataStorage.setConfigurationMetadata(target, applicationMetadata); | ||
// | ||
// return target; | ||
// }; |
@@ -8,3 +8,3 @@ "use strict"; | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/embedded | ||
* @docs https://clawject.com/docs/fundamentals/embedded | ||
* | ||
@@ -11,0 +11,0 @@ * @public |
@@ -6,2 +6,8 @@ "use strict"; | ||
/** | ||
* It Indicates that the bean or configuration import is only visible within the class in which it is applied. | ||
* When applied on class level, | ||
* all beans and configuration imports defined in the class are only visible within the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#internal | ||
* | ||
* @public | ||
@@ -8,0 +14,0 @@ */ |
@@ -6,2 +6,7 @@ "use strict"; | ||
/** | ||
* It Indicates that the bean or configuration import is visible outside the class in which they are defined. | ||
* When applied on class level, all beans and configuration imports defined in the class become visible outside the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#external | ||
* | ||
* @public | ||
@@ -8,0 +13,0 @@ */ |
@@ -8,3 +8,3 @@ "use strict"; | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/lazy | ||
* @docs https://clawject.com/docs/fundamentals/lazy | ||
* | ||
@@ -11,0 +11,0 @@ * @public |
@@ -6,8 +6,7 @@ "use strict"; | ||
/** | ||
* Allows invoking a decorated method or property with arrow function after context is constructed or bean is created. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* after configuration or the bean has been constructed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#postconstruct | ||
* | ||
* @see PreDestroy | ||
* | ||
* @public */ | ||
@@ -14,0 +13,0 @@ const PostConstruct = () => { |
@@ -6,8 +6,7 @@ "use strict"; | ||
/** | ||
* Allows invoking a decorated method or property with arrow function before context is cleared or bean is destroyed. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* before the application context will be closed or the bean will be destroyed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#predestroy | ||
* | ||
* @see PostConstruct | ||
* | ||
* @public */ | ||
@@ -14,0 +13,0 @@ const PreDestroy = () => { |
@@ -6,4 +6,5 @@ "use strict"; | ||
/** | ||
* Indicates that a specific bean is a primary candidate for injection. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/primary | ||
* @docs https://clawject.com/docs/fundamentals/primary | ||
* | ||
@@ -10,0 +11,0 @@ * @public */ |
@@ -6,5 +6,5 @@ "use strict"; | ||
/** | ||
* Allows specifying custom bean name. | ||
* Allows us to specify a name for a bean. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/qualifier | ||
* @docs https://clawject.com/docs/fundamentals/qualifier | ||
* | ||
@@ -11,0 +11,0 @@ * @public |
@@ -6,5 +6,5 @@ "use strict"; | ||
/** | ||
* Allows specifying the scope of a bean or all beans in context if applied on a class-level. | ||
* The Scope of Bean is a way to define when Bean will be created and how it is managed by container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/scope | ||
* @docs https://clawject.com/docs/fundamentals/scope | ||
* | ||
@@ -11,0 +11,0 @@ * @public |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ExposeBeans = void 0; | ||
/** @public */ | ||
/** | ||
* *ExposeBeans* function allows you to expose beans from the application context, | ||
* so that they can be accessed from the outside of the {@link ClawjectApplication @ClawjectApplication} class. | ||
* | ||
* This function will have an effect only on the root of your application context class | ||
* (the one annotated with {@link ClawjectApplication @ClawjectApplication}). | ||
* Clawject will validate the beans that are being exposed | ||
* and will report an error if the bean is not found in the application context. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/expose-beans | ||
* | ||
* @public | ||
* */ | ||
const ExposeBeans = () => { | ||
@@ -6,0 +18,0 @@ return (exposedBeans) => exposedBeans; |
@@ -6,3 +6,9 @@ "use strict"; | ||
const Utils_1 = require("../Utils"); | ||
/** @public */ | ||
/** | ||
* *Import* function allows you | ||
* to import a {@link Configuration @Configuration} class into the target {@link Configuration @Configuration} class | ||
* to use beans that is provided by imported configuration. | ||
* | ||
* @public | ||
* */ | ||
const Import = (configurationClass, constructorParameters) => { | ||
@@ -9,0 +15,0 @@ if (Utils_1.Utils.isPromise(configurationClass)) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RuntimeErrors = void 0; | ||
/** @public */ | ||
/** | ||
* Namespace for runtime errors. | ||
* | ||
* Each error class is a subclass of `Error` and has a unique name. | ||
* | ||
* @docs https://clawject.com/docs/errors#runtime | ||
* | ||
* @public | ||
*/ | ||
var RuntimeErrors; | ||
@@ -6,0 +14,0 @@ (function (RuntimeErrors) { |
@@ -20,3 +20,3 @@ "use strict"; | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterregisterscope | ||
*/ | ||
@@ -31,3 +31,3 @@ static registerScope(scopeName, scope) { | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterunregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterunregisterscope | ||
* */ | ||
@@ -42,3 +42,3 @@ static unregisterScope(scopeName) { | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterhasscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterhasscope | ||
* */ | ||
@@ -45,0 +45,0 @@ static hasScope(scopeName) { |
@@ -5,3 +5,9 @@ import { ClawjectContainer } from '../container/ClawjectContainer.js'; | ||
/** @public */ | ||
/** | ||
* It's a factory class that creates a {@link ClawjectApplicationContext} instance. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/clawject-factory | ||
* | ||
* @public | ||
* */ | ||
class ClawjectFactory { | ||
@@ -8,0 +14,0 @@ static async createApplicationContext(clawjectApplication, constructorParameters) { |
@@ -5,5 +5,6 @@ import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Indicates that a method/property produces/contains a bean to be managed by the Clawject container. | ||
* Indicates that a method/property produces/contains a bean or a bean constructor | ||
* to be managed by the Clawject container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/bean | ||
* @docs https://clawject.com/docs/fundamentals/bean | ||
* | ||
@@ -10,0 +11,0 @@ * @public |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a {@link Configuration @Configuration} class and an entry point for the Clawject application. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
const ClawjectApplication = () => { | ||
throw ErrorBuilder.usageWithoutConfiguredDI('@ClawjectApplication'); | ||
}; | ||
// ClawjectApplication.copyMetadata = (source, target) => { | ||
// const applicationMetadata = MetadataStorage.getApplicationMetadata(source); | ||
// | ||
// if (applicationMetadata === null) { | ||
// throw new RuntimeErrors.NoClassMetadataFoundError('No application metadata found on source class'); | ||
// } | ||
// | ||
// MetadataStorage.setApplicationMetadata(target, applicationMetadata); | ||
// | ||
// return target; | ||
// }; | ||
export { ClawjectApplication }; |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a Configuration class, and can contains bean definitions, configuration imports. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
const Configuration = (() => { | ||
throw ErrorBuilder.usageWithoutConfiguredDI('@Configuration'); | ||
}); | ||
// Configuration.copyMetadata = (source, target) => { | ||
// const applicationMetadata = MetadataStorage.getConfigurationMetadata(source); | ||
// | ||
// if (applicationMetadata === null) { | ||
// throw new RuntimeErrors.NoClassMetadataFoundError('No configuration metadata found on source class'); | ||
// } | ||
// | ||
// MetadataStorage.setConfigurationMetadata(target, applicationMetadata); | ||
// | ||
// return target; | ||
// }; | ||
export { Configuration }; |
@@ -6,3 +6,3 @@ import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/embedded | ||
* @docs https://clawject.com/docs/fundamentals/embedded | ||
* | ||
@@ -9,0 +9,0 @@ * @public |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* It Indicates that the bean or configuration import is only visible within the class in which it is applied. | ||
* When applied on class level, | ||
* all beans and configuration imports defined in the class are only visible within the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#internal | ||
* | ||
* @public | ||
@@ -5,0 +11,0 @@ */ |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* It Indicates that the bean or configuration import is visible outside the class in which they are defined. | ||
* When applied on class level, all beans and configuration imports defined in the class become visible outside the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#external | ||
* | ||
* @public | ||
@@ -5,0 +10,0 @@ */ |
@@ -6,3 +6,3 @@ import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/lazy | ||
* @docs https://clawject.com/docs/fundamentals/lazy | ||
* | ||
@@ -9,0 +9,0 @@ * @public |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Allows invoking a decorated method or property with arrow function after context is constructed or bean is created. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* after configuration or the bean has been constructed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#postconstruct | ||
* | ||
* @see PreDestroy | ||
* | ||
* @public */ | ||
@@ -11,0 +10,0 @@ const PostConstruct = () => { |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Allows invoking a decorated method or property with arrow function before context is cleared or bean is destroyed. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* before the application context will be closed or the bean will be destroyed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#predestroy | ||
* | ||
* @see PostConstruct | ||
* | ||
* @public */ | ||
@@ -11,0 +10,0 @@ const PreDestroy = () => { |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Indicates that a specific bean is a primary candidate for injection. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/primary | ||
* @docs https://clawject.com/docs/fundamentals/primary | ||
* | ||
@@ -7,0 +8,0 @@ * @public */ |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Allows specifying custom bean name. | ||
* Allows us to specify a name for a bean. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/qualifier | ||
* @docs https://clawject.com/docs/fundamentals/qualifier | ||
* | ||
@@ -8,0 +8,0 @@ * @public |
import { ErrorBuilder } from '../../ErrorBuilder.js'; | ||
/** | ||
* Allows specifying the scope of a bean or all beans in context if applied on a class-level. | ||
* The Scope of Bean is a way to define when Bean will be created and how it is managed by container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/scope | ||
* @docs https://clawject.com/docs/fundamentals/scope | ||
* | ||
@@ -8,0 +8,0 @@ * @public |
@@ -1,2 +0,14 @@ | ||
/** @public */ | ||
/** | ||
* *ExposeBeans* function allows you to expose beans from the application context, | ||
* so that they can be accessed from the outside of the {@link ClawjectApplication @ClawjectApplication} class. | ||
* | ||
* This function will have an effect only on the root of your application context class | ||
* (the one annotated with {@link ClawjectApplication @ClawjectApplication}). | ||
* Clawject will validate the beans that are being exposed | ||
* and will report an error if the bean is not found in the application context. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/expose-beans | ||
* | ||
* @public | ||
* */ | ||
const ExposeBeans = () => { | ||
@@ -3,0 +15,0 @@ return (exposedBeans) => exposedBeans; |
import { RuntimeErrors } from './RuntimeErrors.js'; | ||
import { Utils } from '../Utils.js'; | ||
/** @public */ | ||
/** | ||
* *Import* function allows you | ||
* to import a {@link Configuration @Configuration} class into the target {@link Configuration @Configuration} class | ||
* to use beans that is provided by imported configuration. | ||
* | ||
* @public | ||
* */ | ||
const Import = (configurationClass, constructorParameters) => { | ||
@@ -6,0 +12,0 @@ if (Utils.isPromise(configurationClass)) { |
@@ -1,2 +0,10 @@ | ||
/** @public */ | ||
/** | ||
* Namespace for runtime errors. | ||
* | ||
* Each error class is a subclass of `Error` and has a unique name. | ||
* | ||
* @docs https://clawject.com/docs/errors#runtime | ||
* | ||
* @public | ||
*/ | ||
var RuntimeErrors; | ||
@@ -3,0 +11,0 @@ (function (RuntimeErrors) { |
@@ -18,3 +18,3 @@ import { InternalScopeRegister } from '../scope/InternalScopeRegister.js'; | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterregisterscope | ||
*/ | ||
@@ -29,3 +29,3 @@ static registerScope(scopeName, scope) { | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterunregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterunregisterscope | ||
* */ | ||
@@ -40,3 +40,3 @@ static unregisterScope(scopeName) { | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterhasscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterhasscope | ||
* */ | ||
@@ -43,0 +43,0 @@ static hasScope(scopeName) { |
@@ -18,5 +18,6 @@ /** | ||
/** | ||
* Indicates that a method/property produces/contains a bean to be managed by the Clawject container. | ||
* Indicates that a method/property produces/contains a bean or a bean constructor | ||
* to be managed by the Clawject container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/bean | ||
* @docs https://clawject.com/docs/fundamentals/bean | ||
* | ||
@@ -41,3 +42,7 @@ * @public | ||
/** @public */ | ||
/** | ||
* @internalApi Just a utility type. | ||
* | ||
* @public | ||
*/ | ||
export declare type ClassConstructor<T, A extends any[] = any[]> = { | ||
@@ -47,11 +52,31 @@ new (...args: A): T; | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a {@link Configuration @Configuration} class and an entry point for the Clawject application. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
export declare const ClawjectApplication: DecoratorWithoutArguments<ClawjectApplicationTarget>; | ||
/** | ||
* It is an object that stores and manages configurations and beans of the application. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/clawject-application-context | ||
* | ||
* @public | ||
*/ | ||
export declare interface ClawjectApplicationContext<T extends ClassConstructor<any>> { | ||
/** | ||
* Returns the exposed bean instance by the given name. | ||
* */ | ||
getExposedBean<K extends keyof GetBeansResult<T>>(beanName: K & string): Promise<GetBeansResult<T>[K]>; | ||
/** | ||
* Returns all exposed beans. | ||
* */ | ||
getExposedBeans(): Promise<GetBeansResult<T>>; | ||
/** | ||
* Closes the application context and destroys all beans. | ||
* Functions annotated with `@PreDestroy` will be called for all beans. | ||
* */ | ||
close(): Promise<void>; | ||
@@ -63,9 +88,36 @@ } | ||
/** @public */ | ||
/** | ||
* It's a factory class that creates a {@link ClawjectApplicationContext} instance. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/clawject-factory | ||
* | ||
* @public | ||
* */ | ||
export declare class ClawjectFactory { | ||
/** | ||
* Creates a {@link ClawjectApplicationContext} instance. | ||
* | ||
* @param clawjectApplication - The class that is annotated with {@link ClawjectApplication @ClawjectApplication}. | ||
* | ||
* @public | ||
* */ | ||
static createApplicationContext<C extends ClassConstructor<any, []>>(clawjectApplication: C): Promise<ClawjectApplicationContext<C>>; | ||
/** | ||
* Creates a {@link ClawjectApplicationContext} instance. | ||
* | ||
* @param clawjectApplication - The class that is annotated with {@link ClawjectApplication @ClawjectApplication}. | ||
* @param constructorParameters - The constructor parameters of the `clawjectApplication` class. | ||
* | ||
* @public | ||
* */ | ||
static createApplicationContext<C extends ClassConstructor<any>>(clawjectApplication: C, constructorParameters: InstantiationConstructorParameters<ConstructorParameters<C>>): Promise<ClawjectApplicationContext<C>>; | ||
} | ||
/** @public */ | ||
/** | ||
* Indicates that a target class is a Configuration class, and can contains bean definitions, configuration imports. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/configurations | ||
* | ||
* @public | ||
*/ | ||
export declare const Configuration: DecoratorWithoutArguments<ConfigurationTarget>; | ||
@@ -80,3 +132,3 @@ | ||
* | ||
* @docs https://clawject.org/docs/advanced-concepts/custom-scopes | ||
* @docs https://clawject.com/docs/advanced-concepts/custom-scopes | ||
* | ||
@@ -164,3 +216,3 @@ * @public | ||
/** | ||
* Type declaration for a decorator without arguments. | ||
* @internalApi Type declaration for a decorator without arguments. | ||
* | ||
@@ -174,3 +226,3 @@ * @public | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/embedded | ||
* @docs https://clawject.com/docs/fundamentals/embedded | ||
* | ||
@@ -184,6 +236,22 @@ * @public | ||
/** @public */ | ||
/** | ||
* *ExposeBeans* function allows you to expose beans from the application context, | ||
* so that they can be accessed from the outside of the {@link ClawjectApplication @ClawjectApplication} class. | ||
* | ||
* This function will have an effect only on the root of your application context class | ||
* (the one annotated with {@link ClawjectApplication @ClawjectApplication}). | ||
* Clawject will validate the beans that are being exposed | ||
* and will report an error if the bean is not found in the application context. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/expose-beans | ||
* | ||
* @public | ||
* */ | ||
export declare const ExposeBeans: <T extends object>() => (exposedBeans: ExposedBeans<T>) => ExposedBeans<T>; | ||
/** @public */ | ||
/** | ||
* @internalApi Object that is produced by {@link ExposeBeans} function. | ||
* | ||
* @public | ||
* */ | ||
export declare interface ExposedBeans<T extends object> { | ||
@@ -195,2 +263,8 @@ readonly beans: T; | ||
/** | ||
* It Indicates that the bean or configuration import is only visible within the class in which it is applied. | ||
* When applied on class level, | ||
* all beans and configuration imports defined in the class are only visible within the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#internal | ||
* | ||
* @public | ||
@@ -204,2 +278,4 @@ */ | ||
/** | ||
* @internalApi Just a utility type. | ||
* | ||
* @public | ||
@@ -210,2 +286,4 @@ */ | ||
/** | ||
* @internalApi Object that is produced by {@link ClawjectApplicationContext#getExposedBeans} function. | ||
* | ||
* @public | ||
@@ -215,3 +293,9 @@ */ | ||
/** @public */ | ||
/** | ||
* *Import* function allows you | ||
* to import a {@link Configuration @Configuration} class into the target {@link Configuration @Configuration} class | ||
* to use beans that is provided by imported configuration. | ||
* | ||
* @public | ||
* */ | ||
export declare const Import: { | ||
@@ -224,3 +308,7 @@ <C extends ClassConstructor<any, []>>(configurationClass: C): ImportedConfiguration<C>; | ||
/** @public */ | ||
/** | ||
* @internalApi Object that is produced by {@link Import} function. | ||
* | ||
* @public | ||
*/ | ||
export declare interface ImportedConfiguration<C extends ClassConstructor<any>, A extends any[] = ConstructorParameters<C>> { | ||
@@ -232,6 +320,15 @@ readonly constructor: C; | ||
/** @public */ | ||
/** | ||
* Just a utility type. | ||
* | ||
* @public | ||
*/ | ||
export declare type InstantiationConstructorParameters<A extends any[]> = A | (() => A | Promise<A>); | ||
/** | ||
* It Indicates that the bean or configuration import is visible outside the class in which they are defined. | ||
* When applied on class level, all beans and configuration imports defined in the class become visible outside the class. | ||
* | ||
* @docs https://clawject.com/docs/fundamentals/internal-external#external | ||
* | ||
* @public | ||
@@ -247,3 +344,3 @@ */ | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/lazy | ||
* @docs https://clawject.com/docs/fundamentals/lazy | ||
* | ||
@@ -258,2 +355,3 @@ * @public | ||
/** | ||
* @internalApi Just a utility type. | ||
* @public | ||
@@ -285,8 +383,7 @@ */ | ||
/** | ||
* Allows invoking a decorated method or property with arrow function after context is constructed or bean is created. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* after configuration or the bean has been constructed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#postconstruct | ||
* | ||
* @see PreDestroy | ||
* | ||
* @public */ | ||
@@ -299,8 +396,7 @@ export declare const PostConstruct: DecoratorWithoutArguments<PostConstructTarget>; | ||
/** | ||
* Allows invoking a decorated method or property with arrow function before context is cleared or bean is destroyed. | ||
* Indicates that an annotated method or property with arrow function should be called | ||
* before the application context will be closed or the bean will be destroyed. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/postconstruct-predestroy | ||
* @docs https://clawject.com/docs/fundamentals/lifecycle#predestroy | ||
* | ||
* @see PostConstruct | ||
* | ||
* @public */ | ||
@@ -313,4 +409,5 @@ export declare const PreDestroy: DecoratorWithoutArguments<PreDestroyTarget>; | ||
/** | ||
* Indicates that a specific bean is a primary candidate for injection. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/primary | ||
* @docs https://clawject.com/docs/fundamentals/primary | ||
* | ||
@@ -324,5 +421,5 @@ * @public */ | ||
/** | ||
* Allows specifying custom bean name. | ||
* Allows us to specify a name for a bean. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/qualifier | ||
* @docs https://clawject.com/docs/fundamentals/qualifier | ||
* | ||
@@ -336,3 +433,11 @@ * @public | ||
/** @public */ | ||
/** | ||
* Namespace for runtime errors. | ||
* | ||
* Each error class is a subclass of `Error` and has a unique name. | ||
* | ||
* @docs https://clawject.com/docs/errors#runtime | ||
* | ||
* @public | ||
*/ | ||
export declare namespace RuntimeErrors { | ||
@@ -378,5 +483,5 @@ /** @public */ | ||
/** | ||
* Allows specifying the scope of a bean or all beans in context if applied on a class-level. | ||
* The Scope of Bean is a way to define when Bean will be created and how it is managed by container. | ||
* | ||
* @docs https://clawject.org/docs/base-concepts/scope | ||
* @docs https://clawject.com/docs/fundamentals/scope | ||
* | ||
@@ -402,3 +507,3 @@ * @public | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterregisterscope | ||
*/ | ||
@@ -411,3 +516,3 @@ static registerScope(scopeName: string | number, scope: CustomScope): void; | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterunregisterscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterunregisterscope | ||
* */ | ||
@@ -420,3 +525,3 @@ static unregisterScope(scopeName: string | number): boolean; | ||
* | ||
* @docs https://clawject.org/docs/api/scope-register#scoperegisterhasscope | ||
* @docs https://clawject.com/docs/api/scope-register#scoperegisterhasscope | ||
* */ | ||
@@ -423,0 +528,0 @@ static hasScope(scopeName: string | number): boolean; |
{ | ||
"name": "@clawject/di", | ||
"version": "0.0.0-alpha.0", | ||
"version": "0.0.0-alpha.1", | ||
"keywords": [ | ||
@@ -74,3 +74,4 @@ "dependency-injection", | ||
"semver": "^7.5.1", | ||
"upath": "^2.0.1" | ||
"upath": "^2.0.1", | ||
"winston": "^3.11.0" | ||
}, | ||
@@ -77,0 +78,0 @@ "devDependencies": { |
415820
268
8691
14
+ Addedwinston@^3.11.0
+ Added@colors/colors@1.6.0(transitive)
+ Added@dabh/diagnostics@2.0.3(transitive)
+ Added@types/node@20.14.6(transitive)
+ Added@types/triple-beam@1.3.5(transitive)
+ Addedasync@3.2.5(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addedenabled@2.0.0(transitive)
+ Addedfecha@4.2.3(transitive)
+ Addedfn.name@1.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedkuler@2.0.0(transitive)
+ Addedlogform@2.6.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedone-time@1.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafe-stable-stringify@2.4.3(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedstack-trace@0.0.10(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtext-hex@1.0.0(transitive)
+ Addedtriple-beam@1.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwinston@3.13.0(transitive)
+ Addedwinston-transport@4.7.0(transitive)
- Removed@types/node@20.14.2(transitive)
- Removedundici-types@5.26.5(transitive)