@adaas/a-concept 0.1.31 → 0.1.32

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.
@@ -1,204 +1,201 @@
1
1
  import { A_Component } from '@adaas/a-concept/global/A-Component/A-Component.class';
2
- import './test.setup'
3
2
  import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
4
3
  import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
5
4
  import { A_Context } from '@adaas/a-concept/global/A-Context/A-Context.class';
6
- import { A_Scope } from '@adaas/a-concept/global/A-Scope/A-Scope.class';
7
- import { A_TYPES__ConceptAbstractions } from '@adaas/a-concept/global/A-Concept/A-Concept.constants';
8
5
  import { A_Inject } from '@adaas/a-concept/global/A-Inject/A-Inject.decorator';
9
6
  import { A_Feature } from '@adaas/a-concept/global/A-Feature/A-Feature.class';
10
7
 
11
8
  jest.retryTimes(0);
12
9
 
13
10
  describe('A-Abstraction Tests', () => {
14
- // it('It should be possible to extend abstraction on A-Component level', async () => {
15
- // class MyComponent extends A_Component {
16
- // private _test: number = 0
17
-
18
- // @A_Concept.Load()
19
- // myMethod() {
20
- // this._test++;
21
- // }
22
- // }
23
- // });
24
-
25
- // it('It should be possible to extend abstraction on A-Container level', async () => {
26
- // class MyContainer extends A_Container {
27
- // private _test: number = 0
28
-
29
- // @A_Concept.Load()
30
- // myMethod() {
31
- // this._test++;
32
- // }
33
- // }
34
- // });
35
-
36
-
37
- // it('It should be possible to proceed Concept Abstraction', async () => {
38
- // class MyComponent extends A_Component {
39
- // _test2: number = 0
40
-
41
- // @A_Concept.Load()
42
- // myMethod() {
43
- // this._test2++;
44
- // }
45
- // }
46
-
47
- // class MyContainer extends A_Container {
48
- // _test: number = 0
49
-
50
- // @A_Concept.Load()
51
- // myMethod() {
52
- // this._test++;
53
- // }
54
- // }
55
-
56
- // const myContainer = new MyContainer({
57
- // name: 'MyContainer',
58
- // components: [MyComponent]
59
- // });
60
-
61
- // const testConcept = new A_Concept({
62
- // name: 'TestConcept',
63
- // containers: [myContainer]
64
- // });
65
-
66
- // await testConcept.load();
67
-
68
-
69
- // const resolvedComponent = myContainer.scope.resolve(MyComponent);
70
-
71
- // expect(resolvedComponent).toBeInstanceOf(MyComponent);
72
- // expect(myContainer._test).toBe(1);
73
- // expect(resolvedComponent._test2).toBe(1);
74
-
75
- // });
76
- // it('Should allow to extend abstraction with multiple containers', async () => {
77
- // A_Context.reset();
78
-
79
- // class MyContainerA extends A_Container {
80
- // _test: number = 0
81
-
82
- // @A_Concept.Load()
83
- // myMethod() {
84
- // this._test++;
85
- // }
86
- // }
87
- // class MyContainerB extends A_Container {
88
- // _test: number = 0
89
-
90
- // @A_Concept.Load()
91
- // myMethod() {
92
- // this._test++;
93
- // }
94
- // }
95
-
96
- // const containerA = new MyContainerA({ name: 'ContainerA' });
97
- // const containerB = new MyContainerB({ name: 'ContainerB' });
98
-
99
- // const concept = new A_Concept({
100
- // name: 'TestConcept',
101
- // containers: [
102
- // containerA,
103
- // containerB
104
- // ]
105
- // });
106
-
107
- // await concept.load();
108
-
109
- // expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
110
- // expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
111
-
112
- // expect(containerA._test).toBe(1);
113
- // expect(containerB._test).toBe(1);
114
-
115
- // })
116
- // it('Should allow to define an async abstraction extension', async () => {
117
- // A_Context.reset();
118
-
119
- // class MyContainerA extends A_Container {
120
- // _test: number = 0
121
-
122
- // @A_Concept.Load()
123
- // async myMethod() {
124
- // this._test = 5;
125
- // }
126
- // }
127
- // class MyContainerB extends A_Container {
128
- // _test: number = 0
129
-
130
- // @A_Concept.Load()
131
- // myMethod() {
132
- // this._test++;
133
- // }
134
- // }
11
+ it('It should be possible to extend abstraction on A-Component level', async () => {
12
+ class MyComponent extends A_Component {
13
+ private _test: number = 0
135
14
 
15
+ @A_Concept.Load()
16
+ myMethod() {
17
+ this._test++;
18
+ }
19
+ }
20
+ });
21
+
22
+ it('It should be possible to extend abstraction on A-Container level', async () => {
23
+ class MyContainer extends A_Container {
24
+ private _test: number = 0
25
+
26
+ @A_Concept.Load()
27
+ myMethod() {
28
+ this._test++;
29
+ }
30
+ }
31
+ });
32
+
33
+
34
+ it('It should be possible to proceed Concept Abstraction', async () => {
35
+ class MyComponent extends A_Component {
36
+ _test2: number = 0
37
+
38
+ @A_Concept.Load()
39
+ myMethod() {
40
+ this._test2++;
41
+ }
42
+ }
43
+
44
+ class MyContainer extends A_Container {
45
+ _test: number = 0
46
+
47
+ @A_Concept.Load()
48
+ myMethod() {
49
+ this._test++;
50
+ }
51
+ }
52
+
53
+ const myContainer = new MyContainer({
54
+ name: 'MyContainer',
55
+ components: [MyComponent]
56
+ });
57
+
58
+ const testConcept = new A_Concept({
59
+ name: 'TestConcept',
60
+ containers: [myContainer]
61
+ });
62
+
63
+ await testConcept.load();
64
+
65
+
66
+ const resolvedComponent = myContainer.scope.resolve(MyComponent)!;
67
+
68
+ expect(resolvedComponent).toBeInstanceOf(MyComponent);
69
+ expect(myContainer._test).toBe(1);
70
+ expect(resolvedComponent._test2).toBe(1);
71
+
72
+ });
73
+ it('Should allow to extend abstraction with multiple containers', async () => {
74
+ A_Context.reset();
75
+
76
+ class MyContainerA extends A_Container {
77
+ _test: number = 0
78
+
79
+ @A_Concept.Load()
80
+ myMethod() {
81
+ this._test++;
82
+ }
83
+ }
84
+ class MyContainerB extends A_Container {
85
+ _test: number = 0
86
+
87
+ @A_Concept.Load()
88
+ myMethod() {
89
+ this._test++;
90
+ }
91
+ }
92
+
93
+ const containerA = new MyContainerA({ name: 'ContainerA' });
94
+ const containerB = new MyContainerB({ name: 'ContainerB' });
95
+
96
+ const concept = new A_Concept({
97
+ name: 'TestConcept',
98
+ containers: [
99
+ containerA,
100
+ containerB
101
+ ]
102
+ });
103
+
104
+ await concept.load();
105
+
106
+ expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
107
+ expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
108
+
109
+ expect(containerA._test).toBe(1);
110
+ expect(containerB._test).toBe(1);
111
+
112
+ })
113
+ it('Should allow to define an async abstraction extension', async () => {
114
+ A_Context.reset();
115
+
116
+ class MyContainerA extends A_Container {
117
+ _test: number = 0
118
+
119
+ @A_Concept.Load()
120
+ async myMethod() {
121
+ this._test = 5;
122
+ }
123
+ }
124
+ class MyContainerB extends A_Container {
125
+ _test: number = 0
126
+
127
+ @A_Concept.Load()
128
+ myMethod() {
129
+ this._test++;
130
+ }
131
+ }
132
+
133
+
134
+ const containerA = new MyContainerA({ name: 'ContainerA' });
135
+ const containerB = new MyContainerB({ name: 'ContainerB' });
136
+
137
+ const concept = new A_Concept({
138
+ name: 'TestConcept',
139
+ containers: [
140
+ containerA,
141
+ containerB
142
+ ]
143
+ });
144
+
145
+ await concept.load();
146
+
147
+ expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
148
+ expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
149
+
150
+ expect(containerA._test).toBe(5);
151
+ expect(containerB._test).toBe(1);
152
+ })
153
+ it('Should execute abstraction in a proper order', async () => {
154
+ A_Context.reset();
155
+
156
+ const order: string[] = [];
157
+
158
+ class MyContainerA extends A_Container {
159
+
160
+ @A_Concept.Load()
161
+ async step1() {
162
+ order.push('step1');
163
+ }
164
+
165
+ @A_Concept.Load()
166
+ async step2() {
167
+ order.push('step2');
168
+ }
169
+ }
170
+ class MyContainerB extends A_Container {
171
+
172
+ @A_Concept.Load()
173
+ async step3() {
174
+ order.push('step3');
175
+ }
176
+
177
+ @A_Concept.Load()
178
+ async step4() {
179
+ order.push('step4');
180
+ }
181
+ }
136
182
 
137
- // const containerA = new MyContainerA({ name: 'ContainerA' });
138
- // const containerB = new MyContainerB({ name: 'ContainerB' });
139
-
140
- // const concept = new A_Concept({
141
- // name: 'TestConcept',
142
- // containers: [
143
- // containerA,
144
- // containerB
145
- // ]
146
- // });
147
-
148
- // await concept.load();
149
-
150
- // expect(containerA.scope.resolve(MyContainerA)).toBeInstanceOf(MyContainerA);
151
- // expect(containerB.scope.resolve(MyContainerB)).toBeInstanceOf(MyContainerB);
152
-
153
- // expect(containerA._test).toBe(5);
154
- // expect(containerB._test).toBe(1);
155
- // })
156
- // it('Should execute abstraction in a proper order', async () => {
157
- // A_Context.reset();
158
-
159
- // const order: string[] = [];
160
-
161
- // class MyContainerA extends A_Container {
162
-
163
- // @A_Concept.Load()
164
- // async step1() {
165
- // order.push('step1');
166
- // }
167
183
 
168
- // @A_Concept.Load()
169
- // async step2() {
170
- // order.push('step2');
171
- // }
172
- // }
173
- // class MyContainerB extends A_Container {
174
-
175
- // @A_Concept.Load()
176
- // async step3() {
177
- // order.push('step3');
178
- // }
179
-
180
- // @A_Concept.Load()
181
- // async step4() {
182
- // order.push('step4');
183
- // }
184
- // }
185
-
186
-
187
- // const containerA = new MyContainerA({ name: 'ContainerA' });
188
- // const containerB = new MyContainerB({ name: 'ContainerB' });
189
-
190
- // const concept = new A_Concept({
191
- // name: 'TestConcept',
192
- // containers: [
193
- // containerA,
194
- // containerB
195
- // ]
196
- // });
197
-
198
- // await concept.load();
199
-
200
- // expect(order).toEqual(['step1', 'step2', 'step3', 'step4']);
201
- // })
184
+ const containerA = new MyContainerA({ name: 'ContainerA' });
185
+ const containerB = new MyContainerB({ name: 'ContainerB' });
186
+
187
+ const concept = new A_Concept({
188
+ name: 'TestConcept',
189
+ containers: [
190
+ containerA,
191
+ containerB
192
+ ]
193
+ });
194
+
195
+ await concept.load();
196
+
197
+ expect(order).toEqual(['step1', 'step2', 'step3', 'step4']);
198
+ })
202
199
  it('Should execute abstraction in order with dependencies', async () => {
203
200
  A_Context.reset();
204
201
 
@@ -274,69 +271,69 @@ describe('A-Abstraction Tests', () => {
274
271
 
275
272
  expect(order).toEqual(['step1', 'step3', 'step2', 'step5', 'step4']);
276
273
  })
277
- // it('Should inherit abstraction extensions', async () => {
278
- // const executionOrder: string[] = [];
279
-
280
- // // 1) create a base component with some abstraction
281
- // class My_Component extends A_Component {
282
-
283
- // @A_Concept.Load()
284
- // async feature1() {
285
- // executionOrder.push('stepOne');
286
- // }
287
- // }
288
-
289
-
290
- // class My_Child_Component extends My_Component { }
291
-
292
- // const concept = new A_Concept({
293
- // name: 'TestConcept',
294
- // containers: [
295
- // new A_Container({
296
- // name: 'TestContainer',
297
- // components: [My_Child_Component],
298
- // })
299
- // ]
300
- // });
301
-
302
- // await concept.load();
303
-
304
- // expect(executionOrder).toEqual(['stepOne']);
305
- // });
306
- // it('Should allow to override abstraction extensions', async () => {
307
- // const executionOrder: string[] = [];
308
-
309
- // // 1) create a base component with some abstraction
310
- // class My_Component extends A_Component {
311
-
312
- // @A_Concept.Load()
313
- // async feature1() {
314
- // executionOrder.push('stepOne');
315
- // }
316
- // }
317
-
318
-
319
- // class My_Child_Component extends My_Component {
320
- // @A_Concept.Load()
321
- // async feature1() {
322
- // // do nothing
323
- // executionOrder.push('stepTwo');
324
-
325
- // }
326
- // }
327
-
328
- // const concept = new A_Concept({
329
- // name: 'TestConcept',
330
- // containers: [
331
- // new A_Container({
332
- // name: 'TestContainer',
333
- // components: [My_Child_Component],
334
- // })
335
- // ]
336
- // });
337
-
338
- // await concept.load();
339
-
340
- // expect(executionOrder).toEqual(['stepTwo']);
341
- // });
274
+ it('Should inherit abstraction extensions', async () => {
275
+ const executionOrder: string[] = [];
276
+
277
+ // 1) create a base component with some abstraction
278
+ class My_Component extends A_Component {
279
+
280
+ @A_Concept.Load()
281
+ async feature1() {
282
+ executionOrder.push('stepOne');
283
+ }
284
+ }
285
+
286
+
287
+ class My_Child_Component extends My_Component { }
288
+
289
+ const concept = new A_Concept({
290
+ name: 'TestConcept',
291
+ containers: [
292
+ new A_Container({
293
+ name: 'TestContainer',
294
+ components: [My_Child_Component],
295
+ })
296
+ ]
297
+ });
298
+
299
+ await concept.load();
300
+
301
+ expect(executionOrder).toEqual(['stepOne']);
302
+ });
303
+ it('Should allow to override abstraction extensions', async () => {
304
+ const executionOrder: string[] = [];
305
+
306
+ // 1) create a base component with some abstraction
307
+ class My_Component extends A_Component {
308
+
309
+ @A_Concept.Load()
310
+ async feature1() {
311
+ executionOrder.push('stepOne');
312
+ }
313
+ }
314
+
315
+
316
+ class My_Child_Component extends My_Component {
317
+ @A_Concept.Load()
318
+ async feature1() {
319
+ // do nothing
320
+ executionOrder.push('stepTwo');
321
+
322
+ }
323
+ }
324
+
325
+ const concept = new A_Concept({
326
+ name: 'TestConcept',
327
+ containers: [
328
+ new A_Container({
329
+ name: 'TestContainer',
330
+ components: [My_Child_Component],
331
+ })
332
+ ]
333
+ });
334
+
335
+ await concept.load();
336
+
337
+ expect(executionOrder).toEqual(['stepTwo']);
338
+ });
342
339
  });
@@ -1,4 +1,3 @@
1
- import './test.setup'
2
1
  import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
3
2
  import { A_IdentityHelper } from "@adaas/a-concept/helpers/A_Identity.helper";
4
3
  import { A_TYPES__DeepPartial } from "@adaas/a-concept/types/A_Common.types";
@@ -1,6 +1,4 @@
1
1
  import { A_Inject } from '@adaas/a-concept/global/A-Inject/A-Inject.decorator';
2
- import './test.setup';
3
-
4
2
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
5
3
  import { A_Context } from '@adaas/a-concept/global/A-Context/A-Context.class';
6
4
  import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
@@ -1,11 +1,9 @@
1
1
  import { A_Caller } from '@adaas/a-concept/global/A-Caller/A_Caller.class';
2
- import './test.setup';
3
2
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
4
3
  import { A_Concept } from "@adaas/a-concept/global/A-Concept/A-Concept.class";
5
4
  import { A_Container } from "@adaas/a-concept/global/A-Container/A-Container.class";
6
5
  import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
7
6
  import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
8
- import { A_TYPES__Entity_Init, A_TYPES__Entity_Serialized } from '@adaas/a-concept/global/A-Entity/A-Entity.types';
9
7
  import { A_Fragment } from "@adaas/a-concept/global/A-Fragment/A-Fragment.class";
10
8
  import { A_Inject } from '@adaas/a-concept/global/A-Inject/A-Inject.decorator';
11
9
  import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
@@ -1,5 +1,4 @@
1
1
  import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
2
- import './test.setup';
3
2
  import { A_Scope } from '@adaas/a-concept/global/A-Scope/A-Scope.class';
4
3
 
5
4
 
@@ -1,5 +1,3 @@
1
- import './test.setup';
2
-
3
1
  import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "@adaas/a-concept/constants/env.constants";
4
2
  import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
5
3
  import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
@@ -1,5 +1,3 @@
1
- import './test.setup';
2
-
3
1
  import { A_Inject } from "@adaas/a-concept/global/A-Inject/A-Inject.decorator";
4
2
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
5
3
  import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
@@ -0,0 +1,53 @@
1
+ import { A_Component, A_Error, A_Inject, A_Scope } from "../src";
2
+
3
+ jest.retryTimes(0);
4
+
5
+ describe('A-Inject tests', () => {
6
+
7
+ it('Should to Inject Error into constructor', async () => {
8
+
9
+ class testComponent extends A_Component {
10
+
11
+ constructor(
12
+ @A_Inject(A_Error) public error: A_Error
13
+ ) {
14
+ super();
15
+ }
16
+
17
+ }
18
+
19
+ const scope = new A_Scope({ name: 'TestScope', components: [testComponent] });
20
+
21
+ scope.register(new A_Error('Test Error'));
22
+
23
+ const resolvedComponent = scope.resolve(testComponent)!;
24
+
25
+ expect(resolvedComponent).toBeInstanceOf(testComponent);
26
+ expect(resolvedComponent.error).toBeInstanceOf(A_Error);
27
+ expect(resolvedComponent.error.message).toBe('Test Error');
28
+ });
29
+
30
+
31
+ it('Should to Inject another component into constructor', async () => {
32
+
33
+ class componentA extends A_Component {
34
+ }
35
+
36
+ class componentB extends A_Component {
37
+
38
+ constructor(
39
+ @A_Inject(componentA) public component: componentA
40
+ ) {
41
+ super();
42
+ }
43
+
44
+ }
45
+
46
+ const scope = new A_Scope({ name: 'TestScope', components: [componentA, componentB] });
47
+
48
+ const resolvedComponent = scope.resolve(componentB)!;
49
+
50
+ expect(resolvedComponent).toBeInstanceOf(componentB);
51
+ expect(resolvedComponent.component).toBeInstanceOf(componentA);
52
+ });
53
+ })
@@ -1,6 +1,3 @@
1
- import './test.setup';
2
-
3
- import { A_Command } from "@adaas/a-concept/base/A-Command/A-Command.entity";
4
1
  import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
5
2
  import { A_Concept } from '@adaas/a-concept/global/A-Concept/A-Concept.class';
6
3
  import { A_Container } from '@adaas/a-concept/global/A-Container/A-Container.class';
@@ -10,6 +7,7 @@ import { A_Feature } from '@adaas/a-concept/global/A-Feature/A-Feature.class';
10
7
  import { A_Fragment } from '@adaas/a-concept/global/A-Fragment/A-Fragment.class';
11
8
  import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
12
9
  import { ASEID } from '@adaas/a-concept/global/ASEID/ASEID.class';
10
+ import { A_Error } from '../src';
13
11
 
14
12
  jest.retryTimes(0);
15
13
 
@@ -326,4 +324,17 @@ describe('A-Scope tests', () => {
326
324
  expect(container.scope.issuer()).toBe(container);
327
325
  });
328
326
 
327
+ it('Should be able to resolve Error in scope', async () => {
328
+
329
+ const container = new A_Container();
330
+
331
+ container.scope.register(new A_Error('Test Error'));
332
+
333
+ const resolved = container.scope.resolve(A_Error);
334
+ expect(resolved).toBeInstanceOf(A_Error);
335
+ expect(resolved?.message).toBe('Test Error');
336
+
337
+ expect(container.scope.issuer()).toBe(container);
338
+ });
339
+
329
340
  });
@@ -1,4 +1,3 @@
1
- import './test.setup';
2
1
  import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "@adaas/a-concept/constants/env.constants";
3
2
  import { A_Context } from '@adaas/a-concept/global/A-Context/A-Context.class';
4
3
  import { ASEID } from "@adaas/a-concept/global/ASEID/ASEID.class";
File without changes