arkenv 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/core-Byznlywt.cjs +11 -0
  2. package/dist/core-DzT5rjcY.mjs +6 -0
  3. package/dist/core-DzT5rjcY.mjs.map +1 -0
  4. package/dist/core.cjs +8 -0
  5. package/dist/core.d.cts +45 -0
  6. package/dist/core.d.cts.map +1 -0
  7. package/dist/core.d.mts +39 -0
  8. package/dist/core.d.mts.map +1 -0
  9. package/dist/core.mjs +1 -0
  10. package/dist/{create-env-BDbKkDKm.d.mts → index-Cic20SzT.d.mts} +85 -165
  11. package/dist/index-Cic20SzT.d.mts.map +1 -0
  12. package/dist/{create-env-D7N4rUVE.d.cts → index-bSO6Cmhi.d.cts} +85 -165
  13. package/dist/index-bSO6Cmhi.d.cts.map +1 -0
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.d.cts +153 -28
  16. package/dist/index.d.cts.map +1 -1
  17. package/dist/index.d.mts +153 -28
  18. package/dist/index.d.mts.map +1 -1
  19. package/dist/index.mjs +1 -1
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/standard.cjs +8 -0
  22. package/dist/standard.d.cts +70 -0
  23. package/dist/standard.d.cts.map +1 -0
  24. package/dist/standard.d.mts +64 -0
  25. package/dist/standard.d.mts.map +1 -0
  26. package/dist/standard.mjs +3 -0
  27. package/dist/standard.mjs.map +1 -0
  28. package/package.json +22 -10
  29. package/dist/arktype/index.cjs +0 -8
  30. package/dist/arktype/index.d.cts +0 -116
  31. package/dist/arktype/index.d.cts.map +0 -1
  32. package/dist/arktype/index.d.mts +0 -110
  33. package/dist/arktype/index.d.mts.map +0 -1
  34. package/dist/arktype/index.mjs +0 -3
  35. package/dist/arktype/index.mjs.map +0 -1
  36. package/dist/create-env-BDbKkDKm.d.mts.map +0 -1
  37. package/dist/create-env-D7N4rUVE.d.cts.map +0 -1
  38. package/dist/errors-Bi-pULbt.mjs +0 -7
  39. package/dist/errors-Bi-pULbt.mjs.map +0 -1
  40. package/dist/errors-BtUS5QYF.cjs +0 -12
package/dist/index.d.mts CHANGED
@@ -1,38 +1,163 @@
1
- import { n as EnvSchema, r as createEnv, t as ArkEnvConfig } from "./create-env-BDbKkDKm.mjs";
2
- import { ArkErrors } from "arktype";
1
+ import { ArkEnvError } from "./core.mjs";
2
+ import { a as Dict, n as SchemaShape, o as $, r as InferType, t as CompiledEnvSchema } from "./index-Cic20SzT.mjs";
3
+ import * as arktype0 from "arktype";
4
+ import { distill, type as type$1 } from "arktype";
5
+ import * as arktype_internal_keywords_string_ts0 from "arktype/internal/keywords/string.ts";
6
+ import * as arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
7
+ import * as arktype_internal_type_ts0 from "arktype/internal/type.ts";
8
+
9
+ //#region src/create-env.d.ts
3
10
 
4
- //#region src/errors.d.ts
5
- type InternalValidationError = {
6
- path: string;
7
- message: string;
8
- };
9
11
  /**
10
- * Error thrown when environment variable validation fails.
12
+ * Declarative environment schema definition accepted by ArkEnv.
11
13
  *
12
- * This error extends the native `Error` class and provides formatted error messages
13
- * that clearly indicate which environment variables are invalid and why.
14
+ * Represents a declarative schema object mapping environment
15
+ * variable names to schema definitions (e.g. ArkType DSL strings
16
+ * or Standard Schema validators).
14
17
  *
15
- * @example
16
- * ```ts
17
- * import { createEnv, ArkEnvError } from 'arkenv';
18
+ * This type is used to validate that a schema object is compatible with
19
+ * ArkEnv’s validator scope before being compiled or parsed.
18
20
  *
19
- * try {
20
- * const env = createEnv({
21
- * PORT: 'number.port',
22
- * HOST: 'string.host',
23
- * });
24
- * } catch (error) {
25
- * if (error instanceof ArkEnvError) {
26
- * console.error('Environment validation failed:', error.message);
27
- * }
28
- * }
29
- * ```
21
+ * Most users will provide schemas in this form.
22
+ *
23
+ * @template def - The schema shape object
24
+ */
25
+ type EnvSchema<def$1> = type$1.validate<def$1, $>;
26
+ type RuntimeEnvironment = Dict<string>;
27
+ /**
28
+ * Configuration options for `createEnv`
29
+ */
30
+ type ArkEnvConfig = {
31
+ /**
32
+ * The environment variables to parse. Defaults to `process.env`
33
+ */
34
+ env?: RuntimeEnvironment;
35
+ /**
36
+ * Whether to coerce environment variables to their defined types. Defaults to `true`
37
+ */
38
+ coerce?: boolean;
39
+ /**
40
+ * Control how ArkEnv handles environment variables that are not defined in your schema.
41
+ *
42
+ * Defaults to `'delete'` to ensure your output object only contains
43
+ * keys you've explicitly declared. This differs from ArkType's standard behavior, which
44
+ * mirrors TypeScript by defaulting to `'ignore'`.
45
+ *
46
+ * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
47
+ * - `ignore` (ArkType default): Undeclared keys are allowed and preserved in the output.
48
+ * - `reject`: Undeclared keys will cause validation to fail.
49
+ *
50
+ * @default "delete"
51
+ * @see https://arktype.io/docs/configuration#onundeclaredkey
52
+ */
53
+ onUndeclaredKey?: "ignore" | "delete" | "reject";
54
+ /**
55
+ * The format to use for array parsing when coercion is enabled.
56
+ *
57
+ * - `comma` (default): Strings are split by comma and trimmed.
58
+ * - `json`: Strings are parsed as JSON.
59
+ *
60
+ * @default "comma"
61
+ */
62
+ arrayFormat?: "comma" | "json";
63
+ };
64
+ /**
65
+ * TODO: `SchemaShape` is basically `Record<string, unknown>`.
66
+ * If possible, find a better type than "const T extends Record<string, unknown>",
67
+ * and be as close as possible to the type accepted by ArkType's `type`.
68
+ */
69
+ /**
70
+ * Utility to parse environment variables using ArkType or Standard Schema
71
+ * @param def - The schema definition
72
+ * @param config - The evaluation configuration
73
+ * @returns The parsed environment variables
74
+ * @throws An {@link ArkEnvError | error} if the environment variables are invalid.
30
75
  */
