envapt 7.0.0-next.0 → 7.0.0-next.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/index.mjs.map +1 -1
  3. package/dist/{node → types}/engine/NodeEnvapter.d.mts +0 -2
  4. package/dist/{node → types}/index.d.mts +0 -2
  5. package/dist/{node/sources/NodeEnvSource.d.cts → types/sources/NodeEnvSource.d.mts} +2 -2
  6. package/package.json +23 -19
  7. package/dist/node/config.d.mts +0 -2
  8. package/dist/node/converters/Converters.d.cts +0 -93
  9. package/dist/node/converters/Converters.d.mts +0 -95
  10. package/dist/node/converters/ValueConverter.d.cts +0 -25
  11. package/dist/node/converters/ValueConverter.d.mts +0 -27
  12. package/dist/node/core/AdvancedMethods.d.cts +0 -76
  13. package/dist/node/core/AdvancedMethods.d.mts +0 -78
  14. package/dist/node/core/EnvapterBase.d.cts +0 -75
  15. package/dist/node/core/EnvapterBase.d.mts +0 -77
  16. package/dist/node/core/EnvironmentMethods.d.cts +0 -115
  17. package/dist/node/core/EnvironmentMethods.d.mts +0 -117
  18. package/dist/node/core/PrimitiveMethods.d.cts +0 -70
  19. package/dist/node/core/PrimitiveMethods.d.mts +0 -72
  20. package/dist/node/decorators/legacy/Envapt.d.cts +0 -218
  21. package/dist/node/decorators/legacy/Envapt.d.mts +0 -220
  22. package/dist/node/decorators/legacy/SugarDecorators.d.cts +0 -40
  23. package/dist/node/decorators/legacy/SugarDecorators.d.mts +0 -42
  24. package/dist/node/decorators/modern/Envapt.d.cts +0 -218
  25. package/dist/node/decorators/modern/Envapt.d.mts +0 -220
  26. package/dist/node/decorators/modern/SugarDecorators.d.cts +0 -40
  27. package/dist/node/decorators/modern/SugarDecorators.d.mts +0 -42
  28. package/dist/node/engine/Envapter.d.cts +0 -70
  29. package/dist/node/engine/Envapter.d.mts +0 -72
  30. package/dist/node/engine/NodeEnvapter.d.cts +0 -73
  31. package/dist/node/engine/TemplateResolver.d.cts +0 -17
  32. package/dist/node/engine/TemplateResolver.d.mts +0 -19
  33. package/dist/node/index.d.cts +0 -19
  34. package/dist/node/infra/Debug.d.cts +0 -13
  35. package/dist/node/infra/Debug.d.mts +0 -15
  36. package/dist/node/infra/Dotenv.d.cts +0 -17
  37. package/dist/node/infra/Dotenv.d.mts +0 -19
  38. package/dist/node/infra/Error.d.cts +0 -72
  39. package/dist/node/infra/Error.d.mts +0 -74
  40. package/dist/node/infra/StandardSchema.d.cts +0 -59
  41. package/dist/node/infra/StandardSchema.d.mts +0 -61
  42. package/dist/node/legacy.d.cts +0 -4
  43. package/dist/node/legacy.d.mts +0 -6
  44. package/dist/node/sources/ManualEnvSource.d.cts +0 -19
  45. package/dist/node/sources/ManualEnvSource.d.mts +0 -21
  46. package/dist/node/sources/NodeEnvSource.d.mts +0 -22
  47. package/dist/node/sources/WorkerEnvSource.d.cts +0 -19
  48. package/dist/node/sources/WorkerEnvSource.d.mts +0 -21
  49. package/dist/node/types/Conversion.d.cts +0 -123
  50. package/dist/node/types/Conversion.d.mts +0 -125
  51. package/dist/node/types/Decorator.d.cts +0 -26
  52. package/dist/node/types/Decorator.d.mts +0 -28
  53. package/dist/node/types/Env.d.cts +0 -17
  54. package/dist/node/types/Env.d.mts +0 -19
  55. package/dist/node/types/Options.d.cts +0 -39
  56. package/dist/node/types/Options.d.mts +0 -41
  57. package/dist/node/types/Schema.d.cts +0 -12
  58. package/dist/node/types/Schema.d.mts +0 -14
  59. package/dist/node/types/Source.d.cts +0 -44
  60. package/dist/node/types/Source.d.mts +0 -46
  61. package/dist/workerd/converters/Converters.d.mts +0 -93
  62. package/dist/workerd/converters/ValueConverter.d.mts +0 -25
  63. package/dist/workerd/core/AdvancedMethods.d.mts +0 -76
  64. package/dist/workerd/core/EnvapterBase.d.mts +0 -75
  65. package/dist/workerd/core/EnvironmentMethods.d.mts +0 -115
  66. package/dist/workerd/core/PrimitiveMethods.d.mts +0 -70
  67. package/dist/workerd/decorators/legacy/Envapt.d.mts +0 -218
  68. package/dist/workerd/decorators/legacy/SugarDecorators.d.mts +0 -40
  69. package/dist/workerd/decorators/modern/Envapt.d.mts +0 -218
  70. package/dist/workerd/decorators/modern/SugarDecorators.d.mts +0 -40
  71. package/dist/workerd/engine/Envapter.d.mts +0 -70
  72. package/dist/workerd/engine/TemplateResolver.d.mts +0 -17
  73. package/dist/workerd/index.d.mts +0 -18
  74. package/dist/workerd/infra/Debug.d.mts +0 -13
  75. package/dist/workerd/infra/Dotenv.d.mts +0 -17
  76. package/dist/workerd/infra/Error.d.mts +0 -72
  77. package/dist/workerd/infra/StandardSchema.d.mts +0 -59
  78. package/dist/workerd/legacy.d.mts +0 -4
  79. package/dist/workerd/sources/ManualEnvSource.d.mts +0 -19
  80. package/dist/workerd/sources/WorkerEnvSource.d.mts +0 -19
  81. package/dist/workerd/types/Conversion.d.mts +0 -123
  82. package/dist/workerd/types/Decorator.d.mts +0 -26
  83. package/dist/workerd/types/Env.d.mts +0 -17
  84. package/dist/workerd/types/Options.d.mts +0 -39
  85. package/dist/workerd/types/Schema.d.mts +0 -12
  86. package/dist/workerd/types/Source.d.mts +0 -44
  87. /package/dist/{node/config.d.cts → types/config.d.mts} +0 -0
  88. /package/dist/{browser → types}/converters/Converters.d.mts +0 -0
  89. /package/dist/{browser → types}/converters/ValueConverter.d.mts +0 -0
  90. /package/dist/{browser → types}/core/AdvancedMethods.d.mts +0 -0
  91. /package/dist/{browser → types}/core/EnvapterBase.d.mts +0 -0
  92. /package/dist/{browser → types}/core/EnvironmentMethods.d.mts +0 -0
  93. /package/dist/{browser → types}/core/PrimitiveMethods.d.mts +0 -0
  94. /package/dist/{browser → types}/decorators/legacy/Envapt.d.mts +0 -0
  95. /package/dist/{browser → types}/decorators/legacy/SugarDecorators.d.mts +0 -0
  96. /package/dist/{browser → types}/decorators/modern/Envapt.d.mts +0 -0
  97. /package/dist/{browser → types}/decorators/modern/SugarDecorators.d.mts +0 -0
  98. /package/dist/{browser → types}/engine/Envapter.d.mts +0 -0
  99. /package/dist/{browser → types}/engine/TemplateResolver.d.mts +0 -0
  100. /package/dist/{browser/index.d.mts → types/index.portable.d.mts} +0 -0
  101. /package/dist/{browser → types}/infra/Debug.d.mts +0 -0
  102. /package/dist/{browser → types}/infra/Dotenv.d.mts +0 -0
  103. /package/dist/{browser → types}/infra/Error.d.mts +0 -0
  104. /package/dist/{browser → types}/infra/StandardSchema.d.mts +0 -0
  105. /package/dist/{browser → types}/legacy.d.mts +0 -0
  106. /package/dist/{browser → types}/sources/ManualEnvSource.d.mts +0 -0
  107. /package/dist/{browser → types}/sources/WorkerEnvSource.d.mts +0 -0
  108. /package/dist/{browser → types}/types/Conversion.d.mts +0 -0
  109. /package/dist/{browser → types}/types/Decorator.d.mts +0 -0
  110. /package/dist/{browser → types}/types/Env.d.mts +0 -0
  111. /package/dist/{browser → types}/types/Options.d.mts +0 -0
  112. /package/dist/{browser → types}/types/Schema.d.mts +0 -0
  113. /package/dist/{browser → types}/types/Source.d.mts +0 -0
