envapt 5.0.3 → 5.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/Debug.cjs +2 -0
  3. package/dist/Debug.cjs.map +1 -0
  4. package/dist/Debug.d.cts +13 -0
  5. package/dist/Debug.d.cts.map +1 -0
  6. package/dist/Debug.d.mts +13 -0
  7. package/dist/Debug.d.mts.map +1 -0
  8. package/dist/Debug.mjs +2 -0
  9. package/dist/Debug.mjs.map +1 -0
  10. package/dist/Dotenv.cjs +3 -0
  11. package/dist/Dotenv.cjs.map +1 -0
  12. package/dist/Dotenv.d.cts +17 -0
  13. package/dist/Dotenv.d.cts.map +1 -0
  14. package/dist/Dotenv.d.mts +17 -0
  15. package/dist/Dotenv.d.mts.map +1 -0
  16. package/dist/Dotenv.mjs +3 -0
  17. package/dist/Dotenv.mjs.map +1 -0
  18. package/dist/Envapter.cjs +2 -0
  19. package/dist/Envapter.cjs.map +1 -0
  20. package/dist/Envapter.d.cts +70 -0
  21. package/dist/Envapter.d.cts.map +1 -0
  22. package/dist/Envapter.d.mts +70 -0
  23. package/dist/Envapter.d.mts.map +1 -0
  24. package/dist/Envapter.mjs +2 -0
  25. package/dist/Envapter.mjs.map +1 -0
  26. package/dist/Error.cjs +2 -0
  27. package/dist/Error.cjs.map +1 -0
  28. package/dist/Error.d.cts +68 -0
  29. package/dist/Error.d.cts.map +1 -0
  30. package/dist/Error.d.mts +68 -0
  31. package/dist/Error.d.mts.map +1 -0
  32. package/dist/Error.mjs +2 -0
  33. package/dist/Error.mjs.map +1 -0
  34. package/dist/StandardSchema.d.cts +59 -0
  35. package/dist/StandardSchema.d.cts.map +1 -0
  36. package/dist/StandardSchema.d.mts +59 -0
  37. package/dist/StandardSchema.d.mts.map +1 -0
  38. package/dist/TemplateResolver.cjs +2 -0
  39. package/dist/TemplateResolver.cjs.map +1 -0
  40. package/dist/TemplateResolver.d.cts +17 -0
  41. package/dist/TemplateResolver.d.cts.map +1 -0
  42. package/dist/TemplateResolver.d.mts +17 -0
  43. package/dist/TemplateResolver.d.mts.map +1 -0
  44. package/dist/TemplateResolver.mjs +2 -0
  45. package/dist/TemplateResolver.mjs.map +1 -0
  46. package/dist/Validators.cjs +2 -0
  47. package/dist/Validators.cjs.map +1 -0
  48. package/dist/Validators.mjs +2 -0
  49. package/dist/Validators.mjs.map +1 -0
  50. package/dist/_virtual/_rolldown/runtime.cjs +1 -0
  51. package/dist/config.cjs +1 -1
  52. package/dist/config.cjs.map +1 -1
  53. package/dist/config.mjs +1 -1
  54. package/dist/config.mjs.map +1 -1
  55. package/dist/converters/BuiltInConverters.cjs +2 -0
  56. package/dist/converters/BuiltInConverters.cjs.map +1 -0
  57. package/dist/converters/BuiltInConverters.mjs +2 -0
  58. package/dist/converters/BuiltInConverters.mjs.map +1 -0
  59. package/dist/converters/Converters.cjs +2 -0
  60. package/dist/converters/Converters.cjs.map +1 -0
  61. package/dist/converters/Converters.d.cts +93 -0
  62. package/dist/converters/Converters.d.cts.map +1 -0
  63. package/dist/converters/Converters.d.mts +93 -0
  64. package/dist/converters/Converters.d.mts.map +1 -0
  65. package/dist/converters/Converters.mjs +2 -0
  66. package/dist/converters/Converters.mjs.map +1 -0
  67. package/dist/converters/ListOfBuiltInConverters.cjs +2 -0
  68. package/dist/converters/ListOfBuiltInConverters.cjs.map +1 -0
  69. package/dist/converters/ListOfBuiltInConverters.mjs +2 -0
  70. package/dist/converters/ListOfBuiltInConverters.mjs.map +1 -0
  71. package/dist/converters/ValueConverter.cjs +2 -0
  72. package/dist/converters/ValueConverter.cjs.map +1 -0
  73. package/dist/converters/ValueConverter.d.cts +25 -0
  74. package/dist/converters/ValueConverter.d.cts.map +1 -0
  75. package/dist/converters/ValueConverter.d.mts +25 -0
  76. package/dist/converters/ValueConverter.d.mts.map +1 -0
  77. package/dist/converters/ValueConverter.mjs +2 -0
  78. package/dist/converters/ValueConverter.mjs.map +1 -0
  79. package/dist/core/AdvancedMethods.cjs +2 -0
  80. package/dist/core/AdvancedMethods.cjs.map +1 -0
  81. package/dist/core/AdvancedMethods.d.cts +76 -0
  82. package/dist/core/AdvancedMethods.d.cts.map +1 -0
  83. package/dist/core/AdvancedMethods.d.mts +76 -0
  84. package/dist/core/AdvancedMethods.d.mts.map +1 -0
  85. package/dist/core/AdvancedMethods.mjs +2 -0
  86. package/dist/core/AdvancedMethods.mjs.map +1 -0
  87. package/dist/core/EnvapterBase.cjs +2 -0
  88. package/dist/core/EnvapterBase.cjs.map +1 -0
  89. package/dist/core/EnvapterBase.d.cts +105 -0
  90. package/dist/core/EnvapterBase.d.cts.map +1 -0
  91. package/dist/core/EnvapterBase.d.mts +105 -0
  92. package/dist/core/EnvapterBase.d.mts.map +1 -0
  93. package/dist/core/EnvapterBase.mjs +2 -0
  94. package/dist/core/EnvapterBase.mjs.map +1 -0
  95. package/dist/core/EnvironmentMethods.cjs +2 -0
  96. package/dist/core/EnvironmentMethods.cjs.map +1 -0
  97. package/dist/core/EnvironmentMethods.d.cts +132 -0
  98. package/dist/core/EnvironmentMethods.d.cts.map +1 -0
  99. package/dist/core/EnvironmentMethods.d.mts +132 -0
  100. package/dist/core/EnvironmentMethods.d.mts.map +1 -0
  101. package/dist/core/EnvironmentMethods.mjs +2 -0
  102. package/dist/core/EnvironmentMethods.mjs.map +1 -0
  103. package/dist/core/PrimitiveMethods.cjs +2 -0
  104. package/dist/core/PrimitiveMethods.cjs.map +1 -0
  105. package/dist/core/PrimitiveMethods.d.cts +70 -0
  106. package/dist/core/PrimitiveMethods.d.cts.map +1 -0
  107. package/dist/core/PrimitiveMethods.d.mts +70 -0
  108. package/dist/core/PrimitiveMethods.d.mts.map +1 -0
  109. package/dist/core/PrimitiveMethods.mjs +2 -0
  110. package/dist/core/PrimitiveMethods.mjs.map +1 -0
  111. package/dist/decorators/Envapt.cjs +2 -0
  112. package/dist/decorators/Envapt.cjs.map +1 -0
  113. package/dist/decorators/Envapt.d.cts +233 -0
  114. package/dist/decorators/Envapt.d.cts.map +1 -0
  115. package/dist/decorators/Envapt.d.mts +233 -0
  116. package/dist/decorators/Envapt.d.mts.map +1 -0
  117. package/dist/decorators/Envapt.mjs +2 -0
  118. package/dist/decorators/Envapt.mjs.map +1 -0
  119. package/dist/decorators/SugarDecorators.cjs +2 -0
  120. package/dist/decorators/SugarDecorators.cjs.map +1 -0
  121. package/dist/decorators/SugarDecorators.d.cts +34 -0
  122. package/dist/decorators/SugarDecorators.d.cts.map +1 -0
  123. package/dist/decorators/SugarDecorators.d.mts +34 -0
  124. package/dist/decorators/SugarDecorators.d.mts.map +1 -0
  125. package/dist/decorators/SugarDecorators.mjs +2 -0
  126. package/dist/decorators/SugarDecorators.mjs.map +1 -0
  127. package/dist/decorators/createPropertyDecorator.cjs +2 -0
  128. package/dist/decorators/createPropertyDecorator.cjs.map +1 -0
  129. package/dist/decorators/createPropertyDecorator.mjs +2 -0
  130. package/dist/decorators/createPropertyDecorator.mjs.map +1 -0
  131. package/dist/index.cjs +1 -2
  132. package/dist/index.d.cts +14 -1127
  133. package/dist/index.d.mts +14 -1127
  134. package/dist/index.mjs +1 -2
  135. package/dist/types/Conversion.d.cts +128 -0
  136. package/dist/types/Conversion.d.cts.map +1 -0
  137. package/dist/types/Conversion.d.mts +128 -0
  138. package/dist/types/Conversion.d.mts.map +1 -0
  139. package/dist/types/Env.d.cts +17 -0
  140. package/dist/types/Env.d.cts.map +1 -0
  141. package/dist/types/Env.d.mts +17 -0
  142. package/dist/types/Env.d.mts.map +1 -0
  143. package/dist/types/Options.d.cts +39 -0
  144. package/dist/types/Options.d.cts.map +1 -0
  145. package/dist/types/Options.d.mts +39 -0
  146. package/dist/types/Options.d.mts.map +1 -0
  147. package/dist/types/Schema.d.cts +12 -0
  148. package/dist/types/Schema.d.cts.map +1 -0
  149. package/dist/types/Schema.d.mts +12 -0
  150. package/dist/types/Schema.d.mts.map +1 -0
  151. package/package.json +3 -2
  152. package/dist/Envapter-CBSM3v-5.cjs +0 -3
  153. package/dist/Envapter-CBSM3v-5.cjs.map +0 -1
  154. package/dist/Envapter-D8FEdzBR.mjs +0 -3
  155. package/dist/Envapter-D8FEdzBR.mjs.map +0 -1
  156. package/dist/index.cjs.map +0 -1
  157. package/dist/index.d.cts.map +0 -1
  158. package/dist/index.d.mts.map +0 -1
  159. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,233 @@
