@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
@@ -0,0 +1,191 @@
1
+ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "@adaas/a-concept/constants/env.constants";
2
+ import { A_Context } from "@adaas/a-concept/global/A-Context/A-Context.class";
3
+ import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
4
+ import { A_TYPES__Entity_JSON } from "@adaas/a-concept/global/A-Entity/A-Entity.types";
5
+ import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
6
+ import { ASEID } from "@adaas/a-utils";
7
+
8
+ jest.retryTimes(0);
9
+
10
+ describe('A-Entity tests', () => {
11
+ it('Should Allow to create an entity from undefined', async () => {
12
+ const entity = new A_Entity();
13
+ });
14
+ it('Should Allow to create an entity with Default ASEID', async () => {
15
+ const entity = new A_Entity();
16
+
17
+ expect(entity.aseid).toBeInstanceOf(ASEID);
18
+ expect(entity.aseid.scope).toBe('core');
19
+ expect(entity.aseid.namespace).toBe('a-concept');
20
+
21
+ });
22
+ it('Should Allow to create an entity with overridden ASEID Scope or Namespace', async () => {
23
+ class MyEntity extends A_Entity {
24
+ static get entity(): string {
25
+ return 'my-entity-test';
26
+ }
27
+
28
+ static get scope(): string {
29
+ return 'custom-scope';
30
+ }
31
+
32
+ static get namespace(): string {
33
+ return 'custom-namespace';
34
+ }
35
+ }
36
+
37
+ const entity = new MyEntity();
38
+
39
+ expect(entity.aseid).toBeInstanceOf(ASEID);
40
+ expect(entity.aseid.scope).toBe('custom-scope');
41
+ expect(entity.aseid.namespace).toBe('custom-namespace');
42
+ expect(entity.aseid.entity).toBe('my-entity-test');
43
+
44
+ });
45
+ it('Should Allow to create an entity with overridden ASEID Scope or Namespace from ENV Variables', async () => {
46
+ process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_DEFAULT_SCOPE] = 'env-scope';
47
+ process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_NAMESPACE] = 'env-namespace';
48
+
49
+ A_Context.reset();
50
+
51
+ const entity = new A_Entity();
52
+
53
+ expect(entity.aseid).toBeInstanceOf(ASEID);
54
+ expect(entity.aseid.scope).toBe('env-scope');
55
+ expect(entity.aseid.namespace).toBe('env-namespace');
56
+
57
+ delete process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_DEFAULT_SCOPE];
58
+ delete process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_NAMESPACE];
59
+
60
+ A_Context.reset();
61
+ });
62
+ it('Should Allow to create an entity from ASEID', async () => {
63
+ const entity = new A_Entity(
64
+ new ASEID({
65
+ namespace: 'default',
66
+ scope: 'default',
67
+ entity: 'entity-a',
68
+ id: Math.floor(Math.random() * 1000000000).toString(),
69
+ })
70
+ );
71
+ });
72
+ it('Should Allow to create an entity from string', async () => {
73
+ const entity = new A_Entity('default@default:entity-a:123456789');
74
+
75
+ expect(entity.aseid.toString()).toBe('default@default:entity-a:123456789');
76
+ expect(entity.aseid.id).toBe('123456789');
77
+ });
78
+ it('Should Allow to create an entity from object', async () => {
79
+
80
+ class MyEntity extends A_Entity<{ foo: string }, { foo: string } & A_TYPES__Entity_JSON> {
81
+ foo!: string;
82
+
83
+ fromNew(newEntity: { foo: string; }): void {
84
+ super.fromNew(newEntity);
85
+ this.aseid = new ASEID({
86
+ namespace: 'default',
87
+ scope: 'default',
88
+ entity: 'entity-a',
89
+ id: Math.floor(Math.random() * 1000000000).toString(),
90
+ });
91
+ this.foo = newEntity.foo;
92
+ }
93
+ }
94
+
95
+ const entity = new MyEntity({ foo: 'bar' });
96
+
97
+ expect(entity.foo).toBe('bar');
98
+ });
99
+ it('Should return an error when creating an entity from invalid string', async () => {
100
+ expect(() => {
101
+ const entity = new A_Entity('invalid-string');
102
+ }).toThrowError();
103
+ });
104
+ it('Should Allow to rewrite initializer method without changes to other methods', async () => {
105
+
106
+ class MyEntity extends A_Entity<{ foo: string }, { foo: string } & A_TYPES__Entity_JSON> {
107
+ foo!: string;
108
+
109
+ protected getInitializer(props?: string | { foo: string; } | ({ foo: string; } & A_TYPES__Entity_JSON) | ASEID | undefined): (props: any) => void | (() => void) {
110
+ if (typeof props === 'object' && props !== null && 'foo' in props) {
111
+ return this.fromFoo.bind(this);
112
+ }
113
+ return super.getInitializer(props);
114
+ }
115
+
116
+
117
+ fromFoo(props: { foo: string; }): void {
118
+ this.foo = props.foo;
119
+ }
120
+
121
+ fromNew(newEntity: { foo: string; }): void {
122
+ super.fromNew(newEntity);
123
+ this.aseid = new ASEID({
124
+ namespace: 'default',
125
+ scope: 'default',
126
+ entity: 'entity-a',
127
+ id: Math.floor(Math.random() * 1000000000).toString(),
128
+ });
129
+ this.foo = 'not a bar';
130
+ }
131
+ }
132
+
133
+ const entity = new MyEntity({ foo: 'bar' });
134
+
135
+ expect(entity.foo).toBe('bar');
136
+ });
137
+
138
+ it('Should allow to define a feature on an entity', async () => {
139
+
140
+
141
+ class MyEntity extends A_Entity {
142
+ public foo!: string;
143
+
144
+
145
+ @A_Feature.Define()
146
+ async doSomething() { }
147
+ }
148
+
149
+ });
150
+ it('Should allow to serialize and deserialize an entity', async () => {
151
+
152
+ class MyEntity extends A_Entity<{ foo: string }, { foo: string } & A_TYPES__Entity_JSON> {
153
+ public foo!: string;
154
+
155
+ fromNew(newEntity: { foo: string; }): void {
156
+ this.aseid = new ASEID({
157
+ namespace: 'default',
158
+ scope: 'default',
159
+ entity: 'entity-a',
160
+ id: Math.floor(Math.random() * 1000000000).toString(),
161
+ });
162
+ this.foo = newEntity.foo;
163
+ }
164
+
165
+ fromJSON(serialized: { foo: string; } & A_TYPES__Entity_JSON): void {
166
+ this.aseid = new ASEID(serialized.aseid);
167
+ this.foo = serialized.foo;
168
+ return;
169
+ }
170
+
171
+ toJSON(): { foo: string } & A_TYPES__Entity_JSON {
172
+ return {
173
+ ...super.toJSON(),
174
+ foo: this.foo,
175
+ };
176
+ }
177
+ }
178
+
179
+ const entity = new MyEntity({ foo: 'baz' });
180
+ const aseid = entity.aseid.toString();
181
+
182
+ const serialized = entity.toJSON();
183
+ expect(serialized.foo).toBe('baz');
184
+
185
+ const entity2 = new MyEntity(serialized);
186
+ expect(entity2.foo).toBe('baz');
187
+ expect(entity2.aseid.toString()).toBe(aseid);
188
+ expect(entity2.aseid.toString()).toBe(entity.aseid.toString());
189
+ });
190
+
191
+ });
@@ -0,0 +1,131 @@
1
+ import { A_Inject } from "@adaas/a-concept/decorators/A-Inject/A-Inject.decorator";
2
+ import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
3
+ import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
4
+ import { A_FeatureCaller } from "@adaas/a-concept/global/A-Feature/A-FeatureCaller.class";
5
+ import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
6
+
7
+ jest.retryTimes(0);
8
+
9
+ describe('A-Feature tests', () => {
10
+ it('Should Allow to create a feature from undefined', async () => {
11
+ const feature = new A_Feature({
12
+ name: 'TestFeature',
13
+ scope: new A_Scope({ name: 'TestScope' }),
14
+ steps: [],
15
+ caller: new A_Component()
16
+ });
17
+ });
18
+ it('Should Allow to create a feature with steps', async () => {
19
+ const feature = new A_Feature({
20
+ name: 'TestFeature',
21
+ scope: new A_Scope({ name: 'TestScope' }),
22
+ steps: [
23
+ {
24
+ name: 'A_Component.testHandler',
25
+ component: A_Component,
26
+ handler: 'testHandler',
27
+ behavior: 'sync',
28
+ before: [],
29
+ after: []
30
+ }
31
+ ],
32
+ caller: new A_Component()
33
+ });
34
+ });
35
+ it('Should be possible to execute a feature with steps as a template on the component', async () => {
36
+ // 1) create a base component with some feature
37
+ class MyExtendedComponent extends A_Component {
38
+
39
+ async testHandler(
40
+ @A_Inject(A_FeatureCaller) caller: MyComponent
41
+ ) {
42
+ caller.sum = 2;
43
+ }
44
+ }
45
+
46
+ // 2) create a custom component with a defined template feature
47
+ class MyComponent extends A_Component {
48
+ sum: number = 0;
49
+
50
+ @A_Feature.Define({
51
+ invoke: true,
52
+ template: [{
53
+ name: 'MyExtendedComponent.testHandler',
54
+ component: MyExtendedComponent,
55
+ handler: 'testHandler',
56
+ behavior: 'sync',
57
+ before: [],
58
+ after: []
59
+ }]
60
+ })
61
+ async testHandler() { }
62
+ }
63
+
64
+
65
+ // 3) create a running scope
66
+ const scope = new A_Scope({ name: 'TestScope' });
67
+ scope.register(MyExtendedComponent);
68
+ scope.register(MyComponent);
69
+
70
+ // 4) create an instance of the component from the scope
71
+ const myComponent = scope.resolve(MyComponent);
72
+ expect(myComponent).toBeInstanceOf(MyComponent);
73
+ expect(myComponent.sum).toBe(0);
74
+
75
+ // 5) call the feature caller to execute the feature
76
+ await myComponent.testHandler();
77
+
78
+ // 6) check the results
79
+ expect(myComponent.sum).toBe(2);
80
+
81
+ });
82
+ it('Should be possible to execute a feature with steps as a template on the component with string component declaration', async () => {
83
+ // 1) create a base component with some feature
84
+ class MyExtendedComponent2 extends A_Component {
85
+
86
+ async testHandler(
87
+ @A_Inject(A_FeatureCaller) caller: MyComponent2
88
+ ) {
89
+ caller.sum = 2;
90
+ }
91
+ }
92
+
93
+ // 2) create a custom component with a defined template feature
94
+ class MyComponent2 extends A_Component {
95
+ sum: number = 0;
96
+
97
+ @A_Feature.Define({
98
+ invoke: true,
99
+ template: [{
100
+ name: 'MyExtendedComponent2.testHandler',
101
+ component: 'MyExtendedComponent2',
102
+ handler: 'testHandler',
103
+ behavior: 'sync',
104
+ before: [],
105
+ after: []
106
+ }]
107
+ })
108
+ async testHandler() { }
109
+ }
110
+
111
+
112
+ // 3) create a running scope
113
+ const scope = new A_Scope({ name: 'TestScope' });
114
+ scope.register(MyExtendedComponent2);
115
+ scope.register(MyComponent2);
116
+
117
+ // 4) create an instance of the component from the scope
118
+ const myComponent = scope.resolve(MyComponent2);
119
+ expect(myComponent).toBeInstanceOf(MyComponent2);
120
+ expect(myComponent.sum).toBe(0);
121
+
122
+ // 5) call the feature caller to execute the feature
123
+ await myComponent.testHandler();
124
+
125
+ // 6) check the results
126
+ expect(myComponent.sum).toBe(2);
127
+
128
+ });
129
+
130
+
131
+ });
@@ -0,0 +1,163 @@
1
+ import { A_Component } from "@adaas/a-concept/global/A-Component/A-Component.class";
2
+ import { A_Entity } from "@adaas/a-concept/global/A-Entity/A-Entity.class";
3
+ import { A_Scope } from "@adaas/a-concept/global/A-Scope/A-Scope.class";
4
+ import { ASEID } from "@adaas/a-utils";
5
+
6
+ jest.retryTimes(0);
7
+
8
+ describe('A-Scope tests', () => {
9
+
10
+ it('Should Allow to create a scope', async () => {
11
+ const scope = new A_Scope({ name: 'TestScope' });
12
+ });
13
+ it('Should allow to register a component', async () => {
14
+ const component = new A_Component();
15
+ const scope = new A_Scope({ name: 'TestScope' });
16
+ scope.register(component);
17
+
18
+ });
19
+ it('Should allow to resolve a component', async () => {
20
+ const component = new A_Component();
21
+ const scope = new A_Scope({ name: 'TestScope' });
22
+ scope.register(component);
23
+
24
+ const resolved = scope.resolve(A_Component);
25
+ expect(resolved).toBe(component);
26
+ });
27
+ it('Should return an error when resolving a non-registered component', async () => {
28
+ const scope = new A_Scope({ name: 'TestScope' });
29
+ expect(() => scope.resolve(A_Component)).toThrowError();
30
+ });
31
+ it('Should allow to register and resolve a component with dependencies', async () => {
32
+ class DependentComponent extends A_Component {
33
+ constructor(
34
+ public dependency: A_Component
35
+ ) {
36
+ super();
37
+ }
38
+ }
39
+
40
+ const component = new A_Component();
41
+ const scope = new A_Scope({ name: 'TestScope' });
42
+ scope.register(component);
43
+ scope.register(new DependentComponent(component));
44
+
45
+ const resolved = scope.resolve(DependentComponent);
46
+ expect(resolved).toBeInstanceOf(DependentComponent);
47
+ expect(resolved.dependency).toBe(component);
48
+ });
49
+
50
+ it('should resolve component registered in parent scope', async () => {
51
+ const parentScope = new A_Scope({ name: 'ParentScope' });
52
+ const childScope = new A_Scope({ name: 'ChildScope'});
53
+
54
+ childScope.parent(parentScope);
55
+
56
+ const component = new A_Component();
57
+ parentScope.register(component);
58
+
59
+ const resolved = childScope.resolve(A_Component);
60
+ expect(resolved).toBe(component);
61
+ });
62
+
63
+ it('Should resolve only one entity if no query is provided', async () => {
64
+ class MyEntity extends A_Entity<{ bar: string }> {
65
+ public bar!: string;
66
+ fromNew(newEntity: { bar: string; }): void {
67
+ this.aseid = new ASEID({
68
+ namespace: 'default',
69
+ scope: 'default',
70
+ entity: 'entity-a',
71
+ id: Math.floor(Math.random() * 1000000000).toString(),
72
+ })
73
+ this.bar = newEntity.bar;
74
+ }
75
+ }
76
+
77
+
78
+ const scope = new A_Scope({ name: 'TestScope' });
79
+ const entity1 = new MyEntity({ bar: 'bar' });
80
+ const entity2 = new MyEntity({ bar: 'baz' });
81
+ scope.register(entity1);
82
+ scope.register(entity2);
83
+ const resolved = scope.resolve(MyEntity);
84
+ expect(resolved).toBe(entity1);
85
+
86
+ });
87
+ it('Should resolve entities based on a query', async () => {
88
+ class MyEntity extends A_Entity<{ bar: string }> {
89
+ public bar!: string;
90
+ fromNew(newEntity: { bar: string; }): void {
91
+ this.aseid = new ASEID({
92
+ namespace: 'default',
93
+ scope: 'default',
94
+ entity: 'entity-a',
95
+ id: Math.floor(Math.random() * 1000000000).toString(),
96
+ })
97
+ this.bar = newEntity.bar;
98
+ }
99
+ }
100
+
101
+ const scope = new A_Scope({ name: 'TestScope' });
102
+ const entity1 = new MyEntity({ bar: 'bar' });
103
+ const entity2 = new MyEntity({ bar: 'baz' });
104
+ scope.register(entity1);
105
+ scope.register(entity2);
106
+ const resolved = scope.resolve(MyEntity, { query: { bar: 'baz' } });
107
+ expect(resolved).toBe(entity2);
108
+
109
+
110
+ });
111
+ it('Should return array if pagination.count is provided', async () => {
112
+ class MyEntity extends A_Entity<{ foo: string }> {
113
+ public foo!: string;
114
+ fromNew(newEntity: { foo: string; }): void {
115
+ this.aseid = new ASEID({
116
+ namespace: 'default',
117
+ scope: 'default',
118
+ entity: 'entity-a',
119
+ id: Math.floor(Math.random() * 1000000000).toString(),
120
+ })
121
+ this.foo = newEntity.foo;
122
+ }
123
+ }
124
+ const scope = new A_Scope({ name: 'TestScope' });
125
+ for (let i = 0; i < 10; i++) {
126
+ const entity = new MyEntity({ foo: 'bar' });
127
+ scope.register(entity);
128
+ }
129
+ const resolved = scope.resolve(MyEntity, { pagination: { count: 10 } });
130
+ expect(Array.isArray(resolved)).toBe(true);
131
+ });
132
+ it('Should return array with pagination.count and provided filter', async () => {
133
+ class MyEntity extends A_Entity<{ foo: string }> {
134
+ public foo!: string;
135
+ fromNew(newEntity: { foo: string; }): void {
136
+ this.aseid = new ASEID({
137
+ namespace: 'default',
138
+ scope: 'default',
139
+ entity: 'entity-a',
140
+ id: Math.floor(Math.random() * 1000000000).toString(),
141
+ })
142
+ this.foo = newEntity.foo;
143
+ }
144
+ }
145
+ const scope = new A_Scope({ name: 'TestScope' });
146
+ for (let i = 0; i < 5; i++) {
147
+ const entity = new MyEntity({ foo: 'bar' });
148
+ scope.register(entity);
149
+ }
150
+ for (let i = 0; i < 5; i++) {
151
+ const entity = new MyEntity({ foo: 'baz' });
152
+ scope.register(entity);
153
+ }
154
+ const resolved = scope.resolve(MyEntity, { query: { foo: 'baz' }, pagination: { count: 10 } });
155
+ expect(Array.isArray(resolved)).toBe(true);
156
+ expect((resolved as Array<MyEntity>).length).toBe(5);
157
+ (resolved as Array<MyEntity>).forEach(r => {
158
+ expect(r.foo).toBe('baz');
159
+ });
160
+
161
+ });
162
+
163
+ });
@@ -1,11 +0,0 @@
1
- "use strict";
2
- // import { A_TYPES__ConceptLifecycle_MethodDeclarationConfig } from "../decorators/A-ConceptLifecycle/A-ConceptLifecycle.decorator.types";
3
- // export const A_CONSTANTS__DEFAULT_CONCEPT_LIFECYCLE_METHOD_DECLARATION_CONFIG: A_TYPES__ConceptLifecycle_MethodDeclarationConfig = {
4
- // name: '',
5
- // behavior: 'sync',
6
- // type: 'extension',
7
- // after: [],
8
- // before: [],
9
- // override: []
10
- // }
11
- //# sourceMappingURL=A_ConceptLifecycle.constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_ConceptLifecycle.constants.js","sourceRoot":"","sources":["../../../src/constants/A_ConceptLifecycle.constants.ts"],"names":[],"mappings":";AAAA,2IAA2I;AAI3I,uIAAuI;AACvI,gBAAgB;AAChB,wBAAwB;AACxB,yBAAyB;AACzB,iBAAiB;AACjB,kBAAkB;AAClB,mBAAmB;AACnB,KAAK"}
@@ -1,12 +0,0 @@
1
- // import { A_TYPES__ConceptLifecycle_MethodDeclarationConfig } from "../decorators/A-ConceptLifecycle/A-ConceptLifecycle.decorator.types";
2
-
3
-
4
-
5
- // export const A_CONSTANTS__DEFAULT_CONCEPT_LIFECYCLE_METHOD_DECLARATION_CONFIG: A_TYPES__ConceptLifecycle_MethodDeclarationConfig = {
6
- // name: '',
7
- // behavior: 'sync',
8
- // type: 'extension',
9
- // after: [],
10
- // before: [],
11
- // override: []
12
- // }