runcheck 0.53.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/dist/autofixable.cjs +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-65CFL2UP.js +2 -0
- package/dist/runcheck.cjs +2 -2
- package/dist/runcheck.d.ts +28 -6
- package/dist/runcheck.js +1 -1
- package/package.json +3 -2
- package/dist/chunk-BBFBYV3C.js +0 -2
package/README.md
CHANGED
|
@@ -576,6 +576,18 @@ type SchemaType = {
|
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
578
|
}
|
|
579
|
+
optionalObj?: {
|
|
580
|
+
a: string
|
|
581
|
+
}
|
|
582
|
+
objOrNull: null | {
|
|
583
|
+
a: string
|
|
584
|
+
}
|
|
585
|
+
objOrNullish:
|
|
586
|
+
| null
|
|
587
|
+
| undefined
|
|
588
|
+
| {
|
|
589
|
+
a: string
|
|
590
|
+
}
|
|
579
591
|
}
|
|
580
592
|
|
|
581
593
|
const schema = rc_obj_builder<SchemaType>()({
|
|
@@ -589,5 +601,48 @@ const schema = rc_obj_builder<SchemaType>()({
|
|
|
589
601
|
},
|
|
590
602
|
},
|
|
591
603
|
},
|
|
604
|
+
optionalObj: [
|
|
605
|
+
'optional',
|
|
606
|
+
{
|
|
607
|
+
a: rc_string,
|
|
608
|
+
// better error here and autocompletion :)
|
|
609
|
+
},
|
|
610
|
+
],
|
|
611
|
+
objOrNull: [
|
|
612
|
+
'null_or',
|
|
613
|
+
{
|
|
614
|
+
a: rc_string,
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
objOrNullish: [
|
|
618
|
+
'nullish_or',
|
|
619
|
+
{
|
|
620
|
+
a: rc_string,
|
|
621
|
+
},
|
|
622
|
+
],
|
|
623
|
+
})
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
# `rc_discriminated_union`
|
|
627
|
+
|
|
628
|
+
Creates a discriminated union type with faster check performance compared to `rc_union`.
|
|
629
|
+
|
|
630
|
+
```ts
|
|
631
|
+
const networkState = rc_discriminated_union('state', {
|
|
632
|
+
loading: {},
|
|
633
|
+
success: {
|
|
634
|
+
response: rc_string,
|
|
635
|
+
},
|
|
636
|
+
error: {
|
|
637
|
+
code: rc_number,
|
|
638
|
+
},
|
|
592
639
|
})
|
|
640
|
+
|
|
641
|
+
const result = rc_unwrap(
|
|
642
|
+
rc_parse({ state: 'success', response: 'hello' }, networkState),
|
|
643
|
+
)
|
|
644
|
+
// result will be inferred as:
|
|
645
|
+
// | { state: 'loading' }
|
|
646
|
+
// | { state: 'success', response: string }
|
|
647
|
+
// | { state: 'error', code: number }
|
|
593
648
|
```
|
package/dist/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)f(e,n,{get:r[n],enumerable:!0})},w=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&f(e,t,{get:()=>r[t],enumerable:!(o=h(r,t))||o.enumerable});return e};var P=e=>w(f({},"__esModule",{value:!0}),e);var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)f(e,n,{get:r[n],enumerable:!0})},w=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&f(e,t,{get:()=>r[t],enumerable:!(o=h(r,t))||o.enumerable});return e};var P=e=>w(f({},"__esModule",{value:!0}),e);var A={};m(A,{rc_boolean_autofix:()=>I,rc_number_autofix:()=>S,rc_string_autofix:()=>v});module.exports=P(A);function k(e){return{...this,g:e}}function u(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function c(e,r){e.T.push(r.startsWith("$")?r:u(e,r))}function s(e,r,n,o){if(e.d&&r===void 0)return[!0,r];if(e.p&&r==null)return[!0,r];if(e.R&&r===null)return[!0,r];let t=o();if(t&&(t===!0||!t.errors)){let i=t===!0?r:t.data;return e.c&&!e.c(i)?[!1,[u(n,`Predicate failed for type '${e.e}'`)]]:[!0,i]}if(!n.i){let i=e.g;if(i!==void 0)return c(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,E(i)?i():i];if(e.j&&e.h){let l=e.h(r);if(l)return e.c&&!e.c(l.fixed)?[!1,[u(n,`Predicate failed for autofix in type '${e.e}'`)]]:(c(n,`Autofixed from error "${y(t,n,e,r)}"`),[!0,l.fixed])}}return[!1,t?t.errors:[u(n,T(e,r))]]}function y(e,r,n,o){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,o)}function x(e){return{...this,j:!0,h:e}}function $(e){return{...this,c:e}}function d(){return{...this,d:!0,e:`${this.e}_optional`}}function T(e,r){return`Type '${O(r,!!e.O)}' is not assignable to '${e.e}'`}function N(){return{...this,R:!0,e:`${this.e}_or_null`}}function j(){return{...this,p:!0,e:`${this.e}_or_nullish`}}var a={__rc_type:void 0,withFallback:k,where:$,optional:d,optionalKey:d,orNullish:j,withAutofix:x,orNull:N,_:void 0,g:void 0,c:void 0,d:!1,R:!1,p:!1,j:!1,O:!1,y:void 0,h:void 0,t:void 0,f:!1,b:!1,u:[]},C={...a,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},K={...a,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},V={...a,r(e,r){return s(this,e,r,()=>!0)},e:"any"},q={...a,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},p={...a,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...a,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},R={...a,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...a,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e,r){let n=typeof e,o=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(o==="string"||o==="number"||o==="boolean")?`${o}(${e})`:o}function E(e){return typeof e=="function"}var I=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),v=_.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});
|
package/dist/autofixable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as f,s as t,t as o}from"./chunk-
|
|
1
|
+
import{r as f,s as t,t as o}from"./chunk-65CFL2UP.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,2 @@
|
|
|
1
|
+
function z(e,r){return{...r,y:e}}function L(e){return k(e)&&"__rc_type"in e}function O(e){if(L(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=O(t);return _(r)}else if(Array.isArray(e)){let[r,n]=e;switch(r){case"optional":return O(n).optional();case"nullish_or":return O(n).orNullish();case"null_or":return O(n).orNull();case"array":return W(O(n));case"loose_array":return q(O(n))}}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=O(o);return{...l,t:n,e:"object",f:!0,u:Object.entries(n),r(t,o){return y(this,t,o,()=>{if(!k(t))return o.s=-1,!1;let s=this.e==="strict_obj"||o.a?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.s=-1;let p=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[f]of this.u)s.has(f)?s.delete(f):p.push(d(o,`Key '${f}' is missing`));for(let f of s)p.push(d(o,`Key '${f}' is not defined in the object shape`));return{data:void 0,errors:p}}let c={},i=[],u=o.n,T=-1;for(let[p,f]of this.u){let h=p;T+=1;let b=`.${p}`,g=`${u}${b}`;o.n=g;let R=t[p],j=p;if(R===void 0&&f.y&&(R=t[f.y],j=f.y),R===void 0&&r==="snake_case"){let x=C(p);R=t[x],j=x}s?.delete(j);let[S,m]=f.r(R,o);if(S)c[h]=m;else{for(let x of m)o.n=g,i.push(x);if(o.o){o.s=T;break}}}if(s&&s.size>0)for(let p of s)o.n=u,i.push(d(o,`Key '${p}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...c}}:{errors:!1,data:c}})}}}function Q(e,r){return{..._(e,r),e:"extends_object",b:!0}}function J(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function Z(e,r){return{..._(e,r),e:"strict_obj"}}function G(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.a;t.a=!0;let a=e.r(n,t);return t.a=o,a}}}function H(...e){let r={};for(let n of e)Object.assign(r,n.t);return _(r)}function X(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return _(n)}function Y(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 _(n)}function ee(){return(e,r)=>_(e,r)}function re(e){return{...this,g:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function K(e,r){e.T.push(r.startsWith("$")?r:d(e,r))}function U(e,r){r.forEach(n=>K(e,n))}function y(e,r,n,t){if(e.d&&r===void 0)return[!0,r];if(e.p&&r==null)return[!0,r];if(e.R&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.g;if(a!==void 0)return K(n,`Fallback used, errors -> ${B(o,n,e,r)}`),[!0,N(a)?a():a];if(e.j&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(K(n,`Autofixed from error "${B(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,D(e,r))]]}function B(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):D(n,t)}function ne(e){return{...this,j:!0,h:e}}function te(e){return{...this,c:e}}function F(){return{...this,d:!0,e:`${this.e}_optional`}}function D(e,r){return`Type '${P(r,!!e.O)}' is not assignable to '${e.e}'`}function oe(){return{...this,R:!0,e:`${this.e}_or_null`}}function se(){return{...this,p:!0,e:`${this.e}_or_nullish`}}var l={__rc_type:void 0,withFallback:re,where:te,optional:F,optionalKey:F,orNullish:se,withAutofix:ne,orNull:oe,_:void 0,g:void 0,c:void 0,d:!1,R:!1,p:!1,j:!1,O:!1,y:void 0,h:void 0,t:void 0,f:!1,b:!1,u:[]},ge={...l,r(e,r){return y(this,e,r,()=>e===void 0)},e:"undefined"},je={...l,r(e,r){return y(this,e,r,()=>e===null)},e:"null"},Oe={...l,r(e,r){return y(this,e,r,()=>!0)},e:"any"},ke={...l,r(e,r){return y(this,e,r,()=>!0)},e:"unknown"},me={...l,r(e,r){return y(this,e,r,()=>typeof e=="boolean")},e:"boolean"},xe={...l,r(e,r){return y(this,e,r,()=>typeof e=="string")},e:"string"},we={...l,r(e,r){return y(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Pe={...l,r(e,r){return y(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function Ee(e){return{...l,r(r,n){return y(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{...l,r(r,n){return y(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},O:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var V=1;function $e(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...l,r(r,n){return y(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,c=[],i=0;for(let u of e){i+=1,u.f&&(n.n=`${t}|union ${i}|`);let T=n.o;n.o=!0,n.s=0;let[p,f]=u.r(r,n),h=n.s;if(n.o=T,n.s=0,p)return!0;u.f&&h!==-1?h>0?c.push(...f):(a<V&&o.push(...f),a+=1):s=!0}return n.n=t,c.length>0||o.length>0?((a>V||s)&&o.push(d(n,"not matches any other union member")),{errors:[...c,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Ae(e,r){return{...e,d:!1,p:!1,R:!1,r(t,o){return y(this,t,o,()=>{if(t===void 0)return n();let[a,s]=e.r(t,o);return a?s===void 0?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`};function n(){return{data:N(r)?r():r,errors:!1}}}function Ke(e,r){return{...e,d:!1,p:!1,R:!1,r(t,o){return y(this,t,o,()=>{if(t==null)return n();let[a,s]=e.r(t,o);return a?s==null?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`};function n(){return{data:N(r)?r():r,errors:!1}}}function ae(e,{checkKey:r,looseCheck:n}={}){return{...l,e:`record<string, ${e.e}>`,r(t,o){return y(this,t,o,()=>{if(!k(t))return!1;let a={},s=[],c=o.n;for(let[i,u]of Object.entries(t)){let T=`.${i}`,p=`${c}${T}`;if(o.n=p,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let f=t[i],[h,b]=e.r(u,o);if(h)a[i]=f;else{let g=b;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)U(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function ve(e,r){let n={};for(let[t,o]of Object.entries(r))n[t]=_(o);return{...l,e:"discriminated_union",f:!0,r(t,o){return y(this,t,o,()=>{if(!k(t))return o.s=-1,!1;let a=t[e];o.n=`${o.n}.${e}`;let s=n[a];if(!s){let u=P(a,!0);return{errors:[d(o,`Type '${u}' is not a valid discriminator`)],data:void 0}}o.n=`${o.n}|${a}|`;let[c,i]=s.r(t,o);return c?(i[e]=a,{errors:!1,data:i}):{errors:i,data:void 0}})}}}function Ie(e,{checkKey:r}={}){return ae(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let a=t&&!n.i&&!n.l,s=o?.unique,c=[],i=[],u=s?new Set:void 0,T=n.n,p=Array.isArray(r),f=-1;for(let h of e){f++;let b=p?r[f]:r,g=`[${f}]`,R=`${T}${g}`;n.n=R;let j=b.r(h,n),[S,m]=j;if(n.n=R,S&&u){let w=m,A=typeof s=="string";A?w=m[s]:typeof s=="function"&&(w=s(m)),u.has(w)?(A&&(n.n=`${T}${g}.${s}`),j=[!1,[d(n,A?`Type '${b.t?.[s]?.e}' with value "${w}" is not unique`:typeof s=="function"?`Type '${b.e}' unique fn return with value "${w}" is not unique`:`${b.e} value is not unique`)]]):u.add(w)}let[x,$]=j;if(x)i.push($);else if(a){c.push($);continue}else return{errors:$,data:void 0}}if(c.length>0){if(i.length===0)return{errors:c.slice(0,5).flat(),data:void 0};U(n,c.flat())}return{errors:!1,data:i}}function W(e,r){return{...l,e:`${e.e}[]`,_:e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function Ne(e){if(!e._)throw new Error("Type does not have an item type");return e._}function We(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.l;t.l=!0;let a=e.r(n,t);return t.l=o,a}}}function q(e,r){return{...l,_:e,e:`${e.e}[]`,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!0,r):!1)}}}function qe(e){return{...l,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return y(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:E.call(this,r,e,n))}}}function I(e,r,{noWarnings:n=!1}={}){let t={T:[],n:"",o:!1,s:0,i:n,a:!1,l:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,value:a,warnings:t.T.length>0?t.T:!1}:{ok:!1,error:!0,errors:a}}function Ce(e){return r=>I(r,e)}function Be(e,r,n){let t=I(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.value,errors:!1,warnings:t.warnings}}function Fe(e){return ie(e,null)}function ie(e,r){return e.error?{value:r,errors:e.errors,warnings:!1}:{value:e.value,errors:!1,warnings:e.warnings}}var v=class extends Error{constructor(n){super(n.join(`
|
|
2
|
+
`));this.errors=n}};function Ve(e){if(e.error)throw new v(e.errors);return e}function ue(e,r){let n={T:[],n:"",o:!1,s:0,i:!1,a:!1,l:!1};return!!r.r(e,n)[0]}function Ue(e){return r=>ue(r,e)}function De(e){return{...l,e:"recursive",r(r,n){return e().r(r,n)}}}function M(e,r,n,t){let o=e.n,a=e.o,s=e.a,c=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.a=!0,e.i=!0);let i=r.r(n,e);return e.a=s,e.i=c,e.n=o,e.o=a,i}function ce(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...l,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=M(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);return c?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function Me(e,r){return ce(e,r)}function ze(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...l,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=M(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);if(c){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[d(a,u.errors)]:u.errors.map(T=>d(a,T))]}return[!1,[...s||[],...i]]}}}function P(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Le(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 Qe(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${P(e,!0)}`]};let t=JSON.parse(e);return I(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${k(t)?t.message:""}`]}}}function N(e){return typeof e=="function"}export{z as a,_ as b,Q as c,J as d,Z as e,G as f,H as g,X as h,Y as i,ee as j,d as k,y as l,l as m,ge as n,je as o,Oe as p,ke as q,me as r,xe as s,we as t,Pe as u,Ee as v,Se as w,$e as x,Ae as y,Ke as z,ae as A,ve as B,Ie as C,W as D,Ne as E,We as F,q as G,qe as H,I,Ce as J,Be as K,Fe as L,ie as M,v as N,Ve as O,ue as P,Ue as Q,De as R,ce as S,Me as T,ze as U,Le as V,k as W,C as X,Qe as Y};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(e,r)=>{for(var n in r)I(e,n,{get:r[n],enumerable:!0})},ie=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of oe(r))!se.call(e,o)&&o!==n&&I(e,o,{get:()=>r[o],enumerable:!(t=te(r,o))||t.enumerable});return e};var ue=e=>ie(I({},"__esModule",{value:!0}),e);var Me={};ae(Me,{RcValidationError:()=>w,defaultProps:()=>l,getWarningOrErrorWithPath:()=>d,isObject:()=>k,parse:()=>c,rc_any:()=>_e,rc_array:()=>$e,rc_assert_is_valid:()=>Ve,rc_boolean:()=>be,rc_date:()=>ke,rc_default:()=>we,rc_disable_loose_array:()=>Se,rc_enable_obj_strict:()=>V,rc_get_array_item_type:()=>Ae,rc_get_from_key_as_fallback:()=>q,rc_get_obj_schema:()=>F,rc_instanceof:()=>Oe,rc_is_valid:()=>ee,rc_literals:()=>xe,rc_loose_array:()=>Ke,rc_loose_parse:()=>Ne,rc_loose_record:()=>Ee,rc_narrow:()=>Fe,rc_null:()=>Re,rc_nullish_default:()=>Pe,rc_number:()=>je,rc_obj_builder:()=>L,rc_obj_extends:()=>B,rc_obj_merge:()=>D,rc_obj_omit:()=>z,rc_obj_pick:()=>M,rc_obj_strict:()=>U,rc_object:()=>_,rc_parse:()=>$,rc_parse_json:()=>De,rc_parser:()=>ve,rc_record:()=>X,rc_recursive:()=>Be,rc_string:()=>ge,rc_transform:()=>ne,rc_tuple:()=>Ie,rc_undefined:()=>de,rc_union:()=>me,rc_unknown:()=>he,rc_unsafe_transform:()=>Ue,rc_unwrap:()=>qe,rc_unwrap_or:()=>Y,rc_unwrap_or_null:()=>We,rc_validator:()=>Ce,snakeCase:()=>v});module.exports=ue(Me);function q(e,r){return{...r,y:e}}function ce(e){return k(e)&&"__rc_type"in e}function C(e){if(ce(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=C(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]=C(o);return{...l,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!k(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let p=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[f]of this.u)s.has(f)?s.delete(f):p.push(d(o,`Key '${f}' is missing`));for(let f of s)p.push(d(o,`Key '${f}' is not defined in the object shape`));return{data:void 0,errors:p}}let y={},i=[],u=o.n,T=-1;for(let[p,f]of this.u){let h=p;T+=1;let b=`.${p}`,g=`${u}${b}`;o.n=g;let R=t[p],j=p;if(R===void 0&&f.y&&(R=t[f.y],j=f.y),R===void 0&&r==="snake_case"){let x=v(p);R=t[x],j=x}s?.delete(j);let[A,O]=f.r(R,o);if(A)y[h]=O;else{for(let x of O)o.n=g,i.push(x);if(o.o){o.a=T;break}}}if(s&&s.size>0)for(let p of s)o.n=u,i.push(d(o,`Key '${p}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...y}}:{errors:!1,data:y}})}}}function B(e,r){return{..._(e,r),e:"extends_object",b:!0}}function F(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function U(e,r){return{..._(e,r),e:"strict_obj"}}function V(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function D(...e){let r={};for(let n of e)Object.assign(r,n.t);return _(r)}function M(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return _(n)}function z(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 _(n)}function L(){return(e,r)=>_(e,r)}function le(e){return{...this,g:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function N(e,r){e.f.push(r.startsWith("$")?r:d(e,r))}function G(e,r){r.forEach(n=>N(e,n))}function c(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.p&&r==null)return[!0,r];if(e.d&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.g;if(a!==void 0)return N(n,`Fallback used, errors -> ${Q(o,n,e,r)}`),[!0,W(a)?a():a];if(e.j&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(N(n,`Autofixed from error "${Q(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,H(e,r))]]}function Q(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):H(n,t)}function ye(e){return{...this,j:!0,h:e}}function fe(e){return{...this,c:e}}function J(){return{...this,T:!0}}function H(e,r){return`Type '${P(r,!!e.k)}' is not assignable to '${e.e}'`}function Te(){return{...this,d:!0,e:`${this.e}_or_null`}}function pe(){return{...this,p:!0,e:`${this.e}_or_nullish`}}var l={__rc_type:void 0,withFallback:le,where:fe,optional:J,optionalKey:J,orNullish:pe,withAutofix:ye,orNull:Te,R:void 0,g:void 0,c:void 0,T:!1,d:!1,p:!1,j:!1,k:!1,y:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},de={...l,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},Re={...l,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},_e={...l,r(e,r){return c(this,e,r,()=>!0)},e:"any"},he={...l,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},be={...l,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ge={...l,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},je={...l,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ke={...l,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function Oe(e){return{...l,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function xe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...l,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var Z=1;function me(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...l,r(r,n){return c(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,y=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let T=n.o;n.o=!0,n.a=0;let[p,f]=u.r(r,n),h=n.a;if(n.o=T,n.a=0,p)return!0;u._&&h!==-1?h>0?y.push(...f):(a<Z&&o.push(...f),a+=1):s=!0}return n.n=t,y.length>0||o.length>0?((a>Z||s)&&o.push(d(n,"not matches any other union member")),{errors:[...y,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function we(e,r){return{...e,T:!1,p:!1,d:!1,r(t,o){return c(this,t,o,()=>{if(t===void 0)return n();let[a,s]=e.r(t,o);return a?s===void 0?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`};function n(){return{data:W(r)?r():r,errors:!1}}}function Pe(e,r){return{...e,T:!1,p:!1,d:!1,r(t,o){return c(this,t,o,()=>{if(t==null)return n();let[a,s]=e.r(t,o);return a?s==null?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`};function n(){return{data:W(r)?r():r,errors:!1}}}function X(e,{checkKey:r,looseCheck:n}={}){return{...l,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!k(t))return!1;let a={},s=[],y=o.n;for(let[i,u]of Object.entries(t)){let T=`.${i}`,p=`${y}${T}`;if(o.n=p,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let f=t[i],[h,b]=e.r(u,o);if(h)a[i]=f;else{let g=b;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)G(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function Ee(e,{checkKey:r}={}){return X(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let a=t&&!n.i&&!n.l,s=o?.unique,y=[],i=[],u=s?new Set:void 0,T=n.n,p=Array.isArray(r),f=-1;for(let h of e){f++;let b=p?r[f]:r,g=`[${f}]`,R=`${T}${g}`;n.n=R;let j=b.r(h,n),[A,O]=j;if(n.n=R,A&&u){let m=O,K=typeof s=="string";K?m=O[s]:typeof s=="function"&&(m=s(O)),u.has(m)?(K&&(n.n=`${T}${g}.${s}`),j=[!1,[d(n,K?`Type '${b.t?.[s]?.e}' with value "${m}" is not unique`:typeof s=="function"?`Type '${b.e}' unique fn return with value "${m}" is not unique`:`${b.e} value is not unique`)]]):u.add(m)}let[x,S]=j;if(x)i.push(S);else if(a){y.push(S);continue}else return{errors:S,data:void 0}}if(y.length>0){if(i.length===0)return{errors:y.slice(0,5).flat(),data:void 0};G(n,y.flat())}return{errors:!1,data:i}}function $e(e,r){return{...l,e:`${e.e}[]`,R: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 Ae(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function Se(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.l;t.l=!0;let a=e.r(n,t);return t.l=o,a}}}function Ke(e,r){return{...l,R:e,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 Ie(e){return{...l,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,{noWarnings:n=!1}={}){let t={f:[],n:"",o:!1,a:0,i:n,s:!1,l:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,value:a,warnings:t.f.length>0?t.f:!1}:{ok:!1,error:!0,errors:a}}function ve(e){return r=>$(r,e)}function Ne(e,r,n){let t=$(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.value,errors:!1,warnings:t.warnings}}function We(e){return Y(e,null)}function Y(e,r){return e.error?{value:r,errors:e.errors,warnings:!1}:{value:e.value,errors:!1,warnings:e.warnings}}var w=class extends Error{constructor(n){super(n.join(`
|
|
2
|
-
`));this.errors=n}};function
|
|
1
|
+
"use strict";var I=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var ue=(e,r)=>{for(var n in r)I(e,n,{get:r[n],enumerable:!0})},ce=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ae(r))!ie.call(e,o)&&o!==n&&I(e,o,{get:()=>r[o],enumerable:!(t=se(r,o))||t.enumerable});return e};var ye=e=>ce(I({},"__esModule",{value:!0}),e);var ze={};ue(ze,{RcValidationError:()=>E,defaultProps:()=>l,getWarningOrErrorWithPath:()=>d,isObject:()=>g,parse:()=>y,rc_any:()=>be,rc_array:()=>N,rc_assert_is_valid:()=>De,rc_boolean:()=>je,rc_date:()=>me,rc_default:()=>Ee,rc_disable_loose_array:()=>ve,rc_discriminated_union:()=>$e,rc_enable_obj_strict:()=>M,rc_get_array_item_type:()=>Ke,rc_get_from_key_as_fallback:()=>F,rc_get_obj_schema:()=>U,rc_instanceof:()=>xe,rc_is_valid:()=>ne,rc_literals:()=>we,rc_loose_array:()=>W,rc_loose_parse:()=>We,rc_loose_record:()=>Ae,rc_narrow:()=>Ve,rc_null:()=>he,rc_nullish_default:()=>Se,rc_number:()=>ke,rc_obj_builder:()=>J,rc_obj_extends:()=>V,rc_obj_merge:()=>z,rc_obj_omit:()=>Q,rc_obj_pick:()=>L,rc_obj_strict:()=>D,rc_object:()=>R,rc_parse:()=>$,rc_parse_json:()=>Me,rc_parser:()=>Ne,rc_record:()=>ee,rc_recursive:()=>Fe,rc_string:()=>Oe,rc_transform:()=>oe,rc_tuple:()=>Ie,rc_undefined:()=>_e,rc_union:()=>Pe,rc_unknown:()=>ge,rc_unsafe_transform:()=>Ue,rc_unwrap:()=>Ce,rc_unwrap_or:()=>re,rc_unwrap_or_null:()=>qe,rc_validator:()=>Be,snakeCase:()=>q});module.exports=ye(ze);function F(e,r){return{...r,l:e}}function le(e){return g(e)&&"__rc_type"in e}function k(e){if(le(e))return e;if(g(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=k(t);return R(r)}else if(Array.isArray(e)){let[r,n]=e;switch(r){case"optional":return k(n).optional();case"nullish_or":return k(n).orNullish();case"null_or":return k(n).orNull();case"array":return N(k(n));case"loose_array":return W(k(n))}}throw new Error(`invalid schema: ${e}`)}function R(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=k(o);return{...l,t:n,e:"object",f:!0,u:Object.entries(n),r(t,o){return y(this,t,o,()=>{if(!g(t))return o.s=-1,!1;let s=this.e==="strict_obj"||o.a?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.s=-1;let p=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[f]of this.u)s.has(f)?s.delete(f):p.push(d(o,`Key '${f}' is missing`));for(let f of s)p.push(d(o,`Key '${f}' is not defined in the object shape`));return{data:void 0,errors:p}}let c={},i=[],u=o.n,T=-1;for(let[p,f]of this.u){let h=p;T+=1;let b=`.${p}`,j=`${u}${b}`;o.n=j;let _=t[p],O=p;if(_===void 0&&f.l&&(_=t[f.l],O=f.l),_===void 0&&r==="snake_case"){let x=q(p);_=t[x],O=x}s?.delete(O);let[A,m]=f.r(_,o);if(A)c[h]=m;else{for(let x of m)o.n=j,i.push(x);if(o.o){o.s=T;break}}}if(s&&s.size>0)for(let p of s)o.n=u,i.push(d(o,`Key '${p}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...c}}:{errors:!1,data:c}})}}}function V(e,r){return{...R(e,r),e:"extends_object",b:!0}}function U(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function D(e,r){return{...R(e,r),e:"strict_obj"}}function M(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.a;t.a=!0;let a=e.r(n,t);return t.a=o,a}}}function z(...e){let r={};for(let n of e)Object.assign(r,n.t);return R(r)}function L(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return R(n)}function Q(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 R(n)}function J(){return(e,r)=>R(e,r)}function fe(e){return{...this,g:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function C(e,r){e.T.push(r.startsWith("$")?r:d(e,r))}function X(e,r){r.forEach(n=>C(e,n))}function y(e,r,n,t){if(e.p&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.R&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.g;if(a!==void 0)return C(n,`Fallback used, errors -> ${Z(o,n,e,r)}`),[!0,B(a)?a():a];if(e.j&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(C(n,`Autofixed from error "${Z(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,Y(e,r))]]}function Z(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):Y(n,t)}function Te(e){return{...this,j:!0,h:e}}function pe(e){return{...this,c:e}}function G(){return{...this,p:!0,e:`${this.e}_optional`}}function Y(e,r){return`Type '${P(r,!!e.O)}' is not assignable to '${e.e}'`}function de(){return{...this,R:!0,e:`${this.e}_or_null`}}function Re(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var l={__rc_type:void 0,withFallback:fe,where:pe,optional:G,optionalKey:G,orNullish:Re,withAutofix:Te,orNull:de,_:void 0,g:void 0,c:void 0,p:!1,R:!1,d:!1,j:!1,O:!1,l:void 0,h:void 0,t:void 0,f:!1,b:!1,u:[]},_e={...l,r(e,r){return y(this,e,r,()=>e===void 0)},e:"undefined"},he={...l,r(e,r){return y(this,e,r,()=>e===null)},e:"null"},be={...l,r(e,r){return y(this,e,r,()=>!0)},e:"any"},ge={...l,r(e,r){return y(this,e,r,()=>!0)},e:"unknown"},je={...l,r(e,r){return y(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Oe={...l,r(e,r){return y(this,e,r,()=>typeof e=="string")},e:"string"},ke={...l,r(e,r){return y(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},me={...l,r(e,r){return y(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function xe(e){return{...l,r(r,n){return y(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function we(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...l,r(r,n){return y(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},O:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var H=1;function Pe(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...l,r(r,n){return y(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,c=[],i=0;for(let u of e){i+=1,u.f&&(n.n=`${t}|union ${i}|`);let T=n.o;n.o=!0,n.s=0;let[p,f]=u.r(r,n),h=n.s;if(n.o=T,n.s=0,p)return!0;u.f&&h!==-1?h>0?c.push(...f):(a<H&&o.push(...f),a+=1):s=!0}return n.n=t,c.length>0||o.length>0?((a>H||s)&&o.push(d(n,"not matches any other union member")),{errors:[...c,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Ee(e,r){return{...e,p:!1,d:!1,R:!1,r(t,o){return y(this,t,o,()=>{if(t===void 0)return n();let[a,s]=e.r(t,o);return a?s===void 0?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`};function n(){return{data:B(r)?r():r,errors:!1}}}function Se(e,r){return{...e,p:!1,d:!1,R:!1,r(t,o){return y(this,t,o,()=>{if(t==null)return n();let[a,s]=e.r(t,o);return a?s==null?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`};function n(){return{data:B(r)?r():r,errors:!1}}}function ee(e,{checkKey:r,looseCheck:n}={}){return{...l,e:`record<string, ${e.e}>`,r(t,o){return y(this,t,o,()=>{if(!g(t))return!1;let a={},s=[],c=o.n;for(let[i,u]of Object.entries(t)){let T=`.${i}`,p=`${c}${T}`;if(o.n=p,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let f=t[i],[h,b]=e.r(u,o);if(h)a[i]=f;else{let j=b;for(let _ of j)s.push(_);if(o.o)break}}if(s.length>0)if(n)X(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function $e(e,r){let n={};for(let[t,o]of Object.entries(r))n[t]=R(o);return{...l,e:"discriminated_union",f:!0,r(t,o){return y(this,t,o,()=>{if(!g(t))return o.s=-1,!1;let a=t[e];o.n=`${o.n}.${e}`;let s=n[a];if(!s){let u=P(a,!0);return{errors:[d(o,`Type '${u}' is not a valid discriminator`)],data:void 0}}o.n=`${o.n}|${a}|`;let[c,i]=s.r(t,o);return c?(i[e]=a,{errors:!1,data:i}):{errors:i,data:void 0}})}}}function Ae(e,{checkKey:r}={}){return ee(e,{checkKey:r,looseCheck:!0})}function S(e,r,n,t=!1,o){let a=t&&!n.i&&!n.y,s=o?.unique,c=[],i=[],u=s?new Set:void 0,T=n.n,p=Array.isArray(r),f=-1;for(let h of e){f++;let b=p?r[f]:r,j=`[${f}]`,_=`${T}${j}`;n.n=_;let O=b.r(h,n),[A,m]=O;if(n.n=_,A&&u){let w=m,v=typeof s=="string";v?w=m[s]:typeof s=="function"&&(w=s(m)),u.has(w)?(v&&(n.n=`${T}${j}.${s}`),O=[!1,[d(n,v?`Type '${b.t?.[s]?.e}' with value "${w}" is not unique`:typeof s=="function"?`Type '${b.e}' unique fn return with value "${w}" is not unique`:`${b.e} value is not unique`)]]):u.add(w)}let[x,K]=O;if(x)i.push(K);else if(a){c.push(K);continue}else return{errors:K,data:void 0}}if(c.length>0){if(i.length===0)return{errors:c.slice(0,5).flat(),data:void 0};X(n,c.flat())}return{errors:!1,data:i}}function N(e,r){return{...l,e:`${e.e}[]`,_:e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,t,!1,r):!1)}}}function Ke(e){if(!e._)throw new Error("Type does not have an item type");return e._}function ve(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.y;t.y=!0;let a=e.r(n,t);return t.y=o,a}}}function W(e,r){return{...l,_:e,e:`${e.e}[]`,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,t,!0,r):!1)}}}function Ie(e){return{...l,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return y(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function $(e,r,{noWarnings:n=!1}={}){let t={T:[],n:"",o:!1,s:0,i:n,a:!1,y:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,value:a,warnings:t.T.length>0?t.T:!1}:{ok:!1,error:!0,errors:a}}function Ne(e){return r=>$(r,e)}function We(e,r,n){let t=$(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.value,errors:!1,warnings:t.warnings}}function qe(e){return re(e,null)}function re(e,r){return e.error?{value:r,errors:e.errors,warnings:!1}:{value:e.value,errors:!1,warnings:e.warnings}}var E=class extends Error{constructor(n){super(n.join(`
|
|
2
|
+
`));this.errors=n}};function Ce(e){if(e.error)throw new E(e.errors);return e}function ne(e,r){let n={T:[],n:"",o:!1,s:0,i:!1,a:!1,y:!1};return!!r.r(e,n)[0]}function Be(e){return r=>ne(r,e)}function Fe(e){return{...l,e:"recursive",r(r,n){return e().r(r,n)}}}function te(e,r,n,t){let o=e.n,a=e.o,s=e.a,c=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.a=!0,e.i=!0);let i=r.r(n,e);return e.a=s,e.i=c,e.n=o,e.o=a,i}function oe(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...l,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=te(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);return c?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function Ve(e,r){return oe(e,r)}function Ue(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...l,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=te(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);if(c){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[d(a,u.errors)]:u.errors.map(T=>d(a,T))]}return[!1,[...s||[],...i]]}}}function P(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function De(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function q(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 ${P(e,!0)}`]};let t=JSON.parse(e);return $(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${g(t)?t.message:""}`]}}}function B(e){return typeof e=="function"}0&&(module.exports={RcValidationError,defaultProps,getWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_disable_loose_array,rc_discriminated_union,rc_enable_obj_strict,rc_get_array_item_type,rc_get_from_key_as_fallback,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_narrow,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_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_unwrap,rc_unwrap_or,rc_unwrap_or_null,rc_validator,snakeCase});
|
package/dist/runcheck.d.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
declare function rc_get_from_key_as_fallback<T extends RcType<any>>(fallbackKey: string, type: T): RcType<RcInferType<T>>;
|
|
6
6
|
type RcObject = {
|
|
7
|
-
[key: string]: RcBase<any, any> | RcObject
|
|
7
|
+
[key: string]: RcBase<any, any> | RcObject | [
|
|
8
|
+
'optional' | 'nullish_or' | 'null_or' | 'array' | 'loose_array',
|
|
9
|
+
RcObject
|
|
10
|
+
];
|
|
8
11
|
};
|
|
9
12
|
type TypeOfObjectType<T extends RcObject> = Flatten<AddQuestionMarks<{
|
|
10
13
|
[K in keyof T]: T[K] extends RcType<infer U> ? RequiredKey<U> : T[K] extends RcOptionalKeyType<infer W> ? W : T[K] extends RcObject ? RequiredKey<TypeOfObjectType<T[K]>> : never;
|
|
@@ -39,12 +42,25 @@ declare function rc_obj_merge<A extends AnyObj, B extends AnyObj, C extends AnyO
|
|
|
39
42
|
declare function rc_obj_merge<A extends AnyObj, B extends AnyObj, C extends AnyObj, D extends AnyObj>(...objs: [RcType<A>, RcType<B>, RcType<C>, RcType<D>]): RcType<Extends<Extends<Extends<A, B>, C>, D>>;
|
|
40
43
|
declare function rc_obj_pick<O extends AnyObj, K extends keyof O>(obj: RcType<O>, keys: K[]): RcType<Pick<O, K>>;
|
|
41
44
|
declare function rc_obj_omit<O extends AnyObj, K extends keyof O>(obj: RcType<O>, keys: K[]): RcType<Pick<O, K>>;
|
|
45
|
+
type ExpectedSchema<T> = (t: T) => void;
|
|
42
46
|
type RcTypeWithSquemaEqualTo<T> = {
|
|
43
|
-
__rc_type:
|
|
47
|
+
__rc_type: ExpectedSchema<T>;
|
|
44
48
|
};
|
|
45
|
-
type
|
|
49
|
+
type StrictObjTypeToRcType<T> = {
|
|
46
50
|
[K in keyof T]-?: StricTypeToRcType<T[K]>;
|
|
47
|
-
}
|
|
51
|
+
};
|
|
52
|
+
type StricTypeToRcType<T> = [
|
|
53
|
+
T
|
|
54
|
+
] extends [Record<string, any>[]] ? RcTypeWithSquemaEqualTo<T> | ['array' | 'loose_array', StrictObjTypeToRcType<T[number]>] : [T] extends [any[]] ? RcTypeWithSquemaEqualTo<T> : [T] extends [Record<string, any>] ? StrictObjTypeToRcType<T> | RcTypeWithSquemaEqualTo<T> : [T] extends [Record<string, any> | null] ? [
|
|
55
|
+
'null_or',
|
|
56
|
+
StrictObjTypeToRcType<T>
|
|
57
|
+
] | RcTypeWithSquemaEqualTo<T> : [T] extends [Record<string, any> | undefined] ? [
|
|
58
|
+
'optional',
|
|
59
|
+
StrictObjTypeToRcType<T>
|
|
60
|
+
] | RcTypeWithSquemaEqualTo<T> : [T] extends [Record<string, any> | null | undefined] ? [
|
|
61
|
+
'nullish_or',
|
|
62
|
+
StrictObjTypeToRcType<T>
|
|
63
|
+
] | RcTypeWithSquemaEqualTo<T> : RcTypeWithSquemaEqualTo<T>;
|
|
48
64
|
type StricTypeToRcTypeBase<T extends Record<string, any>> = {
|
|
49
65
|
[K in keyof T]-?: StricTypeToRcType<T[K]>;
|
|
50
66
|
};
|
|
@@ -76,8 +92,9 @@ type InternalParseResult<T> = [success: true, data: T] | [success: false, errors
|
|
|
76
92
|
type WithFallback<T> = (fallback: T | (() => T)) => RcType<T>;
|
|
77
93
|
type RcOptionalKeyType<T> = RcBase<T, true>;
|
|
78
94
|
type RcType<T> = RcBase<T, false>;
|
|
95
|
+
type Schema<T> = (t: T) => void;
|
|
79
96
|
type RcBase<T, RequiredKey extends boolean> = {
|
|
80
|
-
__rc_type:
|
|
97
|
+
__rc_type: Schema<T>;
|
|
81
98
|
readonly withFallback: WithFallback<T>;
|
|
82
99
|
readonly where: (predicate: (input: T) => boolean) => RcType<T>;
|
|
83
100
|
/** RcType | undefined */
|
|
@@ -126,6 +143,11 @@ declare function rc_record<V>(valueType: RcType<V>, { checkKey, looseCheck, }?:
|
|
|
126
143
|
checkKey?: (key: string) => boolean;
|
|
127
144
|
looseCheck?: boolean;
|
|
128
145
|
}): RcType<Record<string, V>>;
|
|
146
|
+
declare function rc_discriminated_union<K extends string, T extends Record<string, RcObject>>(discriminatorKey: K, types: T): RcType<Prettify<{
|
|
147
|
+
[P in keyof T]: {
|
|
148
|
+
[Q in K]: P;
|
|
149
|
+
} & TypeOfObjectType<T[P]>;
|
|
150
|
+
}[keyof T]>>;
|
|
129
151
|
/** instead of returning a general error, rejects invalid keys and returns warnings for these items */
|
|
130
152
|
declare function rc_loose_record<V>(valueType: RcType<V>, { checkKey }?: {
|
|
131
153
|
checkKey?: (key: string) => boolean;
|
|
@@ -217,4 +239,4 @@ type Prettify<T> = T extends Record<string, any> ? {
|
|
|
217
239
|
} : T;
|
|
218
240
|
type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
|
|
219
241
|
|
|
220
|
-
export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, RcValidationError, defaultProps, getWarningOrErrorWithPath, parse, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, rc_disable_loose_array, rc_enable_obj_strict, rc_get_array_item_type, rc_get_from_key_as_fallback, rc_get_obj_shape as rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_loose_record, rc_narrow, 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_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_unsafe_transform, rc_unwrap, rc_unwrap_or, rc_unwrap_or_null, rc_validator };
|
|
242
|
+
export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, RcValidationError, defaultProps, getWarningOrErrorWithPath, parse, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, rc_disable_loose_array, rc_discriminated_union, rc_enable_obj_strict, rc_get_array_item_type, rc_get_from_key_as_fallback, rc_get_obj_shape as rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_loose_record, rc_narrow, 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_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_unsafe_transform, rc_unwrap, rc_unwrap_or, rc_unwrap_or_null, rc_validator };
|
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,Q,R,S,T,U,V,W,X,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,N,O,P,Q,R,S,T,U,V,W,X,Y,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-65CFL2UP.js";export{N as RcValidationError,m as defaultProps,k as getWarningOrErrorWithPath,W as isObject,l as parse,p as rc_any,D as rc_array,V as rc_assert_is_valid,r as rc_boolean,u as rc_date,y as rc_default,F as rc_disable_loose_array,B as rc_discriminated_union,f as rc_enable_obj_strict,E as rc_get_array_item_type,a as rc_get_from_key_as_fallback,d as rc_get_obj_schema,v as rc_instanceof,P as rc_is_valid,w as rc_literals,G as rc_loose_array,K as rc_loose_parse,C as rc_loose_record,T as rc_narrow,o as rc_null,z as rc_nullish_default,t as rc_number,j as rc_obj_builder,c as rc_obj_extends,g as rc_obj_merge,i as rc_obj_omit,h as rc_obj_pick,e as rc_obj_strict,b as rc_object,I as rc_parse,Y as rc_parse_json,J as rc_parser,A as rc_record,R as rc_recursive,s as rc_string,S as rc_transform,H as rc_tuple,n as rc_undefined,x as rc_union,q as rc_unknown,U as rc_unsafe_transform,O as rc_unwrap,M as rc_unwrap_or,L as rc_unwrap_or_null,Q as rc_validator,X 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.
|
|
4
|
+
"version": "0.54.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"eslint": "^8.37.0",
|
|
43
43
|
"eslint-plugin-vitest": "^0.0.57",
|
|
44
44
|
"mitata": "^0.1.6",
|
|
45
|
+
"prettier": "4.0.0-alpha.3",
|
|
45
46
|
"tsm": "^2.3.0",
|
|
46
47
|
"tsup": "^6.7.0",
|
|
47
48
|
"typescript": "^5.0.3",
|
|
48
49
|
"v8-profiler-next": "^1.9.0",
|
|
49
50
|
"vite": "^4.3.9",
|
|
50
51
|
"vitest": "1.0.0-beta.3",
|
|
51
|
-
"zod": "^3.
|
|
52
|
+
"zod": "^3.22.4"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
55
|
"test": "vitest --ui",
|
package/dist/chunk-BBFBYV3C.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function D(e,r){return{...r,l:e}}function M(e){return m(e)&&"__rc_type"in e}function N(e){if(M(e))return e;if(m(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=N(t);return b(r)}throw new Error(`invalid schema: ${e}`)}function b(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=N(o);return{...y,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return l(this,t,o,()=>{if(!m(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let p=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[f]of this.u)s.has(f)?s.delete(f):p.push(d(o,`Key '${f}' is missing`));for(let f of s)p.push(d(o,`Key '${f}' is not defined in the object shape`));return{data:void 0,errors:p}}let c={},i=[],u=o.n,T=-1;for(let[p,f]of this.u){let _=p;T+=1;let h=`.${p}`,g=`${u}${h}`;o.n=g;let R=t[p],j=p;if(R===void 0&&f.l&&(R=t[f.l],j=f.l),R===void 0&&r==="snake_case"){let O=W(p);R=t[O],j=O}s?.delete(j);let[E,k]=f.r(R,o);if(E)c[_]=k;else{for(let O of k)o.n=g,i.push(O);if(o.o){o.a=T;break}}}if(s&&s.size>0)for(let p of s)o.n=u,i.push(d(o,`Key '${p}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...c}}:{errors:!1,data:c}})}}}function z(e,r){return{...b(e,r),e:"extends_object",b:!0}}function L(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function Q(e,r){return{...b(e,r),e:"strict_obj"}}function J(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function Z(...e){let r={};for(let n of e)Object.assign(r,n.t);return b(r)}function G(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return b(n)}function H(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 b(n)}function X(){return(e,r)=>b(e,r)}function Y(e){return{...this,g:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function S(e,r){e.y.push(r.startsWith("$")?r:d(e,r))}function F(e,r){r.forEach(n=>S(e,n))}function l(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.g;if(a!==void 0)return S(n,`Fallback used, errors -> ${q(o,n,e,r)}`),[!0,v(a)?a():a];if(e.j&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(S(n,`Autofixed from error "${q(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,U(e,r))]]}function q(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):U(n,t)}function ee(e){return{...this,j:!0,h:e}}function re(e){return{...this,c:e}}function C(){return{...this,T:!0}}function U(e,r){return`Type '${w(r,!!e.k)}' is not assignable to '${e.e}'`}function ne(){return{...this,p:!0,e:`${this.e}_or_null`}}function te(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var y={__rc_type:void 0,withFallback:Y,where:re,optional:C,optionalKey:C,orNullish:te,withAutofix:ee,orNull:ne,R:void 0,g:void 0,c:void 0,T:!1,p:!1,d:!1,j:!1,k:!1,l:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},de={...y,r(e,r){return l(this,e,r,()=>e===void 0)},e:"undefined"},Re={...y,r(e,r){return l(this,e,r,()=>e===null)},e:"null"},_e={...y,r(e,r){return l(this,e,r,()=>!0)},e:"any"},he={...y,r(e,r){return l(this,e,r,()=>!0)},e:"unknown"},be={...y,r(e,r){return l(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ge={...y,r(e,r){return l(this,e,r,()=>typeof e=="string")},e:"string"},je={...y,r(e,r){return l(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ke={...y,r(e,r){return l(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function Oe(e){return{...y,r(r,n){return l(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function xe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...y,r(r,n){return l(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var B=1;function me(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...y,r(r,n){return l(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,c=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let T=n.o;n.o=!0,n.a=0;let[p,f]=u.r(r,n),_=n.a;if(n.o=T,n.a=0,p)return!0;u._&&_!==-1?_>0?c.push(...f):(a<B&&o.push(...f),a+=1):s=!0}return n.n=t,c.length>0||o.length>0?((a>B||s)&&o.push(d(n,"not matches any other union member")),{errors:[...c,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function we(e,r){return{...e,T:!1,d:!1,p:!1,r(t,o){return l(this,t,o,()=>{if(t===void 0)return n();let[a,s]=e.r(t,o);return a?s===void 0?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`};function n(){return{data:v(r)?r():r,errors:!1}}}function Pe(e,r){return{...e,T:!1,d:!1,p:!1,r(t,o){return l(this,t,o,()=>{if(t==null)return n();let[a,s]=e.r(t,o);return a?s==null?n():{data:s,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`};function n(){return{data:v(r)?r():r,errors:!1}}}function oe(e,{checkKey:r,looseCheck:n}={}){return{...y,e:`record<string, ${e.e}>`,r(t,o){return l(this,t,o,()=>{if(!m(t))return!1;let a={},s=[],c=o.n;for(let[i,u]of Object.entries(t)){let T=`.${i}`,p=`${c}${T}`;if(o.n=p,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let f=t[i],[_,h]=e.r(u,o);if(_)a[i]=f;else{let g=h;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)F(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function Ee(e,{checkKey:r}={}){return oe(e,{checkKey:r,looseCheck:!0})}function P(e,r,n,t=!1,o){let a=t&&!n.i&&!n.f,s=o?.unique,c=[],i=[],u=s?new Set:void 0,T=n.n,p=Array.isArray(r),f=-1;for(let _ of e){f++;let h=p?r[f]:r,g=`[${f}]`,R=`${T}${g}`;n.n=R;let j=h.r(_,n),[E,k]=j;if(n.n=R,E&&u){let x=k,A=typeof s=="string";A?x=k[s]:typeof s=="function"&&(x=s(k)),u.has(x)?(A&&(n.n=`${T}${g}.${s}`),j=[!1,[d(n,A?`Type '${h.t?.[s]?.e}' with value "${x}" is not unique`:typeof s=="function"?`Type '${h.e}' unique fn return with value "${x}" is not unique`:`${h.e} value is not unique`)]]):u.add(x)}let[O,$]=j;if(O)i.push($);else if(a){c.push($);continue}else return{errors:$,data:void 0}}if(c.length>0){if(i.length===0)return{errors:c.slice(0,5).flat(),data:void 0};F(n,c.flat())}return{errors:!1,data:i}}function $e(e,r){return{...y,e:`${e.e}[]`,R:e,r(n,t){return l(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1,r):!1)}}}function Ae(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function Se(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return l(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.f;t.f=!0;let a=e.r(n,t);return t.f=o,a}}}function Ke(e,r){return{...y,R:e,e:`${e.e}[]`,r(n,t){return l(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!0,r):!1)}}}function Ie(e){return{...y,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return l(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:P.call(this,r,e,n))}}}function I(e,r,{noWarnings:n=!1}={}){let t={y:[],n:"",o:!1,a:0,i:n,s:!1,f:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,value:a,warnings:t.y.length>0?t.y:!1}:{ok:!1,error:!0,errors:a}}function ve(e){return r=>I(r,e)}function Ne(e,r,n){let t=I(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.value,errors:!1,warnings:t.warnings}}function We(e){return se(e,null)}function se(e,r){return e.error?{value:r,errors:e.errors,warnings:!1}:{value:e.value,errors:!1,warnings:e.warnings}}var K=class extends Error{constructor(n){super(n.join(`
|
|
2
|
-
`));this.errors=n}};function qe(e){if(e.error)throw new K(e.errors);return e}function ae(e,r){let n={y:[],n:"",o:!1,a:0,i:!1,s:!1,f:!1};return!!r.r(e,n)[0]}function Ce(e){return r=>ae(r,e)}function Be(e){return{...y,e:"recursive",r(r,n){return e().r(r,n)}}}function V(e,r,n,t){let o=e.n,a=e.o,s=e.s,c=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.s=!0,e.i=!0);let i=r.r(n,e);return e.s=s,e.i=c,e.n=o,e.o=a,i}function ie(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=V(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);return c?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function Fe(e,r){return ie(e,r)}function Ue(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,T]=V(a,n,o,t);if(u)return[!0,T];s=T}let[c,i]=e.r(o,a);if(c){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[d(a,u.errors)]:u.errors.map(T=>d(a,T))]}return[!1,[...s||[],...i]]}}}function w(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Ve(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 W(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function De(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 I(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${m(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}export{D as a,b,z as c,L as d,Q as e,J as f,Z as g,G as h,H as i,X as j,d as k,l,y as m,de as n,Re as o,_e as p,he as q,be as r,ge as s,je as t,ke as u,Oe as v,xe as w,me as x,we as y,Pe as z,oe as A,Ee as B,$e as C,Ae as D,Se as E,Ke as F,Ie as G,I as H,ve as I,Ne as J,We as K,se as L,K as M,qe as N,ae as O,Ce as P,Be as Q,ie as R,Fe as S,Ue as T,Ve as U,m as V,W,De as X};
|