runcheck 0.39.0 → 0.40.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 +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-VOMXQGTP.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +2 -2
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2DQLFKXQ.js +0 -1
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 O=e=>j(u({},"__esModule",{value:!0}),e);var v={};x(v,{rc_boolean_autofix:()=>N,rc_number_autofix:()=>I,rc_string_autofix:()=>S});module.exports=O(v);function k(e){return{...this,d:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.n?`$${e.n}: `:""}${r}`}function y(e,r){e.i.push(g(e,r))}function o(e,r,n,i){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.y&&r===null)return[!0,r];let t=i();if(t&&(t===!0||!t.errors)){let a=t===!0?r:t.data;return e.s&&!e.s(a)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,a]}if(!n.p){let a=e.d;if(a!==void 0)return y(n,`Fallback used, errors -> ${f(t,n,e,r)}`),[!0,K(a)?a():a];if(e.R&&e.l){let c=e.l(r);if(c)return e.s&&!e.s(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.n,"")).join("; "):T(n,i)}function m(e){return{...this,R:!0,l:e}}function w(e){return{...this,s:e}}function l(){return{...this,c:!0}}function T(e,r){return`Type '${P(r,!!e.b)}' is not assignable to '${e.e}'`}function A(){return{...this,y:!0,e:`${this.e}_or_null`}}function $(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var s={__rc_type:void 0,withFallback:k,where:w,optional:l,optionalKey:l,orNullish:$,withAutofix:m,orNull:A,d:void 0,s:void 0,c:!1,y:!1,u:!1,R:!1,b:!1,f:void 0,l:void 0,x:void 0,t:void 0,T:!1,_:!1,h:[]},q={...s,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},C={...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 P(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 K(e){return typeof e=="function"}var N=d.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),S=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-VOMXQGTP.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 F(e){return{...this,d:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.n?`$${e.n}: `:""}${r}`}function P(e,r){e.i.push(j(e,r))}function q(e,r){r.forEach(n=>P(e,n))}function c(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.y&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.s&&!e.s(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n.p){let o=e.d;if(o!==void 0)return P(n,`Fallback used, errors -> ${N(s,n,e,r)}`),[!0,I(o)?o():o];if(e.R&&e.l){let a=e.l(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${N(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[C(e,r)]]}function N(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):C(n,t)}function U(e){return{...this,R:!0,l:e}}function W(e){return{...this,s:e}}function v(){return{...this,c:!0}}function C(e,r){return`Type '${w(r,!!e.b)}' is not assignable to '${e.e}'`}function D(){return{...this,y:!0,e:`${this.e}_or_null`}}function M(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:F,where:W,optional:v,optionalKey:v,orNullish:M,withAutofix:U,orNull:D,d:void 0,s:void 0,c:!1,y:!1,u:!1,R:!1,b:!1,f:void 0,l:void 0,x:void 0,t:void 0,T:!1,_:!1,h:[]},G={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},H={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},X={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},Y={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},ee={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},re={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},ne={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},te={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function se(e){return{...i,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function oe(...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})},b:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var E=1;function ae(...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.n,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.T&&(n.n=`${t}|union ${f}|`),n.a=!0,n.o=0;let[u,T]=R.r(r,n);n.a=!1;let d=n.o;if(n.o=0,u)return!0;R.T&&d!==-1?d>0?y.push(...T):(o<E&&s.push(...T),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>E||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ie(e,r){return{...e,c:!1,u:!1,y:!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:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ce(e,r){return{...e,c:!1,u:!1,y:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function z(e,r){return{...r,f:e}}var ue=z;function V(e){return m(e)&&"__rc_type"in e}function B(e){if(V(e))return e;if(m(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=B(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]=B(s);return{...i,t:n,e:"object",T:!0,h:Object.entries(n),r(t,s){return c(this,t,s,()=>{if(!m(t))return s.o=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.n,R=-1;for(let[u,T]of this.h){let d=u;R+=1;let k=`.${u}`,h=`${f}${k}`;s.n=h;let l,_=u;if(T.f&&(l=t[T.f],_=T.f),l===void 0&&(l=t[u],_=u),l===void 0&&r==="snake_case"){let x=Z(u);l=t[x],_=x}o?.delete(_);let[g,p]=T.r(l,s);if(g)a[d]=p;else{for(let x of p)s.n=h,y.push(j(s,x));if(s.a){s.o=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._?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function ye(e,r){return{...O(e,r),e:"extends_object",_:!0}}function fe(e){return e.t}function Q(e,r){let n=(()=>{if(V(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?Q(o,r):o;return t}}return e})();return{...O(n,r),e:"strict_obj"}}function le(...e){let r={};for(let n of e)Object.assign(r,n.t);return O(r)}function Te(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 de(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 J(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return c(this,t,s,()=>{if(!m(t))return!1;let o={},a=[],y=s.n;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.n=T,r&&!r(f)){a.push(j(s,`Key '${f}' is not allowed`));continue}let d=t[f],[k,h]=e.r(R,s);if(k)o[f]=d;else{let l=h;for(let _ of l)a.push(j(s,_));if(s.a)break}}if(a.length>0)if(n)q(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function pe(e,{checkKey:r}={}){return J(e,{checkKey:r,looseCheck:!0})}function K(e,r,n,t=!1,s){let o=[],a=[],y=new Set,f=n.n,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,k=`[${u}]`,h=`${f}${k}`;n.n=h;let l=d.r(T,n),[_,g]=l;n.n=h;let p=s?.unique;if(_&&p){let b=g,A=typeof p=="string";A?b=g[p]:typeof p=="function"&&(b=p(g)),y.has(b)?(A&&(n.n=`${f}${k}.${p}`),l=[!1,[j(n,A?`Type '${d.t?.[p]?.e}' with value "${b}" is not unique`:typeof p=="function"?`Type '${d.e}' unique fn return with value "${b}" is not unique`:`${d.e} value is not unique`)]]):y.add(b)}let[x,$]=l;if(x)a.push($);else if(t){o.push($.map(b=>j(n,b)));continue}else return{errors:$.map(b=>j(n,b)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};q(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:K.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:K.call(this,n,e,t,!0,r):!1)}}}function _e(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:K.call(this,r,e,n))}}}function S(e,r,{noWarnings:n=!1}={}){let t={i:[],n:"",a:!1,o:0,p:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.i.length>0?t.i:!1}:{ok:!1,error:!0,errors:o}}function he(e){return r=>S(r,e)}function je(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 L(e,r){let n={i:[],n:"",a:!1,o:0,p:!1};return!!r.r(e,n)[0]}function Oe(e){return r=>L(r,e)}function ke(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function xe(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 ge(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 me(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 Z(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function we(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 S(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${m(t)?t.message:""}`]}}}function I(e){return typeof e=="function"}function $e(){return(e,r)=>O(e,r)}export{G as a,H as b,X as c,Y as d,ee as e,re as f,ne as g,te as h,se as i,oe as j,ae as k,ie as l,ce as m,z as n,ue as o,O as p,ye as q,fe as r,Q as s,le as t,Te as u,de as v,J as w,pe as x,Re as y,be as z,_e as A,S as B,he as C,je as D,L as E,Oe as F,ke as G,xe as H,ge as I,me as J,Z as K,we as L,$e as M};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var Z=(e,r)=>{for(var n in r)P(e,n,{get:r[n],enumerable:!0})},G=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of J(r))!L.call(e,o)&&o!==n&&P(e,o,{get:()=>r[o],enumerable:!(t=Q(r,o))||t.enumerable});return e};var H=e=>G(P({},"__esModule",{value:!0}),e);var ve={};Z(ve,{rc_any:()=>se,rc_array:()=>ke,rc_assert_is_valid:()=>Ee,rc_boolean:()=>ie,rc_date:()=>ye,rc_default:()=>pe,rc_get_obj_schema:()=>he,rc_instanceof:()=>fe,rc_is_valid:()=>M,rc_literals:()=>le,rc_loose_array:()=>ge,rc_loose_parse:()=>$e,rc_loose_record:()=>Oe,rc_null:()=>oe,rc_nullish_default:()=>de,rc_number:()=>ue,rc_obj_builder:()=>Ne,rc_obj_extends:()=>be,rc_obj_intersection:()=>_e,rc_obj_omit:()=>xe,rc_obj_pick:()=>je,rc_obj_strict:()=>W,rc_object:()=>_,rc_parse:()=>$,rc_parse_json:()=>Ie,rc_parser:()=>me,rc_record:()=>D,rc_recursive:()=>Ae,rc_rename_from_key:()=>B,rc_rename_key:()=>Re,rc_string:()=>ce,rc_transform:()=>Pe,rc_tuple:()=>we,rc_undefined:()=>te,rc_union:()=>Te,rc_unknown:()=>ae,rc_unsafe_transform:()=>Se,rc_validator:()=>Ke,snakeCase:()=>z});module.exports=H(ve);function X(e){return{...this,y:e}}function x(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function S(e,r){e.warnings.push(x(e,r))}function q(e,r){r.forEach(n=>S(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 o=t();if(o&&(o===!0||!o.errors)){let s=o===!0?r:o.data;return e.t&&!e.t(s)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,s]}if(!n.strict){let s=e.y;if(s!==void 0)return S(n,`Fallback used, errors -> ${N(o,n,e,r)}`),[!0,I(s)?s():s];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}'`]]:(S(n,`Autofixed from error "${N(o,n,e,r)}"`),[!0,a.fixed])}}return[!1,o?o.errors:[V(e,r)]]}function N(e,r,n,t){return e?e.errors.map(o=>o.replace(r.path,"")).join("; "):V(n,t)}function Y(e){return{...this,f:!0,c:e}}function ee(e){return{...this,t:e}}function v(){return{...this,o:!0}}function V(e,r){return`Type '${m(r,!!e.l)}' is not assignable to '${e.e}'`}function re(){return{...this,a:!0,e:`${this.e}_or_null`}}function ne(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:X,where:ee,optional:v,optionalKey:v,orNullish:ne,withAutofix:Y,orNull:re,y:void 0,t:void 0,o:!1,a:!1,s:!1,f:!1,l:!1,i:void 0,c:void 0,d:void 0,n:void 0,u:!1,T:!1,p:[]},te={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},oe={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},se={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},ae={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},ie={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ce={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},ue={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ye={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function fe(e){return{...i,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function le(...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?m(e[0],!0):e.map(r=>m(r,!0)).join(" | ")}}var C=1;function Te(...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,o=[],s=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 p=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&p!==-1?p>0?y.push(...T):(s<C&&o.push(...T),s+=1):a=!0}return n.path=t,y.length>0||o.length>0?((s>C||a)&&o.push("not matches any other union member"),{errors:[...y,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function pe(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[s,a]=o;return s?a!==void 0?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function de(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[s,a]=o;return s?a!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function B(e,r){return{...r,i:e}}var Re=B;function F(e){return w(e)&&"__rc_type"in e}function U(e){if(F(e))return e;if(w(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=U(t);return _(r)}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=U(o);return{...i,n,e:"object",u:!0,p:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!w(t))return o.objErrKeyIndex=-1,!1;let s=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=o.path,R=-1;for(let[u,T]of this.p){let p=u;R+=1;let O=`.${u}`,j=`${f}${O}`;o.path=j;let l,h=u;if(T.i&&(l=t[T.i],h=T.i),l===void 0&&(l=t[u],h=u),l===void 0&&r==="snake_case"){let k=z(u);l=t[k],h=k}s?.delete(h);let[g,d]=T.r(l,o);if(g)a[p]=d;else{for(let k of d)o.path=j,y.push(x(o,k));if(o.objErrShortCircuit){o.objErrKeyIndex=R;break}}}if(s&&s.size>0)for(let u of s)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 be(e,r){return{..._(e,r),e:"extends_object",T:!0}}function he(e){return e.n}function W(e,r){let n=(()=>{if(F(e)){if(!e.n)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.n;{let t={};for(let[o,s]of Object.entries(e.n))t[o]=s.n?W(s,r):s;return t}}return e})();return{..._(n,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 o=e.n[t];o&&(n[t]=o)}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 D(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!w(t))return!1;let s={},a=[],y=o.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(o.path=T,r&&!r(f)){a.push(x(o,`Key '${f}' is not allowed`));continue}let p=t[f],[O,j]=e.r(R,o);if(O)s[f]=p;else{let l=j;for(let h of l)a.push(x(o,h));if(o.objErrShortCircuit)break}}if(a.length>0)if(n)q(o,a);else return{errors:a,data:void 0};return{errors:!1,data:s}})}}}function Oe(e,{checkKey:r}={}){return D(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let s=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let p=R?r[u]:r,O=`[${u}]`,j=`${f}${O}`;n.path=j;let l=p.r(T,n),[h,g]=l;n.path=j;let d=o?.unique;if(h&&d){let b=g,A=typeof d=="string";A?b=g[d]:typeof d=="function"&&(b=d(g)),y.has(b)?(A&&(n.path=`${f}${O}.${d}`),l=[!1,[x(n,A?`Type '${p.n?.[d]?.e}' with value "${b}" is not unique`:typeof d=="function"?`Type '${p.e}' unique fn return with value "${b}" is not unique`:`${p.e} value is not unique`)]]):y.add(b)}let[k,K]=l;if(k)a.push(K);else if(t){s.push(K.map(b=>x(n,b)));continue}else return{errors:K.map(b=>x(n,b)),data:void 0}}if(s.length>0){if(a.length===0)return{errors:s.slice(0,5).flat(),data:void 0};q(n,s.flat())}return{errors:!1,data:a}}function ke(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function ge(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.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:E.call(this,r,e,n))}}}function $(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[o,s]=r.r(e,t);return o?{error:!1,ok:!0,data:s,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:s}}function me(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 M(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function Ke(e){return r=>M(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[o,s]=e.r(n,t);return o?[!0,r(s)]:[!1,s]}}}function Se(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[o,s]=e.r(n,t);if(o){let a=r(s);return a.ok?[!0,a.data]:[!1,a.errors]}return[!1,s]}}}function m(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 w(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function z(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 ${m(e,!0)}`]};let t=JSON.parse(e);return $(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${w(t)?t.message:""}`]}}}function I(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_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_intersection,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_rename_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 Q=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var Z=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},G=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of J(r))!L.call(e,s)&&s!==n&&K(e,s,{get:()=>r[s],enumerable:!(t=Q(r,s))||t.enumerable});return e};var H=e=>G(K({},"__esModule",{value:!0}),e);var Ee={};Z(Ee,{rc_any:()=>oe,rc_array:()=>xe,rc_assert_is_valid:()=>Ie,rc_boolean:()=>ie,rc_date:()=>ye,rc_default:()=>de,rc_get_obj_schema:()=>_e,rc_instanceof:()=>fe,rc_is_valid:()=>M,rc_literals:()=>le,rc_loose_array:()=>ge,rc_loose_parse:()=>$e,rc_loose_record:()=>ke,rc_null:()=>se,rc_nullish_default:()=>pe,rc_number:()=>ue,rc_obj_builder:()=>ve,rc_obj_extends:()=>be,rc_obj_intersection:()=>he,rc_obj_omit:()=>Oe,rc_obj_pick:()=>je,rc_obj_strict:()=>W,rc_object:()=>h,rc_parse:()=>$,rc_parse_json:()=>Ne,rc_parser:()=>we,rc_record:()=>D,rc_recursive:()=>Pe,rc_rename_from_key:()=>B,rc_rename_key:()=>Re,rc_string:()=>ce,rc_transform:()=>Ke,rc_tuple:()=>me,rc_undefined:()=>te,rc_union:()=>Te,rc_unknown:()=>ae,rc_unsafe_transform:()=>Se,rc_validator:()=>Ae,snakeCase:()=>z});module.exports=H(Ee);function X(e){return{...this,d:e}}function O(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.n?`$${e.n}: `:""}${r}`}function S(e,r){e.i.push(O(e,r))}function C(e,r){r.forEach(n=>S(e,n))}function c(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.y&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.o&&!e.o(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n.p){let o=e.d;if(o!==void 0)return S(n,`Fallback used, errors -> ${v(s,n,e,r)}`),[!0,N(o)?o():o];if(e.R&&e.l){let a=e.l(r);if(a)return e.o&&!e.o(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(S(n,`Autofixed from error "${v(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[V(e,r)]]}function v(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):V(n,t)}function Y(e){return{...this,R:!0,l:e}}function ee(e){return{...this,o:e}}function E(){return{...this,c:!0}}function V(e,r){return`Type '${w(r,!!e.b)}' is not assignable to '${e.e}'`}function re(){return{...this,y:!0,e:`${this.e}_or_null`}}function ne(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:X,where:ee,optional:E,optionalKey:E,orNullish:ne,withAutofix:Y,orNull:re,d:void 0,o:void 0,c:!1,y:!1,u:!1,R:!1,b:!1,f:void 0,l:void 0,j:void 0,t:void 0,T:!1,_:!1,h:[]},te={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},se={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},oe={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},ae={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},ie={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ce={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},ue={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ye={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function fe(e){return{...i,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function le(...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})},b:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var q=1;function Te(...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.n,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.T&&(n.n=`${t}|union ${f}|`),n.a=!0,n.s=0;let[u,T]=R.r(r,n);n.a=!1;let d=n.s;if(n.s=0,u)return!0;R.T&&d!==-1?d>0?y.push(...T):(o<q&&s.push(...T),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>q||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function de(e,r){return{...e,c:!1,u:!1,y:!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:N(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function pe(e,r){return{...e,c:!1,u:!1,y:!1,r(n,t){return c(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:N(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function B(e,r){return{...r,f:e}}var Re=B;function F(e){return m(e)&&"__rc_type"in e}function U(e){if(F(e))return e;if(m(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=U(t);return h(r)}throw new Error(`invalid schema: ${e}`)}function h(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=U(s);return{...i,t:n,e:"object",T:!0,h:Object.entries(n),r(t,s){return c(this,t,s,()=>{if(!m(t))return s.s=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.n,R=-1;for(let[u,T]of this.h){let d=u;R+=1;let k=`.${u}`,j=`${f}${k}`;s.n=j;let l,_=u;if(T.f&&(l=t[T.f],_=T.f),l===void 0&&(l=t[u],_=u),l===void 0&&r==="snake_case"){let x=z(u);l=t[x],_=x}o?.delete(_);let[g,p]=T.r(l,s);if(g)a[d]=p;else{for(let x of p)s.n=j,y.push(O(s,x));if(s.a){s.s=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._?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function be(e,r){return{...h(e,r),e:"extends_object",_:!0}}function _e(e){return e.t}function W(e,r){let n=(()=>{if(F(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?W(o,r):o;return t}}return e})();return{...h(n,r),e:"strict_obj"}}function he(...e){let r={};for(let n of e)Object.assign(r,n.t);return h(r)}function je(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 h(n)}function Oe(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 h(n)}function D(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return c(this,t,s,()=>{if(!m(t))return!1;let o={},a=[],y=s.n;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.n=T,r&&!r(f)){a.push(O(s,`Key '${f}' is not allowed`));continue}let d=t[f],[k,j]=e.r(R,s);if(k)o[f]=d;else{let l=j;for(let _ of l)a.push(O(s,_));if(s.a)break}}if(a.length>0)if(n)C(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ke(e,{checkKey:r}={}){return D(e,{checkKey:r,looseCheck:!0})}function I(e,r,n,t=!1,s){let o=[],a=[],y=new Set,f=n.n,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,k=`[${u}]`,j=`${f}${k}`;n.n=j;let l=d.r(T,n),[_,g]=l;n.n=j;let p=s?.unique;if(_&&p){let b=g,P=typeof p=="string";P?b=g[p]:typeof p=="function"&&(b=p(g)),y.has(b)?(P&&(n.n=`${f}${k}.${p}`),l=[!1,[O(n,P?`Type '${d.t?.[p]?.e}' with value "${b}" is not unique`:typeof p=="function"?`Type '${d.e}' unique fn return with value "${b}" is not unique`:`${d.e} value is not unique`)]]):y.add(b)}let[x,A]=l;if(x)a.push(A);else if(t){o.push(A.map(b=>O(n,b)));continue}else return{errors:A.map(b=>O(n,b)),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 xe(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:I.call(this,n,e,t,!1,r):!1)}}}function ge(e,r){return{...i,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:I.call(this,n,e,t,!0,r):!1)}}}function me(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:I.call(this,r,e,n))}}}function $(e,r,{noWarnings:n=!1}={}){let t={i:[],n:"",a:!1,s:0,p:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.i.length>0?t.i:!1}:{ok:!1,error:!0,errors:o}}function we(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 M(e,r){let n={i:[],n:"",a:!1,s:0,p:!1};return!!r.r(e,n)[0]}function Ae(e){return r=>M(r,e)}function Pe(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function Ke(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 Ie(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 z(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 $(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${m(t)?t.message:""}`]}}}function N(e){return typeof e=="function"}function ve(){return(e,r)=>h(e,r)}0&&(module.exports={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_intersection,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_rename_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
|
package/dist/runcheck.d.ts
CHANGED
|
@@ -109,13 +109,13 @@ type MapTupleToTypes<T extends readonly [...any[]]> = {
|
|
|
109
109
|
declare function rc_tuple<T extends readonly RcType<any>[]>(types: T): RcType<MapTupleToTypes<T>>;
|
|
110
110
|
type ParseOptions = {
|
|
111
111
|
/** ignore fallback and autofix */
|
|
112
|
-
|
|
112
|
+
noWarnings?: boolean;
|
|
113
113
|
};
|
|
114
114
|
/**
|
|
115
115
|
* Parse a runcheck type. If valid return the valid input, with warning for autofix
|
|
116
116
|
* and fallback, or the errors if invalid
|
|
117
117
|
*/
|
|
118
|
-
declare function rc_parse<S>(input: any, type: RcType<S>, {
|
|
118
|
+
declare function rc_parse<S>(input: any, type: RcType<S>, { noWarnings }?: ParseOptions): RcParseResult<S>;
|
|
119
119
|
type RcParser<T> = (input: any) => RcParseResult<T>;
|
|
120
120
|
/** create a reusable parser for a certain type */
|
|
121
121
|
declare function rc_parser<S>(type: RcType<S>): RcParser<S>;
|
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-VOMXQGTP.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,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,q as rc_obj_extends,t as rc_obj_intersection,v as rc_obj_omit,u as rc_obj_pick,s as rc_obj_strict,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,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
package/dist/chunk-2DQLFKXQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function F(e){return{...this,y:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function A(e,r){e.warnings.push(j(e,r))}function C(e,r){r.forEach(n=>A(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 o=t();if(o&&(o===!0||!o.errors)){let s=o===!0?r:o.data;return e.t&&!e.t(s)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,s]}if(!n.strict){let s=e.y;if(s!==void 0)return A(n,`Fallback used, errors -> ${I(o,n,e,r)}`),[!0,E(s)?s():s];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}'`]]:(A(n,`Autofixed from error "${I(o,n,e,r)}"`),[!0,a.fixed])}}return[!1,o?o.errors:[q(e,r)]]}function I(e,r,n,t){return e?e.errors.map(o=>o.replace(r.path,"")).join("; "):q(n,t)}function U(e){return{...this,f:!0,c:e}}function W(e){return{...this,t:e}}function N(){return{...this,o:!0}}function q(e,r){return`Type '${m(r,!!e.l)}' is not assignable to '${e.e}'`}function D(){return{...this,a:!0,e:`${this.e}_or_null`}}function M(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:F,where:W,optional:N,optionalKey:N,orNullish:M,withAutofix:U,orNull:D,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:[]},G={...i,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},H={...i,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},X={...i,r(e,r){return c(this,e,r,()=>!0)},e:"any"},Y={...i,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},ee={...i,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},re={...i,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},ne={...i,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},te={...i,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function oe(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?m(e[0],!0):e.map(r=>m(r,!0)).join(" | ")}}var v=1;function ae(...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,o=[],s=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 p=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&p!==-1?p>0?y.push(...T):(s<v&&o.push(...T),s+=1):a=!0}return n.path=t,y.length>0||o.length>0?((s>v||a)&&o.push("not matches any other union member"),{errors:[...y,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ie(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[s,a]=o;return s?a!==void 0?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ce(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[s,a]=o;return s?a!=null?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function z(e,r){return{...r,i:e}}var ue=z;function V(e){return w(e)&&"__rc_type"in e}function B(e){if(V(e))return e;if(w(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=B(t);return x(r)}throw new Error(`invalid schema: ${e}`)}function x(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=B(o);return{...i,n,e:"object",u:!0,d:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!w(t))return o.objErrKeyIndex=-1,!1;let s=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=o.path,R=-1;for(let[u,T]of this.d){let p=u;R+=1;let O=`.${u}`,_=`${f}${O}`;o.path=_;let l,h=u;if(T.i&&(l=t[T.i],h=T.i),l===void 0&&(l=t[u],h=u),l===void 0&&r==="snake_case"){let k=Z(u);l=t[k],h=k}s?.delete(h);let[g,d]=T.r(l,o);if(g)a[p]=d;else{for(let k of d)o.path=_,y.push(j(o,k));if(o.objErrShortCircuit){o.objErrKeyIndex=R;break}}}if(s&&s.size>0)for(let u of s)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 ye(e,r){return{...x(e,r),e:"extends_object",T:!0}}function fe(e){return e.n}function Q(e,r){let n=(()=>{if(V(e)){if(!e.n)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.n;{let t={};for(let[o,s]of Object.entries(e.n))t[o]=s.n?Q(s,r):s;return t}}return e})();return{...x(n,r),e:"strict_obj"}}function le(...e){let r={};for(let n of e)Object.assign(r,n.n);return x(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 o=e.n[t];o&&(n[t]=o)}return x(n)}function pe(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 x(n)}function J(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!w(t))return!1;let s={},a=[],y=o.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(o.path=T,r&&!r(f)){a.push(j(o,`Key '${f}' is not allowed`));continue}let p=t[f],[O,_]=e.r(R,o);if(O)s[f]=p;else{let l=_;for(let h of l)a.push(j(o,h));if(o.objErrShortCircuit)break}}if(a.length>0)if(n)C(o,a);else return{errors:a,data:void 0};return{errors:!1,data:s}})}}}function de(e,{checkKey:r}={}){return J(e,{checkKey:r,looseCheck:!0})}function P(e,r,n,t=!1,o){let s=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let p=R?r[u]:r,O=`[${u}]`,_=`${f}${O}`;n.path=_;let l=p.r(T,n),[h,g]=l;n.path=_;let d=o?.unique;if(h&&d){let b=g,K=typeof d=="string";K?b=g[d]:typeof d=="function"&&(b=d(g)),y.has(b)?(K&&(n.path=`${f}${O}.${d}`),l=[!1,[j(n,K?`Type '${p.n?.[d]?.e}' with value "${b}" is not unique`:typeof d=="function"?`Type '${p.e}' unique fn return with value "${b}" is not unique`:`${p.e} value is not unique`)]]):y.add(b)}let[k,$]=l;if(k)a.push($);else if(t){s.push($.map(b=>j(n,b)));continue}else return{errors:$.map(b=>j(n,b)),data:void 0}}if(s.length>0){if(a.length===0)return{errors:s.slice(0,5).flat(),data:void 0};C(n,s.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:P.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:P.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:P.call(this,r,e,n))}}}function S(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[o,s]=r.r(e,t);return o?{error:!1,ok:!0,data:s,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:s}}function _e(e){return r=>S(r,e)}function je(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 L(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function xe(e){return r=>L(r,e)}function Oe(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function ke(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[o,s]=e.r(n,t);return o?[!0,r(s)]:[!1,s]}}}function ge(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[o,s]=e.r(n,t);if(o){let a=r(s);return a.ok?[!0,a.data]:[!1,a.errors]}return[!1,s]}}}function m(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 w(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Z(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 ${m(e,!0)}`]};let t=JSON.parse(e);return S(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${w(t)?t.message:""}`]}}}function E(e){return typeof e=="function"}function $e(){return(e,r)=>x(e,r)}export{G as a,H as b,X as c,Y as d,ee as e,re as f,ne as g,te as h,oe as i,se as j,ae as k,ie as l,ce as m,z as n,ue as o,x as p,ye as q,fe as r,Q as s,le as t,Te as u,pe as v,J as w,de as x,Re as y,be as z,he as A,S as B,_e as C,je as D,L as E,xe as F,Oe as G,ke as H,ge as I,we as J,Z as K,me as L,$e as M};
|