@adaas/a-concept 0.0.56 → 0.0.58

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.
Files changed (104) hide show
  1. package/.nvmrc +1 -1
  2. package/dist/src/base/A-Command/A_Command.constants.d.ts +12 -0
  3. package/dist/src/base/A-Command/A_Command.constants.js +17 -0
  4. package/dist/src/base/A-Command/A_Command.constants.js.map +1 -0
  5. package/dist/src/base/A-Command/A_Command.entity.d.ts +123 -0
  6. package/dist/src/base/A-Command/A_Command.entity.js +259 -0
  7. package/dist/src/base/A-Command/A_Command.entity.js.map +1 -0
  8. package/dist/src/base/A-Command/A_Command.types.d.ts +15 -0
  9. package/dist/src/base/A-Command/A_Command.types.js +3 -0
  10. package/dist/src/base/A-Command/A_Command.types.js.map +1 -0
  11. package/dist/src/base/A-Command/context/A_Command.context.d.ts +64 -0
  12. package/dist/src/base/A-Command/context/A_Command.context.js +85 -0
  13. package/dist/src/base/A-Command/context/A_Command.context.js.map +1 -0
  14. package/dist/src/base/A-Command/context/A_CommandFactory.context.js +2 -0
  15. package/dist/src/base/A-Command/context/A_CommandFactory.context.js.map +1 -0
  16. package/dist/src/base/A-Config/A-Config.container.d.ts +1 -2
  17. package/dist/src/base/A-Config/A-Config.container.js +2 -4
  18. package/dist/src/base/A-Config/A-Config.container.js.map +1 -1
  19. package/dist/src/base/A-Config/A-Config.context.d.ts +10 -11
  20. package/dist/src/base/A-Config/A-Config.context.js +5 -24
  21. package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
  22. package/dist/src/base/A-Config/A-Config.types.d.ts +4 -4
  23. package/dist/src/base/A-Config/A-Config.types.js.map +1 -1
  24. package/dist/src/base/A-Config/components/ConfigReader.component.js +6 -12
  25. package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
  26. package/dist/src/base/A-Config/components/ENVConfigReader.component.js +5 -1
  27. package/dist/src/base/A-Config/components/ENVConfigReader.component.js.map +1 -1
  28. package/dist/src/constants/env.constants.d.ts +26 -0
  29. package/dist/src/constants/env.constants.js +40 -0
  30. package/dist/src/constants/env.constants.js.map +1 -0
  31. package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +3 -3
  32. package/dist/src/decorators/A-Inject/A-Inject.decorator.types.d.ts +9 -10
  33. package/dist/src/global/A-Channel/A-Channel.class.d.ts +2 -0
  34. package/dist/src/global/A-Channel/A-Channel.class.js +2 -0
  35. package/dist/src/global/A-Channel/A-Channel.class.js.map +1 -1
  36. package/dist/src/global/A-Concept/A_Concept.class.d.ts +5 -3
  37. package/dist/src/global/A-Concept/A_Concept.class.js +32 -27
  38. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  39. package/dist/src/global/A-Concept/A_Concept.meta.d.ts +1 -8
  40. package/dist/src/global/A-Concept/A_Concept.meta.js +1 -25
  41. package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
  42. package/dist/src/global/A-Concept/A_Concept.types.d.ts +10 -1
  43. package/dist/src/global/A-Container/A-Container.class.d.ts +5 -0
  44. package/dist/src/global/A-Container/A-Container.class.js +5 -0
  45. package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
  46. package/dist/src/global/A-Context/A-Context.class.d.ts +23 -1
  47. package/dist/src/global/A-Context/A-Context.class.js +38 -1
  48. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  49. package/dist/src/global/A-Entity/A-Entity.class.d.ts +124 -23
  50. package/dist/src/global/A-Entity/A-Entity.class.js +159 -49
  51. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  52. package/dist/src/global/A-Scope/A-Scope.class.d.ts +7 -6
  53. package/dist/src/global/A-Scope/A-Scope.class.js +57 -20
  54. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  55. package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
  56. package/dist/src/global/A-Stage/A-Stage.class.js +9 -6
  57. package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
  58. package/dist/src/global/A-Stage/A-Stage.types.d.ts +1 -1
  59. package/dist/src/helpers/StepsManager.class.js +1 -1
  60. package/dist/src/helpers/StepsManager.class.js.map +1 -1
  61. package/examples/simple/components/A.component.ts +9 -2
  62. package/examples/simple/concept.ts +6 -0
  63. package/examples/simple/entities/EntityA.entity.ts +18 -0
  64. package/jest.config.ts +1 -1
  65. package/package.json +3 -3
  66. package/src/base/A-Command/A_Command.constants.ts +20 -0
  67. package/src/base/A-Command/A_Command.entity.ts +287 -0
  68. package/src/base/A-Command/A_Command.types.ts +34 -0
  69. package/src/base/A-Command/context/A_Command.context.ts +114 -0
  70. package/src/base/A-Command/context/A_CommandFactory.context.ts +0 -0
  71. package/src/base/A-Config/A-Config.container.ts +0 -1
  72. package/src/base/A-Config/A-Config.context.ts +22 -28
  73. package/src/base/A-Config/A-Config.types.ts +5 -24
  74. package/src/base/A-Config/components/ConfigReader.component.ts +6 -15
  75. package/src/base/A-Config/components/ENVConfigReader.component.ts +6 -1
  76. package/src/constants/env.constants.ts +44 -0
  77. package/src/decorators/A-Inject/A-Inject.decorator.ts +3 -3
  78. package/src/decorators/A-Inject/A-Inject.decorator.types.ts +10 -9
  79. package/src/global/A-Channel/A-Channel.class.ts +2 -0
  80. package/src/global/A-Concept/A_Concept.class.ts +49 -32
  81. package/src/global/A-Concept/A_Concept.meta.ts +3 -41
  82. package/src/global/A-Concept/A_Concept.types.ts +6 -4
  83. package/src/global/A-Container/A-Container.class.ts +5 -2
  84. package/src/global/A-Context/A-Context.class.ts +67 -8
  85. package/src/global/A-Entity/A-Entity.class.ts +203 -73
  86. package/src/global/A-Scope/A-Scope.class.ts +88 -39
  87. package/src/global/A-Stage/A-Stage.class.ts +11 -7
  88. package/src/global/A-Stage/A-Stage.types.ts +1 -1
  89. package/src/helpers/StepsManager.class.ts +2 -2
  90. package/tests/A-Command.test.ts +130 -0
  91. package/tests/A-Component.test.ts +25 -0
  92. package/tests/A-Config.test.ts +106 -0
  93. package/tests/A-Entity.test.ts +191 -0
  94. package/tests/A-Feature.test.ts +131 -0
  95. package/tests/A-Scope.test.ts +163 -0
  96. package/dist/src/constants/A_ConceptLifecycle.constants.js +0 -11
  97. package/dist/src/constants/A_ConceptLifecycle.constants.js.map +0 -1
  98. package/src/constants/A_ConceptLifecycle.constants.ts +0 -12
  99. package/tests/channel.ts +0 -213
  100. package/tests/context.test.ts +0 -124
  101. package/tests/default.test.ts +0 -159
  102. package/tests/log.ts +0 -102
  103. package/tests/polyfill.test.ts +0 -37
  104. /package/dist/src/{constants/A_ConceptLifecycle.constants.d.ts → base/A-Command/context/A_CommandFactory.context.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  A_CommonHelper,
3
+ A_Error,
3
4
  A_Polyfills,
4
5
  } from "@adaas/a-utils";
