runcheck 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},R=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!p.call(e,n)&&n!==t&&c(e,n,{get:()=>r[n],enumerable:!(i=y(r,n))||i.enumerable});return e};var h=e=>R(c({},"__esModule",{value:!0}),e);var P={};d(P,{rc_boolean_autofix:()=>k,rc_number_autofix:()=>A,rc_string_autofix:()=>O});module.exports=h(P);function _(e){return{...this,o:e}}function a(e,r,t,i){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let s=n===!0?r:n.data;return e.s&&!e.s(s)?[!1,[e.n(s)]]:[!0,s]}if(e.o!==void 0)return t.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.f&&e.i){let s=e.i(r);if(s)return e.s&&!e.s(s.fixed)?[!1,[e.n(s.fixed)]]:(t.warnings.push(`${t.path?`$${t.path}: `:""}Autofixed from error "${e.n(r)}"`),[!0,s.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function b(e){return{...this,f:!0,i:e}}function g(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function x(){return{...this,c:!0}}function w(e){return`Type '${j(e)}' is not assignable to '${this.e}'`}function m(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function $(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:_,where:g,optional:x,n:w,nullable:m,withAutofix:b,nullish:$},N={...o,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},V={...o,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},I={...o,r(e,r){return a(this,e,r,()=>!0)},e:"any"},q={...o,r(e,r){return a(this,e,r,()=>!0)},e:"unknown"},u={...o,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...o,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},f={...o,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},E={...o,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var k=u.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),O=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),A=f.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
1
+ "use strict";var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var o in r)c(e,o,{get:r[o],enumerable:!0})},h=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of d(r))!p.call(e,n)&&n!==o&&c(e,n,{get:()=>r[n],enumerable:!(i=T(r,n))||i.enumerable});return e};var _=e=>h(c({},"__esModule",{value:!0}),e);var N={};R(N,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>S,rc_string_autofix:()=>P});module.exports=_(N);function b(e){return{...this,o:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function u(e,r){e.warnings.push(g(e,r))}function s(e,r,o,i){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let t=n===!0?r:n.data;return e.s&&!e.s(t)?[!1,[e.n(t)]]:[!0,t]}if(e.o!==void 0)return u(o,`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.f&&e.i){let t=e.i(r);if(t)return e.s&&!e.s(t.fixed)?[!1,[e.n(t.fixed)]]:(u(o,`Autofixed from error "${e.n(r)}"`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function x(e){return{...this,f:!0,i:e}}function w(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function m(){return{...this,c:!0}}function j(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function $(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function k(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var a={withFallback:b,where:w,optional:m,n:j,nullable:$,withAutofix:x,nullish:k},I={...a,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},q={...a,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},E={...a,r(e,r){return s(this,e,r,()=>!0)},e:"any"},C={...a,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},l={...a,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},f={...a,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},y={...a,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},K={...a,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var A=l.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),P=f.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),S=y.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
@@ -1 +1 @@
1
- import{e as f,f as t,g as o}from"./chunk-NNEEJPIK.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
1
+ import{e as f,f as t,g as o}from"./chunk-JSISETW3.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 I(e){return{...this,o:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function $(e,r){e.warnings.push(_(e,r))}function O(e,r){r.forEach(n=>$(e,n))}function c(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.s&&!e.s(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return $(n,`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.f&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:($(n,`Autofixed from error "${e.n(r)}"`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function q(e){return{...this,f:!0,i:e}}function E(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function C(){return{...this,c:!0}}function K(e){return`Type '${S(e)}' is not assignable to '${this.e}'`}function N(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function v(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:I,where:E,optional:C,n:K,nullable:N,withAutofix:q,nullish:v},B={...o,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},z={...o,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},D={...o,r(e,r){return c(this,e,r,()=>!0)},e:"any"},M={...o,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},L={...o,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Z={...o,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},G={...o,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},H={...o,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function J(e){return{...o,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function Q(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${S(e[0])}_literal`:"literals"}}function X(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return c(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function F(e,r){return{...r,a:e}}var Y=F;function k(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",y:!0,r(n,t){return c(this,n,t,()=>{if(!V(n))return!1;let s=new Set(Object.keys(n)),a={},u=[],d=t.path;for(let[i,T]of Object.entries(e)){let b=i,R=`.${i}`;t.path=`${d}${R}`;let l,y=i;if(T.a&&(l=n[T.a],y=T.a),l===void 0&&(l=n[i],y=i),l===void 0&&r==="snake_case"){let f=U(i);l=n[f],y=f}s.delete(y);let[g,h]=T.r(l,t);if(g)a[b]=h;else{let f=h;for(let x of f)u.push(_(t,x))}}if(this.e==="strict_obj"&&s.size>0)for(let i of s)u.push(`Key '${i}' is not defined in the object shape`);return u.length>0?{errors:u}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ee(e){return{...k(e),e:"extends_object"}}function re(e){return e.t}function ne(e){return{...k(e),e:"strict_obj"}}function te(e,r){return k({...e.t,...r.t})}function se(e,{checkKey:r,looseCheck:n}={}){return{...o,e:`record<string, ${e.e}>`,r(t,s){return c(this,t,s,()=>{if(!V(t))return!1;let a={},u=[],d=s.path;for(let[i,T]of Object.entries(t)){let b=`.${i}`;if(s.path=`${d}${b}`,r&&!r(i)){u.push(_(s,`Key '${i}' is not allowed`));continue}let R=t[i],[l,y]=e.r(T,s);if(l)a[i]=R;else{let g=y;for(let h of g)u.push(_(s,h))}}if(u.length>0)if(n)O(s,u);else return{errors:u};return{data:a}})}}}function A(e,r){if(typeof r=="string"&&!e.t?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function m(e,r,n,t=!1,s){let a=-1,u=[],d=[],i=new Set,T=n.path;for(let b of e){a++;let R=Array.isArray(r)?r[a]:r,l=`[${a}]`;n.path=`${T}${l}`;let y=R.r(b,n),[g,h]=y,f=s?.unique;if(g&&f){let p=h,j=typeof f=="string";j&&(p=h[f]),i.has(p)?(j&&(n.path=`${T}${l}.${f}`),y=[!1,[_(n,j?`Type '${R.t?.[f]?.e}' with value "${p}" is not unique`:`${R.e} value is not unique`)]]):i.add(p)}let[x,w]=y;if(x)d.push(w);else if(t){u.push(w.map(p=>_(n,p)));continue}else return{errors:w.map(p=>_(n,p))}}if(u.length>0){if(d.length===0)return{errors:u.slice(0,5).flat()};O(n,u.flat())}return{data:d}}function ae(e,r){return A(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:m.call(this,n,e,t,!1,r):!1)}}}function oe(e,r){return A(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:m.call(this,n,e,t,!0,r):!1)}}}function ie(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:m.call(this,r,e,n))}}}function P(e,r){let n={warnings:[],path:""},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function ce(e){return r=>P(r,e)}function ue(e,r){let n=P(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function W(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function le(e){return r=>W(r,e)}function ye(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function fe(e,r){return{...o,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function S(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function V(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function U(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}export{B as a,z as b,D as c,M as d,L as e,Z as f,G as g,H as h,J as i,Q as j,X as k,F as l,Y as m,k as n,ee as o,re as p,ne as q,te as r,se as s,ae as t,oe as u,ie as v,P as w,ce as x,ue as y,W as z,le as A,ye as B,fe as C,U as D};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var v=(e,r)=>{for(var n in r)j(e,n,{get:r[n],enumerable:!0})},C=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of K(r))!N.call(e,s)&&s!==n&&j(e,s,{get:()=>r[s],enumerable:!(t=E(r,s))||t.enumerable});return e};var F=e=>C(j({},"__esModule",{value:!0}),e);var _e={};v(_e,{rc_any:()=>H,rc_array:()=>le,rc_boolean:()=>Q,rc_date:()=>ee,rc_extends_obj:()=>ae,rc_get_obj_schema:()=>oe,rc_instanceof:()=>re,rc_is_valid:()=>S,rc_literals:()=>ne,rc_loose_array:()=>ye,rc_loose_parse:()=>pe,rc_null:()=>G,rc_number:()=>Y,rc_obj_intersection:()=>ce,rc_object:()=>x,rc_parse:()=>m,rc_parser:()=>Te,rc_record:()=>ue,rc_recursive:()=>Re,rc_rename_from_key:()=>A,rc_rename_key:()=>se,rc_strict_obj:()=>ie,rc_string:()=>X,rc_transform:()=>he,rc_tuple:()=>fe,rc_undefined:()=>Z,rc_union:()=>te,rc_unknown:()=>J,rc_validator:()=>de,snakeCase:()=>q});module.exports=F(_e);function U(e){return{...this,o:e}}function i(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.s&&!e.s(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.y&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`${n.path?`$${n.path}: `:""}Autofixed from error "${e.n(r)}"`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function z(e){return{...this,y:!0,i:e}}function B(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function W(){return{...this,c:!0}}function D(e){return`Type '${V(e)}' is not assignable to '${this.e}'`}function M(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function L(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:U,where:B,optional:W,n:D,nullable:M,withAutofix:z,nullish:L},Z={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},G={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},H={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},J={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},Q={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},X={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},Y={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ee={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function re(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ne(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${V(e[0])}_literal`:"literals"}}function te(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function A(e,r){return{...r,a:e}}var se=A;function h(e,r){if(!r)return e;if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function x(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",f:!0,r(n,t){return i(this,n,t,()=>{if(!I(n))return!1;let s=new Set(Object.keys(n)),a={},c=[],y=t.path;for(let[u,p]of Object.entries(e)){let _=u,d=`.${u}`;t.path=`${y}${d}`;let l,f=u;if(p.a&&(l=n[p.a],f=p.a),l===void 0&&(l=n[u],f=u),l===void 0&&r==="snake_case"){let T=q(u);l=n[T],f=T}s.delete(f);let[b,g]=p.r(l,t);if(b)a[_]=g;else{let T=g;for(let w of T)c.push(h(w,d))}}if(this.e==="strict_obj"&&s.size>0)for(let u of s)c.push(`Key '${u}' is not defined in the object shape`);return c.length>0?{errors:c}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ae(e){return{...x(e),e:"extends_object"}}function oe(e){return e.t}function ie(e){return{...x(e),e:"strict_obj"}}function ce(e,r){return x({...e.t,...r.t})}function ue(e,{checkKey:r,looseCheck:n}={}){return{...o,e:`record<string, ${e.e}>`,r(t,s){return i(this,t,s,()=>{if(!I(t))return!1;let a={},c=[];for(let[y,u]of Object.entries(t)){let p=`.${y}`;if(r&&!r(y)){c.push(h(`Key '${y}' is not allowed`,p));continue}let _=t[y],[d,l]=e.r(u,s);if(d)a[y]=_;else{let f=l;for(let b of f)c.push(h(b,p))}}if(c.length>0)if(n)s.warnings.push(...c);else return{errors:c};return{data:a}})}}}function P(e,r){if(typeof r=="string"&&!e.t?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function k(e,r,n,t=!1,s){let a=-1,c=[],y=[],u=new Set,p=n.path;for(let _ of e){a++;let d=Array.isArray(r)?r[a]:r,l=`[${a}]`;n.path=`${p}${l}`;let f=d.r(_,n),[b,g]=f,T=s?.unique;if(b&&T){let R=g,O=typeof T=="string";O&&(R=g[T]),u.has(R)?f=[!1,[O?h(`Type '${d.t?.[T]?.e}' with value "${R}" is not unique`,`.${T}`):`${d.e} value is not unique`]]:u.add(R)}let[w,$]=f;if(w)y.push($);else if(t){c.push($.map(R=>h(R,l)));continue}else return{errors:$.map(R=>h(R,l))}}if(c.length>0){if(y.length===0)return{errors:c.slice(0,5).flat()};n.warnings.push(...c.flat())}return{data:y}}function le(e,r){return P(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:k.call(this,n,e,t,!1,r):!1)}}}function ye(e,r){return P(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:k.call(this,n,e,t,!0,r):!1)}}}function fe(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:k.call(this,r,e,n))}}}function m(e,r){let n={warnings:[],path:""},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function Te(e){return r=>m(r,e)}function pe(e,r){let n=m(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function S(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function de(e){return r=>S(r,e)}function Re(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function he(e,r){return{...o,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function V(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function I(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function q(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator,snakeCase});
1
+ "use strict";var k=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var F=(e,r)=>{for(var n in r)k(e,n,{get:r[n],enumerable:!0})},W=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of N(r))!v.call(e,t)&&t!==n&&k(e,t,{get:()=>r[t],enumerable:!(s=K(r,t))||s.enumerable});return e};var U=e=>W(k({},"__esModule",{value:!0}),e);var ge={};F(ge,{rc_any:()=>Q,rc_array:()=>fe,rc_boolean:()=>Y,rc_date:()=>ne,rc_extends_obj:()=>ie,rc_get_obj_schema:()=>ce,rc_instanceof:()=>te,rc_is_valid:()=>I,rc_literals:()=>se,rc_loose_array:()=>Te,rc_loose_parse:()=>Re,rc_null:()=>J,rc_number:()=>re,rc_obj_intersection:()=>le,rc_object:()=>x,rc_parse:()=>A,rc_parser:()=>de,rc_record:()=>ye,rc_recursive:()=>_e,rc_rename_from_key:()=>S,rc_rename_key:()=>oe,rc_strict_obj:()=>ue,rc_string:()=>ee,rc_transform:()=>be,rc_tuple:()=>pe,rc_undefined:()=>H,rc_union:()=>ae,rc_unknown:()=>X,rc_validator:()=>he,snakeCase:()=>C});module.exports=U(ge);function B(e){return{...this,o:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function m(e,r){e.warnings.push(_(e,r))}function P(e,r){r.forEach(n=>m(e,n))}function c(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let a=t===!0?r:t.data;return e.s&&!e.s(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return m(n,`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.y&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:(m(n,`Autofixed from error "${e.n(r)}"`),[!0,a.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function z(e){return{...this,y:!0,i:e}}function D(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function M(){return{...this,c:!0}}function L(e){return`Type '${q(e)}' is not assignable to '${this.e}'`}function Z(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function G(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:B,where:D,optional:M,n:L,nullable:Z,withAutofix:z,nullish:G},H={...o,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},J={...o,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},Q={...o,r(e,r){return c(this,e,r,()=>!0)},e:"any"},X={...o,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},Y={...o,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ee={...o,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},re={...o,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ne={...o,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function te(e){return{...o,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function se(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return c(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},e:e.length==1?`${q(e[0])}_literal`:"literals"}}function ae(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return c(this,r,n,()=>{for(let s of e)if(s.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function S(e,r){return{...r,a:e}}var oe=S;function x(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",f:!0,r(n,s){return c(this,n,s,()=>{if(!E(n))return!1;let t=new Set(Object.keys(n)),a={},u=[],d=s.path;for(let[i,T]of Object.entries(e)){let b=i,R=`.${i}`;s.path=`${d}${R}`;let l,y=i;if(T.a&&(l=n[T.a],y=T.a),l===void 0&&(l=n[i],y=i),l===void 0&&r==="snake_case"){let f=C(i);l=n[f],y=f}t.delete(y);let[g,h]=T.r(l,s);if(g)a[b]=h;else{let f=h;for(let w of f)u.push(_(s,w))}}if(this.e==="strict_obj"&&t.size>0)for(let i of t)u.push(`Key '${i}' is not defined in the object shape`);return u.length>0?{errors:u}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ie(e){return{...x(e),e:"extends_object"}}function ce(e){return e.t}function ue(e){return{...x(e),e:"strict_obj"}}function le(e,r){return x({...e.t,...r.t})}function ye(e,{checkKey:r,looseCheck:n}={}){return{...o,e:`record<string, ${e.e}>`,r(s,t){return c(this,s,t,()=>{if(!E(s))return!1;let a={},u=[],d=t.path;for(let[i,T]of Object.entries(s)){let b=`.${i}`;if(t.path=`${d}${b}`,r&&!r(i)){u.push(_(t,`Key '${i}' is not allowed`));continue}let R=s[i],[l,y]=e.r(T,t);if(l)a[i]=R;else{let g=y;for(let h of g)u.push(_(t,h))}}if(u.length>0)if(n)P(t,u);else return{errors:u};return{data:a}})}}}function V(e,r){if(typeof r=="string"&&!e.t?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function O(e,r,n,s=!1,t){let a=-1,u=[],d=[],i=new Set,T=n.path;for(let b of e){a++;let R=Array.isArray(r)?r[a]:r,l=`[${a}]`;n.path=`${T}${l}`;let y=R.r(b,n),[g,h]=y,f=t?.unique;if(g&&f){let p=h,$=typeof f=="string";$&&(p=h[f]),i.has(p)?($&&(n.path=`${T}${l}.${f}`),y=[!1,[_(n,$?`Type '${R.t?.[f]?.e}' with value "${p}" is not unique`:`${R.e} value is not unique`)]]):i.add(p)}let[w,j]=y;if(w)d.push(j);else if(s){u.push(j.map(p=>_(n,p)));continue}else return{errors:j.map(p=>_(n,p))}}if(u.length>0){if(d.length===0)return{errors:u.slice(0,5).flat()};P(n,u.flat())}return{data:d}}function fe(e,r){return V(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:O.call(this,n,e,s,!1,r):!1)}}}function Te(e,r){return V(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:O.call(this,n,e,s,!0,r):!1)}}}function pe(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:O.call(this,r,e,n))}}}function A(e,r){let n={warnings:[],path:""},[s,t]=r.r(e,n);return s?{error:!1,data:t,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:t}}function de(e){return r=>A(r,e)}function Re(e,r){let n=A(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function I(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function he(e){return r=>I(r,e)}function _e(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function be(e,r){return{...o,e:`transform_from_${e.e}`,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function q(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function E(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("_")}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator,snakeCase});
package/dist/runcheck.js CHANGED
@@ -1 +1 @@
1
- import{A,B,C,D,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-NNEEJPIK.js";export{c as rc_any,t as rc_array,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,z as rc_is_valid,j as rc_literals,u as rc_loose_array,y as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,n as rc_object,w as rc_parse,x as rc_parser,s as rc_record,B as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,C as rc_transform,v as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,A as rc_validator,D as snakeCase};
1
+ import{A,B,C,D,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-JSISETW3.js";export{c as rc_any,t as rc_array,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,z as rc_is_valid,j as rc_literals,u as rc_loose_array,y as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,n as rc_object,w as rc_parse,x as rc_parser,s as rc_record,B as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,C as rc_transform,v as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,A as rc_validator,D as snakeCase};
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "runcheck",
3
3
  "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
- "version": "0.20.0",
4
+ "version": "0.20.1",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",
8
8
  "test:run": "vitest run",
9
9
  "lint": "pnpm tsc && pnpm eslint",
10
10
  "tsc": "tsc -p tsconfig.prod.json",
11
+ "vitest-bench": "vitest bench",
11
12
  "benchmark": "tsm benchmarks/benchmark.ts",
12
13
  "benchmark:generate-profile": "tsm benchmarks/generateProfiles.ts",
13
14
  "eslint": "CI=true eslint --color --ext .jsx,.js,.ts,.tsx src/ tests/",
@@ -1 +0,0 @@
1
- function S(e){return{...this,o:e}}function i(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.s&&!e.s(a)?[!1,[e.n(a)]]:[!0,a]}if(e.o!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.o];if(e.f&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`${n.path?`$${n.path}: `:""}Autofixed from error "${e.n(r)}"`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function V(e){return{...this,f:!0,i:e}}function I(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function q(){return{...this,c:!0}}function E(e){return`Type '${A(e)}' is not assignable to '${this.e}'`}function K(){return{...this,l:!0,e:`${this.e}_or_nullable`}}function N(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:S,where:I,optional:q,n:E,nullable:K,withAutofix:V,nullish:N},U={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},z={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},B={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},W={...o,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},D={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},M={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},L={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Z={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function G(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function H(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${A(e[0])}_literal`:"literals"}}function J(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function v(e,r){return{...r,a:e}}var Q=v;function h(e,r){if(!r)return e;if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function $(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",y:!0,r(n,t){return i(this,n,t,()=>{if(!P(n))return!1;let s=new Set(Object.keys(n)),a={},c=[],y=t.path;for(let[u,p]of Object.entries(e)){let _=u,d=`.${u}`;t.path=`${y}${d}`;let l,f=u;if(p.a&&(l=n[p.a],f=p.a),l===void 0&&(l=n[u],f=u),l===void 0&&r==="snake_case"){let T=F(u);l=n[T],f=T}s.delete(f);let[b,g]=p.r(l,t);if(b)a[_]=g;else{let T=g;for(let x of T)c.push(h(x,d))}}if(this.e==="strict_obj"&&s.size>0)for(let u of s)c.push(`Key '${u}' is not defined in the object shape`);return c.length>0?{errors:c}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function X(e){return{...$(e),e:"extends_object"}}function Y(e){return e.t}function ee(e){return{...$(e),e:"strict_obj"}}function re(e,r){return $({...e.t,...r.t})}function ne(e,{checkKey:r,looseCheck:n}={}){return{...o,e:`record<string, ${e.e}>`,r(t,s){return i(this,t,s,()=>{if(!P(t))return!1;let a={},c=[];for(let[y,u]of Object.entries(t)){let p=`.${y}`;if(r&&!r(y)){c.push(h(`Key '${y}' is not allowed`,p));continue}let _=t[y],[d,l]=e.r(u,s);if(d)a[y]=_;else{let f=l;for(let b of f)c.push(h(b,p))}}if(c.length>0)if(n)s.warnings.push(...c);else return{errors:c};return{data:a}})}}}function m(e,r){if(typeof r=="string"&&!e.t?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function j(e,r,n,t=!1,s){let a=-1,c=[],y=[],u=new Set,p=n.path;for(let _ of e){a++;let d=Array.isArray(r)?r[a]:r,l=`[${a}]`;n.path=`${p}${l}`;let f=d.r(_,n),[b,g]=f,T=s?.unique;if(b&&T){let R=g,k=typeof T=="string";k&&(R=g[T]),u.has(R)?f=[!1,[k?h(`Type '${d.t?.[T]?.e}' with value "${R}" is not unique`,`.${T}`):`${d.e} value is not unique`]]:u.add(R)}let[x,w]=f;if(x)y.push(w);else if(t){c.push(w.map(R=>h(R,l)));continue}else return{errors:w.map(R=>h(R,l))}}if(c.length>0){if(y.length===0)return{errors:c.slice(0,5).flat()};n.warnings.push(...c.flat())}return{data:y}}function te(e,r){return m(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:j.call(this,n,e,t,!1,r):!1)}}}function se(e,r){return m(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:j.call(this,n,e,t,!0,r):!1)}}}function ae(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:j.call(this,r,e,n))}}}function O(e,r){let n={warnings:[],path:""},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function oe(e){return r=>O(r,e)}function ie(e,r){let n=O(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function C(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function ce(e){return r=>C(r,e)}function ue(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function le(e,r){return{...o,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function A(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function P(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}export{U as a,z as b,B as c,W as d,D as e,M as f,L as g,Z as h,G as i,H as j,J as k,v as l,Q as m,$ as n,X as o,Y as p,ee as q,re as r,ne as s,te as t,se as u,ae as v,O as w,oe as x,ie as y,C as z,ce as A,ue as B,le as C,F as D};