@e-n-v/env 0.0.1 → 0.0.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.
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 +59 -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
@@ -1,1716 +1,14 @@
1
1
  import { t as __export } from "./chunk-Bp6m_JJh.js";
2
- import { mkdirSync, promises, readFileSync, writeFileSync } from "node:fs";
2
+ import { t as resolveChannel } from "./resolveChannel-v9BDsw-M.js";
3
+ import { i as preprocessors, r as resolvePreprocessor } from "./src-CLTURaoo.js";
4
+ import { i as resolveSchemas, n as EnvModel } from "./src-CVdUqK3q.js";
3
5
  import { dirname, relative, resolve } from "node:path";
4
- import { readFile } from "node:fs/promises";
5
- import { existsSync, writeFileSync as writeFileSync$1 } from "fs";
6
- import { z } from "zod";
7
- import * as z4core from "zod/v4/core";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
8
7
  import { stdin, stdout } from "node:process";
9
8
  import { Prompt, isCancel } from "@clack/core";
10
- import { fileURLToPath, pathToFileURL } from "node:url";
11
9
  import color from "picocolors";
12
10
  import { clearLine, cursorTo, moveCursor } from "node:readline";
13
11
 
14
- //#region ../files/src/utils.ts
15
- function normalizeContent(content) {
16
- return content.replace(/\r\n/g, "\n");
17
- }
18
- function splitLines(content) {
19
- return content === "" ? [] : content.split("\n");
20
- }
21
- function validateKey(key) {
22
- const trimmed = key.trim();
23
- if (!trimmed) throw new TypeError("Environment variable name cannot be empty");
24
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed)) throw new TypeError(`Invalid environment variable name: ${trimmed}`);
25
- return trimmed;
26
- }
27
- function parseAssignmentEndingAt(lines, endIndex) {
28
- const lastLine = lines[endIndex];
29
- if (typeof lastLine !== "string" || isSkippableLine(lastLine)) return null;
30
- const block = [];
31
- let start = endIndex;
32
- while (start >= 0) {
33
- const currentLine = lines[start];
34
- if (typeof currentLine !== "string") break;
35
- block.unshift(currentLine);
36
- if (containsAssignmentOperator(currentLine)) {
37
- const parsed = tryParseAssignmentBlock(block);
38
- if (!parsed) return null;
39
- return {
40
- ...parsed,
41
- startIndex: start,
42
- endIndex
43
- };
44
- }
45
- start -= 1;
46
- }
47
- return null;
48
- }
49
- function isSkippableLine(line) {
50
- const trimmed = line.trim();
51
- return trimmed.length === 0 || trimmed.startsWith("#");
52
- }
53
- function containsAssignmentOperator(line) {
54
- const trimmed = line.trimStart();
55
- if (trimmed.length === 0 || trimmed.startsWith("#")) return false;
56
- const commentIndex = trimmed.indexOf("#");
57
- return (commentIndex === -1 ? trimmed : trimmed.slice(0, commentIndex)).includes("=");
58
- }
59
- function tryParseAssignmentBlock(blockLines) {
60
- if (blockLines.length === 0) return null;
61
- const firstLine = blockLines[0];
62
- const leadingMatch = firstLine.match(/^\s*/);
63
- const leading = leadingMatch ? leadingMatch[0] : "";
64
- let remainder = firstLine.slice(leading.length);
65
- if (remainder.length === 0 || remainder.startsWith("#")) return null;
66
- let exportPrefix = "";
67
- if (remainder.startsWith("export")) {
68
- const afterExport = remainder.slice(6);
69
- if (/^\s/.test(afterExport)) {
70
- const spacingMatch = afterExport.match(/^\s+/);
71
- const spacing = spacingMatch ? spacingMatch[0] : " ";
72
- exportPrefix = `export${spacing}`;
73
- remainder = afterExport.slice(spacing.length);
74
- }
75
- }
76
- const equalsIndex = remainder.indexOf("=");
77
- if (equalsIndex === -1) return null;
78
- const key = validateKey(remainder.slice(0, equalsIndex).trim());
79
- const parsedValue = parseValueSource([remainder.slice(equalsIndex + 1).replace(/^\s+/, ""), ...blockLines.slice(1)].join("\n"));
80
- if (!parsedValue) return null;
81
- const trailingTrimmed = parsedValue.trailing.trim();
82
- if (trailingTrimmed.length > 0 && !trailingTrimmed.startsWith("#")) return null;
83
- return {
84
- key,
85
- value: parsedValue.value,
86
- leading,
87
- exportPrefix,
88
- trailing: parsedValue.trailing,
89
- lines: [...blockLines]
90
- };
91
- }
92
- function parseValueSource(source) {
93
- if (source.length === 0) return {
94
- value: "",
95
- trailing: ""
96
- };
97
- const firstChar = source[0];
98
- if (firstChar === "\"") return parseDoubleQuotedValue(source);
99
- if (firstChar === "'") return parseSingleQuotedValue(source);
100
- if (source.includes("\n")) return null;
101
- const commentIndex = source.indexOf(" #");
102
- const raw = commentIndex === -1 ? source : source.slice(0, commentIndex);
103
- const trailing = commentIndex === -1 ? source.slice(raw.length) : source.slice(commentIndex);
104
- return {
105
- value: raw.trim(),
106
- trailing
107
- };
108
- }
109
- function parseDoubleQuotedValue(source) {
110
- let value = "";
111
- let escaping = false;
112
- for (let i = 1; i < source.length; i += 1) {
113
- const char = source[i] ?? "";
114
- if (escaping) {
115
- switch (char) {
116
- case "n":
117
- value += "\n";
118
- break;
119
- case "r":
120
- value += "\r";
121
- break;
122
- case "t":
123
- value += " ";
124
- break;
125
- case "\"":
126
- value += "\"";
127
- break;
128
- case "\\":
129
- value += "\\";
130
- break;
131
- default:
132
- value += char;
133
- break;
134
- }
135
- escaping = false;
136
- continue;
137
- }
138
- if (char === "\\") {
139
- escaping = true;
140
- continue;
141
- }
142
- if (char === "\"") {
143
- const trailing = source.slice(i + 1);
144
- return {
145
- value,
146
- trailing
147
- };
148
- }
149
- if (char === "\n") {
150
- value += "\n";
151
- continue;
152
- }
153
- value += char;
154
- }
155
- return null;
156
- }
157
- function parseSingleQuotedValue(source) {
158
- let value = "";
159
- for (let i = 1; i < source.length; i += 1) {
160
- const char = source[i] ?? "";
161
- if (char === "'") {
162
- const trailing = source.slice(i + 1);
163
- return {
164
- value,
165
- trailing
166
- };
167
- }
168
- if (char === "\n") {
169
- value += "\n";
170
- continue;
171
- }
172
- value += char;
173
- }
174
- return null;
175
- }
176
-
177
- //#endregion
178
- //#region ../files/src/get.ts
179
- function get(content, arg) {
180
- const lines = splitLines(normalizeContent(content));
181
- if (typeof arg === "undefined") {
182
- const map = scanAll(lines);
183
- return Object.fromEntries(map);
184
- }
185
- if (typeof arg === "string") return scanForSingle(lines, arg);
186
- const normalizedTargets = Array.from(new Set(arg.map((name) => validateKey(name))));
187
- const lookup = scanForMany(lines, new Set(normalizedTargets));
188
- const ordered = normalizedTargets.map((key) => [key, lookup.get(key)]);
189
- return Object.fromEntries(ordered);
190
- }
191
- function scanAll(lines) {
192
- const result = /* @__PURE__ */ new Map();
193
- iterateAssignments(lines, (assignment) => {
194
- if (!result.has(assignment.key)) result.set(assignment.key, assignment.value);
195
- });
196
- return result;
197
- }
198
- function scanForSingle(lines, target) {
199
- const name = validateKey(target);
200
- let found;
201
- iterateAssignments(lines, (assignment) => {
202
- if (assignment.key === name) {
203
- found = assignment.value;
204
- return true;
205
- }
206
- });
207
- return found;
208
- }
209
- function scanForMany(lines, targets) {
210
- const normalizedTargets = /* @__PURE__ */ new Set();
211
- for (const target of targets) normalizedTargets.add(validateKey(target));
212
- const found = /* @__PURE__ */ new Map();
213
- const remaining = new Set(normalizedTargets);
214
- iterateAssignments(lines, (assignment) => {
215
- if (!remaining.has(assignment.key) || found.has(assignment.key)) return;
216
- found.set(assignment.key, assignment.value);
217
- remaining.delete(assignment.key);
218
- if (remaining.size === 0) return true;
219
- });
220
- return found;
221
- }
222
- function iterateAssignments(lines, callback) {
223
- for (let i = lines.length - 1; i >= 0;) {
224
- const parsed = parseAssignmentEndingAt(lines, i);
225
- if (!parsed) {
226
- i -= 1;
227
- continue;
228
- }
229
- if (callback(parsed) === true) return;
230
- i = parsed.startIndex - 1;
231
- }
232
- }
233
-
234
- //#endregion
235
- //#region ../files/src/set.ts
236
- function set(content, arg, value) {
237
- const normalized = normalizeContent(content);
238
- const lines = splitLines(normalized);
239
- const entries = normalizeWriteArguments(arg, value);
240
- if (entries.length === 0) return ensureTrailingNewline(normalized);
241
- const replacements = new Map(entries);
242
- const touched = /* @__PURE__ */ new Set();
243
- for (let i = lines.length - 1; i >= 0;) {
244
- if (replacements.size === 0) break;
245
- const parsed = parseAssignmentEndingAt(lines, i);
246
- if (!parsed) {
247
- i -= 1;
248
- continue;
249
- }
250
- const { key, startIndex, endIndex, leading, exportPrefix, trailing, value: currentValue } = parsed;
251
- const nextValue = replacements.get(key);
252
- if (typeof nextValue === "undefined" || touched.has(key)) {
253
- i = startIndex - 1;
254
- continue;
255
- }
256
- if (nextValue === currentValue) {
257
- touched.add(key);
258
- replacements.delete(key);
259
- i = startIndex - 1;
260
- continue;
261
- }
262
- const block = buildAssignmentLines(key, nextValue, {
263
- leading,
264
- exportPrefix,
265
- trailing
266
- });
267
- lines.splice(startIndex, endIndex - startIndex + 1, ...block);
268
- touched.add(key);
269
- replacements.delete(key);
270
- i = startIndex - 1;
271
- }
272
- for (const [key, val] of entries) {
273
- if (touched.has(key)) continue;
274
- const block = buildAssignmentLines(key, val);
275
- const insertIndex = lines.length > 0 && lines[lines.length - 1] === "" ? lines.length - 1 : lines.length;
276
- lines.splice(insertIndex, 0, ...block);
277
- touched.add(key);
278
- }
279
- return ensureTrailingNewline(lines.join("\n"));
280
- }
281
- function ensureTrailingNewline(content) {
282
- if (content.length === 0) return "";
283
- if (!content.endsWith("\n")) return `${content}\n`;
284
- return content;
285
- }
286
- function isObjectRecord(value) {
287
- return typeof value === "object" && value !== null && !Array.isArray(value);
288
- }
289
- function normalizeWriteArguments(arg, value) {
290
- if (typeof arg === "string") {
291
- if (typeof value === "undefined") throw new TypeError(`Value for variable "${arg}" must be provided`);
292
- return [[validateKey(arg), formatValueInput(value)]];
293
- }
294
- if (!isObjectRecord(arg)) throw new TypeError("Argument must be a string name or an object of key-value pairs");
295
- const entries = [];
296
- for (const [key, rawValue] of Object.entries(arg)) {
297
- if (typeof rawValue === "undefined") throw new TypeError(`Value for variable "${key}" must be provided`);
298
- entries.push([validateKey(key), formatValueInput(rawValue)]);
299
- }
300
- return entries;
301
- }
302
- function formatValueInput(value) {
303
- if (typeof value === "bigint") return value.toString();
304
- return String(value);
305
- }
306
- function serializeValue(value) {
307
- const normalized = value.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
308
- if (!(normalized.length === 0 || /[\s"'\\#]/.test(normalized) || normalized.includes("\n"))) return normalized;
309
- let result = "\"";
310
- for (const char of normalized) {
311
- if (char === "\"") {
312
- result += "\\\"";
313
- continue;
314
- }
315
- if (char === "\\") {
316
- result += "\\\\";
317
- continue;
318
- }
319
- if (char === "\n") {
320
- result += "\n";
321
- continue;
322
- }
323
- result += char;
324
- }
325
- result += "\"";
326
- return result;
327
- }
328
- function buildAssignmentLines(key, value, style = {}) {
329
- const leading = style.leading ?? "";
330
- const exportPrefix = style.exportPrefix ?? "";
331
- const trailing = style.trailing ?? "";
332
- const segments = serializeValue(value).split("\n");
333
- return segments.map((segment, index) => {
334
- if (index === 0) return `${leading}${exportPrefix}${key}=${segment}${segments.length === 1 ? trailing : ""}`;
335
- if (index === segments.length - 1 && trailing && segments.length > 1) return `${segment}${trailing}`;
336
- return segment;
337
- });
338
- }
339
-
340
- //#endregion
341
- //#region ../files/src/EnvSource.ts
342
- var EnvSource = class {
343
- filePath;
344
- constructor(filePath) {
345
- this.filePath = resolve(process.cwd(), filePath);
346
- }
347
- readSync(arg) {
348
- const content = this.readContentSync();
349
- if (typeof arg === "undefined") return get(content);
350
- if (typeof arg === "string") return get(content, arg);
351
- return get(content, arg);
352
- }
353
- async read(arg) {
354
- const content = await this.readContent();
355
- if (typeof arg === "undefined") return get(content);
356
- if (typeof arg === "string") return get(content, arg);
357
- return get(content, arg);
358
- }
359
- writeSync(arg, value) {
360
- const originalContent = this.readContentSync();
361
- let nextContent;
362
- if (typeof arg === "string") nextContent = set(originalContent, arg, value);
363
- else nextContent = set(originalContent, arg);
364
- if (nextContent === originalContent) return;
365
- this.ensureDirectorySync();
366
- writeFileSync(this.filePath, nextContent, "utf8");
367
- }
368
- async write(arg, value) {
369
- const originalContent = await this.readContent();
370
- let nextContent;
371
- if (typeof arg === "string") nextContent = set(originalContent, arg, value);
372
- else nextContent = set(originalContent, arg);
373
- if (nextContent === originalContent) return;
374
- await this.ensureDirectory();
375
- await promises.writeFile(this.filePath, nextContent, "utf8");
376
- }
377
- readContentSync() {
378
- try {
379
- return readFileSync(this.filePath, "utf8").replace(/\r\n/g, "\n");
380
- } catch (error) {
381
- if (error.code === "ENOENT") return "";
382
- throw error;
383
- }
384
- }
385
- async readContent() {
386
- try {
387
- return (await promises.readFile(this.filePath, "utf8")).replace(/\r\n/g, "\n");
388
- } catch (error) {
389
- if (error.code === "ENOENT") return "";
390
- throw error;
391
- }
392
- }
393
- ensureDirectorySync() {
394
- try {
395
- mkdirSync(dirname(this.filePath), { recursive: true });
396
- } catch (error) {
397
- if (error.code !== "EEXIST") throw error;
398
- }
399
- }
400
- async ensureDirectory() {
401
- try {
402
- await promises.mkdir(dirname(this.filePath), { recursive: true });
403
- } catch (error) {
404
- if (error.code !== "EEXIST") throw error;
405
- }
406
- }
407
- };
408
-
409
- //#endregion
410
- //#region ../channels/src/channels/default/DefaultEnvChannel.ts
411
- /**
412
- * Default implementation of EnvChannel that works with .env files using envrw
413
- */
414
- var DefaultEnvChannel = class {
415
- envSource;
416
- /**
417
- * Create a new DefaultEnvChannel
418
- * @param filePath - Path to the .env file to manage
419
- */
420
- constructor(filePath) {
421
- this.envSource = new EnvSource(filePath);
422
- }
423
- /**
424
- * Get all environment variables
425
- * @returns Promise that resolves to object containing all environment variable key-value pairs
426
- */
427
- async get() {
428
- return await this.envSource.read();
429
- }
430
- /**
431
- * Set multiple environment variables
432
- * @param values - Object containing key-value pairs to set
433
- * @returns Promise that resolves when the values have been set
434
- */
435
- async set(values) {
436
- await this.envSource.write(values);
437
- }
438
- };
439
-
440
- //#endregion
441
- //#region ../channels/src/channels/dotenv/DotEnvChannel.ts
442
- function isFileNotFound(error) {
443
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
444
- }
445
- function normalizeParsed(parsed) {
446
- if (!parsed) return {};
447
- const result = {};
448
- for (const [key, value] of Object.entries(parsed)) {
449
- if (typeof value === "undefined") continue;
450
- result[key] = value;
451
- }
452
- return result;
453
- }
454
- var DotEnvChannel = class {
455
- dotenv;
456
- targetPath;
457
- absolutePath;
458
- encoding;
459
- parseOptions;
460
- envSource;
461
- constructor(dotenv, defaultPath = ".env", getOptions = {}, parseOptions = {}) {
462
- this.dotenv = dotenv;
463
- this.targetPath = (typeof getOptions.path === "string" ? getOptions.path : void 0) ?? defaultPath;
464
- this.absolutePath = resolve(process.cwd(), this.targetPath);
465
- this.encoding = getOptions.encoding ?? "utf8";
466
- this.parseOptions = { ...parseOptions };
467
- this.envSource = new EnvSource(this.targetPath);
468
- }
469
- async get() {
470
- try {
471
- const content = await readFile(this.absolutePath, { encoding: this.encoding });
472
- return normalizeParsed(this.dotenv.parse(content, this.parseOptions));
473
- } catch (error) {
474
- if (isFileNotFound(error)) return {};
475
- throw error;
476
- }
477
- }
478
- async set(values) {
479
- await this.envSource.write(values);
480
- const parsed = await this.get();
481
- const mismatches = [];
482
- for (const [key, expected] of Object.entries(values)) {
483
- const actual = parsed[key];
484
- if (actual !== expected) mismatches.push(`${key}=expected(${JSON.stringify(expected)}) actual(${JSON.stringify(actual)})`);
485
- }
486
- if (mismatches.length > 0) throw new Error(`Failed to correctly write values to ${this.targetPath}: ${mismatches.join(", ")}`);
487
- }
488
- getPrimaryPath() {
489
- return this.targetPath;
490
- }
491
- clearCache() {}
492
- };
493
-
494
- //#endregion
495
- //#region ../channels/src/channels/dotenvx/DotEnvXChannel.ts
496
- /**
497
- * Simple DotEnvX implementation of EnvChannel that wraps @dotenvx/dotenvx library
498
- * This is just an API mapping wrapper without caching or complex state management
499
- */
500
- var DotEnvXChannel = class {
501
- dotenvx;
502
- getOptions;
503
- setOptions;
504
- defaultPath;
505
- /**
506
- * Create a new DotEnvXChannel
507
- * @param dotenvx - The dotenvx instance to use
508
- * @param defaultPath - Default path for env files
509
- * @param getOptions - Options for get operations
510
- * @param setOptions - Options for set operations
511
- */
512
- constructor(dotenvx, defaultPath = ".env", getOptions = {}, setOptions = {}) {
513
- this.dotenvx = dotenvx;
514
- this.defaultPath = defaultPath;
515
- this.getOptions = getOptions;
516
- this.setOptions = setOptions;
517
- }
518
- /**
519
- * Get all environment variables
520
- * @returns Promise that resolves to object containing all environment variable key-value pairs
521
- */
522
- async get() {
523
- try {
524
- return this.dotenvx.config({
525
- processEnv: {},
526
- quiet: true,
527
- ignore: ["MISSING_ENV_FILE"],
528
- path: this.defaultPath,
529
- ...this.getOptions
530
- }).parsed || {};
531
- } catch {
532
- return {};
533
- }
534
- }
535
- /**
536
- * Set multiple environment variables
537
- * @param values - Object containing key-value pairs to set
538
- * @returns Promise that resolves when the values have been set
539
- */
540
- async set(values) {
541
- if (!existsSync(this.defaultPath)) writeFileSync$1(this.defaultPath, "", "utf8");
542
- try {
543
- const options = {
544
- path: this.defaultPath,
545
- ...this.setOptions
546
- };
547
- for (const [key, value] of Object.entries(values)) this.dotenvx.set(key, value, options);
548
- } catch (error) {
549
- throw new Error(`Failed to set environment variables: ${error}`);
550
- }
551
- }
552
- /**
553
- * Get the primary path being used for env files
554
- * @returns The primary path
555
- */
556
- getPrimaryPath() {
557
- return this.defaultPath;
558
- }
559
- /**
560
- * Clear any cached data (no-op for this implementation since we don't cache)
561
- */
562
- clearCache() {}
563
- };
564
-
565
- //#endregion
566
- //#region ../channels/src/channels/processenv/ProcessEnvChannel.ts
567
- /**
568
- * EnvChannel implementation that works with process.env
569
- * This channel reads from and writes to the current process environment
570
- */
571
- var ProcessEnvChannel = class {
572
- /**
573
- * Get all environment variables from process.env
574
- * @returns Promise that resolves to object containing all environment variable key-value pairs
575
- */
576
- async get() {
577
- const env = {};
578
- for (const [key, value] of Object.entries(process.env)) if (value !== void 0) env[key] = value;
579
- return env;
580
- }
581
- /**
582
- * Set multiple environment variables in process.env
583
- * @param values - Object containing key-value pairs to set
584
- * @returns Promise that resolves when the values have been set
585
- */
586
- async set(values) {
587
- for (const [key, value] of Object.entries(values)) process.env[key] = value;
588
- }
589
- };
590
-
591
- //#endregion
592
- //#region ../channels/src/resolveChannel.ts
593
- /**
594
- * Resolve channel options into an EnvChannel instance
595
- * @param options - The channel options to resolve
596
- * @param defaultPath - Default path to use for env files (default: ".env")
597
- * @returns An EnvChannel instance
598
- */
599
- function resolveChannel(options, defaultPath = ".env") {
600
- if (options === void 0 || options === "default") return new DefaultEnvChannel(defaultPath);
601
- if (options === "processenv") return new ProcessEnvChannel();
602
- if (typeof options === "object" && options !== null) {
603
- if ("dotenv" in options) {
604
- const { dotenv, get: getOptions = {}, parse: parseOptions = {}, path } = options;
605
- if (!dotenv) throw new Error("Dotenv instance is required for dotenv channel");
606
- const resolvedPath = path ?? defaultPath;
607
- const mergedGetOptions = { ...getOptions };
608
- if (typeof mergedGetOptions.path !== "string") mergedGetOptions.path = resolvedPath;
609
- return new DotEnvChannel(dotenv, resolvedPath, mergedGetOptions, parseOptions ?? {});
610
- }
611
- if ("dotenvx" in options) {
612
- const { dotenvx, get: getOptions = {}, set: setOptions = {} } = options;
613
- if (!dotenvx) throw new Error("DotEnvX instance is required for dotenvx channel");
614
- return new DotEnvXChannel(dotenvx, defaultPath, getOptions, setOptions);
615
- }
616
- if ("process" in options) {
617
- if (options.process && typeof options.process === "object" && "env" in options.process) return new ProcessEnvChannel();
618
- throw new Error("Invalid process object provided to channel config");
619
- }
620
- if ("name" in options) if (options.name === "default") return new DefaultEnvChannel(defaultPath);
621
- else if (options.name === "processenv") return new ProcessEnvChannel();
622
- else throw new Error(`Unknown channel name: ${options.name}`);
623
- }
624
- throw new Error(`Invalid channel options: ${options}`);
625
- }
626
-
627
- //#endregion
628
- //#region ../core/src/schemas/EnvVarSchemaBase.ts
629
- var EnvVarSchemaBase = class {
630
- required;
631
- default;
632
- description;
633
- process;
634
- constructor(input) {
635
- this.required = input?.required ?? true;
636
- this.default = input?.default;
637
- this.description = input?.description;
638
- this.process = input.process;
639
- }
640
- };
641
-
642
- //#endregion
643
- //#region ../core/src/processing/processors.ts
644
- /**
645
- * Default processors for environment variable types.
646
- * Each processor factory returns a function that takes a value and returns T | undefined.
647
- * Returns undefined for empty/null values, throws descriptive errors for invalid values.
648
- */
649
- /**
650
- * Create a string processor - pass through as-is
651
- */
652
- const stringProcessor = () => (value) => {
653
- if (typeof value !== "string") throw new Error("Value must be a string");
654
- return value === "" ? void 0 : value;
655
- };
656
- /**
657
- * Create a number processor using parseFloat
658
- */
659
- const numberProcessor = () => (value) => {
660
- if (typeof value !== "string") throw new Error("Value must be a string");
661
- const trimmed = value.trim();
662
- if (trimmed === "") return;
663
- const parsed = parseFloat(trimmed);
664
- if (isNaN(parsed)) throw new Error(`"${value}" is not a valid number`);
665
- return parsed;
666
- };
667
- /**
668
- * Create a boolean processor from string representation
669
- */
670
- const booleanProcessor = () => (value) => {
671
- if (typeof value !== "string") throw new Error("Value must be a string");
672
- const trimmed = value.trim().toLowerCase();
673
- if (trimmed === "") return;
674
- if (trimmed === "true" || trimmed === "1" || trimmed === "yes" || trimmed === "on") return true;
675
- if (trimmed === "false" || trimmed === "0" || trimmed === "no" || trimmed === "off") return false;
676
- throw new Error(`"${value}" is not a valid boolean. Use: true/false, 1/0, yes/no, or on/off`);
677
- };
678
- /**
679
- * Create an enum processor that validates values against allowed options
680
- */
681
- const enumProcessor = (allowedValues) => (value) => {
682
- if (typeof value !== "string") throw new Error("Value must be a string");
683
- const trimmed = value.trim();
684
- if (trimmed === "") return;
685
- if (!allowedValues.includes(trimmed)) throw new Error(`"${value}" is not a valid option. Must be one of: ${allowedValues.join(", ")}`);
686
- return trimmed;
687
- };
688
- /**
689
- * Default processors map for each environment variable type
690
- */
691
- const processors = {
692
- string: stringProcessor,
693
- number: numberProcessor,
694
- boolean: booleanProcessor,
695
- enum: enumProcessor
696
- };
697
-
698
- //#endregion
699
- //#region ../core/src/schemas/typed/BooleanEnvVarSchema.ts
700
- var BooleanEnvVarSchema = class extends EnvVarSchemaBase {
701
- type = "boolean";
702
- constructor(input = {}) {
703
- super({
704
- ...input,
705
- process: input.process ?? processors.boolean()
706
- });
707
- }
708
- };
709
-
710
- //#endregion
711
- //#region ../core/src/schemas/typed/EnumEnvVarSchema.ts
712
- var EnumEnvVarSchema = class extends EnvVarSchemaBase {
713
- type = "enum";
714
- values;
715
- constructor(input) {
716
- super({
717
- ...input,
718
- process: input.process ?? processors.enum(input.values)
719
- });
720
- this.values = input.values;
721
- }
722
- };
723
-
724
- //#endregion
725
- //#region ../core/src/schemas/typed/NumberEnvVarSchema.ts
726
- var NumberEnvVarSchema = class extends EnvVarSchemaBase {
727
- type = "number";
728
- constructor(input = {}) {
729
- super({
730
- ...input,
731
- process: input.process ?? processors.number()
732
- });
733
- }
734
- };
735
-
736
- //#endregion
737
- //#region ../core/src/schemas/typed/StringEnvVarSchema.ts
738
- var StringEnvVarSchema = class extends EnvVarSchemaBase {
739
- type = "string";
740
- secret;
741
- constructor(input = {}) {
742
- super({
743
- ...input,
744
- process: input.process ?? processors.string()
745
- });
746
- this.secret = input.secret;
747
- }
748
- };
749
-
750
- //#endregion
751
- //#region ../core/src/schemas/EnvVarSchema.ts
752
- /**
753
- * Type guard to check if a value is a EnvVarSchema instance
754
- */
755
- function isEnvVarSchema(value) {
756
- return value instanceof StringEnvVarSchema || value instanceof NumberEnvVarSchema || value instanceof BooleanEnvVarSchema || value instanceof EnumEnvVarSchema;
757
- }
758
-
759
- //#endregion
760
- //#region ../core/src/processing/preprocessors.ts
761
- const defaultBooleanPreprocessorOptions = {
762
- true: [
763
- "on",
764
- "enabled",
765
- "active",
766
- "yes"
767
- ],
768
- false: [
769
- "off",
770
- "disabled",
771
- "inactive",
772
- "no"
773
- ]
774
- };
775
- /**
776
- * Create a string preprocessor - pass through unchanged
777
- */
778
- const stringPreprocessor = () => (value) => value;
779
- /**
780
- * Create a number preprocessor that strips commas and whitespace
781
- */
782
- const numberPreprocessor = () => (value) => {
783
- try {
784
- const cleaned = value.replace(/,/g, "").trim();
785
- if (/^-?\d*\.?\d+$/.test(cleaned)) return cleaned;
786
- } catch {}
787
- return value;
788
- };
789
- /**
790
- * Create a boolean preprocessor that normalizes common truthy/falsy phrases
791
- */
792
- const booleanPreprocessor = (options = defaultBooleanPreprocessorOptions) => {
793
- const normalize = (candidate) => candidate.toLowerCase().trim();
794
- const trueValues = new Set(options.true.map(normalize));
795
- const falseValues = new Set(options.false.map(normalize));
796
- for (const candidate of trueValues) if (falseValues.has(candidate)) throw new Error(`Boolean preprocessor option value "${candidate}" cannot map to both true and false`);
797
- return (value) => {
798
- try {
799
- const cleaned = normalize(value);
800
- if (trueValues.has(cleaned)) return true;
801
- if (falseValues.has(cleaned)) return false;
802
- } catch {}
803
- return value;
804
- };
805
- };
806
- /**
807
- * Create an enum preprocessor - pass through unchanged
808
- */
809
- const enumPreprocessor = () => (value) => value;
810
- /**
811
- * Default preprocessors map for each environment variable type
812
- */
813
- const preprocessors = {
814
- string: stringPreprocessor,
815
- number: numberPreprocessor,
816
- boolean: booleanPreprocessor,
817
- enum: enumPreprocessor
818
- };
819
-
820
- //#endregion
821
- //#region ../core/src/processing/Preprocessor.ts
822
- const optionKeyMap = {
823
- string: "string",
824
- number: "number",
825
- boolean: "boolean",
826
- enum: "enum"
827
- };
828
- const explicitPreprocessorFactories = {
829
- string: stringPreprocessor,
830
- number: numberPreprocessor,
831
- boolean: booleanPreprocessor,
832
- enum: enumPreprocessor
833
- };
834
- function createDefaultPreprocessor(envVarType) {
835
- switch (envVarType) {
836
- case "number": return numberPreprocessor();
837
- case "boolean": return booleanPreprocessor();
838
- default: return;
839
- }
840
- }
841
- function createExplicitPreprocessor(envVarType) {
842
- const factory = explicitPreprocessorFactories[envVarType];
843
- if (!factory) return;
844
- return factory();
845
- }
846
- /**
847
- * Resolve the effective preprocessor for a given environment variable type.
848
- * Respects custom overrides and falls back to built-in defaults (number, boolean).
849
- */
850
- function resolvePreprocessor(envVarType, preprocessorOptions) {
851
- if (envVarType === "boolean") {
852
- const override = preprocessorOptions?.boolean;
853
- if (override === void 0) return createDefaultPreprocessor(envVarType);
854
- if (override === false) return;
855
- if (override === true) return createExplicitPreprocessor(envVarType);
856
- if (typeof override === "function") return override;
857
- return booleanPreprocessor(override);
858
- }
859
- const key = optionKeyMap[envVarType];
860
- const custom = preprocessorOptions?.[key];
861
- if (custom === void 0) return createDefaultPreprocessor(envVarType);
862
- if (custom === false) return;
863
- if (custom === true) return createExplicitPreprocessor(envVarType);
864
- return custom;
865
- }
866
-
867
- //#endregion
868
- //#region ../converters/src/converters/zod/ZodV3Converter.ts
869
- /**
870
- * Zod v3 schema converter implementation
871
- */
872
- var ZodV3Converter = class {
873
- applies(schema) {
874
- return isZodV3Schema(schema);
875
- }
876
- convert(schema) {
877
- return convertFromZodV3Schema(schema);
878
- }
879
- };
880
- /**
881
- * Check if a schema is a Zod v3 schema
882
- */
883
- function isZodV3Schema(schema) {
884
- if (!schema || typeof schema !== "object") return false;
885
- const candidate = schema;
886
- return Boolean(candidate._def && !("_zod" in candidate) && (candidate._def.typeName || typeof candidate.parse === "function"));
887
- }
888
- /**
889
- * Extract definition from Zod v3 schema
890
- */
891
- function getV3Def(schema) {
892
- return schema._def || {};
893
- }
894
- /**
895
- * Get the type name from a Zod v3 definition
896
- */
897
- function getV3TypeName(def) {
898
- return def.typeName || "unknown";
899
- }
900
- /**
901
- * Check if a type is a wrapper type that should be unwrapped
902
- */
903
- function isV3WrapperType(typeName) {
904
- return [
905
- "ZodOptional",
906
- "ZodDefault",
907
- "ZodEffects",
908
- "ZodNullable",
909
- "ZodNullish",
910
- "ZodReadonly",
911
- "ZodBranded",
912
- "ZodCatch"
913
- ].includes(typeName);
914
- }
915
- /**
916
- * Get inner schema from wrapper
917
- */
918
- function getV3InnerSchema(def) {
919
- return def.innerType || def.schema;
920
- }
921
- /**
922
- * Get default value from definition
923
- */
924
- function getV3DefaultValue(def) {
925
- if (def.defaultValue === void 0) return void 0;
926
- return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
927
- }
928
- /**
929
- * Extract enum values from schema
930
- */
931
- function extractV3EnumValues(def) {
932
- if (!Array.isArray(def.values)) return void 0;
933
- return def.values.map((v) => String(v));
934
- }
935
- /**
936
- * Get description from schema
937
- */
938
- function getV3Description(schema, def) {
939
- const directDesc = schema.description;
940
- if (typeof directDesc === "string" && directDesc.length > 0) return directDesc;
941
- if (typeof def.description === "string" && def.description.length > 0) return def.description;
942
- }
943
- /**
944
- * Resolve environment variable type from schema
945
- */
946
- function resolveV3EnvVarType(schema) {
947
- const def = getV3Def(schema);
948
- switch (getV3TypeName(def)) {
949
- case "ZodString": return "string";
950
- case "ZodNumber": return "number";
951
- case "ZodBoolean": return "boolean";
952
- case "ZodEnum": return "enum";
953
- default:
954
- if (def.values) return "enum";
955
- return "string";
956
- }
957
- }
958
- function peelV3Schema(schema) {
959
- let current = schema;
960
- let required = true;
961
- let defaultValue = void 0;
962
- let description = void 0;
963
- for (let i = 0; i < 20; i++) {
964
- const def = getV3Def(current);
965
- const typeName = getV3TypeName(def);
966
- if (!description) description = getV3Description(current, def);
967
- if (!isV3WrapperType(typeName)) break;
968
- if (typeName === "ZodOptional" || typeName === "ZodNullish") required = false;
969
- if (typeName === "ZodDefault" && defaultValue === void 0) defaultValue = getV3DefaultValue(def);
970
- const inner = getV3InnerSchema(def);
971
- if (!inner) break;
972
- current = inner;
973
- }
974
- return {
975
- schema: current,
976
- required,
977
- default: defaultValue,
978
- description
979
- };
980
- }
981
- /**
982
- * Create a process function for Zod v3 schemas
983
- */
984
- function createV3ProcessFunction(schema, type) {
985
- return (value) => {
986
- try {
987
- let processSchema = schema;
988
- if (type === "number") processSchema = z.coerce.number();
989
- else if (type === "boolean") processSchema = z.string().transform((val) => {
990
- const lower = val.toLowerCase().trim();
991
- if ([
992
- "true",
993
- "1",
994
- "yes",
995
- "on",
996
- "enabled"
997
- ].includes(lower)) return true;
998
- if ([
999
- "false",
1000
- "0",
1001
- "no",
1002
- "off",
1003
- "disabled"
1004
- ].includes(lower)) return false;
1005
- throw new Error(`Expected boolean value, received "${val}"`);
1006
- });
1007
- const result = processSchema.safeParse(value);
1008
- if (result.success) return result.data;
1009
- throw new Error(`Failed to parse value "${value}": ${result.error.issues.map((issue) => issue.message).join("; ")}`);
1010
- } catch (error) {
1011
- const message = error instanceof Error ? error.message : String(error);
1012
- throw new Error(message);
1013
- }
1014
- };
1015
- }
1016
- /**
1017
- * Convert Zod v3 schema to EnvVarSchema
1018
- */
1019
- function convertFromZodV3Schema(schema) {
1020
- const peeled = peelV3Schema(schema);
1021
- const type = resolveV3EnvVarType(peeled.schema);
1022
- const def = getV3Def(peeled.schema);
1023
- switch (type) {
1024
- case "boolean": return new BooleanEnvVarSchema({
1025
- process: createV3ProcessFunction(peeled.schema, "boolean"),
1026
- required: peeled.required,
1027
- default: typeof peeled.default === "boolean" ? peeled.default : void 0,
1028
- description: peeled.description
1029
- });
1030
- case "number": return new NumberEnvVarSchema({
1031
- process: createV3ProcessFunction(peeled.schema, "number"),
1032
- required: peeled.required,
1033
- default: typeof peeled.default === "number" ? peeled.default : void 0,
1034
- description: peeled.description
1035
- });
1036
- case "enum": {
1037
- const values = extractV3EnumValues(def) || [];
1038
- return new EnumEnvVarSchema({
1039
- process: createV3ProcessFunction(peeled.schema, "enum"),
1040
- values,
1041
- required: peeled.required,
1042
- default: typeof peeled.default === "string" ? peeled.default : void 0,
1043
- description: peeled.description
1044
- });
1045
- }
1046
- case "string":
1047
- default: {
1048
- const process$1 = createV3ProcessFunction(peeled.schema, "string");
1049
- const defaultValue = typeof peeled.default === "string" ? peeled.default : void 0;
1050
- return new StringEnvVarSchema({
1051
- process: process$1,
1052
- required: peeled.required,
1053
- default: defaultValue,
1054
- description: peeled.description
1055
- });
1056
- }
1057
- }
1058
- }
1059
-
1060
- //#endregion
1061
- //#region ../converters/src/converters/zod/ZodV4Converter.ts
1062
- /**
1063
- * Zod v4 schema converter implementation
1064
- */
1065
- var ZodV4Converter = class {
1066
- applies(schema) {
1067
- return isZodV4Schema(schema);
1068
- }
1069
- convert(schema) {
1070
- return convertFromZodV4Schema(schema);
1071
- }
1072
- };
1073
- /**
1074
- * Check if a schema is a Zod v4 schema
1075
- */
1076
- function isZodV4Schema(schema) {
1077
- if (!schema || typeof schema !== "object") return false;
1078
- return "_zod" in schema;
1079
- }
1080
- /**
1081
- * Extract definition from Zod v4 schema
1082
- */
1083
- function getV4Def(schema) {
1084
- const container = schema;
1085
- if (container._zod && container._zod.def) return container._zod.def;
1086
- return {};
1087
- }
1088
- /**
1089
- * Get the type name from a Zod v4 definition
1090
- */
1091
- function getV4TypeName(def) {
1092
- return def.type || "unknown";
1093
- }
1094
- /**
1095
- * Check if a type is a wrapper type that should be unwrapped
1096
- */
1097
- function isV4WrapperType(typeName) {
1098
- return [
1099
- "optional",
1100
- "default",
1101
- "catch",
1102
- "readonly",
1103
- "brand",
1104
- "prefault",
1105
- "nullable",
1106
- "nullish"
1107
- ].includes(typeName);
1108
- }
1109
- /**
1110
- * Get inner schema from wrapper
1111
- */
1112
- function getV4InnerSchema(def) {
1113
- return def.innerType || def.schema || def.in || def.inner;
1114
- }
1115
- /**
1116
- * Get default value from definition
1117
- */
1118
- function getV4DefaultValue(def) {
1119
- if (def.defaultValue !== void 0) return typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
1120
- if (def.prefaultValue !== void 0) return typeof def.prefaultValue === "function" ? def.prefaultValue() : def.prefaultValue;
1121
- }
1122
- /**
1123
- * Extract enum values from schema
1124
- */
1125
- function extractV4EnumValues(def) {
1126
- if (Array.isArray(def.values)) return def.values.map((v) => String(v));
1127
- if (def.entries && typeof def.entries === "object") return Object.values(def.entries).map((v) => String(v));
1128
- }
1129
- /**
1130
- * Get description from schema
1131
- */
1132
- function getV4Description(schema, def) {
1133
- const directDesc = schema.description;
1134
- if (typeof directDesc === "string" && directDesc.length > 0) return directDesc;
1135
- if (typeof def.description === "string" && def.description.length > 0) return def.description;
1136
- const metaFn = schema.meta;
1137
- if (typeof metaFn === "function") {
1138
- const meta = metaFn.call(schema);
1139
- if (meta?.description && typeof meta.description === "string") return meta.description.trim();
1140
- }
1141
- }
1142
- /**
1143
- * Resolve environment variable type from schema
1144
- */
1145
- function resolveV4EnvVarType(schema) {
1146
- const def = getV4Def(schema);
1147
- switch (getV4TypeName(def)) {
1148
- case "string": return "string";
1149
- case "number":
1150
- case "int": return "number";
1151
- case "boolean":
1152
- case "stringbool": return "boolean";
1153
- case "pipe":
1154
- if (def.in && def.out) {
1155
- const inType = resolveV4EnvVarType(def.in);
1156
- const outType = resolveV4EnvVarType(def.out);
1157
- if (inType === "string" && outType === "boolean") return "boolean";
1158
- }
1159
- return "string";
1160
- case "enum": return "enum";
1161
- default:
1162
- if (def.values || def.entries) return "enum";
1163
- return "string";
1164
- }
1165
- }
1166
- function peelV4Schema(schema) {
1167
- let current = schema;
1168
- let required = true;
1169
- let defaultValue = void 0;
1170
- let description = void 0;
1171
- for (let i = 0; i < 20; i++) {
1172
- const def = getV4Def(current);
1173
- const typeName = getV4TypeName(def);
1174
- if (!description) description = getV4Description(current, def);
1175
- if (!isV4WrapperType(typeName)) if (typeName === "pipe" && def.in && def.out) {
1176
- const inType = resolveV4EnvVarType(def.in);
1177
- const outType = resolveV4EnvVarType(def.out);
1178
- if (inType === "string" && outType === "boolean") break;
1179
- } else break;
1180
- if (typeName === "optional" || typeName === "nullish") required = false;
1181
- if ((typeName === "default" || typeName === "prefault") && defaultValue === void 0) defaultValue = getV4DefaultValue(def);
1182
- const inner = getV4InnerSchema(def);
1183
- if (!inner) break;
1184
- current = inner;
1185
- }
1186
- return {
1187
- schema: current,
1188
- required,
1189
- default: defaultValue,
1190
- description
1191
- };
1192
- }
1193
- /**
1194
- * Create a process function for Zod v4 schemas
1195
- */
1196
- function createV4ProcessFunction(schema, type, originalSchema) {
1197
- return (value) => {
1198
- try {
1199
- let processSchema = schema;
1200
- const def = getV4Def(schema);
1201
- const typeName = getV4TypeName(def);
1202
- if (typeName === "stringbool" || typeName === "pipe" && def.in && def.out && resolveV4EnvVarType(def.in) === "string" && resolveV4EnvVarType(def.out) === "boolean") processSchema = originalSchema;
1203
- else if (type === "number") processSchema = z.coerce.number();
1204
- else if (type === "boolean") processSchema = z.stringbool();
1205
- const result = z4core.safeParse(processSchema, value);
1206
- if (result.success) return result.data;
1207
- throw new Error(`Failed to parse value "${value}": ${result.error.issues.map((issue) => issue.message).join("; ")}`);
1208
- } catch (error) {
1209
- const message = error instanceof Error ? error.message : String(error);
1210
- throw new Error(message);
1211
- }
1212
- };
1213
- }
1214
- /**
1215
- * Convert Zod v4 schema to EnvVarSchema
1216
- */
1217
- function convertFromZodV4Schema(schema) {
1218
- const peeled = peelV4Schema(schema);
1219
- const type = resolveV4EnvVarType(peeled.schema);
1220
- const def = getV4Def(peeled.schema);
1221
- switch (type) {
1222
- case "boolean": return new BooleanEnvVarSchema({
1223
- process: createV4ProcessFunction(peeled.schema, "boolean", schema),
1224
- required: peeled.required,
1225
- default: typeof peeled.default === "boolean" ? peeled.default : void 0,
1226
- description: peeled.description
1227
- });
1228
- case "number": return new NumberEnvVarSchema({
1229
- process: createV4ProcessFunction(peeled.schema, "number", schema),
1230
- required: peeled.required,
1231
- default: typeof peeled.default === "number" ? peeled.default : void 0,
1232
- description: peeled.description
1233
- });
1234
- case "enum": {
1235
- const values = extractV4EnumValues(def) || [];
1236
- return new EnumEnvVarSchema({
1237
- process: createV4ProcessFunction(peeled.schema, "enum", schema),
1238
- values,
1239
- required: peeled.required,
1240
- default: typeof peeled.default === "string" ? peeled.default : void 0,
1241
- description: peeled.description
1242
- });
1243
- }
1244
- case "string":
1245
- default: {
1246
- const process$1 = createV4ProcessFunction(peeled.schema, "string", schema);
1247
- const defaultValue = typeof peeled.default === "string" ? peeled.default : void 0;
1248
- return new StringEnvVarSchema({
1249
- process: process$1,
1250
- required: peeled.required,
1251
- default: defaultValue,
1252
- description: peeled.description
1253
- });
1254
- }
1255
- }
1256
- }
1257
-
1258
- //#endregion
1259
- //#region ../converters/src/converters/joi/JoiConverter.ts
1260
- /**
1261
- * Joi schema converter implementation
1262
- */
1263
- var JoiConverter = class {
1264
- applies(schema) {
1265
- return isJoiSchema(schema);
1266
- }
1267
- convert(schema) {
1268
- return convertFromJoiSchema(schema);
1269
- }
1270
- };
1271
- /**
1272
- * Check if a schema is a Joi schema using the official API
1273
- */
1274
- function isJoiSchema(schema) {
1275
- if (!schema || typeof schema !== "object") return false;
1276
- const candidate = schema;
1277
- if (!(typeof candidate.describe === "function" && typeof candidate.validate === "function")) return false;
1278
- if (candidate.isJoi === true) return true;
1279
- const hasAsyncVariant = typeof candidate.validateAsync === "function";
1280
- const hasRoot = typeof candidate.$_root === "object" && candidate.$_root !== null;
1281
- const hasFlags = typeof candidate._flags === "object" && candidate._flags !== null;
1282
- return hasAsyncVariant || hasRoot || hasFlags;
1283
- }
1284
- /**
1285
- * Get description from Joi schema using public API first, internal as fallback
1286
- */
1287
- function getJoiDescription(schema) {
1288
- try {
1289
- return schema.describe()?.flags?.description;
1290
- } catch {
1291
- return schema._flags?.description;
1292
- }
1293
- }
1294
- /**
1295
- * Check if schema is required using public API first, internal as fallback
1296
- */
1297
- function isJoiRequired(schema) {
1298
- try {
1299
- const presence = schema.describe()?.flags?.presence;
1300
- if (presence === "required") return true;
1301
- if (presence === "optional") return false;
1302
- return presence === void 0;
1303
- } catch {
1304
- const flags = schema._flags;
1305
- if (flags?.presence === "required") return true;
1306
- if (flags?.presence === "optional") return false;
1307
- return true;
1308
- }
1309
- }
1310
- /**
1311
- * Get default value from Joi schema using public API first, internal as fallback
1312
- */
1313
- function getJoiDefaultValue(schema) {
1314
- try {
1315
- const defaultValue = schema.describe()?.flags?.default;
1316
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
1317
- } catch {
1318
- const flags = schema._flags;
1319
- if (flags?.default !== void 0) {
1320
- const defaultValue = flags.default;
1321
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
1322
- }
1323
- return;
1324
- }
1325
- }
1326
- /**
1327
- * Get valid values for enum-like schemas using public API first, internal as fallback
1328
- */
1329
- function getJoiValidValues(schema) {
1330
- const values = [];
1331
- let isOnlySchema = false;
1332
- try {
1333
- const description = schema.describe();
1334
- if (description?.allow && Array.isArray(description.allow)) values.push(...description.allow);
1335
- isOnlySchema = description?.flags?.only === true;
1336
- } catch {
1337
- if (schema._valids?._values) values.push(...Array.from(schema._valids._values));
1338
- isOnlySchema = schema._flags?.only === true;
1339
- }
1340
- if (isOnlySchema && values.length > 0) return values.map((v) => String(v));
1341
- }
1342
- /**
1343
- * Resolve environment variable type from Joi schema using public API first, internal as fallback
1344
- */
1345
- function resolveJoiEnvVarType(schema) {
1346
- let type;
1347
- const exposedSchema = schema;
1348
- try {
1349
- type = schema.describe()?.type;
1350
- } catch {
1351
- type = exposedSchema._type || schema.type;
1352
- }
1353
- const validValues = getJoiValidValues(schema);
1354
- if (validValues && validValues.length > 0) return "enum";
1355
- switch (type) {
1356
- case "string": return "string";
1357
- case "number": return "number";
1358
- case "boolean": return "boolean";
1359
- default: return "string";
1360
- }
1361
- }
1362
- /**
1363
- * Create a process function for Joi schemas
1364
- */
1365
- function createJoiProcessFunction(schema, type) {
1366
- return (value) => {
1367
- try {
1368
- let processValue$1 = value;
1369
- if (type === "number") {
1370
- const num = Number(value);
1371
- if (Number.isNaN(num)) throw new Error(`Expected number, received "${value}"`);
1372
- processValue$1 = num;
1373
- } else if (type === "boolean") {
1374
- const lower = value.toLowerCase().trim();
1375
- if ([
1376
- "true",
1377
- "1",
1378
- "yes",
1379
- "on",
1380
- "enabled"
1381
- ].includes(lower)) processValue$1 = true;
1382
- else if ([
1383
- "false",
1384
- "0",
1385
- "no",
1386
- "off",
1387
- "disabled"
1388
- ].includes(lower)) processValue$1 = false;
1389
- else throw new Error(`Expected boolean value, received "${value}"`);
1390
- }
1391
- const result = schema.validate(processValue$1, { convert: true });
1392
- if (result.error) {
1393
- const message = result.error.details ? result.error.details.map((d) => d.message).join("; ") : result.error.message || String(result.error);
1394
- throw new Error(`Validation failed: ${message}`);
1395
- }
1396
- return result.value;
1397
- } catch (error) {
1398
- const message = error instanceof Error ? error.message : String(error);
1399
- throw new Error(message);
1400
- }
1401
- };
1402
- }
1403
- /**
1404
- * Convert Joi schema to EnvVarSchema
1405
- */
1406
- function convertFromJoiSchema(schema) {
1407
- const type = resolveJoiEnvVarType(schema);
1408
- const required = isJoiRequired(schema);
1409
- const defaultValue = getJoiDefaultValue(schema);
1410
- const description = getJoiDescription(schema);
1411
- switch (type) {
1412
- case "boolean": return new BooleanEnvVarSchema({
1413
- process: createJoiProcessFunction(schema, "boolean"),
1414
- required,
1415
- default: typeof defaultValue === "boolean" ? defaultValue : void 0,
1416
- description
1417
- });
1418
- case "number": return new NumberEnvVarSchema({
1419
- process: createJoiProcessFunction(schema, "number"),
1420
- required,
1421
- default: typeof defaultValue === "number" ? defaultValue : void 0,
1422
- description
1423
- });
1424
- case "enum": {
1425
- const values = getJoiValidValues(schema) || [];
1426
- return new EnumEnvVarSchema({
1427
- process: createJoiProcessFunction(schema, "enum"),
1428
- values,
1429
- required,
1430
- default: typeof defaultValue === "string" ? defaultValue : void 0,
1431
- description
1432
- });
1433
- }
1434
- case "string":
1435
- default: return new StringEnvVarSchema({
1436
- process: createJoiProcessFunction(schema, "string"),
1437
- required,
1438
- default: typeof defaultValue === "string" ? defaultValue : void 0,
1439
- description
1440
- });
1441
- }
1442
- }
1443
-
1444
- //#endregion
1445
- //#region ../converters/src/converters/superstruct/SuperstructConverter.ts
1446
- /**
1447
- * Superstruct schema converter implementation
1448
- */
1449
- var SuperstructConverter = class {
1450
- applies(schema) {
1451
- return isSuperstructSchema(schema);
1452
- }
1453
- convert(schema) {
1454
- return convertFromSuperstruct(schema);
1455
- }
1456
- };
1457
- /**
1458
- * Detect if a value looks like a Superstruct Struct instance
1459
- */
1460
- function isSuperstructSchema(value) {
1461
- if (!value || typeof value !== "object") return false;
1462
- const candidate = value;
1463
- return typeof candidate.type === "string" && typeof candidate.validate === "function" && typeof candidate.create === "function";
1464
- }
1465
- /**
1466
- * Convert a Superstruct schema to an EnvVarSchema
1467
- */
1468
- function convertFromSuperstruct(schema) {
1469
- const resolvedType = resolveSuperstructEnvVarType(schema);
1470
- const required = isStructRequired(schema);
1471
- const description = getStructDescription(schema);
1472
- const defaultValue = getStructDefault(schema);
1473
- if (resolvedType === "enum") {
1474
- const values = extractEnumValues(schema);
1475
- if (!values || values.length === 0) return createStringEnvVarSchema(schema, required, defaultValue, description);
1476
- const readonlyValues = values;
1477
- return new EnumEnvVarSchema({
1478
- process: createSuperstructProcessFunction(schema, "enum"),
1479
- values: readonlyValues,
1480
- required,
1481
- default: typeof defaultValue === "string" ? defaultValue : void 0,
1482
- description
1483
- });
1484
- }
1485
- if (resolvedType === "boolean") return new BooleanEnvVarSchema({
1486
- process: createSuperstructProcessFunction(schema, "boolean"),
1487
- required,
1488
- default: typeof defaultValue === "boolean" ? defaultValue : void 0,
1489
- description
1490
- });
1491
- if (resolvedType === "number") return new NumberEnvVarSchema({
1492
- process: createSuperstructProcessFunction(schema, "number"),
1493
- required,
1494
- default: typeof defaultValue === "number" ? defaultValue : void 0,
1495
- description
1496
- });
1497
- return createStringEnvVarSchema(schema, required, defaultValue, description);
1498
- }
1499
- function createStringEnvVarSchema(schema, required, defaultValue, description) {
1500
- return new StringEnvVarSchema({
1501
- process: createSuperstructProcessFunction(schema, "string"),
1502
- required,
1503
- default: typeof defaultValue === "string" ? defaultValue : void 0,
1504
- description
1505
- });
1506
- }
1507
- function resolveSuperstructEnvVarType(schema) {
1508
- switch (getStructType(schema)) {
1509
- case "boolean": return "boolean";
1510
- case "number":
1511
- case "integer": return "number";
1512
- case "enums": return "enum";
1513
- case "literal": return typeof schema.schema === "string" ? "enum" : "string";
1514
- default: return "string";
1515
- }
1516
- }
1517
- function getStructType(schema) {
1518
- const typeValue = schema.type;
1519
- return typeof typeValue === "string" ? typeValue : "unknown";
1520
- }
1521
- function extractEnumValues(schema) {
1522
- const typeName = getStructType(schema);
1523
- if (typeName === "enums") {
1524
- const structSchema = schema.schema;
1525
- if (structSchema && typeof structSchema === "object") {
1526
- const rawValues = Object.values(structSchema);
1527
- if (rawValues.every((value) => typeof value === "string")) return rawValues;
1528
- }
1529
- }
1530
- if (typeName === "literal") {
1531
- const value = schema.schema;
1532
- if (typeof value === "string") return [value];
1533
- }
1534
- }
1535
- function isStructRequired(schema) {
1536
- try {
1537
- const [error] = schema.validate(void 0);
1538
- return !!error;
1539
- } catch {
1540
- return true;
1541
- }
1542
- }
1543
- function getStructDefault(schema) {
1544
- try {
1545
- const [error, value] = schema.validate(void 0, { coerce: true });
1546
- if (!error && value !== void 0) return value;
1547
- } catch {}
1548
- }
1549
- function getStructDescription(schema) {
1550
- const structSchema = schema.schema;
1551
- if (structSchema && typeof structSchema === "object" && typeof structSchema.description === "string") return structSchema.description;
1552
- if (typeof schema.description === "string") return schema.description;
1553
- }
1554
- function createSuperstructProcessFunction(schema, type) {
1555
- return (value) => {
1556
- if (typeof value !== "string") throw new Error("Value must be a string");
1557
- let candidate = value;
1558
- if (type === "number") {
1559
- const trimmed = value.trim();
1560
- if (trimmed === "") candidate = void 0;
1561
- else {
1562
- const parsed = Number(trimmed);
1563
- if (Number.isNaN(parsed) || !Number.isFinite(parsed)) throw new Error(`"${value}" is not a valid number`);
1564
- candidate = parsed;
1565
- }
1566
- } else if (type === "boolean") {
1567
- const trimmed = value.trim().toLowerCase();
1568
- if (trimmed === "") candidate = void 0;
1569
- else if ([
1570
- "true",
1571
- "1",
1572
- "yes",
1573
- "on",
1574
- "enabled"
1575
- ].includes(trimmed)) candidate = true;
1576
- else if ([
1577
- "false",
1578
- "0",
1579
- "no",
1580
- "off",
1581
- "disabled"
1582
- ].includes(trimmed)) candidate = false;
1583
- else throw new Error(`"${value}" is not a valid boolean. Use: true/false, 1/0, yes/no, on/off, or enabled/disabled`);
1584
- } else if (value === "") candidate = void 0;
1585
- const [error, result] = schema.validate(candidate, { coerce: true });
1586
- if (error) throw new Error(error.message);
1587
- return result;
1588
- };
1589
- }
1590
-
1591
- //#endregion
1592
- //#region ../converters/src/converters.ts
1593
- /**
1594
- * Registry of available schema converters
1595
- */
1596
- const converters = [
1597
- new ZodV4Converter(),
1598
- new ZodV3Converter(),
1599
- new JoiConverter(),
1600
- new SuperstructConverter()
1601
- ];
1602
-
1603
- //#endregion
1604
- //#region ../models/src/resolve.ts
1605
- /**
1606
- * Resolve any supported schema to a EnvVarSchema.
1607
- *
1608
- * This is the main entry point for converting external schemas
1609
- * (like Zod schemas) to envcredible's internal schema format.
1610
- * If the input is already a EnvVarSchema, it returns it directly.
1611
- *
1612
- * @param schema - The schema to convert (e.g., Zod v3/v4 schema or EnvVarSchema)
1613
- * @returns EnvVarSchema that can be used with envcredible
1614
- * @throws Error if no converter can handle the schema
1615
- */
1616
- function resolveSchema(schema) {
1617
- if (isEnvVarSchema(schema)) return schema;
1618
- for (const converter of converters) if (converter.applies(schema)) return converter.convert(schema);
1619
- throw new Error(`No converter found for schema. Supported types: Zod v3, Zod v4, Joi, Superstruct, EnvVarSchema. Received: ${typeof schema}`);
1620
- }
1621
- /**
1622
- * Resolve mixed schema map (Zod schemas or EnvVarSchema) to pure EnvVarSchema map.
1623
- *
1624
- * This function takes a map where values can be:
1625
- * - Zod v3 schemas
1626
- * - Zod v4 schemas
1627
- * - Already resolved EnvVarSchema instances
1628
- *
1629
- * And converts everything to EnvVarSchema instances that can be used throughout envcredible.
1630
- *
1631
- * @param schemas - Object mapping environment variable names to various schema types
1632
- * @returns Record mapping env var names to EnvVarSchema instances
1633
- */
1634
- function resolveSchemas(schemas) {
1635
- const resolved = {};
1636
- for (const [key, schema] of Object.entries(schemas)) try {
1637
- resolved[key] = resolveSchema(schema);
1638
- } catch (error) {
1639
- const message = error instanceof Error ? error.message : String(error);
1640
- throw new Error(`Failed to resolve schema for environment variable "${key}": ${message}`);
1641
- }
1642
- return resolved;
1643
- }
1644
-
1645
- //#endregion
1646
- //#region ../models/src/EnvModel.ts
1647
- /**
1648
- * Environment variable specification container
1649
- * Encapsulates schemas and preprocessor configuration
1650
- */
1651
- var EnvModel = class {
1652
- /**
1653
- * Resolved environment variable schemas
1654
- */
1655
- schemas;
1656
- /**
1657
- * Preprocessing configuration for environment variable types
1658
- */
1659
- preprocess;
1660
- /**
1661
- * Create an EnvModel instance from options
1662
- * @param options - Specification options
1663
- */
1664
- constructor(options) {
1665
- this.schemas = resolveSchemas(options.schemas);
1666
- this.preprocess = this.resolvePreprocessors(options.preprocess);
1667
- }
1668
- /**
1669
- * Resolve preprocessor configuration from options
1670
- * @param config - Preprocessor configuration (true, false, or partial object)
1671
- * @returns Resolved preprocessors object
1672
- */
1673
- resolvePreprocessors(config) {
1674
- if (config === false) return {
1675
- string: false,
1676
- number: false,
1677
- boolean: false,
1678
- enum: false
1679
- };
1680
- if (config === true || config === void 0) return {};
1681
- return { ...config };
1682
- }
1683
- };
1684
-
1685
- //#endregion
1686
- //#region ../models/src/model.ts
1687
- /**
1688
- * Create an environment variable model
1689
- *
1690
- * Sugar utility for creating EnvModel instances with full type inference
1691
- *
1692
- * @param options - Model options
1693
- * @returns EnvModel instance with inferred types
1694
- *
1695
- * @example
1696
- * ```typescript
1697
- * import { define, s } from "@e-n-v/models";
1698
- *
1699
- * export default define({
1700
- * schemas: {
1701
- * PORT: s.number({ default: 3000 }),
1702
- * DATABASE_URL: s.string(),
1703
- * DEBUG: s.boolean({ default: false })
1704
- * },
1705
- * preprocess: true
1706
- * });
1707
- * ```
1708
- */
1709
- function define(options) {
1710
- return new EnvModel(options);
1711
- }
1712
-
1713
- //#endregion
1714
12
  //#region ../prompt/src/options/defaults.ts
1715
13
  var defaults_exports = /* @__PURE__ */ __export({
1716
14
  ENV_PATH: () => ENV_PATH,
@@ -1723,7 +21,7 @@ const SECRET_PATTERNS = Object.freeze([
1723
21
  /password/i,
1724
22
  /passphrase/i,
1725
23
  /secret/i,
1726
- /token/i,
24
+ /(?<!expires[_-]?in[_-]?)token(?![_-]?(?:expires|expiry|expiration|ttl|lifetime|duration|age|max[_-]?age|validity))/i,
1727
25
  /api[_-]?key/i,
1728
26
  /client[_-]?secret/i,
1729
27
  /private[_-]?key/i,
@@ -2215,23 +513,13 @@ function processValue(envKey, value, schema, preprocess) {
2215
513
  return resolvePreprocessor(schema.type);
2216
514
  })();
2217
515
  const processedValue = activePreprocessor ? activePreprocessor(value) : value;
2218
- if (schema.type === "boolean" && typeof processedValue === "boolean") return {
2219
- value: processedValue,
2220
- rawValue: value,
2221
- isValid: true
2222
- };
2223
- if (schema.type === "number" && typeof processedValue === "number") return {
2224
- value: processedValue,
2225
- rawValue: value,
2226
- isValid: true
2227
- };
2228
- if (typeof processedValue === "string") return {
2229
- value: schema.process(processedValue),
2230
- rawValue: value,
2231
- isValid: true
2232
- };
516
+ let stringValue;
517
+ if (typeof processedValue === "boolean") stringValue = String(processedValue);
518
+ else if (typeof processedValue === "number") stringValue = String(processedValue);
519
+ else if (typeof processedValue === "string") stringValue = processedValue;
520
+ else stringValue = value;
2233
521
  return {
2234
- value: schema.process(value),
522
+ value: schema.process(stringValue),
2235
523
  rawValue: value,
2236
524
  isValid: true
2237
525
  };
@@ -3624,10 +1912,10 @@ function createPrompt({ key, schema, currentValue, theme, truncate, shouldMask,
3624
1912
  const booleanOverride = preprocessors$1?.boolean;
3625
1913
  let booleanPreprocess;
3626
1914
  if (booleanOverride === void 0) booleanPreprocess = void 0;
3627
- else if (booleanOverride === true) booleanPreprocess = booleanPreprocessor();
1915
+ else if (booleanOverride === true) booleanPreprocess = preprocessors.boolean();
3628
1916
  else if (booleanOverride === false) booleanPreprocess = false;
3629
1917
  else if (typeof booleanOverride === "function") booleanPreprocess = booleanOverride;
3630
- else booleanPreprocess = booleanPreprocessor(booleanOverride);
1918
+ else booleanPreprocess = preprocessors.boolean(booleanOverride);
3631
1919
  return new EnvBooleanPrompt(schema, {
3632
1920
  ...baseOptions,
3633
1921
  current: currentValue,
@@ -3857,4 +2145,4 @@ async function prompt(modelOrOptions, interactiveOptions) {
3857
2145
  }
3858
2146
 
3859
2147
  //#endregion
3860
- export { set as A, EnvVarSchemaBase as C, DotEnvChannel as D, DotEnvXChannel as E, DefaultEnvChannel as O, stringProcessor as S, ProcessEnvChannel as T, BooleanEnvVarSchema as _, resolveSchema as a, numberProcessor as b, booleanPreprocessor as c, preprocessors as d, stringPreprocessor as f, EnumEnvVarSchema as g, NumberEnvVarSchema as h, EnvModel as i, get as j, EnvSource as k, enumPreprocessor as l, StringEnvVarSchema as m, defaults_exports as n, resolveSchemas as o, isEnvVarSchema as p, define as r, resolvePreprocessor as s, prompt as t, numberPreprocessor as u, booleanProcessor as v, resolveChannel as w, processors as x, enumProcessor as y };
2148
+ export { defaults_exports as n, prompt as t };