xypriss 4.3.6 → 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/dist/index.d.ts CHANGED
@@ -3559,6 +3559,526 @@ interface RouteOptions {
3559
3559
  };
3560
3560
  }
3561
3561
 
3562
+ /**
3563
+ * XyPriss System Variables Class
3564
+ *
3565
+ * Provides centralized access to system variables, configuration management,
3566
+ * and environment utilities for XyPriss applications. This class serves as
3567
+ * a type-safe wrapper around system configuration with built-in helpers
3568
+ * for common operations.
3569
+ *
3570
+ * @class XyPrissSys
3571
+ * @version 1.0.0
3572
+ *
3573
+ * @example
3574
+ * ```typescript
3575
+ * // Initialize with default values
3576
+ * const sys = new XyPrissSys({
3577
+ * __version__: "1.0.0",
3578
+ * __author__: "John Doe",
3579
+ * __port__: 8080,
3580
+ * __env__: "production"
3581
+ * });
3582
+ *
3583
+ * // Check environment
3584
+ * if (__sys__$isProduction()) {
3585
+ * console.log('Running in production mode');
3586
+ * }
3587
+ *
3588
+ * // Access variables
3589
+ * const port = __sys__$get('__port__', 3000);
3590
+ * ```
3591
+ */
3592
+ declare class XyPrissSys {
3593
+ /**
3594
+ * Application version string following semantic versioning.
3595
+ *
3596
+ * @type {string}
3597
+ * @default "0.0.0"
3598
+ *
3599
+ * @example
3600
+ * ```typescript
3601
+ * __sys____version__ = "1.2.3";
3602
+ * console.log(`App version: ${__sys____version__}`);
3603
+ * ```
3604
+ */
3605
+ __version__: string;
3606
+ /**
3607
+ * Application author or maintainer name.
3608
+ *
3609
+ * @type {string}
3610
+ * @default "unknown"
3611
+ *
3612
+ * @example
3613
+ * ```typescript
3614
+ * __sys____author__ = "Jane Smith";
3615
+ * ```
3616
+ */
3617
+ __author__: string;
3618
+ /**
3619
+ * Collection of application URLs for various environments or services.
3620
+ * Useful for storing API endpoints, frontend URLs, or external service links.
3621
+ *
3622
+ * @type {Record<string, string>}
3623
+ * @default {}
3624
+ *
3625
+ * @example
3626
+ * ```typescript
3627
+ * __sys____app_urls__ = {
3628
+ * api: "https://api.example.com",
3629
+ * frontend: "https://app.example.com",
3630
+ * docs: "https://docs.example.com"
3631
+ * };
3632
+ *
3633
+ * const apiUrl = __sys____app_urls__.api;
3634
+ * ```
3635
+ */
3636
+ __app_urls__: Record<string, string>;
3637
+ /**
3638
+ * Application name identifier.
3639
+ *
3640
+ * @type {string}
3641
+ * @default "xypriss-app"
3642
+ *
3643
+ * @example
3644
+ * ```typescript
3645
+ * __sys____name__ = "my-awesome-app";
3646
+ * ```
3647
+ */
3648
+ __name__: string;
3649
+ /**
3650
+ * Application alias or short name.
3651
+ * Used for abbreviated references or CLI commands.
3652
+ *
3653
+ * @type {string}
3654
+ * @default "app"
3655
+ *
3656
+ * @example
3657
+ * ```typescript
3658
+ * __sys____alias__ = "myapp";
3659
+ * ```
3660
+ */
3661
+ __alias__: string;
3662
+ /**
3663
+ * Server port number (lowercase variant).
3664
+ * Synchronized automatically with __PORT__.
3665
+ *
3666
+ * @type {number}
3667
+ * @default 3000
3668
+ *
3669
+ * @example
3670
+ * ```typescript
3671
+ * __sys____port__ = 8080;
3672
+ * console.log(__sys____PORT__); // Also 8080 (auto-synced)
3673
+ * ```
3674
+ */
3675
+ __port__: number;
3676
+ /**
3677
+ * Server port number (uppercase variant).
3678
+ * Synchronized automatically with __port__.
3679
+ *
3680
+ * @type {number}
3681
+ * @default 3000
3682
+ *
3683
+ * @example
3684
+ * ```typescript
3685
+ * __sys____PORT__ = 5000;
3686
+ * console.log(__sys____port__); // Also 5000 (auto-synced)
3687
+ * ```
3688
+ */
3689
+ __PORT__: number;
3690
+ /**
3691
+ * Current environment mode.
3692
+ * Typically "development", "production", "staging", or "test".
3693
+ *
3694
+ * @type {string}
3695
+ * @default "development"
3696
+ *
3697
+ * @example
3698
+ * ```typescript
3699
+ * __sys____env__ = "production";
3700
+ * if (__sys__$isProduction()) {
3701
+ * // Production-specific logic
3702
+ * }
3703
+ * ```
3704
+ */
3705
+ __env__: string;
3706
+ /**
3707
+ * Environment variables manager providing access to process.env.
3708
+ * Offers a clean API for getting, setting, and managing environment variables.
3709
+ *
3710
+ * @type {Object}
3711
+ * @property {Function} set - Set an environment variable
3712
+ * @property {Function} get - Get an environment variable with optional default
3713
+ * @property {Function} has - Check if an environment variable exists
3714
+ * @property {Function} delete - Remove an environment variable
3715
+ * @property {Function} all - Get all environment variables
3716
+ *
3717
+ * @example
3718
+ * ```typescript
3719
+ * // Set environment variable
3720
+ * __sys____ENV__.set('API_KEY', 'secret123');
3721
+ *
3722
+ * // Get with default
3723
+ * const apiKey = __sys____ENV__.get('API_KEY', 'default-key');
3724
+ *
3725
+ * // Check existence
3726
+ * if (__sys____ENV__.has('DATABASE_URL')) {
3727
+ * const dbUrl = __sys____ENV__.get('DATABASE_URL');
3728
+ * }
3729
+ *
3730
+ * // Delete variable
3731
+ * __sys____ENV__.delete('TEMP_VAR');
3732
+ *
3733
+ * // Get all variables
3734
+ * const allEnv = __sys____ENV__.all();
3735
+ * ```
3736
+ */
3737
+ __ENV__: {
3738
+ /**
3739
+ * Set an environment variable.
3740
+ *
3741
+ * @param {string} key - The environment variable name
3742
+ * @param {string} value - The value to set
3743
+ * @returns {void}
3744
+ */
3745
+ set: (key: string, value: string) => void;
3746
+ /**
3747
+ * Get an environment variable with an optional default value.
3748
+ *
3749
+ * @param {string} key - The environment variable name
3750
+ * @param {string} [defaultValue] - Default value if variable is not set
3751
+ * @returns {string | undefined} The environment variable value or default
3752
+ */
3753
+ get: (key: string, defaultValue?: string) => string | undefined;
3754
+ /**
3755
+ * Check if an environment variable exists.
3756
+ *
3757
+ * @param {string} key - The environment variable name
3758
+ * @returns {boolean} True if the variable exists
3759
+ */
3760
+ has: (key: string) => boolean;
3761
+ /**
3762
+ * Delete an environment variable.
3763
+ *
3764
+ * @param {string} key - The environment variable name
3765
+ * @returns {void}
3766
+ */
3767
+ delete: (key: string) => void;
3768
+ /**
3769
+ * Get all environment variables.
3770
+ *
3771
+ * @returns {NodeJS.ProcessEnv} All environment variables
3772
+ */
3773
+ all: () => NodeJS.ProcessEnv;
3774
+ };
3775
+ /**
3776
+ * Index signature allowing dynamic property assignment.
3777
+ * Enables flexible extension of system variables at runtime.
3778
+ *
3779
+ * @example
3780
+ * ```typescript
3781
+ * sys['customProperty'] = 'custom value';
3782
+ * __sys__$add('anotherProperty', 123);
3783
+ * ```
3784
+ */
3785
+ [key: string]: any;
3786
+ /**
3787
+ * Creates a new XyPrissSys instance with optional initial data.
3788
+ * All port-related properties are automatically synchronized.
3789
+ *
3790
+ * @constructor
3791
+ * @param {Record<string, any>} [data={}] - Initial system variable data
3792
+ *
3793
+ * @example
3794
+ * ```typescript
3795
+ * // Create with defaults
3796
+ * const sys = new XyPrissSys();
3797
+ *
3798
+ * // Create with custom data
3799
+ * const sys = new XyPrissSys({
3800
+ * __version__: "2.0.0",
3801
+ * __author__: "Development Team",
3802
+ * __port__: 8080,
3803
+ * __env__: "production",
3804
+ * customVar: "custom value"
3805
+ * });
3806
+ * ```
3807
+ */
3808
+ constructor(data?: Record<string, any>);
3809
+ /**
3810
+ * Update system variables with new data.
3811
+ * Automatically synchronizes __port__ and __PORT__ to maintain consistency.
3812
+ * Supports backward compatibility for legacy single-underscore variants.
3813
+ *
3814
+ * @param {Record<string, any>} data - Partial data to merge into system variables
3815
+ * @returns {void}
3816
+ *
3817
+ * @example
3818
+ * ```typescript
3819
+ * __sys__$update({
3820
+ * __version__: "1.5.0",
3821
+ * __port__: 9000,
3822
+ * newFeature: true
3823
+ * });
3824
+ *
3825
+ * // Port is automatically synced
3826
+ * console.log(__sys____port__); // 9000
3827
+ * console.log(__sys____PORT__); // 9000
3828
+ * ```
3829
+ */
3830
+ $update(data: Record<string, any>): void;
3831
+ /**
3832
+ * Add or update a single system variable.
3833
+ * Provides a cleaner API for adding individual properties.
3834
+ *
3835
+ * @param {string} key - Variable name
3836
+ * @param {any} value - Variable value (any type)
3837
+ * @returns {void}
3838
+ *
3839
+ * @example
3840
+ * ```typescript
3841
+ * __sys__$add('databaseUrl', 'postgresql://localhost:5432/mydb');
3842
+ * __sys__$add('maxConnections', 100);
3843
+ * __sys__$add('features', { darkMode: true, beta: false });
3844
+ *
3845
+ * console.log(__sys__databaseUrl); // 'postgresql://localhost:5432/mydb'
3846
+ * console.log(__sys__maxConnections); // 100
3847
+ * ```
3848
+ */
3849
+ $add(key: string, value: any): void;
3850
+ /**
3851
+ * Remove a system variable.
3852
+ *
3853
+ * @param {string} key - Variable name to remove
3854
+ * @returns {boolean} True if the variable existed and was removed
3855
+ *
3856
+ * @example
3857
+ * ```typescript
3858
+ * __sys__$add('tempVar', 'temporary');
3859
+ * console.log(__sys__$has('tempVar')); // true
3860
+ *
3861
+ * __sys__$remove('tempVar');
3862
+ * console.log(__sys__$has('tempVar')); // false
3863
+ * ```
3864
+ */
3865
+ $remove(key: string): boolean;
3866
+ /**
3867
+ * Export all system variables as a plain JavaScript object.
3868
+ * Excludes internal methods (starting with $) and the __ENV__ manager.
3869
+ * Useful for serialization, logging, or persistence.
3870
+ *
3871
+ * @returns {Record<string, any>} Plain object containing all system variables
3872
+ *
3873
+ * @example
3874
+ * ```typescript
3875
+ * const config = __sys__$toJSON();
3876
+ * console.log(JSON.stringify(config, null, 2));
3877
+ *
3878
+ * // Save to file
3879
+ * fs.writeFileSync('config.json', JSON.stringify(config, null, 2));
3880
+ *
3881
+ * // Send in API response
3882
+ * res.json({ system: config });
3883
+ * ```
3884
+ */
3885
+ $toJSON(): Record<string, any>;
3886
+ /**
3887
+ * Check if the current environment is production.
3888
+ * Compares __env__ against "production" (case-sensitive).
3889
+ *
3890
+ * @returns {boolean} True if environment is production
3891
+ *
3892
+ * @example
3893
+ * ```typescript
3894
+ * if (__sys__$isProduction()) {
3895
+ * console.log('Running in production mode');
3896
+ * // Enable production optimizations
3897
+ * enableCaching();
3898
+ * disableDebugMode();
3899
+ * }
3900
+ * ```
3901
+ */
3902
+ $isProduction(): boolean;
3903
+ /**
3904
+ * Check if the current environment is development.
3905
+ * Compares __env__ against "development" (case-sensitive).
3906
+ *
3907
+ * @returns {boolean} True if environment is development
3908
+ *
3909
+ * @example
3910
+ * ```typescript
3911
+ * if (__sys__$isDevelopment()) {
3912
+ * console.log('Running in development mode');
3913
+ * // Enable development features
3914
+ * enableHotReload();
3915
+ * showDebugInfo();
3916
+ * }
3917
+ * ```
3918
+ */
3919
+ $isDevelopment(): boolean;
3920
+ /**
3921
+ * Check if the current environment is staging.
3922
+ * Compares __env__ against "staging" (case-sensitive).
3923
+ *
3924
+ * @returns {boolean} True if environment is staging
3925
+ *
3926
+ * @example
3927
+ * ```typescript
3928
+ * if (__sys__$isStaging()) {
3929
+ * console.log('Running in staging mode');
3930
+ * // Use staging configurations
3931
+ * }
3932
+ * ```
3933
+ */
3934
+ $isStaging(): boolean;
3935
+ /**
3936
+ * Check if the current environment is test.
3937
+ * Compares __env__ against "test" (case-sensitive).
3938
+ *
3939
+ * @returns {boolean} True if environment is test
3940
+ *
3941
+ * @example
3942
+ * ```typescript
3943
+ * if (__sys__$isTest()) {
3944
+ * console.log('Running in test mode');
3945
+ * // Use test database
3946
+ * useTestDatabase();
3947
+ * }
3948
+ * ```
3949
+ */
3950
+ $isTest(): boolean;
3951
+ /**
3952
+ * Check if environment matches a custom environment name.
3953
+ * Performs case-sensitive comparison.
3954
+ *
3955
+ * @param {string} envName - Environment name to check against
3956
+ * @returns {boolean} True if current environment matches the provided name
3957
+ *
3958
+ * @example
3959
+ * ```typescript
3960
+ * if (__sys__$isEnvironment('qa')) {
3961
+ * console.log('Running in QA environment');
3962
+ * }
3963
+ *
3964
+ * if (__sys__$isEnvironment('local')) {
3965
+ * // Local development specific code
3966
+ * }
3967
+ * ```
3968
+ */
3969
+ $isEnvironment(envName: string): boolean;
3970
+ /**
3971
+ * Get a system variable with an optional default value.
3972
+ * Type-safe retrieval with generic type parameter support.
3973
+ *
3974
+ * @template T - Expected type of the return value
3975
+ * @param {string} key - Variable name to retrieve
3976
+ * @param {T} [defaultValue] - Default value if variable doesn't exist
3977
+ * @returns {T} The variable value or default value
3978
+ *
3979
+ * @example
3980
+ * ```typescript
3981
+ * // Get with type inference
3982
+ * const port = __sys__$get<number>('__port__', 3000);
3983
+ * const name = __sys__$get<string>('__name__', 'default-app');
3984
+ *
3985
+ * // Get complex types
3986
+ * interface AppConfig {
3987
+ * theme: string;
3988
+ * features: string[];
3989
+ * }
3990
+ * const config = __sys__$get<AppConfig>('config', {
3991
+ * theme: 'light',
3992
+ * features: []
3993
+ * });
3994
+ *
3995
+ * // Works with undefined variables
3996
+ * const missing = __sys__$get('nonexistent', 'fallback'); // 'fallback'
3997
+ * ```
3998
+ */
3999
+ $get<T = any>(key: string, defaultValue?: T): T;
4000
+ /**
4001
+ * Check if a system variable exists.
4002
+ * Returns true even if the value is falsy (null, false, 0, empty string).
4003
+ *
4004
+ * @param {string} key - Variable name to check
4005
+ * @returns {boolean} True if variable exists (even if falsy)
4006
+ *
4007
+ * @example
4008
+ * ```typescript
4009
+ * __sys__$add('enabled', false);
4010
+ * __sys__$add('count', 0);
4011
+ * __sys__$add('name', '');
4012
+ *
4013
+ * console.log(__sys__$has('enabled')); // true (even though value is false)
4014
+ * console.log(__sys__$has('count')); // true (even though value is 0)
4015
+ * console.log(__sys__$has('name')); // true (even though value is '')
4016
+ * console.log(__sys__$has('missing')); // false
4017
+ *
4018
+ * // Conditional logic
4019
+ * if (__sys__$has('apiKey')) {
4020
+ * const apiKey = __sys__$get('apiKey');
4021
+ * initializeAPI(apiKey);
4022
+ * }
4023
+ * ```
4024
+ */
4025
+ $has(key: string): boolean;
4026
+ /**
4027
+ * Get all system variable keys.
4028
+ * Excludes internal methods and the __ENV__ manager.
4029
+ *
4030
+ * @returns {string[]} Array of all variable names
4031
+ *
4032
+ * @example
4033
+ * ```typescript
4034
+ * const keys = __sys__$keys();
4035
+ * console.log(keys); // ['__version__', '__author__', '__port__', ...]
4036
+ *
4037
+ * // Iterate over all variables
4038
+ * keys.forEach(key => {
4039
+ * console.log(`${key}: ${__sys__$get(key)}`);
4040
+ * });
4041
+ * ```
4042
+ */
4043
+ $keys(): string[];
4044
+ /**
4045
+ * Reset all system variables to default values.
4046
+ * Preserves the __ENV__ manager instance.
4047
+ *
4048
+ * @returns {void}
4049
+ *
4050
+ * @example
4051
+ * ```typescript
4052
+ * __sys__$add('customVar', 'custom');
4053
+ * __sys____version__ = "2.0.0";
4054
+ *
4055
+ * __sys__$reset();
4056
+ *
4057
+ * console.log(__sys____version__); // "0.0.0" (default)
4058
+ * console.log(__sys__$has('customVar')); // false
4059
+ * ```
4060
+ */
4061
+ $reset(): void;
4062
+ /**
4063
+ * Clone the current system configuration.
4064
+ * Creates a new instance with the same variable values.
4065
+ *
4066
+ * @returns {XyPrissSys} New instance with cloned values
4067
+ *
4068
+ * @example
4069
+ * ```typescript
4070
+ * const sys1 = new XyPrissSys({ __version__: "1.0.0" });
4071
+ * const sys2 = sys1.$clone();
4072
+ *
4073
+ * sys2.__version__ = "2.0.0";
4074
+ *
4075
+ * console.log(sys1.__version__); // "1.0.0" (unchanged)
4076
+ * console.log(sys2.__version__); // "2.0.0"
4077
+ * ```
4078
+ */
4079
+ $clone(): XyPrissSys;
4080
+ }
4081
+
3562
4082
  /**
3563
4083
  * @fileoverview Main export file for XyPrissJS Express integration types
3564
4084
  *
@@ -3591,7 +4111,12 @@ declare global {
3591
4111
  stdio?: string[];
3592
4112
  }) => BunSubprocess;
3593
4113
  };
4114
+ /**
4115
+ * Global system variables for XyPriss applications
4116
+ */
4117
+ var __sys__: XyPrissSys;
3594
4118
  }
4119
+
3595
4120
  type BunSubprocess = {
3596
4121
  exited: Promise<number | null>;
3597
4122
  kill: (signal?: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xypriss",
3
- "version": "4.3.6",
3
+ "version": "4.4.0",
4
4
  "description": "XyPriss is a lightweight, TypeScript-first, open-source Node.js web framework crafted for developers seeking a familiar Express-like API without Express dependencies. It features built-in security middleware, a robust routing system, and performance optimizations to build scalable, secure web applications effortlessly. Join our community and contribute on GitHub!",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",