@arkenv/standard 1.0.0-alpha.7 → 1.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bind-arkenv-D5X_ukEU.js +1 -0
- package/dist/{bind-arkenv-F4i-iDsA.cjs → bind-arkenv-DCVPKJ39.cjs} +1 -1
- package/dist/index-ByAIZ0F1.d.ts +622 -0
- package/dist/index-DdPEn3aK.d.cts +622 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{src-BZoXXFsx.cjs → src-CJWeQijZ.js} +1 -1
- package/dist/{src-BxruqAr0.js → src-DTEO2b2p.cjs} +1 -2
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.cts +2 -3
- package/dist/valibot.d.ts +2 -3
- package/dist/valibot.js +1 -2
- package/dist/zod-mini.cjs +1 -1
- package/dist/zod-mini.d.cts +2 -3
- package/dist/zod-mini.d.ts +2 -3
- package/dist/zod-mini.js +1 -2
- package/package.json +1 -1
- package/dist/bind-arkenv-Z7Nl-5uk.js +0 -2
- package/dist/bind-arkenv-Z7Nl-5uk.js.map +0 -1
- package/dist/index-DLnvC3Za.d.ts +0 -12612
- package/dist/index-DLnvC3Za.d.ts.map +0 -1
- package/dist/index-Dn1RAoiV.d.cts +0 -12612
- package/dist/index-Dn1RAoiV.d.cts.map +0 -1
- package/dist/src-BxruqAr0.js.map +0 -1
- package/dist/valibot.d.cts.map +0 -1
- package/dist/valibot.d.ts.map +0 -1
- package/dist/valibot.js.map +0 -1
- package/dist/zod-mini.d.cts.map +0 -1
- package/dist/zod-mini.d.ts.map +0 -1
- package/dist/zod-mini.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./src-CJWeQijZ.js";function t(t){function n(n,r){return e(n,{...r,toJsonSchema:r?.toJsonSchema??t})}return n}export{t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./src-
|
|
1
|
+
const e=require(`./src-DTEO2b2p.cjs`);function t(t){function n(n,r){return e.t(n,{...r,toJsonSchema:r?.toJsonSchema??t})}return n}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
//#region ../internal/types/dist/standard-schema.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
4
|
+
*
|
|
5
|
+
* Copied from standard-schema (MIT License)
|
|
6
|
+
* Copyright (c) 2024 Colin McDannell
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
10
|
+
*/
|
|
11
|
+
interface StandardTypedV1$1<Input = unknown, Output = Input> {
|
|
12
|
+
/**
|
|
13
|
+
* The Standard properties.
|
|
14
|
+
*/
|
|
15
|
+
readonly "~standard": StandardTypedV1$1.Props<Input, Output>;
|
|
16
|
+
}
|
|
17
|
+
declare namespace StandardTypedV1$1 {
|
|
18
|
+
/**
|
|
19
|
+
* The Standard Typed properties interface.
|
|
20
|
+
*/
|
|
21
|
+
interface Props<Input = unknown, Output = Input> {
|
|
22
|
+
/**
|
|
23
|
+
* The version number of the standard.
|
|
24
|
+
*/
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/**
|
|
27
|
+
* The vendor name of the schema library.
|
|
28
|
+
*/
|
|
29
|
+
readonly vendor: string;
|
|
30
|
+
/**
|
|
31
|
+
* Inferred types associated with the schema.
|
|
32
|
+
*/
|
|
33
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The Standard Typed types interface.
|
|
37
|
+
*/
|
|
38
|
+
interface Types<Input = unknown, Output = Input> {
|
|
39
|
+
/**
|
|
40
|
+
* The input type of the schema.
|
|
41
|
+
*/
|
|
42
|
+
readonly input: Input;
|
|
43
|
+
/**
|
|
44
|
+
* The output type of the schema.
|
|
45
|
+
*/
|
|
46
|
+
readonly output: Output;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Infers the input type of a Standard Typed.
|
|
50
|
+
*/
|
|
51
|
+
type InferInput<Schema extends StandardTypedV1$1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
52
|
+
/**
|
|
53
|
+
* Infers the output type of a Standard Typed.
|
|
54
|
+
*/
|
|
55
|
+
type InferOutput<Schema extends StandardTypedV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Standard Schema interface.
|
|
59
|
+
*/
|
|
60
|
+
interface StandardSchemaV1$1<Input = unknown, Output = Input> {
|
|
61
|
+
/**
|
|
62
|
+
* The Standard Schema properties.
|
|
63
|
+
*/
|
|
64
|
+
readonly "~standard": StandardSchemaV1$1.Props<Input, Output>;
|
|
65
|
+
}
|
|
66
|
+
declare namespace StandardSchemaV1$1 {
|
|
67
|
+
/**
|
|
68
|
+
* The Standard Schema properties interface.
|
|
69
|
+
*/
|
|
70
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1$1.Props<Input, Output> {
|
|
71
|
+
/**
|
|
72
|
+
* Validates unknown input values.
|
|
73
|
+
*/
|
|
74
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1$1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The result interface of the validate function.
|
|
78
|
+
*/
|
|
79
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
80
|
+
/**
|
|
81
|
+
* The result interface if validation succeeds.
|
|
82
|
+
*/
|
|
83
|
+
interface SuccessResult<Output> {
|
|
84
|
+
/**
|
|
85
|
+
* The typed output value.
|
|
86
|
+
*/
|
|
87
|
+
readonly value: Output;
|
|
88
|
+
/**
|
|
89
|
+
* A falsy value for `issues` indicates success.
|
|
90
|
+
*/
|
|
91
|
+
readonly issues?: undefined;
|
|
92
|
+
}
|
|
93
|
+
interface Options {
|
|
94
|
+
/**
|
|
95
|
+
* Explicit support for additional vendor-specific parameters, if needed.
|
|
96
|
+
*/
|
|
97
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The result interface if validation fails.
|
|
101
|
+
*/
|
|
102
|
+
interface FailureResult {
|
|
103
|
+
/**
|
|
104
|
+
* The issues of failed validation.
|
|
105
|
+
*/
|
|
106
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The issue interface of the failure output.
|
|
110
|
+
*/
|
|
111
|
+
interface Issue {
|
|
112
|
+
/**
|
|
113
|
+
* The error message of the issue.
|
|
114
|
+
*/
|
|
115
|
+
readonly message: string;
|
|
116
|
+
/**
|
|
117
|
+
* The path of the issue, if any.
|
|
118
|
+
*/
|
|
119
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The path segment interface of the issue.
|
|
123
|
+
*/
|
|
124
|
+
interface PathSegment {
|
|
125
|
+
/**
|
|
126
|
+
* The key representing a path segment.
|
|
127
|
+
*/
|
|
128
|
+
readonly key: PropertyKey;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The Standard types interface.
|
|
132
|
+
*/
|
|
133
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1$1.Types<Input, Output> {}
|
|
134
|
+
/**
|
|
135
|
+
* Infers the input type of a Standard.
|
|
136
|
+
*/
|
|
137
|
+
type InferInput<Schema extends StandardTypedV1$1> = StandardTypedV1$1.InferInput<Schema>;
|
|
138
|
+
/**
|
|
139
|
+
* Infers the output type of a Standard.
|
|
140
|
+
*/
|
|
141
|
+
type InferOutput<Schema extends StandardTypedV1$1> = StandardTypedV1$1.InferOutput<Schema>;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region ../internal/utils/dist/index.d.ts
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region ../types/dist/standard-schema.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
149
|
+
*
|
|
150
|
+
* Copied from standard-schema (MIT License)
|
|
151
|
+
* Copyright (c) 2024 Colin McDannell
|
|
152
|
+
*/
|
|
153
|
+
/**
|
|
154
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
155
|
+
*/
|
|
156
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
157
|
+
/**
|
|
158
|
+
* The Standard properties.
|
|
159
|
+
*/
|
|
160
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
161
|
+
}
|
|
162
|
+
declare namespace StandardTypedV1 {
|
|
163
|
+
/**
|
|
164
|
+
* The Standard Typed properties interface.
|
|
165
|
+
*/
|
|
166
|
+
interface Props<Input = unknown, Output = Input> {
|
|
167
|
+
/**
|
|
168
|
+
* The version number of the standard.
|
|
169
|
+
*/
|
|
170
|
+
readonly version: 1;
|
|
171
|
+
/**
|
|
172
|
+
* The vendor name of the schema library.
|
|
173
|
+
*/
|
|
174
|
+
readonly vendor: string;
|
|
175
|
+
/**
|
|
176
|
+
* Inferred types associated with the schema.
|
|
177
|
+
*/
|
|
178
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The Standard Typed types interface.
|
|
182
|
+
*/
|
|
183
|
+
interface Types<Input = unknown, Output = Input> {
|
|
184
|
+
/**
|
|
185
|
+
* The input type of the schema.
|
|
186
|
+
*/
|
|
187
|
+
readonly input: Input;
|
|
188
|
+
/**
|
|
189
|
+
* The output type of the schema.
|
|
190
|
+
*/
|
|
191
|
+
readonly output: Output;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Infers the input type of a Standard Typed.
|
|
195
|
+
*/
|
|
196
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
197
|
+
/**
|
|
198
|
+
* Infers the output type of a Standard Typed.
|
|
199
|
+
*/
|
|
200
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The Standard Schema interface.
|
|
204
|
+
*/
|
|
205
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
206
|
+
/**
|
|
207
|
+
* The Standard Schema properties.
|
|
208
|
+
*/
|
|
209
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
210
|
+
}
|
|
211
|
+
declare namespace StandardSchemaV1 {
|
|
212
|
+
/**
|
|
213
|
+
* The Standard Schema properties interface.
|
|
214
|
+
*/
|
|
215
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
216
|
+
/**
|
|
217
|
+
* Validates unknown input values.
|
|
218
|
+
*/
|
|
219
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The result interface of the validate function.
|
|
223
|
+
*/
|
|
224
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
225
|
+
/**
|
|
226
|
+
* The result interface if validation succeeds.
|
|
227
|
+
*/
|
|
228
|
+
interface SuccessResult<Output> {
|
|
229
|
+
/**
|
|
230
|
+
* The typed output value.
|
|
231
|
+
*/
|
|
232
|
+
readonly value: Output;
|
|
233
|
+
/**
|
|
234
|
+
* A falsy value for `issues` indicates success.
|
|
235
|
+
*/
|
|
236
|
+
readonly issues?: undefined;
|
|
237
|
+
}
|
|
238
|
+
interface Options {
|
|
239
|
+
/**
|
|
240
|
+
* Explicit support for additional vendor-specific parameters, if needed.
|
|
241
|
+
*/
|
|
242
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The result interface if validation fails.
|
|
246
|
+
*/
|
|
247
|
+
interface FailureResult {
|
|
248
|
+
/**
|
|
249
|
+
* The issues of failed validation.
|
|
250
|
+
*/
|
|
251
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The issue interface of the failure output.
|
|
255
|
+
*/
|
|
256
|
+
interface Issue {
|
|
257
|
+
/**
|
|
258
|
+
* The error message of the issue.
|
|
259
|
+
*/
|
|
260
|
+
readonly message: string;
|
|
261
|
+
/**
|
|
262
|
+
* The path of the issue, if any.
|
|
263
|
+
*/
|
|
264
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The path segment interface of the issue.
|
|
268
|
+
*/
|
|
269
|
+
interface PathSegment {
|
|
270
|
+
/**
|
|
271
|
+
* The key representing a path segment.
|
|
272
|
+
*/
|
|
273
|
+
readonly key: PropertyKey;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The Standard types interface.
|
|
277
|
+
*/
|
|
278
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
279
|
+
/**
|
|
280
|
+
* Infers the input type of a Standard.
|
|
281
|
+
*/
|
|
282
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
283
|
+
/**
|
|
284
|
+
* Infers the output type of a Standard.
|
|
285
|
+
*/
|
|
286
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
287
|
+
} //#endregion
|
|
288
|
+
//#region src/coercion/environment.d.ts
|
|
289
|
+
/**
|
|
290
|
+
* Prepare an environment record by optionally stripping empty strings and applying coercion.
|
|
291
|
+
*
|
|
292
|
+
* @param env The raw environment variables
|
|
293
|
+
* @param emptyAsUndefined Whether to strip empty string values before processing
|
|
294
|
+
* @param arrayFormat The format to use for array coercion
|
|
295
|
+
* @param getSchema Optional callback that returns a JSON Schema and whether it exists,
|
|
296
|
+
* used to determine coercion targets. When omitted, no coercion is performed.
|
|
297
|
+
* @returns The processed environment, the coerced environment, and any missing schema keys
|
|
298
|
+
*/
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/core.d.ts
|
|
301
|
+
/**
|
|
302
|
+
* Machine-readable classification codes for environment validation issues.
|
|
303
|
+
*/
|
|
304
|
+
type EnvIssueCode =
|
|
305
|
+
/**
|
|
306
|
+
* The environment variable is required but was not provided, and has no default value.
|
|
307
|
+
*/
|
|
308
|
+
"MISSING_VARIABLE"
|
|
309
|
+
/**
|
|
310
|
+
* The variable value failed a type assertion (e.g., expected a number or boolean but received a string).
|
|
311
|
+
*/
|
|
312
|
+
| "INVALID_TYPE"
|
|
313
|
+
/**
|
|
314
|
+
* The variable value falls below the minimum allowed numeric limit or string/array length constraint.
|
|
315
|
+
*/
|
|
316
|
+
| "VALUE_TOO_SMALL"
|
|
317
|
+
/**
|
|
318
|
+
* The variable value exceeds the maximum allowed numeric limit or string/array length constraint.
|
|
319
|
+
*/
|
|
320
|
+
| "VALUE_TOO_LARGE"
|
|
321
|
+
/**
|
|
322
|
+
* The variable value did not match the specified regular expression (regex) pattern constraint.
|
|
323
|
+
*/
|
|
324
|
+
| "PATTERN_MISMATCH"
|
|
325
|
+
/**
|
|
326
|
+
* The variable value is not in a valid format (e.g., failed email or UUID format validation).
|
|
327
|
+
*/
|
|
328
|
+
| "INVALID_FORMAT"
|
|
329
|
+
/**
|
|
330
|
+
* An undeclared key was found in the environment, and the schema config is set to reject undeclared keys.
|
|
331
|
+
*/
|
|
332
|
+
| "UNDECLARED_KEY"
|
|
333
|
+
/**
|
|
334
|
+
* The provided validation schema definition itself is malformed or invalid.
|
|
335
|
+
*/
|
|
336
|
+
| "INVALID_SCHEMA"
|
|
337
|
+
/**
|
|
338
|
+
* A validation error was triggered by a custom validator function or inline pipe logic.
|
|
339
|
+
*/
|
|
340
|
+
| "CUSTOM";
|
|
341
|
+
/**
|
|
342
|
+
* Metadata associated with an environment validation issue.
|
|
343
|
+
*/
|
|
344
|
+
type EnvIssueMeta = {
|
|
345
|
+
/**
|
|
346
|
+
* The minimum expected boundary for numeric/string length constraints
|
|
347
|
+
*/
|
|
348
|
+
min?: number;
|
|
349
|
+
/**
|
|
350
|
+
* The maximum expected boundary for numeric/string length constraints
|
|
351
|
+
*/
|
|
352
|
+
max?: number;
|
|
353
|
+
/**
|
|
354
|
+
* Additional validation pattern/specifier details
|
|
355
|
+
*/
|
|
356
|
+
validation?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Any custom constraint descriptions
|
|
359
|
+
*/
|
|
360
|
+
constraint?: string;
|
|
361
|
+
/**
|
|
362
|
+
* Traversal error occurred during JSON-parsing of the environment variable
|
|
363
|
+
*/
|
|
364
|
+
traversalError?: string;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Normalized validation issue representing a failure on a specific environment variable.
|
|
368
|
+
*/
|
|
369
|
+
type EnvIssue = {
|
|
370
|
+
/**
|
|
371
|
+
* The dot-separated property path/name of the environment variable
|
|
372
|
+
*/
|
|
373
|
+
path: string;
|
|
374
|
+
/**
|
|
375
|
+
* The descriptive, user-friendly error message
|
|
376
|
+
*/
|
|
377
|
+
message: string;
|
|
378
|
+
/**
|
|
379
|
+
* The normalized classification code for the issue
|
|
380
|
+
*/
|
|
381
|
+
code: EnvIssueCode;
|
|
382
|
+
/**
|
|
383
|
+
* The expected type or value shape description
|
|
384
|
+
*/
|
|
385
|
+
expected?: string;
|
|
386
|
+
/**
|
|
387
|
+
* The raw value received (redacted in string formatting if sensitive)
|
|
388
|
+
*/
|
|
389
|
+
received?: unknown;
|
|
390
|
+
/**
|
|
391
|
+
* Additional validation metadata
|
|
392
|
+
*/
|
|
393
|
+
meta?: EnvIssueMeta;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Format a list of normalized environment issues into a single styled string.
|
|
397
|
+
*
|
|
398
|
+
* @param issues - The array of normalized issues to format
|
|
399
|
+
* @returns The formatted and styled error report string
|
|
400
|
+
*/
|
|
401
|
+
declare function formatIssues(issues: EnvIssue[]): string;
|
|
402
|
+
/**
|
|
403
|
+
* Error thrown when environment variable validation fails.
|
|
404
|
+
*
|
|
405
|
+
* This error extends the native `Error` class and provides formatted error messages
|
|
406
|
+
* that clearly indicate which environment variables are invalid and why.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* try {
|
|
411
|
+
* const env = arkenv({
|
|
412
|
+
* PORT: 'number.port',
|
|
413
|
+
* HOST: 'string.host',
|
|
414
|
+
* });
|
|
415
|
+
* } catch (error) {
|
|
416
|
+
* if (error instanceof ArkEnvError) {
|
|
417
|
+
* console.error('Environment validation failed:', error.message);
|
|
418
|
+
* }
|
|
419
|
+
* }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare class ArkEnvError extends Error {
|
|
423
|
+
/**
|
|
424
|
+
* The list of normalized issues that caused the validation failure
|
|
425
|
+
*/
|
|
426
|
+
readonly issues: EnvIssue[];
|
|
427
|
+
constructor(issues: EnvIssue[], message?: string);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Result of a non-throwing arkenv parse operation.
|
|
431
|
+
*/
|
|
432
|
+
type SafeArkEnvResult<T> = {
|
|
433
|
+
success: true;
|
|
434
|
+
data: T;
|
|
435
|
+
} | {
|
|
436
|
+
success: false;
|
|
437
|
+
issues: readonly EnvIssue[];
|
|
438
|
+
}; //#endregion
|
|
439
|
+
//#region src/guards.d.ts
|
|
440
|
+
/**
|
|
441
|
+
* Throws if the given value is a string (ArkType DSL) in standard mode.
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/parse-standard.d.ts
|
|
446
|
+
/**
|
|
447
|
+
* Configuration options for {@link parseStandard}.
|
|
448
|
+
*/
|
|
449
|
+
type ParseStandardConfig = {
|
|
450
|
+
/**
|
|
451
|
+
* The environment variables to parse. Defaults to `process.env`.
|
|
452
|
+
*
|
|
453
|
+
* All values must be strings (or `undefined`) to match `process.env` semantics.
|
|
454
|
+
*/
|
|
455
|
+
env?: Record<string, string | undefined>;
|
|
456
|
+
/**
|
|
457
|
+
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
458
|
+
*
|
|
459
|
+
* Defaults to `'delete'` so the output object only contains keys you've declared.
|
|
460
|
+
*
|
|
461
|
+
* - `delete` (default): Undeclared keys are allowed on input but stripped from the output.
|
|
462
|
+
* - `ignore`: Undeclared keys are allowed and preserved in the output.
|
|
463
|
+
* - `reject`: Undeclared keys will cause validation to fail.
|
|
464
|
+
*
|
|
465
|
+
* @default "delete"
|
|
466
|
+
*/
|
|
467
|
+
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
468
|
+
/**
|
|
469
|
+
* Whether to bypass secret redaction and print raw sensitive values during debugging.
|
|
470
|
+
* Defaults to checking `process.env.ARKENV_DEBUG_SECRETS === "true"` or `"1"`.
|
|
471
|
+
*/
|
|
472
|
+
debugSecrets?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Whether to perform best-effort coercion on the environment variables.
|
|
475
|
+
* Coercion prefers validators that expose Standard JSON Schema on the value
|
|
476
|
+
* itself (e.g. Zod). For converters that live outside the schema (e.g. Valibot
|
|
477
|
+
* via `@valibot/to-json-schema`, Zod Mini via `z.toJSONSchema`, or Zod v3 via
|
|
478
|
+
* `zod-to-json-schema`), pass {@link toJsonSchema}.
|
|
479
|
+
*
|
|
480
|
+
* @see https://standard-schema.dev
|
|
481
|
+
* @default true
|
|
482
|
+
*/
|
|
483
|
+
coerce?: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Optional fallback that converts a Standard Schema validator to JSON Schema
|
|
486
|
+
* for ArkEnv pre-coercion when a key has no Standard JSON Schema on the value.
|
|
487
|
+
*
|
|
488
|
+
* Called per key only in that case. Not called when omitted, when `coerce` is
|
|
489
|
+
* `false`, or when JSON Schema was already read from the value.
|
|
490
|
+
*
|
|
491
|
+
* - Return a plain object to use as that key's JSON Schema.
|
|
492
|
+
* - Return `undefined` to skip coercion for that key only.
|
|
493
|
+
* - Throwing or returning a non-plain object fails the parse with
|
|
494
|
+
* {@link ArkEnvError} for that key (`INVALID_SCHEMA`).
|
|
495
|
+
*
|
|
496
|
+
* Typed as {@link StandardSchemaV1}. Host converters (Valibot, Zod Mini,
|
|
497
|
+
* Zod v3 via `zod-to-json-schema`) do not accept that type — assert at the
|
|
498
|
+
* converter call (`as v.GenericSchema`, `as z.ZodMiniType`,
|
|
499
|
+
* `as z.ZodTypeAny`). Same assertion for a single-library map and a hybrid
|
|
500
|
+
* with classic Zod (Zod never reaches this callback at runtime).
|
|
501
|
+
*
|
|
502
|
+
* @example Valibot wiring
|
|
503
|
+
* ```ts
|
|
504
|
+
* import { toJsonSchema } from "@valibot/to-json-schema";
|
|
505
|
+
* import * as v from "valibot";
|
|
506
|
+
*
|
|
507
|
+
* arkenv(
|
|
508
|
+
* { PORT: v.number() },
|
|
509
|
+
* {
|
|
510
|
+
* toJsonSchema: (schema) =>
|
|
511
|
+
* toJsonSchema(schema as v.GenericSchema, {
|
|
512
|
+
* typeMode: "input",
|
|
513
|
+
* target: "draft-07",
|
|
514
|
+
* }),
|
|
515
|
+
* },
|
|
516
|
+
* );
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* @example Zod v3 wiring
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { z } from "zod/v3";
|
|
522
|
+
* import { zodToJsonSchema } from "zod-to-json-schema";
|
|
523
|
+
*
|
|
524
|
+
* arkenv(
|
|
525
|
+
* { PORT: z.number() },
|
|
526
|
+
* {
|
|
527
|
+
* toJsonSchema: (schema) =>
|
|
528
|
+
* zodToJsonSchema(schema as z.ZodTypeAny, {
|
|
529
|
+
* $refStrategy: "none",
|
|
530
|
+
* }),
|
|
531
|
+
* },
|
|
532
|
+
* );
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
toJsonSchema?: (schema: StandardSchemaV1) => object | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* The format to use for array parsing when coercion is enabled.
|
|
538
|
+
*
|
|
539
|
+
* - `comma` (default): Strings are split by comma and trimmed.
|
|
540
|
+
* - `json`: Strings are parsed as JSON.
|
|
541
|
+
*
|
|
542
|
+
* @default "comma"
|
|
543
|
+
*/
|
|
544
|
+
arrayFormat?: "comma" | "json";
|
|
545
|
+
/**
|
|
546
|
+
* Whether to treat empty strings (`""`) as `undefined` before validation.
|
|
547
|
+
*
|
|
548
|
+
* When enabled, an environment variable set to an empty value (e.g. `PORT=`)
|
|
549
|
+
* will be treated as if it were missing, allowing defaults to apply and
|
|
550
|
+
* preventing validation errors for numeric or boolean types.
|
|
551
|
+
*
|
|
552
|
+
* @default false
|
|
553
|
+
*/
|
|
554
|
+
emptyAsUndefined?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Whether to return a safe result object instead of throwing an error on validation failure.
|
|
557
|
+
*
|
|
558
|
+
* When enabled, the function returns an object with `{ success: true, data }` or `{ success: false, issues }`.
|
|
559
|
+
*
|
|
560
|
+
* @default false
|
|
561
|
+
*/
|
|
562
|
+
safe?: boolean;
|
|
563
|
+
};
|
|
564
|
+
/**
|
|
565
|
+
* Parse and validate environment variables using Standard Schema 1.0 validators.
|
|
566
|
+
*
|
|
567
|
+
* @param def An object mapping environment variable keys to Standard Schema 1.0 validators
|
|
568
|
+
* @param config Parsing options, including environment source, undeclared key handling, and coercion config
|
|
569
|
+
* @returns The parsed and validated environment variables
|
|
570
|
+
* @throws An ArkEnvError if validation fails
|
|
571
|
+
*/
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/schema.d.ts
|
|
574
|
+
/**
|
|
575
|
+
* Extract the keys from a schema definition.
|
|
576
|
+
* Supports plain objects, ArkType schemas, and Standard Schema validators.
|
|
577
|
+
*
|
|
578
|
+
* @param schema The schema definition to extract keys from
|
|
579
|
+
* @returns An array of extracted key names
|
|
580
|
+
*/
|
|
581
|
+
declare function getSchemaKeys(schema: any): string[]; //#endregion
|
|
582
|
+
//#region src/schema-capture.d.ts
|
|
583
|
+
/**
|
|
584
|
+
* Start recording `arkenv()` schema arguments instead of validating the environment.
|
|
585
|
+
*
|
|
586
|
+
* CLI-supporting API: tools such as the ArkEnv CLI use this to inspect a user's
|
|
587
|
+
* schema module without requiring `process.env` to be populated.
|
|
588
|
+
*/
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region src/index.d.ts
|
|
591
|
+
/**
|
|
592
|
+
* Configuration options for `arkenv` from `@arkenv/standard`.
|
|
593
|
+
*/
|
|
594
|
+
type StandardEnvConfig = ParseStandardConfig;
|
|
595
|
+
type StandardEnvOutput<T extends Record<string, StandardSchemaV1$1>> = { [K in keyof T]: StandardSchemaV1$1.InferOutput<T[K]> };
|
|
596
|
+
/**
|
|
597
|
+
* Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).
|
|
598
|
+
*
|
|
599
|
+
* This entry is ArkType-free - ArkType is never imported, even transitively.
|
|
600
|
+
* Use this when your project must not depend on ArkType.
|
|
601
|
+
*
|
|
602
|
+
* @param def An object mapping variable names to Standard Schema validators
|
|
603
|
+
* @param config Optional configuration
|
|
604
|
+
* @returns The validated environment variables, a SafeArkEnvResult if `{ safe: true }` is configured, or a value-less stub when schema capture is active
|
|
605
|
+
* @throws An {@link ArkEnvError} if validation fails and `safe` is not enabled
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* import arkenv from "@arkenv/standard";
|
|
610
|
+
* import * as z from "zod";
|
|
611
|
+
*
|
|
612
|
+
* const env = arkenv({
|
|
613
|
+
* PORT: z.number(),
|
|
614
|
+
* HOST: z.string(),
|
|
615
|
+
* });
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
declare function arkenv<const T extends Record<string, StandardSchemaV1$1>, const Safe extends boolean | undefined = undefined>(def: T, config?: Omit<StandardEnvConfig, "safe"> & {
|
|
619
|
+
safe?: Safe;
|
|
620
|
+
}): [Safe] extends [true] ? SafeArkEnvResult<StandardEnvOutput<T>> : StandardEnvOutput<T>;
|
|
621
|
+
//#endregion
|
|
622
|
+
export { SafeArkEnvResult as a, EnvIssue as i, arkenv as n, formatIssues as o, ArkEnvError as r, getSchemaKeys as s, StandardEnvConfig as t };
|