runcheck 0.38.0 → 0.38.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/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var x=(e,r)=>{for(var n in r)u(e,n,{get:r[n],enumerable:!0})},j=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of _(r))!h.call(e,t)&&t!==n&&u(e,t,{get:()=>r[t],enumerable:!(i=b(r,t))||i.enumerable});return e};var g=e=>j(u({},"__esModule",{value:!0}),e);var N={};x(N,{rc_boolean_autofix:()=>S,rc_number_autofix:()=>I,rc_string_autofix:()=>E});module.exports=g(N);function k(e){return{...this,y:e}}function O(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function y(e,r){e.warnings.push(O(e,r))}function o(e,r,n,i){if(e.o&&r===void 0)return[!0,r];if(e.s&&r==null)return[!0,r];if(e.a&&r===null)return[!0,r];let t=i();if(t&&(t===!0||!t.errors)){let a=t===!0?r:t.data;return e.t&&!e.t(a)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,a]}if(!n.strict){let a=e.y;if(a!==void 0)return y(n,`Fallback used, errors -> ${f(t,n,e,r)}`),[!0,P(a)?a():a];if(e.f&&e.c){let c=e.c(r);if(c)return e.t&&!e.t(c.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(y(n,`Autofixed from error "${f(t,n,e,r)}"`),[!0,c.fixed])}}return[!1,t?t.errors:[T(e,r)]]}function f(e,r,n,i){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):T(n,i)}function m(e){return{...this,f:!0,c:e}}function w(e){return{...this,t:e}}function l(){return{...this,o:!0}}function T(e,r){return`Type '${A(r,!!e.l)}' is not assignable to '${e.e}'`}function $(){return{...this,a:!0,e:`${this.e}_or_null`}}function K(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var s={__rc_type:void 0,withFallback:k,where:w,optional:l,optionalKey:l,orNullish:K,withAutofix:m,orNull:$,y:void 0,t:void 0,o:!1,a:!1,s:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},v={...s,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},q={...s,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},V={...s,r(e,r){return o(this,e,r,()=>!0)},e:"any"},B={...s,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},d={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},p={...s,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},R={...s,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...s,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function A(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function P(e){return typeof e=="function"}var S=d.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),E=p.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),I=R.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
|
package/dist/autofixable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as f,f as t,g as o}from"./chunk-
|
|
1
|
+
import{e as f,f as t,g as o}from"./chunk-KBK3GZDZ.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function B(e){return{...this,y:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function K(e,r){e.warnings.push(_(e,r))}function C(e,r){r.forEach(n=>K(e,n))}function c(e,r,n,t){if(e.o&&r===void 0)return[!0,r];if(e.s&&r==null)return[!0,r];if(e.a&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n.strict){let o=e.y;if(o!==void 0)return K(n,`Fallback used, errors -> ${
|
|
1
|
+
function B(e){return{...this,y:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function K(e,r){e.warnings.push(_(e,r))}function C(e,r){r.forEach(n=>K(e,n))}function c(e,r,n,t){if(e.o&&r===void 0)return[!0,r];if(e.s&&r==null)return[!0,r];if(e.a&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n.strict){let o=e.y;if(o!==void 0)return K(n,`Fallback used, errors -> ${E(s,n,e,r)}`),[!0,S(o)?o():o];if(e.f&&e.c){let a=e.c(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(K(n,`Autofixed from error "${E(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[v(e,r)]]}function E(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):v(n,t)}function F(e){return{...this,f:!0,c:e}}function U(e){return{...this,t:e}}function I(){return{...this,o:!0}}function v(e,r){return`Type '${w(r,!!e.l)}' is not assignable to '${e.e}'`}function W(){return{...this,a:!0,e:`${this.e}_or_null`}}function D(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:B,where:U,optional:I,optionalKey:I,orNullish:D,withAutofix:F,orNull:W,y:void 0,t:void 0,o:!1,a:!1,s:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},Z={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},G={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},H={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},X={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},Y={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ee={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},re={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ne={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function te(e){return{...i,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function se(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},l:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var N=1;function oe(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return c(this,r,n,()=>{let t=n.path,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.u&&(n.path=`${t}|union ${f}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[u,T]=R.r(r,n);n.objErrShortCircuit=!1;let d=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&d!==-1?d>0?y.push(...T):(o<N&&s.push(...T),o+=1):a=!0}return n.path=t,y.length>0||s.length>0?((o>N||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ae(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:S(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ie(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:S(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function M(e,r){return{...r,i:e}}var ce=M;function z(e){return O(e)&&"__rc_type"in e}function q(e){if(z(e))return e;if(O(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=q(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=q(s);return{...i,n,e:"object",u:!0,d:Object.entries(n),r(t,s){return c(this,t,s,()=>{if(!O(t))return s.objErrKeyIndex=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.path,R=-1;for(let[u,T]of this.d){let d=u;R+=1;let x=`.${u}`;s.path=`${f}${x}`;let p,b=u;if(T.i&&(p=t[T.i],b=T.i),p===void 0&&(p=t[u],b=u),p===void 0&&r==="snake_case"){let l=L(u);p=t[l],b=l}o?.delete(b);let[g,k]=T.r(p,s);if(g)a[d]=k;else{for(let l of k)y.push(_(s,l));if(s.objErrShortCircuit){s.objErrKeyIndex=R;break}}}if(o&&o.size>0)for(let u of o)y.push(`Key '${u}' is not defined in the object shape`);return y.length>0?{errors:y,data:void 0}:this.T?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function ue(e,r){return{...j(e,r),e:"extends_object",T:!0}}function ye(e){return e.n}function fe(e,r){return{...j(e,r),e:"strict_obj"}}function le(...e){let r={};for(let n of e)Object.assign(r,n.n);return j(r)}function Te(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return j(n)}function de(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return j(n)}function Q(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return c(this,t,s,()=>{if(!O(t))return!1;let o={},a=[],y=s.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.path=T,r&&!r(f)){a.push(_(s,`Key '${f}' is not allowed`));continue}let d=t[f],[x,p]=e.r(R,s);if(x)o[f]=d;else{let b=p;for(let g of b)a.push(_(s,g));if(s.objErrShortCircuit)break}}if(a.length>0)if(n)C(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function pe(e,{checkKey:r}={}){return Q(e,{checkKey:r,looseCheck:!0})}function A(e,r,n,t=!1,s){let o=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,x=`[${u}]`,p=`${f}${x}`;n.path=p;let b=d.r(T,n),[g,k]=b;n.path=p;let l=s?.unique;if(g&&l){let h=k,$=typeof l=="string";$?h=k[l]:typeof l=="function"&&(h=l(k)),y.has(h)?($&&(n.path=`${f}${x}.${l}`),b=[!1,[_(n,$?`Type '${d.n?.[l]?.e}' with value "${h}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${h}" is not unique`:`${d.e} value is not unique`)]]):y.add(h)}let[V,m]=b;if(V)a.push(m);else if(t){o.push(m.map(h=>_(n,h)));continue}else return{errors:m.map(h=>_(n,h)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};C(n,o.flat())}return{errors:!1,data:a}}function Re(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:A.call(this,n,e,t,!1,r):!1)}}}function be(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:A.call(this,n,e,t,!0,r):!1)}}}function he(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:A.call(this,r,e,n))}}}function P(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:o}}function _e(e){return r=>P(r,e)}function je(e,r,n){let t=P(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function J(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function xe(e){return r=>J(r,e)}function ke(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function ge(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);return s?[!0,r(o)]:[!1,o]}}}function Oe(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);if(s){let a=r(o);return a.ok?[!0,a.data]:[!1,a.errors]}return[!1,o]}}}function w(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function we(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function L(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function me(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return P(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${O(t)?t.message:""}`]}}}function S(e){return typeof e=="function"}function $e(){return(e,r)=>j(e,r)}export{Z as a,G as b,H as c,X as d,Y as e,ee as f,re as g,ne as h,te as i,se as j,oe as k,ae as l,ie as m,M as n,ce as o,j as p,ue as q,ye as r,fe as s,le as t,Te as u,de as v,Q as w,pe as x,Re as y,be as z,he as A,P as B,_e as C,je as D,J as E,xe as F,ke as G,ge as H,Oe as I,we as J,L as K,me as L,$e as M};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var A=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var J=(e,r)=>{for(var n in r)A(e,n,{get:r[n],enumerable:!0})},L=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of z(r))!Q.call(e,s)&&s!==n&&A(e,s,{get:()=>r[s],enumerable:!(t=M(r,s))||t.enumerable});return e};var Z=e=>L(A({},"__esModule",{value:!0}),e);var Ce={};J(Ce,{rc_any:()=>te,rc_array:()=>ge,rc_assert_is_valid:()=>Ee,rc_boolean:()=>oe,rc_date:()=>ce,rc_default:()=>le,rc_extends_obj:()=>Re,rc_get_obj_schema:()=>be,rc_instanceof:()=>ue,rc_is_valid:()=>U,rc_literals:()=>ye,rc_loose_array:()=>Oe,rc_loose_parse:()=>$e,rc_loose_record:()=>ke,rc_null:()=>ne,rc_nullish_default:()=>Te,rc_number:()=>ie,rc_obj_builder:()=>Ne,rc_obj_intersection:()=>_e,rc_obj_omit:()=>xe,rc_obj_pick:()=>je,rc_object:()=>_,rc_parse:()=>m,rc_parse_json:()=>Ie,rc_parser:()=>me,rc_record:()=>F,rc_recursive:()=>Ae,rc_rename_from_key:()=>V,rc_rename_key:()=>de,rc_strict_obj:()=>he,rc_string:()=>ae,rc_transform:()=>Pe,rc_tuple:()=>we,rc_undefined:()=>re,rc_union:()=>fe,rc_unknown:()=>se,rc_unsafe_transform:()=>Se,rc_validator:()=>Ke,snakeCase:()=>W});module.exports=Z(Ce);function G(e){return{...this,y:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function P(e,r){e.warnings.push(j(e,r))}function v(e,r){r.forEach(n=>P(e,n))}function c(e,r,n,t){if(e.s&&r===void 0)return[!0,r];if(e.o&&r==null)return[!0,r];if(e.a&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n.strict){let o=e.y;if(o!==void 0)return P(n,`Fallback used, errors -> ${I(s,n,e,r)}`),[!0,E(o)?o():o];if(e.f&&e.c){let a=e.c(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${I(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[q(e,r)]]}function I(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):q(n,t)}function H(e){return{...this,f:!0,c:e}}function X(e){return{...this,t:e}}function N(){return{...this,s:!0}}function q(e,r){return`Type '${w(r,!!e.l)}' is not assignable to '${e.e}'`}function Y(){return{...this,a:!0,e:`${this.e}_or_null`}}function ee(){return{...this,o:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:G,where:X,optional:N,optionalKey:N,orNullish:ee,withAutofix:H,orNull:Y,y:void 0,t:void 0,s:!1,a:!1,o:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},re={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},ne={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},te={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},se={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},oe={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ae={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},ie={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ce={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ue(e){return{...i,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ye(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},l:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var C=1;function fe(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return c(this,r,n,()=>{let t=n.path,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.u&&(n.path=`${t}|union ${f}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[u,T]=R.r(r,n);n.objErrShortCircuit=!1;let d=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&d!==-1?d>0?y.push(...T):(o<C&&s.push(...T),o+=1):a=!0}return n.path=t,y.length>0||s.length>0?((o>C||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function le(e,r){return{...e,s:!1,o:!1,a:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function Te(e,r){return{...e,s:!1,o:!1,a:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function V(e,r){return{...r,i:e}}var de=V;function pe(e){return O(e)&&"__rc_type"in e}function B(e){if(pe(e))return e;if(O(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=B(t);return _(r)}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=B(s);return{...i,n,e:"object",u:!0,d:Object.entries(n),r(t,s){return c(this,t,s,()=>{if(!O(t))return s.objErrKeyIndex=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.path,R=-1;for(let[u,T]of this.d){let d=u;R+=1;let x=`.${u}`;s.path=`${f}${x}`;let p,b=u;if(T.i&&(p=t[T.i],b=T.i),p===void 0&&(p=t[u],b=u),p===void 0&&r==="snake_case"){let l=W(u);p=t[l],b=l}o?.delete(b);let[g,k]=T.r(p,s);if(g)a[d]=k;else{for(let l of k)y.push(j(s,l));if(s.objErrShortCircuit){s.objErrKeyIndex=R;break}}}if(o&&o.size>0)for(let u of o)y.push(`Key '${u}' is not defined in the object shape`);return y.length>0?{errors:y,data:void 0}:this.T?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function Re(e,r){return{..._(e,r),e:"extends_object",T:!0}}function be(e){return e.n}function he(e,r){return{..._(e,r),e:"strict_obj"}}function _e(...e){let r={};for(let n of e)Object.assign(r,n.n);return _(r)}function je(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return _(n)}function xe(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return _(n)}function F(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return c(this,t,s,()=>{if(!O(t))return!1;let o={},a=[],y=s.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.path=T,r&&!r(f)){a.push(j(s,`Key '${f}' is not allowed`));continue}let d=t[f],[x,p]=e.r(R,s);if(x)o[f]=d;else{let b=p;for(let g of b)a.push(j(s,g));if(s.objErrShortCircuit)break}}if(a.length>0)if(n)v(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ke(e,{checkKey:r}={}){return F(e,{checkKey:r,looseCheck:!0})}function S(e,r,n,t=!1,s){let o=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,x=`[${u}]`,p=`${f}${x}`;n.path=p;let b=d.r(T,n),[g,k]=b;n.path=p;let l=s?.unique;if(g&&l){let h=k,K=typeof l=="string";K?h=k[l]:typeof l=="function"&&(h=l(k)),y.has(h)?(K&&(n.path=`${f}${x}.${l}`),b=[!1,[j(n,K?`Type '${d.n?.[l]?.e}' with value "${h}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${h}" is not unique`:`${d.e} value is not unique`)]]):y.add(h)}let[D,$]=b;if(D)a.push($);else if(t){o.push($.map(h=>j(n,h)));continue}else return{errors:$.map(h=>j(n,h)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};v(n,o.flat())}return{errors:!1,data:a}}function ge(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,t,!1,r):!1)}}}function Oe(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,t,!0,r):!1)}}}function we(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function m(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:o}}function me(e){return r=>m(r,e)}function $e(e,r,n){let t=m(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function U(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function Ke(e){return r=>U(r,e)}function Ae(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function Pe(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);return s?[!0,r(o)]:[!1,o]}}}function Se(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);if(s){let a=r(o);return a.ok?[!0,a.data]:[!1,a.errors]}return[!1,o]}}}function w(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function Ee(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function O(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ie(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return m(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${O(t)?t.message:""}`]}}}function E(e){return typeof e=="function"}function Ne(){return(e,r)=>_(e,r)}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_extends_obj,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_intersection,rc_obj_omit,rc_obj_pick,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
|
package/dist/runcheck.d.ts
CHANGED
|
@@ -73,14 +73,10 @@ declare function rc_extends_obj<T extends RcObject>(shape: T, options?: ObjOptio
|
|
|
73
73
|
declare function rc_get_obj_schema<T extends RcObject>(type: RcObjTypeReturn<T>): T;
|
|
74
74
|
/** return an error if the obj has more keys than the expected type */
|
|
75
75
|
declare function rc_strict_obj<T extends RcObject>(shape: T, options?: ObjOptions): RcObjTypeReturn<T>;
|
|
76
|
-
|
|
77
|
-
declare function rc_obj_intersection<A extends
|
|
78
|
-
declare function rc_obj_intersection<A extends
|
|
79
|
-
|
|
80
|
-
RcObjTypeReturn<B>,
|
|
81
|
-
RcObjTypeReturn<C>,
|
|
82
|
-
RcObjTypeReturn<D>
|
|
83
|
-
]): RcObjTypeReturn<A & B & C & D>;
|
|
76
|
+
type AnyObj = Record<string, unknown>;
|
|
77
|
+
declare function rc_obj_intersection<A extends AnyObj, B extends AnyObj>(...objs: [RcType<A>, RcType<B>]): RcType<A & B>;
|
|
78
|
+
declare function rc_obj_intersection<A extends AnyObj, B extends AnyObj, C extends AnyObj>(...objs: [RcType<A>, RcType<B>, RcType<C>]): RcType<A & B & C>;
|
|
79
|
+
declare function rc_obj_intersection<A extends AnyObj, B extends AnyObj, C extends AnyObj, D extends AnyObj>(...objs: [RcType<A>, RcType<B>, RcType<C>, RcType<D>]): RcType<A & B & C & D>;
|
|
84
80
|
declare function rc_obj_pick<O extends RcObject, K extends keyof O>(obj: RcObjTypeReturn<O>, keys: K[]): RcObjTypeReturn<Pick<O, K>>;
|
|
85
81
|
declare function rc_obj_omit<O extends RcObject, K extends keyof O>(obj: RcObjTypeReturn<O>, keys: K[]): RcObjTypeReturn<Pick<O, K>>;
|
|
86
82
|
type RcRecord<V extends RcType<any>> = Record<string, V>;
|
package/dist/runcheck.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,F,G,H,I,J,K,L,M,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-KBK3GZDZ.js";export{c as rc_any,y as rc_array,J as rc_assert_is_valid,e as rc_boolean,h as rc_date,l as rc_default,q as rc_extends_obj,r as rc_get_obj_schema,i as rc_instanceof,E as rc_is_valid,j as rc_literals,z as rc_loose_array,D as rc_loose_parse,x as rc_loose_record,b as rc_null,m as rc_nullish_default,g as rc_number,M as rc_obj_builder,t as rc_obj_intersection,v as rc_obj_omit,u as rc_obj_pick,p as rc_object,B as rc_parse,L as rc_parse_json,C as rc_parser,w as rc_record,G as rc_recursive,n as rc_rename_from_key,o as rc_rename_key,s as rc_strict_obj,f as rc_string,H as rc_transform,A as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,I as rc_unsafe_transform,F as rc_validator,K as snakeCase};
|
package/package.json
CHANGED