xypriss 4.0.0 → 4.1.0

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 (54) hide show
  1. package/dist/cjs/src/config.js +57 -31
  2. package/dist/cjs/src/config.js.map +1 -1
  3. package/dist/cjs/src/file-upload.js +5 -4
  4. package/dist/cjs/src/file-upload.js.map +1 -1
  5. package/dist/cjs/src/index.js +1 -1
  6. package/dist/cjs/src/plugins/api/PluginAPI.js +135 -0
  7. package/dist/cjs/src/plugins/api/PluginAPI.js.map +1 -0
  8. package/dist/cjs/src/plugins/core/PluginManager.js +266 -0
  9. package/dist/cjs/src/plugins/core/PluginManager.js.map +1 -0
  10. package/dist/cjs/src/server/FastServer.js +28 -15
  11. package/dist/cjs/src/server/FastServer.js.map +1 -1
  12. package/dist/cjs/src/server/ServerFactory.js +29 -24
  13. package/dist/cjs/src/server/ServerFactory.js.map +1 -1
  14. package/dist/cjs/src/server/components/fastapi/FileUploadManager.js +3 -2
  15. package/dist/cjs/src/server/components/fastapi/FileUploadManager.js.map +1 -1
  16. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js +74 -22
  17. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  18. package/dist/cjs/src/server/components/fastapi/console/types.js +0 -1
  19. package/dist/cjs/src/server/components/fastapi/console/types.js.map +1 -1
  20. package/dist/cjs/src/server/const/default.js +75 -0
  21. package/dist/cjs/src/server/const/default.js.map +1 -1
  22. package/dist/cjs/src/server/handlers/NotFoundHandler.js +1 -1
  23. package/dist/esm/src/config.js +57 -31
  24. package/dist/esm/src/config.js.map +1 -1
  25. package/dist/esm/src/file-upload.js +3 -2
  26. package/dist/esm/src/file-upload.js.map +1 -1
  27. package/dist/esm/src/index.js +1 -1
  28. package/dist/esm/src/plugins/api/PluginAPI.js +131 -0
  29. package/dist/esm/src/plugins/api/PluginAPI.js.map +1 -0
  30. package/dist/esm/src/plugins/core/PluginManager.js +264 -0
  31. package/dist/esm/src/plugins/core/PluginManager.js.map +1 -0
  32. package/dist/esm/src/server/FastServer.js +28 -15
  33. package/dist/esm/src/server/FastServer.js.map +1 -1
  34. package/dist/esm/src/server/ServerFactory.js +28 -23
  35. package/dist/esm/src/server/ServerFactory.js.map +1 -1
  36. package/dist/esm/src/server/components/fastapi/FileUploadManager.js +3 -2
  37. package/dist/esm/src/server/components/fastapi/FileUploadManager.js.map +1 -1
  38. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js +74 -22
  39. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  40. package/dist/esm/src/server/components/fastapi/console/types.js +0 -1
  41. package/dist/esm/src/server/components/fastapi/console/types.js.map +1 -1
  42. package/dist/esm/src/server/const/default.js +75 -0
  43. package/dist/esm/src/server/const/default.js.map +1 -1
  44. package/dist/esm/src/server/handlers/NotFoundHandler.js +1 -1
  45. package/dist/index.d.ts +112 -109
  46. package/package.json +2 -1
  47. package/dist/cjs/src/plugins/core/PluginAPI.js +0 -80
  48. package/dist/cjs/src/plugins/core/PluginAPI.js.map +0 -1
  49. package/dist/cjs/src/server/utils/ConfigLoader.js +0 -306
  50. package/dist/cjs/src/server/utils/ConfigLoader.js.map +0 -1
  51. package/dist/esm/src/plugins/core/PluginAPI.js +0 -78
  52. package/dist/esm/src/plugins/core/PluginAPI.js.map +0 -1
  53. package/dist/esm/src/server/utils/ConfigLoader.js +0 -283
  54. package/dist/esm/src/server/utils/ConfigLoader.js.map +0 -1
