@e-n-v/env 0.0.2 → 0.0.5

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 (99) hide show
  1. package/README.md +43 -24
  2. package/dist/BooleanMap-B2eIP3tZ.d.cts +32 -0
  3. package/dist/BooleanMap-DmFnCA-O.d.ts +32 -0
  4. package/dist/EnvChannel-LMIRYvT1.d.cts +16 -0
  5. package/dist/EnvChannel-w27PEm7x.d.ts +16 -0
  6. package/dist/EnvChannelOptions-BPkWDrmr.d.cts +108 -0
  7. package/dist/EnvChannelOptions-CRwDLWjd.d.ts +108 -0
  8. package/dist/EnvModel-CrGclUpJ.d.cts +134 -0
  9. package/dist/EnvModel-D8rt0EJ6.d.ts +134 -0
  10. package/dist/EnvSource-BVnmdHku.cjs +420 -0
  11. package/dist/EnvSource-DA3ZGlES.js +400 -0
  12. package/dist/ProcessEnvChannel-D465c-dp.d.cts +97 -0
  13. package/dist/ProcessEnvChannel-Do4-yiLI.d.ts +97 -0
  14. package/dist/StringEnvVarSchema-B8MT7htU.d.ts +64 -0
  15. package/dist/StringEnvVarSchema-BF6C0nyT.d.cts +64 -0
  16. package/dist/channels.cjs +8 -0
  17. package/dist/channels.d.cts +20 -0
  18. package/dist/channels.d.ts +20 -0
  19. package/dist/channels.js +4 -0
  20. package/dist/chunk-pbleEpgJ.cjs +44 -0
  21. package/dist/cli.cjs +16 -10
  22. package/dist/cli.js +7 -2
  23. package/dist/coerce-DNIuYAx4.js +11028 -0
  24. package/dist/coerce-b7UVodS9.cjs +12365 -0
  25. package/dist/core.cjs +68 -0
  26. package/dist/core.d.cts +6 -0
  27. package/dist/core.d.ts +6 -0
  28. package/dist/core.js +40 -0
  29. package/dist/custom-Bt_wnxIu.js +114 -0
  30. package/dist/custom-D_Rqjm09.cjs +168 -0
  31. package/dist/files.cjs +18 -0
  32. package/dist/files.d.cts +38 -0
  33. package/dist/files.d.ts +38 -0
  34. package/dist/files.js +13 -0
  35. package/dist/index-D8pslhp4.d.cts +170 -0
  36. package/dist/index-Dq_0aeAL.d.ts +170 -0
  37. package/dist/model-Dic8IJsf.d.ts +29 -0
  38. package/dist/model-ft0WhSSS.d.cts +29 -0
  39. package/dist/model.cjs +14 -0
  40. package/dist/model.d.cts +35 -0
  41. package/dist/model.d.ts +35 -0
  42. package/dist/model.js +9 -0
  43. package/dist/parse-BT1QSa5e.d.cts +28 -0
  44. package/dist/parse-DwtLpVhC.d.ts +28 -0
  45. package/dist/parse.cjs +17 -0
  46. package/dist/parse.d.cts +52 -0
  47. package/dist/parse.d.ts +52 -0
  48. package/dist/parse.js +10 -0
  49. package/dist/prompt-C5WudV9x.d.cts +74 -0
  50. package/dist/prompt-yKdccbtZ.d.ts +74 -0
  51. package/dist/prompt.cjs +24 -0
  52. package/dist/prompt.d.cts +17 -0
  53. package/dist/prompt.d.ts +17 -0
  54. package/dist/prompt.js +12 -0
  55. package/dist/redis-CJOpRPjc.js +395 -0
  56. package/dist/redis-EcC7TX3K.cjs +611 -0
  57. package/dist/resolveChannel-CjAuxy3p.cjs +257 -0
  58. package/dist/resolveChannel-v9BDsw-M.js +224 -0
  59. package/dist/root.cjs +36 -0
  60. package/dist/root.d.cts +21 -0
  61. package/dist/root.d.ts +21 -0
  62. package/dist/root.js +21 -0
  63. package/dist/schema-DH4GiW9A.d.cts +18 -0
  64. package/dist/schema-jN4EtvEP.d.ts +18 -0
  65. package/dist/schemas/zod.cjs +629 -0
  66. package/dist/schemas/zod.d.cts +239 -0
  67. package/dist/schemas/zod.d.ts +239 -0
  68. package/dist/schemas/zod.js +550 -0
  69. package/dist/schemas.cjs +133 -0
  70. package/dist/schemas.d.cts +3 -0
  71. package/dist/schemas.d.ts +3 -0
  72. package/dist/schemas.js +6 -0
  73. package/dist/src-B7FG1rak.js +638 -0
  74. package/dist/src-BBwjK5SK.js +127 -0
  75. package/dist/src-CLTURaoo.js +311 -0
  76. package/dist/src-CVdUqK3q.js +850 -0
  77. package/dist/src-Cjo2XA4n.cjs +138 -0
  78. package/dist/{src-oetJm-nZ.cjs → src-DWYoqPX1.cjs} +31 -1964
  79. package/dist/src-DZmpNGrQ.cjs +1411 -0
  80. package/dist/{src-RlCvrI0s.js → src-Dtv7TlJx.js} +14 -1726
  81. package/dist/src-XjL5cyPG.cjs +873 -0
  82. package/dist/src-meUnCASg.cjs +413 -0
  83. package/dist/validate-BxA3a-ns.d.cts +203 -0
  84. package/dist/validate-CyxrRacF.d.ts +203 -0
  85. package/dist/vars-BNVI6k89.d.ts +21 -0
  86. package/dist/vars-CYOaskkK.cjs +27 -0
  87. package/dist/vars-CptZRPX5.d.cts +21 -0
  88. package/dist/vars-DOW0LiiN.js +22 -0
  89. package/dist/vars.cjs +138 -0
  90. package/dist/vars.d.cts +7 -0
  91. package/dist/vars.d.ts +7 -0
  92. package/dist/vars.js +9 -0
  93. package/package.json +58 -9
  94. package/assets/demo.gif +0 -0
  95. package/assets/env-logo.png +0 -0
  96. package/dist/bundle.cjs +0 -1290
  97. package/dist/bundle.d.cts +0 -1057
  98. package/dist/bundle.d.ts +0 -1055
  99. package/dist/bundle.js +0 -1244
