@arkenv/standard 1.0.0-alpha.4 → 1.0.0-alpha.6
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 +3 -0
- package/dist/bind-arkenv-F4i-iDsA.cjs +1 -0
- package/dist/bind-arkenv-Z7Nl-5uk.js +2 -0
- package/dist/bind-arkenv-Z7Nl-5uk.js.map +1 -0
- package/dist/index-Bg1-O9yz.d.ts +12612 -0
- package/dist/index-Bg1-O9yz.d.ts.map +1 -0
- package/dist/index-rF5YpE9o.d.cts +12612 -0
- package/dist/index-rF5YpE9o.d.cts.map +1 -0
- package/dist/index.cjs +1 -4
- package/dist/index.d.cts +2 -12296
- package/dist/index.d.ts +2 -12296
- package/dist/index.js +1 -5
- package/dist/src-BZoXXFsx.cjs +4 -0
- package/dist/src-BxruqAr0.js +5 -0
- package/dist/src-BxruqAr0.js.map +1 -0
- package/dist/valibot.cjs +1 -0
- package/dist/valibot.d.cts +30 -0
- package/dist/valibot.d.cts.map +1 -0
- package/dist/valibot.d.ts +30 -0
- package/dist/valibot.d.ts.map +1 -0
- package/dist/valibot.js +2 -0
- package/dist/valibot.js.map +1 -0
- package/dist/zod-mini.cjs +1 -0
- package/dist/zod-mini.d.cts +31 -0
- package/dist/zod-mini.d.cts.map +1 -0
- package/dist/zod-mini.d.ts +31 -0
- package/dist/zod-mini.d.ts.map +1 -0
- package/dist/zod-mini.js +2 -0
- package/dist/zod-mini.js.map +1 -0
- package/package.json +52 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=
|
|
2
|
-
`).map(e=>`${` `.repeat(t)}${e}`).join(`
|
|
3
|
-
`),l={red:`\x1B[31m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,reset:`\x1B[0m`},u=()=>typeof process<`u`&&process.versions!=null&&process.versions.node!=null,d=()=>!!(!u()||process.env.NO_COLOR!==void 0||process.env.CI!==void 0||process.stdout&&!process.stdout.isTTY),f=(e,t)=>u()&&!d()?`${l[e]}${t}${l.reset}`:t;function p(e){return e.map(e=>`${f(`yellow`,e.path)} ${e.message.trimStart()}`).join(`
|
|
4
|
-
`)}var m=class extends Error{constructor(e,t=`Errors found while validating environment variables`){let n=p(e);super(`${f(`red`,t)}\n${c(n)}\n`),this.name=`ArkEnvError`,this.issues=e}};Object.defineProperty(m,`name`,{value:`ArkEnvError`});function h(e,t){if(typeof t==`string`)throw new m([{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 g(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 m([{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 _(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new m([{path:``,message:`Invalid schema: expected an object mapping in "standard" mode.`,code:`INVALID_SCHEMA`}])}const v=/secret|(_|^)key(_|$)|token|(_|^)password(_|$)|(_|^)pass(_|$)|(_|^)auth(_|$)|jwt|cert|credential|database_url|db_url/i;function y(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 b(e){return v.test(e)&&!/public/i.test(e)}function x(e,t,n){let r=y(n?.debugSecrets);if(e===void 0)return`missing`;if(e===null)return`null`;if(!r&&b(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=>x(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}: ${x(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 S={too_small:`VALUE_TOO_SMALL`,too_big:`VALUE_TOO_LARGE`,invalid_string:`INVALID_FORMAT`,invalid_date:`INVALID_FORMAT`,custom:`INVALID_FORMAT`};function C(e,t,n){let r=t.toLowerCase();return e===`invalid_type`&&(n===void 0||n===`undefined`)||r===`required`?`MISSING_VARIABLE`:e in S?S[e]:/regex|pattern|match/.test(r)?`PATTERN_MISMATCH`:`INVALID_TYPE`}function w(e){let t=e.minimum??e.min,n=e.maximum??e.max;return{...typeof t==`number`?{min:t}:{},...typeof n==`number`?{max:n}:{}}}function T(e){try{return{success:!0,data:e()}}catch(e){if(e instanceof m)return{success:!1,issues:e.issues};throw e}}function E(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 D(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 ${f(`cyan`,!y(a?.debugSecrets)&&b(i)?`[REDACTED]`:x(r,i,a))})`;return n&&!e.includes(`Expected`)?`must be ${n} ${o}`:`${e} ${o}`}function O(e){let t={type:`object`,properties:{}},n=!1,r=[];for(let i in e){let a=e[i];if(!a){r.push(i);continue}let o=a[`~standard`];if(typeof o?.jsonSchema?.input==`function`)try{let e=o.jsonSchema.input({target:`draft-07`});if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.jsonSchema?.input==`function`)try{let e=a.jsonSchema.input({target:`draft-07`});if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.toJSONSchema==`function`)try{let e=a.toJSONSchema();if(e){t.properties[i]=e,n=!0;continue}}catch{}if(typeof a.toStandardJSONSchema?.v1==`function`)try{let e=a.toStandardJSONSchema.v1();if(e){t.properties[i]=e,n=!0;continue}}catch{}r.push(i)}return{jsonSchema:t,hasJsonSchema:n,missingKeys:r}}function k(e){return typeof e==`object`&&e&&`key`in e?String(e.key):String(e)}function A(e,t){return!t||t.length===0?e:[e,...t.map(k)].join(`.`)}function j(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?.[k(e)];n=i}}catch(e){r=`[Traversal error: ${e.message}]`}return{receivedVal:n,traversalError:r}}function M(e,t){let{env:n=process.env,onUndeclaredKey:r=`delete`,coerce:i=!0,arrayFormat:a=`comma`,emptyAsUndefined:o=!1}=t,c={},l=[],{processedEnv:u,coercedEnv:d,missingKeys:f}=s(n,o,a,i?()=>{let{jsonSchema:t,hasJsonSchema:n,missingKeys:r}=O(e);return{schema:t,hasSchema:n,missingKeys:r}}:void 0),p=new Set(Object.keys(u));for(let n in e){let r=e[n],a=d[n];if(!r||typeof r!=`object`||!(`~standard`in r))throw new m([E(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 m([E(n,`Async validation is not supported. ArkEnv is synchronous.`,`INVALID_SCHEMA`)]);if(o.issues)for(let e of o.issues){let r=A(n,e.path),a,o;if(n in u){let t=u[n];if(typeof t==`string`&&e.path?.length){let n=j(t,e.path);a=n.receivedVal,o=n.traversalError}else a=t}else a=e.received;let s=C(e.code||`invalid_type`,e.message||``,a),c=e.expected||void 0,d={...w(e)},p=e;p.validation!==void 0&&(d.validation=p.validation),o!==void 0&&(d.traversalError=o);let m=D(e.message||``,s,c,a,r,t);i&&f.includes(n)&&(m+=` (Hint: coercion is enabled by default, but the validator for '${n}' lacks Standard JSON Schema support.)`),l.push(E(r,m,s,d,c,a))}else c[n]=o.value;p.delete(n)}if(r!==`delete`)for(let e of p)r===`reject`?l.push(E(e,`Undeclared key`,`UNDECLARED_KEY`)):r===`ignore`&&(c[e]=d[e]);if(l.length>0)throw new m(l);return c}function N(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)}function P(e,t={}){_(e);for(let t in e){let n=e[t];h(t,n),g(t,n)}return t.safe?T(()=>M(e,t)):M(e,t)}exports.ArkEnvError=m,exports.arkenv=P,exports.default=P,exports.formatIssues=p,exports.getSchemaKeys=N;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./src-BZoXXFsx.cjs`);exports.ArkEnvError=e.n,exports.arkenv=e.t,exports.default=e.t,exports.formatIssues=e.r,exports.getSchemaKeys=e.i;
|