runcheck 0.35.2 → 0.36.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/README.md +39 -0
- package/dist/autofixable.cjs +1 -1
- package/dist/autofixable.js +1 -1
- package/dist/chunk-RQJKBTUL.js +1 -0
- package/dist/runcheck.cjs +1 -1
- package/dist/runcheck.d.ts +16 -5
- package/dist/runcheck.js +1 -1
- package/package.json +5 -4
- package/dist/chunk-S5P42XEZ.js +0 -1
package/README.md
CHANGED
|
@@ -195,6 +195,21 @@ const parseResult = parser(jsonInput)
|
|
|
195
195
|
const parseResult2 = parser(jsonInput2)
|
|
196
196
|
```
|
|
197
197
|
|
|
198
|
+
## Strict parsing
|
|
199
|
+
|
|
200
|
+
Use the `strict` option to disable autofix and fallback
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const parseResult = rc_parse(
|
|
204
|
+
input,
|
|
205
|
+
// fallback will be ignored
|
|
206
|
+
rc_array(rc_string).withFallback([]),
|
|
207
|
+
{
|
|
208
|
+
strict: true,
|
|
209
|
+
},
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
198
213
|
# Type assertion
|
|
199
214
|
|
|
200
215
|
Use `rc_is_valid` and `rc_validator` to do a simple type assertion.
|
|
@@ -352,6 +367,30 @@ const result = rc_parse(
|
|
|
352
367
|
)
|
|
353
368
|
```
|
|
354
369
|
|
|
370
|
+
# Default types
|
|
371
|
+
|
|
372
|
+
You can use `rc_default` to provide a default value if the input is `undefined`.
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
const input = {
|
|
376
|
+
name: 'John',
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const result = rc_parse(
|
|
380
|
+
input,
|
|
381
|
+
rc_object({
|
|
382
|
+
name: rc_string,
|
|
383
|
+
age: rc_default(rc_number, 20),
|
|
384
|
+
}),
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
if (result.ok) {
|
|
388
|
+
result.data.age // = 20
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
If you need to use default in nullish values you can use `rc_nullish_default`.
|
|
393
|
+
|
|
355
394
|
# Advanced object types
|
|
356
395
|
|
|
357
396
|
## `rc_rename_from_key`
|
package/dist/autofixable.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var j=(e,r)=>{for(var n in r)u(e,n,{get:r[n],enumerable:!0})},x=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of h(r))!_.call(e,t)&&t!==n&&u(e,t,{get:()=>r[t],enumerable:!(i=b(r,t))||i.enumerable});return e};var g=e=>x(u({},"__esModule",{value:!0}),e);var I={};j(I,{rc_boolean_autofix:()=>E,rc_number_autofix:()=>A,rc_string_autofix:()=>N});module.exports=g(I);function O(e){return{...this,y:e}}function k(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function y(e,r){e.warnings.push(k(e,r))}function o(e,r,n,i){if(e.o&&r===void 0)return[!0,r];if(e.s&&r==null)return[!0,r];if(e.a&&r===null)return[!0,r];let t=i();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]}if(!n.strict){let a=e.y;if(a!==void 0)return y(n,`Fallback used, errors -> ${f(t,n,e,r)}`),[!0,S(a)?a():a];if(e.f&&e.c){let c=e.c(r);if(c)return e.t&&!e.t(c.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(y(n,`Autofixed from error "${f(t,n,e,r)}"`),[!0,c.fixed])}}return[!1,t?t.errors:[T(e,r)]]}function f(e,r,n,i){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):T(n,i)}function w(e){return{...this,f:!0,c:e}}function m(e){return{...this,t:e}}function l(){return{...this,o:!0}}function T(e,r){return`Type '${P(r,!!e.l)}' is not assignable to '${e.e}'`}function $(){return{...this,a:!0,e:`${this.e}_or_null`}}function K(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var s={__rc_type:void 0,withFallback:O,where:m,optional:l,optionalKey:l,orNullish:K,withAutofix:w,orNull:$,y:void 0,t:void 0,o:!1,a:!1,s:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},q={...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"},V={...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"},d={...s,r(e,r){return o(this,e,r,()=>typeof e=="boolean")},e:"boolean"},p={...s,r(e,r){return o(this,e,r,()=>typeof e=="string")},e:"string"},R={...s,r(e,r){return o(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},U={...s,r(e,r){return o(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 E=d.withAutofix(e=>e==null||e===0||e===1?{fixed:!!e}:e==="true"||e==="false"?{fixed:e==="true"}:!1),N=p.withAutofix(e=>typeof e=="number"&&!Number.isNaN(e)?{fixed:e.toString()}:!1),A=R.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-RQJKBTUL.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 U(e){return{...this,y:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function K(e,r){e.warnings.push(_(e,r))}function C(e,r){r.forEach(n=>K(e,n))}function i(e,r,n,t){if(e.o&&r===void 0)return[!0,r];if(e.s&&r==null)return[!0,r];if(e.a&&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]}if(!n.strict){let o=e.y;if(o!==void 0)return K(n,`Fallback used, errors -> ${I(s,n,e,r)}`),[!0,E(o)?o():o];if(e.f&&e.c){let a=e.c(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(K(n,`Autofixed from error "${I(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[q(e,r)]]}function I(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):q(n,t)}function F(e){return{...this,f:!0,c:e}}function W(e){return{...this,t:e}}function A(){return{...this,o:!0}}function q(e,r){return`Type '${w(r,!!e.l)}' is not assignable to '${e.e}'`}function D(){return{...this,a:!0,e:`${this.e}_or_null`}}function M(){return{...this,s:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:U,where:W,optional:A,optionalKey:A,orNullish:M,withAutofix:F,orNull:D,y:void 0,t:void 0,o:!1,a:!1,s:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},G={...c,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},H={...c,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},X={...c,r(e,r){return i(this,e,r,()=>!0)},e:"any"},Y={...c,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},ee={...c,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},re={...c,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},ne={...c,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},te={...c,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function se(e){return{...c,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function oe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},l:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var N=1;function ae(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return i(this,r,n,()=>{let t=n.path,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.u&&(n.path=`${t}|union ${f}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[u,T]=R.r(r,n);n.objErrShortCircuit=!1;let d=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&d!==-1?d>0?y.push(...T):(o<N&&s.push(...T),o+=1):a=!0}return n.path=t,y.length>0||s.length>0?((o>N||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function ie(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return i(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function ce(e,r){return{...e,o:!1,s:!1,a:!1,r(n,t){return i(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:E(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function z(e,r){return{...r,i:e}}var ue=z;function Q(e){return k(e)&&"__rc_type"in e}function v(e){if(Q(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=v(t);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=v(s);return{...c,n,e:"object",u:!0,d:Object.entries(n),r(t,s){return i(this,t,s,()=>{if(!k(t))return s.objErrKeyIndex=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.path,R=-1;for(let[u,T]of this.d){let d=u;R+=1;let x=`.${u}`;s.path=`${f}${x}`;let p,b=u;if(T.i&&(p=t[T.i],b=T.i),p===void 0&&(p=t[u],b=u),p===void 0&&r==="snake_case"){let l=Z(u);p=t[l],b=l}o?.delete(b);let[O,g]=T.r(p,s);if(O)a[d]=g;else{for(let l of g)y.push(_(s,l));if(s.objErrShortCircuit){s.objErrKeyIndex=R;break}}}if(o&&o.size>0)for(let u of o)y.push(`Key '${u}' is not defined in the object shape`);return y.length>0?{errors:y,data:void 0}:this.T?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function ye(e,r){return{...j(e,r),e:"extends_object",T:!0}}function fe(e){return e.n}function le(e,r){return{...j(e,r),e:"strict_obj"}}function Te(...e){let r={};for(let n of e)Object.assign(r,n.n);return j(r)}function de(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 j(n)}function pe(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 j(n)}function J(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return i(this,t,s,()=>{if(!k(t))return!1;let o={},a=[],y=s.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.path=T,r&&!r(f)){a.push(_(s,`Key '${f}' is not allowed`));continue}let d=t[f],[x,p]=e.r(R,s);if(x)o[f]=d;else{let b=p;for(let O of b)a.push(_(s,O));if(s.objErrShortCircuit)break}}if(a.length>0)if(n)C(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function Re(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 P(e,r,n,t=!1,s){let o=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,x=`[${u}]`,p=`${f}${x}`;n.path=p;let b=d.r(T,n),[O,g]=b;n.path=p;let l=s?.unique;if(O&&l){let h=g,$=typeof l=="string";$?h=g[l]:typeof l=="function"&&(h=l(g)),y.has(h)?($&&(n.path=`${f}${x}.${l}`),b=[!1,[_(n,$?`Type '${d.n?.[l]?.e}' with value "${h}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${h}" is not unique`:`${d.e} value is not unique`)]]):y.add(h)}let[B,m]=b;if(B)a.push(m);else if(t){o.push(m.map(h=>_(n,h)));continue}else return{errors:m.map(h=>_(n,h)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};C(n,o.flat())}return{errors:!1,data:a}}function be(e,r){return V(e,r?.unique),{...c,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!1,r):!1)}}}function he(e,r){return V(e,r?.unique),{...c,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:P.call(this,n,e,t,!0,r):!1)}}}function _e(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:P.call(this,r,e,n))}}}function S(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:o}}function je(e){return r=>S(r,e)}function xe(e,r,n){let t=S(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function L(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function ge(e){return r=>L(r,e)}function Oe(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function ke(e,r){return{...c,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);return s?[!0,r(o)]:[!1,o]}}}function w(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 we(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 me(e,r){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let n=JSON.parse(e);return S(n,r)}catch(n){return{ok:!1,error:!0,errors:[`json parse error: ${k(n)?n.message:""}`]}}}function E(e){return typeof e=="function"}function $e(){return(e,r)=>j(e,r)}export{G as a,H as b,X as c,Y as d,ee as e,re as f,ne as g,te as h,se as i,oe as j,ae as k,ie as l,ce as m,z as n,ue as o,j as p,ye as q,fe as r,le as s,Te as t,de as u,pe as v,J as w,Re as x,be as y,he as z,_e as A,S as B,je as C,xe as D,L as E,ge as F,Oe as G,ke as H,we as I,Z as J,me as K,$e as L};
|
package/dist/runcheck.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var L=(e,r)=>{for(var n in r)P(e,n,{get:r[n],enumerable:!0})},Z=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Q(r))!J.call(e,s)&&s!==n&&P(e,s,{get:()=>r[s],enumerable:!(t=z(r,s))||t.enumerable});return e};var G=e=>Z(P({},"__esModule",{value:!0}),e);var Ce={};L(Ce,{rc_any:()=>se,rc_array:()=>ke,rc_assert_is_valid:()=>Ie,rc_boolean:()=>ae,rc_date:()=>ue,rc_default:()=>Te,rc_extends_obj:()=>be,rc_get_obj_schema:()=>he,rc_instanceof:()=>ye,rc_is_valid:()=>W,rc_literals:()=>fe,rc_loose_array:()=>we,rc_loose_parse:()=>Ke,rc_loose_record:()=>Oe,rc_null:()=>te,rc_nullish_default:()=>de,rc_number:()=>ce,rc_obj_builder:()=>Ne,rc_obj_intersection:()=>je,rc_obj_omit:()=>ge,rc_obj_pick:()=>xe,rc_object:()=>_,rc_parse:()=>m,rc_parse_json:()=>Ae,rc_parser:()=>$e,rc_record:()=>U,rc_recursive:()=>Se,rc_rename_from_key:()=>V,rc_rename_key:()=>pe,rc_strict_obj:()=>_e,rc_string:()=>ie,rc_transform:()=>Ee,rc_tuple:()=>me,rc_undefined:()=>ne,rc_union:()=>le,rc_unknown:()=>oe,rc_validator:()=>Pe,snakeCase:()=>D});module.exports=G(Ce);function H(e){return{...this,y: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 q(e,r){r.forEach(n=>S(e,n))}function i(e,r,n,t){if(e.s&&r===void 0)return[!0,r];if(e.o&&r==null)return[!0,r];if(e.a&&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]}if(!n.strict){let o=e.y;if(o!==void 0)return S(n,`Fallback used, errors -> ${A(s,n,e,r)}`),[!0,I(o)?o():o];if(e.f&&e.c){let a=e.c(r);if(a)return e.t&&!e.t(a.fixed)?[!1,[`Predicate failed for autofix in type '${e.e}'`]]:(S(n,`Autofixed from error "${A(s,n,e,r)}"`),[!0,a.fixed])}}return[!1,s?s.errors:[v(e,r)]]}function A(e,r,n,t){return e?e.errors.map(s=>s.replace(r.path,"")).join("; "):v(n,t)}function X(e){return{...this,f:!0,c:e}}function Y(e){return{...this,t:e}}function N(){return{...this,s:!0}}function v(e,r){return`Type '${w(r,!!e.l)}' is not assignable to '${e.e}'`}function ee(){return{...this,a:!0,e:`${this.e}_or_null`}}function re(){return{...this,o:!0,e:`${this.e}_or_nullish`}}var c={__rc_type:void 0,withFallback:H,where:Y,optional:N,optionalKey:N,orNullish:re,withAutofix:X,orNull:ee,y:void 0,t:void 0,s:!1,a:!1,o:!1,f:!1,l:!1,i:void 0,c:void 0,p:void 0,n:void 0,u:!1,T:!1,d:[]},ne={...c,r(e,r){return i(this,e,r,()=>e===void 0)},e:"undefined"},te={...c,r(e,r){return i(this,e,r,()=>e===null)},e:"null"},se={...c,r(e,r){return i(this,e,r,()=>!0)},e:"any"},oe={...c,r(e,r){return i(this,e,r,()=>!0)},e:"unknown"},ae={...c,r(e,r){return i(this,e,r,()=>typeof e=="boolean")},e:"boolean"},ie={...c,r(e,r){return i(this,e,r,()=>typeof e=="string")},e:"string"},ce={...c,r(e,r){return i(this,e,r,()=>typeof e=="number"&&!Number.isNaN(e))},e:"number"},ue={...c,r(e,r){return i(this,e,r,()=>typeof e=="object"&&e instanceof Date&&!Number.isNaN(e.getTime()))},e:"date"};function ye(e){return{...c,r(r,n){return i(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function fe(...e){if(e.length===0)throw new Error("rc_literal requires at least one literal");return{...c,r(r,n){return i(this,r,n,()=>{for(let t of e)if(r===t)return!0;return!1})},l:!0,e:e.length==1?w(e[0],!0):e.map(r=>w(r,!0)).join(" | ")}}var C=1;function le(...e){if(e.length===0)throw new Error("Unions should have at least one type");return{...c,r(r,n){return i(this,r,n,()=>{let t=n.path,s=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.u&&(n.path=`${t}|union ${f}|`),n.objErrShortCircuit=!0,n.objErrKeyIndex=0;let[u,T]=R.r(r,n);n.objErrShortCircuit=!1;let d=n.objErrKeyIndex;if(n.objErrKeyIndex=0,u)return!0;R.u&&d!==-1?d>0?y.push(...T):(o<C&&s.push(...T),o+=1):a=!0}return n.path=t,y.length>0||s.length>0?((o>C||a)&&s.push("not matches any other union member"),{errors:[...y,...s],data:void 0}):!1})},e:e.map(r=>r.e).join(" | ")}}function Te(e,r){return{...e,s:!1,o:!1,a:!1,r(n,t){return i(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!==void 0?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_default`}}function de(e,r){return{...e,s:!1,o:!1,a:!1,r(n,t){return i(this,n,t,()=>{let s=e.r(n,t),[o,a]=s;return o?a!=null?!0:{data:I(r)?r():r,errors:!1}:{data:void 0,errors:a}})},e:`${e.e}_nullish_default`}}function V(e,r){return{...r,i:e}}var pe=V;function Re(e){return k(e)&&"__rc_type"in e}function B(e){if(Re(e))return e;if(k(e)){let r={};for(let[n,t]of Object.entries(e))r[n]=B(t);return _(r)}throw new Error(`invalid schema: ${e}`)}function _(e,{normalizeKeysFrom:r}={}){let n={};for(let[t,s]of Object.entries(e))n[t]=B(s);return{...c,n,e:"object",u:!0,d:Object.entries(n),r(t,s){return i(this,t,s,()=>{if(!k(t))return s.objErrKeyIndex=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(t)):void 0,a={},y=[],f=s.path,R=-1;for(let[u,T]of this.d){let d=u;R+=1;let x=`.${u}`;s.path=`${f}${x}`;let p,b=u;if(T.i&&(p=t[T.i],b=T.i),p===void 0&&(p=t[u],b=u),p===void 0&&r==="snake_case"){let l=D(u);p=t[l],b=l}o?.delete(b);let[O,g]=T.r(p,s);if(O)a[d]=g;else{for(let l of g)y.push(j(s,l));if(s.objErrShortCircuit){s.objErrKeyIndex=R;break}}}if(o&&o.size>0)for(let u of o)y.push(`Key '${u}' is not defined in the object shape`);return y.length>0?{errors:y,data:void 0}:this.T?{errors:!1,data:{...t,...a}}:{errors:!1,data:a}})}}}function be(e,r){return{..._(e,r),e:"extends_object",T:!0}}function he(e){return e.n}function _e(e,r){return{..._(e,r),e:"strict_obj"}}function je(...e){let r={};for(let n of e)Object.assign(r,n.n);return _(r)}function xe(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 _(n)}function ge(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 _(n)}function U(e,{checkKey:r,looseCheck:n}={}){return{...c,e:`record<string, ${e.e}>`,r(t,s){return i(this,t,s,()=>{if(!k(t))return!1;let o={},a=[],y=s.path;for(let[f,R]of Object.entries(t)){let u=`.${f}`,T=`${y}${u}`;if(s.path=T,r&&!r(f)){a.push(j(s,`Key '${f}' is not allowed`));continue}let d=t[f],[x,p]=e.r(R,s);if(x)o[f]=d;else{let b=p;for(let O of b)a.push(j(s,O));if(s.objErrShortCircuit)break}}if(a.length>0)if(n)q(s,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function Oe(e,{checkKey:r}={}){return U(e,{checkKey:r,looseCheck:!0})}function F(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 o=[],a=[],y=new Set,f=n.path,R=Array.isArray(r),u=-1;for(let T of e){u++;let d=R?r[u]:r,x=`[${u}]`,p=`${f}${x}`;n.path=p;let b=d.r(T,n),[O,g]=b;n.path=p;let l=s?.unique;if(O&&l){let h=g,K=typeof l=="string";K?h=g[l]:typeof l=="function"&&(h=l(g)),y.has(h)?(K&&(n.path=`${f}${x}.${l}`),b=[!1,[j(n,K?`Type '${d.n?.[l]?.e}' with value "${h}" is not unique`:typeof l=="function"?`Type '${d.e}' unique fn return with value "${h}" is not unique`:`${d.e} value is not unique`)]]):y.add(h)}let[M,$]=b;if(M)a.push($);else if(t){o.push($.map(h=>j(n,h)));continue}else return{errors:$.map(h=>j(n,h)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};q(n,o.flat())}return{errors:!1,data:a}}function ke(e,r){return F(e,r?.unique),{...c,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!1,r):!1)}}}function we(e,r){return F(e,r?.unique),{...c,e:`${e.e}[]`,r(n,t){return i(this,n,t,()=>Array.isArray(n)?n.length===0?!0:E.call(this,n,e,t,!0,r):!1)}}}function me(e){return{...c,e:`[${e.map(r=>r.e).join(", ")}]`,r(r,n){return i(this,r,n,()=>!Array.isArray(r)||r.length!==e.length?!1:E.call(this,r,e,n))}}}function m(e,r,{strict:n=!1}={}){let t={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:n},[s,o]=r.r(e,t);return s?{error:!1,ok:!0,data:o,warnings:t.warnings.length>0?t.warnings:!1}:{ok:!1,error:!0,errors:o}}function $e(e){return r=>m(r,e)}function Ke(e,r,n){let t=m(e,r,n);return t.error?{data:null,errors:t.errors,warnings:!1}:{data:t.data,errors:!1,warnings:t.warnings}}function W(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0,strict:!1};return!!r.r(e,n)[0]}function Pe(e){return r=>W(r,e)}function Se(e){return{...c,e:"recursive",r(r,n){return e().r(r,n)}}}function Ee(e,r){return{...c,e:`transform_from_${e.e}`,r(n,t){let[s,o]=e.r(n,t);return s?[!0,r(o)]:[!1,o]}}}function w(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 Ie(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 D(e){return e.replace(/\W+/g," ").split(/ |\B(?=[A-Z])/).map(r=>r.toLowerCase()).join("_")}function Ae(e,r){try{if(typeof e!="string")return{ok:!1,error:!0,errors:[`expected a json string, got ${w(e,!0)}`]};let n=JSON.parse(e);return m(n,r)}catch(n){return{ok:!1,error:!0,errors:[`json parse error: ${k(n)?n.message:""}`]}}}function I(e){return typeof e=="function"}function Ne(){return(e,r)=>_(e,r)}0&&(module.exports={rc_any,rc_array,rc_assert_is_valid,rc_boolean,rc_date,rc_default,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_nullish_default,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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
type RcParseResult<T> = {
|
|
2
2
|
error: false;
|
|
3
|
+
ok: true;
|
|
3
4
|
data: T;
|
|
4
5
|
warnings: string[] | false;
|
|
5
6
|
} | {
|
|
7
|
+
ok: false;
|
|
6
8
|
error: true;
|
|
7
9
|
errors: string[];
|
|
8
10
|
};
|
|
@@ -25,7 +27,7 @@ type RcBase<T, RequiredKey extends boolean> = {
|
|
|
25
27
|
readonly withAutofix: (customAutofix: (input: unknown) => false | {
|
|
26
28
|
fixed: T;
|
|
27
29
|
}) => RcType<T>;
|
|
28
|
-
readonly _optional_key_
|
|
30
|
+
readonly _optional_key_?: RequiredKey;
|
|
29
31
|
};
|
|
30
32
|
declare const rc_undefined: RcType<undefined>;
|
|
31
33
|
declare const rc_null: RcType<null>;
|
|
@@ -38,6 +40,10 @@ declare const rc_date: RcType<Date>;
|
|
|
38
40
|
declare function rc_instanceof<T extends Function>(classToCheck: T): RcType<T>;
|
|
39
41
|
declare function rc_literals<T extends (string | number | boolean)[]>(...literals: T): RcType<T[number]>;
|
|
40
42
|
declare function rc_union<T extends RcType<any>[]>(...types: T): RcType<RcInferType<T[number]>>;
|
|
43
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
44
|
+
declare function rc_default<T>(schema: RcType<T>, defaultValue: NotUndefined<T> | (() => NotUndefined<T>)): RcType<NotUndefined<T>>;
|
|
45
|
+
type NotNullish<T> = T extends null | undefined ? never : T;
|
|
46
|
+
declare function rc_nullish_default<T>(schema: RcType<T>, defaultValue: NotNullish<T> | (() => NotNullish<T>)): RcType<NotNullish<T>>;
|
|
41
47
|
declare function rc_rename_from_key<T extends RcType<any>>(alternativeNames: string, type: T): RcType<RcInferType<T>>;
|
|
42
48
|
/** @deprecated use `rc_rename_from_key` instead */
|
|
43
49
|
declare const rc_rename_key: typeof rc_rename_from_key;
|
|
@@ -103,16 +109,20 @@ type MapTupleToTypes<T extends readonly [...any[]]> = {
|
|
|
103
109
|
* TS equivalent example: [string, number, boolean]
|
|
104
110
|
*/
|
|
105
111
|
declare function rc_tuple<T extends readonly RcType<any>[]>(types: T): RcType<MapTupleToTypes<T>>;
|
|
112
|
+
type ParseOptions = {
|
|
113
|
+
/** ignore fallback and autofix */
|
|
114
|
+
strict?: boolean;
|
|
115
|
+
};
|
|
106
116
|
/**
|
|
107
117
|
* Parse a runcheck type. If valid return the valid input, with warning for autofix
|
|
108
118
|
* and fallback, or the errors if invalid
|
|
109
119
|
*/
|
|
110
|
-
declare function rc_parse<S>(input: any, type: RcType<S
|
|
120
|
+
declare function rc_parse<S>(input: any, type: RcType<S>, { strict }?: ParseOptions): RcParseResult<S>;
|
|
111
121
|
type RcParser<T> = (input: any) => RcParseResult<T>;
|
|
112
122
|
/** create a reusable parser for a certain type */
|
|
113
123
|
declare function rc_parser<S>(type: RcType<S>): RcParser<S>;
|
|
114
124
|
/** does the same as `rc_parse` but without requiring to check for errors before using the parsed data */
|
|
115
|
-
declare function rc_loose_parse<S>(input: any, type: RcType<S
|
|
125
|
+
declare function rc_loose_parse<S>(input: any, type: RcType<S>, options?: ParseOptions): {
|
|
116
126
|
data: S | null;
|
|
117
127
|
errors: string[] | false;
|
|
118
128
|
warnings: string[] | false;
|
|
@@ -123,11 +133,12 @@ declare function rc_recursive<T>(type: () => RcType<T>): RcType<T>;
|
|
|
123
133
|
/** validate a input or subset of input and transform the valid result */
|
|
124
134
|
declare function rc_transform<Input, Transformed>(type: RcType<Input>, transform: (input: Input) => Transformed): RcType<Transformed>;
|
|
125
135
|
declare function rc_assert_is_valid<S>(result: RcParseResult<S>): asserts result is {
|
|
136
|
+
ok: true;
|
|
126
137
|
error: false;
|
|
127
138
|
data: S;
|
|
128
139
|
warnings: string[] | false;
|
|
129
140
|
};
|
|
130
|
-
declare function rc_parse_json<T>(jsonString:
|
|
141
|
+
declare function rc_parse_json<T>(jsonString: unknown, schema: RcType<T>): RcParseResult<T>;
|
|
131
142
|
type Prettify<T> = T extends Record<string, any> ? {
|
|
132
143
|
[K in keyof T]: Prettify<T[K]>;
|
|
133
144
|
} : T;
|
|
@@ -137,4 +148,4 @@ type StricTypeToRcType<T> = [T] extends [any[]] ? RcType<T> : [T] extends [Recor
|
|
|
137
148
|
} & Partial<Record<keyof RcType<any>, never>>) | RcType<T> : RcType<T>;
|
|
138
149
|
declare function rc_obj_builder<T extends Record<string, any>>(): <S extends StricTypeToRcType<T>>(schema: { [K in keyof S]: K extends keyof T ? S[K] : never; }, options?: ObjOptions) => RcType<T>;
|
|
139
150
|
|
|
140
|
-
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 };
|
|
151
|
+
export { RcInferType, RcParseResult, RcParser, RcPrettyInferType, RcType, rc_any, rc_array, rc_assert_is_valid, rc_boolean, rc_date, rc_default, 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_nullish_default, 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,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,K,L,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-RQJKBTUL.js";export{c as rc_any,y as rc_array,I as rc_assert_is_valid,e as rc_boolean,h as rc_date,l as rc_default,q as rc_extends_obj,r as rc_get_obj_schema,i as rc_instanceof,E as rc_is_valid,j as rc_literals,z as rc_loose_array,D as rc_loose_parse,x as rc_loose_record,b as rc_null,m as rc_nullish_default,g as rc_number,L as rc_obj_builder,t as rc_obj_intersection,v as rc_obj_omit,u as rc_obj_pick,p as rc_object,B as rc_parse,K as rc_parse_json,C as rc_parser,w as rc_record,G as rc_recursive,n as rc_rename_from_key,o as rc_rename_key,s as rc_strict_obj,f as rc_string,H as rc_transform,A as rc_tuple,a as rc_undefined,k as rc_union,d as rc_unknown,F as rc_validator,J 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.
|
|
4
|
+
"version": "0.36.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -42,11 +42,13 @@
|
|
|
42
42
|
"@vitest/ui": "^0.29.8",
|
|
43
43
|
"eslint": "^8.37.0",
|
|
44
44
|
"eslint-plugin-vitest": "^0.0.57",
|
|
45
|
+
"mitata": "^0.1.6",
|
|
45
46
|
"tsm": "^2.3.0",
|
|
46
47
|
"tsup": "^6.7.0",
|
|
47
48
|
"typescript": "^5.0.3",
|
|
49
|
+
"v8-profiler-next": "^1.9.0",
|
|
48
50
|
"vite": "^4.3.9",
|
|
49
|
-
"vitest": "^0.
|
|
51
|
+
"vitest": "^0.30.0",
|
|
50
52
|
"zod": "^3.21.4"
|
|
51
53
|
},
|
|
52
54
|
"scripts": {
|
|
@@ -54,8 +56,7 @@
|
|
|
54
56
|
"test:run": "vitest run",
|
|
55
57
|
"lint": "pnpm tsc && pnpm eslint",
|
|
56
58
|
"tsc": "tsc -p tsconfig.prod.json",
|
|
57
|
-
"
|
|
58
|
-
"benchmark": "tsm benchmarks/benchmark.ts",
|
|
59
|
+
"benchmark": "tsm benchmarks/mitataBench.ts",
|
|
59
60
|
"benchmark:generate-profile": "tsm benchmarks/generateProfiles.ts",
|
|
60
61
|
"eslint": "CI=true eslint --color --ext .jsx,.js,.ts,.tsx src/ tests/",
|
|
61
62
|
"build": "pnpm test:run && pnpm lint && pnpm build:no-test",
|
package/dist/chunk-S5P42XEZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function N(e){return{...this,i:e}}function _(e,r){return r.startsWith("$[")||r.startsWith("$.")?r:`${e.path?`$${e.path}: `:""}${r}`}function K(e,r){e.warnings.push(_(e,r))}function C(e,r){r.forEach(n=>K(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 a=t===!0?r:t.data;return e.t&&!e.t(a)?[!1,[`Predicate failed for type '${e.e}'`]]:[!0,a]}let o=e.i;if(o!==void 0)return K(n,`Fallback used, errors -> ${E(t,n,e,r)}`),[!0,Z(o)?o():o];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}'`]]:(K(n,`Autofixed from error "${E(t,n,e,r)}"`),[!0,a.fixed])}return[!1,t?t.errors:[e.l(r)]]}function E(e,r,n,s){return e?e.errors.map(t=>t.replace(r.path,"")).join("; "):n.l(s)}function B(e){return{...this,f:!0,s:e}}function F(e){return{...this,t:e}}function I(){return{...this,c:!0}}function W(e){return`Type '${$(e,!!this.T)}' is not assignable to '${this.e}'`}function U(){return{...this,y:!0,e:`${this.e}_or_null`}}function D(){return{...this,u:!0,e:`${this.e}_or_nullish`}}var i={__rc_type:void 0,withFallback:N,where:F,optional:I,optionalKey:I,l:W,orNullish:D,withAutofix:B,orNull:U,R:!1,i:void 0,t:void 0,c:!1,y:!1,u:!1,f:!1,T:!1,o:void 0,s:void 0,b:void 0,n:void 0,a:!1,d:!1,p:[]},G={...i,r(e,r){return u(this,e,r,()=>e===void 0)},e:"undefined"},H={...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 se(e){return{...i,r(r,n){return u(this,r,n,()=>r instanceof e)},e:`instanceof_${e.name?`_${e.name}`:""}`}}function oe(...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})},T:!0,e:e.length==1?$(e[0],!0):e.map(r=>$(r,!0)).join(" | ")}}var A=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 s=n.path,t=[],o=0,a=!1,y=[],f=0;for(let R of e){f+=1,R.a&&(n.path=`${s}|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):(o<A&&t.push(...T),o+=1):a=!0}return n.path=s,y.length>0||t.length>0?((o>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 M(e,r){return{...r,o:e}}var ie=M;function z(e){return k(e)&&"__rc_type"in e}function q(e){if(z(e))return e;if(k(e)){let r={};for(let[n,s]of Object.entries(e))r[n]=q(s);return j(r)}throw new Error(`invalid schema: ${e}`)}function j(e,{normalizeKeysFrom:r}={}){let n={};for(let[s,t]of Object.entries(e))n[s]=q(t);return{...i,n,e:"object",a:!0,p:Object.entries(n),r(s,t){return u(this,s,t,()=>{if(!k(s))return t.objErrKeyIndex=-1,!1;let o=this.e==="strict_obj"?new Set(Object.keys(s)):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=s[T.o],b=T.o),d===void 0&&(d=s[c],b=c),d===void 0&&r==="snake_case"){let l=L(c);d=s[l],b=l}o?.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(o&&o.size>0)for(let c of o)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:{...s,...a}}:{errors:!1,data:a}})}}}function ce(e,r){return{...j(e,r),e:"extends_object",d:!0}}function ue(e){return e.n}function ye(e,r){return{...j(e,r),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 s of r){let t=e.n[s];t&&(n[s]=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 s of Object.keys(e.n))r.includes(s)||(n[s]=e.n[s]);return j(n)}function Q(e,{checkKey:r,looseCheck:n}={}){return{...i,e:`record<string, ${e.e}>`,r(s,t){return u(this,s,t,()=>{if(!k(s))return!1;let o={},a=[],y=t.path;for(let[f,R]of Object.entries(s)){let c=`.${f}`,T=`${y}${c}`;if(t.path=T,r&&!r(f)){a.push(_(t,`Key '${f}' is not allowed`));continue}let p=s[f],[g,d]=e.r(R,t);if(g)o[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)C(t,a);else return{errors:a,data:void 0};return{errors:!1,data:o}})}}}function pe(e,{checkKey:r}={}){return Q(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,s=!1,t){let o=[],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(s){o.push(w.map(h=>_(n,h)));continue}else return{errors:w.map(h=>_(n,h)),data:void 0}}if(o.length>0){if(a.length===0)return{errors:o.slice(0,5).flat(),data:void 0};C(n,o.flat())}return{errors:!1,data:a}}function de(e,r){return v(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 Re(e,r){return v(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 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},[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 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 J(e,r){let n={warnings:[],path:"",objErrShortCircuit:!1,objErrKeyIndex:0};return!!r.r(e,n)[0]}function je(e){return r=>J(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,s){let[t,o]=e.r(n,s);return t?[!0,r(o)]:[!1,o]}}}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 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 L(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 Z(e){return typeof e=="function"}function we(){return(e,r)=>j(e,r)}export{G as a,H as b,X as c,Y as d,ee as e,re as f,ne as g,te as h,se as i,oe 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,Q as u,pe as v,de as w,Re as x,be as y,P as z,he as A,_e as B,J as C,je as D,ge as E,xe as F,Oe as G,L as H,ke as I,we as J};
|