envapt 4.0.2 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@ var __defProp = Object.defineProperty;
13
13
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
14
 
15
15
  // src/Error.ts
16
- var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2) => {
16
+ var EnvaptErrorCodes = /* @__PURE__ */ (function(EnvaptErrorCodes2) {
17
17
  EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallback"] = 101] = "InvalidFallback";
18
18
  EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallbackType"] = 102] = "InvalidFallbackType";
19
19
  EnvaptErrorCodes2[EnvaptErrorCodes2["ArrayFallbackElementTypeMismatch"] = 103] = "ArrayFallbackElementTypeMismatch";
@@ -26,8 +26,9 @@ var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2) => {
26
26
  EnvaptErrorCodes2[EnvaptErrorCodes2["MissingDelimiter"] = 301] = "MissingDelimiter";
27
27
  EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidUserDefinedConfig"] = 302] = "InvalidUserDefinedConfig";
28
28
  EnvaptErrorCodes2[EnvaptErrorCodes2["EnvFilesNotFound"] = 303] = "EnvFilesNotFound";
29
+ EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidKeyInput"] = 304] = "InvalidKeyInput";
29
30
  return EnvaptErrorCodes2;
30
- })(EnvaptErrorCodes || {});
31
+ })({});
31
32
  var EnvaptError = class extends Error {
32
33
  static {
33
34
  __name(this, "EnvaptError");
@@ -102,19 +103,18 @@ var Validator = class {
102
103
  */
103
104
  static isValidArrayConverterType(value) {
104
105
  if (typeof value !== "string") return false;
105
- const invalidTypes = ["array", "json", "regexp"];
106
+ const invalidTypes = [
107
+ "array",
108
+ "json",
109
+ "regexp"
110
+ ];
106
111
  if (invalidTypes.includes(value)) return false;
107
- const validTypes = ListOfBuiltInConverters.filter(
108
- (type) => !invalidTypes.includes(type)
109
- );
112
+ const validTypes = ListOfBuiltInConverters.filter((type) => !invalidTypes.includes(type));
110
113
  return validTypes.includes(value);
111
114
  }
112
115
  static customConvertor(converter) {
113
116
  if (typeof converter !== "function") {
114
- throw new EnvaptError(
115
- 203 /* InvalidCustomConverter */,
116
- `Custom converter must be a function, got ${typeof converter}.`
117
- );
117
+ throw new EnvaptError(EnvaptErrorCodes.InvalidCustomConverter, `Custom converter must be a function, got ${typeof converter}.`);
118
118
  }
119
119
  }
120
120
  /**
@@ -122,13 +122,10 @@ var Validator = class {
122
122
  */
123
123
  static arrayConverter(value) {
124
124
  if (!this.isArrayConverter(value)) {
125
- throw new EnvaptError(301 /* MissingDelimiter */, "Must have delimiter property");
125
+ throw new EnvaptError(EnvaptErrorCodes.MissingDelimiter, "Must have delimiter property");
126
126
  }
127
127
  if (value.type !== void 0 && !this.isValidArrayConverterType(value.type)) {
128
- throw new EnvaptError(
129
- 201 /* InvalidArrayConverterType */,
130
- `"${value.type}" is not a valid converter type`
131
- );
128
+ throw new EnvaptError(EnvaptErrorCodes.InvalidArrayConverterType, `"${value.type}" is not a valid converter type`);
132
129
  }
133
130
  }
134
131
  /**
@@ -136,13 +133,10 @@ var Validator = class {
136
133
  */
137
134
  static builtInConverter(value) {
138
135
  if (typeof value !== "string") {
139
- throw new EnvaptError(204 /* InvalidConverterType */, `Expected string, got ${typeof value}`);
136
+ throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);
140
137
  }
141
138
  if (!ListOfBuiltInConverters.includes(value)) {
142
- throw new EnvaptError(
143
- 202 /* InvalidBuiltInConverter */,
144
- `"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`
145
- );
139
+ throw new EnvaptError(EnvaptErrorCodes.InvalidBuiltInConverter, `"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`);
146
140
  }
147
141
  }
148
142
  /**
@@ -151,10 +145,7 @@ var Validator = class {
151
145
  static validateBuiltInConverterFallback(converter, fallback) {
152
146
  const typeChecker = BuiltInConverterTypeCheckers[converter];
153
147
  if (!typeChecker(fallback)) {
154
- throw new EnvaptError(
155
- 104 /* FallbackConverterTypeMismatch */,
156
- `Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`
157
- );
148
+ throw new EnvaptError(EnvaptErrorCodes.FallbackConverterTypeMismatch, `Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`);
158
149
  }
