tinybase 0.0.0 → 0.9.3

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/lib/checkpoints.d.ts +876 -0
  3. package/lib/checkpoints.js +1 -0
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/common.d.ts +59 -0
  6. package/lib/debug/checkpoints.d.ts +876 -0
  7. package/lib/debug/checkpoints.js +326 -0
  8. package/lib/debug/common.d.ts +59 -0
  9. package/lib/debug/indexes.d.ts +829 -0
  10. package/lib/debug/indexes.js +390 -0
  11. package/lib/debug/metrics.d.ts +753 -0
  12. package/lib/debug/metrics.js +391 -0
  13. package/lib/debug/persisters.d.ts +704 -0
  14. package/lib/debug/persisters.js +191 -0
  15. package/lib/debug/relationships.d.ts +1114 -0
  16. package/lib/debug/relationships.js +418 -0
  17. package/lib/debug/store.d.ts +2503 -0
  18. package/lib/debug/store.js +725 -0
  19. package/lib/debug/tinybase.d.ts +13 -0
  20. package/lib/debug/tinybase.js +1708 -0
  21. package/lib/debug/ui-react.d.ts +7158 -0
  22. package/lib/debug/ui-react.js +1040 -0
  23. package/lib/indexes.d.ts +829 -0
  24. package/lib/indexes.js +1 -0
  25. package/lib/indexes.js.gz +0 -0
  26. package/lib/metrics.d.ts +753 -0
  27. package/lib/metrics.js +1 -0
  28. package/lib/metrics.js.gz +0 -0
  29. package/lib/persisters.d.ts +704 -0
  30. package/lib/persisters.js +1 -0
  31. package/lib/persisters.js.gz +0 -0
  32. package/lib/relationships.d.ts +1114 -0
  33. package/lib/relationships.js +1 -0
  34. package/lib/relationships.js.gz +0 -0
  35. package/lib/store.d.ts +2503 -0
  36. package/lib/store.js +1 -0
  37. package/lib/store.js.gz +0 -0
  38. package/lib/tinybase.d.ts +13 -0
  39. package/lib/tinybase.js +1 -0
  40. package/lib/tinybase.js.gz +0 -0
  41. package/lib/ui-react.d.ts +7158 -0
  42. package/lib/ui-react.js +1 -0
  43. package/lib/ui-react.js.gz +0 -0
  44. package/lib/umd/checkpoints.js +1 -0
  45. package/lib/umd/checkpoints.js.gz +0 -0
  46. package/lib/umd/indexes.js +1 -0
  47. package/lib/umd/indexes.js.gz +0 -0
  48. package/lib/umd/metrics.js +1 -0
  49. package/lib/umd/metrics.js.gz +0 -0
  50. package/lib/umd/persisters.js +1 -0
  51. package/lib/umd/persisters.js.gz +0 -0
  52. package/lib/umd/relationships.js +1 -0
  53. package/lib/umd/relationships.js.gz +0 -0
  54. package/lib/umd/store.js +1 -0
  55. package/lib/umd/store.js.gz +0 -0
  56. package/lib/umd/tinybase.js +1 -0
  57. package/lib/umd/tinybase.js.gz +0 -0
  58. package/lib/umd/ui-react.js +1 -0
  59. package/lib/umd/ui-react.js.gz +0 -0
  60. package/package.json +98 -2
  61. package/readme.md +195 -0
@@ -0,0 +1 @@
1
+ import{promises as t,watch as e}from"fs";const a=t=>null==t,o=(t,e,o)=>a(t)?o?.():e(t),s=Object.freeze,r=(t,e,r,n,c)=>{let i,d=0;const l={load:async o=>{if(2!=d){d=1;const s=await e();a(s)||""==s?t.setTables(o):t.setJson(s),d=0}return l},startAutoLoad:async t=>(l.stopAutoLoad(),await l.load(t),n(l.load),l),stopAutoLoad:()=>(c(),l),save:async()=>(1!=d&&(d=2,await r(t.getJson()),d=0),l),startAutoSave:async()=>(await l.stopAutoSave().save(),i=t.addTablesListener((()=>l.save())),l),stopAutoSave:()=>(o(i,t.delListener),l),getStore:()=>t,destroy:()=>l.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return s(l)},n=globalThis.window,c=(t,e,a)=>{let o;return r(t,(async()=>a.getItem(e)),(async t=>a.setItem(e,t)),(t=>{o=o=>{o.storageArea===a&&o.key===e&&t()},n.addEventListener("storage",o)}),(()=>{n.removeEventListener("storage",o),o=void 0}))},i=(t,e)=>c(t,e,localStorage),d=(t,e)=>c(t,e,sessionStorage),l=(a,o)=>{let s;return r(a,(async()=>{try{return await t.readFile(o,"utf8")}catch{}}),(async e=>{try{await t.writeFile(o,e,"utf8")}catch{}}),(t=>{s=e(o,t)}),(()=>{s?.close(),s=void 0}))},u=t=>t.headers.get("ETag"),y=(t,e,s,n)=>{let c,i;return r(t,(async()=>{const t=await fetch(e);return i=u(t),t.text()}),(async t=>await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:t})),(t=>{c=setInterval((async()=>{const o=await fetch(e,{method:"HEAD"}),s=u(o);a(i)||a(s)||s==i||(i=s,t())}),1e3*n)}),(()=>{o(c,clearInterval),c=void 0}))};export{r as createCustomPersister,l as createFilePersister,i as createLocalPersister,y as createRemotePersister,d as createSessionPersister};
Binary file