runcheck 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autofixable.cjs +2 -2
- package/dist/autofixable.cjs.map +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-UNFQGHGF.js +4 -0
- package/dist/{chunk-UNF3OWHK.js.map → chunk-UNFQGHGF.js.map} +1 -1
- package/dist/runcheck.cjs +3 -3
- package/dist/runcheck.cjs.map +1 -1
- package/dist/runcheck.d.cts +16 -6
- package/dist/runcheck.d.ts +16 -6
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-UNF3OWHK.js +0 -4
package/dist/chunk-UNF3OWHK.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
function Z(e,r){return{...r,u:e}}function b(e){if(A(e))return e;if(w(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=b(t);return m(r)}else if(Array.isArray(e)){let[r,n]=e;switch(r){case"optional":return b(n).optional();case"nullish_or":return b(n).orNullish();case"null_or":return b(n).orNull();case"array_of":return P(b(n));case"loose_array_of":return S(b(n));case"optional_array_of":return P(b(n)).optional();case"optional_loose_array_of":return S(b(n)).optional();case"null_or_array_of":return P(b(n)).orNull();case"null_or_loose_array_of":return S(b(n)).orNull();case"nullish_or_array_of":return P(b(n)).orNullish();case"nullish_or_loose_array_of":return S(b(n)).orNullish();default:return r}}throw new Error(`invalid schema: ${e}`)}function m(e,{normalizeKeysFrom:r}={}){let n={};for(let[o,s]of Object.entries(e))n[o]=b(s);let t=Object.entries(n).map(([o,s])=>({key:o,type:s}));return{...y,t:n,e:"object",d:"",o:!0,r(o,s){return f(this,o,s,()=>{if(!w(o)){if(s.a=-1,s.s&&!this.d)return!1;if(!this.d){let T=`${this.e}{ `,c=0;for(let{key:R,type:g}of t){if(T.length>100){T+=", ...";break}c!==0&&(T+=", "),T+=`${R}: ${g.e}`,c++}T+=" }",this.d=T}return{data:void 0,errors:[h(s,`Type '${j(o,!1)}' is not assignable to '${this.d}'`)]}}let i=this.e==="strict_obj"||s.i?new Set(Object.keys(o)):void 0;if(i&&i.size>t.length){s.a=-1;let T=[];if(s.s)return{data:void 0,errors:[h(s,`Expected strict object with ${t.length} keys but got ${i.size}`)]};for(let{key:c}of t)i.has(c)?i.delete(c):T.push(h(s,`Key '${c}' is missing`));for(let c of i)T.push(h(s,`Key '${c}' is not defined in the object shape`));return{data:void 0,errors:T}}let u={},l=[],_=s.n,k=-1;for(let T of t){let c=T.key,R=T.type,g=c;k+=1;let O=c===""||c.includes(" ")?`['${c}']`:`.${c}`,d=`${_}${O}`;s.n=d;let p=o[c],x=c;if(p===void 0&&R.u&&(p=o[R.u],x=R.u),p===void 0&&r==="snake_case"){let $=C(c);p=o[$],x=$}i?.delete(x);let D=R.r(p,s);if(D.ok)u[g]=D.data;else{for(let $ of D.errors)s.n=d,l.push($);if(s.s){s.a=k;break}}}if(i&&i.size>0)for(let T of i)s.n=_,l.push(h(s,`Key '${T}' is not defined in the object shape`));return l.length>0?{errors:l,data:void 0}:(s.n=_,this.b?{errors:!1,data:{...o,...u}}:{errors:!1,data:u})})}}}function G(e,r){return{...m(e,r),e:"extends_object",b:!0}}function H(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function X(e,r){return{...m(e,r),e:"strict_obj"}}function Y(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.i;t.i=!0;let s=e.r(n,t);return t.i=o,s}}}function ee(...e){let r={};for(let n of e)Object.assign(r,n.t);return m(r)}function re(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return m(n)}function ne(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return m(n)}function te(){return(e,r)=>m(e,r)}function V(e,r){let n={};for(let[t,o]of Object.entries(r))n[t]=A(o)?o:m(o);return{...y,e:"discriminated_union",o:!0,r(t,o){return f(this,t,o,()=>{if(!w(t))return o.a=-1,!1;let s=t[e],a=o.n,i=n[s];if(!i){let l=j(s,!0);return{errors:[h({n:`${a}.${e}`},`Type '${l}' is not a valid discriminator`)],data:void 0}}o.n=`${a}|${e}: ${s}|`;let u=i.r(t,o);return o.n=a,u.ok?(u.data[e]=s,{errors:!1,data:u.data}):{errors:u.errors,data:void 0}})}}}function oe(e){return r=>V(e,r)}function se(...e){let r="",n=!0;for(let t of e)r&&(r+=" & "),t.o||(n=!1),r+=t.e.includes("|")?`(${t.e})`:t.e;return{...y,e:r,o:n,r(t,o){return f(this,t,o,()=>{let s=null;for(let a of e){let i=a.r(t,o);if(i.ok)a.o&&(s={...s||{},...i.data});else return a.o?i:!1}return s?{data:s,errors:!1}:!0})}}}var ae=()=>{};function ie(e){return{...this,p:e===void 0?ae:e}}function ue(e){return he(this,e)}function ce(e){return _e(this,e)}function le(e){return Re(this,e)}function fe(e,r){return N(e,this,r)}function h(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function B(e,r){e._.push(r.startsWith("$")?r:h(e,r))}function L(e,r){r.forEach(n=>B(e,n))}function f(e,r,n,t){if(e.c&&r===void 0)return{ok:!0,data:r,errors:void 0};if(e.l&&r==null)return{ok:!0,data:r,errors:void 0};if(e.f&&r===null)return{ok:!0,data:r,errors:void 0};let o=t();if(o&&(o===!0||!o.errors))return{ok:!0,data:o===!0?r:o.data,errors:void 0};if(!n.y){let s=e.p;if(s!==void 0)return B(n,`Fallback used, errors -> ${F(o,n,e,r)}`),{ok:!0,data:U(s)?s():s,errors:void 0};if(e.g&&e.T){let a=e.T(r);if(a)return B(n,`Autofixed from error "${F(o,n,e,r)}"`),{ok:!0,data:a.fixed,errors:void 0}}}return{ok:!1,data:void 0,errors:o?o.errors:[h(n,Q(e,r))]}}function F(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):Q(n,t)}function ye(e){return{...this,g:!0,T:e}}function Te(e){return{...this,r:(r,n)=>f(this,r,n,()=>{let t=this.r(r,n);if(!t.ok)return{errors:t.errors,data:void 0};let o=e(t.data);return o!==!0?{errors:[h(n,`Predicate failed${o===!1?` for type '${this.e}'`:`: ${o.error}`}`)],data:void 0}:{errors:!1,data:t.data}})}}function M(){return{...this,c:!0,e:`undefined | ${this.e}`}}function Q(e,r){return`Type '${j(r,!!e.k)}' is not assignable to '${e.e}'`}function de(){return{...this,f:!0,e:`null | ${this.e}`}}function pe(){return{...this,l:!0,e:`null | undefined | ${this.e}`}}var y={__rc_type:void 0,withFallback:ie,where:Te,r:void 0,e:void 0,optional:M,optionalKey:M,orNullish:pe,withAutofix:ye,orNull:de,default:ue,nullishDefault:ce,or:le,parse:fe,R:void 0,p:void 0,m:void 0,c:!1,f:!1,l:!1,g:!1,k:!1,u:void 0,T:void 0,t:void 0,d:void 0,o:!1,b:!1},Fe={...y,r(e,r){return f(this,e,r,()=>e===void 0)},e:"undefined"},Me={...y,r(e,r){return f(this,e,r,()=>e===null)},e:"null"},ze={...y,r(e){return{ok:!0,data:e,errors:void 0}},e:"any"},Le={...y,r(e){return{ok:!0,data:e,errors:void 0}},e:"unknown"},Qe={...y,r(e,r){return f(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Je={...y,r(e,r){return f(this,e,r,()=>typeof e=="string")},e:"string"},Ze={...y,r(e,r){return f(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Ge={...y,r(e,r){return f(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function He(e){return{...y,r(r,n){return f(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function Xe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...y,r(r,n){return f(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?j(e[0],!0):e.map(r=>j(r,!0)).join(" | ")}}var z=1;function Re(...e){if(e.length===0)throw new Error("Unions should have at least one type");let r="",n=!1;for(let t of e)r&&(r+=" | "),r+=t.e,!n&&t.o&&(n=!0);return{...y,e:r,o:n,r(t,o){return f(this,t,o,()=>{let s=o.n,a=[],i=0,u=!1,l=[],_=0;for(let k of e){_+=1,k.o&&(o.n=`${s}|union ${_}|`);let T=o.s;o.s=!0,o.a=0;let c=k.r(t,o),R=o.a;if(o.s=T,o.a=0,c.ok)return{data:c.data,errors:!1};k.o&&R!==-1?R>0?l.push(...c.errors):(i<z&&a.push(...c.errors),i+=1):u=!0}return o.n=s,l.length>0||a.length>0?((i>z||u)&&a.push(h(o,"not matches any other union member")),{errors:[...l,...a],data:void 0}):!1})}}}function he(e,r){return{...e,c:!1,l:!1,f:!1,r(t,o){return f(this,t,o,()=>{if(t===void 0)return n();let s=e.r(t,o);return s.ok?s.data===void 0?n():{data:s.data,errors:!1}:{data:void 0,errors:s.errors}})},e:`${e.e}_default`};function n(){return{data:U(r)?r():r,errors:!1}}}function _e(e,r){return{...e,c:!1,l:!1,f:!1,r(t,o){return f(this,t,o,()=>{if(t==null)return n();let s=e.r(t,o);return s.ok?s.data===null||s.data===void 0?n():{data:s.data,errors:!1}:{data:void 0,errors:s.errors}})},e:`${e.e}_nullish_default`};function n(){return{data:U(r)?r():r,errors:!1}}}function Ye(e,r){return{...e,r(n,t){return f(this,n,t,()=>{let o=e.r(n,t);return o.ok?{data:o.data,errors:!1}:{data:U(r)?r():r,errors:!1}})}}}function be(e,{checkKey:r,looseCheck:n}={}){return{...y,e:`record<string, ${e.e}>`,o:!0,r(t,o){return f(this,t,o,()=>{if(!w(t))return!1;let s={},a=[],i=o.n;for(let[u,l]of Object.entries(t)){let _=u===""||u.includes(" ")?`['${u}']`:`.${u}`,k=`${i}${_}`;if(o.n=k,r&&!r(u)){a.push(h(o,`Key '${u}' is not allowed`));continue}let T=t[u],c=e.r(l,o);if(c.ok)s[u]=T;else{let R=c.errors;for(let g of R)a.push(g);if(o.s)break}}if(a.length>0)if(n)L(o,a);else return{errors:a,data:void 0};return o.n=i,{errors:!1,data:s}})}}}function er(e,{checkKey:r}={}){return be(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let s=t&&!n.y&&!n.h,a=o?.unique,i=[],u=[],l=a?new Set:void 0,_=n.n,k=Array.isArray(r),T=-1;for(let c of e){T++;let R=k?r[T]:r,g=`[${T}]`,O=`${_}${g}`;if(n.n=O,o?.filter){let p=o.filter(c);if(typeof p=="boolean"){if(!p)continue}else if("errors"in p)if(s){i.push([p.errors,O]);continue}else return{errors:p.errors,data:void 0};n.n=O}let d=R.r(c,n);if(n.n=O,d.ok&&l){let p=d.data,x=typeof a=="string";x?p=d.data[a]:typeof a=="function"&&(p=a(d.data)),l.has(p)?(x&&(n.n=`${_}${g}.${a}`),d={ok:!1,data:void 0,errors:[h(n,x?`Type '${R.t?.[a]?.e}' with value "${p}" is not unique`:typeof a=="function"?`Type '${R.e}' unique fn return with value "${p}" is not unique`:`${R.e} value is not unique`)]}):l.add(p)}if(d.ok)u.push(d.data);else if(s){i.push([d.errors,O]);continue}else return{errors:d.errors,data:void 0}}if(i.length>0){let c=[];for(let[R,g]of i){for(let O of R){let d=O.slice(g.length+1);d.startsWith(": ")&&(d=d.slice(2)),(d.startsWith(".")||d.startsWith("["))&&(d=`#${d}`);let p=`$${g}: Rejected, error -> ${d}`;c.push(p)}L(n,c)}}return{errors:!1,data:u}}function P(e,r){return{...y,e:`${e.e}[]`,R:e,r(n,t){return f(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function rr(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function nr(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return f(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.h;t.h=!0;let s=e.r(n,t);return t.h=o,s}}}function S(e,r){return{...y,R:e,e:`${e.e}[]`,r(n,t){return f(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!0,r):!1)}}}function tr(e,r,n,t){return{...y,R:n,e:`${n.e}[]`,r(o,s){return f(this,o,s,()=>Array.isArray(o)?o.length===0?!0:E.call(this,o,n,s,t?.loose,{...t,filter(a){let i=e.r(a,s);return i.ok?r(i.data):{errors:i.errors}}}):!1)}}}function or(e){return{...y,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return f(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:E.call(this,r,e,n))}}}function q(e){e.warnings&&e.warnings.length>0&&console.warn(`Unwrap warnings: ${e.warnings.join(`
|
|
2
|
-
`)}`)}function v(){if(this.errors)throw new I(this.errors);return q(this),this.value}function K(e){return this.errors?e:(q(this),this.value)}function W(){return this.errors?null:(q(this),this.value)}function N(e,r,{noWarnings:n=!1}={}){let t={_:[],n:"",s:!1,a:0,y:n,i:!1,h:!1},o=r.r(e,t);return o.ok?{error:!1,errors:!1,ok:!0,data:o.data,value:o.data,warnings:t._.length>0?t._:!1,unwrap:v,unwrapOr:K,unwrapOrNull:W}:{ok:!1,error:!0,errors:o.errors,unwrap:v,unwrapOr:K,unwrapOrNull:W}}function sr(e){return r=>N(r,e)}function ar(e,r,n){let t=N(e,r,n);return t.errors?{data:null,errors:t.errors,warnings:!1}:{data:t.value,errors:!1,warnings:t.warnings}}function ir(e){return ge(e,null)}function ge(e,r){return e.error?{value:r,errors:e.errors,warnings:!1}:{value:e.value,errors:!1,warnings:e.warnings}}var I=class extends Error{constructor(n){super(n.join(`
|
|
3
|
-
`));this.errors=n}name="RcValidationError"};function ur(e){if(e.errors)throw new I(e.errors);return e}function ke(e,r){let n={_:[],n:"",s:!1,a:0,y:!1,i:!1,h:!1};return r.r(e,n).ok}function cr(e){return r=>ke(r,e)}function lr(e){let r;return{...y,e:"recursive",r(n,t){return r||(r={...e()},this.c&&(r.c=this.c),this.l&&(r.l=this.l),this.f&&(r.f=this.f),this.T&&(r.T=this.T),this.p&&(r.p=this.p),this.u&&(r.u=this.u)),r.r(n,t)}}}function J(e,r,n,t){let o=e.n,s=e.s,a=e.i,i=e.y;e.s=!0,e.n=`${o}|output|`,t||(e.i=!0,e.y=!0);let u=r.r(n,e);return e.i=a,e.y=i,e.n=o,e.s=s,u}function me(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`${e.e}_transform`,r(o,s){return f(this,o,s,()=>{let a=null;if(n){let l=J(s,n,o,t);if(l.ok)return{data:l.data,errors:!1};a=l.errors}let u={...e,e:this.e}.r(o,s);return u.ok?{errors:!1,data:r(u.data,e)}:{errors:[...a||[],...u.errors],data:void 0}})}}}function fr(e,r){return me(e,r)}function yr(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`${e.e}_transform`,r(o,s){return f(this,o,s,()=>{let a=null;if(n){let l=J(s,n,o,t);if(l.ok)return{errors:!1,data:l.data};a=l.errors}let u={...e,e:this.e}.r(o,s);if(u.ok){let l=r(u.data,e);return l.ok?{errors:!1,data:l.data}:{errors:typeof l.errors=="string"?[h(s,l.errors)]:l.errors.map(_=>h(s,_)),data:void 0}}return{errors:[...a||[],...u.errors],data:void 0}})}}}function j(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e=="number"&&Number.isNaN(e)?"NaN":n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Tr(e){if(e.errors)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function w(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function C(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function dr(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${j(e,!0)}`],unwrap:v,unwrapOr:K,unwrapOrNull:W};let t=JSON.parse(e);return N(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${w(t)?t.message:""}`],unwrap:v,unwrapOr:K,unwrapOrNull:W}}}function U(e){return typeof e=="function"}function A(e){return w(e)&&"__rc_type"in e}function pr(e){return e}function Rr(e){return e.e}function hr(e,{errorOnWarnings:r=!1}={}){return{"~standard":{validate(n){let t="ok"in e?e:N(n,e);return Oe(t,r)},vendor:"runcheck",version:1}}}function Oe(e,r){return r&&e.ok&&e.warnings?{issues:e.warnings.map(n=>({message:n}))}:e.ok?{value:e.value}:{issues:e.errors.map(n=>({message:n}))}}export{Z as a,m as b,G as c,H as d,X as e,Y as f,ee as g,re as h,ne as i,te as j,V as k,oe as l,se as m,h as n,f as o,y as p,Fe as q,Me as r,ze as s,Le as t,Qe as u,Je as v,Ze as w,Ge as x,He as y,Xe as z,Re as A,he as B,_e as C,Ye as D,be as E,er as F,P as G,rr as H,nr as I,S as J,tr as K,or as L,N as M,sr as N,ar as O,ir as P,ge as Q,I as R,ur as S,ke as T,cr as U,lr as V,me as W,fr as X,yr as Y,j as Z,Tr as _,w as $,C as aa,dr as ba,A as ca,pr as da,Rr as ea,hr as fa};
|
|
4
|
-
//# sourceMappingURL=chunk-UNF3OWHK.js.map
|