5
6
  import { A_Component } from "../A-Component/A-Component.class";
@@ -20,6 +21,7 @@ import { A_TYPES__ContainerMetaKey } from "../A-Container/A-Container.types";
20
21
  import { A_TYPES__ComponentMetaKey } from "../A-Component/A-Component.types";
21
22
  import { A_TYPES__ConceptStage } from "../A-Concept/A_Concept.types";
22
23
  import { A_TYPES__A_DefineDecorator_Meta } from "@adaas/a-concept/decorators/A-Feature/A-Feature.decorator.types";
24
+ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "@adaas/a-concept/constants/env.constants";
23
25
 
24
26
 
25
27
 
@@ -79,7 +81,7 @@ export class A_Context {
79
81
 
80
82
  private constructor() {
81
83
  this._root = new A_Scope({
82
- name: 'root'
84
+ name: process && process.env ? process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_NAMESPACE] || 'a-concept' : 'a-concept'
83
85
  });
84
86
  }
85
87
 
@@ -147,6 +149,10 @@ export class A_Context {
147
149
 
148
150
  const newScope = param2 instanceof A_Scope ? param2 : new A_Scope(param2, param2);
149
151
 
152
+ if (!newScope.isInheritedFrom(A_Context.root)) {
153
+ newScope.inherit(A_Context.root);
154
+ }
155
+
150
156
  switch (true) {
151
157
  case param1 instanceof A_Container:
152
158
  instance.containers.set(param1, newScope);
@@ -169,6 +175,14 @@ export class A_Context {
169
175
 
170
176
 
171
177
 
178
+ /**
179
+ * Get or Create Meta for the specific class or instance.
180
+ * This method will return the existing meta if it exists, or create a new one if it doesn't.
181
+ *
182
+ * Meta object contains custom metadata based on the class type.
183
+ *
184
+ * @param container
185
+ */
172
186
  static meta(
173
187
  container: typeof A_Container,
174
188
  ): A_ContainerMeta
@@ -181,6 +195,9 @@ export class A_Context {
181
195
  static meta(
182
196
  entity: typeof A_Entity,
183
197
  ): A_ContainerMeta
198
+ static meta(
199
+ component: string,
200
+ ): A_ComponentMeta
184
201
  static meta(
185
202
  component: typeof A_Component,
186
203
  ): A_ComponentMeta
@@ -193,6 +210,7 @@ export class A_Context {
193
210
  | A_Entity
194
211
  | typeof A_Entity
195
212
  | { new(...args: any[]): any }
213
+ | string
196
214
  ): A_Meta<T>
197
215
  static meta<T extends Record<string, any>>(
198
216
  param1: typeof A_Component | typeof A_Container | A_Container
@@ -200,9 +218,9 @@ export class A_Context {
200
218
  | A_Entity
201
219
  | typeof A_Entity
202
220
  | { new(...args: any[]): any }
221
+ | string
203
222
  ): A_ContainerMeta | A_ComponentMeta | A_Meta<T> {
204
223
 
205
-
206
224
  const instance = this.getInstance();
207
225
 
208
226
  let metaStorage: WeakMap<typeof A_Container.constructor, A_Meta<any>>;
@@ -211,6 +229,7 @@ export class A_Context {
211
229
 
212
230
 
213
231
  switch (true) {
232
+ // 1) If param1 is instance of A_Container
214
233
  case param1 instanceof A_Container: {
215
234
 
216
235
  metaStorage = instance.containersMeta;
@@ -219,7 +238,7 @@ export class A_Context {
219
238
 
220
239
  break;
221
240
  }
222
-
241
+ // 2) If param1 is class of A_Container
223
242
  case A_CommonHelper.isInheritedFrom(param1, A_Container): {
224
243
  metaStorage = instance.containersMeta;
225
244
  property = param1 as typeof A_Container;
@@ -227,7 +246,7 @@ export class A_Context {
227
246
 
228
247
  break;
229
248
  }
230
-
249
+ // 3) If param1 is instance of A_Component
231
250
  case param1 instanceof A_Component: {
232
251
  metaStorage = instance.componentsMeta;
233
252
  property = param1.constructor;
@@ -235,7 +254,7 @@ export class A_Context {
235
254
 
236
255
  break;
237
256
  }
238
-
257
+ // 4) If param1 is class of A_Component
239
258
  case A_CommonHelper.isInheritedFrom(param1, A_Component): {
240
259
  metaStorage = instance.componentsMeta;
241
260
  property = param1 as typeof A_Component;
@@ -243,7 +262,7 @@ export class A_Context {
243
262
 
244
263
  break;
245
264
  }
246
-
265
+ // 5) If param1 is instance of A_Entity
247
266
  case param1 instanceof A_Entity: {
248
267
  metaStorage = instance.entitiesMeta;
249
268
  property = param1.constructor;
@@ -251,15 +270,25 @@ export class A_Context {
251
270
 
252
271
  break;
253
272
  }
254
-
273
+ // 6) If param1 is class of A_Entity
255
274
  case A_CommonHelper.isInheritedFrom(param1, A_Entity): {
256
275
  metaStorage = instance.entitiesMeta;
257
276
  property = param1 as typeof A_Entity;
258
277
  metaType = A_EntityMeta;
278
+
259
279
  break;
260
280
  }
281
+ // 7) If param1 is string then we need to find the component by its name
282
+ case typeof param1 === 'string': {
283
+ metaStorage = instance.componentsMeta;
284
+ const found = Array.from(instance.componentsMeta).find(([c]) => c.name === param1)!;
285
+ if (!(found && found.length)) throw new A_Error(`Component with name ${param1} not found`);
286
+ property = found[0];
287
+ metaType = A_ComponentMeta;
261
288
 
262
-
289
+ break;
290
+ }
291
+ // 8) If param1 is any other class or function
263
292
  default: {
264
293
  metaStorage = instance.customMeta;
265
294
  property = typeof (param1 as any) === 'function' ? param1 : param1.constructor;
@@ -281,6 +310,15 @@ export class A_Context {
281
310
 
282
311
 
283
312
 
313
+ /**
314
+ * Get the scope of the specific class or instance.
315
+ *
316
+ * Every execution in Concept has its own scope.
317
+ *
318
+ * This method will return the scope of the specific class or instance.
319
+ *
320
+ * @param entity
321
+ */
284
322
  static scope(
285
323
  entity: A_Entity
286
324
  ): A_Scope
@@ -589,4 +627,25 @@ export class A_Context {
589
627
  break;
590
628
  }
591
629
  }
630
+
631
+
632
+ /**
633
+ * Resets the Context to its initial state.
634
+ */
635
+ static reset() {
636
+ const instance = A_Context.getInstance();
637
+
638
+ instance.containers = new WeakMap();
639
+ instance.features = new WeakMap();
640
+ instance.registry = new WeakMap();
641
+ instance.containersMeta = new Map();
642
+ instance.componentsMeta = new Map();
643
+ instance.entitiesMeta = new Map();
644
+ instance.customMeta = new Map();
645
+
646
+ instance._root = new A_Scope({
647
+ name: process && process.env ? process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_NAMESPACE] || 'a-concept' : 'a-concept'
648
+ });
649
+
650
+ }
592
651
  }
@@ -9,8 +9,8 @@ import {
9
9
  } from "./A-Entity.types";
10
10
  import { A_CONSTANTS__DEFAULT_ERRORS } from "@adaas/a-utils/dist/src/constants/errors.constants";
11
11
  import { A_Context } from "../A-Context/A-Context.class";
12
- import { A_TYPES__FeatureCallParams } from "../A-Feature/A-Feature.types";
13
12
  import { A_Scope } from "../A-Scope/A-Scope.class";
13
+ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY } from "@adaas/a-concept/constants/env.constants";
14
14
 
15
15
 
16
16
 
@@ -27,8 +27,10 @@ export class A_Entity<
27
27
  >
28
28
  implements A_TYPES__IEntity {
29
29
 
30
- aseid!: ASEID;
31
30
 
31
+ // ====================================================================
32
+ // ================== Static A-Entity Information ============================
33
+ // ====================================================================
32
34
 
33
35
  /**
34
36
  * Entity Identifier that corresponds to the class name
@@ -40,6 +42,49 @@ export class A_Entity<
40
42
  .replace(/_/g, '-');
41
43
  }
42
44
 
45
+ /**
46
+ * DEFAULT Namespace of the entity from environment variable A_CONCEPT_NAMESPACE
47
+ * [!] If environment variable is not set, it will default to 'a-concept'
48
+ */
49
+ static get namespace(): string {
50
+ return A_Context.root.name;
51
+ }
52
+
53
+ /**
54
+ * DEFAULT Scope of the entity from environment variable A_CONCEPT_DEFAULT_SCOPE
55
+ * [!] If environment variable is not set, it will default to 'core'
56
+ * [!] Scope is an application specific identifier that can be used to group entities together
57
+ * [!] e.g. 'default', 'core', 'public', 'internal', etc
58
+ */
59
+ static get scope(): string {
60
+ return process && process.env ? process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_DEFAULT_SCOPE] || 'core' : 'core';
61
+ }
62
+
63
+ // ====================================================================
64
+ // ================== Instance A-Entity Information ====================
65
+ // ====================================================================
66
+
67
+ /**
68
+ * ASEID is an entity identifier that is unique across the system
69
+ * A - A_Concept or Application
70
+ * S - System or Scope
71
+ * E - Entity
72
+ * ID - Identifier
73
+ *
74
+ * [!] ASEID is immutable and should not be changed after the entity is created
75
+ *
76
+ * [!] ASEID is composed of the following parts:
77
+ * - namespace: an application specific identifier from where the entity is coming from
78
+ * - scope: the scope of the entity from Application Namespace
79
+ * - entity: the name of the entity from Application Namespace
80
+ * - id: the unique identifier of the entity
81
+ *
82
+ * [!] For more information about ASEID, please refer to the ASEID class documentation]
83
+ */
84
+ aseid!: ASEID;
85
+
86
+
87
+
43
88
  /**
44
89
  * Create a new A_entity instance from Aseid String
45
90
  * e.g. project@scope:entity:0000000001
@@ -50,7 +95,7 @@ export class A_Entity<
50
95
  /**
51
96
  * ASEID string that represents the entity
52
97
  */
53
- aseid: string
98
+ aseid?: string
54
99
  )
55
100
  /**
56
101
  * Create a new A_entity instance from Aseid instance
@@ -84,15 +129,72 @@ export class A_Entity<
84
129
  /**
85
130
  * Constructor object that represents the entity
86
131
  */
87
- newEntity: _ConstructorType
132
+ newEntity?: _ConstructorType
88
133
  )
89
- constructor(props: string | ASEID | _SerializedType | _ConstructorType) {
134
+ constructor(props?: string | ASEID | _SerializedType | _ConstructorType) {
90
135
 
91
136
  const initializer = this.getInitializer(props);
92
137
  // the returned initializer is already bound to `this` (we used .bind(this)),
93
138
  // so calling it will run the appropriate logic on this instance:
94
139
  initializer.call(this, props);
95
140
  }
141
+ // ====================================================================
142
+ // ================== DUPLICATED ASEID Getters ========================
143
+ // ====================================================================
144
+
145
+ /**
146
+ * Extracts the ID from the ASEID
147
+ * ID is the unique identifier of the entity
148
+ */
149
+ get id(): string | number {
150
+ return this.aseid.id;
151
+ }
152
+
153
+ /**
154
+ * Extracts the namespace from the ASEID
155
+ * namespace is an application specific identifier from where the entity is coming from
156
+ */
157
+ get namespace(): string {
158
+ return this.aseid.namespace
159
+ }
160
+
161
+ /**
162
+ * Extracts the scope from the ASEID
163
+ * scope is the scope of the entity from Application Namespace
164
+ */
165
+ get scope(): string {
166
+ return this.aseid.scope;
167
+ }
168
+
169
+ /**
170
+ * Extracts the entity from the ASEID
171
+ * entity is the name of the entity from Application Namespace
172
+ *
173
+ */
174
+ get entity(): string {
175
+ return this.aseid.entity;
176
+ }
177
+
178
+ /**
179
+ * Extracts the version from the ASEID
180
+ * version is the version of the entity
181
+ */
182
+
183
+ get version(): string | undefined {
184
+ return this.aseid.version;
185
+ }
186
+
187
+ /**
188
+ * Extracts the shard from the ASEID
189
+ * shard is the shard of the entity
190
+ */
191
+ get shard(): string | undefined {
192
+ return this.aseid.shard;
193
+ }
194
+
195
+ // ====================================================================
196
+ // ================== Constructor Helpers =============================
197
+ // ====================================================================
96
198
 
97
199
 
98
200
  // --- Type guards used to classify `props` properly ---
@@ -126,10 +228,42 @@ export class A_Entity<
126
228
  return !!x && typeof x === "object" && !("aseid" in (x as object));
127
229
  }
128
230
 
129
- // --- Overloads: provide precise return-type depending on input ---
231
+ /**
232
+ * Determines the appropriate initializer method based on the type of `props`.
233
+ * The method checks if `props` is:
234
+ * 1) a string that matches ASEID format -> fromASEID
235
+ * 2) an ASEID instance -> fromASEID
236
+ * 3) a serialized object (has 'aseid') -> fromJSON
237
+ * 4) a plain object with no 'aseid' -> treat as constructor props -> fromNew
238
+ *
239
+ * [!] If `props` is undefined, it will call fromUndefined method
240
+ *
241
+ * If none of the above, it throws an error indicating incorrect constructor usage.
242
+ *
243
+ *
244
+ * To get a custom initializer, override this method in the child class.
245
+ * Example:
246
+ * ```typescript
247
+ * protected getInitializer(
248
+ * props?: string | ASEID | _SerializedType | _ConstructorType
249
+ * ): (props: any) => void | (() => void) {
250
+ * if('customField' in props) {
251
+ * return this.fromCustomField.bind(this);
252
+ * }
253
+ * return super.getInitializer(props);
254
+ * }
255
+ * ```
256
+ * @param props
257
+ * @returns The appropriate initializer method
258
+ */
130
259
  protected getInitializer(
131
- props: string | ASEID | _SerializedType | _ConstructorType
132
- ): (props: any) => void {
260
+ props?: string | ASEID | _SerializedType | _ConstructorType
261
+ ): (props: any) => void | (() => void) {
262
+
263
+ if (!props) {
264
+ return this.fromUndefined
265
+ }
266
+
133
267
  // 1) string that matches ASEID format -> fromASEID
134
268
  if (this.isStringASEID(props)) {
135
269
  return this.fromASEID as (p: string) => void;
@@ -155,67 +289,10 @@ export class A_Entity<
155
289
  }
156
290
 
157
291
 
158
-
159
-
160
- // ====================================================================
161
- // ================== DUPLICATED ASEID Getters ========================
162
- // ====================================================================
163
-
164
- /**
165
- * Extracts the ID from the ASEID
166
- * ID is the unique identifier of the entity
167
- */
168
- get id(): string | number {
169
- return this.aseid.id;
170
- }
171
-
172
- /**
173
- * Extracts the namespace from the ASEID
174
- * namespace is an application specific identifier from where the entity is coming from
175
- */
176
- get namespace(): string {
177
- return this.aseid.namespace
178
- }
179
-
180
292
  /**
181
- * Extracts the scope from the ASEID
182
- * scope is the scope of the entity from Application Namespace
183
- */
184
- get scope(): string {
185
- return this.aseid.scope;
186
- }
187
-
188
- /**
189
- * Extracts the entity from the ASEID
190
- * entity is the name of the entity from Application Namespace
293
+ * Call a feature of the component with the provided scope
191
294
  *
192
- */
193
- get entity(): string {
194
- return this.aseid.entity;
195
- }
196
-
197
- /**
198
- * Extracts the version from the ASEID
199
- * version is the version of the entity
200
- */
201
-
202
- get version(): string | undefined {
203
- return this.aseid.version;
204
- }
205
-
206
- /**
207
- * Extracts the shard from the ASEID
208
- * shard is the shard of the entity
209
- */
210
- get shard(): string | undefined {
211
- return this.aseid.shard;
212
- }
213
-
214
-
215
-
216
-
217
- /**
218
- * Call a feature of the component
295
+ * [!] If the provided scope is not inherited from the entity scope, it will be inherited
219
296
  *
220
297
  * @param lifecycleMethod
221
298
  * @param args
@@ -228,8 +305,6 @@ export class A_Entity<
228
305
  // or it can be inherited from the entity scope
229
306
  // [!Not Now!] however, each feature should create own scope regardless of the passed scope
230
307
  // to avoid any possible side effects
231
-
232
-
233
308
  if (scope && !scope.isInheritedFrom(A_Context.scope(this))) {
234
309
  scope = scope.inherit(A_Context.scope(this));
235
310
  }
@@ -244,8 +319,6 @@ export class A_Entity<
244
319
  // ================== Entity Base Methods =============================
245
320
  // ====================================================================
246
321
 
247
-
248
-
249
322
  /**
250
323
  * The default method that can be called and extended to load entity data.
251
324
  */
@@ -275,6 +348,13 @@ export class A_Entity<
275
348
  // ================== Entity Serialization ============================
276
349
  // ====================================================================
277
350
 
351
+ /**
352
+ * Create a new entity from ASEID string or instance
353
+ * [!] Executed when the constructor is called with a string or ASEID instance that represents the ASEID
354
+ * [!] Executes By Default with new A_Entity('aseid-string') or new A_Entity(new ASEID(...)) if getInitializer has not been overridden
355
+ *
356
+ * @param aseid
357
+ */
278
358
  fromASEID(aseid: string | ASEID): void {
279
359
  if (typeof aseid === 'string' && ASEID.isASEID(aseid)) {
280
360
  this.aseid = new ASEID(aseid);
@@ -285,14 +365,56 @@ export class A_Entity<
285
365
  }
286
366
  }
287
367
 
368
+ /**
369
+ * Handles the case when no props are provided to the constructor.
370
+ * This method can be overridden in child classes to set default values or perform specific initialization logic.
371
+ * By default, it does nothing.
372
+ *
373
+ *
374
+ * @returns
375
+ */
376
+ fromUndefined(): void {
377
+ this.aseid = new ASEID({
378
+ namespace: (this.constructor as typeof A_Entity).namespace,
379
+ scope: (this.constructor as typeof A_Entity).scope,
380
+ entity: (this.constructor as typeof A_Entity).entity,
381
+ id: `${new Date().getTime().toString()}-${Math.floor(Math.random() * 10000000).toString()}`,
382
+ });
383
+ return;
384
+ }
385
+
386
+ /**
387
+ * Create a new entity from constructor object
388
+ * [!] Executed when the constructor is called with an object that does not contain "aseid" property
389
+ * [!] Executes By Default with new A_Entity({}) if getInitializer has not been overridden
390
+ *
391
+ * @param newEntity
392
+ * @returns
393
+ */
288
394
  fromNew(newEntity: _ConstructorType): void {
289
- // this.aseid = new ASEID
395
+ this.aseid = new ASEID({
396
+ namespace: (this.constructor as typeof A_Entity).namespace,
397
+ scope: (this.constructor as typeof A_Entity).scope,
398
+ entity: (this.constructor as typeof A_Entity).entity,
399
+ id: `${new Date().getTime().toString()}-${Math.floor(Math.random() * 10000000).toString()}`,
400
+ });
290
401
 
291
402
  return;
292
403
  }
293
404
 
405
+
406
+ /**
407
+ * Creates a new entity from serialized object
408
+ *
409
+ * [!] Executed when the constructor is called with an object that contains "aseid" property
410
+ * [!] Executes By Default with new A_Entity({ aseid: '...' }) if getInitializer has not been overridden
411
+ *
412
+ *
413
+ * @param serialized
414
+ * @returns
415
+ */
294
416
  fromJSON(serialized: _SerializedType): void {
295
- this.aseid = new ASEID((serialized).aseid);
417
+ this.aseid = new ASEID(serialized.aseid);
296
418
  return;
297
419
  }
298
420
 
@@ -300,6 +422,8 @@ export class A_Entity<
300
422
 
301
423
  /**
302
424
  * Converts the entity to a JSON object
425
+ * [!] This method should be extended in the child classes to include all properties of the entity
426
+ * [!] Includes aseid by default
303
427
  *
304
428
  *
305
429
  * @returns
@@ -311,6 +435,12 @@ export class A_Entity<
311
435
  }
312
436
 
313
437
 
438
+ /**
439
+ * Returns the string representation of the entity
440
+ * what is basically the ASEID string
441
+ *
442
+ * @returns
443
+ */
314
444
  toString(): string {
315
445
  return this.aseid ? this.aseid.toString() : this.constructor.name;
316
446
  }