@adaas/a-utils 0.1.10 → 0.1.11

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 (116) hide show
  1. package/dist/index.d.mts +914 -0
  2. package/dist/index.d.ts +914 -27
  3. package/dist/index.js +1760 -90
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1738 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +5 -3
  8. package/src/index.ts +70 -0
  9. package/src/lib/A-Logger/A-Logger.component.ts +10 -3
  10. package/src/lib/A-Polyfill/A-Polyfill.component.ts +153 -15
  11. package/src/lib/A-Polyfill/A-Polyfill.types.ts +54 -0
  12. package/src/lib/A-Polyfill/classes/A-Buffer-Polyfill.class.ts +85 -0
  13. package/src/lib/A-Polyfill/classes/A-Crypto-Polyfill.class.ts +87 -0
  14. package/src/lib/A-Polyfill/classes/A-FS-Polyfill.class.ts +61 -0
  15. package/src/lib/A-Polyfill/classes/A-Http-Polyfill.class.ts +100 -0
  16. package/src/lib/A-Polyfill/classes/A-Https-Polyfill.class.ts +100 -0
  17. package/src/lib/A-Polyfill/classes/A-Path-Polyfill.class.ts +97 -0
  18. package/src/lib/A-Polyfill/classes/A-Process-Polyfill.class.ts +73 -0
  19. package/src/lib/A-Polyfill/classes/A-Url-Polyfill.class.ts +88 -0
  20. package/tests/A-Config.test.ts +5 -5
  21. package/tests/A-Polyfill.test.ts +446 -29
  22. package/tsconfig.json +1 -1
  23. package/tsup.config.ts +15 -0
  24. package/dist/src/constants/errors.constants.d.ts +0 -0
  25. package/dist/src/constants/errors.constants.js +0 -2
  26. package/dist/src/constants/errors.constants.js.map +0 -1
  27. package/dist/src/lib/A-Channel/A-Channel.component.d.ts +0 -22
  28. package/dist/src/lib/A-Channel/A-Channel.component.js +0 -84
  29. package/dist/src/lib/A-Channel/A-Channel.component.js.map +0 -1
  30. package/dist/src/lib/A-Channel/A-Channel.error.d.ts +0 -4
  31. package/dist/src/lib/A-Channel/A-Channel.error.js +0 -9
  32. package/dist/src/lib/A-Channel/A-Channel.error.js.map +0 -1
  33. package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
  34. package/dist/src/lib/A-Channel/A-Channel.types.js +0 -2
  35. package/dist/src/lib/A-Channel/A-Channel.types.js.map +0 -1
  36. package/dist/src/lib/A-Command/A-Command.constants.d.ts +0 -22
  37. package/dist/src/lib/A-Command/A-Command.constants.js +0 -28
  38. package/dist/src/lib/A-Command/A-Command.constants.js.map +0 -1
  39. package/dist/src/lib/A-Command/A-Command.entity.d.ts +0 -133
  40. package/dist/src/lib/A-Command/A-Command.entity.js +0 -273
  41. package/dist/src/lib/A-Command/A-Command.entity.js.map +0 -1
  42. package/dist/src/lib/A-Command/A-Command.error.d.ts +0 -3
  43. package/dist/src/lib/A-Command/A-Command.error.js +0 -8
  44. package/dist/src/lib/A-Command/A-Command.error.js.map +0 -1
  45. package/dist/src/lib/A-Command/A-Command.types.d.ts +0 -73
  46. package/dist/src/lib/A-Command/A-Command.types.js +0 -4
  47. package/dist/src/lib/A-Command/A-Command.types.js.map +0 -1
  48. package/dist/src/lib/A-Config/A-Config.constants.d.ts +0 -3
  49. package/dist/src/lib/A-Config/A-Config.constants.js +0 -6
  50. package/dist/src/lib/A-Config/A-Config.constants.js.map +0 -1
  51. package/dist/src/lib/A-Config/A-Config.container.d.ts +0 -6
  52. package/dist/src/lib/A-Config/A-Config.container.js +0 -77
  53. package/dist/src/lib/A-Config/A-Config.container.js.map +0 -1
  54. package/dist/src/lib/A-Config/A-Config.context.d.ts +0 -29
  55. package/dist/src/lib/A-Config/A-Config.context.js +0 -63
  56. package/dist/src/lib/A-Config/A-Config.context.js.map +0 -1
  57. package/dist/src/lib/A-Config/A-Config.error.d.ts +0 -4
  58. package/dist/src/lib/A-Config/A-Config.error.js +0 -9
  59. package/dist/src/lib/A-Config/A-Config.error.js.map +0 -1
  60. package/dist/src/lib/A-Config/A-Config.types.d.ts +0 -19
  61. package/dist/src/lib/A-Config/A-Config.types.js +0 -7
  62. package/dist/src/lib/A-Config/A-Config.types.js.map +0 -1
  63. package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +0 -30
  64. package/dist/src/lib/A-Config/components/ConfigReader.component.js +0 -103
  65. package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +0 -1
  66. package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +0 -14
  67. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +0 -72
  68. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +0 -1
  69. package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +0 -11
  70. package/dist/src/lib/A-Config/components/FileConfigReader.component.js +0 -47
  71. package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +0 -1
  72. package/dist/src/lib/A-Logger/A-Logger.component.d.ts +0 -29
  73. package/dist/src/lib/A-Logger/A-Logger.component.js +0 -152
  74. package/dist/src/lib/A-Logger/A-Logger.component.js.map +0 -1
  75. package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
  76. package/dist/src/lib/A-Logger/A-Logger.types.js +0 -2
  77. package/dist/src/lib/A-Logger/A-Logger.types.js.map +0 -1
  78. package/dist/src/lib/A-Manifest/A-Manifest.context.d.ts +0 -52
  79. package/dist/src/lib/A-Manifest/A-Manifest.context.js +0 -154
  80. package/dist/src/lib/A-Manifest/A-Manifest.context.js.map +0 -1
  81. package/dist/src/lib/A-Manifest/A-Manifest.error.d.ts +0 -4
  82. package/dist/src/lib/A-Manifest/A-Manifest.error.js +0 -9
  83. package/dist/src/lib/A-Manifest/A-Manifest.error.js.map +0 -1
  84. package/dist/src/lib/A-Manifest/A-Manifest.types.d.ts +0 -43
  85. package/dist/src/lib/A-Manifest/A-Manifest.types.js +0 -3
  86. package/dist/src/lib/A-Manifest/A-Manifest.types.js.map +0 -1
  87. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.d.ts +0 -14
  88. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js +0 -24
  89. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js.map +0 -1
  90. package/dist/src/lib/A-Memory/A-Memory.context.d.ts +0 -64
  91. package/dist/src/lib/A-Memory/A-Memory.context.js +0 -105
  92. package/dist/src/lib/A-Memory/A-Memory.context.js.map +0 -1
  93. package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +0 -20
  94. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +0 -53
  95. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +0 -1
  96. package/dist/src/lib/A-Polyfill/A-Polyfill.types.d.ts +0 -9
  97. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +0 -3
  98. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +0 -1
  99. package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +0 -11
  100. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js +0 -123
  101. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +0 -1
  102. package/dist/src/lib/A-Schedule/A-Deferred.class.d.ts +0 -12
  103. package/dist/src/lib/A-Schedule/A-Deferred.class.js +0 -23
  104. package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +0 -1
  105. package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +0 -57
  106. package/dist/src/lib/A-Schedule/A-Schedule.component.js +0 -49
  107. package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +0 -1
  108. package/dist/src/lib/A-Schedule/A-Schedule.types.d.ts +0 -10
  109. package/dist/src/lib/A-Schedule/A-Schedule.types.js +0 -3
  110. package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +0 -1
  111. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +0 -29
  112. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js +0 -58
  113. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +0 -1
  114. package/index.ts +0 -71
  115. package/src/lib/A-Polyfill/A-Polyfills.class.ts +0 -99
  116. package/tsconfig.build.json +0 -56
