xypriss 4.3.5 → 4.4.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.
- package/README.md +1 -1
- package/dist/cjs/src/index.js +12 -0
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/plugins/core/PluginManager.js +7 -1
- package/dist/cjs/src/plugins/core/PluginManager.js.map +1 -1
- package/dist/cjs/src/server/ServerFactory.js +9 -0
- package/dist/cjs/src/server/ServerFactory.js.map +1 -1
- package/dist/cjs/src/sys.js +600 -0
- package/dist/cjs/src/sys.js.map +1 -0
- package/dist/esm/src/index.js +12 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/plugins/core/PluginManager.js +7 -1
- package/dist/esm/src/plugins/core/PluginManager.js.map +1 -1
- package/dist/esm/src/server/ServerFactory.js +9 -0
- package/dist/esm/src/server/ServerFactory.js.map +1 -1
- package/dist/esm/src/sys.js +598 -0
- package/dist/esm/src/sys.js.map +1 -0
- package/dist/index.d.ts +525 -0
- package/package.json +1 -1
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XyPriss System Variables Class
|
|
3
|
+
*
|
|
4
|
+
* Provides centralized access to system variables, configuration management,
|
|
5
|
+
* and environment utilities for XyPriss applications. This class serves as
|
|
6
|
+
* a type-safe wrapper around system configuration with built-in helpers
|
|
7
|
+
* for common operations.
|
|
8
|
+
*
|
|
9
|
+
* @class XyPrissSys
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Initialize with default values
|
|
15
|
+
* const sys = new XyPrissSys({
|
|
16
|
+
* __version__: "1.0.0",
|
|
17
|
+
* __author__: "John Doe",
|
|
18
|
+
* __port__: 8080,
|
|
19
|
+
* __env__: "production"
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Check environment
|
|
23
|
+
* if (__sys__$isProduction()) {
|
|
24
|
+
* console.log('Running in production mode');
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Access variables
|
|
28
|
+
* const port = __sys__$get('__port__', 3000);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
class XyPrissSys {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new XyPrissSys instance with optional initial data.
|
|
34
|
+
* All port-related properties are automatically synchronized.
|
|
35
|
+
*
|
|
36
|
+
* @constructor
|
|
37
|
+
* @param {Record<string, any>} [data={}] - Initial system variable data
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* // Create with defaults
|
|
42
|
+
* const sys = new XyPrissSys();
|
|
43
|
+
*
|
|
44
|
+
* // Create with custom data
|
|
45
|
+
* const sys = new XyPrissSys({
|
|
46
|
+
* __version__: "2.0.0",
|
|
47
|
+
* __author__: "Development Team",
|
|
48
|
+
* __port__: 8080,
|
|
49
|
+
* __env__: "production",
|
|
50
|
+
* customVar: "custom value"
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
constructor(data = {}) {
|
|
55
|
+
/**
|
|
56
|
+
* Application version string following semantic versioning.
|
|
57
|
+
*
|
|
58
|
+
* @type {string}
|
|
59
|
+
* @default "0.0.0"
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* __sys____version__ = "1.2.3";
|
|
64
|
+
* console.log(`App version: ${__sys____version__}`);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
this.__version__ = "0.0.0";
|
|
68
|
+
/**
|
|
69
|
+
* Application author or maintainer name.
|
|
70
|
+
*
|
|
71
|
+
* @type {string}
|
|
72
|
+
* @default "unknown"
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* __sys____author__ = "Jane Smith";
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
this.__author__ = "unknown";
|
|
80
|
+
/**
|
|
81
|
+
* Collection of application URLs for various environments or services.
|
|
82
|
+
* Useful for storing API endpoints, frontend URLs, or external service links.
|
|
83
|
+
*
|
|
84
|
+
* @type {Record<string, string>}
|
|
85
|
+
* @default {}
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* __sys____app_urls__ = {
|
|
90
|
+
* api: "https://api.example.com",
|
|
91
|
+
* frontend: "https://app.example.com",
|
|
92
|
+
* docs: "https://docs.example.com"
|
|
93
|
+
* };
|
|
94
|
+
*
|
|
95
|
+
* const apiUrl = __sys____app_urls__.api;
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
this.__app_urls__ = {};
|
|
99
|
+
/**
|
|
100
|
+
* Application name identifier.
|
|
101
|
+
*
|
|
102
|
+
* @type {string}
|
|
103
|
+
* @default "xypriss-app"
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* __sys____name__ = "my-awesome-app";
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
this.__name__ = "xypriss-app";
|
|
111
|
+
/**
|
|
112
|
+
* Application alias or short name.
|
|
113
|
+
* Used for abbreviated references or CLI commands.
|
|
114
|
+
*
|
|
115
|
+
* @type {string}
|
|
116
|
+
* @default "app"
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* __sys____alias__ = "myapp";
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
this.__alias__ = "app";
|
|
124
|
+
/**
|
|
125
|
+
* Server port number (lowercase variant).
|
|
126
|
+
* Synchronized automatically with __PORT__.
|
|
127
|
+
*
|
|
128
|
+
* @type {number}
|
|
129
|
+
* @default 3000
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* __sys____port__ = 8080;
|
|
134
|
+
* console.log(__sys____PORT__); // Also 8080 (auto-synced)
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
this.__port__ = 3000;
|
|
138
|
+
/**
|
|
139
|
+
* Server port number (uppercase variant).
|
|
140
|
+
* Synchronized automatically with __port__.
|
|
141
|
+
*
|
|
142
|
+
* @type {number}
|
|
143
|
+
* @default 3000
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* __sys____PORT__ = 5000;
|
|
148
|
+
* console.log(__sys____port__); // Also 5000 (auto-synced)
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
this.__PORT__ = 3000;
|
|
152
|
+
/**
|
|
153
|
+
* Current environment mode.
|
|
154
|
+
* Typically "development", "production", "staging", or "test".
|
|
155
|
+
*
|
|
156
|
+
* @type {string}
|
|
157
|
+
* @default "development"
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* __sys____env__ = "production";
|
|
162
|
+
* if (__sys__$isProduction()) {
|
|
163
|
+
* // Production-specific logic
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
this.__env__ = "development";
|
|
168
|
+
/**
|
|
169
|
+
* Environment variables manager providing access to process.env.
|
|
170
|
+
* Offers a clean API for getting, setting, and managing environment variables.
|
|
171
|
+
*
|
|
172
|
+
* @type {Object}
|
|
173
|
+
* @property {Function} set - Set an environment variable
|
|
174
|
+
* @property {Function} get - Get an environment variable with optional default
|
|
175
|
+
* @property {Function} has - Check if an environment variable exists
|
|
176
|
+
* @property {Function} delete - Remove an environment variable
|
|
177
|
+
* @property {Function} all - Get all environment variables
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* // Set environment variable
|
|
182
|
+
* __sys____ENV__.set('API_KEY', 'secret123');
|
|
183
|
+
*
|
|
184
|
+
* // Get with default
|
|
185
|
+
* const apiKey = __sys____ENV__.get('API_KEY', 'default-key');
|
|
186
|
+
*
|
|
187
|
+
* // Check existence
|
|
188
|
+
* if (__sys____ENV__.has('DATABASE_URL')) {
|
|
189
|
+
* const dbUrl = __sys____ENV__.get('DATABASE_URL');
|
|
190
|
+
* }
|
|
191
|
+
*
|
|
192
|
+
* // Delete variable
|
|
193
|
+
* __sys____ENV__.delete('TEMP_VAR');
|
|
194
|
+
*
|
|
195
|
+
* // Get all variables
|
|
196
|
+
* const allEnv = __sys____ENV__.all();
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
this.__ENV__ = {
|
|
200
|
+
/**
|
|
201
|
+
* Set an environment variable.
|
|
202
|
+
*
|
|
203
|
+
* @param {string} key - The environment variable name
|
|
204
|
+
* @param {string} value - The value to set
|
|
205
|
+
* @returns {void}
|
|
206
|
+
*/
|
|
207
|
+
set: (key, value) => {
|
|
208
|
+
process.env[key] = value;
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* Get an environment variable with an optional default value.
|
|
212
|
+
*
|
|
213
|
+
* @param {string} key - The environment variable name
|
|
214
|
+
* @param {string} [defaultValue] - Default value if variable is not set
|
|
215
|
+
* @returns {string | undefined} The environment variable value or default
|
|
216
|
+
*/
|
|
217
|
+
get: (key, defaultValue) => {
|
|
218
|
+
return process.env[key] || defaultValue;
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Check if an environment variable exists.
|
|
222
|
+
*
|
|
223
|
+
* @param {string} key - The environment variable name
|
|
224
|
+
* @returns {boolean} True if the variable exists
|
|
225
|
+
*/
|
|
226
|
+
has: (key) => {
|
|
227
|
+
return process.env[key] !== undefined;
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* Delete an environment variable.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} key - The environment variable name
|
|
233
|
+
* @returns {void}
|
|
234
|
+
*/
|
|
235
|
+
delete: (key) => {
|
|
236
|
+
delete process.env[key];
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
* Get all environment variables.
|
|
240
|
+
*
|
|
241
|
+
* @returns {NodeJS.ProcessEnv} All environment variables
|
|
242
|
+
*/
|
|
243
|
+
all: () => {
|
|
244
|
+
return process.env;
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
this.$update(data);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Update system variables with new data.
|
|
251
|
+
* Automatically synchronizes __port__ and __PORT__ to maintain consistency.
|
|
252
|
+
* Supports backward compatibility for legacy single-underscore variants.
|
|
253
|
+
*
|
|
254
|
+
* @param {Record<string, any>} data - Partial data to merge into system variables
|
|
255
|
+
* @returns {void}
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* __sys__$update({
|
|
260
|
+
* __version__: "1.5.0",
|
|
261
|
+
* __port__: 9000,
|
|
262
|
+
* newFeature: true
|
|
263
|
+
* });
|
|
264
|
+
*
|
|
265
|
+
* // Port is automatically synced
|
|
266
|
+
* console.log(__sys____port__); // 9000
|
|
267
|
+
* console.log(__sys____PORT__); // 9000
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
$update(data) {
|
|
271
|
+
Object.assign(this, data);
|
|
272
|
+
// Synchronize port variants
|
|
273
|
+
if (data.__port__ !== undefined)
|
|
274
|
+
this.__PORT__ = data.__port__;
|
|
275
|
+
if (data.__PORT__ !== undefined)
|
|
276
|
+
this.__port__ = data.__PORT__;
|
|
277
|
+
// Backward compatibility for single underscore
|
|
278
|
+
if (data.__port !== undefined) {
|
|
279
|
+
this.__port__ = data.__port;
|
|
280
|
+
this.__PORT__ = data.__port;
|
|
281
|
+
}
|
|
282
|
+
if (data.__PORT !== undefined) {
|
|
283
|
+
this.__port__ = data.__PORT;
|
|
284
|
+
this.__PORT__ = data.__PORT;
|
|
285
|
+
}
|
|
286
|
+
if (data.__env !== undefined)
|
|
287
|
+
this.__env__ = data.__env;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Add or update a single system variable.
|
|
291
|
+
* Provides a cleaner API for adding individual properties.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} key - Variable name
|
|
294
|
+
* @param {any} value - Variable value (any type)
|
|
295
|
+
* @returns {void}
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* __sys__$add('databaseUrl', 'postgresql://localhost:5432/mydb');
|
|
300
|
+
* __sys__$add('maxConnections', 100);
|
|
301
|
+
* __sys__$add('features', { darkMode: true, beta: false });
|
|
302
|
+
*
|
|
303
|
+
* console.log(__sys__databaseUrl); // 'postgresql://localhost:5432/mydb'
|
|
304
|
+
* console.log(__sys__maxConnections); // 100
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
$add(key, value) {
|
|
308
|
+
this[key] = value;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Remove a system variable.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} key - Variable name to remove
|
|
314
|
+
* @returns {boolean} True if the variable existed and was removed
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* __sys__$add('tempVar', 'temporary');
|
|
319
|
+
* console.log(__sys__$has('tempVar')); // true
|
|
320
|
+
*
|
|
321
|
+
* __sys__$remove('tempVar');
|
|
322
|
+
* console.log(__sys__$has('tempVar')); // false
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
$remove(key) {
|
|
326
|
+
if (this.$has(key)) {
|
|
327
|
+
delete this[key];
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Export all system variables as a plain JavaScript object.
|
|
334
|
+
* Excludes internal methods (starting with $) and the __ENV__ manager.
|
|
335
|
+
* Useful for serialization, logging, or persistence.
|
|
336
|
+
*
|
|
337
|
+
* @returns {Record<string, any>} Plain object containing all system variables
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const config = __sys__$toJSON();
|
|
342
|
+
* console.log(JSON.stringify(config, null, 2));
|
|
343
|
+
*
|
|
344
|
+
* // Save to file
|
|
345
|
+
* fs.writeFileSync('config.json', JSON.stringify(config, null, 2));
|
|
346
|
+
*
|
|
347
|
+
* // Send in API response
|
|
348
|
+
* res.json({ system: config });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
$toJSON() {
|
|
352
|
+
const json = {};
|
|
353
|
+
for (const key in this) {
|
|
354
|
+
if (!key.startsWith("$") &&
|
|
355
|
+
typeof this[key] !== "function" &&
|
|
356
|
+
key !== "__ENV__") {
|
|
357
|
+
json[key] = this[key];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return json;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Check if the current environment is production.
|
|
364
|
+
* Compares __env__ against "production" (case-sensitive).
|
|
365
|
+
*
|
|
366
|
+
* @returns {boolean} True if environment is production
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* if (__sys__$isProduction()) {
|
|
371
|
+
* console.log('Running in production mode');
|
|
372
|
+
* // Enable production optimizations
|
|
373
|
+
* enableCaching();
|
|
374
|
+
* disableDebugMode();
|
|
375
|
+
* }
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
$isProduction() {
|
|
379
|
+
return this.__env__ === "production";
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Check if the current environment is development.
|
|
383
|
+
* Compares __env__ against "development" (case-sensitive).
|
|
384
|
+
*
|
|
385
|
+
* @returns {boolean} True if environment is development
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* if (__sys__$isDevelopment()) {
|
|
390
|
+
* console.log('Running in development mode');
|
|
391
|
+
* // Enable development features
|
|
392
|
+
* enableHotReload();
|
|
393
|
+
* showDebugInfo();
|
|
394
|
+
* }
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
$isDevelopment() {
|
|
398
|
+
return this.__env__ === "development";
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Check if the current environment is staging.
|
|
402
|
+
* Compares __env__ against "staging" (case-sensitive).
|
|
403
|
+
*
|
|
404
|
+
* @returns {boolean} True if environment is staging
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* if (__sys__$isStaging()) {
|
|
409
|
+
* console.log('Running in staging mode');
|
|
410
|
+
* // Use staging configurations
|
|
411
|
+
* }
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
$isStaging() {
|
|
415
|
+
return this.__env__ === "staging";
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Check if the current environment is test.
|
|
419
|
+
* Compares __env__ against "test" (case-sensitive).
|
|
420
|
+
*
|
|
421
|
+
* @returns {boolean} True if environment is test
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```typescript
|
|
425
|
+
* if (__sys__$isTest()) {
|
|
426
|
+
* console.log('Running in test mode');
|
|
427
|
+
* // Use test database
|
|
428
|
+
* useTestDatabase();
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
$isTest() {
|
|
433
|
+
return this.__env__ === "test";
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Check if environment matches a custom environment name.
|
|
437
|
+
* Performs case-sensitive comparison.
|
|
438
|
+
*
|
|
439
|
+
* @param {string} envName - Environment name to check against
|
|
440
|
+
* @returns {boolean} True if current environment matches the provided name
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* if (__sys__$isEnvironment('qa')) {
|
|
445
|
+
* console.log('Running in QA environment');
|
|
446
|
+
* }
|
|
447
|
+
*
|
|
448
|
+
* if (__sys__$isEnvironment('local')) {
|
|
449
|
+
* // Local development specific code
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
$isEnvironment(envName) {
|
|
454
|
+
return this.__env__ === envName;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Get a system variable with an optional default value.
|
|
458
|
+
* Type-safe retrieval with generic type parameter support.
|
|
459
|
+
*
|
|
460
|
+
* @template T - Expected type of the return value
|
|
461
|
+
* @param {string} key - Variable name to retrieve
|
|
462
|
+
* @param {T} [defaultValue] - Default value if variable doesn't exist
|
|
463
|
+
* @returns {T} The variable value or default value
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* // Get with type inference
|
|
468
|
+
* const port = __sys__$get<number>('__port__', 3000);
|
|
469
|
+
* const name = __sys__$get<string>('__name__', 'default-app');
|
|
470
|
+
*
|
|
471
|
+
* // Get complex types
|
|
472
|
+
* interface AppConfig {
|
|
473
|
+
* theme: string;
|
|
474
|
+
* features: string[];
|
|
475
|
+
* }
|
|
476
|
+
* const config = __sys__$get<AppConfig>('config', {
|
|
477
|
+
* theme: 'light',
|
|
478
|
+
* features: []
|
|
479
|
+
* });
|
|
480
|
+
*
|
|
481
|
+
* // Works with undefined variables
|
|
482
|
+
* const missing = __sys__$get('nonexistent', 'fallback'); // 'fallback'
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
$get(key, defaultValue) {
|
|
486
|
+
return (this[key] !== undefined ? this[key] : defaultValue);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Check if a system variable exists.
|
|
490
|
+
* Returns true even if the value is falsy (null, false, 0, empty string).
|
|
491
|
+
*
|
|
492
|
+
* @param {string} key - Variable name to check
|
|
493
|
+
* @returns {boolean} True if variable exists (even if falsy)
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* __sys__$add('enabled', false);
|
|
498
|
+
* __sys__$add('count', 0);
|
|
499
|
+
* __sys__$add('name', '');
|
|
500
|
+
*
|
|
501
|
+
* console.log(__sys__$has('enabled')); // true (even though value is false)
|
|
502
|
+
* console.log(__sys__$has('count')); // true (even though value is 0)
|
|
503
|
+
* console.log(__sys__$has('name')); // true (even though value is '')
|
|
504
|
+
* console.log(__sys__$has('missing')); // false
|
|
505
|
+
*
|
|
506
|
+
* // Conditional logic
|
|
507
|
+
* if (__sys__$has('apiKey')) {
|
|
508
|
+
* const apiKey = __sys__$get('apiKey');
|
|
509
|
+
* initializeAPI(apiKey);
|
|
510
|
+
* }
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
$has(key) {
|
|
514
|
+
return this[key] !== undefined;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Get all system variable keys.
|
|
518
|
+
* Excludes internal methods and the __ENV__ manager.
|
|
519
|
+
*
|
|
520
|
+
* @returns {string[]} Array of all variable names
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const keys = __sys__$keys();
|
|
525
|
+
* console.log(keys); // ['__version__', '__author__', '__port__', ...]
|
|
526
|
+
*
|
|
527
|
+
* // Iterate over all variables
|
|
528
|
+
* keys.forEach(key => {
|
|
529
|
+
* console.log(`${key}: ${__sys__$get(key)}`);
|
|
530
|
+
* });
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
$keys() {
|
|
534
|
+
return Object.keys(this).filter((key) => !key.startsWith("$") &&
|
|
535
|
+
typeof this[key] !== "function" &&
|
|
536
|
+
key !== "__ENV__");
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Reset all system variables to default values.
|
|
540
|
+
* Preserves the __ENV__ manager instance.
|
|
541
|
+
*
|
|
542
|
+
* @returns {void}
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* __sys__$add('customVar', 'custom');
|
|
547
|
+
* __sys____version__ = "2.0.0";
|
|
548
|
+
*
|
|
549
|
+
* __sys__$reset();
|
|
550
|
+
*
|
|
551
|
+
* console.log(__sys____version__); // "0.0.0" (default)
|
|
552
|
+
* console.log(__sys__$has('customVar')); // false
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
$reset() {
|
|
556
|
+
// Store __ENV__ reference
|
|
557
|
+
const envManager = this.__ENV__;
|
|
558
|
+
// Clear all properties
|
|
559
|
+
Object.keys(this).forEach((key) => {
|
|
560
|
+
if (key !== "__ENV__" && !key.startsWith("$")) {
|
|
561
|
+
delete this[key];
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
// Restore defaults
|
|
565
|
+
this.__version__ = "0.0.0";
|
|
566
|
+
this.__author__ = "unknown";
|
|
567
|
+
this.__app_urls__ = {};
|
|
568
|
+
this.__name__ = "xypriss-app";
|
|
569
|
+
this.__alias__ = "app";
|
|
570
|
+
this.__port__ = 3000;
|
|
571
|
+
this.__PORT__ = 3000;
|
|
572
|
+
this.__env__ = "development";
|
|
573
|
+
this.__ENV__ = envManager;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Clone the current system configuration.
|
|
577
|
+
* Creates a new instance with the same variable values.
|
|
578
|
+
*
|
|
579
|
+
* @returns {XyPrissSys} New instance with cloned values
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* const sys1 = new XyPrissSys({ __version__: "1.0.0" });
|
|
584
|
+
* const sys2 = sys1.$clone();
|
|
585
|
+
*
|
|
586
|
+
* sys2.__version__ = "2.0.0";
|
|
587
|
+
*
|
|
588
|
+
* console.log(sys1.__version__); // "1.0.0" (unchanged)
|
|
589
|
+
* console.log(sys2.__version__); // "2.0.0"
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
$clone() {
|
|
593
|
+
return new XyPrissSys(this.$toJSON());
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
export { XyPrissSys };
|
|
598
|
+
//# sourceMappingURL=sys.js.map
|
|
@@ -0,0 +1 @@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