159
150
  }
160
151
  /**
@@ -168,10 +159,7 @@ var Validator = class {
168
159
  return typeof element !== firstElementType;
169
160
  });
170
161
  if (hasInconsistentTypes) {
171
- throw new EnvaptError(
172
- 103 /* ArrayFallbackElementTypeMismatch */,
173
- `All elements in array fallback must have the same type. Found mixed types.`
174
- );
162
+ throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `All elements in array fallback must have the same type. Found mixed types.`);
175
163
  }
176
164
  }
177
165
  /**
@@ -182,10 +170,7 @@ var Validator = class {
182
170
  const firstElement = fallback[0];
183
171
  const typeChecker = BuiltInConverterTypeCheckers[converterType];
184
172
  if (!typeChecker(firstElement)) {
185
- throw new EnvaptError(
186
- 103 /* ArrayFallbackElementTypeMismatch */,
187
- `Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`
188
- );
173
+ throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`);
189
174
  }
190
175
  }
191
176
  /**
@@ -223,33 +208,27 @@ var Validator = class {
223
208
  if (converter === BigInt) return BigInt(fallback);
224
209
  if (converter === Symbol) return Symbol.for(String(fallback));
225
210
  } catch (error) {
226
- throw new EnvaptError(
227
- 205 /* PrimitiveCoercionFailed */,
228
- `Failed to coerce fallback value using ${converter.name}: ${error.message}`
229
- );
211
+ throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Failed to coerce fallback value using ${converter.name}: ${error.message}`);
230
212
  }
