arkenv 0.8.3 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/arktype/index.cjs +1 -0
- package/dist/arktype/index.d.cts +109 -0
- package/dist/arktype/index.d.cts.map +1 -0
- package/dist/arktype/index.d.ts +109 -0
- package/dist/arktype/index.d.ts.map +1 -0
- package/dist/arktype/index.js +2 -0
- package/dist/arktype/index.js.map +1 -0
- package/dist/create-env-BPsNJfxy.d.cts +285 -0
- package/dist/create-env-BPsNJfxy.d.cts.map +1 -0
- package/dist/create-env-CFw1N3G1.d.ts +285 -0
- package/dist/create-env-CFw1N3G1.d.ts.map +1 -0
- package/dist/errors-DM9X9ICI.cjs +5 -0
- package/dist/errors-D_Q1KGgZ.js +6 -0
- package/dist/errors-D_Q1KGgZ.js.map +1 -0
- package/dist/index.cjs +1 -4
- package/dist/index.d.cts +29 -246
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +29 -246
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +24 -12
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import * as arktype0 from "arktype";
|
|
2
|
+
import { Type, distill, type } from "arktype";
|
|
3
|
+
import * as arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
|
|
4
|
+
import * as arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
5
|
+
|
|
6
|
+
//#region ../internal/types/dist/helpers.d.ts
|
|
7
|
+
type Dict<T> = Record<string, T | undefined>;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region ../internal/types/dist/standard-schema.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
12
|
+
*
|
|
13
|
+
* Copied from standard-schema (MIT License)
|
|
14
|
+
* Copyright (c) 2024 Colin McDannell
|
|
15
|
+
*/
|
|
16
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
17
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
18
|
+
/** The Standard properties. */
|
|
19
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
20
|
+
}
|
|
21
|
+
declare namespace StandardTypedV1 {
|
|
22
|
+
/** The Standard Typed properties interface. */
|
|
23
|
+
interface Props<Input = unknown, Output = Input> {
|
|
24
|
+
/** The version number of the standard. */
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/** The vendor name of the schema library. */
|
|
27
|
+
readonly vendor: string;
|
|
28
|
+
/** Inferred types associated with the schema. */
|
|
29
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
30
|
+
}
|
|
31
|
+
/** The Standard Typed types interface. */
|
|
32
|
+
interface Types<Input = unknown, Output = Input> {
|
|
33
|
+
/** The input type of the schema. */
|
|
34
|
+
readonly input: Input;
|
|
35
|
+
/** The output type of the schema. */
|
|
36
|
+
readonly output: Output;
|
|
37
|
+
}
|
|
38
|
+
/** Infers the input type of a Standard Typed. */
|
|
39
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
40
|
+
/** Infers the output type of a Standard Typed. */
|
|
41
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
42
|
+
}
|
|
43
|
+
/** The Standard Schema interface. */
|
|
44
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
45
|
+
/** The Standard Schema properties. */
|
|
46
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
47
|
+
}
|
|
48
|
+
declare namespace StandardSchemaV1 {
|
|
49
|
+
/** The Standard Schema properties interface. */
|
|
50
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
51
|
+
/** Validates unknown input values. */
|
|
52
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
53
|
+
}
|
|
54
|
+
/** The result interface of the validate function. */
|
|
55
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
56
|
+
/** The result interface if validation succeeds. */
|
|
57
|
+
interface SuccessResult<Output> {
|
|
58
|
+
/** The typed output value. */
|
|
59
|
+
readonly value: Output;
|
|
60
|
+
/** A falsy value for `issues` indicates success. */
|
|
61
|
+
readonly issues?: undefined;
|
|
62
|
+
}
|
|
63
|
+
interface Options {
|
|
64
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
65
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
66
|
+
}
|
|
67
|
+
/** The result interface if validation fails. */
|
|
68
|
+
interface FailureResult {
|
|
69
|
+
/** The issues of failed validation. */
|
|
70
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
71
|
+
}
|
|
72
|
+
/** The issue interface of the failure output. */
|
|
73
|
+
interface Issue {
|
|
74
|
+
/** The error message of the issue. */
|
|
75
|
+
readonly message: string;
|
|
76
|
+
/** The path of the issue, if any. */
|
|
77
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
78
|
+
}
|
|
79
|
+
/** The path segment interface of the issue. */
|
|
80
|
+
interface PathSegment {
|
|
81
|
+
/** The key representing a path segment. */
|
|
82
|
+
readonly key: PropertyKey;
|
|
83
|
+
}
|
|
84
|
+
/** The Standard types interface. */
|
|
85
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
86
|
+
/** Infers the input type of a Standard. */
|
|
87
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
88
|
+
/** Infers the output type of a Standard. */
|
|
89
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region ../internal/types/dist/infer-type.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Extract the inferred type from a schema definition.
|
|
95
|
+
* Supports both ArkType type definitions and Standard Schema 1.0 validators.
|
|
96
|
+
*
|
|
97
|
+
* For Standard Schema validators (e.g., Zod, Valibot), extracts the output type.
|
|
98
|
+
* For ArkType definitions, checks the call signature or type properties.
|
|
99
|
+
*
|
|
100
|
+
* @template T - The schema definition to infer from
|
|
101
|
+
*/
|
|
102
|
+
type InferType<T> = T extends StandardSchemaV1<infer _Input, infer Output> ? Output : T extends ((value: Record<string, string | undefined>) => infer R) ? R extends type.errors ? never : R : T extends {
|
|
103
|
+
t: infer U;
|
|
104
|
+
} ? U : T extends type.Any<infer U, infer _Scope> ? U : never;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region ../internal/scope/dist/index.d.ts
|
|
107
|
+
//#region src/root.d.ts
|
|
108
|
+
/**
|
|
109
|
+
* The root scope for the ArkEnv library,
|
|
110
|
+
* containing extensions to the ArkType scopes with ArkEnv-specific types
|
|
111
|
+
* like `string.host` and `number.port`.
|
|
112
|
+
*/
|
|
113
|
+
declare const $: arktype0.Scope<{
|
|
114
|
+
string: arktype0.Submodule<{
|
|
115
|
+
trim: arktype0.Submodule<arktype_internal_keywords_string_ts0.trim.$ & {
|
|
116
|
+
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
117
|
+
}>;
|
|
118
|
+
normalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.normalize.$ & {
|
|
119
|
+
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
120
|
+
}>;
|
|
121
|
+
root: string;
|
|
122
|
+
alpha: string;
|
|
123
|
+
alphanumeric: string;
|
|
124
|
+
hex: string;
|
|
125
|
+
base64: arktype0.Submodule<{
|
|
126
|
+
root: string;
|
|
127
|
+
url: string;
|
|
128
|
+
} & {
|
|
129
|
+
" arkInferred": string;
|
|
130
|
+
}>;
|
|
131
|
+
capitalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.capitalize.$ & {
|
|
132
|
+
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
133
|
+
}>;
|
|
134
|
+
creditCard: string;
|
|
135
|
+
date: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringDate.$ & {
|
|
136
|
+
" arkInferred": string;
|
|
137
|
+
}>;
|
|
138
|
+
digits: string;
|
|
139
|
+
email: string;
|
|
140
|
+
integer: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringInteger.$ & {
|
|
141
|
+
" arkInferred": string;
|
|
142
|
+
}>;
|
|
143
|
+
ip: arktype0.Submodule<arktype_internal_keywords_string_ts0.ip.$ & {
|
|
144
|
+
" arkInferred": string;
|
|
145
|
+
}>;
|
|
146
|
+
json: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringJson.$ & {
|
|
147
|
+
" arkInferred": string;
|
|
148
|
+
}>;
|
|
149
|
+
lower: arktype0.Submodule<arktype_internal_keywords_string_ts0.lower.$ & {
|
|
150
|
+
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
151
|
+
}>;
|
|
152
|
+
numeric: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringNumeric.$ & {
|
|
153
|
+
" arkInferred": string;
|
|
154
|
+
}>;
|
|
155
|
+
regex: string;
|
|
156
|
+
semver: string;
|
|
157
|
+
upper: arktype0.Submodule<{
|
|
158
|
+
root: (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
159
|
+
preformatted: string;
|
|
160
|
+
} & {
|
|
161
|
+
" arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
|
|
162
|
+
}>;
|
|
163
|
+
url: arktype0.Submodule<arktype_internal_keywords_string_ts0.url.$ & {
|
|
164
|
+
" arkInferred": string;
|
|
165
|
+
}>;
|
|
166
|
+
uuid: arktype0.Submodule<arktype_internal_keywords_string_ts0.uuid.$ & {
|
|
167
|
+
" arkInferred": string;
|
|
168
|
+
}>;
|
|
169
|
+
" arkInferred": string;
|
|
170
|
+
host: string;
|
|
171
|
+
}>;
|
|
172
|
+
number: arktype0.Submodule<{
|
|
173
|
+
NaN: number;
|
|
174
|
+
Infinity: number;
|
|
175
|
+
root: number;
|
|
176
|
+
integer: number;
|
|
177
|
+
" arkInferred": number;
|
|
178
|
+
epoch: number;
|
|
179
|
+
safe: number;
|
|
180
|
+
NegativeInfinity: number;
|
|
181
|
+
port: number;
|
|
182
|
+
}>;
|
|
183
|
+
}>;
|
|
184
|
+
type $ = (typeof $)["t"];
|
|
185
|
+
//#endregion
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ../internal/types/dist/schema.d.ts
|
|
188
|
+
type SchemaShape = Record<string, unknown>;
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*
|
|
192
|
+
* Compiled ArkType schema accepted by ArkEnv.
|
|
193
|
+
* Produced by `arktype.type(...)` or `scope(...)`.
|
|
194
|
+
*
|
|
195
|
+
* Represents an already-constructed ArkType `Type` instance that
|
|
196
|
+
* defines the full environment schema.
|
|
197
|
+
*
|
|
198
|
+
* This form bypasses schema validation and is intended for advanced
|
|
199
|
+
* or programmatic use cases where schemas are constructed dynamically.
|
|
200
|
+
*/
|
|
201
|
+
type CompiledEnvSchema = Type<SchemaShape, $>;
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/create-env.d.ts
|
|
204
|
+
/**
|
|
205
|
+
* Declarative environment schema definition accepted by ArkEnv.
|
|
206
|
+
*
|
|
207
|
+
* Represents a declarative schema object mapping environment
|
|
208
|
+
* variable names to schema definitions (e.g. ArkType DSL strings
|
|
209
|
+
* or Standard Schema validators).
|
|
210
|
+
*
|
|
211
|
+
* This type is used to validate that a schema object is compatible with
|
|
212
|
+
* ArkEnv’s validator scope before being compiled or parsed.
|
|
213
|
+
*
|
|
214
|
+
* Most users will provide schemas in this form.
|
|
215
|
+
*
|
|
216
|
+
* @template def - The schema shape object
|
|
217
|
+
*/
|
|
218
|
+
type EnvSchema<def> = type.validate<def, $>;
|
|
219
|
+
type RuntimeEnvironment = Dict<string>;
|
|
220
|
+
/**
|
|
221
|
+
* Configuration options for `createEnv`
|
|
222
|
+
*/
|
|
223
|
+
type ArkEnvConfig = {
|
|
224
|
+
/**
|
|
225
|
+
* The environment variables to parse. Defaults to `process.env`
|
|
226
|
+
*/
|
|
227
|
+
env?: RuntimeEnvironment;
|
|
228
|
+
/**
|
|
229
|
+
* Whether to coerce environment variables to their defined types. Defaults to `true`
|
|
230
|
+
*/
|
|
231
|
+
coerce?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
234
|
+
*
|
|
235
|
+
* Defaults to `'delete'` to ensure your output object only contains
|
|
236
|
+
* keys you've explicitly declared. This differs from ArkType's standard behavior, which
|
|
237
|
+
* mirrors TypeScript by defaulting to `'ignore'`.
|
|
238
|
+
*
|
|
239
|
+
* - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
|
|
240
|
+
* - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
|
|
241
|
+
* - `reject`: Undeclared keys will cause validation to fail.
|
|
242
|
+
*
|
|
243
|
+
* @default "delete"
|
|
244
|
+
* @see https://arktype.io/docs/configuration#onundeclaredkey
|
|
245
|
+
*/
|
|
246
|
+
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
247
|
+
/**
|
|
248
|
+
* The format to use for array parsing when coercion is enabled.
|
|
249
|
+
*
|
|
250
|
+
* - `comma` (default): Strings are split by comma and trimmed.
|
|
251
|
+
* - `json`: Strings are parsed as JSON.
|
|
252
|
+
*
|
|
253
|
+
* @default "comma"
|
|
254
|
+
*/
|
|
255
|
+
arrayFormat?: "comma" | "json";
|
|
256
|
+
/**
|
|
257
|
+
* Choose the validator engine to use.
|
|
258
|
+
*
|
|
259
|
+
* - `arktype` (default): Uses ArkType for all validation and coercion.
|
|
260
|
+
* - `standard`: Uses Standard Schema 1.0 directly for validation. Coercion is not supported in this mode.
|
|
261
|
+
*
|
|
262
|
+
* @default "arktype"
|
|
263
|
+
*/
|
|
264
|
+
validator?: "arktype" | "standard";
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* TODO: `SchemaShape` is basically `Record<string, unknown>`.
|
|
268
|
+
* If possible, find a better type than "const T extends Record<string, unknown>",
|
|
269
|
+
* and be as close as possible to the type accepted by ArkType's `type`.
|
|
270
|
+
*/
|
|
271
|
+
/**
|
|
272
|
+
* Utility to parse environment variables using ArkType or Standard Schema
|
|
273
|
+
* @param def - The schema definition
|
|
274
|
+
* @param config - The evaluation configuration
|
|
275
|
+
* @returns The parsed environment variables
|
|
276
|
+
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
277
|
+
*/
|
|
278
|
+
declare function createEnv<const T extends Record<string, StandardSchemaV1>>(def: T, config: ArkEnvConfig & {
|
|
279
|
+
validator: "standard";
|
|
280
|
+
}): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
|
|
281
|
+
declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type.infer<T, $>>;
|
|
282
|
+
declare function createEnv<T extends CompiledEnvSchema>(def: T, config?: ArkEnvConfig): InferType<T>;
|
|
283
|
+
//#endregion
|
|
284
|
+
export { SchemaShape as i, EnvSchema as n, createEnv as r, ArkEnvConfig as t };
|
|
285
|
+
//# sourceMappingURL=create-env-CFw1N3G1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-env-CFw1N3G1.d.ts","names":["Dict","T","Record","StandardTypedV1","Input","Output","Props","Schema","Types","NonNullable","StandardSchemaV1","Options","Result","Promise","SuccessResult","FailureResult","Record","Issue","ReadonlyArray","PropertyKey","PathSegment","InferInput","InferOutput","StandardJSONSchemaV1","Converter","Target","type","StandardSchemaV1","InferType","T","Record","errors","Any","arktype0","arktype_internal_keywords_string_ts0","arktype_internal_attributes_ts0","$","trim","To","Submodule","normalize","capitalize","stringDate","stringInteger","ip","stringJson","lower","stringNumeric","url","uuid","Scope","$","Type","SchemaShape","Record","CompiledEnvSchema"],"sources":["../../internal/types/dist/helpers.d.ts","../../internal/types/dist/standard-schema.d.ts","../../internal/types/dist/infer-type.d.ts","../../internal/scope/dist/index.d.ts","../../internal/types/dist/schema.d.ts","../src/create-env.ts"],"sourcesContent":["export type Dict<T> = Record<string, T | undefined>;\n//# sourceMappingURL=helpers.d.ts.map","/**\n * @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec\n *\n * Copied from standard-schema (MIT License)\n * Copyright (c) 2024 Colin McDannell\n */\n/** The Standard Typed interface. This is a base type extended by other specs. */\nexport interface StandardTypedV1<Input = unknown, Output = Input> {\n /** The Standard properties. */\n readonly \"~standard\": StandardTypedV1.Props<Input, Output>;\n}\nexport declare namespace StandardTypedV1 {\n /** The Standard Typed properties interface. */\n interface Props<Input = unknown, Output = Input> {\n /** The version number of the standard. */\n readonly version: 1;\n /** The vendor name of the schema library. */\n readonly vendor: string;\n /** Inferred types associated with the schema. */\n readonly types?: Types<Input, Output> | undefined;\n }\n /** The Standard Typed types interface. */\n interface Types<Input = unknown, Output = Input> {\n /** The input type of the schema. */\n readonly input: Input;\n /** The output type of the schema. */\n readonly output: Output;\n }\n /** Infers the input type of a Standard Typed. */\n type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema[\"~standard\"][\"types\"]>[\"input\"];\n /** Infers the output type of a Standard Typed. */\n type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema[\"~standard\"][\"types\"]>[\"output\"];\n}\n/** The Standard Schema interface. */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n /** The Standard Schema properties. */\n readonly \"~standard\": StandardSchemaV1.Props<Input, Output>;\n}\nexport declare namespace StandardSchemaV1 {\n /** The Standard Schema properties interface. */\n interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {\n /** Validates unknown input values. */\n readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;\n }\n /** The result interface of the validate function. */\n type Result<Output> = SuccessResult<Output> | FailureResult;\n /** The result interface if validation succeeds. */\n interface SuccessResult<Output> {\n /** The typed output value. */\n readonly value: Output;\n /** A falsy value for `issues` indicates success. */\n readonly issues?: undefined;\n }\n interface Options {\n /** Explicit support for additional vendor-specific parameters, if needed. */\n readonly libraryOptions?: Record<string, unknown> | undefined;\n }\n /** The result interface if validation fails. */\n interface FailureResult {\n /** The issues of failed validation. */\n readonly issues: ReadonlyArray<Issue>;\n }\n /** The issue interface of the failure output. */\n interface Issue {\n /** The error message of the issue. */\n readonly message: string;\n /** The path of the issue, if any. */\n readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;\n }\n /** The path segment interface of the issue. */\n interface PathSegment {\n /** The key representing a path segment. */\n readonly key: PropertyKey;\n }\n /** The Standard types interface. */\n interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {\n }\n /** Infers the input type of a Standard. */\n type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;\n /** Infers the output type of a Standard. */\n type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;\n}\n/** The Standard JSON Schema interface. */\nexport interface StandardJSONSchemaV1<Input = unknown, Output = Input> {\n /** The Standard JSON Schema properties. */\n readonly \"~standard\": StandardJSONSchemaV1.Props<Input, Output>;\n}\nexport declare namespace StandardJSONSchemaV1 {\n /** The Standard JSON Schema properties interface. */\n interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {\n /** Methods for generating the input/output JSON Schema. */\n readonly jsonSchema: StandardJSONSchemaV1.Converter;\n }\n /** The Standard JSON Schema converter interface. */\n interface Converter {\n /** Converts the input type to JSON Schema. May throw if conversion is not supported. */\n readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;\n /** Converts the output type to JSON Schema. May throw if conversion is not supported. */\n readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;\n }\n /**\n * The target version of the generated JSON Schema.\n *\n * It is *strongly recommended* that implementers support `\"draft-2020-12\"` and `\"draft-07\"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.\n *\n * The `\"openapi-3.0\"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `\"draft-04\"`.\n */\n type Target = \"draft-2020-12\" | \"draft-07\" | \"openapi-3.0\" | ({} & string);\n /** The options for the input/output methods. */\n interface Options {\n /** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */\n readonly target: Target;\n /** Explicit support for additional vendor-specific parameters, if needed. */\n readonly libraryOptions?: Record<string, unknown> | undefined;\n }\n /** The Standard types interface. */\n interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {\n }\n /** Infers the input type of a Standard. */\n type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;\n /** Infers the output type of a Standard. */\n type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;\n}\n//# sourceMappingURL=standard-schema.d.ts.map","import type { type } from \"arktype\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\n/**\n * Extract the inferred type from a schema definition.\n * Supports both ArkType type definitions and Standard Schema 1.0 validators.\n *\n * For Standard Schema validators (e.g., Zod, Valibot), extracts the output type.\n * For ArkType definitions, checks the call signature or type properties.\n *\n * @template T - The schema definition to infer from\n */\nexport type InferType<T> = T extends StandardSchemaV1<infer _Input, infer Output> ? Output : T extends (value: Record<string, string | undefined>) => infer R ? R extends type.errors ? never : R : T extends {\n t: infer U;\n} ? U : T extends type.Any<infer U, infer _Scope> ? U : never;\n//# sourceMappingURL=infer-type.d.ts.map","import * as arktype0 from \"arktype\";\nimport * as arktype_internal_keywords_string_ts0 from \"arktype/internal/keywords/string.ts\";\nimport * as arktype_internal_attributes_ts0 from \"arktype/internal/attributes.ts\";\n\n//#region src/root.d.ts\n/**\n * The root scope for the ArkEnv library,\n * containing extensions to the ArkType scopes with ArkEnv-specific types\n * like `string.host` and `number.port`.\n */\ndeclare const $: arktype0.Scope<{\n string: arktype0.Submodule<{\n trim: arktype0.Submodule<arktype_internal_keywords_string_ts0.trim.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n normalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.normalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n root: string;\n alpha: string;\n alphanumeric: string;\n hex: string;\n base64: arktype0.Submodule<{\n root: string;\n url: string;\n } & {\n \" arkInferred\": string;\n }>;\n capitalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.capitalize.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n creditCard: string;\n date: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringDate.$ & {\n \" arkInferred\": string;\n }>;\n digits: string;\n email: string;\n integer: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringInteger.$ & {\n \" arkInferred\": string;\n }>;\n ip: arktype0.Submodule<arktype_internal_keywords_string_ts0.ip.$ & {\n \" arkInferred\": string;\n }>;\n json: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringJson.$ & {\n \" arkInferred\": string;\n }>;\n lower: arktype0.Submodule<arktype_internal_keywords_string_ts0.lower.$ & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n numeric: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringNumeric.$ & {\n \" arkInferred\": string;\n }>;\n regex: string;\n semver: string;\n upper: arktype0.Submodule<{\n root: (In: string) => arktype_internal_attributes_ts0.To<string>;\n preformatted: string;\n } & {\n \" arkInferred\": (In: string) => arktype_internal_attributes_ts0.To<string>;\n }>;\n url: arktype0.Submodule<arktype_internal_keywords_string_ts0.url.$ & {\n \" arkInferred\": string;\n }>;\n uuid: arktype0.Submodule<arktype_internal_keywords_string_ts0.uuid.$ & {\n \" arkInferred\": string;\n }>;\n \" arkInferred\": string;\n host: string;\n }>;\n number: arktype0.Submodule<{\n NaN: number;\n Infinity: number;\n root: number;\n integer: number;\n \" arkInferred\": number;\n epoch: number;\n safe: number;\n NegativeInfinity: number;\n port: number;\n }>;\n}>;\ntype $ = (typeof $)[\"t\"];\n//#endregion\nexport { $ };\n//# sourceMappingURL=index.d.ts.map","import type { $ } from \"@repo/scope\";\nimport type { Type } from \"arktype\";\nexport type SchemaShape = Record<string, unknown>;\n/**\n * @internal\n *\n * Compiled ArkType schema accepted by ArkEnv.\n * Produced by `arktype.type(...)` or `scope(...)`.\n *\n * Represents an already-constructed ArkType `Type` instance that\n * defines the full environment schema.\n *\n * This form bypasses schema validation and is intended for advanced\n * or programmatic use cases where schemas are constructed dynamically.\n */\nexport type CompiledEnvSchema = Type<SchemaShape, $>;\n//# sourceMappingURL=schema.d.ts.map"],"mappings":";;;;;;KAAYA,UAAUE,eAAeD;;;;;;;;;AAArC;UCOiBE,0CAA0CC;;wBAEjCD,eAAAA,CAAgBG,MAAMF,OAAOC;AAFvD;AAA2DD,kBAIlCD,eAAAA,CAJkCC;EAEXA;EAAOC,UAAAA,KAAAA,CAAAA,QAAAA,OAAAA,EAAAA,SAITD,KAJSC,CAAAA,CAAAA;IAA7BF;IAAqB,SAAA,OAAA,EAAA,CAAA;IAEtBA;IAEqBC,SAAAA,MAAAA,EAAAA,MAAAA;IAMfA;IAAOC,SAAAA,KAAAA,CAAAA,EAAbG,KAAaH,CAAPD,KAAOC,EAAAA,MAAAA,CAAAA,GAAAA,SAAAA;EAAbG;EAGqBJ;EAEtBA,UAAAA,KAAAA,CAAAA,QAAAA,OAAAA,EAAAA,SAFsBA,KAEtBA,CAAAA,CAAAA;IAECC;IAGUF,SAAAA,KAAAA,EALXC,KAKWD;IAA+BI;IAAZE,SAAAA,MAAAA,EAH7BJ,MAG6BI;EAElBN;EAA+BI;EAAZE,KAAAA,UAAAA,CAAAA,eAFpB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AAA,CAAA;iBGsFV,oBAAoB,wBAC9B,YACI,eACP,UAAU"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const e=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
|
|
2
|
+
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
+
`),t={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},n=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,r=()=>!!(!n()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),i=(e,i)=>n()&&!r()?`${t[e]}${i}${t.reset}`:i,a=e=>typeof e==`object`&&!!e&&`byPath`in e,o=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message,r=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=RegExp(`^\\s*[:.-]?\\s*${r}\\s*[:.-]?\\s*`,`i`);n=a.test(n)?n.replace(a,t=>`${i(`yellow`,e)}${t.toLowerCase().replace(e.toLowerCase(),``)}`):`${i(`yellow`,e)} ${n}`;let o=n.match(/\(was (.*)\)/);if(o?.[1]){let e=o[1];if(!e.includes(`\x1B[`)){let t=i(`cyan`,e);n=n.replace(`(was ${e})`,`(was ${t})`)}}return n}).join(`
|
|
4
|
+
`),s=e=>e.map(e=>`${i(`yellow`,e.path)} ${e.message.trimStart()}`).join(`
|
|
5
|
+
`);var c=class extends Error{constructor(t,n=`Errors found while validating environment variables`){let r=a(t)?o(t):s(t);super(`${i(`red`,n)}\n${e(r)}\n`),this.name=`ArkEnvError`}};Object.defineProperty(c,`name`,{value:`ArkEnvError`}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const e=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
|
|
2
|
+
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
+
`),t={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},n=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,r=()=>!!(!n()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),i=(e,i)=>n()&&!r()?`${t[e]}${i}${t.reset}`:i,a=e=>typeof e==`object`&&!!e&&`byPath`in e,o=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message,r=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=RegExp(`^\\s*[:.-]?\\s*${r}\\s*[:.-]?\\s*`,`i`);n=a.test(n)?n.replace(a,t=>`${i(`yellow`,e)}${t.toLowerCase().replace(e.toLowerCase(),``)}`):`${i(`yellow`,e)} ${n}`;let o=n.match(/\(was (.*)\)/);if(o?.[1]){let e=o[1];if(!e.includes(`\x1B[`)){let t=i(`cyan`,e);n=n.replace(`(was ${e})`,`(was ${t})`)}}return n}).join(`
|
|
4
|
+
`),s=e=>e.map(e=>`${i(`yellow`,e.path)} ${e.message.trimStart()}`).join(`
|
|
5
|
+
`);var c=class extends Error{constructor(t,n=`Errors found while validating environment variables`){let r=a(t)?o(t):s(t);super(`${i(`red`,n)}\n${e(r)}\n`),this.name=`ArkEnvError`}};Object.defineProperty(c,`name`,{value:`ArkEnvError`});export{c as t};
|
|
6
|
+
//# sourceMappingURL=errors-D_Q1KGgZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-D_Q1KGgZ.js","names":[],"sources":["../src/utils/indent.ts","../src/utils/style-text.ts","../src/errors.ts"],"sourcesContent":["/**\n * Options for the `indent` function\n */\ntype IndentOptions = {\n\t/**\n\t * Whether to detect newlines and indent each line individually, defaults to false (indenting the whole string)\n\t */\n\tdontDetectNewlines?: boolean;\n};\n\n/**\n * Indent a string by a given amount\n * @param str - The string to indent\n * @param amt - The amount to indent by, defaults to 2\n * @param options - {@link IndentOptions}\n * @returns The indented string\n */\nexport const indent = (\n\tstr: string,\n\tamt = 2,\n\t{ dontDetectNewlines = false }: IndentOptions = {},\n) => {\n\tconst detectNewlines = !dontDetectNewlines;\n\tif (detectNewlines) {\n\t\treturn str\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => `${\" \".repeat(amt)}${line}`)\n\t\t\t.join(\"\\n\");\n\t}\n\n\treturn `${\" \".repeat(amt)}${str}`;\n};\n","/**\n * Cross-platform text styling utility\n * Uses ANSI colors in Node environments, plain text in browsers\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\n\n// ANSI color codes for Node environments\nconst colors = {\n\tred: \"\\x1b[31m\",\n\tyellow: \"\\x1b[33m\",\n\tcyan: \"\\x1b[36m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\n/**\n * Check if we're in a Node environment (not browser)\n * Checked dynamically to allow for testing with mocked globals\n */\nconst isNode = (): boolean =>\n\ttypeof process !== \"undefined\" &&\n\tprocess.versions != null &&\n\tprocess.versions.node != null;\n\n/**\n * Check if colors should be disabled based on environment\n * Respects NO_COLOR, CI environment variables, and TTY detection\n */\nconst shouldDisableColors = (): boolean => {\n\tif (!isNode()) return true;\n\n\t// Respect NO_COLOR environment variable (https://no-color.org/)\n\tif (process.env.NO_COLOR !== undefined) return true;\n\n\t// Disable colors in CI environments by default\n\tif (process.env.CI !== undefined) return true;\n\n\t// Disable colors if not writing to a TTY\n\tif (process.stdout && !process.stdout.isTTY) return true;\n\n\treturn false;\n};\n\n/**\n * Style text with color. Uses ANSI codes in Node, plain text in browsers.\n * @param color - The color to apply\n * @param text - The text to style\n * @returns Styled text in Node (if colors enabled), plain text otherwise\n */\nexport const styleText = (\n\tcolor: \"red\" | \"yellow\" | \"cyan\",\n\ttext: string,\n): string => {\n\t// Use ANSI colors only in Node environments with colors enabled\n\tif (isNode() && !shouldDisableColors()) {\n\t\treturn `${colors[color]}${text}${colors.reset}`;\n\t}\n\t// Fall back to plain text in browsers or when colors are disabled\n\treturn text;\n};\n","import type { ArkErrors } from \"arktype\";\nimport { indent } from \"./utils/indent.ts\";\nimport { styleText } from \"./utils/style-text.ts\";\n\nexport type InternalValidationError = {\n\tpath: string;\n\tmessage: string;\n};\n\n/**\n * Check if the provided object is ArkType errors\n */\nconst isArkErrors = (errors: unknown): errors is ArkErrors => {\n\treturn (\n\t\terrors !== null &&\n\t\ttypeof errors === \"object\" &&\n\t\t\"byPath\" in (errors as Record<string, unknown>)\n\t);\n};\n\n/**\n * Format the errors returned by ArkType to be more readable\n * @param errors - The errors returned by ArkType\n * @returns A string of the formatted errors\n */\nexport const formatArkErrors = (errors: ArkErrors): string => {\n\treturn Object.entries(errors.byPath)\n\t\t.map(([path, error]) => {\n\t\t\tlet message = error.message;\n\n\t\t\tconst escapedPath = path.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\t\t\tconst pathRegex = new RegExp(\n\t\t\t\t`^\\\\s*[:.-]?\\\\s*${escapedPath}\\\\s*[:.-]?\\\\s*`,\n\t\t\t\t\"i\",\n\t\t\t);\n\n\t\t\tif (pathRegex.test(message)) {\n\t\t\t\t// Style the existing path prefix\n\t\t\t\tmessage = message.replace(pathRegex, (match) => {\n\t\t\t\t\treturn `${styleText(\"yellow\", path)}${match.toLowerCase().replace(path.toLowerCase(), \"\")}`;\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// Prepend styled path\n\t\t\t\tmessage = `${styleText(\"yellow\", path)} ${message}`;\n\t\t\t}\n\n\t\t\t// Style (was ...)\n\t\t\tconst valueMatch = message.match(/\\(was (.*)\\)/);\n\t\t\tif (valueMatch?.[1]) {\n\t\t\t\tconst value = valueMatch[1];\n\t\t\t\tif (!value.includes(\"\\x1b[\")) {\n\t\t\t\t\tconst styledValue = styleText(\"cyan\", value);\n\t\t\t\t\tmessage = message.replace(`(was ${value})`, `(was ${styledValue})`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn message;\n\t\t})\n\t\t.join(\"\\n\");\n};\n\nexport const formatInternalErrors = (\n\terrors: InternalValidationError[],\n): string =>\n\terrors\n\t\t.map(\n\t\t\t(error) =>\n\t\t\t\t`${styleText(\"yellow\", error.path)} ${error.message.trimStart()}`,\n\t\t)\n\t\t.join(\"\\n\");\n\n/**\n * Error thrown when environment variable validation fails.\n *\n * This error extends the native `Error` class and provides formatted error messages\n * that clearly indicate which environment variables are invalid and why.\n *\n * @example\n * ```ts\n * import { createEnv, ArkEnvError } from 'arkenv';\n *\n * try {\n * const env = createEnv({\n * PORT: 'number.port',\n * HOST: 'string.host',\n * });\n * } catch (error) {\n * if (error instanceof ArkEnvError) {\n * console.error('Environment validation failed:', error.message);\n * }\n * }\n * ```\n */\nexport class ArkEnvError extends Error {\n\tconstructor(\n\t\terrors: ArkErrors | InternalValidationError[],\n\t\tmessage = \"Errors found while validating environment variables\",\n\t) {\n\t\t// ArkType errors subclass Array, so we must check for ArkErrors specifically first\n\t\tconst formattedErrors = isArkErrors(errors)\n\t\t\t? formatArkErrors(errors)\n\t\t\t: formatInternalErrors(errors as InternalValidationError[]);\n\n\t\tsuper(`${styleText(\"red\", message)}\\n${indent(formattedErrors)}\\n`);\n\t\tthis.name = \"ArkEnvError\";\n\t}\n}\n\nObject.defineProperty(ArkEnvError, \"name\", { value: \"ArkEnvError\" });\n"],"mappings":"AAiBA,MAAa,GACZ,EACA,EAAM,EACN,CAAE,qBAAqB,IAAyB,EAAE,GAE1B,EAQjB,GAAG,IAAI,OAAO,EAAI,GAAG,IANpB,EACL,MAAM;EAAK,CACX,IAAK,GAAS,GAAG,IAAI,OAAO,EAAI,GAAG,IAAO,CAC1C,KAAK;EAAK,CCpBR,EAAS,CACd,IAAK,WACL,OAAQ,WACR,KAAM,WACN,MAAO,UACP,CAMK,MACL,OAAO,QAAY,KACnB,QAAQ,UAAY,MACpB,QAAQ,SAAS,MAAQ,KAMpB,MAUL,GATI,CAAC,GAAQ,EAGT,QAAQ,IAAI,WAAa,IAAA,IAGzB,QAAQ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CAAE,MAAO,cAAe,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,`__esModule`,{value:!0});
|
|
2
|
-
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
-
`),f={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},p=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,m=()=>!!(!p()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),h=(e,t)=>p()&&!m()?`${f[e]}${t}${f.reset}`:t,g=e=>Object.entries(e.byPath).map(([e,t])=>{let n=t.message.startsWith(e)?t.message.slice(e.length):t.message,r=n.match(/\(was "([^"]+)"\)/),i=r?n.replace(`(was "${r[1]}")`,`(was ${h(`cyan`,`"${r[1]}"`)})`):n;return`${h(`yellow`,e)} ${i.trimStart()}`}).join(`
|
|
4
|
-
`);var _=class extends Error{constructor(e,t=`Errors found while validating environment variables`){super(`${h(`red`,t)}\n${d(g(e))}\n`),this.name=`ArkEnvError`}};Object.defineProperty(_,`name`,{value:`ArkEnvError`});const v=o.type;function y(e,{env:t=process.env,coerce:n=!0,onUndeclaredKey:r=`delete`,arrayFormat:i=`comma`}={}){let a=typeof e==`function`&&`assert`in e?e:o.type.raw(e);a=a.onUndeclaredKey(r),n&&(a=u(a,{arrayFormat:i}));let s=a(t);if(s instanceof v.errors)throw new _(s);return s}const b=y;var x=b;exports.ArkEnvError=_,exports.createEnv=y,exports.default=x,exports.type=v;
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./errors-DM9X9ICI.cjs`);let t=require(`node:module`);function n(t,n){let{env:r=process.env,onUndeclaredKey:i=`delete`}=n,a={},o=[],s=new Set(Object.keys(r));for(let e in t){let n=t[e],i=r[e];if(!n||typeof n!=`object`||!(`~standard`in n))throw Error(`Invalid schema for key "${e}": expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in "standard" mode.`);let c=n[`~standard`].validate(i);if(c instanceof Promise)throw Error(`Async validation is not supported for key "${e}". ArkEnv is synchronous.`);if(c.issues)for(let t of c.issues)o.push({path:e,message:t.message});else a[e]=c.value;s.delete(e)}if(i!==`delete`)for(let e of s)i===`reject`?o.push({path:e,message:`Undeclared key`}):i===`ignore`&&(a[e]=r[e]);if(o.length>0)throw new e.t(o);return a}function r(){let e=(0,t.createRequire)(require(`url`).pathToFileURL(__filename).href),n=[`./arktype.cjs`,`../arktype.cjs`,`./arktype/index.cjs`,`../arktype/index.cjs`,`./arktype`,`../arktype`,`./arktype/index.ts`,`../arktype/index.ts`],r;for(let t of n)try{return e(t)}catch(e){if(r=e,e.code===`MODULE_NOT_FOUND`){let n=e.message||``;if((n.includes(`'arktype'`)||n.includes(`"arktype"`)||n.includes(`Cannot find module 'arktype'`))&&!n.includes(t))break}}let i=r?.message||``;throw r?.code===`MODULE_NOT_FOUND`&&(i.includes(`'arktype'`)||i.includes(`"arktype"`)||i.includes(`Cannot find module 'arktype'`))&&!i.includes(`./arktype`)&&!i.includes(`../arktype`)?Error(`The 'arktype' package is required when using the default validator mode. Please install it (npm install arktype) or set 'validator: "standard"' in your config if you only intend to use Standard Schema validators (like Zod or Valibot).`):r}function i(t,i={}){if((i.validator??`arktype`)===`standard`){if(!t||typeof t!=`object`||Array.isArray(t))throw new e.t([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}]);for(let n in t){let r=t[n];if(typeof r==`string`)throw new e.t([{path:n,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or set validator: "arktype".`}]);if(!r||typeof r!=`object`||!(`~standard`in r))throw new e.t([{path:n,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). ArkType validators are not supported in "standard" mode. Use validator: "arktype" for ArkType schemas.`}])}return n(t,i)}let{parse:a}=r();return a(t,i)}const a=i;var o=a;exports.ArkEnvError=e.t,exports.createEnv=i,exports.default=o;
|