runcheck 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-7UEXEHUI.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-USNZM5S6.js +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Runcheck
|
|
2
2
|
|
|
3
|
-
A lib for js/typescript runtime type checks with autofix support. Runcheck has the goal of being very lightweight
|
|
3
|
+
A lib for js/typescript runtime type checks with autofix support. Runcheck has the goal of being very lightweight and fast ⚡. Because of that, it has only around [1.7kb Gzipped](https://bundlephobia.com/package/runcheck), has no dependencies and is tree-shakeable!
|
|
4
|
+
|
|
5
|
+
Benchmarks:
|
|
6
|
+
|
|
7
|
+

|
|
4
8
|
|
|
5
9
|
Obs: Runcheck is in Beta and it's api can still change
|
|
6
10
|
|
package/dist/autofixable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as f,f as t,g as o}from"./chunk-
|
|
1
|
+
import{e as f,f as t,g as o}from"./chunk-7UEXEHUI.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,a:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function w(e,r){e.warnings.push(_(e,r))}function S(e,r){r.forEach(n=>w(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 o=t===!0?r:t.data;return e.s&&!e.s(o)?[!1,[e.n(o)]]:[!0,o]}if(e.a!==void 0)return w(n,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let o=e.i(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.n(o.fixed)]]:(w(n,`Autofixed from error "${e.n(r)}"`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function I(e){return{...this,y:!0,i:e}}function q(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function V(){return{...this,c:!0}}function N(e){return`Type '${k(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:C,where:q,optional:V,n:N,orNullish:K,withAutofix:I,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"},J={...u,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},L={...u,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},Z={...u,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},G={...u,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function H(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?k(e[0],!0):e.map(r=>k(r,!0)).join(" | ")}}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=[],o=0,i=0;for(let y of e){i+=1,y.u&&(n.path=`${s}|union ${i}|`),n.objErrShortCircuit=!0;let[a,f]=y.r(r,n);if(n.objErrShortCircuit=!1,a)return!0;y.u&&o<=2&&(o+=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 m(e,{normalizeKeysFrom:r}={}){return{...u,t:e,e:"object",u:!0,r(n,s){return c(this,n,s,()=>{if(!A(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,o={},i=[],y=s.path;for(let[a,f]of Object.entries(e)){let b=a,R=`.${a}`;s.path=`${y}${R}`;let T,p=a;if(f.o&&(T=n[f.o],p=f.o),T===void 0&&(T=n[a],p=a),T===void 0&&r==="snake_case"){let l=U(a);T=n[l],p=l}t?.delete(p);let[g,h]=f.r(T,s);if(g)o[b]=h;else{let l=h;for(let x of l)i.push(_(s,x));if(s.objErrShortCircuit)break}}if(t&&t.size>0)for(let a of t)i.push(`Key '${a}' is not defined in the object shape`);return i.length>0?{errors:i}:this.e.startsWith("extends_object")?{data:{...n,...o}}:{data:o}})}}}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{...u,e:`record<string, ${e.e}>`,r(s,t){return c(this,s,t,()=>{if(!A(s))return!1;let o={},i=[],y=t.path;for(let[a,f]of Object.entries(s)){let b=`.${a}`,R=`${y}${b}`;if(t.path=R,r&&!r(a)){i.push(_(t,`Key '${a}' is not allowed`));continue}let T=s[a],[p,g]=e.r(f,t);if(p)o[a]=T;else{let h=g;for(let l of h)i.push(_(t,l));if(t.objErrShortCircuit)break}}if(i.length>0)if(n)S(t,i);else return{errors:i};return{data:o}})}}}function E(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 o=-1,i=[],y=[],a=new Set,f=n.path;for(let b of e){o++;let R=Array.isArray(r)?r[o]:r,T=`[${o}]`;n.path=`${f}${T}`;let p=R.r(b,n),[g,h]=p,l=t?.unique;if(g&&l){let d=h,$=typeof l=="string";$?d=h[l]:typeof l=="function"&&(d=l(h)),a.has(d)?($&&(n.path=`${f}${T}.${l}`),p=[!1,[_(n,$?`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`)]]):a.add(d)}let[x,j]=p;if(x)y.push(j);else if(s){i.push(j.map(d=>_(n,d)));continue}else return{errors:j.map(d=>_(n,d))}}if(i.length>0){if(y.length===0)return{errors:i.slice(0,5).flat()};S(n,i.flat())}return{data:y}}function oe(e,r){return E(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 ae(e,r){return E(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 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:O.call(this,r,e,n))}}}function P(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1},[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=>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 F(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1};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,o]=e.r(n,s);return t?[!0,r(o)]:[!1,o]}}}function k(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 A(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("_")}function Te(e,r){try{let n=JSON.parse(e);return P(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${A(n)?n.message:""}`]}}}export{B as a,z as b,D as c,M as d,J as e,L as f,Z as g,G as h,H as i,Q as j,X as k,W as l,Y as m,m as n,ee as o,re as p,ne as q,te as r,se as s,oe as t,ae as u,ie as v,P as w,ue as x,ce as y,F as z,le as A,ye as B,fe as C,U as D,Te as E};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var W=(e,r)=>{for(var n in r)m(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&&m(e,t,{get:()=>r[t],enumerable:!(s=N(r,t))||s.enumerable});return e};var U=e=>F(m({},"__esModule",{value:!0}),e);var xe={};W(xe,{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:()=>
|
|
1
|
+
"use strict";var m=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var W=(e,r)=>{for(var n in r)m(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&&m(e,t,{get:()=>r[t],enumerable:!(s=N(r,t))||s.enumerable});return e};var U=e=>F(m({},"__esModule",{value:!0}),e);var xe={};W(xe,{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:()=>H,rc_number:()=>re,rc_obj_intersection:()=>le,rc_object:()=>x,rc_parse:()=>j,rc_parse_json:()=>ge,rc_parser:()=>de,rc_record:()=>ye,rc_recursive:()=>_e,rc_rename_from_key:()=>C,rc_rename_key:()=>ae,rc_strict_obj:()=>ce,rc_string:()=>ee,rc_transform:()=>be,rc_tuple:()=>pe,rc_undefined:()=>G,rc_union:()=>oe,rc_unknown:()=>X,rc_validator:()=>he,snakeCase:()=>V});module.exports=U(xe);function B(e){return{...this,a:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function O(e,r){e.warnings.push(_(e,r))}function E(e,r){r.forEach(n=>O(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 o=t===!0?r:t.data;return e.s&&!e.s(o)?[!1,[e.n(o)]]:[!0,o]}if(e.a!==void 0)return O(n,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.f&&e.i){let o=e.i(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.n(o.fixed)]]:(O(n,`Autofixed from error "${e.n(r)}"`),[!0,o.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 J(e){return`Type '${P(e,!!this.T)}' is not assignable to '${this.e}'`}function L(){return{...this,y:!0,e:`${this.e}_or_null`}}function Z(){return{...this,l:!0,e:`${this.e}_or_nullish`}}var u={withFallback:B,where:D,optional:M,n:J,orNullish:Z,withAutofix:z,orNull:L},G={...u,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},H={...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?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}function oe(...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=[],o=0,i=0;for(let y of e){i+=1,y.u&&(n.path=`${s}|union ${i}|`),n.objErrShortCircuit=!0;let[a,f]=y.r(r,n);if(n.objErrShortCircuit=!1,a)return!0;y.u&&o<=2&&(o+=1,t.push(...f))}return n.path=s,t.length>0?{errors:t}:!1})},e:e.map(r=>r.e).join(" | ")}}function C(e,r){return{...r,o:e}}var ae=C;function x(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,o={},i=[],y=s.path;for(let[a,f]of Object.entries(e)){let b=a,R=`.${a}`;s.path=`${y}${R}`;let T,p=a;if(f.o&&(T=n[f.o],p=f.o),T===void 0&&(T=n[a],p=a),T===void 0&&r==="snake_case"){let l=V(a);T=n[l],p=l}t?.delete(p);let[g,h]=f.r(T,s);if(g)o[b]=h;else{let l=h;for(let $ of l)i.push(_(s,$));if(s.objErrShortCircuit)break}}if(t&&t.size>0)for(let a of t)i.push(`Key '${a}' is not defined in the object shape`);return i.length>0?{errors:i}:this.e.startsWith("extends_object")?{data:{...n,...o}}:{data:o}})}}}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(!S(s))return!1;let o={},i=[],y=t.path;for(let[a,f]of Object.entries(s)){let b=`.${a}`,R=`${y}${b}`;if(t.path=R,r&&!r(a)){i.push(_(t,`Key '${a}' is not allowed`));continue}let T=s[a],[p,g]=e.r(f,t);if(p)o[a]=T;else{let h=g;for(let l of h)i.push(_(t,l));if(t.objErrShortCircuit)break}}if(i.length>0)if(n)E(t,i);else return{errors:i};return{data:o}})}}}function I(e,r){if(typeof r=="string"&&!e.t?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function A(e,r,n,s=!1,t){let o=-1,i=[],y=[],a=new Set,f=n.path;for(let b of e){o++;let R=Array.isArray(r)?r[o]:r,T=`[${o}]`;n.path=`${f}${T}`;let p=R.r(b,n),[g,h]=p,l=t?.unique;if(g&&l){let d=h,k=typeof l=="string";k?d=h[l]:typeof l=="function"&&(d=l(h)),a.has(d)?(k&&(n.path=`${f}${T}.${l}`),p=[!1,[_(n,k?`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`)]]):a.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()};E(n,i.flat())}return{data:y}}function fe(e,r){return I(e,r?.unique),{...u,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:A.call(this,n,e,s,!1,r):!1)}}}function Te(e,r){return I(e,r?.unique),{...u,e:`${e.e}[]`,r(n,s){return c(this,n,s,()=>Array.isArray(n)?n.length===0?!0:A.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:A.call(this,r,e,n))}}}function j(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1},[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=>j(r,e)}function Re(e,r){let n=j(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};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,o]=e.r(n,s);return t?[!0,r(o)]:[!1,o]}}}function P(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 V(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function ge(e,r){try{let n=JSON.parse(e);return j(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${S(n)?n.message:""}`]}}}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_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,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-
|
|
1
|
+
import{A,B,C,D,E,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-7UEXEHUI.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,E as rc_parse_json,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
package/dist/chunk-USNZM5S6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function C(e){return{...this,a:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function w(e,r){e.warnings.push(_(e,r))}function A(e,r){r.forEach(n=>w(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 o=t===!0?r:t.data;return e.s&&!e.s(o)?[!1,[e.n(o)]]:[!0,o]}if(e.a!==void 0)return w(n,`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.y&&e.i){let o=e.i(r);if(o)return e.s&&!e.s(o.fixed)?[!1,[e.n(o.fixed)]]:(w(n,`Autofixed from error "${e.n(r)}"`),[!0,o.fixed])}return[!1,t&&"errors"in t?t.errors:[e.n(r)]]}function I(e){return{...this,y:!0,i:e}}function q(e){return{...this,s:e,e:`${this.e}_with_predicate`}}function V(){return{...this,c:!0}}function N(e){return`Type '${E(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:C,where:q,optional:V,n:N,orNullish:K,withAutofix:I,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"},J={...u,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},L={...u,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},Z={...u,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},G={...u,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function H(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?`${E(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=[],o=0,i=0;for(let y of e){i+=1,y.u&&(n.path=`${s}|union ${i}|`),n.objErrShortCircuit=!0;let[a,f]=y.r(r,n);if(n.objErrShortCircuit=!1,a)return!0;y.u&&o<=2&&(o+=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(!P(n))return!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,o={},i=[],y=s.path;for(let[a,f]of Object.entries(e)){let b=a,R=`.${a}`;s.path=`${y}${R}`;let T,p=a;if(f.o&&(T=n[f.o],p=f.o),T===void 0&&(T=n[a],p=a),T===void 0&&r==="snake_case"){let l=U(a);T=n[l],p=l}t?.delete(p);let[g,h]=f.r(T,s);if(g)o[b]=h;else{let l=h;for(let x of l)i.push(_(s,x));if(s.objErrShortCircuit)break}}if(t&&t.size>0)for(let a of t)i.push(`Key '${a}' is not defined in the object shape`);return i.length>0?{errors:i}:this.e.startsWith("extends_object")?{data:{...n,...o}}:{data:o}})}}}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(!P(s))return!1;let o={},i=[],y=t.path;for(let[a,f]of Object.entries(s)){let b=`.${a}`,R=`${y}${b}`;if(t.path=R,r&&!r(a)){i.push(_(t,`Key '${a}' is not allowed`));continue}let T=s[a],[p,g]=e.r(f,t);if(p)o[a]=T;else{let h=g;for(let l of h)i.push(_(t,l));if(t.objErrShortCircuit)break}}if(i.length>0)if(n)A(t,i);else return{errors:i};return{data:o}})}}}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 m(e,r,n,s=!1,t){let o=-1,i=[],y=[],a=new Set,f=n.path;for(let b of e){o++;let R=Array.isArray(r)?r[o]:r,T=`[${o}]`;n.path=`${f}${T}`;let p=R.r(b,n),[g,h]=p,l=t?.unique;if(g&&l){let d=h,$=typeof l=="string";$?d=h[l]:typeof l=="function"&&(d=l(h)),a.has(d)?($&&(n.path=`${f}${T}.${l}`),p=[!1,[_(n,$?`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`)]]):a.add(d)}let[x,j]=p;if(x)y.push(j);else if(s){i.push(j.map(d=>_(n,d)));continue}else return{errors:j.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 oe(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:m.call(this,n,e,s,!1,r):!1)}}}function ae(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: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 O(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1},[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=>O(r,e)}function ce(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 F(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1};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,o]=e.r(n,s);return t?[!0,r(o)]:[!1,o]}}}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 P(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("_")}function Te(e,r){try{let n=JSON.parse(e);return O(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${P(n)?n.message:""}`]}}}export{B as a,z as b,D as c,M as d,J as e,L as f,Z as g,G as h,H 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,oe as t,ae as u,ie as v,O as w,ue as x,ce as y,F as z,le as A,ye as B,fe as C,U as D,Te as E};
|