@asenajs/ioc 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +219 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/CircularDependencyDetector.d.ts +49 -0
- package/dist/lib/CircularDependencyDetector.js +69 -0
- package/dist/lib/CircularDependencyDetector.js.map +1 -0
- package/dist/lib/Container.d.ts +247 -0
- package/dist/lib/Container.js +563 -0
- package/dist/lib/Container.js.map +1 -0
- package/dist/lib/IocApplication.d.ts +88 -0
- package/dist/lib/IocApplication.js +110 -0
- package/dist/lib/IocApplication.js.map +1 -0
- package/dist/lib/IocEngine.d.ts +173 -0
- package/dist/lib/IocEngine.js +725 -0
- package/dist/lib/IocEngine.js.map +1 -0
- package/dist/lib/component/Scope.d.ts +4 -0
- package/dist/lib/component/Scope.js +6 -0
- package/dist/lib/component/Scope.js.map +1 -0
- package/dist/lib/component/componentRegistry.d.ts +34 -0
- package/dist/lib/component/componentRegistry.js +134 -0
- package/dist/lib/component/componentRegistry.js.map +1 -0
- package/dist/lib/component/componentUtils.d.ts +16 -0
- package/dist/lib/component/componentUtils.js +44 -0
- package/dist/lib/component/componentUtils.js.map +1 -0
- package/dist/lib/component/decorators/Component.d.ts +8 -0
- package/dist/lib/component/decorators/Component.js +12 -0
- package/dist/lib/component/decorators/Component.js.map +1 -0
- package/dist/lib/component/decorators/Implements.d.ts +7 -0
- package/dist/lib/component/decorators/Implements.js +14 -0
- package/dist/lib/component/decorators/Implements.js.map +1 -0
- package/dist/lib/component/decorators/Inject.d.ts +29 -0
- package/dist/lib/component/decorators/Inject.js +82 -0
- package/dist/lib/component/decorators/Inject.js.map +1 -0
- package/dist/lib/component/decorators/OnStart.d.ts +20 -0
- package/dist/lib/component/decorators/OnStart.js +33 -0
- package/dist/lib/component/decorators/OnStart.js.map +1 -0
- package/dist/lib/component/decorators/OnStop.d.ts +15 -0
- package/dist/lib/component/decorators/OnStop.js +28 -0
- package/dist/lib/component/decorators/OnStop.js.map +1 -0
- package/dist/lib/component/decorators/PostConstruct.d.ts +14 -0
- package/dist/lib/component/decorators/PostConstruct.js +16 -0
- package/dist/lib/component/decorators/PostConstruct.js.map +1 -0
- package/dist/lib/component/decorators/PostProcessor.d.ts +25 -0
- package/dist/lib/component/decorators/PostProcessor.js +29 -0
- package/dist/lib/component/decorators/PostProcessor.js.map +1 -0
- package/dist/lib/component/decorators/Service.d.ts +8 -0
- package/dist/lib/component/decorators/Service.js +12 -0
- package/dist/lib/component/decorators/Service.js.map +1 -0
- package/dist/lib/component/decorators/Strategy.d.ts +9 -0
- package/dist/lib/component/decorators/Strategy.js +29 -0
- package/dist/lib/component/decorators/Strategy.js.map +1 -0
- package/dist/lib/component/decorators/Value.d.ts +29 -0
- package/dist/lib/component/decorators/Value.js +41 -0
- package/dist/lib/component/decorators/Value.js.map +1 -0
- package/dist/lib/component/decorators/index.d.ts +11 -0
- package/dist/lib/component/decorators/index.js +12 -0
- package/dist/lib/component/decorators/index.js.map +1 -0
- package/dist/lib/component/decorators/legacyDecorator.d.ts +15 -0
- package/dist/lib/component/decorators/legacyDecorator.js +24 -0
- package/dist/lib/component/decorators/legacyDecorator.js.map +1 -0
- package/dist/lib/component/index.d.ts +3 -0
- package/dist/lib/component/index.js +4 -0
- package/dist/lib/component/index.js.map +1 -0
- package/dist/lib/constants/ComponentConstants.d.ts +21 -0
- package/dist/lib/constants/ComponentConstants.js +25 -0
- package/dist/lib/constants/ComponentConstants.js.map +1 -0
- package/dist/lib/constants/index.d.ts +1 -0
- package/dist/lib/constants/index.js +2 -0
- package/dist/lib/constants/index.js.map +1 -0
- package/dist/lib/decorators/CoreService.d.ts +11 -0
- package/dist/lib/decorators/CoreService.js +30 -0
- package/dist/lib/decorators/CoreService.js.map +1 -0
- package/dist/lib/decorators/index.d.ts +1 -0
- package/dist/lib/decorators/index.js +2 -0
- package/dist/lib/decorators/index.js.map +1 -0
- package/dist/lib/helper/fileHelper.d.ts +1 -0
- package/dist/lib/helper/fileHelper.js +29 -0
- package/dist/lib/helper/fileHelper.js.map +1 -0
- package/dist/lib/helper/iocHelper.d.ts +2 -0
- package/dist/lib/helper/iocHelper.js +12 -0
- package/dist/lib/helper/iocHelper.js.map +1 -0
- package/dist/lib/helper/valueResolver.d.ts +24 -0
- package/dist/lib/helper/valueResolver.js +37 -0
- package/dist/lib/helper/valueResolver.js.map +1 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.js +13 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/lifecycle/LifecycleService.d.ts +78 -0
- package/dist/lib/lifecycle/LifecycleService.js +181 -0
- package/dist/lib/lifecycle/LifecycleService.js.map +1 -0
- package/dist/lib/lifecycle/LifecycleState.d.ts +20 -0
- package/dist/lib/lifecycle/LifecycleState.js +22 -0
- package/dist/lib/lifecycle/LifecycleState.js.map +1 -0
- package/dist/lib/lifecycle/index.d.ts +2 -0
- package/dist/lib/lifecycle/index.js +3 -0
- package/dist/lib/lifecycle/index.js.map +1 -0
- package/dist/lib/logger/IocLogger.d.ts +35 -0
- package/dist/lib/logger/IocLogger.js +2 -0
- package/dist/lib/logger/IocLogger.js.map +1 -0
- package/dist/lib/logger/index.d.ts +1 -0
- package/dist/lib/logger/index.js +2 -0
- package/dist/lib/logger/index.js.map +1 -0
- package/dist/lib/types/Class.d.ts +1 -0
- package/dist/lib/types/Class.js +2 -0
- package/dist/lib/types/Class.js.map +1 -0
- package/dist/lib/types/ComponentPostProcessor.d.ts +30 -0
- package/dist/lib/types/ComponentPostProcessor.js +2 -0
- package/dist/lib/types/ComponentPostProcessor.js.map +1 -0
- package/dist/lib/types/ContainerService.d.ts +6 -0
- package/dist/lib/types/ContainerService.js +2 -0
- package/dist/lib/types/ContainerService.js.map +1 -0
- package/dist/lib/types/ICoreService.d.ts +9 -0
- package/dist/lib/types/ICoreService.js +2 -0
- package/dist/lib/types/ICoreService.js.map +1 -0
- package/dist/lib/types/ICoreServiceNames.d.ts +10 -0
- package/dist/lib/types/ICoreServiceNames.js +12 -0
- package/dist/lib/types/ICoreServiceNames.js.map +1 -0
- package/dist/lib/types/InjectableComponent.d.ts +42 -0
- package/dist/lib/types/InjectableComponent.js +2 -0
- package/dist/lib/types/InjectableComponent.js.map +1 -0
- package/dist/lib/types/IocConfig.d.ts +11 -0
- package/dist/lib/types/IocConfig.js +2 -0
- package/dist/lib/types/IocConfig.js.map +1 -0
- package/dist/lib/types/LifecycleComponent.d.ts +29 -0
- package/dist/lib/types/LifecycleComponent.js +2 -0
- package/dist/lib/types/LifecycleComponent.js.map +1 -0
- package/dist/lib/types/decorators/ComponentParams.d.ts +5 -0
- package/dist/lib/types/decorators/ComponentParams.js +2 -0
- package/dist/lib/types/decorators/ComponentParams.js.map +1 -0
- package/dist/lib/types/decorators/ComponentType.d.ts +14 -0
- package/dist/lib/types/decorators/ComponentType.js +10 -0
- package/dist/lib/types/decorators/ComponentType.js.map +1 -0
- package/dist/lib/types/decorators/ServiceParams.d.ts +2 -0
- package/dist/lib/types/decorators/ServiceParams.js +2 -0
- package/dist/lib/types/decorators/ServiceParams.js.map +1 -0
- package/dist/lib/types/index.d.ts +11 -0
- package/dist/lib/types/index.js +12 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/utils/errorChain.d.ts +4 -0
- package/dist/lib/utils/errorChain.js +29 -0
- package/dist/lib/utils/errorChain.js.map +1 -0
- package/dist/lib/utils/typedMetadata.d.ts +54 -0
- package/dist/lib/utils/typedMetadata.js +97 -0
- package/dist/lib/utils/typedMetadata.js.map +1 -0
- package/package.json +73 -4
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ComponentParams } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator for defining a PostProcessor component.
|
|
4
|
+
*
|
|
5
|
+
* PostProcessors hook into the component creation lifecycle and can modify or inspect
|
|
6
|
+
* instances after they are fully initialized (constructor + DI + PostConstruct).
|
|
7
|
+
*
|
|
8
|
+
* PostProcessor components and their dependencies are registered BEFORE other components
|
|
9
|
+
* (Phase A) and are NOT themselves post-processed.
|
|
10
|
+
*
|
|
11
|
+
* @param {ComponentParams | string} [params] - Optional parameters (name, scope).
|
|
12
|
+
* @returns {ClassDecorator} - The class decorator for the PostProcessor.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* @PostProcessor()
|
|
17
|
+
* class TracingPostProcessor implements ComponentPostProcessor {
|
|
18
|
+
* postProcess<T>(instance: T, Class: any): T {
|
|
19
|
+
* // Wrap with tracing proxy
|
|
20
|
+
* return new Proxy(instance, { ... });
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const PostProcessor: (params?: ComponentParams | string) => ClassDecorator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentType } from '../../types';
|
|
2
|
+
import { defineComponent } from '../componentUtils';
|
|
3
|
+
/**
|
|
4
|
+
* Decorator for defining a PostProcessor component.
|
|
5
|
+
*
|
|
6
|
+
* PostProcessors hook into the component creation lifecycle and can modify or inspect
|
|
7
|
+
* instances after they are fully initialized (constructor + DI + PostConstruct).
|
|
8
|
+
*
|
|
9
|
+
* PostProcessor components and their dependencies are registered BEFORE other components
|
|
10
|
+
* (Phase A) and are NOT themselves post-processed.
|
|
11
|
+
*
|
|
12
|
+
* @param {ComponentParams | string} [params] - Optional parameters (name, scope).
|
|
13
|
+
* @returns {ClassDecorator} - The class decorator for the PostProcessor.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @PostProcessor()
|
|
18
|
+
* class TracingPostProcessor implements ComponentPostProcessor {
|
|
19
|
+
* postProcess<T>(instance: T, Class: any): T {
|
|
20
|
+
* // Wrap with tracing proxy
|
|
21
|
+
* return new Proxy(instance, { ... });
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const PostProcessor = (params) => {
|
|
27
|
+
return defineComponent(ComponentType.POST_PROCESSOR, params || {});
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=PostProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostProcessor.js","sourceRoot":"","sources":["../../../../lib/component/decorators/PostProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,aAAa,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAiC,EAAkB,EAAE;IACjF,OAAO,eAAe,CAAC,aAAa,CAAC,cAAc,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ServiceParams } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator for defining a Service component.
|
|
4
|
+
*
|
|
5
|
+
* @param {ServiceParams | string} [params] - Optional parameters for the service. string is used for defining the name.
|
|
6
|
+
* @returns {ClassDecorator} - The class decorator for the service.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Service: (params?: ServiceParams | string) => ClassDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentType } from '../../types';
|
|
2
|
+
import { defineComponent } from '../componentUtils';
|
|
3
|
+
/**
|
|
4
|
+
* Decorator for defining a Service component.
|
|
5
|
+
*
|
|
6
|
+
* @param {ServiceParams | string} [params] - Optional parameters for the service. string is used for defining the name.
|
|
7
|
+
* @returns {ClassDecorator} - The class decorator for the service.
|
|
8
|
+
*/
|
|
9
|
+
export const Service = (params) => {
|
|
10
|
+
return defineComponent(ComponentType.SERVICE, params);
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=Service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../../../lib/component/decorators/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAsB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAA+B,EAAkB,EAAE;IACzE,OAAO,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Class } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Property decorator to define a strategy.
|
|
4
|
+
*
|
|
5
|
+
* @param {Class | string} Injection - The class of component to inject.
|
|
6
|
+
* @param expression - The expression to evaluate on the injected class.
|
|
7
|
+
* @returns {PropertyDecorator} - The property decorator function.
|
|
8
|
+
*/
|
|
9
|
+
export declare const Strategy: (Injection: Class | string, expression?: (injectedClass: any) => any) => PropertyDecorator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentConstants } from '../../constants';
|
|
2
|
+
import { defineTypedMetadata, getOwnTypedMetadata, getTypedMetadata } from '../../utils/typedMetadata';
|
|
3
|
+
import { assertLegacyDecorator } from './legacyDecorator';
|
|
4
|
+
/**
|
|
5
|
+
* Property decorator to define a strategy.
|
|
6
|
+
*
|
|
7
|
+
* @param {Class | string} Injection - The class of component to inject.
|
|
8
|
+
* @param expression - The expression to evaluate on the injected class.
|
|
9
|
+
* @returns {PropertyDecorator} - The property decorator function.
|
|
10
|
+
*/
|
|
11
|
+
export const Strategy = (Injection, expression) => {
|
|
12
|
+
return (target, propertyKey) => {
|
|
13
|
+
assertLegacyDecorator('Strategy', propertyKey);
|
|
14
|
+
const strategies = getOwnTypedMetadata(ComponentConstants.StrategyKey, target.constructor) || {};
|
|
15
|
+
const injectionName = typeof Injection === 'string' ? Injection : getTypedMetadata(ComponentConstants.NameKey, Injection);
|
|
16
|
+
if (!strategies[propertyKey]) {
|
|
17
|
+
strategies[propertyKey] = injectionName;
|
|
18
|
+
}
|
|
19
|
+
if (expression) {
|
|
20
|
+
const expressions = getOwnTypedMetadata(ComponentConstants.ExpressionKey, target.constructor) || {};
|
|
21
|
+
if (!expressions[propertyKey]) {
|
|
22
|
+
expressions[propertyKey] = expression;
|
|
23
|
+
}
|
|
24
|
+
defineTypedMetadata(ComponentConstants.ExpressionKey, expressions, target.constructor);
|
|
25
|
+
}
|
|
26
|
+
defineTypedMetadata(ComponentConstants.StrategyKey, strategies, target.constructor);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=Strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Strategy.js","sourceRoot":"","sources":["../../../../lib/component/decorators/Strategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,SAAyB,EAAE,UAAmC,EAAqB,EAAE;IAC5G,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAE,EAAE;QAC7C,qBAAqB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAE/C,MAAM,UAAU,GACd,mBAAmB,CAAa,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAE5F,MAAM,aAAa,GACjB,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAS,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAE9G,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7B,UAAU,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC;QAC1C,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,WAAW,GACf,mBAAmB,CAAc,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAE/F,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC9B,WAAW,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC;YACxC,CAAC;YAED,mBAAmB,CAAc,kBAAkB,CAAC,aAAa,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACtG,CAAC;QAED,mBAAmB,CAAa,kBAAkB,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAClG,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ValueOptions } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Property decorator to inject a configuration value from the environment.
|
|
4
|
+
*
|
|
5
|
+
* The value is read from `process.env[key]` when the container builds the component.
|
|
6
|
+
* A `parse` function converts the raw string (`parse: Number` for numbers); `default`
|
|
7
|
+
* is used when the variable is not set, and its *presence* is what counts - `0`, `''`
|
|
8
|
+
* and `null` are honored as defaults. A missing variable on a field without a default
|
|
9
|
+
* fails the component's construction - at registration for a singleton, at the first
|
|
10
|
+
* resolve for a transient - with an error naming the class and the field.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} key - Environment variable name
|
|
13
|
+
* @param {ValueOptions} options - Optional `default` and `parse`
|
|
14
|
+
* @returns {PropertyDecorator} - The property decorator function
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @Value('DB_POOL_MAX', { parse: Number, default: 10 })
|
|
19
|
+
* private poolMax: number;
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Required: no default, boot fails when JWT_SECRET is not set
|
|
25
|
+
* @Value('JWT_SECRET')
|
|
26
|
+
* private jwtSecret: string;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const Value: (key: string, options?: ValueOptions) => PropertyDecorator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComponentConstants } from '../../constants';
|
|
2
|
+
import { defineTypedMetadata, getOwnTypedMetadata } from '../../utils/typedMetadata';
|
|
3
|
+
import { assertLegacyDecorator } from './legacyDecorator';
|
|
4
|
+
/**
|
|
5
|
+
* Property decorator to inject a configuration value from the environment.
|
|
6
|
+
*
|
|
7
|
+
* The value is read from `process.env[key]` when the container builds the component.
|
|
8
|
+
* A `parse` function converts the raw string (`parse: Number` for numbers); `default`
|
|
9
|
+
* is used when the variable is not set, and its *presence* is what counts - `0`, `''`
|
|
10
|
+
* and `null` are honored as defaults. A missing variable on a field without a default
|
|
11
|
+
* fails the component's construction - at registration for a singleton, at the first
|
|
12
|
+
* resolve for a transient - with an error naming the class and the field.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} key - Environment variable name
|
|
15
|
+
* @param {ValueOptions} options - Optional `default` and `parse`
|
|
16
|
+
* @returns {PropertyDecorator} - The property decorator function
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* @Value('DB_POOL_MAX', { parse: Number, default: 10 })
|
|
21
|
+
* private poolMax: number;
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Required: no default, boot fails when JWT_SECRET is not set
|
|
27
|
+
* @Value('JWT_SECRET')
|
|
28
|
+
* private jwtSecret: string;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const Value = (key, options = {}) => {
|
|
32
|
+
return (target, propertyKey) => {
|
|
33
|
+
assertLegacyDecorator('Value', propertyKey);
|
|
34
|
+
const fields = getOwnTypedMetadata(ComponentConstants.ValueKey, target.constructor) || {};
|
|
35
|
+
if (!fields[propertyKey]) {
|
|
36
|
+
fields[propertyKey] = { key, ...options };
|
|
37
|
+
}
|
|
38
|
+
defineTypedMetadata(ComponentConstants.ValueKey, fields, target.constructor);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=Value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Value.js","sourceRoot":"","sources":["../../../../lib/component/decorators/Value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,UAAwB,EAAE,EAAqB,EAAE;IAClF,OAAO,CAAC,MAAc,EAAE,WAAmB,EAAQ,EAAE;QACnD,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAE5C,MAAM,MAAM,GAAgB,mBAAmB,CAAc,kBAAkB,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAEpH,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC5C,CAAC;QAED,mBAAmB,CAAc,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5F,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './Component';
|
|
2
|
+
export * from './Service';
|
|
3
|
+
export * from './PostProcessor';
|
|
4
|
+
export * from './Inject';
|
|
5
|
+
export * from './Value';
|
|
6
|
+
export * from './Implements';
|
|
7
|
+
export * from '../componentUtils';
|
|
8
|
+
export * from './Strategy';
|
|
9
|
+
export * from './PostConstruct';
|
|
10
|
+
export * from './OnStart';
|
|
11
|
+
export * from './OnStop';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './Component';
|
|
2
|
+
export * from './Service';
|
|
3
|
+
export * from './PostProcessor';
|
|
4
|
+
export * from './Inject';
|
|
5
|
+
export * from './Value';
|
|
6
|
+
export * from './Implements';
|
|
7
|
+
export * from '../componentUtils';
|
|
8
|
+
export * from './Strategy';
|
|
9
|
+
export * from './PostConstruct';
|
|
10
|
+
export * from './OnStart';
|
|
11
|
+
export * from './OnStop';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/component/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail with an explanation when a field or method decorator of this package is applied as a
|
|
3
|
+
* standard (TC39) decorator.
|
|
4
|
+
*
|
|
5
|
+
* In that dialect the second argument is a context object instead of the member name, and the
|
|
6
|
+
* first is `undefined` for a field and the function itself for a method. A field decorator then
|
|
7
|
+
* dies on `target.constructor`, and a method decorator writes its metadata onto `Function` and
|
|
8
|
+
* the hook is silently never run.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} decorator - The decorator's name, for the message
|
|
11
|
+
* @param {unknown} propertyKey - The second argument the decorator was called with
|
|
12
|
+
* @returns {void}
|
|
13
|
+
* @throws When the decorator was called with a decorator context
|
|
14
|
+
*/
|
|
15
|
+
export declare const assertLegacyDecorator: (decorator: string, propertyKey: unknown) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail with an explanation when a field or method decorator of this package is applied as a
|
|
3
|
+
* standard (TC39) decorator.
|
|
4
|
+
*
|
|
5
|
+
* In that dialect the second argument is a context object instead of the member name, and the
|
|
6
|
+
* first is `undefined` for a field and the function itself for a method. A field decorator then
|
|
7
|
+
* dies on `target.constructor`, and a method decorator writes its metadata onto `Function` and
|
|
8
|
+
* the hook is silently never run.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} decorator - The decorator's name, for the message
|
|
11
|
+
* @param {unknown} propertyKey - The second argument the decorator was called with
|
|
12
|
+
* @returns {void}
|
|
13
|
+
* @throws When the decorator was called with a decorator context
|
|
14
|
+
*/
|
|
15
|
+
export const assertLegacyDecorator = (decorator, propertyKey) => {
|
|
16
|
+
if (typeof propertyKey !== 'object' || propertyKey === null || !('kind' in propertyKey)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`@${decorator} was applied as a standard (TC39) decorator, but @asenajs/ioc needs legacy decorators: ` +
|
|
20
|
+
'set "experimentalDecorators": true in tsconfig.json. Bun takes that setting from the tsconfig.json ' +
|
|
21
|
+
'of the working directory when it runs TypeScript from source, so a program started from another ' +
|
|
22
|
+
'directory has to ship built output or be started with --tsconfig-override.');
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=legacyDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacyDecorator.js","sourceRoot":"","sources":["../../../../lib/component/decorators/legacyDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,WAAoB,EAAQ,EAAE;IACrF,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,WAAW,CAAC,EAAE,CAAC;QACxF,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CACb,IAAI,SAAS,yFAAyF;QACpG,qGAAqG;QACrG,kGAAkG;QAClG,4EAA4E,CAC/E,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/component/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Component constants used in the IOC (Inversion of Control) container.
|
|
3
|
+
* All keys are Symbols to prevent naming collisions and external manipulation.
|
|
4
|
+
*
|
|
5
|
+
* A class with static members so that anything built on the container can extend it and keep
|
|
6
|
+
* its own metadata keys beside these, under one name.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ComponentConstants {
|
|
9
|
+
static readonly NameKey: unique symbol;
|
|
10
|
+
static readonly ScopeKey: unique symbol;
|
|
11
|
+
static readonly InterfaceKey: unique symbol;
|
|
12
|
+
static readonly DependencyKey: unique symbol;
|
|
13
|
+
static readonly DependencyClassKey: unique symbol;
|
|
14
|
+
static readonly SoftDependencyKey: unique symbol;
|
|
15
|
+
static readonly StrategyKey: unique symbol;
|
|
16
|
+
static readonly ExpressionKey: unique symbol;
|
|
17
|
+
static readonly ValueKey: unique symbol;
|
|
18
|
+
static readonly PostConstructKey: unique symbol;
|
|
19
|
+
static readonly OnStopKey: unique symbol;
|
|
20
|
+
static readonly IOCObjectKey: unique symbol;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Component constants used in the IOC (Inversion of Control) container.
|
|
3
|
+
* All keys are Symbols to prevent naming collisions and external manipulation.
|
|
4
|
+
*
|
|
5
|
+
* A class with static members so that anything built on the container can extend it and keep
|
|
6
|
+
* its own metadata keys beside these, under one name.
|
|
7
|
+
*/
|
|
8
|
+
export class ComponentConstants {
|
|
9
|
+
// Component metadata keys - Symbol based for uniqueness
|
|
10
|
+
static NameKey = Symbol('component:name');
|
|
11
|
+
static ScopeKey = Symbol('component:scope');
|
|
12
|
+
static InterfaceKey = Symbol('component:interface');
|
|
13
|
+
static DependencyKey = Symbol('component:dependency');
|
|
14
|
+
static DependencyClassKey = Symbol('component:dependencyClass');
|
|
15
|
+
static SoftDependencyKey = Symbol('component:softDependency');
|
|
16
|
+
static StrategyKey = Symbol('component:strategy');
|
|
17
|
+
static ExpressionKey = Symbol('component:expression');
|
|
18
|
+
static ValueKey = Symbol('component:value');
|
|
19
|
+
// Start hooks. The key keeps the old name because @PostConstruct is still a supported alias
|
|
20
|
+
// for @OnStart and both must land in the same list.
|
|
21
|
+
static PostConstructKey = Symbol('component:postConstruct');
|
|
22
|
+
static OnStopKey = Symbol('component:onStop');
|
|
23
|
+
static IOCObjectKey = Symbol('component:iocObject');
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ComponentConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComponentConstants.js","sourceRoot":"","sources":["../../../lib/constants/ComponentConstants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IAC7B,wDAAwD;IACjD,MAAM,CAAU,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEnD,MAAM,CAAU,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAErD,MAAM,CAAU,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAE7D,MAAM,CAAU,aAAa,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAE/D,MAAM,CAAU,kBAAkB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAEzE,MAAM,CAAU,iBAAiB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAEvE,MAAM,CAAU,WAAW,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAE3D,MAAM,CAAU,aAAa,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAE/D,MAAM,CAAU,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAE5D,4FAA4F;IAC5F,oDAAoD;IAC7C,MAAM,CAAU,gBAAgB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAErE,MAAM,CAAU,SAAS,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEvD,MAAM,CAAU,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ComponentConstants';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const CORE_SERVICE: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* @description Decorator for marking core services - the infrastructure registered by whoever
|
|
4
|
+
* builds the container (the engine, the lifecycle service, a framework's own services), as
|
|
5
|
+
* opposed to the components an application declares.
|
|
6
|
+
* Core services are always singletons. They are not discovered: register them by hand with
|
|
7
|
+
* `Container.register()` before the components that inject them.
|
|
8
|
+
* @param {string} name - Optional service name (defaults to class name)
|
|
9
|
+
* @returns {Function} Class decorator
|
|
10
|
+
*/
|
|
11
|
+
export declare function CoreService(name?: string): (target: any) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineTypedMetadata, getOwnTypedMetadata } from '../utils/typedMetadata';
|
|
2
|
+
import { ComponentConstants } from '../constants';
|
|
3
|
+
import { Scope } from '../component';
|
|
4
|
+
export const CORE_SERVICE = Symbol('CORE_SERVICE');
|
|
5
|
+
/**
|
|
6
|
+
* @description Decorator for marking core services - the infrastructure registered by whoever
|
|
7
|
+
* builds the container (the engine, the lifecycle service, a framework's own services), as
|
|
8
|
+
* opposed to the components an application declares.
|
|
9
|
+
* Core services are always singletons. They are not discovered: register them by hand with
|
|
10
|
+
* `Container.register()` before the components that inject them.
|
|
11
|
+
* @param {string} name - Optional service name (defaults to class name)
|
|
12
|
+
* @returns {Function} Class decorator
|
|
13
|
+
*/
|
|
14
|
+
export function CoreService(name) {
|
|
15
|
+
return function (target) {
|
|
16
|
+
defineTypedMetadata(CORE_SERVICE, true, target);
|
|
17
|
+
const serviceName = name || target.name;
|
|
18
|
+
defineTypedMetadata(ComponentConstants.NameKey, serviceName, target);
|
|
19
|
+
defineTypedMetadata(ComponentConstants.ScopeKey, Scope.SINGLETON, target);
|
|
20
|
+
// Initialize dependency metadata for injection to work
|
|
21
|
+
if (getOwnTypedMetadata(ComponentConstants.DependencyKey, target) === undefined) {
|
|
22
|
+
defineTypedMetadata(ComponentConstants.DependencyKey, {}, target);
|
|
23
|
+
}
|
|
24
|
+
// Initialize strategy metadata for injection to work
|
|
25
|
+
if (getOwnTypedMetadata(ComponentConstants.StrategyKey, target) === undefined) {
|
|
26
|
+
defineTypedMetadata(ComponentConstants.StrategyKey, {}, target);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=CoreService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreService.js","sourceRoot":"","sources":["../../../lib/decorators/CoreService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAGrC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,OAAO,UAAU,MAAW;QAC1B,mBAAmB,CAAC,YAAY,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC;QAExC,mBAAmB,CAAC,kBAAkB,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QACrE,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAE1E,uDAAuD;QACvD,IAAI,mBAAmB,CAAe,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;YAC9F,mBAAmB,CAAe,kBAAkB,CAAC,aAAa,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAClF,CAAC;QAED,qDAAqD;QACrD,IAAI,mBAAmB,CAAa,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,KAAK,SAAS,EAAE,CAAC;YAC1F,mBAAmB,CAAa,kBAAkB,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CoreService';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getAllFiles: (dirPath: string, arrayOfFiles?: string[]) => string[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Directories that never hold application components. `node_modules` alone is the
|
|
5
|
+
* overwhelming majority of a project's files, and walking it made every boot stat
|
|
6
|
+
* tens of thousands of paths. Dotfolders (`.git`, `.idea`, `.vscode`, ...) are
|
|
7
|
+
* skipped by prefix rather than by name.
|
|
8
|
+
*/
|
|
9
|
+
const EXCLUDED_DIRECTORIES = new Set(['node_modules']);
|
|
10
|
+
const isExcludedDirectory = (name) => name.startsWith('.') || EXCLUDED_DIRECTORIES.has(name);
|
|
11
|
+
export const getAllFiles = (dirPath, arrayOfFiles = []) => {
|
|
12
|
+
// Sorted because `readdirSync` order is not defined: without this, which file wins a
|
|
13
|
+
// name collision - or which config is picked up first - can differ between machines
|
|
14
|
+
const files = fs.readdirSync(dirPath, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
15
|
+
files.forEach((file) => {
|
|
16
|
+
const filePath = path.join(dirPath, file.name);
|
|
17
|
+
if (file.isDirectory()) {
|
|
18
|
+
if (isExcludedDirectory(file.name)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
getAllFiles(filePath, arrayOfFiles);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
arrayOfFiles.push(filePath);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return arrayOfFiles;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=fileHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileHelper.js","sourceRoot":"","sources":["../../../lib/helper/fileHelper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC;;;;;GAKG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;AAEvD,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAE9G,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,eAAyB,EAAE,EAAY,EAAE;IACpF,qFAAqF;IACrF,oFAAoF;IACpF,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5G,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAE/C,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACvB,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnC,OAAO;YACT,CAAC;YAED,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getTypedMetadata } from '../utils/typedMetadata';
|
|
2
|
+
import { ComponentConstants } from '../constants';
|
|
3
|
+
// make it proper class
|
|
4
|
+
export const getStrategyClass = (interfaceNames, injectables) => {
|
|
5
|
+
if (!interfaceNames)
|
|
6
|
+
return [];
|
|
7
|
+
const strategies = Object.values(interfaceNames);
|
|
8
|
+
return injectables
|
|
9
|
+
.filter((injectable) => strategies.includes(injectable.interface))
|
|
10
|
+
.map((injectable) => getTypedMetadata(ComponentConstants.NameKey, injectable.Class));
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=iocHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iocHelper.js","sourceRoot":"","sources":["../../../lib/helper/iocHelper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,uBAAuB;AACvB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,cAAsC,EACtC,WAAkC,EACxB,EAAE;IACZ,IAAI,CAAC,cAAc;QAAE,OAAO,EAAE,CAAC;IAE/B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO,WAAW;SACf,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;SACjE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,gBAAgB,CAAS,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AACjG,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Class, ValueFields, ValueSpec } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Collects the @Value fields of a class as a single record: the whole prototype chain,
|
|
4
|
+
* ancestors first, so a field redeclared in a subclass overwrites the base class entry -
|
|
5
|
+
* the same subclass-wins rule @Inject fields follow.
|
|
6
|
+
*
|
|
7
|
+
* @param ComponentClass - Component class to inspect
|
|
8
|
+
* @returns The merged `{ [field]: { key, default?, parse? } }` record
|
|
9
|
+
*/
|
|
10
|
+
export declare function collectValueFields(ComponentClass: any): ValueFields;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves one @Value field against `process.env`.
|
|
13
|
+
*
|
|
14
|
+
* A set variable wins and goes through `parse` when one was given. An unset variable
|
|
15
|
+
* falls back to `default` - presence of the option, not its truthiness, so `0`, `''`
|
|
16
|
+
* and `null` are respected - and only a field with neither throws.
|
|
17
|
+
*
|
|
18
|
+
* @param spec - The stored field metadata: env key plus options
|
|
19
|
+
* @param Class - The class owning the field, for the error message
|
|
20
|
+
* @param field - The field name, for the error message
|
|
21
|
+
* @returns The resolved value: parsed env string, or the default
|
|
22
|
+
* @throws When the variable is not set and no default was given
|
|
23
|
+
*/
|
|
24
|
+
export declare function readValue(spec: ValueSpec, Class: Class, field: string): unknown;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ComponentConstants } from '../constants';
|
|
2
|
+
import { getChainedTypedMetadata } from '../utils/typedMetadata';
|
|
3
|
+
/**
|
|
4
|
+
* Collects the @Value fields of a class as a single record: the whole prototype chain,
|
|
5
|
+
* ancestors first, so a field redeclared in a subclass overwrites the base class entry -
|
|
6
|
+
* the same subclass-wins rule @Inject fields follow.
|
|
7
|
+
*
|
|
8
|
+
* @param ComponentClass - Component class to inspect
|
|
9
|
+
* @returns The merged `{ [field]: { key, default?, parse? } }` record
|
|
10
|
+
*/
|
|
11
|
+
export function collectValueFields(ComponentClass) {
|
|
12
|
+
return getChainedTypedMetadata(ComponentConstants.ValueKey, ComponentClass);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves one @Value field against `process.env`.
|
|
16
|
+
*
|
|
17
|
+
* A set variable wins and goes through `parse` when one was given. An unset variable
|
|
18
|
+
* falls back to `default` - presence of the option, not its truthiness, so `0`, `''`
|
|
19
|
+
* and `null` are respected - and only a field with neither throws.
|
|
20
|
+
*
|
|
21
|
+
* @param spec - The stored field metadata: env key plus options
|
|
22
|
+
* @param Class - The class owning the field, for the error message
|
|
23
|
+
* @param field - The field name, for the error message
|
|
24
|
+
* @returns The resolved value: parsed env string, or the default
|
|
25
|
+
* @throws When the variable is not set and no default was given
|
|
26
|
+
*/
|
|
27
|
+
export function readValue(spec, Class, field) {
|
|
28
|
+
const raw = process.env[spec.key];
|
|
29
|
+
if (raw !== undefined) {
|
|
30
|
+
return spec.parse ? spec.parse(raw) : raw;
|
|
31
|
+
}
|
|
32
|
+
if ('default' in spec) {
|
|
33
|
+
return spec.default;
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`@Value('${spec.key}') on ${Class.name}.${field}: environment variable is not set and no default was given`);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=valueResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueResolver.js","sourceRoot":"","sources":["../../../lib/helper/valueResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAAmB;IACpD,OAAO,uBAAuB,CAAc,kBAAkB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,IAAe,EAAE,KAAY,EAAE,KAAa;IACpE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAElC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC5C,CAAC;IAED,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,MAAM,IAAI,KAAK,CACb,WAAW,IAAI,CAAC,GAAG,SAAS,KAAK,CAAC,IAAI,IAAI,KAAK,4DAA4D,CAC5G,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './IocApplication';
|
|
2
|
+
export * from './IocEngine';
|
|
3
|
+
export * from './Container';
|
|
4
|
+
export * from './CircularDependencyDetector';
|
|
5
|
+
export * from './component';
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export * from './decorators';
|
|
8
|
+
export * from './helper/valueResolver';
|
|
9
|
+
export * from './lifecycle';
|
|
10
|
+
export * from './logger';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './utils/typedMetadata';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './IocApplication';
|
|
2
|
+
export * from './IocEngine';
|
|
3
|
+
export * from './Container';
|
|
4
|
+
export * from './CircularDependencyDetector';
|
|
5
|
+
export * from './component';
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export * from './decorators';
|
|
8
|
+
export * from './helper/valueResolver';
|
|
9
|
+
export * from './lifecycle';
|
|
10
|
+
export * from './logger';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './utils/typedMetadata';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC"}
|