-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(config): add NestJS-inspired configuration system(rikta config similarity) #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4ab1cf9
9c0f614
e7b3aaf
9d70ef5
6acd372
56d0f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2724,35 +2724,16 @@ impl HealthController { | |
| .to_string() | ||
| } | ||
|
|
||
| fn template_app_config_rs(transport: AppTransport) -> String { | ||
| let default_app_name = match transport { | ||
| AppTransport::Http => "NestForge HTTP", | ||
| AppTransport::Graphql => "NestForge GraphQL", | ||
| AppTransport::Grpc => "NestForge gRPC", | ||
| AppTransport::Websockets => "NestForge WebSockets", | ||
| AppTransport::Microservices => "NestForge Microservices", | ||
| }; | ||
|
|
||
| format!( | ||
| r#"use nestforge::{{prelude::*, ConfigModule, ConfigOptions}}; | ||
|
|
||
| #[injectable(factory = load_app_config)] | ||
| pub struct AppConfig {{ | ||
| pub app_name: String, | ||
| }} | ||
| fn template_app_config_rs(_transport: AppTransport) -> String { | ||
| r#"use nestforge_config::{ConfigService, ConfigModule}; | ||
|
|
||
| fn load_app_config() -> anyhow::Result<AppConfig> {{ | ||
| Ok(ConfigModule::for_root::<AppConfig>(ConfigOptions::new().env_file(".env"))?) | ||
| }} | ||
| pub type AppConfig = ConfigService; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This changes the generated Useful? React with 👍 / 👎. |
||
|
|
||
| impl nestforge::FromEnv for AppConfig {{ | ||
| fn from_env(env: &nestforge::EnvStore) -> Result<Self, nestforge::ConfigError> {{ | ||
| let app_name = env.get("APP_NAME").unwrap_or("{default_app_name}").to_string(); | ||
| Ok(Self {{ app_name }}) | ||
| }} | ||
| }} | ||
| pub fn load_config() -> AppConfig { | ||
| ConfigModule::for_root_with_options(ConfigModule::for_root().env_file(".env")) | ||
| } | ||
|
Comment on lines
+2727
to
+2734
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Scaffolded app won't compile The CLI now generates app_config.rs that imports nestforge_config directly and defines AppConfig = ConfigService, but the generated Cargo.toml doesn’t add a nestforge-config dependency and other templates still register/consume AppConfig as if it were a struct (register_injectable::<AppConfig>, config.app_name), causing immediate compilation failures in new projects. Agent Prompt
|
||
| "# | ||
| ) | ||
| .to_string() | ||
|
Comment on lines
+2727
to
+2736
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This generated Line 2728 switches the template to 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| fn template_graphql_schema_rs() -> String { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ categories = ["config"] | |
|
|
||
| [dependencies] | ||
| thiserror = { workspace = true } | ||
| dotenvy = "0.15" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,60 @@ | ||
| # nestforge-config | ||
|
|
||
| Environment configuration loading and validation utilities for NestForge. | ||
| A NestJS-inspired configuration module for NestForge applications. | ||
|
|
||
| - Repository: https://github.com/vernonthedev/nestforge | ||
| - Docs: https://github.com/vernonthedev/nestforge/wiki | ||
| ## Features | ||
|
|
||
| - **Type-safe configuration** - Get typed values from environment variables | ||
| - **NestJS-like API** - Familiar patterns for NestJS developers | ||
| - **DI Integration** - Seamlessly works with NestForge's dependency injection | ||
| - **Simple getters** - No unwrap_or chains, just `get_string_or("KEY", "default")` | ||
| - **Dotenv support** - Automatic loading from `.env` files | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```rust | ||
| use nestforge_config::{ConfigService, ConfigModule}; | ||
|
|
||
| pub type AppConfig = ConfigService; | ||
|
|
||
| pub fn load_config() -> AppConfig { | ||
| ConfigModule::for_root_with_options(ConfigModule::for_root().env_file(".env")) | ||
| } | ||
|
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check the actual for_root method signature and usage
ast-grep --pattern 'fn for_root($$$) -> $_ {
$$$
}'
# Check how ConfigOptions is created
rg 'ConfigModule::for_root\(' --type=rust
rg 'ConfigOptions::new\(\)' --type=rustRepository: vernonthedev/nestforge Length of output: 1225 🏁 Script executed: # Check the ConfigModule::for_root() method signature and what it returns
ast-grep --pattern 'impl ConfigModule {
$$$
fn for_root($$$) {
$$$
}
$$$
}'
# Also check for ConfigModule::for_root_with_options signature
ast-grep --pattern 'fn for_root_with_options($$$) {
$$$
}'Repository: vernonthedev/nestforge Length of output: 48 🏁 Script executed: # Get the README.md content around lines 20-22 for full context
sed -n '15,30p' crates/nestforge-config/README.mdRepository: vernonthedev/nestforge Length of output: 373 🏁 Script executed: # Check what ConfigModule::for_root() actually returns by looking at the implementation
rg -A 5 'fn for_root\(' crates/nestforge-config/src/lib.rs --type=rustRepository: vernonthedev/nestforge Length of output: 308 Standardize configuration initialization pattern across documentation and examples. The example code is correct— 🤖 Prompt for AI Agents |
||
| ``` | ||
|
|
||
| ## Usage in Services | ||
|
|
||
| ```rust | ||
| use nestforge::prelude::*; | ||
|
|
||
| pub struct MyService { | ||
| config: Config<AppConfig>, | ||
| } | ||
|
|
||
| impl MyService { | ||
| pub fn do_something(&self) { | ||
| let app_name = self.config.get_string_or("APP_NAME", "My App"); | ||
| let port = self.config.get_u16_or("PORT", 3000); | ||
| let debug = self.config.get_bool_or("DEBUG", false); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Available Methods | ||
|
|
||
| | Method | Description | | ||
| |--------|-------------| | ||
| | `get_string("KEY")` | Get string (default: `""`) | | ||
| | `get_string_or("KEY", "default")` | Get with default | | ||
| | `get_u16("KEY")` | Get u16 (default: `0`) | | ||
| | `get_u16_or("KEY", 3000)` | Get with default | | ||
| | `get_bool("KEY")` | Get bool (default: `false`) | | ||
| | `get_bool_or("KEY", true)` | Get with default | | ||
| | `get("KEY")` | Get `Option<&str>` | | ||
| | `has("KEY")` | Check if key exists | | ||
|
|
||
| ## Resources | ||
|
|
||
| - [Documentation](https://github.com/vernonthedev/nestforge/wiki) | ||
| - [Examples](https://github.com/vernonthedev/nestforge/tree/main/examples) | ||
| - [Discord Community](https://discord.gg/nestforge) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: vernonthedev/nestforge
Length of output: 98
🏁 Script executed:
Repository: vernonthedev/nestforge
Length of output: 179
🏁 Script executed:
Repository: vernonthedev/nestforge
Length of output: 14611
🏁 Script executed:
Repository: vernonthedev/nestforge
Length of output: 639
🏁 Script executed:
Repository: vernonthedev/nestforge
Length of output: 432
Remove unused
validatordependency.The
validatorcrate is declared as a workspace dependency but is never used. The codebase implements a custom validation system with theValidatetrait and#[derive(Validate)]macro instead.🤖 Prompt for AI Agents