@arkenv/standard 1.0.0-alpha.10
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/LICENSE +24 -0
- package/dist/bind-arkenv-C8RYZhdK.js +1 -0
- package/dist/dist-CkiUgOD9.js +4 -0
- package/dist/index-CHZF-Mlg.d.ts +630 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/safe.d.ts +35 -0
- package/dist/safe.js +1 -0
- package/dist/valibot.d.ts +29 -0
- package/dist/valibot.js +1 -0
- package/dist/zod-mini.d.ts +30 -0
- package/dist/zod-mini.js +1 -0
- package/package.json +122 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yam Borodetsky <https://yam.codes/>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
The `apps/dash` maintainer dashboard is licensed separately under
|
|
24
|
+
AGPL-3.0-or-later. See `apps/dash/LICENSE`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{arkenv as e}from"./index.js";function t(t){function n(n,r){return e(n,{...r,toJsonSchema:r?.toJsonSchema??t})}return n}export{t};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const e=`ArkEnvError`,t=e=>{if(typeof e==`number`||typeof e!=`string`||!e.trim())return e;if(e.trim()===`NaN`)return NaN;let t=Number(e);return Number.isNaN(t)?e:t},n=e=>e===`true`?!0:e===`false`?!1:e,r=e=>{if(typeof e!=`string`)return e;let t=e.trim();if(t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}},i=e=>{if(e instanceof Date||typeof e!=`string`||!e.trim())return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t},a=e=>{let t={};for(let n in e){let r=e[n];r!==``&&(t[n]=r)}return t},o=(e,t=[])=>{let n=[];if(!e||typeof e!=`object`||Array.isArray(e))return n;let r=e;if(`const`in r){let e=typeof r.const;(e===`number`||e===`boolean`)&&n.push({path:[...t],type:`primitive`})}`enum`in r&&Array.isArray(r.enum)&&r.enum.some(e=>typeof e==`number`||typeof e==`boolean`)&&n.push({path:[...t],type:`primitive`});let i=r.type;if(i===`number`||i===`integer`||i===`boolean`)n.push({path:[...t],type:`primitive`});else if(i===`string`&&`format`in r&&(r.format===`date-time`||r.format===`date`))n.push({path:[...t],type:`date`});else if(i===`object`){if(r.properties&&Object.keys(r.properties).length>0){n.push({path:[...t],type:`object`});for(let e in r.properties)n.push(...o(r.properties[e],[...t,e]))}}else i===`array`&&(n.push({path:[...t],type:`array`}),r.items&&(Array.isArray(r.items)?r.items.forEach((e,r)=>{n.push(...o(e,[...t,String(r)]))}):n.push(...o(r.items,[...t,`*`]))));for(let e of[`anyOf`,`allOf`,`oneOf`])if(r[e]&&Array.isArray(r[e]))for(let i of r[e])n.push(...o(i,t));let a=new Set;return n.filter(e=>{let t=e.path.join(`/`)+`:`+e.type;return a.has(t)?!1:a.add(t)})},s=(e,a,o={})=>{let{arrayFormat:s=`comma`}=o,c=e=>{if(s===`json`)try{return JSON.parse(e)}catch{return e}return e.trim()?e.split(`,`).map(e=>e.trim()):[]},l=(e,a)=>{if(a===`array`&&typeof e==`string`)return c(e);if(a===`object`&&typeof e==`string`)return r(e);if(a===`date`&&typeof e==`string`)return i(e);if(a===`primitive`){if(Array.isArray(e))return e.map(e=>{if(typeof e!=`string`)return e;let r=t(e);return typeof r==`number`?r:n(e)});if(typeof e!=`string`)return e;let r=t(e);return typeof r==`number`?r:n(e)}return e};if(typeof e!=`object`||!e){let t=a.find(e=>e.path.length===0);return t?l(e,t.type):e}let u=[...a].sort((e,t)=>e.path.length-t.path.length),d=(e,t,n)=>{if(t.length===0)return n(e);let[r,...i]=t;if(r===`*`){if(Array.isArray(e)){let t=!1,r=e.map(e=>{let r=d(e,i,n);return r!==e&&(t=!0),r});return t?r:e}return e}if(!e||typeof e!=`object`)return e;if(Array.isArray(e)){let t=Number(r);if(!Number.isNaN(t)&&t>=0&&t<e.length){let r=d(e[t],i,n);if(r!==e[t]){let n=[...e];return n[t]=r,n}}return e}if(Object.hasOwn(e,r)){let t=d(e[r],i,n);if(t!==e[r])return{...e,[r]:t}}return e},f=e;for(let e of u)e.path.length>0&&(f=d(f,e.path,t=>l(t,e.type)));return f};function c(e,t,n,r){let i=t?a(e):e,c={...i},l=[];if(r){let e=r();l.push(...e.missingKeys||[]),e.hasSchema&&(c=s(c,o(e.schema),{arrayFormat:n}))}return{processedEnv:i,coercedEnv:c,missingKeys:l}}const l=(e,t=2,{dontDetectNewlines:n=!1}={})=>n?`${` `.repeat(t)}${e}`:e.split(`
|
|
2
|
+
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
+
`),u={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},d=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,f=()=>!!(!d()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),p=(e,t)=>d()&&!f()?`${u[e]}${t}${u.reset}`:t;function m(e){return e.map(e=>`${p(`yellow`,e.path)} ${e.message.trimStart()}`).join(`
|
|
4
|
+
`)}var h=class extends Error{constructor(t,n=`Errors found while validating environment variables`){let r=m(t);super(`${p(`red`,n)}\n${l(r)}\n`),this.name=e,this.issues=t}};Object.defineProperty(h,`name`,{value:e});function g(e,t){if(typeof t==`string`)throw new h([{path:e,message:`ArkType DSL strings are not supported in "standard" mode. Use a Standard Schema validator (e.g., Zod, Valibot) or import from "arkenv" for ArkType schemas.`,code:`INVALID_SCHEMA`}])}function _(e,t){let n=t&&typeof t==`object`&&`~standard`in t&&t[`~standard`];if(!n||typeof n!=`object`||!(`validate`in n)||typeof n.validate!=`function`)throw new h([{path:e,message:`Invalid validator: expected a Standard Schema 1.0 validator (must have "~standard" property). Import from "arkenv" to use ArkType schemas.`,code:`INVALID_SCHEMA`}])}function v(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new h([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`,code:`INVALID_SCHEMA`}])}const y=/secret|(_|^)key(_|$)|token|(_|^)password(_|$)|(_|^)pass(_|$)|(_|^)auth(_|$)|jwt|cert|credential|database_url|db_url/i;function b(e){if(e!==void 0)return e;if(typeof process>`u`)return!1;let t=process.env.ARKENV_DEBUG_SECRETS;return t===`true`||t===`1`}function x(e){return y.test(e)&&!/public/i.test(e)}function S(e,t,n){let r=b(n?.debugSecrets);if(e===void 0)return`missing`;if(e===null)return`null`;if(!r&&x(t))return`[REDACTED]`;if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return String(e);if(typeof e==`symbol`)return e.toString();if(typeof e==`function`)return`[Function]`;if(e&&typeof e==`object`)try{if(Array.isArray(e)){let r=e.slice(0,3).map(e=>S(e,t,n));return e.length>3&&r.push(`...(+${e.length-3} more)`),`[${r.join(`, `)}]`}let r=Object.keys(e),i=r.slice(0,3).map(r=>`${r}: ${S(e[r],t,n)}`);return r.length>3&&i.push(`...(+${r.length-3} more)`),`{ ${i.join(`, `)} }`}catch{return Object.prototype.toString.call(e)}return String(e)}const C={too_small:`VALUE_TOO_SMALL`,too_big:`VALUE_TOO_LARGE`,invalid_string:`INVALID_FORMAT`,invalid_date:`INVALID_FORMAT`,custom:`INVALID_FORMAT`};function w(e,t,n){let r=t.toLowerCase();return e===`invalid_type`&&(n===void 0||n===`undefined`)||r===`required`?`MISSING_VARIABLE`:e in C?C[e]:/regex|pattern|match/.test(r)?`PATTERN_MISMATCH`:`INVALID_TYPE`}function T(e){let t=e.minimum??e.min,n=e.maximum??e.max;return{...typeof t==`number`?{min:t}:{},...typeof n==`number`?{max:n}:{}}}function E(e){try{return{success:!0,data:e()}}catch(e){if(e instanceof h)return{success:!1,issues:e.issues};throw e}}function D(e,t,n,r,i,a){let o={path:e,message:t,code:n,meta:r??{}};return i&&(o.expected=i),a!==void 0&&(o.received=a),o}function O(e,t,n,r,i,a){if(t===`MISSING_VARIABLE`)return n?`must be ${n} (was missing)`:`is required`;if(e.includes(`(was `))return e;let o=`(was ${p(`cyan`,!b(a?.debugSecrets)&&x(i)?`[REDACTED]`:S(r,i,a))})`;return n&&!e.includes(`Expected`)?`must be ${n} ${o}`:`${e} ${o}`}const k=[`draft-07`,`draft-2020-12`];function A(e){return Object.prototype.toString.call(e)===`[object Object]`}function j(e){let t=`converter returned a non-schema`;for(let n of k)try{let r=e({target:n});if(A(r))return{ok:!0,schema:r};t=`converter returned a non-schema`}catch(e){t=e instanceof Error?e.message:String(e)}return{ok:!1,detail:t}}function M(e,t){throw new h([D(e,`JSON Schema conversion failed for '${e}': ${t}`,`INVALID_SCHEMA`)])}function N(e,t){let n={type:`object`,properties:{}},r=!1,i=[];for(let a in e){let o=e[a];if(!o){i.push(a);continue}let s=o[`~standard`];if(typeof s?.jsonSchema?.input==`function`){let e=j(s.jsonSchema.input);if(e.ok){n.properties[a]=e.schema,r=!0;continue}M(a,e.detail)}if(typeof o.jsonSchema?.input==`function`){let e=j(o.jsonSchema.input);if(e.ok){n.properties[a]=e.schema,r=!0;continue}M(a,e.detail)}if(typeof o.toJSONSchema==`function`)try{let e=o.toJSONSchema();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(typeof o.toStandardJSONSchema?.v1==`function`)try{let e=o.toStandardJSONSchema.v1();if(e){n.properties[a]=e,r=!0;continue}}catch{}if(t){let e;try{e=t(o)}catch(e){throw new h([D(a,`toJsonSchema failed for '${a}': ${e instanceof Error?e.message:String(e)}`,`INVALID_SCHEMA`)])}if(!e){i.push(a);continue}if(!A(e))throw new h([D(a,`toJsonSchema must return a plain object or undefined for '${a}'.`,`INVALID_SCHEMA`)]);n.properties[a]=e,r=!0;continue}i.push(a)}return{jsonSchema:n,hasJsonSchema:r,missingKeys:i}}function P(e){return typeof e==`object`&&e&&`key`in e?String(e.key):String(e)}function F(e,t){return!t||t.length===0?e:[e,...t.map(P)].join(`.`)}function I(e,t){let n=e,r;try{let i=e,a=e.trim();if(a[0]===`{`||a[0]===`[`)try{i=JSON.parse(e)}catch(e){r=`[Unparseable JSON: ${e.message}]`}if(!r){for(let e of t)i=i?.[P(e)];n=i}}catch(e){r=`[Traversal error: ${e.message}]`}return{receivedVal:n,traversalError:r}}function L(e,t){let{env:n=process.env,onUndeclaredKey:r=`delete`,coerce:i=!0,arrayFormat:a=`comma`,emptyAsUndefined:o=!1,toJsonSchema:s}=t,l={},u=[],{processedEnv:d,coercedEnv:f,missingKeys:p}=c(n,o,a,i?()=>{let{jsonSchema:t,hasJsonSchema:n,missingKeys:r}=N(e,s);return{schema:t,hasSchema:n,missingKeys:r}}:void 0),m=new Set(Object.keys(d));for(let n in e){let r=e[n],a=f[n];if(!r||typeof r!=`object`||!(`~standard`in r))throw new h([D(n,`Invalid schema: expected a Standard Schema 1.0 validator (e.g. Zod, Valibot) in 'standard' mode.`,`INVALID_SCHEMA`)]);let o=r[`~standard`].validate(a);if(o instanceof Promise)throw new h([D(n,`Async validation is not supported. ArkEnv is synchronous.`,`INVALID_SCHEMA`)]);if(o.issues)for(let e of o.issues){let r=F(n,e.path),a,o;if(n in d){let t=d[n];if(typeof t==`string`&&e.path?.length){let n=I(t,e.path);a=n.receivedVal,o=n.traversalError}else a=t}else a=e.received;let s=w(e.code||`invalid_type`,e.message||``,a),c=e.expected||void 0,l={...T(e)},f=e;f.validation!==void 0&&(l.validation=f.validation),o!==void 0&&(l.traversalError=o);let m=O(e.message||``,s,c,a,r,t);i&&p.includes(n)&&(m+=` (Hint: coercion is enabled by default, but the validator for '${n}' lacks Standard JSON Schema support.)`),u.push(D(r,m,s,l,c,a))}else l[n]=o.value;m.delete(n)}if(r!==`delete`)for(let e of m)r===`reject`?u.push(D(e,`Undeclared key`,`UNDECLARED_KEY`)):r===`ignore`&&(l[e]=f[e]);if(u.length>0)throw new h(u);return l}function R(e){if(!e||typeof e!=`object`&&typeof e!=`function`)return[];if(e.json&&typeof e.json==`object`&&e.json.domain===`object`){let t=[];if(Array.isArray(e.json.required))for(let n of e.json.required)n&&typeof n==`object`&&`key`in n&&t.push(n.key);if(Array.isArray(e.json.optional))for(let n of e.json.optional)n&&typeof n==`object`&&`key`in n&&t.push(n.key);return t}let t=e[`~standard`],n=typeof t?.jsonSchema?.input==`function`&&t.jsonSchema.input||typeof e.jsonSchema?.input==`function`&&e.jsonSchema.input;if(n)try{let e=n({target:`draft-07`});if(e&&typeof e==`object`&&e.properties)return Object.keys(e.properties)}catch{}if(typeof e.toJSONSchema==`function`)try{let t=e.toJSONSchema();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}if(typeof e.toStandardJSONSchema?.v1==`function`)try{let t=e.toStandardJSONSchema.v1();if(t&&typeof t==`object`&&t.properties)return Object.keys(t.properties)}catch{}return Object.keys(e)}const z=Symbol.for(`arkenv.schemaCapture.v1`);function B(){let e=globalThis;return e[z]||(e[z]={capturing:!1,definitions:[]}),e[z]}function V(){return B().capturing}function H(e){let t=B();t.capturing&&t.definitions.push(e)}export{m as a,L as c,v as i,H as l,g as n,R as o,_ as r,V as s,h as t,E as u};
|
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
//#region ../internal/types/dist/standard-schema.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
4
|
+
*
|
|
5
|
+
* Copied from standard-schema (MIT License)
|
|
6
|
+
* Copyright (c) 2024 Colin McDannell
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
10
|
+
*/
|
|
11
|
+
interface StandardTypedV1$1<Input = unknown, Output = Input> {
|
|
12
|
+
/**
|
|
13
|
+
* The Standard properties.
|
|
14
|
+
*/
|
|
15
|
+
readonly "~standard": StandardTypedV1$1.Props<Input, Output>;
|
|
16
|
+
}
|
|
17
|
+
declare namespace StandardTypedV1$1 {
|
|
18
|
+
/**
|
|
19
|
+
* The Standard Typed properties interface.
|
|
20
|
+
*/
|
|
21
|
+
interface Props<Input = unknown, Output = Input> {
|
|
22
|
+
/**
|
|
23
|
+
* The version number of the standard.
|
|
24
|
+
*/
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/**
|
|
27
|
+
* The vendor name of the schema library.
|
|
28
|
+
*/
|
|
29
|
+
readonly vendor: string;
|
|
30
|
+
/**
|
|
31
|
+
* Inferred types associated with the schema.
|
|
32
|
+
*/
|
|
33
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The Standard Typed types interface.
|
|
37
|
+
*/
|
|
38
|
+
interface Types<Input = unknown, Output = Input> {
|
|
39
|
+
/**
|
|
40
|
+
* The input type of the schema.
|
|
41
|
+
*/
|
|
42
|
+
readonly input: Input;
|
|
43
|
+
/**
|
|
44
|
+
* The output type of the schema.
|
|
45
|
+
*/
|
|
46
|
+
readonly output: Output;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Infers the input type of a Standard Typed.
|
|
50
|
+
*/
|
|
51
|
+
type InferInput<Schema extends StandardTypedV1$1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
52
|
+
/**
|
|
53
|
+
* Infers the output type of a Standard Typed.
|
|
54
|
+
*/
|
|
55
|
+
type InferOutput<Schema extends StandardTypedV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Standard Schema interface.
|
|
59
|
+
*/
|
|
60
|
+
interface StandardSchemaV1$1<Input = unknown, Output = Input> {
|
|
61
|
+
/**
|
|
62
|
+
* The Standard Schema properties.
|
|
63
|
+
*/
|
|
64
|
+
readonly "~standard": StandardSchemaV1$1.Props<Input, Output>;
|
|
65
|
+
}
|
|
66
|
+
declare namespace StandardSchemaV1$1 {
|
|
67
|
+
/**
|
|
68
|
+
* The Standard Schema properties interface.
|
|
69
|
+
*/
|
|
70
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1$1.Props<Input, Output> {
|
|
71
|
+
/**
|
|
72
|
+
* Validates unknown input values.
|
|
73
|
+
*/
|
|
74
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1$1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The result interface of the validate function.
|
|
78
|
+
*/
|
|
79
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
80
|
+
/**
|
|
81
|
+
* The result interface if validation succeeds.
|
|
82
|
+
*/
|
|
83
|
+
interface SuccessResult<Output> {
|
|
84
|
+
/**
|
|
85
|
+
* The typed output value.
|
|
86
|
+
*/
|
|
87
|
+
readonly value: Output;
|
|
88
|
+
/**
|
|
89
|
+
* A falsy value for `issues` indicates success.
|
|
90
|
+
*/
|
|
91
|
+
readonly issues?: undefined;
|
|
92
|
+
}
|
|
93
|
+
interface Options {
|
|
94
|
+
/**
|
|
95
|
+
* Explicit support for additional vendor-specific parameters, if needed.
|
|
96
|
+
*/
|
|
97
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The result interface if validation fails.
|
|
101
|
+
*/
|
|
102
|
+
interface FailureResult {
|
|
103
|
+
/**
|
|
104
|
+
* The issues of failed validation.
|
|
105
|
+
*/
|
|
106
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The issue interface of the failure output.
|
|
110
|
+
*/
|
|
111
|
+
interface Issue {
|
|
112
|
+
/**
|
|
113
|
+
* The error message of the issue.
|
|
114
|
+
*/
|
|
115
|
+
readonly message: string;
|
|
116
|
+
/**
|
|
117
|
+
* The path of the issue, if any.
|
|
118
|
+
*/
|
|
119
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The path segment interface of the issue.
|
|
123
|
+
*/
|
|
124
|
+
interface PathSegment {
|
|
125
|
+
/**
|
|
126
|
+
* The key representing a path segment.
|
|
127
|
+
*/
|
|
128
|
+
readonly key: PropertyKey;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The Standard types interface.
|
|
132
|
+
*/
|
|
133
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1$1.Types<Input, Output> {}
|
|
134
|
+
/**
|
|
135
|
+
* Infers the input type of a Standard.
|
|
136
|
+
*/
|
|
137
|
+
type InferInput<Schema extends StandardTypedV1$1> = StandardTypedV1$1.InferInput<Schema>;
|
|
138
|
+
/**
|
|
139
|
+
* Infers the output type of a Standard.
|
|
140
|
+
*/
|
|
141
|
+
type InferOutput<Schema extends StandardTypedV1$1> = StandardTypedV1$1.InferOutput<Schema>;
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region ../internal/utils/dist/index.d.ts
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region ../types/dist/standard-schema.d.ts
|
|
147
|
+
/**
|
|
148
|
+
* @see https://github.com/standard-schema/standard-schema/tree/3130ce43fdd848d9ab49dbb0458d04f18459961c/packages/spec
|
|
149
|
+
*
|
|
150
|
+
* Copied from standard-schema (MIT License)
|
|
151
|
+
* Copyright (c) 2024 Colin McDannell
|
|
152
|
+
*/
|
|
153
|
+
/**
|
|
154
|
+
* The Standard Typed interface. This is a base type extended by other specs.
|
|
155
|
+
*/
|
|
156
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
157
|
+
/**
|
|
158
|
+
* The Standard properties.
|
|
159
|
+
*/
|
|
160
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
161
|
+
}
|
|
162
|
+
declare namespace StandardTypedV1 {
|
|
163
|
+
/**
|
|
164
|
+
* The Standard Typed properties interface.
|
|
165
|
+
*/
|
|
166
|
+
interface Props<Input = unknown, Output = Input> {
|
|
167
|
+
/**
|
|
168
|
+
* The version number of the standard.
|
|
169
|
+
*/
|
|
170
|
+
readonly version: 1;
|
|
171
|
+
/**
|
|
172
|
+
* The vendor name of the schema library.
|
|
173
|
+
*/
|
|
174
|
+
readonly vendor: string;
|
|
175
|
+
/**
|
|
176
|
+
* Inferred types associated with the schema.
|
|
177
|
+
*/
|
|
178
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The Standard Typed types interface.
|
|
182
|
+
*/
|
|
183
|
+
interface Types<Input = unknown, Output = Input> {
|
|
184
|
+
/**
|
|
185
|
+
* The input type of the schema.
|
|
186
|
+
*/
|
|
187
|
+
readonly input: Input;
|
|
188
|
+
/**
|
|
189
|
+
* The output type of the schema.
|
|
190
|
+
*/
|
|
191
|
+
readonly output: Output;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Infers the input type of a Standard Typed.
|
|
195
|
+
*/
|
|
196
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
197
|
+
/**
|
|
198
|
+
* Infers the output type of a Standard Typed.
|
|
199
|
+
*/
|
|
200
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The Standard Schema interface.
|
|
204
|
+
*/
|
|
205
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
206
|
+
/**
|
|
207
|
+
* The Standard Schema properties.
|
|
208
|
+
*/
|
|
209
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
210
|
+
}
|
|
211
|
+
declare namespace StandardSchemaV1 {
|
|
212
|
+
/**
|
|
213
|
+
* The Standard Schema properties interface.
|
|
214
|
+
*/
|
|
215
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
216
|
+
/**
|
|
217
|
+
* Validates unknown input values.
|
|
218
|
+
*/
|
|
219
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The result interface of the validate function.
|
|
223
|
+
*/
|
|
224
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
225
|
+
/**
|
|
226
|
+
* The result interface if validation succeeds.
|
|
227
|
+
*/
|
|
228
|
+
interface SuccessResult<Output> {
|
|
229
|
+
/**
|
|
230
|
+
* The typed output value.
|
|
231
|
+
*/
|
|
232
|
+
readonly value: Output;
|
|
233
|
+
/**
|
|
234
|
+
* A falsy value for `issues` indicates success.
|
|
235
|
+
*/
|
|
236
|
+
readonly issues?: undefined;
|
|
237
|
+
}
|
|
238
|
+
interface Options {
|
|
239
|
+
/**
|
|
240
|
+
* Explicit support for additional vendor-specific parameters, if needed.
|
|
241
|
+
*/
|
|
242
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The result interface if validation fails.
|
|
246
|
+
*/
|
|
247
|
+
interface FailureResult {
|
|
248
|
+
/**
|
|
249
|
+
* The issues of failed validation.
|
|
250
|
+
*/
|
|
251
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The issue interface of the failure output.
|
|
255
|
+
*/
|
|
256
|
+
interface Issue {
|
|
257
|
+
/**
|
|
258
|
+
* The error message of the issue.
|
|
259
|
+
*/
|
|
260
|
+
readonly message: string;
|
|
261
|
+
/**
|
|
262
|
+
* The path of the issue, if any.
|
|
263
|
+
*/
|
|
264
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The path segment interface of the issue.
|
|
268
|
+
*/
|
|
269
|
+
interface PathSegment {
|
|
270
|
+
/**
|
|
271
|
+
* The key representing a path segment.
|
|
272
|
+
*/
|
|
273
|
+
readonly key: PropertyKey;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The Standard types interface.
|
|
277
|
+
*/
|
|
278
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
279
|
+
/**
|
|
280
|
+
* Infers the input type of a Standard.
|
|
281
|
+
*/
|
|
282
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
283
|
+
/**
|
|
284
|
+
* Infers the output type of a Standard.
|
|
285
|
+
*/
|
|
286
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
287
|
+
} //#endregion
|
|
288
|
+
//#region src/coercion/environment.d.ts
|
|
289
|
+
/**
|
|
290
|
+
* Prepare an environment record by optionally stripping empty strings and applying coercion.
|
|
291
|
+
*
|
|
292
|
+
* @param env The raw environment variables
|
|
293
|
+
* @param emptyAsUndefined Whether to strip empty string values before processing
|
|
294
|
+
* @param arrayFormat The format to use for array coercion
|
|
295
|
+
* @param getSchema Optional callback that returns a JSON Schema and whether it exists,
|
|
296
|
+
* used to determine coercion targets. When omitted, no coercion is performed.
|
|
297
|
+
* @returns The processed environment, the coerced environment, and any missing schema keys
|
|
298
|
+
*/
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/core.d.ts
|
|
301
|
+
/**
|
|
302
|
+
* Machine-readable classification codes for environment validation issues.
|
|
303
|
+
*/
|
|
304
|
+
type EnvIssueCode =
|
|
305
|
+
/**
|
|
306
|
+
* The environment variable is required but was not provided, and has no default value.
|
|
307
|
+
*/
|
|
308
|
+
"MISSING_VARIABLE"
|
|
309
|
+
/**
|
|
310
|
+
* The variable value failed a type assertion (e.g., expected a number or boolean but received a string).
|
|
311
|
+
*/
|
|
312
|
+
| "INVALID_TYPE"
|
|
313
|
+
/**
|
|
314
|
+
* The variable value falls below the minimum allowed numeric limit or string/array length constraint.
|
|
315
|
+
*/
|
|
316
|
+
| "VALUE_TOO_SMALL"
|
|
317
|
+
/**
|
|
318
|
+
* The variable value exceeds the maximum allowed numeric limit or string/array length constraint.
|
|
319
|
+
*/
|
|
320
|
+
| "VALUE_TOO_LARGE"
|
|
321
|
+
/**
|
|
322
|
+
* The variable value did not match the specified regular expression (regex) pattern constraint.
|
|
323
|
+
*/
|
|
324
|
+
| "PATTERN_MISMATCH"
|
|
325
|
+
/**
|
|
326
|
+
* The variable value is not in a valid format (e.g., failed email or UUID format validation).
|
|
327
|
+
*/
|
|
328
|
+
| "INVALID_FORMAT"
|
|
329
|
+
/**
|
|
330
|
+
* An undeclared key was found in the environment, and the schema config is set to reject undeclared keys.
|
|
331
|
+
*/
|
|
332
|
+
| "UNDECLARED_KEY"
|
|
333
|
+
/**
|
|
334
|
+
* The provided validation schema definition itself is malformed or invalid.
|
|
335
|
+
*/
|
|
336
|
+
| "INVALID_SCHEMA"
|
|
337
|
+
/**
|
|
338
|
+
* A validation error was triggered by a custom validator function or inline pipe logic.
|
|
339
|
+
*/
|
|
340
|
+
| "CUSTOM";
|
|
341
|
+
/**
|
|
342
|
+
* Metadata associated with an environment validation issue.
|
|
343
|
+
*/
|
|
344
|
+
type EnvIssueMeta = {
|
|
345
|
+
/**
|
|
346
|
+
* The minimum expected boundary for numeric/string length constraints
|
|
347
|
+
*/
|
|
348
|
+
min?: number;
|
|
349
|
+
/**
|
|
350
|
+
* The maximum expected boundary for numeric/string length constraints
|
|
351
|
+
*/
|
|
352
|
+
max?: number;
|
|
353
|
+
/**
|
|
354
|
+
* Additional validation pattern/specifier details
|
|
355
|
+
*/
|
|
356
|
+
validation?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Any custom constraint descriptions
|
|
359
|
+
*/
|
|
360
|
+
constraint?: string;
|
|
361
|
+
/**
|
|
362
|
+
* Traversal error occurred during JSON-parsing of the environment variable
|
|
363
|
+
*/
|
|
364
|
+
traversalError?: string;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Normalized validation issue representing a failure on a specific environment variable.
|
|
368
|
+
*/
|
|
369
|
+
type EnvIssue = {
|
|
370
|
+
/**
|
|
371
|
+
* The dot-separated property path/name of the environment variable
|
|
372
|
+
*/
|
|
373
|
+
path: string;
|
|
374
|
+
/**
|
|
375
|
+
* The descriptive, user-friendly error message
|
|
376
|
+
*/
|
|
377
|
+
message: string;
|
|
378
|
+
/**
|
|
379
|
+
* The normalized classification code for the issue
|
|
380
|
+
*/
|
|
381
|
+
code: EnvIssueCode;
|
|
382
|
+
/**
|
|
383
|
+
* The expected type or value shape description
|
|
384
|
+
*/
|
|
385
|
+
expected?: string;
|
|
386
|
+
/**
|
|
387
|
+
* The raw value received (redacted in string formatting if sensitive)
|
|
388
|
+
*/
|
|
389
|
+
received?: unknown;
|
|
390
|
+
/**
|
|
391
|
+
* Additional validation metadata
|
|
392
|
+
*/
|
|
393
|
+
meta?: EnvIssueMeta;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Format a list of normalized environment issues into a single styled string.
|
|
397
|
+
*
|
|
398
|
+
* @param issues - The array of normalized issues to format
|
|
399
|
+
* @returns The formatted and styled error report string
|
|
400
|
+
*/
|
|
401
|
+
declare function formatIssues(issues: EnvIssue[]): string;
|
|
402
|
+
/**
|
|
403
|
+
* Error thrown when environment variable validation fails.
|
|
404
|
+
*
|
|
405
|
+
* This error extends the native `Error` class and provides formatted error messages
|
|
406
|
+
* that clearly indicate which environment variables are invalid and why.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* try {
|
|
411
|
+
* const env = arkenv({
|
|
412
|
+
* PORT: 'number.port',
|
|
413
|
+
* HOST: 'string.host',
|
|
414
|
+
* });
|
|
415
|
+
* } catch (error) {
|
|
416
|
+
* if (error instanceof ArkEnvError) {
|
|
417
|
+
* console.error('Environment validation failed:', error.message);
|
|
418
|
+
* }
|
|
419
|
+
* }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare class ArkEnvError extends Error {
|
|
423
|
+
/**
|
|
424
|
+
* The list of normalized issues that caused the validation failure
|
|
425
|
+
*/
|
|
426
|
+
readonly issues: EnvIssue[];
|
|
427
|
+
constructor(issues: EnvIssue[], message?: string);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Result of a non-throwing arkenv parse operation.
|
|
431
|
+
*/
|
|
432
|
+
type SafeArkEnvResult<T> = {
|
|
433
|
+
success: true;
|
|
434
|
+
data: T;
|
|
435
|
+
} | {
|
|
436
|
+
success: false;
|
|
437
|
+
issues: readonly EnvIssue[];
|
|
438
|
+
}; //#endregion
|
|
439
|
+
//#region src/guards.d.ts
|
|
440
|
+
/**
|
|
441
|
+
* Throws if the given value is a string (ArkType DSL) in standard mode.
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/parse-standard.d.ts
|
|
446
|
+
/**
|
|
447
|
+
* Configuration options for {@link parseStandard}.
|
|
448
|
+
*/
|
|
449
|
+
type ParseStandardConfig = {
|
|
450
|
+
/**
|
|
451
|
+
* The environment variables to parse. Defaults to `process.env`.
|
|
452
|
+
*
|
|
453
|
+
* All values must be strings (or `undefined`) to match `process.env` semantics.
|
|
454
|
+
*/
|
|
455
|
+
env?: Record<string, string | undefined>;
|
|
456
|
+
/**
|
|
457
|
+
* Control how ArkEnv handles environment variables that are not defined in your schema.
|
|
458
|
+
*
|
|
459
|
+
* Defaults to `'delete'` so the output object only contains keys you've declared.
|
|
460
|
+
*
|
|
461
|
+
* - `delete` (default): Undeclared keys are allowed on input but stripped from the output.
|
|
462
|
+
* - `ignore`: Undeclared keys are allowed and preserved in the output.
|
|
463
|
+
* - `reject`: Undeclared keys will cause validation to fail.
|
|
464
|
+
*
|
|
465
|
+
* @default "delete"
|
|
466
|
+
*/
|
|
467
|
+
onUndeclaredKey?: "ignore" | "delete" | "reject";
|
|
468
|
+
/**
|
|
469
|
+
* Whether to bypass secret redaction and print raw sensitive values during debugging.
|
|
470
|
+
* Defaults to checking `process.env.ARKENV_DEBUG_SECRETS === "true"` or `"1"`.
|
|
471
|
+
*/
|
|
472
|
+
debugSecrets?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Whether to perform best-effort coercion on the environment variables.
|
|
475
|
+
* Coercion prefers validators that expose Standard JSON Schema on the value
|
|
476
|
+
* itself (e.g. Zod). For converters that live outside the schema (e.g. Valibot
|
|
477
|
+
* via `@valibot/to-json-schema`, Zod Mini via `z.toJSONSchema`, or Zod v3 via
|
|
478
|
+
* `zod-to-json-schema`), pass {@link toJsonSchema}.
|
|
479
|
+
*
|
|
480
|
+
* @see https://standard-schema.dev
|
|
481
|
+
* @default true
|
|
482
|
+
*/
|
|
483
|
+
coerce?: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Optional fallback that converts a Standard Schema validator to JSON Schema
|
|
486
|
+
* for ArkEnv pre-coercion when a key has no Standard JSON Schema on the value.
|
|
487
|
+
*
|
|
488
|
+
* Called per key only in that case. Not called when omitted, when `coerce` is
|
|
489
|
+
* `false`, or when JSON Schema was already read from the value.
|
|
490
|
+
*
|
|
491
|
+
* - Return a plain object to use as that key's JSON Schema.
|
|
492
|
+
* - Return `undefined` to skip coercion for that key only.
|
|
493
|
+
* - Throwing or returning a non-plain object fails the parse with
|
|
494
|
+
* {@link ArkEnvError} for that key (`INVALID_SCHEMA`).
|
|
495
|
+
*
|
|
496
|
+
* Typed as {@link StandardSchemaV1}. Host converters (Valibot, Zod Mini,
|
|
497
|
+
* Zod v3 via `zod-to-json-schema`) do not accept that type — assert at the
|
|
498
|
+
* converter call (`as v.GenericSchema`, `as z.ZodMiniType`,
|
|
499
|
+
* `as z.ZodTypeAny`). Same assertion for a single-library map and a hybrid
|
|
500
|
+
* with classic Zod (Zod never reaches this callback at runtime).
|
|
501
|
+
*
|
|
502
|
+
* @example Valibot wiring
|
|
503
|
+
* ```ts
|
|
504
|
+
* import { toJsonSchema } from "@valibot/to-json-schema";
|
|
505
|
+
* import * as v from "valibot";
|
|
506
|
+
*
|
|
507
|
+
* arkenv(
|
|
508
|
+
* { PORT: v.number() },
|
|
509
|
+
* {
|
|
510
|
+
* toJsonSchema: (schema) =>
|
|
511
|
+
* toJsonSchema(schema as v.GenericSchema, {
|
|
512
|
+
* typeMode: "input",
|
|
513
|
+
* target: "draft-07",
|
|
514
|
+
* }),
|
|
515
|
+
* },
|
|
516
|
+
* );
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* @example Zod v3 wiring
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { z } from "zod/v3";
|
|
522
|
+
* import { zodToJsonSchema } from "zod-to-json-schema";
|
|
523
|
+
*
|
|
524
|
+
* arkenv(
|
|
525
|
+
* { PORT: z.number() },
|
|
526
|
+
* {
|
|
527
|
+
* toJsonSchema: (schema) =>
|
|
528
|
+
* zodToJsonSchema(schema as z.ZodTypeAny, {
|
|
529
|
+
* $refStrategy: "none",
|
|
530
|
+
* }),
|
|
531
|
+
* },
|
|
532
|
+
* );
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
toJsonSchema?: (schema: StandardSchemaV1) => object | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* The format to use for array parsing when coercion is enabled.
|
|
538
|
+
*
|
|
539
|
+
* - `comma` (default): Strings are split by comma and trimmed.
|
|
540
|
+
* - `json`: Strings are parsed as JSON.
|
|
541
|
+
*
|
|
542
|
+
* @default "comma"
|
|
543
|
+
*/
|
|
544
|
+
arrayFormat?: "comma" | "json";
|
|
545
|
+
/**
|
|
546
|
+
* Whether to treat empty strings (`""`) as `undefined` before validation.
|
|
547
|
+
*
|
|
548
|
+
* When enabled, an environment variable set to an empty value (e.g. `PORT=`)
|
|
549
|
+
* will be treated as if it were missing, allowing defaults to apply and
|
|
550
|
+
* preventing validation errors for numeric or boolean types.
|
|
551
|
+
*
|
|
552
|
+
* @default false
|
|
553
|
+
*/
|
|
554
|
+
emptyAsUndefined?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Reserved for call-site compat. Pass `false` or omit.
|
|
557
|
+
* Use `arkenv` from `@arkenv/standard/safe` (or `@arkenv/core/safe`) instead of `{ safe: true }`.
|
|
558
|
+
*
|
|
559
|
+
* @default false
|
|
560
|
+
*/
|
|
561
|
+
safe?: false;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Parse and validate environment variables using Standard Schema 1.0 validators.
|
|
565
|
+
*
|
|
566
|
+
* @param def An object mapping environment variable keys to Standard Schema 1.0 validators
|
|
567
|
+
* @param config Parsing options, including environment source, undeclared key handling, and coercion config
|
|
568
|
+
* @returns The parsed and validated environment variables
|
|
569
|
+
* @throws An ArkEnvError if validation fails
|
|
570
|
+
*/
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/schema.d.ts
|
|
573
|
+
/**
|
|
574
|
+
* Extract the keys from a schema definition.
|
|
575
|
+
* Supports plain objects, ArkType schemas, and Standard Schema validators.
|
|
576
|
+
*
|
|
577
|
+
* @param schema The schema definition to extract keys from
|
|
578
|
+
* @returns An array of extracted key names
|
|
579
|
+
*/
|
|
580
|
+
declare function getSchemaKeys(schema: any): string[]; //#endregion
|
|
581
|
+
//#region src/schema-capture.d.ts
|
|
582
|
+
/**
|
|
583
|
+
* Start recording `arkenv()` schema arguments instead of validating the environment.
|
|
584
|
+
*
|
|
585
|
+
* CLI-supporting API: tools such as the ArkEnv CLI use this to inspect a user's
|
|
586
|
+
* schema module without requiring `process.env` to be populated.
|
|
587
|
+
*/
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region src/index.d.ts
|
|
590
|
+
/**
|
|
591
|
+
* Configuration options for `arkenv` from `@arkenv/standard`.
|
|
592
|
+
*
|
|
593
|
+
* `safe` is reserved for call-site compat — pass `false` or omit. Use
|
|
594
|
+
* `arkenv` from `@arkenv/standard/safe` for a result object.
|
|
595
|
+
*/
|
|
596
|
+
type StandardEnvConfig = Omit<ParseStandardConfig, "safe"> & {
|
|
597
|
+
/**
|
|
598
|
+
* Reserved for call-site compat. Pass `false` or omit.
|
|
599
|
+
* Use `arkenv` from `@arkenv/standard/safe` instead of `{ safe: true }`.
|
|
600
|
+
*
|
|
601
|
+
* @default false
|
|
602
|
+
*/
|
|
603
|
+
safe?: false;
|
|
604
|
+
};
|
|
605
|
+
type StandardEnvOutput<T extends Record<string, StandardSchemaV1$1>> = { [K in keyof T]: StandardSchemaV1$1.InferOutput<T[K]> };
|
|
606
|
+
/**
|
|
607
|
+
* Parse and validate environment variables using Standard Schema 1.0 validators (e.g. Zod, Valibot).
|
|
608
|
+
*
|
|
609
|
+
* This entry is ArkType-free - ArkType is never imported, even transitively.
|
|
610
|
+
* Use this when your project must not depend on ArkType.
|
|
611
|
+
*
|
|
612
|
+
* @param def An object mapping variable names to Standard Schema validators
|
|
613
|
+
* @param config Optional configuration
|
|
614
|
+
* @returns The validated environment variables, or a value-less stub when schema capture is active
|
|
615
|
+
* @throws An {@link ArkEnvError} if validation fails
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* import arkenv from "@arkenv/standard";
|
|
620
|
+
* import * as z from "zod";
|
|
621
|
+
*
|
|
622
|
+
* const env = arkenv({
|
|
623
|
+
* PORT: z.number(),
|
|
624
|
+
* HOST: z.string(),
|
|
625
|
+
* });
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
declare function arkenv<const T extends Record<string, StandardSchemaV1$1>>(def: T, config?: StandardEnvConfig): StandardEnvOutput<T>;
|
|
629
|
+
//#endregion
|
|
630
|
+
export { SafeArkEnvResult as a, StandardSchemaV1$1 as c, EnvIssue as i, arkenv as n, formatIssues as o, ArkEnvError as r, getSchemaKeys as s, StandardEnvConfig as t };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-CHZF-Mlg.js";
|
|
2
|
+
export { ArkEnvError, EnvIssue, SafeArkEnvResult, StandardEnvConfig, arkenv, arkenv as default, formatIssues, getSchemaKeys };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s,t as c}from"./dist-CkiUgOD9.js";function l(e,a){let c=a??{};n(e);for(let t in e){let n=e[t];i(t,n),o(t,n)}return s()?(r(e),{}):t(e,c)}export{c as ArkEnvError,l as arkenv,l as default,e as formatIssues,a as getSchemaKeys};
|
package/dist/safe.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { a as SafeArkEnvResult, c as StandardSchemaV1, t as StandardEnvConfig } from "./index-CHZF-Mlg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/safe.d.ts
|
|
4
|
+
type SafeStandardEnvConfig = Omit<StandardEnvConfig, "safe">;
|
|
5
|
+
type StandardEnvOutput<T extends Record<string, StandardSchemaV1>> = { [K in keyof T]: StandardSchemaV1.InferOutput<T[K]> };
|
|
6
|
+
/**
|
|
7
|
+
* Parse environment variables with Standard Schema validators and return a
|
|
8
|
+
* result object instead of throwing.
|
|
9
|
+
*
|
|
10
|
+
* While CLI schema capture is active, records `def` and returns a stub
|
|
11
|
+
* `{ success: true, data: {} }` without validating the environment — same
|
|
12
|
+
* handshake as `arkenv()` from `@arkenv/standard`.
|
|
13
|
+
*
|
|
14
|
+
* @param def An object mapping variable names to Standard Schema validators
|
|
15
|
+
* @param config Optional configuration
|
|
16
|
+
* @returns `{ success: true, data }` or `{ success: false, issues }`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import arkenv from "@arkenv/standard/safe";
|
|
21
|
+
* import * as z from "zod";
|
|
22
|
+
*
|
|
23
|
+
* const result = arkenv(
|
|
24
|
+
* { PORT: z.coerce.number() },
|
|
25
|
+
* { env: { PORT: "invalid" } },
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* if (!result.success) {
|
|
29
|
+
* console.error(result.issues);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function arkenv<const T extends Record<string, StandardSchemaV1>>(def: T, config?: SafeStandardEnvConfig): SafeArkEnvResult<StandardEnvOutput<T>>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { type SafeArkEnvResult, arkenv, arkenv as default };
|
package/dist/safe.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,i as t,l as n,n as r,r as i,s as a,u as o}from"./dist-CkiUgOD9.js";function s(s,c){let l=c??{};t(s);for(let e in s){let t=s[e];r(e,t),i(e,t)}return a()?(n(s),{success:!0,data:{}}):o(()=>e(s,l))}export{s as arkenv,s as default};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv$1, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-CHZF-Mlg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/valibot.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse and validate environment variables with Valibot.
|
|
6
|
+
*
|
|
7
|
+
* Pre-binds `@valibot/to-json-schema` (`typeMode: "input"`, `target: "draft-07"`)
|
|
8
|
+
* so `v.number()` and `v.boolean()` coerce without a manual `toJsonSchema`
|
|
9
|
+
* callback. Install `@valibot/to-json-schema` alongside `valibot`.
|
|
10
|
+
*
|
|
11
|
+
* @param def An object mapping variable names to Valibot schemas
|
|
12
|
+
* @param config Optional configuration. Pass `toJsonSchema` to override the bound converter
|
|
13
|
+
* @returns The validated environment variables
|
|
14
|
+
* @throws An {@link ArkEnvError} if validation fails
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { arkenv } from "@arkenv/standard/valibot";
|
|
19
|
+
* import * as v from "valibot";
|
|
20
|
+
*
|
|
21
|
+
* const env = arkenv({
|
|
22
|
+
* PORT: v.optional(v.number(), 3000),
|
|
23
|
+
* DEBUG: v.optional(v.boolean(), false),
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const arkenv: typeof arkenv$1;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ArkEnvError, type EnvIssue, type SafeArkEnvResult, type StandardEnvConfig, arkenv, arkenv as default, formatIssues, getSchemaKeys };
|
package/dist/valibot.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,o as t,t as n}from"./dist-CkiUgOD9.js";import"./index.js";import{t as r}from"./bind-arkenv-C8RYZhdK.js";import{toJsonSchema as i}from"@valibot/to-json-schema";const a=r(e=>i(e,{typeMode:`input`,target:`draft-07`}));export{n as ArkEnvError,a as arkenv,a as default,e as formatIssues,t as getSchemaKeys};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { a as SafeArkEnvResult, i as EnvIssue, n as arkenv$1, o as formatIssues, r as ArkEnvError, s as getSchemaKeys, t as StandardEnvConfig } from "./index-CHZF-Mlg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/zod-mini.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse and validate environment variables with Zod Mini.
|
|
6
|
+
*
|
|
7
|
+
* Pre-binds `zod/mini`'s `toJSONSchema` helper (`io: "input"`, `target: "draft-07"`)
|
|
8
|
+
* so Mini `z.number()` and `z.boolean()` coerce without a manual `toJsonSchema`
|
|
9
|
+
* callback. Install `zod` (optional peer) and import Mini from `zod/mini`.
|
|
10
|
+
* Classic Zod should keep using `@arkenv/standard`.
|
|
11
|
+
*
|
|
12
|
+
* @param def An object mapping variable names to Zod Mini schemas
|
|
13
|
+
* @param config Optional configuration. Pass `toJsonSchema` to override the bound converter
|
|
14
|
+
* @returns The validated environment variables
|
|
15
|
+
* @throws An {@link ArkEnvError} if validation fails
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { arkenv } from "@arkenv/standard/zod-mini";
|
|
20
|
+
* import * as z from "zod/mini";
|
|
21
|
+
*
|
|
22
|
+
* const env = arkenv({
|
|
23
|
+
* PORT: z.number(),
|
|
24
|
+
* DEBUG: z.boolean(),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const arkenv: typeof arkenv$1;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ArkEnvError, type EnvIssue, type SafeArkEnvResult, type StandardEnvConfig, arkenv, arkenv as default, formatIssues, getSchemaKeys };
|
package/dist/zod-mini.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,o as t,t as n}from"./dist-CkiUgOD9.js";import"./index.js";import{t as r}from"./bind-arkenv-C8RYZhdK.js";import{toJSONSchema as i}from"zod/mini";const a=r(e=>i(e,{io:`input`,target:`draft-07`}));export{n as ArkEnvError,a as arkenv,a as default,e as formatIssues,t as getSchemaKeys};
|
package/package.json
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arkenv/standard",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-alpha.10",
|
|
5
|
+
"description": "Dependency-free, typesafe environment variables validation based on Standard Schema",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./safe": {
|
|
16
|
+
"types": "./dist/safe.d.ts",
|
|
17
|
+
"import": "./dist/safe.js",
|
|
18
|
+
"default": "./dist/safe.js"
|
|
19
|
+
},
|
|
20
|
+
"./valibot": {
|
|
21
|
+
"types": "./dist/valibot.d.ts",
|
|
22
|
+
"import": "./dist/valibot.js",
|
|
23
|
+
"default": "./dist/valibot.js"
|
|
24
|
+
},
|
|
25
|
+
"./zod-mini": {
|
|
26
|
+
"types": "./dist/zod-mini.d.ts",
|
|
27
|
+
"import": "./dist/zod-mini.js",
|
|
28
|
+
"default": "./dist/zod-mini.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@valibot/to-json-schema": "^1.0.0",
|
|
33
|
+
"zod": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@valibot/to-json-schema": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"zod": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist"
|
|
45
|
+
],
|
|
46
|
+
"keywords": [
|
|
47
|
+
"env",
|
|
48
|
+
"environment-variables",
|
|
49
|
+
"environment",
|
|
50
|
+
"variables",
|
|
51
|
+
"dotenv",
|
|
52
|
+
"config",
|
|
53
|
+
"validation",
|
|
54
|
+
"typesafe",
|
|
55
|
+
"standard-schema",
|
|
56
|
+
"zod",
|
|
57
|
+
"valibot"
|
|
58
|
+
],
|
|
59
|
+
"license": "MIT",
|
|
60
|
+
"homepage": "https://arkenv.js.org",
|
|
61
|
+
"repository": {
|
|
62
|
+
"type": "git",
|
|
63
|
+
"url": "git+https://github.com/yamcodes/arkenv.git"
|
|
64
|
+
},
|
|
65
|
+
"bugs": "https://github.com/yamcodes/arkenv/labels/arkenv",
|
|
66
|
+
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@size-limit/esbuild-why": "12.1.0",
|
|
72
|
+
"@size-limit/preset-small-lib": "12.1.0",
|
|
73
|
+
"@types/node": "24.12.2",
|
|
74
|
+
"@valibot/to-json-schema": "1.6.0",
|
|
75
|
+
"rimraf": "6.1.3",
|
|
76
|
+
"size-limit": "12.1.0",
|
|
77
|
+
"tsdown": "0.21.10",
|
|
78
|
+
"typescript": "6.0.3",
|
|
79
|
+
"valibot": "1.3.1",
|
|
80
|
+
"vitest": "4.1.5",
|
|
81
|
+
"zod": "4.4.1",
|
|
82
|
+
"zod-to-json-schema": "3.25.2",
|
|
83
|
+
"@repo/utils": "0.1.3",
|
|
84
|
+
"@repo/types": "0.1.0"
|
|
85
|
+
},
|
|
86
|
+
"size-limit": [
|
|
87
|
+
{
|
|
88
|
+
"name": "@arkenv/standard",
|
|
89
|
+
"path": "dist/index.js",
|
|
90
|
+
"limit": "3.9 kB",
|
|
91
|
+
"import": "*"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "@arkenv/standard/valibot",
|
|
95
|
+
"path": "dist/valibot.js",
|
|
96
|
+
"limit": "4.5 kB",
|
|
97
|
+
"import": "*",
|
|
98
|
+
"ignore": [
|
|
99
|
+
"@valibot/to-json-schema"
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "@arkenv/standard/zod-mini",
|
|
104
|
+
"path": "dist/zod-mini.js",
|
|
105
|
+
"limit": "4.5 kB",
|
|
106
|
+
"import": "*",
|
|
107
|
+
"ignore": [
|
|
108
|
+
"zod",
|
|
109
|
+
"zod/mini"
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"scripts": {
|
|
114
|
+
"build": "tsdown",
|
|
115
|
+
"size": "size-limit --json > .size-limit.json",
|
|
116
|
+
"test": "vitest",
|
|
117
|
+
"test:once": "vitest run",
|
|
118
|
+
"typecheck": "tsc --noEmit",
|
|
119
|
+
"clean": "rimraf dist node_modules",
|
|
120
|
+
"fix": "pnpm -w run fix"
|
|
121
|
+
}
|
|
122
|
+
}
|