UNPKG

tinybase

Version:

A reactive data store and sync engine.

2 lines (1 loc) 957 B
const e=e=>typeof e,t=e(""),n=e(!0),r=e(0),o="type",l="default",f=e=>(t,n,r)=>e(t)?r?.():n(t),s=e=>null==e,a=f(s),p=f(e=>void 0===e),u=Object,c=e=>u.getPrototypeOf(e),y=u.entries,d=u.keys,i=u.freeze,h=(e=[])=>u.fromEntries(e),T=(e,t)=>((e,t)=>e.forEach(t))(y(e),([e,n])=>t(n,e)),b=(e,t,n)=>{const r=e?.def?.type;return"optional"===r?b(e.def.innerType,t,n):"nullable"===r?b(e.def.innerType,t,!0):r===l?b(e.def.innerType,e.def.defaultValue,n):[e,t,n??!1]},m=e=>e?.def?.shape,g=()=>((e,f)=>{const y=f=>{const[s,a,u]=e(f),c=s?.type;if(c!==t&&c!==r&&c!==n)return;const y={[o]:c};return p(a,e=>{y[l]=e}),u&&(y.allowNull=!0),y};return i({toTablesSchema:e=>{const t=h();return T(e,(e,n)=>{const r=h();var o;p(f(e),e=>T(e,(e,t)=>p(y(e),e=>{r[t]=e}))),(e=>!s(e)&&a(c(e),e=>e==u.prototype||s(c(e)),()=>!0))(o=r)&&0==(e=>d(e).length)(o)||(t[n]=r)}),t},toValuesSchema:e=>{const t=h();return T(e,(e,n)=>p(y(e),e=>{t[n]=e})),t}})})(b,m);export{g as createZodSchematizer};