@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.
@@ -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 };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./src-BZoXXFsx.cjs`);exports.ArkEnvError=e.n,exports.arkenv=e.t,exports.default=e.t,exports.formatIssues=e.r,exports.getSchemaKeys=e.i;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./src-DTEO2b2p.cjs`);exports.ArkEnvError=e.n,exports.arkenv=e.t,exports.default=e.t,exports.formatIssues=e.r,exports.getSchemaKeys=e.i;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-Dn1RAoiV.cjs";
1
+ import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-DdPEn3aK.cjs";
2
2
  export { ArkEnvError, EnvIssue, SafeArkEnvResult, StandardEnvConfig, arkenv, arkenv as default, formatIssues, getSchemaKeys };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-DLnvC3Za.js";
1
+ import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-ByAIZ0F1.js";
2
2
  export { ArkEnvError, EnvIssue, SafeArkEnvResult, StandardEnvConfig, arkenv, arkenv as default, formatIssues, getSchemaKeys };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{i as e,n as t,r as n,t as r}from"./src-BxruqAr0.js";export{t as ArkEnvError,r as arkenv,r as default,n as formatIssues,e as getSchemaKeys};
1
+ import{i as e,n as t,r as n,t as r}from"./src-CJWeQijZ.js";export{t as ArkEnvError,r as arkenv,r as default,n as formatIssues,e as getSchemaKeys};
@@ -1,4 +1,4 @@
1
1
  const e=`ArkEnvError`,t=e=>{if(typeof e==`number`||typeof e!=`string`||!e.trim())return e;if(e.trim()===`NaN`)return NaN;let t=Number(e);return Number.isNaN(t)?e:t},n=e=>e===`true`?!0:e===`false`?!1:e,r=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}},i=e=>{if(e instanceof Date||typeof e!=`string`||!e.trim())return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t},a=e=>{let t={};for(let n in e){let r=e[n];r!==``&&(t[n]=r)}return t},o=(e,t=[])=>{let n=[];if(!e||typeof e!=`object`||Array.isArray(e))return n;let r=e;if(`const`in r){let e=typeof r.const;(e===`number`||e===`boolean`)&&n.push({path:[...t],type:`primitive`})}`enum`in r&&Array.isArray(r.enum)&&r.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`});let i=r.type;if(i===`number`||i===`integer`||i===`boolean`)n.push({path:[...t],type:`primitive`});else if(i===`string`&&`format`in r&&(r.format===`date-time`||r.format===`date`))n.push({path:[...t],type:`date`});else if(i===`object`){if(r.properties&&Object.keys(r.properties).length>0){n.push({path:[...t],type:`object`});for(let e in r.properties)n.push(...o(r.properties[e],[...t,e]))}}else i===`array`&&(n.push({path:[...t],type:`array`}),r.items&&(Array.isArray(r.items)?r.items.forEach((e,r)=>{n.push(...o(e,[...t,String(r)]))}):n.push(...o(r.items,[...t,`*`]))));for(let e of[`anyOf`,`allOf`,`oneOf`])if(r[e]&&Array.isArray(r[e]))for(let i of r[e])n.push(...o(i,t));let a=new Set;return n.filter(e=>{let t=e.path.join(`/`)+`:`+e.type;return a.has(t)?!1:a.add(t)})},s=(e,a,o={})=>{let{arrayFormat:s=`comma`}=o,c=e=>{if(s===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]},l=(e,a)=>{if(a===`array`&&typeof e==`string`)return c(e);if(a===`object`&&typeof e==`string`)return r(e);if(a===`date`&&typeof e==`string`)return i(e);if(a===`primitive`){if(Array.isArray(e))return e.map(e=>{if(typeof e!=`string`)return e;let r=t(e);return typeof r==`number`?r:n(e)});if(typeof e!=`string`)return e;let r=t(e);return typeof r==`number`?r:n(e)}return e};if(typeof e!=`object`||!e){let t=a.find(e=>e.path.length===0);return t?l(e,t.type):e}let u=[...a].sort((e,t)=>e.path.length-t.path.length),d=(e,t,n)=>{if(t.length===0)return n(e);let[r,...i]=t;if(r===`*`){if(Array.isArray(e)){let t=!1,r=e.map(e=>{let r=d(e,i,n);return r!==e&&(t=!0),r});return t?r:e}return e}if(!e||typeof e!=`object`)return e;if(Array.isArray(e)){let t=Number(r);if(!Number.isNaN(t)&&t>=0&&t<e.length){let r=d(e[t],i,n);if(r!==e[t]){let n=[...e];return n[t]=r,n}}return e}if(Object.hasOwn(e,r)){let t=d(e[r],i,n);if(t!==e[r])return{...e,[r]:t}}return e},f=e;for(let e of u)e.path.length>0&&(f=d(f,e.path,t=>l(t,e.type)));return f};function c(e,t,n,r){let i=t?a(e):e,c={...i},l=[];if(r){let e=r();l.push(...e.missingKeys||[]),e.hasSchema&&(c=s(c,o(e.schema),{arrayFormat:n}))}return{processedEnv:i,coercedEnv:c,missingKeys:l}}const l=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
2
2
  `).map(e=>`${` `.repeat(t)}${e}`).join(`
3
3
  `),u={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},d=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,f=()=>!!(!d()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),p=(e,t)=>d()&&!f()?`${u[e]}${t}${u.reset}`:t;function m(e){return e.map(e=>`${p(`yellow`,e.path)} ${e.message.trimStart()}`).join(`
4
- `)}var h=class extends Error{constructor(t,n=`Errors found while validating environment variables`){let r=m(t);super(`${p(`red`,n)}\n${l(r)}\n`),this.name=e,this.issues=t}};Object.defineProperty(h,`name`,{value:e});function g(e,t){if(typeof t==`string`)throw new h([{path:e,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or import from "arkenv" for ArkType schemas.`,code:`INVALID_SCHEMA`}])}function _(e,t){let n=t&&typeof t==`object`&&`~standard`in t&&t[`~standard`];if(!n||typeof n!=`object`||!(`validate`in n)||typeof n.validate!=`function`)throw new h([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`,code:`INVALID_SCHEMA`}])}function v(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new h([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`,code:`INVALID_SCHEMA`}])}const y=/secret|(_|^)key(_|$)|token|(_|^)password(_|$)|(_|^)pass(_|$)|(_|^)auth(_|$)|jwt|cert|credential|database_url|db_url/i;function b(e){if(e!==void 0)return e;if(typeof process>`u`)return!1;let t=process.env.ARKENV_DEBUG_SECRETS;return t===`true`||t===`1`}function x(e){return y.test(e)&&!/public/i.test(e)}function S(e,t,n){let r=b(n?.debugSecrets);if(e===void 0)return`missing`;if(e===null)return`null`;if(!r&&x(t))return`[REDACTED]`;if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);if(typeof e==`symbol`)return e.toString();if(typeof e==`function`)return`[Function]`;if(e&&typeof e==`object`)try{if(Array.isArray(e)){let r=e.slice(0,3).map(e=>S(e,t,n));return e.length>3&&r.push(`...(+${e.length-3} more)`),`[${r.join(`, `)}]`}let r=Object.keys(e),i=r.slice(0,3).map(r=>`${r}: ${S(e[r],t,n)}`);return r.length>3&&i.push(`...(+${r.length-3} more)`),`{ ${i.join(`, `)} }`}catch{return Object.prototype.toString.call(e)}return String(e)}const C={too_small:`VALUE_TOO_SMALL`,too_big:`VALUE_TOO_LARGE`,invalid_string:`INVALID_FORMAT`,invalid_date:`INVALID_FORMAT`,custom:`INVALID_FORMAT`};function w(e,t,n){let r=t.toLowerCase();return e===`invalid_type`&&(n===void 0||n===`undefined`)||r===`required`?`MISSING_VARIABLE`:e in C?C[e]:/regex|pattern|match/.test(r)?`PATTERN_MISMATCH`:`INVALID_TYPE`}function T(e){let t=e.minimum??e.min,n=e.maximum??e.max;return{...typeof t==`number`?{min:t}:{},...typeof n==`number`?{max:n}:{}}}function E(e){try{return{success:!0,data:e()}}catch(e){if(e instanceof h)return{success:!1,issues:e.issues};throw e}}function D(e,t,n,r,i,a){let o={path:e,message:t,code:n,meta:r??{}};return i&&(o.expected=i),a!==void 0&&(o.received=a),o}function O(e,t,n,r,i,a){if(t===`MISSING_VARIABLE`)return n?`must be ${n} (was missing)`:`is required`;if(e.includes(`(was `))return e;let o=`(was ${p(`cyan`,!b(a?.debugSecrets)&&x(i)?`[REDACTED]`:S(r,i,a))})`;return n&&!e.includes(`Expected`)?`must be ${n} ${o}`:`${e} ${o}`}function k(e){return Object.prototype.toString.call(e)===`[object Object]`}function A(e,t){let n={type:`object`,properties:{}},r=!1,i=[];for(let a in e){let o=e[a];if(!o){i.push(a);continue}let s=o[`~standard`];if(typeof s?.jsonSchema?.input==`function`)try{let e=s.jsonSchema.input({target:`draft-07`});if(e){n.properties[a]=e,r=!0;continue}}catch{}if(typeof o.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[a]=e,r=!0;continue}}catch{}if(typeof o.toJSONSchema==`function`)try{let e=o.toJSONSchema();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(typeof o.toStandardJSONSchema?.v1==`function`)try{let e=o.toStandardJSONSchema.v1();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(t){let e;try{e=t(o)}catch(e){throw new h([D(a,`toJsonSchema failed for '${a}': ${e instanceof Error?e.message:String(e)}`,`INVALID_SCHEMA`)])}if(!e){i.push(a);continue}if(!k(e))throw new h([D(a,`toJsonSchema must return a plain object or undefined for '${a}'.`,`INVALID_SCHEMA`)]);n.properties[a]=e,r=!0;continue}i.push(a)}return{jsonSchema:n,hasJsonSchema:r,missingKeys:i}}function j(e){return typeof e==`object`&&e&&`key`in e?String(e.key):String(e)}function M(e,t){return!t||t.length===0?e:[e,...t.map(j)].join(`.`)}function N(e,t){let n=e,r;try{let i=e,a=e.trim();if(a[0]===`{`||a[0]===`[`)try{i=JSON.parse(e)}catch(e){r=`[Unparseable JSON: ${e.message}]`}if(!r){for(let e of t)i=i?.[j(e)];n=i}}catch(e){r=`[Traversal error: ${e.message}]`}return{receivedVal:n,traversalError:r}}function P(e,t){let{env:n=process.env,onUndeclaredKey:r=`delete`,coerce:i=!0,arrayFormat:a=`comma`,emptyAsUndefined:o=!1,toJsonSchema:s}=t,l={},u=[],{processedEnv:d,coercedEnv:f,missingKeys:p}=c(n,o,a,i?()=>{let{jsonSchema:t,hasJsonSchema:n,missingKeys:r}=A(e,s);return{schema:t,hasSchema:n,missingKeys:r}}:void 0),m=new Set(Object.keys(d));for(let n in e){let r=e[n],a=f[n];if(!r||typeof r!=`object`||!(`~standard`in r))throw new h([D(n,`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,`INVALID_SCHEMA`)]);let o=r[`~standard`].validate(a);if(o instanceof Promise)throw new h([D(n,`Async validation is not supported. ArkEnv is synchronous.`,`INVALID_SCHEMA`)]);if(o.issues)for(let e of o.issues){let r=M(n,e.path),a,o;if(n in d){let t=d[n];if(typeof t==`string`&&e.path?.length){let n=N(t,e.path);a=n.receivedVal,o=n.traversalError}else a=t}else a=e.received;let s=w(e.code||`invalid_type`,e.message||``,a),c=e.expected||void 0,l={...T(e)},f=e;f.validation!==void 0&&(l.validation=f.validation),o!==void 0&&(l.traversalError=o);let m=O(e.message||``,s,c,a,r,t);i&&p.includes(n)&&(m+=` (Hint: coercion is enabled by default, but the validator for '${n}' lacks Standard JSON Schema support.)`),u.push(D(r,m,s,l,c,a))}else l[n]=o.value;m.delete(n)}if(r!==`delete`)for(let e of m)r===`reject`?u.push(D(e,`Undeclared key`,`UNDECLARED_KEY`)):r===`ignore`&&(l[e]=f[e]);if(u.length>0)throw new h(u);return l}function F(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}let t=e[`~standard`],n=typeof t?.jsonSchema?.input==`function`&&t.jsonSchema.input||typeof e.jsonSchema?.input==`function`&&e.jsonSchema.input;if(n)try{let e=n({target:`draft-07`});if(e&&typeof e==`object`&&e.properties)return Object.keys(e.properties)}catch{}if(typeof e.toJSONSchema==`function`)try{let t=e.toJSONSchema();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}if(typeof e.toStandardJSONSchema?.v1==`function`)try{let t=e.toStandardJSONSchema.v1();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}return Object.keys(e)}const I=`__ARKENV_SCHEMA_CAPTURE__`;function L(){let e=globalThis;return e[I]||(e[I]={capturing:!1,definitions:[]}),e[I]}function R(){return L().capturing}function z(e){let t=L();t.capturing&&t.definitions.push(e)}function B(e,t){let n=t??{};v(e);for(let t in e){let n=e[t];g(t,n),_(t,n)}return R()?(z(e),{}):n.safe?E(()=>P(e,n)):P(e,n)}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}});
4
+ `)}var h=class extends Error{constructor(t,n=`Errors found while validating environment variables`){let r=m(t);super(`${p(`red`,n)}\n${l(r)}\n`),this.name=e,this.issues=t}};Object.defineProperty(h,`name`,{value:e});function g(e,t){if(typeof t==`string`)throw new h([{path:e,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or import from "arkenv" for ArkType schemas.`,code:`INVALID_SCHEMA`}])}function _(e,t){let n=t&&typeof t==`object`&&`~standard`in t&&t[`~standard`];if(!n||typeof n!=`object`||!(`validate`in n)||typeof n.validate!=`function`)throw new h([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`,code:`INVALID_SCHEMA`}])}function v(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new h([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`,code:`INVALID_SCHEMA`}])}const y=/secret|(_|^)key(_|$)|token|(_|^)password(_|$)|(_|^)pass(_|$)|(_|^)auth(_|$)|jwt|cert|credential|database_url|db_url/i;function b(e){if(e!==void 0)return e;if(typeof process>`u`)return!1;let t=process.env.ARKENV_DEBUG_SECRETS;return t===`true`||t===`1`}function x(e){return y.test(e)&&!/public/i.test(e)}function S(e,t,n){let r=b(n?.debugSecrets);if(e===void 0)return`missing`;if(e===null)return`null`;if(!r&&x(t))return`[REDACTED]`;if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);if(typeof e==`symbol`)return e.toString();if(typeof e==`function`)return`[Function]`;if(e&&typeof e==`object`)try{if(Array.isArray(e)){let r=e.slice(0,3).map(e=>S(e,t,n));return e.length>3&&r.push(`...(+${e.length-3} more)`),`[${r.join(`, `)}]`}let r=Object.keys(e),i=r.slice(0,3).map(r=>`${r}: ${S(e[r],t,n)}`);return r.length>3&&i.push(`...(+${r.length-3} more)`),`{ ${i.join(`, `)} }`}catch{return Object.prototype.toString.call(e)}return String(e)}const C={too_small:`VALUE_TOO_SMALL`,too_big:`VALUE_TOO_LARGE`,invalid_string:`INVALID_FORMAT`,invalid_date:`INVALID_FORMAT`,custom:`INVALID_FORMAT`};function w(e,t,n){let r=t.toLowerCase();return e===`invalid_type`&&(n===void 0||n===`undefined`)||r===`required`?`MISSING_VARIABLE`:e in C?C[e]:/regex|pattern|match/.test(r)?`PATTERN_MISMATCH`:`INVALID_TYPE`}function T(e){let t=e.minimum??e.min,n=e.maximum??e.max;return{...typeof t==`number`?{min:t}:{},...typeof n==`number`?{max:n}:{}}}function E(e){try{return{success:!0,data:e()}}catch(e){if(e instanceof h)return{success:!1,issues:e.issues};throw e}}function D(e,t,n,r,i,a){let o={path:e,message:t,code:n,meta:r??{}};return i&&(o.expected=i),a!==void 0&&(o.received=a),o}function O(e,t,n,r,i,a){if(t===`MISSING_VARIABLE`)return n?`must be ${n} (was missing)`:`is required`;if(e.includes(`(was `))return e;let o=`(was ${p(`cyan`,!b(a?.debugSecrets)&&x(i)?`[REDACTED]`:S(r,i,a))})`;return n&&!e.includes(`Expected`)?`must be ${n} ${o}`:`${e} ${o}`}const k=[`draft-07`,`draft-2020-12`];function A(e){return Object.prototype.toString.call(e)===`[object Object]`}function j(e){let t=`converter returned a non-schema`;for(let n of k)try{let r=e({target:n});if(A(r))return{ok:!0,schema:r};t=`converter returned a non-schema`}catch(e){t=e instanceof Error?e.message:String(e)}return{ok:!1,detail:t}}function M(e,t){throw new h([D(e,`JSON Schema conversion failed for '${e}': ${t}`,`INVALID_SCHEMA`)])}function N(e,t){let n={type:`object`,properties:{}},r=!1,i=[];for(let a in e){let o=e[a];if(!o){i.push(a);continue}let s=o[`~standard`];if(typeof s?.jsonSchema?.input==`function`){let e=j(s.jsonSchema.input);if(e.ok){n.properties[a]=e.schema,r=!0;continue}M(a,e.detail)}if(typeof o.jsonSchema?.input==`function`){let e=j(o.jsonSchema.input);if(e.ok){n.properties[a]=e.schema,r=!0;continue}M(a,e.detail)}if(typeof o.toJSONSchema==`function`)try{let e=o.toJSONSchema();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(typeof o.toStandardJSONSchema?.v1==`function`)try{let e=o.toStandardJSONSchema.v1();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(t){let e;try{e=t(o)}catch(e){throw new h([D(a,`toJsonSchema failed for '${a}': ${e instanceof Error?e.message:String(e)}`,`INVALID_SCHEMA`)])}if(!e){i.push(a);continue}if(!A(e))throw new h([D(a,`toJsonSchema must return a plain object or undefined for '${a}'.`,`INVALID_SCHEMA`)]);n.properties[a]=e,r=!0;continue}i.push(a)}return{jsonSchema:n,hasJsonSchema:r,missingKeys:i}}function P(e){return typeof e==`object`&&e&&`key`in e?String(e.key):String(e)}function F(e,t){return!t||t.length===0?e:[e,...t.map(P)].join(`.`)}function I(e,t){let n=e,r;try{let i=e,a=e.trim();if(a[0]===`{`||a[0]===`[`)try{i=JSON.parse(e)}catch(e){r=`[Unparseable JSON: ${e.message}]`}if(!r){for(let e of t)i=i?.[P(e)];n=i}}catch(e){r=`[Traversal error: ${e.message}]`}return{receivedVal:n,traversalError:r}}function L(e,t){let{env:n=process.env,onUndeclaredKey:r=`delete`,coerce:i=!0,arrayFormat:a=`comma`,emptyAsUndefined:o=!1,toJsonSchema:s}=t,l={},u=[],{processedEnv:d,coercedEnv:f,missingKeys:p}=c(n,o,a,i?()=>{let{jsonSchema:t,hasJsonSchema:n,missingKeys:r}=N(e,s);return{schema:t,hasSchema:n,missingKeys:r}}:void 0),m=new Set(Object.keys(d));for(let n in e){let r=e[n],a=f[n];if(!r||typeof r!=`object`||!(`~standard`in r))throw new h([D(n,`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,`INVALID_SCHEMA`)]);let o=r[`~standard`].validate(a);if(o instanceof Promise)throw new h([D(n,`Async validation is not supported. ArkEnv is synchronous.`,`INVALID_SCHEMA`)]);if(o.issues)for(let e of o.issues){let r=F(n,e.path),a,o;if(n in d){let t=d[n];if(typeof t==`string`&&e.path?.length){let n=I(t,e.path);a=n.receivedVal,o=n.traversalError}else a=t}else a=e.received;let s=w(e.code||`invalid_type`,e.message||``,a),c=e.expected||void 0,l={...T(e)},f=e;f.validation!==void 0&&(l.validation=f.validation),o!==void 0&&(l.traversalError=o);let m=O(e.message||``,s,c,a,r,t);i&&p.includes(n)&&(m+=` (Hint: coercion is enabled by default, but the validator for '${n}' lacks Standard JSON Schema support.)`),u.push(D(r,m,s,l,c,a))}else l[n]=o.value;m.delete(n)}if(r!==`delete`)for(let e of m)r===`reject`?u.push(D(e,`Undeclared key`,`UNDECLARED_KEY`)):r===`ignore`&&(l[e]=f[e]);if(u.length>0)throw new h(u);return l}function R(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}let t=e[`~standard`],n=typeof t?.jsonSchema?.input==`function`&&t.jsonSchema.input||typeof e.jsonSchema?.input==`function`&&e.jsonSchema.input;if(n)try{let e=n({target:`draft-07`});if(e&&typeof e==`object`&&e.properties)return Object.keys(e.properties)}catch{}if(typeof e.toJSONSchema==`function`)try{let t=e.toJSONSchema();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}if(typeof e.toStandardJSONSchema?.v1==`function`)try{let t=e.toStandardJSONSchema.v1();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}return Object.keys(e)}const z=Symbol.for(`arkenv.schemaCapture.v1`);function B(){let e=globalThis;return e[z]||(e[z]={capturing:!1,definitions:[]}),e[z]}function V(){return B().capturing}function H(e){let t=B();t.capturing&&t.definitions.push(e)}function U(e,t){let n=t??{};v(e);for(let t in e){let n=e[t];g(t,n),_(t,n)}return V()?(H(e),{}):n.safe?E(()=>L(e,n)):L(e,n)}export{R as i,h as n,m as r,U as t};