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