1
+ import { ArrayOf } from "../converters/Converters.mjs";
2
+ import { BuiltInConverter, ConverterFunction, InferConverterFallbackType, InferPrimitiveFallbackType, InferPrimitiveReturnType, PrimitiveConstructor } from "../types/Conversion.mjs";
3
+ import { InferSchemaOutput, StandardSchemaV1 } from "../StandardSchema.mjs";
4
+ import { SchemaConstraint } from "../types/Schema.mjs";
5
+ import { EnvKeyInput } from "../types/Env.mjs";
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.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Envapt.d.mts","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"}
@@ -0,0 +1,2 @@
1
+ import{EnvaptError as e}from"../Error.mjs";import{Validator as t}from"../Validators.mjs";import{createPropertyDecorator as n}from"./createPropertyDecorator.mjs";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(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.isStandardSchema(n.schema))throw new e(302,"`schema` must be a Standard Schema v1 object (zod, valibot, arktype, or any `~standard`-conformant value).");if(s!==void 0)throw new e(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(r,{fallback:o,converter:s,hasFallback:l,required:u,schema:c})}export{r as Envapt};
2
+ //# sourceMappingURL=Envapt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Envapt.mjs","names":[],"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":"iKAwPA,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,IAAI,EAAA,IAEN,uIACJ,EAGJ,GAAI,WAAY,GAAW,EAAQ,SAAW,IAAA,GAAW,CACrD,GAAI,CAAC,EAAU,iBAAiB,EAAQ,MAAM,EAC1C,MAAM,IAAI,EAAA,IAEN,4GACJ,EAEJ,GAAI,IAAoB,IAAA,GACpB,MAAM,IAAI,EAAA,IAEN,qIACJ,EAEJ,EAAe,EAAQ,MAC3B,CACJ,MAEI,EAAW,EACX,EAAkB,EAClB,EAAc,UAAU,OAAS,EAGrC,OAAO,EAAwB,EAAK,CAChC,WACA,UAAW,EACX,cACA,WACA,OAAQ,CACZ,CAAC,CACL"}
@@ -0,0 +1,2 @@
1
+ const e=require("../converters/Converters.cjs"),t=require("./createPropertyDecorator.cjs");function n(e,n,r){return t.createPropertyDecorator(n,{converter:e,fallback:r,hasFallback:r!==void 0,required:!1,schema:void 0})}function r(t,r){return n(e.Converters.Boolean,t,r)}function i(t,r){return n(e.Converters.Number,t,r)}function a(t,r){return n(e.Converters.String,t,r)}function o(t,r){return n(e.Converters.Time,t,r)}function s(t,r){return n(e.Converters.Url,t,r)}exports.EnvBool=r,exports.EnvNum=i,exports.EnvStr=a,exports.EnvTime=o,exports.EnvUrl=s;
2
+ //# sourceMappingURL=SugarDecorators.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugarDecorators.cjs","names":["createPropertyDecorator","Converters"],"sources":["../../src/decorators/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../converters';\n\nimport type { ConverterToken } from '../converters';\nimport type { EnvKeyInput, TimeFallback } from '../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): PropertyDecorator {\n return createPropertyDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n });\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n */\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): PropertyDecorator {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n */\nexport function EnvNum(key: EnvKeyInput, fallback?: number): PropertyDecorator {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n */\nexport function EnvStr(key: EnvKeyInput, fallback?: string): PropertyDecorator {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`); the resolved value is always milliseconds.\n * @public\n */\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): PropertyDecorator {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`\n * instance, not a URL string.\n * @public\n */\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): PropertyDecorator {\n return sugar(Converters.Url, key, fallback);\n}\n"],"mappings":"2FAMA,SAAS,EACL,EACA,EACA,EACiB,CACjB,OAAOA,EAAAA,wBAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CAMA,SAAgB,EAAQ,EAAkB,EAAuC,CAC7E,OAAO,EAAMC,EAAAA,WAAW,QAAS,EAAK,CAAQ,CAClD,CAMA,SAAgB,EAAO,EAAkB,EAAsC,CAC3E,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CAMA,SAAgB,EAAO,EAAkB,EAAsC,CAC3E,OAAO,EAAMA,EAAAA,WAAW,OAAQ,EAAK,CAAQ,CACjD,CAOA,SAAgB,EAAQ,EAAkB,EAA4C,CAClF,OAAO,EAAMA,EAAAA,WAAW,KAAM,EAAK,CAAQ,CAC/C,CAOA,SAAgB,EAAO,EAAkB,EAAmC,CACxE,OAAO,EAAMA,EAAAA,WAAW,IAAK,EAAK,CAAQ,CAC9C"}
@@ -0,0 +1,34 @@
1
+ import { TimeFallback } from "../types/Conversion.cjs";
2
+ import { EnvKeyInput } from "../types/Env.cjs";
3
+
4
+ //#region src/decorators/SugarDecorators.d.ts
5
+ /**
6
+ * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.
7
+ * @public
8
+ */
9
+ declare function EnvBool(key: EnvKeyInput, fallback?: boolean): PropertyDecorator;
10
+ /**
11
+ * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.
12
+ * @public
13
+ */
14
+ declare function EnvNum(key: EnvKeyInput, fallback?: number): PropertyDecorator;
15
+ /**
16
+ * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.
17
+ * @public
18
+ */
19
+ declare function EnvStr(key: EnvKeyInput, fallback?: string): PropertyDecorator;
20
+ /**
21
+ * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a
22
+ * millisecond number or a time string (`'15m'`); the resolved value is always milliseconds.
23
+ * @public
24
+ */
25
+ declare function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): PropertyDecorator;
26
+ /**
27
+ * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`
28
+ * instance, not a URL string.
29
+ * @public
30
+ */
31
+ declare function EnvUrl(key: EnvKeyInput, fallback?: URL): PropertyDecorator;
32
+ //#endregion
33
+ export { EnvBool, EnvNum, EnvStr, EnvTime, EnvUrl };
34
+ //# sourceMappingURL=SugarDecorators.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugarDecorators.d.cts","names":[],"sources":["../../src/decorators/SugarDecorators.ts"],"mappings":";;;;;;;AAwBA;iBAAgB,OAAA,CAAQ,GAAA,EAAK,WAAA,EAAa,QAAA,aAAqB,iBAAiB;;;;;iBAQhE,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,YAAoB,iBAAiB;;;AARE;AAQhF;iBAQgB,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,YAAoB,iBAAiB;;;;;;iBAS9D,OAAA,CAAQ,GAAA,EAAK,WAAA,EAAa,QAAA,GAAW,YAAA,GAAe,iBAAA;;AAjBU;AAQ9E;;;iBAkBgB,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,GAAW,GAAA,GAAM,iBAAA"}
@@ -0,0 +1,34 @@
1
+ import { TimeFallback } from "../types/Conversion.mjs";
2
+ import { EnvKeyInput } from "../types/Env.mjs";
3
+
4
+ //#region src/decorators/SugarDecorators.d.ts
5
+ /**
6
+ * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.
7
+ * @public
8
+ */
9
+ declare function EnvBool(key: EnvKeyInput, fallback?: boolean): PropertyDecorator;
10
+ /**
11
+ * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.
12
+ * @public
13
+ */
14
+ declare function EnvNum(key: EnvKeyInput, fallback?: number): PropertyDecorator;
15
+ /**
16
+ * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.
17
+ * @public
18
+ */
19
+ declare function EnvStr(key: EnvKeyInput, fallback?: string): PropertyDecorator;
20
+ /**
21
+ * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a
22
+ * millisecond number or a time string (`'15m'`); the resolved value is always milliseconds.
23
+ * @public
24
+ */
25
+ declare function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): PropertyDecorator;
26
+ /**
27
+ * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`
28
+ * instance, not a URL string.
29
+ * @public
30
+ */
31
+ declare function EnvUrl(key: EnvKeyInput, fallback?: URL): PropertyDecorator;
32
+ //#endregion
33
+ export { EnvBool, EnvNum, EnvStr, EnvTime, EnvUrl };
34
+ //# sourceMappingURL=SugarDecorators.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugarDecorators.d.mts","names":[],"sources":["../../src/decorators/SugarDecorators.ts"],"mappings":";;;;;;;AAwBA;iBAAgB,OAAA,CAAQ,GAAA,EAAK,WAAA,EAAa,QAAA,aAAqB,iBAAiB;;;;;iBAQhE,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,YAAoB,iBAAiB;;;AARE;AAQhF;iBAQgB,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,YAAoB,iBAAiB;;;;;;iBAS9D,OAAA,CAAQ,GAAA,EAAK,WAAA,EAAa,QAAA,GAAW,YAAA,GAAe,iBAAA;;AAjBU;AAQ9E;;;iBAkBgB,MAAA,CAAO,GAAA,EAAK,WAAA,EAAa,QAAA,GAAW,GAAA,GAAM,iBAAA"}
@@ -0,0 +1,2 @@
1
+ import{Converters as e}from"../converters/Converters.mjs";import{createPropertyDecorator as t}from"./createPropertyDecorator.mjs";function n(e,n,r){return t(n,{converter:e,fallback:r,hasFallback:r!==void 0,required:!1,schema:void 0})}function r(t,r){return n(e.Boolean,t,r)}function i(t,r){return n(e.Number,t,r)}function a(t,r){return n(e.String,t,r)}function o(t,r){return n(e.Time,t,r)}function s(t,r){return n(e.Url,t,r)}export{r as EnvBool,i as EnvNum,a as EnvStr,o as EnvTime,s as EnvUrl};
2
+ //# sourceMappingURL=SugarDecorators.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SugarDecorators.mjs","names":[],"sources":["../../src/decorators/SugarDecorators.ts"],"sourcesContent":["import { createPropertyDecorator } from './createPropertyDecorator';\nimport { Converters } from '../converters';\n\nimport type { ConverterToken } from '../converters';\nimport type { EnvKeyInput, TimeFallback } from '../types';\n\nfunction sugar<TFallback>(\n converter: ConverterToken,\n key: EnvKeyInput,\n fallback: TFallback | undefined\n): PropertyDecorator {\n return createPropertyDecorator<TFallback>(key, {\n converter,\n fallback,\n hasFallback: fallback !== undefined,\n required: false,\n schema: undefined\n });\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Boolean, fallback })`.\n * @public\n */\nexport function EnvBool(key: EnvKeyInput, fallback?: boolean): PropertyDecorator {\n return sugar(Converters.Boolean, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Number, fallback })`.\n * @public\n */\nexport function EnvNum(key: EnvKeyInput, fallback?: number): PropertyDecorator {\n return sugar(Converters.Number, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.String, fallback })`.\n * @public\n */\nexport function EnvStr(key: EnvKeyInput, fallback?: string): PropertyDecorator {\n return sugar(Converters.String, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Time, fallback })`. The fallback is a\n * millisecond number or a time string (`'15m'`); the resolved value is always milliseconds.\n * @public\n */\nexport function EnvTime(key: EnvKeyInput, fallback?: TimeFallback): PropertyDecorator {\n return sugar(Converters.Time, key, fallback);\n}\n\n/**\n * Shorthand for `@Envapt(key, { converter: Converters.Url, fallback })`. The fallback is a `URL`\n * instance, not a URL string.\n * @public\n */\nexport function EnvUrl(key: EnvKeyInput, fallback?: URL): PropertyDecorator {\n return sugar(Converters.Url, key, fallback);\n}\n"],"mappings":"kIAMA,SAAS,EACL,EACA,EACA,EACiB,CACjB,OAAO,EAAmC,EAAK,CAC3C,YACA,WACA,YAAa,IAAa,IAAA,GAC1B,SAAU,GACV,OAAQ,IAAA,EACZ,CAAC,CACL,CAMA,SAAgB,EAAQ,EAAkB,EAAuC,CAC7E,OAAO,EAAM,EAAW,QAAS,EAAK,CAAQ,CAClD,CAMA,SAAgB,EAAO,EAAkB,EAAsC,CAC3E,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CAMA,SAAgB,EAAO,EAAkB,EAAsC,CAC3E,OAAO,EAAM,EAAW,OAAQ,EAAK,CAAQ,CACjD,CAOA,SAAgB,EAAQ,EAAkB,EAA4C,CAClF,OAAO,EAAM,EAAW,KAAM,EAAK,CAAQ,CAC/C,CAOA,SAAgB,EAAO,EAAkB,EAAmC,CACxE,OAAO,EAAM,EAAW,IAAK,EAAK,CAAQ,CAC9C"}
@@ -0,0 +1,2 @@
1
+ const e=require("../Error.cjs"),t=require("../converters/ValueConverter.cjs"),n=require("../core/EnvapterBase.cjs"),r=require("../Envapter.cjs");function i(e){return Array.isArray(e)?`[${e.join(`, `)}]`:String(e)}function a(a,o){let{fallback:s,converter:c,hasFallback:l,required:u,schema:d}=o;return function(o,f){let p=String(f),m=`${typeof o==`function`?o.name:o.constructor.name}.${p}`;Object.defineProperty(o,p,{get:function(){let o=n.EnvaptCache.get(m);if(o===void 0){let f=new r.Envapter;if(u&&d===void 0){let t=f.getRaw(a);if(t===void 0||t.trim()===``)throw new e.EnvaptError(305,`Required environment variable "${i(a)}" is missing or empty.`)}let p=new t.ValueConverter(f);o=d===void 0?p.convertValue(a,s,c,l):p.convertWithSchema(a,d,s,l),n.EnvaptCache.set(m,o)}return o},configurable:!1,enumerable:!0})}}exports.createPropertyDecorator=a;
2
+ //# sourceMappingURL=createPropertyDecorator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPropertyDecorator.cjs","names":["EnvaptCache","Envapter","EnvaptError","ValueConverter"],"sources":["../../src/decorators/createPropertyDecorator.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { EnvaptCache } from '../core';\nimport { Envapter } from '../Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../Error';\n\nimport type { StandardSchemaV1 } from '../StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\ninterface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nexport function createPropertyDecorator<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>\n): PropertyDecorator {\n const { fallback, converter, hasFallback, required, schema } = config;\n return function (target: object, prop: string | symbol): void {\n const propKey = String(prop);\n // Distinguishing constructor (static) from prototype (instance) keeps same-named static and instance properties from colliding in the cache.\n const className = typeof target === 'function' ? target.name : target.constructor.name;\n const cacheKey = `${className}.${propKey}`;\n\n Object.defineProperty(target, propKey, {\n get: function () {\n let value = EnvaptCache.get(cacheKey) as TFallback | null | undefined;\n\n if (value === undefined) {\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (rawValue === undefined || rawValue.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n if (schema !== undefined) {\n value = valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback;\n } else {\n value = valueConverter.convertValue(key, fallback, converter, hasFallback);\n }\n EnvaptCache.set(cacheKey, value);\n }\n\n return value;\n },\n configurable: false,\n enumerable: true\n });\n };\n}\n"],"mappings":"iJAQA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAUA,SAAgB,EACZ,EACA,EACiB,CACjB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAC/D,OAAO,SAAU,EAAgB,EAA6B,CAC1D,IAAM,EAAU,OAAO,CAAI,EAGrB,EAAW,GADC,OAAO,GAAW,WAAa,EAAO,KAAO,EAAO,YAAY,KACpD,GAAG,IAEjC,OAAO,eAAe,EAAQ,EAAS,CACnC,IAAK,UAAY,CACb,IAAI,EAAQA,EAAAA,YAAY,IAAI,CAAQ,EAEpC,GAAI,IAAU,IAAA,GAAW,CACrB,IAAM,EAAW,IAAIC,EAAAA,SAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAI,IAAa,IAAA,IAAa,EAAS,KAAK,IAAM,GAC9C,MAAM,IAAIC,EAAAA,YAAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAIC,EAAAA,eAAe,CAAQ,EAClD,AACI,EADA,IAAW,IAAA,GAGH,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EAFjE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI/E,EAAA,YAAY,IAAI,EAAU,CAAK,CACnC,CAEA,OAAO,CACX,EACA,aAAc,GACd,WAAY,EAChB,CAAC,CACL,CACJ"}
@@ -0,0 +1,2 @@
1
+ import{EnvaptError as e}from"../Error.mjs";import{ValueConverter as t}from"../converters/ValueConverter.mjs";import{EnvaptCache as n}from"../core/EnvapterBase.mjs";import{Envapter as r}from"../Envapter.mjs";function i(e){return Array.isArray(e)?`[${e.join(`, `)}]`:String(e)}function a(a,o){let{fallback:s,converter:c,hasFallback:l,required:u,schema:d}=o;return function(o,f){let p=String(f),m=`${typeof o==`function`?o.name:o.constructor.name}.${p}`;Object.defineProperty(o,p,{get:function(){let o=n.get(m);if(o===void 0){let f=new r;if(u&&d===void 0){let t=f.getRaw(a);if(t===void 0||t.trim()===``)throw new e(305,`Required environment variable "${i(a)}" is missing or empty.`)}let p=new t(f);o=d===void 0?p.convertValue(a,s,c,l):p.convertWithSchema(a,d,s,l),n.set(m,o)}return o},configurable:!1,enumerable:!0})}}export{a as createPropertyDecorator};
2
+ //# sourceMappingURL=createPropertyDecorator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPropertyDecorator.mjs","names":[],"sources":["../../src/decorators/createPropertyDecorator.ts"],"sourcesContent":["import { ValueConverter } from '../converters';\nimport { EnvaptCache } from '../core';\nimport { Envapter } from '../Envapter';\nimport { EnvaptError, EnvaptErrorCodes } from '../Error';\n\nimport type { StandardSchemaV1 } from '../StandardSchema';\nimport type { EnvaptConverter, EnvKeyInput } from '../types';\n\nfunction formatKeyForError(key: EnvKeyInput): string {\n return Array.isArray(key) ? `[${key.join(', ')}]` : String(key);\n}\n\ninterface DecoratorConfig<TFallback> {\n fallback: TFallback | undefined;\n converter: EnvaptConverter<TFallback> | undefined;\n hasFallback: boolean;\n required: boolean;\n schema: StandardSchemaV1 | undefined;\n}\n\nexport function createPropertyDecorator<TFallback>(\n key: EnvKeyInput,\n config: DecoratorConfig<TFallback>\n): PropertyDecorator {\n const { fallback, converter, hasFallback, required, schema } = config;\n return function (target: object, prop: string | symbol): void {\n const propKey = String(prop);\n // Distinguishing constructor (static) from prototype (instance) keeps same-named static and instance properties from colliding in the cache.\n const className = typeof target === 'function' ? target.name : target.constructor.name;\n const cacheKey = `${className}.${propKey}`;\n\n Object.defineProperty(target, propKey, {\n get: function () {\n let value = EnvaptCache.get(cacheKey) as TFallback | null | undefined;\n\n if (value === undefined) {\n const envapter = new Envapter();\n\n if (required && schema === undefined) {\n const rawValue = envapter.getRaw(key);\n if (rawValue === undefined || rawValue.trim() === '') {\n throw new EnvaptError(\n EnvaptErrorCodes.MissingEnvValue,\n `Required environment variable \"${formatKeyForError(key)}\" is missing or empty.`\n );\n }\n }\n\n const valueConverter = new ValueConverter(envapter);\n if (schema !== undefined) {\n value = valueConverter.convertWithSchema(key, schema, fallback, hasFallback) as TFallback;\n } else {\n value = valueConverter.convertValue(key, fallback, converter, hasFallback);\n }\n EnvaptCache.set(cacheKey, value);\n }\n\n return value;\n },\n configurable: false,\n enumerable: true\n });\n };\n}\n"],"mappings":"+MAQA,SAAS,EAAkB,EAA0B,CACjD,OAAO,MAAM,QAAQ,CAAG,EAAI,IAAI,EAAI,KAAK,IAAI,EAAE,GAAK,OAAO,CAAG,CAClE,CAUA,SAAgB,EACZ,EACA,EACiB,CACjB,GAAM,CAAE,WAAU,YAAW,cAAa,WAAU,UAAW,EAC/D,OAAO,SAAU,EAAgB,EAA6B,CAC1D,IAAM,EAAU,OAAO,CAAI,EAGrB,EAAW,GADC,OAAO,GAAW,WAAa,EAAO,KAAO,EAAO,YAAY,KACpD,GAAG,IAEjC,OAAO,eAAe,EAAQ,EAAS,CACnC,IAAK,UAAY,CACb,IAAI,EAAQ,EAAY,IAAI,CAAQ,EAEpC,GAAI,IAAU,IAAA,GAAW,CACrB,IAAM,EAAW,IAAI,EAErB,GAAI,GAAY,IAAW,IAAA,GAAW,CAClC,IAAM,EAAW,EAAS,OAAO,CAAG,EACpC,GAAI,IAAa,IAAA,IAAa,EAAS,KAAK,IAAM,GAC9C,MAAM,IAAI,EAAA,IAEN,kCAAkC,EAAkB,CAAG,EAAE,uBAC7D,CAER,CAEA,IAAM,EAAiB,IAAI,EAAe,CAAQ,EAClD,AACI,EADA,IAAW,IAAA,GAGH,EAAe,aAAa,EAAK,EAAU,EAAW,CAAW,EAFjE,EAAe,kBAAkB,EAAK,EAAQ,EAAU,CAAW,EAI/E,EAAY,IAAI,EAAU,CAAK,CACnC,CAEA,OAAO,CACX,EACA,aAAc,GACd,WAAY,EAChB,CAAC,CACL,CACJ"}
package/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./Envapter-CBSM3v-5.cjs");function t(e){return Array.isArray(e)?`[${e.join(`, `)}]`:String(e)}function n(n,r){let{fallback:i,converter:a,hasFallback:o,required:s,schema:c}=r;return function(r,l){let u=String(l),d=`${typeof r==`function`?r.name:r.constructor.name}.${u}`;Object.defineProperty(r,u,{get:function(){let r=e.r.get(d);if(r===void 0){let l=new e.t;if(s&&c===void 0){let r=l.getRaw(n);if(r===void 0||r.trim()===``)throw new e.o(305,`Required environment variable "${t(n)}" is missing or empty.`)}let u=new e.i(l);r=c===void 0?u.convertValue(n,i,a,o):u.convertWithSchema(n,c,i,o),e.r.set(d,r)}return r},configurable:!1,enumerable:!0})}}function r(t,r,i){let a,o,s,c=!0,l=!1;if(r&&typeof r==`object`&&(`fallback`in r||`converter`in r||`required`in r||`schema`in r)){let t=r;if(a=t.fallback,o=t.converter,c=`fallback`in t,l=t.required===!0,l&&c&&a!==void 0)throw new e.o(302,"`required: true` and `fallback` are mutually exclusive on @Envapt options. Drop the fallback or call `Envapter.require()` separately.");if(`schema`in t&&t.schema!==void 0){if(!e.a.isStandardSchema(t.schema))throw new e.o(302,"`schema` must be a Standard Schema v1 object (zod, valibot, arktype, or any `~standard`-conformant value).");if(o!==void 0)throw new e.o(302,"`schema` and `converter` are mutually exclusive on @Envapt options. Drop one as they both turn a raw env string into a typed value.");s=t.schema}}else a=r,o=i,c=arguments.length>1;return n(t,{fallback:a,converter:o,hasFallback:c,required:l,schema:s})}function i(e,t,r){return n(t,{converter:e,fallback:r,hasFallback:r!==void 0,required:!1,schema:void 0})}function a(t,n){return i(e.c.Boolean,t,n)}function o(t,n){return i(e.c.Number,t,n)}function s(t,n){return i(e.c.String,t,n)}function c(t,n){return i(e.c.Time,t,n)}function l(t,n){return i(e.c.Url,t,n)}exports.Converters=e.c,exports.EnvBool=a,exports.EnvNum=o,exports.EnvStr=s,exports.EnvTime=c,exports.EnvUrl=l,exports.Envapt=r,exports.EnvaptError=e.o,exports.EnvaptErrorCodes=e.s,exports.Envapter=e.t,exports.Environment=e.n,exports.isArrayOf=e.l;
2
- //# sourceMappingURL=index.cjs.map
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./converters/Converters.cjs"),t=require("./Error.cjs"),n=require("./core/EnvironmentMethods.cjs"),r=require("./Envapter.cjs"),i=require("./decorators/Envapt.cjs"),a=require("./decorators/SugarDecorators.cjs");exports.Converters=e.Converters,exports.EnvBool=a.EnvBool,exports.EnvNum=a.EnvNum,exports.EnvStr=a.EnvStr,exports.EnvTime=a.EnvTime,exports.EnvUrl=a.EnvUrl,exports.Envapt=i.Envapt,exports.EnvaptError=t.EnvaptError,exports.EnvaptErrorCodes=t.EnvaptErrorCodes,exports.Envapter=r.Envapter,exports.Environment=n.Environment,exports.isArrayOf=e.isArrayOf;