arkenv 1.0.0-alpha.2 → 1.0.0-alpha.21

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.
@@ -1,105 +0,0 @@
1
- import { a as SafeArkEnvResult } from "./core-BaGd9k2K.mjs";
2
- import { a as Dict, i as StandardSchemaV1 } from "./index-NbQAnciD.mjs";
3
-
4
- //#region src/parse-standard.d.ts
5
- /**
6
- * Configuration options for {@link parseStandard}.
7
- */
8
- type ParseStandardConfig = {
9
- /**
10
- * The environment variables to parse. Defaults to `process.env`
11
- */
12
- env?: Dict<string>;
13
- /**
14
- * Control how ArkEnv handles environment variables that are not defined in your schema.
15
- *
16
- * Defaults to `'delete'` to ensure your output object only contains
17
- * keys you've explicitly declared.
18
- *
19
- * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
20
- * - `ignore`: Undeclared keys are allowed and preserved in the output.
21
- * - `reject`: Undeclared keys will cause validation to fail.
22
- *
23
- * @default "delete"
24
- */
25
- onUndeclaredKey?: "ignore" | "delete" | "reject";
26
- /**
27
- * Whether to bypass secret redaction and print raw sensitive values during debugging.
28
- * Defaults to checking `process.env.ARKENV_DEBUG_SECRETS === "true"` or `"1"`.
29
- */
30
- debugSecrets?: boolean;
31
- /**
32
- * Whether to perform best-effort coercion on the environment variables.
33
- * Coercion requires validators that implement the StandardJSONSchemaV1 spec
34
- * (e.g. Zod, Valibot).
35
- *
36
- * @see https://standard-schema.dev
37
- * @default true
38
- */
39
- coerce?: boolean;
40
- /**
41
- * The format to use for array parsing when coercion is enabled.
42
- *
43
- * - `comma` (default): Strings are split by comma and trimmed.
44
- * - `json`: Strings are parsed as JSON.
45
- *
46
- * @default "comma"
47
- */
48
- arrayFormat?: "comma" | "json";
49
- /**
50
- * Whether to treat empty strings (`""`) as `undefined` before validation.
51
- *
52
- * When enabled, an environment variable set to an empty value (e.g. `PORT=`)
53
- * will be treated as if it were missing, allowing defaults to apply and
54
- * preventing validation errors for numeric or boolean types.
55
- *
56
- * @default false
57
- */
58
- emptyAsUndefined?: boolean;
59
- /**
60
- * Whether to return a safe result object instead of throwing an error on validation failure.
61
- *
62
- * When enabled, the function returns an object with `{ success: true, data }` or `{ success: false, issues }`.
63
- *
64
- * @default false
65
- */
66
- safe?: boolean;
67
- };
68
- //#endregion
69
- //#region src/standard.d.ts
70
- /**
71
- * Configuration options for the `arkenv/standard` entry's `arkenv`.
72
- */
73
- type StandardEnvConfig = ParseStandardConfig;
74
- /**
75
- * Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).
76
- *
77
- * This entry is ArkType-free - ArkType is never imported, even transitively.
78
- * Use this when your project must not depend on ArkType.
79
- *
80
- * @param def An object mapping variable names to Standard Schema validators
81
- * @param config Optional configuration
82
- * @returns The validated environment variables, or a SafeArkEnvResult if `{ safe: true }` is configured
83
- * @throws An {@link ArkEnvError} if validation fails and `safe` is not enabled
84
- *
85
- * @example
86
- * ```ts
87
- * import arkenv from "arkenv/standard";
88
- * import { z } from "zod";
89
- *
90
- * const env = arkenv({
91
- * PORT: z.coerce.number(),
92
- * HOST: z.string(),
93
- * });
94
- * ```
95
- */
96
- declare function arkenv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: StandardEnvConfig & {
97
- safe?: false;
98
- }): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
99
- declare function arkenv<const T extends Record<string, StandardSchemaV1>>(def: T, config: StandardEnvConfig & {
100
- safe: true;
101
- }): SafeArkEnvResult<{ [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> }>;
102
- //#endregion
103
- export { StandardEnvConfig, arkenv, arkenv as default };
104
-
105
- //# sourceMappingURL=standard.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;;KAqCY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,IAAA;EAAA;;;;;;;;;;;;EAaN,eAAA;ECzC4B;;;;ED8C5B,YAAA;ECtBqB;;;;;;;;EDgCrB,MAAA;EC7BoB;;;;;;;;EDuCpB,WAAA;ECxC+B;;;;;;;;;EDmD/B,gBAAA;ECjDe;;;;;;;ED0Df,IAAA;AAAA;;;;AA9DD;;KCxBY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;iBAAgB,MAAA,iBAAuB,MAAA,SAAe,gBAAA,EAAA,CACrD,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,iBAAA;EAAsB,IAAA;AAAA,kBACf,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA;AAAA,iBACpC,MAAA,iBAAuB,MAAA,SAAe,gBAAA,EAAA,CACrD,GAAA,EAAK,CAAA,EACL,MAAA,EAAQ,iBAAA;EAAsB,IAAA;AAAA,IAC5B,gBAAA,eAA+B,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA"}
package/dist/standard.mjs DELETED
@@ -1,3 +0,0 @@
1
- import{c as e,i as t,l as n,n as r,o as i,t as a}from"./errors-C_uh86xh.mjs";import{t as o}from"./core-A65KioHX.mjs";function s(e,t){if(typeof t==`string`)throw new o([{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 c(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 o([{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 l(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new o([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`,code:`INVALID_SCHEMA`}])}function u(e){let t={type:`object`,properties:{}},n=!1,r=[];for(let i in e){let a=e[i];if(!a){r.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){t.properties[i]=e,n=!0;continue}}catch{}r.push(i)}return{jsonSchema:t,hasJsonSchema:n,missingKeys:r}}function d(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(d)].join(`.`)}function p(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?.[d(e)];n=i}}catch(e){r=`[Traversal error: ${e.message}]`}return{receivedVal:n,traversalError:r}}function m(e,s){let{env:c=process.env,onUndeclaredKey:l=`delete`,coerce:d=!0,arrayFormat:m=`comma`,emptyAsUndefined:h=!1}=s,g={},_=[],{processedEnv:v,coercedEnv:y,missingKeys:b}=n(c,h,m,d?()=>{let{jsonSchema:t,hasJsonSchema:n,missingKeys:r}=u(e);return{schema:t,hasSchema:n,missingKeys:r}}:void 0),x=new Set(Object.keys(v));for(let n in e){let c=e[n],l=y[n];if(!c||typeof c!=`object`||!(`~standard`in c))throw new o([a(n,`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,`INVALID_SCHEMA`)]);let u=c[`~standard`].validate(l);if(u instanceof Promise)throw new o([a(n,`Async validation is not supported. ArkEnv is synchronous.`,`INVALID_SCHEMA`)]);if(u.issues)for(let e of u.issues){let o=f(n,e.path),c,l;if(n in v){let t=v[n];if(typeof t==`string`&&e.path?.length){let n=p(t,e.path);c=n.receivedVal,l=n.traversalError}else c=t}else c=e.received;let u=i(e.code||`invalid_type`,e.message||``,c),m=e.expected||void 0,h={...t(e)},g=e;g.validation!==void 0&&(h.validation=g.validation),l!==void 0&&(h.traversalError=l);let y=r(e.message||``,u,m,c,o,s);d&&b.includes(n)&&(y+=` (Hint: coercion is enabled by default, but the validator for '${n}' lacks Standard JSON Schema support.)`),_.push(a(o,y,u,h,m,c))}else g[n]=u.value;x.delete(n)}if(l!==`delete`)for(let e of x)l===`reject`?_.push(a(e,`Undeclared key`,`UNDECLARED_KEY`)):l===`ignore`&&(g[e]=y[e]);if(_.length>0)throw new o(_);return g}function h(t,n={}){l(t);for(let e in t){let n=t[e];s(e,n),c(e,n)}return n.safe?e(()=>m(t,n)):m(t,n)}export{h as arkenv,h as default};
2
-
3
- //# sourceMappingURL=standard.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"standard.mjs","names":[],"sources":["../src/guards.ts","../src/utils/standard-helpers.ts","../src/parse-standard.ts","../src/standard.ts"],"sourcesContent":["import { ArkEnvError } from \"./core\";\n\n/**\n * Throws if the given value is a string (ArkType DSL) in standard mode.\n * @internal\n */\nexport function assertNotArkTypeDsl(key: string, value: unknown): void {\n\tif (typeof value === \"string\") {\n\t\tthrow new ArkEnvError([\n\t\t\t{\n\t\t\t\tpath: key,\n\t\t\t\tmessage:\n\t\t\t\t\t'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.',\n\t\t\t\tcode: \"INVALID_SCHEMA\",\n\t\t\t},\n\t\t]);\n\t}\n}\n\n/**\n * Throws if the given value is not a well-formed Standard Schema validator\n * (must have a `~standard` property whose `validate` field is a function).\n * @internal\n */\nexport function assertStandardSchema(key: string, value: unknown): void {\n\tconst std =\n\t\tvalue &&\n\t\ttypeof value === \"object\" &&\n\t\t\"~standard\" in value &&\n\t\t(value as Record<string, unknown>)[\"~standard\"];\n\n\tif (\n\t\t!std ||\n\t\ttypeof std !== \"object\" ||\n\t\t!(\"validate\" in std) ||\n\t\ttypeof (std as Record<string, unknown>).validate !== \"function\"\n\t) {\n\t\tthrow new ArkEnvError([\n\t\t\t{\n\t\t\t\tpath: key,\n\t\t\t\tmessage:\n\t\t\t\t\t'Invalid validator: expected a Standard Schema 1.0 validator (must have \"~standard\" property). Import from \"arkenv\" to use ArkType schemas.',\n\t\t\t\tcode: \"INVALID_SCHEMA\",\n\t\t\t},\n\t\t]);\n\t}\n}\n\n/**\n * Throws if `def` is not a plain object (i.e. not a valid schema map).\n * @internal\n */\nexport function assertStandardSchemaMap(\n\tdef: unknown,\n): asserts def is Record<string, unknown> {\n\tif (!def || typeof def !== \"object\" || Array.isArray(def)) {\n\t\tthrow new ArkEnvError([\n\t\t\t{\n\t\t\t\tpath: \"\",\n\t\t\t\tmessage:\n\t\t\t\t\t'Invalid schema: expected an object mapping in \"standard\" mode.',\n\t\t\t\tcode: \"INVALID_SCHEMA\",\n\t\t\t},\n\t\t]);\n\t}\n}\n","/**\n * Extract JSON Schema definitions from standard schema validators.\n *\n * @param def The schema dictionary mapping keys to validators\n * @returns The generated JSON Schema, a flag indicating if any JSON Schema was found,\n * and a list of keys that do not support JSON Schema\n */\nexport function extractJsonSchema(def: Record<string, unknown>): {\n\tjsonSchema: Record<string, any>;\n\thasJsonSchema: boolean;\n\tmissingKeys: string[];\n} {\n\tconst jsonSchema: Record<string, any> = { type: \"object\", properties: {} };\n\tlet hasJsonSchema = false;\n\tconst missingKeys: string[] = [];\n\n\tfor (const key in def) {\n\t\tconst validator = def[key] as any;\n\t\tif (!validator) {\n\t\t\tmissingKeys.push(key);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// 1. Standard way via ~standard property\n\t\tconst std = validator[\"~standard\"];\n\t\tif (typeof std?.jsonSchema?.input === \"function\") {\n\t\t\ttry {\n\t\t\t\tconst schema = std.jsonSchema.input({ target: \"draft-07\" });\n\t\t\t\tif (schema) {\n\t\t\t\t\tjsonSchema.properties[key] = schema;\n\t\t\t\t\thasJsonSchema = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t}\n\n\t\t// 2. Direct jsonSchema.input on validator\n\t\tif (typeof validator.jsonSchema?.input === \"function\") {\n\t\t\ttry {\n\t\t\t\tconst schema = validator.jsonSchema.input({ target: \"draft-07\" });\n\t\t\t\tif (schema) {\n\t\t\t\t\tjsonSchema.properties[key] = schema;\n\t\t\t\t\thasJsonSchema = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t}\n\n\t\t// 3. toJSONSchema method (e.g. zod mini, zod-to-json-schema)\n\t\tif (typeof validator.toJSONSchema === \"function\") {\n\t\t\ttry {\n\t\t\t\tconst schema = validator.toJSONSchema();\n\t\t\t\tif (schema) {\n\t\t\t\t\tjsonSchema.properties[key] = schema;\n\t\t\t\t\thasJsonSchema = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t}\n\n\t\t// 4. toStandardJSONSchema.v1 method (e.g. stnl)\n\t\tif (typeof validator.toStandardJSONSchema?.v1 === \"function\") {\n\t\t\ttry {\n\t\t\t\tconst schema = validator.toStandardJSONSchema.v1();\n\t\t\t\tif (schema) {\n\t\t\t\t\tjsonSchema.properties[key] = schema;\n\t\t\t\t\thasJsonSchema = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t}\n\n\t\tmissingKeys.push(key);\n\t}\n\n\treturn { jsonSchema, hasJsonSchema, missingKeys };\n}\n\n/**\n * Get the property key from a path segment.\n *\n * @param s The path segment which can be a key or a segment object\n * @returns The string representation of the property key\n */\nexport function getProp(\n\ts: string | number | symbol | { readonly key: string | number | symbol },\n): string {\n\treturn typeof s === \"object\" && s !== null && \"key\" in s\n\t\t? String(s.key)\n\t\t: String(s);\n}\n\n/**\n * Format standard schema validation issue path.\n *\n * @param key The base key of the environment variable\n * @param path The relative path segments of the issue\n * @returns The formatted dot-separated path string\n */\nexport function formatIssuePath(\n\tkey: string,\n\tpath:\n\t\t| readonly (\n\t\t\t\t| string\n\t\t\t\t| number\n\t\t\t\t| symbol\n\t\t\t\t| { readonly key: string | number | symbol }\n\t\t )[]\n\t\t| undefined,\n): string {\n\tif (!path || path.length === 0) return key;\n\treturn [key, ...path.map(getProp)].join(\".\");\n}\n\n/**\n * Traverse the raw string value (attempting to parse as JSON if it represents an object/array)\n * to extract the nested value targeted by the issue path.\n *\n * @param rawVal The raw string value of the environment variable\n * @param path The path segments of the validation issue\n * @returns An object containing the resolved nested value and an optional traversal error string\n */\nexport function traverseReceivedValue(\n\trawVal: string,\n\tpath: readonly (\n\t\t| string\n\t\t| number\n\t\t| symbol\n\t\t| { readonly key: string | number | symbol }\n\t)[],\n): { receivedVal: unknown; traversalError?: string | undefined } {\n\tlet receivedVal: unknown = rawVal;\n\tlet traversalError: string | undefined;\n\n\ttry {\n\t\tlet current: any = rawVal;\n\t\tconst trimmed = rawVal.trim();\n\t\tif (trimmed[0] === \"{\" || trimmed[0] === \"[\") {\n\t\t\ttry {\n\t\t\t\tcurrent = JSON.parse(rawVal);\n\t\t\t} catch (e: any) {\n\t\t\t\ttraversalError = `[Unparseable JSON: ${e.message}]`;\n\t\t\t}\n\t\t}\n\t\tif (!traversalError) {\n\t\t\tfor (const seg of path) {\n\t\t\t\tcurrent = current?.[getProp(seg)];\n\t\t\t}\n\t\t\treceivedVal = current;\n\t\t}\n\t} catch (e: any) {\n\t\ttraversalError = `[Traversal error: ${e.message}]`;\n\t}\n\n\treturn { receivedVal, traversalError };\n}\n","import type { Dict, StandardSchemaV1 } from \"@repo/types\";\nimport { coerceEnvironment } from \"@/coercion\";\nimport { ArkEnvError, type EnvIssue, type EnvIssueMeta } from \"./core\";\nimport {\n\tbuildEnvIssue,\n\tformatStandardIssueMessage,\n\tgetStandardMeta,\n\tmapStandardCode,\n} from \"./utils/errors\";\nimport {\n\textractJsonSchema,\n\tformatIssuePath,\n\ttraverseReceivedValue,\n} from \"./utils/standard-helpers\";\n\n/*\n * ⚠️ ARCHITECTURAL WARNING: DO NOT DRY THIS FILE ⚠️\n *\n * This file contains parsing logic that looks very similar to the code in\n * `src/arktype/index.ts`. **This duplication is 100% intentional.**\n *\n * `parse-standard.ts` powers the `arkenv/standard` module export. The entire\n * purpose of the `arkenv/standard` entrypoint is to guarantee a zero-dependency\n * environment for users utilizing Zod or Valibot, ensuring the `arktype` library\n * is NEVER included in their bundle.\n *\n * If you attempt to DRY up this code by merging it with the ArkType parser or\n * importing utilities from `src/arktype/*`, bundlers will statically trace those\n * imports and silently drag the entire ArkType library into the `arkenv/standard`\n * bundle.\n *\n * Prioritize strict module boundaries and tree-shaking over DRYness.\n */\n\n/**\n * Configuration options for {@link parseStandard}.\n */\nexport type ParseStandardConfig = {\n\t/**\n\t * The environment variables to parse. Defaults to `process.env`\n\t */\n\tenv?: Dict<string>;\n\t/**\n\t * Control how ArkEnv handles environment variables that are not defined in your schema.\n\t *\n\t * Defaults to `'delete'` to ensure your output object only contains\n\t * keys you've explicitly declared.\n\t *\n\t * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.\n\t * - `ignore`: Undeclared keys are allowed and preserved in the output.\n\t * - `reject`: Undeclared keys will cause validation to fail.\n\t *\n\t * @default \"delete\"\n\t */\n\tonUndeclaredKey?: \"ignore\" | \"delete\" | \"reject\";\n\t/**\n\t * Whether to bypass secret redaction and print raw sensitive values during debugging.\n\t * Defaults to checking `process.env.ARKENV_DEBUG_SECRETS === \"true\"` or `\"1\"`.\n\t */\n\tdebugSecrets?: boolean;\n\n\t/**\n\t * Whether to perform best-effort coercion on the environment variables.\n\t * Coercion requires validators that implement the StandardJSONSchemaV1 spec\n\t * (e.g. Zod, Valibot).\n\t *\n\t * @see https://standard-schema.dev\n\t * @default true\n\t */\n\tcoerce?: boolean;\n\n\t/**\n\t * The format to use for array parsing when coercion is enabled.\n\t *\n\t * - `comma` (default): Strings are split by comma and trimmed.\n\t * - `json`: Strings are parsed as JSON.\n\t *\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\n\n\t/**\n\t * Whether to treat empty strings (`\"\"`) as `undefined` before validation.\n\t *\n\t * When enabled, an environment variable set to an empty value (e.g. `PORT=`)\n\t * will be treated as if it were missing, allowing defaults to apply and\n\t * preventing validation errors for numeric or boolean types.\n\t *\n\t * @default false\n\t */\n\temptyAsUndefined?: boolean;\n\n\t/**\n\t * Whether to return a safe result object instead of throwing an error on validation failure.\n\t *\n\t * When enabled, the function returns an object with `{ success: true, data }` or `{ success: false, issues }`.\n\t *\n\t * @default false\n\t */\n\tsafe?: boolean;\n};\n\n/**\n * Parse and validate environment variables using Standard Schema 1.0 validators.\n *\n * @param def An object mapping environment variable keys to Standard Schema 1.0 validators\n * @param config Parsing options, including environment source, undeclared key handling, and coercion config\n * @returns The parsed and validated environment variables\n * @throws An ArkEnvError if validation fails\n */\nexport function parseStandard(\n\tdef: Record<string, unknown>,\n\tconfig: ParseStandardConfig,\n): Record<string, unknown> {\n\tconst {\n\t\tenv = process.env,\n\t\tonUndeclaredKey = \"delete\",\n\t\tcoerce = true,\n\t\tarrayFormat = \"comma\",\n\t\temptyAsUndefined = false,\n\t} = config;\n\tconst output: Record<string, unknown> = {};\n\tconst errors: EnvIssue[] = [];\n\n\tconst {\n\t\tprocessedEnv,\n\t\tcoercedEnv,\n\t\tmissingKeys: missingJsonSchemaKeys,\n\t} = coerceEnvironment(\n\t\tenv as Dict<string>,\n\t\temptyAsUndefined,\n\t\tarrayFormat,\n\t\tcoerce\n\t\t\t? () => {\n\t\t\t\t\tconst { jsonSchema, hasJsonSchema, missingKeys } =\n\t\t\t\t\t\textractJsonSchema(def);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tschema: jsonSchema,\n\t\t\t\t\t\thasSchema: hasJsonSchema,\n\t\t\t\t\t\tmissingKeys,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t: undefined,\n\t);\n\tconst envKeys = new Set(Object.keys(processedEnv));\n\n\t// 1. Validate declared keys\n\tfor (const key in def) {\n\t\tconst validator = def[key];\n\t\tconst value = coercedEnv[key];\n\n\t\t// Check if it's a Standard Schema validator\n\t\tif (\n\t\t\t!validator ||\n\t\t\ttypeof validator !== \"object\" ||\n\t\t\t!(\"~standard\" in validator)\n\t\t) {\n\t\t\tthrow new ArkEnvError([\n\t\t\t\tbuildEnvIssue(\n\t\t\t\t\tkey,\n\t\t\t\t\t`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,\n\t\t\t\t\t\"INVALID_SCHEMA\",\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tconst result = (validator as StandardSchemaV1)[\"~standard\"].validate(value);\n\n\t\tif (result instanceof Promise) {\n\t\t\tthrow new ArkEnvError([\n\t\t\t\tbuildEnvIssue(\n\t\t\t\t\tkey,\n\t\t\t\t\t\"Async validation is not supported. ArkEnv is synchronous.\",\n\t\t\t\t\t\"INVALID_SCHEMA\",\n\t\t\t\t),\n\t\t\t]);\n\t\t}\n\n\t\tif (result.issues) {\n\t\t\tfor (const issue of result.issues) {\n\t\t\t\tconst issuePath = formatIssuePath(key, issue.path);\n\n\t\t\t\tlet receivedVal: unknown;\n\t\t\t\tlet traversalError: string | undefined;\n\n\t\t\t\tif (key in processedEnv) {\n\t\t\t\t\tconst rawVal = processedEnv[key];\n\t\t\t\t\tif (typeof rawVal === \"string\" && issue.path?.length) {\n\t\t\t\t\t\tconst traversed = traverseReceivedValue(rawVal, issue.path);\n\t\t\t\t\t\treceivedVal = traversed.receivedVal;\n\t\t\t\t\t\ttraversalError = traversed.traversalError;\n\t\t\t\t\t} else {\n\t\t\t\t\t\treceivedVal = rawVal;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treceivedVal = (issue as any).received;\n\t\t\t\t}\n\n\t\t\t\tconst issueCode = (issue as any).code || \"invalid_type\";\n\t\t\t\tconst msg = issue.message || \"\";\n\t\t\t\tconst code = mapStandardCode(issueCode, msg, receivedVal);\n\n\t\t\t\tconst expected = (issue as any).expected || undefined;\n\t\t\t\tconst bounds = getStandardMeta(issue);\n\n\t\t\t\tconst meta: EnvIssueMeta = {\n\t\t\t\t\t...bounds,\n\t\t\t\t};\n\t\t\t\tconst iss = issue as any;\n\t\t\t\tif (iss.validation !== undefined) meta.validation = iss.validation;\n\t\t\t\tif (traversalError !== undefined) meta.traversalError = traversalError;\n\n\t\t\t\tlet message = formatStandardIssueMessage(\n\t\t\t\t\tissue.message || \"\",\n\t\t\t\t\tcode,\n\t\t\t\t\texpected,\n\t\t\t\t\treceivedVal,\n\t\t\t\t\tissuePath,\n\t\t\t\t\tconfig,\n\t\t\t\t);\n\n\t\t\t\tif (coerce && missingJsonSchemaKeys.includes(key)) {\n\t\t\t\t\tmessage += ` (Hint: coercion is enabled by default, but the validator for '${key}' lacks Standard JSON Schema support.)`;\n\t\t\t\t}\n\n\t\t\t\terrors.push(\n\t\t\t\t\tbuildEnvIssue(issuePath, message, code, meta, expected, receivedVal),\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\toutput[key] = result.value;\n\t\t}\n\n\t\tenvKeys.delete(key);\n\t}\n\n\t// 2. Handle undeclared keys\n\tif (onUndeclaredKey !== \"delete\") {\n\t\tfor (const key of envKeys) {\n\t\t\tif (onUndeclaredKey === \"reject\") {\n\t\t\t\terrors.push(buildEnvIssue(key, \"Undeclared key\", \"UNDECLARED_KEY\"));\n\t\t\t} else if (onUndeclaredKey === \"ignore\") {\n\t\t\t\toutput[key] = coercedEnv[key];\n\t\t\t}\n\t\t}\n\t}\n\n\tif (errors.length > 0) {\n\t\tthrow new ArkEnvError(errors);\n\t}\n\n\treturn output;\n}\n","import type { StandardSchemaV1 } from \"@repo/types\";\nimport { ArkEnvError, type SafeArkEnvResult } from \"./core\";\nimport {\n\tassertNotArkTypeDsl,\n\tassertStandardSchema,\n\tassertStandardSchemaMap,\n} from \"./guards\";\nimport { type ParseStandardConfig, parseStandard } from \"./parse-standard\";\nimport { safeExecute } from \"./utils/errors\";\n\n/**\n * Configuration options for the `arkenv/standard` entry's `arkenv`.\n */\nexport type StandardEnvConfig = ParseStandardConfig;\n\n/**\n * Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).\n *\n * This entry is ArkType-free - ArkType is never imported, even transitively.\n * Use this when your project must not depend on ArkType.\n *\n * @param def An object mapping variable names to Standard Schema validators\n * @param config Optional configuration\n * @returns The validated environment variables, or a SafeArkEnvResult if `{ safe: true }` is configured\n * @throws An {@link ArkEnvError} if validation fails and `safe` is not enabled\n *\n * @example\n * ```ts\n * import arkenv from \"arkenv/standard\";\n * import { z } from \"zod\";\n *\n * const env = arkenv({\n * PORT: z.coerce.number(),\n * HOST: z.string(),\n * });\n * ```\n */\nexport function arkenv<const T extends Record<string, StandardSchemaV1>>(\n\tdef: T,\n\tconfig?: StandardEnvConfig & { safe?: false },\n): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };\nexport function arkenv<const T extends Record<string, StandardSchemaV1>>(\n\tdef: T,\n\tconfig: StandardEnvConfig & { safe: true },\n): SafeArkEnvResult<{ [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> }>;\nexport function arkenv<const T extends Record<string, StandardSchemaV1>>(\n\tdef: T,\n\tconfig: StandardEnvConfig = {},\n):\n\t| { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> }\n\t| SafeArkEnvResult<{ [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> }> {\n\tassertStandardSchemaMap(def);\n\n\tfor (const key in def) {\n\t\tconst validator = (def as Record<string, unknown>)[key];\n\t\tassertNotArkTypeDsl(key, validator);\n\t\tassertStandardSchema(key, validator);\n\t}\n\n\tif (config.safe) {\n\t\treturn safeExecute(\n\t\t\t() =>\n\t\t\t\tparseStandard(def as Record<string, unknown>, config) as {\n\t\t\t\t\t[K in keyof T]: StandardSchemaV1.InferOutput<T[K]>;\n\t\t\t\t},\n\t\t);\n\t}\n\n\treturn parseStandard(def as Record<string, unknown>, config) as {\n\t\t[K in keyof T]: StandardSchemaV1.InferOutput<T[K]>;\n\t};\n}\n\n/**\n * ArkEnv's Standard Schema export\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nexport default arkenv;\n"],"mappings":"qHAMA,SAAgB,EAAoB,EAAa,EAAsB,CACtE,GAAI,OAAO,GAAU,SACpB,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,EACN,QACC,8JACD,KAAM,iBACN,CACD,CAAC,CASJ,SAAgB,EAAqB,EAAa,EAAsB,CACvE,IAAM,EACL,GACA,OAAO,GAAU,UACjB,cAAe,GACd,EAAkC,aAEpC,GACC,CAAC,GACD,OAAO,GAAQ,UACf,EAAE,aAAc,IAChB,OAAQ,EAAgC,UAAa,WAErD,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,EACN,QACC,6IACD,KAAM,iBACN,CACD,CAAC,CAQJ,SAAgB,EACf,EACyC,CACzC,GAAI,CAAC,GAAO,OAAO,GAAQ,UAAY,MAAM,QAAQ,EAAI,CACxD,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,GACN,QACC,iEACD,KAAM,iBACN,CACD,CAAC,CCxDJ,SAAgB,EAAkB,EAIhC,CACD,IAAM,EAAkC,CAAE,KAAM,SAAU,WAAY,EAAE,CAAE,CACtE,EAAgB,GACd,EAAwB,EAAE,CAEhC,IAAK,IAAM,KAAO,EAAK,CACtB,IAAM,EAAY,EAAI,GACtB,GAAI,CAAC,EAAW,CACf,EAAY,KAAK,EAAI,CACrB,SAID,IAAM,EAAM,EAAU,aACtB,GAAI,OAAO,GAAK,YAAY,OAAU,WACrC,GAAI,CACH,IAAM,EAAS,EAAI,WAAW,MAAM,CAAE,OAAQ,WAAY,CAAC,CAC3D,GAAI,EAAQ,CACX,EAAW,WAAW,GAAO,EAC7B,EAAgB,GAChB,eAEM,EAIT,GAAI,OAAO,E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