runcheck 0.29.0 → 0.30.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
- import{e as f,f as t,g as o}from"./chunk-IMW5H7XS.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-2VUA7VF5.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 C(e){return{...this,c:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function k(e,r){e.warnings.push(j(e,r))}function P(e,r){r.forEach(n=>k(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||"data"in s)){let o=s===!0?r:s.data;return e.s&&!e.s(o)?[!1,[e.t(o)]]:[!0,o]}let a=e.c;if(a!==void 0)return k(n,`Fallback used, ${e.t(r)}`),[!0,U(a)?a():a];if(e.l&&e.a){let o=e.a(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.t(o.fixed)]]:(k(n,`Autofixed from error "${e.t(r)}"`),[!0,o.fixed])}return[!1,s&&"errors"in s?s.errors:[e.t(r)]]}function K(e){return{...this,l:!0,a:e}}function q(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function N(){return{...this,u:!0}}function V(e){return`Type '${m(e,!!this.p)}' is not assignable to '${this.e}'`}function v(){return{...this,f:!0,e:`${this.e}_or_null`}}function B(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var i={withFallback:C,where:q,optional:N,t:V,orNullish:B,withAutofix:K,orNull:v},M={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},z={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},J={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},L={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Z={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},G={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},H={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Q={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function X(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function Y(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},p:!0,e:e.length==1?m(e[0],!0):e.map(r=>m(r,!0)).join(" | ")}}var A=1;function ee(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let t=n.path,s=[],a=0,o=!1,p=[],y=0;for(let c of e){y+=1,c.i&&(n.path=`${t}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[d,T]=c.r(r,n);n.objErrShortCircuit=!1;let b=n.objErrKeyIndex;if(n.objErrKeyIndex=0,d)return!0;c.i&&b!==-1?b>0?p.push(...T):(a<A&&s.push(...T),a+=1):o=!0}return n.path=t,p.length>0||s.length>0?((a>A||o)&&s.push("not matches any other union member"),{errors:[...p,...s]}):!1})},e:e.map(r=>r.e).join(" | ")}}function F(e,r){return{...r,o:e}}var re=F;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",i:!0,r(n,t){return u(this,n,t,()=>{if(!S(n))return t.objErrKeyIndex=-1,!1;let s=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],p=t.path,y=-1;for(let[c,d]of Object.entries(e)){let T=c;y+=1;let b=`.${c}`;t.path=`${p}${b}`;let f,h=c;if(d.o&&(f=n[d.o],h=d.o),f===void 0&&(f=n[c],h=c),f===void 0&&r==="snake_case"){let g=D(c);f=n[g],h=g}s?.delete(h);let[_,l]=d.r(f,t);if(_)a[T]=l;else{let g=l;for(let x of g)o.push(j(t,x));if(t.objErrShortCircuit){t.objErrKeyIndex=y;break}}}if(s&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ne(e){return{...O(e),e:"extends_object"}}function te(e){return e.n}function se(e){return{...O(e),e:"strict_obj"}}function oe(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function ae(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return O(n)}function ie(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return O(n)}function ce(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!S(t))return!1;let a={},o=[],p=s.path;for(let[y,c]of Object.entries(t)){let d=`.${y}`,T=`${p}${d}`;if(s.path=T,r&&!r(y)){o.push(j(s,`Key '${y}' is not allowed`));continue}let b=t[y],[f,h]=e.r(c,s);if(f)a[y]=b;else{let _=h;for(let l of _)o.push(j(s,l));if(s.objErrShortCircuit)break}}if(o.length>0)if(n)P(s,o);else return{errors:o};return{data:a}})}}}function I(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function $(e,r,n,t=!1,s){let a=-1,o=[],p=[],y=new Set,c=n.path;for(let d of e){a++;let T=Array.isArray(r)?r[a]:r,b=`[${a}]`;n.path=`${c}${b}`;let f=T.r(d,n),[h,_]=f,l=s?.unique;if(h&&l){let R=_,w=typeof l=="string";w?R=_[l]:typeof l=="function"&&(R=l(_)),y.has(R)?(w&&(n.path=`${c}${b}.${l}`),f=[!1,[j(n,w?`Type '${T.n?.[l]?.e}' with value "${R}" is not unique`:typeof l=="function"?`Type '${T.e}' unique fn return with value "${R}" is not unique`:`${T.e} value is not unique`)]]):y.add(R)}let[g,x]=f;if(g)p.push(x);else if(t){o.push(x.map(R=>j(n,R)));continue}else return{errors:x.map(R=>j(n,R))}}if(o.length>0){if(p.length===0)return{errors:o.slice(0,5).flat()};P(n,o.flat())}return{data:p}}function ue(e,r){return I(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:$.call(this,n,e,t,!1,r):!1)}}}function ye(e,r){return I(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:$.call(this,n,e,t,!0,r):!1)}}}function le(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:$.call(this,r,e,n))}}}function E(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[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 fe(e){return r=>E(r,e)}function pe(e,r){let n=E(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:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function Te(e){return r=>W(r,e)}function de(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function Re(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function m(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 be(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function he(e,r){try{let n=JSON.parse(e);return E(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${S(n)?n.message:""}`]}}}function U(e){return typeof e=="function"}export{M as a,z as b,J as c,L as d,Z as e,G as f,H as g,Q as h,X as i,Y as j,ee as k,F as l,re as m,O as n,ne as o,te as p,se as q,oe as r,ae as s,ie as t,ce as u,ue as v,ye as w,le as x,E as y,fe as z,pe as A,W as B,Te as C,de as D,Re as E,be as F,D as G,he as H};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var m=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var B=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))!B.call(e,t)&&t!==n&&m(e,t,{get:()=>r[t],enumerable:!(s=V(r,t))||s.enumerable});return e};var D=e=>W(m({},"__esModule",{value:!0}),e);var me={};F(me,{rc_any:()=>X,rc_array:()=>de,rc_assert_is_valid:()=>Oe,rc_boolean:()=>ee,rc_date:()=>te,rc_extends_obj:()=>ce,rc_get_obj_schema:()=>ue,rc_instanceof:()=>se,rc_is_valid:()=>q,rc_literals:()=>oe,rc_loose_array:()=>Re,rc_loose_parse:()=>_e,rc_null:()=>Q,rc_number:()=>ne,rc_obj_intersection:()=>le,rc_obj_omit:()=>pe,rc_obj_pick:()=>fe,rc_object:()=>x,rc_parse:()=>w,rc_parse_json:()=>we,rc_parser:()=>he,rc_record:()=>Te,rc_recursive:()=>ge,rc_rename_from_key:()=>C,rc_rename_key:()=>ie,rc_strict_obj:()=>ye,rc_string:()=>re,rc_transform:()=>xe,rc_tuple:()=>be,rc_undefined:()=>H,rc_union:()=>ae,rc_unknown:()=>Y,rc_validator:()=>je,snakeCase:()=>N});module.exports=D(me);function U(e){return{...this,c:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function $(e,r){e.warnings.push(j(e,r))}function I(e,r){r.forEach(n=>$(e,n))}function u(e,r,n,s){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.s&&!e.s(o)?[!1,[e.t(o)]]:[!0,o]}let a=e.c;if(a!==void 0)return $(n,`Fallback used, ${e.t(r)}`),[!0,ke(a)?a():a];if(e.f&&e.a){let o=e.a(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.t(o.fixed)]]:($(n,`Autofixed from error "${e.t(r)}"`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.t(r)]]}function M(e){return{...this,f:!0,a:e}}function z(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function J(){return{...this,u:!0}}function L(e){return`Type '${E(e,!!this.p)}' is not assignable to '${this.e}'`}function Z(){return{...this,l:!0,e:`${this.e}_or_null`}}function G(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var i={withFallback:U,where:z,optional:J,t:L,orNullish:G,withAutofix:M,orNull:Z},H={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},Q={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},X={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Y={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},ee={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},re={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},ne={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},te={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function se(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function oe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},p:!0,e:e.length==1?E(e[0],!0):e.map(r=>E(r,!0)).join(" | ")}}var P=1;function ae(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let s=n.path,t=[],a=0,o=!1,p=[],y=0;for(let c of e){y+=1,c.i&&(n.path=`${s}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[d,T]=c.r(r,n);n.objErrShortCircuit=!1;let b=n.objErrKeyIndex;if(n.objErrKeyIndex=0,d)return!0;c.i?b>0?p.push(...T):(a<P&&t.push(...T),a+=1):o=!0}return n.path=s,p.length>0||t.length>0?((a>P||o)&&t.push("not matches any other union member"),{errors:[...p,...t]}):!1})},e:e.map(r=>r.e).join(" | ")}}function C(e,r){return{...r,o:e}}var ie=C;function x(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",i:!0,r(n,s){return u(this,n,s,()=>{if(!A(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],p=s.path,y=-1;for(let[c,d]of Object.entries(e)){let T=c;y+=1;let b=`.${c}`;s.path=`${p}${b}`;let f,h=c;if(d.o&&(f=n[d.o],h=d.o),f===void 0&&(f=n[c],h=c),f===void 0&&r==="snake_case"){let g=N(c);f=n[g],h=g}t?.delete(h);let[_,l]=d.r(f,s);if(_)a[T]=l;else{let g=l;for(let O of g)o.push(j(s,O));if(s.objErrShortCircuit){s.objErrKeyIndex=y;break}}}if(t&&t.size>0)for(let c of t)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ce(e){return{...x(e),e:"extends_object"}}function ue(e){return e.n}function ye(e){return{...x(e),e:"strict_obj"}}function le(...e){let r={};for(let n of e)Object.assign(r,n.n);return x(r)}function fe(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let s of r){let t=e.n[s];t&&(n[s]=t)}return x(n)}function pe(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let s of Object.keys(e.n))r.includes(s)||(n[s]=e.n[s]);return x(n)}function Te(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(s,t){return u(this,s,t,()=>{if(!A(s))return!1;let a={},o=[],p=t.path;for(let[y,c]of Object.entries(s)){let d=`.${y}`,T=`${p}${d}`;if(t.path=T,r&&!r(y)){o.push(j(t,`Key '${y}' is not allowed`));continue}let b=s[y],[f,h]=e.r(c,t);if(f)a[y]=b;else{let _=h;for(let l of _)o.push(j(t,l));if(t.objErrShortCircuit)break}}if(o.length>0)if(n)I(t,o);else return{errors:o};return{data:a}})}}}function K(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function S(e,r,n,s=!1,t){let a=-1,o=[],p=[],y=new Set,c=n.path;for(let d of e){a++;let T=Array.isArray(r)?r[a]:r,b=`[${a}]`;n.path=`${c}${b}`;let f=T.r(d,n),[h,_]=f,l=t?.unique;if(h&&l){let R=_,k=typeof l=="string";k?R=_[l]:typeof l=="function"&&(R=l(_)),y.has(R)?(k&&(n.path=`${c}${b}.${l}`),f=[!1,[j(n,k?`Type '${T.n?.[l]?.e}' with value "${R}" is not unique`:typeof l=="function"?`Type '${T.e}' unique fn return with value "${R}" is not unique`:`${T.e} value is not unique`)]]):y.add(R)}let[g,O]=f;if(g)p.push(O);else if(s){o.push(O.map(R=>j(n,R)));continue}else return{errors:O.map(R=>j(n,R))}}if(o.length>0){if(p.length===0)return{errors:o.slice(0,5).flat()};I(n,o.flat())}return{data:p}}function de(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!1,r):!1)}}}function Re(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!0,r):!1)}}}function be(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function w(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[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 he(e){return r=>w(r,e)}function _e(e,r){let n=w(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:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function je(e){return r=>q(r,e)}function ge(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function xe(e,r){return{...i,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 Oe(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function A(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 we(e,r){try{let n=JSON.parse(e);return w(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${A(n)?n.message:""}`]}}}function ke(e){return typeof e=="function"}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,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_obj_omit,rc_obj_pick,rc_object,rc_parse,rc_parse_json,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 m=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var B=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))!B.call(e,t)&&t!==n&&m(e,t,{get:()=>r[t],enumerable:!(s=V(r,t))||s.enumerable});return e};var D=e=>W(m({},"__esModule",{value:!0}),e);var me={};F(me,{rc_any:()=>X,rc_array:()=>de,rc_assert_is_valid:()=>Oe,rc_boolean:()=>ee,rc_date:()=>te,rc_extends_obj:()=>ce,rc_get_obj_schema:()=>ue,rc_instanceof:()=>se,rc_is_valid:()=>q,rc_literals:()=>oe,rc_loose_array:()=>Re,rc_loose_parse:()=>_e,rc_null:()=>Q,rc_number:()=>ne,rc_obj_intersection:()=>le,rc_obj_omit:()=>pe,rc_obj_pick:()=>fe,rc_object:()=>x,rc_parse:()=>w,rc_parse_json:()=>we,rc_parser:()=>he,rc_record:()=>Te,rc_recursive:()=>ge,rc_rename_from_key:()=>C,rc_rename_key:()=>ie,rc_strict_obj:()=>ye,rc_string:()=>re,rc_transform:()=>xe,rc_tuple:()=>be,rc_undefined:()=>H,rc_union:()=>ae,rc_unknown:()=>Y,rc_validator:()=>je,snakeCase:()=>N});module.exports=D(me);function U(e){return{...this,c:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function $(e,r){e.warnings.push(j(e,r))}function I(e,r){r.forEach(n=>$(e,n))}function u(e,r,n,s){if(e.u&&r===void 0)return[!0,r];if(e.y&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||"data"in t)){let o=t===!0?r:t.data;return e.s&&!e.s(o)?[!1,[e.t(o)]]:[!0,o]}let a=e.c;if(a!==void 0)return $(n,`Fallback used, ${e.t(r)}`),[!0,ke(a)?a():a];if(e.f&&e.a){let o=e.a(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.t(o.fixed)]]:($(n,`Autofixed from error "${e.t(r)}"`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.t(r)]]}function M(e){return{...this,f:!0,a:e}}function z(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function J(){return{...this,u:!0}}function L(e){return`Type '${E(e,!!this.p)}' is not assignable to '${this.e}'`}function Z(){return{...this,l:!0,e:`${this.e}_or_null`}}function G(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var i={withFallback:U,where:z,optional:J,t:L,orNullish:G,withAutofix:M,orNull:Z},H={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},Q={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},X={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},Y={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},ee={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},re={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},ne={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},te={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function se(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function oe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},p:!0,e:e.length==1?E(e[0],!0):e.map(r=>E(r,!0)).join(" | ")}}var P=1;function ae(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let s=n.path,t=[],a=0,o=!1,p=[],y=0;for(let c of e){y+=1,c.i&&(n.path=`${s}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[d,T]=c.r(r,n);n.objErrShortCircuit=!1;let b=n.objErrKeyIndex;if(n.objErrKeyIndex=0,d)return!0;c.i&&b!==-1?b>0?p.push(...T):(a<P&&t.push(...T),a+=1):o=!0}return n.path=s,p.length>0||t.length>0?((a>P||o)&&t.push("not matches any other union member"),{errors:[...p,...t]}):!1})},e:e.map(r=>r.e).join(" | ")}}function C(e,r){return{...r,o:e}}var ie=C;function x(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",i:!0,r(n,s){return u(this,n,s,()=>{if(!A(n))return s.objErrKeyIndex=-1,!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],p=s.path,y=-1;for(let[c,d]of Object.entries(e)){let T=c;y+=1;let b=`.${c}`;s.path=`${p}${b}`;let f,h=c;if(d.o&&(f=n[d.o],h=d.o),f===void 0&&(f=n[c],h=c),f===void 0&&r==="snake_case"){let g=N(c);f=n[g],h=g}t?.delete(h);let[_,l]=d.r(f,s);if(_)a[T]=l;else{let g=l;for(let O of g)o.push(j(s,O));if(s.objErrShortCircuit){s.objErrKeyIndex=y;break}}}if(t&&t.size>0)for(let c of t)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ce(e){return{...x(e),e:"extends_object"}}function ue(e){return e.n}function ye(e){return{...x(e),e:"strict_obj"}}function le(...e){let r={};for(let n of e)Object.assign(r,n.n);return x(r)}function fe(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let s of r){let t=e.n[s];t&&(n[s]=t)}return x(n)}function pe(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let s of Object.keys(e.n))r.includes(s)||(n[s]=e.n[s]);return x(n)}function Te(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(s,t){return u(this,s,t,()=>{if(!A(s))return!1;let a={},o=[],p=t.path;for(let[y,c]of Object.entries(s)){let d=`.${y}`,T=`${p}${d}`;if(t.path=T,r&&!r(y)){o.push(j(t,`Key '${y}' is not allowed`));continue}let b=s[y],[f,h]=e.r(c,t);if(f)a[y]=b;else{let _=h;for(let l of _)o.push(j(t,l));if(t.objErrShortCircuit)break}}if(o.length>0)if(n)I(t,o);else return{errors:o};return{data:a}})}}}function K(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function S(e,r,n,s=!1,t){let a=-1,o=[],p=[],y=new Set,c=n.path;for(let d of e){a++;let T=Array.isArray(r)?r[a]:r,b=`[${a}]`;n.path=`${c}${b}`;let f=T.r(d,n),[h,_]=f,l=t?.unique;if(h&&l){let R=_,k=typeof l=="string";k?R=_[l]:typeof l=="function"&&(R=l(_)),y.has(R)?(k&&(n.path=`${c}${b}.${l}`),f=[!1,[j(n,k?`Type '${T.n?.[l]?.e}' with value "${R}" is not unique`:typeof l=="function"?`Type '${T.e}' unique fn return with value "${R}" is not unique`:`${T.e} value is not unique`)]]):y.add(R)}let[g,O]=f;if(g)p.push(O);else if(s){o.push(O.map(R=>j(n,R)));continue}else return{errors:O.map(R=>j(n,R))}}if(o.length>0){if(p.length===0)return{errors:o.slice(0,5).flat()};I(n,o.flat())}return{data:p}}function de(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!1,r):!1)}}}function Re(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!0,r):!1)}}}function be(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function w(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[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 he(e){return r=>w(r,e)}function _e(e,r){let n=w(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:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function je(e){return r=>q(r,e)}function ge(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function xe(e,r){return{...i,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 Oe(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function A(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 we(e,r){try{let n=JSON.parse(e);return w(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${A(n)?n.message:""}`]}}}function ke(e){return typeof e=="function"}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,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_obj_omit,rc_obj_pick,rc_object,rc_parse,rc_parse_json,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,E,F,G,H,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-IMW5H7XS.js";export{c as rc_any,v as rc_array,F as rc_assert_is_valid,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,B as rc_is_valid,j as rc_literals,w as rc_loose_array,A as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,t as rc_obj_omit,s as rc_obj_pick,n as rc_object,y as rc_parse,H as rc_parse_json,z as rc_parser,u as rc_record,D as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,E as rc_transform,x as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,C as rc_validator,G as snakeCase};
1
+ import{A,B,C,D,E,F,G,H,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-2VUA7VF5.js";export{c as rc_any,v as rc_array,F as rc_assert_is_valid,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,B as rc_is_valid,j as rc_literals,w as rc_loose_array,A as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,t as rc_obj_omit,s as rc_obj_pick,n as rc_object,y as rc_parse,H as rc_parse_json,z as rc_parser,u as rc_record,D as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,E as rc_transform,x as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,C as rc_validator,G 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.29.0",
4
+ "version": "0.30.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",
@@ -1 +0,0 @@
1
- function C(e){return{...this,c:e}}function j(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function k(e,r){e.warnings.push(j(e,r))}function P(e,r){r.forEach(n=>k(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||"data"in s)){let o=s===!0?r:s.data;return e.s&&!e.s(o)?[!1,[e.t(o)]]:[!0,o]}let a=e.c;if(a!==void 0)return k(n,`Fallback used, ${e.t(r)}`),[!0,U(a)?a():a];if(e.l&&e.a){let o=e.a(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.t(o.fixed)]]:(k(n,`Autofixed from error "${e.t(r)}"`),[!0,o.fixed])}return[!1,s&&"errors"in s?s.errors:[e.t(r)]]}function K(e){return{...this,l:!0,a:e}}function q(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function N(){return{...this,u:!0}}function V(e){return`Type '${m(e,!!this.p)}' is not assignable to '${this.e}'`}function v(){return{...this,f:!0,e:`${this.e}_or_null`}}function B(){return{...this,y:!0,e:`${this.e}_or_nullish`}}var i={withFallback:C,where:q,optional:N,t:V,orNullish:B,withAutofix:K,orNull:v},M={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},z={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},J={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},L={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Z={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},G={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},H={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},Q={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function X(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function Y(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},p:!0,e:e.length==1?m(e[0],!0):e.map(r=>m(r,!0)).join(" | ")}}var A=1;function ee(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let t=n.path,s=[],a=0,o=!1,p=[],y=0;for(let c of e){y+=1,c.i&&(n.path=`${t}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[d,T]=c.r(r,n);n.objErrShortCircuit=!1;let b=n.objErrKeyIndex;if(n.objErrKeyIndex=0,d)return!0;c.i?b>0?p.push(...T):(a<A&&s.push(...T),a+=1):o=!0}return n.path=t,p.length>0||s.length>0?((a>A||o)&&s.push("not matches any other union member"),{errors:[...p,...s]}):!1})},e:e.map(r=>r.e).join(" | ")}}function F(e,r){return{...r,o:e}}var re=F;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",i:!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={},o=[],p=t.path,y=-1;for(let[c,d]of Object.entries(e)){let T=c;y+=1;let b=`.${c}`;t.path=`${p}${b}`;let f,h=c;if(d.o&&(f=n[d.o],h=d.o),f===void 0&&(f=n[c],h=c),f===void 0&&r==="snake_case"){let g=D(c);f=n[g],h=g}s?.delete(h);let[_,l]=d.r(f,t);if(_)a[T]=l;else{let g=l;for(let x of g)o.push(j(t,x));if(t.objErrShortCircuit){t.objErrKeyIndex=y;break}}}if(s&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o}:this.e.startsWith("extends_object")?{data:{...n,...a}}:{data:a}})}}}function ne(e){return{...O(e),e:"extends_object"}}function te(e){return e.n}function se(e){return{...O(e),e:"strict_obj"}}function oe(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function ae(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return O(n)}function ie(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return O(n)}function ce(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!S(t))return!1;let a={},o=[],p=s.path;for(let[y,c]of Object.entries(t)){let d=`.${y}`,T=`${p}${d}`;if(s.path=T,r&&!r(y)){o.push(j(s,`Key '${y}' is not allowed`));continue}let b=t[y],[f,h]=e.r(c,s);if(f)a[y]=b;else{let _=h;for(let l of _)o.push(j(s,l));if(s.objErrShortCircuit)break}}if(o.length>0)if(n)P(s,o);else return{errors:o};return{data:a}})}}}function I(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function $(e,r,n,t=!1,s){let a=-1,o=[],p=[],y=new Set,c=n.path;for(let d of e){a++;let T=Array.isArray(r)?r[a]:r,b=`[${a}]`;n.path=`${c}${b}`;let f=T.r(d,n),[h,_]=f,l=s?.unique;if(h&&l){let R=_,w=typeof l=="string";w?R=_[l]:typeof l=="function"&&(R=l(_)),y.has(R)?(w&&(n.path=`${c}${b}.${l}`),f=[!1,[j(n,w?`Type '${T.n?.[l]?.e}' with value "${R}" is not unique`:typeof l=="function"?`Type '${T.e}' unique fn return with value "${R}" is not unique`:`${T.e} value is not unique`)]]):y.add(R)}let[g,x]=f;if(g)p.push(x);else if(t){o.push(x.map(R=>j(n,R)));continue}else return{errors:x.map(R=>j(n,R))}}if(o.length>0){if(p.length===0)return{errors:o.slice(0,5).flat()};P(n,o.flat())}return{data:p}}function ue(e,r){return I(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:$.call(this,n,e,t,!1,r):!1)}}}function ye(e,r){return I(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:$.call(this,n,e,t,!0,r):!1)}}}function le(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:$.call(this,r,e,n))}}}function E(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[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 fe(e){return r=>E(r,e)}function pe(e,r){let n=E(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:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function Te(e){return r=>W(r,e)}function de(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function Re(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function m(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 be(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function D(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function he(e,r){try{let n=JSON.parse(e);return E(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${S(n)?n.message:""}`]}}}function U(e){return typeof e=="function"}export{M as a,z as b,J as c,L as d,Z as e,G as f,H as g,Q as h,X as i,Y as j,ee as k,F as l,re as m,O as n,ne as o,te as p,se as q,oe as r,ae as s,ie as t,ce as u,ue as v,ye as w,le as x,E as y,fe as z,pe as A,W as B,Te as C,de as D,Re as E,be as F,D as G,he as H};