@adaas/a-concept 0.0.59 → 0.0.61

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 (66) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.js +8 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.d.ts +2 -1
  5. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js +9 -2
  6. package/dist/src/decorators/A-Feature/A-Feature-Define.decorator.js.map +1 -1
  7. package/dist/src/{base/A-Command/A_Command.entity.d.ts → global/A-Command/A-Command.class.d.ts} +72 -10
  8. package/dist/src/{base/A-Command/A_Command.entity.js → global/A-Command/A-Command.class.js} +119 -46
  9. package/dist/src/global/A-Command/A-Command.class.js.map +1 -0
  10. package/dist/src/{base/A-Command/A_Command.constants.js → global/A-Command/A-Command.constants.js} +1 -1
  11. package/dist/src/global/A-Command/A-Command.constants.js.map +1 -0
  12. package/dist/src/global/A-Command/A-Command.meta.d.ts +11 -0
  13. package/dist/src/global/A-Command/A-Command.meta.js +18 -0
  14. package/dist/src/global/A-Command/A-Command.meta.js.map +1 -0
  15. package/dist/src/global/A-Command/A-Command.types.d.ts +43 -0
  16. package/dist/src/global/A-Command/A-Command.types.js +10 -0
  17. package/dist/src/global/A-Command/A-Command.types.js.map +1 -0
  18. package/dist/src/{base → global}/A-Command/context/A_Command.context.d.ts +1 -1
  19. package/dist/src/{base → global}/A-Command/context/A_Command.context.js +1 -1
  20. package/dist/src/global/A-Command/context/A_Command.context.js.map +1 -0
  21. package/dist/src/global/A-Concept/A_Concept.class.js +2 -0
  22. package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
  23. package/dist/src/global/A-Concept/A_Concept.types.d.ts +10 -0
  24. package/dist/src/global/A-Concept/A_Concept.types.js.map +1 -1
  25. package/dist/src/global/A-Context/A-Context.class.d.ts +3 -1
  26. package/dist/src/global/A-Context/A-Context.class.js +16 -6
  27. package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
  28. package/dist/src/global/A-Entity/A-Entity.class.js +1 -4
  29. package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
  30. package/dist/src/global/A-Feature/A-FeatureCaller.class.d.ts +4 -3
  31. package/dist/src/global/A-Feature/A-FeatureCaller.class.js.map +1 -1
  32. package/dist/src/global/A-Scope/A-Scope.class.d.ts +23 -0
  33. package/dist/src/global/A-Scope/A-Scope.class.js +87 -1
  34. package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
  35. package/dist/src/global/A-Scope/A-Scope.types.d.ts +7 -0
  36. package/dist/src/global/A-Stage/A-Stage.class.d.ts +1 -1
  37. package/index.ts +9 -0
  38. package/package.json +2 -2
  39. package/src/decorators/A-Feature/A-Feature-Define.decorator.ts +13 -6
  40. package/src/{base/A-Command/A_Command.entity.ts → global/A-Command/A-Command.class.ts} +149 -35
  41. package/src/global/A-Command/A-Command.meta.ts +22 -0
  42. package/src/global/A-Command/A-Command.types.ts +71 -0
  43. package/src/global/A-Concept/A_Concept.class.ts +3 -0
  44. package/src/global/A-Concept/A_Concept.types.ts +10 -0
  45. package/src/global/A-Context/A-Context.class.ts +23 -5
  46. package/src/global/A-Entity/A-Entity.class.ts +1 -4
  47. package/src/global/A-Feature/A-FeatureCaller.class.ts +4 -3
  48. package/src/global/A-Scope/A-Scope.class.ts +119 -5
  49. package/src/global/A-Scope/A-Scope.types.ts +7 -0
  50. package/tests/A-Command.test.ts +15 -11
  51. package/tests/A-Concept.test.ts +110 -0
  52. package/tests/A-Scope.test.ts +64 -1
  53. package/dist/src/base/A-Command/A_Command.constants.js.map +0 -1
  54. package/dist/src/base/A-Command/A_Command.entity.js.map +0 -1
  55. package/dist/src/base/A-Command/A_Command.types.d.ts +0 -15
  56. package/dist/src/base/A-Command/A_Command.types.js +0 -3
  57. package/dist/src/base/A-Command/A_Command.types.js.map +0 -1
  58. package/dist/src/base/A-Command/context/A_Command.context.js.map +0 -1
  59. package/dist/src/base/A-Command/context/A_CommandFactory.context.d.ts +0 -0
  60. package/dist/src/base/A-Command/context/A_CommandFactory.context.js +0 -2
  61. package/dist/src/base/A-Command/context/A_CommandFactory.context.js.map +0 -1
  62. package/src/base/A-Command/A_Command.types.ts +0 -34
  63. package/src/base/A-Command/context/A_CommandFactory.context.ts +0 -0
  64. /package/dist/src/{base/A-Command/A_Command.constants.d.ts → global/A-Command/A-Command.constants.d.ts} +0 -0
  65. /package/src/{base/A-Command/A_Command.constants.ts → global/A-Command/A-Command.constants.ts} +0 -0
  66. /package/src/{base → global}/A-Command/context/A_Command.context.ts +0 -0
