runcheck 0.46.0 → 0.48.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 CHANGED
@@ -4,7 +4,7 @@ A lib for js/typescript runtime type checks with autofix support. Runcheck has t
4
4
 
5
5
  Benchmarks:
6
6
 
7
- ![Benchmarks](image.png)
7
+ ![Benchmarks](imgs/image.png)
8
8
 
9
9
  Obs: Runcheck is in Beta and it's api can still change
10
10
 
@@ -405,6 +405,25 @@ const schema = rc_transform(
405
405
  )
406
406
  ```
407
407
 
408
+ ## Tranformed types which result can be validated with same schema
409
+
410
+ You may want to create a transformed type which result can be validated with the same schema. For this you can use the `rc_narrow` type. Example:
411
+
412
+ ```ts
413
+ const stringOrArrayOfStrings = rc_union(rc_string, rc_array(rc_string))
414
+
415
+ const schema = rc_narrow(stringOrArrayOfStrings, (input) =>
416
+ Array.isArray(input) ? input : [input],
417
+ )
418
+
419
+ const result = rc_parse('hello', schema)
420
+
421
+ if (result.ok) {
422
+ // the schema can safely be used to validate the result too
423
+ const transformedResult = rc_parse(result.data, schema)
424
+ }
425
+ ```
426
+
408
427
  # Default types
409
428
 
410
429
  You can use `rc_default` to provide a default value if the input is `undefined`.
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)f(e,n,{get:r[n],enumerable:!0})},P=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&f(e,t,{get:()=>r[t],enumerable:!(o=R(r,t))||o.enumerable});return e};var w=e=>P(f({},"__esModule",{value:!0}),e);var W={};m(W,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>S,rc_string_autofix:()=>I});module.exports=w(W);function k(e){return{...this,j:e}}function u(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function c(e,r){e.l.push(r.startsWith("$")?r:u(e,r))}function s(e,r,n,o){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let t=o();if(t&&(t===!0||!t.errors)){let i=t===!0?r:t.data;return e.c&&!e.c(i)?[!1,[u(n,`Predicate failed for type '${e.e}'`)]]:[!0,i]}if(!n.i){let i=e.j;if(i!==void 0)return c(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,O(i)?i():i];if(e.g&&e.h){let l=e.h(r);if(l)return e.c&&!e.c(l.fixed)?[!1,[u(n,`Predicate failed for autofix in type '${e.e}'`)]]:(c(n,`Autofixed from error "${y(t,n,e,r)}"`),[!0,l.fixed])}}return[!1,t?t.errors:[u(n,T(e,r))]]}function y(e,r,n,o){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,o)}function x(e){return{...this,g:!0,h:e}}function $(e){return{...this,c:e}}function d(){return{...this,T:!0}}function T(e,r){return`Type '${j(r,!!e.k)}' is not assignable to '${e.e}'`}function E(){return{...this,p:!0,e:`${this.e}_or_null`}}function N(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var a={__rc_type:void 0,withFallback:k,where:$,optional:d,optionalKey:d,orNullish:N,withAutofix:x,orNull:E,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,y:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},C={...a,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},K={...a,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},q={...a,r(e,r){return s(this,e,r,()=>!0)},e:"any"},V={...a,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},p={...a,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...a,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},h={...a,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...a,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e,r){let n=typeof e,o=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(o==="string"||o==="number"||o==="boolean")?`${o}(${e})`:o}function O(e){return typeof e=="function"}var A=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),I=_.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),S=h.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
1
+ "use strict";var f=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var m=(e,r)=>{for(var n in r)f(e,n,{get:r[n],enumerable:!0})},w=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!g.call(e,t)&&t!==n&&f(e,t,{get:()=>r[t],enumerable:!(o=R(r,t))||o.enumerable});return e};var P=e=>w(f({},"__esModule",{value:!0}),e);var W={};m(W,{rc_boolean_autofix:()=>O,rc_number_autofix:()=>S,rc_string_autofix:()=>A});module.exports=P(W);function k(e){return{...this,j:e}}function u(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function c(e,r){e.l.push(r.startsWith("$")?r:u(e,r))}function s(e,r,n,o){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let t=o();if(t&&(t===!0||!t.errors)){let i=t===!0?r:t.data;return e.c&&!e.c(i)?[!1,[u(n,`Predicate failed for type '${e.e}'`)]]:[!0,i]}if(!n.i){let i=e.j;if(i!==void 0)return c(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,I(i)?i():i];if(e.g&&e.h){let l=e.h(r);if(l)return e.c&&!e.c(l.fixed)?[!1,[u(n,`Predicate failed for autofix in type '${e.e}'`)]]:(c(n,`Autofixed from error "${y(t,n,e,r)}"`),[!0,l.fixed])}}return[!1,t?t.errors:[u(n,T(e,r))]]}function y(e,r,n,o){return e?e.errors.map(t=>t.replace(r.n,"")).join("; "):T(n,o)}function x(e){return{...this,g:!0,h:e}}function $(e){return{...this,c:e}}function d(){return{...this,T:!0}}function T(e,r){return`Type '${j(r,!!e.k)}' is not assignable to '${e.e}'`}function N(){return{...this,p:!0,e:`${this.e}_or_null`}}function E(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var a={__rc_type:void 0,withFallback:k,where:$,optional:d,optionalKey:d,orNullish:E,withAutofix:x,orNull:N,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,f:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},C={...a,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},K={...a,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},q={...a,r(e,r){return s(this,e,r,()=>!0)},e:"any"},V={...a,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},p={...a,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_={...a,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},h={...a,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...a,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function j(e,r){let n=typeof e,o=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(o==="string"||o==="number"||o==="boolean")?`${o}(${e})`:o}function I(e){return typeof e=="function"}var O=p.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),A=_.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),S=h.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
@@ -1 +1 @@
1
- import{r as f,s as t,t as o}from"./chunk-55WVY724.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{r as f,s as t,t as o}from"./chunk-AGB5O5CP.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
@@ -0,0 +1 @@
1
+ function V(e,r){return{...r,f:e}}function D(e){return x(e)&&"__rc_type"in e}function W(e){if(D(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=W(o);return{...f,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return y(this,t,o,()=>{if(!x(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let T=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[l]of this.u)s.has(l)?s.delete(l):T.push(d(o,`Key '${l}' is missing`));for(let l of s)T.push(d(o,`Key '${l}' is not defined in the object shape`));return{data:void 0,errors:T}}let c={},i=[],u=o.n,p=-1;for(let[T,l]of this.u){let _=T;p+=1;let h=`.${T}`,g=`${u}${h}`;o.n=g;let R,b=T;if(l.f&&(R=t[l.f],b=l.f),R===void 0&&(R=t[T],b=T),R===void 0&&r==="snake_case"){let O=N(T);R=t[O],b=O}s?.delete(b);let[E,k]=l.r(R,o);if(E)c[_]=k;else{for(let O of k)o.n=g,i.push(O);if(o.o){o.a=p;break}}}if(s&&s.size>0)for(let T of s)o.n=u,i.push(d(o,`Key '${T}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...c}}:{errors:!1,data:c}})}}}function M(e,r){return{...j(e,r),e:"extends_object",b:!0}}function z(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function L(e,r){return{...j(e,r),e:"strict_obj"}}function Q(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function J(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function Z(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return j(n)}function G(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return j(n)}function H(){return(e,r)=>j(e,r)}function X(e){return{...this,j:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function S(e,r){e.l.push(r.startsWith("$")?r:d(e,r))}function B(e,r){r.forEach(n=>S(e,n))}function y(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return S(n,`Fallback used, errors -> ${v(o,n,e,r)}`),[!0,I(a)?a():a];if(e.g&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(S(n,`Autofixed from error "${v(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,F(e,r))]]}function v(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):F(n,t)}function Y(e){return{...this,g:!0,h:e}}function ee(e){return{...this,c:e}}function q(){return{...this,T:!0}}function F(e,r){return`Type '${w(r,!!e.k)}' is not assignable to '${e.e}'`}function re(){return{...this,p:!0,e:`${this.e}_or_null`}}function ne(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var f={__rc_type:void 0,withFallback:X,where:ee,optional:q,optionalKey:q,orNullish:ne,withAutofix:Y,orNull:re,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,f:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},Te={...f,r(e,r){return y(this,e,r,()=>e===void 0)},e:"undefined"},pe={...f,r(e,r){return y(this,e,r,()=>e===null)},e:"null"},de={...f,r(e,r){return y(this,e,r,()=>!0)},e:"any"},Re={...f,r(e,r){return y(this,e,r,()=>!0)},e:"unknown"},_e={...f,r(e,r){return y(this,e,r,()=>typeof e=="boolean")},e:"boolean"},he={...f,r(e,r){return y(this,e,r,()=>typeof e=="string")},e:"string"},be={...f,r(e,r){return y(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},je={...f,r(e,r){return y(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ge(e){return{...f,r(r,n){return y(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ke(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...f,r(r,n){return y(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var C=1;function Oe(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...f,r(r,n){return y(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,c=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let p=n.o;n.o=!0,n.a=0;let[T,l]=u.r(r,n),_=n.a;if(n.o=p,n.a=0,T)return!0;u._&&_!==-1?_>0?c.push(...l):(a<C&&o.push(...l),a+=1):s=!0}return n.n=t,c.length>0||o.length>0?((a>C||s)&&o.push(d(n,"not matches any other union member")),{errors:[...c,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function me(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function xe(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function te(e,{checkKey:r,looseCheck:n}={}){return{...f,e:`record<string, ${e.e}>`,r(t,o){return y(this,t,o,()=>{if(!x(t))return!1;let a={},s=[],c=o.n;for(let[i,u]of Object.entries(t)){let p=`.${i}`,T=`${c}${p}`;if(o.n=T,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let l=t[i],[_,h]=e.r(u,o);if(_)a[i]=l;else{let g=h;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)B(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function we(e,{checkKey:r}={}){return te(e,{checkKey:r,looseCheck:!0})}function P(e,r,n,t=!1,o){let a=t&&!n.i&&!n.y,s=o?.unique,c=[],i=[],u=s?new Set:void 0,p=n.n,T=Array.isArray(r),l=-1;for(let _ of e){l++;let h=T?r[l]:r,g=`[${l}]`,R=`${p}${g}`;n.n=R;let b=h.r(_,n),[E,k]=b;if(n.n=R,E&&u){let m=k,A=typeof s=="string";A?m=k[s]:typeof s=="function"&&(m=s(k)),u.has(m)?(A&&(n.n=`${p}${g}.${s}`),b=[!1,[d(n,A?`Type '${h.t?.[s]?.e}' with value "${m}" is not unique`:typeof s=="function"?`Type '${h.e}' unique fn return with value "${m}" is not unique`:`${h.e} value is not unique`)]]):u.add(m)}let[O,$]=b;if(O)i.push($);else if(a){c.push($);continue}else return{errors:$,data:void 0}}if(c.length>0){if(i.length===0)return{errors:c.slice(0,5).flat(),data:void 0};B(n,c.flat())}return{errors:!1,data:i}}function Pe(e,r){return{...f,e:`${e.e}[]`,R:e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1,r):!1)}}}function Ee(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function $e(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.y;t.y=!0;let a=e.r(n,t);return t.y=o,a}}}function Ae(e,r){return{...f,R:e,e:`${e.e}[]`,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!0,r):!1)}}}function Se(e){return{...f,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return y(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:P.call(this,r,e,n))}}}function K(e,r,{noWarnings:n=!1}={}){let t={l:[],n:"",o:!1,a:0,i:n,s:!1,y:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ke(e){return r=>K(r,e)}function Ie(e,r,n){let t=K(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function oe(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,y:!1};return!!r.r(e,n)[0]}function We(e){return r=>oe(r,e)}function Ne(e){return{...f,e:"recursive",r(r,n){return e().r(r,n)}}}function U(e,r,n,t){let o=e.n,a=e.o,s=e.s,c=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.s=!0,e.i=!0);let i=r.r(n,e);return e.s=s,e.i=c,e.n=o,e.o=a,i}function se(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,p]=U(a,n,o,t);if(u)return[!0,p];s=p}let[c,i]=e.r(o,a);return c?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function ve(e,r){return se(e,r)}function qe(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,p]=U(a,n,o,t);if(u)return[!0,p];s=p}let[c,i]=e.r(o,a);if(c){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[d(a,u.errors)]:u.errors.map(p=>d(a,p))]}return[!1,[...s||[],...i]]}}}function w(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Ce(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function N(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Be(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return K(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${x(t)?t.message:""}`]}}}function I(e){return typeof e=="function"}export{V as a,j as b,M as c,z as d,L as e,Q as f,J as g,Z as h,G as i,H as j,d as k,y as l,f as m,Te as n,pe as o,de as p,Re as q,_e as r,he as s,be as t,je as u,ge as v,ke as w,Oe as x,me as y,xe as z,te as A,we as B,Pe as C,Ee as D,$e as E,Ae as F,Se as G,K as H,Ke as I,Ie as J,oe as K,We as L,Ne as M,se as N,ve as O,qe as P,Ce as Q,x as R,N as S,Be as T};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var S=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var te=(e,r)=>{for(var n in r)S(e,n,{get:r[n],enumerable:!0})},oe=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of re(r))!ne.call(e,o)&&o!==n&&S(e,o,{get:()=>r[o],enumerable:!(t=ee(r,o))||t.enumerable});return e};var se=e=>oe(S({},"__esModule",{value:!0}),e);var Be={};te(Be,{defaultProps:()=>y,getWarningOrErrorWithPath:()=>p,isObject:()=>k,parse:()=>c,rc_any:()=>de,rc_array:()=>Pe,rc_assert_is_valid:()=>Ce,rc_boolean:()=>Re,rc_date:()=>be,rc_default:()=>Oe,rc_disable_loose_array:()=>Ee,rc_enable_obj_strict:()=>U,rc_get_array_item_type:()=>we,rc_get_obj_schema:()=>B,rc_instanceof:()=>je,rc_is_valid:()=>X,rc_literals:()=>ge,rc_loose_array:()=>$e,rc_loose_parse:()=>Se,rc_loose_record:()=>xe,rc_null:()=>Te,rc_nullish_default:()=>me,rc_number:()=>he,rc_obj_builder:()=>z,rc_obj_extends:()=>q,rc_obj_merge:()=>V,rc_obj_omit:()=>M,rc_obj_pick:()=>D,rc_obj_strict:()=>F,rc_object:()=>_,rc_parse:()=>E,rc_parse_json:()=>qe,rc_parser:()=>Ke,rc_record:()=>H,rc_recursive:()=>We,rc_rename_from_key:()=>N,rc_string:()=>_e,rc_transform:()=>ve,rc_tuple:()=>Ae,rc_undefined:()=>le,rc_union:()=>ke,rc_unknown:()=>pe,rc_unsafe_transform:()=>Ne,rc_validator:()=>Ie,snakeCase:()=>I});module.exports=se(Be);function N(e,r){return{...r,f:e}}function ae(e){return k(e)&&"__rc_type"in e}function C(e){if(ae(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=C(t);return _(r)}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=C(o);return{...y,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!k(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let T=[];if(o.o)return{data:void 0,errors:[p(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[l]of this.u)s.has(l)?s.delete(l):T.push(p(o,`Key '${l}' is missing`));for(let l of s)T.push(p(o,`Key '${l}' is not defined in the object shape`));return{data:void 0,errors:T}}let f={},i=[],u=o.n,d=-1;for(let[T,l]of this.u){let h=T;d+=1;let b=`.${T}`,g=`${u}${b}`;o.n=g;let R,j=T;if(l.f&&(R=t[l.f],j=l.f),R===void 0&&(R=t[T],j=T),R===void 0&&r==="snake_case"){let m=I(T);R=t[m],j=m}s?.delete(j);let[$,O]=l.r(R,o);if($)f[h]=O;else{for(let m of O)o.n=g,i.push(m);if(o.o){o.a=d;break}}}if(s&&s.size>0)for(let T of s)o.n=u,i.push(p(o,`Key '${T}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...f}}:{errors:!1,data:f}})}}}function q(e,r){return{..._(e,r),e:"extends_object",b:!0}}function B(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function F(e,r){return{..._(e,r),e:"strict_obj"}}function U(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function V(...e){let r={};for(let n of e)Object.assign(r,n.t);return _(r)}function D(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return _(n)}function M(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return _(n)}function z(){return(e,r)=>_(e,r)}function ie(e){return{...this,j:e}}function p(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function W(e,r){e.l.push(r.startsWith("$")?r:p(e,r))}function Z(e,r){r.forEach(n=>W(e,n))}function c(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[p(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return W(n,`Fallback used, errors -> ${L(o,n,e,r)}`),[!0,v(a)?a():a];if(e.g&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[p(n,`Predicate failed for autofix in type '${e.e}'`)]]:(W(n,`Autofixed from error "${L(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[p(n,G(e,r))]]}function L(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):G(n,t)}function ue(e){return{...this,g:!0,h:e}}function ce(e){return{...this,c:e}}function Q(){return{...this,T:!0}}function G(e,r){return`Type '${P(r,!!e.k)}' is not assignable to '${e.e}'`}function ye(){return{...this,p:!0,e:`${this.e}_or_null`}}function fe(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var y={__rc_type:void 0,withFallback:ie,where:ce,optional:Q,optionalKey:Q,orNullish:fe,withAutofix:ue,orNull:ye,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,f:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},le={...y,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},Te={...y,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},de={...y,r(e,r){return c(this,e,r,()=>!0)},e:"any"},pe={...y,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},Re={...y,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_e={...y,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},he={...y,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},be={...y,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function je(e){return{...y,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ge(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...y,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var J=1;function ke(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...y,r(r,n){return c(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,f=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let d=n.o;n.o=!0,n.a=0;let[T,l]=u.r(r,n),h=n.a;if(n.o=d,n.a=0,T)return!0;u._&&h!==-1?h>0?f.push(...l):(a<J&&o.push(...l),a+=1):s=!0}return n.n=t,f.length>0||o.length>0?((a>J||s)&&o.push(p(n,"not matches any other union member")),{errors:[...f,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Oe(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function me(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:v(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function H(e,{checkKey:r,looseCheck:n}={}){return{...y,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!k(t))return!1;let a={},s=[],f=o.n;for(let[i,u]of Object.entries(t)){let d=`.${i}`,T=`${f}${d}`;if(o.n=T,r&&!r(i)){s.push(p(o,`Key '${i}' is not allowed`));continue}let l=t[i],[h,b]=e.r(u,o);if(h)a[i]=l;else{let g=b;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)Z(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function xe(e,{checkKey:r}={}){return H(e,{checkKey:r,looseCheck:!0})}function w(e,r,n,t=!1,o){let a=t&&!n.i&&!n.y,s=o?.unique,f=[],i=[],u=s?new Set:void 0,d=n.n,T=Array.isArray(r),l=-1;for(let h of e){l++;let b=T?r[l]:r,g=`[${l}]`,R=`${d}${g}`;n.n=R;let j=b.r(h,n),[$,O]=j;if(n.n=R,$&&u){let x=O,K=typeof s=="string";K?x=O[s]:typeof s=="function"&&(x=s(O)),u.has(x)?(K&&(n.n=`${d}${g}.${s}`),j=[!1,[p(n,K?`Type '${b.t?.[s]?.e}' with value "${x}" is not unique`:typeof s=="function"?`Type '${b.e}' unique fn return with value "${x}" is not unique`:`${b.e} value is not unique`)]]):u.add(x)}let[m,A]=j;if(m)i.push(A);else if(a){f.push(A);continue}else return{errors:A,data:void 0}}if(f.length>0){if(i.length===0)return{errors:f.slice(0,5).flat(),data:void 0};Z(n,f.flat())}return{errors:!1,data:i}}function Pe(e,r){return{...y,e:`${e.e}[]`,R:e,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!1,r):!1)}}}function we(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function Ee(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.y;t.y=!0;let a=e.r(n,t);return t.y=o,a}}}function $e(e,r){return{...y,R:e,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!0,r):!1)}}}function Ae(e){return{...y,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:w.call(this,r,e,n))}}}function E(e,r,{noWarnings:n=!1}={}){let t={l:[],n:"",o:!1,a:0,i:n,s:!1,y:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ke(e){return r=>E(r,e)}function Se(e,r,n){let t=E(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function X(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,y:!1};return!!r.r(e,n)[0]}function Ie(e){return r=>X(r,e)}function We(e){return{...y,e:"recursive",r(r,n){return e().r(r,n)}}}function Y(e,r,n,t){let o=e.n,a=e.o,s=e.s,f=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.s=!0,e.i=!0);let i=r.r(n,e);return e.s=s,e.i=f,e.n=o,e.o=a,i}function ve(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=Y(a,n,o,t);if(u)return[!0,d];s=d}let[f,i]=e.r(o,a);return f?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function Ne(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=Y(a,n,o,t);if(u)return[!0,d];s=d}let[f,i]=e.r(o,a);if(f){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[p(a,u.errors)]:u.errors.map(d=>p(a,d))]}return[!1,[...s||[],...i]]}}}function P(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Ce(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function qe(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${P(e,!0)}`]};let t=JSON.parse(e);return E(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${k(t)?t.message:""}`]}}}function v(e){return typeof e=="function"}0&&(module.exports={defaultProps,getWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_disable_loose_array,rc_enable_obj_strict,rc_get_array_item_type,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
1
+ "use strict";var K=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var oe=(e,r)=>{for(var n in r)K(e,n,{get:r[n],enumerable:!0})},se=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ne(r))!te.call(e,o)&&o!==n&&K(e,o,{get:()=>r[o],enumerable:!(t=re(r,o))||t.enumerable});return e};var ae=e=>se(K({},"__esModule",{value:!0}),e);var Fe={};oe(Fe,{defaultProps:()=>y,getWarningOrErrorWithPath:()=>d,isObject:()=>k,parse:()=>c,rc_any:()=>de,rc_array:()=>Pe,rc_assert_is_valid:()=>Ce,rc_boolean:()=>_e,rc_date:()=>je,rc_default:()=>me,rc_disable_loose_array:()=>$e,rc_enable_obj_strict:()=>U,rc_get_array_item_type:()=>Ee,rc_get_obj_schema:()=>B,rc_instanceof:()=>ge,rc_is_valid:()=>X,rc_literals:()=>ke,rc_loose_array:()=>Ae,rc_loose_parse:()=>Ie,rc_loose_record:()=>we,rc_narrow:()=>ve,rc_null:()=>pe,rc_nullish_default:()=>xe,rc_number:()=>be,rc_obj_builder:()=>z,rc_obj_extends:()=>C,rc_obj_merge:()=>V,rc_obj_omit:()=>M,rc_obj_pick:()=>D,rc_obj_strict:()=>F,rc_object:()=>_,rc_parse:()=>E,rc_parse_json:()=>Be,rc_parser:()=>Ke,rc_record:()=>H,rc_recursive:()=>Ne,rc_rename_from_key:()=>v,rc_string:()=>he,rc_transform:()=>ee,rc_tuple:()=>Se,rc_undefined:()=>Te,rc_union:()=>Oe,rc_unknown:()=>Re,rc_unsafe_transform:()=>qe,rc_validator:()=>We,snakeCase:()=>I});module.exports=ae(Fe);function v(e,r){return{...r,f:e}}function ie(e){return k(e)&&"__rc_type"in e}function q(e){if(ie(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=q(t);return _(r)}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=q(o);return{...y,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return c(this,t,o,()=>{if(!k(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let T=[];if(o.o)return{data:void 0,errors:[d(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[l]of this.u)s.has(l)?s.delete(l):T.push(d(o,`Key '${l}' is missing`));for(let l of s)T.push(d(o,`Key '${l}' is not defined in the object shape`));return{data:void 0,errors:T}}let f={},i=[],u=o.n,p=-1;for(let[T,l]of this.u){let h=T;p+=1;let b=`.${T}`,g=`${u}${b}`;o.n=g;let R,j=T;if(l.f&&(R=t[l.f],j=l.f),R===void 0&&(R=t[T],j=T),R===void 0&&r==="snake_case"){let m=I(T);R=t[m],j=m}s?.delete(j);let[$,O]=l.r(R,o);if($)f[h]=O;else{for(let m of O)o.n=g,i.push(m);if(o.o){o.a=p;break}}}if(s&&s.size>0)for(let T of s)o.n=u,i.push(d(o,`Key '${T}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...f}}:{errors:!1,data:f}})}}}function C(e,r){return{..._(e,r),e:"extends_object",b:!0}}function B(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function F(e,r){return{..._(e,r),e:"strict_obj"}}function U(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function V(...e){let r={};for(let n of e)Object.assign(r,n.t);return _(r)}function D(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return _(n)}function M(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return _(n)}function z(){return(e,r)=>_(e,r)}function ue(e){return{...this,j:e}}function d(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function W(e,r){e.l.push(r.startsWith("$")?r:d(e,r))}function Z(e,r){r.forEach(n=>W(e,n))}function c(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.p&&r==null)return[!0,r];if(e.d&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[d(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return W(n,`Fallback used, errors -> ${L(o,n,e,r)}`),[!0,N(a)?a():a];if(e.g&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[d(n,`Predicate failed for autofix in type '${e.e}'`)]]:(W(n,`Autofixed from error "${L(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[d(n,G(e,r))]]}function L(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):G(n,t)}function ce(e){return{...this,g:!0,h:e}}function ye(e){return{...this,c:e}}function Q(){return{...this,T:!0}}function G(e,r){return`Type '${w(r,!!e.k)}' is not assignable to '${e.e}'`}function fe(){return{...this,d:!0,e:`${this.e}_or_null`}}function le(){return{...this,p:!0,e:`${this.e}_or_nullish`}}var y={__rc_type:void 0,withFallback:ue,where:ye,optional:Q,optionalKey:Q,orNullish:le,withAutofix:ce,orNull:fe,R:void 0,j:void 0,c:void 0,T:!1,d:!1,p:!1,g:!1,k:!1,f:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},Te={...y,r(e,r){return c(this,e,r,()=>e===void 0)},e:"undefined"},pe={...y,r(e,r){return c(this,e,r,()=>e===null)},e:"null"},de={...y,r(e,r){return c(this,e,r,()=>!0)},e:"any"},Re={...y,r(e,r){return c(this,e,r,()=>!0)},e:"unknown"},_e={...y,r(e,r){return c(this,e,r,()=>typeof e=="boolean")},e:"boolean"},he={...y,r(e,r){return c(this,e,r,()=>typeof e=="string")},e:"string"},be={...y,r(e,r){return c(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},je={...y,r(e,r){return c(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ge(e){return{...y,r(r,n){return c(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ke(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...y,r(r,n){return c(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var J=1;function Oe(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...y,r(r,n){return c(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,f=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let p=n.o;n.o=!0,n.a=0;let[T,l]=u.r(r,n),h=n.a;if(n.o=p,n.a=0,T)return!0;u._&&h!==-1?h>0?f.push(...l):(a<J&&o.push(...l),a+=1):s=!0}return n.n=t,f.length>0||o.length>0?((a>J||s)&&o.push(d(n,"not matches any other union member")),{errors:[...f,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function me(e,r){return{...e,T:!1,p:!1,d:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:N(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function xe(e,r){return{...e,T:!1,p:!1,d:!1,r(n,t){return c(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:N(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function H(e,{checkKey:r,looseCheck:n}={}){return{...y,e:`record<string, ${e.e}>`,r(t,o){return c(this,t,o,()=>{if(!k(t))return!1;let a={},s=[],f=o.n;for(let[i,u]of Object.entries(t)){let p=`.${i}`,T=`${f}${p}`;if(o.n=T,r&&!r(i)){s.push(d(o,`Key '${i}' is not allowed`));continue}let l=t[i],[h,b]=e.r(u,o);if(h)a[i]=l;else{let g=b;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)Z(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function we(e,{checkKey:r}={}){return H(e,{checkKey:r,looseCheck:!0})}function P(e,r,n,t=!1,o){let a=t&&!n.i&&!n.y,s=o?.unique,f=[],i=[],u=s?new Set:void 0,p=n.n,T=Array.isArray(r),l=-1;for(let h of e){l++;let b=T?r[l]:r,g=`[${l}]`,R=`${p}${g}`;n.n=R;let j=b.r(h,n),[$,O]=j;if(n.n=R,$&&u){let x=O,S=typeof s=="string";S?x=O[s]:typeof s=="function"&&(x=s(O)),u.has(x)?(S&&(n.n=`${p}${g}.${s}`),j=[!1,[d(n,S?`Type '${b.t?.[s]?.e}' with value "${x}" is not unique`:typeof s=="function"?`Type '${b.e}' unique fn return with value "${x}" is not unique`:`${b.e} value is not unique`)]]):u.add(x)}let[m,A]=j;if(m)i.push(A);else if(a){f.push(A);continue}else return{errors:A,data:void 0}}if(f.length>0){if(i.length===0)return{errors:f.slice(0,5).flat(),data:void 0};Z(n,f.flat())}return{errors:!1,data:i}}function Pe(e,r){return{...y,e:`${e.e}[]`,R:e,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1,r):!1)}}}function Ee(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function $e(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.y;t.y=!0;let a=e.r(n,t);return t.y=o,a}}}function Ae(e,r){return{...y,R:e,e:`${e.e}[]`,r(n,t){return c(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!0,r):!1)}}}function Se(e){return{...y,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return c(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:P.call(this,r,e,n))}}}function E(e,r,{noWarnings:n=!1}={}){let t={l:[],n:"",o:!1,a:0,i:n,s:!1,y:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ke(e){return r=>E(r,e)}function Ie(e,r,n){let t=E(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function X(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,y:!1};return!!r.r(e,n)[0]}function We(e){return r=>X(r,e)}function Ne(e){return{...y,e:"recursive",r(r,n){return e().r(r,n)}}}function Y(e,r,n,t){let o=e.n,a=e.o,s=e.s,f=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.s=!0,e.i=!0);let i=r.r(n,e);return e.s=s,e.i=f,e.n=o,e.o=a,i}function ee(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,p]=Y(a,n,o,t);if(u)return[!0,p];s=p}let[f,i]=e.r(o,a);return f?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function ve(e,r){return ee(e,r)}function qe(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...y,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,p]=Y(a,n,o,t);if(u)return[!0,p];s=p}let[f,i]=e.r(o,a);if(f){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[d(a,u.errors)]:u.errors.map(p=>d(a,p))]}return[!1,[...s||[],...i]]}}}function w(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Ce(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Be(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let t=JSON.parse(e);return E(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${k(t)?t.message:""}`]}}}function N(e){return typeof e=="function"}0&&(module.exports={defaultProps,getWarningOrErrorWithPath,isObject,parse,rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,rc_disable_loose_array,rc_enable_obj_strict,rc_get_array_item_type,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_loose_record,rc_narrow,rc_null,rc_nullish_default,rc_number,rc_obj_builder,rc_obj_extends,rc_obj_merge,rc_obj_omit,rc_obj_pick,rc_obj_strict,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_unsafe_transform,rc_validator,snakeCase});
@@ -35,10 +35,16 @@ declare function rc_obj_merge<A extends AnyObj, B extends AnyObj, C extends AnyO
35
35
  declare function rc_obj_merge<A extends AnyObj, B extends AnyObj, C extends AnyObj, D extends AnyObj>(...objs: [RcType<A>, RcType<B>, RcType<C>, RcType<D>]): RcType<Extends<Extends<Extends<A, B>, C>, D>>;
36
36
  declare function rc_obj_pick<O extends AnyObj, K extends keyof O>(obj: RcType<O>, keys: K[]): RcType<Pick<O, K>>;
37
37
  declare function rc_obj_omit<O extends AnyObj, K extends keyof O>(obj: RcType<O>, keys: K[]): RcType<Pick<O, K>>;
38
- type StricTypeToRcType<T> = [T] extends [any[]] ? RcType<T> : [T] extends [Record<string, any>] ? ({
38
+ type RcTypeWithSquemaEqualTo<T> = {
39
+ __rc_type: T;
40
+ };
41
+ type StricTypeToRcType<T> = [T] extends [any[]] ? RcTypeWithSquemaEqualTo<T> : [T] extends [Record<string, any>] ? {
39
42
  [K in keyof T]-?: StricTypeToRcType<T[K]>;
40
- } & Partial<Record<keyof RcType<any>, never>>) | RcType<T> : RcType<T>;
41
- declare function rc_obj_builder<T extends Record<string, any>>(): <S extends StricTypeToRcType<T>>(schema: { [K in keyof S]: K extends keyof T ? S[K] : never; }, options?: ObjOptions) => RcType<T>;
43
+ } | RcTypeWithSquemaEqualTo<T> : RcTypeWithSquemaEqualTo<T>;
44
+ type StricTypeToRcTypeBase<T extends Record<string, any>> = {
45
+ [K in keyof T]-?: StricTypeToRcType<T[K]>;
46
+ };
47
+ declare function rc_obj_builder<T extends Record<string, any>>(): <S extends StricTypeToRcTypeBase<T>>(schema: { [K in keyof S]: K extends keyof T ? S[K] : never; }, options?: ObjOptions) => RcType<T>;
42
48
 
43
49
  type RcParseResult<T> = {
44
50
  error: false;
@@ -164,6 +170,8 @@ type TransformOptions<T> = {
164
170
  };
165
171
  /** validate a input or subset of input and transform the valid result */
166
172
  declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => Transformed, { outputSchema, disableStrictOutputSchema, }?: TransformOptions<Transformed>): RcType<Transformed>;
173
+ /** Create transforms which result can be validated with the same schema */
174
+ declare function rc_narrow<Input, Narrowed extends Input>(type: RcType<Input>, narrow: (input: Input, inputSchema: RcType<Input>) => Narrowed): RcType<Narrowed>;
167
175
  declare function rc_unsafe_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input, inputSchema: RcType<Input>) => {
168
176
  ok: true;
169
177
  data: Transformed;
@@ -188,4 +196,4 @@ type Prettify<T> = T extends Record<string, any> ? {
188
196
  } : T;
189
197
  type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
190
198
 
191
- export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, defaultProps, getWarningOrErrorWithPath, isObject, parse, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, rc_disable_loose_array, rc_enable_obj_strict, rc_get_array_item_type, rc_get_obj_shape as rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_loose_record, rc_null, rc_nullish_default, rc_number, rc_obj_builder, rc_obj_extends, rc_obj_merge, rc_obj_omit, rc_obj_pick, rc_obj_strict, rc_object, rc_parse, rc_parse_json, rc_parser, rc_record, rc_recursive, rc_rename_from_key, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_unsafe_transform, rc_validator };
199
+ export { RcBase, RcInferType, RcOptionalKeyType, RcParseResult, RcParser, RcPrettyInferType, RcType, defaultProps, getWarningOrErrorWithPath, isObject, parse, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, rc_disable_loose_array, rc_enable_obj_strict, rc_get_array_item_type, rc_get_obj_shape as rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_loose_record, rc_narrow, rc_null, rc_nullish_default, rc_number, rc_obj_builder, rc_obj_extends, rc_obj_merge, rc_obj_omit, rc_obj_pick, rc_obj_strict, rc_object, rc_parse, rc_parse_json, rc_parser, rc_record, rc_recursive, rc_rename_from_key, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_unsafe_transform, rc_validator };
package/dist/runcheck.js CHANGED
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,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-55WVY724.js";export{m as defaultProps,k as getWarningOrErrorWithPath,Q as isObject,l as parse,p as rc_any,C as rc_array,P as rc_assert_is_valid,r as rc_boolean,u as rc_date,y as rc_default,E as rc_disable_loose_array,f as rc_enable_obj_strict,D as rc_get_array_item_type,d as rc_get_obj_schema,v as rc_instanceof,K as rc_is_valid,w as rc_literals,F as rc_loose_array,J as rc_loose_parse,B as rc_loose_record,o as rc_null,z as rc_nullish_default,t as rc_number,j as rc_obj_builder,c as rc_obj_extends,g as rc_obj_merge,i as rc_obj_omit,h as rc_obj_pick,e as rc_obj_strict,b as rc_object,H as rc_parse,S as rc_parse_json,I as rc_parser,A as rc_record,M as rc_recursive,a as rc_rename_from_key,s as rc_string,N as rc_transform,G as rc_tuple,n as rc_undefined,x as rc_union,q as rc_unknown,O as rc_unsafe_transform,L as rc_validator,R as snakeCase};
1
+ import{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,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-AGB5O5CP.js";export{m as defaultProps,k as getWarningOrErrorWithPath,R as isObject,l as parse,p as rc_any,C as rc_array,Q as rc_assert_is_valid,r as rc_boolean,u as rc_date,y as rc_default,E as rc_disable_loose_array,f as rc_enable_obj_strict,D as rc_get_array_item_type,d as rc_get_obj_schema,v as rc_instanceof,K as rc_is_valid,w as rc_literals,F as rc_loose_array,J as rc_loose_parse,B as rc_loose_record,O as rc_narrow,o as rc_null,z as rc_nullish_default,t as rc_number,j as rc_obj_builder,c as rc_obj_extends,g as rc_obj_merge,i as rc_obj_omit,h as rc_obj_pick,e as rc_obj_strict,b as rc_object,H as rc_parse,T as rc_parse_json,I as rc_parser,A as rc_record,M as rc_recursive,a as rc_rename_from_key,s as rc_string,N as rc_transform,G as rc_tuple,n as rc_undefined,x as rc_union,q as rc_unknown,P as rc_unsafe_transform,L as rc_validator,S 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.46.0",
4
+ "version": "0.48.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "dist"
@@ -1 +0,0 @@
1
- function V(e,r){return{...r,y:e}}function D(e){return x(e)&&"__rc_type"in e}function W(e){if(D(e))return e;if(x(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=W(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,o]of Object.entries(e))n[t]=W(o);return{...f,t:n,e:"object",_:!0,u:Object.entries(n),r(t,o){return y(this,t,o,()=>{if(!x(t))return o.a=-1,!1;let s=this.e==="strict_obj"||o.s?new Set(Object.keys(t)):void 0;if(s&&s.size>this.u.length){o.a=-1;let T=[];if(o.o)return{data:void 0,errors:[p(o,`Expected strict object with ${this.u.length} keys but got ${s.size}`)]};for(let[l]of this.u)s.has(l)?s.delete(l):T.push(p(o,`Key '${l}' is missing`));for(let l of s)T.push(p(o,`Key '${l}' is not defined in the object shape`));return{data:void 0,errors:T}}let c={},i=[],u=o.n,d=-1;for(let[T,l]of this.u){let _=T;d+=1;let h=`.${T}`,g=`${u}${h}`;o.n=g;let R,b=T;if(l.y&&(R=t[l.y],b=l.y),R===void 0&&(R=t[T],b=T),R===void 0&&r==="snake_case"){let O=v(T);R=t[O],b=O}s?.delete(b);let[E,k]=l.r(R,o);if(E)c[_]=k;else{for(let O of k)o.n=g,i.push(O);if(o.o){o.a=d;break}}}if(s&&s.size>0)for(let T of s)o.n=u,i.push(p(o,`Key '${T}' is not defined in the object shape`));return i.length>0?{errors:i,data:void 0}:this.b?{errors:!1,data:{...t,...c}}:{errors:!1,data:c}})}}}function M(e,r){return{...j(e,r),e:"extends_object",b:!0}}function z(e){if(!e.t)throw new Error("type does not have an object shape");return e.t}function L(e,r){return{...j(e,r),e:"strict_obj"}}function Q(e,{nonRecursive:r}={}){if(r){if(!e.t)throw new Error("rc_enable_obj_strict: nonRecursive option can only be used on object types");return{...e,e:"strict_obj"}}return{...e,r(n,t){let o=t.s;t.s=!0;let a=e.r(n,t);return t.s=o,a}}}function J(...e){let r={};for(let n of e)Object.assign(r,n.t);return j(r)}function Z(e,r){let n={};if(!e.t)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let o=e.t[t];o&&(n[t]=o)}return j(n)}function G(e,r){let n={};if(!e.t)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.t))r.includes(t)||(n[t]=e.t[t]);return j(n)}function H(){return(e,r)=>j(e,r)}function X(e){return{...this,j:e}}function p(e,r){return`${e.n?`$${e.n}: `:""}${r}`}function K(e,r){e.l.push(r.startsWith("$")?r:p(e,r))}function B(e,r){r.forEach(n=>K(e,n))}function y(e,r,n,t){if(e.T&&r===void 0)return[!0,r];if(e.d&&r==null)return[!0,r];if(e.p&&r===null)return[!0,r];let o=t();if(o&&(o===!0||!o.errors)){let a=o===!0?r:o.data;return e.c&&!e.c(a)?[!1,[p(n,`Predicate failed for type '${e.e}'`)]]:[!0,a]}if(!n.i){let a=e.j;if(a!==void 0)return K(n,`Fallback used, errors -> ${N(o,n,e,r)}`),[!0,I(a)?a():a];if(e.g&&e.h){let s=e.h(r);if(s)return e.c&&!e.c(s.fixed)?[!1,[p(n,`Predicate failed for autofix in type '${e.e}'`)]]:(K(n,`Autofixed from error "${N(o,n,e,r)}"`),[!0,s.fixed])}}return[!1,o?o.errors:[p(n,F(e,r))]]}function N(e,r,n,t){return e?e.errors.map(o=>o.replace(r.n,"")).join("; "):F(n,t)}function Y(e){return{...this,g:!0,h:e}}function ee(e){return{...this,c:e}}function C(){return{...this,T:!0}}function F(e,r){return`Type '${P(r,!!e.k)}' is not assignable to '${e.e}'`}function re(){return{...this,p:!0,e:`${this.e}_or_null`}}function ne(){return{...this,d:!0,e:`${this.e}_or_nullish`}}var f={__rc_type:void 0,withFallback:X,where:ee,optional:C,optionalKey:C,orNullish:ne,withAutofix:Y,orNull:re,R:void 0,j:void 0,c:void 0,T:!1,p:!1,d:!1,g:!1,k:!1,y:void 0,h:void 0,t:void 0,_:!1,b:!1,u:[]},le={...f,r(e,r){return y(this,e,r,()=>e===void 0)},e:"undefined"},Te={...f,r(e,r){return y(this,e,r,()=>e===null)},e:"null"},de={...f,r(e,r){return y(this,e,r,()=>!0)},e:"any"},pe={...f,r(e,r){return y(this,e,r,()=>!0)},e:"unknown"},Re={...f,r(e,r){return y(this,e,r,()=>typeof e=="boolean")},e:"boolean"},_e={...f,r(e,r){return y(this,e,r,()=>typeof e=="string")},e:"string"},he={...f,r(e,r){return y(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},be={...f,r(e,r){return y(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function je(e){return{...f,r(r,n){return y(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ge(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...f,r(r,n){return y(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},k:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var q=1;function ke(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...f,r(r,n){return y(this,r,n,()=>{let t=n.n,o=[],a=0,s=!1,c=[],i=0;for(let u of e){i+=1,u._&&(n.n=`${t}|union ${i}|`);let d=n.o;n.o=!0,n.a=0;let[T,l]=u.r(r,n),_=n.a;if(n.o=d,n.a=0,T)return!0;u._&&_!==-1?_>0?c.push(...l):(a<q&&o.push(...l),a+=1):s=!0}return n.n=t,c.length>0||o.length>0?((a>q||s)&&o.push(p(n,"not matches any other union member")),{errors:[...c,...o],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Oe(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!==void 0?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_default`}}function me(e,r){return{...e,T:!1,d:!1,p:!1,r(n,t){return y(this,n,t,()=>{let o=e.r(n,t),[a,s]=o;return a?s!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:s}})},e:`${e.e}_nullish_default`}}function te(e,{checkKey:r,looseCheck:n}={}){return{...f,e:`record<string, ${e.e}>`,r(t,o){return y(this,t,o,()=>{if(!x(t))return!1;let a={},s=[],c=o.n;for(let[i,u]of Object.entries(t)){let d=`.${i}`,T=`${c}${d}`;if(o.n=T,r&&!r(i)){s.push(p(o,`Key '${i}' is not allowed`));continue}let l=t[i],[_,h]=e.r(u,o);if(_)a[i]=l;else{let g=h;for(let R of g)s.push(R);if(o.o)break}}if(s.length>0)if(n)B(o,s);else return{errors:s,data:void 0};return{errors:!1,data:a}})}}}function xe(e,{checkKey:r}={}){return te(e,{checkKey:r,looseCheck:!0})}function w(e,r,n,t=!1,o){let a=t&&!n.i&&!n.f,s=o?.unique,c=[],i=[],u=s?new Set:void 0,d=n.n,T=Array.isArray(r),l=-1;for(let _ of e){l++;let h=T?r[l]:r,g=`[${l}]`,R=`${d}${g}`;n.n=R;let b=h.r(_,n),[E,k]=b;if(n.n=R,E&&u){let m=k,A=typeof s=="string";A?m=k[s]:typeof s=="function"&&(m=s(k)),u.has(m)?(A&&(n.n=`${d}${g}.${s}`),b=[!1,[p(n,A?`Type '${h.t?.[s]?.e}' with value "${m}" is not unique`:typeof s=="function"?`Type '${h.e}' unique fn return with value "${m}" is not unique`:`${h.e} value is not unique`)]]):u.add(m)}let[O,$]=b;if(O)i.push($);else if(a){c.push($);continue}else return{errors:$,data:void 0}}if(c.length>0){if(i.length===0)return{errors:c.slice(0,5).flat(),data:void 0};B(n,c.flat())}return{errors:!1,data:i}}function Pe(e,r){return{...f,e:`${e.e}[]`,R:e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!1,r):!1)}}}function we(e){if(!e.R)throw new Error("Type does not have an item type");return e.R}function Ee(e,{nonRecursive:r=!1}={}){if(r){if(!e.e.endsWith("[]"))throw new Error("rc_disable_loose_array: nonRecursive option can only be used with array types");return{...e,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!1):!1)}}}return{...e,r(n,t){let o=t.f;t.f=!0;let a=e.r(n,t);return t.f=o,a}}}function $e(e,r){return{...f,R:e,e:`${e.e}[]`,r(n,t){return y(this,n,t,()=>Array.isArray(n)?n.length===0?!0:w.call(this,n,e,t,!0,r):!1)}}}function Ae(e){return{...f,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return y(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:w.call(this,r,e,n))}}}function S(e,r,{noWarnings:n=!1}={}){let t={l:[],n:"",o:!1,a:0,i:n,s:!1,f:!1},[o,a]=r.r(e,t);return o?{error:!1,ok:!0,data:a,warnings:t.l.length>0?t.l:!1}:{ok:!1,error:!0,errors:a}}function Ke(e){return r=>S(r,e)}function Se(e,r,n){let t=S(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function oe(e,r){let n={l:[],n:"",o:!1,a:0,i:!1,s:!1,f:!1};return!!r.r(e,n)[0]}function Ie(e){return r=>oe(r,e)}function We(e){return{...f,e:"recursive",r(r,n){return e().r(r,n)}}}function U(e,r,n,t){let o=e.n,a=e.o,s=e.s,c=e.i;e.o=!0,e.n=`${o}|output|`,t||(e.s=!0,e.i=!0);let i=r.r(n,e);return e.s=s,e.i=c,e.n=o,e.o=a,i}function ve(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=U(a,n,o,t);if(u)return[!0,d];s=d}let[c,i]=e.r(o,a);return c?[!0,r(i,e)]:[!1,[...s||[],...i]]}}}function Ne(e,r,{outputSchema:n,disableStrictOutputSchema:t}={}){return{...f,e:`transform_from_${e.e}`,r(o,a){let s=null;if(n){let[u,d]=U(a,n,o,t);if(u)return[!0,d];s=d}let[c,i]=e.r(o,a);if(c){let u=r(i,e);return u.ok?[!0,u.data]:[!1,typeof u.errors=="string"?[p(a,u.errors)]:u.errors.map(d=>p(a,d))]}return[!1,[...s||[],...i]]}}}function P(e,r){let n=typeof e,t=(()=>{if(n==="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return n})();return r&&(t==="string"||t==="number"||t==="boolean")?`${t}(${e})`:t}function Ce(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function x(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function qe(e,r,n){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${P(e,!0)}`]};let t=JSON.parse(e);return S(t,r,n)}catch(t){return{ok:!1,error:!0,errors:[`json parsing error: ${x(t)?t.message:""}`]}}}function I(e){return typeof e=="function"}export{V as a,j as b,M as c,z as d,L as e,Q as f,J as g,Z as h,G as i,H as j,p as k,y as l,f as m,le as n,Te as o,de as p,pe as q,Re as r,_e as s,he as t,be as u,je as v,ge as w,ke as x,Oe as y,me as z,te as A,xe as B,Pe as C,we as D,Ee as E,$e as F,Ae as G,S as H,Ke as I,Se as J,oe as K,Ie as L,We as M,ve as N,Ne as O,Ce as P,x as Q,v as R,qe as S};