runcheck 0.31.0 → 0.32.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
@@ -252,7 +252,7 @@ const positiveNumberType = rc_number.where((input) => input > 0)
252
252
 
253
253
  # Infer types from schemas
254
254
 
255
- You can use `RcInferType<typeof T>` to infer the types from a schema.
255
+ You can use `RcInferType<typeof schema>` to infer the types from a schema.
256
256
 
257
257
  ```ts
258
258
  const schema = rc_object({
@@ -264,15 +264,17 @@ const schema = rc_object({
264
264
  export type Person = RcInferType<typeof schema>
265
265
  ```
266
266
 
267
+ You can also use the `RcPrettyInferType<typeof schema>` to get a more readable type.
268
+
267
269
  # Type modifiers
268
270
 
269
- You can use also modiers like `rc_string.optional()` to extend or modify the rc types:
271
+ You can use also modiers like `rc_string.optional()` to extend the rc types:
270
272
 
271
- | runcheck modifier | ts type equivalent |
272
- | ---------------------- | ------------------------ |
273
- | `rc_[type].optional()` | `T \| undefined` |
274
- | `rc_[type].nullable()` | `T \| null` |
275
- | `rc_[type].nullish()` | `T \| null \| undefined` |
273
+ | runcheck modifier | ts type equivalent |
274
+ | ----------------------- | ------------------------ |
275
+ | `rc_[type].optional()` | `T \| undefined` |
276
+ | `rc_[type].orNull()` | `T \| null` |
277
+ | `rc_[type].orNullish()` | `T \| null \| undefined` |
276
278
 
277
279
  # Recursive types
278
280
 
