runcheck 0.42.0 → 0.44.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-FXQPJI45.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +17 -10
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-PJTM2QW6.js +0 -1
package/dist/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var R=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})},P=(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=R(r,t))||o.enumerable});return e};var w=e=>P(f({},"__esModule",{value:!0}),e);var W={};m(W,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>S,rc_string_autofix:()=>I});module.exports=w(W);function k(e){return{...this,j:e}}function u(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function c(e,r){e.l.push(r.startsWith("$")?r:u(e,r))}function s(e,r,n,o){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 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.j;if(i!==void 0)return c(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,O(i)?i():i];if(e.g&&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,g:!0,h:e}}function $(e){return{...this,c:e}}function d(){return{...this,T:!0}}function T(e,r){return`Type '${j(r,!!e.k)}' is not assignable to '${e.e}'`}function E(){return{...this,p:!0,e:`${this.e}_or_null`}}function N(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var a={__rc_type:void 0,withFallback:k,where:$,optional:d,optionalKey:d,orNullish:N,withAutofix:x,orNull:E,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,y:void 0,h:void 0,t:void 0,_:!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"},q={...a,r(e,r){return s(this,e,r,()=>!0)},e:"any"},V={...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"},h={...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 j(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 O(e){return typeof e=="function"}var A=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),I=_.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),S=h.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{q as f,r as t,s as o}from"./chunk-
|
|
1
|
+
import{q as f,r as t,s as o}from"./chunk-FXQPJI45.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 V(e,r){return{...r,y:e}}function D(e){return x(e)&&"__rc_type"in e}function W(e){if(D(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(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]=W(o);return{...f,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return y(this,t,o,()=>{if(!x(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 c=[];if(o.o)return{data:void 0,errors:[p(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[T]of this.u)s.has(T)?s.delete(T):c.push(p(o,`Key '${T}' is missing`));for(let T of s)c.push(p(o,`Key '${T}' is not defined in the object shape`));return{data:void 0,errors:c}}let l={},i=[],u=o.n,d=-1;for(let[c,T]of this.u){let h=c;d+=1;let g=`.${c}`,j=`${u}${g}`;o.n=j;let R,k=c;if(T.y&&(R=t[T.y],k=T.y),R===void 0&&(R=t[c],k=c),R===void 0&&r==="snake_case"){let O=v(c);R=t[O],k=O}s?.delete(k);let[P,_]=T.r(R,o);if(P)l[h]=_;else{for(let O of _)o.n=j,i.push(O);if(o.o){o.a=d;break}}}if(s&&s.size>0)for(let c of s)o.n=u,i.push(p(o,`Key '${c}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...l}}:{errors:!1,data:l}})}}}function M(e,r){return{...b(e,r),e:"extends_object",b:!0}}function z(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function L(e,r){return{...b(e,r),e:"strict_obj"}}function Q(...e){let r={};for(let n of e)Object.assign(r,n.t);return b(r)}function J(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return b(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 b(n)}function G(){return(e,r)=>b(e,r)}function H(e){return{...this,j:e}}function p(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function K(e,r){e.l.push(r.startsWith("$")?r:p(e,r))}function B(e,r){r.forEach(n=>K(e,n))}function y(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,[p(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return K(n,`Fallback used, errors -> ${N(o,n,e,r)}`),[!0,I(a)?a():a];if(e.g&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[p(n,`Predicate failed for autofix in type '${e.e}'`)]]:(K(n,`Autofixed from error "${N(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[p(n,F(e,r))]]}function N(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):F(n,t)}function X(e){return{...this,g:!0,h:e}}function Y(e){return{...this,c:e}}function C(){return{...this,T:!0}}function F(e,r){return`Type '${w(r,!!e.k)}' is not assignable to '${e.e}'`}function ee(){return{...this,p:!0,e:`${this.e}_or_null`}}function re(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var f={__rc_type:void 0,withFallback:H,where:Y,optional:C,optionalKey:C,orNullish:re,withAutofix:X,orNull:ee,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,y:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},fe={...f,r(e,r){return y(this,e,r,()=>e===void 0)},e:"undefined"},le={...f,r(e,r){return y(this,e,r,()=>e===null)},e:"null"},Te={...f,r(e,r){return y(this,e,r,()=>!0)},e:"any"},de={...f,r(e,r){return y(this,e,r,()=>!0)},e:"unknown"},pe={...f,r(e,r){return y(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Re={...f,r(e,r){return y(this,e,r,()=>typeof e=="string")},e:"string"},he={...f,r(e,r){return y(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...f,r(e,r){return y(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...f,r(r,n){return y(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function je(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...f,r(r,n){return y(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 q=1;function ge(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...f,r(r,n){return y(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,l=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let d=n.o;n.o=!0,n.a=0;let[c,T]=u.r(r,n),h=n.a;if(n.o=d,n.a=0,c)return!0;u._&&h!==-1?h>0?l.push(...T):(a<q&&o.push(...T),a+=1):s=!0}return n.n=t,l.length>0||o.length>0?((a>q||s)&&o.push(p(n,"not matches any other union member")),{errors:[...l,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ke(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function Oe(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function ne(e,{checkKey:r,looseCheck:n}={}){return{...f,e:`record<string, ${e.e}>`,r(t,o){return y(this,t,o,()=>{if(!x(t))return!1;let a={},s=[],l=o.n;for(let[i,u]of Object.entries(t)){let d=`.${i}`,c=`${l}${d}`;if(o.n=c,r&&!r(i)){s.push(p(o,`Key '${i}' is not allowed`));continue}let T=t[i],[h,g]=e.r(u,o);if(h)a[i]=T;else{let j=g;for(let R of j)s.push(R);if(o.o)break}}if(s.length>0)if(n)B(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function me(e,{checkKey:r}={}){return ne(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let a=t&&!n.i&&!n.f,s=[],l=[],i=new Set,u=n.n,d=Array.isArray(r),c=-1;for(let T of e){c++;let h=d?r[c]:r,g=`[${c}]`,j=`${u}${g}`;n.n=j;let R=h.r(T,n),[k,P]=R;n.n=j;let _=o?.unique;if(k&&_){let m=P,A=typeof _=="string";A?m=P[_]:typeof _=="function"&&(m=_(P)),i.has(m)?(A&&(n.n=`${u}${g}.${_}`),R=[!1,[p(n,A?`Type '${h.t?.[_]?.e}' with value "${m}" is not unique`:typeof _=="function"?`Type '${h.e}' unique fn return with value "${m}" is not unique`:`${h.e} value is not unique`)]]):i.add(m)}let[O,$]=R;if(O)l.push($);else if(a){s.push($);continue}else return{errors:$,data:void 0}}if(s.length>0){if(l.length===0)return{errors:s.slice(0,5).flat(),data:void 0};B(n,s.flat())}return{errors:!1,data:l}}function xe(e,r){return{...f,e:`${e.e}[]`,R: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 Pe(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}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.f;t.f=!0;let a=e.r(n,t);return t.f=o,a}}}function Ee(e,r){return{...f,R: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 $e(e){return{...f,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 S(e,r,{noWarnings:n=!1}={}){let t={l:[],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,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ae(e){return r=>S(r,e)}function Ke(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 te(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,f:!1};return!!r.r(e,n)[0]}function Se(e){return r=>te(r,e)}function Ie(e){return{...f,e:"recursive",r(r,n){return e().r(r,n)}}}function U(e,r,n,t){let o=e.n,a=e.o,s=e.s,l=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=l,e.n=o,e.o=a,i}function We(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=U(a,n,o,t);if(u)return[!0,d];s=d}let[l,i]=e.r(o,a);return l?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function ve(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=U(a,n,o,t);if(u)return[!0,d];s=d}let[l,i]=e.r(o,a);if(l){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[p(a,u.errors)]:u.errors.map(d=>p(a,d))]}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 Ne(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ce(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 parsing error: ${x(t)?t.message:""}`]}}}function I(e){return typeof e=="function"}export{V as a,b,M as c,z as d,L as e,Q as f,J as g,Z as h,G as i,p as j,y as k,f as l,fe as m,le as n,Te as o,de as p,pe as q,Re as r,he as s,_e as t,be as u,je as v,ge as w,ke as x,Oe as y,ne as z,me as A,xe as B,Pe as C,we as D,Ee as E,$e as F,S as G,Ae as H,Ke as I,te as J,Se as K,Ie as L,We as M,ve as N,Ne as O,x as P,v as Q,Ce as R};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ee(r))!re.call(e,s)&&s!==n&&K(e,s,{get:()=>r[s],enumerable:!(t=Y(r,s))||t.enumerable});return e};var se=e=>te(K({},"__esModule",{value:!0}),e);var ve={};ne(ve,{defaultProps:()=>c,gerWarningOrErrorWithPath:()=>b,isObject:()=>x,parse:()=>u,rc_any:()=>le,rc_array:()=>xe,rc_assert_is_valid:()=>Ie,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>ge,rc_get_obj_schema:()=>F,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>he,rc_loose_array:()=>me,rc_loose_parse:()=>$e,rc_loose_record:()=>ke,rc_null:()=>fe,rc_nullish_default:()=>Oe,rc_number:()=>Re,rc_obj_builder:()=>M,rc_obj_extends:()=>B,rc_obj_merge:()=>U,rc_obj_omit:()=>D,rc_obj_pick:()=>V,rc_obj_strict:()=>S,rc_object:()=>j,rc_parse:()=>$,rc_parse_json:()=>Ne,rc_parser:()=>Ae,rc_record:()=>G,rc_recursive:()=>Ke,rc_rename_from_key:()=>C,rc_string:()=>de,rc_transform:()=>Se,rc_tuple:()=>we,rc_undefined:()=>ye,rc_union:()=>je,rc_unknown:()=>Te,rc_unsafe_transform:()=>Ee,rc_validator:()=>Pe,snakeCase:()=>E});module.exports=se(ve);function C(e,r){return{...r,i:e}}function q(e){return x(e)&&"__rc_type"in e}function W(e){if(q(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=W(s);return{...c,t:n,e:"object",T:!0,c:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!x(t))return s.o=-1,!1;let a=this.e==="strict_obj"?new Set(Object.keys(t)):void 0;if(a&&this.c.length!==a.size){for(let[f]of this.c)a.delete(f);s.o=-1;let l=[];for(let f of a)l.push(`Key '${f}' is not defined in the object shape`);return{data:void 0,errors:l}}let y={},i=[],T=s.n,p=-1;for(let[l,f]of this.c){let h=l;p+=1;let m=`.${l}`,g=`${T}${m}`;s.n=g;let d,O=l;if(f.i&&(d=t[f.i],O=f.i),d===void 0&&(d=t[l],O=l),d===void 0&&r==="snake_case"){let k=E(l);d=t[k],O=k}a?.delete(O);let[R,w]=f.r(d,s);if(R)y[h]=w;else{for(let k of w)s.n=g,i.push(b(s,k));if(s.s){s.o=p;break}}}if(a&&a.size>0)for(let l of a)i.push(`Key '${l}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.d?{errors:!1,data:{...t,...y}}:{errors:!1,data:y}})}}}function B(e,r){return{...j(e,r),e:"extends_object",d:!0}}function F(e){return e.t}function S(e,r){let n=(()=>{if(q(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?S(o,r):o;return t}}return e})();return{...j(n,r),e:"strict_obj"}}function U(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function V(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.t[t];s&&(n[t]=s)}return j(n)}function D(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return j(n)}function M(){return(e,r)=>j(e,r)}function oe(e){return{...this,R:e}}function b(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function I(e,r){e.u.push(b(e,r))}function L(e,r){r.forEach(n=>I(e,n))}function u(e,r,n,t){if(e.y&&r===void 0)return[!0,r];if(e.f&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return I(n,`Fallback used, errors -> ${z(s,n,e,r)}`),[!0,v(o)?o():o];if(e.b&&e.p){let a=e.p(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(I(n,`Autofixed from error "${z(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[b(n,Z(e,r))]]}function z(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):Z(n,t)}function ae(e){return{...this,b:!0,p:e}}function ie(e){return{...this,a:e}}function Q(){return{...this,y:!0}}function Z(e,r){return`Type '${A(r,!!e.h)}' is not assignable to '${e.e}'`}function ce(){return{...this,l:!0,e:`${this.e}_or_null`}}function ue(){return{...this,f:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:oe,where:ie,optional:Q,optionalKey:Q,orNullish:ue,withAutofix:ae,orNull:ce,R:void 0,a:void 0,y:!1,l:!1,f:!1,b:!1,h:!1,i:void 0,p:void 0,j:void 0,t:void 0,T:!1,d:!1,c:[]},ye={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},fe={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Te={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function he(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?A(e[0],!0):e.map(r=>A(r,!0)).join(" | ")}}var J=1;function je(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,y=[],i=0;for(let T of e){i+=1,T.T&&(n.n=`${t}|union ${i}|`);let p=n.s;n.s=!0,n.o=0;let[l,f]=T.r(r,n),h=n.o;if(n.s=p,n.o=0,l)return!0;T.T&&h!==-1?h>0?y.push(...f):(o<J&&s.push(...f),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>J||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ge(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function Oe(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function G(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!x(t))return!1;let o={},a=[],y=s.n;for(let[i,T]of Object.entries(t)){let p=`.${i}`,l=`${y}${p}`;if(s.n=l,r&&!r(i)){a.push(b(s,`Key '${i}' is not allowed`));continue}let f=t[i],[h,m]=e.r(T,s);if(h)o[i]=f;else{let g=m;for(let d of g)a.push(b(s,d));if(s.s)break}}if(a.length>0)if(n)L(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ke(e,{checkKey:r}={}){return G(e,{checkKey:r,looseCheck:!0})}function N(e,r,n,t=!1,s){let o=[],a=[],y=new Set,i=n.n,T=Array.isArray(r),p=-1;for(let l of e){p++;let f=T?r[p]:r,h=`[${p}]`,m=`${i}${h}`;n.n=m;let g=f.r(l,n),[d,O]=g;n.n=m;let R=s?.unique;if(d&&R){let _=O,P=typeof R=="string";P?_=O[R]:typeof R=="function"&&(_=R(O)),y.has(_)?(P&&(n.n=`${i}${h}.${R}`),g=[!1,[b(n,P?`Type '${f.t?.[R]?.e}' with value "${_}" is not unique`:typeof R=="function"?`Type '${f.e}' unique fn return with value "${_}" is not unique`:`${f.e} value is not unique`)]]):y.add(_)}let[w,k]=g;if(w)a.push(k);else if(t){o.push(k.map(_=>b(n,_)));continue}else return{errors:k.map(_=>b(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};L(n,o.flat())}return{errors:!1,data:a}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!1,r):!1)}}}function me(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!0,r):!1)}}}function we(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:N.call(this,r,e,n))}}}function $(e,r,{noWarnings:n=!1}={}){let t={u:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.u.length>0?t.u:!1}:{ok:!1,error:!0,errors:o}}function Ae(e){return r=>$(r,e)}function $e(e,r,n){let t=$(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function H(e,r){let n={u:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function Pe(e){return r=>H(r,e)}function Ke(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function X(e,r,n){let t=e.n,s=e.s;e.s=!0,e.n=`${t}|output|`;let o=r.r(n,e);return e.n=t,e.s=s,o}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=X(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);return a?[!0,r(y,e)]:[!1,[...o||[],...y]]}}}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=X(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);if(a){let i=r(y,e);return i.ok?[!0,i.data]:[!1,typeof i.errors=="string"?[i.errors]:i.errors]}return[!1,[...o||[],...y]]}}}function A(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function Ie(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ne(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${A(e,!0)}`]};let t=JSON.parse(e);return $(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${x(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,gerWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
|
|
1
|
+
"use strict";var S=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,r)=>{for(var n in r)S(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ee(r))!re.call(e,o)&&o!==n&&S(e,o,{get:()=>r[o],enumerable:!(t=Y(r,o))||t.enumerable});return e};var oe=e=>te(S({},"__esModule",{value:!0}),e);var qe={};ne(qe,{defaultProps:()=>y,getWarningOrErrorWithPath:()=>p,isObject:()=>g,parse:()=>c,rc_any:()=>Te,rc_array:()=>xe,rc_assert_is_valid:()=>Ne,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>ke,rc_disable_loose_array:()=>we,rc_get_array_item_type:()=>Pe,rc_get_obj_schema:()=>B,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>je,rc_loose_array:()=>Ee,rc_loose_parse:()=>Ke,rc_loose_record:()=>me,rc_null:()=>le,rc_nullish_default:()=>Oe,rc_number:()=>he,rc_obj_builder:()=>M,rc_obj_extends:()=>q,rc_obj_merge:()=>U,rc_obj_omit:()=>D,rc_obj_pick:()=>V,rc_obj_strict:()=>F,rc_object:()=>b,rc_parse:()=>$,rc_parse_json:()=>Ce,rc_parser:()=>Ae,rc_record:()=>G,rc_recursive:()=>Ie,rc_rename_from_key:()=>N,rc_string:()=>Re,rc_transform:()=>We,rc_tuple:()=>$e,rc_undefined:()=>fe,rc_union:()=>ge,rc_unknown:()=>de,rc_unsafe_transform:()=>ve,rc_validator:()=>Se,snakeCase:()=>I});module.exports=oe(qe);function N(e,r){return{...r,f:e}}function se(e){return g(e)&&"__rc_type"in e}function C(e){if(se(e))return e;if(g(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=C(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]=C(o);return{...y,t:n,e:"object",h:!0,u:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!g(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 f=[];if(o.o)return{data:void 0,errors:[p(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[T]of this.u)s.has(T)?s.delete(T):f.push(p(o,`Key '${T}' is missing`));for(let T of s)f.push(p(o,`Key '${T}' is not defined in the object shape`));return{data:void 0,errors:f}}let l={},i=[],u=o.n,d=-1;for(let[f,T]of this.u){let h=f;d+=1;let k=`.${f}`,j=`${u}${k}`;o.n=j;let R,O=f;if(T.f&&(R=t[T.f],O=T.f),R===void 0&&(R=t[f],O=f),R===void 0&&r==="snake_case"){let m=I(f);R=t[m],O=m}s?.delete(O);let[P,_]=T.r(R,o);if(P)l[h]=_;else{for(let m of _)o.n=j,i.push(m);if(o.o){o.a=d;break}}}if(s&&s.size>0)for(let f of s)o.n=u,i.push(p(o,`Key '${f}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...l}}:{errors:!1,data:l}})}}}function q(e,r){return{...b(e,r),e:"extends_object",b:!0}}function B(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function F(e,r){return{...b(e,r),e:"strict_obj"}}function U(...e){let r={};for(let n of e)Object.assign(r,n.t);return b(r)}function V(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return b(n)}function D(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return b(n)}function M(){return(e,r)=>b(e,r)}function ae(e){return{...this,j:e}}function p(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function W(e,r){e.l.push(r.startsWith("$")?r:p(e,r))}function J(e,r){r.forEach(n=>W(e,n))}function c(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,[p(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return W(n,`Fallback used, errors -> ${z(o,n,e,r)}`),[!0,v(a)?a():a];if(e.g&&e._){let s=e._(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[p(n,`Predicate failed for autofix in type '${e.e}'`)]]:(W(n,`Autofixed from error "${z(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[p(n,Z(e,r))]]}function z(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):Z(n,t)}function ie(e){return{...this,g:!0,_:e}}function ue(e){return{...this,c:e}}function L(){return{...this,T:!0}}function Z(e,r){return`Type '${w(r,!!e.k)}' is not assignable to '${e.e}'`}function ce(){return{...this,p:!0,e:`${this.e}_or_null`}}function ye(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var y={__rc_type:void 0,withFallback:ae,where:ue,optional:L,optionalKey:L,orNullish:ye,withAutofix:ie,orNull:ce,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,f:void 0,_:void 0,t:void 0,h:!1,b:!1,u:[]},fe={...y,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},le={...y,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},Te={...y,r(e,r){return c(this,e,r,()=>!0)},e:"any"},de={...y,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},pe={...y,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Re={...y,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},he={...y,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...y,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...y,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function je(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...y,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?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var Q=1;function ge(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...y,r(r,n){return c(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,l=[],i=0;for(let u of e){i+=1,u.h&&(n.n=`${t}|union ${i}|`);let d=n.o;n.o=!0,n.a=0;let[f,T]=u.r(r,n),h=n.a;if(n.o=d,n.a=0,f)return!0;u.h&&h!==-1?h>0?l.push(...T):(a<Q&&o.push(...T),a+=1):s=!0}return n.n=t,l.length>0||o.length>0?((a>Q||s)&&o.push(p(n,"not matches any other union member")),{errors:[...l,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ke(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function Oe(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function G(e,{checkKey:r,looseCheck:n}={}){return{...y,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!g(t))return!1;let a={},s=[],l=o.n;for(let[i,u]of Object.entries(t)){let d=`.${i}`,f=`${l}${d}`;if(o.n=f,r&&!r(i)){s.push(p(o,`Key '${i}' is not allowed`));continue}let T=t[i],[h,k]=e.r(u,o);if(h)a[i]=T;else{let j=k;for(let R of j)s.push(R);if(o.o)break}}if(s.length>0)if(n)J(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function me(e,{checkKey:r}={}){return G(e,{checkKey:r,looseCheck:!0})}function E(e,r,n,t=!1,o){let a=t&&!n.i&&!n.y,s=[],l=[],i=new Set,u=n.n,d=Array.isArray(r),f=-1;for(let T of e){f++;let h=d?r[f]:r,k=`[${f}]`,j=`${u}${k}`;n.n=j;let R=h.r(T,n),[O,P]=R;n.n=j;let _=o?.unique;if(O&&_){let x=P,K=typeof _=="string";K?x=P[_]:typeof _=="function"&&(x=_(P)),i.has(x)?(K&&(n.n=`${u}${k}.${_}`),R=[!1,[p(n,K?`Type '${h.t?.[_]?.e}' with value "${x}" is not unique`:typeof _=="function"?`Type '${h.e}' unique fn return with value "${x}" is not unique`:`${h.e} value is not unique`)]]):i.add(x)}let[m,A]=R;if(m)l.push(A);else if(a){s.push(A);continue}else return{errors:A,data:void 0}}if(s.length>0){if(l.length===0)return{errors:s.slice(0,5).flat(),data:void 0};J(n,s.flat())}return{errors:!1,data:l}}function xe(e,r){return{...y,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 Pe(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}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 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.y;t.y=!0;let a=e.r(n,t);return t.y=o,a}}}function Ee(e,r){return{...y,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 $e(e){return{...y,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={l:[],n:"",o:!1,a:0,i:n,s:!1,y:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ae(e){return r=>$(r,e)}function Ke(e,r,n){let t=$(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function H(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,y:!1};return!!r.r(e,n)[0]}function Se(e){return r=>H(r,e)}function Ie(e){return{...y,e:"recursive",r(r,n){return e().r(r,n)}}}function X(e,r,n,t){let o=e.n,a=e.o,s=e.s,l=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=l,e.n=o,e.o=a,i}function We(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=X(a,n,o,t);if(u)return[!0,d];s=d}let[l,i]=e.r(o,a);return l?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function ve(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=X(a,n,o,t);if(u)return[!0,d];s=d}let[l,i]=e.r(o,a);if(l){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[p(a,u.errors)]:u.errors.map(d=>p(a,d))]}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 Ne(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 I(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ce(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 parsing error: ${g(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,getWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_disable_loose_array,rc_get_array_item_type,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
|
package/dist/runcheck.d.ts
CHANGED
|
@@ -22,11 +22,8 @@ type ObjOptions = {
|
|
|
22
22
|
};
|
|
23
23
|
declare function rc_object<T extends RcObject>(shape: T, { normalizeKeysFrom }?: ObjOptions): RcObjTypeReturn<T>;
|
|
24
24
|
declare function rc_obj_extends<T extends RcObject>(shape: T, options?: ObjOptions): RcObjTypeReturn<T>;
|
|
25
|
-
declare function
|
|
25
|
+
declare function rc_get_obj_shape<T extends RcObject>(type: RcObjTypeReturn<T>): T;
|
|
26
26
|
/** return an error if the obj has more keys than the expected type */
|
|
27
|
-
declare function rc_obj_strict<T extends AnyObj>(shape: RcType<T>, options?: ObjOptions & {
|
|
28
|
-
nonRecursive?: boolean;
|
|
29
|
-
}): RcType<T>;
|
|
30
27
|
declare function rc_obj_strict<T extends RcObject>(shape: T, options?: ObjOptions): RcObjTypeReturn<T>;
|
|
31
28
|
type AnyObj = Record<string, unknown>;
|
|
32
29
|
type Extends<T extends AnyObj, W extends AnyObj> = Omit<T, keyof W> & W;
|
|
@@ -56,9 +53,11 @@ type ParseResultCtx = {
|
|
|
56
53
|
path_: string;
|
|
57
54
|
objErrShortCircuit_: boolean;
|
|
58
55
|
objErrKeyIndex_: number;
|
|
56
|
+
strictObj_: boolean;
|
|
59
57
|
noWarnings_: boolean;
|
|
58
|
+
noLooseArray_: boolean;
|
|
60
59
|
};
|
|
61
|
-
type InternalParseResult<T> = [success: true, data: T] | [success: false, errors:
|
|
60
|
+
type InternalParseResult<T> = [success: true, data: T] | [success: false, errors: ErrorWithPath[]];
|
|
62
61
|
type WithFallback<T> = (fallback: T | (() => T)) => RcType<T>;
|
|
63
62
|
type RcOptionalKeyType<T> = RcBase<T, true>;
|
|
64
63
|
type RcType<T> = RcBase<T, false>;
|
|
@@ -79,13 +78,16 @@ type RcBase<T, RequiredKey extends boolean> = {
|
|
|
79
78
|
}) => RcType<T>;
|
|
80
79
|
readonly _optional_key_?: RequiredKey;
|
|
81
80
|
};
|
|
82
|
-
|
|
81
|
+
type ErrorWithouPath = string & {
|
|
82
|
+
__withPath?: never;
|
|
83
|
+
};
|
|
84
|
+
declare function getWarningOrErrorWithPath(ctx: ParseResultCtx, message: ErrorWithouPath): ErrorWithPath;
|
|
83
85
|
type IsValid<T> = boolean | {
|
|
84
86
|
data: T;
|
|
85
87
|
errors: false;
|
|
86
88
|
} | {
|
|
87
89
|
data: undefined;
|
|
88
|
-
errors:
|
|
90
|
+
errors: ErrorWithPath[];
|
|
89
91
|
};
|
|
90
92
|
declare function parse<T>(type: RcType<T>, input: unknown, ctx: ParseResultCtx, checkIfIsValid: () => IsValid<T>): InternalParseResult<T>;
|
|
91
93
|
declare const defaultProps: Omit<RcType<any>, '_parse_' | '_kind_'>;
|
|
@@ -116,6 +118,10 @@ type ArrayOptions<T extends RcType<any>> = {
|
|
|
116
118
|
unique?: RcInferType<T> extends Record<string, any> ? keyof RcInferType<T> | ((parsedItem: RcInferType<T>) => any) : boolean | ((parsedItem: RcInferType<T>) => any);
|
|
117
119
|
};
|
|
118
120
|
declare function rc_array<T extends RcType<any>>(type: T, options?: ArrayOptions<T>): RcType<RcInferType<T>[]>;
|
|
121
|
+
declare function rc_get_array_item_type<T>(type: RcType<T[]>): RcType<T>;
|
|
122
|
+
declare function rc_disable_loose_array<T extends RcType<any>>(type: T, { nonRecursive }?: {
|
|
123
|
+
nonRecursive?: boolean;
|
|
124
|
+
}): T;
|
|
119
125
|
/** instead of returning a general error, rejects invalid array items and returns warnings for these items */
|
|
120
126
|
declare function rc_loose_array<T extends RcType<any>>(type: T, options?: ArrayOptions<T>): RcType<RcInferType<T>[]>;
|
|
121
127
|
type MapTupleToTypes<T extends readonly [...any[]]> = {
|
|
@@ -151,16 +157,17 @@ declare function rc_recursive<T>(type: () => RcType<T>): RcType<T>;
|
|
|
151
157
|
type TransformOptions<T> = {
|
|
152
158
|
/** if the input type is invalid, the transform will be ignored and this schema will be used to validate the input */
|
|
153
159
|
outputSchema?: RcType<T>;
|
|
160
|
+
disableStrictOutputSchema?: boolean;
|
|
154
161
|
};
|
|
155
162
|
/** validate a input or subset of input and transform the valid result */
|
|
156
|
-
declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => Transformed, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
163
|
+
declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => Transformed, { outputSchema, disableStrictOutputSchema, }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
157
164
|
declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => {
|
|
158
165
|
ok: true;
|
|
159
166
|
data: Transformed;
|
|
160
167
|
} | {
|
|
161
168
|
ok: false;
|
|
162
169
|
errors: string | string[];
|
|
163
|
-
}, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
170
|
+
}, { outputSchema, disableStrictOutputSchema, }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
164
171
|
type NonArrayObject = {
|
|
165
172
|
[x: string]: any;
|
|
166
173
|
[y: number]: never;
|
|
@@ -178,4 +185,4 @@ type Prettify<T> = T extends Record<string, any> ? {
|
|
|
178
185
|
} : T;
|
|
179
186
|
type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
|
|
180
187
|
|
|
181
|
-
export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, defaultProps,
|
|
188
|
+
export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, defaultProps, getWarningOrErrorWithPath, isObject, parse, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, rc_disable_loose_array, rc_get_array_item_type, 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_null, rc_nullish_default, rc_number, rc_obj_builder, rc_obj_extends, rc_obj_merge, rc_obj_omit, rc_obj_pick, rc_obj_strict, rc_object, rc_parse, rc_parse_json, rc_parser, rc_record, rc_recursive, rc_rename_from_key, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_unsafe_transform, rc_validator };
|
package/dist/runcheck.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,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-FXQPJI45.js";export{l as defaultProps,j as getWarningOrErrorWithPath,P as isObject,k as parse,o as rc_any,B as rc_array,O as rc_assert_is_valid,q as rc_boolean,t as rc_date,x as rc_default,D as rc_disable_loose_array,C as rc_get_array_item_type,d as rc_get_obj_schema,u as rc_instanceof,J as rc_is_valid,v as rc_literals,E as rc_loose_array,I as rc_loose_parse,A as rc_loose_record,n as rc_null,y as rc_nullish_default,s as rc_number,i as rc_obj_builder,c as rc_obj_extends,f as rc_obj_merge,h as rc_obj_omit,g as rc_obj_pick,e as rc_obj_strict,b as rc_object,G as rc_parse,R as rc_parse_json,H as rc_parser,z as rc_record,L as rc_recursive,a as rc_rename_from_key,r as rc_string,M as rc_transform,F as rc_tuple,m as rc_undefined,w as rc_union,p as rc_unknown,N as rc_unsafe_transform,K as rc_validator,Q as snakeCase};
|
package/package.json
CHANGED
package/dist/chunk-PJTM2QW6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function D(e,r){return{...r,i:e}}function I(e){return m(e)&&"__rc_type"in e}function N(e){if(I(e))return e;if(m(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=N(t);return k(r)}throw new Error(`invalid schema: ${e}`)}function k(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=N(s);return{...c,t:n,e:"object",T:!0,c:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!m(t))return s.o=-1,!1;let a=this.e==="strict_obj"?new Set(Object.keys(t)):void 0;if(a&&this.c.length!==a.size){for(let[f]of this.c)a.delete(f);s.o=-1;let l=[];for(let f of a)l.push(`Key '${f}' is not defined in the object shape`);return{data:void 0,errors:l}}let y={},i=[],T=s.n,p=-1;for(let[l,f]of this.c){let b=l;p+=1;let x=`.${l}`,j=`${T}${x}`;s.n=j;let d,g=l;if(f.i&&(d=t[f.i],g=f.i),d===void 0&&(d=t[l],g=l),d===void 0&&r==="snake_case"){let O=C(l);d=t[O],g=O}a?.delete(g);let[R,w]=f.r(d,s);if(R)y[b]=w;else{for(let O of w)s.n=j,i.push(h(s,O));if(s.s){s.o=p;break}}}if(a&&a.size>0)for(let l of a)i.push(`Key '${l}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.p?{errors:!1,data:{...t,...y}}:{errors:!1,data:y}})}}}function M(e,r){return{...k(e,r),e:"extends_object",p:!0}}function z(e){return e.t}function v(e,r){let n=(()=>{if(I(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?v(o,r):o;return t}}return e})();return{...k(n,r),e:"strict_obj"}}function Q(...e){let r={};for(let n of e)Object.assign(r,n.t);return k(r)}function J(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.t[t];s&&(n[t]=s)}return k(n)}function L(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return k(n)}function Z(){return(e,r)=>k(e,r)}function G(e){return{...this,R:e}}function h(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function P(e,r){e.u.push(h(e,r))}function F(e,r){r.forEach(n=>P(e,n))}function u(e,r,n,t){if(e.y&&r===void 0)return[!0,r];if(e.f&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return P(n,`Fallback used, errors -> ${q(s,n,e,r)}`),[!0,E(o)?o():o];if(e.b&&e.d){let a=e.d(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${q(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[h(n,U(e,r))]]}function q(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):U(n,t)}function H(e){return{...this,b:!0,d:e}}function X(e){return{...this,a:e}}function W(){return{...this,y:!0}}function U(e,r){return`Type '${A(r,!!e.h)}' is not assignable to '${e.e}'`}function Y(){return{...this,l:!0,e:`${this.e}_or_null`}}function ee(){return{...this,f:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:G,where:X,optional:W,optionalKey:W,orNullish:ee,withAutofix:H,orNull:Y,R:void 0,a:void 0,y:!1,l:!1,f:!1,b:!1,h:!1,i:void 0,d:void 0,j:void 0,t:void 0,T:!1,p:!1,c:[]},ue={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ye={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},fe={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Te={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function _e(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function be(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?A(e[0],!0):e.map(r=>A(r,!0)).join(" | ")}}var B=1;function he(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,y=[],i=0;for(let T of e){i+=1,T.T&&(n.n=`${t}|union ${i}|`);let p=n.s;n.s=!0,n.o=0;let[l,f]=T.r(r,n),b=n.o;if(n.s=p,n.o=0,l)return!0;T.T&&b!==-1?b>0?y.push(...f):(o<B&&s.push(...f),o+=1):a=!0}return n.n=t,y.length>0||s.length>0?((o>B||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function je(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ge(e,r){return{...e,y:!1,f:!1,l:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function re(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!m(t))return!1;let o={},a=[],y=s.n;for(let[i,T]of Object.entries(t)){let p=`.${i}`,l=`${y}${p}`;if(s.n=l,r&&!r(i)){a.push(h(s,`Key '${i}' is not allowed`));continue}let f=t[i],[b,x]=e.r(T,s);if(b)o[i]=f;else{let j=x;for(let d of j)a.push(h(s,d));if(s.s)break}}if(a.length>0)if(n)F(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function Oe(e,{checkKey:r}={}){return re(e,{checkKey:r,looseCheck:!0})}function K(e,r,n,t=!1,s){let o=[],a=[],y=new Set,i=n.n,T=Array.isArray(r),p=-1;for(let l of e){p++;let f=T?r[p]:r,b=`[${p}]`,x=`${i}${b}`;n.n=x;let j=f.r(l,n),[d,g]=j;n.n=x;let R=s?.unique;if(d&&R){let _=g,$=typeof R=="string";$?_=g[R]:typeof R=="function"&&(_=R(g)),y.has(_)?($&&(n.n=`${i}${b}.${R}`),j=[!1,[h(n,$?`Type '${f.t?.[R]?.e}' with value "${_}" is not unique`:typeof R=="function"?`Type '${f.e}' unique fn return with value "${_}" is not unique`:`${f.e} value is not unique`)]]):y.add(_)}let[w,O]=j;if(w)a.push(O);else if(t){o.push(O.map(_=>h(n,_)));continue}else return{errors:O.map(_=>h(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};F(n,o.flat())}return{errors:!1,data:a}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!1,r):!1)}}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!0,r):!1)}}}function me(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:K.call(this,r,e,n))}}}function S(e,r,{noWarnings:n=!1}={}){let t={u:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.u.length>0?t.u:!1}:{ok:!1,error:!0,errors:o}}function we(e){return r=>S(r,e)}function Ae(e,r,n){let t=S(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function ne(e,r){let n={u:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function $e(e){return r=>ne(r,e)}function Pe(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function V(e,r,n){let t=e.n,s=e.s;e.s=!0,e.n=`${t}|output|`;let o=r.r(n,e);return e.n=t,e.s=s,o}function Ke(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=V(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);return a?[!0,r(y,e)]:[!1,[...o||[],...y]]}}}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=null;if(n){let[i,T]=V(s,n,t);if(i)return[!0,T];o=T}let[a,y]=e.r(t,s);if(a){let i=r(y,e);return i.ok?[!0,i.data]:[!1,typeof i.errors=="string"?[i.errors]:i.errors]}return[!1,[...o||[],...y]]}}}function A(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function Ee(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function m(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function C(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ie(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${A(e,!0)}`]};let t=JSON.parse(e);return S(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${m(t)?t.message:""}`]}}}function E(e){return typeof e=="function"}export{D as a,k as b,M as c,z as d,v as e,Q as f,J as g,L as h,Z as i,h as j,u as k,c as l,ue as m,ye as n,fe as o,le as p,Te as q,pe as r,de as s,Re as t,_e as u,be as v,he as w,je as x,ge as y,re as z,Oe as A,ke as B,xe as C,me as D,S as E,we as F,Ae as G,ne as H,$e as I,Pe as J,Ke as K,Se as L,Ee as M,m as N,C as O,Ie as P};
|