@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.
- package/.nvmrc +1 -1
- package/dist/src/base/A-Command/A_Command.constants.d.ts +12 -0
- package/dist/src/base/A-Command/A_Command.constants.js +17 -0
- package/dist/src/base/A-Command/A_Command.constants.js.map +1 -0
- package/dist/src/base/A-Command/A_Command.entity.d.ts +123 -0
- package/dist/src/base/A-Command/A_Command.entity.js +259 -0
- package/dist/src/base/A-Command/A_Command.entity.js.map +1 -0
- package/dist/src/base/A-Command/A_Command.types.d.ts +15 -0
- package/dist/src/base/A-Command/A_Command.types.js +3 -0
- package/dist/src/base/A-Command/A_Command.types.js.map +1 -0
- package/dist/src/base/A-Command/context/A_Command.context.d.ts +64 -0
- package/dist/src/base/A-Command/context/A_Command.context.js +85 -0
- package/dist/src/base/A-Command/context/A_Command.context.js.map +1 -0
- package/dist/src/base/A-Command/context/A_CommandFactory.context.js +2 -0
- package/dist/src/base/A-Command/context/A_CommandFactory.context.js.map +1 -0
- package/dist/src/base/A-Config/A-Config.container.d.ts +1 -2
- package/dist/src/base/A-Config/A-Config.container.js +2 -4
- package/dist/src/base/A-Config/A-Config.container.js.map +1 -1
- package/dist/src/base/A-Config/A-Config.context.d.ts +10 -11
- package/dist/src/base/A-Config/A-Config.context.js +5 -24
- package/dist/src/base/A-Config/A-Config.context.js.map +1 -1
- package/dist/src/base/A-Config/A-Config.types.d.ts +4 -4
- package/dist/src/base/A-Config/A-Config.types.js.map +1 -1
- package/dist/src/base/A-Config/components/ConfigReader.component.js +6 -12
- package/dist/src/base/A-Config/components/ConfigReader.component.js.map +1 -1
- package/dist/src/base/A-Config/components/ENVConfigReader.component.js +5 -1
- package/dist/src/base/A-Config/components/ENVConfigReader.component.js.map +1 -1
- package/dist/src/constants/env.constants.d.ts +26 -0
- package/dist/src/constants/env.constants.js +40 -0
- package/dist/src/constants/env.constants.js.map +1 -0
- package/dist/src/decorators/A-Inject/A-Inject.decorator.d.ts +3 -3
- package/dist/src/decorators/A-Inject/A-Inject.decorator.types.d.ts +9 -10
- package/dist/src/global/A-Channel/A-Channel.class.d.ts +2 -0
- package/dist/src/global/A-Channel/A-Channel.class.js +2 -0
- package/dist/src/global/A-Channel/A-Channel.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.class.d.ts +5 -3
- package/dist/src/global/A-Concept/A_Concept.class.js +32 -27
- package/dist/src/global/A-Concept/A_Concept.class.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.meta.d.ts +1 -8
- package/dist/src/global/A-Concept/A_Concept.meta.js +1 -25
- package/dist/src/global/A-Concept/A_Concept.meta.js.map +1 -1
- package/dist/src/global/A-Concept/A_Concept.types.d.ts +10 -1
- package/dist/src/global/A-Container/A-Container.class.d.ts +5 -0
- package/dist/src/global/A-Container/A-Container.class.js +5 -0
- package/dist/src/global/A-Container/A-Container.class.js.map +1 -1
- package/dist/src/global/A-Context/A-Context.class.d.ts +23 -1
- package/dist/src/global/A-Context/A-Context.class.js +38 -1
- package/dist/src/global/A-Context/A-Context.class.js.map +1 -1
- package/dist/src/global/A-Entity/A-Entity.class.d.ts +124 -23
- package/dist/src/global/A-Entity/A-Entity.class.js +159 -49
- package/dist/src/global/A-Entity/A-Entity.class.js.map +1 -1
- package/dist/src/global/A-Scope/A-Scope.class.d.ts +7 -6
- package/dist/src/global/A-Scope/A-Scope.class.js +57 -20
- package/dist/src/global/A-Scope/A-Scope.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.class.d.ts +3 -2
- package/dist/src/global/A-Stage/A-Stage.class.js +9 -6
- package/dist/src/global/A-Stage/A-Stage.class.js.map +1 -1
- package/dist/src/global/A-Stage/A-Stage.types.d.ts +1 -1
- package/dist/src/helpers/StepsManager.class.js +1 -1
- package/dist/src/helpers/StepsManager.class.js.map +1 -1
- package/examples/simple/components/A.component.ts +9 -2
- package/examples/simple/concept.ts +6 -0
- package/examples/simple/entities/EntityA.entity.ts +18 -0
- package/jest.config.ts +1 -1
- package/package.json +3 -3
- package/src/base/A-Command/A_Command.constants.ts +20 -0
- package/src/base/A-Command/A_Command.entity.ts +287 -0
- package/src/base/A-Command/A_Command.types.ts +34 -0
- package/src/base/A-Command/context/A_Command.context.ts +114 -0
- package/src/base/A-Command/context/A_CommandFactory.context.ts +0 -0
- package/src/base/A-Config/A-Config.container.ts +0 -1
- package/src/base/A-Config/A-Config.context.ts +22 -28
- package/src/base/A-Config/A-Config.types.ts +5 -24
- package/src/base/A-Config/components/ConfigReader.component.ts +6 -15
- package/src/base/A-Config/components/ENVConfigReader.component.ts +6 -1
- package/src/constants/env.constants.ts +44 -0
- package/src/decorators/A-Inject/A-Inject.decorator.ts +3 -3
- package/src/decorators/A-Inject/A-Inject.decorator.types.ts +10 -9
- package/src/global/A-Channel/A-Channel.class.ts +2 -0
- package/src/global/A-Concept/A_Concept.class.ts +49 -32
- package/src/global/A-Concept/A_Concept.meta.ts +3 -41
- package/src/global/A-Concept/A_Concept.types.ts +6 -4
- package/src/global/A-Container/A-Container.class.ts +5 -2
- package/src/global/A-Context/A-Context.class.ts +67 -8
- package/src/global/A-Entity/A-Entity.class.ts +203 -73
- package/src/global/A-Scope/A-Scope.class.ts +88 -39
- package/src/global/A-Stage/A-Stage.class.ts +11 -7
- package/src/global/A-Stage/A-Stage.types.ts +1 -1
- package/src/helpers/StepsManager.class.ts +2 -2
- package/tests/A-Command.test.ts +130 -0
- package/tests/A-Component.test.ts +25 -0
- package/tests/A-Config.test.ts +106 -0
- package/tests/A-Entity.test.ts +191 -0
- package/tests/A-Feature.test.ts +131 -0
- package/tests/A-Scope.test.ts +163 -0
- package/dist/src/constants/A_ConceptLifecycle.constants.js +0 -11
- package/dist/src/constants/A_ConceptLifecycle.constants.js.map +0 -1
- package/src/constants/A_ConceptLifecycle.constants.ts +0 -12
- package/tests/channel.ts +0 -213
- package/tests/context.test.ts +0 -124
- package/tests/default.test.ts +0 -159
- package/tests/log.ts +0 -102
- package/tests/polyfill.test.ts +0 -37
- /package/dist/src/{constants/A_ConceptLifecycle.constants.d.ts → base/A-Command/context/A_CommandFactory.context.d.ts} +0 -0
package/tests/channel.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
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_Container } from "@adaas/a-concept/global/A-Container/A-Container.class";
|
|
4
|
-
// import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
|
|
5
|
-
// import { EventEmitter } from "stream";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// class ComponentA extends A_Component<[
|
|
9
|
-
// 'method1',
|
|
10
|
-
// 'method2'
|
|
11
|
-
// ]> {
|
|
12
|
-
|
|
13
|
-
// @A_Feature.Define({
|
|
14
|
-
// name: 'method1',
|
|
15
|
-
// channels: []
|
|
16
|
-
// } as any)
|
|
17
|
-
// async method1() {
|
|
18
|
-
|
|
19
|
-
// }
|
|
20
|
-
|
|
21
|
-
// @A_Feature.Define({
|
|
22
|
-
// name: 'method2',
|
|
23
|
-
// channels: []
|
|
24
|
-
// } as any)
|
|
25
|
-
// async method2() {
|
|
26
|
-
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// class ComponentB extends A_Component<[
|
|
32
|
-
// 'ComponentB_method3',
|
|
33
|
-
// 'ComponentB_method4'
|
|
34
|
-
// ]> {
|
|
35
|
-
|
|
36
|
-
// @A_Feature.Define({
|
|
37
|
-
// name: 'ComponentB_method3',
|
|
38
|
-
// channels: []
|
|
39
|
-
// } as any)
|
|
40
|
-
// async ComponentB_method3(param1: {
|
|
41
|
-
// key: string
|
|
42
|
-
// }) {
|
|
43
|
-
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// @A_Feature.Define({
|
|
47
|
-
// name: 'ComponentB_method4',
|
|
48
|
-
// channels: []
|
|
49
|
-
// } as any)
|
|
50
|
-
// async ComponentB_method4(foo: number) {
|
|
51
|
-
|
|
52
|
-
// }
|
|
53
|
-
// }
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// type MethodsWithSpecificArg<T, ArgType> = {
|
|
58
|
-
// [K in keyof T]: T[K] extends (arg: ArgType, ...args: any[]) => Promise<any> ? K : never
|
|
59
|
-
// }[keyof T];
|
|
60
|
-
|
|
61
|
-
// // Example argument type
|
|
62
|
-
// type SpecificArgType = { key: string };
|
|
63
|
-
|
|
64
|
-
// type AggregateMethods<TClasses extends A_Component[]> = {
|
|
65
|
-
// [K in keyof TClasses]: TClasses[K] extends infer Instance
|
|
66
|
-
// ? MethodsWithSpecificArg<Instance, SpecificArgType>
|
|
67
|
-
// : never;
|
|
68
|
-
// }[number];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// type MethodObject2<TClasses extends any[]> = {
|
|
72
|
-
// [Method in AggregateMethods<TClasses>]: {
|
|
73
|
-
// [Class in keyof TClasses]: TClasses[Class] extends infer Instance
|
|
74
|
-
// ? Method extends keyof Instance
|
|
75
|
-
// ? Instance[Method]
|
|
76
|
-
// : never
|
|
77
|
-
// : never;
|
|
78
|
-
// }[number]; // Select the method signature from any matching class
|
|
79
|
-
// };
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// // decorator to create a channel
|
|
84
|
-
// function A_Connect() {
|
|
85
|
-
// return function (target: any, prop: string) {
|
|
86
|
-
// console.log('A_Connect', target, prop);
|
|
87
|
-
// }
|
|
88
|
-
// }
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// class Channel<T extends A_Component[]> {
|
|
93
|
-
|
|
94
|
-
// channel: MethodObject2<T>;
|
|
95
|
-
|
|
96
|
-
// constructor() {
|
|
97
|
-
// this.channel = new Proxy(
|
|
98
|
-
// {} as MethodObject2<T>,
|
|
99
|
-
// {
|
|
100
|
-
// get: (target, prop) => {
|
|
101
|
-
// return async (...args: any[]) => {
|
|
102
|
-
// this.call(prop as AggregateMethods<T>);
|
|
103
|
-
// };
|
|
104
|
-
// }
|
|
105
|
-
// });
|
|
106
|
-
// }
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// async call(prop: AggregateMethods<T>) {
|
|
110
|
-
// // do HTTP Call or just inject class or whatever you want
|
|
111
|
-
|
|
112
|
-
// console.log('Calling method', prop);
|
|
113
|
-
// }
|
|
114
|
-
|
|
115
|
-
// }
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// class HTTP<T extends A_Component[]> extends Channel<T> {
|
|
121
|
-
|
|
122
|
-
// async call(prop: AggregateMethods<T>): Promise<void> {
|
|
123
|
-
|
|
124
|
-
// console.log('HTTP Call', prop);
|
|
125
|
-
// }
|
|
126
|
-
// }
|
|
127
|
-
|
|
128
|
-
// class ConceptDirect<T extends A_Component[]> extends Channel<T> {
|
|
129
|
-
|
|
130
|
-
// // protected originalInstance: T;
|
|
131
|
-
|
|
132
|
-
// async call(prop: AggregateMethods<T>): Promise<void> {
|
|
133
|
-
// console.log('Direct Call', prop);
|
|
134
|
-
// }
|
|
135
|
-
|
|
136
|
-
// }
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// class ConceptEE extends Channel<any> {
|
|
141
|
-
|
|
142
|
-
// private emitter: EventEmitter = new EventEmitter();
|
|
143
|
-
|
|
144
|
-
// constructor() {
|
|
145
|
-
// super();
|
|
146
|
-
// }
|
|
147
|
-
|
|
148
|
-
// async call(prop: string): Promise<void> {
|
|
149
|
-
// console.log('EE Call', prop);
|
|
150
|
-
// }
|
|
151
|
-
|
|
152
|
-
// on = this.emitter.on.bind(this.emitter);
|
|
153
|
-
|
|
154
|
-
// emit = this.emitter.emit.bind(this.emitter);
|
|
155
|
-
|
|
156
|
-
// }
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// class FooContainer extends A_Container<[
|
|
179
|
-
// 'doSomething',
|
|
180
|
-
// 'doAnotherThing'
|
|
181
|
-
// ]> {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// @A_Feature.Define({
|
|
185
|
-
// name: 'doSomething',
|
|
186
|
-
// channels: [ConceptDirect, HTTP]
|
|
187
|
-
// } as any)
|
|
188
|
-
// async doSomething(
|
|
189
|
-
// @A_Inject(HTTP) http: HTTP<[ComponentA, ComponentB]>,
|
|
190
|
-
// ) {
|
|
191
|
-
|
|
192
|
-
// // @A_Connect(http, 'ComponentB_method3')
|
|
193
|
-
|
|
194
|
-
// const foo = await http.channel.ComponentB_method3({
|
|
195
|
-
// key: 'value'
|
|
196
|
-
// });
|
|
197
|
-
// }
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// @A_Feature.Define({
|
|
203
|
-
// name: 'doAnotherThing',
|
|
204
|
-
// channels: [HTTP]
|
|
205
|
-
// } as any)
|
|
206
|
-
// async onRequest() {
|
|
207
|
-
// await this.call('doSomething');
|
|
208
|
-
// }
|
|
209
|
-
// }
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
package/tests/context.test.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// import { A_CONSTANTS__ERROR_CODES } from '@adaas/a-concept/constants/errors.constants';
|
|
2
|
-
// import { A_ContextClass } from '@adaas/a-concept/global/A-Namespace/A_Namespace.class';
|
|
3
|
-
// import { A_Error } from '@adaas/a-concept/global/A_Error.class';
|
|
4
|
-
// import { config } from 'dotenv';
|
|
5
|
-
// config();
|
|
6
|
-
// jest.retryTimes(0);
|
|
7
|
-
|
|
8
|
-
// describe('Context Tests', () => {
|
|
9
|
-
|
|
10
|
-
// it('Should load default context ', async () => {
|
|
11
|
-
// const testContext = new A_ContextClass({
|
|
12
|
-
// namespace: 'test',
|
|
13
|
-
// });
|
|
14
|
-
|
|
15
|
-
// await testContext.ready;
|
|
16
|
-
// });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// it('Should log data ', async () => {
|
|
20
|
-
// const testContext = new A_ContextClass({
|
|
21
|
-
// namespace: 'test',
|
|
22
|
-
// });
|
|
23
|
-
|
|
24
|
-
// await testContext.ready;
|
|
25
|
-
|
|
26
|
-
// testContext.Logger.log('Test Log');
|
|
27
|
-
// });
|
|
28
|
-
|
|
29
|
-
// it('Should throw Error ', async () => {
|
|
30
|
-
|
|
31
|
-
// const namespace = 'test-namespace';
|
|
32
|
-
// const testContext = new A_ContextClass({
|
|
33
|
-
// namespace,
|
|
34
|
-
// });
|
|
35
|
-
|
|
36
|
-
// await testContext.ready;
|
|
37
|
-
|
|
38
|
-
// try {
|
|
39
|
-
// testContext.Errors.throw(A_CONSTANTS__ERROR_CODES.METHOD_NOT_IMPLEMENTED);
|
|
40
|
-
// } catch (error) {
|
|
41
|
-
// testContext.Logger.error(error);
|
|
42
|
-
|
|
43
|
-
// expect(error).toBeDefined();
|
|
44
|
-
// expect(error).toBeInstanceOf(A_Error);
|
|
45
|
-
// expect((error as A_Error).code).toBe(
|
|
46
|
-
// `${namespace}@error:${A_CONSTANTS__ERROR_CODES.METHOD_NOT_IMPLEMENTED}`
|
|
47
|
-
// );
|
|
48
|
-
// }
|
|
49
|
-
// });
|
|
50
|
-
|
|
51
|
-
// it('Should log original error ', async () => {
|
|
52
|
-
|
|
53
|
-
// const namespace = 'test-error-namespace';
|
|
54
|
-
// const testContext = new A_ContextClass({
|
|
55
|
-
// namespace,
|
|
56
|
-
// });
|
|
57
|
-
|
|
58
|
-
// await testContext.ready;
|
|
59
|
-
// try {
|
|
60
|
-
// try {
|
|
61
|
-
// throw new Error('Test Error');
|
|
62
|
-
// } catch (error) {
|
|
63
|
-
// throw testContext.Errors.wrap(error);
|
|
64
|
-
// }
|
|
65
|
-
// } catch (error) {
|
|
66
|
-
// testContext.Logger.error(error);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// expect(error).toBeDefined();
|
|
70
|
-
// expect(error).toBeInstanceOf(A_Error);
|
|
71
|
-
// }
|
|
72
|
-
// });
|
|
73
|
-
|
|
74
|
-
// it('Should read allowed configuration property ', async () => {
|
|
75
|
-
|
|
76
|
-
// const namespace = 'test-config-read-ok';
|
|
77
|
-
// const testContext = new A_ContextClass({
|
|
78
|
-
// namespace,
|
|
79
|
-
// });
|
|
80
|
-
|
|
81
|
-
// const ignoreErrors = testContext.getConfigurationProperty('CONFIG_IGNORE_ERRORS');
|
|
82
|
-
|
|
83
|
-
// expect(ignoreErrors).toBe(false);
|
|
84
|
-
// });
|
|
85
|
-
|
|
86
|
-
// it('Should fail to read unknown property', async () => {
|
|
87
|
-
|
|
88
|
-
// const namespace = 'test-config-read-fail';
|
|
89
|
-
// const testContext = new A_ContextClass({
|
|
90
|
-
// namespace,
|
|
91
|
-
// });
|
|
92
|
-
|
|
93
|
-
// try {
|
|
94
|
-
// testContext.getConfigurationProperty('TEST_PROPERTY' as any);
|
|
95
|
-
// } catch (error) {
|
|
96
|
-
// testContext.Logger.error(error);
|
|
97
|
-
|
|
98
|
-
// expect(error).toBeDefined();
|
|
99
|
-
// expect(error).toBeInstanceOf(A_Error);
|
|
100
|
-
// expect((error as A_Error).code).toBe(
|
|
101
|
-
// `${namespace}@error:${A_CONSTANTS__ERROR_CODES.CONFIGURATION_PROPERTY_NOT_EXISTS_OR_NOT_ALLOWED_TO_READ}`
|
|
102
|
-
// );
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
|
-
// });
|
|
106
|
-
|
|
107
|
-
// it('Should Log data properly', async () => {
|
|
108
|
-
|
|
109
|
-
// const namespace = 'test-config-read-fail';
|
|
110
|
-
// const testContext = new A_ContextClass({
|
|
111
|
-
// namespace,
|
|
112
|
-
// });
|
|
113
|
-
|
|
114
|
-
// testContext.Logger.log(`
|
|
115
|
-
// Some Suff that should be done`, {
|
|
116
|
-
// test: 'data',
|
|
117
|
-
// test2: {
|
|
118
|
-
// test: 'data'
|
|
119
|
-
// }
|
|
120
|
-
// });
|
|
121
|
-
|
|
122
|
-
// });
|
|
123
|
-
|
|
124
|
-
// });
|
package/tests/default.test.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
// import { A_CommonHelper } from '@adaas/a-concept/helpers/Common.helper';
|
|
2
|
-
// import { A_TYPES__DeepPartial } from '@adaas/a-concept/types/common.types';
|
|
3
|
-
// import { config } from 'dotenv';
|
|
4
|
-
// config();
|
|
5
|
-
// jest.retryTimes(0);
|
|
6
|
-
|
|
7
|
-
// describe('CommonHelper Tests', () => {
|
|
8
|
-
|
|
9
|
-
// it('Schedule Should execute promise and await it ', async () => {
|
|
10
|
-
|
|
11
|
-
// const start = Date.now();
|
|
12
|
-
// let res = '';
|
|
13
|
-
|
|
14
|
-
// try {
|
|
15
|
-
// const scheduler = A_CommonHelper.schedule(3000, async () => {
|
|
16
|
-
// return 'RESOLVED';
|
|
17
|
-
// });
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// res = await scheduler.promise;
|
|
21
|
-
|
|
22
|
-
// } catch (error) {
|
|
23
|
-
// // Handle error if any
|
|
24
|
-
// } finally {
|
|
25
|
-
// const end = Date.now();
|
|
26
|
-
// const duration = end - start;
|
|
27
|
-
|
|
28
|
-
// expect(res).toBe('RESOLVED');
|
|
29
|
-
// // Check if the duration exceeds 3 seconds
|
|
30
|
-
// expect(duration).toBeGreaterThan(3000);
|
|
31
|
-
// }
|
|
32
|
-
|
|
33
|
-
// });
|
|
34
|
-
|
|
35
|
-
// it('Schedule Should be canceled and rejected', async () => {
|
|
36
|
-
|
|
37
|
-
// const start = Date.now();
|
|
38
|
-
// let res = '';
|
|
39
|
-
|
|
40
|
-
// try {
|
|
41
|
-
// const scheduler = A_CommonHelper.schedule(3000, async () => {
|
|
42
|
-
// return 'RESOLVED';
|
|
43
|
-
// });
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// scheduler.clear();
|
|
47
|
-
// res = await scheduler.promise;
|
|
48
|
-
// } catch (error) {
|
|
49
|
-
// // Handle error if any
|
|
50
|
-
// } finally {
|
|
51
|
-
// const end = Date.now();
|
|
52
|
-
// const duration = end - start;
|
|
53
|
-
|
|
54
|
-
// expect(res).toBe('');
|
|
55
|
-
// // Check if the duration exceeds 3 seconds
|
|
56
|
-
// expect(duration).toBeLessThan(3000);
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
// });
|
|
60
|
-
|
|
61
|
-
// it('Deep Clone and Merge ', async () => {
|
|
62
|
-
|
|
63
|
-
// type TestType = {
|
|
64
|
-
// a: string,
|
|
65
|
-
// b: string,
|
|
66
|
-
// c: {
|
|
67
|
-
// d: string
|
|
68
|
-
// },
|
|
69
|
-
// f: (name: string) => string
|
|
70
|
-
// s: Date
|
|
71
|
-
// }
|
|
72
|
-
|
|
73
|
-
// const t: TestType = {
|
|
74
|
-
// a: 'a',
|
|
75
|
-
// b: 'b',
|
|
76
|
-
// c: {
|
|
77
|
-
// d: 'd'
|
|
78
|
-
// },
|
|
79
|
-
// f: (name: string) => { return name },
|
|
80
|
-
// s: new Date()
|
|
81
|
-
// }
|
|
82
|
-
|
|
83
|
-
// const t2: A_TYPES__DeepPartial<TestType> = {
|
|
84
|
-
// a: 'aa',
|
|
85
|
-
// c: {
|
|
86
|
-
// d: 'dd'
|
|
87
|
-
// },
|
|
88
|
-
// f: (name: string) => { return name + '2' }
|
|
89
|
-
// }
|
|
90
|
-
|
|
91
|
-
// const merged = A_CommonHelper.deepCloneAndMerge(t2, t);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// const name = merged.f('names');
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// expect(merged.a).toBe('aa');
|
|
98
|
-
// expect(merged.b).toBe('b');
|
|
99
|
-
// expect(merged.c.d).toBe('dd');
|
|
100
|
-
// expect(name).toBe('names2');
|
|
101
|
-
// expect(t).not.toEqual(merged);
|
|
102
|
-
// expect(t2).not.toEqual(merged);
|
|
103
|
-
// });
|
|
104
|
-
|
|
105
|
-
// it('Deep Clone Different Types', async () => {
|
|
106
|
-
|
|
107
|
-
// type TestType = {
|
|
108
|
-
// a: string,
|
|
109
|
-
// b: string,
|
|
110
|
-
// c: {
|
|
111
|
-
// d: string
|
|
112
|
-
// },
|
|
113
|
-
// bool:{
|
|
114
|
-
// a: boolean
|
|
115
|
-
// },
|
|
116
|
-
// f: (name: string) => string
|
|
117
|
-
// s: Date
|
|
118
|
-
// }
|
|
119
|
-
|
|
120
|
-
// const t: TestType = {
|
|
121
|
-
// a: 'a',
|
|
122
|
-
// b: 'b',
|
|
123
|
-
// c: {
|
|
124
|
-
// d: 'd'
|
|
125
|
-
// },
|
|
126
|
-
// bool:{
|
|
127
|
-
// a: true
|
|
128
|
-
// },
|
|
129
|
-
// f: (name: string) => { return name },
|
|
130
|
-
// s: new Date()
|
|
131
|
-
// }
|
|
132
|
-
|
|
133
|
-
// const t2: any = {
|
|
134
|
-
// e: 'foo',
|
|
135
|
-
// b: 'bb',
|
|
136
|
-
// c:{
|
|
137
|
-
// d: 'ddd'
|
|
138
|
-
// },
|
|
139
|
-
// bool:{
|
|
140
|
-
// a: false
|
|
141
|
-
// },
|
|
142
|
-
// some: {
|
|
143
|
-
// d: 'dd'
|
|
144
|
-
// },
|
|
145
|
-
// }
|
|
146
|
-
|
|
147
|
-
// const merged = A_CommonHelper.deepCloneAndMerge(t2, t);
|
|
148
|
-
|
|
149
|
-
// console.log('merged: ', merged)
|
|
150
|
-
|
|
151
|
-
// expect(merged.a).toBe('a');
|
|
152
|
-
// expect(merged.b).toBe('bb');
|
|
153
|
-
// expect(merged.c.d).toBe('ddd');
|
|
154
|
-
// expect(merged.bool.a).toBe(false);
|
|
155
|
-
// expect((merged as any).e).toBe('foo');
|
|
156
|
-
// expect((merged as any).some.d).toBe('dd');
|
|
157
|
-
// expect(merged.f('names')).toBe('names');
|
|
158
|
-
// });
|
|
159
|
-
// });
|
package/tests/log.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// import { A_Container } from "@adaas/a-concept/global/A-Container/A-Container.class";
|
|
2
|
-
// import { A_Feature } from "@adaas/a-concept/global/A-Feature/A-Feature.class";
|
|
3
|
-
// import EventEmitter from "events";
|
|
4
|
-
|
|
5
|
-
// type MethodsOfComponent<T> = T extends typeof BaseComponent<infer M extends Array<string>> ? M : never;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// class BaseComponent<_Methods extends string[] = []> {
|
|
10
|
-
|
|
11
|
-
// constructor(
|
|
12
|
-
// private params?: Partial<{
|
|
13
|
-
// exports: _Methods
|
|
14
|
-
// }>) {
|
|
15
|
-
|
|
16
|
-
// }
|
|
17
|
-
// }
|
|
18
|
-
|
|
19
|
-
// class BaseContainer<_AllComponents extends typeof BaseComponent<string[]>[]> {
|
|
20
|
-
|
|
21
|
-
// constructor(public components: _AllComponents) {
|
|
22
|
-
// // this.allMethods = components
|
|
23
|
-
// // .map((component) => component.methods)
|
|
24
|
-
// // .flat(); // Extract methods at runtime
|
|
25
|
-
// }
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// callMethod(method: MethodsOfComponent<_AllComponents[number]>[number]) {
|
|
29
|
-
// // if (!this.allMethods.includes(method)) {
|
|
30
|
-
// // throw new Error(`Method ${method} is not available.`);
|
|
31
|
-
// // }
|
|
32
|
-
// console.log(`Calling method: ${method}`);
|
|
33
|
-
// }
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// // Define your components
|
|
39
|
-
// class ComponentA extends BaseComponent<['doSomething']> {
|
|
40
|
-
// // constructor() {
|
|
41
|
-
// // super(['doSomething']);
|
|
42
|
-
// // }
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// type ProxyTypeWithMethods<T> = T extends BaseContainer<infer M extends typeof BaseComponent<string[]>[]> ? MethodsOfComponent<M[number]> : never;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// class channel<T extends BaseContainer<typeof BaseComponent<string[]>[]>> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// getProvider()
|
|
53
|
-
// : {
|
|
54
|
-
// [K in ProxyTypeWithMethods<T>[number]]: () => void
|
|
55
|
-
// } {
|
|
56
|
-
// return new Proxy({} as any, {
|
|
57
|
-
// get(target, prop, receiver) {
|
|
58
|
-
// return target[prop];
|
|
59
|
-
// }
|
|
60
|
-
// });
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
// class ComponentB extends BaseComponent<['doAnotherThing']> {
|
|
65
|
-
// // constructor() {
|
|
66
|
-
// // super(['doAnotherThing']);
|
|
67
|
-
// // }
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// method3() {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// }
|
|
75
|
-
// }
|
|
76
|
-
|
|
77
|
-
// // Instantiate the container
|
|
78
|
-
// const container = new BaseContainer([
|
|
79
|
-
// ComponentA,
|
|
80
|
-
// ComponentB
|
|
81
|
-
// ]);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// // Correct usage
|
|
88
|
-
// container.callMethod('doSomething'); // Calling method: doSomething
|
|
89
|
-
// container.callMethod('doAnotherThing'); // Calling method: doAnotherThing
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// const channelInstance = new channel<typeof container>();
|
|
94
|
-
|
|
95
|
-
// const provider = channelInstance.getProvider();
|
|
96
|
-
|
|
97
|
-
// provider.doAnotherThing();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// // Incorrect usage
|
|
101
|
-
// // container.callMethod('nonExistentMethod'); // Throws error: Method nonExistentMethod is not available
|
|
102
|
-
|
package/tests/polyfill.test.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// import { config } from 'dotenv';
|
|
2
|
-
// import { A_Polyfills } from '../src/lib/A_Polyfills'
|
|
3
|
-
// config();
|
|
4
|
-
// jest.retryTimes(0);
|
|
5
|
-
|
|
6
|
-
// describe('Polyfill Tests', () => {
|
|
7
|
-
|
|
8
|
-
// it('It Should return fs', async () => {
|
|
9
|
-
|
|
10
|
-
// const fs = await A_Polyfills.fs();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// console.log('fs: ', fs)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// });
|
|
17
|
-
// it('It Should return crypto', async () => {
|
|
18
|
-
|
|
19
|
-
// const crypto = await A_Polyfills.crypto();
|
|
20
|
-
|
|
21
|
-
// console.log('crypto: ', crypto)
|
|
22
|
-
|
|
23
|
-
// });
|
|
24
|
-
|
|
25
|
-
// it('Crypto should calculate Hash', async () => {
|
|
26
|
-
|
|
27
|
-
// const crypto = await A_Polyfills.crypto();
|
|
28
|
-
|
|
29
|
-
// const hash = await crypto.createFileHash('./index.ts', 'sha-256');
|
|
30
|
-
|
|
31
|
-
// console.log('hash: ', hash)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// });
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// });
|