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