@adaas/a-concept 0.2.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "A-Concept is a framework of the new generation that is tailored to use AI, enabling developers to create AI-powered applications with ease. It provides a structured approach to building, managing, and deploying AI-driven solutions.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -10,6 +10,7 @@ import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
11
  import { A_Entity } from "../A-Entity/A-Entity.class";
12
12
  import { A_TYPES__Entity_Constructor } from "../A-Entity/A-Entity.types";
13
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
13
14
 
14
15
 
15
16
  /**
@@ -49,6 +50,10 @@ export function A_Dependency_All<T extends A_Entity>(
49
50
  case A_TypeGuards.isContainerInstance(target):
50
51
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
51
52
  break;
53
+
54
+ case A_TypeGuards.isEntityInstance(target):
55
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
56
+ break;
52
57
  }
53
58
 
54
59
  // get existing meta or create a new one
@@ -8,6 +8,7 @@ import { A_TYPES__A_InjectDecorator_Meta, A_TYPES__InjectableTargets } from "../
8
8
  import { A_TYPES__A_Dependency_DefaultDecoratorReturn } from "./A-Dependency.types";
9
9
  import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
11
12
 
12
13
 
13
14
  /**
@@ -48,6 +49,10 @@ export function A_Dependency_Default(
48
49
  case A_TypeGuards.isContainerInstance(target):
49
50
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
50
51
  break;
52
+
53
+ case A_TypeGuards.isEntityInstance(target):
54
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
55
+ break;
51
56
  }
52
57
 
53
58
  // get existing meta or create a new one
@@ -8,6 +8,7 @@ import { A_TYPES__A_InjectDecorator_Meta, A_TYPES__InjectableTargets } from "../
8
8
  import { A_TYPES__A_Dependency_FlatDecoratorReturn } from "./A-Dependency.types";
9
9
  import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
11
12
 
12
13
 
13
14
  /**
@@ -42,6 +43,10 @@ export function A_Dependency_Flat(): A_TYPES__A_Dependency_FlatDecoratorReturn {
42
43
  case A_TypeGuards.isContainerInstance(target):
43
44
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
44
45
  break;
46
+
47
+ case A_TypeGuards.isEntityInstance(target):
48
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
49
+ break;
45
50
  }
46
51
 
47
52
  // get existing meta or create a new one
@@ -8,6 +8,7 @@ import { A_TYPES__A_InjectDecorator_Meta, A_TYPES__InjectableTargets } from "../
8
8
  import { A_TYPES__A_Dependency_LoadDecoratorReturn } from "./A-Dependency.types";
9
9
  import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
11
12
 
12
13
 
13
14
  /**
@@ -51,6 +52,10 @@ export function A_Dependency_Load(
51
52
  case A_TypeGuards.isContainerInstance(target):
52
53
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
53
54
  break;
55
+
56
+ case A_TypeGuards.isEntityInstance(target):
57
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
58
+ break;
54
59
  }
55
60
 
56
61
  // get existing meta or create a new one
@@ -8,6 +8,7 @@ import { A_TYPES__A_InjectDecorator_Meta, A_TYPES__InjectableTargets } from "../
8
8
  import { A_TYPES__A_Dependency_ParentDecoratorReturn } from "./A-Dependency.types";
9
9
  import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
11
12
 
12
13
 
13
14
  /**
@@ -49,6 +50,10 @@ export function A_Dependency_Parent(
49
50
  case A_TypeGuards.isContainerInstance(target):
50
51
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
51
52
  break;
53
+
54
+ case A_TypeGuards.isEntityInstance(target):
55
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
56
+ break;
52
57
  }
53
58
 
54
59
  // get existing meta or create a new one
@@ -8,6 +8,7 @@ import { A_TYPES__A_InjectDecorator_Meta, A_TYPES__InjectableTargets } from "../
8
8
  import { A_TYPES__A_Dependency_RequireDecoratorReturn } from "./A-Dependency.types";
9
9
  import { A_DependencyError } from "./A-Dependency.error";
10
10
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
11
+ import { A_TYPES__EntityMetaKey } from "../A-Entity/A-Entity.constants";
11
12
 
12
13
 
13
14
  /**
@@ -42,6 +43,10 @@ export function A_Dependency_Require(): A_TYPES__A_Dependency_RequireDecoratorRe
42
43
  case A_TypeGuards.isContainerInstance(target):
43
44
  metaKey = A_TYPES__ContainerMetaKey.INJECTIONS;
44
45
  break;
46
+
47
+ case A_TypeGuards.isEntityInstance(target):
48
+ metaKey = A_TYPES__EntityMetaKey.INJECTIONS;
49
+ break;
45
50
  }
46
51
 
47
52
  // get existing meta or create a new one
@@ -5,8 +5,7 @@ import { A_Dependency_Load } from "./A-Dependency-Load.decorator";
5
5
  import { A_Dependency_Parent } from "./A-Dependency-Parent.decorator";
6
6
  import { A_Dependency_Require } from "./A-Dependency-Require.decorator";
7
7
  import { A_DependencyError } from "./A-Dependency.error";
8
- import { A_TYPES__A_Dependency_EntityInjectionPagination, A_TYPES__A_Dependency_EntityInjectionQuery, A_TYPES__A_Dependency_Serialized, A_TYPES__A_DependencyInjectable, A_TYPES__A_DependencyResolutionStrategy, A_TYPES__A_DependencyResolutionType } from "./A-Dependency.types";
9
- import { A_Entity } from "../A-Entity/A-Entity.class";
8
+ import { A_TYPES__A_Dependency_EntityInjectionPagination, A_TYPES__A_Dependency_EntityInjectionQuery, A_TYPES__A_Dependency_Serialized, A_TYPES__A_DependencyInjectable, A_TYPES__A_DependencyResolutionStrategy } from "./A-Dependency.types";
10
9
  import { A_TYPES__Ctor } from "@adaas/a-concept/types/A_Common.types";
11
10
 
12
11
 
@@ -62,7 +61,7 @@ export class A_Dependency<
62
61
  protected _name: string;
63
62
  protected _target?: A_TYPES__Ctor<T>;
64
63
  protected _resolutionStrategy!: A_TYPES__A_DependencyResolutionStrategy;
65
-
64
+
66
65
  protected _defaultPagination: A_TYPES__A_DependencyResolutionStrategy['pagination'] = {
67
66
  count: 1,
68
67
  from: 'start',
@@ -102,8 +101,8 @@ export class A_Dependency<
102
101
  get args(): any[] {
103
102
  return this._resolutionStrategy.args;
104
103
  }
105
- get query(): Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T extends A_Entity ? T : A_Entity>> {
106
- return this._resolutionStrategy.query;
104
+ get query(): Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T>> {
105
+ return this._resolutionStrategy.query as Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T>>;
107
106
  }
108
107
  get pagination(): A_TYPES__A_Dependency_EntityInjectionPagination {
109
108
  return this._resolutionStrategy.pagination;
@@ -119,7 +118,7 @@ export class A_Dependency<
119
118
  */
