@onebun/envs 0.1.0 → 0.1.2

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 (2) hide show
  1. package/README.md +47 -14
  2. package/package.json +12 -2
package/README.md CHANGED
@@ -167,23 +167,56 @@ const schema = {
167
167
 
168
168
  ### Nested Configuration
169
169
 
170
+ For nested schemas, use `EnvSchema<T>` type annotation for proper type inference:
171
+
170
172
  ```typescript
171
- const schema = {
173
+ import { TypedEnv, Env, type EnvSchema } from '@onebun/envs';
174
+
175
+ // Define the type structure for nested configuration
176
+ const schema: EnvSchema<{
172
177
  server: {
173
- http: {
174
- port: Env.number({ default: 3000 }),
175
- host: Env.string({ default: 'localhost' })
176
- },
177
- https: {
178
- port: Env.number({ default: 3443 }),
179
- cert: Env.string({ sensitive: true })
180
- }
181
- }
178
+ port: number;
179
+ host: string;
180
+ };
181
+ database: {
182
+ host: string;
183
+ password: string;
184
+ };
185
+ }> = {
186
+ server: {
187
+ port: Env.number({ default: 3000 }),
188
+ host: Env.string({ default: 'localhost' }),
189
+ },
190
+ database: {
191
+ host: Env.string({ default: '127.0.0.1' }),
192
+ password: Env.string({ sensitive: true }),
193
+ },
182
194
  };
183
195
 
184
- // Access nested values
185
- const httpPort = config.get('server.http.port');
186
- const httpsCert = config.get('server.https.cert');
196
+ const config = await TypedEnv.createAsync(schema);
197
+
198
+ // Access nested values with full type safety
199
+ const port = config.get('server.port'); // number
200
+ const dbHost = config.get('database.host'); // string
201
+ ```
202
+
203
+ **Environment Variable Naming:**
204
+
205
+ Nested paths are converted to uppercase with underscores:
206
+
207
+ | Schema Path | Environment Variable |
208
+ |-------------|---------------------|
209
+ | `server.port` | `SERVER_PORT` |
210
+ | `database.host` | `DATABASE_HOST` |
211
+ | `database.password` | `DATABASE_PASSWORD` |
212
+
213
+ You can override the auto-generated name with the `env` option:
214
+
215
+ ```typescript
216
+ port: Env.number({
217
+ default: 3000,
218
+ env: 'PORT' // Uses PORT instead of SERVER_PORT
219
+ })
187
220
  ```
188
221
 
189
222
  ## Error Handling
@@ -203,4 +236,4 @@ try {
203
236
 
204
237
  ## License
205
238
 
206
- MIT
239
+ [LGPL-3.0](../../LICENSE)
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@onebun/envs",
3
- "version": "0.1.0",
4
- "description": "Environment variables management package for OneBun framework",
3
+ "version": "0.1.2",
4
+ "description": "Environment variables management for OneBun framework - typed config with validation",
5
5
  "license": "LGPL-3.0",
6
6
  "author": "RemRyahirev",
7
+ "keywords": [
8
+ "onebun",
9
+ "environment",
10
+ "config",
11
+ "dotenv",
12
+ "validation",
13
+ "bun",
14
+ "typescript",
15
+ "effect"
16
+ ],
7
17
  "repository": {
8
18
  "type": "git",
9
19
  "url": "git+https://github.com/RemRyahirev/onebun.git",