231
- throw new EnvaptError(
232
- 205 /* PrimitiveCoercionFailed */,
233
- `Unknown primitive converter: ${converter.name}`
234
- );
213
+ throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Unknown primitive converter: ${converter.name}`);
235
214
  }
236
215
  /**
237
216
  * Make sure the user hasn't provided prohibited options in their dotenv config
238
217
  */
239
218
  static validateDotenvConfig(config2) {
240
219
  if ("path" in config2 || "processEnv" in config2) {
241
- throw new EnvaptError(
242
- 302 /* InvalidUserDefinedConfig */,
243
- 'Custom dotenvConfig should not include "path" or "processEnv" options. Those are managed by Envapter.'
244
- );
220
+ throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, 'Custom dotenvConfig should not include "path" or "processEnv" options. Those are managed by Envapter.');
245
221
  }
246
- const validKeys = /* @__PURE__ */ new Set(["encoding", "quiet", "debug", "override", "DOTENV_KEY"]);
222
+ const validKeys = /* @__PURE__ */ new Set([
223
+ "encoding",
224
+ "quiet",
225
+ "debug",
226
+ "override",
227
+ "DOTENV_KEY"
228
+ ]);
247
229
  const invalidKeys = Object.keys(config2).filter((key) => !validKeys.has(key));
248
230
  if (invalidKeys.length > 0) {
249
- throw new EnvaptError(
250
- 302 /* InvalidUserDefinedConfig */,
251
- `Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`
252
- );
231
+ throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, `Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`);
253
232
  }
254
233
  return true;
255
234
  }
@@ -266,10 +245,7 @@ var Validator = class {
266
245
  }
267
246
  });
268
247
  if (missing.length > 0) {
269
- throw new EnvaptError(
270
- 303 /* EnvFilesNotFound */,
271
- `Environment file not found at path: ${missing.join(", ")}`
272
- );
248
+ throw new EnvaptError(EnvaptErrorCodes.EnvFilesNotFound, `Environment file not found at path: ${missing.join(", ")}`);
273
249
  }
274
250
  }
275
251
  };
@@ -280,15 +256,20 @@ var EnvapterBase = class _EnvapterBase {
280
256
  static {
281
257
  __name(this, "EnvapterBase");
282
258
  }
283
- static _envPaths = [".env"];
284
- // default path
285
- static _userDefinedDotenvConfig = { quiet: true };
259
+ static _envPaths = [
260
+ ".env"
261
+ ];
262
+ static _userDefinedDotenvConfig = {
263
+ quiet: true
264
+ };
286
265
  /**
287
266
  * Set custom .env file paths. Accepts either a single path or array of paths.
288
267
  * Setting new paths clears the cache and reloads environment variables.
289
268
  */
290
269
  static set envPaths(paths) {
291
- const newPaths = Array.isArray(paths) ? paths : [paths];
270
+ const newPaths = Array.isArray(paths) ? paths : [
271
+ paths
272
+ ];
292
273
  Validator.validateEnvFilesExist(newPaths);
293
274
  this._envPaths = newPaths;
294
275
  this.refreshCache();
@@ -317,11 +298,45 @@ var EnvapterBase = class _EnvapterBase {
317
298
  EnvaptCache.clear();
318
299
  void this.config;
319
300
  }
301
+ static resolveKeyInput(keyInput) {
302
+ const keys = Array.isArray(keyInput) ? keyInput : [
303
+ keyInput
304
+ ];
305
+ const normalizedKeys = keys;
306
+ if (normalizedKeys.length === 0) {
307
+ throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "At least one environment key must be provided.");
308
+ }
309
+ if (normalizedKeys.some((k) => typeof k !== "string")) {
310
+ throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys must be strings.");
311
+ }
312
+ if (normalizedKeys.some((k) => k.trim() === "")) {
313
+ throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys cannot be empty strings.");
314
+ }
315
+ for (const candidate of normalizedKeys) {
316
+ const value = this.config.get(candidate);
317
+ if (value !== void 0) {
318
+ return {
319
+ key: candidate,
320
+ value
321
+ };
322
+ }
323
+ }
324
+ return {
325
+ key: normalizedKeys[0],
326
+ value: void 0
327
+ };
328
+ }
320
329
  static get config() {
321
330
  if (EnvaptCache.size === 0) {
322
- const isolatedEnv = { ...process__default.default.env };
331
+ const isolatedEnv = {
332
+ ...process__default.default.env
333
+ };
323
334
  try {
324
- dotenv.config({ path: this._envPaths, processEnv: isolatedEnv, ...this._userDefinedDotenvConfig });
335
+ dotenv.config({
336
+ path: this._envPaths,
337
+ processEnv: isolatedEnv,
338
+ ...this._userDefinedDotenvConfig
339
+ });
325
340
  } catch {
326
341
  }
327
342
  for (const [key, value] of Object.entries(isolatedEnv)) EnvaptCache.set(key, value);
@@ -332,7 +347,7 @@ var EnvapterBase = class _EnvapterBase {
332
347
  * Get raw environment variable value without parsing or conversion.
333
348
  */
334
349
  getRaw(key) {
335
- return _EnvapterBase.config.get(key);
350
+ return _EnvapterBase.resolveKeyInput(key).value;
336
351
  }
337
352
  };
338
353
 
@@ -350,8 +365,18 @@ var BuiltInConverters = class _BuiltInConverters {
350
365
  }
351
366
  static boolean(raw, fallback) {
352
367
  const lower = raw.toLowerCase().trim();
353
- const truthyValues = ["1", "yes", "true", "on"];
354
- const falsyValues = ["0", "no", "false", "off"];
368
+ const truthyValues = [
369
+ "1",
370
+ "yes",
371
+ "true",
372
+ "on"
373
+ ];
374
+ const falsyValues = [
375
+ "0",
376
+ "no",
377
+ "false",
378
+ "off"
379
+ ];
355
380
  if (truthyValues.includes(lower)) return true;
356
381
  if (falsyValues.includes(lower)) return false;
357
382
  return fallback;
@@ -475,13 +500,14 @@ var BuiltInConverters = class _BuiltInConverters {
475
500
 
476
501
  // src/Parser.ts
477
502
  var Parser = class {
478
- constructor(envService) {
479
- this.envService = envService;
480
- }
481
503
  static {
482
504
  __name(this, "Parser");
483
505
  }
506
+ envService;
484
507
  TEMPLATE_REGEX = /\${\w*}/g;
508
+ constructor(envService) {
509
+ this.envService = envService;
510
+ }
485
511
  /**
486
512
  * Resolve template variables in a string while handling circular references and missing variables
487
513
  * @internal
@@ -528,7 +554,7 @@ var Parser = class {
528
554
  if (primitiveConstructor === Boolean) return "boolean";
529
555
  if (primitiveConstructor === BigInt) return "bigint";
530
556
  if (primitiveConstructor === Symbol) return "symbol";
531
- throw new EnvaptError(204 /* InvalidConverterType */, `Unknown primitive constructor`);
557
+ throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Unknown primitive constructor`);
532
558
  }
