@onebun/envs 0.1.3 → 0.1.4
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/package.json +1 -1
- package/src/types.ts +28 -0
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -113,3 +113,31 @@ export interface EnvLoadOptions {
|
|
|
113
113
|
*/
|
|
114
114
|
valueOverrides?: Record<string, string | number | boolean>;
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Infer config type from EnvSchema.
|
|
119
|
+
* Recursively extracts value types from EnvVariableConfig at any depth.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* const schema = {
|
|
123
|
+
* server: {
|
|
124
|
+
* port: Env.number({ default: 3000 }),
|
|
125
|
+
* host: Env.string({ default: '0.0.0.0' }),
|
|
126
|
+
* },
|
|
127
|
+
* database: {
|
|
128
|
+
* connection: {
|
|
129
|
+
* host: Env.string({ default: 'localhost' }),
|
|
130
|
+
* ssl: { enabled: Env.boolean({ default: true }) },
|
|
131
|
+
* },
|
|
132
|
+
* },
|
|
133
|
+
* };
|
|
134
|
+
* type Config = InferConfigType<typeof schema>;
|
|
135
|
+
* // { server: { port: number; host: string }; database: { connection: { host: string; ssl: { enabled: boolean } } } }
|
|
136
|
+
*/
|
|
137
|
+
export type InferConfigType<S> = {
|
|
138
|
+
[K in keyof S]: S[K] extends EnvVariableConfig<infer T>
|
|
139
|
+
? T
|
|
140
|
+
: S[K] extends Record<string, unknown>
|
|
141
|
+
? InferConfigType<S[K]>
|
|
142
|
+
: never;
|
|
143
|
+
};
|