@adaas/a-utils 0.0.9 → 0.1.1
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/dist/index.d.ts +21 -15
- package/dist/index.js +53 -22
- package/dist/index.js.map +1 -1
- package/dist/src/constants/errors.constants.d.ts +0 -65
- package/dist/src/constants/errors.constants.js +0 -72
- package/dist/src/constants/errors.constants.js.map +1 -1
- package/dist/src/lib/A-Channel/A-Channel.component.d.ts +3 -0
- package/dist/src/lib/A-Channel/A-Channel.component.js +8 -0
- package/dist/src/lib/A-Channel/A-Channel.component.js.map +1 -0
- package/dist/src/lib/A-Channel/A-Channel.error.d.ts +3 -0
- package/dist/src/lib/A-Channel/A-Channel.error.js +8 -0
- package/dist/src/lib/A-Channel/A-Channel.error.js.map +1 -0
- package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
- package/dist/src/lib/A-Channel/A-Channel.types.js +2 -0
- package/dist/src/lib/A-Channel/A-Channel.types.js.map +1 -0
- package/dist/src/lib/A-Command/A-Command.constants.d.ts +22 -0
- package/dist/src/lib/A-Command/A-Command.constants.js +28 -0
- package/dist/src/lib/A-Command/A-Command.constants.js.map +1 -0
- package/dist/src/lib/A-Command/A-Command.entity.d.ts +133 -0
- package/dist/src/lib/A-Command/A-Command.entity.js +273 -0
- package/dist/src/lib/A-Command/A-Command.entity.js.map +1 -0
- package/dist/src/lib/A-Command/A-Command.error.d.ts +3 -0
- package/dist/src/lib/A-Command/A-Command.error.js +8 -0
- package/dist/src/lib/A-Command/A-Command.error.js.map +1 -0
- package/dist/src/lib/A-Command/A-Command.types.d.ts +73 -0
- package/dist/src/lib/A-Command/A-Command.types.js +4 -0
- package/dist/src/lib/A-Command/A-Command.types.js.map +1 -0
- package/dist/src/lib/A-Config/A-Config.constants.d.ts +3 -0
- package/dist/src/lib/A-Config/A-Config.constants.js +6 -0
- package/dist/src/lib/A-Config/A-Config.constants.js.map +1 -0
- package/dist/src/lib/A-Config/A-Config.container.d.ts +8 -0
- package/dist/src/lib/A-Config/A-Config.container.js +75 -0
- package/dist/src/lib/A-Config/A-Config.container.js.map +1 -0
- package/dist/src/lib/A-Config/A-Config.context.d.ts +29 -0
- package/dist/src/lib/A-Config/A-Config.context.js +63 -0
- package/dist/src/lib/A-Config/A-Config.context.js.map +1 -0
- package/dist/src/lib/A-Config/A-Config.error.d.ts +4 -0
- package/dist/src/lib/A-Config/A-Config.error.js +9 -0
- package/dist/src/lib/A-Config/A-Config.error.js.map +1 -0
- package/dist/src/lib/A-Config/A-Config.types.d.ts +19 -0
- package/dist/src/lib/A-Config/A-Config.types.js +7 -0
- package/dist/src/lib/A-Config/A-Config.types.js.map +1 -0
- package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +30 -0
- package/dist/src/lib/A-Config/components/ConfigReader.component.js +85 -0
- package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +1 -0
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +10 -0
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +37 -0
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +1 -0
- package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +11 -0
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js +47 -0
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +1 -0
- package/dist/src/lib/A-Logger/A-Logger.component.d.ts +29 -0
- package/dist/src/lib/A-Logger/A-Logger.component.js +152 -0
- package/dist/src/lib/A-Logger/A-Logger.component.js.map +1 -0
- package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
- package/dist/src/lib/A-Logger/A-Logger.types.js +2 -0
- package/dist/src/lib/A-Logger/A-Logger.types.js.map +1 -0
- package/dist/src/lib/A-Memory/A-Memory.context.d.ts +64 -0
- package/dist/src/lib/A-Memory/A-Memory.context.js +105 -0
- package/dist/src/lib/A-Memory/A-Memory.context.js.map +1 -0
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +20 -0
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +53 -0
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +1 -0
- package/dist/src/{global/A_Polyfills.d.ts → lib/A-Polyfill/A-Polyfill.types.d.ts} +1 -13
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +2 -0
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +1 -0
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +10 -0
- package/dist/src/{global/A_Polyfills.js → lib/A-Polyfill/A-Polyfills.class.js} +4 -4
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +1 -0
- package/dist/src/{global/A_Deferred.class.d.ts → lib/A-Schedule/A-Deferred.class.d.ts} +4 -0
- package/dist/src/{global/A_Deferred.class.js → lib/A-Schedule/A-Deferred.class.js} +5 -1
- package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +1 -0
- package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +57 -0
- package/dist/src/lib/A-Schedule/A-Schedule.component.js +49 -0
- package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +1 -0
- package/dist/src/{types/A_ScheduleObject.types.d.ts → lib/A-Schedule/A-Schedule.types.d.ts} +2 -1
- package/dist/src/{types/ASEID.types.js → lib/A-Schedule/A-Schedule.types.js} +1 -3
- package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +1 -0
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +29 -0
- package/dist/src/{global/A_ScheduleObject.class.js → lib/A-Schedule/A-ScheduleObject.class.js} +25 -5
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +1 -0
- package/index.ts +33 -58
- package/jest.config.ts +3 -3
- package/package.json +6 -6
- package/src/constants/errors.constants.ts +0 -78
- package/src/lib/A-Channel/A-Channel.component.ts +8 -0
- package/src/lib/A-Channel/A-Channel.error.ts +6 -0
- package/src/lib/A-Channel/A-Channel.types.ts +0 -0
- package/src/lib/A-Command/A-Command.constants.ts +31 -0
- package/src/lib/A-Command/A-Command.entity.ts +327 -0
- package/src/lib/A-Command/A-Command.error.ts +6 -0
- package/src/lib/A-Command/A-Command.types.ts +100 -0
- package/src/lib/A-Config/A-Config.constants.ts +13 -0
- package/src/lib/A-Config/A-Config.container.ts +63 -0
- package/src/lib/A-Config/A-Config.context.ts +117 -0
- package/src/lib/A-Config/A-Config.error.ts +7 -0
- package/src/lib/A-Config/A-Config.types.ts +26 -0
- package/src/lib/A-Config/components/ConfigReader.component.ts +67 -0
- package/src/lib/A-Config/components/ENVConfigReader.component.ts +31 -0
- package/src/lib/A-Config/components/FileConfigReader.component.ts +42 -0
- package/src/lib/A-Logger/A-Logger.component.ts +190 -0
- package/src/lib/A-Logger/A-Logger.types.ts +0 -0
- package/src/lib/A-Memory/A-Memory.context.ts +115 -0
- package/src/lib/A-Polyfill/A-Polyfill.component.ts +45 -0
- package/src/lib/A-Polyfill/A-Polyfill.types.ts +10 -0
- package/src/{global/A_Polyfills.ts → lib/A-Polyfill/A-Polyfills.class.ts} +2 -16
- package/src/{global/A_Deferred.class.ts → lib/A-Schedule/A-Deferred.class.ts} +4 -0
- package/src/lib/A-Schedule/A-Schedule.component.ts +89 -0
- package/src/{types/A_ScheduleObject.types.ts → lib/A-Schedule/A-Schedule.types.ts} +7 -2
- package/src/{global/A_ScheduleObject.class.ts → lib/A-Schedule/A-ScheduleObject.class.ts} +25 -7
- package/tests/A-Channel.test.ts +16 -0
- package/tests/A-Command.test.ts +133 -0
- package/tests/A-Config.test.ts +185 -0
- package/tests/A-Polyfill.test.ts +67 -0
- package/tests/A-Schedule.test.ts +84 -0
- package/tests/jest.setup.ts +35 -0
- package/tsconfig.build.json +56 -0
- package/tsconfig.json +2 -2
- package/dist/src/global/ASEID.class.d.ts +0 -77
- package/dist/src/global/ASEID.class.js +0 -129
- package/dist/src/global/ASEID.class.js.map +0 -1
- package/dist/src/global/A_Deferred.class.js.map +0 -1
- package/dist/src/global/A_Entity.class.d.ts +0 -49
- package/dist/src/global/A_Entity.class.js +0 -94
- package/dist/src/global/A_Entity.class.js.map +0 -1
- package/dist/src/global/A_Error.class.d.ts +0 -13
- package/dist/src/global/A_Error.class.js +0 -63
- package/dist/src/global/A_Error.class.js.map +0 -1
- package/dist/src/global/A_Polyfills.js.map +0 -1
- package/dist/src/global/A_ScheduleObject.class.d.ts +0 -9
- package/dist/src/global/A_ScheduleObject.class.js.map +0 -1
- package/dist/src/global/A_ServerError.class.d.ts +0 -13
- package/dist/src/global/A_ServerError.class.js +0 -57
- package/dist/src/global/A_ServerError.class.js.map +0 -1
- package/dist/src/helpers/A_Common.helper.d.ts +0 -42
- package/dist/src/helpers/A_Common.helper.js +0 -214
- package/dist/src/helpers/A_Common.helper.js.map +0 -1
- package/dist/src/helpers/A_ID.helper.d.ts +0 -17
- package/dist/src/helpers/A_ID.helper.js +0 -26
- package/dist/src/helpers/A_ID.helper.js.map +0 -1
- package/dist/src/helpers/A_Schedule.helper.d.ts +0 -6
- package/dist/src/helpers/A_Schedule.helper.js +0 -21
- package/dist/src/helpers/A_Schedule.helper.js.map +0 -1
- package/dist/src/types/ASEID.types.d.ts +0 -65
- package/dist/src/types/ASEID.types.js.map +0 -1
- package/dist/src/types/A_Common.types.d.ts +0 -59
- package/dist/src/types/A_Common.types.js +0 -3
- package/dist/src/types/A_Common.types.js.map +0 -1
- package/dist/src/types/A_Entity.types.d.ts +0 -13
- package/dist/src/types/A_Entity.types.js +0 -4
- package/dist/src/types/A_Entity.types.js.map +0 -1
- package/dist/src/types/A_Error.type.d.ts +0 -7
- package/dist/src/types/A_Error.type.js +0 -3
- package/dist/src/types/A_Error.type.js.map +0 -1
- package/dist/src/types/A_Error.types.d.ts +0 -7
- package/dist/src/types/A_Error.types.js +0 -3
- package/dist/src/types/A_Error.types.js.map +0 -1
- package/dist/src/types/A_ScheduleObject.types.js +0 -3
- package/dist/src/types/A_ScheduleObject.types.js.map +0 -1
- package/dist/src/types/A_ServerError.types.d.ts +0 -4
- package/dist/src/types/A_ServerError.types.js +0 -3
- package/dist/src/types/A_ServerError.types.js.map +0 -1
- package/src/global/ASEID.class.ts +0 -208
- package/src/global/A_Error.class.ts +0 -88
- package/src/global/A_ServerError.class.ts +0 -70
- package/src/helpers/A_Common.helper.ts +0 -265
- package/src/helpers/A_ID.helper.ts +0 -32
- package/src/helpers/A_Schedule.helper.ts +0 -25
- package/src/types/ASEID.types.ts +0 -86
- package/src/types/A_Common.types.ts +0 -111
- package/src/types/A_Entity.types.ts +0 -17
- package/src/types/A_Error.types.ts +0 -10
- package/src/types/A_ServerError.types.ts +0 -7
- package/tests/default.test.ts +0 -173
- package/tests/polyfill.test.ts +0 -37
package/src/types/ASEID.types.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
export interface A_TYPES__ASEID_Constructor {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Namespace for the ASEID
|
|
5
|
-
* Generally it is the application name or code, should correspond to the namespace of the application
|
|
6
|
-
* Could be ID or ASEID
|
|
7
|
-
*/
|
|
8
|
-
namespace?: string,
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Entity Scope the primary location of the resource
|
|
12
|
-
* Organization, or organization Unit
|
|
13
|
-
* Could be ID or ASEID
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
scope: number | string
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Entity Type the type of the resource
|
|
20
|
-
*/
|
|
21
|
-
entity: string
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Entity ID the unique identifier of the resource
|
|
25
|
-
*/
|
|
26
|
-
id: number | string
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Version of the entity (optional)
|
|
31
|
-
*/
|
|
32
|
-
version?: string
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Shard of the entity (optional)
|
|
36
|
-
*/
|
|
37
|
-
shard?: string
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export interface A_TYPES__ASEID_ConstructorConfig {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* If true, the entity ASEID will be distributed across multiple shards.
|
|
46
|
-
* In this case SHARD should be provided via Environment Variables (A_SHARD) or Configurations
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
sharding?: boolean
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export type A_TYPES__ASEID_JSON = {
|
|
56
|
-
/**
|
|
57
|
-
* Namespace for the ASEID
|
|
58
|
-
*/
|
|
59
|
-
namespace: string,
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Entity Scope the primary location of the resource
|
|
63
|
-
*/
|
|
64
|
-
scope: string,
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Entity Type the type of the resource
|
|
68
|
-
*/
|
|
69
|
-
entity: string,
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Entity ID the unique identifier of the resource
|
|
73
|
-
*/
|
|
74
|
-
id: string,
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Version of the entity (optional)
|
|
78
|
-
*/
|
|
79
|
-
version?: string,
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Shard of the entity (optional)
|
|
83
|
-
*/
|
|
84
|
-
shard?: string
|
|
85
|
-
}
|
|
86
|
-
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export type A_AUTH_RequestParam = {
|
|
2
|
-
id?: string,
|
|
3
|
-
/**
|
|
4
|
-
* The issuer of the parameter. Could be system, custom, proxy, credentials or SIC to data provider service(e.g. CSS)
|
|
5
|
-
*/
|
|
6
|
-
issuer?: 'system' | 'custom' | 'proxy' | 'credentials' | string;
|
|
7
|
-
/**
|
|
8
|
-
* Common internal value, uses for proper mapping
|
|
9
|
-
*/
|
|
10
|
-
key?: string,
|
|
11
|
-
/**
|
|
12
|
-
* Allows to define the type of the parameter to convert input during the execution
|
|
13
|
-
*/
|
|
14
|
-
type: 'json' | 'array' | 'number' | 'string' | 'boolean' | 'base_64' | 'file' | 'file_url';
|
|
15
|
-
/**
|
|
16
|
-
* The name of the parameter
|
|
17
|
-
*/
|
|
18
|
-
name: string,
|
|
19
|
-
/**
|
|
20
|
-
* The value of the parameter
|
|
21
|
-
*/
|
|
22
|
-
value: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// =======================================================
|
|
30
|
-
// ==================== COMMON TYPES =====================
|
|
31
|
-
// =======================================================
|
|
32
|
-
|
|
33
|
-
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
34
|
-
type Decrement = [never, 0, 1, 2, 3, 4, 5];
|
|
35
|
-
|
|
36
|
-
export type A_TYPES__DeepPartial<T, D extends number = 5> = {
|
|
37
|
-
[P in keyof Required<T>]?:
|
|
38
|
-
[D] extends [never] ? any :
|
|
39
|
-
|
|
40
|
-
Required<T>[P] extends Array<infer U>
|
|
41
|
-
? Array<A_TYPES__DeepPartial<U, Decrement[D]>>
|
|
42
|
-
|
|
43
|
-
: Required<T>[P] extends Function
|
|
44
|
-
? Required<T>[P]
|
|
45
|
-
|
|
46
|
-
: Required<T>[P] extends object
|
|
47
|
-
? A_TYPES__DeepPartial<T[P], Decrement[D]>
|
|
48
|
-
: T[P]
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// export type A_TYPES__DeepPartial<T> = {
|
|
53
|
-
// [P in keyof Required<T>]?: Required<T>[P] extends object ? A_TYPES__DeepPartial<T[P]> : T[P];
|
|
54
|
-
// };
|
|
55
|
-
|
|
56
|
-
export type A_TYPES__ObjectKeyEnum<T, E> = {
|
|
57
|
-
[P in keyof Required<T>]?: T[P] extends object ? A_TYPES__ObjectKeyEnum<T[P], E> : E;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export type A_TYPES__Dictionary<T> = {
|
|
62
|
-
[Key: string]: T;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export type A_TYPES__NonObjectPaths<T> = T extends object ? { [K in keyof T]:
|
|
67
|
-
`${Exclude<K, symbol>}${""}`
|
|
68
|
-
}[keyof T] : never
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export type A_TYPES__Paths<T, D extends number = 5> = [D] extends [never] ? never : (
|
|
74
|
-
T extends object ? { [K in keyof T]:
|
|
75
|
-
`${Exclude<K, symbol>}${"" | `.${A_TYPES__Paths<T[K], Decrement[D]>}`}`
|
|
76
|
-
}[keyof T] : never
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
export type A_TYPES__UnionToIntersection<U> =
|
|
80
|
-
(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export type A_TYPES__PathsToObject<_Obj, T extends readonly string[]> = A_TYPES__UnionToIntersection<
|
|
84
|
-
{
|
|
85
|
-
[K in keyof T]: T[K] extends `${infer Key}.${infer Rest}`
|
|
86
|
-
? { [P in Key]: P extends keyof _Obj
|
|
87
|
-
? A_TYPES__PathsToObject<Required<_Obj>[P], [Rest]>
|
|
88
|
-
: any
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
: { [P in T[K]]:
|
|
92
|
-
`${T[K]}` extends keyof Required<_Obj> ? Required<_Obj>[`${T[K]}`] : never
|
|
93
|
-
};
|
|
94
|
-
}[number]
|
|
95
|
-
>;
|
|
96
|
-
|
|
97
|
-
export type A_TYPES__Required<T, arr extends (A_TYPES__Paths<T>)[] = (A_TYPES__Paths<T>)[]> = A_TYPES__PathsToObject<T, arr> & T;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
export type A_TYPES__ExtractNested<T, P extends string> = P extends `${infer K}.${infer Rest}`
|
|
101
|
-
? K extends keyof T
|
|
102
|
-
? { [Key in K]: A_TYPES__ExtractNested<T[K], Rest> }
|
|
103
|
-
: never
|
|
104
|
-
: P extends keyof T
|
|
105
|
-
? { [Key in P]: T[P] }
|
|
106
|
-
: never;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export type A_TYPES__ExtractProperties<T, P extends A_TYPES__Paths<T>[]> = A_TYPES__UnionToIntersection<{
|
|
110
|
-
[K in keyof P]: P[K] extends string ? A_TYPES__ExtractNested<T, P[K]> : never
|
|
111
|
-
}[number]>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ASEID } from "../global/ASEID.class";
|
|
2
|
-
|
|
3
|
-
export interface A_TYPES__IAEntity {
|
|
4
|
-
/**
|
|
5
|
-
* The ASEID of the entity
|
|
6
|
-
*/
|
|
7
|
-
aseid: ASEID
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type A_TYPES__AEntity_JSON = {
|
|
12
|
-
/**
|
|
13
|
-
* The ASEID of the entity
|
|
14
|
-
*/
|
|
15
|
-
aseid: string
|
|
16
|
-
};
|
|
17
|
-
|
package/tests/default.test.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { A_CommonHelper } from '@adaas/a-utils/helpers/A_Common.helper';
|
|
2
|
-
import { A_IdentityHelper } from '@adaas/a-utils/helpers/A_ID.helper';
|
|
3
|
-
import { A_ScheduleHelper } from '@adaas/a-utils/helpers/A_Schedule.helper';
|
|
4
|
-
import { A_TYPES__DeepPartial } from '@adaas/a-utils/types/A_Common.types';
|
|
5
|
-
import { config } from 'dotenv';
|
|
6
|
-
config();
|
|
7
|
-
jest.retryTimes(0);
|
|
8
|
-
|
|
9
|
-
describe('CommonHelper Tests', () => {
|
|
10
|
-
|
|
11
|
-
it('Schedule Should execute promise and await it ', async () => {
|
|
12
|
-
|
|
13
|
-
const start = Date.now();
|
|
14
|
-
let res = '';
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const scheduler = A_ScheduleHelper.schedule(3000, async () => {
|
|
18
|
-
return 'RESOLVED';
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
res = await scheduler.promise;
|
|
23
|
-
|
|
24
|
-
} catch (error) {
|
|
25
|
-
// Handle error if any
|
|
26
|
-
} finally {
|
|
27
|
-
const end = Date.now();
|
|
28
|
-
const duration = end - start;
|
|
29
|
-
|
|
30
|
-
expect(res).toBe('RESOLVED');
|
|
31
|
-
// Check if the duration exceeds 3 seconds
|
|
32
|
-
expect(duration).toBeGreaterThan(3000);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Schedule Should be canceled and rejected', async () => {
|
|
38
|
-
|
|
39
|
-
const start = Date.now();
|
|
40
|
-
let res = '';
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const scheduler = A_ScheduleHelper.schedule(3000, async () => {
|
|
44
|
-
return 'RESOLVED';
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
scheduler.clear();
|
|
49
|
-
res = await scheduler.promise;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
// Handle error if any
|
|
52
|
-
} finally {
|
|
53
|
-
const end = Date.now();
|
|
54
|
-
const duration = end - start;
|
|
55
|
-
|
|
56
|
-
expect(res).toBe('');
|
|
57
|
-
// Check if the duration exceeds 3 seconds
|
|
58
|
-
expect(duration).toBeLessThan(3000);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('Deep Clone and Merge ', async () => {
|
|
64
|
-
|
|
65
|
-
type TestType = {
|
|
66
|
-
a: string,
|
|
67
|
-
b: string,
|
|
68
|
-
c: {
|
|
69
|
-
d: string
|
|
70
|
-
},
|
|
71
|
-
f: (name: string) => string
|
|
72
|
-
s: Date
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const t: TestType = {
|
|
76
|
-
a: 'a',
|
|
77
|
-
b: 'b',
|
|
78
|
-
c: {
|
|
79
|
-
d: 'd'
|
|
80
|
-
},
|
|
81
|
-
f: (name: string) => { return name },
|
|
82
|
-
s: new Date()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const t2: A_TYPES__DeepPartial<TestType> = {
|
|
86
|
-
a: 'aa',
|
|
87
|
-
c: {
|
|
88
|
-
d: 'dd'
|
|
89
|
-
},
|
|
90
|
-
f: (name: string) => { return name + '2' }
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const merged = A_CommonHelper.deepCloneAndMerge(t2, t);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const name = merged.f('names');
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
expect(merged.a).toBe('aa');
|
|
100
|
-
expect(merged.b).toBe('b');
|
|
101
|
-
expect(merged.c.d).toBe('dd');
|
|
102
|
-
expect(name).toBe('names2');
|
|
103
|
-
expect(t).not.toEqual(merged);
|
|
104
|
-
expect(t2).not.toEqual(merged);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('Deep Clone Different Types', async () => {
|
|
108
|
-
|
|
109
|
-
type TestType = {
|
|
110
|
-
a: string,
|
|
111
|
-
b: string,
|
|
112
|
-
c: {
|
|
113
|
-
d: string
|
|
114
|
-
},
|
|
115
|
-
bool:{
|
|
116
|
-
a: boolean
|
|
117
|
-
},
|
|
118
|
-
f: (name: string) => string
|
|
119
|
-
s: Date
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const t: TestType = {
|
|
123
|
-
a: 'a',
|
|
124
|
-
b: 'b',
|
|
125
|
-
c: {
|
|
126
|
-
d: 'd'
|
|
127
|
-
},
|
|
128
|
-
bool:{
|
|
129
|
-
a: true
|
|
130
|
-
},
|
|
131
|
-
f: (name: string) => { return name },
|
|
132
|
-
s: new Date()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const t2: any = {
|
|
136
|
-
e: 'foo',
|
|
137
|
-
b: 'bb',
|
|
138
|
-
c:{
|
|
139
|
-
d: 'ddd'
|
|
140
|
-
},
|
|
141
|
-
bool:{
|
|
142
|
-
a: false
|
|
143
|
-
},
|
|
144
|
-
some: {
|
|
145
|
-
d: 'dd'
|
|
146
|
-
},
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const merged = A_CommonHelper.deepCloneAndMerge(t2, t);
|
|
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
|
-
it('should generate and then parse Unique time based IDs', async () => {
|
|
160
|
-
const id = A_IdentityHelper.generateTimeId();
|
|
161
|
-
const parts = A_IdentityHelper.parseTimeId(id);
|
|
162
|
-
|
|
163
|
-
expect(id).toBeDefined();
|
|
164
|
-
expect(parts.timestamp).toBeInstanceOf(Date);
|
|
165
|
-
expect(parts.random).toHaveLength(6);
|
|
166
|
-
|
|
167
|
-
// Check that the timestamp is recent (within the last minute)
|
|
168
|
-
const now = Date.now();
|
|
169
|
-
const timestamp = parts.timestamp.getTime();
|
|
170
|
-
expect(timestamp).toBeLessThanOrEqual(now);
|
|
171
|
-
expect(timestamp).toBeGreaterThan(now - 60000); // within the last minute
|
|
172
|
-
});
|
|
173
|
-
});
|
package/tests/polyfill.test.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { config } from 'dotenv';
|
|
2
|
-
import { A_Polyfills } from '../src/global/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
|
-
});
|