envapt 5.0.2 → 5.1.0
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/CHANGELOG.md +12 -0
- package/dist/Debug.cjs +2 -0
- package/dist/Debug.cjs.map +1 -0
- package/dist/Debug.d.cts +13 -0
- package/dist/Debug.d.cts.map +1 -0
- package/dist/Debug.d.mts +13 -0
- package/dist/Debug.d.mts.map +1 -0
- package/dist/Debug.mjs +2 -0
- package/dist/Debug.mjs.map +1 -0
- package/dist/Dotenv.cjs +3 -0
- package/dist/Dotenv.cjs.map +1 -0
- package/dist/Dotenv.d.cts +17 -0
- package/dist/Dotenv.d.cts.map +1 -0
- package/dist/Dotenv.d.mts +17 -0
- package/dist/Dotenv.d.mts.map +1 -0
- package/dist/Dotenv.mjs +3 -0
- package/dist/Dotenv.mjs.map +1 -0
- package/dist/Envapter.cjs +2 -0
- package/dist/Envapter.cjs.map +1 -0
- package/dist/Envapter.d.cts +70 -0
- package/dist/Envapter.d.cts.map +1 -0
- package/dist/Envapter.d.mts +70 -0
- package/dist/Envapter.d.mts.map +1 -0
- package/dist/Envapter.mjs +2 -0
- package/dist/Envapter.mjs.map +1 -0
- package/dist/Error.cjs +2 -0
- package/dist/Error.cjs.map +1 -0
- package/dist/Error.d.cts +68 -0
- package/dist/Error.d.cts.map +1 -0
- package/dist/Error.d.mts +68 -0
- package/dist/Error.d.mts.map +1 -0
- package/dist/Error.mjs +2 -0
- package/dist/Error.mjs.map +1 -0
- package/dist/StandardSchema.d.cts +59 -0
- package/dist/StandardSchema.d.cts.map +1 -0
- package/dist/StandardSchema.d.mts +59 -0
- package/dist/StandardSchema.d.mts.map +1 -0
- package/dist/TemplateResolver.cjs +2 -0
- package/dist/TemplateResolver.cjs.map +1 -0
- package/dist/TemplateResolver.d.cts +17 -0
- package/dist/TemplateResolver.d.cts.map +1 -0
- package/dist/TemplateResolver.d.mts +17 -0
- package/dist/TemplateResolver.d.mts.map +1 -0
- package/dist/TemplateResolver.mjs +2 -0
- package/dist/TemplateResolver.mjs.map +1 -0
- package/dist/Validators.cjs +2 -0
- package/dist/Validators.cjs.map +1 -0
- package/dist/Validators.mjs +2 -0
- package/dist/Validators.mjs.map +1 -0
- package/dist/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/converters/BuiltInConverters.cjs +2 -0
- package/dist/converters/BuiltInConverters.cjs.map +1 -0
- package/dist/converters/BuiltInConverters.mjs +2 -0
- package/dist/converters/BuiltInConverters.mjs.map +1 -0
- package/dist/converters/Converters.cjs +2 -0
- package/dist/converters/Converters.cjs.map +1 -0
- package/dist/converters/Converters.d.cts +93 -0
- package/dist/converters/Converters.d.cts.map +1 -0
- package/dist/converters/Converters.d.mts +93 -0
- package/dist/converters/Converters.d.mts.map +1 -0
- package/dist/converters/Converters.mjs +2 -0
- package/dist/converters/Converters.mjs.map +1 -0
- package/dist/converters/ListOfBuiltInConverters.cjs +2 -0
- package/dist/converters/ListOfBuiltInConverters.cjs.map +1 -0
- package/dist/converters/ListOfBuiltInConverters.mjs +2 -0
- package/dist/converters/ListOfBuiltInConverters.mjs.map +1 -0
- package/dist/converters/ValueConverter.cjs +2 -0
- package/dist/converters/ValueConverter.cjs.map +1 -0
- package/dist/converters/ValueConverter.d.cts +25 -0
- package/dist/converters/ValueConverter.d.cts.map +1 -0
- package/dist/converters/ValueConverter.d.mts +25 -0
- package/dist/converters/ValueConverter.d.mts.map +1 -0
- package/dist/converters/ValueConverter.mjs +2 -0
- package/dist/converters/ValueConverter.mjs.map +1 -0
- package/dist/core/AdvancedMethods.cjs +2 -0
- package/dist/core/AdvancedMethods.cjs.map +1 -0
- package/dist/core/AdvancedMethods.d.cts +76 -0
- package/dist/core/AdvancedMethods.d.cts.map +1 -0
- package/dist/core/AdvancedMethods.d.mts +76 -0
- package/dist/core/AdvancedMethods.d.mts.map +1 -0
- package/dist/core/AdvancedMethods.mjs +2 -0
- package/dist/core/AdvancedMethods.mjs.map +1 -0
- package/dist/core/EnvapterBase.cjs +2 -0
- package/dist/core/EnvapterBase.cjs.map +1 -0
- package/dist/core/EnvapterBase.d.cts +105 -0
- package/dist/core/EnvapterBase.d.cts.map +1 -0
- package/dist/core/EnvapterBase.d.mts +105 -0
- package/dist/core/EnvapterBase.d.mts.map +1 -0
- package/dist/core/EnvapterBase.mjs +2 -0
- package/dist/core/EnvapterBase.mjs.map +1 -0
- package/dist/core/EnvironmentMethods.cjs +2 -0
- package/dist/core/EnvironmentMethods.cjs.map +1 -0
- package/dist/core/EnvironmentMethods.d.cts +132 -0
- package/dist/core/EnvironmentMethods.d.cts.map +1 -0
- package/dist/core/EnvironmentMethods.d.mts +132 -0
- package/dist/core/EnvironmentMethods.d.mts.map +1 -0
- package/dist/core/EnvironmentMethods.mjs +2 -0
- package/dist/core/EnvironmentMethods.mjs.map +1 -0
- package/dist/core/PrimitiveMethods.cjs +2 -0
- package/dist/core/PrimitiveMethods.cjs.map +1 -0
- package/dist/core/PrimitiveMethods.d.cts +70 -0
- package/dist/core/PrimitiveMethods.d.cts.map +1 -0
- package/dist/core/PrimitiveMethods.d.mts +70 -0
- package/dist/core/PrimitiveMethods.d.mts.map +1 -0
- package/dist/core/PrimitiveMethods.mjs +2 -0
- package/dist/core/PrimitiveMethods.mjs.map +1 -0
- package/dist/decorators/Envapt.cjs +2 -0
- package/dist/decorators/Envapt.cjs.map +1 -0
- package/dist/decorators/Envapt.d.cts +233 -0
- package/dist/decorators/Envapt.d.cts.map +1 -0
- package/dist/decorators/Envapt.d.mts +233 -0
- package/dist/decorators/Envapt.d.mts.map +1 -0
- package/dist/decorators/Envapt.mjs +2 -0
- package/dist/decorators/Envapt.mjs.map +1 -0
- package/dist/decorators/SugarDecorators.cjs +2 -0
- package/dist/decorators/SugarDecorators.cjs.map +1 -0
- package/dist/decorators/SugarDecorators.d.cts +34 -0
- package/dist/decorators/SugarDecorators.d.cts.map +1 -0
- package/dist/decorators/SugarDecorators.d.mts +34 -0
- package/dist/decorators/SugarDecorators.d.mts.map +1 -0
- package/dist/decorators/SugarDecorators.mjs +2 -0
- package/dist/decorators/SugarDecorators.mjs.map +1 -0
- package/dist/decorators/createPropertyDecorator.cjs +2 -0
- package/dist/decorators/createPropertyDecorator.cjs.map +1 -0
- package/dist/decorators/createPropertyDecorator.mjs +2 -0
- package/dist/decorators/createPropertyDecorator.mjs.map +1 -0
- package/dist/index.cjs +1 -2
- package/dist/index.d.cts +14 -1127
- package/dist/index.d.mts +14 -1127
- package/dist/index.mjs +1 -2
- package/dist/types/Conversion.d.cts +128 -0
- package/dist/types/Conversion.d.cts.map +1 -0
- package/dist/types/Conversion.d.mts +128 -0
- package/dist/types/Conversion.d.mts.map +1 -0
- package/dist/types/Env.d.cts +17 -0
- package/dist/types/Env.d.cts.map +1 -0
- package/dist/types/Env.d.mts +17 -0
- package/dist/types/Env.d.mts.map +1 -0
- package/dist/types/Options.d.cts +39 -0
- package/dist/types/Options.d.cts.map +1 -0
- package/dist/types/Options.d.mts +39 -0
- package/dist/types/Options.d.mts.map +1 -0
- package/dist/types/Schema.d.cts +12 -0
- package/dist/types/Schema.d.cts.map +1 -0
- package/dist/types/Schema.d.mts +12 -0
- package/dist/types/Schema.d.mts.map +1 -0
- package/package.json +2 -2
- package/dist/Envapter-CBSM3v-5.cjs +0 -3
- package/dist/Envapter-CBSM3v-5.cjs.map +0 -1
- package/dist/Envapter-D8FEdzBR.mjs +0 -3
- package/dist/Envapter-D8FEdzBR.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ConditionalReturn } from "../types/Conversion.cjs";
|
|
2
|
+
import { EnvironmentMethods } from "./EnvironmentMethods.cjs";
|
|
3
|
+
import { EnvKeyInput, EnvapterService } from "../types/Env.cjs";
|
|
4
|
+
import { ValueConverter } from "../converters/ValueConverter.cjs";
|
|
5
|
+
import { TemplateResolver } from "../TemplateResolver.cjs";
|
|
6
|
+
|
|
7
|
+
//#region src/core/PrimitiveMethods.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare class PrimitiveMethods extends EnvironmentMethods implements EnvapterService {
|
|
12
|
+
private static readonly service;
|
|
13
|
+
protected static readonly templateResolver: TemplateResolver;
|
|
14
|
+
protected static readonly valueConverter: ValueConverter;
|
|
15
|
+
isStrict(): boolean;
|
|
16
|
+
private static _get;
|
|
17
|
+
/**
|
|
18
|
+
* Get a string environment variable with optional fallback.
|
|
19
|
+
* Supports template variable resolution using `${VAR}` syntax.
|
|
20
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
21
|
+
*/
|
|
22
|
+
static get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
|
|
23
|
+
/**
|
|
24
|
+
* @see {@link PrimitiveMethods.get}
|
|
25
|
+
*/
|
|
26
|
+
get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
|
|
27
|
+
/**
|
|
28
|
+
* Get a number environment variable with optional fallback.
|
|
29
|
+
* Automatically converts string values to numbers.
|
|
30
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
31
|
+
*/
|
|
32
|
+
static getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
|
|
33
|
+
/**
|
|
34
|
+
* @see {@link PrimitiveMethods.getNumber}
|
|
35
|
+
*/
|
|
36
|
+
getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a boolean environment variable with optional fallback.
|
|
39
|
+
* Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).
|
|
40
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
41
|
+
*/
|
|
42
|
+
static getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
|
|
43
|
+
/**
|
|
44
|
+
* @see {@link PrimitiveMethods.getBoolean}
|
|
45
|
+
*/
|
|
46
|
+
getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a bigint environment variable with optional fallback.
|
|
49
|
+
* Automatically converts string values to bigint.
|
|
50
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
51
|
+
*/
|
|
52
|
+
static getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
|
|
53
|
+
/**
|
|
54
|
+
* @see {@link PrimitiveMethods.getBigInt}
|
|
55
|
+
*/
|
|
56
|
+
getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a symbol environment variable with optional fallback.
|
|
59
|
+
* Creates a symbol from the string value.
|
|
60
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
61
|
+
*/
|
|
62
|
+
static getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
|
|
63
|
+
/**
|
|
64
|
+
* @see {@link PrimitiveMethods.getSymbol}
|
|
65
|
+
*/
|
|
66
|
+
getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { PrimitiveMethods };
|
|
70
|
+
//# sourceMappingURL=PrimitiveMethods.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimitiveMethods.d.cts","names":[],"sources":["../../src/core/PrimitiveMethods.ts"],"mappings":";;;;;;;;;AAuBA;cAAa,gBAAA,SAAyB,kBAAA,YAA8B,eAAA;EAAA,wBACxC,OAAA;EAAA,0BACE,gBAAA,EAAkB,gBAAA;EAAA,0BAClB,cAAA,EAAgB,cAAA;EAK1C,QAAA,CAAA;EAAA,eAIe,IAAA;EAmCc;;;;;EAAA,OAHtB,GAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAoBpB;;;EAbT,GAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAoBpB;;;;;EAAA,OAXF,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAsBC;;;EAf9B,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAsBC;;;;;EAAA,OAbvB,UAAA,iDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,UAA2B,OAAA;EA8BrB;;;EAvBT,UAAA,iDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,UAA2B,OAAA;EAgCrB;;;;;EAAA,OAvBF,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAgCA;;;EAzB7B,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EA3HkD;;;;;EAAA,OAoIxE,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EArIe;;;EA4I5C,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;AAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ConditionalReturn } from "../types/Conversion.mjs";
|
|
2
|
+
import { EnvironmentMethods } from "./EnvironmentMethods.mjs";
|
|
3
|
+
import { EnvKeyInput, EnvapterService } from "../types/Env.mjs";
|
|
4
|
+
import { ValueConverter } from "../converters/ValueConverter.mjs";
|
|
5
|
+
import { TemplateResolver } from "../TemplateResolver.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/core/PrimitiveMethods.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
declare class PrimitiveMethods extends EnvironmentMethods implements EnvapterService {
|
|
12
|
+
private static readonly service;
|
|
13
|
+
protected static readonly templateResolver: TemplateResolver;
|
|
14
|
+
protected static readonly valueConverter: ValueConverter;
|
|
15
|
+
isStrict(): boolean;
|
|
16
|
+
private static _get;
|
|
17
|
+
/**
|
|
18
|
+
* Get a string environment variable with optional fallback.
|
|
19
|
+
* Supports template variable resolution using `${VAR}` syntax.
|
|
20
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
21
|
+
*/
|
|
22
|
+
static get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
|
|
23
|
+
/**
|
|
24
|
+
* @see {@link PrimitiveMethods.get}
|
|
25
|
+
*/
|
|
26
|
+
get<Default extends string | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<string, Default>;
|
|
27
|
+
/**
|
|
28
|
+
* Get a number environment variable with optional fallback.
|
|
29
|
+
* Automatically converts string values to numbers.
|
|
30
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
31
|
+
*/
|
|
32
|
+
static getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
|
|
33
|
+
/**
|
|
34
|
+
* @see {@link PrimitiveMethods.getNumber}
|
|
35
|
+
*/
|
|
36
|
+
getNumber<Default extends number | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<number, Default>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a boolean environment variable with optional fallback.
|
|
39
|
+
* Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).
|
|
40
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
41
|
+
*/
|
|
42
|
+
static getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
|
|
43
|
+
/**
|
|
44
|
+
* @see {@link PrimitiveMethods.getBoolean}
|
|
45
|
+
*/
|
|
46
|
+
getBoolean<Default extends boolean | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<boolean, Default>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a bigint environment variable with optional fallback.
|
|
49
|
+
* Automatically converts string values to bigint.
|
|
50
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
51
|
+
*/
|
|
52
|
+
static getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
|
|
53
|
+
/**
|
|
54
|
+
* @see {@link PrimitiveMethods.getBigInt}
|
|
55
|
+
*/
|
|
56
|
+
getBigInt<Default extends bigint | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<bigint, Default>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a symbol environment variable with optional fallback.
|
|
59
|
+
* Creates a symbol from the string value.
|
|
60
|
+
* Accepts a single key or an ordered array of keys (first match wins).
|
|
61
|
+
*/
|
|
62
|
+
static getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
|
|
63
|
+
/**
|
|
64
|
+
* @see {@link PrimitiveMethods.getSymbol}
|
|
65
|
+
*/
|
|
66
|
+
getSymbol<Default extends symbol | undefined = undefined>(key: EnvKeyInput, def?: Default): ConditionalReturn<symbol, Default>;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { PrimitiveMethods };
|
|
70
|
+
//# sourceMappingURL=PrimitiveMethods.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimitiveMethods.d.mts","names":[],"sources":["../../src/core/PrimitiveMethods.ts"],"mappings":";;;;;;;;;AAuBA;cAAa,gBAAA,SAAyB,kBAAA,YAA8B,eAAA;EAAA,wBACxC,OAAA;EAAA,0BACE,gBAAA,EAAkB,gBAAA;EAAA,0BAClB,cAAA,EAAgB,cAAA;EAK1C,QAAA,CAAA;EAAA,eAIe,IAAA;EAmCc;;;;;EAAA,OAHtB,GAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAoBpB;;;EAbT,GAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAoBpB;;;;;EAAA,OAXF,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAsBC;;;EAf9B,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAsBC;;;;;EAAA,OAbvB,UAAA,iDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,UAA2B,OAAA;EA8BrB;;;EAvBT,UAAA,iDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,UAA2B,OAAA;EAgCrB;;;;;EAAA,OAvBF,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EAgCA;;;EAzB7B,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EA3HkD;;;;;EAAA,OAoIxE,SAAA,gDAAA,CACH,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;EArIe;;;EA4I5C,SAAA,gDAAA,CACI,GAAA,EAAK,WAAA,EACL,GAAA,GAAM,OAAA,GACP,iBAAA,SAA0B,OAAA;AAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{BuiltInConverters as e}from"../converters/BuiltInConverters.mjs";import{ValueConverter as t}from"../converters/ValueConverter.mjs";import{debugWarn as n}from"../Debug.mjs";import{EnvapterBase as r}from"./EnvapterBase.mjs";import{EnvironmentMethods as i}from"./EnvironmentMethods.mjs";import{TemplateResolver as a}from"../TemplateResolver.mjs";var o=class o extends i{static service=new o;static templateResolver=new a(o.service);static valueConverter=new t(o.service);isStrict(){return r.strict}static _get(t,r,i){let{key:a,value:o}=this.resolveKeyInput(t);if(this.treatAsMissing(o))return i!==void 0&&n(`${a} not found, using fallback ${String(i)}`),i;let s=o,c=this.templateResolver.resolveTemplate(a,String(s)),l;return l=r===1?e.number(c,i):r===2?e.boolean(c,i):r===3?e.bigint(c,i):r===4?e.symbol(c,i):e.string(c,i),l}static get(e,t){return this._get(e,0,t)}get(e,t){return o._get(e,0,t)}static getNumber(e,t){return this._get(e,1,t)}getNumber(e,t){return o._get(e,1,t)}static getBoolean(e,t){return this._get(e,2,t)}getBoolean(e,t){return o._get(e,2,t)}static getBigInt(e,t){return this._get(e,3,t)}getBigInt(e,t){return o._get(e,3,t)}static getSymbol(e,t){return this._get(e,4,t)}getSymbol(e,t){return o._get(e,4,t)}};export{o as PrimitiveMethods};
|
|
2
|
+
//# sourceMappingURL=PrimitiveMethods.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimitiveMethods.mjs","names":[],"sources":["../../src/core/PrimitiveMethods.ts"],"sourcesContent":["import { BuiltInConverters, ValueConverter } from '../converters';\nimport { debugWarn } from '../Debug';\nimport { TemplateResolver } from '../TemplateResolver';\nimport { EnvapterBase } from './EnvapterBase';\nimport { EnvironmentMethods } from './EnvironmentMethods';\n\nimport type { ConditionalReturn, EnvKeyInput } from '../types';\nimport type { EnvapterService } from '../types/Env';\n\n/**\n * @internal\n */\nenum Primitive {\n String,\n Number,\n Boolean,\n BigInt,\n Symbol\n}\n\n/**\n * @internal\n */\nexport class PrimitiveMethods extends EnvironmentMethods implements EnvapterService {\n private static readonly service = new PrimitiveMethods();\n protected static readonly templateResolver: TemplateResolver = new TemplateResolver(PrimitiveMethods.service);\n protected static readonly valueConverter: ValueConverter = new ValueConverter(PrimitiveMethods.service);\n\n // Read `EnvapterBase.strict` directly: `PrimitiveMethods._strict` would resolve to the\n // BaseClass default because a `Envapter.strict = true` write lands as an own-property\n // on `Envapter`, which is a descendant of `PrimitiveMethods`, not an ancestor.\n isStrict(): boolean {\n return EnvapterBase.strict;\n }\n\n private static _get<EnvVarReturnType, DefaultType extends EnvVarReturnType | undefined = undefined>(\n key: EnvKeyInput,\n type: Primitive,\n def?: DefaultType\n ): ConditionalReturn<EnvVarReturnType, DefaultType> {\n const { key: resolvedKey, value } = this.resolveKeyInput(key);\n if (this.treatAsMissing(value)) {\n if (def !== undefined) debugWarn(`${resolvedKey} not found, using fallback ${String(def)}`);\n return def as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n const rawVal = value as string | number | boolean | undefined;\n\n const parsed = this.templateResolver.resolveTemplate(resolvedKey, String(rawVal));\n\n let result: EnvVarReturnType;\n if (type === Primitive.Number) result = BuiltInConverters.number(parsed, def as number) as EnvVarReturnType;\n else if (type === Primitive.Boolean)\n result = BuiltInConverters.boolean(parsed, def as boolean) as EnvVarReturnType;\n else if (type === Primitive.BigInt)\n result = BuiltInConverters.bigint(parsed, def as bigint) as EnvVarReturnType;\n else if (type === Primitive.Symbol)\n result = BuiltInConverters.symbol(parsed, def as symbol) as EnvVarReturnType;\n else result = BuiltInConverters.string(parsed, def as string) as EnvVarReturnType;\n\n return result as ConditionalReturn<EnvVarReturnType, DefaultType>;\n }\n\n /**\n * Get a string environment variable with optional fallback.\n * Supports template variable resolution using `${VAR}` syntax.\n * Accepts a single key or an ordered array of keys (first match wins).\n */\n static get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return this._get(key, Primitive.String, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.get}\n */\n get<Default extends string | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<string, Default> {\n return PrimitiveMethods._get(key, Primitive.String, def);\n }\n\n /**\n * Get a number environment variable with optional fallback.\n * Automatically converts string values to numbers.\n * Accepts a single key or an ordered array of keys (first match wins).\n */\n static getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return this._get(key, Primitive.Number, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getNumber}\n */\n getNumber<Default extends number | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<number, Default> {\n return PrimitiveMethods._get(key, Primitive.Number, def);\n }\n\n /**\n * Get a boolean environment variable with optional fallback.\n * Recognizes: `1`, `yes`, `true`, `on` as **true**; `0`, `no`, `false`, `off` as **false** (case-insensitive).\n * Accepts a single key or an ordered array of keys (first match wins).\n */\n static getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return this._get(key, Primitive.Boolean, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBoolean}\n */\n getBoolean<Default extends boolean | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<boolean, Default> {\n return PrimitiveMethods._get(key, Primitive.Boolean, def);\n }\n\n /**\n * Get a bigint environment variable with optional fallback.\n * Automatically converts string values to bigint.\n * Accepts a single key or an ordered array of keys (first match wins).\n */\n static getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return this._get(key, Primitive.BigInt, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getBigInt}\n */\n getBigInt<Default extends bigint | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<bigint, Default> {\n return PrimitiveMethods._get(key, Primitive.BigInt, def);\n }\n\n /**\n * Get a symbol environment variable with optional fallback.\n * Creates a symbol from the string value.\n * Accepts a single key or an ordered array of keys (first match wins).\n */\n static getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return this._get(key, Primitive.Symbol, def);\n }\n\n /**\n * @see {@link PrimitiveMethods.getSymbol}\n */\n getSymbol<Default extends symbol | undefined = undefined>(\n key: EnvKeyInput,\n def?: Default\n ): ConditionalReturn<symbol, Default> {\n return PrimitiveMethods._get(key, Primitive.Symbol, def);\n }\n}\n"],"mappings":"8VAuBA,IAAa,EAAb,MAAa,UAAyB,CAA8C,CAChF,OAAwB,QAAU,IAAI,EACtC,OAA0B,iBAAqC,IAAI,EAAiB,EAAiB,OAAO,EAC5G,OAA0B,eAAiC,IAAI,EAAe,EAAiB,OAAO,EAKtG,UAAoB,CAChB,OAAO,EAAa,MACxB,CAEA,OAAe,KACX,EACA,EACA,EACgD,CAChD,GAAM,CAAE,IAAK,EAAa,SAAU,KAAK,gBAAgB,CAAG,EAC5D,GAAI,KAAK,eAAe,CAAK,EAEzB,OADI,IAAQ,IAAA,IAAW,EAAU,GAAG,EAAY,6BAA6B,OAAO,CAAG,GAAG,EACnF,EAEX,IAAM,EAAS,EAET,EAAS,KAAK,iBAAiB,gBAAgB,EAAa,OAAO,CAAM,CAAC,EAE5E,EAUJ,MATA,CAOK,EAPD,IAAA,EAAoC,EAAkB,OAAO,EAAQ,CAAa,EAC7E,IAAA,EACI,EAAkB,QAAQ,EAAQ,CAAc,EACpD,IAAA,EACI,EAAkB,OAAO,EAAQ,CAAa,EAClD,IAAA,EACI,EAAkB,OAAO,EAAQ,CAAa,EAC7C,EAAkB,OAAO,EAAQ,CAAa,EAErD,CACX,CAOA,OAAO,IACH,EACA,EACkC,CAClC,OAAO,KAAK,KAAK,EAAA,EAAuB,CAAG,CAC/C,CAKA,IACI,EACA,EACkC,CAClC,OAAO,EAAiB,KAAK,EAAA,EAAuB,CAAG,CAC3D,CAOA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,KAAK,KAAK,EAAA,EAAuB,CAAG,CAC/C,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAiB,KAAK,EAAA,EAAuB,CAAG,CAC3D,CAOA,OAAO,WACH,EACA,EACmC,CACnC,OAAO,KAAK,KAAK,EAAA,EAAwB,CAAG,CAChD,CAKA,WACI,EACA,EACmC,CACnC,OAAO,EAAiB,KAAK,EAAA,EAAwB,CAAG,CAC5D,CAOA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,KAAK,KAAK,EAAA,EAAuB,CAAG,CAC/C,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAiB,KAAK,EAAA,EAAuB,CAAG,CAC3D,CAOA,OAAO,UACH,EACA,EACkC,CAClC,OAAO,KAAK,KAAK,EAAA,EAAuB,CAAG,CAC/C,CAKA,UACI,EACA,EACkC,CAClC,OAAO,EAAiB,KAAK,EAAA,EAAuB,CAAG,CAC3D,CACJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../Error.cjs"),t=require("../Validators.cjs"),n=require("./createPropertyDecorator.cjs");function r(r,i,a){let o,s,c,l=!0,u=!1;if(i&&typeof i==`object`&&(`fallback`in i||`converter`in i||`required`in i||`schema`in i)){let n=i;if(o=n.fallback,s=n.converter,l=`fallback`in n,u=n.required===!0,u&&l&&o!==void 0)throw new e.EnvaptError(302,"`required: true` and `fallback` are mutually exclusive on @Envapt options. Drop the fallback or call `Envapter.require()` separately.");if(`schema`in n&&n.schema!==void 0){if(!t.Validator.isStandardSchema(n.schema))throw new e.EnvaptError(302,"`schema` must be a Standard Schema v1 object (zod, valibot, arktype, or any `~standard`-conformant value).");if(s!==void 0)throw new e.EnvaptError(302,"`schema` and `converter` are mutually exclusive on @Envapt options. Drop one as they both turn a raw env string into a typed value.");c=n.schema}}else o=i,s=a,l=arguments.length>1;return n.createPropertyDecorator(r,{fallback:o,converter:s,hasFallback:l,required:u,schema:c})}exports.Envapt=r;
|
|
2
|
+
//# sourceMappingURL=Envapt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapt.cjs","names":["EnvaptError","Validator","createPropertyDecorator"],"sources":["../../src/decorators/Envapt.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { EnvaptError, EnvaptErrorCodes } from '../Error';\nimport { Validator } from '../Validators';\n\nimport type { ArrayOf } from '../converters';\nimport type { InferSchemaOutput, StandardSchemaV1 } from '../StandardSchema';\nimport type {\n BuiltInConverter,\n ConverterFunction,\n EnvKeyInput,\n EnvaptConverter,\n EnvaptOptions,\n InferConverterFallbackType,\n InferPrimitiveFallbackType,\n InferPrimitiveReturnType,\n PrimitiveConstructor,\n SchemaConstraint\n} from '../types';\n\n/**\n * Usage 1: Either a custom converter function + fallback (both required), OR a fallback\n * only (no converter).\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * // Custom converter that validates a non-empty API key\n * \\@Envapt('API_KEY', {\n * fallback: 'default-key',\n * converter(raw, _fallback) {\n * if (!raw || raw.trim() === '') throw new Error('API_KEY required');\n * return raw.trim();\n * }\n * })\n * static readonly apiKey: string;\n *\n * // Fallback-only (no converter): string fallback\n * \\@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })\n * static readonly logFile: string;\n *\n * // Fallback-only: arbitrary object fallback\n * \\@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })\n * static readonly retryPolicy: unknown;\n * }\n * ```\n */\nexport function Envapt<TFallback>(\n key: EnvKeyInput,\n options:\n | { converter: (raw: string | undefined, fallback: TFallback) => TFallback; fallback: TFallback }\n | { fallback: TFallback; converter?: undefined }\n): PropertyDecorator;\n\n/**\n * Usage 2: Custom converter function without fallback. Either omit `required` (returns the\n * converter's output, possibly `undefined`) or pass `required: true` to throw `MissingEnvValue`\n * on missing/empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options with custom converter only, with optional `required: true`\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('FEATURE_FLAGS', { converter(raw) {\n * return raw ? raw.split('|').map(s => s.trim()) : [];\n * } })\n * static readonly featureFlags: string[];\n *\n * \\@Envapt('JWT_SECRET', {\n * converter: (raw) => Buffer.from(raw ?? '', 'base64'),\n * required: true\n * })\n * declare static readonly jwtSecret: Buffer;\n * }\n * ```\n */\nexport function Envapt<TReturnType>(\n key: EnvKeyInput,\n options:\n | { converter: ConverterFunction<TReturnType>; required?: false }\n | { converter: ConverterFunction<TReturnType>; required: true }\n): PropertyDecorator;\n\n/**\n * Usage 3: Built-in or array converter with optional fallback OR `required: true`.\n *\n * `InferConverterFallbackType` handles asymmetric cases: scalar `Converters.Time` accepts\n * `TimeFallback`, and `ArrayOf<'time'>` accepts `TimeFallback[]`. Every other converter\n * reduces to `InferConverterReturnType`. The two object-shape branches are mutually\n * exclusive: either provide a `fallback`, or pass `required: true` to throw\n * `MissingEnvValue` on missing/empty values.\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options\n * @public\n * @example\n * ```ts\n * import { Converters } from 'envapt';\n *\n * class Config extends Envapter {\n * // Use built-in Number converter with a numeric fallback\n * \\@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })\n * static readonly port: number;\n *\n * // Url converter: the fallback is a URL instance, not a string\n * \\@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })\n * static readonly url: URL;\n *\n * // Prefer CANARY_URL when present, otherwise fall back to APP_URL\n * \\@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })\n * static readonly canaryUrl: URL | null;\n *\n * // `Converters.Time` accepts either a number (milliseconds) or a time-string fallback (`<integer><unit>`).\n * \\@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })\n * static readonly requestTimeout: number;\n *\n * // Array converter: comma-separated list of origins -> string[]\n * \\@Envapt('ALLOWED_ORIGINS', {\n * converter: Converters.array({ of: Converters.String }),\n * fallback: ['https://example.com']\n * })\n * static readonly allowedOrigins: string[];\n *\n * \\@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })\n * declare static readonly databaseUrl: URL;\n * }\n * ```\n */\nexport function Envapt<TConverter extends BuiltInConverter | ArrayOf>(\n key: EnvKeyInput,\n options:\n | { converter: TConverter; fallback?: InferConverterFallbackType<TConverter> | undefined; required?: false }\n | { converter: TConverter; required: true }\n): PropertyDecorator;\n\n/**\n * Usage 4: Primitive constructor with optional fallback\n *\n * @param key - Environment variable name(s) to load\n * @param options - Configuration options with primitive constructor\n * @public\n * @example\n * ```ts\n * // Use primitive constructors to coerce values\n * class Config extends Envapter {\n * \\@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })\n * static readonly maxConnections: number;\n *\n * \\@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })\n * static readonly featureEnabled: boolean;\n * }\n * ```\n */\nexport function Envapt<TConstructor extends PrimitiveConstructor>(\n key: EnvKeyInput,\n options:\n | { converter: TConstructor; fallback?: InferPrimitiveReturnType<TConstructor>; required?: false }\n | { converter: TConstructor; required: true }\n): PropertyDecorator;\n\n/**\n * Usage 5: Required, no converter (raw string). Throws `MissingEnvValue` on first access if\n * the env value is missing or empty (post-trim). Independent of global `Envapter.strict`.\n * Combining `required: true` with `fallback` fails to match any overload at compile time;\n * the runtime Validator catches dynamic objects that bypass the types.\n *\n * @param key - Environment variable name(s) to load\n * @param options - `{ required: true }`\n * @public\n * @example\n * ```ts\n * class Config extends Envapter {\n * \\@Envapt('API_KEY', { required: true })\n * declare static readonly apiKey: string;\n * }\n * ```\n */\nexport function Envapt(key: EnvKeyInput, options: { required: true }): PropertyDecorator;\n\n/**\n * Classic API: No fallback\n *\n * @param key - Environment variable name(s) to load\n * @public\n * @example\n * ```ts\n * // Classic API: no fallback — property will resolve from env or be null\n * class Config extends Envapter {\n * \\@Envapt('SIMPLE_VALUE')\n * static readonly simple?: string | null;\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function Envapt<_TReturnType = string | null>(key: EnvKeyInput): PropertyDecorator;\n\n/**\n * Classic API: Primitive fallback only\n *\n * @param key - Environment variable name(s) to load\n * @param fallback - Default primitive value\n * @param converter - Optional primitive constructor (String, Number, etc.)\n * @public\n * @deprecated - Use the options object: `@Envapt('KEY', { converter, fallback })`. The positional\n * form only accepts primitive constructors and cannot express built-in tokens, array/custom\n * converters, `schema`, or `required`. Deprecated in v5, removed in v6.\n * @example\n * ```ts\n * // Classic API with primitive fallback and optional primitive converter\n * class Config extends Envapter {\n * // Provide fallback only\n * \\@Envapt('HOST', 'localhost')\n * static readonly host: string;\n *\n * // Provide fallback and converter\n * \\@Envapt('PORT', 8080, Number)\n * static readonly port: number;\n * }\n * ```\n */\nexport function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(\n key: EnvKeyInput,\n fallback: InferPrimitiveFallbackType<TFallback>,\n converter?: PrimitiveConstructor\n): PropertyDecorator;\n\n/**\n * Usage 6: Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous\n * schemas only; a Promise-returning `validate` triggers a runtime\n * `InvalidUserDefinedConfig` throw. Combining `schema` with `converter` fails to match any\n * overload at compile time; the runtime Validator catches dynamic objects that bypass the\n * types.\n * @public\n */\nexport function Envapt<Schema extends StandardSchemaV1>(\n key: EnvKeyInput,\n options:\n | { schema: SchemaConstraint<Schema>; fallback?: InferSchemaOutput<Schema>; required?: false }\n | { schema: SchemaConstraint<Schema>; required: true }\n): PropertyDecorator;\n\n/**\n * Instance/Static Property decorator that automatically loads and converts environment variables.\n */\nexport function Envapt<TFallback = unknown>(\n key: EnvKeyInput,\n fallbackOrOptions?: TFallback | EnvaptOptions<TFallback>,\n converter?: EnvaptConverter<TFallback>\n): PropertyDecorator {\n // Determine if using new options API or classic API\n let fallback: TFallback | undefined;\n let actualConverter: EnvaptConverter<TFallback> | undefined;\n let actualSchema: StandardSchemaV1 | undefined;\n let hasFallback = true;\n let required = false;\n\n if (\n fallbackOrOptions &&\n typeof fallbackOrOptions === 'object' &&\n ('fallback' in fallbackOrOptions ||\n 'converter' in fallbackOrOptions ||\n 'required' in fallbackOrOptions ||\n 'schema' in fallbackOrOptions)\n ) {\n const options = fallbackOrOptions as {\n fallback?: TFallback;\n converter?: EnvaptConverter<TFallback>;\n required?: boolean;\n schema?: unknown;\n };\n fallback = options.fallback;\n actualConverter = options.converter;\n hasFallback = 'fallback' in options;\n required = options.required === true;\n\n if (required && hasFallback && fallback !== undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n '`required: true` and `fallback` are mutually exclusive on @Envapt options. Drop the fallback or call `Envapter.require()` separately.'\n );\n }\n\n if ('schema' in options && options.schema !== undefined) {\n if (!Validator.isStandardSchema(options.schema)) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n '`schema` must be a Standard Schema v1 object (zod, valibot, arktype, or any `~standard`-conformant value).'\n );\n }\n if (actualConverter !== undefined) {\n throw new EnvaptError(\n EnvaptErrorCodes.InvalidUserDefinedConfig,\n '`schema` and `converter` are mutually exclusive on @Envapt options. Drop one as they both turn a raw env string into a typed value.'\n );\n }\n actualSchema = options.schema;\n }\n } else {\n // Classic API\n fallback = fallbackOrOptions as TFallback;\n actualConverter = converter;\n hasFallback = arguments.length > 1;\n }\n\n return createPropertyDecorator(key, {\n fallback,\n converter: actualConverter,\n hasFallback,\n required,\n schema: actualSchema\n });\n}\n"],"mappings":"0GAwPA,SAAgB,EACZ,EACA,EACA,EACiB,CAEjB,IAAI,EACA,EACA,EACA,EAAc,GACd,EAAW,GAEf,GACI,GACA,OAAO,GAAsB,WAC5B,aAAc,GACX,cAAe,GACf,aAAc,GACd,WAAY,GAClB,CACE,IAAM,EAAU,EAWhB,GALA,EAAW,EAAQ,SACnB,EAAkB,EAAQ,UAC1B,EAAc,aAAc,EAC5B,EAAW,EAAQ,WAAa,GAE5B,GAAY,GAAe,IAAa,IAAA,GACxC,MAAM,IAAIA,EAAAA,YAAAA,IAEN,uIACJ,EAGJ,GAAI,WAAY,GAAW,EAAQ,SAAW,IAAA,GAAW,CACrD,GAAI,CAACC,EAAAA,UAAU,iBAAiB,EAAQ,MAAM,EAC1C,MAAM,IAAID,EAAAA,YAAAA,IAEN,4GACJ,EAEJ,GAAI,IAAoB,IAAA,GACpB,MAAM,IAAIA,EAAAA,YAAAA,IAEN,qIACJ,EAEJ,EAAe,EAAQ,MAC3B,CACJ,MAEI,EAAW,EACX,EAAkB,EAClB,EAAc,UAAU,OAAS,EAGrC,OAAOE,EAAAA,wBAAwB,EAAK,CAChC,WACA,UAAW,EACX,cACA,WACA,OAAQ,CACZ,CAAC,CACL"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { ArrayOf } from "../converters/Converters.cjs";
|
|
2
|
+
import { BuiltInConverter, ConverterFunction, InferConverterFallbackType, InferPrimitiveFallbackType, InferPrimitiveReturnType, PrimitiveConstructor } from "../types/Conversion.cjs";
|
|
3
|
+
import { InferSchemaOutput, StandardSchemaV1 } from "../StandardSchema.cjs";
|
|
4
|
+
import { SchemaConstraint } from "../types/Schema.cjs";
|
|
5
|
+
import { EnvKeyInput } from "../types/Env.cjs";
|
|
6
|
+
|
|
7
|
+
//#region src/decorators/Envapt.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Usage 1: Either a custom converter function + fallback (both required), OR a fallback
|
|
10
|
+
* only (no converter).
|
|
11
|
+
*
|
|
12
|
+
* @param key - Environment variable name(s) to load
|
|
13
|
+
* @param options - Configuration options
|
|
14
|
+
* @public
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* class Config extends Envapter {
|
|
18
|
+
* // Custom converter that validates a non-empty API key
|
|
19
|
+
* \@Envapt('API_KEY', {
|
|
20
|
+
* fallback: 'default-key',
|
|
21
|
+
* converter(raw, _fallback) {
|
|
22
|
+
* if (!raw || raw.trim() === '') throw new Error('API_KEY required');
|
|
23
|
+
* return raw.trim();
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
* static readonly apiKey: string;
|
|
27
|
+
*
|
|
28
|
+
* // Fallback-only (no converter): string fallback
|
|
29
|
+
* \@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })
|
|
30
|
+
* static readonly logFile: string;
|
|
31
|
+
*
|
|
32
|
+
* // Fallback-only: arbitrary object fallback
|
|
33
|
+
* \@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })
|
|
34
|
+
* static readonly retryPolicy: unknown;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function Envapt<TFallback>(key: EnvKeyInput, options: {
|
|
39
|
+
converter: (raw: string | undefined, fallback: TFallback) => TFallback;
|
|
40
|
+
fallback: TFallback;
|
|
41
|
+
} | {
|
|
42
|
+
fallback: TFallback;
|
|
43
|
+
converter?: undefined;
|
|
44
|
+
}): PropertyDecorator;
|
|
45
|
+
/**
|
|
46
|
+
* Usage 2: Custom converter function without fallback. Either omit `required` (returns the
|
|
47
|
+
* converter's output, possibly `undefined`) or pass `required: true` to throw `MissingEnvValue`
|
|
48
|
+
* on missing/empty values.
|
|
49
|
+
*
|
|
50
|
+
* @param key - Environment variable name(s) to load
|
|
51
|
+
* @param options - Configuration options with custom converter only, with optional `required: true`
|
|
52
|
+
* @public
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* class Config extends Envapter {
|
|
56
|
+
* \@Envapt('FEATURE_FLAGS', { converter(raw) {
|
|
57
|
+
* return raw ? raw.split('|').map(s => s.trim()) : [];
|
|
58
|
+
* } })
|
|
59
|
+
* static readonly featureFlags: string[];
|
|
60
|
+
*
|
|
61
|
+
* \@Envapt('JWT_SECRET', {
|
|
62
|
+
* converter: (raw) => Buffer.from(raw ?? '', 'base64'),
|
|
63
|
+
* required: true
|
|
64
|
+
* })
|
|
65
|
+
* declare static readonly jwtSecret: Buffer;
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
|
|
70
|
+
converter: ConverterFunction<TReturnType>;
|
|
71
|
+
required?: false;
|
|
72
|
+
} | {
|
|
73
|
+
converter: ConverterFunction<TReturnType>;
|
|
74
|
+
required: true;
|
|
75
|
+
}): PropertyDecorator;
|
|
76
|
+
/**
|
|
77
|
+
* Usage 3: Built-in or array converter with optional fallback OR `required: true`.
|
|
78
|
+
*
|
|
79
|
+
* `InferConverterFallbackType` handles asymmetric cases: scalar `Converters.Time` accepts
|
|
80
|
+
* `TimeFallback`, and `ArrayOf<'time'>` accepts `TimeFallback[]`. Every other converter
|
|
81
|
+
* reduces to `InferConverterReturnType`. The two object-shape branches are mutually
|
|
82
|
+
* exclusive: either provide a `fallback`, or pass `required: true` to throw
|
|
83
|
+
* `MissingEnvValue` on missing/empty values.
|
|
84
|
+
*
|
|
85
|
+
* @param key - Environment variable name(s) to load
|
|
86
|
+
* @param options - Configuration options
|
|
87
|
+
* @public
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { Converters } from 'envapt';
|
|
91
|
+
*
|
|
92
|
+
* class Config extends Envapter {
|
|
93
|
+
* // Use built-in Number converter with a numeric fallback
|
|
94
|
+
* \@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })
|
|
95
|
+
* static readonly port: number;
|
|
96
|
+
*
|
|
97
|
+
* // Url converter: the fallback is a URL instance, not a string
|
|
98
|
+
* \@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })
|
|
99
|
+
* static readonly url: URL;
|
|
100
|
+
*
|
|
101
|
+
* // Prefer CANARY_URL when present, otherwise fall back to APP_URL
|
|
102
|
+
* \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
|
|
103
|
+
* static readonly canaryUrl: URL | null;
|
|
104
|
+
*
|
|
105
|
+
* // `Converters.Time` accepts either a number (milliseconds) or a time-string fallback (`<integer><unit>`).
|
|
106
|
+
* \@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })
|
|
107
|
+
* static readonly requestTimeout: number;
|
|
108
|
+
*
|
|
109
|
+
* // Array converter: comma-separated list of origins -> string[]
|
|
110
|
+
* \@Envapt('ALLOWED_ORIGINS', {
|
|
111
|
+
* converter: Converters.array({ of: Converters.String }),
|
|
112
|
+
* fallback: ['https://example.com']
|
|
113
|
+
* })
|
|
114
|
+
* static readonly allowedOrigins: string[];
|
|
115
|
+
*
|
|
116
|
+
* \@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })
|
|
117
|
+
* declare static readonly databaseUrl: URL;
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
|
|
122
|
+
converter: TConverter;
|
|
123
|
+
fallback?: InferConverterFallbackType<TConverter> | undefined;
|
|
124
|
+
required?: false;
|
|
125
|
+
} | {
|
|
126
|
+
converter: TConverter;
|
|
127
|
+
required: true;
|
|
128
|
+
}): PropertyDecorator;
|
|
129
|
+
/**
|
|
130
|
+
* Usage 4: Primitive constructor with optional fallback
|
|
131
|
+
*
|
|
132
|
+
* @param key - Environment variable name(s) to load
|
|
133
|
+
* @param options - Configuration options with primitive constructor
|
|
134
|
+
* @public
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* // Use primitive constructors to coerce values
|
|
138
|
+
* class Config extends Envapter {
|
|
139
|
+
* \@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })
|
|
140
|
+
* static readonly maxConnections: number;
|
|
141
|
+
*
|
|
142
|
+
* \@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })
|
|
143
|
+
* static readonly featureEnabled: boolean;
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
|
|
148
|
+
converter: TConstructor;
|
|
149
|
+
fallback?: InferPrimitiveReturnType<TConstructor>;
|
|
150
|
+
required?: false;
|
|
151
|
+
} | {
|
|
152
|
+
converter: TConstructor;
|
|
153
|
+
required: true;
|
|
154
|
+
}): PropertyDecorator;
|
|
155
|
+
/**
|
|
156
|
+
* Usage 5: Required, no converter (raw string). Throws `MissingEnvValue` on first access if
|
|
157
|
+
* the env value is missing or empty (post-trim). Independent of global `Envapter.strict`.
|
|
158
|
+
* Combining `required: true` with `fallback` fails to match any overload at compile time;
|
|
159
|
+
* the runtime Validator catches dynamic objects that bypass the types.
|
|
160
|
+
*
|
|
161
|
+
* @param key - Environment variable name(s) to load
|
|
162
|
+
* @param options - `{ required: true }`
|
|
163
|
+
* @public
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* class Config extends Envapter {
|
|
167
|
+
* \@Envapt('API_KEY', { required: true })
|
|
168
|
+
* declare static readonly apiKey: string;
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function Envapt(key: EnvKeyInput, options: {
|
|
173
|
+
required: true;
|
|
174
|
+
}): PropertyDecorator;
|
|
175
|
+
/**
|
|
176
|
+
* Classic API: No fallback
|
|
177
|
+
*
|
|
178
|
+
* @param key - Environment variable name(s) to load
|
|
179
|
+
* @public
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* // Classic API: no fallback — property will resolve from env or be null
|
|
183
|
+
* class Config extends Envapter {
|
|
184
|
+
* \@Envapt('SIMPLE_VALUE')
|
|
185
|
+
* static readonly simple?: string | null;
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function Envapt<_TReturnType = string | null>(key: EnvKeyInput): PropertyDecorator;
|
|
190
|
+
/**
|
|
191
|
+
* Classic API: Primitive fallback only
|
|
192
|
+
*
|
|
193
|
+
* @param key - Environment variable name(s) to load
|
|
194
|
+
* @param fallback - Default primitive value
|
|
195
|
+
* @param converter - Optional primitive constructor (String, Number, etc.)
|
|
196
|
+
* @public
|
|
197
|
+
* @deprecated - Use the options object: `@Envapt('KEY', { converter, fallback })`. The positional
|
|
198
|
+
* form only accepts primitive constructors and cannot express built-in tokens, array/custom
|
|
199
|
+
* converters, `schema`, or `required`. Deprecated in v5, removed in v6.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* // Classic API with primitive fallback and optional primitive converter
|
|
203
|
+
* class Config extends Envapter {
|
|
204
|
+
* // Provide fallback only
|
|
205
|
+
* \@Envapt('HOST', 'localhost')
|
|
206
|
+
* static readonly host: string;
|
|
207
|
+
*
|
|
208
|
+
* // Provide fallback and converter
|
|
209
|
+
* \@Envapt('PORT', 8080, Number)
|
|
210
|
+
* static readonly port: number;
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare function Envapt<TFallback extends string | number | boolean | bigint | symbol | undefined>(key: EnvKeyInput, fallback: InferPrimitiveFallbackType<TFallback>, converter?: PrimitiveConstructor): PropertyDecorator;
|
|
215
|
+
/**
|
|
216
|
+
* Usage 6: Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous
|
|
217
|
+
* schemas only; a Promise-returning `validate` triggers a runtime
|
|
218
|
+
* `InvalidUserDefinedConfig` throw. Combining `schema` with `converter` fails to match any
|
|
219
|
+
* overload at compile time; the runtime Validator catches dynamic objects that bypass the
|
|
220
|
+
* types.
|
|
221
|
+
* @public
|
|
222
|
+
*/
|
|
223
|
+
declare function Envapt<Schema extends StandardSchemaV1>(key: EnvKeyInput, options: {
|
|
224
|
+
schema: SchemaConstraint<Schema>;
|
|
225
|
+
fallback?: InferSchemaOutput<Schema>;
|
|
226
|
+
required?: false;
|
|
227
|
+
} | {
|
|
228
|
+
schema: SchemaConstraint<Schema>;
|
|
229
|
+
required: true;
|
|
230
|
+
}): PropertyDecorator;
|
|
231
|
+
//#endregion
|
|
232
|
+
export { Envapt };
|
|
233
|
+
//# sourceMappingURL=Envapt.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Envapt.d.cts","names":[],"sources":["../../src/decorators/Envapt.ts"],"mappings":";;;;;;;;;;;AAiDA;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,MAAA,WAAA,CACZ,GAAA,EAAK,WAAA,EACL,OAAA;EACQ,SAAA,GAAY,GAAA,sBAAyB,QAAA,EAAU,SAAA,KAAc,SAAA;EAAW,QAAA,EAAU,SAAA;AAAA;EAClF,QAAA,EAAU,SAAA;EAAW,SAAA;AAAA,IAC9B,iBAAA;;;;;;;;;;;;;;;;;;;;;AA+BiB;AA+CpB;;;iBApDgB,MAAA,aAAA,CACZ,GAAA,EAAK,WAAA,EACL,OAAA;EACQ,SAAA,EAAW,iBAAA,CAAkB,WAAA;EAAc,QAAA;AAAA;EAC3C,SAAA,EAAW,iBAAA,CAAkB,WAAA;EAAc,QAAA;AAAA,IACpD,iBAAA;;;;;;;;;;;;;;;;;;;;;AAoDiB;AAoBpB;;;;;;;;;;;;;;;;;;;;;;;;iBAzBgB,MAAA,oBAA0B,gBAAA,GAAmB,OAAA,CAAA,CACzD,GAAA,EAAK,WAAA,EACL,OAAA;EACQ,SAAA,EAAW,UAAA;EAAY,QAAA,GAAW,0BAAA,CAA2B,UAAA;EAAyB,QAAA;AAAA;EACtF,SAAA,EAAW,UAAA;EAAY,QAAA;AAAA,IAChC,iBAAA;;;;;;;;AA4CqF;AAiBxF;;;;;;;;;AAAyF;iBAzCzE,MAAA,sBAA4B,oBAAA,CAAA,CACxC,GAAA,EAAK,WAAA,EACL,OAAA;EACQ,SAAA,EAAW,YAAA;EAAc,QAAA,GAAW,wBAAA,CAAyB,YAAA;EAAe,QAAA;AAAA;EAC5E,SAAA,EAAW,YAAA;EAAc,QAAA;AAAA,IAClC,iBAAA;;;;;;;;;;;;;AAkEiB;AAUpB;;;;iBAzDgB,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,OAAA;EAAW,QAAA;AAAA,IAAmB,iBAAiB;;;;;;;;;;;;;;;iBAiBxE,MAAA,8BAAA,CAAqC,GAAA,EAAK,WAAA,GAAc,iBAAiB;;;;;;;;;;;AA6CrE;;;;;;;;;;;;;;iBAnBJ,MAAA,2EAAA,CACZ,GAAA,EAAK,WAAA,EACL,QAAA,EAAU,0BAAA,CAA2B,SAAA,GACrC,SAAA,GAAY,oBAAA,GACb,iBAAA;;;;;;;;;iBAUa,MAAA,gBAAsB,gBAAA,CAAA,CAClC,GAAA,EAAK,WAAA,EACL,OAAA;EACQ,MAAA,EAAQ,gBAAA,CAAiB,MAAA;EAAS,QAAA,GAAW,iBAAA,CAAkB,MAAA;EAAS,QAAA;AAAA;EACxE,MAAA,EAAQ,gBAAA,CAAiB,MAAA;EAAS,QAAA;AAAA,IAC3C,iBAAA"}
|