533
559
  processBuiltInConverter(key, fallback, resolvedConverter, hasFallback, wasOriginallyConstructor) {
534
560
  Validator.builtInConverter(resolvedConverter);
@@ -548,10 +574,7 @@ var Parser = class {
548
574
  processArrayConverter(key, fallback, resolvedConverter, hasFallback) {
549
575
  Validator.arrayConverter(resolvedConverter);
550
576
  if (hasFallback && fallback !== void 0 && !Array.isArray(fallback)) {
551
- throw new EnvaptError(
552
- 101 /* InvalidFallback */,
553
- `ArrayConverter requires that the fallback be an array, got ${typeof fallback}`
554
- );
577
+ throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, `ArrayConverter requires that the fallback be an array, got ${typeof fallback}`);
555
578
  }
556
579
  if (hasFallback && Array.isArray(fallback)) {
557
580
  Validator.validateArrayFallbackElementTypes(fallback);
@@ -582,12 +605,12 @@ var Parser = class {
582
605
  };
583
606
 
584
607
  // src/core/EnvironmentMethods.ts
585
- var Environment = /* @__PURE__ */ ((Environment2) => {
608
+ var Environment = /* @__PURE__ */ (function(Environment2) {
586
609
  Environment2[Environment2["Development"] = 0] = "Development";
587
610
  Environment2[Environment2["Staging"] = 1] = "Staging";
588
611
  Environment2[Environment2["Production"] = 2] = "Production";
589
612
  return Environment2;
590
- })(Environment || {});
613
+ })({});
591
614
  var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
592
615
  static {
593
616
  __name(this, "EnvironmentMethods");
@@ -596,7 +619,7 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
596
619
  static determineEnvironment(env) {
597
620
  const environment = env ?? this.getRawValue("ENVIRONMENT", this.getRawValue("ENV", this.getRawValue("NODE_ENV", "development")));
598
621
  if (typeof environment === "string") {
599
- this._environment = environment.toLowerCase() === "production" ? 2 /* Production */ : environment === "staging" ? 1 /* Staging */ : 0 /* Development */;
622
+ this._environment = environment.toLowerCase() === "production" ? 2 : environment === "staging" ? 1 : 0;
600
623
  } else {
601
624
  this._environment = environment;
602
625
  }
@@ -635,37 +658,37 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
635
658
  * Check if the current environment is production
636
659
  */
637
660
  static get isProduction() {
638
- return this.environment === 2 /* Production */;
661
+ return this.environment === 2;
639
662
  }
640
663
  /**
641
664
  * @see {@link EnvironmentMethods.isProduction}
642
665
  */
643
666
  get isProduction() {
644
- return _EnvironmentMethods.environment === 2 /* Production */;
667
+ return _EnvironmentMethods.environment === 2;
645
668
  }
646
669
  /**
647
670
  * Check if the current environment is staging
648
671
  */
649
672
  static get isStaging() {
650
- return this.environment === 1 /* Staging */;
673
+ return this.environment === 1;
651
674
  }
652
675
  /**
653
676
  * @see {@link EnvironmentMethods.isStaging}
654
677
  */
655
678
  get isStaging() {
656
- return _EnvironmentMethods.environment === 1 /* Staging */;
679
+ return _EnvironmentMethods.environment === 1;
657
680
  }
658
681
  /**
659
682
  * Check if the current environment is development
660
683
  */
661
684
  static get isDevelopment() {
662
- return this.environment === 0 /* Development */;
685
+ return this.environment === 0;
663
686
  }
664
687
  /**
665
688
  * @see {@link EnvironmentMethods.isDevelopment}
666
689
  */
667
690
  get isDevelopment() {
668
- return _EnvironmentMethods.environment === 0 /* Development */;
691
+ return _EnvironmentMethods.environment === 0;
669
692
  }
670
693
  static refreshCache() {
671
694
  super.refreshCache();
@@ -680,84 +703,84 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
680
703
  }
681
704
  static parser = new Parser(new _PrimitiveMethods());
682
705
  static _get(key, type, def) {
683
- const rawVal = this.config.get(key);
706
+ const { key: resolvedKey, value } = this.resolveKeyInput(key);
707
+ const rawVal = value;
684
708
  if (!rawVal) return def;
685
- const parsed = this.parser.resolveTemplate(key, String(rawVal));
709
+ const parsed = this.parser.resolveTemplate(resolvedKey, String(rawVal));
686
710
  let result;
687
- if (type === 1 /* Number */) result = BuiltInConverters.number(parsed, def);
688
- else if (type === 2 /* Boolean */)
689
- result = BuiltInConverters.boolean(parsed, def);
690
- else if (type === 3 /* BigInt */)
691
- result = BuiltInConverters.bigint(parsed, def);
692
- else if (type === 4 /* Symbol */)
693
- result = BuiltInConverters.symbol(parsed, def);
711
+ if (type === 1) result = BuiltInConverters.number(parsed, def);
712
+ else if (type === 2) result = BuiltInConverters.boolean(parsed, def);
713
+ else if (type === 3) result = BuiltInConverters.bigint(parsed, def);
714
+ else if (type === 4) result = BuiltInConverters.symbol(parsed, def);
694
715
  else result = BuiltInConverters.string(parsed, def);
695
716
  return result;
696
717
  }
697
718
  /**
698
719
  * Get a string environment variable with optional fallback.
699
- * Supports template variable resolution using $\{VAR\} syntax.
720
+ * Supports template variable resolution using `${VAR}` syntax.
721
+ * Accepts a single key or an ordered array of keys (first match wins).
700
722
  */
701
723
  static get(key, def) {
702
- return this._get(key, 0 /* String */, def);
724
+ return this._get(key, 0, def);
703
725
  }
704
- /**
705
- * @see {@link PrimitiveMethods.get}
706
- */
707
726
  get(key, def) {
708
- return _PrimitiveMethods._get(key, 0 /* String */, def);
727
+ return _PrimitiveMethods._get(key, 0, def);
709
728
  }
710
729
  /**
711
730
  * Get a number environment variable with optional fallback.
712
731
  * Automatically converts string values to numbers.
732
+ * Accepts a single key or an ordered array of keys (first match wins).
713
733
  */
714
734
  static getNumber(key, def) {
715
- return this._get(key, 1 /* Number */, def);
735
+ return this._get(key, 1, def);
716
736
  }
717
737
  /**
718
738
  * @see {@link PrimitiveMethods.getNumber}
719
739
  */
720
740
  getNumber(key, def) {
721
- return _PrimitiveMethods._get(key, 1 /* Number */, def);
741
+ return _PrimitiveMethods._get(key, 1, def);
722
742
  }
723
743
  /**
724
744
  * Get a boolean environment variable with optional fallback.
725
745
  * Recognizes: `1`, `yes`, `true`, 'on' as **true**; `0`, `no`, `false`, 'off' as **false** (case-insensitive).
746
+ * Accepts a single key or an ordered array of keys (first match wins).
726
747
  */
727
748
  static getBoolean(key, def) {
728
- return this._get(key, 2 /* Boolean */, def);
749
+ return this._get(key, 2, def);
729
750
  }
730
751
  /**
731
752
  * @see {@link PrimitiveMethods.getBoolean}
732
753
  */
733
754
  getBoolean(key, def) {
734
- return _PrimitiveMethods._get(key, 2 /* Boolean */, def);
755
+ return _PrimitiveMethods._get(key, 2, def);
735
756
  }
736
757
  /**
737
758
  * Get a bigint environment variable with optional fallback.
738
759
  * Automatically converts string values to bigint.
760
+ * Accepts a single key or an ordered array of keys (first match wins).
739
761
  */
740
762
  static getBigInt(key, def) {
741
- return this._get(key, 3 /* BigInt */, def);
763
+ return this._get(key, 3, def);
742
764
  }
743
765
  /**
744
766
  * @see {@link PrimitiveMethods.getBigInt}
745
767
  */
746
768
  getBigInt(key, def) {
747
- return _PrimitiveMethods._get(key, 3 /* BigInt */, def);
769
+ return _PrimitiveMethods._get(key, 3, def);
748
770
  }
749
771
  /**
750
772
  * Get a symbol environment variable with optional fallback.
751
773
  * Creates a symbol from the string value.
774
+ * Accepts a single key or an ordered array of keys (first match wins).
752
775
  */
753
776
  static getSymbol(key, def) {
754
- return this._get(key, 4 /* Symbol */, def);
777
+ return this._get(key, 4, def);
755
778
  }
756
779
  /**
757
780
  * @see {@link PrimitiveMethods.getSymbol}
758
781
  */
759
782
  getSymbol(key, def) {
760
- return _PrimitiveMethods._get(key, 4 /* Symbol */, def);
783
+ return _PrimitiveMethods._get(key, 4, def);
761
784
  }
762
785
  };
763
786
 
@@ -767,10 +790,10 @@ var AdvancedMethods = class _AdvancedMethods extends PrimitiveMethods {
767
790
  __name(this, "AdvancedMethods");
768
791
  }
769
792
  static getUsing(key, converter, fallback) {
770
- const rawVal = this.config.get(key);
771
- if (!rawVal) return fallback;
793
+ const { key: resolvedKey, value } = this.resolveKeyInput(key);
794
+ if (!value) return fallback;
772
795
  const hasFallback = fallback !== void 0;
773
- const result = this.parser.convertValue(key, fallback, converter, hasFallback);
796
+ const result = this.parser.convertValue(resolvedKey, fallback, converter, hasFallback);
774
797
  return result;
775
798
  }
776
799
  getUsing(key, converter, fallback) {
@@ -778,17 +801,13 @@ var AdvancedMethods = class _AdvancedMethods extends PrimitiveMethods {
778
801
  }
779
802
  /**
780
803
  * Get an environment variable using a custom converter function.
804
+ * Accepts a single key or an ordered list for automatic fallback.
781
805
  */
782
806
  static getWith(key, converter, fallback) {
783
- const rawVal = this.config.get(key);
784
- if (!rawVal) return fallback;
807
+ const { key: resolvedKey, value } = this.resolveKeyInput(key);
808
+ if (!value) return fallback;
785
809
  const hasFallback = fallback !== void 0;
786
- const result = this.parser.convertValue(
787
- key,
788
- fallback,
789
- converter,
790
- hasFallback
791
- );
810
+ const result = this.parser.convertValue(resolvedKey, fallback, converter, hasFallback);
792
811
  return result;
793
812
  }
794
813
  /**
@@ -875,7 +894,7 @@ function Envapt(key, fallbackOrOptions, converter) {
875
894
  __name(Envapt, "Envapt");
876
895
 
877
896
  // src/Converters.ts
878
- var Converters = /* @__PURE__ */ ((Converters2) => {
897
+ var Converters = /* @__PURE__ */ (function(Converters2) {
879
898
  Converters2["String"] = "string";
880
899
  Converters2["Number"] = "number";
881
900
  Converters2["Boolean"] = "boolean";
@@ -890,7 +909,7 @@ var Converters = /* @__PURE__ */ ((Converters2) => {
890
909
  Converters2["Date"] = "date";
891
910
  Converters2["Time"] = "time";
892
911
  return Converters2;
893
- })(Converters || {});
912
+ })({});
894
913
  /* v8 ignore next -- @preserve */
895
914
 
896
915
  exports.Converters = Converters;