@@ -1,70 +0,0 @@
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 "../engine/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
@@ -1,218 +0,0 @@
1
- import { ArrayOf } from "../../converters/Converters.mjs";
2
- import { BuiltInConverter, ConverterFunction, InferConverterFallbackType, InferConverterReturnType, InferPrimitiveReturnType, PrimitiveConstructor } from "../../types/Conversion.mjs";
3
- import { InferSchemaOutput, StandardSchemaV1 } from "../../infra/StandardSchema.mjs";
4
- import { SchemaConstraint } from "../../types/Schema.mjs";
5
- import { EnvKeyInput } from "../../types/Env.mjs";
6
- import { EnvaptFieldDecorator } from "../../types/Decorator.mjs";
7
-
8
- //#region src/decorators/legacy/Envapt.d.ts
9
- /**
10
- * A custom converter function with a fallback (both required), or a fallback only.
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
- * \@Envapt('API_KEY', {
19
- * fallback: 'default-key',
20
- * converter(raw, _fallback) {
21
- * if (!raw || raw.trim() === '') throw new Error('API_KEY required');
22
- * return raw.trim();
23
- * }
24
- * })
25
- * static readonly apiKey: string;
26
- *
27
- * \@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })
28
- * static readonly logFile: string;
29
- *
30
- * \@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })
31
- * static readonly retryPolicy: unknown;
32
- * }
33
- * ```
34
- */
35
- declare function Envapt(key: EnvKeyInput, options: {
36
- fallback: undefined;
37
- converter?: undefined;
38
- }): EnvaptFieldDecorator<string | undefined>;
39
- declare function Envapt<TFallback>(key: EnvKeyInput, options: {
40
- converter: (raw: string | undefined, fallback: TFallback) => TFallback;
41
- fallback: TFallback;
42
- } | {
43
- fallback: TFallback;
44
- converter?: undefined;
45
- }): EnvaptFieldDecorator<TFallback>;
46
- /**
47
- * A custom converter function without a fallback. Omit `required` to return the converter's
48
- * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on
49
- * missing or empty values.
50
- *
51
- * @param key - Environment variable name(s) to load
52
- * @param options - Configuration options
53
- * @public
54
- * @example
55
- * ```ts
56
- * class Config extends Envapter {
57
- * \@Envapt('FEATURE_FLAGS', { converter(raw) {
58
- * return raw ? raw.split('|').map(s => s.trim()) : [];
59
- * } })
60
- * static readonly featureFlags: string[];
61
- *
62
- * \@Envapt('JWT_SECRET', {
63
- * converter: (raw) => Buffer.from(raw ?? '', 'base64'),
64
- * required: true
65
- * })
66
- * static readonly jwtSecret: Buffer;
67
- * }
68
- * ```
69
- */
70
- declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
71
- converter: ConverterFunction<TReturnType>;
72
- required?: false;
73
- } | {
74
- converter: ConverterFunction<TReturnType>;
75
- required: true;
76
- }): EnvaptFieldDecorator<TReturnType>;
77
- /**
78
- * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks
79
- * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes
80
- * a `URL` instance.
81
- *
82
- * @param key - Environment variable name(s) to load
83
- * @param options - Configuration options
84
- * @public
85
- * @example
86
- * ```ts
87
- * import { Converters } from 'envapt';
88
- *
89
- * class Config extends Envapter {
90
- * \@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })
91
- * static readonly port: number;
92
- *
93
- * // the Url fallback is a URL instance, not a string
94
- * \@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })
95
- * static readonly url: URL;
96
- *
97
- * // prefers CANARY_URL when present, otherwise APP_URL
98
- * \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
99
- * static readonly canaryUrl: URL | null;
100
- *
101
- * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)
102
- * \@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })
103
- * static readonly requestTimeout: number;
104
- *
105
- * \@Envapt('ALLOWED_ORIGINS', {
106
- * converter: Converters.array({ of: Converters.String }),
107
- * fallback: ['https://example.com']
108
- * })
109
- * static readonly allowedOrigins: string[];
110
- *
111
- * \@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })
112
- * static readonly databaseUrl: URL;
113
- * }
114
- * ```
115
- */
116
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
117
- converter: TConverter;
118
- fallback: InferConverterFallbackType<TConverter>;
119
- required?: false;
120
- } | {
121
- converter: TConverter;
122
- required: true;
123
- }): EnvaptFieldDecorator<InferConverterReturnType<TConverter>>;
124
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
125
- converter: TConverter;
126
- fallback: undefined;
127
- required?: false;
128
- }): EnvaptFieldDecorator<InferConverterReturnType<TConverter> | undefined>;
129
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
130
- converter: TConverter;
131
- required?: false;
132
- }): EnvaptFieldDecorator<InferConverterReturnType<TConverter> | null>;
133
- /**
134
- * A primitive constructor (`Number`, `Boolean`) with an optional fallback.
135
- *
136
- * @param key - Environment variable name(s) to load
137
- * @param options - Configuration options
138
- * @public
139
- * @example
140
- * ```ts
141
- * class Config extends Envapter {
142
- * \@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })
143
- * static readonly maxConnections: number;
144
- *
145
- * \@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })
146
- * static readonly featureEnabled: boolean;
147
- * }
148
- * ```
149
- */
150
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
151
- converter: TConstructor;
152
- fallback: InferPrimitiveReturnType<TConstructor>;
153
- required?: false;
154
- } | {
155
- converter: TConstructor;
156
- required: true;
157
- }): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor>>;
158
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
159
- converter: TConstructor;
160
- fallback: undefined;
161
- required?: false;
162
- }): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;
163
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
164
- converter: TConstructor;
165
- required?: false;
166
- }): EnvaptFieldDecorator<InferPrimitiveReturnType<TConstructor> | null>;
167
- /**
168
- * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env
169
- * value is missing or empty after trimming, independent of the global `Envapter.strict` flag.
170
- * Pairing `required: true` with `fallback` matches no overload at compile time, and the runtime
171
- * Validator rejects dynamic objects that bypass the types.
172
- *
173
- * @param key - Environment variable name(s) to load
174
- * @param options - `{ required: true }`
175
- * @public
176
- * @example
177
- * ```ts
178
- * class Config extends Envapter {
179
- * \@Envapt('API_KEY', { required: true })
180
- * static readonly apiKey: string;
181
- * }
182
- * ```
183
- */
184
- declare function Envapt(key: EnvKeyInput, options: {
185
- required: true;
186
- }): EnvaptFieldDecorator<string>;
187
- /**
188
- * No-fallback form. The property resolves from env or `null`.
189
- *
190
- * @param key - Environment variable name(s) to load
191
- * @public
192
- * @example
193
- * ```ts
194
- * class Config extends Envapter {
195
- * \@Envapt('SIMPLE_VALUE')
196
- * static readonly simple?: string | null;
197
- * }
198
- * ```
199
- */
200
- declare function Envapt(key: EnvKeyInput): EnvaptFieldDecorator<string | null>;
201
- /**
202
- * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only,
203
- * so a Promise-returning `validate` throws `InvalidUserDefinedConfig` at runtime. Pairing
204
- * `schema` with `converter` matches no overload at compile time, and the runtime Validator
205
- * rejects dynamic objects that bypass the types.
206
- * @public
207
- */
208
- declare function Envapt<Schema extends StandardSchemaV1>(key: EnvKeyInput, options: {
209
- schema: SchemaConstraint<Schema>;
210
- fallback?: InferSchemaOutput<Schema>;
211
- required?: false;
212
- } | {
213
- schema: SchemaConstraint<Schema>;
214
- required: true;
215
- }): EnvaptFieldDecorator<InferSchemaOutput<Schema>>;
216
- //#endregion
217
- export { Envapt };
218
- //# sourceMappingURL=Envapt.d.mts.map
@@ -1,40 +0,0 @@
1
- import { TimeFallback } from "../../types/Conversion.mjs";
2
- import { EnvKeyInput } from "../../types/Env.mjs";
3
- import { EnvaptFieldDecorator } from "../../types/Decorator.mjs";
4
-
5
- //#region src/decorators/legacy/SugarDecorators.d.ts
6
- /**
7
- * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.
8
- * @public
9
- */
10
- declare function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptFieldDecorator<boolean>;
11
- declare function EnvBool(key: EnvKeyInput): EnvaptFieldDecorator<boolean | null>;
12
- /**
13
- * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.
14
- * @public
15
- */
16
- declare function EnvNum(key: EnvKeyInput, fallback: number): EnvaptFieldDecorator<number>;
17
- declare function EnvNum(key: EnvKeyInput): EnvaptFieldDecorator<number | null>;
18
- /**
19
- * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.
20
- * @public
21
- */
22
- declare function EnvStr(key: EnvKeyInput, fallback: string): EnvaptFieldDecorator<string>;
23
- declare function EnvStr(key: EnvKeyInput): EnvaptFieldDecorator<string | null>;
24
- /**
25
- * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a
26
- * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.
27
- * @public
28
- */
29
- declare function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptFieldDecorator<number>;
30
- declare function EnvTime(key: EnvKeyInput): EnvaptFieldDecorator<number | null>;
31
- /**
32
- * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`
33
- * instance, not a URL string.
34
- * @public
35
- */
36
- declare function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptFieldDecorator<URL>;
37
- declare function EnvUrl(key: EnvKeyInput): EnvaptFieldDecorator<URL | null>;
38
- //#endregion
39
- export { EnvBool, EnvNum, EnvStr, EnvTime, EnvUrl };
40
- //# sourceMappingURL=SugarDecorators.d.mts.map
@@ -1,218 +0,0 @@
1
- import { ArrayOf } from "../../converters/Converters.mjs";
2
- import { BuiltInConverter, ConverterFunction, InferConverterFallbackType, InferConverterReturnType, InferPrimitiveReturnType, PrimitiveConstructor } from "../../types/Conversion.mjs";
3
- import { InferSchemaOutput, StandardSchemaV1 } from "../../infra/StandardSchema.mjs";
4
- import { SchemaConstraint } from "../../types/Schema.mjs";
5
- import { EnvKeyInput } from "../../types/Env.mjs";
6
- import { EnvaptAccessorDecorator } from "../../types/Decorator.mjs";
7
-
8
- //#region src/decorators/modern/Envapt.d.ts
9
- /**
10
- * A custom converter function with a fallback (both required), or a fallback only.
11
- *
12
- * @param key - Environment variable name(s) to load
13
- * @param options - Configuration options
14
- * @public
15
- * @example
16
- * ```ts
17
- * class Config {
18
- * \@Envapt('API_KEY', {
19
- * fallback: 'default-key',
20
- * converter(raw, _fallback) {
21
- * if (!raw || raw.trim() === '') throw new Error('API_KEY required');
22
- * return raw.trim();
23
- * }
24
- * })
25
- * static accessor apiKey: string;
26
- *
27
- * \@Envapt('LOG_FILE', { fallback: '/var/log/app.log' })
28
- * static accessor logFile: string;
29
- *
30
- * \@Envapt('RETRY_POLICY', { fallback: { retries: 3, backoff: 'exponential' } })
31
- * static accessor retryPolicy: unknown;
32
- * }
33
- * ```
34
- */
35
- declare function Envapt(key: EnvKeyInput, options: {
36
- fallback: undefined;
37
- converter?: undefined;
38
- }): EnvaptAccessorDecorator<string | undefined>;
39
- declare function Envapt<TFallback>(key: EnvKeyInput, options: {
40
- converter: (raw: string | undefined, fallback: TFallback) => TFallback;
41
- fallback: TFallback;
42
- } | {
43
- fallback: TFallback;
44
- converter?: undefined;
45
- }): EnvaptAccessorDecorator<TFallback>;
46
- /**
47
- * A custom converter function without a fallback. Omit `required` to return the converter's
48
- * output (possibly `undefined`), or pass `required: true` to throw `MissingEnvValue` on
49
- * missing or empty values.
50
- *
51
- * @param key - Environment variable name(s) to load
52
- * @param options - Configuration options
53
- * @public
54
- * @example
55
- * ```ts
56
- * class Config {
57
- * \@Envapt('FEATURE_FLAGS', { converter(raw) {
58
- * return raw ? raw.split('|').map(s => s.trim()) : [];
59
- * } })
60
- * static accessor featureFlags: string[];
61
- *
62
- * \@Envapt('JWT_SECRET', {
63
- * converter: (raw) => Buffer.from(raw ?? '', 'base64'),
64
- * required: true
65
- * })
66
- * static accessor jwtSecret: Buffer;
67
- * }
68
- * ```
69
- */
70
- declare function Envapt<TReturnType>(key: EnvKeyInput, options: {
71
- converter: ConverterFunction<TReturnType>;
72
- required?: false;
73
- } | {
74
- converter: ConverterFunction<TReturnType>;
75
- required: true;
76
- }): EnvaptAccessorDecorator<TReturnType>;
77
- /**
78
- * A built-in or array converter with a fallback, or `required: true`. The fallback type tracks
79
- * the converter, so `Converters.Time` takes a number or time-string and `Converters.Url` takes
80
- * a `URL` instance.
81
- *
82
- * @param key - Environment variable name(s) to load
83
- * @param options - Configuration options
84
- * @public
85
- * @example
86
- * ```ts
87
- * import { Converters } from 'envapt';
88
- *
89
- * class Config {
90
- * \@Envapt('APP_PORT', { converter: Converters.Number, fallback: 3000 })
91
- * static accessor port: number;
92
- *
93
- * // the Url fallback is a URL instance, not a string
94
- * \@Envapt('APP_URL', { converter: Converters.Url, fallback: new URL('http://localhost:3000') })
95
- * static accessor url: URL;
96
- *
97
- * // prefers CANARY_URL when present, otherwise APP_URL
98
- * \@Envapt(['CANARY_URL', 'APP_URL'], { converter: Converters.Url })
99
- * static accessor canaryUrl: URL | null;
100
- *
101
- * // Time takes a number (milliseconds) or a time-string fallback (`<number><unit>`)
102
- * \@Envapt('REQUEST_TIMEOUT', { converter: Converters.Time, fallback: '10s' })
103
- * static accessor requestTimeout: number;
104
- *
105
- * \@Envapt('ALLOWED_ORIGINS', {
106
- * converter: Converters.array({ of: Converters.String }),
107
- * fallback: ['https://example.com']
108
- * })
109
- * static accessor allowedOrigins: string[];
110
- *
111
- * \@Envapt('DATABASE_URL', { converter: Converters.Url, required: true })
112
- * static accessor databaseUrl: URL;
113
- * }
114
- * ```
115
- */
116
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
117
- converter: TConverter;
118
- fallback: InferConverterFallbackType<TConverter>;
119
- required?: false;
120
- } | {
121
- converter: TConverter;
122
- required: true;
123
- }): EnvaptAccessorDecorator<InferConverterReturnType<TConverter>>;
124
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
125
- converter: TConverter;
126
- fallback: undefined;
127
- required?: false;
128
- }): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | undefined>;
129
- declare function Envapt<TConverter extends BuiltInConverter | ArrayOf>(key: EnvKeyInput, options: {
130
- converter: TConverter;
131
- required?: false;
132
- }): EnvaptAccessorDecorator<InferConverterReturnType<TConverter> | null>;
133
- /**
134
- * A primitive constructor (`Number`, `Boolean`) with an optional fallback.
135
- *
136
- * @param key - Environment variable name(s) to load
137
- * @param options - Configuration options
138
- * @public
139
- * @example
140
- * ```ts
141
- * class Config {
142
- * \@Envapt('MAX_CONNECTIONS', { converter: Number, fallback: 100 })
143
- * static accessor maxConnections: number;
144
- *
145
- * \@Envapt('FEATURE_ENABLED', { converter: Boolean, fallback: false })
146
- * static accessor featureEnabled: boolean;
147
- * }
148
- * ```
149
- */
150
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
151
- converter: TConstructor;
152
- fallback: InferPrimitiveReturnType<TConstructor>;
153
- required?: false;
154
- } | {
155
- converter: TConstructor;
156
- required: true;
157
- }): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor>>;
158
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
159
- converter: TConstructor;
160
- fallback: undefined;
161
- required?: false;
162
- }): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | undefined>;
163
- declare function Envapt<TConstructor extends PrimitiveConstructor>(key: EnvKeyInput, options: {
164
- converter: TConstructor;
165
- required?: false;
166
- }): EnvaptAccessorDecorator<InferPrimitiveReturnType<TConstructor> | null>;
167
- /**
168
- * Required, no converter (raw string). Throws `MissingEnvValue` on first access when the env
169
- * value is missing or empty after trimming, independent of the global `Envapter.strict` flag.
170
- * Pairing `required: true` with `fallback` matches no overload at compile time, and the runtime
171
- * Validator rejects dynamic objects that bypass the types.
172
- *
173
- * @param key - Environment variable name(s) to load
174
- * @param options - `{ required: true }`
175
- * @public
176
- * @example
177
- * ```ts
178
- * class Config {
179
- * \@Envapt('API_KEY', { required: true })
180
- * static accessor apiKey: string;
181
- * }
182
- * ```
183
- */
184
- declare function Envapt(key: EnvKeyInput, options: {
185
- required: true;
186
- }): EnvaptAccessorDecorator<string>;
187
- /**
188
- * No-fallback form. The property resolves from env or `null`.
189
- *
190
- * @param key - Environment variable name(s) to load
191
- * @public
192
- * @example
193
- * ```ts
194
- * class Config {
195
- * \@Envapt('SIMPLE_VALUE')
196
- * static accessor simple: string | null;
197
- * }
198
- * ```
199
- */
200
- declare function Envapt(key: EnvKeyInput): EnvaptAccessorDecorator<string | null>;
201
- /**
202
- * A Standard Schema v1 adapter (zod, valibot, arktype, hand-rolled). Synchronous schemas only,
203
- * so a Promise-returning `validate` throws `InvalidUserDefinedConfig` at runtime. Pairing
204
- * `schema` with `converter` matches no overload at compile time, and the runtime Validator
205
- * rejects dynamic objects that bypass the types.
206
- * @public
207
- */
208
- declare function Envapt<Schema extends StandardSchemaV1>(key: EnvKeyInput, options: {
209
- schema: SchemaConstraint<Schema>;
210
- fallback?: InferSchemaOutput<Schema>;
211
- required?: false;
212
- } | {
213
- schema: SchemaConstraint<Schema>;
214
- required: true;
215
- }): EnvaptAccessorDecorator<InferSchemaOutput<Schema>>;
216
- //#endregion
217
- export { Envapt };
218
- //# sourceMappingURL=Envapt.d.mts.map
@@ -1,40 +0,0 @@
1
- import { TimeFallback } from "../../types/Conversion.mjs";
2
- import { EnvKeyInput } from "../../types/Env.mjs";
3
- import { EnvaptAccessorDecorator } from "../../types/Decorator.mjs";
4
-
5
- //#region src/decorators/modern/SugarDecorators.d.ts
6
- /**
7
- * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.
8
- * @public
9
- */
10
- declare function EnvBool(key: EnvKeyInput, fallback: boolean): EnvaptAccessorDecorator<boolean>;
11
- declare function EnvBool(key: EnvKeyInput): EnvaptAccessorDecorator<boolean | null>;
12
- /**
13
- * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.
14
- * @public
15
- */
16
- declare function EnvNum(key: EnvKeyInput, fallback: number): EnvaptAccessorDecorator<number>;
17
- declare function EnvNum(key: EnvKeyInput): EnvaptAccessorDecorator<number | null>;
18
- /**
19
- * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.
20
- * @public
21
- */
22
- declare function EnvStr(key: EnvKeyInput, fallback: string): EnvaptAccessorDecorator<string>;
23
- declare function EnvStr(key: EnvKeyInput): EnvaptAccessorDecorator<string | null>;
24
- /**
25
- * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a
26
- * millisecond number or a time string (`'15m'`), and the resolved value is always milliseconds.
27
- * @public
28
- */
29
- declare function EnvTime(key: EnvKeyInput, fallback: TimeFallback): EnvaptAccessorDecorator<number>;
30
- declare function EnvTime(key: EnvKeyInput): EnvaptAccessorDecorator<number | null>;
31
- /**
32
- * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`
33
- * instance, not a URL string.
34
- * @public
35
- */
36
- declare function EnvUrl(key: EnvKeyInput, fallback: URL): EnvaptAccessorDecorator<URL>;
37
- declare function EnvUrl(key: EnvKeyInput): EnvaptAccessorDecorator<URL | null>;
38
- //#endregion
39
- export { EnvBool, EnvNum, EnvStr, EnvTime, EnvUrl };
40
- //# sourceMappingURL=SugarDecorators.d.mts.map
@@ -1,70 +0,0 @@
1
- import { Environment } from "../core/EnvironmentMethods.mjs";
2
- import { AdvancedMethods } from "../core/AdvancedMethods.mjs";
3
-
4
- //#region src/engine/Envapter.d.ts
5
- /**
6
- * Main configuration class for environment variable management.
7
- *
8
- * Provides both static and instance methods for retrieving typed environment variables
9
- * with support for template resolution, multiple .env files, and environment detection.
10
- *
11
- * Extend your own classes from this to define properties with \@Envapt decorators and get access to environment-variable methods.
12
- *
13
- * @example
14
- * ```ts
15
- * // Static usage
16
- * const port = Envapter.getNumber('PORT', 3000);
17
- * const url = Envapter.get('API_URL', 'http://localhost');
18
- * const replica = Envapter.get(['READONLY_URL', 'DATABASE_URL'], 'sqlite://memory');
19
- *
20
- * // Instance usage
21
- * const env = new Envapter();
22
- * const dbUrl = env.get('DATABASE_URL', 'sqlite://memory');
23
- * const primaryHost = env.get(['PRIMARY_HOST', 'SECONDARY_HOST']);
24
- * ```
25
- *
26
- * @public
27
- */
28
- declare class Envapter extends AdvancedMethods {
29
- /**
30
- * Tagged template literal for resolving environment variables in template strings.
31
- *
32
- * @example
33
- * ```ts
34
- * // Given API_HOST=api.example.com and API_PORT=8080 in environment
35
- * const endpoint = Envapter.resolve`Connecting to ${'API_HOST'}:${'API_PORT'}`;
36
- * // Returns: "Connecting to api.example.com:8080"
37
- *
38
- * // Works with template variables in .env too:
39
- * // API_URL=https://${API_HOST}:${API_PORT}
40
- * const message = Envapter.resolve`Service endpoint: ${'API_URL'}`;
41
- * // Returns: "Service endpoint: https://api.example.com:8080"
42
- * ```
43
- */
44
- static resolve(strings: TemplateStringsArray, ...keys: string[]): string;
45
- /**
46
- * @see {@link Envapter.resolve}
47
- */
48
- resolve(strings: TemplateStringsArray, ...keys: string[]): string;
49
- /**
50
- * Assert that one or more environment variables are present and non-empty (post-trim,
51
- * after template resolution). Throws `MissingEnvValue` listing every missing key.
52
- *
53
- * For typed fail-fast in functional code, use `Envapter.getUsing(key, { converter, required: true })`.
54
- *
55
- * @example
56
- * ```ts
57
- * Envapter.require('DATABASE_URL');
58
- * Envapter.require('DATABASE_URL', 'API_KEY', 'SENTRY_DSN');
59
- * ```
60
- */
61
- static require(...keys: [string, ...string[]]): void;
62
- private static resolveAndValidate;
63
- /**
64
- * @see {@link Envapter.require}
65
- */
66
- require(...keys: [string, ...string[]]): void;
67
- }
68
- //#endregion
69
- export { Envapter };
70
- //# sourceMappingURL=Envapter.d.mts.map
@@ -1,17 +0,0 @@
1
- import { EnvapterService } from "../types/Env.mjs";
2
-
3
- //#region src/engine/TemplateResolver.d.ts
4
- /**
5
- * Resolve `${VAR}` template references in environment values, guarding against circular
6
- * references and missing variables.
7
- * @internal
8
- */
9
- declare class TemplateResolver {
10
- private readonly envService;
11
- private readonly TEMPLATE_REGEX;
12
- constructor(envService: EnvapterService);
13
- resolveTemplate(key: string, value: string, stack?: Set<string>): string;
14
- }
15
- //#endregion
16
- export { TemplateResolver };
17
- //# sourceMappingURL=TemplateResolver.d.mts.map