@@ -12,6 +12,7 @@ import {
12
12
  A_TYPES__A_InjectDecorator_EntityInjectionQuery,
13
13
  A_TYPES__A_InjectDecorator_Injectable
14
14
  } from "@adaas/a-concept/decorators/A-Inject/A-Inject.decorator.types";
15
+ import { A_Command } from "../A-Command/A-Command.class";
15
16
 
16
17
 
17
18
  /**
@@ -33,6 +34,7 @@ export class A_Scope {
33
34
 
34
35
  private _components: WeakMap<typeof A_Component.constructor, any> = new WeakMap();
35
36
  private _fragments: WeakMap<typeof A_Fragment.constructor, any> = new WeakMap();
37
+ private _commands: Map<string, A_Command> = new Map();
36
38
  private _entities: Map<string, A_Entity> = new Map();
37
39
 
38
40
  private _parent?: A_Scope;
@@ -52,6 +54,7 @@ export class A_Scope {
52
54
  components: [],
53
55
  fragments: [],
54
56
  entities: [],
57
+ commands: [],
55
58
  };
56
59
 
57
60
 
@@ -90,6 +93,10 @@ export class A_Scope {
90
93
  return this.params.components || [];
91
94
  }
92
95
 
96
+ get commands() {
97
+ return this.params.commands || [];
98
+ }
99
+
93
100
  get fragments() {
94
101
  return this.params.fragments || [];
95
102
  }
@@ -189,7 +196,7 @@ export class A_Scope {
189
196
  has(
190
197
  constructor: string
191
198
  ): boolean
192
- has<T extends A_Fragment | A_Component | A_Entity>(
199
+ has<T extends A_Fragment | A_Component | A_Entity | A_Command>(
193
200
  entity: T | string | (new (...args: any[]) => T)
194
201
  ): boolean {
195
202
 
@@ -221,7 +228,7 @@ export class A_Scope {
221
228
 
222
229
  case typeof entity === 'function'
223
230
  && A_CommonHelper.isInheritedFrom(entity, A_Component): {
224
- const found = this.params.components.includes(entity as { new(...args: any[]): A_Component });
231
+ const found = this.components.includes(entity as { new(...args: any[]): A_Component });
225
232
 
226
233
  if (!found && !!this._parent) {
227
234
  return this._parent.has(entity as any);
@@ -248,6 +255,16 @@ export class A_Scope {
248
255
 
249
256
  return found;
250
257
  }
258
+ case typeof entity === 'function'
259
+ && A_CommonHelper.isInheritedFrom(entity, A_Command): {
260
+ const found = this.commands.includes(entity as { new(...args: any[]): A_Command });
261
+
262
+ if (!found && !!this._parent)
263
+ return this._parent.has(entity as any);
264
+
265
+ return found;
266
+ }
267
+
251
268
 
252
269
  default: {
253
270
  return false;
@@ -292,6 +309,52 @@ export class A_Scope {
292
309
  }
293
310
 
294
311
 
312
+ /**
313
+ * Allows to retrieve the constructor of the component or entity by its name
314
+ *
315
+ * [!] Notes:
316
+ * - In case of search for A-Entity please ensure that provided string corresponds to the static entity property of the class. [!] By default it's the kebab-case of the class name
317
+ * - In case of search for A_Command please ensure that provided string corresponds to the static code property of the class. [!] By default it's the kebab-case of the class name
318
+ * - In case of search for A_Component please ensure that provided string corresponds to the class name in PascalCase
319
+ *
320
+ * @param name
321
+ * @returns
322
+ */
323
+ resolveConstructor<T extends A_Component | A_Entity>(name: string): new (...args: any[]) => T {
324
+ // Check components
325
+ const component = this.params.components.find(c => c.name === A_CommonHelper.toPascalCase(name));
326
+ if (component) return component as any;
327
+
328
+ // Check entities
329
+ const entity = this.params.entities.find(e => (e.constructor as any).entity === name
330
+ || (e.constructor as any).name === A_CommonHelper.toPascalCase(name)
331
+ || (e.constructor as any).entity === A_CommonHelper.toKebabCase(name)
332
+ );
333
+ if (entity) return entity.constructor as any;
334
+
335
+ // Check commands
336
+ const command = this.params.commands.find(c => (c as any).code === name
337
+ || (c as any).name === A_CommonHelper.toPascalCase(name)
338
+ || (c as any).code === A_CommonHelper.toKebabCase(name)
339
+ );
340
+ if (command) return command as any;
341
+
342
+ // If not found in current scope, check parent scope
343
+ if (!!this._parent) {
344
+ return this._parent.resolveConstructor(name);
345
+ }
346
+
347
+ console.log('this.params.components', this.params.components);
348
+ console.log('this.params.entities', this.params.entities);
349
+ console.log('this.params.commands', this.params.commands);
350
+
351
+ throw new Error(`Component or Entity with name ${name} not found in the scope ${this.name}`);
352
+ }
353
+
354
+
355
+
356
+
357
+
295
358
  /**
296
359
  * This method is used to get the component by class
297
360
  *
@@ -343,6 +406,10 @@ export class A_Scope {
343
406
  const component = this.params.components.find(c => c.name === name);
344
407
  if (component) return this.resolveComponent(component);
345
408
 
409
+ // Check commands
410
+ const command = this.params.commands.find(c => c.name === name);
411
+ if (command) return this.resolveComponent(command);
412
+
346
413
  // Check fragments
347
414
  const fragment = this.params.fragments.find(f => f.constructor.name === name);
348
415
  if (fragment) return this.resolveFragment(fragment.constructor as any);
@@ -408,10 +475,8 @@ export class A_Scope {
408
475
 
409
476
  switch (true) {
410
477
  case !instructions: {
411
-
412
478
  const entities = Array.from(this._entities.values());
413
479
 
414
-
415
480
  const found = entities.find(e => e instanceof entity);
416
481
 
417
482
  switch (true) {
@@ -565,6 +630,31 @@ export class A_Scope {
565
630
  }
566
631
 
567
632
 
633
+ /**
634
+ * Should be similar to resolveEntity but for commands
635
+ *
636
+ * @param command
637
+ */
638
+ private resolveCommand<T extends A_Command>(command: {
639
+ new(...args: any[]): T
640
+ }): T {
641
+ const commands = Array.from(this._commands.values());
642
+
643
+ const found = commands.find(e => e instanceof command);
644
+
645
+ switch (true) {
646
+ case !!found:
647
+ return found as T;
648
+
649
+ case !found && !!this._parent:
650
+ return this._parent.resolveCommand(command);
651
+
652
+ default:
653
+ throw new Error(`Command ${command.name} not found in the scope ${this.name}`);
654
+ }
655
+ }
656
+
657
+
568
658
 
