@adaas/a-utils 0.1.10 → 0.1.12

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