runcheck 0.33.0 → 0.34.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 +19 -23
- package/dist/autofixable.cjs +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-GF3CAQXF.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +11 -4
- package/dist/runcheck.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3GG5XFSK.js +0 -1
package/README.md
CHANGED
|
@@ -82,6 +82,11 @@ const shape = rc_object({
|
|
|
82
82
|
name: rc_string,
|
|
83
83
|
age: rc_number,
|
|
84
84
|
isCool: rc_boolean,
|
|
85
|
+
// nested objects
|
|
86
|
+
address: {
|
|
87
|
+
street: rc_string,
|
|
88
|
+
number: rc_number,
|
|
89
|
+
},
|
|
85
90
|
})
|
|
86
91
|
```
|
|
87
92
|
|
|
@@ -129,16 +134,10 @@ const shape = rc_record(rc_number, {
|
|
|
129
134
|
|
|
130
135
|
Validates only the values of a object, equivalent to `Record<string, T>` in typescript. But, it will reject invalid keys and return the valid ones.
|
|
131
136
|
|
|
132
|
-
|
|
133
|
-
|
|
134
137
|
```ts
|
|
135
138
|
const shape = rc_loose_record(rc_number)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
|
|
142
141
|
# Parsing
|
|
143
142
|
|
|
144
143
|
```ts
|
|
@@ -416,23 +415,11 @@ const shape = rc_object({
|
|
|
416
415
|
const baseSchema = rc_obj_omit(shape, ['isCool'])
|
|
417
416
|
```
|
|
418
417
|
|
|
419
|
-
#
|
|
418
|
+
# `rc_obj_builder`
|
|
420
419
|
|
|
421
|
-
|
|
420
|
+
Creates a `rc_object` from a type. This gives better error messages and autocompletion.
|
|
422
421
|
|
|
423
422
|
```ts
|
|
424
|
-
const schema = rc_object({
|
|
425
|
-
level1: {
|
|
426
|
-
level2: {
|
|
427
|
-
level3: {
|
|
428
|
-
level4: {
|
|
429
|
-
level5: rc_string,
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
})
|
|
435
|
-
|
|
436
423
|
type SchemaType = {
|
|
437
424
|
level1: {
|
|
438
425
|
level2: {
|
|
@@ -445,7 +432,16 @@ type SchemaType = {
|
|
|
445
432
|
}
|
|
446
433
|
}
|
|
447
434
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
435
|
+
const schema = rc_obj_builder<SchemaType>()({
|
|
436
|
+
level1: {
|
|
437
|
+
level2: {
|
|
438
|
+
level3: {
|
|
439
|
+
level4: {
|
|
440
|
+
level5: rc_string,
|
|
441
|
+
// better error here
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
})
|
|
451
447
|
```
|
package/dist/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var p=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=p(r,t))||a.enumerable});return e};var j=e=>_(u({},"__esModule",{value:!0}),e);var C={};h(C,{rc_boolean_autofix:()=>K,rc_number_autofix:()=>I,rc_string_autofix:()=>A});module.exports=j(C);function x(e){return{...this,i:e}}function g(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function y(e,r){e.warnings.push(g(e,r))}function o(e,r,n,a){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=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 y(n,`Fallback used, errors -> ${f(t,n,e,r)}`),[!0,P(c)?c():c];if(e.f&&e.s){let i=e.s(r);if(i)return e.t&&!e.t(i.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(y(n,`Autofixed from error "${f(t,n,e,r)}"`),[!0,i.fixed])}return[!1,t?t.errors:[e.l(r)]]}function f(e,r,n,a){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.l(a)}function O(e){return{...this,f:!0,s:e}}function k(e){return{...this,t:e}}function m(){return{...this,c:!0}}function w(e){return`Type '${E(e,!!this.T)}' is not assignable to '${this.e}'`}function $(){return{...this,y:!0,e:`${this.e}_or_null`}}function S(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var s={withFallback:x,where:k,optional:m,l:w,orNullish:S,withAutofix:O,orNull:$,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:[]},V={...s,r(e,r){return o(this,e,r,()=>e===void 0)},e:"undefined"},v={...s,r(e,r){return o(this,e,r,()=>e===null)},e:"null"},q={...s,r(e,r){return o(this,e,r,()=>!0)},e:"any"},B={...s,r(e,r){return o(this,e,r,()=>!0)},e:"unknown"},l={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},T={...s,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},d={...s,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},F={...s,r(e,r){return o(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function E(e,r){let n=(()=>{if(typeof e=="object"){if(Array.isArray(e))return"array";if(!e)return"null"}return typeof e})();return r&&(n==="string"||n==="number"||n==="boolean")?`${n}(${e})`:n}function P(e){return typeof e=="function"}var K=l.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),A=T.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),I=d.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});
|
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-GF3CAQXF.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 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};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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:()=>k,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 typeof e=="object"&&e!==null&&"_kind_"in e}function v(e){if(Te(e))return e;if(w(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(!w(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(!w(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 k(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=>k(r,e)}function we(e,r){let n=k(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 w(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 k(n,r)}catch(n){return{error:!0,errors:[`json parse error: ${w(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
|
@@ -35,9 +35,11 @@ declare function rc_union<T extends RcType<any>[]>(...types: T): RcType<RcInferT
|
|
|
35
35
|
declare function rc_rename_from_key<T extends RcType<any>>(alternativeNames: string, type: T): RcType<RcInferType<T>>;
|
|
36
36
|
/** @deprecated use `rc_rename_from_key` instead */
|
|
37
37
|
declare const rc_rename_key: typeof rc_rename_from_key;
|
|
38
|
-
type RcObject =
|
|
38
|
+
type RcObject = {
|
|
39
|
+
[key: string]: RcType<any> | RcObject;
|
|
40
|
+
};
|
|
39
41
|
type TypeOfObjectType<T extends RcObject> = {
|
|
40
|
-
[K in keyof T]: RcInferType<T[K]
|
|
42
|
+
[K in keyof T]: T[K] extends RcType<any> ? RcInferType<T[K]> : T[K] extends RcObject ? TypeOfObjectType<T[K]> : never;
|
|
41
43
|
};
|
|
42
44
|
type RcObjType<T extends RcObject> = RcType<TypeOfObjectType<T>>;
|
|
43
45
|
declare function rc_object<T extends RcObject>(shape: T, { normalizeKeysFrom }?: {
|
|
@@ -107,6 +109,11 @@ type Prettify<T> = T extends Record<string, any> ? {
|
|
|
107
109
|
[K in keyof T]: Prettify<T[K]>;
|
|
108
110
|
} : T;
|
|
109
111
|
type RcPrettyInferType<T extends RcType<any>> = Prettify<RcInferType<T>>;
|
|
110
|
-
type
|
|
112
|
+
type TypeToRcType<T> = [T] extends [
|
|
113
|
+
string | number | boolean | undefined | null
|
|
114
|
+
] ? RcType<T> : {
|
|
115
|
+
[K in keyof T]: TypeToRcType<T[K]>;
|
|
116
|
+
};
|
|
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>;
|
|
111
118
|
|
|
112
|
-
export { RcInferType, RcParseResult, RcParser, RcPrettyInferType,
|
|
119
|
+
export { RcInferType, RcParseResult, RcParser, RcPrettyInferType, 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_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 };
|
package/dist/runcheck.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A,B,C,D,E,F,G,H,I,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-GF3CAQXF.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-3GG5XFSK.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,J(a)?a():a];if(e.y&&e.s){let o=e.s(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,s: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,o:void 0,s: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"},Q={...i,r(e,r){return u(this,e,r,()=>!0)},e:"unknown"},X={...i,r(e,r){return u(this,e,r,()=>typeof e=="boolean")},e:"boolean"},Y={...i,r(e,r){return u(this,e,r,()=>typeof e=="string")},e:"string"},ee={...i,r(e,r){return u(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},re={...i,r(e,r){return u(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ne(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function te(...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 se(...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,o:e}}var oe=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.o&&(p=n[f.o],R=f.o),p===void 0&&(p=n[c],R=c),p===void 0&&r==="snake_case"){let h=H(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 ae(e){return{...O(e),e:"extends_object",p:!0}}function ie(e){return e.n}function ce(e){return{...O(e),e:"strict_obj"}}function ue(...e){let r={};for(let n of e)Object.assign(r,n.n);return O(r)}function ye(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 fe(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 M(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 le(e,{checkKey:r}={}){return M(e,{checkKey:r,looseCheck:!0})}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,w=typeof _=="string";w?d=h[_]:typeof _=="function"&&(d=_(h)),T.has(d)?(w&&(n.path=`${y}${p}.${_}`),j=[!1,[g(n,w?`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,k]=j;if(V)o.push(k);else if(t){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};C(n,a.flat())}return{errors:!1,data:o}}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,!1,r):!1)}}}function Te(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 Re(e){return r=>P(r,e)}function be(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 z(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function he(e){return r=>z(r,e)}function _e(e){return{...i,e:"recursive",r(r,n){return e().r(r,n)}}}function je(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 ge(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 H(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function xe(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,Q as d,X as e,Y as f,ee as g,re as h,ne as i,te as j,se as k,U as l,oe as m,O as n,ae as o,ie as p,ce as q,ue as r,ye as s,fe as t,M as u,le as v,pe as w,Te as x,de as y,P as z,Re as A,be as B,z as C,he as D,_e as E,je as F,ge as G,H,xe as I};
|