@@ -0,0 +1,850 @@
1
+ import { a as isEnvVarSchema, c as EnumEnvVarSchema, l as BooleanEnvVarSchema, o as StringEnvVarSchema, s as NumberEnvVarSchema } from "./src-CLTURaoo.js";
2
+ import { Qr as safeParse, jn as stringbool, kn as string, n as number } from "./coerce-DNIuYAx4.js";
3
+
4
+ //#region ../converters/src/converters/zod/ZodV3Converter.ts
5
+ /**
6
+ * Zod v3 schema converter implementation
7
+ */
8
+ var ZodV3Converter = class {
9
+ applies(schema) {
10
+ return isZodV3Schema(schema);
11
+ }
12
+ convert(schema) {
13
+ return convertFromZodV3Schema(schema);
14
+ }
15
+ };
16
+ /**
17
+ * Check if a schema is a Zod v3 schema
18
+ */
19
+ function isZodV3Schema(schema) {
20
+ if (!schema || typeof schema !== "object") return false;
21
+ const candidate = schema;
22
+ return Boolean(candidate._def && !("_zod" in candidate) && (candidate._def.typeName || typeof candidate.parse === "function"));
23
+ }
24
+ /**
25
+ * Extract definition from Zod v3 schema
26
+ */
27
+ function getV3Def(schema) {
28
+ return schema._def || {};
29
+ }
30
+ /**
31
+ * Get the type name from a Zod v3 definition
32
+ */
33
+ function getV3TypeName(def) {
34
+ return def.typeName || "unknown";
35
+ }
36
+ /**
37
+ * Check if a type is a wrapper type that should be unwrapped
38
+ */
39
+ function isV3WrapperType(typeName) {
40
+ return [
41
+ "ZodOptional",
42
+ "ZodDefault",
43
+ "ZodEffects",
44
+ "ZodNullable",
45
+ "ZodNullish",
46
+ "ZodReadonly",
47
+ "ZodBranded",
48
+ "ZodCatch"
49
+ ].includes(typeName);
50
+ }
51
+ /**
52
+ * Get inner schema from wrapper
53
+ */
54
+ function getV3InnerSchema(def) {
55
+ return def.innerType || def.schema;
56
+ }
57
+ /**
58
+ * Get default value from definition
59
+ */
60
+ function getV3DefaultValue(def) {
61
+ if (def.defaultValue === void 0) return void 0;
62
+ return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
63
+ }
64
+ /**
65
+ * Extract enum values from schema
66
+ */
67
+ function extractV3EnumValues(def) {
68
+ if (!Array.isArray(def.values)) return void 0;
69
+ return def.values.map((v) => String(v));
70
+ }
71
+ /**
72
+ * Get description from schema
73
+ */
74
+ function getV3Description(schema, def) {
75
+ const directDesc = schema.description;
76
+ if (typeof directDesc === "string" && directDesc.length > 0) return directDesc;
77
+ if (typeof def.description === "string" && def.description.length > 0) return def.description;
78
+ }
79
+ /**
80
+ * Resolve environment variable type from schema
81
+ */
82
+ function resolveV3EnvVarType(schema) {
83
+ const def = getV3Def(schema);
84
+ switch (getV3TypeName(def)) {
85
+ case "ZodString": return "string";
86
+ case "ZodNumber": return "number";
87
+ case "ZodBoolean": return "boolean";
88
+ case "ZodEnum": return "enum";
89
+ default:
90
+ if (def.values) return "enum";
91
+ return "string";
92
+ }
93
+ }
94
+ function peelV3Schema(schema) {
95
+ let current = schema;
96
+ let required = true;
97
+ let defaultValue = void 0;
98
+ let description = void 0;
99
+ for (let i = 0; i < 20; i++) {
100
+ const def = getV3Def(current);
101
+ const typeName = getV3TypeName(def);
102
+ if (!description) description = getV3Description(current, def);
103
+ if (!isV3WrapperType(typeName)) break;
104
+ if (typeName === "ZodOptional" || typeName === "ZodNullish") required = false;
105
+ if (typeName === "ZodDefault" && defaultValue === void 0) defaultValue = getV3DefaultValue(def);
106
+ const inner = getV3InnerSchema(def);
107
+ if (!inner) break;
108
+ current = inner;
109
+ }
110
+ return {
111
+ schema: current,
112
+ required,
113
+ default: defaultValue,
114
+ description
115
+ };
116
+ }
117
+ /**
118
+ * Create a process function for Zod v3 schemas
119
+ */
120
+ function createV3ProcessFunction(schema, type) {
121
+ return (value) => {
122
+ try {
123
+ let processSchema = schema;
124
+ if (type === "number") processSchema = number();
125
+ else if (type === "boolean") processSchema = string().transform((val) => {
126
+ const lower = val.toLowerCase().trim();
127
+ if ([
128
+ "true",
129
+ "1",
130
+ "yes",
131
+ "on",
132
+ "enabled"
133
+ ].includes(lower)) return true;
134
+ if ([
135
+ "false",
136
+ "0",
137
+ "no",
138
+ "off",
139
+ "disabled"
140
+ ].includes(lower)) return false;
141
+ throw new Error(`Expected boolean value, received "${val}"`);
142
+ });
143
+ const result = processSchema.safeParse(value);
144
+ if (result.success) return result.data;
145
+ throw new Error(`Failed to parse value "${value}": ${result.error.issues.map((issue) => issue.message).join("; ")}`);
146
+ } catch (error) {
147
+ const message = error instanceof Error ? error.message : String(error);
148
+ throw new Error(message);
149
+ }
150
+ };
151
+ }
152
+ /**
153
+ * Convert Zod v3 schema to EnvVarSchema
154
+ */
155
+ function convertFromZodV3Schema(schema) {
156
+ const peeled = peelV3Schema(schema);
157
+ const type = resolveV3EnvVarType(peeled.schema);
158
+ const def = getV3Def(peeled.schema);
159
+ switch (type) {
160
+ case "boolean": return new BooleanEnvVarSchema({
161
+ process: createV3ProcessFunction(peeled.schema, "boolean"),
162
+ required: peeled.required,
163
+ default: typeof peeled.default === "boolean" ? peeled.default : void 0,
164
+ description: peeled.description
165
+ });
166
+ case "number": return new NumberEnvVarSchema({
167
+ process: createV3ProcessFunction(peeled.schema, "number"),
168
+ required: peeled.required,
169
+ default: typeof peeled.default === "number" ? peeled.default : void 0,
170
+ description: peeled.description
171
+ });
172
+ case "enum": {
173
+ const values = extractV3EnumValues(def) || [];
174
+ return new EnumEnvVarSchema({
175
+ process: createV3ProcessFunction(peeled.schema, "enum"),
176
+ values,
177
+ required: peeled.required,
178
+ default: typeof peeled.default === "string" ? peeled.default : void 0,
179
+ description: peeled.description
180
+ });
181
+ }
182
+ case "string":
183
+ default: {
184
+ const process = createV3ProcessFunction(peeled.schema, "string");
185
+ const defaultValue = typeof peeled.default === "string" ? peeled.default : void 0;
186
+ return new StringEnvVarSchema({
187
+ process,
188
+ required: peeled.required,
189
+ default: defaultValue,
190
+ description: peeled.description
191
+ });
192
+ }
193
+ }
194
+ }
195
+
196
+ //#endregion
197
+ //#region ../converters/src/converters/zod/ZodV4Converter.ts
198
+ /**
199
+ * Zod v4 schema converter implementation
200
+ */
201
+ var ZodV4Converter = class {
202
+ applies(schema) {
203
+ return isZodV4Schema(schema);
204
+ }
205
+ convert(schema) {
206
+ return convertFromZodV4Schema(schema);
207
+ }
208
+ };
209
+ /**
210
+ * Check if a schema is a Zod v4 schema
211
+ */
212
+ function isZodV4Schema(schema) {
213
+ if (!schema || typeof schema !== "object") return false;
214
+ return "_zod" in schema;
215
+ }
216
+ /**
217
+ * Extract definition from Zod v4 schema
218
+ */
219
+ function getV4Def(schema) {
220
+ const container = schema;
221
+ if (container._zod && container._zod.def) return container._zod.def;
222
+ return {};
223
+ }
224
+ /**
225
+ * Get the type name from a Zod v4 definition
226
+ */
227
+ function getV4TypeName(def) {
228
+ return def.type || "unknown";
229
+ }
230
+ /**
231
+ * Check if a type is a wrapper type that should be unwrapped
232
+ */
233
+ function isV4WrapperType(typeName) {
234
+ return [
235
+ "optional",
236
+ "default",
237
+ "catch",
238
+ "readonly",
239
+ "brand",
240
+ "prefault",
241
+ "nullable",
242
+ "nullish"
243
+ ].includes(typeName);
244
+ }
245
+ /**
246
+ * Get inner schema from wrapper
247
+ */
248
+ function getV4InnerSchema(def) {
249
+ return def.innerType || def.schema || def.in || def.inner;
250
+ }
251
+ /**
252
+ * Get default value from definition
253
+ */
254
+ function getV4DefaultValue(def) {
255
+ if (def.defaultValue !== void 0) return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
256
+ if (def.prefaultValue !== void 0) return typeof def.prefaultValue === "function" ? def.prefaultValue() : def.prefaultValue;
257
+ }
258
+ /**
259
+ * Extract enum values from schema
260
+ */
261
+ function extractV4EnumValues(def) {
262
+ if (Array.isArray(def.values)) return def.values.map((v) => String(v));
263
+ if (def.entries && typeof def.entries === "object") return Object.values(def.entries).map((v) => String(v));
264
+ }
265
+ /**
266
+ * Get description from schema
267
+ */
268
+ function getV4Description(schema, def) {
269
+ const directDesc = schema.description;
270
+ if (typeof directDesc === "string" && directDesc.length > 0) return directDesc;
271
+ if (typeof def.description === "string" && def.description.length > 0) return def.description;
272
+ const metaFn = schema.meta;
273
+ if (typeof metaFn === "function") {
274
+ const meta = metaFn.call(schema);
275
+ if (meta?.description && typeof meta.description === "string") return meta.description.trim();
276
+ }
277
+ }
278
+ /**
279
+ * Resolve environment variable type from schema
280
+ */
281
+ function resolveV4EnvVarType(schema) {
282
+ const def = getV4Def(schema);
283
+ switch (getV4TypeName(def)) {
284
+ case "string": return "string";
285
+ case "number":
286
+ case "int": return "number";
287
+ case "boolean":
288
+ case "stringbool": return "boolean";
289
+ case "pipe":
290
+ if (def.in && def.out) {
291
+ const inType = resolveV4EnvVarType(def.in);
292
+ const outType = resolveV4EnvVarType(def.out);
293
+ if (inType === "string" && outType === "boolean") return "boolean";
294
+ }
295
+ return "string";
296
+ case "enum": return "enum";
297
+ default:
298
+ if (def.values || def.entries) return "enum";
299
+ return "string";
300
+ }
301
+ }
302
+ function peelV4Schema(schema) {
303
+ let current = schema;
304
+ let required = true;
305
+ let defaultValue = void 0;
306
+ let description = void 0;
307
+ for (let i = 0; i < 20; i++) {
308
+ const def = getV4Def(current);
309
+ const typeName = getV4TypeName(def);
310
+ if (!description) description = getV4Description(current, def);
311
+ if (!isV4WrapperType(typeName)) if (typeName === "pipe" && def.in && def.out) {
312
+ const inType = resolveV4EnvVarType(def.in);
313
+ const outType = resolveV4EnvVarType(def.out);
314
+ if (inType === "string" && outType === "boolean") break;
315
+ } else break;
316
+ if (typeName === "optional" || typeName === "nullish") required = false;
317
+ if ((typeName === "default" || typeName === "prefault") && defaultValue === void 0) defaultValue = getV4DefaultValue(def);
318
+ const inner = getV4InnerSchema(def);
319
+ if (!inner) break;
320
+ current = inner;
321
+ }
322
+ return {
323
+ schema: current,
324
+ required,
325
+ default: defaultValue,
326
+ description
327
+ };
328
+ }
329
+ /**
330
+ * Create a process function for Zod v4 schemas
331
+ */
332
+ function createV4ProcessFunction(schema, type, originalSchema) {
333
+ return (value) => {
334
+ try {
335
+ let processSchema = schema;
336
+ const def = getV4Def(schema);
337
+ const typeName = getV4TypeName(def);
338
+ if (typeName === "stringbool" || typeName === "pipe" && def.in && def.out && resolveV4EnvVarType(def.in) === "string" && resolveV4EnvVarType(def.out) === "boolean") processSchema = originalSchema;
339
+ else if (type === "number") processSchema = number();
340
+ else if (type === "boolean") processSchema = stringbool();
341
+ const result = safeParse(processSchema, value);
342
+ if (result.success) return result.data;
343
+ throw new Error(`Failed to parse value "${value}": ${result.error.issues.map((issue) => issue.message).join("; ")}`);
344
+ } catch (error) {
345
+ const message = error instanceof Error ? error.message : String(error);
346
+ throw new Error(message);
347
+ }
348
+ };
349
+ }
350
+ /**
351
+ * Convert Zod v4 schema to EnvVarSchema
352
+ */
353
+ function convertFromZodV4Schema(schema) {
354
+ const peeled = peelV4Schema(schema);
355
+ const type = resolveV4EnvVarType(peeled.schema);
356
+ const def = getV4Def(peeled.schema);
357
+ switch (type) {
358
+ case "boolean": return new BooleanEnvVarSchema({
359
+ process: createV4ProcessFunction(peeled.schema, "boolean", schema),
360
+ required: peeled.required,
361
+ default: typeof peeled.default === "boolean" ? peeled.default : void 0,
362
+ description: peeled.description
363
+ });
364
+ case "number": return new NumberEnvVarSchema({
365
+ process: createV4ProcessFunction(peeled.schema, "number", schema),
366
+ required: peeled.required,
367
+ default: typeof peeled.default === "number" ? peeled.default : void 0,
368
+ description: peeled.description
369
+ });
370
+ case "enum": {
371
+ const values = extractV4EnumValues(def) || [];
372
+ return new EnumEnvVarSchema({
373
+ process: createV4ProcessFunction(peeled.schema, "enum", schema),
374
+ values,
375
+ required: peeled.required,
376
+ default: typeof peeled.default === "string" ? peeled.default : void 0,
377
+ description: peeled.description
378
+ });
379
+ }
380
+ case "string":
381
+ default: {
382
+ const process = createV4ProcessFunction(peeled.schema, "string", schema);
383
+ const defaultValue = typeof peeled.default === "string" ? peeled.default : void 0;
384
+ return new StringEnvVarSchema({
385
+ process,
386
+ required: peeled.required,
387
+ default: defaultValue,
388
+ description: peeled.description
389
+ });
390
+ }
391
+ }
392
+ }
393
+
394
+ //#endregion
395
+ //#region ../converters/src/converters/joi/JoiConverter.ts
396
+ /**
397
+ * Joi schema converter implementation
398
+ */
399
+ var JoiConverter = class {
400
+ applies(schema) {
401
+ return isJoiSchema(schema);
402
+ }
403
+ convert(schema) {
404
+ return convertFromJoiSchema(schema);
405
+ }
406
+ };
407
+ /**
408
+ * Check if a schema is a Joi schema using the official API
409
+ */
410
+ function isJoiSchema(schema) {
411
+ if (!schema || typeof schema !== "object") return false;
412
+ const candidate = schema;
413
+ if (!(typeof candidate.describe === "function" && typeof candidate.validate === "function")) return false;
414
+ if (candidate.isJoi === true) return true;
415
+ const hasAsyncVariant = typeof candidate.validateAsync === "function";
416
+ const hasRoot = typeof candidate.$_root === "object" && candidate.$_root !== null;
417
+ const hasFlags = typeof candidate._flags === "object" && candidate._flags !== null;
418
+ return hasAsyncVariant || hasRoot || hasFlags;
419
+ }
420
+ /**
421
+ * Get description from Joi schema using public API first, internal as fallback
422
+ */
423
+ function getJoiDescription(schema) {
424
+ try {
425
+ return schema.describe()?.flags?.description;
426
+ } catch {
427
+ return schema._flags?.description;
428
+ }
429
+ }
430
+ /**
431
+ * Check if schema is required using public API first, internal as fallback
432
+ */
433
+ function isJoiRequired(schema) {
434
+ try {
435
+ const presence = schema.describe()?.flags?.presence;
436
+ if (presence === "required") return true;
437
+ if (presence === "optional") return false;
438
+ return presence === void 0;
439
+ } catch {
440
+ const flags = schema._flags;
441
+ if (flags?.presence === "required") return true;
442
+ if (flags?.presence === "optional") return false;
443
+ return true;
444
+ }
445
+ }
446
+ /**
447
+ * Get default value from Joi schema using public API first, internal as fallback
448
+ */
449
+ function getJoiDefaultValue(schema) {
450
+ try {
451
+ const defaultValue = schema.describe()?.flags?.default;
452
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
453
+ } catch {
454
+ const flags = schema._flags;
455
+ if (flags?.default !== void 0) {
456
+ const defaultValue = flags.default;
457
+ return typeof defaultValue === "function" ? defaultValue() : defaultValue;
458
+ }
459
+ return;
460
+ }
461
+ }
462
+ /**
463
+ * Get valid values for enum-like schemas using public API first, internal as fallback
464
+ */
465
+ function getJoiValidValues(schema) {
466
+ const values = [];
467
+ let isOnlySchema = false;
468
+ try {
469
+ const description = schema.describe();
470
+ if (description?.allow && Array.isArray(description.allow)) values.push(...description.allow);
471
+ isOnlySchema = description?.flags?.only === true;
472
+ } catch {
473
+ if (schema._valids?._values) values.push(...Array.from(schema._valids._values));
474
+ isOnlySchema = schema._flags?.only === true;
475
+ }
476
+ if (isOnlySchema && values.length > 0) return values.map((v) => String(v));
477
+ }
478
+ /**
479
+ * Resolve environment variable type from Joi schema using public API first, internal as fallback
480
+ */
481
+ function resolveJoiEnvVarType(schema) {
482
+ let type;
483
+ const exposedSchema = schema;
484
+ try {
485
+ type = schema.describe()?.type;
486
+ } catch {
487
+ type = exposedSchema._type || schema.type;
488
+ }
489
+ const validValues = getJoiValidValues(schema);
490
+ if (validValues && validValues.length > 0) return "enum";
491
+ switch (type) {
492
+ case "string": return "string";
493
+ case "number": return "number";
494
+ case "boolean": return "boolean";
495
+ default: return "string";
496
+ }
497
+ }
498
+ /**
499
+ * Create a process function for Joi schemas
500
+ */
501
+ function createJoiProcessFunction(schema, type) {
502
+ return (value) => {
503
+ try {
504
+ let processValue = value;
505
+ if (type === "number") {
506
+ const num = Number(value);
507
+ if (Number.isNaN(num)) throw new Error(`Expected number, received "${value}"`);
508
+ processValue = num;
509
+ } else if (type === "boolean") {
510
+ const lower = value.toLowerCase().trim();
511
+ if ([
512
+ "true",
513
+ "1",
514
+ "yes",
515
+ "on",
516
+ "enabled"
517
+ ].includes(lower)) processValue = true;
518
+ else if ([
519
+ "false",
520
+ "0",
521
+ "no",
522
+ "off",
523
+ "disabled"
524
+ ].includes(lower)) processValue = false;
525
+ else throw new Error(`Expected boolean value, received "${value}"`);
526
+ }
527
+ const result = schema.validate(processValue, { convert: true });
528
+ if (result.error) {
529
+ const message = result.error.details ? result.error.details.map((d) => d.message).join("; ") : result.error.message || String(result.error);
530
+ throw new Error(`Validation failed: ${message}`);
531
+ }
532
+ return result.value;
533
+ } catch (error) {
534
+ const message = error instanceof Error ? error.message : String(error);
535
+ throw new Error(message);
536
+ }
537
+ };
538
+ }
539
+ /**
540
+ * Convert Joi schema to EnvVarSchema
541
+ */
542
+ function convertFromJoiSchema(schema) {
543
+ const type = resolveJoiEnvVarType(schema);
544
+ const required = isJoiRequired(schema);
545
+ const defaultValue = getJoiDefaultValue(schema);
546
+ const description = getJoiDescription(schema);
547
+ switch (type) {
548
+ case "boolean": return new BooleanEnvVarSchema({
549
+ process: createJoiProcessFunction(schema, "boolean"),
550
+ required,
551
+ default: typeof defaultValue === "boolean" ? defaultValue : void 0,
552
+ description
553
+ });
554
+ case "number": return new NumberEnvVarSchema({
555
+ process: createJoiProcessFunction(schema, "number"),
556
+ required,
557
+ default: typeof defaultValue === "number" ? defaultValue : void 0,
558
+ description
559
+ });
560
+ case "enum": {
561
+ const values = getJoiValidValues(schema) || [];
562
+ return new EnumEnvVarSchema({
563
+ process: createJoiProcessFunction(schema, "enum"),
564
+ values,
565
+ required,
566
+ default: typeof defaultValue === "string" ? defaultValue : void 0,
567
+ description
568
+ });
569
+ }
570
+ case "string":
571
+ default: return new StringEnvVarSchema({
572
+ process: createJoiProcessFunction(schema, "string"),
573
+ required,
574
+ default: typeof defaultValue === "string" ? defaultValue : void 0,
575
+ description
576
+ });
577
+ }
578
+ }
579
+
580
+ //#endregion
581
+ //#region ../converters/src/converters/superstruct/SuperstructConverter.ts
582
+ /**
583
+ * Superstruct schema converter implementation
584
+ */
585
+ var SuperstructConverter = class {
586
+ applies(schema) {
587
+ return isSuperstructSchema(schema);
588
+ }
589
+ convert(schema) {
590
+ return convertFromSuperstruct(schema);
591
+ }
592
+ };
593
+ /**
594
+ * Detect if a value looks like a Superstruct Struct instance
595
+ */
596
+ function isSuperstructSchema(value) {
597
+ if (!value || typeof value !== "object") return false;
598
+ const candidate = value;
599
+ return typeof candidate.type === "string" && typeof candidate.validate === "function" && typeof candidate.create === "function";
600
+ }
601
+ /**
602
+ * Convert a Superstruct schema to an EnvVarSchema
603
+ */
604
+ function convertFromSuperstruct(schema) {
605
+ const resolvedType = resolveSuperstructEnvVarType(schema);
606
+ const required = isStructRequired(schema);
607
+ const description = getStructDescription(schema);
608
+ const defaultValue = getStructDefault(schema);
609
+ if (resolvedType === "enum") {
610
+ const values = extractEnumValues(schema);
611
+ if (!values || values.length === 0) return createStringEnvVarSchema(schema, required, defaultValue, description);
612
+ const readonlyValues = values;
613
+ return new EnumEnvVarSchema({
614
+ process: createSuperstructProcessFunction(schema, "enum"),
615
+ values: readonlyValues,
616
+ required,
617
+ default: typeof defaultValue === "string" ? defaultValue : void 0,
618
+ description
619
+ });
620
+ }
621
+ if (resolvedType === "boolean") return new BooleanEnvVarSchema({
622
+ process: createSuperstructProcessFunction(schema, "boolean"),
623
+ required,
624
+ default: typeof defaultValue === "boolean" ? defaultValue : void 0,
625
+ description
626
+ });
627
+ if (resolvedType === "number") return new NumberEnvVarSchema({
628
+ process: createSuperstructProcessFunction(schema, "number"),
629
+ required,
630
+ default: typeof defaultValue === "number" ? defaultValue : void 0,
631
+ description
632
+ });
633
+ return createStringEnvVarSchema(schema, required, defaultValue, description);
634
+ }
635
+ function createStringEnvVarSchema(schema, required, defaultValue, description) {
636
+ return new StringEnvVarSchema({
637
+ process: createSuperstructProcessFunction(schema, "string"),
638
+ required,
639
+ default: typeof defaultValue === "string" ? defaultValue : void 0,
640
+ description
641
+ });
642
+ }
643
+ function resolveSuperstructEnvVarType(schema) {
644
+ switch (getStructType(schema)) {
645
+ case "boolean": return "boolean";
646
+ case "number":
647
+ case "integer": return "number";
648
+ case "enums": return "enum";
649
+ case "literal": return typeof schema.schema === "string" ? "enum" : "string";
650
+ default: return "string";
651
+ }
652
+ }
653
+ function getStructType(schema) {
654
+ const typeValue = schema.type;
655
+ return typeof typeValue === "string" ? typeValue : "unknown";
656
+ }
657
+ function extractEnumValues(schema) {
658
+ const typeName = getStructType(schema);
659
+ if (typeName === "enums") {
660
+ const structSchema = schema.schema;
661
+ if (structSchema && typeof structSchema === "object") {
662
+ const rawValues = Object.values(structSchema);
663
+ if (rawValues.every((value) => typeof value === "string")) return rawValues;
664
+ }
665
+ }
666
+ if (typeName === "literal") {
667
+ const value = schema.schema;
668
+ if (typeof value === "string") return [value];
669
+ }
670
+ }
671
+ function isStructRequired(schema) {
672
+ try {
673
+ const [error] = schema.validate(void 0);
674
+ return !!error;
675
+ } catch {
676
+ return true;
677
+ }
678
+ }
679
+ function getStructDefault(schema) {
680
+ try {
681
+ const [error, value] = schema.validate(void 0, { coerce: true });
682
+ if (!error && value !== void 0) return value;
683
+ } catch {}
684
+ }
685
+ function getStructDescription(schema) {
686
+ const structSchema = schema.schema;
687
+ if (structSchema && typeof structSchema === "object" && typeof structSchema.description === "string") return structSchema.description;
688
+ if (typeof schema.description === "string") return schema.description;
689
+ }
690
+ function createSuperstructProcessFunction(schema, type) {
691
+ return (value) => {
692
+ if (typeof value !== "string") throw new Error("Value must be a string");
693
+ let candidate = value;
694
+ if (type === "number") {
695
+ const trimmed = value.trim();
696
+ if (trimmed === "") candidate = void 0;
697
+ else {
698
+ const parsed = Number(trimmed);
699
+ if (Number.isNaN(parsed) || !Number.isFinite(parsed)) throw new Error(`"${value}" is not a valid number`);
700
+ candidate = parsed;
701
+ }
702
+ } else if (type === "boolean") {
703
+ const trimmed = value.trim().toLowerCase();
704
+ if (trimmed === "") candidate = void 0;
705
+ else if ([
706
+ "true",
707
+ "1",
708
+ "yes",
709
+ "on",
710
+ "enabled"
711
+ ].includes(trimmed)) candidate = true;
712
+ else if ([
713
+ "false",
714
+ "0",
715
+ "no",
716
+ "off",
717
+ "disabled"
718
+ ].includes(trimmed)) candidate = false;
719
+ else throw new Error(`"${value}" is not a valid boolean. Use: true/false, 1/0, yes/no, on/off, or enabled/disabled`);
720
+ } else if (value === "") candidate = void 0;
721
+ const [error, result] = schema.validate(candidate, { coerce: true });
722
+ if (error) throw new Error(error.message);
723
+ return result;
724
+ };
725
+ }
726
+
727
+ //#endregion
728
+ //#region ../converters/src/converters.ts
729
+ /**
730
+ * Registry of available schema converters
731
+ */
732
+ const converters = [
733
+ new ZodV4Converter(),
734
+ new ZodV3Converter(),
735
+ new JoiConverter(),
736
+ new SuperstructConverter()
737
+ ];
738
+
739
+ //#endregion
740
+ //#region ../models/src/resolve.ts
741
+ /**
742
+ * Resolve any supported schema to a EnvVarSchema.
743
+ *
744
+ * This is the main entry point for converting external schemas
745
+ * (like Zod schemas) to envcredible's internal schema format.
746
+ * If the input is already a EnvVarSchema, it returns it directly.
747
+ *
748
+ * @param schema - The schema to convert (e.g., Zod v3/v4 schema or EnvVarSchema)
749
+ * @returns EnvVarSchema that can be used with envcredible
750
+ * @throws Error if no converter can handle the schema
751
+ */
752
+ function resolveSchema(schema) {
753
+ if (isEnvVarSchema(schema)) return schema;
754
+ for (const converter of converters) if (converter.applies(schema)) return converter.convert(schema);
755
+ throw new Error(`No converter found for schema. Supported types: Zod v3, Zod v4, Joi, Superstruct, EnvVarSchema. Received: ${typeof schema}`);
756
+ }
757
+ /**
758
+ * Resolve mixed schema map (Zod schemas or EnvVarSchema) to pure EnvVarSchema map.
759
+ *
760
+ * This function takes a map where values can be:
761
+ * - Zod v3 schemas
762
+ * - Zod v4 schemas
763
+ * - Already resolved EnvVarSchema instances
764
+ *
765
+ * And converts everything to EnvVarSchema instances that can be used throughout envcredible.
766
+ *
767
+ * @param schemas - Object mapping environment variable names to various schema types
768
+ * @returns Record mapping env var names to EnvVarSchema instances
769
+ */
770
+ function resolveSchemas(schemas) {
771
+ const resolved = {};
772
+ for (const [key, schema] of Object.entries(schemas)) try {
773
+ resolved[key] = resolveSchema(schema);
774
+ } catch (error) {
775
+ const message = error instanceof Error ? error.message : String(error);
776
+ throw new Error(`Failed to resolve schema for environment variable "${key}": ${message}`);
777
+ }
778
+ return resolved;
779
+ }
780
+
781
+ //#endregion
782
+ //#region ../models/src/EnvModel.ts
783
+ /**
784
+ * Environment variable specification container
785
+ * Encapsulates schemas and preprocessor configuration
786
+ */
787
+ var EnvModel = class {
788
+ /**
789
+ * Resolved environment variable schemas
790
+ */
791
+ schemas;
792
+ /**
793
+ * Preprocessing configuration for environment variable types
794
+ */
795
+ preprocess;
796
+ /**
797
+ * Create an EnvModel instance from options
798
+ * @param options - Specification options
799
+ */
800
+ constructor(options) {
801
+ this.schemas = resolveSchemas(options.schemas);
802
+ this.preprocess = this.resolvePreprocessors(options.preprocess);
803
+ }
804
+ /**
805
+ * Resolve preprocessor configuration from options
806
+ * @param config - Preprocessor configuration (true, false, or partial object)
807
+ * @returns Resolved preprocessors object
808
+ */
809
+ resolvePreprocessors(config) {
810
+ if (config === false) return {
811
+ string: false,
812
+ number: false,
813
+ boolean: false,
814
+ enum: false
815
+ };
816
+ if (config === true || config === void 0) return {};
817
+ return { ...config };
818
+ }
819
+ };
820
+
821
+ //#endregion
822
+ //#region ../models/src/model.ts
823
+ /**
824
+ * Create an environment variable model
825
+ *
826
+ * Sugar utility for creating EnvModel instances with full type inference
827
+ *
828
+ * @param options - Model options
829
+ * @returns EnvModel instance with inferred types
830
+ *
831
+ * @example
832
+ * ```typescript
833
+ * import { define, s } from "@e-n-v/models";
834
+ *
835
+ * export default define({
836
+ * schemas: {
837
+ * PORT: s.number({ default: 3000 }),
838
+ * DATABASE_URL: s.string(),
839
+ * DEBUG: s.boolean({ default: false })
840
+ * },
841
+ * preprocess: true
842
+ * });
843
+ * ```
844
+ */
845
+ function define(options) {
846
+ return new EnvModel(options);
847
+ }
848
+
849
+ //#endregion
850
+ export { resolveSchemas as i, EnvModel as n, resolveSchema as r, define as t };