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