arkenv 1.0.0-alpha.0 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -12
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/standard.cjs +1 -1
- package/dist/standard.d.cts +3 -9
- package/dist/standard.d.cts.map +1 -1
- package/dist/standard.d.mts +3 -9
- package/dist/standard.d.mts.map +1 -1
- package/dist/standard.mjs +1 -1
- package/dist/standard.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./shared-Bx3sbEJf.cjs`),t=require(`./core-BftJnV8f.cjs`);let n=require(`arktype`);const r=(0,n.type)(`0 <= number.integer <= 65535`),i=(0,n.type)(`string.ip | 'localhost'`),a=(0,n.scope)({string:n.type.module({...n.type.keywords.string,host:i}),number:n.type.module({...n.type.keywords.number,port:r})});function o(e){return Object.entries(e.byPath).map(([e,n])=>{let r=n.message,i=r.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(e.toLowerCase())){let t=i.slice(e.length).trimStart();t.length>0&&`:.-`.includes(t[0])&&(t=t.slice(1)),r=t.trimStart()}let a=r.match(/\(was (.*)\)/);if(a?.[1]){let e=a[1];e.includes(`\x1B[`)||(r=r.replace(`(was ${e})`,`(was ${t.r(`cyan`,e)})`))}return{path:e,message:r}})}function s(r,i){let{env:s=process.env,coerce:c=!0,onUndeclaredKey:l=`delete`,arrayFormat:u=`comma`,emptyAsUndefined:d=!1}=i,f=(typeof r==`function`&&`assert`in r?r:a.type.raw(r)).onUndeclaredKey(l),p={...d?e.r(s):s};if(c){let t=e.n(f.in.toJsonSchema({fallback:e=>e.base}));t.length>0&&(p=e.t(p,t,{arrayFormat:u}))}let m=f(p);if(m instanceof n.ArkErrors)throw new t.t(o(m));return m}function c(e,t={}){return s(e,t)}const l=a.type
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./shared-Bx3sbEJf.cjs`),t=require(`./core-BftJnV8f.cjs`);let n=require(`arktype`);const r=(0,n.type)(`0 <= number.integer <= 65535`),i=(0,n.type)(`string.ip | 'localhost'`),a=(0,n.scope)({string:n.type.module({...n.type.keywords.string,host:i}),number:n.type.module({...n.type.keywords.number,port:r})});function o(e){return Object.entries(e.byPath).map(([e,n])=>{let r=n.message,i=r.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(e.toLowerCase())){let t=i.slice(e.length).trimStart();t.length>0&&`:.-`.includes(t[0])&&(t=t.slice(1)),r=t.trimStart()}let a=r.match(/\(was (.*)\)/);if(a?.[1]){let e=a[1];e.includes(`\x1B[`)||(r=r.replace(`(was ${e})`,`(was ${t.r(`cyan`,e)})`))}return{path:e,message:r}})}function s(r,i){let{env:s=process.env,coerce:c=!0,onUndeclaredKey:l=`delete`,arrayFormat:u=`comma`,emptyAsUndefined:d=!1}=i,f=(typeof r==`function`&&`assert`in r?r:a.type.raw(r)).onUndeclaredKey(l),p={...d?e.r(s):s};if(c){let t=e.n(f.in.toJsonSchema({fallback:e=>e.base}));t.length>0&&(p=e.t(p,t,{arrayFormat:u}))}let m=f(p);if(m instanceof n.ArkErrors)throw new t.t(o(m));return m}function c(e,t={}){return s(e,t)}const l=a.type;var u=c;exports.arkenv=c,exports.default=u,exports.type=l;
|
|
2
2
|
|
|
3
3
|
// CJS Interop Shim
|
|
4
4
|
if (module.exports && module.exports.default) {
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import * as _$arktype from "arktype";
|
|
|
5
5
|
import { distill, type as type$1 } from "arktype";
|
|
6
6
|
import * as _$arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
|
-
//#region src/
|
|
8
|
+
//#region src/arkenv.d.ts
|
|
9
9
|
/**
|
|
10
10
|
* Declarative environment schema definition accepted by ArkEnv.
|
|
11
11
|
*
|
|
@@ -30,7 +30,7 @@ type EnvSchema<def> = type$1.validate<def, $>;
|
|
|
30
30
|
type Infer<T> = T extends SchemaShape ? distill.Out<type$1.infer<T, $>> : InferType<T>;
|
|
31
31
|
type RuntimeEnvironment = Dict<string>;
|
|
32
32
|
/**
|
|
33
|
-
* Configuration options for `
|
|
33
|
+
* Configuration options for `arkenv`
|
|
34
34
|
*/
|
|
35
35
|
type ArkEnvConfig = {
|
|
36
36
|
/**
|
|
@@ -88,9 +88,9 @@ type ArkEnvConfig = {
|
|
|
88
88
|
* @returns The parsed environment variables
|
|
89
89
|
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
90
|
*/
|
|
91
|
-
declare function
|
|
92
|
-
declare function
|
|
93
|
-
declare function
|
|
91
|
+
declare function arkenv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>>;
|
|
92
|
+
declare function arkenv<T extends CompiledEnvSchema>(def: T, config?: ArkEnvConfig): InferType<T>;
|
|
93
|
+
declare function arkenv<const T extends SchemaShape>(def: EnvSchema<T> | CompiledEnvSchema, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>> | InferType<typeof def>;
|
|
94
94
|
//#endregion
|
|
95
95
|
//#region src/index.d.ts
|
|
96
96
|
/**
|
|
@@ -173,14 +173,8 @@ declare const type: _$arktype_internal_type_ts0.TypeParser<{
|
|
|
173
173
|
port: number;
|
|
174
174
|
}>;
|
|
175
175
|
}>;
|
|
176
|
-
/**
|
|
177
|
-
* ArkEnv's main export, an alias for {@link createEnv}
|
|
178
|
-
*
|
|
179
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
180
|
-
*/
|
|
181
|
-
declare const arkenv: typeof createEnv;
|
|
182
176
|
//#endregion
|
|
183
|
-
export { type ArkEnvConfig, type EnvSchema, type Infer,
|
|
177
|
+
export { type ArkEnvConfig, type EnvSchema, type Infer, arkenv, arkenv as default, type };
|
|
184
178
|
|
|
185
179
|
// CJS Interop Shim
|
|
186
180
|
if (module.exports && module.exports.default) {
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/arkenv.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;KAAY,SAAA,QAAiB,MAAA,CAAG,QAAA,CAAS,GAAA,EAAK,CAAA;;;;;;AAQ9C;KAAY,KAAA,MAAW,CAAA,SAAU,WAAA,GAC9B,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KACxB,SAAA,CAAU,CAAA;AAAA,KAER,kBAAA,GAAqB,IAAA;;;;KAKd,YAAA;EARG;;;EAYd,GAAA,GAAM,kBAAA;EAXK;;;EAeX,MAAA;EAjBgC;;;;;;;;;;;AAEjB;;;EA8Bf,eAAA;EA5B6B;AAK9B;;;;;;;EAiCC,WAAA;EAAA;;;;AA2BD;;;;;EAhBC,gBAAA;AAAA;;;;;;;;;;;;;iBAgBe,MAAA,iBAAuB,WAAA,CAAA,CACtC,GAAA,EAAK,SAAA,CAAU,CAAA,GACf,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA;AAAA,iBACX,MAAA,WAAiB,iBAAA,CAAA,CAChC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,YAAA,GACP,SAAA,CAAU,CAAA;AAAA,iBACG,MAAA,iBAAuB,WAAA,CAAA,CACtC,GAAA,EAAK,SAAA,CAAU,CAAA,IAAK,iBAAA,EACpB,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KAAM,SAAA,QAAiB,GAAA;;;;;;;;;AAxFlD;;;cCZa,IAAA,8BAAI,UAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import * as _$arktype_internal_keywords_string_ts0 from "arktype/internal/keywor
|
|
|
5
5
|
import * as _$arktype_internal_attributes_ts0 from "arktype/internal/attributes.ts";
|
|
6
6
|
import * as _$arktype_internal_type_ts0 from "arktype/internal/type.ts";
|
|
7
7
|
|
|
8
|
-
//#region src/
|
|
8
|
+
//#region src/arkenv.d.ts
|
|
9
9
|
/**
|
|
10
10
|
* Declarative environment schema definition accepted by ArkEnv.
|
|
11
11
|
*
|
|
@@ -30,7 +30,7 @@ type EnvSchema<def> = type$1.validate<def, $>;
|
|
|
30
30
|
type Infer<T> = T extends SchemaShape ? distill.Out<type$1.infer<T, $>> : InferType<T>;
|
|
31
31
|
type RuntimeEnvironment = Dict<string>;
|
|
32
32
|
/**
|
|
33
|
-
* Configuration options for `
|
|
33
|
+
* Configuration options for `arkenv`
|
|
34
34
|
*/
|
|
35
35
|
type ArkEnvConfig = {
|
|
36
36
|
/**
|
|
@@ -88,9 +88,9 @@ type ArkEnvConfig = {
|
|
|
88
88
|
* @returns The parsed environment variables
|
|
89
89
|
* @throws An {@link ArkEnvError | error} if the environment variables are invalid.
|
|
90
90
|
*/
|
|
91
|
-
declare function
|
|
92
|
-
declare function
|
|
93
|
-
declare function
|
|
91
|
+
declare function arkenv<const T extends SchemaShape>(def: EnvSchema<T>, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>>;
|
|
92
|
+
declare function arkenv<T extends CompiledEnvSchema>(def: T, config?: ArkEnvConfig): InferType<T>;
|
|
93
|
+
declare function arkenv<const T extends SchemaShape>(def: EnvSchema<T> | CompiledEnvSchema, config?: ArkEnvConfig): distill.Out<type$1.infer<T, $>> | InferType<typeof def>;
|
|
94
94
|
//#endregion
|
|
95
95
|
//#region src/index.d.ts
|
|
96
96
|
/**
|
|
@@ -173,13 +173,7 @@ declare const type: _$arktype_internal_type_ts0.TypeParser<{
|
|
|
173
173
|
port: number;
|
|
174
174
|
}>;
|
|
175
175
|
}>;
|
|
176
|
-
/**
|
|
177
|
-
* ArkEnv's main export, an alias for {@link createEnv}
|
|
178
|
-
*
|
|
179
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
180
|
-
*/
|
|
181
|
-
declare const arkenv: typeof createEnv;
|
|
182
176
|
//#endregion
|
|
183
|
-
export { type ArkEnvConfig, type EnvSchema, type Infer,
|
|
177
|
+
export { type ArkEnvConfig, type EnvSchema, type Infer, arkenv, arkenv as default, type };
|
|
184
178
|
|
|
185
179
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/arkenv.ts","../src/index.ts"],"mappings":";;;;;;;;;;;;;AAyBA;;;;;;;;;KAAY,SAAA,QAAiB,MAAA,CAAG,QAAA,CAAS,GAAA,EAAK,CAAA;;;;;;AAQ9C;KAAY,KAAA,MAAW,CAAA,SAAU,WAAA,GAC9B,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KACxB,SAAA,CAAU,CAAA;AAAA,KAER,kBAAA,GAAqB,IAAA;;;;KAKd,YAAA;EARG;;;EAYd,GAAA,GAAM,kBAAA;EAXK;;;EAeX,MAAA;EAjBgC;;;;;;;;;;;AAEjB;;;EA8Bf,eAAA;EA5B6B;AAK9B;;;;;;;EAiCC,WAAA;EAAA;;;;AA2BD;;;;;EAhBC,gBAAA;AAAA;;;;;;;;;;;;;iBAgBe,MAAA,iBAAuB,WAAA,CAAA,CACtC,GAAA,EAAK,SAAA,CAAU,CAAA,GACf,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA;AAAA,iBACX,MAAA,WAAiB,iBAAA,CAAA,CAChC,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,YAAA,GACP,SAAA,CAAU,CAAA;AAAA,iBACG,MAAA,iBAAuB,WAAA,CAAA,CACtC,GAAA,EAAK,SAAA,CAAU,CAAA,IAAK,iBAAA,EACpB,MAAA,GAAS,YAAA,GACP,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAG,KAAA,CAAM,CAAA,EAAG,CAAA,KAAM,SAAA,QAAiB,GAAA;;;;;;;;;AAxFlD;;;cCZa,IAAA,8BAAI,UAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./shared-B7lIFzfk.mjs";import{r,t as i}from"./core-B0IkKRzg.mjs";import{ArkErrors as a,scope as o,type as s}from"arktype";const c=s(`0 <= number.integer <= 65535`),l=s(`string.ip | 'localhost'`),u=o({string:s.module({...s.keywords.string,host:l}),number:s.module({...s.keywords.number,port:c})});function d(e){return Object.entries(e.byPath).map(([e,t])=>{let n=t.message,i=n.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(e.toLowerCase())){let t=i.slice(e.length).trimStart();t.length>0&&`:.-`.includes(t[0])&&(t=t.slice(1)),n=t.trimStart()}let a=n.match(/\(was (.*)\)/);if(a?.[1]){let e=a[1];e.includes(`\x1B[`)||(n=n.replace(`(was ${e})`,`(was ${r(`cyan`,e)})`))}return{path:e,message:n}})}function f(r,o){let{env:s=process.env,coerce:c=!0,onUndeclaredKey:l=`delete`,arrayFormat:f=`comma`,emptyAsUndefined:p=!1}=o,m=(typeof r==`function`&&`assert`in r?r:u.type.raw(r)).onUndeclaredKey(l),h={...p?t(s):s};if(c){let t=e(m.in.toJsonSchema({fallback:e=>e.base}));t.length>0&&(h=n(h,t,{arrayFormat:f}))}let g=m(h);if(g instanceof a)throw new i(d(g));return g}function p(e,t={}){return f(e,t)}const m=u.type
|
|
1
|
+
import{n as e,r as t,t as n}from"./shared-B7lIFzfk.mjs";import{r,t as i}from"./core-B0IkKRzg.mjs";import{ArkErrors as a,scope as o,type as s}from"arktype";const c=s(`0 <= number.integer <= 65535`),l=s(`string.ip | 'localhost'`),u=o({string:s.module({...s.keywords.string,host:l}),number:s.module({...s.keywords.number,port:c})});function d(e){return Object.entries(e.byPath).map(([e,t])=>{let n=t.message,i=n.trimStart();if(i.length>0&&`:.-`.includes(i[0])&&(i=i.slice(1).trimStart()),i.toLowerCase().startsWith(e.toLowerCase())){let t=i.slice(e.length).trimStart();t.length>0&&`:.-`.includes(t[0])&&(t=t.slice(1)),n=t.trimStart()}let a=n.match(/\(was (.*)\)/);if(a?.[1]){let e=a[1];e.includes(`\x1B[`)||(n=n.replace(`(was ${e})`,`(was ${r(`cyan`,e)})`))}return{path:e,message:n}})}function f(r,o){let{env:s=process.env,coerce:c=!0,onUndeclaredKey:l=`delete`,arrayFormat:f=`comma`,emptyAsUndefined:p=!1}=o,m=(typeof r==`function`&&`assert`in r?r:u.type.raw(r)).onUndeclaredKey(l),h={...p?t(s):s};if(c){let t=e(m.in.toJsonSchema({fallback:e=>e.base}));t.length>0&&(h=n(h,t,{arrayFormat:f}))}let g=m(h);if(g instanceof a)throw new i(d(g));return g}function p(e,t={}){return f(e,t)}const m=u.type;var h=p;export{p as arkenv,h as default,m as type};
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["t","e","$","$"],"sources":["../../internal/scope/dist/index.js","../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","import { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { distill } from \"arktype\";\nimport { ArkErrors } from \"arktype\";\nimport {\n\tapplyCoercion,\n\tfindCoercionPaths,\n\tstripEmptyStrings,\n} from \"@/coercion\";\nimport { ArkEnvError, type ValidationIssue } from \"@/core\";\nimport type { ArkEnvConfig, EnvSchema } from \"@/create-env\";\nimport { styleText } from \"@/utils/style-text\";\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 * @param errors The ArkType errors object to convert\n * @returns An array of flattened validation issues\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 * @param def The ArkType schema definition to validate against\n * @param config The configuration object for parsing and coercion\n * @returns The parsed and validated environment variables\n * @throws {@link ArkEnvError} if validation fails\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\temptyAsUndefined = false,\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// Optionally treat empty strings as undefined\n\tconst processedEnv = emptyAsUndefined\n\t\t? stripEmptyStrings(env as Record<string, string | undefined>)\n\t\t: env;\n\n\tlet coercedEnv = { ...processedEnv } as Record<string, unknown>;\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tif (shouldCoerce) {\n\t\tconst json = schemaWithKeys.in.toJsonSchema({\n\t\t\tfallback: (ctx: { base: unknown }) => ctx.base,\n\t\t});\n\t\tconst targets = findCoercionPaths(json);\n\t\tif (targets.length > 0) {\n\t\t\tcoercedEnv = applyCoercion(coercedEnv, targets, {\n\t\t\t\tarrayFormat,\n\t\t\t});\n\t\t}\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = schemaWithKeys(coercedEnv);\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, $>;\n\n/**\n * Infer the validated and coerced environment object type from a schema.\n * Supports declarative schema shapes, compiled ArkType schemas, and Standard Schema validators.\n *\n * @template T - The schema type\n */\nexport type Infer<T> = T extends SchemaShape\n\t? distill.Out<at.infer<T, $>>\n\t: InferType<T>;\n\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\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\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 type { ArkEnvConfig, EnvSchema, Infer } 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 validator from editor to runtime.\n */\nconst arkenv = createEnv;\nexport default arkenv;\n"],"mappings":"2JAA0C,MAAM,EAAEA,EAAE,+BAA+B,CAAC,EAAEA,EAAE,0BAA0B,CAAC,EAAEC,EAAE,CAAC,OAAOD,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,OAAOA,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CCmCvN,SAAS,EAAkB,EAAsC,CAChE,OAAO,OAAO,QAAQ,EAAO,OAAO,CAAC,KAAK,CAAC,EAAM,KAAW,CAC3D,IAAI,EAAU,EAAM,QAGhB,EAAU,EAAQ,WAAW,CAIjC,GAHI,EAAQ,OAAS,GAAK,MAAM,SAAS,EAAQ,GAAG,GACnD,EAAU,EAAQ,MAAM,EAAE,CAAC,WAAW,EAEnC,EAAQ,aAAa,CAAC,WAAW,EAAK,aAAa,CAAC,CAAE,CACzD,IAAI,EAAO,EAAQ,MAAM,EAAK,OAAO,CAAC,WAAW,CAC7C,EAAK,OAAS,GAAK,MAAM,SAAS,EAAK,GAAG,GAC7C,EAAO,EAAK,MAAM,EAAE,EAErB,EAAU,EAAK,WAAW,CAI3B,IAAM,EAAa,EAAQ,MAAM,eAAe,CAChD,GAAI,IAAa,GAAI,CACpB,IAAM,EAAQ,EAAW,GACpB,EAAM,SAAS,QAAQ,GAC3B,EAAU,EAAQ,QACjB,QAAQ,EAAM,GACd,QAAQ,EAAU,OAAQ,EAAM,CAAC,GACjC,EAIH,MAAO,CAAE,OAAM,UAAS,EACvB,CAwBH,SAAgB,EACf,EACA,EACC,CACD,GAAM,CACL,MAAM,QAAQ,IACd,OAAQ,EAAe,GACvB,kBAAkB,SAClB,cAAc,QACd,mBAAmB,IAChB,EAQE,GAJiB,OAAO,GAAQ,YAAc,WAAY,EAC/B,EAAME,EAAE,KAAK,IAAI,EAAI,EAGxB,gBAAgB,EAAgB,CAO1D,EAAa,CAAE,GAJE,EAClB,EAAkB,EAA0C,CAC5D,EAEiC,CAGpC,GAAI,EAAc,CAIjB,IAAM,EAAU,EAHH,EAAe,GAAG,aAAa,CAC3C,SAAW,GAA2B,EAAI,KAC1C,CACqC,CAAC,CACnC,EAAQ,OAAS,IACpB,EAAa,EAAc,EAAY,EAAS,CAC/C,cACA,CAAC,EAKJ,IAAM,EAAe,EAAe,EAAW,CAG/C,GAAI,aAAwB,EAC3B,MAAM,IAAI,EAAY,EAAkB,EAAa,CAAC,CAGvD,OAAO,ECvBR,SAAgB,EACf,EACA,EAAuB,EAAE,CAC6B,CAEtD,OAAO,EAAM,EAAY,EAAO,CC1GjC,MAAa,EAAOC,EAAE,KAQhB,EAAS"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["t","e","$","$"],"sources":["../../internal/scope/dist/index.js","../src/arktype/index.ts","../src/arkenv.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","import { $ } from \"@repo/scope\";\nimport type { SchemaShape } from \"@repo/types\";\nimport type { distill } from \"arktype\";\nimport { ArkErrors } from \"arktype\";\nimport type { ArkEnvConfig, EnvSchema } from \"@/arkenv\";\nimport {\n\tapplyCoercion,\n\tfindCoercionPaths,\n\tstripEmptyStrings,\n} from \"@/coercion\";\nimport { ArkEnvError, type ValidationIssue } from \"@/core\";\nimport { styleText } from \"@/utils/style-text\";\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 * @param errors The ArkType errors object to convert\n * @returns An array of flattened validation issues\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 * @param def The ArkType schema definition to validate against\n * @param config The configuration object for parsing and coercion\n * @returns The parsed and validated environment variables\n * @throws {@link ArkEnvError} if validation fails\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\temptyAsUndefined = false,\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// Optionally treat empty strings as undefined\n\tconst processedEnv = emptyAsUndefined\n\t\t? stripEmptyStrings(env as Record<string, string | undefined>)\n\t\t: env;\n\n\tlet coercedEnv = { ...processedEnv } as Record<string, unknown>;\n\n\t// Apply coercion transformation to allow strings to be parsed as numbers/booleans\n\tif (shouldCoerce) {\n\t\tconst json = schemaWithKeys.in.toJsonSchema({\n\t\t\tfallback: (ctx: { base: unknown }) => ctx.base,\n\t\t});\n\t\tconst targets = findCoercionPaths(json);\n\t\tif (targets.length > 0) {\n\t\t\tcoercedEnv = applyCoercion(coercedEnv, targets, {\n\t\t\t\tarrayFormat,\n\t\t\t});\n\t\t}\n\t}\n\n\t// Validate the environment variables\n\tconst validatedEnv = schemaWithKeys(coercedEnv);\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, $>;\n\n/**\n * Infer the validated and coerced environment object type from a schema.\n * Supports declarative schema shapes, compiled ArkType schemas, and Standard Schema validators.\n *\n * @template T - The schema type\n */\nexport type Infer<T> = T extends SchemaShape\n\t? distill.Out<at.infer<T, $>>\n\t: InferType<T>;\n\ntype RuntimeEnvironment = Dict<string>;\n\n/**\n * Configuration options for `arkenv`\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\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\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 arkenv<const T extends SchemaShape>(\n\tdef: EnvSchema<T>,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>>;\nexport function arkenv<T extends CompiledEnvSchema>(\n\tdef: T,\n\tconfig?: ArkEnvConfig,\n): InferType<T>;\nexport function arkenv<const T extends SchemaShape>(\n\tdef: EnvSchema<T> | CompiledEnvSchema,\n\tconfig?: ArkEnvConfig,\n): distill.Out<at.infer<T, $>> | InferType<typeof def>;\nexport function arkenv<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 { arkenv } from \"./arkenv\";\n\nexport { arkenv };\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 type { ArkEnvConfig, EnvSchema, Infer } from \"./arkenv\";\n\n/**\n * ArkEnv's main export, an alias for {@link arkenv}\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nexport default arkenv;\n"],"mappings":"2JAA0C,MAAM,EAAEA,EAAE,+BAA+B,CAAC,EAAEA,EAAE,0BAA0B,CAAC,EAAEC,EAAE,CAAC,OAAOD,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,OAAOA,EAAE,OAAO,CAAC,GAAGA,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CCmCvN,SAAS,EAAkB,EAAsC,CAChE,OAAO,OAAO,QAAQ,EAAO,OAAO,CAAC,KAAK,CAAC,EAAM,KAAW,CAC3D,IAAI,EAAU,EAAM,QAGhB,EAAU,EAAQ,WAAW,CAIjC,GAHI,EAAQ,OAAS,GAAK,MAAM,SAAS,EAAQ,GAAG,GACnD,EAAU,EAAQ,MAAM,EAAE,CAAC,WAAW,EAEnC,EAAQ,aAAa,CAAC,WAAW,EAAK,aAAa,CAAC,CAAE,CACzD,IAAI,EAAO,EAAQ,MAAM,EAAK,OAAO,CAAC,WAAW,CAC7C,EAAK,OAAS,GAAK,MAAM,SAAS,EAAK,GAAG,GAC7C,EAAO,EAAK,MAAM,EAAE,EAErB,EAAU,EAAK,WAAW,CAI3B,IAAM,EAAa,EAAQ,MAAM,eAAe,CAChD,GAAI,IAAa,GAAI,CACpB,IAAM,EAAQ,EAAW,GACpB,EAAM,SAAS,QAAQ,GAC3B,EAAU,EAAQ,QACjB,QAAQ,EAAM,GACd,QAAQ,EAAU,OAAQ,EAAM,CAAC,GACjC,EAIH,MAAO,CAAE,OAAM,UAAS,EACvB,CAwBH,SAAgB,EACf,EACA,EACC,CACD,GAAM,CACL,MAAM,QAAQ,IACd,OAAQ,EAAe,GACvB,kBAAkB,SAClB,cAAc,QACd,mBAAmB,IAChB,EAQE,GAJiB,OAAO,GAAQ,YAAc,WAAY,EAC/B,EAAME,EAAE,KAAK,IAAI,EAAI,EAGxB,gBAAgB,EAAgB,CAO1D,EAAa,CAAE,GAJE,EAClB,EAAkB,EAA0C,CAC5D,EAEiC,CAGpC,GAAI,EAAc,CAIjB,IAAM,EAAU,EAHH,EAAe,GAAG,aAAa,CAC3C,SAAW,GAA2B,EAAI,KAC1C,CACqC,CAAC,CACnC,EAAQ,OAAS,IACpB,EAAa,EAAc,EAAY,EAAS,CAC/C,cACA,CAAC,EAKJ,IAAM,EAAe,EAAe,EAAW,CAG/C,GAAI,aAAwB,EAC3B,MAAM,IAAI,EAAY,EAAkB,EAAa,CAAC,CAGvD,OAAO,ECvBR,SAAgB,EACf,EACA,EAAuB,EAAE,CAC6B,CAEtD,OAAO,EAAM,EAAY,EAAO,CC1GjC,MAAa,EAAOC,EAAE,KAQtB,IAAA,EAAe"}
|
package/dist/standard.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./shared-Bx3sbEJf.cjs`),t=require(`./core-BftJnV8f.cjs`);function n(e,n){if(typeof n==`string`)throw new t.t([{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.`}])}function r(e,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 t.t([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function i(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t.t([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function a(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function o(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function s(n,r){let{env:i=process.env,onUndeclaredKey:s=`delete`,coerce:c=!0,arrayFormat:l=`comma`,emptyAsUndefined:u=!1}=r,d={},f=[],p=u?e.r(i):i,m=new Set(Object.keys(p)),h={...p},g=[];if(c){let{jsonSchema:t,hasJsonSchema:r}=a(n,g);r&&(h=e.t(h,e.n(t),{arrayFormat:l}))}for(let e in n){let r=n[e],i=h[e];if(!r||typeof r!=`object`||!(`~standard`in r))throw new t.t([{path:e,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=r[`~standard`].validate(i);if(a instanceof Promise)throw new t.t([{path:e,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let t of a.issues){let n=o(e,t.path),r=t.message;c&&g.includes(e)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${e}' lacks Standard JSON Schema support.)`),f.push({path:n,message:r})}else d[e]=a.value;m.delete(e)}if(s!==`delete`)for(let e of m)s===`reject`?f.push({path:e,message:`Undeclared key`}):s===`ignore`&&(d[e]=h[e]);if(f.length>0)throw new t.t(f);return d}function c(e,t){i(e);for(let t in e){let i=e[t];n(t,i),r(t,i)}return s(e,t??{})}
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./shared-Bx3sbEJf.cjs`),t=require(`./core-BftJnV8f.cjs`);function n(e,n){if(typeof n==`string`)throw new t.t([{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.`}])}function r(e,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 t.t([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function i(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t.t([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function a(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function o(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function s(n,r){let{env:i=process.env,onUndeclaredKey:s=`delete`,coerce:c=!0,arrayFormat:l=`comma`,emptyAsUndefined:u=!1}=r,d={},f=[],p=u?e.r(i):i,m=new Set(Object.keys(p)),h={...p},g=[];if(c){let{jsonSchema:t,hasJsonSchema:r}=a(n,g);r&&(h=e.t(h,e.n(t),{arrayFormat:l}))}for(let e in n){let r=n[e],i=h[e];if(!r||typeof r!=`object`||!(`~standard`in r))throw new t.t([{path:e,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=r[`~standard`].validate(i);if(a instanceof Promise)throw new t.t([{path:e,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let t of a.issues){let n=o(e,t.path),r=t.message;c&&g.includes(e)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${e}' lacks Standard JSON Schema support.)`),f.push({path:n,message:r})}else d[e]=a.value;m.delete(e)}if(s!==`delete`)for(let e of m)s===`reject`?f.push({path:e,message:`Undeclared key`}):s===`ignore`&&(d[e]=h[e]);if(f.length>0)throw new t.t(f);return d}function c(e,t){i(e);for(let t in e){let i=e[t];n(t,i),r(t,i)}return s(e,t??{})}exports.arkenv=c,exports.default=c;
|
|
2
2
|
|
|
3
3
|
// CJS Interop Shim
|
|
4
4
|
if (module.exports && module.exports.default) {
|
package/dist/standard.d.cts
CHANGED
|
@@ -54,7 +54,7 @@ type ParseStandardConfig = {
|
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/standard.d.ts
|
|
56
56
|
/**
|
|
57
|
-
* Configuration options for the `arkenv/standard` entry's `
|
|
57
|
+
* Configuration options for the `arkenv/standard` entry's `arkenv`.
|
|
58
58
|
*/
|
|
59
59
|
type StandardEnvConfig = ParseStandardConfig;
|
|
60
60
|
/**
|
|
@@ -79,15 +79,9 @@ type StandardEnvConfig = ParseStandardConfig;
|
|
|
79
79
|
* });
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
declare function
|
|
83
|
-
/**
|
|
84
|
-
* ArkEnv's Standard Schema export, an alias for {@link createEnv}
|
|
85
|
-
*
|
|
86
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
87
|
-
*/
|
|
88
|
-
declare const arkenv: typeof createEnv;
|
|
82
|
+
declare function arkenv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: StandardEnvConfig): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
|
|
89
83
|
//#endregion
|
|
90
|
-
export { StandardEnvConfig,
|
|
84
|
+
export { StandardEnvConfig, arkenv, arkenv as default };
|
|
91
85
|
|
|
92
86
|
// CJS Interop Shim
|
|
93
87
|
if (module.exports && module.exports.default) {
|
package/dist/standard.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.cts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAWY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;;ACJP;;EDiBC,eAAA;ECjB+B;;AAwBhC;;;;;;EDEC,MAAA;ECCgB;;;;;;;;EDQhB,WAAA;ECVK;;;;;;;;;EDqBL,gBAAA;AAAA;;;;AA9CD;;KCAY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;iBAAgB,
|
|
1
|
+
{"version":3,"file":"standard.d.cts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAWY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;;ACJP;;EDiBC,eAAA;ECjB+B;;AAwBhC;;;;;;EDEC,MAAA;ECCgB;;;;;;;;EDQhB,WAAA;ECVK;;;;;;;;;EDqBL,gBAAA;AAAA;;;;AA9CD;;KCAY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;iBAAgB,MAAA,iBAAuB,MAAA,SAAe,gBAAA,EAAA,CACrD,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,iBAAA,iBACO,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA"}
|
package/dist/standard.d.mts
CHANGED
|
@@ -54,7 +54,7 @@ type ParseStandardConfig = {
|
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/standard.d.ts
|
|
56
56
|
/**
|
|
57
|
-
* Configuration options for the `arkenv/standard` entry's `
|
|
57
|
+
* Configuration options for the `arkenv/standard` entry's `arkenv`.
|
|
58
58
|
*/
|
|
59
59
|
type StandardEnvConfig = ParseStandardConfig;
|
|
60
60
|
/**
|
|
@@ -79,14 +79,8 @@ type StandardEnvConfig = ParseStandardConfig;
|
|
|
79
79
|
* });
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
declare function
|
|
83
|
-
/**
|
|
84
|
-
* ArkEnv's Standard Schema export, an alias for {@link createEnv}
|
|
85
|
-
*
|
|
86
|
-
* {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.
|
|
87
|
-
*/
|
|
88
|
-
declare const arkenv: typeof createEnv;
|
|
82
|
+
declare function arkenv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: StandardEnvConfig): { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
|
|
89
83
|
//#endregion
|
|
90
|
-
export { StandardEnvConfig,
|
|
84
|
+
export { StandardEnvConfig, arkenv, arkenv as default };
|
|
91
85
|
|
|
92
86
|
//# sourceMappingURL=standard.d.mts.map
|
package/dist/standard.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAWY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;;ACJP;;EDiBC,eAAA;ECjB+B;;AAwBhC;;;;;;EDEC,MAAA;ECCgB;;;;;;;;EDQhB,WAAA;ECVK;;;;;;;;;EDqBL,gBAAA;AAAA;;;;AA9CD;;KCAY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;iBAAgB,
|
|
1
|
+
{"version":3,"file":"standard.d.mts","names":[],"sources":["../src/parse-standard.ts","../src/standard.ts"],"mappings":";;;;;;KAWY,mBAAA;EAAmB;;;EAI9B,GAAA,GAAM,MAAA;EAAA;;;;;;;;;;ACJP;;EDiBC,eAAA;ECjB+B;;AAwBhC;;;;;;EDEC,MAAA;ECCgB;;;;;;;;EDQhB,WAAA;ECVK;;;;;;;;;EDqBL,gBAAA;AAAA;;;;AA9CD;;KCAY,iBAAA,GAAoB,mBAAA;;;;;;;;;;;;;AAAhC;;;;;AAwBA;;;;;iBAAgB,MAAA,iBAAuB,MAAA,SAAe,gBAAA,EAAA,CACrD,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,iBAAA,iBACO,CAAA,GAAI,gBAAA,CAAiB,WAAA,CAAY,CAAA,CAAE,CAAA"}
|
package/dist/standard.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./shared-B7lIFzfk.mjs";import{t as r}from"./core-B0IkKRzg.mjs";function i(e,t){if(typeof t==`string`)throw new r([{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.`}])}function a(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 r([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function o(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new r([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function s(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function c(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function l(i,a){let{env:o=process.env,onUndeclaredKey:l=`delete`,coerce:u=!0,arrayFormat:d=`comma`,emptyAsUndefined:f=!1}=a,p={},m=[],h=f?t(o):o,g=new Set(Object.keys(h)),_={...h},v=[];if(u){let{jsonSchema:t,hasJsonSchema:r}=s(i,v);r&&(_=n(_,e(t),{arrayFormat:d}))}for(let e in i){let t=i[e],n=_[e];if(!t||typeof t!=`object`||!(`~standard`in t))throw new r([{path:e,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=t[`~standard`].validate(n);if(a instanceof Promise)throw new r([{path:e,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let t of a.issues){let n=c(e,t.path),r=t.message;u&&v.includes(e)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${e}' lacks Standard JSON Schema support.)`),m.push({path:n,message:r})}else p[e]=a.value;g.delete(e)}if(l!==`delete`)for(let e of g)l===`reject`?m.push({path:e,message:`Undeclared key`}):l===`ignore`&&(p[e]=_[e]);if(m.length>0)throw new r(m);return p}function u(e,t){o(e);for(let t in e){let n=e[t];i(t,n),a(t,n)}return l(e,t??{})}
|
|
1
|
+
import{n as e,r as t,t as n}from"./shared-B7lIFzfk.mjs";import{t as r}from"./core-B0IkKRzg.mjs";function i(e,t){if(typeof t==`string`)throw new r([{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.`}])}function a(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 r([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`}])}function o(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new r([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`}])}function s(e,t){let n={type:`object`,properties:{}},r=!1;for(let i in e){let a=e[i];if(!a){t.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){n.properties[i]=e,r=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){n.properties[i]=e,r=!0;continue}}catch{}t.push(i)}return{jsonSchema:n,hasJsonSchema:r}}function c(e,t){return!t||t.length===0?e:[e,...t.map(e=>typeof e==`object`&&e&&`key`in e?String(e.key):String(e))].join(`.`)}function l(i,a){let{env:o=process.env,onUndeclaredKey:l=`delete`,coerce:u=!0,arrayFormat:d=`comma`,emptyAsUndefined:f=!1}=a,p={},m=[],h=f?t(o):o,g=new Set(Object.keys(h)),_={...h},v=[];if(u){let{jsonSchema:t,hasJsonSchema:r}=s(i,v);r&&(_=n(_,e(t),{arrayFormat:d}))}for(let e in i){let t=i[e],n=_[e];if(!t||typeof t!=`object`||!(`~standard`in t))throw new r([{path:e,message:`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`}]);let a=t[`~standard`].validate(n);if(a instanceof Promise)throw new r([{path:e,message:`Async validation is not supported. ArkEnv is synchronous.`}]);if(a.issues)for(let t of a.issues){let n=c(e,t.path),r=t.message;u&&v.includes(e)&&(r+=` (Hint: coercion is enabled by default, but the validator for '${e}' lacks Standard JSON Schema support.)`),m.push({path:n,message:r})}else p[e]=a.value;g.delete(e)}if(l!==`delete`)for(let e of g)l===`reject`?m.push({path:e,message:`Undeclared key`}):l===`ignore`&&(p[e]=_[e]);if(m.length>0)throw new r(m);return p}function u(e,t){o(e);for(let t in e){let n=e[t];i(t,n),a(t,n)}return l(e,t??{})}export{u as arkenv,u as default};
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=standard.mjs.map
|
package/dist/standard.mjs.map
CHANGED
|
@@ -1 +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 {\n\tapplyCoercion,\n\tfindCoercionPaths,\n\tstripEmptyStrings,\n} from \"./coercion/shared\";\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\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\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\n/**\n * Extract JSON Schema definitions from standard schema validators.\n */\nfunction extractJsonSchema(\n\tdef: Record<string, unknown>,\n\tmissingJsonSchemaKeys: string[],\n): { jsonSchema: Record<string, any>; hasJsonSchema: boolean } {\n\tconst jsonSchema: Record<string, any> = { type: \"object\", properties: {} };\n\tlet hasJsonSchema = false;\n\n\tfor (const key in def) {\n\t\tconst validator = def[key] as any;\n\t\tif (!validator) {\n\t\t\tmissingJsonSchemaKeys.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\tmissingJsonSchemaKeys.push(key);\n\t}\n\n\treturn { jsonSchema, hasJsonSchema };\n}\n\n/**\n * Format standard schema validation issue path.\n */\nfunction 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\n\tconst segments = path.map((segment) =>\n\t\tsegment !== null && typeof segment === \"object\" && \"key\" in segment\n\t\t\t? String(segment.key)\n\t\t\t: String(segment),\n\t);\n\treturn [key, ...segments].join(\".\");\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) {\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: ValidationIssue[] = [];\n\n\tconst processedEnv = emptyAsUndefined\n\t\t? stripEmptyStrings(env as Record<string, string | undefined>)\n\t\t: env;\n\tconst envKeys = new Set(Object.keys(processedEnv));\n\n\tlet coercedEnv: Record<string, unknown> = { ...processedEnv };\n\tconst missingJsonSchemaKeys: string[] = [];\n\n\tif (coerce) {\n\t\tconst { jsonSchema, hasJsonSchema } = extractJsonSchema(\n\t\t\tdef,\n\t\t\tmissingJsonSchemaKeys,\n\t\t);\n\t\tif (hasJsonSchema) {\n\t\t\tcoercedEnv = applyCoercion(coercedEnv, findCoercionPaths(jsonSchema), {\n\t\t\t\tarrayFormat,\n\t\t\t}) as Record<string, unknown>;\n\t\t}\n\t}\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\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 = formatIssuePath(key, issue.path);\n\t\t\t\tlet message = issue.message;\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\tpath: issuePath,\n\t\t\t\t\tmessage,\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] = 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 {\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":"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"}
|
|
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 {\n\tapplyCoercion,\n\tfindCoercionPaths,\n\tstripEmptyStrings,\n} from \"./coercion/shared\";\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\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\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\n/**\n * Extract JSON Schema definitions from standard schema validators.\n */\nfunction extractJsonSchema(\n\tdef: Record<string, unknown>,\n\tmissingJsonSchemaKeys: string[],\n): { jsonSchema: Record<string, any>; hasJsonSchema: boolean } {\n\tconst jsonSchema: Record<string, any> = { type: \"object\", properties: {} };\n\tlet hasJsonSchema = false;\n\n\tfor (const key in def) {\n\t\tconst validator = def[key] as any;\n\t\tif (!validator) {\n\t\t\tmissingJsonSchemaKeys.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\tmissingJsonSchemaKeys.push(key);\n\t}\n\n\treturn { jsonSchema, hasJsonSchema };\n}\n\n/**\n * Format standard schema validation issue path.\n */\nfunction 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\n\tconst segments = path.map((segment) =>\n\t\tsegment !== null && typeof segment === \"object\" && \"key\" in segment\n\t\t\t? String(segment.key)\n\t\t\t: String(segment),\n\t);\n\treturn [key, ...segments].join(\".\");\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) {\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: ValidationIssue[] = [];\n\n\tconst processedEnv = emptyAsUndefined\n\t\t? stripEmptyStrings(env as Record<string, string | undefined>)\n\t\t: env;\n\tconst envKeys = new Set(Object.keys(processedEnv));\n\n\tlet coercedEnv: Record<string, unknown> = { ...processedEnv };\n\tconst missingJsonSchemaKeys: string[] = [];\n\n\tif (coerce) {\n\t\tconst { jsonSchema, hasJsonSchema } = extractJsonSchema(\n\t\t\tdef,\n\t\t\tmissingJsonSchemaKeys,\n\t\t);\n\t\tif (hasJsonSchema) {\n\t\t\tcoercedEnv = applyCoercion(coercedEnv, findCoercionPaths(jsonSchema), {\n\t\t\t\tarrayFormat,\n\t\t\t}) as Record<string, unknown>;\n\t\t}\n\t}\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\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 = formatIssuePath(key, issue.path);\n\t\t\t\tlet message = issue.message;\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\tpath: issuePath,\n\t\t\t\t\tmessage,\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] = 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 {\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 `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\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 arkenv<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\n *\n * {@link https://arkenv.js.org | ArkEnv} is a typesafe environment variables validator from editor to runtime.\n */\nexport default arkenv;\n"],"mappings":"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"}
|
package/package.json
CHANGED