120
119
  constructor(
121
120
  name: string | A_TYPES__Ctor<T>,
122
- resolutionStrategy?: Partial<Omit<A_TYPES__A_DependencyResolutionStrategy<T extends A_Entity ? T : A_Entity>, 'pagination'> & { pagination: Partial<A_TYPES__A_Dependency_EntityInjectionPagination> }>
121
+ resolutionStrategy?: Partial<Omit<A_TYPES__A_DependencyResolutionStrategy<T>, 'pagination'> & { pagination: Partial<A_TYPES__A_Dependency_EntityInjectionPagination> }>
123
122
  ) {
124
123
  this._name = typeof name === 'string' ? name : A_CommonHelper.getComponentName(name);
125
124
 
@@ -152,14 +151,14 @@ export class A_Dependency<
152
151
  /**
153
152
  * Gets the dependency resolution strategy
154
153
  */
155
- get resolutionStrategy(): A_TYPES__A_DependencyResolutionStrategy<T extends A_Entity ? T : A_Entity> {
154
+ get resolutionStrategy(): A_TYPES__A_DependencyResolutionStrategy<T> {
156
155
  return this._resolutionStrategy!;
157
156
  }
158
157
 
159
158
  /**
160
159
  * Sets the dependency resolution strategy
161
160
  */
162
- set resolutionStrategy(strategy: Partial<Omit<A_TYPES__A_DependencyResolutionStrategy<T extends A_Entity ? T : A_Entity>, 'pagination'> & { pagination: Partial<A_TYPES__A_Dependency_EntityInjectionPagination> }>) {
161
+ set resolutionStrategy(strategy: Partial<Omit<A_TYPES__A_DependencyResolutionStrategy<T>, 'pagination'> & { pagination: Partial<A_TYPES__A_Dependency_EntityInjectionPagination> }>) {
163
162
  this._resolutionStrategy = {
164
163
  ...this._defaultResolutionStrategy,
165
164
  ...this._resolutionStrategy,
@@ -177,8 +176,7 @@ export class A_Dependency<
177
176
  *
178
177
  * @returns
179
178
  */
180
- private initCheck(
181
- ): this {
179
+ private initCheck(): this {
182
180
  if (!this._resolutionStrategy) {
183
181
  throw new A_DependencyError(
184
182
  A_DependencyError.ResolutionParametersError,
@@ -186,8 +184,6 @@ export class A_Dependency<
186
184
  );
187
185
  }
188
186
 
189
-
190
-
191
187
  return this;
192
188
  }
193
189
 
@@ -197,7 +193,7 @@ export class A_Dependency<
197
193
  *
198
194
  * @returns
199
195
  */
200
- toJSON(): A_TYPES__A_Dependency_Serialized {
196
+ toJSON(): A_TYPES__A_Dependency_Serialized<T> {
201
197
  return {
202
198
  name: this._name,
203
199
  all: this.all,
@@ -64,7 +64,7 @@ export type A_TYPES__A_DependencyResolutionStrategy<T extends A_TYPES__A_Depende
64
64
  /**
65
65
  * Allows to query by specific entity properties e.g. ASEID, name, type, custom properties, etc.
66
66
  */
67
- query: Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T extends A_Entity ? T : A_Entity>>,
67
+ query: Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T>>,
68
68
  /**
69
69
  * Pagination settings for the entity search
70
70
  */
@@ -72,7 +72,7 @@ export type A_TYPES__A_DependencyResolutionStrategy<T extends A_TYPES__A_Depende
72
72
  }
73
73
 
74
74
 
75
- export type A_TYPES__A_Dependency_Serialized = {
75
+ export type A_TYPES__A_Dependency_Serialized<T extends A_TYPES__A_DependencyInjectable = A_TYPES__A_DependencyInjectable> = {
76
76
  name: string,
77
77
  all: boolean,
78
78
  require: boolean,
@@ -81,7 +81,7 @@ export type A_TYPES__A_Dependency_Serialized = {
81
81
  flat: boolean,
82
82
  create: any,
83
83
  args: any[],
84
- query: Partial<A_TYPES__A_Dependency_EntityInjectionQuery>,
84
+ query: Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T>>,
85
85
  pagination: A_TYPES__A_Dependency_EntityInjectionPagination
86
86
  }
87
87
 
@@ -90,17 +90,20 @@ export type A_TYPES__A_Dependency_Serialized = {
90
90
  // =--------------------------------------------------------------------------------------------
91
91
 
92
92
 
93
- export type A_TYPES__A_Dependency_EntityResolutionConfig<T extends A_Entity = A_Entity> = {
93
+ export type A_TYPES__A_Dependency_EntityResolutionConfig<T extends A_TYPES__A_DependencyInjectable = A_TYPES__A_DependencyInjectable> = {
94
94
  query: Partial<A_TYPES__A_Dependency_EntityInjectionQuery<T>>,
95
95
  pagination: Partial<A_TYPES__A_Dependency_EntityInjectionPagination>
96
96
  }
97
97
 
98
98
 
99
- export type A_TYPES__A_Dependency_EntityInjectionQuery<T extends A_Entity = A_Entity> = {
100
- aseid: string,
101
- } & {
102
- [key in keyof T]?: any
103
- };
99
+ export type A_TYPES__A_Dependency_EntityInjectionQuery<T extends A_TYPES__A_DependencyInjectable = A_TYPES__A_DependencyInjectable> =
100
+ T extends A_Entity
101
+ ? {
102
+ aseid: string,
103
+ } & {
104
+ [key in keyof T]?: any
105
+ }
106
+ : never;
104
107
 
105
108
 
106
109
  export type A_TYPES__A_Dependency_EntityInjectionPagination = {
@@ -145,7 +145,7 @@ export function A_Inject<T extends A_TYPES__A_DependencyInjectable>(
145
145
  ): A_TYPES__A_InjectDecoratorReturn
146
146
  export function A_Inject<T extends A_TYPES__A_DependencyInjectable>(
147
147
  param1: string | A_TYPES__Ctor<T> | A_Dependency<T>,
148
- param2?: Partial<A_TYPES__A_DependencyResolutionStrategy<T extends A_Entity ? T : A_Entity>>
148
+ param2?: Partial<A_TYPES__A_DependencyResolutionStrategy<T>>
149
149
  ): A_TYPES__A_InjectDecoratorReturn {
150
150
 
151
151
  // pre call checks
@@ -197,7 +197,7 @@ export function A_Inject<T extends A_TYPES__A_DependencyInjectable>(
197
197
 
198
198
  // set the parameter injection info
199
199
  paramsArray[parameterIndex] = param1 instanceof A_Dependency ? param1 : new A_Dependency(param1, param2);
200
-
200
+
201
201
  // save back the updated injections array
202
202
  existedMeta.set(method, paramsArray);
203
203
 
@@ -1,4 +1,4 @@
1
- import { A_Component, A_Dependency, A_Entity, A_Error, A_Inject, A_Scope, A_ScopeError } from "../src";
1
+ import { A_Component, A_Dependency, A_Entity, A_Error, A_Feature, A_FeatureError, A_Inject, A_Scope, A_ScopeError } from "../src";
2
2
 
3
3
 
4
4
 
@@ -45,9 +45,23 @@ describe('A-Dependency tests', () => {
45
45
  ) {
46
46
  super();
47
47
  }
48
+
48
49
  }
49
50
 
50
- const scope = new A_Scope({ components: [Test] });
51
+ class testEntity extends A_Entity {
52
+
53
+ @A_Feature.Extend({
54
+ name: 'test'
55
+ })
56
+ async test(
57
+ @A_Dependency.Required()
58
+ @A_Inject(DependencyRequiredComponent) component: DependencyRequiredComponent,
59
+ ) {
60
+
61
+ }
62
+ }
63
+
64
+ const scope = new A_Scope({ components: [Test], entities: [new testEntity()] });
51
65
 
52
66
  try {
53
67
  scope.resolve(Test);
@@ -59,6 +73,18 @@ describe('A-Dependency tests', () => {
59
73
  const dependency = scope.resolve(DependencyRequiredComponent);
60
74
 
61
75
  expect(dependency).toBeUndefined();
76
+
77
+
78
+ const entityInstance = scope.resolve(testEntity);
79
+
80
+ try {
81
+ await entityInstance?.call('test');
82
+ } catch (error) {
83
+ expect(error).toBeInstanceOf(A_FeatureError);
84
+ expect((error as A_FeatureError).originalError).toBeInstanceOf(A_ScopeError);
85
+ expect((error as A_FeatureError).originalError.title).toBe(A_ScopeError.ResolutionError);
86
+ }
87
+
62
88
  });
63
89
  it('Should resolve a component if it has default constructor for dependency', async () => {
64
90
  class MyCustomEntity extends A_Entity<{ foo: string }> {