tinybase
Version:
A reactive data store and sync engine.
2 lines (1 loc) • 748 B
JavaScript
const t=t=>typeof t,e=t(""),o=t(!0),r=t(0),n="type",s=t=>(e,o,r)=>t(e)?r?.():o(e),c=t=>null==t,l=s(c),u=s(t=>void 0===t),a=Object,f=t=>a.getPrototypeOf(t),p=a.entries,y=a.keys,h=a.freeze,i=(t=[])=>a.fromEntries(t),m=(t,e)=>((t,e)=>t.forEach(e))(p(t),([t,o])=>e(o,t)),b=(t,s)=>{const p=s=>{const[c,l,a]=t(s),f=c?.type;if(f!==e&&f!==r&&f!==o)return;const p={[n]:f};return u(l,t=>{p.default=t}),a&&(p.allowNull=!0),p};return h({toTablesSchema:t=>{const e=i();return m(t,(t,o)=>{const r=i();var n;u(s(t),t=>m(t,(t,e)=>u(p(t),t=>{r[e]=t}))),(t=>!c(t)&&l(f(t),t=>t==a.prototype||c(f(t)),()=>!0))(n=r)&&0==(t=>y(t).length)(n)||(e[o]=r)}),e},toValuesSchema:t=>{const e=i();return m(t,(t,o)=>u(p(t),t=>{e[o]=t})),e}})};export{b as createCustomSchematizer};