runcheck 0.22.0 → 0.24.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.
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},h=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of p(r))!d.call(e,n)&&n!==t&&u(e,n,{get:()=>r[n],enumerable:!(i=T(r,n))||i.enumerable});return e};var _=e=>h(u({},"__esModule",{value:!0}),e);var I={};R(I,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>N,rc_string_autofix:()=>P});module.exports=_(I);function b(e){return{...this,a:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function c(e,r){e.warnings.push(g(e,r))}function o(e,r,t,i){if(e.u&&r===void 0)return[!0,r];if(e.c&&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.a!==void 0)return c(t,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.f&&e.i){let s=e.i(r);if(s)return e.s&&!e.s(s.fixed)?[!1,[e.n(s.fixed)]]:(c(t,`Autofixed from error "${e.n(r)}"`),[!0,s.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,u:!0}}function $(e){return`Type '${O(e,!!this.y)}' is not assignable to '${this.e}'`}function j(){return{...this,l:!0,e:`${this.e}_or_null`}}function k(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var a={withFallback:b,where:w,optional:m,n:$,orNullish:k,withAutofix:x,orNull:j},q={...a,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},V={...a,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},E={...a,r(e,r){return o(this,e,r,()=>!0)},e:"any"},C={...a,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},l={...a,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},f={...a,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},y={...a,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},v={...a,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e,r){let t=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}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),N=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
+ "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var t in r)u(e,t,{get:r[t],enumerable:!0})},h=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of p(r))!d.call(e,n)&&n!==t&&u(e,n,{get:()=>r[n],enumerable:!(i=T(r,n))||i.enumerable});return e};var _=e=>h(u({},"__esModule",{value:!0}),e);var I={};R(I,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>N,rc_string_autofix:()=>P});module.exports=_(I);function b(e){return{...this,a:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function c(e,r){e.warnings.push(g(e,r))}function o(e,r,t,i){if(e.c&&r===void 0)return[!0,r];if(e.l&&r==null)return[!0,r];if(e.f&&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.a!==void 0)return c(t,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let s=e.i(r);if(s)return e.s&&!e.s(s.fixed)?[!1,[e.n(s.fixed)]]:(c(t,`Autofixed from error "${e.n(r)}"`),[!0,s.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function x(e){return{...this,y:!0,i:e}}function w(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function m(){return{...this,c:!0}}function $(e){return`Type '${O(e,!!this.T)}' is not assignable to '${this.e}'`}function j(){return{...this,f:!0,e:`${this.e}_or_null`}}function k(){return{...this,l:!0,e:`${this.e}_or_nullish`}}var a={withFallback:b,where:w,optional:m,n:$,orNullish:k,withAutofix:x,orNull:j},q={...a,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},E={...a,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},V={...a,r(e,r){return o(this,e,r,()=>!0)},e:"any"},C={...a,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},l={...a,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},f={...a,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},y={...a,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},v={...a,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function O(e,r){let t=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}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),N=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-KVFLPQIJ.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-DU6YZ7TW.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 q(e){return{...this,a:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function j(e,r){e.warnings.push(_(e,r))}function O(e,r){r.forEach(n=>j(e,n))}function c(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.l&&r==null)return[!0,r];if(e.f&&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.a!==void 0)return j(n,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:(j(n,`Autofixed from error "${e.n(r)}"`),[!0,a.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function E(e){return{...this,y:!0,i:e}}function V(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function N(){return{...this,c:!0}}function C(e){return`Type '${I(e,!!this.T)}' is not assignable to '${this.e}'`}function v(){return{...this,f:!0,e:`${this.e}_or_null`}}function K(){return{...this,l:!0,e:`${this.e}_or_nullish`}}var u={withFallback:q,where:V,optional:N,n:C,orNullish:K,withAutofix:E,orNull:v},B={...u,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},z={...u,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},D={...u,r(e,r){return c(this,e,r,()=>!0)},e:"any"},M={...u,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},L={...u,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Z={...u,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},G={...u,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},H={...u,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function J(e){return{...u,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{...u,r(r,n){return c(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},T:!0,e:e.length==1?`${I(e[0],!1)}_literal`:"literals"}}function X(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...u,r(r,n){return c(this,r,n,()=>{let s=n.path,t=[],a=0,i=0;for(let y of e){i+=1,y.u&&(n.path=`${s}|union ${i}|`);let[o,f]=y.r(r,n);if(o)return!0;y.u&&a<=3&&(a+=1,t.push(...f))}return n.path=s,t.length>0?{errors:t}:!1})},e:e.map(r=>r.e).join(" | ")}}function W(e,r){return{...r,o:e}}var Y=W;function k(e,{normalizeKeysFrom:r}={}){return{...u,t:e,e:"object",u:!0,r(n,s){return c(this,n,s,()=>{if(!S(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},i=[],y=s.path;for(let[o,f]of Object.entries(e)){let b=o,R=`.${o}`;s.path=`${y}${R}`;let T,p=o;if(f.o&&(T=n[f.o],p=f.o),T===void 0&&(T=n[o],p=o),T===void 0&&r==="snake_case"){let l=U(o);T=n[l],p=l}t?.delete(p);let[g,h]=f.r(T,s);if(g)a[b]=h;else{let l=h;for(let x of l)i.push(_(s,x))}}if(t&&t.size>0)for(let o of t)i.push(`Key '${o}' is not defined in the object shape`);return i.length>0?{errors:i}: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{...u,e:`record<string, ${e.e}>`,r(s,t){return c(this,s,t,()=>{if(!S(s))return!1;let a={},i=[],y=t.path;for(let[o,f]of Object.entries(s)){let b=`.${o}`,R=`${y}${b}`;if(t.path=R,r&&!r(o)){i.push(_(t,`Key '${o}' is not allowed`));continue}let T=s[o],[p,g]=e.r(f,t);if(p)a[o]=T;else{let h=g;for(let l of h)i.push(_(t,l))}}if(i.length>0)if(n)O(t,i);else return{errors:i};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 m(e,r,n,s=!1,t){let a=-1,i=[],y=[],o=new Set,f=n.path;for(let b of e){a++;let R=Array.isArray(r)?r[a]:r,T=`[${a}]`;n.path=`${f}${T}`;let p=R.r(b,n),[g,h]=p,l=t?.unique;if(g&&l){let d=h,w=typeof l=="string";w?d=h[l]:typeof l=="function"&&(d=l(h)),o.has(d)?(w&&(n.path=`${f}${T}.${l}`),p=[!1,[_(n,w?`Type '${R.t?.[l]?.e}' with value "${d}" is not unique`:typeof l=="function"?`Type '${R.e}' unique fn return with value "${d}" is not unique`:`${R.e} value is not unique`)]]):o.add(d)}let[x,$]=p;if(x)y.push($);else if(s){i.push($.map(d=>_(n,d)));continue}else return{errors:$.map(d=>_(n,d))}}if(i.length>0){if(y.length===0)return{errors:i.slice(0,5).flat()};O(n,i.flat())}return{data:y}}function ae(e,r){return P(e,r?.unique),{...u,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:m.call(this,n,e,s,!1,r):!1)}}}function oe(e,r){return P(e,r?.unique),{...u,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:m.call(this,n,e,s,!0,r):!1)}}}function ie(e){return{...u,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 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 ue(e){return r=>A(r,e)}function ce(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 F(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function le(e){return r=>F(r,e)}function ye(e){return{...u,e:"recursive",r(r,n){return e().r(r,n)}}}function fe(e,r){return{...u,e:`transform_from_${e.e}`,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function I(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 S(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,W 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,A as w,ue as x,ce as y,F 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 m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var F=(e,r)=>{for(var n in r)m(e,n,{get:r[n],enumerable:!0})},W=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of v(r))!K.call(e,t)&&t!==n&&m(e,t,{get:()=>r[t],enumerable:!(s=C(r,t))||s.enumerable});return e};var U=e=>W(m({},"__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:()=>ue,rc_instanceof:()=>te,rc_is_valid:()=>q,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:()=>I,rc_rename_key:()=>oe,rc_strict_obj:()=>ce,rc_string:()=>ee,rc_transform:()=>be,rc_tuple:()=>pe,rc_undefined:()=>H,rc_union:()=>ae,rc_unknown:()=>X,rc_validator:()=>he,snakeCase:()=>N});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 k(e,r){e.warnings.push(_(e,r))}function P(e,r){r.forEach(n=>k(e,n))}function u(e,r,n,s){if(e.u&&r===void 0)return[!0,r];if(e.c&&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 k(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)]]:(k(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,u:!0}}function L(e){return`Type '${V(e,!!this.f)}' is not assignable to '${this.e}'`}function Z(){return{...this,l:!0,e:`${this.e}_or_null`}}function G(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:B,where:D,optional:M,n:L,orNullish:G,withAutofix:z,orNull:Z},H={...o,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},J={...o,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},Q={...o,r(e,r){return u(this,e,r,()=>!0)},e:"any"},X={...o,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Y={...o,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ee={...o,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},re={...o,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ne={...o,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function te(e){return{...o,r(r,n){return u(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 u(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},f:!0,e:e.length==1?`${V(e[0],!1)}_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 u(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 I(e,r){return{...r,a:e}}var oe=I;function x(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",T:!0,r(n,s){return u(this,n,s,()=>{if(!E(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},c=[],h=s.path;for(let[i,p]of Object.entries(e)){let b=i,d=`.${i}`;s.path=`${h}${d}`;let y,f=i;if(p.a&&(y=n[p.a],f=p.a),y===void 0&&(y=n[i],f=i),y===void 0&&r==="snake_case"){let l=N(i);y=n[l],f=l}t?.delete(f);let[g,R]=p.r(y,s);if(g)a[b]=R;else{let l=R;for(let w of l)c.push(_(s,w))}}if(t&&t.size>0)for(let i of t)c.push(`Key '${i}' is not defined in the object shape`);return c.length>0?{errors:c}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ie(e){return{...x(e),e:"extends_object"}}function ue(e){return e.t}function ce(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 u(this,s,t,()=>{if(!E(s))return!1;let a={},c=[],h=t.path;for(let[i,p]of Object.entries(s)){let b=`.${i}`;if(t.path=`${h}${b}`,r&&!r(i)){c.push(_(t,`Key '${i}' is not allowed`));continue}let d=s[i],[y,f]=e.r(p,t);if(y)a[i]=d;else{let g=f;for(let R of g)c.push(_(t,R))}}if(c.length>0)if(n)P(t,c);else return{errors:c};return{data:a}})}}}function S(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,c=[],h=[],i=new Set,p=n.path;for(let b of e){a++;let d=Array.isArray(r)?r[a]:r,y=`[${a}]`;n.path=`${p}${y}`;let f=d.r(b,n),[g,R]=f,l=t?.unique;if(g&&l){let T=R,j=typeof l=="string";j?T=R[l]:typeof l=="function"&&(T=l(R)),i.has(T)?(j&&(n.path=`${p}${y}.${l}`),f=[!1,[_(n,j?`Type '${d.t?.[l]?.e}' with value "${T}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${T}" is not unique`:`${d.e} value is not unique`)]]):i.add(T)}let[w,$]=f;if(w)h.push($);else if(s){c.push($.map(T=>_(n,T)));continue}else return{errors:$.map(T=>_(n,T))}}if(c.length>0){if(h.length===0)return{errors:c.slice(0,5).flat()};P(n,c.flat())}return{data:h}}function fe(e,r){return S(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:O.call(this,n,e,s,!1,r):!1)}}}function Te(e,r){return S(e,r?.unique),{...o,e:`${e.e}[]`,r(n,s){return u(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 u(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 q(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function he(e){return r=>q(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 V(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 E(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("_")}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 C=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var W=(e,r)=>{for(var n in r)k(e,n,{get:r[n],enumerable:!0})},F=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of v(r))!K.call(e,t)&&t!==n&&k(e,t,{get:()=>r[t],enumerable:!(s=C(r,t))||s.enumerable});return e};var U=e=>F(k({},"__esModule",{value:!0}),e);var ge={};W(ge,{rc_any:()=>Q,rc_array:()=>fe,rc_boolean:()=>Y,rc_date:()=>ne,rc_extends_obj:()=>ie,rc_get_obj_schema:()=>ue,rc_instanceof:()=>te,rc_is_valid:()=>q,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:()=>P,rc_parser:()=>de,rc_record:()=>ye,rc_recursive:()=>_e,rc_rename_from_key:()=>I,rc_rename_key:()=>oe,rc_strict_obj:()=>ce,rc_string:()=>ee,rc_transform:()=>be,rc_tuple:()=>pe,rc_undefined:()=>H,rc_union:()=>ae,rc_unknown:()=>X,rc_validator:()=>he,snakeCase:()=>N});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 A(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.l&&r==null)return[!0,r];if(e.y&&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.f&&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,f:!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 '${E(e,!!this.T)}' is not assignable to '${this.e}'`}function Z(){return{...this,y:!0,e:`${this.e}_or_null`}}function G(){return{...this,l:!0,e:`${this.e}_or_nullish`}}var u={withFallback:B,where:D,optional:M,n:L,orNullish:G,withAutofix:z,orNull:Z},H={...u,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},J={...u,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},Q={...u,r(e,r){return c(this,e,r,()=>!0)},e:"any"},X={...u,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},Y={...u,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ee={...u,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},re={...u,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ne={...u,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function te(e){return{...u,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{...u,r(r,n){return c(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},T:!0,e:e.length==1?`${E(e[0],!1)}_literal`:"literals"}}function ae(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...u,r(r,n){return c(this,r,n,()=>{let s=n.path,t=[],a=0,i=0;for(let y of e){i+=1,y.u&&(n.path=`${s}|union ${i}|`);let[o,f]=y.r(r,n);if(o)return!0;y.u&&a<=3&&(a+=1,t.push(...f))}return n.path=s,t.length>0?{errors:t}:!1})},e:e.map(r=>r.e).join(" | ")}}function I(e,r){return{...r,a:e}}var oe=I;function x(e,{normalizeKeysFrom:r}={}){return{...u,t:e,e:"object",u:!0,r(n,s){return c(this,n,s,()=>{if(!V(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},i=[],y=s.path;for(let[o,f]of Object.entries(e)){let b=o,R=`.${o}`;s.path=`${y}${R}`;let T,p=o;if(f.a&&(T=n[f.a],p=f.a),T===void 0&&(T=n[o],p=o),T===void 0&&r==="snake_case"){let l=N(o);T=n[l],p=l}t?.delete(p);let[g,h]=f.r(T,s);if(g)a[b]=h;else{let l=h;for(let $ of l)i.push(_(s,$))}}if(t&&t.size>0)for(let o of t)i.push(`Key '${o}' is not defined in the object shape`);return i.length>0?{errors:i}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ie(e){return{...x(e),e:"extends_object"}}function ue(e){return e.t}function ce(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{...u,e:`record<string, ${e.e}>`,r(s,t){return c(this,s,t,()=>{if(!V(s))return!1;let a={},i=[],y=t.path;for(let[o,f]of Object.entries(s)){let b=`.${o}`,R=`${y}${b}`;if(t.path=R,r&&!r(o)){i.push(_(t,`Key '${o}' is not allowed`));continue}let T=s[o],[p,g]=e.r(f,t);if(p)a[o]=T;else{let h=g;for(let l of h)i.push(_(t,l))}}if(i.length>0)if(n)A(t,i);else return{errors:i};return{data:a}})}}}function S(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,i=[],y=[],o=new Set,f=n.path;for(let b of e){a++;let R=Array.isArray(r)?r[a]:r,T=`[${a}]`;n.path=`${f}${T}`;let p=R.r(b,n),[g,h]=p,l=t?.unique;if(g&&l){let d=h,j=typeof l=="string";j?d=h[l]:typeof l=="function"&&(d=l(h)),o.has(d)?(j&&(n.path=`${f}${T}.${l}`),p=[!1,[_(n,j?`Type '${R.t?.[l]?.e}' with value "${d}" is not unique`:typeof l=="function"?`Type '${R.e}' unique fn return with value "${d}" is not unique`:`${R.e} value is not unique`)]]):o.add(d)}let[$,w]=p;if($)y.push(w);else if(s){i.push(w.map(d=>_(n,d)));continue}else return{errors:w.map(d=>_(n,d))}}if(i.length>0){if(y.length===0)return{errors:i.slice(0,5).flat()};A(n,i.flat())}return{data:y}}function fe(e,r){return S(e,r?.unique),{...u,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 S(e,r?.unique),{...u,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{...u,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 P(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=>P(r,e)}function Re(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 q(e,r){let n={warnings:[],path:""};return!!r.r(e,n)[0]}function he(e){return r=>q(r,e)}function _e(e){return{...u,e:"recursive",r(r,n){return e().r(r,n)}}}function be(e,r){return{...u,e:`transform_from_${e.e}`,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function E(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 V(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("_")}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-KVFLPQIJ.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-DU6YZ7TW.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,7 +1,7 @@
1
1
  {
2
2
  "name": "runcheck",
3
3
  "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
- "version": "0.22.0",
4
+ "version": "0.24.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",
@@ -61,7 +61,7 @@
61
61
  "typescript": "^5.0.3",
62
62
  "v8-profiler-next": "^1.9.0",
63
63
  "vite": "^4.2.1",
64
- "vitest": "^0.29.8",
64
+ "vitest": "^0.30.0",
65
65
  "zod": "^3.21.4"
66
66
  }
67
67
  }
@@ -1 +0,0 @@
1
- function q(e){return{...this,a:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function j(e,r){e.warnings.push(_(e,r))}function O(e,r){r.forEach(n=>j(e,n))}function u(e,r,n,t){if(e.u&&r===void 0)return[!0,r];if(e.c&&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.a!==void 0)return j(n,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.f&&e.i){let a=e.i(r);if(a)return e.s&&!e.s(a.fixed)?[!1,[e.n(a.fixed)]]:(j(n,`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 E(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function N(){return{...this,u:!0}}function C(e){return`Type '${I(e,!!this.y)}' is not assignable to '${this.e}'`}function v(){return{...this,l:!0,e:`${this.e}_or_null`}}function K(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:q,where:E,optional:N,n:C,orNullish:K,withAutofix:V,orNull:v},B={...o,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},z={...o,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},D={...o,r(e,r){return u(this,e,r,()=>!0)},e:"any"},M={...o,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},L={...o,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Z={...o,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},G={...o,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},H={...o,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function J(e){return{...o,r(r,n){return u(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 u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},y:!0,e:e.length==1?`${I(e[0],!1)}_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 u(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,o:e}}var Y=F;function m(e,{normalizeKeysFrom:r}={}){return{...o,t:e,e:"object",T:!0,r(n,t){return u(this,n,t,()=>{if(!S(n))return!1;let s=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},c=[],h=t.path;for(let[i,p]of Object.entries(e)){let b=i,d=`.${i}`;t.path=`${h}${d}`;let y,f=i;if(p.o&&(y=n[p.o],f=p.o),y===void 0&&(y=n[i],f=i),y===void 0&&r==="snake_case"){let l=U(i);y=n[l],f=l}s?.delete(f);let[g,R]=p.r(y,t);if(g)a[b]=R;else{let l=R;for(let x of l)c.push(_(t,x))}}if(s&&s.size>0)for(let i of s)c.push(`Key '${i}' is not defined in the object shape`);return c.length>0?{errors:c}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ee(e){return{...m(e),e:"extends_object"}}function re(e){return e.t}function ne(e){return{...m(e),e:"strict_obj"}}function te(e,r){return m({...e.t,...r.t})}function se(e,{checkKey:r,looseCheck:n}={}){return{...o,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!S(t))return!1;let a={},c=[],h=s.path;for(let[i,p]of Object.entries(t)){let b=`.${i}`;if(s.path=`${h}${b}`,r&&!r(i)){c.push(_(s,`Key '${i}' is not allowed`));continue}let d=t[i],[y,f]=e.r(p,s);if(y)a[i]=d;else{let g=f;for(let R of g)c.push(_(s,R))}}if(c.length>0)if(n)O(s,c);else return{errors:c};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 k(e,r,n,t=!1,s){let a=-1,c=[],h=[],i=new Set,p=n.path;for(let b of e){a++;let d=Array.isArray(r)?r[a]:r,y=`[${a}]`;n.path=`${p}${y}`;let f=d.r(b,n),[g,R]=f,l=s?.unique;if(g&&l){let T=R,$=typeof l=="string";$?T=R[l]:typeof l=="function"&&(T=l(R)),i.has(T)?($&&(n.path=`${p}${y}.${l}`),f=[!1,[_(n,$?`Type '${d.t?.[l]?.e}' with value "${T}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${T}" is not unique`:`${d.e} value is not unique`)]]):i.add(T)}let[x,w]=f;if(x)h.push(w);else if(t){c.push(w.map(T=>_(n,T)));continue}else return{errors:w.map(T=>_(n,T))}}if(c.length>0){if(h.length===0)return{errors:c.slice(0,5).flat()};O(n,c.flat())}return{data:h}}function ae(e,r){return A(e,r?.unique),{...o,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 oe(e,r){return A(e,r?.unique),{...o,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 ie(e){return{...o,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 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 ue(e){return r=>P(r,e)}function ce(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 I(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 S(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,m 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,ue as x,ce as y,W as z,le as A,ye as B,fe as C,U as D};