@adaas/a-concept 0.3.1 → 0.3.3
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/browser/index.d.mts +65 -6
- package/dist/browser/index.mjs +2 -2
- package/dist/browser/index.mjs.map +1 -1
- package/dist/node/index.cjs +100 -10
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.mts +65 -6
- package/dist/node/index.d.ts +65 -6
- package/dist/node/index.mjs +100 -11
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/env/env.base.ts +1 -1
- package/src/lib/A-Context/A-Context.class.ts +20 -17
- package/src/lib/A-Dependency/A-Dependency-Query.decorator.ts +90 -0
- package/src/lib/A-Dependency/A-Dependency.class.ts +11 -0
- package/src/lib/A-Dependency/A-Dependency.types.ts +12 -1
- package/src/lib/A-Dependency/index.ts +1 -0
- package/src/lib/A-Meta/A-Meta.class.ts +22 -26
- package/src/lib/A-Scope/A-Scope.class.ts +61 -6
- package/src/lib/A-Scope/A-Scope.types.ts +1 -1
- package/tests/A-Dependency.test.ts +67 -0
- package/tests/A-Entity.test.ts +101 -0
- package/tests/A-Meta.test.ts +44 -1
- package/tests/A-Scope.test.ts +17 -0
package/dist/node/index.cjs
CHANGED
|
@@ -507,7 +507,7 @@ var A_CONCEPT_BASE_ENV = class {
|
|
|
507
507
|
* Environment of the application e.g. development, production, staging
|
|
508
508
|
*/
|
|
509
509
|
static get A_CONCEPT_ENVIRONMENT() {
|
|
510
|
-
return "
|
|
510
|
+
return "development";
|
|
511
511
|
}
|
|
512
512
|
/**
|
|
513
513
|
* Runtime environment of the application e.g. browser, node
|
|
@@ -1258,6 +1258,17 @@ var A_Meta = class _A_Meta {
|
|
|
1258
1258
|
this.meta = new Map(meta.meta);
|
|
1259
1259
|
return this;
|
|
1260
1260
|
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Allows to create a copy of the meta object with the same values, this is needed to ensure that when we inherit meta from the parent component, we create a copy of it, not a reference to the same object. This allows us to modify the meta of the child component without affecting the meta of the parent component.
|
|
1263
|
+
*
|
|
1264
|
+
* @returns
|
|
1265
|
+
*/
|
|
1266
|
+
clone() {
|
|
1267
|
+
const ctor = this.constructor;
|
|
1268
|
+
const copy = new ctor();
|
|
1269
|
+
copy.meta = new Map(this.meta);
|
|
1270
|
+
return copy;
|
|
1271
|
+
}
|
|
1261
1272
|
/**
|
|
1262
1273
|
* Method to set values in the map
|
|
1263
1274
|
*
|
|
@@ -1369,9 +1380,20 @@ var A_Meta = class _A_Meta {
|
|
|
1369
1380
|
clear() {
|
|
1370
1381
|
this.meta.clear();
|
|
1371
1382
|
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Method to convert the meta to an array of key-value pairs
|
|
1385
|
+
*
|
|
1386
|
+
* @returns
|
|
1387
|
+
*/
|
|
1372
1388
|
toArray() {
|
|
1373
1389
|
return Array.from(this.meta.entries());
|
|
1374
1390
|
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Helper method to recursively convert the meta object to a JSON-compatible format. It handles nested A_Meta instances, Maps, Arrays, and plain objects.
|
|
1393
|
+
*
|
|
1394
|
+
* @param value
|
|
1395
|
+
* @returns
|
|
1396
|
+
*/
|
|
1375
1397
|
recursiveToJSON(value) {
|
|
1376
1398
|
switch (true) {
|
|
1377
1399
|
case value instanceof _A_Meta:
|
|
@@ -2136,6 +2158,49 @@ function A_Dependency_All() {
|
|
|
2136
2158
|
};
|
|
2137
2159
|
}
|
|
2138
2160
|
|
|
2161
|
+
// src/lib/A-Dependency/A-Dependency-Query.decorator.ts
|
|
2162
|
+
function A_Dependency_Query(query, pagination) {
|
|
2163
|
+
return function(target, methodName, parameterIndex) {
|
|
2164
|
+
const componentName = A_CommonHelper.getComponentName(target);
|
|
2165
|
+
if (!A_TypeGuards.isTargetAvailableForInjection(target)) {
|
|
2166
|
+
throw new A_DependencyError(
|
|
2167
|
+
A_DependencyError.InvalidDependencyTarget,
|
|
2168
|
+
`A-All cannot be used on the target of type ${typeof target} (${componentName})`
|
|
2169
|
+
);
|
|
2170
|
+
}
|
|
2171
|
+
const method = methodName ? String(methodName) : "constructor";
|
|
2172
|
+
let metaKey;
|
|
2173
|
+
switch (true) {
|
|
2174
|
+
case (A_TypeGuards.isComponentConstructor(target) || A_TypeGuards.isComponentInstance(target)):
|
|
2175
|
+
metaKey = "a-component-injections" /* INJECTIONS */;
|
|
2176
|
+
break;
|
|
2177
|
+
case A_TypeGuards.isContainerInstance(target):
|
|
2178
|
+
metaKey = "a-container-injections" /* INJECTIONS */;
|
|
2179
|
+
break;
|
|
2180
|
+
case A_TypeGuards.isEntityInstance(target):
|
|
2181
|
+
metaKey = "a-component-injections" /* INJECTIONS */;
|
|
2182
|
+
break;
|
|
2183
|
+
}
|
|
2184
|
+
const existedMeta = A_Context.meta(target).get(metaKey) || new A_Meta();
|
|
2185
|
+
const paramsArray = existedMeta.get(method) || [];
|
|
2186
|
+
paramsArray[parameterIndex].resolutionStrategy = {
|
|
2187
|
+
query: {
|
|
2188
|
+
...paramsArray[parameterIndex].resolutionStrategy.query,
|
|
2189
|
+
...query
|
|
2190
|
+
},
|
|
2191
|
+
pagination: {
|
|
2192
|
+
...paramsArray[parameterIndex].resolutionStrategy.pagination,
|
|
2193
|
+
...pagination
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
existedMeta.set(method, paramsArray);
|
|
2197
|
+
A_Context.meta(target).set(
|
|
2198
|
+
metaKey,
|
|
2199
|
+
existedMeta
|
|
2200
|
+
);
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2139
2204
|
// src/lib/A-Dependency/A-Dependency.class.ts
|
|
2140
2205
|
var A_Dependency = class {
|
|
2141
2206
|
/**
|
|
@@ -2215,6 +2280,15 @@ var A_Dependency = class {
|
|
|
2215
2280
|
static get All() {
|
|
2216
2281
|
return A_Dependency_All;
|
|
2217
2282
|
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Allows to indicate that the dependency should be resolved by specific query parameters
|
|
2285
|
+
* e.g. by ASEID, name, type, custom properties, etc.
|
|
2286
|
+
*
|
|
2287
|
+
* @returns
|
|
2288
|
+
*/
|
|
2289
|
+
static get Query() {
|
|
2290
|
+
return A_Dependency_Query;
|
|
2291
|
+
}
|
|
2218
2292
|
get flat() {
|
|
2219
2293
|
return this._resolutionStrategy.flat;
|
|
2220
2294
|
}
|
|
@@ -4072,6 +4146,21 @@ var A_Scope = class {
|
|
|
4072
4146
|
return slice.length === 1 && count !== -1 ? slice[0] : slice.length ? slice : void 0;
|
|
4073
4147
|
}
|
|
4074
4148
|
resolveConstructor(name) {
|
|
4149
|
+
switch (true) {
|
|
4150
|
+
case A_TypeGuards.isComponentConstructor(name):
|
|
4151
|
+
return Array.from(this.allowedComponents).find((c) => A_CommonHelper.isInheritedFrom(c, name));
|
|
4152
|
+
case A_TypeGuards.isEntityConstructor(name):
|
|
4153
|
+
return Array.from(this.allowedEntities).find((e) => A_CommonHelper.isInheritedFrom(e, name));
|
|
4154
|
+
case A_TypeGuards.isFragmentConstructor(name):
|
|
4155
|
+
return Array.from(this.allowedFragments).find((f) => A_CommonHelper.isInheritedFrom(f, name));
|
|
4156
|
+
case A_TypeGuards.isErrorConstructor(name):
|
|
4157
|
+
return Array.from(this.allowedErrors).find((e) => A_CommonHelper.isInheritedFrom(e, name));
|
|
4158
|
+
}
|
|
4159
|
+
if (!A_TypeGuards.isString(name))
|
|
4160
|
+
throw new A_ScopeError(
|
|
4161
|
+
A_ScopeError.ResolutionError,
|
|
4162
|
+
`Invalid constructor name provided: ${name}`
|
|
4163
|
+
);
|
|
4075
4164
|
const component = Array.from(this.allowedComponents).find(
|
|
4076
4165
|
(c) => c.name === name || c.name === A_FormatterHelper.toPascalCase(name)
|
|
4077
4166
|
);
|
|
@@ -4974,7 +5063,7 @@ var A_Context = class _A_Context {
|
|
|
4974
5063
|
}
|
|
4975
5064
|
if (!inheritedMeta)
|
|
4976
5065
|
inheritedMeta = new metaType();
|
|
4977
|
-
instance._metaStorage.set(property,
|
|
5066
|
+
instance._metaStorage.set(property, inheritedMeta.clone());
|
|
4978
5067
|
}
|
|
4979
5068
|
return instance._metaStorage.get(property);
|
|
4980
5069
|
}
|
|
@@ -5006,13 +5095,6 @@ var A_Context = class _A_Context {
|
|
|
5006
5095
|
if (!this.isAllowedForScopeAllocation(param1) && !this.isAllowedToBeRegistered(param1))
|
|
5007
5096
|
throw new A_ContextError(A_ContextError.InvalidScopeParameterError, `Invalid parameter provided to get scope. Component of type ${name} is not allowed for scope allocation.`);
|
|
5008
5097
|
switch (true) {
|
|
5009
|
-
case this.isAllowedForScopeAllocation(param1):
|
|
5010
|
-
if (!instance._registry.has(param1))
|
|
5011
|
-
throw new A_ContextError(
|
|
5012
|
-
A_ContextError.ScopeNotFoundError,
|
|
5013
|
-
`Invalid parameter provided to get scope. Component of type ${name} does not have a scope allocated. Make sure to allocate a scope using A_Context.allocate() method before trying to get the scope.`
|
|
5014
|
-
);
|
|
5015
|
-
return instance._registry.get(param1);
|
|
5016
5098
|
case this.isAllowedToBeRegistered(param1):
|
|
5017
5099
|
if (!instance._scopeStorage.has(param1))
|
|
5018
5100
|
throw new A_ContextError(
|
|
@@ -5020,6 +5102,13 @@ var A_Context = class _A_Context {
|
|
|
5020
5102
|
`Invalid parameter provided to get scope. Component of type ${name} does not have a scope registered. Make sure to register the component using A_Context.register() method before trying to get the scope.`
|
|
5021
5103
|
);
|
|
5022
5104
|
return instance._scopeStorage.get(param1);
|
|
5105
|
+
case this.isAllowedForScopeAllocation(param1):
|
|
5106
|
+
if (!instance._registry.has(param1))
|
|
5107
|
+
throw new A_ContextError(
|
|
5108
|
+
A_ContextError.ScopeNotFoundError,
|
|
5109
|
+
`Invalid parameter provided to get scope. Component of type ${name} does not have a scope allocated. Make sure to allocate a scope using A_Context.allocate() method before trying to get the scope.`
|
|
5110
|
+
);
|
|
5111
|
+
return instance._registry.get(param1);
|
|
5023
5112
|
default:
|
|
5024
5113
|
throw new A_ContextError(A_ContextError.InvalidScopeParameterError, `Invalid parameter provided to get scope. Component of type ${name} is not allowed to be registered.`);
|
|
5025
5114
|
}
|
|
@@ -5237,7 +5326,7 @@ var A_Context = class _A_Context {
|
|
|
5237
5326
|
* @returns
|
|
5238
5327
|
*/
|
|
5239
5328
|
static isAllowedForScopeAllocation(param) {
|
|
5240
|
-
return A_TypeGuards.isContainerInstance(param) || A_TypeGuards.isFeatureInstance(param);
|
|
5329
|
+
return A_TypeGuards.isContainerInstance(param) || A_TypeGuards.isFeatureInstance(param) || A_TypeGuards.isEntityInstance(param);
|
|
5241
5330
|
}
|
|
5242
5331
|
/**
|
|
5243
5332
|
* Type guard to check if the param is allowed to be registered in the context.
|
|
@@ -5726,6 +5815,7 @@ exports.A_Dependency_Default = A_Dependency_Default;
|
|
|
5726
5815
|
exports.A_Dependency_Flat = A_Dependency_Flat;
|
|
5727
5816
|
exports.A_Dependency_Load = A_Dependency_Load;
|
|
5728
5817
|
exports.A_Dependency_Parent = A_Dependency_Parent;
|
|
5818
|
+
exports.A_Dependency_Query = A_Dependency_Query;
|
|
5729
5819
|
exports.A_Dependency_Require = A_Dependency_Require;
|
|
5730
5820
|
exports.A_Entity = A_Entity;
|
|
5731
5821
|
exports.A_EntityError = A_EntityError;
|