package/dist/index.mjs ADDED
@@ -0,0 +1,1738 @@
1
+ import { A_Feature, A_Inject, A_Scope, A_Concept, A_Container, A_Error, A_Component, A_Fragment, A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_CommonHelper, A_FormatterHelper, A_Context, A_Entity, A_ScopeError, A_TypeGuards } from '@adaas/a-concept';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
14
+ var A_ChannelError = class extends A_Error {
15
+ };
16
+ A_ChannelError.MethodNotImplemented = "A-Channel Method Not Implemented";
17
+
18
+ // src/lib/A-Channel/A-Channel.component.ts
19
+ var A_Channel = class extends A_Component {
20
+ constructor() {
21
+ super(...arguments);
22
+ /**
23
+ * Indicates whether the channel is processing requests
24
+ */
25
+ this._processing = false;
26
+ }
27
+ /**
28
+ * Indicates whether the channel is processing requests
29
+ */
30
+ get processing() {
31
+ return this._processing;
32
+ }
33
+ /**
34
+ * Indicates whether the channel is connected
35
+ */
36
+ get initialize() {
37
+ if (!this._initialized) {
38
+ this._initialized = this.connect();
39
+ }
40
+ return this._initialized;
41
+ }
42
+ /**
43
+ * Initializes the channel before use
44
+ */
45
+ async connect() {
46
+ throw new A_ChannelError(
47
+ A_ChannelError.MethodNotImplemented,
48
+ `The connect method is not implemented in ${this.constructor.name} channel. This method is required to initialize the channel before use. So please implement it in the derived class.`
49
+ );
50
+ }
51
+ /**
52
+ * Allows to send a request through the channel
53
+ *
54
+ * @param req - The request parameters
55
+ * @returns The response from the channel
56
+ */
57
+ async request(params) {
58
+ throw new A_ChannelError(
59
+ A_ChannelError.MethodNotImplemented,
60
+ `The request method is not implemented in ${this.constructor.name} channel.`
61
+ );
62
+ }
63
+ /**
64
+ * Uses for Fire-and-Forget messaging through the channel
65
+ *
66
+ * @param message - can be of any type depending on the channel implementation
67
+ */
68
+ async send(message) {
69
+ throw new A_ChannelError(
70
+ A_ChannelError.MethodNotImplemented,
71
+ `The send method is not implemented in ${this.constructor.name} channel.`
72
+ );
73
+ }
74
+ };
75
+ __decorateClass([
76
+ A_Feature.Define()
77
+ ], A_Channel.prototype, "connect", 1);
78
+ __decorateClass([
79
+ A_Feature.Define()
80
+ ], A_Channel.prototype, "request", 1);
81
+ __decorateClass([
82
+ A_Feature.Define()
83
+ ], A_Channel.prototype, "send", 1);
84
+
85
+ // src/lib/A-Command/A-Command.constants.ts
86
+ var A_TYPES__CommandMetaKey = /* @__PURE__ */ ((A_TYPES__CommandMetaKey2) => {
87
+ A_TYPES__CommandMetaKey2["EXTENSIONS"] = "a-command-extensions";
88
+ A_TYPES__CommandMetaKey2["FEATURES"] = "a-command-features";
89
+ A_TYPES__CommandMetaKey2["ABSTRACTIONS"] = "a-command-abstractions";
90
+ return A_TYPES__CommandMetaKey2;
91
+ })(A_TYPES__CommandMetaKey || {});
92
+ var A_CONSTANTS__A_Command_Status = /* @__PURE__ */ ((A_CONSTANTS__A_Command_Status2) => {
93
+ A_CONSTANTS__A_Command_Status2["INITIALIZED"] = "INITIALIZED";
94
+ A_CONSTANTS__A_Command_Status2["IN_PROGRESS"] = "IN_PROGRESS";
95
+ A_CONSTANTS__A_Command_Status2["COMPLETED"] = "COMPLETED";
96
+ A_CONSTANTS__A_Command_Status2["FAILED"] = "FAILED";
97
+ return A_CONSTANTS__A_Command_Status2;
98
+ })(A_CONSTANTS__A_Command_Status || {});
99
+ var A_CONSTANTS_A_Command_Features = /* @__PURE__ */ ((A_CONSTANTS_A_Command_Features2) => {
100
+ A_CONSTANTS_A_Command_Features2["INIT"] = "init";
101
+ A_CONSTANTS_A_Command_Features2["COMPLIED"] = "complied";
102
+ A_CONSTANTS_A_Command_Features2["EXECUTE"] = "execute";
103
+ A_CONSTANTS_A_Command_Features2["COMPLETE"] = "complete";
104
+ A_CONSTANTS_A_Command_Features2["FAIL"] = "fail";
105
+ return A_CONSTANTS_A_Command_Features2;
106
+ })(A_CONSTANTS_A_Command_Features || {});
107
+ var A_Memory = class extends A_Fragment {
108
+ /**
109
+ * Memory object that allows to store intermediate values and errors
110
+ *
111
+ * @param initialValues
112
+ */
113
+ constructor(initialValues) {
114
+ super();
115
+ this._memory = new Map(Object.entries(initialValues || {}));
116
+ this._errors = /* @__PURE__ */ new Set();
117
+ }
118
+ get Errors() {
119
+ return this._errors.size > 0 ? this._errors : void 0;
120
+ }
121
+ /**
122
+ * Verifies that all required keys are present in the proxy values
123
+ *
124
+ * @param requiredKeys
125
+ * @returns
126
+ */
127
+ async verifyPrerequisites(requiredKeys) {
128
+ return requiredKeys.every((key) => this._memory.has(key));
129
+ }
130
+ /**
131
+ * Adds an error to the context
132
+ *
133
+ * @param error
134
+ */
135
+ async error(error) {
136
+ this._errors.add(error);
137
+ }
138
+ /**
139
+ * Saves a value in the context memory
140
+ *
141
+ * @param key
142
+ * @param value
143
+ */
144
+ async set(key, value) {
145
+ this._memory.set(key, value);
146
+ }
147
+ /**
148
+ * Removes a value from the context memory by key
149
+ *
150
+ * @param key
151
+ */
152
+ async drop(key) {
153
+ this._memory.delete(key);
154
+ }
155
+ /**
156
+ * Clears all stored values in the context memory
157
+ */
158
+ async clear() {
159
+ this._memory.clear();
160
+ }
161
+ /**
162
+ * Converts all stored values to a plain object
163
+ *
164
+ * [!] By default uses all saved in memory values
165
+ *
166
+ * @returns
167
+ */
168
+ toJSON() {
169
+ const obj = {};
170
+ this._memory.forEach((value, key) => {
171
+ obj[key] = typeof value === "object" && value !== null && "toJSON" in value && typeof value.toJSON === "function" ? value.toJSON() : value;
172
+ });
173
+ return obj;
174
+ }
175
+ };
176
+
177
+ // src/lib/A-Command/A-Command.entity.ts
178
+ var A_Command = class extends A_Entity {
179
+ /**
180
+ *
181
+ * A-Command represents an executable command with a specific code and parameters.
182
+ * It can be executed within a given scope and stores execution results and errors.
183
+ *
184
+ *
185
+ * A-Command should be context independent and execution logic should be based on attached components
186
+ *
187
+ * @param code
188
+ * @param params
189
+ */
190
+ constructor(params) {
191
+ super(params);
192
+ this._listeners = /* @__PURE__ */ new Map();
193
+ }
194
+ // ====================================================================
195
+ // ================== Static A-Command Information ====================
196
+ // ====================================================================
197
+ /**
198
+ * Command Identifier that corresponds to the class name
199
+ */
200
+ static get code() {
201
+ return super.entity;
202
+ }
203
+ /**
204
+ * Execution Duration in milliseconds
205
+ */
206
+ get duration() {
207
+ return this._endTime && this._startTime ? this._endTime.getTime() - this._startTime.getTime() : this._startTime ? (/* @__PURE__ */ new Date()).getTime() - this._startTime.getTime() : void 0;
208
+ }
209
+ /**
210
+ * A shared scope between all features of the command during its execution
211
+ */
212
+ get scope() {
213
+ return this._executionScope;
214
+ }
215
+ /**
216
+ * Unique code identifying the command type
217
+ * Example: 'user.create', 'task.complete', etc.
218
+ *
219
+ */
220
+ get code() {
221
+ return this.constructor.code;
222
+ }
223
+ /**
224
+ * Current status of the command
225
+ */
226
+ get status() {
227
+ return this._status;
228
+ }
229
+ /**
230
+ * Start time of the command execution
231
+ */
232
+ get startedAt() {
233
+ return this._startTime;
234
+ }
235
+ /**
236
+ * End time of the command execution
237
+ */
238
+ get endedAt() {
239
+ return this._endTime;
240
+ }
241
+ /**
242
+ * Result of the command execution stored in the context
243
+ */
244
+ get result() {
245
+ return this._result;
246
+ }
247
+ /**
248
+ * Errors encountered during the command execution stored in the context
249
+ */
250
+ get errors() {
251
+ return this._errors;
252
+ }
253
+ /**
254
+ * Parameters used to invoke the command
255
+ */
256
+ get params() {
257
+ return this._params;
258
+ }
259
+ /**
260
+ * Indicates if the command has failed
261
+ */
262
+ get isFailed() {
263
+ return this._status === "FAILED" /* FAILED */;
264
+ }
265
+ /**
266
+ * Indicates if the command has completed successfully
267
+ */
268
+ get isCompleted() {
269
+ return this._status === "COMPLETED" /* COMPLETED */;
270
+ }
271
+ // --------------------------------------------------------------------------
272
+ // A-Command Lifecycle Methods
273
+ // --------------------------------------------------------------------------
274
+ // should create a new Task in DB with basic records
275
+ async init() {
276
+ this._status = "IN_PROGRESS" /* IN_PROGRESS */;
277
+ this._startTime = /* @__PURE__ */ new Date();
278
+ if (!this.scope.isInheritedFrom(A_Context.scope(this))) {
279
+ this.scope.inherit(A_Context.scope(this));
280
+ }
281
+ this.emit("init");
282
+ return await this.call("init", this.scope);
283
+ }
284
+ // Should compile everything before execution
285
+ async compile() {
286
+ this.emit("compile");
287
+ return await this.call("compile", this.scope);
288
+ }
289
+ /**
290
+ * Executes the command logic.
291
+ */
292
+ async execute() {
293
+ try {
294
+ await this.init();
295
+ await this.compile();
296
+ this.emit("execute");
297
+ await this.call("execute", this.scope);
298
+ await this.complete();
299
+ } catch (error) {
300
+ await this.fail();
301
+ }
302
+ }
303
+ /**
304
+ * Marks the command as completed
305
+ */
306
+ async complete() {
307
+ this._status = "COMPLETED" /* COMPLETED */;
308
+ this._endTime = /* @__PURE__ */ new Date();
309
+ this._result = this.scope.resolve(A_Memory).toJSON();
310
+ this.emit("complete");
311
+ return await this.call("complete", this.scope);
312
+ }
313
+ /**
314
+ * Marks the command as failed
315
+ */
316
+ async fail() {
317
+ this._status = "FAILED" /* FAILED */;
318
+ this._endTime = /* @__PURE__ */ new Date();
319
+ this._errors = this.scope.resolve(A_Memory).Errors;
320
+ this.emit("fail");
321
+ return await this.call("fail", this.scope);
322
+ }
323
+ // --------------------------------------------------------------------------
324
+ // A-Command Event-Emitter methods
325
+ // --------------------------------------------------------------------------
326
+ /**
327
+ * Registers an event listener for a specific event
328
+ *
329
+ * @param event
330
+ * @param listener
331
+ */
332
+ on(event, listener) {
333
+ if (!this._listeners.has(event)) {
334
+ this._listeners.set(event, /* @__PURE__ */ new Set());
335
+ }
336
+ this._listeners.get(event).add(listener);
337
+ }
338
+ /**
339
+ * Removes an event listener for a specific event
340
+ *
341
+ * @param event
342
+ * @param listener
343
+ */
344
+ off(event, listener) {
345
+ this._listeners.get(event)?.delete(listener);
346
+ }
347
+ /**
348
+ * Emits an event to all registered listeners
349
+ *
350
+ * @param event
351
+ */
352
+ emit(event) {
353
+ this._listeners.get(event)?.forEach((listener) => {
354
+ listener(this);
355
+ });
356
+ }
357
+ // --------------------------------------------------------------------------
358
+ // A-Entity Base Class Overrides
359
+ // --------------------------------------------------------------------------
360
+ // Serialization / Deserialization
361
+ // -------------------------------------------------------------------------
362
+ /**
363
+ * Allows to create a Command instance from new data
364
+ *
365
+ * @param newEntity
366
+ */
367
+ fromNew(newEntity) {
368
+ super.fromNew(newEntity);
369
+ this._executionScope = new A_Scope();
370
+ this._executionScope.register(new A_Memory());
371
+ this._params = newEntity;
372
+ this._status = "INITIALIZED" /* INITIALIZED */;
373
+ }
374
+ /**
375
+ * Allows to convert serialized data to Command instance
376
+ *
377
+ * [!] By default it omits params as they are not stored in the serialized data
378
+ *
379
+ * @param serialized
380
+ */
381
+ fromJSON(serialized) {
382
+ super.fromJSON(serialized);
383
+ this._executionScope = new A_Scope();
384
+ const memory = new A_Memory();
385
+ this._executionScope.register(memory);
386
+ if (serialized.startedAt) this._startTime = new Date(serialized.startedAt);
387
+ if (serialized.endedAt) this._endTime = new Date(serialized.endedAt);
388
+ if (serialized.result) {
389
+ Object.entries(serialized.result).forEach(([key, value]) => {
390
+ memory.set(key, value);
391
+ });
392
+ }
393
+ if (serialized.errors) {
394
+ serialized.errors.forEach((err) => {
395
+ memory.error(new A_Error(err));
396
+ });
397
+ }
398
+ this._status = serialized.status || "INITIALIZED" /* INITIALIZED */;
399
+ }
400
+ /**
401
+ * Converts the Command instance to a plain object
402
+ *
403
+ * @returns
404
+ */
405
+ toJSON() {
406
+ return {
407
+ ...super.toJSON(),
408
+ code: this.code,
409
+ status: this._status,
410
+ startedAt: this._startTime ? this._startTime.toISOString() : void 0,
411
+ endedAt: this._endTime ? this._endTime.toISOString() : void 0,
412
+ duration: this.duration,
413
+ result: this.result,
414
+ errors: this.errors ? Array.from(this.errors).map((err) => err.toJSON()) : void 0
415
+ };
416
+ }
417
+ };
418
+ var A_CommandError = class extends A_Error {
419
+ };
420
+
421
+ // src/lib/A-Config/A-Config.constants.ts
422
+ var A_CONSTANTS__CONFIG_ENV_VARIABLES = {};
423
+ var A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY = [];
424
+
425
+ // src/lib/A-Config/A-Config.context.ts
426
+ var A_Config = class extends A_Fragment {
427
+ constructor(config) {
428
+ super({
429
+ name: "A_Config"
430
+ });
431
+ this.VARIABLES = /* @__PURE__ */ new Map();
432
+ this.DEFAULT_ALLOWED_TO_READ_PROPERTIES = [
433
+ ...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
434
+ ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
435
+ ];
436
+ this.config = A_CommonHelper.deepCloneAndMerge(config, {
437
+ strict: false,
438
+ defaults: {},
439
+ variables: A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY
440
+ });
441
+ this.CONFIG_PROPERTIES = this.config.variables ? this.config.variables : [];
442
+ this.config.variables.forEach((variable) => {
443
+ this.VARIABLES.set(
444
+ A_FormatterHelper.toUpperSnakeCase(variable),
445
+ this.config.defaults[variable]
446
+ );
447
+ });
448
+ }
449
+ /**
450
+ * This method is used to get the configuration property by name
451
+ *
452
+ * @param property
453
+ * @returns
454
+ */
455
+ get(property) {
456
+ if (this.CONFIG_PROPERTIES.includes(property) || this.DEFAULT_ALLOWED_TO_READ_PROPERTIES.includes(property) || !this.config.strict)
457
+ return this.VARIABLES.get(A_FormatterHelper.toUpperSnakeCase(property));
458
+ throw new Error("Property not exists or not allowed to read");
459
+ }
460
+ set(property, value) {
461
+ const array = Array.isArray(property) ? property : typeof property === "string" ? [{ property, value }] : Object.keys(property).map((key) => ({
462
+ property: key,
463
+ value: property[key]
464
+ }));
465
+ for (const { property: property2, value: value2 } of array) {
466
+ let targetValue = value2 ? value2 : this.config?.defaults ? this.config.defaults[property2] : void 0;
467
+ this.VARIABLES.set(A_FormatterHelper.toUpperSnakeCase(property2), targetValue);
468
+ }
469
+ }
470
+ };
471
+ var A_Logger = class extends A_Component {
472
+ constructor(scope) {
473
+ super();
474
+ this.scope = scope;
475
+ this.colors = {
476
+ green: "32",
477
+ blue: "34",
478
+ red: "31",
479
+ yellow: "33",
480
+ gray: "90",
481
+ magenta: "35",
482
+ cyan: "36",
483
+ white: "37",
484
+ pink: "95"
485
+ };
486
+ this.config = this.scope.has(A_Config) ? this.scope.resolve(A_Config) : void 0;
487
+ }
488
+ get scopeLength() {
489
+ return this.scope.name.length;
490
+ }
491
+ compile(color, ...args) {
492
+ return [
493
+ `\x1B[${this.colors[color]}m[${this.scope.name}] |${this.getTime()}|`,
494
+ args.length > 1 ? `
495
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "",
496
+ ...args.map((arg, i) => {
497
+ switch (true) {
498
+ case arg instanceof A_Error:
499
+ return this.compile_A_Error(arg);
500
+ case arg instanceof Error:
501
+ return this.compile_Error(arg);
502
+ case typeof arg === "object":
503
+ return JSON.stringify(arg, null, 2).replace(/\n/g, `
504
+ ${" ".repeat(this.scopeLength + 3)}| `);
505
+ default:
506
+ return String(
507
+ (i > 0 || args.length > 1 ? "\n" : "") + arg
508
+ ).replace(/\n/g, `
509
+ ${" ".repeat(this.scopeLength + 3)}| `);
510
+ }
511
+ }),
512
+ args.length > 1 ? `
513
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------\x1B[0m` : "\x1B[0m"
514
+ ];
515
+ }
516
+ get allowedToLog() {
517
+ return this.config ? this.config.get("CONFIG_VERBOSE") !== void 0 && this.config.get("CONFIG_VERBOSE") !== "false" && this.config.get("CONFIG_VERBOSE") !== false : true;
518
+ }
519
+ log(param1, ...args) {
520
+ if (!this.allowedToLog)
521
+ return;
522
+ if (typeof param1 === "string" && this.colors[param1]) {
523
+ console.log(...this.compile(param1, ...args));
524
+ return;
525
+ } else {
526
+ console.log(...this.compile("blue", param1, ...args));
527
+ }
528
+ }
529
+ warning(...args) {
530
+ if (!this.allowedToLog)
531
+ return;
532
+ console.log(...this.compile("yellow", ...args));
533
+ }
534
+ error(...args) {
535
+ if (this.config && this.config.get("CONFIG_IGNORE_ERRORS"))
536
+ return;
537
+ return console.log(...this.compile("red", ...args));
538
+ }
539
+ log_A_Error(error) {
540
+ const time = this.getTime();
541
+ console.log(`\x1B[31m[${this.scope.name}] |${time}| ERROR ${error.code}
542
+ ${" ".repeat(this.scopeLength + 3)}| ${error.message}
543
+ ${" ".repeat(this.scopeLength + 3)}| ${error.description}
544
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
545
+ ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
546
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
547
+ \x1B[0m` + (error.originalError ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
548
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
549
+ ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
550
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
551
+ \x1B[0m` : "") + (error.link ? `\x1B[31m${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
552
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
553
+ \x1B[0m` : ""));
554
+ }
555
+ compile_A_Error(error) {
556
+ this.getTime();
557
+ return `
558
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
559
+ ${" ".repeat(this.scopeLength + 3)}| Error: | ${error.code}
560
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
561
+ ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.message}
562
+ ${" ".repeat(this.scopeLength + 3)}|${" ".repeat(10)}| ${error.description}
563
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
564
+ ${" ".repeat(this.scopeLength + 3)}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
565
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` + (error.originalError ? `${" ".repeat(this.scopeLength + 3)}| Wrapped From ${error.originalError.message}
566
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------
567
+ ${" ".repeat(this.scopeLength + 3)}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n") || "No stack trace"}
568
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "") + (error.link ? `${" ".repeat(this.scopeLength + 3)}| Read in docs: ${error.link}
569
+ ${" ".repeat(this.scopeLength + 3)}|-------------------------------` : "");
570
+ }
571
+ compile_Error(error) {
572
+ return JSON.stringify({
573
+ name: error.name,
574
+ message: error.message,
575
+ stack: error.stack?.split("\n").map((line, index) => index === 0 ? line : `${" ".repeat(this.scopeLength + 3)}| ${line}`).join("\n")
576
+ }, null, 2).replace(/\n/g, `
577
+ ${" ".repeat(this.scopeLength + 3)}| `).replace(/\\n/g, "\n");
578
+ }
579
+ getTime() {
580
+ const now = /* @__PURE__ */ new Date();
581
+ const minutes = String(now.getMinutes()).padStart(2, "0");
582
+ const seconds = String(now.getSeconds()).padStart(2, "0");
583
+ const milliseconds = String(now.getMilliseconds()).padStart(4, "0");
584
+ return `${minutes}:${seconds}:${milliseconds}`;
585
+ }
586
+ };
587
+ A_Logger = __decorateClass([
588
+ __decorateParam(0, A_Inject(A_Scope))
589
+ ], A_Logger);
590
+ var A_FSPolyfillClass = class {
591
+ constructor(logger) {
592
+ this.logger = logger;
593
+ this._initialized = false;
594
+ }
595
+ get isInitialized() {
596
+ return this._initialized;
597
+ }
598
+ async get() {
599
+ if (!this._initialized) {
600
+ await this.init();
601
+ }
602
+ return this._fs;
603
+ }
604
+ async init() {
605
+ try {
606
+ if (A_Context.environment === "server") {
607
+ await this.initServer();
608
+ } else {
609
+ this.initBrowser();
610
+ }
611
+ this._initialized = true;
612
+ } catch (error) {
613
+ this.initBrowser();
614
+ this._initialized = true;
615
+ }
616
+ }
617
+ async initServer() {
618
+ this._fs = await import('fs');
619
+ }
620
+ initBrowser() {
621
+ this._fs = {
622
+ readFileSync: (path, encoding) => {
623
+ this.logger.warning("fs.readFileSync not available in browser environment");
624
+ return "";
625
+ },
626
+ existsSync: (path) => {
627
+ this.logger.warning("fs.existsSync not available in browser environment");
628
+ return false;
629
+ },
630
+ createReadStream: (path) => {
631
+ this.logger.warning("fs.createReadStream not available in browser environment");
632
+ return null;
633
+ }
634
+ };
635
+ }
636
+ };
637
+ var A_CryptoPolyfillClass = class {
638
+ constructor(logger) {
639
+ this.logger = logger;
640
+ this._initialized = false;
641
+ }
642
+ get isInitialized() {
643
+ return this._initialized;
644
+ }
645
+ async get(fsPolyfill) {
646
+ if (!this._initialized) {
647
+ this._fsPolyfill = fsPolyfill;
648
+ await this.init();
649
+ }
650
+ return this._crypto;
651
+ }
652
+ async init() {
653
+ try {
654
+ if (A_Context.environment === "server") {
655
+ await this.initServer();
656
+ } else {
657
+ this.initBrowser();
658
+ }
659
+ this._initialized = true;
660
+ } catch (error) {
661
+ this.initBrowser();
662
+ this._initialized = true;
663
+ }
664
+ }
665
+ async initServer() {
666
+ const crypto2 = await import('crypto');
667
+ this._crypto = {
668
+ createTextHash: (text, algorithm = "sha384") => Promise.resolve(
669
+ `${algorithm}-${crypto2.createHash(algorithm).update(text).digest("base64")}`
670
+ ),
671
+ createFileHash: (filePath, algorithm = "sha384") => new Promise(async (resolve, reject) => {
672
+ try {
673
+ if (!this._fsPolyfill) {
674
+ throw new Error("FS polyfill is required for file hashing");
675
+ }
676
+ const hash = crypto2.createHash(algorithm);
677
+ const fileStream = this._fsPolyfill.createReadStream(filePath);
678
+ fileStream.on("data", (data) => hash.update(data));
679
+ fileStream.on("end", () => resolve(`${algorithm}-${hash.digest("base64")}`));
680
+ fileStream.on("error", (err) => reject(err));
681
+ } catch (error) {
682
+ reject(error);
683
+ }
684
+ })
685
+ };
686
+ }
687
+ initBrowser() {
688
+ this._crypto = {
689
+ createFileHash: () => {
690
+ this.logger.warning("File hash not available in browser environment");
691
+ return Promise.resolve("");
692
+ },
693
+ createTextHash: (text, algorithm = "SHA-384") => new Promise(async (resolve, reject) => {
694
+ try {
695
+ if (!crypto.subtle) {
696
+ throw new Error("SubtleCrypto not available");
697
+ }
698
+ const encoder = new TextEncoder();
699
+ const data = encoder.encode(text);
700
+ const hashBuffer = await crypto.subtle.digest(algorithm, data);
701
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
702
+ const hashBase64 = btoa(String.fromCharCode(...hashArray));
703
+ resolve(`${algorithm}-${hashBase64}`);
704
+ } catch (error) {
705
+ reject(error);
706
+ }
707
+ })
708
+ };
709
+ }
710
+ };
711
+ var A_HttpPolyfillClass = class {
712
+ constructor(logger) {
713
+ this.logger = logger;
714
+ this._initialized = false;
715
+ }
716
+ get isInitialized() {
717
+ return this._initialized;
718
+ }
719
+ async get() {
720
+ if (!this._initialized) {
721
+ await this.init();
722
+ }
723
+ return this._http;
724
+ }
725
+ async init() {
726
+ try {
727
+ if (A_Context.environment === "server") {
728
+ await this.initServer();
729
+ } else {
730
+ this.initBrowser();
731
+ }
732
+ this._initialized = true;
733
+ } catch (error) {
734
+ this.initBrowser();
735
+ this._initialized = true;
736
+ }
737
+ }
738
+ async initServer() {
739
+ const httpModule = await import('http');
740
+ this._http = {
741
+ request: httpModule.request,
742
+ get: httpModule.get,
743
+ createServer: httpModule.createServer
744
+ };
745
+ }
746
+ initBrowser() {
747
+ this._http = {
748
+ request: (options, callback) => {
749
+ this.logger.warning("http.request not available in browser/test environment, use fetch instead");
750
+ return this.createMockRequest(options, callback, false);
751
+ },
752
+ get: (url, callback) => {
753
+ this.logger.warning("http.get not available in browser/test environment, use fetch instead");
754
+ return this.createMockRequest(typeof url === "string" ? { hostname: url } : url, callback, false);
755
+ },
756
+ createServer: () => {
757
+ this.logger.error("http.createServer not available in browser/test environment");
758
+ return null;
759
+ }
760
+ };
761
+ }
762
+ createMockRequest(options, callback, isHttps = false) {
763
+ const request = {
764
+ end: () => {
765
+ if (callback) {
766
+ const mockResponse = {
767
+ statusCode: 200,
768
+ headers: {},
769
+ on: (event, handler) => {
770
+ if (event === "data") {
771
+ setTimeout(() => handler("mock data"), 0);
772
+ } else if (event === "end") {
773
+ setTimeout(() => handler(), 0);
774
+ }
775
+ },
776
+ pipe: (dest) => {
777
+ if (dest.write) dest.write("mock data");
778
+ if (dest.end) dest.end();
779
+ }
780
+ };
781
+ setTimeout(() => callback(mockResponse), 0);
782
+ }
783
+ },
784
+ write: (data) => {
785
+ },
786
+ on: (event, handler) => {
787
+ }
788
+ };
789
+ return request;
790
+ }
791
+ };
792
+ var A_HttpsPolyfillClass = class {
793
+ constructor(logger) {
794
+ this.logger = logger;
795
+ this._initialized = false;
796
+ }
797
+ get isInitialized() {
798
+ return this._initialized;
799
+ }
800
+ async get() {
801
+ if (!this._initialized) {
802
+ await this.init();
803
+ }
804
+ return this._https;
805
+ }
806
+ async init() {
807
+ try {
808
+ if (A_Context.environment === "server") {
809
+ await this.initServer();
810
+ } else {
811
+ this.initBrowser();
812
+ }
813
+ this._initialized = true;
814
+ } catch (error) {
815
+ this.initBrowser();
816
+ this._initialized = true;
817
+ }
818
+ }
819
+ async initServer() {
820
+ const httpsModule = await import('https');
821
+ this._https = {
822
+ request: httpsModule.request,
823
+ get: httpsModule.get,
824
+ createServer: httpsModule.createServer
825
+ };
826
+ }
827
+ initBrowser() {
828
+ this._https = {
829
+ request: (options, callback) => {
830
+ this.logger.warning("https.request not available in browser/test environment, use fetch instead");
831
+ return this.createMockRequest(options, callback, true);
832
+ },
833
+ get: (url, callback) => {
834
+ this.logger.warning("https.get not available in browser/test environment, use fetch instead");
835
+ return this.createMockRequest(typeof url === "string" ? { hostname: url } : url, callback, true);
836
+ },
837
+ createServer: () => {
838
+ this.logger.error("https.createServer not available in browser/test environment");
839
+ return null;
840
+ }
841
+ };
842
+ }
843
+ createMockRequest(options, callback, isHttps = true) {
844
+ const request = {
845
+ end: () => {
846
+ if (callback) {
847
+ const mockResponse = {
848
+ statusCode: 200,
849
+ headers: {},
850
+ on: (event, handler) => {
851
+ if (event === "data") {
852
+ setTimeout(() => handler("mock data"), 0);
853
+ } else if (event === "end") {
854
+ setTimeout(() => handler(), 0);
855
+ }
856
+ },
857
+ pipe: (dest) => {
858
+ if (dest.write) dest.write("mock data");
859
+ if (dest.end) dest.end();
860
+ }
861
+ };
862
+ setTimeout(() => callback(mockResponse), 0);
863
+ }
864
+ },
865
+ write: (data) => {
866
+ },
867
+ on: (event, handler) => {
868
+ }
869
+ };
870
+ return request;
871
+ }
872
+ };
873
+ var A_PathPolyfillClass = class {
874
+ constructor(logger) {
875
+ this.logger = logger;
876
+ this._initialized = false;
877
+ }
878
+ get isInitialized() {
879
+ return this._initialized;
880
+ }
881
+ async get() {
882
+ if (!this._initialized) {
883
+ await this.init();
884
+ }
885
+ return this._path;
886
+ }
887
+ async init() {
888
+ try {
889
+ if (A_Context.environment === "server") {
890
+ await this.initServer();
891
+ } else {
892
+ this.initBrowser();
893
+ }
894
+ this._initialized = true;
895
+ } catch (error) {
896
+ this.initBrowser();
897
+ this._initialized = true;
898
+ }
899
+ }
900
+ async initServer() {
901
+ this._path = await import('path');
902
+ }
903
+ initBrowser() {
904
+ this._path = {
905
+ join: (...paths) => {
906
+ return paths.join("/").replace(/\/+/g, "/");
907
+ },
908
+ resolve: (...paths) => {
909
+ let resolvedPath = "";
910
+ for (const path of paths) {
911
+ if (path.startsWith("/")) {
912
+ resolvedPath = path;
913
+ } else {
914
+ resolvedPath = this._path.join(resolvedPath, path);
915
+ }
916
+ }
917
+ return resolvedPath || "/";
918
+ },
919
+ dirname: (path) => {
920
+ const parts = path.split("/");
921
+ return parts.slice(0, -1).join("/") || "/";
922
+ },
923
+ basename: (path, ext) => {
924
+ const base = path.split("/").pop() || "";
925
+ return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base;
926
+ },
927
+ extname: (path) => {
928
+ const parts = path.split(".");
929
+ return parts.length > 1 ? "." + parts.pop() : "";
930
+ },
931
+ relative: (from, to) => {
932
+ return to.replace(from, "").replace(/^\//, "");
933
+ },
934
+ normalize: (path) => {
935
+ return path.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
936
+ },
937
+ isAbsolute: (path) => {
938
+ return path.startsWith("/") || /^[a-zA-Z]:/.test(path);
939
+ },
940
+ parse: (path) => {
941
+ const ext = this._path.extname(path);
942
+ const base = this._path.basename(path);
943
+ const name = this._path.basename(path, ext);
944
+ const dir = this._path.dirname(path);
945
+ return { root: "/", dir, base, ext, name };
946
+ },
947
+ format: (pathObject) => {
948
+ return this._path.join(pathObject.dir || "", pathObject.base || "");
949
+ },
950
+ sep: "/",
951
+ delimiter: ":"
952
+ };
953
+ }
954
+ };
955
+ var A_UrlPolyfillClass = class {
956
+ constructor(logger) {
957
+ this.logger = logger;
958
+ this._initialized = false;
959
+ }
960
+ get isInitialized() {
961
+ return this._initialized;
962
+ }
963
+ async get() {
964
+ if (!this._initialized) {
965
+ await this.init();
966
+ }
967
+ return this._url;
968
+ }
969
+ async init() {
970
+ try {
971
+ if (A_Context.environment === "server") {
972
+ await this.initServer();
973
+ } else {
974
+ this.initBrowser();
975
+ }
976
+ this._initialized = true;
977
+ } catch (error) {
978
+ this.initBrowser();
979
+ this._initialized = true;
980
+ }
981
+ }
982
+ async initServer() {
983
+ const urlModule = await import('url');
984
+ this._url = {
985
+ parse: urlModule.parse,
986
+ format: urlModule.format,
987
+ resolve: urlModule.resolve,
988
+ URL: urlModule.URL || globalThis.URL,
989
+ URLSearchParams: urlModule.URLSearchParams || globalThis.URLSearchParams
990
+ };
991
+ }
992
+ initBrowser() {
993
+ this._url = {
994
+ parse: (urlString) => {
995
+ try {
996
+ const url = new URL(urlString);
997
+ return {
998
+ protocol: url.protocol,
999
+ hostname: url.hostname,
1000
+ port: url.port,
1001
+ pathname: url.pathname,
1002
+ search: url.search,
1003
+ hash: url.hash,
1004
+ host: url.host,
1005
+ href: url.href
1006
+ };
1007
+ } catch {
1008
+ return {};
1009
+ }
1010
+ },
1011
+ format: (urlObject) => {
1012
+ try {
1013
+ return new URL("", urlObject.href || `${urlObject.protocol}//${urlObject.host}${urlObject.pathname}${urlObject.search}${urlObject.hash}`).href;
1014
+ } catch {
1015
+ return "";
1016
+ }
1017
+ },
1018
+ resolve: (from, to) => {
1019
+ try {
1020
+ return new URL(to, from).href;
1021
+ } catch {
1022
+ return to;
1023
+ }
1024
+ },
1025
+ URL: globalThis.URL,
1026
+ URLSearchParams: globalThis.URLSearchParams
1027
+ };
1028
+ }
1029
+ };
1030
+ var A_BufferPolyfillClass = class {
1031
+ constructor(logger) {
1032
+ this.logger = logger;
1033
+ this._initialized = false;
1034
+ }
1035
+ get isInitialized() {
1036
+ return this._initialized;
1037
+ }
1038
+ async get() {
1039
+ if (!this._initialized) {
1040
+ await this.init();
1041
+ }
1042
+ return this._buffer;
1043
+ }
1044
+ async init() {
1045
+ try {
1046
+ if (A_Context.environment === "server") {
1047
+ await this.initServer();
1048
+ } else {
1049
+ this.initBrowser();
1050
+ }
1051
+ this._initialized = true;
1052
+ } catch (error) {
1053
+ this.initBrowser();
1054
+ this._initialized = true;
1055
+ }
1056
+ }
1057
+ async initServer() {
1058
+ const bufferModule = await import('buffer');
1059
+ this._buffer = {
1060
+ from: bufferModule.Buffer.from,
1061
+ alloc: bufferModule.Buffer.alloc,
1062
+ allocUnsafe: bufferModule.Buffer.allocUnsafe,
1063
+ isBuffer: bufferModule.Buffer.isBuffer,
1064
+ concat: bufferModule.Buffer.concat
1065
+ };
1066
+ }
1067
+ initBrowser() {
1068
+ this._buffer = {
1069
+ from: (data, encoding) => {
1070
+ if (typeof data === "string") {
1071
+ return new TextEncoder().encode(data);
1072
+ }
1073
+ return new Uint8Array(data);
1074
+ },
1075
+ alloc: (size, fill) => {
1076
+ const buffer = new Uint8Array(size);
1077
+ if (fill !== void 0) {
1078
+ buffer.fill(fill);
1079
+ }
1080
+ return buffer;
1081
+ },
1082
+ allocUnsafe: (size) => {
1083
+ return new Uint8Array(size);
1084
+ },
1085
+ isBuffer: (obj) => {
1086
+ return obj instanceof Uint8Array || obj instanceof ArrayBuffer;
1087
+ },
1088
+ concat: (list, totalLength) => {
1089
+ const length = totalLength || list.reduce((sum, buf) => sum + buf.length, 0);
1090
+ const result = new Uint8Array(length);
1091
+ let offset = 0;
1092
+ for (const buf of list) {
1093
+ result.set(buf, offset);
1094
+ offset += buf.length;
1095
+ }
1096
+ return result;
1097
+ }
1098
+ };
1099
+ }
1100
+ };
1101
+ var A_ProcessPolyfillClass = class {
1102
+ constructor(logger) {
1103
+ this.logger = logger;
1104
+ this._initialized = false;
1105
+ }
1106
+ get isInitialized() {
1107
+ return this._initialized;
1108
+ }
1109
+ async get() {
1110
+ if (!this._initialized) {
1111
+ await this.init();
1112
+ }
1113
+ return this._process;
1114
+ }
1115
+ async init() {
1116
+ try {
1117
+ if (A_Context.environment === "server") {
1118
+ this.initServer();
1119
+ } else {
1120
+ this.initBrowser();
1121
+ }
1122
+ this._initialized = true;
1123
+ } catch (error) {
1124
+ this.initBrowser();
1125
+ this._initialized = true;
1126
+ }
1127
+ }
1128
+ initServer() {
1129
+ this._process = {
1130
+ env: process.env,
1131
+ argv: process.argv,
1132
+ platform: process.platform,
1133
+ version: process.version,
1134
+ versions: process.versions,
1135
+ cwd: process.cwd,
1136
+ exit: process.exit,
1137
+ nextTick: process.nextTick
1138
+ };
1139
+ }
1140
+ initBrowser() {
1141
+ this._process = {
1142
+ env: {
1143
+ NODE_ENV: "browser",
1144
+ ...globalThis.process?.env || {}
1145
+ },
1146
+ argv: ["browser"],
1147
+ platform: "browser",
1148
+ version: "browser",
1149
+ versions: { node: "browser" },
1150
+ cwd: () => "/",
1151
+ exit: (code) => {
1152
+ this.logger.warning("process.exit not available in browser");
1153
+ throw new Error(`Process exit with code ${code}`);
1154
+ },
1155
+ nextTick: (callback, ...args) => {
1156
+ setTimeout(() => callback(...args), 0);
1157
+ }
1158
+ };
1159
+ }
1160
+ };
1161
+
1162
+ // src/lib/A-Polyfill/A-Polyfill.component.ts
1163
+ var A_Polyfill = class extends A_Component {
1164
+ constructor(logger) {
1165
+ super();
1166
+ this.logger = logger;
1167
+ this._initializing = null;
1168
+ }
1169
+ /**
1170
+ * Indicates whether the channel is connected
1171
+ */
1172
+ get ready() {
1173
+ if (!this._initialized) {
1174
+ this._initialized = this._loadInternal();
1175
+ }
1176
+ return this._initialized;
1177
+ }
1178
+ async load() {
1179
+ await this.ready;
1180
+ }
1181
+ async attachToWindow() {
1182
+ if (A_Context.environment !== "browser") return;
1183
+ globalThis.A_Polyfill = this;
1184
+ globalThis.process = { env: { NODE_ENV: "production" }, cwd: () => "/" };
1185
+ globalThis.__dirname = "/";
1186
+ }
1187
+ async _loadInternal() {
1188
+ this._fsPolyfill = new A_FSPolyfillClass(this.logger);
1189
+ this._cryptoPolyfill = new A_CryptoPolyfillClass(this.logger);
1190
+ this._httpPolyfill = new A_HttpPolyfillClass(this.logger);
1191
+ this._httpsPolyfill = new A_HttpsPolyfillClass(this.logger);
1192
+ this._pathPolyfill = new A_PathPolyfillClass(this.logger);
1193
+ this._urlPolyfill = new A_UrlPolyfillClass(this.logger);
1194
+ this._bufferPolyfill = new A_BufferPolyfillClass(this.logger);
1195
+ this._processPolyfill = new A_ProcessPolyfillClass(this.logger);
1196
+ await this._fsPolyfill.get();
1197
+ await this._cryptoPolyfill.get(await this._fsPolyfill.get());
1198
+ await this._httpPolyfill.get();
1199
+ await this._httpsPolyfill.get();
1200
+ await this._pathPolyfill.get();
1201
+ await this._urlPolyfill.get();
1202
+ await this._bufferPolyfill.get();
1203
+ await this._processPolyfill.get();
1204
+ }
1205
+ /**
1206
+ * Allows to use the 'fs' polyfill methods regardless of the environment
1207
+ * This method loads the 'fs' polyfill and returns its instance
1208
+ *
1209
+ * @returns
1210
+ */
1211
+ async fs() {
1212
+ await this.ready;
1213
+ return await this._fsPolyfill.get();
1214
+ }
1215
+ /**
1216
+ * Allows to use the 'crypto' polyfill methods regardless of the environment
1217
+ * This method loads the 'crypto' polyfill and returns its instance
1218
+ *
1219
+ * @returns
1220
+ */
1221
+ async crypto() {
1222
+ await this.ready;
1223
+ return await this._cryptoPolyfill.get();
1224
+ }
1225
+ /**
1226
+ * Allows to use the 'http' polyfill methods regardless of the environment
1227
+ * This method loads the 'http' polyfill and returns its instance
1228
+ *
1229
+ * @returns
1230
+ */
1231
+ async http() {
1232
+ await this.ready;
1233
+ return await this._httpPolyfill.get();
1234
+ }
1235
+ /**
1236
+ * Allows to use the 'https' polyfill methods regardless of the environment
1237
+ * This method loads the 'https' polyfill and returns its instance
1238
+ *
1239
+ * @returns
1240
+ */
1241
+ async https() {
1242
+ await this.ready;
1243
+ return await this._httpsPolyfill.get();
1244
+ }
1245
+ /**
1246
+ * Allows to use the 'path' polyfill methods regardless of the environment
1247
+ * This method loads the 'path' polyfill and returns its instance
1248
+ *
1249
+ * @returns
1250
+ */
1251
+ async path() {
1252
+ await this.ready;
1253
+ return await this._pathPolyfill.get();
1254
+ }
1255
+ /**
1256
+ * Allows to use the 'url' polyfill methods regardless of the environment
1257
+ * This method loads the 'url' polyfill and returns its instance
1258
+ *
1259
+ * @returns
1260
+ */
1261
+ async url() {
1262
+ await this.ready;
1263
+ return await this._urlPolyfill.get();
1264
+ }
1265
+ /**
1266
+ * Allows to use the 'buffer' polyfill methods regardless of the environment
1267
+ * This method loads the 'buffer' polyfill and returns its instance
1268
+ *
1269
+ * @returns
1270
+ */
1271
+ async buffer() {
1272
+ await this.ready;
1273
+ return await this._bufferPolyfill.get();
1274
+ }
1275
+ /**
1276
+ * Allows to use the 'process' polyfill methods regardless of the environment
1277
+ * This method loads the 'process' polyfill and returns its instance
1278
+ *
1279
+ * @returns
1280
+ */
1281
+ async process() {
1282
+ await this.ready;
1283
+ return await this._processPolyfill.get();
1284
+ }
1285
+ };
1286
+ __decorateClass([
1287
+ A_Concept.Load()
1288
+ ], A_Polyfill.prototype, "load", 1);
1289
+ __decorateClass([
1290
+ A_Concept.Load()
1291
+ ], A_Polyfill.prototype, "attachToWindow", 1);
1292
+ A_Polyfill = __decorateClass([
1293
+ __decorateParam(0, A_Inject(A_Logger))
1294
+ ], A_Polyfill);
1295
+ var A_ConfigError = class extends A_Error {
1296
+ };
1297
+ A_ConfigError.InitializationError = "A-Config Initialization Error";
1298
+ var ConfigReader = class extends A_Component {
1299
+ constructor(polyfill) {
1300
+ super();
1301
+ this.polyfill = polyfill;
1302
+ }
1303
+ async attachContext(container, feature) {
1304
+ if (!container.scope.has(A_Config)) {
1305
+ const newConfig = new A_Config({
1306
+ variables: [
1307
+ ...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
1308
+ ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
1309
+ ],
1310
+ defaults: {}
1311
+ });
1312
+ container.scope.register(newConfig);
1313
+ }
1314
+ const config = container.scope.resolve(A_Config);
1315
+ const rootDir = await this.getProjectRoot();
1316
+ config.set("A_CONCEPT_ROOT_FOLDER", rootDir);
1317
+ }
1318
+ async initialize(config) {
1319
+ const data = await this.read([
1320
+ ...config.CONFIG_PROPERTIES,
1321
+ ...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
1322
+ ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
1323
+ ]);
1324
+ config.set(data);
1325
+ }
1326
+ /**
1327
+ * Get the configuration property by Name
1328
+ * @param property
1329
+ */
1330
+ resolve(property) {
1331
+ return property;
1332
+ }
1333
+ /**
1334
+ * This method reads the configuration and sets the values to the context
1335
+ *
1336
+ * @returns
1337
+ */
1338
+ async read(variables = []) {
1339
+ return {};
1340
+ }
1341
+ /**
1342
+ * Finds the root directory of the project by locating the folder containing package.json
1343
+ *
1344
+ * @param {string} startPath - The initial directory to start searching from (default is __dirname)
1345
+ * @returns {string|null} - The path to the root directory or null if package.json is not found
1346
+ */
1347
+ async getProjectRoot(startPath = __dirname) {
1348
+ return process.cwd();
1349
+ }
1350
+ };
1351
+ __decorateClass([
1352
+ A_Concept.Load(),
1353
+ __decorateParam(0, A_Inject(A_Container)),
1354
+ __decorateParam(1, A_Inject(A_Feature))
1355
+ ], ConfigReader.prototype, "attachContext", 1);
1356
+ __decorateClass([
1357
+ A_Concept.Load(),
1358
+ __decorateParam(0, A_Inject(A_Config))
1359
+ ], ConfigReader.prototype, "initialize", 1);
1360
+ ConfigReader = __decorateClass([
1361
+ __decorateParam(0, A_Inject(A_Polyfill))
1362
+ ], ConfigReader);
1363
+
1364
+ // src/lib/A-Config/components/FileConfigReader.component.ts
1365
+ var FileConfigReader = class extends ConfigReader {
1366
+ constructor() {
1367
+ super(...arguments);
1368
+ this.FileData = /* @__PURE__ */ new Map();
1369
+ }
1370
+ /**
1371
+ * Get the configuration property Name
1372
+ * @param property
1373
+ */
1374
+ getConfigurationProperty_File_Alias(property) {
1375
+ return A_FormatterHelper.toCamelCase(property);
1376
+ }
1377
+ resolve(property) {
1378
+ return this.FileData.get(this.getConfigurationProperty_File_Alias(property));
1379
+ }
1380
+ async read(variables) {
1381
+ const fs = await this.polyfill.fs();
1382
+ try {
1383
+ const data = fs.readFileSync(`${A_Context.concept}.conf.json`, "utf8");
1384
+ const config = JSON.parse(data);
1385
+ this.FileData = new Map(Object.entries(config));
1386
+ return config;
1387
+ } catch (error) {
1388
+ return {};
1389
+ }
1390
+ }
1391
+ };
1392
+ var ENVConfigReader = class extends ConfigReader {
1393
+ async readEnvFile(config, polyfill, feature) {
1394
+ const fs = await polyfill.fs();
1395
+ if (fs.existsSync(".env"))
1396
+ fs.readFileSync(`${config.get("A_CONCEPT_ROOT_FOLDER")}/.env`, "utf-8").split("\n").forEach((line) => {
1397
+ const [key, value] = line.split("=");
1398
+ if (key && value) {
1399
+ process.env[key.trim()] = value.trim();
1400
+ }
1401
+ });
1402
+ }
1403
+ /**
1404
+ * Get the configuration property Name
1405
+ * @param property
1406
+ */
1407
+ getConfigurationProperty_ENV_Alias(property) {
1408
+ return A_FormatterHelper.toUpperSnakeCase(property);
1409
+ }
1410
+ resolve(property) {
1411
+ return process.env[this.getConfigurationProperty_ENV_Alias(property)];
1412
+ }
1413
+ async read(variables = []) {
1414
+ const allVariables = [
1415
+ ...variables,
1416
+ ...Object.keys(process.env)
1417
+ ];
1418
+ const config = {};
1419
+ allVariables.forEach((variable) => {
1420
+ config[variable] = this.resolve(variable);
1421
+ });
1422
+ return config;
1423
+ }
1424
+ };
1425
+ __decorateClass([
1426
+ A_Concept.Load({
1427
+ before: ["ENVConfigReader.initialize"]
1428
+ }),
1429
+ __decorateParam(0, A_Inject(A_Config)),
1430
+ __decorateParam(1, A_Inject(A_Polyfill)),
1431
+ __decorateParam(2, A_Inject(A_Feature))
1432
+ ], ENVConfigReader.prototype, "readEnvFile", 1);
1433
+
1434
+ // src/lib/A-Config/A-Config.container.ts
1435
+ var A_ConfigLoader = class extends A_Container {
1436
+ async prepare(polyfill) {
1437
+ if (!this.scope.has(A_Config)) {
1438
+ const newConfig = new A_Config({
1439
+ variables: [
1440
+ ...A_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY,
1441
+ ...A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY
1442
+ ],
1443
+ defaults: {}
1444
+ });
1445
+ this.scope.register(newConfig);
1446
+ }
1447
+ const fs = await polyfill.fs();
1448
+ try {
1449
+ switch (true) {
1450
+ case (A_Context.environment === "server" && !!fs.existsSync(`${A_Context.concept}.conf.json`)):
1451
+ this.reader = this.scope.resolve(FileConfigReader);
1452
+ break;
1453
+ case (A_Context.environment === "server" && !fs.existsSync(`${A_Context.concept}.conf.json`)):
1454
+ this.reader = this.scope.resolve(ENVConfigReader);
1455
+ break;
1456
+ case A_Context.environment === "browser":
1457
+ this.reader = this.scope.resolve(ENVConfigReader);
1458
+ break;
1459
+ default:
1460
+ throw new A_ConfigError(
1461
+ A_ConfigError.InitializationError,
1462
+ `Environment ${A_Context.environment} is not supported`
1463
+ );
1464
+ }
1465
+ } catch (error) {
1466
+ if (error instanceof A_ScopeError) {
1467
+ throw new A_ConfigError({
1468
+ title: A_ConfigError.InitializationError,
1469
+ description: `Failed to initialize A_ConfigLoader. Reader not found for environment ${A_Context.environment}`,
1470
+ originalError: error
1471
+ });
1472
+ }
1473
+ }
1474
+ }
1475
+ };
1476
+ __decorateClass([
1477
+ A_Concept.Load({
1478
+ before: /.*/
1479
+ }),
1480
+ __decorateParam(0, A_Inject(A_Polyfill))
1481
+ ], A_ConfigLoader.prototype, "prepare", 1);
1482
+
1483
+ // src/lib/A-Config/A-Config.types.ts
1484
+ var A_TYPES__ConfigFeature = /* @__PURE__ */ ((A_TYPES__ConfigFeature2) => {
1485
+ return A_TYPES__ConfigFeature2;
1486
+ })(A_TYPES__ConfigFeature || {});
1487
+ var A_ManifestError = class extends A_Error {
1488
+ };
1489
+ A_ManifestError.ManifestInitializationError = "A-Manifest Initialization Error";
1490
+
1491
+ // src/lib/A-Manifest/classes/A-ManifestChecker.class.ts
1492
+ var A_ManifestChecker = class {
1493
+ constructor(manifest, component, method, checkExclusion = false) {
1494
+ this.manifest = manifest;
1495
+ this.component = component;
1496
+ this.method = method;
1497
+ this.checkExclusion = checkExclusion;
1498
+ }
1499
+ for(target) {
1500
+ const result = this.manifest.internal_checkAccess({
1501
+ component: this.component,
1502
+ method: this.method,
1503
+ target
1504
+ });
1505
+ return this.checkExclusion ? !result : result;
1506
+ }
1507
+ };
1508
+
1509
+ // src/lib/A-Manifest/A-Manifest.context.ts
1510
+ var A_Manifest = class extends A_Fragment {
1511
+ /**
1512
+ * A-Manifest is a configuration set that allows to include or exclude component application for the particular methods.
1513
+ *
1514
+ * For example, if A-Scope provides polymorphic A-Component that applies for All A-Entities in it but you have another component that should be used for only One particular Entity, you can use A-Manifest to specify this behavior.
1515
+ *
1516
+ *
1517
+ * By default if Component is provided in the scope - it applies for all entities in it. However, if you want to exclude some entities or include only some entities for the particular component - you can use A-Manifest to define this behavior.
1518
+ *
1519
+ * @param config - Array of component configurations
1520
+ */
1521
+ constructor(config = []) {
1522
+ super({
1523
+ name: "A-Manifest"
1524
+ });
1525
+ this.rules = [];
1526
+ this.prepare(config);
1527
+ }
1528
+ /**
1529
+ * Should convert received configuration into internal Regexp applicable for internal storage
1530
+ */
1531
+ prepare(config) {
1532
+ if (!A_TypeGuards.isArray(config))
1533
+ throw new A_ManifestError(
1534
+ A_ManifestError.ManifestInitializationError,
1535
+ `A-Manifest configuration should be an array of configurations`
1536
+ );
1537
+ for (const item of config) {
1538
+ this.processConfigItem(item);
1539
+ }
1540
+ }
1541
+ /**
1542
+ * Process a single configuration item and convert it to internal rules
1543
+ */
1544
+ processConfigItem(item) {
1545
+ if (!A_TypeGuards.isComponentConstructor(item.component))
1546
+ throw new A_ManifestError(
1547
+ A_ManifestError.ManifestInitializationError,
1548
+ `A-Manifest configuration item should be a A-Component constructor`
1549
+ );
1550
+ const componentRegex = this.constructorToRegex(item.component);
1551
+ if (item.apply || item.exclude) {
1552
+ const methodRegex = /.*/;
1553
+ this.rules.push({
1554
+ componentRegex,
1555
+ methodRegex,
1556
+ applyRegex: item.apply ? this.allowedComponentsToRegex(item.apply) : void 0,
1557
+ excludeRegex: item.exclude ? this.allowedComponentsToRegex(item.exclude) : void 0
1558
+ });
1559
+ }
1560
+ if (item.methods && item.methods.length > 0) {
1561
+ for (const methodConfig of item.methods) {
1562
+ const methodRegex = this.methodToRegex(methodConfig.method);
1563
+ this.rules.push({
1564
+ componentRegex,
1565
+ methodRegex,
1566
+ applyRegex: methodConfig.apply ? this.allowedComponentsToRegex(methodConfig.apply) : void 0,
1567
+ excludeRegex: methodConfig.exclude ? this.allowedComponentsToRegex(methodConfig.exclude) : void 0
1568
+ });
1569
+ }
1570
+ }
1571
+ }
1572
+ /**
1573
+ * Convert a constructor to a regex pattern
1574
+ */
1575
+ constructorToRegex(ctor) {
1576
+ return new RegExp(`^${this.escapeRegex(ctor.name)}$`);
1577
+ }
1578
+ /**
1579
+ * Convert a method name or regex to a regex pattern
1580
+ */
1581
+ methodToRegex(method) {
1582
+ if (method instanceof RegExp) {
1583
+ return method;
1584
+ }
1585
+ return new RegExp(`^${this.escapeRegex(method)}$`);
1586
+ }
1587
+ /**
1588
+ * Convert allowed components array or regex to a single regex
1589
+ */
1590
+ allowedComponentsToRegex(components) {
1591
+ if (components instanceof RegExp) {
1592
+ return components;
1593
+ }
1594
+ const patterns = components.map((ctor) => this.escapeRegex(ctor.name));
1595
+ return new RegExp(`^(${patterns.join("|")})$`);
1596
+ }
1597
+ /**
1598
+ * Escape special regex characters in a string
1599
+ */
1600
+ escapeRegex(str) {
1601
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1602
+ }
1603
+ configItemToRegexp(item) {
1604
+ return this.constructorToRegex(item);
1605
+ }
1606
+ ID(component, method) {
1607
+ return `${component.name}.${method}`;
1608
+ }
1609
+ /**
1610
+ * Check if a component and method combination is allowed for a target
1611
+ */
1612
+ isAllowed(ctor, method) {
1613
+ const componentCtor = typeof ctor === "function" ? ctor : ctor.constructor;
1614
+ return new A_ManifestChecker(this, componentCtor, method);
1615
+ }
1616
+ /**
1617
+ * Internal method to check if access is allowed
1618
+ */
1619
+ internal_checkAccess(query) {
1620
+ const componentName = query.component.name;
1621
+ const methodName = query.method;
1622
+ const targetName = query.target.name;
1623
+ const matchingRules = this.rules.filter(
1624
+ (rule) => rule.componentRegex.test(componentName) && rule.methodRegex.test(methodName)
1625
+ ).sort((a, b) => {
1626
+ const aIsGeneral = a.methodRegex.source === ".*";
1627
+ const bIsGeneral = b.methodRegex.source === ".*";
1628
+ if (aIsGeneral && !bIsGeneral) return 1;
1629
+ if (!aIsGeneral && bIsGeneral) return -1;
1630
+ return 0;
1631
+ });
1632
+ if (matchingRules.length === 0) {
1633
+ return true;
1634
+ }
1635
+ for (const rule of matchingRules) {
1636
+ if (rule.excludeRegex && rule.excludeRegex.test(targetName)) {
1637
+ return false;
1638
+ }
1639
+ if (rule.applyRegex) {
1640
+ return rule.applyRegex.test(targetName);
1641
+ }
1642
+ }
1643
+ return true;
1644
+ }
1645
+ isExcluded(ctor, method) {
1646
+ const componentCtor = typeof ctor === "function" ? ctor : ctor.constructor;
1647
+ return new A_ManifestChecker(this, componentCtor, method, true);
1648
+ }
1649
+ };
1650
+
1651
+ // src/lib/A-Schedule/A-Deferred.class.ts
1652
+ var A_Deferred = class {
1653
+ /**
1654
+ * Creates a deferred promise
1655
+ * @returns A promise that can be resolved or rejected later
1656
+ */
1657
+ constructor() {
1658
+ this.promise = new Promise((resolve, reject) => {
1659
+ this.resolveFn = resolve;
1660
+ this.rejectFn = reject;
1661
+ });
1662
+ }
1663
+ resolve(value) {
1664
+ this.resolveFn(value);
1665
+ }
1666
+ reject(reason) {
1667
+ this.rejectFn(reason);
1668
+ }
1669
+ };
1670
+ var A_ScheduleObject = class {
1671
+ /**
1672
+ * Creates a scheduled object that will execute the action after specified milliseconds
1673
+ *
1674
+ *
1675
+ * @param ms - milliseconds to wait before executing the action
1676
+ * @param action - the action to execute
1677
+ * @param config - configuration options for the schedule object
1678
+ */
1679
+ constructor(ms, action, config) {
1680
+ this.config = {
1681
+ /**
1682
+ * If the timeout is cleared, should the promise resolve or reject?
1683
+ * BY Default it rejects
1684
+ *
1685
+ * !!!NOTE: If the property is set to true, the promise will resolve with undefined
1686
+ */
1687
+ resolveOnClear: false
1688
+ };
1689
+ if (config)
1690
+ this.config = { ...this.config, ...config };
1691
+ this.deferred = new A_Deferred();
1692
+ this.timeout = setTimeout(
1693
+ () => action().then((...args) => this.deferred.resolve(...args)).catch((...args) => this.deferred.reject(...args)),
1694
+ ms
1695
+ );
1696
+ }
1697
+ get promise() {
1698
+ return this.deferred.promise;
1699
+ }
1700
+ clear() {
1701
+ if (this.timeout) {
1702
+ clearTimeout(this.timeout);
1703
+ if (this.config.resolveOnClear)
1704
+ this.deferred.resolve(void 0);
1705
+ else
1706
+ this.deferred.reject(new A_Error("Timeout Cleared"));
1707
+ }
1708
+ }
1709
+ };
1710
+
1711
+ // src/lib/A-Schedule/A-Schedule.component.ts
1712
+ var A_Schedule = class extends A_Component {
1713
+ async schedule(date, callback, config) {
1714
+ const timestamp = A_TypeGuards.isString(date) ? new Date(date).getTime() : date;
1715
+ return new A_ScheduleObject(
1716
+ timestamp - Date.now(),
1717
+ callback,
1718
+ config
1719
+ );
1720
+ }
1721
+ /**
1722
+ * Allows to execute callback after particular delay in milliseconds
1723
+ * So the callback will be executed after the specified delay
1724
+ *
1725
+ * @param ms
1726
+ */
1727
+ async delay(ms, callback, config) {
1728
+ return new A_ScheduleObject(
1729
+ ms,
1730
+ callback,
1731
+ config
1732
+ );
1733
+ }
1734
+ };
1735
+
1736
+ export { A_CONSTANTS_A_Command_Features, A_CONSTANTS__A_Command_Status, A_CONSTANTS__CONFIG_ENV_VARIABLES, A_CONSTANTS__CONFIG_ENV_VARIABLES_ARRAY, A_Channel, A_ChannelError, A_Command, A_CommandError, A_Config, A_ConfigError, A_ConfigLoader, A_Deferred, A_Logger, A_Manifest, A_ManifestChecker, A_ManifestError, A_Memory, A_Polyfill, A_Schedule, A_ScheduleObject, A_TYPES__CommandMetaKey, A_TYPES__ConfigFeature, ConfigReader, ENVConfigReader, FileConfigReader };
1737
+ //# sourceMappingURL=index.mjs.map
1738
+ //# sourceMappingURL=index.mjs.map