@adaas/a-utils 0.0.8 → 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.
Files changed (172) hide show
  1. package/.nvmrc +1 -1
  2. package/dist/index.d.ts +21 -14
  3. package/dist/index.js +53 -20
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/constants/errors.constants.d.ts +0 -65
  6. package/dist/src/constants/errors.constants.js +0 -72
  7. package/dist/src/constants/errors.constants.js.map +1 -1
  8. package/dist/src/lib/A-Channel/A-Channel.component.d.ts +3 -0
  9. package/dist/src/lib/A-Channel/A-Channel.component.js +8 -0
  10. package/dist/src/lib/A-Channel/A-Channel.component.js.map +1 -0
  11. package/dist/src/lib/A-Channel/A-Channel.error.d.ts +3 -0
  12. package/dist/src/lib/A-Channel/A-Channel.error.js +8 -0
  13. package/dist/src/lib/A-Channel/A-Channel.error.js.map +1 -0
  14. package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
  15. package/dist/src/lib/A-Channel/A-Channel.types.js +2 -0
  16. package/dist/src/lib/A-Channel/A-Channel.types.js.map +1 -0
  17. package/dist/src/lib/A-Command/A-Command.constants.d.ts +22 -0
  18. package/dist/src/lib/A-Command/A-Command.constants.js +28 -0
  19. package/dist/src/lib/A-Command/A-Command.constants.js.map +1 -0
  20. package/dist/src/lib/A-Command/A-Command.entity.d.ts +133 -0
  21. package/dist/src/lib/A-Command/A-Command.entity.js +273 -0
  22. package/dist/src/lib/A-Command/A-Command.entity.js.map +1 -0
  23. package/dist/src/lib/A-Command/A-Command.error.d.ts +3 -0
  24. package/dist/src/lib/A-Command/A-Command.error.js +8 -0
  25. package/dist/src/lib/A-Command/A-Command.error.js.map +1 -0
  26. package/dist/src/lib/A-Command/A-Command.types.d.ts +73 -0
  27. package/dist/src/lib/A-Command/A-Command.types.js +4 -0
  28. package/dist/src/lib/A-Command/A-Command.types.js.map +1 -0
  29. package/dist/src/lib/A-Config/A-Config.constants.d.ts +3 -0
  30. package/dist/src/lib/A-Config/A-Config.constants.js +6 -0
  31. package/dist/src/lib/A-Config/A-Config.constants.js.map +1 -0
  32. package/dist/src/lib/A-Config/A-Config.container.d.ts +8 -0
  33. package/dist/src/lib/A-Config/A-Config.container.js +75 -0
  34. package/dist/src/lib/A-Config/A-Config.container.js.map +1 -0
  35. package/dist/src/lib/A-Config/A-Config.context.d.ts +29 -0
  36. package/dist/src/lib/A-Config/A-Config.context.js +63 -0
  37. package/dist/src/lib/A-Config/A-Config.context.js.map +1 -0
  38. package/dist/src/lib/A-Config/A-Config.error.d.ts +4 -0
  39. package/dist/src/lib/A-Config/A-Config.error.js +9 -0
  40. package/dist/src/lib/A-Config/A-Config.error.js.map +1 -0
  41. package/dist/src/lib/A-Config/A-Config.types.d.ts +19 -0
  42. package/dist/src/lib/A-Config/A-Config.types.js +7 -0
  43. package/dist/src/lib/A-Config/A-Config.types.js.map +1 -0
  44. package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +30 -0
  45. package/dist/src/lib/A-Config/components/ConfigReader.component.js +85 -0
  46. package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +1 -0
  47. package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +10 -0
  48. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +37 -0
  49. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +1 -0
  50. package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +11 -0
  51. package/dist/src/lib/A-Config/components/FileConfigReader.component.js +47 -0
  52. package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +1 -0
  53. package/dist/src/lib/A-Logger/A-Logger.component.d.ts +29 -0
  54. package/dist/src/lib/A-Logger/A-Logger.component.js +152 -0
  55. package/dist/src/lib/A-Logger/A-Logger.component.js.map +1 -0
  56. package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
  57. package/dist/src/lib/A-Logger/A-Logger.types.js +2 -0
  58. package/dist/src/lib/A-Logger/A-Logger.types.js.map +1 -0
  59. package/dist/src/lib/A-Memory/A-Memory.context.d.ts +64 -0
  60. package/dist/src/lib/A-Memory/A-Memory.context.js +105 -0
  61. package/dist/src/lib/A-Memory/A-Memory.context.js.map +1 -0
  62. package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +20 -0
  63. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +53 -0
  64. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +1 -0
  65. package/dist/src/{global/A_Polyfills.d.ts → lib/A-Polyfill/A-Polyfill.types.d.ts} +1 -13
  66. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +2 -0
  67. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +1 -0
  68. package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +10 -0
  69. package/dist/src/{global/A_Polyfills.js → lib/A-Polyfill/A-Polyfills.class.js} +4 -4
  70. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +1 -0
  71. package/dist/src/{global/A_Deferred.class.d.ts → lib/A-Schedule/A-Deferred.class.d.ts} +4 -0
  72. package/dist/src/{global/A_Deferred.class.js → lib/A-Schedule/A-Deferred.class.js} +5 -1
  73. package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +1 -0
  74. package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +57 -0
  75. package/dist/src/lib/A-Schedule/A-Schedule.component.js +49 -0
  76. package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +1 -0
  77. package/dist/src/{types/A_ScheduleObject.types.d.ts → lib/A-Schedule/A-Schedule.types.d.ts} +2 -1
  78. package/dist/src/{types/ASEID.types.js → lib/A-Schedule/A-Schedule.types.js} +1 -3
  79. package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +1 -0
  80. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +29 -0
  81. package/dist/src/{global/A_ScheduleObject.class.js → lib/A-Schedule/A-ScheduleObject.class.js} +25 -5
  82. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +1 -0
  83. package/index.ts +23 -47
  84. package/jest.config.ts +3 -3
  85. package/package.json +6 -6
  86. package/src/constants/errors.constants.ts +0 -78
  87. package/src/lib/A-Channel/A-Channel.component.ts +8 -0
  88. package/src/lib/A-Channel/A-Channel.error.ts +6 -0
  89. package/src/lib/A-Channel/A-Channel.types.ts +0 -0
  90. package/src/lib/A-Command/A-Command.constants.ts +31 -0
  91. package/src/lib/A-Command/A-Command.entity.ts +327 -0
  92. package/src/lib/A-Command/A-Command.error.ts +6 -0
  93. package/src/lib/A-Command/A-Command.types.ts +100 -0
  94. package/src/lib/A-Config/A-Config.constants.ts +13 -0
  95. package/src/lib/A-Config/A-Config.container.ts +63 -0
  96. package/src/lib/A-Config/A-Config.context.ts +117 -0
  97. package/src/lib/A-Config/A-Config.error.ts +7 -0
  98. package/src/lib/A-Config/A-Config.types.ts +26 -0
  99. package/src/lib/A-Config/components/ConfigReader.component.ts +67 -0
  100. package/src/lib/A-Config/components/ENVConfigReader.component.ts +31 -0
  101. package/src/lib/A-Config/components/FileConfigReader.component.ts +42 -0
  102. package/src/lib/A-Logger/A-Logger.component.ts +190 -0
  103. package/src/lib/A-Logger/A-Logger.types.ts +0 -0
  104. package/src/lib/A-Memory/A-Memory.context.ts +115 -0
  105. package/src/lib/A-Polyfill/A-Polyfill.component.ts +45 -0
  106. package/src/lib/A-Polyfill/A-Polyfill.types.ts +10 -0
  107. package/src/{global/A_Polyfills.ts → lib/A-Polyfill/A-Polyfills.class.ts} +2 -16
  108. package/src/{global/A_Deferred.class.ts → lib/A-Schedule/A-Deferred.class.ts} +4 -0
  109. package/src/lib/A-Schedule/A-Schedule.component.ts +89 -0
  110. package/src/{types/A_ScheduleObject.types.ts → lib/A-Schedule/A-Schedule.types.ts} +7 -2
  111. package/src/{global/A_ScheduleObject.class.ts → lib/A-Schedule/A-ScheduleObject.class.ts} +25 -7
  112. package/tests/A-Channel.test.ts +16 -0
  113. package/tests/A-Command.test.ts +133 -0
  114. package/tests/A-Config.test.ts +185 -0
  115. package/tests/A-Polyfill.test.ts +67 -0
  116. package/tests/A-Schedule.test.ts +84 -0
  117. package/tests/jest.setup.ts +35 -0
  118. package/tsconfig.build.json +56 -0
  119. package/tsconfig.json +2 -2
  120. package/dist/src/global/ASEID.class.d.ts +0 -77
  121. package/dist/src/global/ASEID.class.js +0 -129
  122. package/dist/src/global/ASEID.class.js.map +0 -1
  123. package/dist/src/global/A_Deferred.class.js.map +0 -1
  124. package/dist/src/global/A_Entity.class.d.ts +0 -49
  125. package/dist/src/global/A_Entity.class.js +0 -94
  126. package/dist/src/global/A_Entity.class.js.map +0 -1
  127. package/dist/src/global/A_Error.class.d.ts +0 -13
  128. package/dist/src/global/A_Error.class.js +0 -63
  129. package/dist/src/global/A_Error.class.js.map +0 -1
  130. package/dist/src/global/A_Polyfills.js.map +0 -1
  131. package/dist/src/global/A_ScheduleObject.class.d.ts +0 -9
  132. package/dist/src/global/A_ScheduleObject.class.js.map +0 -1
  133. package/dist/src/global/A_ServerError.class.d.ts +0 -13
  134. package/dist/src/global/A_ServerError.class.js +0 -57
  135. package/dist/src/global/A_ServerError.class.js.map +0 -1
  136. package/dist/src/helpers/A_Common.helper.d.ts +0 -42
  137. package/dist/src/helpers/A_Common.helper.js +0 -214
  138. package/dist/src/helpers/A_Common.helper.js.map +0 -1
  139. package/dist/src/helpers/A_Schedule.helper.d.ts +0 -6
  140. package/dist/src/helpers/A_Schedule.helper.js +0 -21
  141. package/dist/src/helpers/A_Schedule.helper.js.map +0 -1
  142. package/dist/src/types/ASEID.types.d.ts +0 -65
  143. package/dist/src/types/ASEID.types.js.map +0 -1
  144. package/dist/src/types/A_Common.types.d.ts +0 -59
  145. package/dist/src/types/A_Common.types.js +0 -3
  146. package/dist/src/types/A_Common.types.js.map +0 -1
  147. package/dist/src/types/A_Entity.types.d.ts +0 -13
  148. package/dist/src/types/A_Entity.types.js +0 -4
  149. package/dist/src/types/A_Entity.types.js.map +0 -1
  150. package/dist/src/types/A_Error.type.d.ts +0 -7
  151. package/dist/src/types/A_Error.type.js +0 -3
  152. package/dist/src/types/A_Error.type.js.map +0 -1
  153. package/dist/src/types/A_Error.types.d.ts +0 -7
  154. package/dist/src/types/A_Error.types.js +0 -3
  155. package/dist/src/types/A_Error.types.js.map +0 -1
  156. package/dist/src/types/A_ScheduleObject.types.js +0 -3
  157. package/dist/src/types/A_ScheduleObject.types.js.map +0 -1
  158. package/dist/src/types/A_ServerError.types.d.ts +0 -4
  159. package/dist/src/types/A_ServerError.types.js +0 -3
  160. package/dist/src/types/A_ServerError.types.js.map +0 -1
  161. package/src/global/ASEID.class.ts +0 -208
  162. package/src/global/A_Error.class.ts +0 -88
  163. package/src/global/A_ServerError.class.ts +0 -70
  164. package/src/helpers/A_Common.helper.ts +0 -265
  165. package/src/helpers/A_Schedule.helper.ts +0 -25
  166. package/src/types/ASEID.types.ts +0 -86
  167. package/src/types/A_Common.types.ts +0 -111
  168. package/src/types/A_Entity.types.ts +0 -17
  169. package/src/types/A_Error.types.ts +0 -10
  170. package/src/types/A_ServerError.types.ts +0 -7
  171. package/tests/default.test.ts +0 -160
  172. package/tests/polyfill.test.ts +0 -37
