@onebun/envs 0.1.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onebun/envs",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Environment variables management for OneBun framework - typed config with validation",
5
5
  "license": "LGPL-3.0",
6
6
  "author": "RemRyahirev",
package/src/helpers.ts CHANGED
@@ -242,7 +242,7 @@ export const Env = {
242
242
  */
243
243
  port(errorMessage?: string): (value: number) => Effect.Effect<number, EnvValidationError> {
244
244
  return (value: number) => {
245
- // eslint-disable-next-line no-magic-numbers
245
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
246
246
  if (!Number.isInteger(value) || value < 1 || value > 65535) {
247
247
  return Effect.fail(
248
248
  new EnvValidationError(
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
+ };