runcheck 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/autofixable.cjs +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-TS4C7BNK.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +16 -11
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EHQOQ4HE.js +0 -1
package/README.md
CHANGED
|
@@ -367,7 +367,7 @@ const result = rc_parse(
|
|
|
367
367
|
)
|
|
368
368
|
```
|
|
369
369
|
|
|
370
|
-
Use the `outputSchema` option to create a type that validates both the input and the output of the transform. So if the input
|
|
370
|
+
Use the `outputSchema` option to create a type that validates both the input and the output of the transform. So if the input matches the `outputSchema` the transform will be ignored.
|
|
371
371
|
|
|
372
372
|
```ts
|
|
373
373
|
const input = 'hello'
|
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,i)=>{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:!(i=R(r,t))||i.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,b:e}}function u(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function c(e,r){e.l.push(u(e,r))}function o(e,r,n,i){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=i();if(t&&(t===!0||!t.errors)){let a=t===!0?r:t.data;return e.c&&!e.c(a)?[!1,[u(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.b;if(a!==void 0)return c(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,O(a)?a():a];if(e.j&&e._){let l=e._(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,i){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,i)}function x(e){return{...this,j:!0,_:e}}function $(e){return{...this,c:e}}function d(){return{...this,T:!0}}function T(e,r){return`Type '${j(r,!!e.g)}' 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 s={__rc_type:void 0,withFallback:k,where:$,optional:d,optionalKey:d,orNullish:N,withAutofix:x,orNull:E,b:void 0,c:void 0,T:!1,p:!1,d:!1,j:!1,g:!1,y:void 0,_:void 0,k:void 0,t:void 0,R:!1,h:!1,u:[]},C={...s,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},K={...s,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},q={...s,r(e,r){return o(this,e,r,()=>!0)},e:"any"},V={...s,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},p={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...s,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},h={...s,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...s,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function O(e){return typeof e=="function"}var A=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),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-TS4C7BNK.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 m(e)&&"__rc_type"in e}function W(e){if(D(e))return e;if(m(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",R:!0,u:Object.entries(n),r(t,o){return y(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 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=N(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.h?{errors:!1,data:{...t,...l}}:{errors:!1,data:l}})}}}function M(e,r){return{...b(e,r),e:"extends_object",h:!0}}function z(e){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,b:e}}function p(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function K(e,r){e.l.push(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.b;if(a!==void 0)return K(n,`Fallback used, errors -> ${v(o,n,e,r)}`),[!0,I(a)?a():a];if(e.j&&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}'`)]]:(K(n,`Autofixed from error "${v(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[p(n,F(e,r))]]}function v(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):F(n,t)}function X(e){return{...this,j:!0,_:e}}function Y(e){return{...this,c:e}}function C(){return{...this,T:!0}}function F(e,r){return`Type '${w(r,!!e.g)}' 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,b:void 0,c:void 0,T:!1,p:!1,d:!1,j:!1,g:!1,y:void 0,_:void 0,k:void 0,t:void 0,R:!1,h:!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})},g:!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.R&&(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.R&&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(!m(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 xe(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 x=P,A=typeof _=="string";A?x=P[_]:typeof _=="function"&&(x=_(P)),i.has(x)?(A&&(n.n=`${u}${g}.${_}`),R=[!1,[p(n,A?`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[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 me(e,r){return{...f,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 Pe(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 we(e,r){return{...f,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 Ee(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 $e(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 te(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,f:!1};return!!r.r(e,n)[0]}function Ke(e){return r=>te(r,e)}function Se(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 Ie(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 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);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=(()=>{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 Ne(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 N(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function ve(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: ${m(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,xe as A,me as B,Pe as C,we as D,Ee as E,S as F,$e as G,Ae as H,te as I,Ke as J,Se as K,Ie as L,We as M,Ne as N,m as O,N as P,ve as Q};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var ne=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ee(r))!re.call(e,s)&&s!==n&&K(e,s,{get:()=>r[s],enumerable:!(t=Y(r,s))||t.enumerable});return e};var se=e=>te(K({},"__esModule",{value:!0}),e);var ve={};ne(ve,{defaultProps:()=>c,gerWarningOrErrorWithPath:()=>b,isObject:()=>x,parse:()=>u,rc_any:()=>le,rc_array:()=>ke,rc_assert_is_valid:()=>Ie,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>Oe,rc_get_obj_schema:()=>F,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>he,rc_loose_array:()=>me,rc_loose_parse:()=>$e,rc_loose_record:()=>xe,rc_null:()=>fe,rc_nullish_default:()=>ge,rc_number:()=>Re,rc_obj_builder:()=>M,rc_obj_extends:()=>B,rc_obj_merge:()=>U,rc_obj_omit:()=>D,rc_obj_pick:()=>V,rc_obj_strict:()=>E,rc_object:()=>j,rc_parse:()=>A,rc_parse_json:()=>Ne,rc_parser:()=>Ae,rc_record:()=>G,rc_recursive:()=>Ke,rc_rename_from_key:()=>C,rc_string:()=>de,rc_transform:()=>Ee,rc_tuple:()=>we,rc_undefined:()=>ye,rc_union:()=>je,rc_unknown:()=>Te,rc_unsafe_transform:()=>Se,rc_validator:()=>Pe,snakeCase:()=>S});module.exports=se(ve);function C(e,r){return{...r,i:e}}function q(e){return x(e)&&"__rc_type"in e}function W(e){if(q(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=W(s);return{...c,t:n,e:"object",l:!0,p:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!x(t))return s.o=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},i=[],f=s.n,d=-1;for(let[y,R]of this.p){let T=y;d+=1;let h=`.${y}`,g=`${f}${h}`;s.n=g;let l,O=y;if(R.i&&(l=t[R.i],O=R.i),l===void 0&&(l=t[y],O=y),l===void 0&&r==="snake_case"){let k=S(y);l=t[k],O=k}o?.delete(O);let[m,p]=R.r(l,s);if(m)a[T]=p;else{for(let k of p)s.n=g,i.push(b(s,k));if(s.s){s.o=d;break}}}if(o&&o.size>0)for(let y of o)i.push(`Key '${y}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.d?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function B(e,r){return{...j(e,r),e:"extends_object",d:!0}}function F(e){return e.t}function E(e,r){let n=(()=>{if(q(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?E(o,r):o;return t}}return e})();return{...j(n,r),e:"strict_obj"}}function U(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function V(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.t[t];s&&(n[t]=s)}return j(n)}function D(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return j(n)}function M(){return(e,r)=>j(e,r)}function oe(e){return{...this,R:e}}function b(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function I(e,r){e.c.push(b(e,r))}function L(e,r){r.forEach(n=>I(e,n))}function u(e,r,n,t){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return I(n,`Fallback used, errors -> ${z(s,n,e,r)}`),[!0,v(o)?o():o];if(e.b&&e.T){let a=e.T(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(I(n,`Autofixed from error "${z(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[b(n,Z(e,r))]]}function z(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):Z(n,t)}function ae(e){return{...this,b:!0,T:e}}function ie(e){return{...this,a:e}}function Q(){return{...this,u:!0}}function Z(e,r){return`Type '${w(r,!!e.h)}' is not assignable to '${e.e}'`}function ce(){return{...this,f:!0,e:`${this.e}_or_null`}}function ue(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:oe,where:ie,optional:Q,optionalKey:Q,orNullish:ue,withAutofix:ae,orNull:ce,R:void 0,a:void 0,u:!1,f:!1,y:!1,b:!1,h:!1,i:void 0,T:void 0,j:void 0,t:void 0,l:!1,d:!1,p:[]},ye={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},fe={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Te={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},_e={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function be(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function he(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var J=1;function je(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,i=[],f=0;for(let d of e){f+=1,d.l&&(n.n=`${t}|union ${f}|`);let y=n.s;n.s=!0,n.o=0;let[R,T]=d.r(r,n),h=n.o;if(n.s=y,n.o=0,R)return!0;d.l&&h!==-1?h>0?i.push(...T):(o<J&&s.push(...T),o+=1):a=!0}return n.n=t,i.length>0||s.length>0?((o>J||a)&&s.push("not matches any other union member"),{errors:[...i,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Oe(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ge(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function G(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!x(t))return!1;let o={},a=[],i=s.n;for(let[f,d]of Object.entries(t)){let y=`.${f}`,R=`${i}${y}`;if(s.n=R,r&&!r(f)){a.push(b(s,`Key '${f}' is not allowed`));continue}let T=t[f],[h,g]=e.r(d,s);if(h)o[f]=T;else{let l=g;for(let O of l)a.push(b(s,O));if(s.s)break}}if(a.length>0)if(n)L(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function xe(e,{checkKey:r}={}){return G(e,{checkKey:r,looseCheck:!0})}function N(e,r,n,t=!1,s){let o=[],a=[],i=new Set,f=n.n,d=Array.isArray(r),y=-1;for(let R of e){y++;let T=d?r[y]:r,h=`[${y}]`,g=`${f}${h}`;n.n=g;let l=T.r(R,n),[O,m]=l;n.n=g;let p=s?.unique;if(O&&p){let _=m,P=typeof p=="string";P?_=m[p]:typeof p=="function"&&(_=p(m)),i.has(_)?(P&&(n.n=`${f}${h}.${p}`),l=[!1,[b(n,P?`Type '${T.t?.[p]?.e}' with value "${_}" is not unique`:typeof p=="function"?`Type '${T.e}' unique fn return with value "${_}" is not unique`:`${T.e} value is not unique`)]]):i.add(_)}let[k,$]=l;if(k)a.push($);else if(t){o.push($.map(_=>b(n,_)));continue}else return{errors:$.map(_=>b(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};L(n,o.flat())}return{errors:!1,data:a}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!1,r):!1)}}}function me(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:N.call(this,n,e,t,!0,r):!1)}}}function we(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:N.call(this,r,e,n))}}}function A(e,r,{noWarnings:n=!1}={}){let t={c:[],n:"",s:!1,o:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.c.length>0?t.c:!1}:{ok:!1,error:!0,errors:o}}function Ae(e){return r=>A(r,e)}function $e(e,r,n){let t=A(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function H(e,r){let n={c:[],n:"",s:!1,o:0,_:!1};return!!r.r(e,n)[0]}function Pe(e){return r=>H(r,e)}function Ke(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function X(e,r,n,t){let s=e.n;e.n=`${s}|output|`;let[o,a]=r.r(n,e);return e.n=s,o?[!0,a]:[!1,[...t,...a]]}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=s.s;n&&(s.s=!0);let[a,i]=e.r(t,s);return n&&(s.s=o),a?[!0,r(i)]:n?X(s,n,t,i):[!1,i]}}}function Se(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let[o,a]=e.r(t,s);if(o){let i=r(a);return i.ok?[!0,i.data]:[!1,i.errors]}else if(n)return X(s,n,t,a);return[!1,a]}}}function w(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function Ie(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ne(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return A(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${x(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,gerWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
|
|
1
|
+
"use strict";var 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 Ce={};ne(Ce,{defaultProps:()=>y,getWarningOrErrorWithPath:()=>p,isObject:()=>g,parse:()=>c,rc_any:()=>Te,rc_array:()=>me,rc_assert_is_valid:()=>Ne,rc_boolean:()=>pe,rc_date:()=>_e,rc_default:()=>ke,rc_disable_loose_array:()=>Pe,rc_get_obj_schema:()=>B,rc_instanceof:()=>be,rc_is_valid:()=>H,rc_literals:()=>je,rc_loose_array:()=>we,rc_loose_parse:()=>Ae,rc_loose_record:()=>xe,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:()=>ve,rc_parser:()=>$e,rc_record:()=>G,rc_recursive:()=>Se,rc_rename_from_key:()=>v,rc_string:()=>Re,rc_transform:()=>Ie,rc_tuple:()=>Ee,rc_undefined:()=>fe,rc_union:()=>ge,rc_unknown:()=>de,rc_unsafe_transform:()=>We,rc_validator:()=>Ke,snakeCase:()=>I});module.exports=oe(Ce);function v(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",R:!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 x=I(f);R=t[x],O=x}s?.delete(O);let[P,_]=T.r(R,o);if(P)l[h]=_;else{for(let x of _)o.n=j,i.push(x);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._?{errors:!1,data:{...t,...l}}:{errors:!1,data:l}})}}}function q(e,r){return{...b(e,r),e:"extends_object",_:!0}}function B(e){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,b:e}}function p(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function W(e,r){e.l.push(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.b;if(a!==void 0)return W(n,`Fallback used, errors -> ${z(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,[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,j:!0,h:e}}function ue(e){return{...this,c:e}}function L(){return{...this,T:!0}}function Z(e,r){return`Type '${w(r,!!e.g)}' 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,b:void 0,c:void 0,T:!1,p:!1,d:!1,j:!1,g:!1,f:void 0,h:void 0,k:void 0,t:void 0,R:!1,_:!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})},g:!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.R&&(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.R&&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:N(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:N(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 xe(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 m=P,K=typeof _=="string";K?m=P[_]:typeof _=="function"&&(m=_(P)),i.has(m)?(K&&(n.n=`${u}${k}.${_}`),R=[!1,[p(n,K?`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[x,A]=R;if(x)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 me(e,r){return{...y,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function Pe(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 we(e,r){return{...y,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 Ee(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 $e(e){return r=>$(r,e)}function Ae(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 Ke(e){return r=>H(r,e)}function Se(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 Ie(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 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);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=(()=>{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 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 ve(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 N(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_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
|
@@ -24,9 +24,6 @@ declare function rc_object<T extends RcObject>(shape: T, { normalizeKeysFrom }?:
|
|
|
24
24
|
declare function rc_obj_extends<T extends RcObject>(shape: T, options?: ObjOptions): RcObjTypeReturn<T>;
|
|
25
25
|
declare function rc_get_obj_schema<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,15 @@ type RcBase<T, RequiredKey extends boolean> = {
|
|
|
79
78
|
}) => RcType<T>;
|
|
80
79
|
readonly _optional_key_?: RequiredKey;
|
|
81
80
|
};
|
|
82
|
-
declare function
|
|
81
|
+
declare function getWarningOrErrorWithPath(ctx: ParseResultCtx, message: string & {
|
|
82
|
+
__withPath?: never;
|
|
83
|
+
}): ErrorWithPath;
|
|
83
84
|
type IsValid<T> = boolean | {
|
|
84
85
|
data: T;
|
|
85
86
|
errors: false;
|
|
86
87
|
} | {
|
|
87
88
|
data: undefined;
|
|
88
|
-
errors:
|
|
89
|
+
errors: ErrorWithPath[];
|
|
89
90
|
};
|
|
90
91
|
declare function parse<T>(type: RcType<T>, input: unknown, ctx: ParseResultCtx, checkIfIsValid: () => IsValid<T>): InternalParseResult<T>;
|
|
91
92
|
declare const defaultProps: Omit<RcType<any>, '_parse_' | '_kind_'>;
|
|
@@ -116,6 +117,9 @@ type ArrayOptions<T extends RcType<any>> = {
|
|
|
116
117
|
unique?: RcInferType<T> extends Record<string, any> ? keyof RcInferType<T> | ((parsedItem: RcInferType<T>) => any) : boolean | ((parsedItem: RcInferType<T>) => any);
|
|
117
118
|
};
|
|
118
119
|
declare function rc_array<T extends RcType<any>>(type: T, options?: ArrayOptions<T>): RcType<RcInferType<T>[]>;
|
|
120
|
+
declare function rc_disable_loose_array<T extends RcType<any>>(type: T, { nonRecursive }?: {
|
|
121
|
+
nonRecursive?: boolean;
|
|
122
|
+
}): T;
|
|
119
123
|
/** instead of returning a general error, rejects invalid array items and returns warnings for these items */
|
|
120
124
|
declare function rc_loose_array<T extends RcType<any>>(type: T, options?: ArrayOptions<T>): RcType<RcInferType<T>[]>;
|
|
121
125
|
type MapTupleToTypes<T extends readonly [...any[]]> = {
|
|
@@ -151,16 +155,17 @@ declare function rc_recursive<T>(type: () => RcType<T>): RcType<T>;
|
|
|
151
155
|
type TransformOptions<T> = {
|
|
152
156
|
/** if the input type is invalid, the transform will be ignored and this schema will be used to validate the input */
|
|
153
157
|
outputSchema?: RcType<T>;
|
|
158
|
+
disableStrictOutputSchema?: boolean;
|
|
154
159
|
};
|
|
155
160
|
/** validate a input or subset of input and transform the valid result */
|
|
156
|
-
declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => Transformed, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
157
|
-
declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => {
|
|
161
|
+
declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => Transformed, { outputSchema, disableStrictOutputSchema, }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
162
|
+
declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => {
|
|
158
163
|
ok: true;
|
|
159
164
|
data: Transformed;
|
|
160
165
|
} | {
|
|
161
166
|
ok: false;
|
|
162
|
-
errors: string[];
|
|
163
|
-
}, { outputSchema }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
167
|
+
errors: string | string[];
|
|
168
|
+
}, { outputSchema, disableStrictOutputSchema, }?: TransformOptions<Transformed>): RcType<Transformed>;
|
|
164
169
|
type NonArrayObject = {
|
|
165
170
|
[x: string]: any;
|
|
166
171
|
[y: number]: never;
|
|
@@ -178,4 +183,4 @@ type Prettify<T> = T extends Record<string, any> ? {
|
|
|
178
183
|
} : T;
|
|
179
184
|
type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
|
|
180
185
|
|
|
181
|
-
export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, defaultProps,
|
|
186
|
+
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_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,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-TS4C7BNK.js";export{l as defaultProps,j as getWarningOrErrorWithPath,O as isObject,k as parse,o as rc_any,B as rc_array,N as rc_assert_is_valid,q as rc_boolean,t as rc_date,x as rc_default,C as rc_disable_loose_array,d as rc_get_obj_schema,u as rc_instanceof,I as rc_is_valid,v as rc_literals,D as rc_loose_array,H 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,F as rc_parse,Q as rc_parse_json,G as rc_parser,z as rc_record,K as rc_recursive,a as rc_rename_from_key,r as rc_string,L as rc_transform,E as rc_tuple,m as rc_undefined,w as rc_union,p as rc_unknown,M as rc_unsafe_transform,J as rc_validator,P as snakeCase};
|
package/package.json
CHANGED
package/dist/chunk-EHQOQ4HE.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function D(e,r){return{...r,i:e}}function I(e){return k(e)&&"__rc_type"in e}function N(e){if(I(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=N(t);return O(r)}throw new Error(`invalid schema: ${e}`)}function O(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=N(s);return{...c,t:n,e:"object",l:!0,d:Object.entries(n),r(t,s){return u(this,t,s,()=>{if(!k(t))return s.s=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},i=[],f=s.n,d=-1;for(let[y,R]of this.d){let T=y;d+=1;let b=`.${y}`,g=`${f}${b}`;s.n=g;let l,j=y;if(R.i&&(l=t[R.i],j=R.i),l===void 0&&(l=t[y],j=y),l===void 0&&r==="snake_case"){let x=C(y);l=t[x],j=x}o?.delete(j);let[m,p]=R.r(l,s);if(m)a[T]=p;else{for(let x of p)s.n=g,i.push(h(s,x));if(s.o){s.s=d;break}}}if(o&&o.size>0)for(let y of o)i.push(`Key '${y}' is not defined in the object shape`);return i.length>0?{errors:i,data:void 0}:this.p?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function M(e,r){return{...O(e,r),e:"extends_object",p:!0}}function z(e){return e.t}function v(e,r){let n=(()=>{if(I(e)){if(!e.t)throw new Error("rc_strict_obj: expected an object type");if(r?.nonRecursive)return e.t;{let t={};for(let[s,o]of Object.entries(e.t))t[s]=o.t?v(o,r):o;return t}}return e})();return{...O(n,r),e:"strict_obj"}}function Q(...e){let r={};for(let n of e)Object.assign(r,n.t);return O(r)}function J(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.t[t];s&&(n[t]=s)}return O(n)}function L(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return O(n)}function Z(){return(e,r)=>O(e,r)}function G(e){return{...this,R:e}}function h(e,r){return r.startsWith("$")?r:`${e.n?`$${e.n}: `:""}${r}`}function P(e,r){e.c.push(h(e,r))}function F(e,r){r.forEach(n=>P(e,n))}function u(e,r,n,t){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.a&&!e.a(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}if(!n._){let o=e.R;if(o!==void 0)return P(n,`Fallback used, errors -> ${q(s,n,e,r)}`),[!0,S(o)?o():o];if(e.b&&e.T){let a=e.T(r);if(a)return e.a&&!e.a(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(P(n,`Autofixed from error "${q(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[h(n,U(e,r))]]}function q(e,r,n,t){return e?e.errors.map(s=>s.replace(r.n,"")).join("; "):U(n,t)}function H(e){return{...this,b:!0,T:e}}function X(e){return{...this,a:e}}function W(){return{...this,u:!0}}function U(e,r){return`Type '${w(r,!!e.h)}' is not assignable to '${e.e}'`}function Y(){return{...this,f:!0,e:`${this.e}_or_null`}}function ee(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:G,where:X,optional:W,optionalKey:W,orNullish:ee,withAutofix:H,orNull:Y,R:void 0,a:void 0,u:!1,f:!1,y:!1,b:!1,h:!1,i:void 0,T:void 0,j:void 0,t:void 0,l:!1,p:!1,d:[]},ue={...c,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ye={...c,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},fe={...c,r(e,r){return u(this,e,r,()=>!0)},e:"any"},le={...c,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Te={...c,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},pe={...c,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},de={...c,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Re={...c,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function _e(e){return{...c,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function be(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},h:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var B=1;function he(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return u(this,r,n,()=>{let t=n.n,s=[],o=0,a=!1,i=[],f=0;for(let d of e){f+=1,d.l&&(n.n=`${t}|union ${f}|`);let y=n.o;n.o=!0,n.s=0;let[R,T]=d.r(r,n),b=n.s;if(n.o=y,n.s=0,R)return!0;d.l&&b!==-1?b>0?i.push(...T):(o<B&&s.push(...T),o+=1):a=!0}return n.n=t,i.length>0||s.length>0?((o>B||a)&&s.push("not matches any other union member"),{errors:[...i,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function je(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:S(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function Oe(e,r){return{...e,u:!1,y:!1,f:!1,r(n,t){return u(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:S(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function re(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!k(t))return!1;let o={},a=[],i=s.n;for(let[f,d]of Object.entries(t)){let y=`.${f}`,R=`${i}${y}`;if(s.n=R,r&&!r(f)){a.push(h(s,`Key '${f}' is not allowed`));continue}let T=t[f],[b,g]=e.r(d,s);if(b)o[f]=T;else{let l=g;for(let j of l)a.push(h(s,j));if(s.o)break}}if(a.length>0)if(n)F(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function ge(e,{checkKey:r}={}){return re(e,{checkKey:r,looseCheck:!0})}function K(e,r,n,t=!1,s){let o=[],a=[],i=new Set,f=n.n,d=Array.isArray(r),y=-1;for(let R of e){y++;let T=d?r[y]:r,b=`[${y}]`,g=`${f}${b}`;n.n=g;let l=T.r(R,n),[j,m]=l;n.n=g;let p=s?.unique;if(j&&p){let _=m,$=typeof p=="string";$?_=m[p]:typeof p=="function"&&(_=p(m)),i.has(_)?($&&(n.n=`${f}${b}.${p}`),l=[!1,[h(n,$?`Type '${T.t?.[p]?.e}' with value "${_}" is not unique`:typeof p=="function"?`Type '${T.e}' unique fn return with value "${_}" is not unique`:`${T.e} value is not unique`)]]):i.add(_)}let[x,A]=l;if(x)a.push(A);else if(t){o.push(A.map(_=>h(n,_)));continue}else return{errors:A.map(_=>h(n,_)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};F(n,o.flat())}return{errors:!1,data:a}}function xe(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!1,r):!1)}}}function ke(e,r){return{...c,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:K.call(this,n,e,t,!0,r):!1)}}}function me(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:K.call(this,r,e,n))}}}function E(e,r,{noWarnings:n=!1}={}){let t={c:[],n:"",o:!1,s:0,_:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.c.length>0?t.c:!1}:{ok:!1,error:!0,errors:o}}function we(e){return r=>E(r,e)}function Ae(e,r,n){let t=E(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function ne(e,r){let n={c:[],n:"",o:!1,s:0,_:!1};return!!r.r(e,n)[0]}function $e(e){return r=>ne(r,e)}function Pe(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function V(e,r,n,t){let s=e.n;e.n=`${s}|output|`;let[o,a]=r.r(n,e);return e.n=s,o?[!0,a]:[!1,[...t,...a]]}function Ke(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let o=s.o;n&&(s.o=!0);let[a,i]=e.r(t,s);return n&&(s.o=o),a?[!0,r(i)]:n?V(s,n,t,i):[!1,i]}}}function Ee(e,r,{outputSchema:n}={}){return{...c,e:`transform_from_${e.e}`,r(t,s){let[o,a]=e.r(t,s);if(o){let i=r(a);return i.ok?[!0,i.data]:[!1,i.errors]}else if(n)return V(s,n,t,a);return[!1,a]}}}function w(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function Se(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function C(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ie(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return E(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parse error: ${k(t)?t.message:""}`]}}}function S(e){return typeof e=="function"}export{D as a,O as b,M as c,z as d,v as e,Q as f,J as g,L as h,Z as i,h as j,u as k,c as l,ue as m,ye as n,fe as o,le as p,Te as q,pe as r,de as s,Re as t,_e as u,be as v,he as w,je as x,Oe as y,re as z,ge as A,xe as B,ke as C,me as D,E,we as F,Ae as G,ne as H,$e as I,Pe as J,Ke as K,Ee as L,Se as M,k as N,C as O,Ie as P};
|