@@ -1,306 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('fs');
4
- var path = require('path');
5
-
6
- function _interopNamespaceDefault(e) {
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
24
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
25
-
26
- /**
27
- * XyPriss Configuration Loader
28
- *
29
- * Automatically loads configuration from external files (TypeScript or JSON)
30
- * Supports xypriss.config.ts, xypriss.config.js, and xypriss.config.json files
31
- *
32
- * @fileoverview Configuration loader for external config files
33
- * @version 1.0.0
34
- * @author XyPriss Team
35
- * @since 2025-01-01
36
- */
37
- /**
38
- * Configuration file names to search for (in order of preference)
39
- */
40
- const CONFIG_FILES = [
41
- "xypriss.config.ts",
42
- "xypriss.config.js",
43
- "xypriss.config.json",
44
- "xypriss.config.cjs",
45
- "xypriss.config.mjs",
46
- ];
47
- /**
48
- * Configuration loader class
49
- * Handles loading and validation of external configuration files
50
- */
51
- class ConfigLoader {
52
- /**
53
- * Load configuration from external files (synchronous - JSON only)
54
- *
55
- * Searches for JSON configuration files in the current working directory
56
- * and loads the first one found. This is a synchronous version for use in constructors.
57
- *
58
- * @param cwd - Current working directory (defaults to process.cwd())
59
- * @returns Loaded configuration or null if no config found
60
- *
61
- * @example
62
- * ```typescript
63
- * const configLoader = new ConfigLoader();
64
- * const config = configLoader.loadConfigSync();
65
- * if (config) {
66
- * console.log("Loaded config from:", config._source);
67
- * }
68
- * ```
69
- */
70
- loadConfigSync(cwd = process.cwd()) {
71
- // Only load JSON files synchronously for constructor use
72
- const jsonConfigPath = path__namespace.resolve(cwd, "xypriss.config.json");
73
- if (fs__namespace.existsSync(jsonConfigPath)) {
74
- try {
75
- const config = this.loadJsonConfig(jsonConfigPath);
76
- if (config && typeof config === "object") {
77
- // Add source information for debugging
78
- config._source = jsonConfigPath;
79
- return config;
80
- }
81
- }
82
- catch (error) {
83
- // Silently fail in constructor - config loading errors should not break initialization
84
- console.warn(`Warning: Failed to load JSON config from ${jsonConfigPath}:`, error);
85
- }
86
- }
87
- return null;
88
- }
89
- /**
90
- * Load configuration from external files (asynchronous)
91
- *
92
- * Searches for configuration files in the current working directory
93
- * and loads the first one found. Supports TypeScript, JavaScript, and JSON files.
94
- *
95
- * @param cwd - Current working directory (defaults to process.cwd())
96
- * @returns Promise resolving to loaded configuration or null if no config found
97
- *
98
- * @example
99
- * ```typescript
100
- * const configLoader = new ConfigLoader();
101
- * const config = await configLoader.loadConfig();
102
- * if (config) {
103
- * console.log("Loaded config from:", config._source);
104
- * }
105
- * ```
106
- */
107
- async loadConfig(cwd = process.cwd()) {
108
- for (const configFile of CONFIG_FILES) {
109
- const configPath = path__namespace.resolve(cwd, configFile);
110
- if (fs__namespace.existsSync(configPath)) {
111
- try {
112
- const config = await this.loadConfigFile(configPath);
113
- if (config && typeof config === "object") {
114
- // Add source information for debugging
115
- config._source = configPath;
116
- return config;
117
- }
118
- }
119
- catch (error) {
120
- console.warn(`Warning: Failed to load config from ${configPath}:`, error);
121
- // Continue to next file instead of failing
122
- }
123
- }
124
- }
125
- return null; // No configuration file found
126
- }
127
- /**
128
- * Load configuration from a specific file
129
- *
130
- * @param configPath - Absolute path to the configuration file
131
- * @returns Promise resolving to the loaded configuration
132
- * @private
133
- */
134
- async loadConfigFile(configPath) {
135
- const ext = path__namespace.extname(configPath).toLowerCase();
136
- switch (ext) {
137
- case ".json":
138
- return this.loadJsonConfig(configPath);
139
- case ".js":
140
- case ".cjs":
141
- return this.loadJsConfig(configPath);
142
- case ".mjs":
143
- return this.loadMjsConfig(configPath);
144
- case ".ts":
145
- return this.loadTsConfig(configPath);
146
- default:
147
- throw new Error(`Unsupported config file extension: ${ext}`);
148
- }
149
- }
150
- /**
151
- * Load JSON configuration file
152
- *
153
- * @param configPath - Path to JSON config file
154
- * @returns Parsed JSON configuration
155
- * @private
156
- */
157
- loadJsonConfig(configPath) {
158
- const content = fs__namespace.readFileSync(configPath, "utf-8");
159
- return JSON.parse(content);
160
- }
161
- /**
162
- * Load JavaScript configuration file
163
- *
164
- * @param configPath - Path to JS config file
165
- * @returns Configuration object exported by the JS file
166
- * @private
167
- */
168
- async loadJsConfig(configPath) {
169
- // For CommonJS and ESM files, we need dynamic import which works for both
170
- try {
171
- // Use dynamic import which works for both CommonJS and ESM
172
- const config = await import(configPath);
173
- // Handle both default export and named exports
174
- return config.default || config;
175
- }
176
- catch (error) {
177
- // Fallback to require for CommonJS in environments where dynamic import fails
178
- try {
179
- // Clear require cache to allow reloading
180
- delete require.cache[require.resolve(configPath)];
181
- const config = require(configPath);
182
- // Handle both default export and module.exports
183
- return config.default || config;
184
- }
185
- catch (fallbackError) {
186
- throw new Error(`Failed to load JS config: ${error}. Fallback also failed: ${fallbackError}`);
187
- }
188
- }
189
- }
190
- /**
191
- * Load ES Module configuration file
192
- *
193
- * @param configPath - Path to MJS config file
194
- * @returns Configuration object exported by the MJS file
195
- * @private
196
- */
197
- async loadMjsConfig(configPath) {
198
- // For ES modules, we need dynamic import
199
- try {
200
- const config = await import(configPath);
201
- return config.default || config;
202
- }
203
- catch (error) {
204
- throw new Error(`Failed to load MJS config: ${error}`);
205
- }
206
- }
207
- /**
208
- * Load TypeScript configuration file
209
- *
210
- * @param configPath - Path to TS config file
211
- * @returns Configuration object exported by the TS file
212
- * @private
213
- */
214
- async loadTsConfig(configPath) {
215
- try {
216
- // First, try to load as JavaScript (if user compiled it)
217
- const jsPath = configPath.replace(/\.ts$/, ".js");
218
- if (fs__namespace.existsSync(jsPath)) {
219
- return this.loadJsConfig(jsPath);
220
- }
221
- // Try dynamic import directly (works if ts-node or similar is available)
222
- const config = await import(configPath);
223
- return config.default || config;
224
- }
225
- catch (error) {
226
- // If direct import fails, try to compile with ts-node if available
227
- try {
228
- // Check if ts-node is available
229
- require.resolve("ts-node");
230
- // Register ts-node for TypeScript compilation
231
- require("ts-node/register");
232
- // Clear require cache and load the TypeScript file
233
- delete require.cache[require.resolve(configPath)];
234
- const config = require(configPath);
235
- return config.default || config;
236
- }
237
- catch (tsNodeError) {
238
- // If ts-node is not available or fails, provide helpful error message
239
- throw new Error(`Failed to load TS config from ${configPath}. ` +
240
- `Please ensure ts-node is installed (npm install ts-node) or compile to JS first. ` +
241
- `Original error: ${error.message}`);
242
- }
243
- }
244
- }
245
- /**
246
- * Validate configuration object
247
- *
248
- * Performs basic validation on the loaded configuration
249
- *
250
- * @param config - Configuration object to validate
251
- * @returns True if configuration is valid
252
- *
253
- * @example
254
- * ```typescript
255
- * const loader = new ConfigLoader();
256
- * const config = await loader.loadConfig();
257
- * if (config && loader.validateConfig(config)) {
258
- * console.log("Config is valid");
259
- * }
260
- * ```
261
- */
262
- validateConfig(config) {
263
- // Basic validation - check if it's an object
264
- if (!config || typeof config !== "object") {
265
- return false;
266
- }
267
- // Check for required structure (at least one valid property)
268
- const validKeys = [
269
- "env", "server", "security", "performance", "monitoring",
270
- "cache", "cluster", "plugins", "requestManagement", "fileUpload"
271
- ];
272
- return validKeys.some(key => key in config);
273
- }
274
- /**
275
- * Get list of available configuration files in a directory
276
- *
277
- * @param cwd - Directory to search (defaults to process.cwd())
278
- * @returns Array of available configuration file names
279
- *
280
- * @example
281
- * ```typescript
282
- * const loader = new ConfigLoader();
283
- * const files = loader.getAvailableConfigFiles();
284
- * console.log("Available config files:", files);
285
- * ```
286
- */
287
- getAvailableConfigFiles(cwd = process.cwd()) {
288
- const available = [];
289
- for (const configFile of CONFIG_FILES) {
290
- const configPath = path__namespace.resolve(cwd, configFile);
291
- if (fs__namespace.existsSync(configPath)) {
292
- available.push(configFile);
293
- }
294
- }
295
- return available;
296
- }
297
- }
298
- /**
299
- * Default configuration loader instance
300
- * Can be used directly without creating a new instance
301
- */
302
- const configLoader = new ConfigLoader();
303
-
304
- exports.ConfigLoader = ConfigLoader;
305
- exports.configLoader = configLoader;
306
- //# sourceMappingURL=ConfigLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfigLoader.js","sources":["../../../../../src/server/utils/ConfigLoader.ts"],"sourcesContent":[null],"names":["path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA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C,CAAC;AACjD,YAAA,IAAIC,aAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;AAC7B,gBAAA,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAC5B;SACF;AAED,QAAA,OAAO,SAAS,CAAC;KAClB;AACF,CAAA;AAED;;;AAGG;AACU,MAAA,YAAY,GAAG,IAAI,YAAY;;;;;"}
@@ -1,78 +0,0 @@
1
- /**
2
- * Plugin API - Imperative plugin registration
3
- *
4
- * Usage:
5
- * import { Plugin } from 'xypriss';
6
- *
7
- * Plugin.register({
8
- * name: 'my-plugin',
9
- * version: '1.0.0',
10
- * onServerStart: () => console.log('Started!')
11
- * });
12
- */
13
- class PluginAPI {
14
- /**
15
- * Set the plugin manager (called internally by ServerFactory)
16
- */
17
- static setManager(manager) {
18
- this.manager = manager;
19
- }
20
- /**
21
- * Register a plugin imperatively
22
- *
23
- * @example
24
- * Plugin.register({
25
- * name: 'my-plugin',
26
- * version: '1.0.0',
27
- * onServerStart: () => console.log('Started!')
28
- * });
29
- */
30
- static register(plugin, config) {
31
- if (!this.manager) {
32
- throw new Error("Plugin system not initialized. Create a server first.");
33
- }
34
- this.manager.register(plugin, config);
35
- }
36
- /**
37
- * Get a registered plugin by name
38
- */
39
- static get(name) {
40
- if (!this.manager) {
41
- throw new Error("Plugin system not initialized. Create a server first.");
42
- }
43
- return this.manager.getPlugin(name);
44
- }
45
- /**
46
- * Create a plugin (helper for creating plugin objects)
47
- *
48
- * @example
49
- * const myPlugin = Plugin.create({
50
- * name: 'my-plugin',
51
- * version: '1.0.0',
52
- * onServerStart: () => console.log('Started!')
53
- * });
54
- */
55
- static create(plugin) {
56
- return plugin;
57
- }
58
- /**
59
- * Create a plugin factory function
60
- *
61
- * @example
62
- * const createAuthPlugin = Plugin.factory((config) => ({
63
- * name: 'auth',
64
- * version: '1.0.0',
65
- * onRequest: (req, res, next) => {
66
- * // Use config here
67
- * next();
68
- * }
69
- * }));
70
- */
71
- static factory(creator) {
72
- return creator;
73
- }
74
- }
75
- PluginAPI.manager = null;
76
-
77
- export { PluginAPI as Plugin };
78
- //# sourceMappingURL=PluginAPI.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PluginAPI.js","sources":["../../../../../src/plugins/core/PluginAPI.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;AAWG;AAKH,MAAM,SAAS,CAAA;AAGX;;AAEG;IACH,OAAO,UAAU,CAAC,OAAsB,EAAA;AACpC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;KAC1B;AAED;;;;;;;;;AASG;AACH,IAAA,OAAO,QAAQ,CAAC,MAAqC,EAAE,MAAY,EAAA;AAC/D,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CACX,uDAAuD,CAC1D,CAAC;SACL;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACzC;AAED;;AAEG;IACH,OAAO,GAAG,CAAC,IAAY,EAAA;AACnB,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CACX,uDAAuD,CAC1D,CAAC;SACL;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KACvC;AAED;;;;;;;;;AASG;IACH,OAAO,MAAM,CAAC,MAAqB,EAAA;AAC/B,QAAA,OAAO,MAAM,CAAC;KACjB;AAED;;;;;;;;;;;;AAYG;IACH,OAAO,OAAO,CAAC,OAAsB,EAAA;AACjC,QAAA,OAAO,OAAO,CAAC;KAClB;;AArEc,SAAO,CAAA,OAAA,GAAyB,IAAI;;;;"}
@@ -1,283 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
-
4
- /**
5
- * XyPriss Configuration Loader
6
- *
7
- * Automatically loads configuration from external files (TypeScript or JSON)
8
- * Supports xypriss.config.ts, xypriss.config.js, and xypriss.config.json files
9
- *
10
- * @fileoverview Configuration loader for external config files
11
- * @version 1.0.0
12
- * @author XyPriss Team
13
- * @since 2025-01-01
14
- */
15
- /**
16
- * Configuration file names to search for (in order of preference)
17
- */
18
- const CONFIG_FILES = [
19
- "xypriss.config.ts",
20
- "xypriss.config.js",
21
- "xypriss.config.json",
22
- "xypriss.config.cjs",
23
- "xypriss.config.mjs",
24
- ];
25
- /**
26
- * Configuration loader class
27
- * Handles loading and validation of external configuration files
28
- */
29
- class ConfigLoader {
30
- /**
31
- * Load configuration from external files (synchronous - JSON only)
32
- *
33
- * Searches for JSON configuration files in the current working directory
34
- * and loads the first one found. This is a synchronous version for use in constructors.
35
- *
36
- * @param cwd - Current working directory (defaults to process.cwd())
37
- * @returns Loaded configuration or null if no config found
38
- *
39
- * @example
40
- * ```typescript
41
- * const configLoader = new ConfigLoader();
42
- * const config = configLoader.loadConfigSync();
43
- * if (config) {
44
- * console.log("Loaded config from:", config._source);
45
- * }
46
- * ```
47
- */
48
- loadConfigSync(cwd = process.cwd()) {
49
- // Only load JSON files synchronously for constructor use
50
- const jsonConfigPath = path.resolve(cwd, "xypriss.config.json");
51
- if (fs.existsSync(jsonConfigPath)) {
52
- try {
53
- const config = this.loadJsonConfig(jsonConfigPath);
54
- if (config && typeof config === "object") {
55
- // Add source information for debugging
56
- config._source = jsonConfigPath;
57
- return config;
58
- }
59
- }
60
- catch (error) {
61
- // Silently fail in constructor - config loading errors should not break initialization
62
- console.warn(`Warning: Failed to load JSON config from ${jsonConfigPath}:`, error);
63
- }
64
- }
65
- return null;
66
- }
67
- /**
68
- * Load configuration from external files (asynchronous)
69
- *
70
- * Searches for configuration files in the current working directory
71
- * and loads the first one found. Supports TypeScript, JavaScript, and JSON files.
72
- *
73
- * @param cwd - Current working directory (defaults to process.cwd())
74
- * @returns Promise resolving to loaded configuration or null if no config found
75
- *
76
- * @example
77
- * ```typescript
78
- * const configLoader = new ConfigLoader();
79
- * const config = await configLoader.loadConfig();
80
- * if (config) {
81
- * console.log("Loaded config from:", config._source);
82
- * }
83
- * ```
84
- */
85
- async loadConfig(cwd = process.cwd()) {
86
- for (const configFile of CONFIG_FILES) {
87
- const configPath = path.resolve(cwd, configFile);
88
- if (fs.existsSync(configPath)) {
89
- try {
90
- const config = await this.loadConfigFile(configPath);
91
- if (config && typeof config === "object") {
92
- // Add source information for debugging
93
- config._source = configPath;
94
- return config;
95
- }
96
- }
97
- catch (error) {
98
- console.warn(`Warning: Failed to load config from ${configPath}:`, error);
99
- // Continue to next file instead of failing
100
- }
101
- }
102
- }
103
- return null; // No configuration file found
104
- }
105
- /**
106
- * Load configuration from a specific file
107
- *
108
- * @param configPath - Absolute path to the configuration file
109
- * @returns Promise resolving to the loaded configuration
110
- * @private
111
- */
112
- async loadConfigFile(configPath) {
113
- const ext = path.extname(configPath).toLowerCase();
114
- switch (ext) {
115
- case ".json":
116
- return this.loadJsonConfig(configPath);
117
- case ".js":
118
- case ".cjs":
119
- return this.loadJsConfig(configPath);
120
- case ".mjs":
121
- return this.loadMjsConfig(configPath);
122
- case ".ts":
123
- return this.loadTsConfig(configPath);
124
- default:
125
- throw new Error(`Unsupported config file extension: ${ext}`);
126
- }
127
- }
128
- /**
129
- * Load JSON configuration file
130
- *
131
- * @param configPath - Path to JSON config file
132
- * @returns Parsed JSON configuration
133
- * @private
134
- */
135
- loadJsonConfig(configPath) {
136
- const content = fs.readFileSync(configPath, "utf-8");
137
- return JSON.parse(content);
138
- }
139
- /**
140
- * Load JavaScript configuration file
141
- *
142
- * @param configPath - Path to JS config file
143
- * @returns Configuration object exported by the JS file
144
- * @private
145
- */
146
- async loadJsConfig(configPath) {
147
- // For CommonJS and ESM files, we need dynamic import which works for both
148
- try {
149
- // Use dynamic import which works for both CommonJS and ESM
150
- const config = await import(configPath);
151
- // Handle both default export and named exports
152
- return config.default || config;
153
- }
154
- catch (error) {
155
- // Fallback to require for CommonJS in environments where dynamic import fails
156
- try {
157
- // Clear require cache to allow reloading
158
- delete require.cache[require.resolve(configPath)];
159
- const config = require(configPath);
160
- // Handle both default export and module.exports
161
- return config.default || config;
162
- }
163
- catch (fallbackError) {
164
- throw new Error(`Failed to load JS config: ${error}. Fallback also failed: ${fallbackError}`);
165
- }
166
- }
167
- }
168
- /**
169
- * Load ES Module configuration file
170
- *
171
- * @param configPath - Path to MJS config file
172
- * @returns Configuration object exported by the MJS file
173
- * @private
174
- */
175
- async loadMjsConfig(configPath) {
176
- // For ES modules, we need dynamic import
177
- try {
178
- const config = await import(configPath);
179
- return config.default || config;
180
- }
181
- catch (error) {
182
- throw new Error(`Failed to load MJS config: ${error}`);
183
- }
184
- }
185
- /**
186
- * Load TypeScript configuration file
187
- *
188
- * @param configPath - Path to TS config file
189
- * @returns Configuration object exported by the TS file
190
- * @private
191
- */
192
- async loadTsConfig(configPath) {
193
- try {
194
- // First, try to load as JavaScript (if user compiled it)
195
- const jsPath = configPath.replace(/\.ts$/, ".js");
196
- if (fs.existsSync(jsPath)) {
197
- return this.loadJsConfig(jsPath);
198
- }
199
- // Try dynamic import directly (works if ts-node or similar is available)
200
- const config = await import(configPath);
201
- return config.default || config;
202
- }
203
- catch (error) {
204
- // If direct import fails, try to compile with ts-node if available
205
- try {
206
- // Check if ts-node is available
207
- require.resolve("ts-node");
208
- // Register ts-node for TypeScript compilation
209
- require("ts-node/register");
210
- // Clear require cache and load the TypeScript file
211
- delete require.cache[require.resolve(configPath)];
212
- const config = require(configPath);
213
- return config.default || config;
214
- }
215
- catch (tsNodeError) {
216
- // If ts-node is not available or fails, provide helpful error message
217
- throw new Error(`Failed to load TS config from ${configPath}. ` +
218
- `Please ensure ts-node is installed (npm install ts-node) or compile to JS first. ` +
219
- `Original error: ${error.message}`);
220
- }
221
- }
222
- }
223
- /**
224
- * Validate configuration object
225
- *
226
- * Performs basic validation on the loaded configuration
227
- *
228
- * @param config - Configuration object to validate
229
- * @returns True if configuration is valid
230
- *
231
- * @example
232
- * ```typescript
233
- * const loader = new ConfigLoader();
234
- * const config = await loader.loadConfig();
235
- * if (config && loader.validateConfig(config)) {
236
- * console.log("Config is valid");
237
- * }
238
- * ```
239
- */
240
- validateConfig(config) {
241
- // Basic validation - check if it's an object
242
- if (!config || typeof config !== "object") {
243
- return false;
244
- }
245
- // Check for required structure (at least one valid property)
246
- const validKeys = [
247
- "env", "server", "security", "performance", "monitoring",
248
- "cache", "cluster", "plugins", "requestManagement", "fileUpload"
249
- ];
250
- return validKeys.some(key => key in config);
251
- }
252
- /**
253
- * Get list of available configuration files in a directory
254
- *
255
- * @param cwd - Directory to search (defaults to process.cwd())
256
- * @returns Array of available configuration file names
257
- *
258
- * @example
259
- * ```typescript
260
- * const loader = new ConfigLoader();
261
- * const files = loader.getAvailableConfigFiles();
262
- * console.log("Available config files:", files);
263
- * ```
264
- */
265
- getAvailableConfigFiles(cwd = process.cwd()) {
266
- const available = [];
267
- for (const configFile of CONFIG_FILES) {
268
- const configPath = path.resolve(cwd, configFile);
269
- if (fs.existsSync(configPath)) {
270
- available.push(configFile);
271
- }
272
- }
273
- return available;
274
- }
275
- }
276
- /**
277
- * Default configuration loader instance
278
- * Can be used directly without creating a new instance
279
- */
280
- const configLoader = new ConfigLoader();
281
-
282
- export { ConfigLoader, configLoader };
283
- //# sourceMappingURL=ConfigLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfigLoader.js","sources":["../../../../../src/server/utils/ConfigLoader.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;;;;;;;;AAUG;AAMH;;AAEG;AACH,MAAM,YAAY,GAAG;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;CACrB,CAAC;AAEF;;;AAGG;MACU,YAAY,CAAA;AACvB;;;;;;;;;;;;;;;;;AAiBG;AACH,IAAA,cAAc,CAAC,GAAA,GAAc,OAAO,CAAC,GAAG,EAAE,EAAA;;QAExC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,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