runcheck 0.9.0 → 0.10.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
@@ -223,3 +223,27 @@ You can use also modiers like `rc_string.optional()` to extend or modify the rc
223
223
  | `rc_[type].optional()` | `T \| undefined` |
224
224
  | `rc_[type].nullable()` | `T \| null` |
225
225
  | `rc_[type].nullish()` | `T \| null \| undefined` |
226
+
227
+ # Recursive types
228
+
229
+ You can use `rc_recursive` to create recursive types. But the types can't be inferred in this case. So you need to provide the type manually.
230
+
231
+ ```ts
232
+ type MenuTree = {
233
+ name: string
234
+ children: MenuTree[]
235
+ }
236
+
237
+ // the type should be provided manually to the variable in this case
238
+ const menuTreeSchema: RcType<MenuTree[]> = rc_recursive(() =>
239
+ rc_array(
240
+ rc_object({
241
+ name: rc_string,
242
+ // you can safely autorefence the schema here
243
+ children: menuTreeSchema,
244
+ }),
245
+ ),
246
+ )
247
+
248
+ const result = rc_parse(input, menuTreeSchema)
249
+ ```
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var s in r)c(e,s,{get:r[s],enumerable:!0})},p=(e,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==s&&c(e,n,{get:()=>r[n],enumerable:!(i=f(r,n))||i.enumerable});return e};var b=e=>p(c({},"__esModule",{value:!0}),e);var S={};R(S,{rc_boolean_autofix:()=>O,rc_number_autofix:()=>k,rc_string_autofix:()=>A});module.exports=b(S);function h(e){return{...this,a:e}}function a(e,r,s,i){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let t=n===!0?r:n.data;return e.t&&!e.t(t)?[!1,[e.n(t)]]:[!0,t]}if(e.a!==void 0)return s.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let t=e.o(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(s.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function _(e){return{...this,l:!0,o:e}}function x(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,i:!0}}function w(e){return`Type '${m(e)}' is not assignable to '${this.e}'`}function j(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function $(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:h,where:x,optional:g,n:w,nullable:j,withAutofix:_,nullish:$},P={...o,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},V={...o,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},q={...o,r(e,r){return a(this,e,r,()=>!0)},e:"any"},u={...o,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...o,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},y={...o,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},E={...o,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function m(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var O=u.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),A=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),k=y.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
1
+ "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var s in r)c(e,s,{get:r[s],enumerable:!0})},R=(e,r,s,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!d.call(e,n)&&n!==s&&c(e,n,{get:()=>r[n],enumerable:!(i=f(r,n))||i.enumerable});return e};var b=e=>R(c({},"__esModule",{value:!0}),e);var S={};p(S,{rc_boolean_autofix:()=>O,rc_number_autofix:()=>k,rc_string_autofix:()=>A});module.exports=b(S);function h(e){return{...this,a:e}}function a(e,r,s,i){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let n=i();if(n&&(n===!0||"data"in n)){let t=n===!0?r:n.data;return e.t&&!e.t(t)?[!1,[e.n(t)]]:[!0,t]}if(e.a!==void 0)return s.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let t=e.o(r);if(t)return e.t&&!e.t(t.fixed)?[!1,[e.n(t.fixed)]]:(s.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,t.fixed])}return[!1,n&&"errors"in n?n.errors:[e.n(r)]]}function _(e){return{...this,l:!0,o:e}}function x(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function g(){return{...this,i:!0}}function w(e){return`Type '${m(e)}' is not assignable to '${this.e}'`}function j(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function $(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:h,where:x,optional:g,n:w,nullable:j,withAutofix:_,nullish:$},P={...o,r(e,r){return a(this,e,r,()=>e===void 0)},e:"undefined"},V={...o,r(e,r){return a(this,e,r,()=>e===null)},e:"null"},q={...o,r(e,r){return a(this,e,r,()=>!0)},e:"any"},u={...o,r(e,r){return a(this,e,r,()=>typeof e=="boolean")},e:"boolean"},l={...o,r(e,r){return a(this,e,r,()=>typeof e=="string")},e:"string"},y={...o,r(e,r){return a(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},E={...o,r(e,r){return a(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function m(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}var O=u.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),A=l.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),k=y.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
@@ -1 +1 @@
1
- import{d as f,e as t,f as o}from"./chunk-ZJY2BN3P.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{d as f,e as t,f as o}from"./chunk-VZH5A46S.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 +1 @@
1
- function O(e){return{...this,a:e}}function o(e,r,n,t){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let a=e.o(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function k(e){return{...this,l:!0,o:e}}function A(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function m(){return{...this,i:!0}}function S(e){return`Type '${w(e)}' is not assignable to '${this.e}'`}function P(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function V(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:O,where:A,optional:m,n:S,nullable:P,withAutofix:k,nullish:V},E={...i,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},I={...i,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},N={...i,r(e,r){return o(this,e,r,()=>!0)},e:"any"},K={...i,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},v={...i,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},F={...i,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},C={...i,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function U(e){return{...i,r(r,n){return o(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function z(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return o(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${w(e[0])}_literal`:"literals"}}function B(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return o(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function p(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function b(e){return{...i,s:e,e:"object",y:!0,r(r,n){return o(this,r,n,()=>{if(!$(r))return!1;let t=new Set(Object.keys(r)),s={},a=[];for(let[c,d]of Object.entries(e)){let l=c,y=r[c];t.delete(c);let[f,u]=d.r(y,n);if(f)s[l]=y;else{let h=u;for(let R of h)a.push(p(R,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:this.e.startsWith("extends_object")?{data:r}:{data:s}})}}}function M(e){return{...b(e),e:"extends_object"}}function W(e){return{...b(e),e:"strict_obj"}}function D(e,r){return b({...e.s,...r.s})}function G(e){return{...i,e:`record<string, ${e.e}>`,r(r,n){return o(this,r,n,()=>{if(!$(r))return!1;let t={},s=[];for(let[a,c]of Object.entries(r)){let d=r[a],[l,y]=e.r(c,n);if(l)t[a]=d;else{let f=y;for(let u of f)s.push(p(u,`.${a}`))}}return s.length>0?{errors:s}:{data:t}})}}}function x(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function _(e,r,n,t=!1,s){let a=-1,c=[],d=new Set;for(let l of e){a++;let y=Array.isArray(r)?r[a]:r,f=y.r(l,n),u=s?.unique;if(f[0]&&u){let T=l,g=typeof u=="string";g&&(T=l[u]),d.has(T)?f=[!1,[g?p(`${y.s?.[u]?.e} value is not unique`,`.${u}`):`${y.e} value is not unique`]]:d.add(T)}let[h,R]=f;if(h)t&&c.push(l);else if(t){n.warnings.push(...R.map(T=>p(T,`[${a}]`)));continue}else return{errors:R.map(T=>p(T,`[${a}]`))}}return t?{data:c}:!0}function H(e,r){return x(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return o(this,n,t,()=>Array.isArray(n)?n.length===0?!0:_.call(this,n,e,t,!1,r):!1)}}}function J(e,r){return x(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return o(this,n,t,()=>Array.isArray(n)?n.length===0?!0:_.call(this,n,e,t,!0,r):!1)}}}function L(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return o(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:_.call(this,r,e,n))}}}function j(e,r){let n={warnings:[]},[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 Q(e){return r=>j(r,e)}function X(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:[]};return!!r.r(e,n)[0]}function Y(e){return r=>q(r,e)}function w(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function $(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{E as a,I as b,N as c,K as d,v as e,F as f,C as g,U as h,z as i,B as j,b as k,M as l,W as m,D as n,G as o,H as p,J as q,L as r,j as s,Q as t,X as u,q as v,Y as w};
1
+ function O(e){return{...this,a:e}}function i(e,r,n,t){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let a=e.o(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function k(e){return{...this,l:!0,o:e}}function A(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function m(){return{...this,i:!0}}function S(e){return`Type '${w(e)}' is not assignable to '${this.e}'`}function P(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function V(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:O,where:A,optional:m,n:S,nullable:P,withAutofix:k,nullish:V},E={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},I={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},N={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},v={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},K={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},F={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},C={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function U(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function z(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${w(e[0])}_literal`:"literals"}}function B(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function p(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function b(e){return{...o,s:e,e:"object",y:!0,r(r,n){return i(this,r,n,()=>{if(!$(r))return!1;let t=new Set(Object.keys(r)),s={},a=[];for(let[c,d]of Object.entries(e)){let l=c,y=r[c];t.delete(c);let[f,u]=d.r(y,n);if(f)s[l]=y;else{let h=u;for(let R of h)a.push(p(R,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:this.e.startsWith("extends_object")?{data:r}:{data:s}})}}}function M(e){return{...b(e),e:"extends_object"}}function W(e){return{...b(e),e:"strict_obj"}}function D(e,r){return b({...e.s,...r.s})}function G(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!$(r))return!1;let t={},s=[];for(let[a,c]of Object.entries(r)){let d=r[a],[l,y]=e.r(c,n);if(l)t[a]=d;else{let f=y;for(let u of f)s.push(p(u,`.${a}`))}}return s.length>0?{errors:s}:{data:t}})}}}function g(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function _(e,r,n,t=!1,s){let a=-1,c=[],d=new Set;for(let l of e){a++;let y=Array.isArray(r)?r[a]:r,f=y.r(l,n),u=s?.unique;if(f[0]&&u){let T=l,x=typeof u=="string";x&&(T=l[u]),d.has(T)?f=[!1,[x?p(`${y.s?.[u]?.e} value is not unique`,`.${u}`):`${y.e} value is not unique`]]:d.add(T)}let[h,R]=f;if(h)t&&c.push(l);else if(t){n.warnings.push(...R.map(T=>p(T,`[${a}]`)));continue}else return{errors:R.map(T=>p(T,`[${a}]`))}}return t?{data:c}:!0}function H(e,r){return g(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:_.call(this,n,e,t,!1,r):!1)}}}function J(e,r){return g(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:_.call(this,n,e,t,!0,r):!1)}}}function L(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:_.call(this,r,e,n))}}}function j(e,r){let n={warnings:[]},[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 Q(e){return r=>j(r,e)}function X(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:[]};return!!r.r(e,n)[0]}function Y(e){return r=>q(r,e)}function Z(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function w(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function $(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}export{E as a,I as b,N as c,v as d,K as e,F as f,C as g,U as h,z as i,B as j,b as k,M as l,W as m,D as n,G as o,H as p,J as q,L as r,j as s,Q as t,X as u,q as v,Y as w,Z as x};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var P=(e,r)=>{for(var n in r)_(e,n,{get:r[n],enumerable:!0})},V=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of m(r))!S.call(e,s)&&s!==n&&_(e,s,{get:()=>r[s],enumerable:!(t=A(r,s))||t.enumerable});return e};var q=e=>V(_({},"__esModule",{value:!0}),e);var oe={};P(oe,{rc_any:()=>B,rc_array:()=>ee,rc_boolean:()=>M,rc_date:()=>G,rc_extends_obj:()=>Q,rc_instanceof:()=>H,rc_is_valid:()=>$,rc_literals:()=>J,rc_loose_array:()=>re,rc_loose_parse:()=>se,rc_null:()=>z,rc_number:()=>D,rc_obj_intersection:()=>Y,rc_object:()=>h,rc_parse:()=>x,rc_parser:()=>te,rc_record:()=>Z,rc_strict_obj:()=>X,rc_string:()=>W,rc_tuple:()=>ne,rc_undefined:()=>U,rc_union:()=>L,rc_validator:()=>ae});module.exports=q(oe);function E(e){return{...this,a:e}}function o(e,r,n,t){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let a=e.o(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function I(e){return{...this,l:!0,o:e}}function N(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function K(){return{...this,i:!0}}function v(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function F(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function C(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var i={withFallback:E,where:N,optional:K,n:v,nullable:F,withAutofix:I,nullish:C},U={...i,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},z={...i,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},B={...i,r(e,r){return o(this,e,r,()=>!0)},e:"any"},M={...i,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},W={...i,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},D={...i,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},G={...i,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function H(e){return{...i,r(r,n){return o(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function J(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return o(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${O(e[0])}_literal`:"literals"}}function L(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return o(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function p(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function h(e){return{...i,s:e,e:"object",y:!0,r(r,n){return o(this,r,n,()=>{if(!k(r))return!1;let t=new Set(Object.keys(r)),s={},a=[];for(let[c,d]of Object.entries(e)){let l=c,y=r[c];t.delete(c);let[f,u]=d.r(y,n);if(f)s[l]=y;else{let b=u;for(let R of b)a.push(p(R,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:this.e.startsWith("extends_object")?{data:r}:{data:s}})}}}function Q(e){return{...h(e),e:"extends_object"}}function X(e){return{...h(e),e:"strict_obj"}}function Y(e,r){return h({...e.s,...r.s})}function Z(e){return{...i,e:`record<string, ${e.e}>`,r(r,n){return o(this,r,n,()=>{if(!k(r))return!1;let t={},s=[];for(let[a,c]of Object.entries(r)){let d=r[a],[l,y]=e.r(c,n);if(l)t[a]=d;else{let f=y;for(let u of f)s.push(p(u,`.${a}`))}}return s.length>0?{errors:s}:{data:t}})}}}function w(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function g(e,r,n,t=!1,s){let a=-1,c=[],d=new Set;for(let l of e){a++;let y=Array.isArray(r)?r[a]:r,f=y.r(l,n),u=s?.unique;if(f[0]&&u){let T=l,j=typeof u=="string";j&&(T=l[u]),d.has(T)?f=[!1,[j?p(`${y.s?.[u]?.e} value is not unique`,`.${u}`):`${y.e} value is not unique`]]:d.add(T)}let[b,R]=f;if(b)t&&c.push(l);else if(t){n.warnings.push(...R.map(T=>p(T,`[${a}]`)));continue}else return{errors:R.map(T=>p(T,`[${a}]`))}}return t?{data:c}:!0}function ee(e,r){return w(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return o(this,n,t,()=>Array.isArray(n)?n.length===0?!0:g.call(this,n,e,t,!1,r):!1)}}}function re(e,r){return w(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return o(this,n,t,()=>Array.isArray(n)?n.length===0?!0:g.call(this,n,e,t,!0,r):!1)}}}function ne(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return o(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:g.call(this,r,e,n))}}}function x(e,r){let n={warnings:[]},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function te(e){return r=>x(r,e)}function se(e,r){let n=x(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function $(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ae(e){return r=>$(r,e)}function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_strict_obj,rc_string,rc_tuple,rc_undefined,rc_union,rc_validator});
1
+ "use strict";var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var P=(e,r)=>{for(var n in r)_(e,n,{get:r[n],enumerable:!0})},V=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of m(r))!S.call(e,s)&&s!==n&&_(e,s,{get:()=>r[s],enumerable:!(t=A(r,s))||t.enumerable});return e};var q=e=>V(_({},"__esModule",{value:!0}),e);var ie={};P(ie,{rc_any:()=>B,rc_array:()=>ee,rc_boolean:()=>M,rc_date:()=>G,rc_extends_obj:()=>Q,rc_instanceof:()=>H,rc_is_valid:()=>$,rc_literals:()=>J,rc_loose_array:()=>re,rc_loose_parse:()=>se,rc_null:()=>z,rc_number:()=>D,rc_obj_intersection:()=>Y,rc_object:()=>h,rc_parse:()=>g,rc_parser:()=>te,rc_record:()=>Z,rc_recursive:()=>oe,rc_strict_obj:()=>X,rc_string:()=>W,rc_tuple:()=>ne,rc_undefined:()=>U,rc_union:()=>L,rc_validator:()=>ae});module.exports=q(ie);function E(e){return{...this,a:e}}function i(e,r,n,t){if(e.i&&r===void 0)return[!0,r];if(e.c&&r==null)return[!0,r];if(e.u&&r===null)return[!0,r];let s=t();if(s&&(s===!0||"data"in s)){let a=s===!0?r:s.data;return e.t&&!e.t(a)?[!1,[e.n(a)]]:[!0,a]}if(e.a!==void 0)return n.warnings.push(`Fallback used, ${e.n(r)}`),[!0,e.a];if(e.l&&e.o){let a=e.o(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[e.n(a.fixed)]]:(n.warnings.push(`Autofixed from, ${e.n(r)}`),[!0,a.fixed])}return[!1,s&&"errors"in s?s.errors:[e.n(r)]]}function I(e){return{...this,l:!0,o:e}}function N(e){return{...this,t:e,e:`${this.e}_with_predicate`}}function v(){return{...this,i:!0}}function K(e){return`Type '${O(e)}' is not assignable to '${this.e}'`}function F(){return{...this,u:!0,e:`${this.e}_or_nullable`}}function C(){return{...this,c:!0,e:`${this.e}_or_nullish`}}var o={withFallback:E,where:N,optional:v,n:K,nullable:F,withAutofix:I,nullish:C},U={...o,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},z={...o,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},B={...o,r(e,r){return i(this,e,r,()=>!0)},e:"any"},M={...o,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},W={...o,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},D={...o,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},G={...o,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function H(e){return{...o,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function J(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},e:e.length==1?`${O(e[0])}_literal`:"literals"}}function L(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...o,r(r,n){return i(this,r,n,()=>{for(let t of e)if(t.r(r,n)[0])return!0;return!1})},e:e.map(r=>r.e).join(" | ")}}function p(e,r){if(e.startsWith("$[")||e.startsWith("$.")){let[n="",t]=e.split(": "),s=n.slice(1);return`$${r}${s}: ${t}`}return`$${r}: ${e}`}function h(e){return{...o,s:e,e:"object",y:!0,r(r,n){return i(this,r,n,()=>{if(!k(r))return!1;let t=new Set(Object.keys(r)),s={},a=[];for(let[c,d]of Object.entries(e)){let l=c,y=r[c];t.delete(c);let[f,u]=d.r(y,n);if(f)s[l]=y;else{let b=u;for(let R of b)a.push(p(R,`.${c}`))}}if(this.e==="strict_obj"&&t.size>0)for(let c of t)a.push(`Key '${c}' is not defined in the object shape`);return a.length>0?{errors:a}:this.e.startsWith("extends_object")?{data:r}:{data:s}})}}}function Q(e){return{...h(e),e:"extends_object"}}function X(e){return{...h(e),e:"strict_obj"}}function Y(e,r){return h({...e.s,...r.s})}function Z(e){return{...o,e:`record<string, ${e.e}>`,r(r,n){return i(this,r,n,()=>{if(!k(r))return!1;let t={},s=[];for(let[a,c]of Object.entries(r)){let d=r[a],[l,y]=e.r(c,n);if(l)t[a]=d;else{let f=y;for(let u of f)s.push(p(u,`.${a}`))}}return s.length>0?{errors:s}:{data:t}})}}}function w(e,r){if(typeof r=="string"&&!e.s?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function x(e,r,n,t=!1,s){let a=-1,c=[],d=new Set;for(let l of e){a++;let y=Array.isArray(r)?r[a]:r,f=y.r(l,n),u=s?.unique;if(f[0]&&u){let T=l,j=typeof u=="string";j&&(T=l[u]),d.has(T)?f=[!1,[j?p(`${y.s?.[u]?.e} value is not unique`,`.${u}`):`${y.e} value is not unique`]]:d.add(T)}let[b,R]=f;if(b)t&&c.push(l);else if(t){n.warnings.push(...R.map(T=>p(T,`[${a}]`)));continue}else return{errors:R.map(T=>p(T,`[${a}]`))}}return t?{data:c}:!0}function ee(e,r){return w(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:x.call(this,n,e,t,!1,r):!1)}}}function re(e,r){return w(e,r?.unique),{...o,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:x.call(this,n,e,t,!0,r):!1)}}}function ne(e){return{...o,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:x.call(this,r,e,n))}}}function g(e,r){let n={warnings:[]},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function te(e){return r=>g(r,e)}function se(e,r){let n=g(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function $(e,r){let n={warnings:[]};return!!r.r(e,n)[0]}function ae(e){return r=>$(r,e)}function oe(e){return{...o,e:"recursive",r(r,n){return e().r(r,n)}}}function O(e){if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}0&&(module.exports={rc_any,rc_array,rc_boolean,rc_date,rc_extends_obj,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_object,rc_parse,rc_parser,rc_record,rc_recursive,rc_strict_obj,rc_string,rc_tuple,rc_undefined,rc_union,rc_validator});
@@ -69,5 +69,6 @@ declare function rc_loose_parse<S>(input: any, type: RcType<S>): {
69
69
  };
70
70
  declare function rc_is_valid<S>(input: any, type: RcType<S>): input is S;
71
71
  declare function rc_validator<S>(type: RcType<S>): (input: any) => input is S;
72
+ declare function rc_recursive(type: () => RcType<any>): RcType<any>;
72
73
 
73
- export { RcInferType, RcParseResult, RcParser, RcType, rc_any, rc_array, rc_boolean, rc_date, rc_extends_obj, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_null, rc_number, rc_obj_intersection, rc_object, rc_parse, rc_parser, rc_record, rc_strict_obj, rc_string, rc_tuple, rc_undefined, rc_union, rc_validator };
74
+ export { RcInferType, RcParseResult, RcParser, RcType, rc_any, rc_array, rc_boolean, rc_date, rc_extends_obj, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_null, rc_number, rc_obj_intersection, rc_object, rc_parse, rc_parser, rc_record, rc_recursive, rc_strict_obj, rc_string, rc_tuple, rc_undefined, rc_union, 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,t,u,v,w}from"./chunk-ZJY2BN3P.js";export{c as rc_any,p as rc_array,d as rc_boolean,g as rc_date,l as rc_extends_obj,h as rc_instanceof,v as rc_is_valid,i as rc_literals,q as rc_loose_array,u as rc_loose_parse,b as rc_null,f as rc_number,n as rc_obj_intersection,k as rc_object,s as rc_parse,t as rc_parser,o as rc_record,m as rc_strict_obj,e as rc_string,r as rc_tuple,a as rc_undefined,j as rc_union,w as rc_validator};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x}from"./chunk-VZH5A46S.js";export{c as rc_any,p as rc_array,d as rc_boolean,g as rc_date,l as rc_extends_obj,h as rc_instanceof,v as rc_is_valid,i as rc_literals,q as rc_loose_array,u as rc_loose_parse,b as rc_null,f as rc_number,n as rc_obj_intersection,k as rc_object,s as rc_parse,t as rc_parser,o as rc_record,x as rc_recursive,m as rc_strict_obj,e as rc_string,r as rc_tuple,a as rc_undefined,j as rc_union,w as rc_validator};
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.9.0",
4
+ "version": "0.10.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",