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