@adaas/a-concept 0.1.23 → 0.1.25
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/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +3952 -0
- package/dist/index.d.ts +3952 -50
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -6
- package/src/global/A-Abstraction/A-Abstraction-Extend.decorator.ts +18 -13
- package/src/global/A-Component/A-Component.meta.ts +3 -2
- package/src/global/A-Container/A-Container.meta.ts +5 -8
- package/src/global/A-Context/A-Context.class.ts +81 -7
- package/src/global/A-Context/A-Context.error.ts +4 -0
- package/src/global/A-Dependency/A-Dependency-Default.decorator.ts +75 -0
- package/src/global/A-Dependency/A-Dependency-Load.decorator.ts +80 -0
- package/src/global/A-Dependency/A-Dependency-Require.decorator.ts +68 -0
- package/src/global/A-Dependency/A-Dependency.class.ts +33 -0
- package/src/global/A-Dependency/A-Dependency.error.ts +13 -0
- package/src/global/A-Dependency/A-Dependency.types.ts +28 -0
- package/src/global/A-Entity/A-Entity.class.ts +2 -1
- package/src/global/A-Feature/A-Feature-Define.decorator.ts +7 -4
- package/src/global/A-Feature/A-Feature-Extend.decorator.ts +23 -17
- package/src/global/A-Feature/A-Feature.class.ts +12 -1
- package/src/global/A-Feature/A-Feature.types.ts +33 -8
- package/src/global/A-Inject/A-Inject.decorator.ts +4 -2
- package/src/global/A-Inject/A-Inject.types.ts +5 -3
- package/src/global/A-Scope/A-Scope.class.ts +85 -57
- package/src/global/A-Stage/A-Stage.class.ts +22 -2
- package/src/global/A-Stage/A-Stage.error.ts +2 -0
- package/src/global/A-Stage/A-Stage.types.ts +7 -2
- package/src/global/A-StepManager/A-StepManager.class.ts +19 -13
- package/src/helpers/A_Common.helper.ts +101 -0
- package/src/helpers/A_TypeGuards.helper.ts +8 -0
- package/src/index.ts +88 -0
- package/tests/A-Component.test.ts +1 -1
- package/tests/A-Concept.test.ts +58 -10
- package/tests/A-Dependency.test.ts +93 -0
- package/tests/A-Feature.test.ts +11 -11
- package/tests/A-Scope.test.ts +10 -10
- package/tests/A-StepManager.test.ts +60 -11
- package/tsconfig.json +2 -2
- package/tsup.config.ts +32 -0
- package/dist/index.js +0 -112
- package/dist/index.js.map +0 -1
- package/dist/src/constants/env.constants.d.ts +0 -33
- package/dist/src/constants/env.constants.js +0 -47
- package/dist/src/constants/env.constants.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.d.ts +0 -23
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js +0 -89
- package/dist/src/global/A-Abstraction/A-Abstraction-Extend.decorator.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.class.d.ts +0 -74
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js +0 -130
- package/dist/src/global/A-Abstraction/A-Abstraction.class.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.error.d.ts +0 -7
- package/dist/src/global/A-Abstraction/A-Abstraction.error.js +0 -12
- package/dist/src/global/A-Abstraction/A-Abstraction.error.js.map +0 -1
- package/dist/src/global/A-Abstraction/A-Abstraction.types.d.ts +0 -38
- package/dist/src/global/A-Abstraction/A-Abstraction.types.js +0 -3
- package/dist/src/global/A-Abstraction/A-Abstraction.types.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.class.d.ts +0 -33
- package/dist/src/global/A-Caller/A_Caller.class.js +0 -44
- package/dist/src/global/A-Caller/A_Caller.class.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.error.d.ts +0 -7
- package/dist/src/global/A-Caller/A_Caller.error.js +0 -12
- package/dist/src/global/A-Caller/A_Caller.error.js.map +0 -1
- package/dist/src/global/A-Caller/A_Caller.types.d.ts +0 -18
- package/dist/src/global/A-Caller/A_Caller.types.js +0 -3
- package/dist/src/global/A-Caller/A_Caller.types.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.class.d.ts +0 -34
- package/dist/src/global/A-Component/A-Component.class.js +0 -56
- package/dist/src/global/A-Component/A-Component.class.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.constants.d.ts +0 -6
- package/dist/src/global/A-Component/A-Component.constants.js +0 -11
- package/dist/src/global/A-Component/A-Component.constants.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.meta.d.ts +0 -34
- package/dist/src/global/A-Component/A-Component.meta.js +0 -77
- package/dist/src/global/A-Component/A-Component.meta.js.map +0 -1
- package/dist/src/global/A-Component/A-Component.types.d.ts +0 -76
- package/dist/src/global/A-Component/A-Component.types.js +0 -4
- package/dist/src/global/A-Component/A-Component.types.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.class.d.ts +0 -153
- package/dist/src/global/A-Concept/A-Concept.class.js +0 -260
- package/dist/src/global/A-Concept/A-Concept.class.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.constants.d.ts +0 -33
- package/dist/src/global/A-Concept/A-Concept.constants.js +0 -39
- package/dist/src/global/A-Concept/A-Concept.constants.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.meta.d.ts +0 -6
- package/dist/src/global/A-Concept/A-Concept.meta.js +0 -12
- package/dist/src/global/A-Concept/A-Concept.meta.js.map +0 -1
- package/dist/src/global/A-Concept/A-Concept.types.d.ts +0 -66
- package/dist/src/global/A-Concept/A-Concept.types.js +0 -3
- package/dist/src/global/A-Concept/A-Concept.types.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +0 -52
- package/dist/src/global/A-Container/A-Container.class.js +0 -78
- package/dist/src/global/A-Container/A-Container.class.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.constants.d.ts +0 -6
- package/dist/src/global/A-Container/A-Container.constants.js +0 -11
- package/dist/src/global/A-Container/A-Container.constants.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.meta.d.ts +0 -35
- package/dist/src/global/A-Container/A-Container.meta.js +0 -83
- package/dist/src/global/A-Container/A-Container.meta.js.map +0 -1
- package/dist/src/global/A-Container/A-Container.types.d.ts +0 -75
- package/dist/src/global/A-Container/A-Container.types.js +0 -4
- package/dist/src/global/A-Container/A-Container.types.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +0 -361
- package/dist/src/global/A-Context/A-Context.class.js +0 -603
- package/dist/src/global/A-Context/A-Context.class.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.error.d.ts +0 -20
- package/dist/src/global/A-Context/A-Context.error.js +0 -25
- package/dist/src/global/A-Context/A-Context.error.js.map +0 -1
- package/dist/src/global/A-Context/A-Context.types.d.ts +0 -5
- package/dist/src/global/A-Context/A-Context.types.js +0 -3
- package/dist/src/global/A-Context/A-Context.types.js.map +0 -1
- package/dist/src/global/A-Dependency/A-DependencyReference.class.d.ts +0 -0
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js +0 -49
- package/dist/src/global/A-Dependency/A-DependencyReference.class.js.map +0 -1
- package/dist/src/global/A-Dependency/A-DependencyReference.types.d.ts +0 -0
- package/dist/src/global/A-Dependency/A-DependencyReference.types.js +0 -58
- package/dist/src/global/A-Dependency/A-DependencyReference.types.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +0 -214
- package/dist/src/global/A-Entity/A-Entity.class.js +0 -281
- package/dist/src/global/A-Entity/A-Entity.class.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.constants.d.ts +0 -11
- package/dist/src/global/A-Entity/A-Entity.constants.js +0 -17
- package/dist/src/global/A-Entity/A-Entity.constants.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.error.d.ts +0 -7
- package/dist/src/global/A-Entity/A-Entity.error.js +0 -12
- package/dist/src/global/A-Entity/A-Entity.error.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.meta.d.ts +0 -11
- package/dist/src/global/A-Entity/A-Entity.meta.js +0 -18
- package/dist/src/global/A-Entity/A-Entity.meta.js.map +0 -1
- package/dist/src/global/A-Entity/A-Entity.types.d.ts +0 -56
- package/dist/src/global/A-Entity/A-Entity.types.js +0 -5
- package/dist/src/global/A-Entity/A-Entity.types.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.class.d.ts +0 -229
- package/dist/src/global/A-Error/A_Error.class.js +0 -296
- package/dist/src/global/A-Error/A_Error.class.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.constants.d.ts +0 -5
- package/dist/src/global/A-Error/A_Error.constants.js +0 -9
- package/dist/src/global/A-Error/A_Error.constants.js.map +0 -1
- package/dist/src/global/A-Error/A_Error.types.d.ts +0 -93
- package/dist/src/global/A-Error/A_Error.types.js +0 -3
- package/dist/src/global/A-Error/A_Error.types.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.d.ts +0 -15
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js +0 -76
- package/dist/src/global/A-Feature/A-Feature-Define.decorator.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.d.ts +0 -56
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js +0 -119
- package/dist/src/global/A-Feature/A-Feature-Extend.decorator.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.class.d.ts +0 -175
- package/dist/src/global/A-Feature/A-Feature.class.js +0 -318
- package/dist/src/global/A-Feature/A-Feature.class.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.error.d.ts +0 -25
- package/dist/src/global/A-Feature/A-Feature.error.js +0 -33
- package/dist/src/global/A-Feature/A-Feature.error.js.map +0 -1
- package/dist/src/global/A-Feature/A-Feature.types.d.ts +0 -310
- package/dist/src/global/A-Feature/A-Feature.types.js +0 -26
- package/dist/src/global/A-Feature/A-Feature.types.js.map +0 -1
- package/dist/src/global/A-Fragment/A-Fragment.class.d.ts +0 -36
- package/dist/src/global/A-Fragment/A-Fragment.class.js +0 -46
- package/dist/src/global/A-Fragment/A-Fragment.class.js.map +0 -1
- package/dist/src/global/A-Fragment/A-Fragment.types.d.ts +0 -21
- package/dist/src/global/A-Fragment/A-Fragment.types.js +0 -6
- package/dist/src/global/A-Fragment/A-Fragment.types.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.decorator.d.ts +0 -80
- package/dist/src/global/A-Inject/A-Inject.decorator.js +0 -49
- package/dist/src/global/A-Inject/A-Inject.decorator.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.error.d.ts +0 -5
- package/dist/src/global/A-Inject/A-Inject.error.js +0 -10
- package/dist/src/global/A-Inject/A-Inject.error.js.map +0 -1
- package/dist/src/global/A-Inject/A-Inject.types.d.ts +0 -42
- package/dist/src/global/A-Inject/A-Inject.types.js +0 -3
- package/dist/src/global/A-Inject/A-Inject.types.js.map +0 -1
- package/dist/src/global/A-Meta/A-Meta.class.d.ts +0 -97
- package/dist/src/global/A-Meta/A-Meta.class.js +0 -164
- package/dist/src/global/A-Meta/A-Meta.class.js.map +0 -1
- package/dist/src/global/A-Meta/A-Meta.types.d.ts +0 -14
- package/dist/src/global/A-Meta/A-Meta.types.js +0 -3
- package/dist/src/global/A-Meta/A-Meta.types.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +0 -466
- package/dist/src/global/A-Scope/A-Scope.class.js +0 -791
- package/dist/src/global/A-Scope/A-Scope.class.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.error.d.ts +0 -8
- package/dist/src/global/A-Scope/A-Scope.error.js +0 -13
- package/dist/src/global/A-Scope/A-Scope.error.js.map +0 -1
- package/dist/src/global/A-Scope/A-Scope.types.d.ts +0 -81
- package/dist/src/global/A-Scope/A-Scope.types.js +0 -3
- package/dist/src/global/A-Scope/A-Scope.types.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +0 -112
- package/dist/src/global/A-Stage/A-Stage.class.js +0 -240
- package/dist/src/global/A-Stage/A-Stage.class.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.error.d.ts +0 -4
- package/dist/src/global/A-Stage/A-Stage.error.js +0 -11
- package/dist/src/global/A-Stage/A-Stage.error.js.map +0 -1
- package/dist/src/global/A-Stage/A-Stage.types.d.ts +0 -97
- package/dist/src/global/A-Stage/A-Stage.types.js +0 -43
- package/dist/src/global/A-Stage/A-Stage.types.js.map +0 -1
- package/dist/src/global/A-StepManager/A-StepManager.class.d.ts +0 -20
- package/dist/src/global/A-StepManager/A-StepManager.class.js +0 -111
- package/dist/src/global/A-StepManager/A-StepManager.class.js.map +0 -1
- package/dist/src/global/A-StepManager/A-StepManager.error.d.ts +0 -4
- package/dist/src/global/A-StepManager/A-StepManager.error.js +0 -9
- package/dist/src/global/A-StepManager/A-StepManager.error.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.class.d.ts +0 -130
- package/dist/src/global/ASEID/ASEID.class.js +0 -167
- package/dist/src/global/ASEID/ASEID.class.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.constants.d.ts +0 -0
- package/dist/src/global/ASEID/ASEID.constants.js +0 -2
- package/dist/src/global/ASEID/ASEID.constants.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.error.d.ts +0 -5
- package/dist/src/global/ASEID/ASEID.error.js +0 -10
- package/dist/src/global/ASEID/ASEID.error.js.map +0 -1
- package/dist/src/global/ASEID/ASEID.types.d.ts +0 -65
- package/dist/src/global/ASEID/ASEID.types.js +0 -5
- package/dist/src/global/ASEID/ASEID.types.js.map +0 -1
- package/dist/src/helpers/A_Common.helper.d.ts +0 -28
- package/dist/src/helpers/A_Common.helper.js +0 -170
- package/dist/src/helpers/A_Common.helper.js.map +0 -1
- package/dist/src/helpers/A_Formatter.helper.d.ts +0 -35
- package/dist/src/helpers/A_Formatter.helper.js +0 -62
- package/dist/src/helpers/A_Formatter.helper.js.map +0 -1
- package/dist/src/helpers/A_Identity.helper.d.ts +0 -29
- package/dist/src/helpers/A_Identity.helper.js +0 -43
- package/dist/src/helpers/A_Identity.helper.js.map +0 -1
- package/dist/src/helpers/A_TypeGuards.helper.d.ts +0 -207
- package/dist/src/helpers/A_TypeGuards.helper.js +0 -296
- package/dist/src/helpers/A_TypeGuards.helper.js.map +0 -1
- package/dist/src/types/A_Common.types.d.ts +0 -36
- package/dist/src/types/A_Common.types.js +0 -3
- package/dist/src/types/A_Common.types.js.map +0 -1
- package/index.ts +0 -81
- package/src/global/A-Dependency/A-DependencyReference.class.ts +0 -61
- package/src/global/A-Dependency/A-DependencyReference.types.ts +0 -61
- package/trace-require.js +0 -46
- package/tsconfig.build.json +0 -58
|
@@ -4,6 +4,7 @@ import { A_TYPES__FeatureExtendDecoratorConfig, A_TYPES__FeatureExtendDecoratorD
|
|
|
4
4
|
import { A_TypeGuards } from "@adaas/a-concept/helpers/A_TypeGuards.helper";
|
|
5
5
|
import { A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.constants";
|
|
6
6
|
import { A_FeatureError } from "./A-Feature.error";
|
|
7
|
+
import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
@@ -64,7 +65,7 @@ export function A_Feature_Extend(
|
|
|
64
65
|
descriptor: A_TYPES__FeatureExtendDecoratorDescriptor
|
|
65
66
|
) {
|
|
66
67
|
// for error messages
|
|
67
|
-
const componentName = (target
|
|
68
|
+
const componentName = A_CommonHelper.getComponentName(target)
|
|
68
69
|
|
|
69
70
|
if (!A_TypeGuards.isAllowedForFeatureExtension(target))
|
|
70
71
|
throw new A_FeatureError(
|
|
@@ -74,8 +75,9 @@ export function A_Feature_Extend(
|
|
|
74
75
|
|
|
75
76
|
let targetRegexp: RegExp;
|
|
76
77
|
let behavior: 'sync' | 'async' = 'sync';
|
|
77
|
-
let before: string
|
|
78
|
-
let after: string
|
|
78
|
+
let before: string = '';
|
|
79
|
+
let after: string = '';
|
|
80
|
+
let override: string = '';
|
|
79
81
|
let include: Array<A_TYPES__FeatureExtendDecoratorScopeItem> = [];
|
|
80
82
|
let exclude: Array<A_TYPES__FeatureExtendDecoratorScopeItem> = [];
|
|
81
83
|
let throwOnError: boolean = true;
|
|
@@ -104,19 +106,22 @@ export function A_Feature_Extend(
|
|
|
104
106
|
behavior = param1.behavior || behavior;
|
|
105
107
|
throwOnError = param1.throwOnError !== undefined ? param1.throwOnError : throwOnError;
|
|
106
108
|
|
|
107
|
-
before = param1.before
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
before = A_TypeGuards.isArray(param1.before)
|
|
110
|
+
? new RegExp(`^${param1.before.join('|').replace(/\./g, '\\.')}$`).source
|
|
111
|
+
: param1.before instanceof RegExp
|
|
112
|
+
? param1.before.source
|
|
113
|
+
: ''
|
|
114
|
+
after = A_TypeGuards.isArray(param1.after)
|
|
115
|
+
? new RegExp(`^${param1.after.join('|').replace(/\./g, '\\.')}$`).source
|
|
116
|
+
: param1.after instanceof RegExp
|
|
117
|
+
? param1.after.source
|
|
118
|
+
: ''
|
|
119
|
+
|
|
120
|
+
override = A_TypeGuards.isArray(param1.override)
|
|
121
|
+
? new RegExp(`^${param1.override.join('|').replace(/\./g, '\\.')}$`).source
|
|
122
|
+
: param1.override instanceof RegExp
|
|
123
|
+
? param1.override.source
|
|
124
|
+
: ''
|
|
120
125
|
break;
|
|
121
126
|
|
|
122
127
|
default:
|
|
@@ -161,7 +166,8 @@ export function A_Feature_Extend(
|
|
|
161
166
|
behavior,
|
|
162
167
|
before,
|
|
163
168
|
after,
|
|
164
|
-
throwOnError
|
|
169
|
+
throwOnError,
|
|
170
|
+
override
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
if (existedIndex !== -1) {
|
|
@@ -135,6 +135,12 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
135
135
|
* The Scope allocated for the Feature Execution
|
|
136
136
|
*/
|
|
137
137
|
get scope(): A_Scope { return A_Context.scope(this); }
|
|
138
|
+
/**
|
|
139
|
+
* The number of stages in the feature
|
|
140
|
+
*/
|
|
141
|
+
get size(): number {
|
|
142
|
+
return this._stages.length;
|
|
143
|
+
}
|
|
138
144
|
|
|
139
145
|
/**
|
|
140
146
|
* This method checks if the A-Feature is done
|
|
@@ -285,7 +291,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
285
291
|
this._name = params.name;
|
|
286
292
|
|
|
287
293
|
// 2) get scope from where feature is called
|
|
288
|
-
const componentScope = A_Context.scope(params.component);
|
|
294
|
+
const componentScope = params.scope ? params.scope : A_Context.scope(params.component);
|
|
289
295
|
|
|
290
296
|
// 3) create caller wrapper for the simple injection of the caller component
|
|
291
297
|
this._caller = new A_Caller<T>(params.component);
|
|
@@ -357,7 +363,10 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
357
363
|
* @returns
|
|
358
364
|
*/
|
|
359
365
|
async completed(): Promise<void> {
|
|
366
|
+
|
|
360
367
|
this._state = A_TYPES__FeatureState.COMPLETED;
|
|
368
|
+
|
|
369
|
+
this.scope.destroy();
|
|
361
370
|
}
|
|
362
371
|
/**
|
|
363
372
|
* This method marks the feature as failed and throws an error
|
|
@@ -390,6 +399,8 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
|
|
|
390
399
|
}
|
|
391
400
|
|
|
392
401
|
this._state = A_TYPES__FeatureState.INTERRUPTED;
|
|
402
|
+
|
|
403
|
+
this.scope.destroy();
|
|
393
404
|
}
|
|
394
405
|
|
|
395
406
|
|
|
@@ -38,6 +38,13 @@ export type A_TYPES__Feature_InitWithComponent<T extends A_TYPES__FeatureAvailab
|
|
|
38
38
|
* [!] Could be Container, Entity, Component or Command
|
|
39
39
|
*/
|
|
40
40
|
component: T,
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* In case when Entity is not attached to the scope can be used to transparently show dependencies
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
scope?: A_Scope
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* Feature initialization type using template
|
|
@@ -259,11 +266,16 @@ export type A_TYPES__FeatureExtendDecoratorConfig = {
|
|
|
259
266
|
* ```ts
|
|
260
267
|
* @A_Feature.Extend({
|
|
261
268
|
* name: 'load',
|
|
262
|
-
* before: ['Component1.methodName',
|
|
269
|
+
* before: ['Component1.methodName', 'Component2.methodName2']
|
|
270
|
+
* })
|
|
271
|
+
* // OR
|
|
272
|
+
* @A_Feature.Extend({
|
|
273
|
+
* name: 'load',
|
|
274
|
+
* before: /Component2\..+/
|
|
263
275
|
* })
|
|
264
276
|
* ```
|
|
265
277
|
*/
|
|
266
|
-
before: Array<string | RegExp
|
|
278
|
+
before: Array<string> | RegExp
|
|
267
279
|
|
|
268
280
|
/**
|
|
269
281
|
* Allows to define the order of the execution of the method.
|
|
@@ -275,19 +287,28 @@ export type A_TYPES__FeatureExtendDecoratorConfig = {
|
|
|
275
287
|
* ```ts
|
|
276
288
|
* @A_Feature.Extend({
|
|
277
289
|
* name: 'load',
|
|
278
|
-
*
|
|
290
|
+
* after: ['Component1.methodName', 'Component2.methodName2']
|
|
291
|
+
* })
|
|
292
|
+
* // OR
|
|
293
|
+
* @A_Feature.Extend({
|
|
294
|
+
* name: 'load',
|
|
295
|
+
* after: /Component2\..+/
|
|
279
296
|
* })
|
|
280
297
|
* ```
|
|
281
298
|
*
|
|
282
299
|
*/
|
|
283
|
-
after: Array<string | RegExp
|
|
284
|
-
|
|
300
|
+
after: Array<string> | RegExp
|
|
285
301
|
/**
|
|
286
302
|
* Indicates whether to throw an error if the step fails.
|
|
287
303
|
*
|
|
288
304
|
* [!] By default is true
|
|
289
305
|
*/
|
|
290
306
|
throwOnError: boolean
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Allows to override particular steps in the feature sequence by provided names [Component].[Method] or by regexp
|
|
310
|
+
*/
|
|
311
|
+
override: Array<string> | RegExp
|
|
291
312
|
}
|
|
292
313
|
/**
|
|
293
314
|
* Scope item that can be used in A_Extend decorator configuration
|
|
@@ -342,20 +363,24 @@ export type A_TYPES__FeatureExtendDecoratorMeta = {
|
|
|
342
363
|
* [!] In case the method has circular dependencies it will Throw an error.
|
|
343
364
|
*
|
|
344
365
|
*/
|
|
345
|
-
before: string
|
|
366
|
+
before: string
|
|
346
367
|
/**
|
|
347
368
|
* Allows to define the order of the execution of the method.
|
|
348
369
|
*
|
|
349
370
|
* [!] In case the method has circular dependencies it will Throw an error.
|
|
350
371
|
*
|
|
351
372
|
*/
|
|
352
|
-
after: string
|
|
373
|
+
after: string
|
|
353
374
|
/**
|
|
354
375
|
* Indicates whether to throw an error if the step fails.
|
|
355
376
|
*
|
|
356
377
|
* [!] By default is true
|
|
357
378
|
*/
|
|
358
|
-
throwOnError: boolean
|
|
379
|
+
throwOnError: boolean,
|
|
380
|
+
/**
|
|
381
|
+
* Allows to override particular steps in the feature sequence by provided names [Component].[Method] or by regexp
|
|
382
|
+
*/
|
|
383
|
+
override: string
|
|
359
384
|
}
|
|
360
385
|
|
|
361
386
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
A_TYPES__A_InjectDecorator_EntityInjectionInstructions,
|
|
3
|
+
A_TYPES__A_InjectDecorator_Meta,
|
|
3
4
|
A_TYPES__A_InjectDecoratorReturn,
|
|
4
5
|
A_TYPES__InjectableConstructors,
|
|
5
6
|
A_TYPES__InjectableTargets
|
|
@@ -21,6 +22,7 @@ import { A_TYPES__Fragment_Constructor } from "@adaas/a-concept/global/A-Fragmen
|
|
|
21
22
|
import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
|
|
22
23
|
import { A_TYPES__Scope_Constructor } from "@adaas/a-concept/global/A-Scope/A-Scope.types";
|
|
23
24
|
import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
|
|
25
|
+
import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -120,7 +122,7 @@ export function A_Inject(
|
|
|
120
122
|
parameterIndex: number
|
|
121
123
|
) {
|
|
122
124
|
// for Error handling purposes
|
|
123
|
-
const componentName =
|
|
125
|
+
const componentName = A_CommonHelper.getComponentName(target)
|
|
124
126
|
|
|
125
127
|
if (!A_TypeGuards.isTargetAvailableForInjection(target)) {
|
|
126
128
|
throw new A_InjectError(
|
|
@@ -146,7 +148,7 @@ export function A_Inject(
|
|
|
146
148
|
// get existing meta or create a new one
|
|
147
149
|
const existedMeta = A_Context.meta(target).get(metaKey) || new A_Meta();
|
|
148
150
|
// get existing injections for the method or create a new array
|
|
149
|
-
const paramsArray = existedMeta.get(method) || [];
|
|
151
|
+
const paramsArray: A_TYPES__A_InjectDecorator_Meta = existedMeta.get(method) || [];
|
|
150
152
|
|
|
151
153
|
// set the parameter injection info
|
|
152
154
|
paramsArray[parameterIndex] = {
|
|
@@ -32,9 +32,11 @@ export type A_TYPES__A_InjectDecoratorReturn<T = any> = (
|
|
|
32
32
|
|
|
33
33
|
export type A_TYPES__A_InjectDecorator_Meta = Array<{
|
|
34
34
|
target: A_TYPES__InjectableConstructors
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
require?: boolean
|
|
36
|
+
load?: string
|
|
37
|
+
defaultArgs?: any,
|
|
38
|
+
create?: boolean
|
|
39
|
+
instructions?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions>,
|
|
38
40
|
}>;
|
|
39
41
|
|
|
40
42
|
/**
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
A_TYPES__A_InjectDecorator_EntityInjectionInstructions,
|
|
11
11
|
A_TYPES__A_InjectDecorator_EntityInjectionQuery,
|
|
12
12
|
A_TYPES__InjectableConstructors,
|
|
13
|
+
A_TYPES__InjectableTargets,
|
|
13
14
|
} from "@adaas/a-concept/global/A-Inject/A-Inject.types";
|
|
14
15
|
import { A_Fragment } from "../A-Fragment/A-Fragment.class";
|
|
15
16
|
import { A_Context } from "../A-Context/A-Context.class";
|
|
@@ -267,6 +268,31 @@ export class A_Scope<
|
|
|
267
268
|
protected initFragments(_fragments?: _FragmentType) { _fragments?.forEach(this.register.bind(this)); }
|
|
268
269
|
|
|
269
270
|
|
|
271
|
+
// ==========================================================================
|
|
272
|
+
// --------------------Scope Public Methods-----------------------------------
|
|
273
|
+
// ==========================================================================
|
|
274
|
+
/**
|
|
275
|
+
* This method is used to destroy the scope and all its registered components, fragments and entities
|
|
276
|
+
*
|
|
277
|
+
* [!] This method deregisters all components, fragments and entities from the A-Context
|
|
278
|
+
* [!] This method also clears all internal registries and collections
|
|
279
|
+
*/
|
|
280
|
+
destroy() {
|
|
281
|
+
this._components.forEach(component => A_Context.deregister(component));
|
|
282
|
+
this._fragments.forEach(fragment => A_Context.deregister(fragment));
|
|
283
|
+
this._entities.forEach(entity => A_Context.deregister(entity));
|
|
284
|
+
|
|
285
|
+
this._components.clear();
|
|
286
|
+
this._errors.clear();
|
|
287
|
+
this._fragments.clear();
|
|
288
|
+
this._entities.clear();
|
|
289
|
+
|
|
290
|
+
if (this.issuer()) {
|
|
291
|
+
A_Context.deallocate(this);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
270
296
|
/**
|
|
271
297
|
* Returns the issuer of the scope, useful for debugging and tracking purposes
|
|
272
298
|
*
|
|
@@ -499,7 +525,7 @@ export class A_Scope<
|
|
|
499
525
|
*/
|
|
500
526
|
name: string
|
|
501
527
|
): A_TYPES__Fragment_Constructor<T>
|
|
502
|
-
resolveConstructor<T extends A_TYPES__ScopeResolvableComponents>(name: string): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> {
|
|
528
|
+
resolveConstructor<T extends A_TYPES__ScopeResolvableComponents>(name: string): A_TYPES__Entity_Constructor<T> | A_TYPES__Component_Constructor<T> | A_TYPES__Fragment_Constructor<T> | undefined {
|
|
503
529
|
// 1) Check components
|
|
504
530
|
const component = Array.from(this.allowedComponents).find(
|
|
505
531
|
c => c.name === name
|
|
@@ -527,10 +553,7 @@ export class A_Scope<
|
|
|
527
553
|
return this._parent.resolveConstructor(name) as any;
|
|
528
554
|
}
|
|
529
555
|
|
|
530
|
-
|
|
531
|
-
A_ScopeError.ResolutionError,
|
|
532
|
-
`Component or Entity with name ${name} not found in the scope ${this.name}`
|
|
533
|
-
);
|
|
556
|
+
return undefined;
|
|
534
557
|
}
|
|
535
558
|
|
|
536
559
|
|
|
@@ -550,25 +573,25 @@ export class A_Scope<
|
|
|
550
573
|
* Provide a component constructor to resolve its instance from the scope
|
|
551
574
|
*/
|
|
552
575
|
component: A_TYPES__Component_Constructor<T>
|
|
553
|
-
): T
|
|
576
|
+
): T | undefined
|
|
554
577
|
resolve<T extends A_TYPES__Component_Constructor[]>(
|
|
555
578
|
/**
|
|
556
579
|
* Provide an array of component constructors to resolve their instances from the scope
|
|
557
580
|
*/
|
|
558
581
|
components: [...T]
|
|
559
|
-
): Array<InstanceType<T[number]>>
|
|
582
|
+
): Array<InstanceType<T[number]>> | undefined
|
|
560
583
|
resolve<T extends A_Fragment>(
|
|
561
584
|
/**
|
|
562
585
|
* Provide a fragment constructor to resolve its instance from the scope
|
|
563
586
|
*/
|
|
564
587
|
fragment: A_TYPES__Fragment_Constructor<T>
|
|
565
|
-
): T
|
|
588
|
+
): T | undefined
|
|
566
589
|
resolve<T extends A_TYPES__Fragment_Constructor[]>(
|
|
567
590
|
/**
|
|
568
591
|
* Provide an array of fragment constructors to resolve their instances from the scope
|
|
569
592
|
*/
|
|
570
593
|
fragments: [...T]
|
|
571
|
-
): Array<InstanceType<T[number]>>
|
|
594
|
+
): Array<InstanceType<T[number]>> | undefined
|
|
572
595
|
resolve<T extends A_Entity>(
|
|
573
596
|
/**
|
|
574
597
|
* Provide an entity constructor to resolve its instance or an array of instances from the scope
|
|
@@ -582,7 +605,7 @@ export class A_Scope<
|
|
|
582
605
|
* Provide an entity constructor to resolve its instance from the scope
|
|
583
606
|
*/
|
|
584
607
|
scope: new (...args: any[]) => T
|
|
585
|
-
): T
|
|
608
|
+
): T | undefined
|
|
586
609
|
resolve<T extends A_Entity>(
|
|
587
610
|
/**
|
|
588
611
|
* Provide an entity constructor to resolve its instance or an array of instances from the scope
|
|
@@ -595,7 +618,7 @@ export class A_Scope<
|
|
|
595
618
|
): Array<T>
|
|
596
619
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
597
620
|
constructorName: string
|
|
598
|
-
): T
|
|
621
|
+
): T | undefined
|
|
599
622
|
// base definition
|
|
600
623
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
601
624
|
/**
|
|
@@ -603,21 +626,21 @@ export class A_Scope<
|
|
|
603
626
|
*/
|
|
604
627
|
param1: A_TYPES__InjectableConstructors,
|
|
605
628
|
|
|
606
|
-
): T | Array<T>
|
|
629
|
+
): T | Array<T> | undefined
|
|
607
630
|
resolve<T extends A_TYPES__ScopeLinkedConstructors>(
|
|
608
631
|
/**
|
|
609
632
|
* Provide a component, fragment or entity constructor or an array of constructors to resolve its instance(s) from the scope
|
|
610
633
|
*/
|
|
611
634
|
param1: InstanceType<T>,
|
|
612
635
|
|
|
613
|
-
): T | Array<T>
|
|
636
|
+
): T | Array<T> | undefined
|
|
614
637
|
resolve<T extends A_TYPES__ScopeResolvableComponents>(
|
|
615
638
|
/**
|
|
616
639
|
* Provide a component, fragment or entity constructor or an array of constructors to resolve its instance(s) from the scope
|
|
617
640
|
*/
|
|
618
641
|
param1: A_TYPES__InjectableConstructors | Array<A_TYPES__InjectableConstructors>,
|
|
619
642
|
param2?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions>
|
|
620
|
-
): T | Array<T> {
|
|
643
|
+
): T | Array<T> | undefined {
|
|
621
644
|
switch (true) {
|
|
622
645
|
case A_TypeGuards.isArray(param1): {
|
|
623
646
|
return param1.map(c => {
|
|
@@ -637,7 +660,9 @@ export class A_Scope<
|
|
|
637
660
|
}
|
|
638
661
|
|
|
639
662
|
default: {
|
|
640
|
-
throw new
|
|
663
|
+
throw new A_ScopeError(
|
|
664
|
+
A_ScopeError.ResolutionError,
|
|
665
|
+
`Invalid parameter provided to resolve method: ${param1} in scope ${this.name}`);
|
|
641
666
|
}
|
|
642
667
|
}
|
|
643
668
|
}
|
|
@@ -663,7 +688,7 @@ export class A_Scope<
|
|
|
663
688
|
* Provide the name of the component, fragment or entity to resolve
|
|
664
689
|
*/
|
|
665
690
|
name: string
|
|
666
|
-
): _EntityType[number] | InstanceType<_ComponentType[number]> | _FragmentType[number] {
|
|
691
|
+
): _EntityType[number] | InstanceType<_ComponentType[number]> | _FragmentType[number] | undefined {
|
|
667
692
|
// 1) Check components
|
|
668
693
|
const component = Array.from(this.allowedComponents).find(
|
|
669
694
|
c => c.name === name
|
|
@@ -691,10 +716,7 @@ export class A_Scope<
|
|
|
691
716
|
return this._parent.resolveByName(name) as any;
|
|
692
717
|
}
|
|
693
718
|
|
|
694
|
-
|
|
695
|
-
A_ScopeError.ResolutionError,
|
|
696
|
-
`Component or Entity with name ${name} not found in the scope ${this.name}`
|
|
697
|
-
);
|
|
719
|
+
return undefined;
|
|
698
720
|
}
|
|
699
721
|
|
|
700
722
|
/**
|
|
@@ -707,22 +729,12 @@ export class A_Scope<
|
|
|
707
729
|
private resolveOnce(
|
|
708
730
|
component: any,
|
|
709
731
|
instructions?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions>
|
|
710
|
-
): A_TYPES__ScopeResolvableComponents | A_Scope | A_TYPES__ScopeLinkedComponents | Array<A_TYPES__ScopeResolvableComponents> {
|
|
711
|
-
|
|
712
|
-
const componentName = A_TypeGuards.isFunction(component) ? component.name : component.constructor.name || String(component);
|
|
732
|
+
): A_TYPES__ScopeResolvableComponents | A_Scope | A_TYPES__ScopeLinkedComponents | Array<A_TYPES__ScopeResolvableComponents> | undefined {
|
|
713
733
|
|
|
734
|
+
const componentName = A_CommonHelper.getComponentName(component);
|
|
714
735
|
|
|
715
736
|
if (!component || !this.has(component))
|
|
716
|
-
|
|
717
|
-
A_ScopeError.ResolutionError,
|
|
718
|
-
`Injected Component ${componentName} not found in the scope`
|
|
719
|
-
);
|
|
720
|
-
|
|
721
|
-
if (A_TypeGuards.isScopeConstructor(component))
|
|
722
|
-
component
|
|
723
|
-
|
|
724
|
-
if (typeof component == 'function' && component.name === 'A_Scope')
|
|
725
|
-
component
|
|
737
|
+
return undefined;
|
|
726
738
|
|
|
727
739
|
switch (true) {
|
|
728
740
|
case A_TypeGuards.isConstructorAllowedForScopeAllocation(component): {
|
|
@@ -750,7 +762,7 @@ export class A_Scope<
|
|
|
750
762
|
|
|
751
763
|
private resolveIssuer(
|
|
752
764
|
ctor: A_TYPES__ScopeLinkedConstructors
|
|
753
|
-
): A_TYPES__ScopeLinkedComponents {
|
|
765
|
+
): A_TYPES__ScopeLinkedComponents | undefined {
|
|
754
766
|
|
|
755
767
|
const issuer = this.issuer();
|
|
756
768
|
|
|
@@ -765,10 +777,7 @@ export class A_Scope<
|
|
|
765
777
|
return this._parent.resolveIssuer(ctor);
|
|
766
778
|
}
|
|
767
779
|
|
|
768
|
-
|
|
769
|
-
A_ScopeError.ResolutionError,
|
|
770
|
-
`Issuer ${ctor.name} not found in the scope ${this.name}`
|
|
771
|
-
);
|
|
780
|
+
return undefined;
|
|
772
781
|
}
|
|
773
782
|
|
|
774
783
|
/**
|
|
@@ -783,7 +792,7 @@ export class A_Scope<
|
|
|
783
792
|
private resolveEntity<T extends A_Entity>(
|
|
784
793
|
entity: A_TYPES__Entity_Constructor<T>,
|
|
785
794
|
instructions?: Partial<A_TYPES__A_InjectDecorator_EntityInjectionInstructions<T>>
|
|
786
|
-
): T | Array<T> {
|
|
795
|
+
): T | Array<T> | undefined {
|
|
787
796
|
|
|
788
797
|
const query = instructions?.query || {} as Partial<A_TYPES__A_InjectDecorator_EntityInjectionQuery<T>>;
|
|
789
798
|
const count = instructions?.pagination?.count || 1;
|
|
@@ -806,10 +815,7 @@ export class A_Scope<
|
|
|
806
815
|
return this._parent.resolveEntity(entity, instructions);
|
|
807
816
|
|
|
808
817
|
default:
|
|
809
|
-
|
|
810
|
-
A_ScopeError.ResolutionError,
|
|
811
|
-
`Entity ${entity.name} not found in the scope ${this.name}`
|
|
812
|
-
);
|
|
818
|
+
return undefined;
|
|
813
819
|
}
|
|
814
820
|
}
|
|
815
821
|
/**
|
|
@@ -884,7 +890,7 @@ export class A_Scope<
|
|
|
884
890
|
* @param fragment
|
|
885
891
|
* @returns
|
|
886
892
|
*/
|
|
887
|
-
private resolveFragment<T extends A_Fragment>(fragment: A_TYPES__Fragment_Constructor<T>): _FragmentType[number] {
|
|
893
|
+
private resolveFragment<T extends A_Fragment>(fragment: A_TYPES__Fragment_Constructor<T>): _FragmentType[number] | undefined {
|
|
888
894
|
const fragmentInstancePresented = this._fragments.get(fragment);
|
|
889
895
|
|
|
890
896
|
switch (true) {
|
|
@@ -895,10 +901,7 @@ export class A_Scope<
|
|
|
895
901
|
return this._parent.resolveFragment(fragment);
|
|
896
902
|
|
|
897
903
|
default:
|
|
898
|
-
|
|
899
|
-
A_ScopeError.ResolutionError,
|
|
900
|
-
`Fragment ${fragment.name} not found in the scope ${this.name}`
|
|
901
|
-
);
|
|
904
|
+
return undefined;
|
|
902
905
|
}
|
|
903
906
|
}
|
|
904
907
|
/**
|
|
@@ -916,7 +919,7 @@ export class A_Scope<
|
|
|
916
919
|
* @param component
|
|
917
920
|
* @returns
|
|
918
921
|
*/
|
|
919
|
-
private resolveComponent<T extends A_Component>(component: A_TYPES__Component_Constructor<T>): InstanceType<_ComponentType[number]> {
|
|
922
|
+
private resolveComponent<T extends A_Component>(component: A_TYPES__Component_Constructor<T>): InstanceType<_ComponentType[number]> | undefined {
|
|
920
923
|
|
|
921
924
|
// The idea here that in case when Scope has no exact component we have to resolve it from the _parent
|
|
922
925
|
// BUT: if it's not presented in _parent we have to check for inheritance
|
|
@@ -935,15 +938,40 @@ export class A_Scope<
|
|
|
935
938
|
|
|
936
939
|
const resolvedArgs = (argsMeta?.get('constructor') || [])
|
|
937
940
|
.map(arg => {
|
|
938
|
-
|
|
941
|
+
// for Error handling purposes
|
|
942
|
+
const componentName = A_CommonHelper.getComponentName(arg.target)
|
|
943
|
+
|
|
944
|
+
if ('instructions' in arg && !!arg.instructions) {
|
|
939
945
|
const { target, instructions } = arg
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
946
|
+
const dependency = this.resolve(target as any, instructions);
|
|
947
|
+
if (!dependency)
|
|
948
|
+
throw new A_ScopeError(
|
|
949
|
+
A_ScopeError.ResolutionError,
|
|
950
|
+
`Unable to resolve dependency ${componentName} for component ${component.name} in scope ${this.name}`
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
return dependency;
|
|
954
|
+
} else {
|
|
955
|
+
const { target, require, create, defaultArgs } = arg;
|
|
956
|
+
|
|
957
|
+
let dependency = this.resolve(target as any);
|
|
958
|
+
|
|
959
|
+
if (create && !dependency && A_TypeGuards.isAllowedForDependencyDefaultCreation(target)) {
|
|
960
|
+
const newDependency = new target(...defaultArgs);
|
|
961
|
+
|
|
962
|
+
this.register(newDependency);
|
|
963
|
+
return newDependency;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
if (require && !dependency) {
|
|
967
|
+
throw new A_ScopeError(
|
|
968
|
+
A_ScopeError.ResolutionError,
|
|
969
|
+
`Unable to resolve required dependency ${componentName} for component ${component.name} in scope ${this.name}`
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
return dependency;
|
|
944
974
|
}
|
|
945
|
-
// TODO: Fix types mismatch here
|
|
946
|
-
return this.resolve<T>(arg.target as any);
|
|
947
975
|
});
|
|
948
976
|
|
|
949
977
|
const newComponent = new component(...resolvedArgs)
|
|
@@ -1128,7 +1156,7 @@ export class A_Scope<
|
|
|
1128
1156
|
`Fragment ${param1.constructor.name} is already registered in the scope ${this.name}`
|
|
1129
1157
|
);
|
|
1130
1158
|
else {
|
|
1131
|
-
const componentName =
|
|
1159
|
+
const componentName = A_CommonHelper.getComponentName(param1);
|
|
1132
1160
|
|
|
1133
1161
|
throw new A_ScopeError(
|
|
1134
1162
|
A_ScopeError.RegistrationError,
|
|
@@ -12,6 +12,7 @@ import { A_TypeGuards } from "@adaas/a-concept/helpers/A_TypeGuards.helper";
|
|
|
12
12
|
import { A_TYPES__ScopeResolvableComponents } from "../A-Scope/A-Scope.types";
|
|
13
13
|
import { A_TYPES__Container_Constructor } from "../A-Container/A-Container.types";
|
|
14
14
|
import { A_TYPES__Component_Constructor } from "../A-Component/A-Component.types";
|
|
15
|
+
import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
|
|
@@ -141,11 +142,30 @@ export class A_Stage {
|
|
|
141
142
|
case A_TypeGuards.isFeatureConstructor(arg.target):
|
|
142
143
|
return this._feature;
|
|
143
144
|
|
|
144
|
-
case A_TypeGuards.isEntityConstructor(arg.target) && 'instructions' in arg:
|
|
145
|
+
case A_TypeGuards.isEntityConstructor(arg.target) && 'instructions' in arg && !!arg.instructions:
|
|
145
146
|
return scope.resolve(arg.target, arg.instructions)
|
|
146
147
|
|
|
147
|
-
default:
|
|
148
|
+
default: {
|
|
149
|
+
const { target, require, create, defaultArgs } = arg;
|
|
150
|
+
|
|
151
|
+
let dependency = scope.resolve(target as any);
|
|
152
|
+
|
|
153
|
+
if (create && !dependency && A_TypeGuards.isAllowedForDependencyDefaultCreation(target)) {
|
|
154
|
+
const newDependency = new target(...defaultArgs);
|
|
155
|
+
|
|
156
|
+
scope.register(newDependency);
|
|
157
|
+
return newDependency;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (require && !dependency) {
|
|
161
|
+
throw new A_StageError(
|
|
162
|
+
A_StageError.ArgumentsResolutionError,
|
|
163
|
+
`Unable to resolve required argument ${A_CommonHelper.getComponentName(arg.target)} for stage ${this.name} in scope ${scope.name}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
148
167
|
return scope.resolve(arg.target)
|
|
168
|
+
}
|
|
149
169
|
}
|
|
150
170
|
})
|
|
151
171
|
)
|
|
@@ -76,7 +76,7 @@ export type A_TYPES__A_StageStep = {
|
|
|
76
76
|
* [!] In case the method has circular dependencies it will Throw an error.
|
|
77
77
|
*
|
|
78
78
|
*/
|
|
79
|
-
before: string
|
|
79
|
+
before: string
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Allows to define the order of the execution of the method.
|
|
@@ -84,7 +84,7 @@ export type A_TYPES__A_StageStep = {
|
|
|
84
84
|
* [!] In case the method has circular dependencies it will Throw an error.
|
|
85
85
|
*
|
|
86
86
|
*/
|
|
87
|
-
after: string
|
|
87
|
+
after: string,
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Indicates whether to throw an error if the step fails.
|
|
@@ -92,6 +92,11 @@ export type A_TYPES__A_StageStep = {
|
|
|
92
92
|
* [!] By default is true
|
|
93
93
|
*/
|
|
94
94
|
throwOnError: boolean
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
override: string
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
|