runcheck 0.41.0 → 0.42.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/README.md CHANGED
@@ -367,7 +367,7 @@ const result = rc_parse(
367
367
  )
368
368
  ```
369
369
 
370
- Use the `outputSchema` option to create a type that validates both the input and the output of the transform. So if the input type is invalid, it will assume that the input is a transformed value and the `outputSchema` will be used
370
+ Use the `outputSchema` option to create a type that validates both the input and the output of the transform. So if the input matches the `outputSchema` the transform will be ignored.
371
371
 
372
372
  ```ts
373
373
  const input = 'hello'
@@ -1 +1 @@
1
- "use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)l(e,n,{get:r[n],enumerable:!0})},x=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&l(e,t,{get:()=>r[t],enumerable:!(i=h(r,t))||i.enumerable});return e};var k=e=>x(l({},"__esModule",{value:!0}),e);var v={};m(v,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>S,rc_string_autofix:()=>E});module.exports=k(v);function w(e){return{...this,R:e}}function d(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function f(e,r){e.c.push(d(e,r))}function o(e,r,n,i){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let t=i();if(t&&(t===!0||!t.errors)){let a=t===!0?r:t.data;return e.a&&!e.a(a)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,a]}if(!n._){let a=e.R;if(a!==void 0)return f(n,`Fallback used, errors -> ${c(t,n,e,r)}`),[!0,I(a)?a():a];if(e.b&&e.T){let u=e.T(r);if(u)return e.a&&!e.a(u.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(f(n,`Autofixed from error "${c(t,n,e,r)}"`),[!0,u.fixed])}}return[!1,t?t.errors:[d(n,T(e,r))]]}function c(e,r,n,i){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,i)}function $(e){return{...this,b:!0,T:e}}function P(e){return{...this,a:e}}function y(){return{...this,u:!0}}function T(e,r){return`Type '${O(r,!!e.h)}' is not assignable to '${e.e}'`}function N(){return{...this,f:!0,e:`${this.e}_or_null`}}function j(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var s={__rc_type:void 0,withFallback:w,where:P,optional:y,optionalKey:y,orNullish:j,withAutofix:$,orNull:N,R:void 0,a:void 0,u:!1,f:!1,y:!1,b:!1,h:!1,i:void 0,T:void 0,j:void 0,t:void 0,l:!1,p:!1,d:[]},K={...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"},W={...s,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},p={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...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 O(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 I(e){return typeof e=="function"}var A=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),E=_.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),S=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});
1
+ "use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)l(e,n,{get:r[n],enumerable:!0})},x=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&l(e,t,{get:()=>r[t],enumerable:!(i=h(r,t))||i.enumerable});return e};var k=e=>x(l({},"__esModule",{value:!0}),e);var v={};m(v,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>E,rc_string_autofix:()=>S});module.exports=k(v);function w(e){return{...this,R:e}}function d(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function f(e,r){e.u.push(d(e,r))}function o(e,r,n,i){if(e.y&&r===void 0)return[!0,r];if(e.f&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=i();if(t&&(t===!0||!t.errors)){let a=t===!0?r:t.data;return e.a&&!e.a(a)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,a]}if(!n._){let a=e.R;if(a!==void 0)return f(n,`Fallback used, errors -> ${c(t,n,e,r)}`),[!0,O(a)?a():a];if(e.b&&e.d){let u=e.d(r);if(u)return e.a&&!e.a(u.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(f(n,`Autofixed from error "${c(t,n,e,r)}"`),[!0,u.fixed])}}return[!1,t?t.errors:[d(n,T(e,r))]]}function c(e,r,n,i){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,i)}function $(e){return{...this,b:!0,d:e}}function P(e){return{...this,a:e}}function y(){return{...this,y:!0}}function T(e,r){return`Type '${I(r,!!e.h)}' is not assignable to '${e.e}'`}function N(){return{...this,l:!0,e:`${this.e}_or_null`}}function j(){return{...this,f:!0,e:`${this.e}_or_nullish`}}var s={__rc_type:void 0,withFallback:w,where:P,optional:y,optionalKey:y,orNullish:j,withAutofix:$,orNull:N,R:void 0,a:void 0,y:!1,l:!1,f:!1,b:!1,h:!1,i:void 0,d:void 0,j:void 0,t:void 0,T:!1,p:!1,c:[]},K={...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"},W={...s,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},p={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...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 I(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 O(e){return typeof e=="function"}var A=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),S=_.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),E=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});
@@ -1 +1 @@
1
- import{q as f,r as t,s as o}from"./chunk-EHQOQ4HE.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
+ import{q as f,r as t,s as o}from"./chunk-PJTM2QW6.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};
@@ -0,0 +1 @@
1
+ function D(e,r){return{...r,i:e}}function I(e){return m(e)&&"__rc_type"in e}function N(e){if(I(e))return e;if(m(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=N(t);return k(r)}throw new Error(`invalid schema: ${e}`)}function k(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=N(s);return{...c,t:n,e:"object",T:!0,c:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!m(t))return s.o=-1,!1;let a=this.e==="strict_obj"?new Set(Object.keys(t)):void 0;if(a&&this.c.length!==a.size){for(let[f]of this.c)a.delete(f);s.o=-1;let l=[];for(let f of a)l.push(`Key '${f}' is not defined in the object shape`);return{data:void 0,errors:l}}let y={},i=[],T=s.n,p=-1;for(let[l,f]of this.c){let b=l;p+=1;let x=`.${l}`,j=`${T}${x}`;s.n=j;let d,g=l;if(f.i&&(d=t[f.i],g=f.i),d===void 0&&(d=t[l],g=l),d===void 0&&r==="snake_case"){let O=C(l);d=t[O],g=O}a?.delete(g);let[R,w]=f.r(d,s);if(R)y[b]=w;else{for(let O of w)s.n=j,i.push(h(s,O));if(s.s){s.o=p;break}}}if(a&&a.size>0)for(let l of a)i.push(`Key '${l}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.p?{errors:!1,data:{...t,...y}}:{errors:!1,data:y}})}}}function M(e,r){return{...k(e,r),e:"extends_object",p:!0}}function z(e){return e.t}function v(e,r){let n=(()=>{if(I(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?v(o,r):o;return t}}return e})();return{...k(n,r),e:"strict_obj"}}function Q(...e){let r={};for(let n of e)Object.assign(r,n.t);return k(r)}function J(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 s=e.t[t];s&&(n[t]=s)}return k(n)}function L(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 k(n)}function Z(){return(e,r)=>k(e,r)}function G(e){return{...this,R:e}}function h(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function P(e,r){e.u.push(h(e,r))}function F(e,r){r.forEach(n=>P(e,n))}function u(e,r,n,t){if(e.y&&r===void 0)return[!0,r];if(e.f&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return P(n,`Fallback used, errors -> ${q(s,n,e,r)}`),[!0,E(o)?o():o];if(e.b&&e.d){let a=e.d(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${q(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[h(n,U(e,r))]]}function q(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):U(n,t)}function H(e){return{...this,b:!0,d:e}}function X(e){return{...this,a:e}}function W(){return{...this,y:!0}}function U(e,r){return`Type '${A(r,!!e.h)}' is not assignable to '${e.e}'`}function Y(){return{...this,l:!0,e:`${this.e}_or_null`}}function ee(){return{...this,f:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:G,where:X,optional:W,optionalKey:W,orNullish:ee,withAutofix:H,orNull:Y,R:void 0,a:void 0,y:!1,l:!1,f:!1,b:!1,h:!1,i:void 0,d:void 0,j:void 0,t:void 0,T:!1,p:!1,c:[]},ue={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ye={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},fe={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Te={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function _e(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function be(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?A(e[0],!0):e.map(r=>A(r,!0)).join(" | ")}}var B=1;function he(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,y=[],i=0;for(let T of e){i+=1,T.T&&(n.n=`${t}|union ${i}|`);let p=n.s;n.s=!0,n.o=0;let[l,f]=T.r(r,n),b=n.o;if(n.s=p,n.o=0,l)return!0;T.T&&b!==-1?b>0?y.push(...f):(o<B&&s.push(...f),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>B||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function je(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(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 ge(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(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 re(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!m(t))return!1;let o={},a=[],y=s.n;for(let[i,T]of Object.entries(t)){let p=`.${i}`,l=`${y}${p}`;if(s.n=l,r&&!r(i)){a.push(h(s,`Key '${i}' is not allowed`));continue}let f=t[i],[b,x]=e.r(T,s);if(b)o[i]=f;else{let j=x;for(let d of j)a.push(h(s,d));if(s.s)break}}if(a.length>0)if(n)F(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function Oe(e,{checkKey:r}={}){return re(e,{checkKey:r,looseCheck:!0})}function K(e,r,n,t=!1,s){let o=[],a=[],y=new Set,i=n.n,T=Array.isArray(r),p=-1;for(let l of e){p++;let f=T?r[p]:r,b=`[${p}]`,x=`${i}${b}`;n.n=x;let j=f.r(l,n),[d,g]=j;n.n=x;let R=s?.unique;if(d&&R){let _=g,$=typeof R=="string";$?_=g[R]:typeof R=="function"&&(_=R(g)),y.has(_)?($&&(n.n=`${i}${b}.${R}`),j=[!1,[h(n,$?`Type '${f.t?.[R]?.e}' with value "${_}" is not unique`:typeof R=="function"?`Type '${f.e}' unique fn return with value "${_}" is not unique`:`${f.e} value is not unique`)]]):y.add(_)}let[w,O]=j;if(w)a.push(O);else if(t){o.push(O.map(_=>h(n,_)));continue}else return{errors:O.map(_=>h(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};F(n,o.flat())}return{errors:!1,data:a}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!1,r):!1)}}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!0,r):!1)}}}function me(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:K.call(this,r,e,n))}}}function S(e,r,{noWarnings:n=!1}={}){let t={u:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.u.length>0?t.u:!1}:{ok:!1,error:!0,errors:o}}function we(e){return r=>S(r,e)}function Ae(e,r,n){let t=S(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function ne(e,r){let n={u:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function $e(e){return r=>ne(r,e)}function Pe(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function V(e,r,n){let t=e.n,s=e.s;e.s=!0,e.n=`${t}|output|`;let o=r.r(n,e);return e.n=t,e.s=s,o}function Ke(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=V(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);return a?[!0,r(y,e)]:[!1,[...o||[],...y]]}}}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=V(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);if(a){let i=r(y,e);return i.ok?[!0,i.data]:[!1,typeof i.errors=="string"?[i.errors]:i.errors]}return[!1,[...o||[],...y]]}}}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 Ee(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function m(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 Ie(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${A(e,!0)}`]};let t=JSON.parse(e);return S(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${m(t)?t.message:""}`]}}}function E(e){return typeof e=="function"}export{D as a,k as b,M as c,z as d,v as e,Q as f,J as g,L as h,Z as i,h as j,u as k,c as l,ue as m,ye as n,fe as o,le as p,Te as q,pe as r,de as s,Re as t,_e as u,be as v,he as w,je as x,ge as y,re as z,Oe as A,ke as B,xe as C,me as D,S as E,we as F,Ae as G,ne as H,$e as I,Pe as J,Ke as K,Se as L,Ee as M,m as N,C as O,Ie as P};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var K=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ee(r))!re.call(e,s)&&s!==n&&K(e,s,{get:()=>r[s],enumerable:!(t=Y(r,s))||t.enumerable});return e};var se=e=>te(K({},"__esModule",{value:!0}),e);var ve={};ne(ve,{defaultProps:()=>c,gerWarningOrErrorWithPath:()=>b,isObject:()=>x,parse:()=>u,rc_any:()=>le,rc_array:()=>ke,rc_assert_is_valid:()=>Ie,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>Oe,rc_get_obj_schema:()=>F,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>he,rc_loose_array:()=>me,rc_loose_parse:()=>$e,rc_loose_record:()=>xe,rc_null:()=>fe,rc_nullish_default:()=>ge,rc_number:()=>Re,rc_obj_builder:()=>M,rc_obj_extends:()=>B,rc_obj_merge:()=>U,rc_obj_omit:()=>D,rc_obj_pick:()=>V,rc_obj_strict:()=>E,rc_object:()=>j,rc_parse:()=>A,rc_parse_json:()=>Ne,rc_parser:()=>Ae,rc_record:()=>G,rc_recursive:()=>Ke,rc_rename_from_key:()=>C,rc_string:()=>de,rc_transform:()=>Ee,rc_tuple:()=>we,rc_undefined:()=>ye,rc_union:()=>je,rc_unknown:()=>Te,rc_unsafe_transform:()=>Se,rc_validator:()=>Pe,snakeCase:()=>S});module.exports=se(ve);function C(e,r){return{...r,i:e}}function q(e){return x(e)&&"__rc_type"in e}function W(e){if(q(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(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]=W(s);return{...c,t:n,e:"object",l:!0,p:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!x(t))return s.o=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},i=[],f=s.n,d=-1;for(let[y,R]of this.p){let T=y;d+=1;let h=`.${y}`,g=`${f}${h}`;s.n=g;let l,O=y;if(R.i&&(l=t[R.i],O=R.i),l===void 0&&(l=t[y],O=y),l===void 0&&r==="snake_case"){let k=S(y);l=t[k],O=k}o?.delete(O);let[m,p]=R.r(l,s);if(m)a[T]=p;else{for(let k of p)s.n=g,i.push(b(s,k));if(s.s){s.o=d;break}}}if(o&&o.size>0)for(let y of o)i.push(`Key '${y}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.d?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function B(e,r){return{...j(e,r),e:"extends_object",d:!0}}function F(e){return e.t}function E(e,r){let n=(()=>{if(q(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?E(o,r):o;return t}}return e})();return{...j(n,r),e:"strict_obj"}}function U(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function V(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 s=e.t[t];s&&(n[t]=s)}return j(n)}function D(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 j(n)}function M(){return(e,r)=>j(e,r)}function oe(e){return{...this,R:e}}function b(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function I(e,r){e.c.push(b(e,r))}function L(e,r){r.forEach(n=>I(e,n))}function u(e,r,n,t){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return I(n,`Fallback used, errors -> ${z(s,n,e,r)}`),[!0,v(o)?o():o];if(e.b&&e.T){let a=e.T(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(I(n,`Autofixed from error "${z(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[b(n,Z(e,r))]]}function z(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):Z(n,t)}function ae(e){return{...this,b:!0,T:e}}function ie(e){return{...this,a:e}}function Q(){return{...this,u:!0}}function Z(e,r){return`Type '${w(r,!!e.h)}' is not assignable to '${e.e}'`}function ce(){return{...this,f:!0,e:`${this.e}_or_null`}}function ue(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:oe,where:ie,optional:Q,optionalKey:Q,orNullish:ue,withAutofix:ae,orNull:ce,R:void 0,a:void 0,u:!1,f:!1,y:!1,b:!1,h:!1,i:void 0,T:void 0,j:void 0,t:void 0,l:!1,d:!1,p:[]},ye={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},fe={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Te={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function he(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var J=1;function je(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,i=[],f=0;for(let d of e){f+=1,d.l&&(n.n=`${t}|union ${f}|`);let y=n.s;n.s=!0,n.o=0;let[R,T]=d.r(r,n),h=n.o;if(n.s=y,n.o=0,R)return!0;d.l&&h!==-1?h>0?i.push(...T):(o<J&&s.push(...T),o+=1):a=!0}return n.n=t,i.length>0||s.length>0?((o>J||a)&&s.push("not matches any other union member"),{errors:[...i,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Oe(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ge(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function G(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!x(t))return!1;let o={},a=[],i=s.n;for(let[f,d]of Object.entries(t)){let y=`.${f}`,R=`${i}${y}`;if(s.n=R,r&&!r(f)){a.push(b(s,`Key '${f}' is not allowed`));continue}let T=t[f],[h,g]=e.r(d,s);if(h)o[f]=T;else{let l=g;for(let O of l)a.push(b(s,O));if(s.s)break}}if(a.length>0)if(n)L(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function xe(e,{checkKey:r}={}){return G(e,{checkKey:r,looseCheck:!0})}function N(e,r,n,t=!1,s){let o=[],a=[],i=new Set,f=n.n,d=Array.isArray(r),y=-1;for(let R of e){y++;let T=d?r[y]:r,h=`[${y}]`,g=`${f}${h}`;n.n=g;let l=T.r(R,n),[O,m]=l;n.n=g;let p=s?.unique;if(O&&p){let _=m,P=typeof p=="string";P?_=m[p]:typeof p=="function"&&(_=p(m)),i.has(_)?(P&&(n.n=`${f}${h}.${p}`),l=[!1,[b(n,P?`Type '${T.t?.[p]?.e}' with value "${_}" is not unique`:typeof p=="function"?`Type '${T.e}' unique fn return with value "${_}" is not unique`:`${T.e} value is not unique`)]]):i.add(_)}let[k,$]=l;if(k)a.push($);else if(t){o.push($.map(_=>b(n,_)));continue}else return{errors:$.map(_=>b(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};L(n,o.flat())}return{errors:!1,data:a}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!1,r):!1)}}}function me(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!0,r):!1)}}}function we(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:N.call(this,r,e,n))}}}function A(e,r,{noWarnings:n=!1}={}){let t={c:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.c.length>0?t.c:!1}:{ok:!1,error:!0,errors:o}}function Ae(e){return r=>A(r,e)}function $e(e,r,n){let t=A(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function H(e,r){let n={c:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function Pe(e){return r=>H(r,e)}function Ke(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function X(e,r,n,t){let s=e.n;e.n=`${s}|output|`;let[o,a]=r.r(n,e);return e.n=s,o?[!0,a]:[!1,[...t,...a]]}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=s.s;n&&(s.s=!0);let[a,i]=e.r(t,s);return n&&(s.s=o),a?[!0,r(i)]:n?X(s,n,t,i):[!1,i]}}}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let[o,a]=e.r(t,s);if(o){let i=r(a);return i.ok?[!0,i.data]:[!1,i.errors]}else if(n)return X(s,n,t,a);return[!1,a]}}}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 Ie(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ne(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 A(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${x(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,gerWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,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_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
1
+ "use strict";var K=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ee(r))!re.call(e,s)&&s!==n&&K(e,s,{get:()=>r[s],enumerable:!(t=Y(r,s))||t.enumerable});return e};var se=e=>te(K({},"__esModule",{value:!0}),e);var ve={};ne(ve,{defaultProps:()=>c,gerWarningOrErrorWithPath:()=>b,isObject:()=>x,parse:()=>u,rc_any:()=>le,rc_array:()=>xe,rc_assert_is_valid:()=>Ie,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>ge,rc_get_obj_schema:()=>F,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>he,rc_loose_array:()=>me,rc_loose_parse:()=>$e,rc_loose_record:()=>ke,rc_null:()=>fe,rc_nullish_default:()=>Oe,rc_number:()=>Re,rc_obj_builder:()=>M,rc_obj_extends:()=>B,rc_obj_merge:()=>U,rc_obj_omit:()=>D,rc_obj_pick:()=>V,rc_obj_strict:()=>S,rc_object:()=>j,rc_parse:()=>$,rc_parse_json:()=>Ne,rc_parser:()=>Ae,rc_record:()=>G,rc_recursive:()=>Ke,rc_rename_from_key:()=>C,rc_string:()=>de,rc_transform:()=>Se,rc_tuple:()=>we,rc_undefined:()=>ye,rc_union:()=>je,rc_unknown:()=>Te,rc_unsafe_transform:()=>Ee,rc_validator:()=>Pe,snakeCase:()=>E});module.exports=se(ve);function C(e,r){return{...r,i:e}}function q(e){return x(e)&&"__rc_type"in e}function W(e){if(q(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(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]=W(s);return{...c,t:n,e:"object",T:!0,c:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!x(t))return s.o=-1,!1;let a=this.e==="strict_obj"?new Set(Object.keys(t)):void 0;if(a&&this.c.length!==a.size){for(let[f]of this.c)a.delete(f);s.o=-1;let l=[];for(let f of a)l.push(`Key '${f}' is not defined in the object shape`);return{data:void 0,errors:l}}let y={},i=[],T=s.n,p=-1;for(let[l,f]of this.c){let h=l;p+=1;let m=`.${l}`,g=`${T}${m}`;s.n=g;let d,O=l;if(f.i&&(d=t[f.i],O=f.i),d===void 0&&(d=t[l],O=l),d===void 0&&r==="snake_case"){let k=E(l);d=t[k],O=k}a?.delete(O);let[R,w]=f.r(d,s);if(R)y[h]=w;else{for(let k of w)s.n=g,i.push(b(s,k));if(s.s){s.o=p;break}}}if(a&&a.size>0)for(let l of a)i.push(`Key '${l}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.d?{errors:!1,data:{...t,...y}}:{errors:!1,data:y}})}}}function B(e,r){return{...j(e,r),e:"extends_object",d:!0}}function F(e){return e.t}function S(e,r){let n=(()=>{if(q(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?S(o,r):o;return t}}return e})();return{...j(n,r),e:"strict_obj"}}function U(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function V(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 s=e.t[t];s&&(n[t]=s)}return j(n)}function D(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 j(n)}function M(){return(e,r)=>j(e,r)}function oe(e){return{...this,R:e}}function b(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function I(e,r){e.u.push(b(e,r))}function L(e,r){r.forEach(n=>I(e,n))}function u(e,r,n,t){if(e.y&&r===void 0)return[!0,r];if(e.f&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return I(n,`Fallback used, errors -> ${z(s,n,e,r)}`),[!0,v(o)?o():o];if(e.b&&e.p){let a=e.p(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(I(n,`Autofixed from error "${z(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[b(n,Z(e,r))]]}function z(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):Z(n,t)}function ae(e){return{...this,b:!0,p:e}}function ie(e){return{...this,a:e}}function Q(){return{...this,y:!0}}function Z(e,r){return`Type '${A(r,!!e.h)}' is not assignable to '${e.e}'`}function ce(){return{...this,l:!0,e:`${this.e}_or_null`}}function ue(){return{...this,f:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:oe,where:ie,optional:Q,optionalKey:Q,orNullish:ue,withAutofix:ae,orNull:ce,R:void 0,a:void 0,y:!1,l:!1,f:!1,b:!1,h:!1,i:void 0,p:void 0,j:void 0,t:void 0,T:!1,d:!1,c:[]},ye={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},fe={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Te={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function he(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?A(e[0],!0):e.map(r=>A(r,!0)).join(" | ")}}var J=1;function je(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,y=[],i=0;for(let T of e){i+=1,T.T&&(n.n=`${t}|union ${i}|`);let p=n.s;n.s=!0,n.o=0;let[l,f]=T.r(r,n),h=n.o;if(n.s=p,n.o=0,l)return!0;T.T&&h!==-1?h>0?y.push(...f):(o<J&&s.push(...f),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>J||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ge(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function Oe(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function G(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!x(t))return!1;let o={},a=[],y=s.n;for(let[i,T]of Object.entries(t)){let p=`.${i}`,l=`${y}${p}`;if(s.n=l,r&&!r(i)){a.push(b(s,`Key '${i}' is not allowed`));continue}let f=t[i],[h,m]=e.r(T,s);if(h)o[i]=f;else{let g=m;for(let d of g)a.push(b(s,d));if(s.s)break}}if(a.length>0)if(n)L(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ke(e,{checkKey:r}={}){return G(e,{checkKey:r,looseCheck:!0})}function N(e,r,n,t=!1,s){let o=[],a=[],y=new Set,i=n.n,T=Array.isArray(r),p=-1;for(let l of e){p++;let f=T?r[p]:r,h=`[${p}]`,m=`${i}${h}`;n.n=m;let g=f.r(l,n),[d,O]=g;n.n=m;let R=s?.unique;if(d&&R){let _=O,P=typeof R=="string";P?_=O[R]:typeof R=="function"&&(_=R(O)),y.has(_)?(P&&(n.n=`${i}${h}.${R}`),g=[!1,[b(n,P?`Type '${f.t?.[R]?.e}' with value "${_}" is not unique`:typeof R=="function"?`Type '${f.e}' unique fn return with value "${_}" is not unique`:`${f.e} value is not unique`)]]):y.add(_)}let[w,k]=g;if(w)a.push(k);else if(t){o.push(k.map(_=>b(n,_)));continue}else return{errors:k.map(_=>b(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};L(n,o.flat())}return{errors:!1,data:a}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!1,r):!1)}}}function me(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!0,r):!1)}}}function we(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:N.call(this,r,e,n))}}}function $(e,r,{noWarnings:n=!1}={}){let t={u:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.u.length>0?t.u:!1}:{ok:!1,error:!0,errors:o}}function Ae(e){return r=>$(r,e)}function $e(e,r,n){let t=$(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function H(e,r){let n={u:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function Pe(e){return r=>H(r,e)}function Ke(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function X(e,r,n){let t=e.n,s=e.s;e.s=!0,e.n=`${t}|output|`;let o=r.r(n,e);return e.n=t,e.s=s,o}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=X(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);return a?[!0,r(y,e)]:[!1,[...o||[],...y]]}}}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=X(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);if(a){let i=r(y,e);return i.ok?[!0,i.data]:[!1,typeof i.errors=="string"?[i.errors]:i.errors]}return[!1,[...o||[],...y]]}}}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 Ie(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ne(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${A(e,!0)}`]};let t=JSON.parse(e);return $(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${x(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,gerWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,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_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
@@ -153,13 +153,13 @@ type TransformOptions<T> = {
153
153
  outputSchema?: RcType<T>;
154
154
  };
155
155
  /** validate a input or subset of input and transform the valid result */
156
- declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => Transformed, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
157
- declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => {
156
+ declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => Transformed, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
157
+ declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => {
158
158
  ok: true;
159
159
  data: Transformed;
160
160
  } | {
161
161
  ok: false;
162
- errors: string[];
162
+ errors: string | string[];
163
163
  }, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
164
164
  type NonArrayObject = {
165
165
  [x: string]: any;
package/dist/runcheck.js CHANGED
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,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-EHQOQ4HE.js";export{l as defaultProps,j as gerWarningOrErrorWithPath,N as isObject,k as parse,o as rc_any,B as rc_array,M as rc_assert_is_valid,q as rc_boolean,t as rc_date,x as rc_default,d as rc_get_obj_schema,u as rc_instanceof,H as rc_is_valid,v as rc_literals,C as rc_loose_array,G as rc_loose_parse,A as rc_loose_record,n as rc_null,y as rc_nullish_default,s as rc_number,i as rc_obj_builder,c as rc_obj_extends,f as rc_obj_merge,h as rc_obj_omit,g as rc_obj_pick,e as rc_obj_strict,b as rc_object,E as rc_parse,P as rc_parse_json,F as rc_parser,z as rc_record,J as rc_recursive,a as rc_rename_from_key,r as rc_string,K as rc_transform,D as rc_tuple,m as rc_undefined,w as rc_union,p as rc_unknown,L as rc_unsafe_transform,I as rc_validator,O as snakeCase};
1
+ import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,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-PJTM2QW6.js";export{l as defaultProps,j as gerWarningOrErrorWithPath,N as isObject,k as parse,o as rc_any,B as rc_array,M as rc_assert_is_valid,q as rc_boolean,t as rc_date,x as rc_default,d as rc_get_obj_schema,u as rc_instanceof,H as rc_is_valid,v as rc_literals,C as rc_loose_array,G as rc_loose_parse,A as rc_loose_record,n as rc_null,y as rc_nullish_default,s as rc_number,i as rc_obj_builder,c as rc_obj_extends,f as rc_obj_merge,h as rc_obj_omit,g as rc_obj_pick,e as rc_obj_strict,b as rc_object,E as rc_parse,P as rc_parse_json,F as rc_parser,z as rc_record,J as rc_recursive,a as rc_rename_from_key,r as rc_string,K as rc_transform,D as rc_tuple,m as rc_undefined,w as rc_union,p as rc_unknown,L as rc_unsafe_transform,I as rc_validator,O as snakeCase};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "runcheck",
3
3
  "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
- "version": "0.41.0",
4
+ "version": "0.42.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist"
@@ -1 +0,0 @@
1
- function D(e,r){return{...r,i:e}}function I(e){return k(e)&&"__rc_type"in e}function N(e){if(I(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=N(t);return O(r)}throw new Error(`invalid schema: ${e}`)}function O(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=N(s);return{...c,t:n,e:"object",l:!0,d:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!k(t))return s.s=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},i=[],f=s.n,d=-1;for(let[y,R]of this.d){let T=y;d+=1;let b=`.${y}`,g=`${f}${b}`;s.n=g;let l,j=y;if(R.i&&(l=t[R.i],j=R.i),l===void 0&&(l=t[y],j=y),l===void 0&&r==="snake_case"){let x=C(y);l=t[x],j=x}o?.delete(j);let[m,p]=R.r(l,s);if(m)a[T]=p;else{for(let x of p)s.n=g,i.push(h(s,x));if(s.o){s.s=d;break}}}if(o&&o.size>0)for(let y of o)i.push(`Key '${y}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.p?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function M(e,r){return{...O(e,r),e:"extends_object",p:!0}}function z(e){return e.t}function v(e,r){let n=(()=>{if(I(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?v(o,r):o;return t}}return e})();return{...O(n,r),e:"strict_obj"}}function Q(...e){let r={};for(let n of e)Object.assign(r,n.t);return O(r)}function J(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 s=e.t[t];s&&(n[t]=s)}return O(n)}function L(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 O(n)}function Z(){return(e,r)=>O(e,r)}function G(e){return{...this,R:e}}function h(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function P(e,r){e.c.push(h(e,r))}function F(e,r){r.forEach(n=>P(e,n))}function u(e,r,n,t){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return P(n,`Fallback used, errors -> ${q(s,n,e,r)}`),[!0,S(o)?o():o];if(e.b&&e.T){let a=e.T(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${q(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[h(n,U(e,r))]]}function q(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):U(n,t)}function H(e){return{...this,b:!0,T:e}}function X(e){return{...this,a:e}}function W(){return{...this,u:!0}}function U(e,r){return`Type '${w(r,!!e.h)}' is not assignable to '${e.e}'`}function Y(){return{...this,f:!0,e:`${this.e}_or_null`}}function ee(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:G,where:X,optional:W,optionalKey:W,orNullish:ee,withAutofix:H,orNull:Y,R:void 0,a:void 0,u:!1,f:!1,y:!1,b:!1,h:!1,i:void 0,T:void 0,j:void 0,t:void 0,l:!1,p:!1,d:[]},ue={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ye={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},fe={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Te={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function _e(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function be(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var B=1;function he(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,i=[],f=0;for(let d of e){f+=1,d.l&&(n.n=`${t}|union ${f}|`);let y=n.o;n.o=!0,n.s=0;let[R,T]=d.r(r,n),b=n.s;if(n.o=y,n.s=0,R)return!0;d.l&&b!==-1?b>0?i.push(...T):(o<B&&s.push(...T),o+=1):a=!0}return n.n=t,i.length>0||s.length>0?((o>B||a)&&s.push("not matches any other union member"),{errors:[...i,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function je(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(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 Oe(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(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 re(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!k(t))return!1;let o={},a=[],i=s.n;for(let[f,d]of Object.entries(t)){let y=`.${f}`,R=`${i}${y}`;if(s.n=R,r&&!r(f)){a.push(h(s,`Key '${f}' is not allowed`));continue}let T=t[f],[b,g]=e.r(d,s);if(b)o[f]=T;else{let l=g;for(let j of l)a.push(h(s,j));if(s.o)break}}if(a.length>0)if(n)F(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ge(e,{checkKey:r}={}){return re(e,{checkKey:r,looseCheck:!0})}function K(e,r,n,t=!1,s){let o=[],a=[],i=new Set,f=n.n,d=Array.isArray(r),y=-1;for(let R of e){y++;let T=d?r[y]:r,b=`[${y}]`,g=`${f}${b}`;n.n=g;let l=T.r(R,n),[j,m]=l;n.n=g;let p=s?.unique;if(j&&p){let _=m,$=typeof p=="string";$?_=m[p]:typeof p=="function"&&(_=p(m)),i.has(_)?($&&(n.n=`${f}${b}.${p}`),l=[!1,[h(n,$?`Type '${T.t?.[p]?.e}' with value "${_}" is not unique`:typeof p=="function"?`Type '${T.e}' unique fn return with value "${_}" is not unique`:`${T.e} value is not unique`)]]):i.add(_)}let[x,A]=l;if(x)a.push(A);else if(t){o.push(A.map(_=>h(n,_)));continue}else return{errors:A.map(_=>h(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};F(n,o.flat())}return{errors:!1,data:a}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!1,r):!1)}}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!0,r):!1)}}}function me(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:K.call(this,r,e,n))}}}function E(e,r,{noWarnings:n=!1}={}){let t={c:[],n:"",o:!1,s:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.c.length>0?t.c:!1}:{ok:!1,error:!0,errors:o}}function we(e){return r=>E(r,e)}function Ae(e,r,n){let t=E(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function ne(e,r){let n={c:[],n:"",o:!1,s:0,_:!1};return!!r.r(e,n)[0]}function $e(e){return r=>ne(r,e)}function Pe(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function V(e,r,n,t){let s=e.n;e.n=`${s}|output|`;let[o,a]=r.r(n,e);return e.n=s,o?[!0,a]:[!1,[...t,...a]]}function Ke(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=s.o;n&&(s.o=!0);let[a,i]=e.r(t,s);return n&&(s.o=o),a?[!0,r(i)]:n?V(s,n,t,i):[!1,i]}}}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let[o,a]=e.r(t,s);if(o){let i=r(a);return i.ok?[!0,i.data]:[!1,i.errors]}else if(n)return V(s,n,t,a);return[!1,a]}}}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 Se(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function k(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 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 E(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${k(t)?t.message:""}`]}}}function S(e){return typeof e=="function"}export{D as a,O as b,M as c,z as d,v as e,Q as f,J as g,L as h,Z as i,h as j,u as k,c as l,ue as m,ye as n,fe as o,le as p,Te as q,pe as r,de as s,Re as t,_e as u,be as v,he as w,je as x,Oe as y,re as z,ge as A,xe as B,ke as C,me as D,E,we as F,Ae as G,ne as H,$e as I,Pe as J,Ke as K,Ee as L,Se as M,k as N,C as O,Ie as P};