569
659
  /**
570
660
  * This method is used to register the component in the scope
@@ -572,11 +662,18 @@ export class A_Scope {
572
662
  * @param fragment
573
663
  */
574
664
  register<T extends A_Component>(component: new (...args: any[]) => T): void
665
+ register<T extends A_Entity>(entity: new (...args: any[]) => T): void
666
+ register<T extends A_Command>(command: new (...args: any[]) => T): void
575
667
  register(entity: A_Entity): void
576
668
  register(component: A_Component): void
577
669
  register(fragment: A_Fragment): void
578
670
  register(
579
- param1: A_Fragment | A_Component | A_Entity | (new (...args: any[]) => A_Component)
671
+ param1: A_Fragment
672
+ | A_Component
673
+ | A_Entity
674
+ | (new (...args: any[]) => A_Component)
675
+ | (new (...args: any[]) => A_Entity)
676
+ | (new (...args: any[]) => A_Command)
580
677
  ): void {
581
678
  switch (true) {
582
679
  case param1 instanceof A_Component && !this._components.has(param1.constructor): {
@@ -630,6 +727,23 @@ export class A_Scope {
630
727
  this.components.push(param1);
631
728
  break;
632
729
  }
730
+ case typeof param1 === 'function' && A_CommonHelper.isInheritedFrom(param1, A_Entity): {
731
+ const allowedEntity = this.params.entities.find(e => e.constructor === param1);
732
+
733
+ if (!allowedEntity) {
734
+ this.params.entities.push(new (param1 as any)());
735
+ }
736
+ break;
737
+ }
738
+ case typeof param1 === 'function' && A_CommonHelper.isInheritedFrom(param1, A_Command): {
739
+ const allowedCommand = this.commands.find(c => c === param1);
740
+
741
+ if (!allowedCommand) {
742
+ this.commands.push(param1 as any);
743
+ }
744
+ break;
745
+ }
746
+
633
747
  default:
634
748
  if (param1 instanceof A_Entity)
635
749
  throw new Error(`Entity with ASEID ${param1.aseid.toString()} is already registered in the scope ${this.name}`);
@@ -1,3 +1,4 @@
1
+ import { A_Command } from "../A-Command/A-Command.class"
1
2
  import { A_Component } from "../A-Component/A-Component.class"
2
3
  import { A_Entity } from "../A-Entity/A-Entity.class"
3
4
  import { A_Fragment } from "../A-Fragment/A-Fragment.class"
@@ -25,6 +26,12 @@ export type A_TYPES__ScopeConstructor = {
25
26
  */
26
27
  entities: Array<A_Entity>
27
28
 
29
+
30
+ /**
31
+ * A set of Commands available in the Scope
32
+ */
33
+ commands: Array<{ new(...args: any[]): A_Command }>
34
+
28
35
  /**
29
36
  * A list of Features/Lifecycle Hooks available in the Scope
30
37
  */
@@ -1,14 +1,15 @@
1
1
 
2
2
 
3
3
 
4
- import { A_CONSTANTS__A_Command_Status, A_CONSTANTS_A_Command_Features } from "@adaas/a-concept/base/A-Command/A_Command.constants";
5
- import { A_Command } from "@adaas/a-concept/base/A-Command/A_Command.entity";
6
- import { A_CommandContext } from "@adaas/a-concept/base/A-Command/context/A_Command.context";
4
+ import { A_CONSTANTS__A_Command_Status, A_CONSTANTS_A_Command_Features } from "@adaas/a-concept/global/A-Command/A-Command.constants";
5
+ import { A_Command } from "@adaas/a-concept/global/A-Command/A-Command.class";
6
+ import { A_CommandContext } from "@adaas/a-concept/global/A-Command/context/A_Command.context";
7
7
  import { A_Inject } from "@adaas/a-concept/decorators/A-Inject/A-Inject.decorator";
8
8
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
9
9
  import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
10
10
  import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
11
11
  import { A_Error } from "@adaas/a-utils";
12
+ import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
12
13
 
13
14
  jest.retryTimes(0);
14
15
 
@@ -17,7 +18,7 @@ describe('A-Command tests', () => {
17
18
  it('Should Allow to create a command', async () => {
18
19
  const command = new A_Command({});
19
20
  expect(command).toBeInstanceOf(A_Command);
20
- expect(command.Code).toBe('A_Command');
21
+ expect(command.Code).toBe('a-command');
21
22
  expect(command.id).toBeDefined();
22
23
  expect(command.aseid).toBeDefined();
23
24
  expect(command.Status).toBe(A_CONSTANTS__A_Command_Status.INITIALIZED);
@@ -58,12 +59,15 @@ describe('A-Command tests', () => {
58
59
  it('Should allow to execute a command with custom logic', async () => {
59
60
 
60
61
  // 1) create a scope
61
- const scope = new A_Scope({ name: 'TestScope' });
62
+ A_Context.reset();
63
+
62
64
  // 2) create a new command
63
65
  type resultType = { bar: string };
64
66
  type invokeType = { foo: string };
65
67
  class MyCommand extends A_Command<invokeType, resultType> { }
66
68
 
69
+ A_Context.root.register(MyCommand);
70
+
67
71
  // 3) create a custom component with custom logic
68
72
  class MyComponent extends A_Component {
69
73
 
@@ -76,11 +80,10 @@ describe('A-Command tests', () => {
76
80
  }
77
81
 
78
82
  // 4) register component in the scope
79
- scope.register(MyComponent);
83
+ A_Context.root.register(MyComponent);
80
84
 
81
85
  // 5) create a new command instance within the scope
82
86
  const command = new MyCommand({ foo: 'bar' });
83
- scope.register(command);
84
87
 
85
88
  // 6) execute the command
86
89
  await command.execute();
@@ -91,14 +94,16 @@ describe('A-Command tests', () => {
91
94
  expect(command.Result).toEqual({ bar: 'baz' });
92
95
  })
93
96
  it('Should allow to fail a command with custom logic', async () => {
97
+ // 1) reset context to have a clean scope
98
+ A_Context.reset();
94
99
 
95
- // 1) create a scope
96
- const scope = new A_Scope({ name: 'TestScope' });
97
100
  // 2) create a new command
98
101
  type resultType = { bar: string };
99
102
  type invokeType = { foo: string };
100
103
  class MyCommand extends A_Command<invokeType, resultType> { }
101
104
 
105
+ A_Context.root.register(MyCommand);
106
+
102
107
  // 3) create a custom component with custom logic
103
108
  class MyComponent extends A_Component {
104
109
 
@@ -113,10 +118,9 @@ describe('A-Command tests', () => {
113
118
  }
114
119
 
115
120
  // 4) register component in the scope
116
- scope.register(MyComponent);
121
+ A_Context.root.register(MyComponent);
117
122
  // 5) create a new command instance within the scope
118
123
  const command = new MyCommand({ foo: 'bar' });
119
- scope.register(command);
120
124
 
121
125
  // 6) execute the command
122
126
  await command.execute();
@@ -0,0 +1,110 @@
1
+ import { A_Command } from "@adaas/a-concept/global/A-Command/A-Command.class";
2
+ import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
3
+ import { A_Concept } from "@adaas/a-concept/global/A-Concept/A_Concept.class";
4
+ import { A_Container } from "@adaas/a-concept/global/A-Container/A-Container.class";
5
+ import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
6
+ import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
7
+ import { A_Fragment } from "@adaas/a-concept/global/A-Fragment/A-Fragment.class";
8
+ import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
9
+
10
+
11
+ jest.retryTimes(0);
12
+
13
+ describe('A-Concept tests', () => {
14
+
15
+ it('Should Allow to create a concept', async () => {
16
+ const concept = new A_Concept({ name: 'TestConcept' });
17
+ expect(concept).toBeInstanceOf(A_Concept);
18
+ expect(concept.Scope).toBeDefined();
19
+ expect(concept.Scope).toBeInstanceOf(A_Scope);
20
+ });
21
+ it('Should allow to load a concept', async () => {
22
+ const concept = new A_Concept({ name: 'TestConcept' });
23
+ await concept.load();
24
+ });
25
+ it('Should allow to run concept abstractions', async () => {
26
+ const concept = new A_Concept({ name: 'TestConcept' });
27
+ await concept.load();
28
+ await concept.start();
29
+ await concept.deploy();
30
+ await concept.build();
31
+ await concept.publish();
32
+ await concept.stop();
33
+ });
34
+ it('Should allow to provide all base entities to the concept', async () => {
35
+ A_Context.reset();
36
+
37
+ class MyCommand extends A_Command { }
38
+ class MyEntity extends A_Entity { }
39
+ class MyComponent extends A_Component { }
40
+ class MyContainer extends A_Container { }
41
+ class MyContext extends A_Fragment { }
42
+
43
+ const concept = new A_Concept({
44
+ name: 'TestConcept',
45
+ commands: [MyCommand],
46
+ entities: [new MyEntity()],
47
+ components: [MyComponent],
48
+ containers: [new MyContainer({ name: 'test' })],
49
+ fragments: [new MyContext({ name: 'test' })]
50
+ });
51
+
52
+
53
+ expect(concept.Scope.resolveConstructor('MyCommand')).toBe(MyCommand);
54
+ expect(concept.Scope.resolve(MyEntity)).toBeInstanceOf(MyEntity);
55
+ expect(concept.Scope.resolve(MyComponent)).toBeInstanceOf(MyComponent);
56
+ expect(concept.Scope.resolve(MyContext)).toBeInstanceOf(MyContext);
57
+ });
58
+ it('Should allow to separate entities by containers', async () => {
59
+ A_Context.reset();
60
+
61
+ class MyCommandA extends A_Command { }
62
+ class MyCommandB extends A_Command { }
63
+ class MyComponentA extends A_Component { }
64
+ class MyComponentB extends A_Component { }
65
+ class MyContainer extends A_Container { }
66
+ class MyContext extends A_Fragment { }
67
+
68
+ const containerA = new MyContainer({
69
+ name: 'test',
70
+ commands: [MyCommandA],
71
+ components: [MyComponentA]
72
+
73
+ });
74
+
75
+ const containerB = new MyContainer({
76
+ name: 'test2',
77
+ commands: [MyCommandB],
78
+ components: [MyComponentB]
79
+ })
80
+
81
+ const sharedContext = new MyContext({ name: 'test' })
82
+
83
+ const concept = new A_Concept({
84
+ name: 'TestConcept',
85
+ containers: [
86
+ containerA,
87
+ containerB
88
+
89
+ ],
90
+ fragments: [sharedContext]
91
+ });
92
+
93
+ const containerAScope = A_Context.scope(containerA)
94
+ const containerBScope = A_Context.scope(containerB)
95
+
96
+ expect(containerAScope.resolveConstructor('MyCommandA')).toBe(MyCommandA);
97
+ expect(() => {
98
+ containerAScope.resolveConstructor('MyCommandB');
99
+ }).toThrow();
100
+
101
+ expect(containerBScope.resolveConstructor('MyCommandB')).toBe(MyCommandB);
102
+ expect(() => {
103
+ containerBScope.resolveConstructor('MyCommandA');
104
+ }).toThrow();
105
+
106
+ expect(concept.Scope.resolve(MyContext)).toEqual(sharedContext);
107
+ expect(concept.Scope.resolve(MyContext)).toEqual(sharedContext);
108
+ });
109
+
110
+ });
@@ -1,3 +1,4 @@
1
+ import { A_Command } from "@adaas/a-concept/global/A-Command/A-Command.class";
1
2
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
2
3
  import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
3
4
  import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
@@ -49,7 +50,7 @@ describe('A-Scope tests', () => {
49
50
 
50
51
  it('should resolve component registered in parent scope', async () => {
51
52
  const parentScope = new A_Scope({ name: 'ParentScope' });
52
- const childScope = new A_Scope({ name: 'ChildScope'});
53
+ const childScope = new A_Scope({ name: 'ChildScope' });
53
54
 
54
55
  childScope.parent(parentScope);
55
56
 
@@ -159,5 +160,67 @@ describe('A-Scope tests', () => {
159
160
  });
160
161
 
161
162
  });
163
+ it('Should allow to resolve A-Entity by classname', async () => {
164
+ class MyEntity extends A_Entity<{ foo: string }> {
165
+ public foo!: string;
166
+
167
+ fromUndefined(): void {
168
+ super.fromUndefined();
169
+ this.foo = 'bar';
170
+ }
171
+
172
+ }
173
+
174
+ const scope = new A_Scope({ name: 'TestScope' });
175
+ scope.register(MyEntity);
176
+
177
+ const resolved = scope.resolveConstructor<MyEntity>('my_entity');
178
+ const resolved2 = scope.resolveConstructor<MyEntity>('my-entity');
179
+ const resolved3 = scope.resolveConstructor<MyEntity>('MyEntity');
180
+ expect(resolved).toBe(MyEntity);
181
+ expect(resolved2).toBe(MyEntity);
182
+ expect(resolved3).toBe(MyEntity);
183
+
184
+ expect(() => {
185
+ scope.resolveConstructor<MyEntity>('my__entity');
186
+ }).toThrow();
187
+
188
+ const instance = new resolved();
162
189
 
190
+ expect(instance).toBeInstanceOf(MyEntity);
191
+ expect(instance.foo).toBe('bar');
192
+
193
+ });
194
+ it('Should allow to resolve A-Command by classname', async () => {
195
+ class MyCommand extends A_Command<{ foo: string }, { bar: string }> {
196
+ public foo!: string;
197
+
198
+ fromNew(newCommand: { foo: string; }): void {
199
+ super.fromNew(newCommand);
200
+ this.foo = newCommand.foo;
201
+ }
202
+
203
+ }
204
+
205
+ const scope = new A_Scope({ name: 'TestScope' });
206
+ scope.register(MyCommand);
207
+
208
+ const resolved = scope.resolveConstructor<MyCommand>('my-command');
209
+ const resolved2 = scope.resolveConstructor<MyCommand>('my_command');
210
+ const resolved3 = scope.resolveConstructor<MyCommand>('MyCommand');
211
+ expect(resolved).toBe(MyCommand);
212
+ expect(resolved2).toBe(MyCommand);
213
+ expect(resolved3).toBe(MyCommand);
214
+
215
+ expect(() => {
216
+ scope.resolveConstructor<MyCommand>('my--command');
217
+ }).toThrow();
218
+
219
+
220
+ const instance = new resolved({ foo: 'bar' });
221
+
222
+ expect(instance).toBeInstanceOf(MyCommand);
223
+ expect(instance.foo).toBe('bar');
224
+
225
+ });
163
226
  });
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_Command.constants.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.constants.ts"],"names":[],"mappings":";;;AAEA,IAAY,6BAKX;AALD,WAAY,6BAA6B;IACrC,4DAA2B,CAAA;IAC3B,4DAA2B,CAAA;IAC3B,wDAAuB,CAAA;IACvB,kDAAiB,CAAA;AACrB,CAAC,EALW,6BAA6B,6CAA7B,6BAA6B,QAKxC;AAED,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACtC,qDAAmB,CAAA;IACnB,uDAAqB,CAAA;IACrB,+CAAa,CAAA;AACjB,CAAC,EAJW,8BAA8B,8CAA9B,8BAA8B,QAIzC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_Command.entity.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,oFAA2E;AAE3E,4CAAyC;AACzC,iFAAwE;AACxE,uFAA8E;AAC9E,mEAA+D;AAC/D,+DAAoI;AAGpI,MAAa,SAGX,SAAQ,yBAGT;IAcG;;OAEG;IACH,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU;YACnC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACrD,CAAC,CAAC,IAAI,CAAC,UAAU;gBACb,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;gBAClD,CAAC,CAAC,SAAS,CAAC;IACxB,CAAC;IAGD;;;;OAIG;IACH,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAA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;AAMK;IADL,2BAAS,CAAC,MAAM,EAAE;iCAOlB;AAOK;IADL,2BAAS,CAAC,MAAM,EAAE;iCAOlB"}
@@ -1,15 +0,0 @@
1
- import { A_TYPES__Entity_JSON } from "../../global/A-Entity/A-Entity.types";
2
- import { A_Command } from "./A_Command.entity";
3
- import { A_CONSTANTS__A_Command_Status } from "./A_Command.constants";
4
- import { A_TYPES__Error } from "@adaas/a-utils";
5
- export type A_TYPES__Command_Constructor = {};
6
- export type A_TYPES__Command_Serialized<ResultType extends Record<string, any> = Record<string, any>> = {
7
- code: string;
8
- status: A_CONSTANTS__A_Command_Status;
9
- startedAt?: string;
10
- endedAt?: string;
11
- duration?: number;
12
- result?: ResultType;
13
- errors?: Array<A_TYPES__Error>;
14
- } & A_TYPES__Entity_JSON;
15
- export type A_TYPES__Command_Listener<T extends Record<string, any> = Record<string, any>> = (command?: A_Command<any, T>) => void;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=A_Command.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_Command.types.js","sourceRoot":"","sources":["../../../../src/base/A-Command/A_Command.types.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_Command.context.js","sourceRoot":"","sources":["../../../../../src/base/A-Command/context/A_Command.context.ts"],"names":[],"mappings":";;;AAAA,0FAAiF;AAIjF,MAAa,gBAEX,SAAQ,6BAAU;IAchB;;;OAGG;IACH,YAAY,gBAAmB,EAAO;QAClC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC7B,CAAC;IAGD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI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- {"version":3,"file":"A_CommandFactory.context.js","sourceRoot":"","sources":["../../../../../src/base/A-Command/context/A_CommandFactory.context.ts"],"names":[],"mappings":""}
@@ -1,34 +0,0 @@
1
- import { A_TYPES__Entity_JSON } from "@adaas/a-concept/global/A-Entity/A-Entity.types";
2
- import { A_CommandContext } from "./context/A_Command.context";
3
- import { A_Command } from "./A_Command.entity";
4
- import { A_CONSTANTS__A_Command_Status } from "./A_Command.constants";
5
- import { A_Error, A_TYPES__Error } from "@adaas/a-utils";
6
-
7
-
8
-
9
- export type A_TYPES__Command_Constructor = {
10
- }
11
-
12
-
13
-
14
- export type A_TYPES__Command_Serialized<
15
- ResultType extends Record<string, any> = Record<string, any>
16
- > = {
17
- code: string;
18
- status: A_CONSTANTS__A_Command_Status;
19
-
20
- startedAt?: string;
21
- endedAt?: string;
22
- duration?: number;
23
-
24
- result?: ResultType;
25
- errors?: Array<A_TYPES__Error>;
26
-
27
- } & A_TYPES__Entity_JSON
28
-
29
-
30
-
31
-
32
- export type A_TYPES__Command_Listener<
33
- T extends Record<string, any> = Record<string, any>
34
- > = (command?: A_Command<any, T>) => void;