31
- declare class ArkEnvError extends Error {
32
- constructor(errors: ArkErrors | InternalValidationError[], message?: string);
33
- }
76
+ declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>>;
77
+ declare function createEnv<T extends CompiledEnvSchema>(def: T, config?: ArkEnvConfig): InferType<T>;
78
+ declare function createEnv<const T extends SchemaShape>(def: EnvSchema<T> | CompiledEnvSchema, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>> | InferType<typeof def>;
34
79
  //#endregion
35
80
  //#region src/index.d.ts
81
+ /**
82
+ * Like ArkType's `type`, but with ArkEnv's extra keywords, such as:
83
+ *
84
+ * - `string.host` – a hostname (e.g. `"localhost"`, `"127.0.0.1"`)
85
+ * - `number.port` – a port number (e.g. `8080`)
86
+ *
87
+ * See ArkType's docs for the full API:
88
+ * https://arktype.io/docs/type-api
89
+ */
90
+ declare const type: arktype_internal_type_ts0.TypeParser<{
91
+ string: arktype0.Submodule<{
92
+ trim: arktype0.Submodule<arktype_internal_keywords_string_ts0.trim.$ & {
93
+ " arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
94
+ }>;
95
+ normalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.normalize.$ & {
96
+ " arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
97
+ }>;
98
+ root: string;
99
+ alpha: string;
100
+ alphanumeric: string;
101
+ hex: string;
102
+ base64: arktype0.Submodule<{
103
+ root: string;
104
+ url: string;
105
+ } & {
106
+ " arkInferred": string;
107
+ }>;
108
+ capitalize: arktype0.Submodule<arktype_internal_keywords_string_ts0.capitalize.$ & {
109
+ " arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
110
+ }>;
111
+ creditCard: string;
112
+ date: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringDate.$ & {
113
+ " arkInferred": string;
114
+ }>;
115
+ digits: string;
116
+ email: string;
117
+ integer: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringInteger.$ & {
118
+ " arkInferred": string;
119
+ }>;
120
+ ip: arktype0.Submodule<arktype_internal_keywords_string_ts0.ip.$ & {
121
+ " arkInferred": string;
122
+ }>;
123
+ json: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringJson.$ & {
124
+ " arkInferred": string;
125
+ }>;
126
+ lower: arktype0.Submodule<arktype_internal_keywords_string_ts0.lower.$ & {
127
+ " arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
128
+ }>;
129
+ numeric: arktype0.Submodule<arktype_internal_keywords_string_ts0.stringNumeric.$ & {
130
+ " arkInferred": string;
131
+ }>;
132
+ regex: string;
133
+ semver: string;
134
+ upper: arktype0.Submodule<{
135
+ root: (In: string) => arktype_internal_attributes_ts0.To<string>;
136
+ preformatted: string;
137
+ } & {
138
+ " arkInferred": (In: string) => arktype_internal_attributes_ts0.To<string>;
139
+ }>;
140
+ url: arktype0.Submodule<arktype_internal_keywords_string_ts0.url.$ & {
141
+ " arkInferred": string;
142
+ }>;
143
+ uuid: arktype0.Submodule<arktype_internal_keywords_string_ts0.uuid.$ & {
144
+ " arkInferred": string;
145
+ }>;
146
+ " arkInferred": string;
147
+ host: string;
148
+ }>;
149
+ number: arktype0.Submodule<{
150
+ NaN: number;
151
+ Infinity: number;
152
+ root: number;
153
+ integer: number;
154
+ " arkInferred": number;
155
+ epoch: number;
156
+ safe: number;
157
+ NegativeInfinity: number;
158
+ port: number;
159
+ }>;
160
+ }>;
36
161
  /**
37
162
  * ArkEnv's main export, an alias for {@link createEnv}
38
163
  *
@@ -40,6 +165,6 @@ declare class ArkEnvError extends Error {
40
165
  */
41
166
  declare const arkenv: typeof createEnv;
42
167
  //#endregion
43
- export { type ArkEnvConfig, ArkEnvError, type EnvSchema, createEnv, arkenv as default };
168
+ export { type ArkEnvConfig, ArkEnvError, type EnvSchema, createEnv, arkenv as default, type };
44
169
 
45
170
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;KAIY,uBAAA;;;AAAZ,CAAA;;ACA0C;;;;;;;;;;;;;;;;;;;;;cDyF7B,WAAA,SAAoB,KAAA;sBAEvB,YAAY;;;;AA3FtB;AAyFA;;;;cClFM,MDkFgC,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A;MAAG,GAAA,EAAA,MAAA;IACE,CAAA,GAAA;MAAoB,cAAA,EAAA,MAAA;IAC9B,CAAA,CAAA;IACI,UAAA,oBAAA,qDAAA;MACG,cAAA,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,qCAAA,CAAA,MAAA,CAAA;IAAV,CAAA,CAAA;IAAS,UAAA,EAAA,MAAA;IACI,IAAA,oBAAS,qDAAA;MAAiB,cAAA,EAAA,MAAA;IAC1B,CAAA,CAAA;IAAV,MAAA,EAAA,MAAA;IAAe,KAAA,EAAA,MAAA;IACX,OAAA,oBAAA,wDAAA;MACc,cAAA,EAAA,MAAA;IAAG,CAAA,CAAA;IAAT,EAAA,oBAAA,6CAAA;MAAP,cAAA,EAAA,MAAA;IAAuC,CAAA,CAAA;IAAjB,IAAA,oBAAA,qDAAA;MAAS,cAAA,EAAA,MAAA;;;;IC9E7B,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE+C;;;;;cAOtD,eAAM"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import{t as e}from"./errors-Bi-pULbt.mjs";import{createRequire as t}from"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(o);return a}function r(e){return typeof e==`object`&&!!e&&`message`in e&&typeof e.message==`string`}function i(){let e=(()=>{try{let e=import.meta;if(e?.url)return t(e.url)}catch{}try{let e=typeof module<`u`?module:void 0;if(e?.require)return e.require.bind(e)}catch{}try{return t(`${process.cwd()}/index.js`)}catch{}})();if(!e)throw Error(`ArkEnv was unable to load the ArkType validator because neither 'createRequire' nor 'require' are available in this environment.`);let n=[`arkenv/arktype`,`./arktype.cjs`,`../arktype.cjs`,`./arktype/index.cjs`,`../arktype/index.cjs`,`./arktype`,`../arktype`,`./arktype/index.ts`,`../arktype/index.ts`],i;for(let t of n)try{return e(t)}catch(e){if(i=e,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 a=r(i)?i.message:``;throw r(i)&&i.code===`MODULE_NOT_FOUND`&&(a.includes(`'arktype'`)||a.includes(`"arktype"`)||a.includes(`Cannot find module 'arktype'`))&&!a.includes(`./arktype`)&&!a.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).`):i}function a(t,r={}){if((r.validator??`arktype`)===`standard`){if(!t||typeof t!=`object`||Array.isArray(t))throw new e([{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([{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([{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,r)}let{parse:a}=i();return a(t,r)}var o=a;export{e as ArkEnvError,a as createEnv,o as default};
1
+ import{r as e,t}from"./core-DzT5rjcY.mjs";import{ArkErrors as n,scope as r,type as i}from"arktype";const a=i(`0 <= number.integer <= 65535`),o=i(`string.ip | 'localhost'`),s=r({string:i.module({...i.keywords.string,host:o}),number:i.module({...i.keywords.number,port:a})}),c=e=>{if(typeof e==`number`||typeof e!=`string`)return e;let t=e.trim();if(t===``)return e;if(t===`NaN`)return NaN;let n=Number(t);return Number.isNaN(n)?e:n},l=e=>e===`true`?!0:e===`false`?!1:e,u=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}},d=(e,t=[])=>{let n=[];if(typeof e==`boolean`)return n;if(`const`in e&&(typeof e.const==`number`||typeof e.const==`boolean`)&&n.push({path:[...t],type:`primitive`}),`enum`in e&&e.enum&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`}),`type`in e)if(e.type===`number`||e.type===`integer`)n.push({path:[...t],type:`primitive`});else if(e.type===`boolean`)n.push({path:[...t],type:`primitive`});else if(e.type===`object`){if(`properties`in e&&e.properties&&Object.keys(e.properties).length>0&&n.push({path:[...t],type:`object`}),`properties`in e&&e.properties)for(let[r,i]of Object.entries(e.properties))n.push(...d(i,[...t,r]))}else e.type===`array`&&(n.push({path:[...t],type:`array`}),`items`in e&&e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...d(e,[...t,`${r}`]))}):n.push(...d(e.items,[...t,`*`]))));if(`anyOf`in e&&e.anyOf)for(let r of e.anyOf)n.push(...d(r,t));if(`allOf`in e&&e.allOf)for(let r of e.allOf)n.push(...d(r,t));if(`oneOf`in e&&e.oneOf)for(let r of e.oneOf)n.push(...d(r,t));let r=new Set;return n.filter(e=>{let t=JSON.stringify(e.path)+e.type;return r.has(t)?!1:(r.add(t),!0)})},f=(e,t,n={})=>{let{arrayFormat:r=`comma`}=n,i=e=>{if(r===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]};if(typeof e!=`object`||!e){if(t.some(e=>e.path.length===0)){let n=t.find(e=>e.path.length===0);if(n?.type===`object`&&typeof e==`string`)return u(e);if(n?.type===`array`&&typeof e==`string`)return i(e);let r=c(e);return typeof r==`number`?r:l(e)}return e}let a=[...t].sort((e,t)=>e.path.length-t.path.length),o=(e,t,n)=>{if(!e||typeof e!=`object`||t.length===0)return;if(t.length===1){let r=t[0];if(r===`*`){if(Array.isArray(e))for(let t=0;t<e.length;t++){let r=e[t];if(n===`primitive`){let n=c(r);typeof n==`number`?e[t]=n:e[t]=l(r)}else n===`object`&&(e[t]=u(r))}return}let a=e;if(Object.prototype.hasOwnProperty.call(a,r)){let e=a[r];if(n===`array`&&typeof e==`string`){a[r]=i(e);return}if(n===`object`&&typeof e==`string`){a[r]=u(e);return}if(Array.isArray(e)){if(n===`primitive`)for(let t=0;t<e.length;t++){let n=e[t],r=c(n);typeof r==`number`?e[t]=r:e[t]=l(n)}}else if(n===`primitive`){let t=c(e);typeof t==`number`?a[r]=t:a[r]=l(e)}}return}let[r,...a]=t;if(r===`*`){if(Array.isArray(e))for(let t of e)o(t,a,n);return}o(e[r],a,n)};for(let t of a)o(e,t.path,t.type);return e};function p(e,t,n){let r=d(t.in.toJsonSchema({fallback:e=>e.base}));return r.length===0?t:e(`unknown`).pipe(e=>f(e,r,n)).pipe(t)}function m(t){return Object.entries(t.byPath).map(([t,n])=>{let r=n.message,i=r.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(t.toLowerCase())){let e=i.slice(t.length).trimStart();e.length>0&&`:.-`.includes(e[0])&&(e=e.slice(1)),r=e.trimStart()}let a=r.match(/\(was (.*)\)/);if(a?.[1]){let t=a[1];t.includes(`\x1B[`)||(r=r.replace(`(was ${t})`,`(was ${e(`cyan`,t)})`))}return{path:t,message:r}})}function h(e,r){let{env:i=process.env,coerce:a=!0,onUndeclaredKey:o=`delete`,arrayFormat:c=`comma`}=r,l=(typeof e==`function`&&`assert`in e?e:s.type.raw(e)).onUndeclaredKey(o),u=l;a&&(u=p(s.type,l,{arrayFormat:c}));let d=u(i);if(d instanceof n)throw new t(m(d));return d}function g(e,t={}){return h(e,t)}const _=s.type;var v=g;export{t as ArkEnvError,g as createEnv,v as default,_ as type};
2
2
 
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["output: Record<string, unknown>","errors: InternalValidationError[]","lastError: unknown","msg"],"sources":["../src/parse-standard.ts","../src/utils/load-arktype.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@repo/types\";\nimport type { ArkEnvConfig } from \"./create-env.ts\";\nimport { ArkEnvError, type InternalValidationError } from \"./errors.ts\";\n\n/**\n * Standard Schema 1.0 parser dispatcher.\n * This helper implements parsing for the 'validator: \"standard\"' mode.\n */\nexport function parseStandard(\n\tdef: Record<string, unknown>,\n\tconfig: ArkEnvConfig,\n) {\n\tconst { env = process.env, onUndeclaredKey = \"delete\" } = config;\n\tconst output: Record<string, unknown> = {};\n\tconst errors: InternalValidationError[] = [];\n\tconst envKeys = new Set(Object.keys(env));\n\n\t// 1. Validate declared keys\n\tfor (const key in def) {\n\t\tconst validator = def[key];\n\t\tconst value = env[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 Error(\n\t\t\t\t`Invalid schema for key \"${key}\": expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in \"standard\" mode.`,\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 Error(\n\t\t\t\t`Async validation is not supported for key \"${key}\". ArkEnv is synchronous.`,\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\terrors.push({\n\t\t\t\t\tpath: key,\n\t\t\t\t\tmessage: issue.message,\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({\n\t\t\t\t\tpath: key,\n\t\t\t\t\tmessage: \"Undeclared key\",\n\t\t\t\t});\n\t\t\t} else if (onUndeclaredKey === \"ignore\") {\n\t\t\t\toutput[key] = env[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 { createRequire } from \"node:module\";\n\n/**\n * An object that looks like an Error, containing at least a message and optionally a code.\n */\ntype ErrorLike = {\n\tmessage: string;\n\tcode?: string;\n};\n\nfunction isErrorLike(error: unknown): error is ErrorLike {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"message\" in error &&\n\t\ttypeof (error as Record<string, unknown>).message === \"string\"\n\t);\n}\n\n/**\n * Dynamically loads the ArkType validator module.\n * Provides a clear error message if the 'arktype' peer dependency is missing.\n */\nexport function loadArkTypeValidator() {\n\tconst _require = (() => {\n\t\ttry {\n\t\t\t// 1. ESM: Try to use import.meta.url\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: import.meta is not fully typed\n\t\t\tconst meta = import.meta as any;\n\t\t\tif (meta?.url) {\n\t\t\t\treturn createRequire(meta.url);\n\t\t\t}\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\ttry {\n\t\t\t// 2. CommonJS: Use module.require if available\n\t\t\t// This is safer than eval and respects the local module scope.\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: module is a global in CJS\n\t\t\tconst m = typeof module !== \"undefined\" ? (module as any) : undefined;\n\t\t\tif (m?.require) {\n\t\t\t\treturn m.require.bind(m);\n\t\t\t}\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\ttry {\n\t\t\t// 3. Generic Node: Try to use createRequire with the current directory\n\t\t\t// This works in both ESM and CJS if node:module is available.\n\t\t\treturn createRequire(`${process.cwd()}/index.js`);\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\treturn undefined;\n\t})();\n\n\tif (!_require) {\n\t\tthrow new Error(\n\t\t\t\"ArkEnv was unable to load the ArkType validator because neither 'createRequire' \" +\n\t\t\t\t\"nor 'require' are available in this environment.\",\n\t\t);\n\t}\n\n\t// We try multiple paths to support both source execution (src/utils/load-arktype.ts)\n\t// and bundled execution (dist/index.js or dist/index.cjs where this is inlined).\n\tconst searchPaths = [\n\t\t\"arkenv/arktype\",\n\t\t\"./arktype.cjs\",\n\t\t\"../arktype.cjs\",\n\t\t\"./arktype/index.cjs\",\n\t\t\"../arktype/index.cjs\",\n\t\t\"./arktype\",\n\t\t\"../arktype\",\n\t\t\"./arktype/index.ts\",\n\t\t\"../arktype/index.ts\",\n\t];\n\n\tlet lastError: unknown;\n\n\tfor (const path of searchPaths) {\n\t\ttry {\n\t\t\treturn _require(path);\n\t\t} catch (e) {\n\t\t\tlastError = e;\n\n\t\t\tif (isErrorLike(e) && e.code === \"MODULE_NOT_FOUND\") {\n\t\t\t\tconst msg = e.message || \"\";\n\t\t\t\t// Nested failure: The error is about 'arktype' (the package) but we were trying to load a relative path.\n\t\t\t\tconst isNestedArkTypeFailure =\n\t\t\t\t\t(msg.includes(\"'arktype'\") ||\n\t\t\t\t\t\tmsg.includes('\"arktype\"') ||\n\t\t\t\t\t\tmsg.includes(\"Cannot find module 'arktype'\")) &&\n\t\t\t\t\t!msg.includes(path);\n\n\t\t\t\tif (isNestedArkTypeFailure) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// If we reach here, either we searched all paths and none worked,\n\t// or we broke early because of a missing peer dependency.\n\tconst msg = isErrorLike(lastError) ? lastError.message : \"\";\n\t// Simpler heuristic: if the code is MODULE_NOT_FOUND and the message contains 'arktype'\n\t// but doesn't look like a relative path error for the current try.\n\tconst isMissingArkType =\n\t\tisErrorLike(lastError) &&\n\t\tlastError.code === \"MODULE_NOT_FOUND\" &&\n\t\t(msg.includes(\"'arktype'\") ||\n\t\t\tmsg.includes('\"arktype\"') ||\n\t\t\tmsg.includes(\"Cannot find module 'arktype'\")) &&\n\t\t!msg.includes(\"./arktype\") &&\n\t\t!msg.includes(\"../arktype\");\n\n\tif (isMissingArkType) {\n\t\tthrow new Error(\n\t\t\t\"The 'arktype' package is required when using the default validator mode. \" +\n\t\t\t\t\"Please install it (npm install arktype) or set 'validator: \\\"standard\\\"' in your config \" +\n\t\t\t\t\"if you only intend to use Standard Schema validators (like Zod or Valibot).\",\n\t\t);\n\t}\n\n\t// If it's some other error (like a syntax error in the validator), propagate it\n\tthrow lastError;\n}\n","import type { $ } from \"@repo/scope\";\nimport type {\n\tCompiledEnvSchema,\n\tDict,\n\tInferType,\n\tSchemaShape,\n\tStandardSchemaV1,\n} from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { ArkEnvError } from \"./errors.ts\";\nimport { parseStandard } from \"./parse-standard.ts\";\nimport { loadArkTypeValidator } from \"./utils/load-arktype.ts\";\n\n/**\n * Declarative environment schema definition accepted by ArkEnv.\n *\n * Represents a declarative schema object mapping environment\n * variable names to schema definitions (e.g. ArkType DSL strings\n * or Standard Schema validators).\n *\n * This type is used to validate that a schema object is compatible with\n * ArkEnv’s validator scope before being compiled or parsed.\n *\n * Most users will provide schemas in this form.\n *\n * @template def - The schema shape object\n */\nexport type EnvSchema<def> = at.validate<def, $>;\ntype RuntimeEnvironment = Dict<string>;\n\n/**\n * Configuration options for `createEnv`\n */\nexport type ArkEnvConfig = {\n\t/**\n\t * The environment variables to parse. Defaults to `process.env`\n\t */\n\tenv?: RuntimeEnvironment;\n\t/**\n\t * Whether to coerce environment variables to their defined types. Defaults to `true`\n\t */\n\tcoerce?: boolean;\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. This differs from ArkType's standard behavior, which\n\t * mirrors TypeScript by defaulting to `'ignore'`.\n\t *\n\t * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.\n\t * - `ignore` (ArkType default): 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 * @see https://arktype.io/docs/configuration#onundeclaredkey\n\t */\n\tonUndeclaredKey?: \"ignore\" | \"delete\" | \"reject\";\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\t/**\n\t * Choose the validator engine to use.\n\t *\n\t * - `arktype` (default): Uses ArkType for all validation and coercion.\n\t * - `standard`: Uses Standard Schema 1.0 directly for validation. Coercion is not supported in this mode.\n\t *\n\t * @default \"arktype\"\n\t */\n\tvalidator?: \"arktype\" | \"standard\";\n};\n\n/**\n * TODO: `SchemaShape` is basically `Record<string, unknown>`.\n * If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Utility to parse environment variables using ArkType or Standard Schema\n * @param def - The schema definition\n * @param config - The evaluation configuration\n * @returns The parsed environment variables\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends Record<string, StandardSchemaV1>>(\n\tdef: T,\n\tconfig: ArkEnvConfig & { validator: \"standard\" },\n): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>>;\nexport function createEnv<T extends CompiledEnvSchema>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig: ArkEnvConfig = {},\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\tconst mode = config.validator ?? \"arktype\";\n\n\tif (mode === \"standard\") {\n\t\t// Runtime guard: reject ArkType values in standard mode\n\t\tif (!def || typeof def !== \"object\" || Array.isArray(def)) {\n\t\t\tthrow new ArkEnvError([\n\t\t\t\t{\n\t\t\t\t\tpath: \"\",\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t'Invalid schema: expected an object mapping in \"standard\" mode.',\n\t\t\t\t},\n\t\t\t]);\n\t\t}\n\n\t\t// Check each entry to ensure it's a Standard Schema validator\n\t\tfor (const key in def) {\n\t\t\tconst validator = (def as Record<string, unknown>)[key];\n\n\t\t\t// Reject strings (ArkType DSL)\n\t\t\tif (typeof validator === \"string\") {\n\t\t\t\tthrow new ArkEnvError([\n\t\t\t\t\t{\n\t\t\t\t\t\tpath: key,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t'ArkType DSL strings are not supported in \"standard\" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or set validator: \"arktype\".',\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t}\n\n\t\t\t// Reject non-objects or objects without ~standard property (likely ArkType)\n\t\t\tif (\n\t\t\t\t!validator ||\n\t\t\t\ttypeof validator !== \"object\" ||\n\t\t\t\t!(\"~standard\" in validator)\n\t\t\t) {\n\t\t\t\tthrow new ArkEnvError([\n\t\t\t\t\t{\n\t\t\t\t\t\tpath: key,\n\t\t\t\t\t\tmessage:\n\t\t\t\t\t\t\t'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.',\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\n\t\treturn parseStandard(def as Record<string, unknown>, config);\n\t}\n\n\tconst validator = loadArkTypeValidator();\n\tconst { parse } = validator;\n\n\treturn parse(def, config);\n}\n","import { createEnv } from \"./create-env.ts\";\n\nexport { createEnv };\nexport type { ArkEnvConfig, EnvSchema } from \"./create-env.ts\";\nexport { ArkEnvError } from \"./errors.ts\";\n\n/**\n * ArkEnv's main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nconst arkenv = createEnv;\nexport default arkenv;\n"],"mappings":"sFAQA,SAAgB,EACf,EACA,EACC,CACD,GAAM,CAAE,MAAM,QAAQ,IAAK,kBAAkB,UAAa,EACpDA,EAAkC,EAAE,CACpCC,EAAoC,EAAE,CACtC,EAAU,IAAI,IAAI,OAAO,KAAK,EAAI,CAAC,CAGzC,IAAK,IAAM,KAAO,EAAK,CACtB,IAAM,EAAY,EAAI,GAChB,EAAQ,EAAI,GAGlB,GACC,CAAC,GACD,OAAO,GAAc,UACrB,EAAE,cAAe,GAEjB,MAAU,MACT,2BAA2B,EAAI,qFAC/B,CAGF,IAAM,EAAU,EAA+B,aAAa,SAAS,EAAM,CAE3E,GAAI,aAAkB,QACrB,MAAU,MACT,8CAA8C,EAAI,2BAClD,CAGF,GAAI,EAAO,OACV,IAAK,IAAM,KAAS,EAAO,OAC1B,EAAO,KAAK,CACX,KAAM,EACN,QAAS,EAAM,QACf,CAAC,MAGH,EAAO,GAAO,EAAO,MAGtB,EAAQ,OAAO,EAAI,CAIpB,GAAI,IAAoB,aAClB,IAAM,KAAO,EACb,IAAoB,SACvB,EAAO,KAAK,CACX,KAAM,EACN,QAAS,iBACT,CAAC,CACQ,IAAoB,WAC9B,EAAO,GAAO,EAAI,IAKrB,GAAI,EAAO,OAAS,EACnB,MAAM,IAAI,EAAY,EAAO,CAG9B,OAAO,EC/DR,SAAS,EAAY,EAAoC,CACxD,OACC,OAAO,GAAU,YACjB,GACA,YAAa,GACb,OAAQ,EAAkC,SAAY,SAQxD,SAAgB,GAAuB,CACtC,IAAM,OAAkB,CACvB,G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OAAO,GAAc,SACxB,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,EACN,QACC,8IACD,CACD,CAAC,CAIH,GACC,CAAC,GACD,OAAO,GAAc,UACrB,EAAE,cAAe,GAEjB,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,EACN,QACC,uMACD,CACD,CAAC,CAIJ,OAAO,EAAc,EAAgC,EAAO,CAI7D,GAAM,CAAE,SADU,GAAsB,CAGxC,OAAO,EAAM,EAAK,EAAO,CClJ1B,IAAA,EADe"}
1
+ {"version":3,"file":"index.mjs","names":["t","e","n","i","type","$","$"],"sources":["../../internal/scope/dist/index.js","../src/arktype/coercion/morphs.ts","../src/arktype/coercion/coerce.ts","../src/arktype/index.ts","../src/create-env.ts","../src/index.ts"],"sourcesContent":["import{scope as e,type as t}from\"arktype\";const n=t(`0 <= number.integer <= 65535`),r=t(`string.ip | 'localhost'`),i=e({string:t.module({...t.keywords.string,host:r}),number:t.module({...t.keywords.number,port:n})});export{i as $};\n//# sourceMappingURL=index.js.map","/**\n * Attempt to coerce a value to a number.\n *\n * If the input is already a number, returns it unchanged.\n * If the input is a string that can be parsed as a number, returns the parsed number.\n * Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced number or the original value\n */\nexport const coerceNumber = (s: unknown) => {\n\tif (typeof s === \"number\") return s;\n\tif (typeof s !== \"string\") return s;\n\tconst trimmed = s.trim();\n\tif (trimmed === \"\") return s;\n\tif (trimmed === \"NaN\") return Number.NaN;\n\tconst n = Number(trimmed);\n\treturn Number.isNaN(n) ? s : n;\n};\n\n/**\n * Attempt to coerce a value to a boolean.\n *\n * Convert the strings \"true\" and \"false\" to their boolean equivalents.\n * All other values are returned unchanged.\n *\n * @internal\n * @param s - The value to coerce\n * @returns The coerced boolean or the original value\n */\nexport const coerceBoolean = (s: unknown) => {\n\tif (s === \"true\") return true;\n\tif (s === \"false\") return false;\n\treturn s;\n};\n\n/**\n * Attempt to parse a value as JSON.\n *\n * If the input is a string that starts with `{` or `[` and can be parsed as JSON,\n * returns the parsed object or array. Otherwise, returns the original value unchanged.\n *\n * @internal\n * @param s - The value to parse\n * @returns The parsed JSON or the original value\n */\nexport const coerceJson = (s: unknown) => {\n\tif (typeof s !== \"string\") return s;\n\tconst trimmed = s.trim();\n\tif (!trimmed.startsWith(\"{\") && !trimmed.startsWith(\"[\")) return s;\n\ttry {\n\t\treturn JSON.parse(trimmed);\n\t} catch {\n\t\treturn s;\n\t}\n};\n","import type { BaseType, JsonSchema } from \"arktype\";\nimport { coerceBoolean, coerceJson, coerceNumber } from \"./morphs.ts\";\n\n/**\n * A marker used in the coercion path to indicate that the target\n * is the *elements* of an array, rather than the array property itself.\n */\nconst ARRAY_ITEM_MARKER = \"*\";\n\n/**\n * @internal\n * Information about a path in the schema that requires coercion.\n */\ntype CoercionTarget = {\n\tpath: string[];\n\ttype: \"primitive\" | \"array\" | \"object\";\n};\n\n/**\n * Options for coercion behavior.\n */\nexport type CoerceOptions = {\n\t/**\n\t * format to use for array parsing\n\t * @default \"comma\"\n\t */\n\tarrayFormat?: \"comma\" | \"json\";\n};\n\n/**\n * Recursively find all paths in a JSON Schema that require coercion.\n * We prioritize \"number\", \"integer\", \"boolean\", \"array\", and \"object\" types.\n */\nconst findCoercionPaths = (\n\tnode: JsonSchema,\n\tpath: string[] = [],\n): CoercionTarget[] => {\n\tconst results: CoercionTarget[] = [];\n\n\tif (typeof node === \"boolean\") {\n\t\treturn results;\n\t}\n\n\tif (\"const\" in node) {\n\t\tif (typeof node.const === \"number\" || typeof node.const === \"boolean\") {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t}\n\t}\n\n\tif (\"enum\" in node && node.enum) {\n\t\tif (\n\t\t\tnode.enum.some((v) => typeof v === \"number\" || typeof v === \"boolean\")\n\t\t) {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t}\n\t}\n\n\tif (\"type\" in node) {\n\t\tif (node.type === \"number\" || node.type === \"integer\") {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t} else if (node.type === \"boolean\") {\n\t\t\tresults.push({ path: [...path], type: \"primitive\" });\n\t\t} else if (node.type === \"object\") {\n\t\t\t// Check if this object has properties defined\n\t\t\t// If it does, we want to coerce the whole object from a JSON string\n\t\t\t// But we also want to recursively check nested properties\n\t\t\tconst hasProperties =\n\t\t\t\t\"properties\" in node &&\n\t\t\t\tnode.properties &&\n\t\t\t\tObject.keys(node.properties).length > 0;\n\n\t\t\tif (hasProperties) {\n\t\t\t\t// Mark this path as needing object coercion (JSON parsing)\n\t\t\t\tresults.push({ path: [...path], type: \"object\" });\n\t\t\t}\n\n\t\t\t// Also recursively check nested properties for their own coercions\n\t\t\tif (\"properties\" in node && node.properties) {\n\t\t\t\tfor (const [key, prop] of Object.entries(node.properties)) {\n\t\t\t\t\tresults.push(\n\t\t\t\t\t\t...findCoercionPaths(prop as JsonSchema, [...path, key]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (node.type === \"array\") {\n\t\t\t// Mark the array itself as a target for splitting strings\n\t\t\tresults.push({ path: [...path], type: \"array\" });\n\n\t\t\tif (\"items\" in node && node.items) {\n\t\t\t\tif (Array.isArray(node.items)) {\n\t\t\t\t\t// Tuple traversal\n\t\t\t\t\tnode.items.forEach((item, index) => {\n\t\t\t\t\t\tresults.push(\n\t\t\t\t\t\t\t...findCoercionPaths(item as JsonSchema, [...path, `${index}`]),\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// List traversal\n\t\t\t\t\tresults.push(\n\t\t\t\t\t\t...findCoercionPaths(node.items as JsonSchema, [\n\t\t\t\t\t\t\t...path,\n\t\t\t\t\t\t\tARRAY_ITEM_MARKER,\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (\"anyOf\" in node && node.anyOf) {\n\t\tfor (const branch of node.anyOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\tif (\"allOf\" in node && node.allOf) {\n\t\tfor (const branch of node.allOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\tif (\"oneOf\" in node && node.oneOf) {\n\t\tfor (const branch of node.oneOf) {\n\t\t\tresults.push(...findCoercionPaths(branch as JsonSchema, path));\n\t\t}\n\t}\n\n\t// Deduplicate by path and type combination\n\tconst seen = new Set<string>();\n\treturn results.filter((t) => {\n\t\tconst key = JSON.stringify(t.path) + t.type;\n\t\tif (seen.has(key)) return false;\n\t\tseen.add(key);\n\t\treturn true;\n\t});\n};\n\n/**\n * Apply coercion to a data object based on identified paths.\n */\nconst applyCoercion = (\n\tdata: unknown,\n\ttargets: CoercionTarget[],\n\toptions: CoerceOptions = {},\n) => {\n\tconst { arrayFormat = \"comma\" } = options;\n\n\t// Helper to split string to array\n\tconst splitString = (val: string) => {\n\t\tif (arrayFormat === \"json\") {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(val);\n\t\t\t} catch {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t}\n\n\t\tif (!val.trim()) return [];\n\t\treturn val.split(\",\").map((s) => s.trim());\n\t};\n\n\tif (typeof data !== \"object\" || data === null) {\n\t\t// If root data needs coercion\n\t\tif (targets.some((t) => t.path.length === 0)) {\n\t\t\tconst rootTarget = targets.find((t) => t.path.length === 0);\n\n\t\t\tif (rootTarget?.type === \"object\" && typeof data === \"string\") {\n\t\t\t\treturn coerceJson(data);\n\t\t\t}\n\n\t\t\tif (rootTarget?.type === \"array\" && typeof data === \"string\") {\n\t\t\t\treturn splitString(data);\n\t\t\t}\n\n\t\t\tconst asNumber = coerceNumber(data);\n\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\treturn asNumber;\n\t\t\t}\n\t\t\treturn coerceBoolean(data);\n\t\t}\n\t\treturn data;\n\t}\n\n\t// Sort targets by path length to ensure parent objects/arrays are coerced before their children\n\tconst sortedTargets = [...targets].sort(\n\t\t(a, b) => a.path.length - b.path.length,\n\t);\n\n\tconst walk = (\n\t\tcurrent: unknown,\n\t\ttargetPath: string[],\n\t\ttype: \"primitive\" | \"array\" | \"object\",\n\t) => {\n\t\tif (!current || typeof current !== \"object\") return;\n\n\t\tif (targetPath.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If we've reached the last key, apply coercion\n\t\tif (targetPath.length === 1) {\n\t\t\tconst lastKey = targetPath[0];\n\n\t\t\tif (lastKey === ARRAY_ITEM_MARKER) {\n\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\tfor (let i = 0; i < current.length; i++) {\n\t\t\t\t\t\tconst original = current[i];\n\t\t\t\t\t\tif (type === \"primitive\") {\n\t\t\t\t\t\t\tconst asNumber = coerceNumber(original);\n\t\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\t\tcurrent[i] = asNumber;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrent[i] = coerceBoolean(original);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (type === \"object\") {\n\t\t\t\t\t\t\tcurrent[i] = coerceJson(original);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst record = current as Record<string, unknown>;\n\t\t\t// biome-ignore lint/suspicious/noPrototypeBuiltins: ES2020 compatibility\n\t\t\tif (Object.prototype.hasOwnProperty.call(record, lastKey)) {\n\t\t\t\tconst original = record[lastKey];\n\n\t\t\t\tif (type === \"array\" && typeof original === \"string\") {\n\t\t\t\t\trecord[lastKey] = splitString(original);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (type === \"object\" && typeof original === \"string\") {\n\t\t\t\t\trecord[lastKey] = coerceJson(original);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (Array.isArray(original)) {\n\t\t\t\t\tif (type === \"primitive\") {\n\t\t\t\t\t\tfor (let i = 0; i < original.length; i++) {\n\t\t\t\t\t\t\tconst item = original[i];\n\t\t\t\t\t\t\tconst asNumber = coerceNumber(item);\n\t\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\t\toriginal[i] = asNumber;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\toriginal[i] = coerceBoolean(item);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (type === \"primitive\") {\n\t\t\t\t\t\tconst asNumber = coerceNumber(original);\n\t\t\t\t\t\t// If numeric parsing didn't produce a number, try boolean coercion\n\t\t\t\t\t\tif (typeof asNumber === \"number\") {\n\t\t\t\t\t\t\trecord[lastKey] = asNumber;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\trecord[lastKey] = coerceBoolean(original);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Recurse down\n\t\tconst [nextKey, ...rest] = targetPath;\n\n\t\tif (nextKey === ARRAY_ITEM_MARKER) {\n\t\t\tif (Array.isArray(current)) {\n\t\t\t\tfor (const item of current) {\n\t\t\t\t\twalk(item, rest, type);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = current as Record<string, unknown>;\n\t\twalk(record[nextKey], rest, type);\n\t};\n\n\tfor (const target of sortedTargets) {\n\t\twalk(data, target.path, target.type);\n\t}\n\n\treturn data;\n};\n\n/**\n * Create a coercing wrapper around an ArkType schema using JSON Schema introspection.\n * Pre-process input data to coerce string values to numbers/booleans at identified paths\n * before validation.\n */\nexport function coerce<t, $ = {}>(\n\tat: any,\n\tschema: BaseType<t, $>,\n\toptions?: CoerceOptions,\n): BaseType<t, $> {\n\t// Use a fallback to handle unjsonifiable parts of the schema (like predicates)\n\t// by preserving the base schema. This ensures that even if part of the schema\n\t// cannot be fully represented in JSON Schema, we can still perform coercion\n\t// for the parts that can.\n\tconst json = schema.in.toJsonSchema({\n\t\tfallback: (ctx) => (ctx as any).base,\n\t});\n\tconst targets = findCoercionPaths(json as any);\n\n\tif (targets.length === 0) {\n\t\treturn schema;\n\t}\n\n\t/*\n\t * We use `type(\"unknown\")` to start the pipeline, which initializes a default scope.\n\t * Integrating the original `schema` with its custom scope `$` into this pipeline\n\t * creates a scope mismatch in TypeScript ({} vs $).\n\t * We cast to `BaseType<t, $>` to assert the final contract is maintained.\n\t */\n\treturn at(\"unknown\")\n\t\t.pipe((data: unknown) => applyCoercion(data, targets, options))\n\t\t.pipe(schema) as BaseType<t, $>;\n}\n","import { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { distill } from \"arktype\";\nimport { ArkErrors } from \"arktype\";\nimport { ArkEnvError, type ValidationIssue } from \"../core\";\nimport type { ArkEnvConfig, EnvSchema } from \"../create-env\";\nimport { styleText } from \"../utils/style-text.ts\";\nimport { coerce } from \"./coercion/coerce\";\n\n/**\n * Re-export of ArkType's `distill` utilities.\n *\n * Exposed for internal use cases and type-level integrations.\n * ArkEnv does not add behavior or guarantees beyond what ArkType provides.\n *\n * @internal\n * @see https://github.com/arktypeio/arktype\n */\nexport type { distill };\n\n/**\n * Converts ArkType's `ArkErrors` (keyed by path) into a flat `ValidationIssue[]`\n * suitable for `ArkEnvError`. Strips leading path references from messages to\n * avoid duplication when `formatInternalErrors` prepends the styled path, and\n * applies cyan styling to inline \"(was …)\" values.\n *\n * @internal\n */\nfunction arkErrorsToIssues(errors: ArkErrors): ValidationIssue[] {\n\treturn Object.entries(errors.byPath).map(([path, error]) => {\n\t\tlet message = error.message;\n\n\t\t// Strip leading path reference if ArkType included it in the message\n\t\tlet trimmed = message.trimStart();\n\t\tif (trimmed.length > 0 && \":.-\".includes(trimmed[0])) {\n\t\t\ttrimmed = trimmed.slice(1).trimStart();\n\t\t}\n\t\tif (trimmed.toLowerCase().startsWith(path.toLowerCase())) {\n\t\t\tlet rest = trimmed.slice(path.length).trimStart();\n\t\t\tif (rest.length > 0 && \":.-\".includes(rest[0])) {\n\t\t\t\trest = rest.slice(1);\n\t\t\t}\n\t\t\tmessage = rest.trimStart();\n\t\t}\n\n\t\t// Style (was ...) inline values\n\t\tconst valueMatch = message.match(/\\(was (.*)\\)/);\n\t\tif (valueMatch?.[1]) {\n\t\t\tconst value = valueMatch[1];\n\t\t\tif (!value.includes(\"\\x1b[\")) {\n\t\t\t\tmessage = message.replace(\n\t\t\t\t\t`(was ${value})`,\n\t\t\t\t\t`(was ${styleText(\"cyan\", value)})`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { path, message };\n\t});\n}\n\n/**\n * Parse and validate environment variables using ArkEnv's schema rules.\n *\n * This applies:\n * - schema validation\n * - optional coercion (strings → numbers, booleans, arrays)\n * - undeclared key handling\n *\n * On success, returns the validated environment object.\n * On failure, throws an {@link ArkEnvError}.\n *\n * This is a low-level utility used internally by ArkEnv.\n * Most users should prefer the default `arkenv()` export.\n *\n * @internal\n */\nexport function parse<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig: ArkEnvConfig,\n) {\n\tconst {\n\t\tenv = process.env,\n\t\tcoerce: shouldCoerce = true,\n\t\tonUndeclaredKey = \"delete\",\n\t\tarrayFormat = \"comma\",\n\t} = config;\n\n\t// If def is a type definition (has assert method), use it directly\n\t// Otherwise, use raw() to convert the schema definition\n\tconst isCompiledType = typeof def === \"function\" && \"assert\" in def;\n\tconst schema = (isCompiledType ? def : $.type.raw(def)) as any;\n\n\t// Apply the `onUndeclaredKey` option\n\tconst schemaWithKeys = schema.onUndeclaredKey(onUndeclaredKey);\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tlet finalSchema = schemaWithKeys;\n\tif (shouldCoerce) {\n\t\tfinalSchema = coerce($.type, schemaWithKeys, { arrayFormat });\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = finalSchema(env);\n\n\t// In ArkType 2.x, calling a type as a function returns the validated data or ArkErrors\n\tif (validatedEnv instanceof ArkErrors) {\n\t\tthrow new ArkEnvError(arkErrorsToIssues(validatedEnv));\n\t}\n\n\treturn validatedEnv;\n}\n","import type { $ } from \"@repo/scope\";\nimport type {\n\tCompiledEnvSchema,\n\tDict,\n\tInferType,\n\tSchemaShape,\n} from \"@repo/types\";\nimport type { type as at, distill } from \"arktype\";\nimport { parse } from \"./arktype\";\nimport type { ArkEnvError } from \"./core\";\n\n/**\n * Declarative environment schema definition accepted by ArkEnv.\n *\n * Represents a declarative schema object mapping environment\n * variable names to schema definitions (e.g. ArkType DSL strings\n * or Standard Schema validators).\n *\n * This type is used to validate that a schema object is compatible with\n * ArkEnv’s validator scope before being compiled or parsed.\n *\n * Most users will provide schemas in this form.\n *\n * @template def - The schema shape object\n */\nexport type EnvSchema<def> = at.validate<def, $>;\ntype RuntimeEnvironment = Dict<string>;\n\n/**\n * Configuration options for `createEnv`\n */\nexport type ArkEnvConfig = {\n\t/**\n\t * The environment variables to parse. Defaults to `process.env`\n\t */\n\tenv?: RuntimeEnvironment;\n\t/**\n\t * Whether to coerce environment variables to their defined types. Defaults to `true`\n\t */\n\tcoerce?: boolean;\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. This differs from ArkType's standard behavior, which\n\t * mirrors TypeScript by defaulting to `'ignore'`.\n\t *\n\t * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.\n\t * - `ignore` (ArkType default): 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 * @see https://arktype.io/docs/configuration#onundeclaredkey\n\t */\n\tonUndeclaredKey?: \"ignore\" | \"delete\" | \"reject\";\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\n/**\n * TODO: `SchemaShape` is basically `Record<string, unknown>`.\n * If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Utility to parse environment variables using ArkType or Standard Schema\n * @param def - The schema definition\n * @param config - The evaluation configuration\n * @returns The parsed environment variables\n * @throws An {@link ArkEnvError | error} if the environment variables are invalid.\n */\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>>;\nexport function createEnv<T extends CompiledEnvSchema>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function createEnv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig: ArkEnvConfig = {},\n): distill.Out<at.infer<T, $>> | InferType<typeof def> {\n\t// biome-ignore lint/suspicious/noExplicitAny: parse handles both EnvSchema<T> and CompiledEnvSchema at runtime\n\treturn parse(def as any, config);\n}\n","import { $ } from \"@repo/scope\";\nimport { createEnv } from \"./create-env\";\n\nexport { createEnv };\n/**\n * Like ArkType's `type`, but with ArkEnv's extra keywords, such as:\n *\n * - `string.host` – a hostname (e.g. `\"localhost\"`, `\"127.0.0.1\"`)\n * - `number.port` – a port number (e.g. `8080`)\n *\n * See ArkType's docs for the full API:\n * https://arktype.io/docs/type-api\n */\nexport const type = $.type;\nexport { ArkEnvError } from \"./core\";\nexport type { ArkEnvConfig, EnvSchema } from \"./create-env\";\n\n/**\n * ArkEnv's main export, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables valid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E,KAUtB,IAAA,EADe"}
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./core-Byznlywt.cjs`);function t(t,n){if(typeof n==`string`)throw new e.t([{path:t,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.`}])}function n(t,n){let r=n&&typeof n==`object`&&`~standard`in n&&n[`~standard`];if(!r||typeof r!=`object`||!(`validate`in r)||typeof r.validate!=`function`)throw new e.t([{path:t,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function r(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e.t([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function i(t,n){let{env:r=process.env,onUndeclaredKey:i=`delete`}=n,a={},o=[],s=new Set(Object.keys(r));for(let n in t){let i=t[n],c=r[n];if(!i||typeof i!=`object`||!(`~standard`in i))throw new e.t([{path:n,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let l=i[`~standard`].validate(c);if(l instanceof Promise)throw new e.t([{path:n,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(l.issues)for(let e of l.issues){let t=e.path&&e.path.length>0?`${n}.${e.path.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e)).join(`.`)}`:n;o.push({path:t,message:e.message})}else a[n]=l.value;s.delete(n)}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 a(e,a){for(let i in r(e),e){let r=e[i];t(i,r),n(i,r)}return i(e,a??{})}const o=a;var s=o;exports.createEnv=a,exports.default=s;
2
+
3
+ // CJS Interop Shim
4
+ if (module.exports && module.exports.default) {
5
+ Object.assign(module.exports.default, module.exports);
6
+ module.exports = module.exports.default;
7
+ }
8
+
@@ -0,0 +1,70 @@
1
+ import { i as StandardSchemaV1 } from "./index-bSO6Cmhi.cjs";
2
+
3
+ //#region src/parse-standard.d.ts
4
+ /**
5
+ * Configuration options for {@link parseStandard}.
6
+ */
7
+ type ParseStandardConfig = {
8
+ /**
9
+ * The environment variables to parse. Defaults to `process.env`
10
+ */
11
+ env?: Record<string, string | undefined>;
12
+ /**
13
+ * Control how ArkEnv handles environment variables that are not defined in your schema.
14
+ *
15
+ * Defaults to `'delete'` to ensure your output object only contains
16
+ * keys you've explicitly declared.
17
+ *
18
+ * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
19
+ * - `ignore`: Undeclared keys are allowed and preserved in the output.
20
+ * - `reject`: Undeclared keys will cause validation to fail.
21
+ *
22
+ * @default "delete"
23
+ */
24
+ onUndeclaredKey?: "ignore" | "delete" | "reject";
25
+ };
26
+ //#endregion
27
+ //#region src/standard.d.ts
28
+ /**
29
+ * Configuration options for the `arkenv/standard` entry's `createEnv`.
30
+ */
31
+ type StandardEnvConfig = ParseStandardConfig;
32
+ /**
33
+ * Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).
34
+ *
35
+ * This entry is ArkType-free - ArkType is never imported, even transitively.
36
+ * Use this when your project must not depend on ArkType.
37
+ *
38
+ * @param def - An object mapping variable names to Standard Schema validators
39
+ * @param config - Optional configuration
40
+ * @returns The validated environment variables
41
+ * @throws An {@link ArkEnvError} if validation fails
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import arkenv from "arkenv/standard";
46
+ * import { z } from "zod";
47
+ *
48
+ * const env = arkenv({
49
+ * PORT: z.coerce.number(),
50
+ * HOST: z.string(),
51
+ * });
52
+ * ```
53
+ */
54
+ declare function createEnv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: StandardEnvConfig): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
55
+ /**
56
+ * ArkEnv's Standard Schema export, an alias for {@link createEnv}
57
+ *
58
+ * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
59
+ */
60
+ declare const arkenv: typeof createEnv;
61
+ //#endregion
62
+ export { StandardEnvConfig, createEnv, arkenv as default };
63
+
64
+ // CJS Interop Shim
65
+ if (module.exports && module.exports.default) {
66
+ Object.assign(module.exports.default, module.exports);
67
+ module.exports = module.exports.default;
68
+ }
69
+
70
+ //# sourceMappingURL=standard.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.d.cts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"sourcesContent":[],"mappings":";;;;;;AAMY,KAAA,mBAAA,GAAmB;;;;ECKnB,GAAA,CAAA,EDDL,MCCK,CAAA,MAAA,EAAiB,MAAA,GAAA,SAAG,CAAA;EAwBhB;;;;;;;;;;AAef;;;;;;;AD5CD;;KCKY,iBAAA,GAAoB;;AAAhC;AAwBA;;;;;;;;;;AAeC;;;;;;;;;;iBAfe,0BAA0B,eAAe,wBACnD,YACI,kCACO,IAAI,gBAAA,CAAiB,YAAY,EAAE;;;;;;cAmB9C,eAAM"}
@@ -0,0 +1,64 @@
1
+ import { i as StandardSchemaV1 } from "./index-Cic20SzT.mjs";
2
+
3
+ //#region src/parse-standard.d.ts
4
+ /**
5
+ * Configuration options for {@link parseStandard}.
6
+ */
7
+ type ParseStandardConfig = {
8
+ /**
9
+ * The environment variables to parse. Defaults to `process.env`
10
+ */
11
+ env?: Record<string, string | undefined>;
12
+ /**
13
+ * Control how ArkEnv handles environment variables that are not defined in your schema.
14
+ *
15
+ * Defaults to `'delete'` to ensure your output object only contains
16
+ * keys you've explicitly declared.
17
+ *
18
+ * - `delete` (ArkEnv default): Undeclared keys are allowed on input but stripped from the output.
19
+ * - `ignore`: Undeclared keys are allowed and preserved in the output.
20
+ * - `reject`: Undeclared keys will cause validation to fail.
21
+ *
22
+ * @default "delete"
23
+ */
24
+ onUndeclaredKey?: "ignore" | "delete" | "reject";
25
+ };
26
+ //#endregion
27
+ //#region src/standard.d.ts
28
+ /**
29
+ * Configuration options for the `arkenv/standard` entry's `createEnv`.
30
+ */
31
+ type StandardEnvConfig = ParseStandardConfig;
32
+ /**
33
+ * Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).
34
+ *
35
+ * This entry is ArkType-free - ArkType is never imported, even transitively.
36
+ * Use this when your project must not depend on ArkType.
37
+ *
38
+ * @param def - An object mapping variable names to Standard Schema validators
39
+ * @param config - Optional configuration
40
+ * @returns The validated environment variables
41
+ * @throws An {@link ArkEnvError} if validation fails
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import arkenv from "arkenv/standard";
46
+ * import { z } from "zod";
47
+ *
48
+ * const env = arkenv({
49
+ * PORT: z.coerce.number(),
50
+ * HOST: z.string(),
51
+ * });
52
+ * ```
53
+ */
54
+ declare function createEnv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: StandardEnvConfig): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
55
+ /**
56
+ * ArkEnv's Standard Schema export, an alias for {@link createEnv}
57
+ *
58
+ * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
59
+ */
60
+ declare const arkenv: typeof createEnv;
61
+ //#endregion
62
+ export { StandardEnvConfig, createEnv, arkenv as default };
63
+
64
+ //# sourceMappingURL=standard.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"sourcesContent":[],"mappings":";;;;;;AAMY,KAAA,mBAAA,GAAmB;;;;ECKnB,GAAA,CAAA,EDDL,MCCK,CAAA,MAAA,EAAiB,MAAA,GAAA,SAAG,CAAA;EAwBhB;;;;;;;;;;AAef;;;;;;;AD5CD;;KCKY,iBAAA,GAAoB;;AAAhC;AAwBA;;;;;;;;;;AAeC;;;;;;;;;;iBAfe,0BAA0B,eAAe,wBACnD,YACI,kCACO,IAAI,gBAAA,CAAiB,YAAY,EAAE;;;;;;cAmB9C,eAAM"}
@@ -0,0 +1,3 @@
1
+ import{t as e}from"./core-DzT5rjcY.mjs";function t(t,n){if(typeof n==`string`)throw new e([{path:t,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.`}])}function n(t,n){let r=n&&typeof n==`object`&&`~standard`in n&&n[`~standard`];if(!r||typeof r!=`object`||!(`validate`in r)||typeof r.validate!=`function`)throw new e([{path:t,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function r(t){if(!t||typeof t!=`object`||Array.isArray(t))throw new e([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function i(t,n){let{env:r=process.env,onUndeclaredKey:i=`delete`}=n,a={},o=[],s=new Set(Object.keys(r));for(let n in t){let i=t[n],c=r[n];if(!i||typeof i!=`object`||!(`~standard`in i))throw new e([{path:n,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let l=i[`~standard`].validate(c);if(l instanceof Promise)throw new e([{path:n,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(l.issues)for(let e of l.issues){let t=e.path&&e.path.length>0?`${n}.${e.path.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e)).join(`.`)}`:n;o.push({path:t,message:e.message})}else a[n]=l.value;s.delete(n)}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(o);return a}function a(e,a){for(let i in r(e),e){let r=e[i];t(i,r),n(i,r)}return i(e,a??{})}var o=a;export{a as createEnv,o as default};
2
+
3
+ //# sourceMappingURL=standard.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard.mjs","names":[],"sources":["../src/guards.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},\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},\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},\n\t\t]);\n\t}\n}\n","import type { StandardSchemaV1 } from \"@repo/types\";\nimport { ArkEnvError, type ValidationIssue } from \"./core\";\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?: Record<string, string | undefined>;\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};\n\n/**\n * Standard Schema 1.0 parser dispatcher.\n * This helper implements parsing for the `arkenv/standard` entry point.\n *\n * @param def - An object mapping environment variable keys to Standard Schema 1.0 validators.\n * @param config - Parsing options (env source, undeclared key handling).\n */\nexport function parseStandard(\n\tdef: Record<string, unknown>,\n\tconfig: ParseStandardConfig,\n) {\n\tconst { env = process.env, onUndeclaredKey = \"delete\" } = config;\n\tconst output: Record<string, unknown> = {};\n\tconst errors: ValidationIssue[] = [];\n\tconst envKeys = new Set(Object.keys(env));\n\n\t// 1. Validate declared keys\n\tfor (const key in def) {\n\t\tconst validator = def[key];\n\t\tconst value = env[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\t{\n\t\t\t\t\tpath: key,\n\t\t\t\t\tmessage: `Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,\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\t{\n\t\t\t\t\tpath: key,\n\t\t\t\t\tmessage: \"Async validation is not supported. ArkEnv is synchronous.\",\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 =\n\t\t\t\t\tissue.path && issue.path.length > 0\n\t\t\t\t\t\t? `${key}.${issue.path\n\t\t\t\t\t\t\t\t.map((segment) =>\n\t\t\t\t\t\t\t\t\tsegment !== null &&\n\t\t\t\t\t\t\t\t\ttypeof segment === \"object\" &&\n\t\t\t\t\t\t\t\t\t\"key\" in segment\n\t\t\t\t\t\t\t\t\t\t? String(segment.key)\n\t\t\t\t\t\t\t\t\t\t: String(segment),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join(\".\")}`\n\t\t\t\t\t\t: key;\n\t\t\t\terrors.push({\n\t\t\t\t\tpath: issuePath,\n\t\t\t\t\tmessage: issue.message,\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({\n\t\t\t\t\tpath: key,\n\t\t\t\t\tmessage: \"Undeclared key\",\n\t\t\t\t});\n\t\t\t} else if (onUndeclaredKey === \"ignore\") {\n\t\t\t\toutput[key] = env[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 {\n\tassertNotArkTypeDsl,\n\tassertStandardSchema,\n\tassertStandardSchemaMap,\n} from \"./guards\";\nimport { type ParseStandardConfig, parseStandard } from \"./parse-standard\";\n\n/**\n * Configuration options for the `arkenv/standard` entry's `createEnv`.\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\n * @throws An {@link ArkEnvError} if validation fails\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 createEnv<const T extends Record<string, StandardSchemaV1>>(\n\tdef: T,\n\tconfig?: StandardEnvConfig,\n): { [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\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, an alias for {@link createEnv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nconst arkenv = createEnv;\nexport default arkenv;\n"],"mappings":"wCAMA,SAAgB,EAAoB,EAAa,EAAsB,CACtE,GAAI,OAAO,GAAU,SACpB,MAAM,IAAI,EAAY,CACrB,CACC,KAAM,EACN,QACC,8JACD,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,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,CACD,CAAC,CC3BJ,SAAgB,EACf,EACA,EACC,CACD,GAAM,CAAE,MA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ADe"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arkenv",
3
3
  "type": "module",
4
- "version": "0.9.2",
4
+ "version": "0.10.0",
5
5
  "description": "Typesafe environment variables parsing and validation with ArkType",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -15,13 +15,21 @@
15
15
  "import": "./dist/index.mjs",
16
16
  "require": "./dist/index.cjs"
17
17
  },
18
- "./arktype": {
18
+ "./standard": {
19
19
  "types": {
20
- "import": "./dist/arktype/index.d.mts",
21
- "require": "./dist/arktype/index.d.cts"
20
+ "import": "./dist/standard.d.mts",
21
+ "require": "./dist/standard.d.cts"
22
22
  },
23
- "import": "./dist/arktype/index.mjs",
24
- "require": "./dist/arktype/index.cjs"
23
+ "import": "./dist/standard.mjs",
24
+ "require": "./dist/standard.cjs"
25
+ },
26
+ "./core": {
27
+ "types": {
28
+ "import": "./dist/core.d.mts",
29
+ "require": "./dist/core.d.cts"
30
+ },
31
+ "import": "./dist/core.mjs",
32
+ "require": "./dist/core.cjs"
25
33
  }
26
34
  },
27
35
  "files": [
@@ -50,11 +58,11 @@
50
58
  "arktype": "2.1.29",
51
59
  "rimraf": "6.1.2",
52
60
  "size-limit": "12.0.0",
53
- "tsdown": "0.18.4",
61
+ "tsdown": "0.19.0",
54
62
  "typescript": "5.9.3",
55
63
  "vitest": "4.0.17",
56
- "@repo/types": "0.1.0",
57
- "@repo/scope": "0.1.3"
64
+ "@repo/scope": "0.1.3",
65
+ "@repo/types": "0.1.0"
58
66
  },
59
67
  "peerDependencies": {
60
68
  "arktype": "^2.1.22"
@@ -66,7 +74,11 @@
66
74
  },
67
75
  "size-limit": [
68
76
  {
69
- "path": "dist/index.mjs",
77
+ "path": [
78
+ "dist/index.mjs",
79
+ "dist/standard.mjs",
80
+ "dist/core.mjs"
81
+ ],
70
82
  "limit": "3 kB",
71
83
  "import": "*",
72
84
  "ignore": [
@@ -1,8 +0,0 @@
1
- const e=require(`../errors-BtUS5QYF.cjs`);let t=require(`arktype`);const n=(0,t.type)(`0 <= number.integer <= 65535`),r=(0,t.type)(`string.ip | 'localhost'`),i=(0,t.scope)({string:t.type.module({...t.type.keywords.string,host:r}),number:t.type.module({...t.type.keywords.number,port:n})}),a=e=>{if(typeof e==`number`||typeof e!=`string`)return e;let t=e.trim();if(t===``)return e;if(t===`NaN`)return NaN;let n=Number(t);return Number.isNaN(n)?e:n},o=e=>e===`true`?!0:e===`false`?!1:e,s=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(!t.startsWith(`{`)&&!t.startsWith(`[`))return e;try{return JSON.parse(t)}catch{return e}},c=`*`,l=(e,t=[])=>{let n=[];if(typeof e==`boolean`)return n;if(`const`in e&&(typeof e.const==`number`||typeof e.const==`boolean`)&&n.push({path:[...t],type:`primitive`}),`enum`in e&&e.enum&&e.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`}),`type`in e)if(e.type===`number`||e.type===`integer`)n.push({path:[...t],type:`primitive`});else if(e.type===`boolean`)n.push({path:[...t],type:`primitive`});else if(e.type===`object`){if(`properties`in e&&e.properties&&Object.keys(e.properties).length>0&&n.push({path:[...t],type:`object`}),`properties`in e&&e.properties)for(let[r,i]of Object.entries(e.properties))n.push(...l(i,[...t,r]))}else e.type===`array`&&(n.push({path:[...t],type:`array`}),`items`in e&&e.items&&(Array.isArray(e.items)?e.items.forEach((e,r)=>{n.push(...l(e,[...t,`${r}`]))}):n.push(...l(e.items,[...t,`*`]))));if(`anyOf`in e&&e.anyOf)for(let r of e.anyOf)n.push(...l(r,t));if(`allOf`in e&&e.allOf)for(let r of e.allOf)n.push(...l(r,t));if(`oneOf`in e&&e.oneOf)for(let r of e.oneOf)n.push(...l(r,t));let r=new Set;return n.filter(e=>{let t=JSON.stringify(e.path)+e.type;return r.has(t)?!1:(r.add(t),!0)})},u=(e,t,n={})=>{let{arrayFormat:r=`comma`}=n,i=e=>{if(r===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]};if(typeof e!=`object`||!e){if(t.some(e=>e.path.length===0)){let n=t.find(e=>e.path.length===0);if(n?.type===`object`&&typeof e==`string`)return s(e);if(n?.type===`array`&&typeof e==`string`)return i(e);let r=a(e);return typeof r==`number`?r:o(e)}return e}let c=[...t].sort((e,t)=>e.path.length-t.path.length),l=(e,t,n)=>{if(!e||typeof e!=`object`||t.length===0)return;if(t.length===1){let r=t[0];if(r===`*`){if(Array.isArray(e))for(let t=0;t<e.length;t++){let r=e[t];if(n===`primitive`){let n=a(r);typeof n==`number`?e[t]=n:e[t]=o(r)}else n===`object`&&(e[t]=s(r))}return}let c=e;if(Object.prototype.hasOwnProperty.call(c,r)){let e=c[r];if(n===`array`&&typeof e==`string`){c[r]=i(e);return}if(n===`object`&&typeof e==`string`){c[r]=s(e);return}if(Array.isArray(e)){if(n===`primitive`)for(let t=0;t<e.length;t++){let n=e[t],r=a(n);typeof r==`number`?e[t]=r:e[t]=o(n)}}else if(n===`primitive`){let t=a(e);typeof t==`number`?c[r]=t:c[r]=o(e)}}return}let[r,...c]=t;if(r===`*`){if(Array.isArray(e))for(let t of e)l(t,c,n);return}l(e[r],c,n)};for(let t of c)l(e,t.path,t.type);return e};function d(e,t,n){let r=l(t.in.toJsonSchema({fallback:e=>e.base}));return r.length===0?t:e(`unknown`).pipe(e=>u(e,r,n)).pipe(t)}const f=i.type;function p(n,r){let{env:a=process.env,coerce:o=!0,onUndeclaredKey:s=`delete`,arrayFormat:c=`comma`}=r,l=(typeof n==`function`&&`assert`in n?n:i.type.raw(n)).onUndeclaredKey(s),u=l;o&&(u=d(i.type,l,{arrayFormat:c}));let f=u(a);if(f instanceof t.ArkErrors)throw new e.t(f);return f}exports.parse=p,exports.type=f;
2
-
3
- // CJS Interop Shim
4
- if (module.exports && module.exports.default) {
5
- Object.assign(module.exports.default, module.exports);
6
- module.exports = module.exports.default;
7
- }
8
-