@@ -400,4 +402,36 @@ const shape = rc_object({
400
402
  const baseSchema = rc_obj_omit(shape, ['isCool'])
401
403
  ```
402
404
 
403
- # Other useful utils
405
+ # Investigage rc nested type errors
406
+
407
+ There are two type utils to help investigate deeply nested type errors, the `RcPrettyInferType` and the `RcSchemaHasType`
408
+
409
+ ```ts
410
+ const schema = rc_object({
411
+ level1: {
412
+ level2: {
413
+ level3: {
414
+ level4: {
415
+ level5: rc_string,
416
+ },
417
+ },
418
+ },
419
+ },
420
+ })
421
+
422
+ type SchemaType = {
423
+ level1: {
424
+ level2: {
425
+ level3: {
426
+ level4: {
427
+ level5: number
428
+ }
429
+ }
430
+ }
431
+ }
432
+ }
433
+
434
+ type CheckType = RcSchemaHasType<SchemaType, RcPrettyInferType<typeof schema>>
435
+ // this will reporte better errors than:
436
+ // const schema: RcType<SchemaType> = rc_object...
437
+ ```
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(e,r)=>{for(var n in r)u(e,n,{get:r[n],enumerable:!0})},_=(e,r,n,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of R(r))!b.call(e,t)&&t!==n&&u(e,t,{get:()=>r[t],enumerable:!(a=T(r,t))||a.enumerable});return e};var j=e=>_(u({},"__esModule",{value:!0}),e);var K={};h(K,{rc_boolean_autofix:()=>P,rc_number_autofix:()=>C,rc_string_autofix:()=>I});module.exports=j(K);function g(e){return{...this,i:e}}function x(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function f(e,r){e.warnings.push(x(e,r))}function s(e,r,n,a){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let t=a();if(t&&(t===!0||!t.errors)){let i=t===!0?r:t.data;return e.t&&!e.t(i)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,i]}let c=e.i;if(c!==void 0)return f(n,`Fallback used, errors -> ${l(t,n,e,r)}`),[!0,S(c)?c():c];if(e.l&&e.o){let i=e.o(r);if(i)return e.t&&!e.t(i.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(f(n,`Autofixed from error "${l(t,n,e,r)}"`),[!0,i.fixed])}return[!1,t?t.errors:[e.y(r)]]}function l(e,r,n,a){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.y(a)}function O(e){return{...this,l:!0,o:e}}function m(e){return{...this,t:e}}function w(){return{...this,c:!0}}function k(e){return`Type '${A(e,!!this.d)}' is not assignable to '${this.e}'`}function $(){return{...this,f:!0,e:`${this.e}_or_null`}}function E(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:g,where:m,optional:w,y:k,orNullish:E,withAutofix:O,orNull:$,i:void 0,t:void 0,c:!1,f:!1,u:!1,l:!1,d:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,p:!1,T:[]},V={...o,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},q={...o,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},v={...o,r(e,r){return s(this,e,r,()=>!0)},e:"any"},B={...o,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},y={...o,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},d={...o,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},p={...o,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...o,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function A(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=="function"}var P=y.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),I=d.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),C=p.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
1
+ "use strict";var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var h=(e,r)=>{for(var n in r)u(e,n,{get:r[n],enumerable:!0})},_=(e,r,n,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of R(r))!b.call(e,t)&&t!==n&&u(e,t,{get:()=>r[t],enumerable:!(a=T(r,t))||a.enumerable});return e};var j=e=>_(u({},"__esModule",{value:!0}),e);var K={};h(K,{rc_boolean_autofix:()=>A,rc_number_autofix:()=>C,rc_string_autofix:()=>I});module.exports=j(K);function g(e){return{...this,i:e}}function x(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function f(e,r){e.warnings.push(x(e,r))}function s(e,r,n,a){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let t=a();if(t&&(t===!0||!t.errors)){let i=t===!0?r:t.data;return e.t&&!e.t(i)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,i]}let c=e.i;if(c!==void 0)return f(n,`Fallback used, errors -> ${y(t,n,e,r)}`),[!0,S(c)?c():c];if(e.y&&e.o){let i=e.o(r);if(i)return e.t&&!e.t(i.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(f(n,`Autofixed from error "${y(t,n,e,r)}"`),[!0,i.fixed])}return[!1,t?t.errors:[e.l(r)]]}function y(e,r,n,a){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.l(a)}function O(e){return{...this,y:!0,o:e}}function m(e){return{...this,t:e}}function w(){return{...this,c:!0}}function k(e){return`Type '${P(e,!!this.d)}' is not assignable to '${this.e}'`}function $(){return{...this,f:!0,e:`${this.e}_or_null`}}function E(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var o={withFallback:g,where:m,optional:w,l:k,orNullish:E,withAutofix:O,orNull:$,i:void 0,t:void 0,c:!1,f:!1,u:!1,y:!1,d:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,p:!1,T:[]},V={...o,r(e,r){return s(this,e,r,()=>e===void 0)},e:"undefined"},q={...o,r(e,r){return s(this,e,r,()=>e===null)},e:"null"},v={...o,r(e,r){return s(this,e,r,()=>!0)},e:"any"},B={...o,r(e,r){return s(this,e,r,()=>!0)},e:"unknown"},l={...o,r(e,r){return s(this,e,r,()=>typeof e=="boolean")},e:"boolean"},d={...o,r(e,r){return s(this,e,r,()=>typeof e=="string")},e:"string"},p={...o,r(e,r){return s(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...o,r(e,r){return s(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};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=="function"}var A=l.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),I=d.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),C=p.withAutofix(e=>{if(typeof e=="string"){let r=Number(e);if(!Number.isNaN(r))return{fixed:r}}return!1});0&&(module.exports={rc_boolean_autofix,rc_number_autofix,rc_string_autofix});
@@ -1 +1 @@
1
- import{e as f,f as t,g as o}from"./chunk-YAXWQU2M.js";var s=f.withAutofix(r=>r==null||r===0||r===1?{fixed:!!r}:r==="true"||r==="false"?{fixed:r==="true"}:!1),n=t.withAutofix(r=>typeof r=="number"&&!Number.isNaN(r)?{fixed:r.toString()}:!1),u=o.withAutofix(r=>{if(typeof r=="string"){let e=Number(r);if(!Number.isNaN(e))return{fixed:e}}return!1});export{s as rc_boolean_autofix,u as rc_number_autofix,n as rc_string_autofix};
1
+ import{e as f,f as t,g as o}from"./chunk-WQBKLM3G.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 q(e){return{...this,i:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function m(e,r){e.warnings.push(g(e,r))}function C(e,r){r.forEach(n=>m(e,n))}function u(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}let a=e.i;if(a!==void 0)return m(n,`Fallback used, errors -> ${A(s,n,e,r)}`),[!0,J(a)?a():a];if(e.l&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(m(n,`Autofixed from error "${A(s,n,e,r)}"`),[!0,o.fixed])}return[!1,s?s.errors:[e.y(r)]]}function A(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):n.y(t)}function N(e){return{...this,l:!0,o:e}}function v(e){return{...this,t:e}}function B(){return{...this,c:!0}}function F(e){return`Type '${$(e,!!this.d)}' is not assignable to '${this.e}'`}function W(){return{...this,f:!0,e:`${this.e}_or_null`}}function D(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={withFallback:q,where:v,optional:B,y:F,orNullish:D,withAutofix:N,orNull:W,i:void 0,t:void 0,c:!1,f:!1,u:!1,l:!1,d:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,p:!1,T:[]},L={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},Z={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},G={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},H={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Q={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},X={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Y={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ee={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function re(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ne(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},d:!0,e:e.length==1?$(e[0],!0):e.map(r=>$(r,!0)).join(" | ")}}var I=1;function te(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let t=n.path,s=[],a=0,o=!1,d=[],l=0;for(let c of e){l+=1,c.a&&(n.path=`${t}|union ${l}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[f,b]=c.r(r,n);n.objErrShortCircuit=!1;let y=n.objErrKeyIndex;if(n.objErrKeyIndex=0,f)return!0;c.a&&y!==-1?y>0?d.push(...b):(a<I&&s.push(...b),a+=1):o=!0}return n.path=t,d.length>0||s.length>0?((a>I||o)&&s.push("not matches any other union member"),{errors:[...d,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function U(e,r){return{...r,s:e}}var se=U;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",a:!0,T:Object.entries(e),r(n,t){return u(this,n,t,()=>{if(!S(n))return t.objErrKeyIndex=-1,!1;let s=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],d=t.path,l=-1;for(let[c,f]of this.T){let b=c;l+=1;let y=`.${c}`;t.path=`${d}${y}`;let p,R=c;if(f.s&&(p=n[f.s],R=f.s),p===void 0&&(p=n[c],R=c),p===void 0&&r==="snake_case"){let h=z(c);p=n[h],R=h}s?.delete(R);let[j,x]=f.r(p,t);if(j)a[b]=x;else{for(let h of x)o.push(g(t,h));if(t.objErrShortCircuit){t.objErrKeyIndex=l;break}}}if(s&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o,data:void 0}:this.p?{errors:!1,data:{...n,...a}}:{errors:!1,data:a}})}}}function oe(e){return{...O(e),e:"extends_object",p:!0}}function ae(e){return e.n}function ie(e){return{...O(e),e:"strict_obj"}}function ce(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function ue(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return O(n)}function le(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return O(n)}function fe(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!S(t))return!1;let a={},o=[],d=s.path;for(let[l,c]of Object.entries(t)){let f=`.${l}`,b=`${d}${f}`;if(s.path=b,r&&!r(l)){o.push(g(s,`Key '${l}' is not allowed`));continue}let y=t[l],[p,R]=e.r(c,s);if(p)a[l]=y;else{let j=R;for(let x of j)o.push(g(s,x));if(s.objErrShortCircuit)break}}if(o.length>0)if(n)C(s,o);else return{errors:o,data:void 0};return{errors:!1,data:a}})}}}function K(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function E(e,r,n,t=!1,s){let a=[],o=[],d=new Set,l=n.path,c=Array.isArray(r),f=-1;for(let b of e){f++;let y=c?r[f]:r,p=`[${f}]`,R=`${l}${p}`;n.path=R;let j=y.r(b,n),[x,h]=j;n.path=R;let _=s?.unique;if(x&&_){let T=h,k=typeof _=="string";k?T=h[_]:typeof _=="function"&&(T=_(h)),d.has(T)?(k&&(n.path=`${l}${p}.${_}`),j=[!1,[g(n,k?`Type '${y.n?.[_]?.e}' with value "${T}" is not unique`:typeof _=="function"?`Type '${y.e}' unique fn return with value "${T}" is not unique`:`${y.e} value is not unique`)]]):d.add(T)}let[V,w]=j;if(V)o.push(w);else if(t){a.push(w.map(T=>g(n,T)));continue}else return{errors:w.map(T=>g(n,T)),data:void 0}}if(a.length>0){if(o.length===0)return{errors:a.slice(0,5).flat(),data:void 0};C(n,a.flat())}return{errors:!1,data:o}}function ye(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function pe(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!0,r):!1)}}}function de(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:E.call(this,r,e,n))}}}function P(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function Te(e){return r=>P(r,e)}function Re(e,r){let n=P(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function M(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function be(e){return r=>M(r,e)}function he(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function _e(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function $(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 je(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function z(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 P(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${S(n)?n.message:""}`]}}}function J(e){return typeof e=="function"}export{L as a,Z as b,G as c,H as d,Q as e,X as f,Y as g,ee as h,re as i,ne as j,te as k,U as l,se as m,O as n,oe as o,ae as p,ie as q,ce as r,ue as s,le as t,fe as u,ye as v,pe as w,de as x,P as y,Te as z,Re as A,M as B,be as C,he as D,_e as E,je as F,z as G,ge as H};
1
+ function q(e){return{...this,i:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function m(e,r){e.warnings.push(g(e,r))}function C(e,r){r.forEach(n=>m(e,n))}function u(e,r,n,t){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.f&&r===null)return[!0,r];let s=t();if(s&&(s===!0||!s.errors)){let o=s===!0?r:s.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}let a=e.i;if(a!==void 0)return m(n,`Fallback used, errors -> ${I(s,n,e,r)}`),[!0,H(a)?a():a];if(e.y&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(m(n,`Autofixed from error "${I(s,n,e,r)}"`),[!0,o.fixed])}return[!1,s?s.errors:[e.l(r)]]}function I(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):n.l(t)}function N(e){return{...this,y:!0,o:e}}function v(e){return{...this,t:e}}function B(){return{...this,c:!0}}function F(e){return`Type '${$(e,!!this.d)}' is not assignable to '${this.e}'`}function W(){return{...this,f:!0,e:`${this.e}_or_null`}}function D(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={withFallback:q,where:v,optional:B,l:F,orNullish:D,withAutofix:N,orNull:W,i:void 0,t:void 0,c:!1,f:!1,u:!1,y:!1,d:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,p:!1,T:[]},J={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},L={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},Z={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},G={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},Q={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},X={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},Y={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ee={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function re(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ne(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},d:!0,e:e.length==1?$(e[0],!0):e.map(r=>$(r,!0)).join(" | ")}}var A=1;function te(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let t=n.path,s=[],a=0,o=!1,T=[],y=0;for(let c of e){y+=1,c.a&&(n.path=`${t}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[f,b]=c.r(r,n);n.objErrShortCircuit=!1;let l=n.objErrKeyIndex;if(n.objErrKeyIndex=0,f)return!0;c.a&&l!==-1?l>0?T.push(...b):(a<A&&s.push(...b),a+=1):o=!0}return n.path=t,T.length>0||s.length>0?((a>A||o)&&s.push("not matches any other union member"),{errors:[...T,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function U(e,r){return{...r,s:e}}var se=U;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",a:!0,T:Object.entries(e),r(n,t){return u(this,n,t,()=>{if(!S(n))return t.objErrKeyIndex=-1,!1;let s=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],T=t.path,y=-1;for(let[c,f]of this.T){let b=c;y+=1;let l=`.${c}`;t.path=`${T}${l}`;let p,R=c;if(f.s&&(p=n[f.s],R=f.s),p===void 0&&(p=n[c],R=c),p===void 0&&r==="snake_case"){let h=z(c);p=n[h],R=h}s?.delete(R);let[j,x]=f.r(p,t);if(j)a[b]=x;else{for(let h of x)o.push(g(t,h));if(t.objErrShortCircuit){t.objErrKeyIndex=y;break}}}if(s&&s.size>0)for(let c of s)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o,data:void 0}:this.p?{errors:!1,data:{...n,...a}}:{errors:!1,data:a}})}}}function oe(e){return{...O(e),e:"extends_object",p:!0}}function ae(e){return e.n}function ie(e){return{...O(e),e:"strict_obj"}}function ce(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function ue(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let t of r){let s=e.n[t];s&&(n[t]=s)}return O(n)}function ye(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let t of Object.keys(e.n))r.includes(t)||(n[t]=e.n[t]);return O(n)}function fe(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(t,s){return u(this,t,s,()=>{if(!S(t))return!1;let a={},o=[],T=s.path;for(let[y,c]of Object.entries(t)){let f=`.${y}`,b=`${T}${f}`;if(s.path=b,r&&!r(y)){o.push(g(s,`Key '${y}' is not allowed`));continue}let l=t[y],[p,R]=e.r(c,s);if(p)a[y]=l;else{let j=R;for(let x of j)o.push(g(s,x));if(s.objErrShortCircuit)break}}if(o.length>0)if(n)C(s,o);else return{errors:o,data:void 0};return{errors:!1,data:a}})}}}function K(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function E(e,r,n,t=!1,s){let a=[],o=[],T=new Set,y=n.path,c=Array.isArray(r),f=-1;for(let b of e){f++;let l=c?r[f]:r,p=`[${f}]`,R=`${y}${p}`;n.path=R;let j=l.r(b,n),[x,h]=j;n.path=R;let _=s?.unique;if(x&&_){let d=h,k=typeof _=="string";k?d=h[_]:typeof _=="function"&&(d=_(h)),T.has(d)?(k&&(n.path=`${y}${p}.${_}`),j=[!1,[g(n,k?`Type '${l.n?.[_]?.e}' with value "${d}" is not unique`:typeof _=="function"?`Type '${l.e}' unique fn return with value "${d}" is not unique`:`${l.e} value is not unique`)]]):T.add(d)}let[V,w]=j;if(V)o.push(w);else if(t){a.push(w.map(d=>g(n,d)));continue}else return{errors:w.map(d=>g(n,d)),data:void 0}}if(a.length>0){if(o.length===0)return{errors:a.slice(0,5).flat(),data:void 0};C(n,a.flat())}return{errors:!1,data:o}}function le(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function pe(e,r){return K(e,r?.unique),{...i,e:`${e.e}[]`,r(n,t){return u(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!0,r):!1)}}}function Te(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:E.call(this,r,e,n))}}}function P(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[t,s]=r.r(e,n);return t?{error:!1,data:s,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:s}}function de(e){return r=>P(r,e)}function Re(e,r){let n=P(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function M(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function be(e){return r=>M(r,e)}function he(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function _e(e,r){return{...i,e:`transform_from_${e.e}`,r(n,t){let[s,a]=e.r(n,t);return s?[!0,r(a)]:[!1,a]}}}function $(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 je(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function z(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 P(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${S(n)?n.message:""}`]}}}function H(e){return typeof e=="function"}export{J as a,L as b,Z as c,G as d,Q as e,X as f,Y as g,ee as h,re as i,ne as j,te as k,U as l,se as m,O as n,oe as o,ae as p,ie as q,ce as r,ue as s,ye as t,fe as u,le as v,pe as w,Te as x,P as y,de as z,Re as A,M as B,be as C,he as D,_e as E,je as F,z as G,ge as H};
package/dist/runcheck.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var $=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var U=(e,r)=>{for(var n in r)$(e,n,{get:r[n],enumerable:!0})},M=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of W(r))!D.call(e,t)&&t!==n&&$(e,t,{get:()=>r[t],enumerable:!(s=F(r,t))||s.enumerable});return e};var z=e=>M($({},"__esModule",{value:!0}),e);var Pe={};U(Pe,{rc_any:()=>re,rc_array:()=>he,rc_assert_is_valid:()=>me,rc_boolean:()=>te,rc_date:()=>ae,rc_extends_obj:()=>fe,rc_get_obj_schema:()=>ye,rc_instanceof:()=>ie,rc_is_valid:()=>N,rc_literals:()=>ce,rc_loose_array:()=>_e,rc_loose_parse:()=>xe,rc_null:()=>ee,rc_number:()=>oe,rc_obj_intersection:()=>de,rc_obj_omit:()=>Re,rc_obj_pick:()=>Te,rc_object:()=>O,rc_parse:()=>w,rc_parse_json:()=>$e,rc_parser:()=>ge,rc_record:()=>be,rc_recursive:()=>we,rc_rename_from_key:()=>V,rc_rename_key:()=>le,rc_strict_obj:()=>pe,rc_string:()=>se,rc_transform:()=>ke,rc_tuple:()=>je,rc_undefined:()=>Y,rc_union:()=>ue,rc_unknown:()=>ne,rc_validator:()=>Oe,snakeCase:()=>v});module.exports=z(Pe);function J(e){return{...this,i:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function E(e,r){e.warnings.push(g(e,r))}function K(e,r){r.forEach(n=>E(e,n))}function u(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.l&&r===null)return[!0,r];let t=s();if(t&&(t===!0||!t.errors)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}let a=e.i;if(a!==void 0)return E(n,`Fallback used, errors -> ${I(t,n,e,r)}`),[!0,Ee(a)?a():a];if(e.f&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(E(n,`Autofixed from error "${I(t,n,e,r)}"`),[!0,o.fixed])}return[!1,t?t.errors:[e.y(r)]]}function I(e,r,n,s){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.y(s)}function L(e){return{...this,f:!0,o:e}}function Z(e){return{...this,t:e}}function G(){return{...this,c:!0}}function H(e){return`Type '${P(e,!!this.p)}' is not assignable to '${this.e}'`}function Q(){return{...this,l:!0,e:`${this.e}_or_null`}}function X(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={withFallback:J,where:Z,optional:G,y:H,orNullish:X,withAutofix:L,orNull:Q,i:void 0,t:void 0,c:!1,l:!1,u:!1,f:!1,p:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,d:!1,T:[]},Y={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ee={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},re={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},ne={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},te={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},se={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},oe={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ae={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ie(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ce(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},p:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var C=1;function ue(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let s=n.path,t=[],a=0,o=!1,d=[],l=0;for(let c of e){l+=1,c.a&&(n.path=`${s}|union ${l}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[f,b]=c.r(r,n);n.objErrShortCircuit=!1;let y=n.objErrKeyIndex;if(n.objErrKeyIndex=0,f)return!0;c.a&&y!==-1?y>0?d.push(...b):(a<C&&t.push(...b),a+=1):o=!0}return n.path=s,d.length>0||t.length>0?((a>C||o)&&t.push("not matches any other union member"),{errors:[...d,...t],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function V(e,r){return{...r,s:e}}var le=V;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",a:!0,T:Object.entries(e),r(n,s){return u(this,n,s,()=>{if(!A(n))return s.objErrKeyIndex=-1,!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],d=s.path,l=-1;for(let[c,f]of this.T){let b=c;l+=1;let y=`.${c}`;s.path=`${d}${y}`;let p,R=c;if(f.s&&(p=n[f.s],R=f.s),p===void 0&&(p=n[c],R=c),p===void 0&&r==="snake_case"){let h=v(c);p=n[h],R=h}t?.delete(R);let[j,x]=f.r(p,s);if(j)a[b]=x;else{for(let h of x)o.push(g(s,h));if(s.objErrShortCircuit){s.objErrKeyIndex=l;break}}}if(t&&t.size>0)for(let c of t)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o,data:void 0}:this.d?{errors:!1,data:{...n,...a}}:{errors:!1,data:a}})}}}function fe(e){return{...O(e),e:"extends_object",d:!0}}function ye(e){return e.n}function pe(e){return{...O(e),e:"strict_obj"}}function de(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function Te(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let s of r){let t=e.n[s];t&&(n[s]=t)}return O(n)}function Re(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let s of Object.keys(e.n))r.includes(s)||(n[s]=e.n[s]);return O(n)}function be(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(s,t){return u(this,s,t,()=>{if(!A(s))return!1;let a={},o=[],d=t.path;for(let[l,c]of Object.entries(s)){let f=`.${l}`,b=`${d}${f}`;if(t.path=b,r&&!r(l)){o.push(g(t,`Key '${l}' is not allowed`));continue}let y=s[l],[p,R]=e.r(c,t);if(p)a[l]=y;else{let j=R;for(let x of j)o.push(g(t,x));if(t.objErrShortCircuit)break}}if(o.length>0)if(n)K(t,o);else return{errors:o,data:void 0};return{errors:!1,data:a}})}}}function q(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function S(e,r,n,s=!1,t){let a=[],o=[],d=new Set,l=n.path,c=Array.isArray(r),f=-1;for(let b of e){f++;let y=c?r[f]:r,p=`[${f}]`,R=`${l}${p}`;n.path=R;let j=y.r(b,n),[x,h]=j;n.path=R;let _=t?.unique;if(x&&_){let T=h,m=typeof _=="string";m?T=h[_]:typeof _=="function"&&(T=_(h)),d.has(T)?(m&&(n.path=`${l}${p}.${_}`),j=[!1,[g(n,m?`Type '${y.n?.[_]?.e}' with value "${T}" is not unique`:typeof _=="function"?`Type '${y.e}' unique fn return with value "${T}" is not unique`:`${y.e} value is not unique`)]]):d.add(T)}let[B,k]=j;if(B)o.push(k);else if(s){a.push(k.map(T=>g(n,T)));continue}else return{errors:k.map(T=>g(n,T)),data:void 0}}if(a.length>0){if(o.length===0)return{errors:a.slice(0,5).flat(),data:void 0};K(n,a.flat())}return{errors:!1,data:o}}function he(e,r){return q(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!1,r):!1)}}}function _e(e,r){return q(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!0,r):!1)}}}function je(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function w(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[s,t]=r.r(e,n);return s?{error:!1,data:t,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:t}}function ge(e){return r=>w(r,e)}function xe(e,r){let n=w(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function N(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function Oe(e){return r=>N(r,e)}function we(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function ke(e,r){return{...i,e:`transform_from_${e.e}`,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function 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 me(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function A(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function v(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function $e(e,r){try{let n=JSON.parse(e);return w(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${A(n)?n.message:""}`]}}}function Ee(e){return typeof e=="function"}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_extends_obj,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_obj_omit,rc_obj_pick,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator,snakeCase});
1
+ "use strict";var $=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var U=(e,r)=>{for(var n in r)$(e,n,{get:r[n],enumerable:!0})},M=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of W(r))!D.call(e,t)&&t!==n&&$(e,t,{get:()=>r[t],enumerable:!(s=F(r,t))||s.enumerable});return e};var z=e=>M($({},"__esModule",{value:!0}),e);var Pe={};U(Pe,{rc_any:()=>re,rc_array:()=>he,rc_assert_is_valid:()=>me,rc_boolean:()=>te,rc_date:()=>ae,rc_extends_obj:()=>fe,rc_get_obj_schema:()=>le,rc_instanceof:()=>ie,rc_is_valid:()=>N,rc_literals:()=>ce,rc_loose_array:()=>_e,rc_loose_parse:()=>xe,rc_null:()=>ee,rc_number:()=>oe,rc_obj_intersection:()=>Te,rc_obj_omit:()=>Re,rc_obj_pick:()=>de,rc_object:()=>O,rc_parse:()=>w,rc_parse_json:()=>$e,rc_parser:()=>ge,rc_record:()=>be,rc_recursive:()=>we,rc_rename_from_key:()=>V,rc_rename_key:()=>ye,rc_strict_obj:()=>pe,rc_string:()=>se,rc_transform:()=>ke,rc_tuple:()=>je,rc_undefined:()=>Y,rc_union:()=>ue,rc_unknown:()=>ne,rc_validator:()=>Oe,snakeCase:()=>v});module.exports=z(Pe);function H(e){return{...this,i:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function E(e,r){e.warnings.push(g(e,r))}function K(e,r){r.forEach(n=>E(e,n))}function u(e,r,n,s){if(e.c&&r===void 0)return[!0,r];if(e.u&&r==null)return[!0,r];if(e.y&&r===null)return[!0,r];let t=s();if(t&&(t===!0||!t.errors)){let o=t===!0?r:t.data;return e.t&&!e.t(o)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,o]}let a=e.i;if(a!==void 0)return E(n,`Fallback used, errors -> ${A(t,n,e,r)}`),[!0,Ee(a)?a():a];if(e.f&&e.o){let o=e.o(r);if(o)return e.t&&!e.t(o.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(E(n,`Autofixed from error "${A(t,n,e,r)}"`),[!0,o.fixed])}return[!1,t?t.errors:[e.l(r)]]}function A(e,r,n,s){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.l(s)}function J(e){return{...this,f:!0,o:e}}function L(e){return{...this,t:e}}function Z(){return{...this,c:!0}}function G(e){return`Type '${P(e,!!this.p)}' is not assignable to '${this.e}'`}function Q(){return{...this,y:!0,e:`${this.e}_or_null`}}function X(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={withFallback:H,where:L,optional:Z,l:G,orNullish:X,withAutofix:J,orNull:Q,i:void 0,t:void 0,c:!1,y:!1,u:!1,f:!1,p:!1,s:void 0,o:void 0,R:void 0,n:void 0,a:!1,T:!1,d:[]},Y={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},ee={...i,r(e,r){return u(this,e,r,()=>e===null)},e:"null"},re={...i,r(e,r){return u(this,e,r,()=>!0)},e:"any"},ne={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},te={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},se={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},oe={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ae={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ie(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function ce(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...i,r(r,n){return u(this,r,n,()=>{for(let s of e)if(r===s)return!0;return!1})},p:!0,e:e.length==1?P(e[0],!0):e.map(r=>P(r,!0)).join(" | ")}}var C=1;function ue(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...i,r(r,n){return u(this,r,n,()=>{let s=n.path,t=[],a=0,o=!1,T=[],y=0;for(let c of e){y+=1,c.a&&(n.path=`${s}|union ${y}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[f,b]=c.r(r,n);n.objErrShortCircuit=!1;let l=n.objErrKeyIndex;if(n.objErrKeyIndex=0,f)return!0;c.a&&l!==-1?l>0?T.push(...b):(a<C&&t.push(...b),a+=1):o=!0}return n.path=s,T.length>0||t.length>0?((a>C||o)&&t.push("not matches any other union member"),{errors:[...T,...t],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function V(e,r){return{...r,s:e}}var ye=V;function O(e,{normalizeKeysFrom:r}={}){return{...i,n:e,e:"object",a:!0,d:Object.entries(e),r(n,s){return u(this,n,s,()=>{if(!I(n))return s.objErrKeyIndex=-1,!1;let t=this.e==="strict_obj"?new Set(Object.keys(n)):void 0,a={},o=[],T=s.path,y=-1;for(let[c,f]of this.d){let b=c;y+=1;let l=`.${c}`;s.path=`${T}${l}`;let p,R=c;if(f.s&&(p=n[f.s],R=f.s),p===void 0&&(p=n[c],R=c),p===void 0&&r==="snake_case"){let h=v(c);p=n[h],R=h}t?.delete(R);let[j,x]=f.r(p,s);if(j)a[b]=x;else{for(let h of x)o.push(g(s,h));if(s.objErrShortCircuit){s.objErrKeyIndex=y;break}}}if(t&&t.size>0)for(let c of t)o.push(`Key '${c}' is not defined in the object shape`);return o.length>0?{errors:o,data:void 0}:this.T?{errors:!1,data:{...n,...a}}:{errors:!1,data:a}})}}}function fe(e){return{...O(e),e:"extends_object",T:!0}}function le(e){return e.n}function pe(e){return{...O(e),e:"strict_obj"}}function Te(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function de(e,r){let n={};if(!e.n)throw new Error("rc_obj_pick: obj must be an object type");for(let s of r){let t=e.n[s];t&&(n[s]=t)}return O(n)}function Re(e,r){let n={};if(!e.n)throw new Error("rc_obj_omit: obj must be an object type");for(let s of Object.keys(e.n))r.includes(s)||(n[s]=e.n[s]);return O(n)}function be(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(s,t){return u(this,s,t,()=>{if(!I(s))return!1;let a={},o=[],T=t.path;for(let[y,c]of Object.entries(s)){let f=`.${y}`,b=`${T}${f}`;if(t.path=b,r&&!r(y)){o.push(g(t,`Key '${y}' is not allowed`));continue}let l=s[y],[p,R]=e.r(c,t);if(p)a[y]=l;else{let j=R;for(let x of j)o.push(g(t,x));if(t.objErrShortCircuit)break}}if(o.length>0)if(n)K(t,o);else return{errors:o,data:void 0};return{errors:!1,data:a}})}}}function q(e,r){if(typeof r=="string"&&!e.n?.[r])throw new Error(`${e.e} can't be used with unique key option`)}function S(e,r,n,s=!1,t){let a=[],o=[],T=new Set,y=n.path,c=Array.isArray(r),f=-1;for(let b of e){f++;let l=c?r[f]:r,p=`[${f}]`,R=`${y}${p}`;n.path=R;let j=l.r(b,n),[x,h]=j;n.path=R;let _=t?.unique;if(x&&_){let d=h,m=typeof _=="string";m?d=h[_]:typeof _=="function"&&(d=_(h)),T.has(d)?(m&&(n.path=`${y}${p}.${_}`),j=[!1,[g(n,m?`Type '${l.n?.[_]?.e}' with value "${d}" is not unique`:typeof _=="function"?`Type '${l.e}' unique fn return with value "${d}" is not unique`:`${l.e} value is not unique`)]]):T.add(d)}let[B,k]=j;if(B)o.push(k);else if(s){a.push(k.map(d=>g(n,d)));continue}else return{errors:k.map(d=>g(n,d)),data:void 0}}if(a.length>0){if(o.length===0)return{errors:a.slice(0,5).flat(),data:void 0};K(n,a.flat())}return{errors:!1,data:o}}function he(e,r){return q(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!1,r):!1)}}}function _e(e,r){return q(e,r?.unique),{...i,e:`${e.e}[]`,r(n,s){return u(this,n,s,()=>Array.isArray(n)?n.length===0?!0:S.call(this,n,e,s,!0,r):!1)}}}function je(e){return{...i,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return u(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:S.call(this,r,e,n))}}}function w(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0},[s,t]=r.r(e,n);return s?{error:!1,data:t,warnings:n.warnings.length>0?n.warnings:!1}:{error:!0,errors:t}}function ge(e){return r=>w(r,e)}function xe(e,r){let n=w(e,r);return n.error?{data:null,errors:n.errors,warnings:!1}:{data:n.data,errors:!1,warnings:n.warnings}}function N(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function Oe(e){return r=>N(r,e)}function we(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function ke(e,r){return{...i,e:`transform_from_${e.e}`,r(n,s){let[t,a]=e.r(n,s);return t?[!0,r(a)]:[!1,a]}}}function 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 me(e){if(e.error)throw new Error(`invalid input: ${e.errors.join(", ")}`)}function I(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 $e(e,r){try{let n=JSON.parse(e);return w(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${I(n)?n.message:""}`]}}}function Ee(e){return typeof e=="function"}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_extends_obj,rc_get_obj_schema,rc_instanceof,rc_is_valid,rc_literals,rc_loose_array,rc_loose_parse,rc_null,rc_number,rc_obj_intersection,rc_obj_omit,rc_obj_pick,rc_object,rc_parse,rc_parse_json,rc_parser,rc_record,rc_recursive,rc_rename_from_key,rc_rename_key,rc_strict_obj,rc_string,rc_transform,rc_tuple,rc_undefined,rc_union,rc_unknown,rc_validator,snakeCase});
@@ -99,5 +99,10 @@ declare function rc_assert_is_valid<S>(result: RcParseResult<S>): asserts result
99
99
  warnings: string[] | false;
100
100
  };
101
101
  declare function rc_parse_json<T>(jsonString: string, schema: RcType<T>): RcParseResult<T>;
102
+ type Prettify<T> = T extends Record<string, any> ? {
103
+ [K in keyof T]: Prettify<T[K]>;
104
+ } : T;
105
+ type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
106
+ type RcSchemaHasType<E, T extends E> = T;
102
107
 
103
- export { RcInferType, RcParseResult, RcParser, RcType, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_extends_obj, rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_null, rc_number, rc_obj_intersection, rc_obj_omit, rc_obj_pick, rc_object, rc_parse, rc_parse_json, rc_parser, rc_record, rc_recursive, rc_rename_from_key, rc_rename_key, rc_strict_obj, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_validator };
108
+ export { RcInferType, RcParseResult, RcParser, RcPrettyInferType, RcSchemaHasType, RcType, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_extends_obj, rc_get_obj_schema, rc_instanceof, rc_is_valid, rc_literals, rc_loose_array, rc_loose_parse, rc_null, rc_number, rc_obj_intersection, rc_obj_omit, rc_obj_pick, rc_object, rc_parse, rc_parse_json, rc_parser, rc_record, rc_recursive, rc_rename_from_key, rc_rename_key, rc_strict_obj, rc_string, rc_transform, rc_tuple, rc_undefined, rc_union, rc_unknown, rc_validator };
package/dist/runcheck.js CHANGED
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-YAXWQU2M.js";export{c as rc_any,v as rc_array,F as rc_assert_is_valid,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,B as rc_is_valid,j as rc_literals,w as rc_loose_array,A as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,t as rc_obj_omit,s as rc_obj_pick,n as rc_object,y as rc_parse,H as rc_parse_json,z as rc_parser,u as rc_record,D as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,E as rc_transform,x as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,C as rc_validator,G as snakeCase};
1
+ import{A,B,C,D,E,F,G,H,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-WQBKLM3G.js";export{c as rc_any,v as rc_array,F as rc_assert_is_valid,e as rc_boolean,h as rc_date,o as rc_extends_obj,p as rc_get_obj_schema,i as rc_instanceof,B as rc_is_valid,j as rc_literals,w as rc_loose_array,A as rc_loose_parse,b as rc_null,g as rc_number,r as rc_obj_intersection,t as rc_obj_omit,s as rc_obj_pick,n as rc_object,y as rc_parse,H as rc_parse_json,z as rc_parser,u as rc_record,D as rc_recursive,l as rc_rename_from_key,m as rc_rename_key,q as rc_strict_obj,f as rc_string,E as rc_transform,x as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,C as rc_validator,G as snakeCase};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "runcheck",
3
3
  "description": "A tiny (less than 2 KiB Gzipped) and treeshakable! lib for typescript runtime type checks with autofix support",
4
- "version": "0.31.0",
4
+ "version": "0.32.0",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "test": "vitest --ui",