@@ -1,208 +0,0 @@
1
- import { A_CONSTANTS__DEFAULT_ERRORS } from "../constants/errors.constants";
2
- import { A_CommonHelper } from "../helpers/A_Common.helper";
3
- import { A_TYPES__ASEID_Constructor, A_TYPES__ASEID_JSON } from "../types/ASEID.types";
4
- import { A_Error } from "./A_Error.class";
5
-
6
-
7
- /**
8
- * A - ADAAS
9
- * S - System
10
- * E - Entity
11
- * I - Identifier
12
- * D - iDentifier
13
- *
14
- *
15
- * adaas-sso@scope:usr:0000000001
16
- *
17
- * APP_NAMESPACE + @ + SCOPE + : ENTITY_NAME + : + ID + @ + VERSION
18
- */
19
- export class ASEID {
20
-
21
- static regexp: RegExp = new RegExp(`^[a-z|A-Z|0-9|-]+@[a-z|A-Z|0-9|-]+:[a-z|A-Z|0-9|-]+:[a-z|A-Z|0-9|-]+(@v[0-9]+|@lts)?$`)
22
-
23
-
24
- /**
25
- * Namespace for the ASEID
26
- * Generally it is the application name or code, should correspond to the namespace of the application
27
- * Could be ID or ASEID
28
- */
29
- private _namespace!: string;
30
-
31
- /**
32
- * Entity Scope the primary location of the resource
33
- * Organization, or organization Unit
34
- * Could be ID or ASEID
35
- *
36
- */
37
- private _scope!: string
38
-
39
- /**
40
- * Entity Type the type of the resource
41
- */
42
- private _entity!: string
43
-
44
- /**
45
- * Entity ID the unique identifier of the resource
46
- */
47
- private _id!: string
48
-
49
-
50
- /**
51
- * Version of the entity (optional)
52
- */
53
- private _version?: string
54
-
55
- /**
56
- * Shard of the entity (optional)
57
- */
58
- private _shard?: string
59
-
60
-
61
- constructor(
62
- aseid: string
63
- )
64
- constructor(
65
- props: A_TYPES__ASEID_Constructor
66
- )
67
- constructor(param1: string | A_TYPES__ASEID_Constructor) {
68
-
69
- if (typeof param1 === 'string' && !ASEID.isASEID(param1)) {
70
- throw new A_Error(A_CONSTANTS__DEFAULT_ERRORS.INVALID_ASEID)
71
- }
72
-
73
- const aseidString = typeof param1 === 'string' ? param1 : ASEID.generateASEID(param1);
74
-
75
- const { namespace, scope, entity, id, version, shard } = ASEID.parseASEID(aseidString);
76
-
77
- this._namespace = namespace;
78
- this._scope = scope;
79
- this._entity = entity;
80
- this._id = id;
81
- this._version = version;
82
- this._shard = shard;
83
- }
84
-
85
-
86
- get namespace(): string {
87
- return this._namespace;
88
- }
89
-
90
- get scope(): string {
91
- return this._scope;
92
- }
93
-
94
- get entity(): string {
95
- return this._entity;
96
- }
97
-
98
- get id(): string {
99
- return this._id;
100
- }
101
-
102
- get version(): string | undefined {
103
- return this._version;
104
- }
105
-
106
- get shard(): string | undefined {
107
- return this._shard;
108
- }
109
-
110
-
111
- /**
112
- * Tests if the identity string is an ASEID
113
- *
114
- * @param identity
115
- * @returns
116
- */
117
- static isASEID(identity: string): boolean {
118
- return this.regexp.test(
119
- identity
120
- )
121
- }
122
-
123
- /**
124
- * Generate an ASEID from a namespace, entity, and id
125
- *
126
- * @param props
127
- * @returns
128
- */
129
- static generateASEID(
130
- props: A_TYPES__ASEID_Constructor
131
- ): string {
132
-
133
- const namespace = props.namespace
134
- ? this.isASEID(props.namespace)
135
- ? this.parseASEID(props.namespace).id
136
- : props.namespace
137
- : process.env.A_NAMESPACE;
138
-
139
- const scope = typeof props.scope === 'number'
140
- ? A_CommonHelper.formatWithLeadingZeros(props.scope) :
141
- this.isASEID(props.scope)
142
- ? this.parseASEID(props.scope).id
143
- : props.scope;
144
-
145
- const entity = props.entity;
146
-
147
- const id = typeof props.id === 'number'
148
- ? A_CommonHelper.formatWithLeadingZeros(props.id)
149
- : props.id;
150
-
151
- const version = props.version;
152
-
153
- const shard = !props.shard ? undefined : props.shard;
154
-
155
-
156
- return `${namespace}@${scope}:${entity}:${shard ? (shard + '--' + id) : id}${version ? ('@' + version) : ''}`
157
- }
158
-
159
-
160
- /**
161
- * Parse ASEID into its components
162
- *
163
- *
164
- * @param identity
165
- * @returns
166
- */
167
- static parseASEID(identity: string): A_TYPES__ASEID_JSON {
168
-
169
- const [namespace, body, version] = identity.split('@');
170
- const [scope, entity, idCandidate] = body.split(':');
171
-
172
- const shard = idCandidate.includes('--') ? idCandidate.split('--')[0] : undefined;
173
- const id = idCandidate.includes('--') ? idCandidate.split('--')[1] : idCandidate;
174
-
175
- return {
176
- namespace,
177
- scope: scope,
178
- entity,
179
- id: id,
180
- version: version ? version : undefined,
181
- shard
182
- };
183
- }
184
-
185
-
186
- toString(): string {
187
- return ASEID.generateASEID({
188
- namespace: this._namespace,
189
- scope: this._scope,
190
- entity: this._entity,
191
- id: this._id,
192
- version: this._version,
193
- shard: this._shard
194
- })
195
- }
196
-
197
-
198
- toJSON(): A_TYPES__ASEID_JSON {
199
- return {
200
- namespace: this._namespace,
201
- scope: this._scope,
202
- entity: this._entity,
203
- id: this._id,
204
- version: this._version,
205
- shard: this._shard
206
- }
207
- }
208
- }
@@ -1,88 +0,0 @@
1
- import { A_TYPES__ServerError } from '../types/A_ServerError.types';
2
- import { AxiosError } from 'axios';
3
- import { A_TYPES__Error } from '../types/A_Error.types';
4
- import { A_CONSTANTS__ERROR_CODES } from '../constants/errors.constants';
5
-
6
-
7
- export class A_Error extends Error {
8
-
9
- code!: string;
10
- description!: string;
11
- originalError?: Error | any
12
- link?: string;
13
-
14
-
15
- constructor(
16
- params: A_TYPES__Error | Error | AxiosError | string | any
17
- ) {
18
- super(
19
- typeof params === 'string'
20
- ? params :
21
- params?.message || 'Oops... Something went wrong'
22
- );
23
-
24
- this.identifyErrorType(params);
25
-
26
- }
27
-
28
-
29
- get id(): string | undefined {
30
- return this.code.split('@')[1]
31
- }
32
-
33
-
34
- protected identifyErrorType(error: Error | AxiosError | A_TYPES__Error | string | any) {
35
- if (typeof error === 'string') {
36
- this.message = error;
37
- this.code = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
38
- this.description = 'If you see this error please let us know.';
39
- this.link = 'https://support.adaas.org/error/' + this.id;
40
- return;
41
- }
42
-
43
-
44
- if ((error as A_TYPES__ServerError).code &&
45
- (error as A_TYPES__ServerError).description &&
46
- (error as A_TYPES__ServerError).serverCode) {
47
-
48
- const target = error as A_TYPES__ServerError;
49
-
50
- this.message = target.message;
51
- this.code = target.code;
52
- this.description = target.description;
53
- this.originalError = target.originalError;
54
- this.link = target.link;
55
- }
56
- else if (error instanceof Error) {
57
- this.message = error.message;
58
- this.code = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
59
- this.description = 'If you see this error please let us know.';
60
- this.originalError = error;
61
- this.link = 'https://support.adaas.org/error/' + this.id;
62
-
63
-
64
- } else if (error instanceof AxiosError) {
65
- this.message = error.response?.data.message || error.message;
66
- this.code = error.response?.data.code || A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
67
- this.description = error.response?.data.description || 'If you see this error please let us know.';
68
- this.originalError = error.response;
69
- this.link = 'https://support.adaas.org/error/' + this.id;
70
- }
71
- }
72
-
73
-
74
- get compilingData(): A_TYPES__Error {
75
- return {
76
- message: this.message,
77
- code: this.code,
78
- description: this.description,
79
- originalError: this.originalError
80
- }
81
- }
82
-
83
- toJSON(): A_TYPES__Error {
84
- return this.compilingData;
85
- }
86
- }
87
-
88
-
@@ -1,70 +0,0 @@
1
- import { A_TYPES__ServerError } from '../types/A_ServerError.types';
2
- import { AxiosError } from 'axios';
3
- import { A_Error } from './A_Error.class';
4
- import { A_CONSTANTS__ERROR_CODES } from '../constants/errors.constants';
5
-
6
-
7
- export class A_ServerError extends A_Error {
8
-
9
- code!: string;
10
- description!: string;
11
- serverCode: number = 500;
12
- originalError: Error | any
13
-
14
-
15
- constructor(params: A_TYPES__ServerError | Error | AxiosError | any) {
16
- super(params);
17
- this.identifyErrorType(params);
18
- }
19
-
20
-
21
- protected identifyErrorType(error: Error | AxiosError | A_TYPES__ServerError) {
22
-
23
- if ((error as A_TYPES__ServerError).code &&
24
- (error as A_TYPES__ServerError).description &&
25
- (error as A_TYPES__ServerError).serverCode) {
26
-
27
- const target = error as A_TYPES__ServerError;
28
-
29
- this.message = target.message;
30
- this.code = target.code;
31
- this.description = target.description;
32
- this.serverCode = target.serverCode;
33
- this.originalError = target.originalError;
34
- this.link = target.link;
35
- }
36
- else if (error instanceof Error) {
37
- this.message = error.message;
38
- this.code = A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
39
- this.description = 'If you see this error please let us know.';
40
- this.serverCode = 500;
41
- this.originalError = error;
42
- this.link = 'https://support.adaas.org/error/' + this.id;
43
-
44
- } else if (error instanceof AxiosError) {
45
- this.message = error.response?.data.message || error.message;
46
- this.code = error.response?.data.code || A_CONSTANTS__ERROR_CODES.UNEXPECTED_ERROR;
47
- this.description = error.response?.data.description || 'If you see this error please let us know.';
48
- this.serverCode = error.response?.status || 500;
49
- this.originalError = error.response;
50
- this.link = 'https://support.adaas.org/error/' + this.id;
51
- }
52
- }
53
-
54
-
55
- get compilingData(): A_TYPES__ServerError {
56
- return {
57
- message: this.message,
58
- code: this.code,
59
- description: this.description,
60
- serverCode: this.serverCode,
61
- originalError: this.originalError
62
- }
63
- }
64
-
65
- toJSON(): A_TYPES__ServerError {
66
- return this.compilingData;
67
- }
68
- }
69
-
70
-
@@ -1,265 +0,0 @@
1
- import { A_Error } from "../global/A_Error.class";
2
- import { A_TYPES__DeepPartial } from "../types/A_Common.types";
3
-
4
- export class A_CommonHelper {
5
-
6
- static resolve() {
7
- return new Promise<void>((resolve) => resolve());
8
- }
9
-
10
- static omitArrayProperties<T, S extends string>(array: Array<T>, fields: string[]): Omit<T, S>[] {
11
-
12
- return array;
13
- }
14
-
15
- static sanitizeHTML(html: string): string {
16
- // Define the regular expression pattern to match all tags except <span>
17
- const regex = /<(?!\/?span(?=>|\s.*>))\/?.*?>/g;
18
-
19
- // Replace all matched tags with an empty string
20
- return html.replace(regex, '');
21
- }
22
-
23
-
24
-
25
-
26
- /**
27
- * Check if a class is inherited from another class
28
- *
29
- * @param childClass
30
- * @param parentClass
31
- * @returns
32
- */
33
- static isInheritedFrom(childClass: any, parentClass: any): boolean {
34
- let current = childClass;
35
-
36
- // Traverse the prototype chain
37
- while (current) {
38
- if (current === parentClass) {
39
- return true;
40
- }
41
- current = Object.getPrototypeOf(current);
42
- }
43
- return false;
44
- }
45
-
46
-
47
- /**
48
- * Omit properties from an object or array with nested objects
49
- *
50
- * @param input
51
- * @param paths
52
- * @returns
53
- */
54
- static omitProperties<T, S extends string>(
55
- input: T,
56
- paths: string[]
57
-
58
- ): Omit<T, S> {
59
-
60
- // Deep clone the input object or array
61
- const result = JSON.parse(JSON.stringify(input));
62
-
63
- // Helper function to recursively remove properties
64
- function removeProperties(target: Record<string, any> | any[], currPath: string[]) {
65
- const currKey = currPath[0];
66
- if (currPath.length === 1) {
67
- // If current path has only one key, delete the property
68
- delete target[currKey];
69
- } else if (target[currKey] !== undefined && typeof target[currKey] === 'object') {
70
- // If current key exists and is an object, recursively call removeProperties
71
- removeProperties(target[currKey], currPath.slice(1));
72
- }
73
- }
74
-
75
- // Iterate through each path and remove corresponding properties from the result
76
- paths.forEach(path => {
77
- const pathKeys = path.split('.');
78
- removeProperties(result, pathKeys);
79
- });
80
-
81
- return result as Omit<T, S>;
82
- }
83
-
84
-
85
- /**
86
- * Format a number with leading zeros to a fixed length
87
- *
88
- * @param number
89
- * @param maxZeros
90
- * @returns
91
- */
92
- static formatWithLeadingZeros(number, maxZeros = 10) {
93
- const formattedNumber = String(number).padStart(maxZeros + 1, '0');
94
- return formattedNumber.slice(-maxZeros);
95
- }
96
-
97
- /**
98
- * Remove leading zeros from a formatted number
99
- */
100
- static removeLeadingZeros(formattedNumber) {
101
- return String(Number(formattedNumber)); // Convert to number and back to string to remove leading zeros
102
- }
103
-
104
-
105
-
106
- static toUpperSnakeCase(str: string): string {
107
- return str
108
- .replace(/([a-z])([A-Z])/g, '$1_$2') // Handle lowercase followed by uppercase
109
- .replace(/[-\s]([A-Z])/g, '_$1') // Handle non-alphabetical followed by uppercase
110
- .replace(/-/g, '_')
111
- .toUpperCase();
112
- }
113
-
114
- static toCamelCase(str: string): string {
115
- return str.toLowerCase().replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
116
- }
117
-
118
-
119
- static toPascalCase(str: string): string {
120
- const camelCase = this.toCamelCase(str);
121
- return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
122
- }
123
-
124
- static toKebabCase(str: string): string {
125
- return str
126
- .replace(/([a-z])([A-Z])/g, '$1-$2') // Handle lowercase followed by uppercase
127
- .replace(/[_\s]([A-Z])/g, '-$1') // Handle non-alphabetical followed by uppercase
128
- .replace(/_/g, '-')
129
- .toLowerCase();
130
- }
131
-
132
- static isObject(item: unknown): item is Record<string, any> {
133
- return item !== null && typeof item === 'object' && !Array.isArray(item);
134
- }
135
-
136
- static deepMerge<T = any>(target: any, source: any, visited = new Map<any, any>()): T {
137
- if (this.isObject(target) && this.isObject(source)) {
138
- for (const key in source) {
139
- if (this.isObject(source[key])) {
140
- if (!target[key]) {
141
- target[key] = {};
142
- }
143
- // Check if the source object has already been visited
144
- if (!visited.has(source[key])) {
145
- visited.set(source[key], {});
146
- this.deepMerge(target[key], source[key], visited);
147
- } else {
148
- target[key] = visited.get(source[key]);
149
- }
150
- } else {
151
- target[key] = source[key];
152
- }
153
- }
154
- }
155
- return target;
156
- }
157
-
158
-
159
- static deepClone<T>(target: T): T {
160
- // Check if the value is null or undefined
161
- if (target === null || target === undefined) {
162
- return target;
163
- }
164
-
165
- // Handle primitive types (string, number, boolean, etc.)
166
- if (typeof target !== 'object') {
167
- return target;
168
- }
169
-
170
- // Handle Date
171
- if (target instanceof Date) {
172
- return new Date(target.getTime()) as T;
173
- }
174
-
175
- // Handle Array
176
- if (Array.isArray(target)) {
177
- return target.map(item => this.deepClone(item)) as unknown as T;
178
- }
179
-
180
- // Handle Function
181
- if (typeof target === 'function') {
182
- return target;
183
- }
184
-
185
- // Handle Object
186
- if (target instanceof Object) {
187
- const clone = {} as T;
188
- for (const key in target) {
189
- if (target.hasOwnProperty(key)) {
190
- clone[key] = this.deepClone(target[key]);
191
- }
192
- }
193
- return clone;
194
- }
195
-
196
- // For any other cases
197
- throw new Error('Unable to clone the object. Unsupported type.');
198
- }
199
-
200
-
201
- static deepCloneAndMerge<T>(target: A_TYPES__DeepPartial<T>, source: T): T {
202
- if (
203
- (source === null || source === undefined) &&
204
- (target === null || target === undefined))
205
- return target;
206
-
207
- // Check if the value is null or undefined
208
- if ((target === null || target === undefined) &&
209
- source
210
- ) {
211
- return this.deepClone(source);
212
- }
213
-
214
- // Handle primitive types (string, number, boolean, etc.)
215
- if (typeof target !== 'object') {
216
- return target
217
- }
218
-
219
-
220
- // Handle Date
221
- if (target instanceof Date) {
222
- return new Date(target.getTime()) as T;
223
- }
224
-
225
- // Handle Array
226
- if (Array.isArray(target)) {
227
- return target.map(item => this.deepCloneAndMerge(item, source)) as unknown as T;
228
- }
229
-
230
- // Handle Function
231
- if (typeof target === 'function') {
232
- return target;
233
- }
234
-
235
- // Handle Object
236
- if (target instanceof Object) {
237
- const clone = {} as T;
238
- for (const key in target) {
239
- if (
240
- source[key] !== null
241
- &&
242
- source[key] !== undefined
243
- )
244
- clone[key] = this.deepCloneAndMerge(target[key as any], source[key]);
245
- else
246
- clone[key as any] = this.deepClone(target[key]);
247
- }
248
-
249
- for (const key in source) {
250
- if (
251
- target[key] !== undefined
252
- &&
253
- target[key] !== null
254
- )
255
- clone[key] = this.deepCloneAndMerge(target[key], source[key]);
256
- else
257
- clone[key] = this.deepClone(source[key]);
258
- }
259
- return clone;
260
- }
261
-
262
- // For any other cases
263
- throw new A_Error('Unable to clone the object. Unsupported type.');
264
- }
265
- }
@@ -1,25 +0,0 @@
1
- import { A_ScheduleObject } from "../global/A_ScheduleObject.class";
2
- import { A_TYPES__ScheduleObjectConfig } from "../types/A_ScheduleObject.types";
3
-
4
- export class A_ScheduleHelper {
5
-
6
- static delay<T = void>(ms = 1000, resolver?: Promise<T>) {
7
- return new Promise<T>((resolve, reject) => setTimeout(() => {
8
- if (resolver) {
9
- resolver.then(resolve).catch(reject);
10
- }
11
- else {
12
- resolve(0 as T);
13
- }
14
- }, ms))
15
- }
16
-
17
-
18
- static schedule<T = void>(
19
- ms = 1000,
20
- resolver: () => Promise<T>,
21
- config?: A_TYPES__ScheduleObjectConfig
22
- ): A_ScheduleObject<T> {
23
- return new A_ScheduleObject<T>(ms, resolver, config);
24
- }
25
- }