tinybase 4.0.0-beta.2 → 4.0.0-beta.4

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 (142) hide show
  1. package/lib/cjs/persister-automerge.cjs +1 -0
  2. package/lib/cjs/persister-automerge.cjs.gz +0 -0
  3. package/lib/cjs/persister-browser.cjs +1 -1
  4. package/lib/cjs/persister-browser.cjs.gz +0 -0
  5. package/lib/cjs/persister-file.cjs +1 -1
  6. package/lib/cjs/persister-file.cjs.gz +0 -0
  7. package/lib/cjs/persister-remote.cjs +1 -1
  8. package/lib/cjs/persister-remote.cjs.gz +0 -0
  9. package/lib/cjs/persister-yjs.cjs +1 -1
  10. package/lib/cjs/persister-yjs.cjs.gz +0 -0
  11. package/lib/cjs/persisters.cjs +1 -1
  12. package/lib/cjs/persisters.cjs.gz +0 -0
  13. package/lib/cjs/queries.cjs +1 -1
  14. package/lib/cjs/queries.cjs.gz +0 -0
  15. package/lib/cjs/store.cjs +1 -1
  16. package/lib/cjs/store.cjs.gz +0 -0
  17. package/lib/cjs/tinybase.cjs +1 -1
  18. package/lib/cjs/tinybase.cjs.gz +0 -0
  19. package/lib/cjs/tools.cjs +1 -1
  20. package/lib/cjs/tools.cjs.gz +0 -0
  21. package/lib/cjs-es6/persister-automerge.cjs +1 -0
  22. package/lib/cjs-es6/persister-automerge.cjs.gz +0 -0
  23. package/lib/cjs-es6/persister-browser.cjs +1 -1
  24. package/lib/cjs-es6/persister-browser.cjs.gz +0 -0
  25. package/lib/cjs-es6/persister-file.cjs +1 -1
  26. package/lib/cjs-es6/persister-file.cjs.gz +0 -0
  27. package/lib/cjs-es6/persister-remote.cjs +1 -1
  28. package/lib/cjs-es6/persister-remote.cjs.gz +0 -0
  29. package/lib/cjs-es6/persister-yjs.cjs +1 -1
  30. package/lib/cjs-es6/persister-yjs.cjs.gz +0 -0
  31. package/lib/cjs-es6/persisters.cjs +1 -1
  32. package/lib/cjs-es6/persisters.cjs.gz +0 -0
  33. package/lib/cjs-es6/queries.cjs +1 -1
  34. package/lib/cjs-es6/queries.cjs.gz +0 -0
  35. package/lib/cjs-es6/store.cjs +1 -1
  36. package/lib/cjs-es6/store.cjs.gz +0 -0
  37. package/lib/cjs-es6/tinybase.cjs +1 -1
  38. package/lib/cjs-es6/tinybase.cjs.gz +0 -0
  39. package/lib/cjs-es6/tools.cjs +1 -1
  40. package/lib/cjs-es6/tools.cjs.gz +0 -0
  41. package/lib/debug/persister-automerge.js +257 -0
  42. package/lib/debug/persister-browser.js +2 -2
  43. package/lib/debug/persister-file.js +2 -2
  44. package/lib/debug/persister-remote.js +2 -2
  45. package/lib/debug/persister-yjs.js +3 -3
  46. package/lib/debug/persisters.js +2 -2
  47. package/lib/debug/queries.js +1 -1
  48. package/lib/debug/store.js +27 -13
  49. package/lib/debug/tinybase.js +30 -16
  50. package/lib/debug/tools.js +50 -2
  51. package/lib/es6/persister-automerge.js +1 -0
  52. package/lib/es6/persister-automerge.js.gz +0 -0
  53. package/lib/es6/persister-browser.js +1 -1
  54. package/lib/es6/persister-browser.js.gz +0 -0
  55. package/lib/es6/persister-file.js +1 -1
  56. package/lib/es6/persister-file.js.gz +0 -0
  57. package/lib/es6/persister-remote.js +1 -1
  58. package/lib/es6/persister-remote.js.gz +0 -0
  59. package/lib/es6/persister-yjs.js +1 -1
  60. package/lib/es6/persister-yjs.js.gz +0 -0
  61. package/lib/es6/persisters.js +1 -1
  62. package/lib/es6/persisters.js.gz +0 -0
  63. package/lib/es6/queries.js +1 -1
  64. package/lib/es6/queries.js.gz +0 -0
  65. package/lib/es6/store.js +1 -1
  66. package/lib/es6/store.js.gz +0 -0
  67. package/lib/es6/tinybase.js +1 -1
  68. package/lib/es6/tinybase.js.gz +0 -0
  69. package/lib/es6/tools.js +1 -1
  70. package/lib/es6/tools.js.gz +0 -0
  71. package/lib/persister-automerge.js +1 -0
  72. package/lib/persister-automerge.js.gz +0 -0
  73. package/lib/persister-browser.js +1 -1
  74. package/lib/persister-browser.js.gz +0 -0
  75. package/lib/persister-file.js +1 -1
  76. package/lib/persister-file.js.gz +0 -0
  77. package/lib/persister-remote.js +1 -1
  78. package/lib/persister-remote.js.gz +0 -0
  79. package/lib/persister-yjs.js +1 -1
  80. package/lib/persister-yjs.js.gz +0 -0
  81. package/lib/persisters.js +1 -1
  82. package/lib/persisters.js.gz +0 -0
  83. package/lib/queries.js +1 -1
  84. package/lib/queries.js.gz +0 -0
  85. package/lib/store.js +1 -1
  86. package/lib/store.js.gz +0 -0
  87. package/lib/tinybase.js +1 -1
  88. package/lib/tinybase.js.gz +0 -0
  89. package/lib/tools.js +1 -1
  90. package/lib/tools.js.gz +0 -0
  91. package/lib/types/persister-automerge.d.ts +110 -0
  92. package/lib/types/persister-yjs.d.ts +3 -2
  93. package/lib/types/persisters.d.ts +8 -8
  94. package/lib/types/store.d.ts +53 -0
  95. package/lib/types/tools.d.ts +4 -4
  96. package/lib/types/with-schemas/persister-automerge.d.ts +120 -0
  97. package/lib/types/with-schemas/persister-yjs.d.ts +3 -2
  98. package/lib/types/with-schemas/persisters.d.ts +8 -8
  99. package/lib/types/with-schemas/store.d.ts +59 -0
  100. package/lib/types/with-schemas/tools.d.ts +4 -4
  101. package/lib/umd/persister-automerge.js +1 -0
  102. package/lib/umd/persister-automerge.js.gz +0 -0
  103. package/lib/umd/persister-browser.js +1 -1
  104. package/lib/umd/persister-browser.js.gz +0 -0
  105. package/lib/umd/persister-file.js +1 -1
  106. package/lib/umd/persister-file.js.gz +0 -0
  107. package/lib/umd/persister-remote.js +1 -1
  108. package/lib/umd/persister-remote.js.gz +0 -0
  109. package/lib/umd/persister-yjs.js +1 -1
  110. package/lib/umd/persister-yjs.js.gz +0 -0
  111. package/lib/umd/persisters.js +1 -1
  112. package/lib/umd/persisters.js.gz +0 -0
  113. package/lib/umd/queries.js +1 -1
  114. package/lib/umd/queries.js.gz +0 -0
  115. package/lib/umd/store.js +1 -1
  116. package/lib/umd/store.js.gz +0 -0
  117. package/lib/umd/tinybase.js +1 -1
  118. package/lib/umd/tinybase.js.gz +0 -0
  119. package/lib/umd/tools.js +1 -1
  120. package/lib/umd/tools.js.gz +0 -0
  121. package/lib/umd-es6/persister-automerge.js +1 -0
  122. package/lib/umd-es6/persister-automerge.js.gz +0 -0
  123. package/lib/umd-es6/persister-browser.js +1 -1
  124. package/lib/umd-es6/persister-browser.js.gz +0 -0
  125. package/lib/umd-es6/persister-file.js +1 -1
  126. package/lib/umd-es6/persister-file.js.gz +0 -0
  127. package/lib/umd-es6/persister-remote.js +1 -1
  128. package/lib/umd-es6/persister-remote.js.gz +0 -0
  129. package/lib/umd-es6/persister-yjs.js +1 -1
  130. package/lib/umd-es6/persister-yjs.js.gz +0 -0
  131. package/lib/umd-es6/persisters.js +1 -1
  132. package/lib/umd-es6/persisters.js.gz +0 -0
  133. package/lib/umd-es6/queries.js +1 -1
  134. package/lib/umd-es6/queries.js.gz +0 -0
  135. package/lib/umd-es6/store.js +1 -1
  136. package/lib/umd-es6/store.js.gz +0 -0
  137. package/lib/umd-es6/tinybase.js +1 -1
  138. package/lib/umd-es6/tinybase.js.gz +0 -0
  139. package/lib/umd-es6/tools.js +1 -1
  140. package/lib/umd-es6/tools.js.gz +0 -0
  141. package/package.json +56 -26
  142. package/readme.md +3 -3
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",l=t(n),s=t(!0),o=t(0),r=t(t),i="type",a="default",d="Listener",c="Result",u="add",v="Ids",h="Table",f=h+"s",g=h+v,L="Row",p=L+v,y="Sorted"+L+v,S="Cell",w=S+v,R="Value",I=R+"s",T=R+v,b=e=>n+e,C=(e,t)=>e.includes(t),m=(e,t)=>e.every(t),V=(e,t)=>J(e)===J(t)&&m(e,((e,n)=>t[n]===e)),E=(e,t)=>m(e,((n,l)=>0==l||t(e[l-1],n)<=0)),k=(e,t)=>e.sort(t),x=(e,t)=>e.forEach(t),M=(e,t)=>e.map(t),D=e=>O(e,((e,t)=>e+t),0),J=e=>e.length,A=e=>0==J(e),O=(e,t,n)=>e.reduce(t,n),F=(e,t,n)=>e.slice(t,n),P=(e,...t)=>e.push(...t),j=e=>e.pop(),Q=e=>e.shift(),z=e=>JSON.stringify(e,((e,t)=>q(t,Map)?O([...t],((e,[t,n])=>(e[t]=n,e)),{}):t)),N=JSON.parse,W=Math.max,B=Math.min,$=isFinite,q=(e,t)=>e instanceof t,G=e=>null==e,H=(e,t,n)=>G(e)?null==n?void 0:n():t(e),K=e=>e==l||e==s,U=e=>t(e)==r,X=e=>Array.isArray(e),Y=()=>{},Z=Object,_=Z.keys,ee=Z.isFrozen,te=Z.freeze,ne=e=>q(e,Z)&&e.constructor==Z,le=(e,t)=>!G(((e,t)=>H(e,(e=>e[t])))(e,t)),se=(e,t)=>delete e[t],oe=(e,t)=>M(Z.entries(e),(([e,n])=>t(n,e))),re=e=>ne(e)&&A(_(e)),ie=e=>e.size,ae=(e,t)=>{var n;return null!=(n=null==e?void 0:e.has(t))&&n},de=e=>G(e)||0==ie(e),ce=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},ue=e=>e.clear(),ve=(e,t)=>null==e?void 0:e.forEach(t),he=(e,t)=>null==e?void 0:e.delete(t),fe=e=>new Map(e),ge=e=>{var t;return[...null!=(t=null==e?void 0:e.keys())?t:[]]},Le=(e,t)=>null==e?void 0:e.get(t),pe=(e,t)=>ve(e,((e,n)=>t(n,e))),ye=(e,t,n)=>G(n)?(he(e,t),e):null==e?void 0:e.set(t,n),Se=(e,t,n)=>(ae(e,t)||ye(e,t,n()),Le(e,t)),we=(e,t,n)=>{const l={};return ve(e,((e,s)=>{const o=t?t(e,s):e;!(null==n?void 0:n(o,e))&&(l[s]=o)})),l},Re=(e,t,n)=>we(e,(e=>we(e,t,n)),re),Ie=(e,t,n)=>we(e,(e=>Re(e,t,n)),re),Te=(e,t)=>{const n=fe();return ve(e,((e,l)=>{var s;return n.set(l,null!=(s=null==t?void 0:t(e))?s:e)})),n},be=e=>Te(e,Te),Ce=e=>Te(e,be),me=(e,t,n,l,s=0)=>H((n?Se:Le)(e,t[s],s>J(t)-2?n:fe),(o=>{if(s>J(t)-2)return(null==l?void 0:l(o))&&ye(e,t[s]),o;const r=me(o,t,n,l,s+1);return de(o)&&ye(e,t[s]),r})),Ve=e=>{const n=t(e);return K(n)||n==o&&$(e)?n:void 0},Ee=(e,t,n,l,s)=>G(s)?e.delCell(t,n,l,!0):e.setCell(t,n,l,s),ke=(e,t,n)=>G(n)?e.delValue(t):e.setValue(t,n),xe=e=>new Set(X(e)||G(e)?e:[e]),Me=(e,t)=>null==e?void 0:e.add(t),De=(e,t,n)=>{const l=e.hasRow,s=fe(),o=fe(),r=fe(),i=fe(),a=fe(),d=(t,n,...l)=>{const s=Se(a,t,xe);return x(l,(t=>Me(s,t)&&n&&e.callListener(t))),l},c=(t,...n)=>H(Le(a,t),(l=>{x(A(n)?ce(l):n,(t=>{e.delListener(t),he(l,t)})),de(l)&&ye(a,t)})),u=(e,n)=>{ye(s,e,n),ae(o,e)||(ye(o,e,t()),ye(r,e,fe()),ye(i,e,fe()))},v=e=>{ye(s,e),ye(o,e),ye(r,e),ye(i,e),c(e)};return[()=>e,()=>ge(s),e=>pe(o,e),e=>ae(o,e),e=>Le(s,e),e=>Le(o,e),(e,t)=>ye(o,e,t),u,(t,s,o,a,v)=>{u(t,s);const h=fe(),f=fe(),g=Le(r,t),L=Le(i,t),p=t=>{const o=n=>e.getCell(s,t,n),r=Le(g,t),i=l(s,t)?n(a(o,t)):void 0;if(r===i||X(r)&&X(i)&&V(r,i)||ye(h,t,[r,i]),!G(v)){const e=Le(L,t),n=l(s,t)?v(o,t):void 0;e!=n&&ye(f,t,n)}},y=e=>{o((()=>{ve(h,(([,e],t)=>ye(g,t,e))),ve(f,((e,t)=>ye(L,t,e)))}),h,f,g,L,e),ue(h),ue(f)};pe(g,p),e.hasTable(s)&&x(e.getRowIds(s),(e=>{ae(g,e)||p(e)})),y(!0),c(t),d(t,0,e.addRowListener(s,null,((e,t,n)=>p(n))),e.addTableListener(s,(()=>y())))},v,()=>pe(a,v),d,c]},Je=(e,s)=>t(e)==l?t=>t(e):null!=e?e:()=>null!=s?s:n,Ae=e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))},Oe=/^\d+$/,Fe=()=>{const e=[];let t=0;return[l=>{var s;return null!=(s=l?Q(e):null)?s:n+t++},t=>{Oe.test(t)&&J(e)<1e3&&P(e,t)}]},Pe=e=>{let t;const[l,s]=Fe(),o=fe();return[(s,r,i,a=[],d=(()=>[]))=>{null!=t||(t=e());const c=l(1);return ye(o,c,[s,r,i,a,d]),Me(me(r,null!=i?i:[n],xe),c),c},(e,l,...s)=>x(((e,t=[n])=>{const l=[],s=(e,n)=>n==J(t)?P(l,e):null===t[n]?ve(e,(e=>s(e,n+1))):x([t[n],null],(t=>s(Le(e,t),n+1)));return s(e,0),l})(e,l),(e=>ve(e,(e=>Le(o,e)[0](t,...null!=l?l:[],...s))))),e=>H(Le(o,e),(([,t,l])=>(me(t,null!=l?l:[n],void 0,(t=>(he(t,e),de(t)?1:0))),ye(o,e),s(e),l))),e=>H(Le(o,e),(([e,,n=[],l,s])=>{const o=(...r)=>{var i,a;const d=J(r);d==J(n)?e(t,...r,...s(r)):G(n[d])?x(null!=(a=null==(i=l[d])?void 0:i.call(l,...r))?a:[],(e=>o(...r,e))):o(...r,n[d])};o()}))]},je=Ae((e=>{let t,l,s,o=100,r=fe(),i=fe(),a=1;const d=fe(),c=fe(),[u,v,h]=Pe((()=>z)),f=fe(),g=fe(),L=[],p=[],y=(t,n)=>{a=0,e.transaction((()=>{const[l,s]=Le(f,n);ve(l,((n,l)=>ve(n,((n,s)=>ve(n,((n,o)=>Ee(e,l,s,o,n[t]))))))),ve(s,((n,l)=>ke(e,l,n[t])))})),a=1},S=e=>{ye(f,e),ye(g,e),v(c,[e])},w=(e,t)=>x(((e,t)=>e.splice(0,t))(e,null!=t?t:J(e)),S),R=()=>w(L,J(L)-o),I=()=>H(t,(()=>{P(L,t),R(),w(p),t=void 0,s=1})),T=()=>{t=j(L),s=1},b=e.addCellListener(null,null,null,((e,t,n,l,s,o)=>{if(a){I();const e=Se(r,t,fe),i=Se(e,n,fe),a=Se(i,l,(()=>[o,void 0]));a[1]=s,a[0]===s&&de(ye(i,l))&&de(ye(e,n))&&de(ye(r,t))&&T(),M()}})),m=e.addValueListener(null,((e,t,n,l)=>{if(a){I();const e=Se(i,t,(()=>[l,void 0]));e[1]=n,e[0]===n&&de(ye(i,t))&&T(),M()}})),V=(e="")=>(G(t)&&(t=n+l++,ye(f,t,[r,i]),O(t,e),r=fe(),i=fe(),s=1),t),E=()=>{A(L)||(((e,...t)=>{e.unshift(...t)})(p,V()),y(0,t),t=j(L),s=1)},k=()=>{A(p)||(P(L,t),t=Q(p),y(1,t),s=1)},M=()=>{s&&(v(d),s=0)},D=e=>{const t=V(e);return M(),t},O=(e,t)=>(F(e)&&Le(g,e)!==t&&(ye(g,e,t),v(c,[e])),z),F=e=>ae(f,e),z={setSize:e=>(o=e,R(),z),addCheckpoint:D,setCheckpoint:O,getStore:()=>e,getCheckpointIds:()=>[[...L],t,[...p]],forEachCheckpoint:e=>pe(g,e),hasCheckpoint:F,getCheckpoint:e=>Le(g,e),goBackward:()=>(E(),M(),z),goForward:()=>(k(),M(),z),goTo:e=>{const n=C(L,e)?E:C(p,e)?k:null;for(;!G(n)&&e!=t;)n();return M(),z},addCheckpointIdsListener:e=>u(e,d),addCheckpointListener:(e,t)=>u(t,c,[e]),delListener:e=>(h(e),z),clear:()=>(w(L),w(p),G(t)||S(t),t=void 0,l=0,D(),z),destroy:()=>{e.delListener(b),e.delListener(m)},getListenerStats:()=>({})};return te(z.clear())})),Qe=(e,t)=>e<t?-1:1,ze=Ae((e=>{const t=fe(),l=fe(),[s,o,r,i,a,d,c,,u,v,h]=De(e,fe,(e=>G(e)?n:X(e)?M(e,b):b(e))),[f,g,L]=Pe((()=>y)),p=(t,n,l)=>{const s=a(t);ve(l,((t,l)=>n(l,(n=>ve(t,(t=>n(t,(n=>e.forEachCell(s,t,n)))))))))},y={setIndexDefinition:(e,n,s,o,r,i=Qe)=>{const a=G(r)?void 0:([e],[t])=>r(e,t);return u(e,n,((n,s,r,u,v,h)=>{let f=0;const L=xe(),p=xe(),y=d(e);if(ve(s,(([e,t],n)=>{const l=xe(e),s=xe(t);ve(l,(e=>he(s,e)?he(l,e):0)),ve(l,(e=>{Me(L,e),H(Le(y,e),(t=>{he(t,n),de(t)&&(ye(y,e),f=1)}))})),ve(s,(e=>{Me(L,e),ae(y,e)||(ye(y,e,xe()),f=1),Me(Le(y,e),n),G(o)||Me(p,e)}))})),n(),de(v)||(h?pe(y,(e=>Me(p,e))):pe(r,(e=>H(Le(u,e),(e=>Me(p,e))))),ve(p,(e=>{const t=(t,n)=>i(Le(v,t),Le(v,n),e),n=[...Le(y,e)];E(n,t)||(ye(y,e,xe(k(n,t))),Me(L,e))}))),(f||h)&&!G(a)){const t=[...y];E(t,a)||(c(e,fe(k(t,a))),f=1)}f&&g(t,[e]),ve(L,(t=>g(l,[e,t])))}),Je(s),H(o,Je)),y},delIndexDefinition:e=>(v(e),y),getStore:s,getIndexIds:o,forEachIndex:e=>r(((t,n)=>e(t,(e=>p(t,e,n))))),forEachSlice:(e,t)=>p(e,t,d(e)),hasIndex:i,hasSlice:(e,t)=>ae(d(e),t),getTableId:a,getSliceIds:e=>ge(d(e)),getSliceRowIds:(e,t)=>ce(Le(d(e),t)),addSliceIdsListener:(e,n)=>f(n,t,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,l,[e,t]),delListener:e=>(L(e),y),destroy:h,getListenerStats:()=>({})};return te(y)})),Ne=fe([["avg",[(e,t)=>D(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,l)=>e+(t-n)/l]],["max",[e=>W(...e),(e,t)=>W(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:W(t,e)]],["min",[e=>B(...e),(e,t)=>B(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:B(t,e)]],["sum",[e=>D(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),We=(e,t,n,l,s,o=!1)=>{if(de(n))return;const[r,i,a,d]=s;return o||(o=G(e)),ve(l,(([n,l])=>{o||(e=G(n)?null==i?void 0:i(e,l,t++):G(l)?null==a?void 0:a(e,n,t--):null==d?void 0:d(e,l,n,t),o||(o=G(e)))})),o?r(ce(n),ie(n)):e},Be=Ae((e=>{const t=fe(),[l,s,o,r,i,a,d,,c,u,v]=De(e,Y,(e=>isNaN(e)||G(e)||!0===e||!1===e||e===n?void 0:1*e)),[h,f,g]=Pe((()=>L)),L={setMetricDefinition:(e,n,l,s,o,r,i)=>{var u;const v=U(l)?[l,o,r,i]:null!=(u=Le(Ne,l))?u:Le(Ne,"sum");return c(e,n,((n,l,s,o,r,i)=>{const c=a(e),u=ie(o);i||(i=G(c)),n();let h=We(c,u,o,l,v,i);$(h)||(h=void 0),h!=c&&(d(e,h),f(t,[e],h,c))}),Je(s,1)),L},delMetricDefinition:e=>(u(e),L),getStore:l,getMetricIds:s,forEachMetric:o,hasMetric:r,getTableId:i,getMetric:a,addMetricListener:(e,n)=>h(n,t,[e]),delListener:e=>(g(e),L),destroy:v,getListenerStats:()=>({})};return te(L)}));var $e=(e,t,n)=>new Promise(((l,s)=>{var o=e=>{try{i(n.next(e))}catch(e){s(e)}},r=e=>{try{i(n.throw(e))}catch(e){s(e)}},i=e=>e.done?l(e.value):Promise.resolve(e.value).then(o,r);i((n=n.apply(e,t)).next())})),qe=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable;const Ke=Ae((e=>{const t=e.createStore,[l,s,o,r,i,,,a,,v,f,g,R]=De(e,(()=>!0),Y),I=t(),T=t(),b=fe(),C=(e,t,...n)=>x(n,(n=>Me(Se(Se(b,t,fe),e,xe),n))),V=e=>{H(Le(b,e),(e=>{pe(e,((e,t)=>ve(t,(t=>e.delListener(t))))),ue(e)})),x([T,I],(t=>t.delTable(e)))},E=(e,t,n)=>C(t,e,t.addWillFinishTransactionListener(n.startTransaction),t.addDidFinishTransactionListener((()=>n.finishTransaction()))),k={setQueryDefinition:(t,l,s)=>{a(t,l),V(t);const o=[],r=[[null,[l,null,null,[],fe()]]],i=[],d=[],c=[];s({select:(e,t)=>{const l=U(e)?[J(o)+n,e]:[G(t)?e:t,n=>n(e,t)];return P(o,l),{as:e=>l[0]=e}},join:(e,t,n)=>{const l=G(n)||U(t)?null:t,s=G(l)?t:n,o=[e,[e,l,U(s)?s:e=>e(s),[],fe()]];return P(r,o),{as:e=>o[0]=e}},where:(e,t,n)=>P(i,U(e)?e:G(n)?n=>n(e)===t:l=>l(e,t)===n),group:(e,t,n,l,s)=>{var o;const r=[e,[e,U(t)?[t,n,l,s]:null!=(o=Le(Ne,t))?o:[(e,t)=>t]]];return P(d,r),{as:e=>r[0]=e}},having:(e,t)=>P(c,U(e)?e:n=>n(e)===t)});const u=fe(o);if(de(u))return k;const v=fe(r);pe(v,((e,[,t])=>H(Le(v,t),(({3:t})=>G(e)?0:P(t,e)))));const h=fe(d);let f=I;if(de(h)&&A(c))f=T;else{E(t,f,T);const e=fe();pe(h,((t,[n,l])=>Me(Se(e,n,xe),[t,l])));const n=xe();pe(u,(t=>ae(e,t)?0:Me(n,t)));const l=fe(),s=(n,l,s,o)=>H(n,(([r,i,a,d])=>{pe(l,((t,[n])=>{const l=Se(r,t,fe),i=Le(l,s),a=o?void 0:n;if(i!==a){const n=xe([[i,a]]),o=ie(l);ye(l,s,a),ve(Le(e,t),(([e,t])=>{const s=We(d[e],o,l,n,t);d[e]=G(Ve(s))?null:s}))}})),de(i)||!m(c,(e=>e((e=>d[e]))))?T.delRow(t,a):G(a)?n[2]=T.addRow(t,d):T.setRow(t,a,d)}));C(f,t,f.addRowListener(t,null,((o,r,i,a)=>{const d=[],c=[],u=fe(),v=f.hasRow(t,i);let h=!v;ve(n,(e=>{const[n,l,s]=a(t,i,e);P(d,l),P(c,s),h||(h=n)})),pe(e,(e=>{const[n,,l]=a(t,i,e);(h||n)&&ye(u,e,[l])})),h&&s(me(l,d,void 0,(([,e])=>(he(e,i),de(e)))),u,i,1),v&&s(me(l,c,(()=>{const e={};return ve(n,(n=>e[n]=f.getCell(t,i,n))),[fe(),xe(),void 0,e]}),(([,e])=>{Me(e,i)})),u,i)})))}E(t,e,f);const L=(n,s,o,r)=>{const a=t=>e.getCell(s,o,t);x(r,(l=>{var s;const[o,,r,i,d]=Le(v,l),c=null==r?void 0:r(a,n),[u,h]=null!=(s=Le(d,n))?s:[];c!=u&&(G(h)||R(t,h),ye(d,n,G(c)?null:[c,...g(t,1,e.addRowListener(o,c,(()=>L(n,o,c,i))))]))})),(n=>{const s=(t,s)=>{var o,r,i;return e.getCell(...G(s)?[l,n,t]:t===l?[l,n,s]:[null==(o=Le(v,t))?void 0:o[0],null==(i=Le(null==(r=Le(v,t))?void 0:r[4],n))?void 0:i[0],s])};f.transaction((()=>m(i,(e=>e(s)))?pe(u,((e,l)=>Ee(f,t,n,e,l(s,n)))):f.delRow(t,n)))})(n)},{3:p}=Le(v,null);return f.transaction((()=>g(t,1,e.addRowListener(l,null,((n,s,o)=>{e.hasRow(l,o)?L(o,l,o,p):(f.delRow(t,o),ve(v,(({4:e})=>H(Le(e,o),(([,n])=>{R(t,n),ye(e,o)})))))}))))),k},delQueryDefinition:e=>(V(e),v(e),k),getStore:l,getQueryIds:s,forEachQuery:o,hasQuery:r,getTableId:i,delListener:e=>(T.delListener(e),k),destroy:f,getListenerStats:()=>((e,t)=>{var n={};for(var l in e)Ge.call(e,l)&&t.indexOf(l)<0&&(n[l]=e[l]);if(null!=e&&qe)for(var l of qe(e))t.indexOf(l)<0&&He.call(e,l)&&(n[l]=e[l]);return n})(T.getListenerStats(),["tables","tableIds","transaction"])};return oe({[h]:[1,1],[p]:[0,1],[y]:[0,5],[L]:[1,2],[w]:[0,2],[S]:[1,3]},(([e,t],n)=>{x(e?["get","has","forEach"]:["get"],(e=>k[e+c+n]=(...t)=>T[e+n](...t))),k[u+c+n+d]=(...e)=>T[u+n+d](...F(e,0,t),((n,...l)=>e[t](k,...l)))})),te(k)})),Ue=Ae((e=>{const t=fe(),l=fe(),s=fe(),o=fe(),[r,i,a,d,c,u,,,v,h,f]=De(e,(()=>[fe(),fe(),fe(),fe()]),(e=>G(e)?void 0:e+n)),[g,L,p]=Pe((()=>R)),y=(e,t,n)=>H(u(e),(([l,,s])=>{if(!ae(s,t)){const o=xe();if(c(e)!=w(e))Me(o,t);else{let e=t;for(;!G(e)&&!ae(o,e);)Me(o,e),e=Le(l,e)}if(n)return o;ye(s,t,o)}return Le(s,t)})),S=(e,t)=>H(u(e),(([,,e])=>ye(e,t))),w=e=>Le(t,e),R={setRelationshipDefinition:(e,n,r,i)=>(ye(t,e,r),v(e,n,((t,n)=>{const r=xe(),i=xe(),a=xe(),[d,c]=u(e);ve(n,(([t,n],l)=>{G(t)||(Me(i,t),H(Le(c,t),(e=>{he(e,l),de(e)&&ye(c,t)}))),G(n)||(Me(i,n),ae(c,n)||ye(c,n,xe()),Me(Le(c,n),l)),Me(r,l),ye(d,l,n),pe(Le(o,e),(t=>{ae(y(e,t),l)&&Me(a,t)}))})),t(),ve(r,(t=>L(l,[e,t]))),ve(i,(t=>L(s,[e,t]))),ve(a,(t=>{S(e,t),L(o,[e,t])}))}),Je(i)),R),delRelationshipDefinition:e=>(ye(t,e),h(e),R),getStore:r,getRelationshipIds:i,forEachRelationship:t=>a((n=>t(n,(t=>e.forEachRow(c(n),t))))),hasRelationship:d,getLocalTableId:c,getRemoteTableId:w,getRemoteRowId:(e,t)=>{var n;return Le(null==(n=u(e))?void 0:n[0],t)},getLocalRowIds:(e,t)=>{var n;return ce(Le(null==(n=u(e))?void 0:n[1],t))},getLinkedRowIds:(e,t)=>G(u(e))?[t]:ce(y(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>g(n,l,[e,t]),addLocalRowIdsListener:(e,t,n)=>g(n,s,[e,t]),addLinkedRowIdsListener:(e,t,n)=>(y(e,t),g(n,o,[e,t])),delListener:e=>(S(...p(e)),R),destroy:f,getListenerStats:()=>({})};return te(R)})),Xe=e=>[e,e],Ye=()=>[fe(),fe()],Ze=e=>[...e],_e=([e,t])=>e===t,et=(e,t,n,l=ye)=>(oe(t,((t,l)=>n(e,l,t))),pe(e,(n=>le(t,n)?0:l(e,n))),e),tt=(e,t,n)=>G(e)||!ne(e)||re(e)||ee(e)?(null==n||n(),!1):(oe(e,((n,l)=>{t(n,l)||se(e,l)})),!re(e)),nt=(e,t,n)=>ye(e,t,Le(e,t)==-n?void 0:n),lt=()=>{let e,t,n,l,s=0;const r=fe(),c=fe(),v=fe(),y=fe(),m=fe(),E=fe(),D=fe(),J=fe(),A=fe(),O=fe(),j=fe(),Q=fe(),W=xe(),B=fe(),$=fe(),q=fe(),X=Ye(),Y=Ye(),Z=Ye(),_=Ye(),ee=Ye(),ne=Ye(),ie=Ye(),ce=Ye(),me=Ye(),De=Ye(),Je=Ye(),Ae=Ye(),Oe=Ye(),je=Ye(),[ze,Ne,We,Be]=Pe((()=>un)),$e=e=>{if(!tt(e,((e,t)=>C([i,a],t))))return!1;const t=e[i];return!(!K(t)&&t!=o||(Ve(e[a])!=t&&se(e,a),0))},qe=(t,n)=>(!e||ae(A,n)||kt(n))&&tt(t,((e,t)=>Ge(n,t,e)),(()=>kt(n))),Ge=(e,t,n,l)=>tt(l?n:st(n,e,t),((l,s)=>H(He(e,t,s,l),(e=>(n[s]=e,!0)),(()=>!1))),(()=>kt(e,t))),He=(t,n,l,s)=>e?H(Le(Le(A,t),l),(e=>Ve(s)!=e[i]?kt(t,n,l,s,e[a]):s),(()=>kt(t,n,l,s))):G(Ve(s))?kt(t,n,l,s):s,Ke=(e,t)=>tt(t?e:ot(e),((t,n)=>H(Ue(n,t),(t=>(e[n]=t,!0)),(()=>!1))),(()=>xt())),Ue=(e,n)=>t?H(Le(j,e),(t=>Ve(n)!=t[i]?xt(e,n,t[a]):n),(()=>xt(e,n))):G(Ve(n))?xt(e,n):n,st=(e,t,n)=>(H(Le(O,t),(([l,s])=>{ve(l,((t,n)=>{le(e,n)||(e[n]=t)})),ve(s,(l=>{le(e,l)||kt(t,n,l)}))})),e),ot=e=>(t&&(ve(Q,((t,n)=>{le(e,n)||(e[n]=t)})),ve(W,(t=>{le(e,t)||xt(t)}))),e),rt=e=>et(A,e,((e,t,n)=>{const l=fe(),s=xe();et(Se(A,t,fe),n,((e,t,n)=>{ye(e,t,n),H(n[a],(e=>ye(l,t,e)),(()=>Me(s,t)))})),ye(O,t,[l,s])}),((e,t)=>{ye(A,t),ye(O,t)})),it=e=>et(j,e,((e,t,n)=>{ye(j,t,n),H(n[a],(e=>ye(Q,t,e)),(()=>Me(W,t)))}),((e,t)=>{ye(j,t),ye(Q,t),he(W,t)})),at=e=>re(e)?tn():Xt(e),dt=e=>et($,e,((e,t,n)=>ct(t,n)),((e,t)=>St(t))),ct=(e,t)=>et(Se($,e,(()=>(Tt(e,1),fe()))),t,((t,n,l)=>ut(e,t,n,l)),((t,n)=>wt(e,t,n))),ut=(e,t,n,l,s)=>et(Se(t,n,(()=>(bt(e,n,1),fe()))),l,((t,l,s)=>vt(e,n,t,l,s)),((l,o)=>Rt(e,t,n,l,o,s))),vt=(e,t,n,l,s)=>{ae(n,l)||Ct(e,t,l,1);const o=Le(n,l);s!==o&&(mt(e,t,l,o,s),ye(n,l,s))},ht=(e,t,n,l,s)=>H(Le(t,n),(t=>vt(e,n,t,l,s)),(()=>ut(e,t,n,st({[l]:s},e,n)))),ft=e=>re(e)?sn():Yt(e),gt=e=>et(q,e,((e,t,n)=>Lt(t,n)),((e,t)=>It(t))),Lt=(e,t)=>{ae(q,e)||Vt(e,1);const n=Le(q,e);t!==n&&(Et(e,n,t),ye(q,e,t))},pt=(e,t)=>{const[n]=Se(B,e,Fe),l=n(t);return ae(Le($,e),l)?pt(e,t):l},yt=e=>{var t;return null!=(t=Le($,e))?t:ct(e,{})},St=e=>ct(e,{}),wt=(e,t,n)=>{const[,l]=Se(B,e,Fe);l(n),ut(e,t,n,{},!0)},Rt=(e,t,n,l,s,o)=>{var r;const i=Le(null==(r=Le(O,e))?void 0:r[0],s);if(!G(i)&&!o)return vt(e,n,l,s,i);const a=t=>{mt(e,n,t,Le(l,t)),Ct(e,n,t,-1),ye(l,t)};G(i)?a(s):pe(l,a),de(l)&&(bt(e,n,-1),de(ye(t,n))&&(Tt(e,-1),ye($,e),ye(B,e)))},It=e=>{const t=Le(Q,e);if(!G(t))return Lt(e,t);Et(e,Le(q,e)),Vt(e,-1),ye(q,e)},Tt=(e,t)=>nt(r,e,t),bt=(e,t,n)=>nt(Se(c,e,fe),t,n),Ct=(e,t,n,l)=>nt(Se(Se(v,e,fe),t,fe),n,l),mt=(e,t,n,l,s)=>Se(Se(Se(y,e,fe),t,fe),n,(()=>[l,0]))[1]=s,Vt=(e,t)=>nt(m,e,t),Et=(e,t,n)=>Se(E,e,(()=>[t,0]))[1]=n,kt=(e,t,n,l,s)=>(P(Se(Se(Se(D,e,fe),t,fe),n,(()=>[])),l),s),xt=(e,t,n)=>(P(Se(J,e,(()=>[])),t),n),Mt=(e,t,n)=>H(Le(Le(Le(y,e),t),n),(([e,t])=>[!0,e,t]),(()=>[!1,...Xe(Gt(e,t,n))])),Dt=e=>H(Le(E,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Xe(Ut(e))])),Jt=e=>de(D)||de(me[e])?0:ve(e?Ce(D):D,((t,n)=>ve(t,((t,l)=>ve(t,((t,s)=>Ne(me[e],[n,l,s],t))))))),At=e=>de(J)||de(De[e])?0:ve(e?Te(J):J,((t,n)=>Ne(De[e],[n],t))),Ot=(e,t,n)=>{if(!de(t))return Ne(e,n),1},Ft=e=>{const t=de(ee[e]),n=de(ie[e])&&de(_[e])&&t&&de(Y[e]),l=de(ce[e])&&de(ne[e])&&de(Z[e])&&de(X[e]);if(!n||!l){const s=e?[Te(r),be(c),Ce(v),Ce(y)]:[r,c,v,y];if(!n){ve(s[2],((t,n)=>ve(t,((t,l)=>Ot(ie[e],t,[n,l])))));const n=xe();ve(s[1],((l,s)=>{Ot(_[e],l,[s])&&!t&&(Ne(ee[e],[s,null]),Me(n,s))})),t||ve(s[3],((t,l)=>{if(!ae(n,l)){const n=xe();ve(t,(e=>ve(e,(([t,l],s)=>l!==t?Me(n,s):he(e,s))))),ve(n,(t=>Ne(ee[e],[l,t])))}})),Ot(Y[e],s[0])}if(!l){let t;ve(s[3],((n,l)=>{let s;ve(n,((n,o)=>{let r;ve(n,(([n,i],a)=>{i!==n&&(Ne(ce[e],[l,o,a],i,n,Mt),t=s=r=1)})),r&&Ne(ne[e],[l,o],Mt)})),s&&Ne(Z[e],[l],Mt)})),t&&Ne(X[e],void 0,Mt)}}},Pt=e=>{const t=de(Ae[e]),n=de(Oe[e])&&de(Je[e]);if(!t||!n){const l=e?[Te(m),Te(E)]:[m,E];if(t||Ot(Ae[e],l[0]),!n){let t;ve(l[1],(([n,l],s)=>{l!==n&&(Ne(Oe[e],[s],l,n,Dt),t=1)})),t&&Ne(Je[e],void 0,Dt)}}},jt=(e,...t)=>(an((()=>e(...M(t,b)))),un),Qt=()=>[we(y,((e,t)=>-1===Le(r,t)?null:we(e,((e,n)=>-1===Le(Le(c,t),n)?null:we(e,(([,e])=>null!=e?e:null),((e,t)=>_e(t)))),re)),re),we(E,(([,e])=>null!=e?e:null),((e,t)=>_e(t)))],zt=()=>({cellsTouched:n,valuesTouched:l,changedCells:Ie(y,Ze,_e),invalidCells:Ie(D),changedValues:we(E,Ze,_e),invalidValues:we(J),changedTableIds:we(r),changedRowIds:Re(c),changedCellIds:Ie(v),changedValueIds:we(m)}),Nt=()=>Ie($),Wt=()=>ge($),Bt=e=>ge(Le($,b(e))),$t=(e,t,n,l=0,s)=>{return M(F(k((o=Le($,b(e)),r=(e,n)=>[G(t)?n:Le(e,b(t)),n],M([...null!=(i=null==o?void 0:o.entries())?i:[]],(([e,t])=>r(t,e)))),(([e],[t])=>Qe(e,t)*(n?-1:1))),l,G(s)?s:l+s),(([,e])=>e));var o,r,i},qt=(e,t)=>ge(Le(Le($,b(e)),b(t))),Gt=(e,t,n)=>Le(Le(Le($,b(e)),b(t)),b(n)),Ht=()=>we(q),Kt=()=>ge(q),Ut=e=>Le(q,b(e)),Xt=e=>jt((()=>(e=>tt(e,qe,kt))(e)?dt(e):0)),Yt=e=>jt((()=>Ke(e)?gt(e):0)),Zt=e=>{try{at(N(e))}catch(e){}return un},_t=t=>jt((()=>{if((e=tt(t,(e=>tt(e,$e))))&&(rt(t),!de($))){const e=Nt();tn(),Xt(e)}})),en=e=>jt((()=>{if(t=(e=>tt(e,$e))(e)){const n=Ht();rn(),sn(),t=!0,it(e),Yt(n)}})),tn=()=>jt((()=>dt({}))),nn=e=>jt((e=>ae($,e)?St(e):0),e),ln=(e,t)=>jt(((e,t)=>H(Le($,e),(n=>ae(n,t)?wt(e,n,t):0))),e,t),sn=()=>jt((()=>gt({}))),on=()=>jt((()=>{rt({}),e=!1})),rn=()=>jt((()=>{it({}),t=!1})),an=(e,t)=>{if(-1==s)return;dn();const n=e();return cn(t),n},dn=()=>(s++,un),cn=e=>(s>0&&(s--,0==s&&(n=!de(y),l=!de(E),s=1,Jt(1),n&&Ft(1),At(1),l&&Pt(1),s=-1,(null==e?void 0:e(Qt,zt))&&(s=1,ve(y,((e,t)=>ve(e,((e,n)=>ve(e,(([e],l)=>Ee(un,t,n,l,e))))))),ve(E,(([e],t)=>ke(un,t,e))),s=-1,n=l=!1),Ne(je[0],void 0,Qt,zt),Jt(0),n&&Ft(0),At(0),l&&Pt(0),Ne(je[1],void 0,Qt,zt),s=0,x([r,c,v,y,D,m,E,J],ue))),un),un={getContent:()=>[Nt(),Ht()],getTables:Nt,getTableIds:Wt,getTable:e=>Re(Le($,b(e))),getRowIds:Bt,getSortedRowIds:$t,getRow:(e,t)=>we(Le(Le($,b(e)),b(t))),getCellIds:qt,getCell:Gt,getValues:Ht,getValueIds:Kt,getValue:Ut,hasTables:()=>!de($),hasTable:e=>ae($,b(e)),hasRow:(e,t)=>ae(Le($,b(e)),b(t)),hasCell:(e,t,n)=>ae(Le(Le($,b(e)),b(t)),b(n)),hasValues:()=>!de(q),hasValue:e=>ae(q,b(e)),getTablesJson:()=>z($),getValuesJson:()=>z(q),getJson:()=>z([$,q]),getTablesSchemaJson:()=>z(A),getValuesSchemaJson:()=>z(j),getSchemaJson:()=>z([A,j]),setContent:([e,t])=>jt((()=>{Xt(e),Yt(t)})),setTables:Xt,setTable:(e,t)=>jt((e=>qe(t,e)?ct(e,t):0),e),setRow:(e,t,n)=>jt(((e,t)=>Ge(e,t,n)?ut(e,yt(e),t,n):0),e,t),addRow:(e,t,n=!0)=>an((()=>{let l;return Ge(e,l,t)&&(e=b(e),ut(e,yt(e),l=pt(e,n?1:0),t)),l})),setPartialRow:(e,t,n)=>jt(((e,t)=>{if(Ge(e,t,n,1)){const l=yt(e);oe(n,((n,s)=>ht(e,l,t,s,n)))}}),e,t),setCell:(e,t,n,l)=>jt(((e,t,n)=>H(He(e,t,n,U(l)?l(Gt(e,t,n)):l),(l=>ht(e,yt(e),t,n,l)))),e,t,n),setValues:Yt,setPartialValues:e=>jt((()=>Ke(e,1)?oe(e,((e,t)=>Lt(t,e))):0)),setValue:(e,t)=>jt((e=>H(Ue(e,U(t)?t(Ut(e)):t),(t=>Lt(e,t)))),e),setTransactionChanges:e=>jt((()=>{oe(e[0],((e,t)=>G(e)?nn(t):oe(e,((e,n)=>G(e)?ln(t,n):oe(e,((e,l)=>Ee(un,t,n,l,e))))))),oe(e[1],((e,t)=>ke(un,t,e)))})),setTablesJson:Zt,setValuesJson:e=>{try{ft(N(e))}catch(e){}return un},setJson:e=>{try{const[t,n]=N(e);at(t),ft(n)}catch(t){Zt(e)}return un},setTablesSchema:_t,setValuesSchema:en,setSchema:(e,t)=>jt((()=>{_t(e),en(t)})),delTables:tn,delTable:nn,delRow:ln,delCell:(e,t,n,l)=>jt(((e,t,n)=>H(Le($,e),(s=>H(Le(s,t),(o=>ae(o,n)?Rt(e,s,t,o,n,l):0))))),e,t,n),delValues:sn,delValue:e=>jt((e=>ae(q,e)?It(e):0),e),delTablesSchema:on,delValuesSchema:rn,delSchema:()=>jt((()=>{on(),rn()})),transaction:an,startTransaction:dn,finishTransaction:cn,forEachTable:e=>ve($,((t,n)=>e(n,(e=>ve(t,((t,n)=>e(n,(e=>pe(t,e))))))))),forEachRow:(e,t)=>ve(Le($,b(e)),((e,n)=>t(n,(t=>pe(e,t))))),forEachCell:(e,t,n)=>pe(Le(Le($,b(e)),b(t)),n),forEachValue:e=>pe(q,e),addSortedRowIdsListener:(e,t,n,l,s,o,r)=>{let i=$t(e,t,n,l,s);return ze((()=>{const r=$t(e,t,n,l,s);V(r,i)||(i=r,o(un,e,t,n,l,s,i))}),ee[r?1:0],[e,t],[Wt])},addWillFinishTransactionListener:e=>ze(e,je[0]),addDidFinishTransactionListener:e=>ze(e,je[1]),callListener:e=>(Be(e),un),delListener:e=>(We(e),un),getListenerStats:()=>({}),createStore:lt};return oe({[f]:[0,X],[g]:[0,Y],[h]:[1,Z,[Wt]],[p]:[1,_,[Wt]],[L]:[2,ne,[Wt,Bt]],[w]:[2,ie,[Wt,Bt]],[S]:[3,ce,[Wt,Bt,qt],e=>Xe(Gt(...e))],InvalidCell:[3,me],[I]:[0,Je],[T]:[0,Ae],[R]:[1,Oe,[Kt],e=>Xe(Ut(e[0]))],InvalidValue:[1,De]},(([e,t,n,l],s)=>{un[u+s+d]=(...s)=>ze(s[e],t[s[e+1]?1:0],e>0?F(s,0,e):void 0,n,l)})),te(un)};e.createCheckpoints=je,e.createCustomPersister=(e,t,n,l,s)=>{let o,r,i=0,a=!1;const d=e=>$e(void 0,null,(function*(){2!=i&&(i=1,yield e(),i=0)})),c={load:(n,l)=>$e(void 0,null,(function*(){return yield d((()=>$e(void 0,null,(function*(){let s;try{s=yield t()}catch(e){}e.setContent(null!=s?s:[n,l])})))),c})),startAutoLoad:(n,s)=>$e(void 0,null,(function*(){return c.stopAutoLoad(),yield c.load(n,s),a=!0,r=l(((n,l)=>$e(void 0,null,(function*(){yield d((()=>$e(void 0,null,(function*(){var s;if(l)e.setTransactionChanges(l());else try{e.setContent(null!=(s=null==n?void 0:n())?s:yield t())}catch(e){}}))))})))),c})),stopAutoLoad:()=>(a&&(s(r),r=void 0,a=!1),c),save:t=>$e(void 0,null,(function*(){return 1!=i&&(i=2,yield n(e.getContent,t),i=0),c})),startAutoSave:()=>$e(void 0,null,(function*(){return yield c.stopAutoSave().save(),o=e.addDidFinishTransactionListener(((e,t)=>c.save(t))),c})),stopAutoSave:()=>(H(o,e.delListener),c),getStore:()=>e,destroy:()=>c.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return te(c)},e.createIndexes=ze,e.createMetrics=Be,e.createQueries=Ke,e.createRelationships=Ue,e.createStore=lt,e.defaultSorter=Qe},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBase={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",l=t(n),s=t(!0),o=t(0),r=t(t),i="type",a="default",d="Listener",c="Result",u="add",v="Ids",h="Table",f=h+"s",g=h+v,L="Row",p=L+v,S="Sorted"+L+v,y="Cell",w=y+v,R="Value",I=R+"s",T=R+v,b=e=>n+e,C=(e,t)=>e.includes(t),m=(e,t)=>e.every(t),V=(e,t)=>J(e)===J(t)&&m(e,((e,n)=>t[n]===e)),E=(e,t)=>m(e,((n,l)=>0==l||t(e[l-1],n)<=0)),k=(e,t)=>e.sort(t),x=(e,t)=>e.forEach(t),M=(e,t)=>e.map(t),D=e=>O(e,((e,t)=>e+t),0),J=e=>e.length,A=e=>0==J(e),O=(e,t,n)=>e.reduce(t,n),F=(e,t,n)=>e.slice(t,n),P=(e,...t)=>e.push(...t),j=e=>e.pop(),Q=e=>e.shift(),z=e=>JSON.stringify(e,((e,t)=>q(t,Map)?O([...t],((e,[t,n])=>(e[t]=n,e)),{}):t)),N=JSON.parse,B=Math.max,W=Math.min,$=isFinite,q=(e,t)=>e instanceof t,G=e=>null==e,H=(e,t,n)=>G(e)?null==n?void 0:n():t(e),K=e=>e==l||e==s,U=e=>t(e)==r,X=e=>Array.isArray(e),Y=()=>{},Z=Object,_=Z.keys,ee=Z.isFrozen,te=Z.freeze,ne=e=>q(e,Z)&&e.constructor==Z,le=(e,t)=>!G(((e,t)=>H(e,(e=>e[t])))(e,t)),se=(e,t)=>delete e[t],oe=(e,t)=>M(Z.entries(e),(([e,n])=>t(n,e))),re=e=>ne(e)&&A(_(e)),ie=e=>e.size,ae=(e,t)=>{var n;return null!=(n=null==e?void 0:e.has(t))&&n},de=e=>G(e)||0==ie(e),ce=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},ue=e=>e.clear(),ve=(e,t)=>null==e?void 0:e.forEach(t),he=(e,t)=>null==e?void 0:e.delete(t),fe=e=>new Map(e),ge=e=>{var t;return[...null!=(t=null==e?void 0:e.keys())?t:[]]},Le=(e,t)=>null==e?void 0:e.get(t),pe=(e,t)=>ve(e,((e,n)=>t(n,e))),Se=(e,t,n)=>G(n)?(he(e,t),e):null==e?void 0:e.set(t,n),ye=(e,t,n)=>(ae(e,t)||Se(e,t,n()),Le(e,t)),we=(e,t,n)=>{const l={};return ve(e,((e,s)=>{const o=t?t(e,s):e;!(null==n?void 0:n(o,e))&&(l[s]=o)})),l},Re=(e,t,n)=>we(e,(e=>we(e,t,n)),re),Ie=(e,t,n)=>we(e,(e=>Re(e,t,n)),re),Te=(e,t)=>{const n=fe();return ve(e,((e,l)=>{var s;return n.set(l,null!=(s=null==t?void 0:t(e))?s:e)})),n},be=e=>Te(e,Te),Ce=e=>Te(e,be),me=(e,t,n,l,s=0)=>H((n?ye:Le)(e,t[s],s>J(t)-2?n:fe),(o=>{if(s>J(t)-2)return(null==l?void 0:l(o))&&Se(e,t[s]),o;const r=me(o,t,n,l,s+1);return de(o)&&Se(e,t[s]),r})),Ve=e=>{const n=t(e);return K(n)||n==o&&$(e)?n:void 0},Ee=(e,t,n,l,s)=>G(s)?e.delCell(t,n,l,!0):e.setCell(t,n,l,s),ke=(e,t,n)=>G(n)?e.delValue(t):e.setValue(t,n),xe=e=>new Set(X(e)||G(e)?e:[e]),Me=(e,t)=>null==e?void 0:e.add(t),De=(e,t,n)=>{const l=e.hasRow,s=fe(),o=fe(),r=fe(),i=fe(),a=fe(),d=(t,n,...l)=>{const s=ye(a,t,xe);return x(l,(t=>Me(s,t)&&n&&e.callListener(t))),l},c=(t,...n)=>H(Le(a,t),(l=>{x(A(n)?ce(l):n,(t=>{e.delListener(t),he(l,t)})),de(l)&&Se(a,t)})),u=(e,n)=>{Se(s,e,n),ae(o,e)||(Se(o,e,t()),Se(r,e,fe()),Se(i,e,fe()))},v=e=>{Se(s,e),Se(o,e),Se(r,e),Se(i,e),c(e)};return[()=>e,()=>ge(s),e=>pe(o,e),e=>ae(o,e),e=>Le(s,e),e=>Le(o,e),(e,t)=>Se(o,e,t),u,(t,s,o,a,v)=>{u(t,s);const h=fe(),f=fe(),g=Le(r,t),L=Le(i,t),p=t=>{const o=n=>e.getCell(s,t,n),r=Le(g,t),i=l(s,t)?n(a(o,t)):void 0;if(r===i||X(r)&&X(i)&&V(r,i)||Se(h,t,[r,i]),!G(v)){const e=Le(L,t),n=l(s,t)?v(o,t):void 0;e!=n&&Se(f,t,n)}},S=e=>{o((()=>{ve(h,(([,e],t)=>Se(g,t,e))),ve(f,((e,t)=>Se(L,t,e)))}),h,f,g,L,e),ue(h),ue(f)};pe(g,p),e.hasTable(s)&&x(e.getRowIds(s),(e=>{ae(g,e)||p(e)})),S(!0),c(t),d(t,0,e.addRowListener(s,null,((e,t,n)=>p(n))),e.addTableListener(s,(()=>S())))},v,()=>pe(a,v),d,c]},Je=(e,s)=>t(e)==l?t=>t(e):null!=e?e:()=>null!=s?s:n,Ae=e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))},Oe=/^\d+$/,Fe=()=>{const e=[];let t=0;return[l=>{var s;return null!=(s=l?Q(e):null)?s:n+t++},t=>{Oe.test(t)&&J(e)<1e3&&P(e,t)}]},Pe=e=>{let t;const[l,s]=Fe(),o=fe();return[(s,r,i,a=[],d=(()=>[]))=>{null!=t||(t=e());const c=l(1);return Se(o,c,[s,r,i,a,d]),Me(me(r,null!=i?i:[n],xe),c),c},(e,l,...s)=>x(((e,t=[n])=>{const l=[],s=(e,n)=>n==J(t)?P(l,e):null===t[n]?ve(e,(e=>s(e,n+1))):x([t[n],null],(t=>s(Le(e,t),n+1)));return s(e,0),l})(e,l),(e=>ve(e,(e=>Le(o,e)[0](t,...null!=l?l:[],...s))))),e=>H(Le(o,e),(([,t,l])=>(me(t,null!=l?l:[n],void 0,(t=>(he(t,e),de(t)?1:0))),Se(o,e),s(e),l))),e=>H(Le(o,e),(([e,,n=[],l,s])=>{const o=(...r)=>{var i,a;const d=J(r);d==J(n)?e(t,...r,...s(r)):G(n[d])?x(null!=(a=null==(i=l[d])?void 0:i.call(l,...r))?a:[],(e=>o(...r,e))):o(...r,n[d])};o()}))]},je=Ae((e=>{let t,l,s,o=100,r=fe(),i=fe(),a=1;const d=fe(),c=fe(),[u,v,h]=Pe((()=>z)),f=fe(),g=fe(),L=[],p=[],S=(t,n)=>{a=0,e.transaction((()=>{const[l,s]=Le(f,n);ve(l,((n,l)=>ve(n,((n,s)=>ve(n,((n,o)=>Ee(e,l,s,o,n[t]))))))),ve(s,((n,l)=>ke(e,l,n[t])))})),a=1},y=e=>{Se(f,e),Se(g,e),v(c,[e])},w=(e,t)=>x(((e,t)=>e.splice(0,t))(e,null!=t?t:J(e)),y),R=()=>w(L,J(L)-o),I=()=>H(t,(()=>{P(L,t),R(),w(p),t=void 0,s=1})),T=()=>{t=j(L),s=1},b=e.addCellListener(null,null,null,((e,t,n,l,s,o)=>{if(a){I();const e=ye(r,t,fe),i=ye(e,n,fe),a=ye(i,l,(()=>[o,void 0]));a[1]=s,a[0]===s&&de(Se(i,l))&&de(Se(e,n))&&de(Se(r,t))&&T(),M()}})),m=e.addValueListener(null,((e,t,n,l)=>{if(a){I();const e=ye(i,t,(()=>[l,void 0]));e[1]=n,e[0]===n&&de(Se(i,t))&&T(),M()}})),V=(e="")=>(G(t)&&(t=n+l++,Se(f,t,[r,i]),O(t,e),r=fe(),i=fe(),s=1),t),E=()=>{A(L)||(((e,...t)=>{e.unshift(...t)})(p,V()),S(0,t),t=j(L),s=1)},k=()=>{A(p)||(P(L,t),t=Q(p),S(1,t),s=1)},M=()=>{s&&(v(d),s=0)},D=e=>{const t=V(e);return M(),t},O=(e,t)=>(F(e)&&Le(g,e)!==t&&(Se(g,e,t),v(c,[e])),z),F=e=>ae(f,e),z={setSize:e=>(o=e,R(),z),addCheckpoint:D,setCheckpoint:O,getStore:()=>e,getCheckpointIds:()=>[[...L],t,[...p]],forEachCheckpoint:e=>pe(g,e),hasCheckpoint:F,getCheckpoint:e=>Le(g,e),goBackward:()=>(E(),M(),z),goForward:()=>(k(),M(),z),goTo:e=>{const n=C(L,e)?E:C(p,e)?k:null;for(;!G(n)&&e!=t;)n();return M(),z},addCheckpointIdsListener:e=>u(e,d),addCheckpointListener:(e,t)=>u(t,c,[e]),delListener:e=>(h(e),z),clear:()=>(w(L),w(p),G(t)||y(t),t=void 0,l=0,D(),z),destroy:()=>{e.delListener(b),e.delListener(m)},getListenerStats:()=>({})};return te(z.clear())})),Qe=(e,t)=>e<t?-1:1,ze=Ae((e=>{const t=fe(),l=fe(),[s,o,r,i,a,d,c,,u,v,h]=De(e,fe,(e=>G(e)?n:X(e)?M(e,b):b(e))),[f,g,L]=Pe((()=>S)),p=(t,n,l)=>{const s=a(t);ve(l,((t,l)=>n(l,(n=>ve(t,(t=>n(t,(n=>e.forEachCell(s,t,n)))))))))},S={setIndexDefinition:(e,n,s,o,r,i=Qe)=>{const a=G(r)?void 0:([e],[t])=>r(e,t);return u(e,n,((n,s,r,u,v,h)=>{let f=0;const L=xe(),p=xe(),S=d(e);if(ve(s,(([e,t],n)=>{const l=xe(e),s=xe(t);ve(l,(e=>he(s,e)?he(l,e):0)),ve(l,(e=>{Me(L,e),H(Le(S,e),(t=>{he(t,n),de(t)&&(Se(S,e),f=1)}))})),ve(s,(e=>{Me(L,e),ae(S,e)||(Se(S,e,xe()),f=1),Me(Le(S,e),n),G(o)||Me(p,e)}))})),n(),de(v)||(h?pe(S,(e=>Me(p,e))):pe(r,(e=>H(Le(u,e),(e=>Me(p,e))))),ve(p,(e=>{const t=(t,n)=>i(Le(v,t),Le(v,n),e),n=[...Le(S,e)];E(n,t)||(Se(S,e,xe(k(n,t))),Me(L,e))}))),(f||h)&&!G(a)){const t=[...S];E(t,a)||(c(e,fe(k(t,a))),f=1)}f&&g(t,[e]),ve(L,(t=>g(l,[e,t])))}),Je(s),H(o,Je)),S},delIndexDefinition:e=>(v(e),S),getStore:s,getIndexIds:o,forEachIndex:e=>r(((t,n)=>e(t,(e=>p(t,e,n))))),forEachSlice:(e,t)=>p(e,t,d(e)),hasIndex:i,hasSlice:(e,t)=>ae(d(e),t),getTableId:a,getSliceIds:e=>ge(d(e)),getSliceRowIds:(e,t)=>ce(Le(d(e),t)),addSliceIdsListener:(e,n)=>f(n,t,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,l,[e,t]),delListener:e=>(L(e),S),destroy:h,getListenerStats:()=>({})};return te(S)})),Ne=fe([["avg",[(e,t)=>D(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,l)=>e+(t-n)/l]],["max",[e=>B(...e),(e,t)=>B(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:B(t,e)]],["min",[e=>W(...e),(e,t)=>W(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:W(t,e)]],["sum",[e=>D(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),Be=(e,t,n,l,s,o=!1)=>{if(de(n))return;const[r,i,a,d]=s;return o||(o=G(e)),ve(l,(([n,l])=>{o||(e=G(n)?null==i?void 0:i(e,l,t++):G(l)?null==a?void 0:a(e,n,t--):null==d?void 0:d(e,l,n,t),o||(o=G(e)))})),o?r(ce(n),ie(n)):e},We=Ae((e=>{const t=fe(),[l,s,o,r,i,a,d,,c,u,v]=De(e,Y,(e=>isNaN(e)||G(e)||!0===e||!1===e||e===n?void 0:1*e)),[h,f,g]=Pe((()=>L)),L={setMetricDefinition:(e,n,l,s,o,r,i)=>{var u;const v=U(l)?[l,o,r,i]:null!=(u=Le(Ne,l))?u:Le(Ne,"sum");return c(e,n,((n,l,s,o,r,i)=>{const c=a(e),u=ie(o);i||(i=G(c)),n();let h=Be(c,u,o,l,v,i);$(h)||(h=void 0),h!=c&&(d(e,h),f(t,[e],h,c))}),Je(s,1)),L},delMetricDefinition:e=>(u(e),L),getStore:l,getMetricIds:s,forEachMetric:o,hasMetric:r,getTableId:i,getMetric:a,addMetricListener:(e,n)=>h(n,t,[e]),delListener:e=>(g(e),L),destroy:v,getListenerStats:()=>({})};return te(L)}));var $e=(e,t,n)=>new Promise(((l,s)=>{var o=e=>{try{i(n.next(e))}catch(e){s(e)}},r=e=>{try{i(n.throw(e))}catch(e){s(e)}},i=e=>e.done?l(e.value):Promise.resolve(e.value).then(o,r);i((n=n.apply(e,t)).next())})),qe=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable;const Ke=Ae((e=>{const t=e.createStore,[l,s,o,r,i,,,a,,v,f,g,R]=De(e,(()=>!0),Y),I=t(),T=t(),b=fe(),C=(e,t,...n)=>x(n,(n=>Me(ye(ye(b,t,fe),e,xe),n))),V=e=>{H(Le(b,e),(e=>{pe(e,((e,t)=>ve(t,(t=>e.delListener(t))))),ue(e)})),x([T,I],(t=>t.delTable(e)))},E=(e,t,n)=>C(t,e,t.addStartTransactionListener(n.startTransaction),t.addDidFinishTransactionListener((()=>n.finishTransaction()))),k={setQueryDefinition:(t,l,s)=>{a(t,l),V(t);const o=[],r=[[null,[l,null,null,[],fe()]]],i=[],d=[],c=[];s({select:(e,t)=>{const l=U(e)?[J(o)+n,e]:[G(t)?e:t,n=>n(e,t)];return P(o,l),{as:e=>l[0]=e}},join:(e,t,n)=>{const l=G(n)||U(t)?null:t,s=G(l)?t:n,o=[e,[e,l,U(s)?s:e=>e(s),[],fe()]];return P(r,o),{as:e=>o[0]=e}},where:(e,t,n)=>P(i,U(e)?e:G(n)?n=>n(e)===t:l=>l(e,t)===n),group:(e,t,n,l,s)=>{var o;const r=[e,[e,U(t)?[t,n,l,s]:null!=(o=Le(Ne,t))?o:[(e,t)=>t]]];return P(d,r),{as:e=>r[0]=e}},having:(e,t)=>P(c,U(e)?e:n=>n(e)===t)});const u=fe(o);if(de(u))return k;const v=fe(r);pe(v,((e,[,t])=>H(Le(v,t),(({3:t})=>G(e)?0:P(t,e)))));const h=fe(d);let f=I;if(de(h)&&A(c))f=T;else{E(t,f,T);const e=fe();pe(h,((t,[n,l])=>Me(ye(e,n,xe),[t,l])));const n=xe();pe(u,(t=>ae(e,t)?0:Me(n,t)));const l=fe(),s=(n,l,s,o)=>H(n,(([r,i,a,d])=>{pe(l,((t,[n])=>{const l=ye(r,t,fe),i=Le(l,s),a=o?void 0:n;if(i!==a){const n=xe([[i,a]]),o=ie(l);Se(l,s,a),ve(Le(e,t),(([e,t])=>{const s=Be(d[e],o,l,n,t);d[e]=G(Ve(s))?null:s}))}})),de(i)||!m(c,(e=>e((e=>d[e]))))?T.delRow(t,a):G(a)?n[2]=T.addRow(t,d):T.setRow(t,a,d)}));C(f,t,f.addRowListener(t,null,((o,r,i,a)=>{const d=[],c=[],u=fe(),v=f.hasRow(t,i);let h=!v;ve(n,(e=>{const[n,l,s]=a(t,i,e);P(d,l),P(c,s),h||(h=n)})),pe(e,(e=>{const[n,,l]=a(t,i,e);(h||n)&&Se(u,e,[l])})),h&&s(me(l,d,void 0,(([,e])=>(he(e,i),de(e)))),u,i,1),v&&s(me(l,c,(()=>{const e={};return ve(n,(n=>e[n]=f.getCell(t,i,n))),[fe(),xe(),void 0,e]}),(([,e])=>{Me(e,i)})),u,i)})))}E(t,e,f);const L=(n,s,o,r)=>{const a=t=>e.getCell(s,o,t);x(r,(l=>{var s;const[o,,r,i,d]=Le(v,l),c=null==r?void 0:r(a,n),[u,h]=null!=(s=Le(d,n))?s:[];c!=u&&(G(h)||R(t,h),Se(d,n,G(c)?null:[c,...g(t,1,e.addRowListener(o,c,(()=>L(n,o,c,i))))]))})),(n=>{const s=(t,s)=>{var o,r,i;return e.getCell(...G(s)?[l,n,t]:t===l?[l,n,s]:[null==(o=Le(v,t))?void 0:o[0],null==(i=Le(null==(r=Le(v,t))?void 0:r[4],n))?void 0:i[0],s])};f.transaction((()=>m(i,(e=>e(s)))?pe(u,((e,l)=>Ee(f,t,n,e,l(s,n)))):f.delRow(t,n)))})(n)},{3:p}=Le(v,null);return f.transaction((()=>g(t,1,e.addRowListener(l,null,((n,s,o)=>{e.hasRow(l,o)?L(o,l,o,p):(f.delRow(t,o),ve(v,(({4:e})=>H(Le(e,o),(([,n])=>{R(t,n),Se(e,o)})))))}))))),k},delQueryDefinition:e=>(V(e),v(e),k),getStore:l,getQueryIds:s,forEachQuery:o,hasQuery:r,getTableId:i,delListener:e=>(T.delListener(e),k),destroy:f,getListenerStats:()=>((e,t)=>{var n={};for(var l in e)Ge.call(e,l)&&t.indexOf(l)<0&&(n[l]=e[l]);if(null!=e&&qe)for(var l of qe(e))t.indexOf(l)<0&&He.call(e,l)&&(n[l]=e[l]);return n})(T.getListenerStats(),["tables","tableIds","transaction"])};return oe({[h]:[1,1],[p]:[0,1],[S]:[0,5],[L]:[1,2],[w]:[0,2],[y]:[1,3]},(([e,t],n)=>{x(e?["get","has","forEach"]:["get"],(e=>k[e+c+n]=(...t)=>T[e+n](...t))),k[u+c+n+d]=(...e)=>T[u+n+d](...F(e,0,t),((n,...l)=>e[t](k,...l)))})),te(k)})),Ue=Ae((e=>{const t=fe(),l=fe(),s=fe(),o=fe(),[r,i,a,d,c,u,,,v,h,f]=De(e,(()=>[fe(),fe(),fe(),fe()]),(e=>G(e)?void 0:e+n)),[g,L,p]=Pe((()=>R)),S=(e,t,n)=>H(u(e),(([l,,s])=>{if(!ae(s,t)){const o=xe();if(c(e)!=w(e))Me(o,t);else{let e=t;for(;!G(e)&&!ae(o,e);)Me(o,e),e=Le(l,e)}if(n)return o;Se(s,t,o)}return Le(s,t)})),y=(e,t)=>H(u(e),(([,,e])=>Se(e,t))),w=e=>Le(t,e),R={setRelationshipDefinition:(e,n,r,i)=>(Se(t,e,r),v(e,n,((t,n)=>{const r=xe(),i=xe(),a=xe(),[d,c]=u(e);ve(n,(([t,n],l)=>{G(t)||(Me(i,t),H(Le(c,t),(e=>{he(e,l),de(e)&&Se(c,t)}))),G(n)||(Me(i,n),ae(c,n)||Se(c,n,xe()),Me(Le(c,n),l)),Me(r,l),Se(d,l,n),pe(Le(o,e),(t=>{ae(S(e,t),l)&&Me(a,t)}))})),t(),ve(r,(t=>L(l,[e,t]))),ve(i,(t=>L(s,[e,t]))),ve(a,(t=>{y(e,t),L(o,[e,t])}))}),Je(i)),R),delRelationshipDefinition:e=>(Se(t,e),h(e),R),getStore:r,getRelationshipIds:i,forEachRelationship:t=>a((n=>t(n,(t=>e.forEachRow(c(n),t))))),hasRelationship:d,getLocalTableId:c,getRemoteTableId:w,getRemoteRowId:(e,t)=>{var n;return Le(null==(n=u(e))?void 0:n[0],t)},getLocalRowIds:(e,t)=>{var n;return ce(Le(null==(n=u(e))?void 0:n[1],t))},getLinkedRowIds:(e,t)=>G(u(e))?[t]:ce(S(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>g(n,l,[e,t]),addLocalRowIdsListener:(e,t,n)=>g(n,s,[e,t]),addLinkedRowIdsListener:(e,t,n)=>(S(e,t),g(n,o,[e,t])),delListener:e=>(y(...p(e)),R),destroy:f,getListenerStats:()=>({})};return te(R)})),Xe=e=>[e,e],Ye=()=>[fe(),fe()],Ze=e=>[...e],_e=([e,t])=>e===t,et=(e,t,n,l=Se)=>(oe(t,((t,l)=>n(e,l,t))),pe(e,(n=>le(t,n)?0:l(e,n))),e),tt=(e,t,n)=>G(e)||!ne(e)||re(e)||ee(e)?(null==n||n(),!1):(oe(e,((n,l)=>{t(n,l)||se(e,l)})),!re(e)),nt=(e,t,n)=>Se(e,t,Le(e,t)==-n?void 0:n),lt=()=>{let e,t,n=!1,l=!1,s=0;const r=fe(),c=fe(),v=fe(),S=fe(),m=fe(),E=fe(),D=fe(),J=fe(),A=fe(),O=fe(),j=fe(),Q=fe(),B=xe(),W=fe(),$=fe(),q=fe(),X=Ye(),Y=Ye(),Z=Ye(),_=Ye(),ee=Ye(),ne=Ye(),ie=Ye(),ce=Ye(),me=Ye(),De=Ye(),Je=Ye(),Ae=Ye(),Oe=Ye(),je=fe(),ze=Ye(),[Ne,Be,We,$e]=Pe((()=>vn)),qe=e=>{if(!tt(e,((e,t)=>C([i,a],t))))return!1;const t=e[i];return!(!K(t)&&t!=o||(Ve(e[a])!=t&&se(e,a),0))},Ge=(t,n)=>(!e||ae(A,n)||xt(n))&&tt(t,((e,t)=>He(n,t,e)),(()=>xt(n))),He=(e,t,n,l)=>tt(l?n:ot(n,e,t),((l,s)=>H(Ke(e,t,s,l),(e=>(n[s]=e,!0)),(()=>!1))),(()=>xt(e,t))),Ke=(t,n,l,s)=>e?H(Le(Le(A,t),l),(e=>Ve(s)!=e[i]?xt(t,n,l,s,e[a]):s),(()=>xt(t,n,l,s))):G(Ve(s))?xt(t,n,l,s):s,Ue=(e,t)=>tt(t?e:rt(e),((t,n)=>H(st(n,t),(t=>(e[n]=t,!0)),(()=>!1))),(()=>Mt())),st=(e,n)=>t?H(Le(j,e),(t=>Ve(n)!=t[i]?Mt(e,n,t[a]):n),(()=>Mt(e,n))):G(Ve(n))?Mt(e,n):n,ot=(e,t,n)=>(H(Le(O,t),(([l,s])=>{ve(l,((t,n)=>{le(e,n)||(e[n]=t)})),ve(s,(l=>{le(e,l)||xt(t,n,l)}))})),e),rt=e=>(t&&(ve(Q,((t,n)=>{le(e,n)||(e[n]=t)})),ve(B,(t=>{le(e,t)||Mt(t)}))),e),it=e=>et(A,e,((e,t,n)=>{const l=fe(),s=xe();et(ye(A,t,fe),n,((e,t,n)=>{Se(e,t,n),H(n[a],(e=>Se(l,t,e)),(()=>Me(s,t)))})),Se(O,t,[l,s])}),((e,t)=>{Se(A,t),Se(O,t)})),at=e=>et(j,e,((e,t,n)=>{Se(j,t,n),H(n[a],(e=>Se(Q,t,e)),(()=>Me(B,t)))}),((e,t)=>{Se(j,t),Se(Q,t),he(B,t)})),dt=e=>re(e)?nn():Yt(e),ct=e=>et($,e,((e,t,n)=>ut(t,n)),((e,t)=>wt(t))),ut=(e,t)=>et(ye($,e,(()=>(bt(e,1),fe()))),t,((t,n,l)=>vt(e,t,n,l)),((t,n)=>Rt(e,t,n))),vt=(e,t,n,l,s)=>et(ye(t,n,(()=>(Ct(e,n,1),fe()))),l,((t,l,s)=>ht(e,n,t,l,s)),((l,o)=>It(e,t,n,l,o,s))),ht=(e,t,n,l,s)=>{ae(n,l)||mt(e,t,l,1);const o=Le(n,l);s!==o&&(Vt(e,t,l,o,s),Se(n,l,s))},ft=(e,t,n,l,s)=>H(Le(t,n),(t=>ht(e,n,t,l,s)),(()=>vt(e,t,n,ot({[l]:s},e,n)))),gt=e=>re(e)?on():Zt(e),Lt=e=>et(q,e,((e,t,n)=>pt(t,n)),((e,t)=>Tt(t))),pt=(e,t)=>{ae(q,e)||Et(e,1);const n=Le(q,e);t!==n&&(kt(e,n,t),Se(q,e,t))},St=(e,t)=>{const[n]=ye(W,e,Fe),l=n(t);return ae(Le($,e),l)?St(e,t):l},yt=e=>{var t;return null!=(t=Le($,e))?t:ut(e,{})},wt=e=>ut(e,{}),Rt=(e,t,n)=>{const[,l]=ye(W,e,Fe);l(n),vt(e,t,n,{},!0)},It=(e,t,n,l,s,o)=>{var r;const i=Le(null==(r=Le(O,e))?void 0:r[0],s);if(!G(i)&&!o)return ht(e,n,l,s,i);const a=t=>{Vt(e,n,t,Le(l,t)),mt(e,n,t,-1),Se(l,t)};G(i)?a(s):pe(l,a),de(l)&&(Ct(e,n,-1),de(Se(t,n))&&(bt(e,-1),Se($,e),Se(W,e)))},Tt=e=>{const t=Le(Q,e);if(!G(t))return pt(e,t);kt(e,Le(q,e)),Et(e,-1),Se(q,e)},bt=(e,t)=>nt(r,e,t),Ct=(e,t,n)=>nt(ye(c,e,fe),t,n),mt=(e,t,n,l)=>nt(ye(ye(v,e,fe),t,fe),n,l),Vt=(e,t,n,l,s)=>ye(ye(ye(S,e,fe),t,fe),n,(()=>[l,0]))[1]=s,Et=(e,t)=>nt(m,e,t),kt=(e,t,n)=>ye(E,e,(()=>[t,0]))[1]=n,xt=(e,t,n,l,s)=>(P(ye(ye(ye(D,e,fe),t,fe),n,(()=>[])),l),s),Mt=(e,t,n)=>(P(ye(J,e,(()=>[])),t),n),Dt=(e,t,n)=>H(Le(Le(Le(S,e),t),n),(([e,t])=>[!0,e,t]),(()=>[!1,...Xe(Ht(e,t,n))])),Jt=e=>H(Le(E,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Xe(Xt(e))])),At=e=>de(D)||de(me[e])?0:ve(e?Ce(D):D,((t,n)=>ve(t,((t,l)=>ve(t,((t,s)=>Be(me[e],[n,l,s],t))))))),Ot=e=>de(J)||de(De[e])?0:ve(e?Te(J):J,((t,n)=>Be(De[e],[n],t))),Ft=(e,t,n)=>{if(!de(t))return Be(e,n),1},Pt=e=>{const t=de(ee[e]),n=de(ie[e])&&de(_[e])&&t&&de(Y[e]),l=de(ce[e])&&de(ne[e])&&de(Z[e])&&de(X[e]);if(!n||!l){const s=e?[Te(r),be(c),Ce(v),Ce(S)]:[r,c,v,S];if(!n){ve(s[2],((t,n)=>ve(t,((t,l)=>Ft(ie[e],t,[n,l])))));const n=xe();ve(s[1],((l,s)=>{Ft(_[e],l,[s])&&!t&&(Be(ee[e],[s,null]),Me(n,s))})),t||ve(s[3],((t,l)=>{if(!ae(n,l)){const n=xe();ve(t,(e=>ve(e,(([t,l],s)=>l!==t?Me(n,s):he(e,s))))),ve(n,(t=>Be(ee[e],[l,t])))}})),Ft(Y[e],s[0])}if(!l){let t;ve(s[3],((n,l)=>{let s;ve(n,((n,o)=>{let r;ve(n,(([n,i],a)=>{i!==n&&(Be(ce[e],[l,o,a],i,n,Dt),t=s=r=1)})),r&&Be(ne[e],[l,o],Dt)})),s&&Be(Z[e],[l],Dt)})),t&&Be(X[e],void 0,Dt)}}},jt=e=>{const t=de(Ae[e]),n=de(Oe[e])&&de(Je[e]);if(!t||!n){const l=e?[Te(m),Te(E)]:[m,E];if(t||Ft(Ae[e],l[0]),!n){let t;ve(l[1],(([n,l],s)=>{l!==n&&(Be(Oe[e],[s],l,n,Jt),t=1)})),t&&Be(Je[e],void 0,Jt)}}},Qt=(e,...t)=>(dn((()=>e(...M(t,b)))),vn),zt=()=>[we(S,((e,t)=>-1===Le(r,t)?null:we(e,((e,n)=>-1===Le(Le(c,t),n)?null:we(e,(([,e])=>null!=e?e:null),((e,t)=>_e(t)))),re)),re),we(E,(([,e])=>null!=e?e:null),((e,t)=>_e(t)))],Nt=()=>({cellsTouched:n,valuesTouched:l,changedCells:Ie(S,Ze,_e),invalidCells:Ie(D),changedValues:we(E,Ze,_e),invalidValues:we(J),changedTableIds:we(r),changedRowIds:Re(c),changedCellIds:Ie(v),changedValueIds:we(m)}),Bt=()=>Ie($),Wt=()=>ge($),$t=e=>ge(Le($,b(e))),qt=(e,t,n,l=0,s)=>{return M(F(k((o=Le($,b(e)),r=(e,n)=>[G(t)?n:Le(e,b(t)),n],M([...null!=(i=null==o?void 0:o.entries())?i:[]],(([e,t])=>r(t,e)))),(([e],[t])=>Qe(e,t)*(n?-1:1))),l,G(s)?s:l+s),(([,e])=>e));var o,r,i},Gt=(e,t)=>ge(Le(Le($,b(e)),b(t))),Ht=(e,t,n)=>Le(Le(Le($,b(e)),b(t)),b(n)),Kt=()=>we(q),Ut=()=>ge(q),Xt=e=>Le(q,b(e)),Yt=e=>Qt((()=>(e=>tt(e,Ge,xt))(e)?ct(e):0)),Zt=e=>Qt((()=>Ue(e)?Lt(e):0)),_t=e=>{try{dt(N(e))}catch(e){}return vn},en=t=>Qt((()=>{if((e=tt(t,(e=>tt(e,qe))))&&(it(t),!de($))){const e=Bt();nn(),Yt(e)}})),tn=e=>Qt((()=>{if(t=(e=>tt(e,qe))(e)){const n=Kt();an(),on(),t=!0,at(e),Zt(n)}})),nn=()=>Qt((()=>ct({}))),ln=e=>Qt((e=>ae($,e)?wt(e):0),e),sn=(e,t)=>Qt(((e,t)=>H(Le($,e),(n=>ae(n,t)?Rt(e,n,t):0))),e,t),on=()=>Qt((()=>Lt({}))),rn=()=>Qt((()=>{it({}),e=!1})),an=()=>Qt((()=>{at({}),t=!1})),dn=(e,t)=>{if(-1!=s){cn();const n=e();return un(t),n}},cn=()=>(-1!=s&&s++,1==s&&Be(je,void 0,zt,Nt),vn),un=e=>(s>0&&(s--,0==s&&(n=!de(S),l=!de(E),s=1,At(1),n&&Pt(1),Ot(1),l&&jt(1),(null==e?void 0:e(zt,Nt))&&(ve(S,((e,t)=>ve(e,((e,n)=>ve(e,(([e],l)=>Ee(vn,t,n,l,e))))))),ve(E,(([e],t)=>ke(vn,t,e))),n=l=!1),Be(ze[0],void 0,zt,Nt),s=-1,At(0),n&&Pt(0),Ot(0),l&&jt(0),Be(ze[1],void 0,zt,Nt),s=0,n=l=!1,x([r,c,v,S,D,m,E,J],ue))),vn),vn={getContent:()=>[Bt(),Kt()],getTables:Bt,getTableIds:Wt,getTable:e=>Re(Le($,b(e))),getRowIds:$t,getSortedRowIds:qt,getRow:(e,t)=>we(Le(Le($,b(e)),b(t))),getCellIds:Gt,getCell:Ht,getValues:Kt,getValueIds:Ut,getValue:Xt,hasTables:()=>!de($),hasTable:e=>ae($,b(e)),hasRow:(e,t)=>ae(Le($,b(e)),b(t)),hasCell:(e,t,n)=>ae(Le(Le($,b(e)),b(t)),b(n)),hasValues:()=>!de(q),hasValue:e=>ae(q,b(e)),getTablesJson:()=>z($),getValuesJson:()=>z(q),getJson:()=>z([$,q]),getTablesSchemaJson:()=>z(A),getValuesSchemaJson:()=>z(j),getSchemaJson:()=>z([A,j]),setContent:([e,t])=>Qt((()=>{Yt(e),Zt(t)})),setTables:Yt,setTable:(e,t)=>Qt((e=>Ge(t,e)?ut(e,t):0),e),setRow:(e,t,n)=>Qt(((e,t)=>He(e,t,n)?vt(e,yt(e),t,n):0),e,t),addRow:(e,t,n=!0)=>dn((()=>{let l;return He(e,l,t)&&(e=b(e),vt(e,yt(e),l=St(e,n?1:0),t)),l})),setPartialRow:(e,t,n)=>Qt(((e,t)=>{if(He(e,t,n,1)){const l=yt(e);oe(n,((n,s)=>ft(e,l,t,s,n)))}}),e,t),setCell:(e,t,n,l)=>Qt(((e,t,n)=>H(Ke(e,t,n,U(l)?l(Ht(e,t,n)):l),(l=>ft(e,yt(e),t,n,l)))),e,t,n),setValues:Zt,setPartialValues:e=>Qt((()=>Ue(e,1)?oe(e,((e,t)=>pt(t,e))):0)),setValue:(e,t)=>Qt((e=>H(st(e,U(t)?t(Xt(e)):t),(t=>pt(e,t)))),e),setTransactionChanges:e=>Qt((()=>{oe(e[0],((e,t)=>G(e)?ln(t):oe(e,((e,n)=>G(e)?sn(t,n):oe(e,((e,l)=>Ee(vn,t,n,l,e))))))),oe(e[1],((e,t)=>ke(vn,t,e)))})),setTablesJson:_t,setValuesJson:e=>{try{gt(N(e))}catch(e){}return vn},setJson:e=>{try{const[t,n]=N(e);dt(t),gt(n)}catch(t){_t(e)}return vn},setTablesSchema:en,setValuesSchema:tn,setSchema:(e,t)=>Qt((()=>{en(e),tn(t)})),delTables:nn,delTable:ln,delRow:sn,delCell:(e,t,n,l)=>Qt(((e,t,n)=>H(Le($,e),(s=>H(Le(s,t),(o=>ae(o,n)?It(e,s,t,o,n,l):0))))),e,t,n),delValues:on,delValue:e=>Qt((e=>ae(q,e)?Tt(e):0),e),delTablesSchema:rn,delValuesSchema:an,delSchema:()=>Qt((()=>{rn(),an()})),transaction:dn,startTransaction:cn,finishTransaction:un,forEachTable:e=>ve($,((t,n)=>e(n,(e=>ve(t,((t,n)=>e(n,(e=>pe(t,e))))))))),forEachRow:(e,t)=>ve(Le($,b(e)),((e,n)=>t(n,(t=>pe(e,t))))),forEachCell:(e,t,n)=>pe(Le(Le($,b(e)),b(t)),n),forEachValue:e=>pe(q,e),addSortedRowIdsListener:(e,t,n,l,s,o,r)=>{let i=qt(e,t,n,l,s);return Ne((()=>{const r=qt(e,t,n,l,s);V(r,i)||(i=r,o(vn,e,t,n,l,s,i))}),ee[r?1:0],[e,t],[Wt])},addStartTransactionListener:e=>Ne(e,je),addWillFinishTransactionListener:e=>Ne(e,ze[0]),addDidFinishTransactionListener:e=>Ne(e,ze[1]),callListener:e=>($e(e),vn),delListener:e=>(We(e),vn),getListenerStats:()=>({}),createStore:lt};return oe({[f]:[0,X],[g]:[0,Y],[h]:[1,Z,[Wt]],[p]:[1,_,[Wt]],[L]:[2,ne,[Wt,$t]],[w]:[2,ie,[Wt,$t]],[y]:[3,ce,[Wt,$t,Gt],e=>Xe(Ht(...e))],InvalidCell:[3,me],[I]:[0,Je],[T]:[0,Ae],[R]:[1,Oe,[Ut],e=>Xe(Xt(e[0]))],InvalidValue:[1,De]},(([e,t,n,l],s)=>{vn[u+s+d]=(...s)=>Ne(s[e],t[s[e+1]?1:0],e>0?F(s,0,e):void 0,n,l)})),te(vn)};e.createCheckpoints=je,e.createCustomPersister=(e,t,n,l,s)=>{let o,r,i=0,a=!1;const d=e=>$e(void 0,null,(function*(){2!=i&&(i=1,yield e(),i=0)})),c={load:(...n)=>$e(void 0,[...n],(function*(n={},l={}){return yield d((()=>$e(void 0,null,(function*(){let s;try{s=yield t()}catch(e){}e.setContent(null!=s?s:[n,l])})))),c})),startAutoLoad:(...n)=>$e(void 0,[...n],(function*(n={},s={}){return c.stopAutoLoad(),yield c.load(n,s),a=!0,r=l(((n,l)=>$e(void 0,null,(function*(){yield d((()=>$e(void 0,null,(function*(){var s;if(l)e.setTransactionChanges(l());else try{e.setContent(null!=(s=null==n?void 0:n())?s:yield t())}catch(e){}}))))})))),c})),stopAutoLoad:()=>(a&&(s(r),r=void 0,a=!1),c),save:t=>$e(void 0,null,(function*(){return 1!=i&&(i=2,yield n(e.getContent,t),i=0),c})),startAutoSave:()=>$e(void 0,null,(function*(){return yield c.stopAutoSave().save(),o=e.addDidFinishTransactionListener(((e,t)=>c.save(t))),c})),stopAutoSave:()=>(H(o,e.delListener),c),getStore:()=>e,destroy:()=>c.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return te(c)},e.createIndexes=ze,e.createMetrics=We,e.createQueries=Ke,e.createRelationships=Ue,e.createStore=lt,e.defaultSorter=Qe},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBase={});
Binary file
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,l="",a=t(l),n=t(!0),o=t(0),d="type",r="default",s="Listener",I="get",c="add",i="Ids",$="Table",u=$+"s",p=$+i,b="Row",C=b+i,h="Sorted"+b+i,g="Cell",m=g+i,f="Value",w=f+"s",y=f+i,v=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),V=(e,t)=>e.forEach(t),x=(e,t)=>e.map(t),R=e=>e.length,P=e=>0==R(e),k=(e,t)=>e.filter(t),S=(e,...t)=>e.push(...t),A=e=>e.pop(),O=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,j=isFinite,N=(e,t)=>e instanceof t,L=e=>null==e,M=e=>e==a||e==n,G=e=>t(e)==a,J=e=>Array.isArray(e),z=e=>{const l=t(e);return M(l)||l==o&&j(e)?l:void 0},W=Object,B=W.keys,F=W.freeze,U=e=>N(e,W)&&e.constructor==W,_=(e,t)=>x(W.entries(e),(([e,l])=>t(l,e))),Z=e=>U(e)&&P(B(e)),H=(e,t)=>{var l;return null!=(l=null==e?void 0:e.has(t))&&l},Q=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},q=(e,t)=>null==e?void 0:e.forEach(t),K=(e,t)=>null==e?void 0:e.delete(t),X=e=>new Map(e),Y=(e,t)=>null==e?void 0:e.get(t),ee=(e,t)=>q(e,((e,l)=>t(l,e))),te=(e,t)=>{var l;return x([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>t(l,e)))},le=(e,t,l)=>L(l)?(K(e,t),e):null==e?void 0:e.set(t,l),ae=(e,t,l)=>(H(e,t)||le(e,t,l()),Y(e,t)),ne=e=>e.toUpperCase(),oe=e=>e.toLowerCase(),de="a ",re="A function for",se=", and registers a listener so that any changes to that result will cause a re-render",Ie="Callback",ce="Del",ie="Deps",$e=ie+"?: React.DependencyList",ue="doRollback?: DoRollback",pe="actions: () => Return, "+ue,be="export",Ce="Id",he="Invalid",ge="Json",me=oe(s),fe="?: ",we=" | undefined",ye="NonNullable",ve="Partial",Te="Props",Ve="Provider",xe=`Registers a ${me} that will be called`,Re="Represents",Pe="rowId: "+Ce,ke="Schema",Se="Set",Ae=", descending?: boolean, offset?: number, limit?: number",Oe="[]",Ee="the Store",De="Transaction",je=oe(De),Ne="Execute a "+je+" to make multiple mutations",Le="Explicitly starts a "+je,Me="Explicitly finishes a "+je,Ge="the end of the "+je,Je="void",ze=" => "+Je,We="WhenSet",Be=" when setting it",Fe=de+"string serialization of",Ue=" ",_e="Gets a callback that can ",Ze="the ",He=" the schema for",Qe=(e=0,t=0)=>`the ${ut[e]}content of`+(t?Ue+Ee:l),qe=(e=0,t,a=0)=>ct[t]+Ue+Qe(e,1)+(a?" when setting it":l),Ke=(e,t=0)=>Re+` a Row when ${t?"s":"g"}etting ${Qe()} the '${e}' `+$,Xe=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,Ye=(e,t)=>`Calls a function for each ${e} in `+t,et=e=>"The props passed to a component that renders "+e,tt=e=>"A function that takes "+e,lt=(e,t=0)=>re+" listening to changes to "+$t[e]+" in "+$t[t],at=(e,t,a=0)=>xe+" whenever "+$t[e]+" in "+$t[t]+" change"+(a?l:"s"),nt=e=>`the '${e}' `+$,ot=e=>"the specified Row in "+nt(e),dt=(e,t=0)=>ct[t]+` ${Qe()} `+nt(e),rt=(e,t=0)=>ct[t]+` ${Qe()} `+ot(e),st=(e,t,l=0)=>ct[l]+` the '${t}' Cell for `+ot(e),It=(e,t=0)=>ct[t]+` the '${e}' Value`,ct=["Gets","Checks existence of","Sets","Deletes","Sets part of",Re,"Gets "+Fe,"Sets "+Fe,xe+" whenever",_e+"set",_e+"add",_e+"set part of",_e+"delete","Renders","Gets "+Fe+He,"Sets"+He,"Deletes"+He],it=[I,"has","set","del","set","forEach",c,l],$t=[Ee,u,Ze+$+Ue+i,de+$,Ze+b+Ue+i,de+b,Ze+g+Ue+i,de+g,"invalid Cell changes",w,Ze+f+Ue+i,de+f,"invalid Value changes",Ze+"sorted "+b+Ue+i],ut=[l,"tabular ","keyed value "],pt=e=>new Set(J(e)||L(e)?e:[e]),bt=(e,t)=>null==e?void 0:e.add(t),Ct=/[^A-Za-z]+/,ht=/[^A-Za-z0-9]+/,gt=/^( *)\/\*\* *(.*?) *\*\/$/gm,mt=(e,t,l)=>e.substring(t,l),ft=e=>e.includes(","),wt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return H(e,n)?wt(e,t,l,a+1):(le(e,n,l),n)},yt=e=>e.replace(gt,((e,t,l)=>{const a=77-vt(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),vt=e=>e.length,Tt=(e,t=l)=>e.join(t),Vt=e=>e.flat(1e3),xt=(e,t=0)=>Tt(x(e.split(ht),((e,l)=>(l>0||t?ne:oe)(mt(e,0,1))+mt(e,1)))),Rt=e=>ne(Tt((e&&!Ct.test(e[0])?e:" "+e).split(ht),"_")),Pt=e=>`/** ${e}. */`,kt=(...e)=>Tt(k(e,(e=>e)),", "),St=(...e)=>"{"+Tt(e,"; ")+"}",At=(...e)=>St(...x(e,(e=>"readonly "+e))),Ot=()=>{const e=[X(),X(),X(),X()],t=X(),a=X();return[(...e)=>Tt(Vt(e),"\n"),(t,l,...a)=>V(a,(a=>V([0,1],(n=>(null!=t?t:n)==n?bt(ae(e[n],l,pt),a):0)))),(e,a,n,o=l,d=1)=>wt(t,e,[a,n,o,d]),(e,t,l)=>wt(a,e,J(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>Y(a,e)===t?e:wt(a,e,t),(t=0)=>x([...T(te(e[t],((e,t)=>`import {${Tt(T(Q(e)),", ")}} from '${t}';`)),((e,t)=>ft(e)!=ft(t)?ft(e)?-1:1:e>t?1:-1)),l],(e=>e.replace("{React}","React"))),()=>te(t,(([e,t,a,n],o)=>[Pt(t),`${n?be+" ":l}type ${o}${a} = ${e};`,l])),()=>te(a,((e,t)=>(e=J(e)?e:[e],S(e,A(e)+";"),[`const ${t} = ${E(e)}`,e,l])))]},Et=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Dt=(e,t,l)=>[t=>_(e,((e,a)=>t(a,xt(a,1),l(Rt(a),`'${a}'`)))),(t,a)=>_(e[t],((e,t)=>a(t,e[d],e[r],l(Rt(t),`'${t}'`),xt(t,1)))),e=>_(t,((t,a)=>e(a,t[d],t[r],l(Rt(a),`'${a}'`),xt(a,1))))],jt=(e,t,a,n)=>[(n,o)=>{const d=n+": "+o,r=e(u,St(...t((e=>`'${e}'?: {[rowId: Id]: `+St(...a(e,((e,t,a)=>`'${e}'${L(a)?"?":l}: ${t}`)))+"}"))),qe(1,5)),I=e(u+We,St(...t((e=>`'${e}'?: {[rowId: Id]: `+St(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),qe(1,5,1)),c=e($+Ce,"keyof "+r,"A "+$+" Id in "+Ee),i=`<TId extends ${c}>`,f=e($,ye+`<${r}[TId]>`,"A "+$+" in "+Ee,i),w=e($+We,ye+`<${I}[TId]>`,"A "+$+" in "+Ee+Be,i),y=e(b,f+"<TId>[Id]","A "+b+" in a "+$,i),v=e(b+We,w+"<TId>[Id]","A "+b+" in a "+$+Be,i),T=e(g+Ce,`Extract<keyof ${y}<TId>, Id>`,"A "+g+" Id in a "+b,i),V=e(g,ye+`<${r}[TId]>[Id][CId]`,"A "+g+" in a "+b,`<TId extends ${c}, CId extends ${T}<TId>>`),x=e("CellIdCellArray",`CId extends ${T}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,g+" Ids and types in a "+b,`<TId extends ${c}, CId = ${T}<TId>>`,0),R=e(g+Ie,`(...[cellId, cell]: ${x}<TId>)`+ze,tt(de+g+" Id, and "+g),i),P=e(b+Ie,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+ze+") "+ze,tt(de+b+" Id, and a "+g+" iterator"),i),k=e("TableIdForEachRowArray",`TId extends ${c} ? [tableId: TId, forEachRow: (rowCallback: ${P}<TId>)${ze}] : never`,$+" Ids and callback types",`<TId = ${c}>`,0),S=e($+Ie,`(...[tableId, forEachRow]: ${k})`+ze,tt(de+$+" Id, and a "+b+" iterator"),l),A=e("TableIdRowIdCellIdArray",`TId extends ${c} ? [tableId: TId, rowId: Id, cellId: ${T}<TId>] : never`,"Ids for GetCellChange",`<TId = ${c}>`,0),O=e("GetCellChange",`(...[tableId, rowId, cellId]: ${A}) => CellChange`,re+" returning information about any Cell's changes during a "+je),E=e(u+s,`(${d}, getCellChange: ${O}${we})`+ze,lt(1)),D=e(p+s,`(${d})`+ze,lt(2)),j=e($+s,`(${d}, tableId: ${c}, getCellChange: ${O}${we})`+ze,lt(3)),N=e(C+s,`(${d}, tableId: ${c})`+ze,lt(4,3)),M=e(h+s,"("+kt(d,"tableId: "+c,"cellId: Id"+we,"descending: boolean","offset: number","limit: number"+we,"sortedRowIds: Ids")+")"+ze,lt(13,3)),G=e(b+s,"("+kt(""+d,"tableId: "+c,Pe,`getCellChange: ${O}${we}`)+")"+ze,lt(5,3)),J=e(m+s,"("+kt(""+d,"tableId: "+c,Pe)+")"+ze,lt(6,5)),z=e("CellListenerArgsArrayInner",`CId extends ${T}<TId> ? [${d}, tableId: TId, ${Pe}, cellId: CId, newCell: ${V}<TId, CId> ${we}, oldCell: ${V}<TId, CId> ${we}, getCellChange: ${O} ${we}] : never`,"Cell args for CellListener",`<TId extends ${c}, CId = ${T}<TId>>`,0),W=e("CellListenerArgsArrayOuter",`TId extends ${c} ? `+z+"<TId> : never","Table args for CellListener",`<TId = ${c}>`,0);return[r,I,c,f,w,y,v,T,V,R,P,S,E,D,j,N,M,G,J,e(g+s,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${W})`+ze,lt(7,5)),e(he+g+s,`(${d}, tableId: Id, ${Pe}, cellId: Id, invalidCells: any[])`+ze,lt(8))]},(t,a)=>{const o=t+": "+a,d=e(w,St(...n(((e,t,a)=>`'${e}'${L(a)?"?":l}: ${t}`))),qe(2,5)),r=e(w+We,St(...n(((e,t)=>`'${e}'?: ${t}`))),qe(2,5,1)),I=e(f+Ce,"keyof "+d,"A "+f+" Id in "+Ee),c=e(f,ye+`<${d}[VId]>`,"A "+f+" Id in "+Ee,`<VId extends ${I}>`),i=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${c}<VId>] : never`,f+" Ids and types in "+Ee,`<VId = ${I}>`,0),$=e(f+Ie,`(...[valueId, value]: ${i})`+ze,tt(de+f+" Id, and "+f)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,re+" returning information about any Value's changes during a "+je),p=e(w+s,`(${o}, getValueChange: ${u}${we})`+ze,lt(9)),b=e(y+s,`(${o})`+ze,lt(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${c}<VId> ${we}, oldValue: ${c}<VId> ${we}, getValueChange: ${u} ${we}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,r,I,c,$,p,b,e(f+s,`(...[${t}, valueId, newValue, oldValue, getValueChange]: `+C+")"+ze,lt(11)),e(he+f+s,`(${o}, valueId: Id, invalidValues: any[])`+ze,lt(12))]},(t,l)=>e(De+s,`(${t}: ${l}, cellsTouched: boolean, valuesTouched: boolean)`+ze,re+" listening to the completion of a "+je)],Nt=(e,t=l,a=l)=>`store.${e}(${t})`+(a?" as "+a:l),Lt=(e,t=l)=>`fluent(() => ${Nt(e,t)})`,Mt=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(listener)${a?", "+a:l})`,Gt=(e,t,a)=>{const[o,I,v,T,x,R,P,k]=Ot(),[A,E,D]=Dt(e,t,x),[j,N,M]=jt(v,A,E,D),J=X(),z=(e=0)=>te(J,(([t,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${t}): ${a} => ${n},`]:[r+d+`(${t}): ${a};`];return e||O(s,Pt(o)),S(s,l),s})),W=(e,t,a,n,o,d=l)=>wt(J,e,[t,a,n,o,d]),B=(e,t,a,n,o,d=l,r=l,s=l)=>W(it[e]+t+(4==e?ve:l)+a,d,n,(n==_?Lt:Nt)(it[e]+(4==e?ve:l)+a,r,e?void 0:n),o,s),F=(e,t,a,n=l,o=l,d=1,r=l)=>W(c+e+s,(n?n+", ":l)+me+": "+t+(d?", mutator?: boolean":l),Ce,Mt(c+e+s,o,d?"mutator":l),a,r),U=`./${xt(a)}.d`,_=xt(a,1),H=xt(_),q=[],K=X();let ae=[],ne=[];if(I(1,U,_,`create${_} as create${_}Decl`),!Z(e)){I(0,"tinybase","CellChange"),I(null,"tinybase",i);const[e,t,a,o,s,c,f,w,y,T,R,P,k,O,D,N,M,J,z,W,Z]=j(H,_),ee=X();A(((e,t)=>{const l=`<'${e}'>`,a=[v(t+$,o+l,Re+` the '${e}' `+$),v(t+$+We,s+l,Re+` the '${e}' `+$+Be),v(t+b,c+l,Ke(e)),v(t+b+We,f+l,Ke(e,1)),v(t+g+Ce,w+l,`A Cell Id for the '${e}' `+$),v(t+g+Ie,T+l,tt(`a Cell Id and value from a Row in the '${e}' `+$)),v(t+b+Ie,R+l,tt(`a Row Id from the '${e}' Table, and a Cell iterator`))];le(ee,e,a),I(1,U,...a)})),I(1,U,e,t,a,w,P,k,O,D,N,M,J,z,W,Z),ae=[e,t,a,w,k,O,D,N,M,J,z,W,ee],V([[e],[n],[_,"tables: "+t,"tables"],[_]],(([e,t,a],n)=>B(n,l,u,e,qe(1,n),t,a))),B(0,l,p,a+Oe,Xe($,Ee)),B(5,l,$,Je,Ye($,Ee),"tableCallback: "+P,"tableCallback as any"),A(((e,t,a)=>{const[o,d,r,s,I,c,u]=Y(ee,e);V([[o],[n],[_,"table: "+d,", table"],[_]],(([n,o,d=l],r)=>B(r,t,$,n,dt(e,r),o,a+d))),B(0,t,C,i,Xe(b,nt(e)),l,a),B(0,t,h,i,Xe(b,nt(e),1),"cellId?: "+I+Ae,a+", cellId, descending, offset, limit"),B(5,t,b,Je,Ye(b,nt(e)),"rowCallback: "+u,a+", rowCallback as any"),V([[r],[n],[_,", row: "+s,", row"],[_],[_,", partialRow: "+s,", partialRow"]],(([n,o=l,d=l],r)=>B(r,t,b,n,rt(e,r),Pe+o,a+", rowId"+d))),B(6,t,b,Ce+we,"Add a new Row to "+nt(e),"row: "+s+", reuseIds?: boolean",a+", row, reuseIds"),B(0,t,m,I+Oe,Xe(g,ot(e)),Pe,a+", rowId"),B(5,t,g,Je,Ye(g,ot(e)),Pe+", cellCallback: "+c,a+", rowId, cellCallback as any"),E(e,((o,d,r,s,I)=>{const c="Map"+xt(d,1);le(K,d,c);const i=d+(L(r)?we:l);V([[i],[n],[_,`, cell: ${d} | `+c,", cell as any"],[_]],(([n,d=l,r=l],c)=>B(c,t+I,g,n,st(e,o,c),Pe+d,a+", rowId, "+s+r)))}))})),B(0,l,u+ge,ge,qe(1,6)),B(2,l,u+ge,_,qe(1,7),"tablesJson: "+ge,"tables"+ge),F(u,k,qe(1,8)+" changes"),F(p,O,at(2,0,1)),F($,D,at(3,0),`tableId: ${a} | null`,"tableId"),F(C,N,at(4,3,1),`tableId: ${a} | null`,"tableId"),F(h,M,at(13,3,1),kt("tableId: TId",`cellId: ${w}<TId>`+we,"descending: boolean","offset: number","limit: number"+we),kt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),F(b,J,at(5,3),`tableId: ${a} | null, rowId: IdOrNull`,"tableId, rowId"),F(m,z,at(6,5,1),`tableId: ${a} | null, rowId: IdOrNull`,"tableId, rowId"),F(g,W,at(7,5),`tableId: ${a} | null, rowId: IdOrNull, cellId: ${Tt(A((e=>{var t,a;return null!=(a=null==(t=Y(ee,e))?void 0:t[4])?a:l}))," | ")} | null`,"tableId, rowId, cellId"),F(he+g,Z,xe+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),I(1,U,...Q(K)),S(q,".set"+u+ke+"({",Vt(A(((e,t,a)=>[`[${a}]: {`,...E(e,((e,t,a,n)=>`[${n}]: {[${x(Rt(d),`'${d}'`)}]: ${x(Rt(t),`'${t}'`)}${L(a)?l:`, [${x(Rt(r),`'${r}'`)}]: `+(G(a)?x(Rt(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!Z(t)){const[e,t,a,o,s,c,i,$,u]=N(H,_);I(1,U,e,t,a,s,c,i,$,u),ne=[e,t,a,c,i,$],V([[e],[n],[_,"values: "+t,"values"],[_],[_,"partialValues: "+t,"partialValues"]],(([e,t,a],n)=>B(n,l,w,e,qe(2,n),t,a))),B(0,l,y,a+Oe,Xe(f,Ee)),B(5,l,f,"void",Ye(f,Ee),"valueCallback: "+s,"valueCallback as any"),D(((e,t,a,o,d)=>{const r="Map"+xt(t,1);le(K,t,r),V([[t],[n],[_,`value: ${t} | `+r,", value as any"],[_]],(([t,a,n=l],r)=>B(r,d,f,t,It(e,r),a,o+n)))})),B(0,l,w+ge,ge,qe(2,6)),B(2,l,w+ge,_,qe(2,7),"valuesJson: "+ge,"values"+ge),F(w,c,qe(2,8)+" changes"),F(y,i,at(10,0,1)),F(f,$,at(11,0),`valueId: ${a} | null`,"valueId"),F(he+f,u,xe+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),I(1,U,...Q(K)),I(0,"tinybase","ValueChange"),S(q,".set"+w+ke+"({",D(((e,t,a,n)=>[`[${n}]: {[${x(Rt(d),`'${d}'`)}]: ${x(Rt(t),`'${t}'`)}${L(a)?l:`, [${x(Rt(r),`'${r}'`)}]: `+(G(a)?x(Rt(a),`'${a}'`):a)}},`])),"})")}ee(K,((e,t)=>v(t,`(cell: ${e}${we}) => `+e,`Takes a ${e} Cell value and returns another`))),I(null,"tinybase","DoRollback",Ce,"IdOrNull",ge,"Store"),B(0,l,ge,ge,qe(0,6)),B(2,l,ge,_,qe(0,7),"tablesAndValuesJson: "+ge,"tablesAndValuesJson"),B(7,l,je,"Return",Ne,pe,"actions, doRollback","<Return>"),B(7,l,"start"+De,_,Le),B(7,l,"finish"+De,_,Me,ue,"doRollback");const oe=M(H,_);return F("WillFinish"+De,oe,xe+" just before "+Ge,l,l,0),F("DidFinish"+De,oe,xe+" just after "+Ge,l,l,0),B(7,l,"call"+s,_,"Manually provoke a listener to be called","listenerId: Id","listenerId"),B(3,l,s,_,"Remove a listener that was previously added to "+Ee,"listenerId: Id","listenerId"),W("getStore",l,"Store","store",ct[0]+" the underlying Store object"),I(1,"tinybase","createStore"),I(1,U,_,`create${_} as create${_}Decl`,oe),x("store",["createStore()",...q]),T("fluent","actions: () => Store",["actions();",`return ${H};`]),T("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${H}, ...params)`),x(H,["{",...z(1),"}"]),[o(...R(0),...P(),be+" interface "+_+" {",...z(0),"}",l,Pt(`Creates a ${_} object`),be+" function create"+_+"(): "+_+";"),o(...R(1),be+" const create"+_+": typeof create"+_+"Decl = () => {",...k(),`return Object.freeze(${H});`,"};"),ae,ne]},Jt=e=>I+e,zt=e=>kt(Jt(e),Jt(e)+ie),Wt="debugIds?: boolean",Bt="debugIds={debugIds}",Ft="then"+$e,Ut="Parameter",_t=": (parameter: "+Ut+", store: Store) => ",Zt="const contextValue = useContext(Context);",Ht=", based on a parameter",Qt=": ",qt="<"+Ut+",>",Kt=Ut+"ized"+Ie+"<"+Ut+">",Xt="rowId",Yt="rowId={rowId}",el=", separator, debugIds",tl="separator?: ReactElement | string",ll="then?: (store: Store",al=kt(ll+")"+ze,Ft),nl="then, then"+ie,ol=Xt+Qt+Ce,dl="View",rl=(e,...t)=>kt(...t,me+": "+e,me+$e,"mutator?: boolean"),sl=(...e)=>kt(...e,me,me+ie,"mutator"),Il=(e,t,a,n,o)=>{const[d,r,I,c,v,T,V,x]=Ot(),[R,P,k]=Dt(e,t,v),A=`./${xt(a)}.d`,E=`./${xt(a)}-ui-react.d`,D="tinybase/ui-react",j=xt(a,1),N=xt(j),M=j+"Or"+j+Ce,G=N+"Or"+j+Ce,J=N+`={${N}}`,z=X(),W=(e,t,a,n,o,d=l)=>(r(1,E,e+" as "+e+"Decl"),wt(z,e,[t,a,n,o,d])),B=(e,t,a,n,o,d=l)=>W("use"+e,t,a,n,o,d),F=(e,t,a,n,o=l,d=l,s=l,I=l,c=l)=>(r(1,D,`use${t} as use${t}Core`),B(e,kt(o,q,I),a,ee+`(${G}, use${t}Core, [`+(d||l)+(c?"], ["+c:l)+"]);",n,s)),U=(e,t,l,a)=>W(e,t,1,l,a),_=(e=0)=>te(z,(([t,a,n,o,d],r)=>{const s=e?[be+` const ${r}: typeof ${r}Decl = ${d}(${t}): ${1==a?"any":a} =>`,n]:[be+` function ${r}${d}(${t}): ${1==a?"ComponentReturnType":a};`];return e||O(s,Pt(o)),S(s,l),s}));r(null,"tinybase",Ce,"Store",Ie,Ut+"ized"+Ie),r(0,D,"ComponentReturnType"),r(null,D,"ExtraProps"),r(0,A,j);const H=I(M,j+" | "+Ce,`Used when you need to refer to a ${j} in a React hook or component`),Q=I(Ve+Te,At(N+fe+j,N+`ById?: {[${N}Id: Id]: ${j}}`),`Used with the ${Ve} component, so that a `+j+" can be passed into the context of an application");r(0,"react","ReactElement","ComponentType"),r(1,"react","React"),r(1,E,H,Q);const q=G+fe+H;v("{createContext, useContext, useMemo}","React"),v("Context",`createContext<[${j}?, {[${N}Id: Id]: ${j}}?]>([])`),B("Create"+j,`create: () => ${j}, create`+$e,j,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${j} within a React application with convenient memoization`);const K=B(j,"id?: Id",j+we,["{",Zt,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${j} from within a ${Ve} component context`),ee=c("useHook",G+`: ${H} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${N} = ${K}(${G} as Id);`,`return hook(...preParams, ((${G} == null || typeof ${G} == 'string')`,`? ${N} : ${G})?.getStore(), ...postParams)`]),le=c("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),ae=c("wrap",kt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),ne=v("NullComponent","() => null");if(!Z(e)){const[e,t,a,o,d,f,w,y,v,T,V,x,k]=n;r(null,A,e,t,a,d,f,w,y,v,T,V,x),r(0,A,o),r(1,A,j),r(null,"tinybase",i,"IdOrNull");const S=c("tableView",`{${N}, rowComponent, getRowComponentProps`+el+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${ae}(rowIds.map((rowId) => (`,"<Row","{..."+le+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",Yt,J,Bt,"/>","))",el,", tableId,",");"]),O=c("getDefaultTableComponent","tableId: Id",Tt(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+ne),D=c("getDefaultCellComponent","tableId: Id, cellId: Id",Tt(R(((e,t,l)=>`tableId == ${l} ? ${Tt(P(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+ne} : `)))+ne);F(u,u,e,qe(1,0)+se);const M=F(p,p,a+Oe,Xe($,Ee)+se);F(Se+u+Ie,Se+u+Ie,Kt,qe(1,9)+Ht,kt(Jt(u)+_t+t,Jt(u)+$e),zt(u),qt,kt(ll,`tables: ${t})`+ze,Ft),nl),F(ce+u+Ie,ce+u+Ie,Ie,qe(1,12),l,l,l,al,nl);const G=I(g+Te,At("tableId?: TId","rowId: Id","cellId?: CId",N+fe+j,Wt),et(de+g),`<TId extends ${a}, CId extends ${o}<TId>>`),z=I(b+Te,At("tableId?: TId","rowId: Id",N+fe+j,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${G}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,tl,Wt),et(de+b),`<TId extends ${a}>`),W=I($+Te,At("tableId?: TId",N+fe+j,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",tl,Wt),et(de+$),`<TId extends ${a}>`),B=I("Sorted"+$+Te,At("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",N+fe+j,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",tl,Wt),et(de+"sorted "+$),`<TId extends ${a}>`),_=I(u+Te,At(N+fe+j,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${W}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,tl,Wt),et(Qe(1,1)));r(1,E,_,W,B,z,G),U(u+dl,"{"+N+", tableComponents, getTableComponentProps"+el+"}: "+_,[ae+`(${M}(${N}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+O+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${le}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Bt,"/>;","}), separator)"],qe(1,13)+se),R(((e,t,a)=>{const[n,o,d,s,I]=Y(k,e);r(null,A,n,o,d,s,I),F(t+$,$,n,dt(e)+se,l,a);const c=F(t+C,C,i,Xe(b,nt(e))+se,l,a),u=F(t+h,h,i,Xe(b,nt(e),1)+se,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(t+b,b,d,rt(e)+se,ol,kt(a,Xt));const p=F(t+m,m,I+Oe,Xe(g,ot(e))+se,ol,kt(a,Xt));F(Se+t+$+Ie,Se+$+Ie,Kt,dt(e,9)+Ht,kt(Jt($)+_t+o,Jt($)+$e),kt(a,zt($)),qt,kt(ll,`table: ${o})`+ze,Ft),nl),F(ce+t+$+Ie,ce+$+Ie,Ie,dt(e,12),l,a,l,al,nl),F(Se+t+b+Ie,Se+b+Ie,Kt,rt(e,9)+Ht,kt(ol,Jt(b)+_t+s,Jt(b)+$e),kt(a,Xt,zt(b)),qt,kt(ll,`row: ${s})`+ze,Ft),nl),F("Add"+t+b+Ie,"Add"+b+Ie,Kt,rt(e,10)+Ht,kt(Jt(b)+_t+s,Jt(b)+$e),kt(a,zt(b)),qt,"then?: ("+kt(ol+we,"store: Store","row: "+s+")"+ze,"then"+$e)+", reuseRowIds?: boolean",nl+", reuseRowIds"),F(Se+t+ve+b+Ie,Se+ve+b+Ie,Kt,rt(e,11)+Ht,kt(ol,Jt(ve+b)+_t+s,Jt(ve+b)+$e),kt(a,Xt,zt(ve+b)),qt,kt(ll,`partialRow: ${s})`+ze,Ft),nl),F(ce+t+b+Ie,ce+b+Ie,Ie,rt(e,12),ol,kt(a,Xt),l,al,nl);const f=U(t+b+dl,"{rowId, "+N+", cellComponents, getCellComponentProps"+el+`}: ${z}<'${e}'>`,[ae+`(${p}(rowId, ${N}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+D+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${le}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,Yt,"cellId={cellId}",J,Bt,"/>;","})"+el+", rowId)"],rt(e,13)+se);U(t+"Sorted"+$+dl,"{cellId, descending, offset, limit, ...props}: "+B+`<'${e}'>`,S+"(props, "+u+`(cellId, descending, offset, limit, props.${N}), ${a}, ${f});`,dt(e,13)+", sorted"+se),U(t+$+dl,`props: ${W}<'${e}'>`,S+"(props, "+c+`(props.${N}), ${a}, ${f});`,dt(e,13)+se),P(e,((n,o,d,s,I)=>{const c="Map"+xt(o,1);r(0,A,c),r(1,A,c);const i=F(t+I+g,g,o+(L(d)?we:l),st(e,n)+se,ol,kt(a,Xt,s));F(Se+t+I+g+Ie,Se+g+Ie,Kt,st(e,n,9)+Ht,kt(ol,Jt(g)+_t+o+" | "+c,Jt(g)+$e),kt(a,Xt,s,zt(g)),qt,kt(ll,`cell: ${o} | ${c})`+ze,Ft),nl),F(ce+t+I+g+Ie,ce+g+Ie,Ie,st(e,n,12),kt(ol,"forceDel?: boolean"),kt(a,Xt,s,"forceDel"),l,al,nl),U(t+I+g+dl,`{rowId, ${N}, debugIds}: `+G+`<'${e}', '${n}'>`,[ae+`('' + ${i}(rowId, `+N+`) ?? '', undefined, debugIds, ${s})`],st(e,n,13)+se)}))}));const Z=Tt(R((e=>{var t,a;return null!=(a=null==(t=Y(k,e))?void 0:t[4])?a:l}))," | ");F(u+s,u+s,Je,qe(1,8)+" changes",rl(d),sl()),F(p+s,p+s,Je,at(2,0,1),rl(f),sl()),F($+s,$+s,Je,at(3,0),rl(w,`tableId: ${a} | null`),sl("tableId")),F(C+s,C+s,Je,at(4,3,1),rl(y,`tableId: ${a} | null`),sl("tableId")),F(h+s,h+s,Je,at(13,3,1),rl(v,`tableId: ${a} | null`,"cellId: "+Z+we,"descending: boolean","offset: number","limit: number"+we),sl("tableId","cellId","descending","offset","limit")),F(b+s,b+s,Je,at(5,3),rl(T,`tableId: ${a} | null`,Xt+": IdOrNull"),sl("tableId",Xt)),F(m+s,m+s,Je,at(6,5,1),rl(V,`tableId: ${a} | null`,Xt+": IdOrNull"),sl("tableId",Xt)),F(g+s,g+s,Je,at(7,5),rl(x,`tableId: ${a} | null`,Xt+": IdOrNull",`cellId: ${Z} | null`),sl("tableId",Xt,"cellId"))}if(!Z(t)){const[e,t,a,n,d,i]=o;r(null,A,...o),r(1,A,j);const $=c("getDefaultValueComponent","valueId: Id",Tt(k(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+ne);F(w,w,e,qe(2,0)+se);const u=F(y,y,a+Oe,Xe(f,Ee)+se);F(Se+w+Ie,Se+w+Ie,Kt,qe(2,9)+Ht,kt(Jt(w)+_t+t,Jt(w)+$e),zt(w),qt,kt(ll,`values: ${t})`+ze,Ft),nl),F(Se+ve+w+Ie,Se+ve+w+Ie,Kt,qe(2,11)+Ht,kt(Jt(ve+w)+_t+t,Jt(ve+w)+$e),zt(ve+w),qt,kt(ll,`partialValues: ${t})`+ze,Ft),nl),F(ce+w+Ie,ce+w+Ie,Ie,qe(2,12),l,l,l,al,nl);const p=I(f+Te,At("valueId?: VId",N+fe+j,Wt),et("a Value"),`<VId extends ${a}>`),b=I(w+Te,At(N+fe+j,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${p}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,tl,Wt),et(Qe(2,1)));r(1,E,b,p),U(w+dl,"{"+N+", valueComponents, getValueComponentProps"+el+"}: "+b,[ae+`(${u}(${N}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+$+"(valueId);","return <Value",`{...${le}(getValueComponentProps, valueId)}`,"key={valueId}",J,Bt,"/>;","}), separator)"],qe(2,13)+se),k(((e,t,a,n,o)=>{const d="Map"+xt(t,1);r(0,A,d),r(1,A,d);const s=F(o+f,f,t,It(e)+se,l,n);F(Se+o+f+Ie,Se+f+Ie,Kt,It(e,9)+Ht,kt(Jt(f)+_t+t+" | "+d,Jt(f)+$e),kt(n,zt(f)),qt,kt(ll,`value: ${t} | ${d})`+ze,Ft),nl),F(ce+o+f+Ie,ce+f+Ie,Ie,It(e,12),l,n,l,al,nl),U(o+f+dl,`{${N}, debugIds}: ${p}<'${e}'>`,[ae+`('' + ${s}(`+N+`) ?? '', undefined, debugIds, ${n})`],It(e,13)+se)})),F(w+s,w+s,Je,qe(2,8)+" changes",rl(n),sl()),F(y+s,y+s,Je,at(10,0,1),rl(d),sl()),F(f+s,f+s,Je,at(11,0),rl(i,`valueId: ${a} | null`),sl("valueId"))}return U(Ve,`{${N}, ${N}ById, children}: `+Q+" & {children: React.ReactNode}",["{",Zt,"return (","<Context."+Ve,"value={useMemo(",`() => [${N} ?? contextValue[0], {...contextValue[1], ...${N}ById}],`,`[${N}, ${N}ById, contextValue],`,")}>","{children}",`</Context.${Ve}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...T(0),...V(),..._(0)),d(...T(1),...x(),..._(1))]},cl=(e,t,a)=>{if(Z(e)&&Z(t))return[l,l,l,l];const[n,o,d,r]=Gt(e,t,a);return[n,o,...Il(e,t,a,d,r)]};var il=Object.defineProperty,$l=Object.defineProperties,ul=Object.getOwnPropertyDescriptors,pl=Object.getOwnPropertySymbols,bl=Object.prototype.hasOwnProperty,Cl=Object.prototype.propertyIsEnumerable,hl=(e,t,l)=>t in e?il(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,gl=(e,t)=>{for(var l in t||(t={}))bl.call(t,l)&&hl(e,l,t[l]);if(pl)for(var l of pl(t))Cl.call(t,l)&&hl(e,l,t[l]);return e},ml=(e,t)=>$l(e,ul(t)),fl=(e,t,l)=>new Promise(((a,n)=>{var o=e=>{try{r(l.next(e))}catch(e){n(e)}},d=e=>{try{r(l.throw(e))}catch(e){n(e)}},r=e=>e.done?a(e.value):Promise.resolve(e.value).then(o,d);r((l=l.apply(e,t)).next())}));const wl={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},yl=Et((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!Z(t)||v(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=X();if(v(a,(t=>v(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=ae(n,a,(()=>[z(o),X(),[0],0])),[r,s,[I]]=d,c=ae(s,o,(()=>0))+1;return c>I&&(d[2]=[c,o]),le(s,o,c),d[3]++,r==z(o)})))))return t[l]={},q(n,(([e,,[,n],o],s)=>{t[l][s]=gl({[d]:e},o==R(a)?{[r]:n}:{})})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return Z(t)&&e.forEachValue(((e,l)=>{t[e]={[d]:z(l)}})),t},a=e=>cl(t(),l(),e),n=e=>fl(void 0,null,(function*(){const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return x(a(e),((e,a)=>yt(l(e,ml(gl({},wl),{filepath:"_."+t[a]})))))}));return F({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),gl({totalTables:l,totalRows:a,totalCells:n,totalValues:R(e.getValueIds()),jsonLength:vt(e.getJson())},t?{detail:{tables:o}}:{})},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));e.createTools=yl},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,l="",a=t(l),n=t(!0),o=t(0),d="type",r="default",s="Listener",I="get",c="add",i="Ids",$="Table",u=$+"s",p=$+i,b="Row",C=b+i,h="Sorted"+b+i,g="Cell",f=g+i,m="Value",w=m+"s",y=m+i,v=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),V=(e,t)=>e.forEach(t),x=(e,t)=>e.map(t),R=e=>e.length,P=e=>0==R(e),S=(e,t)=>e.filter(t),k=(e,...t)=>e.push(...t),A=e=>e.pop(),O=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,j=isFinite,N=(e,t)=>e instanceof t,L=e=>null==e,G=e=>e==a||e==n,M=e=>t(e)==a,J=e=>Array.isArray(e),z=e=>{const l=t(e);return G(l)||l==o&&j(e)?l:void 0},W=Object,B=W.keys,F=W.freeze,U=e=>N(e,W)&&e.constructor==W,_=(e,t)=>x(W.entries(e),(([e,l])=>t(l,e))),Z=e=>U(e)&&P(B(e)),H=(e,t)=>{var l;return null!=(l=null==e?void 0:e.has(t))&&l},Q=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},q=(e,t)=>null==e?void 0:e.forEach(t),K=(e,t)=>null==e?void 0:e.delete(t),X=e=>new Map(e),Y=(e,t)=>null==e?void 0:e.get(t),ee=(e,t)=>q(e,((e,l)=>t(l,e))),te=(e,t)=>{var l;return x([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>t(l,e)))},le=(e,t,l)=>L(l)?(K(e,t),e):null==e?void 0:e.set(t,l),ae=(e,t,l)=>(H(e,t)||le(e,t,l()),Y(e,t)),ne=e=>e.toUpperCase(),oe=e=>e.toLowerCase(),de="a ",re="A function for",se=", and registers a listener so that any changes to that result will cause a re-render",Ie="Callback",ce="Del",ie="Deps",$e=ie+"?: React.DependencyList",ue="doRollback?: DoRollback",pe="actions: () => Return, "+ue,be="export",Ce="Id",he="Invalid",ge="Json",fe=oe(s),me="?: ",we=" | undefined",ye="NonNullable",ve="Partial",Te="Props",Ve="Provider",xe=`Registers a ${fe} that will be called`,Re="Represents",Pe="rowId: "+Ce,Se="Schema",ke="Set",Ae=", descending?: boolean, offset?: number, limit?: number",Oe="[]",Ee="the Store",De="Transaction",je=De+"Changes",Ne=oe(De),Le="Execute a "+Ne+" to make multiple mutations",Ge="Explicitly starts a "+Ne,Me="Explicitly finishes a "+Ne,Je="the end of the "+Ne,ze="void",We=" => "+ze,Be="WhenSet",Fe=" when setting it",Ue=de+"string serialization of",_e=" ",Ze="Gets a callback that can ",He="the ",Qe=" the schema for",qe=(e=0,t=0)=>`the ${pt[e]}content of`+(t?_e+Ee:l),Ke=(e=0,t,a=0)=>it[t]+_e+qe(e,1)+(a?" when setting it":l),Xe=(e,t=0)=>Re+` a Row when ${t?"s":"g"}etting ${qe()} the '${e}' `+$,Ye=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,et=(e,t)=>`Calls a function for each ${e} in `+t,tt=e=>"The props passed to a component that renders "+e,lt=e=>"A function that takes "+e,at=(e,t=0)=>re+" listening to changes to "+ut[e]+" in "+ut[t],nt=(e,t,a=0)=>xe+" whenever "+ut[e]+" in "+ut[t]+" change"+(a?l:"s"),ot=e=>`the '${e}' `+$,dt=e=>"the specified Row in "+ot(e),rt=(e,t=0)=>it[t]+` ${qe()} `+ot(e),st=(e,t=0)=>it[t]+` ${qe()} `+dt(e),It=(e,t,l=0)=>it[l]+` the '${t}' Cell for `+dt(e),ct=(e,t=0)=>it[t]+` the '${e}' Value`,it=["Gets","Checks existence of","Sets","Deletes","Sets part of",Re,"Gets "+Ue,"Sets "+Ue,xe+" whenever",Ze+"set",Ze+"add",Ze+"set part of",Ze+"delete","Renders","Gets "+Ue+Qe,"Sets"+Qe,"Deletes"+Qe],$t=[I,"has","set","del","set","forEach",c,l],ut=[Ee,u,He+$+_e+i,de+$,He+b+_e+i,de+b,He+g+_e+i,de+g,"invalid Cell changes",w,He+m+_e+i,de+m,"invalid Value changes",He+"sorted "+b+_e+i],pt=[l,"tabular ","keyed value "],bt=e=>new Set(J(e)||L(e)?e:[e]),Ct=(e,t)=>null==e?void 0:e.add(t),ht=/[^A-Za-z]+/,gt=/[^A-Za-z0-9]+/,ft=/^( *)\/\*\* *(.*?) *\*\/$/gm,mt=(e,t,l)=>e.substring(t,l),wt=e=>e.includes(","),yt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return H(e,n)?yt(e,t,l,a+1):(le(e,n,l),n)},vt=e=>e.replace(ft,((e,t,l)=>{const a=77-Tt(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Tt=e=>e.length,Vt=(e,t=l)=>e.join(t),xt=e=>e.flat(1e3),Rt=(e,t=0)=>Vt(x(e.split(gt),((e,l)=>(l>0||t?ne:oe)(mt(e,0,1))+mt(e,1)))),Pt=e=>ne(Vt((e&&!ht.test(e[0])?e:" "+e).split(gt),"_")),St=e=>`/** ${e}. */`,kt=(...e)=>Vt(S(e,(e=>e)),", "),At=(...e)=>"{"+Vt(e,"; ")+"}",Ot=(...e)=>At(...x(e,(e=>"readonly "+e))),Et=()=>{const e=[X(),X(),X(),X()],t=X(),a=X();return[(...e)=>Vt(xt(e),"\n"),(t,l,...a)=>V(a,(a=>V([0,1],(n=>(null!=t?t:n)==n?Ct(ae(e[n],l,bt),a):0)))),(e,a,n,o=l,d=1)=>yt(t,e,[a,n,o,d]),(e,t,l)=>yt(a,e,J(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>Y(a,e)===t?e:yt(a,e,t),(t=0)=>x([...T(te(e[t],((e,t)=>`import {${Vt(T(Q(e)),", ")}} from '${t}';`)),((e,t)=>wt(e)!=wt(t)?wt(e)?-1:1:e>t?1:-1)),l],(e=>e.replace("{React}","React"))),()=>te(t,(([e,t,a,n],o)=>[St(t),`${n?be+" ":l}type ${o}${a} = ${e};`,l])),()=>te(a,((e,t)=>(e=J(e)?e:[e],k(e,A(e)+";"),[`const ${t} = ${E(e)}`,e,l])))]},Dt=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},jt=(e,t,l)=>[t=>_(e,((e,a)=>t(a,Rt(a,1),l(Pt(a),`'${a}'`)))),(t,a)=>_(e[t],((e,t)=>a(t,e[d],e[r],l(Pt(t),`'${t}'`),Rt(t,1)))),e=>_(t,((t,a)=>e(a,t[d],t[r],l(Pt(a),`'${a}'`),Rt(a,1))))],Nt=(e,t,a,n)=>[(n,o)=>{const d=n+": "+o,r=e(u,At(...t((e=>`'${e}'?: {[rowId: Id]: `+At(...a(e,((e,t,a)=>`'${e}'${L(a)?"?":l}: ${t}`)))+"}"))),Ke(1,5)),I=e(u+Be,At(...t((e=>`'${e}'?: {[rowId: Id]: `+At(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Ke(1,5,1)),c=e($+Ce,"keyof "+r,"A "+$+" Id in "+Ee),i=`<TId extends ${c}>`,m=e($,ye+`<${r}[TId]>`,"A "+$+" in "+Ee,i),w=e($+Be,ye+`<${I}[TId]>`,"A "+$+" in "+Ee+Fe,i),y=e(b,m+"<TId>[Id]","A "+b+" in a "+$,i),v=e(b+Be,w+"<TId>[Id]","A "+b+" in a "+$+Fe,i),T=e(g+Ce,`Extract<keyof ${y}<TId>, Id>`,"A "+g+" Id in a "+b,i),V=e(g,ye+`<${r}[TId]>[Id][CId]`,"A "+g+" in a "+b,`<TId extends ${c}, CId extends ${T}<TId>>`),x=e("CellIdCellArray",`CId extends ${T}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,g+" Ids and types in a "+b,`<TId extends ${c}, CId = ${T}<TId>>`,0),R=e(g+Ie,`(...[cellId, cell]: ${x}<TId>)`+We,lt(de+g+" Id, and "+g),i),P=e(b+Ie,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+We+") "+We,lt(de+b+" Id, and a "+g+" iterator"),i),S=e("TableIdForEachRowArray",`TId extends ${c} ? [tableId: TId, forEachRow: (rowCallback: ${P}<TId>)${We}] : never`,$+" Ids and callback types",`<TId = ${c}>`,0),k=e($+Ie,`(...[tableId, forEachRow]: ${S})`+We,lt(de+$+" Id, and a "+b+" iterator"),l),A=e("TableIdRowIdCellIdArray",`TId extends ${c} ? [tableId: TId, rowId: Id, cellId: ${T}<TId>] : never`,"Ids for GetCellChange",`<TId = ${c}>`,0),O=e("GetCellChange",`(...[tableId, rowId, cellId]: ${A}) => CellChange`,re+" returning information about any Cell's changes during a "+Ne),E=e(u+s,`(${d}, getCellChange: ${O}${we})`+We,at(1)),D=e(p+s,`(${d})`+We,at(2)),j=e($+s,`(${d}, tableId: ${c}, getCellChange: ${O}${we})`+We,at(3)),N=e(C+s,`(${d}, tableId: ${c})`+We,at(4,3)),G=e(h+s,"("+kt(d,"tableId: "+c,"cellId: Id"+we,"descending: boolean","offset: number","limit: number"+we,"sortedRowIds: Ids")+")"+We,at(13,3)),M=e(b+s,"("+kt(""+d,"tableId: "+c,Pe,`getCellChange: ${O}${we}`)+")"+We,at(5,3)),J=e(f+s,"("+kt(""+d,"tableId: "+c,Pe)+")"+We,at(6,5)),z=e("CellListenerArgsArrayInner",`CId extends ${T}<TId> ? [${d}, tableId: TId, ${Pe}, cellId: CId, newCell: ${V}<TId, CId> ${we}, oldCell: ${V}<TId, CId> ${we}, getCellChange: ${O} ${we}] : never`,"Cell args for CellListener",`<TId extends ${c}, CId = ${T}<TId>>`,0),W=e("CellListenerArgsArrayOuter",`TId extends ${c} ? `+z+"<TId> : never","Table args for CellListener",`<TId = ${c}>`,0);return[r,I,c,m,w,y,v,T,V,R,P,k,E,D,j,N,G,M,J,e(g+s,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${W})`+We,at(7,5)),e(he+g+s,`(${d}, tableId: Id, ${Pe}, cellId: Id, invalidCells: any[])`+We,at(8))]},(t,a)=>{const o=t+": "+a,d=e(w,At(...n(((e,t,a)=>`'${e}'${L(a)?"?":l}: ${t}`))),Ke(2,5)),r=e(w+Be,At(...n(((e,t)=>`'${e}'?: ${t}`))),Ke(2,5,1)),I=e(m+Ce,"keyof "+d,"A "+m+" Id in "+Ee),c=e(m,ye+`<${d}[VId]>`,"A "+m+" Id in "+Ee,`<VId extends ${I}>`),i=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${c}<VId>] : never`,m+" Ids and types in "+Ee,`<VId = ${I}>`,0),$=e(m+Ie,`(...[valueId, value]: ${i})`+We,lt(de+m+" Id, and "+m)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,re+" returning information about any Value's changes during a "+Ne),p=e(w+s,`(${o}, getValueChange: ${u}${we})`+We,at(9)),b=e(y+s,`(${o})`+We,at(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${c}<VId> ${we}, oldValue: ${c}<VId> ${we}, getValueChange: ${u} ${we}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,r,I,c,$,p,b,e(m+s,`(...[${t}, valueId, newValue, oldValue, getValueChange]: `+C+")"+We,at(11)),e(he+m+s,`(${o}, valueId: Id, invalidValues: any[])`+We,at(12))]},(t,l)=>e(De+s,`(${t}: ${l}, getTransactionChanges: GetTransactionChanges, getTransactionLog: GetTransactionLog)`+We,re+" listening to the completion of a "+Ne)],Lt=(e,t=l,a=l)=>`store.${e}(${t})`+(a?" as "+a:l),Gt=(e,t=l)=>`fluent(() => ${Lt(e,t)})`,Mt=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(listener)${a?", "+a:l})`,Jt=(e,t,a)=>{const[o,I,v,T,x,R,P,S]=Et(),[A,E,D]=jt(e,t,x),[j,N,G]=Nt(v,A,E,D),J=X(),z=(e=0)=>te(J,(([t,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${t}): ${a} => ${n},`]:[r+d+`(${t}): ${a};`];return e||O(s,St(o)),k(s,l),s})),W=(e,t,a,n,o,d=l)=>yt(J,e,[t,a,n,o,d]),B=(e,t,a,n,o,d=l,r=l,s=l)=>W($t[e]+t+(4==e?ve:l)+a,d,n,(n==_?Gt:Lt)($t[e]+(4==e?ve:l)+a,r,e?void 0:n),o,s),F=(e,t,a,n=l,o=l,d=1,r=l)=>W(c+e+s,(n?n+", ":l)+fe+": "+t+(d?", mutator?: boolean":l),Ce,Mt(c+e+s,o,d?"mutator":l),a,r),U=`./${Rt(a)}.d`,_=Rt(a,1),H=Rt(_),q=[],K=X();let ae=[],ne=[];if(I(1,U,_,`create${_} as create${_}Decl`),Z(e))I(null,"tinybase",u);else{I(0,"tinybase","CellChange"),I(null,"tinybase",i);const[e,t,a,o,s,c,m,w,y,T,R,P,S,O,D,N,G,J,z,W,Z]=j(H,_),ee=X();A(((e,t)=>{const l=`<'${e}'>`,a=[v(t+$,o+l,Re+` the '${e}' `+$),v(t+$+Be,s+l,Re+` the '${e}' `+$+Fe),v(t+b,c+l,Xe(e)),v(t+b+Be,m+l,Xe(e,1)),v(t+g+Ce,w+l,`A Cell Id for the '${e}' `+$),v(t+g+Ie,T+l,lt(`a Cell Id and value from a Row in the '${e}' `+$)),v(t+b+Ie,R+l,lt(`a Row Id from the '${e}' Table, and a Cell iterator`))];le(ee,e,a),I(1,U,...a)})),I(1,U,e,t,a,w,P,S,O,D,N,G,J,z,W,Z),ae=[e,t,a,w,S,O,D,N,G,J,z,W,ee],V([[e],[n],[_,"tables: "+t,"tables"],[_]],(([e,t,a],n)=>B(n,l,u,e,Ke(1,n),t,a))),B(0,l,p,a+Oe,Ye($,Ee)),B(5,l,$,ze,et($,Ee),"tableCallback: "+P,"tableCallback as any"),A(((e,t,a)=>{const[o,d,r,s,I,c,u]=Y(ee,e);V([[o],[n],[_,"table: "+d,", table"],[_]],(([n,o,d=l],r)=>B(r,t,$,n,rt(e,r),o,a+d))),B(0,t,C,i,Ye(b,ot(e)),l,a),B(0,t,h,i,Ye(b,ot(e),1),"cellId?: "+I+Ae,a+", cellId, descending, offset, limit"),B(5,t,b,ze,et(b,ot(e)),"rowCallback: "+u,a+", rowCallback as any"),V([[r],[n],[_,", row: "+s,", row"],[_],[_,", partialRow: "+s,", partialRow"]],(([n,o=l,d=l],r)=>B(r,t,b,n,st(e,r),Pe+o,a+", rowId"+d))),B(6,t,b,Ce+we,"Add a new Row to "+ot(e),"row: "+s+", reuseIds?: boolean",a+", row, reuseIds"),B(0,t,f,I+Oe,Ye(g,dt(e)),Pe,a+", rowId"),B(5,t,g,ze,et(g,dt(e)),Pe+", cellCallback: "+c,a+", rowId, cellCallback as any"),E(e,((o,d,r,s,I)=>{const c="Map"+Rt(d,1);le(K,d,c);const i=d+(L(r)?we:l);V([[i],[n],[_,`, cell: ${d} | `+c,", cell as any"],[_]],(([n,d=l,r=l],c)=>B(c,t+I,g,n,It(e,o,c),Pe+d,a+", rowId, "+s+r)))}))})),B(0,l,u+ge,ge,Ke(1,6)),B(2,l,u+ge,_,Ke(1,7),"tablesJson: "+ge,"tables"+ge),F(u,S,Ke(1,8)+" changes"),F(p,O,nt(2,0,1)),F($,D,nt(3,0),`tableId: ${a} | null`,"tableId"),F(C,N,nt(4,3,1),`tableId: ${a} | null`,"tableId"),F(h,G,nt(13,3,1),kt("tableId: TId",`cellId: ${w}<TId>`+we,"descending: boolean","offset: number","limit: number"+we),kt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),F(b,J,nt(5,3),`tableId: ${a} | null, rowId: IdOrNull`,"tableId, rowId"),F(f,z,nt(6,5,1),`tableId: ${a} | null, rowId: IdOrNull`,"tableId, rowId"),F(g,W,nt(7,5),`tableId: ${a} | null, rowId: IdOrNull, cellId: ${Vt(A((e=>{var t,a;return null!=(a=null==(t=Y(ee,e))?void 0:t[4])?a:l}))," | ")} | null`,"tableId, rowId, cellId"),F(he+g,Z,xe+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),I(1,U,...Q(K)),k(q,".set"+u+Se+"({",xt(A(((e,t,a)=>[`[${a}]: {`,...E(e,((e,t,a,n)=>`[${n}]: {[${x(Pt(d),`'${d}'`)}]: ${x(Pt(t),`'${t}'`)}${L(a)?l:`, [${x(Pt(r),`'${r}'`)}]: `+(M(a)?x(Pt(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(Z(t))I(null,"tinybase",w);else{const[e,t,a,o,s,c,i,$,u]=N(H,_);I(1,U,e,t,a,s,c,i,$,u),ne=[e,t,a,c,i,$],V([[e],[n],[_,"values: "+t,"values"],[_],[_,"partialValues: "+t,"partialValues"]],(([e,t,a],n)=>B(n,l,w,e,Ke(2,n),t,a))),B(0,l,y,a+Oe,Ye(m,Ee)),B(5,l,m,"void",et(m,Ee),"valueCallback: "+s,"valueCallback as any"),D(((e,t,a,o,d)=>{const r="Map"+Rt(t,1);le(K,t,r),V([[t],[n],[_,`value: ${t} | `+r,", value as any"],[_]],(([t,a,n=l],r)=>B(r,d,m,t,ct(e,r),a,o+n)))})),B(0,l,w+ge,ge,Ke(2,6)),B(2,l,w+ge,_,Ke(2,7),"valuesJson: "+ge,"values"+ge),F(w,c,Ke(2,8)+" changes"),F(y,i,nt(10,0,1)),F(m,$,nt(11,0),`valueId: ${a} | null`,"valueId"),F(he+m,u,xe+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),I(1,U,...Q(K)),I(0,"tinybase","ValueChange"),k(q,".set"+w+Se+"({",D(((e,t,a,n)=>[`[${n}]: {[${x(Pt(d),`'${d}'`)}]: ${x(Pt(t),`'${t}'`)}${L(a)?l:`, [${x(Pt(r),`'${r}'`)}]: `+(M(a)?x(Pt(a),`'${a}'`):a)}},`])),"})")}B(0,l,"Content",`[${u}, ${w}]`,Ke(0,0)),B(2,l,"Content",_,Ke(0,2),`[tables, values]: [${u}, ${w}]`,"[tables, values]"),B(2,l,je,_,`Applies a set of ${je} to the Store`,"transactionChanges: "+je,"transactionChanges"),ee(K,((e,t)=>v(t,`(cell: ${e}${we}) => `+e,`Takes a ${e} Cell value and returns another`))),I(null,"tinybase","DoRollback",Ce,"IdOrNull",ge,"Store",je),I(0,"tinybase","Get"+je,"GetTransactionLog"),B(0,l,ge,ge,Ke(0,6)),B(2,l,ge,_,Ke(0,7),"tablesAndValuesJson: "+ge,"tablesAndValuesJson"),B(7,l,Ne,"Return",Le,pe,"actions, doRollback","<Return>"),B(7,l,"start"+De,_,Ge),B(7,l,"finish"+De,_,Me,ue,"doRollback");const oe=G(H,_);return F("Start"+De,oe,xe+" just before the start of the "+Ne,l,l,0),F("WillFinish"+De,oe,xe+" just before "+Je,l,l,0),F("DidFinish"+De,oe,xe+" just after "+Je,l,l,0),B(7,l,"call"+s,_,"Manually provoke a listener to be called","listenerId: Id","listenerId"),B(3,l,s,_,"Remove a listener that was previously added to "+Ee,"listenerId: Id","listenerId"),W("getStore",l,"Store","store",it[0]+" the underlying Store object"),I(1,"tinybase","createStore"),I(1,U,_,`create${_} as create${_}Decl`,oe),x("store",["createStore()",...q]),T("fluent","actions: () => Store",["actions();",`return ${H};`]),T("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${H}, ...params)`),x(H,["{",...z(1),"}"]),[o(...R(0),...P(),be+" interface "+_+" {",...z(0),"}",l,St(`Creates a ${_} object`),be+" function create"+_+"(): "+_+";"),o(...R(1),be+" const create"+_+": typeof create"+_+"Decl = () => {",...S(),`return Object.freeze(${H});`,"};"),ae,ne]},zt=e=>I+e,Wt=e=>kt(zt(e),zt(e)+ie),Bt="debugIds?: boolean",Ft="debugIds={debugIds}",Ut="then"+$e,_t="Parameter",Zt=": (parameter: "+_t+", store: Store) => ",Ht="const contextValue = useContext(Context);",Qt=", based on a parameter",qt=": ",Kt="<"+_t+",>",Xt=_t+"ized"+Ie+"<"+_t+">",Yt="rowId",el="rowId={rowId}",tl=", separator, debugIds",ll="separator?: ReactElement | string",al="then?: (store: Store",nl=kt(al+")"+We,Ut),ol="then, then"+ie,dl=Yt+qt+Ce,rl="View",sl=(e,...t)=>kt(...t,fe+": "+e,fe+$e,"mutator?: boolean"),Il=(...e)=>kt(...e,fe,fe+ie,"mutator"),cl=(e,t,a,n,o)=>{const[d,r,I,c,v,T,V,x]=Et(),[R,P,S]=jt(e,t,v),A=`./${Rt(a)}.d`,E=`./${Rt(a)}-ui-react.d`,D="tinybase/ui-react",j=Rt(a,1),N=Rt(j),G=j+"Or"+j+Ce,M=N+"Or"+j+Ce,J=N+`={${N}}`,z=X(),W=(e,t,a,n,o,d=l)=>(r(1,E,e+" as "+e+"Decl"),yt(z,e,[t,a,n,o,d])),B=(e,t,a,n,o,d=l)=>W("use"+e,t,a,n,o,d),F=(e,t,a,n,o=l,d=l,s=l,I=l,c=l)=>(r(1,D,`use${t} as use${t}Core`),B(e,kt(o,q,I),a,ee+`(${M}, use${t}Core, [`+(d||l)+(c?"], ["+c:l)+"]);",n,s)),U=(e,t,l,a)=>W(e,t,1,l,a),_=(e=0)=>te(z,(([t,a,n,o,d],r)=>{const s=e?[be+` const ${r}: typeof ${r}Decl = ${d}(${t}): ${1==a?"any":a} =>`,n]:[be+` function ${r}${d}(${t}): ${1==a?"ComponentReturnType":a};`];return e||O(s,St(o)),k(s,l),s}));r(null,"tinybase",Ce,"Store",Ie,_t+"ized"+Ie),r(0,D,"ComponentReturnType"),r(null,D,"ExtraProps"),r(0,A,j);const H=I(G,j+" | "+Ce,`Used when you need to refer to a ${j} in a React hook or component`),Q=I(Ve+Te,Ot(N+me+j,N+`ById?: {[${N}Id: Id]: ${j}}`),`Used with the ${Ve} component, so that a `+j+" can be passed into the context of an application");r(0,"react","ReactElement","ComponentType"),r(1,"react","React"),r(1,E,H,Q);const q=M+me+H;v("{createContext, useContext, useMemo}","React"),v("Context",`createContext<[${j}?, {[${N}Id: Id]: ${j}}?]>([])`),B("Create"+j,`create: () => ${j}, create`+$e,j,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${j} within a React application with convenient memoization`);const K=B(j,"id?: Id",j+we,["{",Ht,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${j} from within a ${Ve} component context`),ee=c("useHook",M+`: ${H} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${N} = ${K}(${M} as Id);`,`return hook(...preParams, ((${M} == null || typeof ${M} == 'string')`,`? ${N} : ${M})?.getStore(), ...postParams)`]),le=c("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),ae=c("wrap",kt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),ne=v("NullComponent","() => null");if(!Z(e)){const[e,t,a,o,d,m,w,y,v,T,V,x,S]=n;r(null,A,e,t,a,d,m,w,y,v,T,V,x),r(0,A,o),r(1,A,j),r(null,"tinybase",i,"IdOrNull");const k=c("tableView",`{${N}, rowComponent, getRowComponentProps`+tl+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${ae}(rowIds.map((rowId) => (`,"<Row","{..."+le+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",el,J,Ft,"/>","))",tl,", tableId,",");"]),O=c("getDefaultTableComponent","tableId: Id",Vt(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+ne),D=c("getDefaultCellComponent","tableId: Id, cellId: Id",Vt(R(((e,t,l)=>`tableId == ${l} ? ${Vt(P(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+ne} : `)))+ne);F(u,u,e,Ke(1,0)+se);const G=F(p,p,a+Oe,Ye($,Ee)+se);F(ke+u+Ie,ke+u+Ie,Xt,Ke(1,9)+Qt,kt(zt(u)+Zt+t,zt(u)+$e),Wt(u),Kt,kt(al,`tables: ${t})`+We,Ut),ol),F(ce+u+Ie,ce+u+Ie,Ie,Ke(1,12),l,l,l,nl,ol);const M=I(g+Te,Ot("tableId?: TId","rowId: Id","cellId?: CId",N+me+j,Bt),tt(de+g),`<TId extends ${a}, CId extends ${o}<TId>>`),z=I(b+Te,Ot("tableId?: TId","rowId: Id",N+me+j,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${M}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,ll,Bt),tt(de+b),`<TId extends ${a}>`),W=I($+Te,Ot("tableId?: TId",N+me+j,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",ll,Bt),tt(de+$),`<TId extends ${a}>`),B=I("Sorted"+$+Te,Ot("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",N+me+j,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",ll,Bt),tt(de+"sorted "+$),`<TId extends ${a}>`),_=I(u+Te,Ot(N+me+j,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${W}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,ll,Bt),tt(qe(1,1)));r(1,E,_,W,B,z,M),U(u+rl,"{"+N+", tableComponents, getTableComponentProps"+tl+"}: "+_,[ae+`(${G}(${N}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+O+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${le}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Ft,"/>;","}), separator)"],Ke(1,13)+se),R(((e,t,a)=>{const[n,o,d,s,I]=Y(S,e);r(null,A,n,o,d,s,I),F(t+$,$,n,rt(e)+se,l,a);const c=F(t+C,C,i,Ye(b,ot(e))+se,l,a),u=F(t+h,h,i,Ye(b,ot(e),1)+se,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(t+b,b,d,st(e)+se,dl,kt(a,Yt));const p=F(t+f,f,I+Oe,Ye(g,dt(e))+se,dl,kt(a,Yt));F(ke+t+$+Ie,ke+$+Ie,Xt,rt(e,9)+Qt,kt(zt($)+Zt+o,zt($)+$e),kt(a,Wt($)),Kt,kt(al,`table: ${o})`+We,Ut),ol),F(ce+t+$+Ie,ce+$+Ie,Ie,rt(e,12),l,a,l,nl,ol),F(ke+t+b+Ie,ke+b+Ie,Xt,st(e,9)+Qt,kt(dl,zt(b)+Zt+s,zt(b)+$e),kt(a,Yt,Wt(b)),Kt,kt(al,`row: ${s})`+We,Ut),ol),F("Add"+t+b+Ie,"Add"+b+Ie,Xt,st(e,10)+Qt,kt(zt(b)+Zt+s,zt(b)+$e),kt(a,Wt(b)),Kt,"then?: ("+kt(dl+we,"store: Store","row: "+s+")"+We,"then"+$e)+", reuseRowIds?: boolean",ol+", reuseRowIds"),F(ke+t+ve+b+Ie,ke+ve+b+Ie,Xt,st(e,11)+Qt,kt(dl,zt(ve+b)+Zt+s,zt(ve+b)+$e),kt(a,Yt,Wt(ve+b)),Kt,kt(al,`partialRow: ${s})`+We,Ut),ol),F(ce+t+b+Ie,ce+b+Ie,Ie,st(e,12),dl,kt(a,Yt),l,nl,ol);const m=U(t+b+rl,"{rowId, "+N+", cellComponents, getCellComponentProps"+tl+`}: ${z}<'${e}'>`,[ae+`(${p}(rowId, ${N}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+D+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${le}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,el,"cellId={cellId}",J,Ft,"/>;","})"+tl+", rowId)"],st(e,13)+se);U(t+"Sorted"+$+rl,"{cellId, descending, offset, limit, ...props}: "+B+`<'${e}'>`,k+"(props, "+u+`(cellId, descending, offset, limit, props.${N}), ${a}, ${m});`,rt(e,13)+", sorted"+se),U(t+$+rl,`props: ${W}<'${e}'>`,k+"(props, "+c+`(props.${N}), ${a}, ${m});`,rt(e,13)+se),P(e,((n,o,d,s,I)=>{const c="Map"+Rt(o,1);r(0,A,c),r(1,A,c);const i=F(t+I+g,g,o+(L(d)?we:l),It(e,n)+se,dl,kt(a,Yt,s));F(ke+t+I+g+Ie,ke+g+Ie,Xt,It(e,n,9)+Qt,kt(dl,zt(g)+Zt+o+" | "+c,zt(g)+$e),kt(a,Yt,s,Wt(g)),Kt,kt(al,`cell: ${o} | ${c})`+We,Ut),ol),F(ce+t+I+g+Ie,ce+g+Ie,Ie,It(e,n,12),kt(dl,"forceDel?: boolean"),kt(a,Yt,s,"forceDel"),l,nl,ol),U(t+I+g+rl,`{rowId, ${N}, debugIds}: `+M+`<'${e}', '${n}'>`,[ae+`('' + ${i}(rowId, `+N+`) ?? '', undefined, debugIds, ${s})`],It(e,n,13)+se)}))}));const Z=Vt(R((e=>{var t,a;return null!=(a=null==(t=Y(S,e))?void 0:t[4])?a:l}))," | ");F(u+s,u+s,ze,Ke(1,8)+" changes",sl(d),Il()),F(p+s,p+s,ze,nt(2,0,1),sl(m),Il()),F($+s,$+s,ze,nt(3,0),sl(w,`tableId: ${a} | null`),Il("tableId")),F(C+s,C+s,ze,nt(4,3,1),sl(y,`tableId: ${a} | null`),Il("tableId")),F(h+s,h+s,ze,nt(13,3,1),sl(v,`tableId: ${a} | null`,"cellId: "+Z+we,"descending: boolean","offset: number","limit: number"+we),Il("tableId","cellId","descending","offset","limit")),F(b+s,b+s,ze,nt(5,3),sl(T,`tableId: ${a} | null`,Yt+": IdOrNull"),Il("tableId",Yt)),F(f+s,f+s,ze,nt(6,5,1),sl(V,`tableId: ${a} | null`,Yt+": IdOrNull"),Il("tableId",Yt)),F(g+s,g+s,ze,nt(7,5),sl(x,`tableId: ${a} | null`,Yt+": IdOrNull",`cellId: ${Z} | null`),Il("tableId",Yt,"cellId"))}if(!Z(t)){const[e,t,a,n,d,i]=o;r(null,A,...o),r(1,A,j);const $=c("getDefaultValueComponent","valueId: Id",Vt(S(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+ne);F(w,w,e,Ke(2,0)+se);const u=F(y,y,a+Oe,Ye(m,Ee)+se);F(ke+w+Ie,ke+w+Ie,Xt,Ke(2,9)+Qt,kt(zt(w)+Zt+t,zt(w)+$e),Wt(w),Kt,kt(al,`values: ${t})`+We,Ut),ol),F(ke+ve+w+Ie,ke+ve+w+Ie,Xt,Ke(2,11)+Qt,kt(zt(ve+w)+Zt+t,zt(ve+w)+$e),Wt(ve+w),Kt,kt(al,`partialValues: ${t})`+We,Ut),ol),F(ce+w+Ie,ce+w+Ie,Ie,Ke(2,12),l,l,l,nl,ol);const p=I(m+Te,Ot("valueId?: VId",N+me+j,Bt),tt("a Value"),`<VId extends ${a}>`),b=I(w+Te,Ot(N+me+j,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${p}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,ll,Bt),tt(qe(2,1)));r(1,E,b,p),U(w+rl,"{"+N+", valueComponents, getValueComponentProps"+tl+"}: "+b,[ae+`(${u}(${N}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+$+"(valueId);","return <Value",`{...${le}(getValueComponentProps, valueId)}`,"key={valueId}",J,Ft,"/>;","}), separator)"],Ke(2,13)+se),S(((e,t,a,n,o)=>{const d="Map"+Rt(t,1);r(0,A,d),r(1,A,d);const s=F(o+m,m,t,ct(e)+se,l,n);F(ke+o+m+Ie,ke+m+Ie,Xt,ct(e,9)+Qt,kt(zt(m)+Zt+t+" | "+d,zt(m)+$e),kt(n,Wt(m)),Kt,kt(al,`value: ${t} | ${d})`+We,Ut),ol),F(ce+o+m+Ie,ce+m+Ie,Ie,ct(e,12),l,n,l,nl,ol),U(o+m+rl,`{${N}, debugIds}: ${p}<'${e}'>`,[ae+`('' + ${s}(`+N+`) ?? '', undefined, debugIds, ${n})`],ct(e,13)+se)})),F(w+s,w+s,ze,Ke(2,8)+" changes",sl(n),Il()),F(y+s,y+s,ze,nt(10,0,1),sl(d),Il()),F(m+s,m+s,ze,nt(11,0),sl(i,`valueId: ${a} | null`),Il("valueId"))}return U(Ve,`{${N}, ${N}ById, children}: `+Q+" & {children: React.ReactNode}",["{",Ht,"return (","<Context."+Ve,"value={useMemo(",`() => [${N} ?? contextValue[0], {...contextValue[1], ...${N}ById}],`,`[${N}, ${N}ById, contextValue],`,")}>","{children}",`</Context.${Ve}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...T(0),...V(),..._(0)),d(...T(1),...x(),..._(1))]},il=(e,t,a)=>{if(Z(e)&&Z(t))return[l,l,l,l];const[n,o,d,r]=Jt(e,t,a);return[n,o,...cl(e,t,a,d,r)]};var $l=Object.defineProperty,ul=Object.defineProperties,pl=Object.getOwnPropertyDescriptors,bl=Object.getOwnPropertySymbols,Cl=Object.prototype.hasOwnProperty,hl=Object.prototype.propertyIsEnumerable,gl=(e,t,l)=>t in e?$l(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,fl=(e,t)=>{for(var l in t||(t={}))Cl.call(t,l)&&gl(e,l,t[l]);if(bl)for(var l of bl(t))hl.call(t,l)&&gl(e,l,t[l]);return e},ml=(e,t)=>ul(e,pl(t)),wl=(e,t,l)=>new Promise(((a,n)=>{var o=e=>{try{r(l.next(e))}catch(e){n(e)}},d=e=>{try{r(l.throw(e))}catch(e){n(e)}},r=e=>e.done?a(e.value):Promise.resolve(e.value).then(o,d);r((l=l.apply(e,t)).next())}));const yl={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},vl=Dt((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!Z(t)||v(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=X();if(v(a,(t=>v(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=ae(n,a,(()=>[z(o),X(),[0],0])),[r,s,[I]]=d,c=ae(s,o,(()=>0))+1;return c>I&&(d[2]=[c,o]),le(s,o,c),d[3]++,r==z(o)})))))return t[l]={},q(n,(([e,,[,n],o],s)=>{t[l][s]=fl({[d]:e},o==R(a)?{[r]:n}:{})})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return Z(t)&&e.forEachValue(((e,l)=>{t[e]={[d]:z(l)}})),t},a=e=>il(t(),l(),e),n=e=>wl(void 0,null,(function*(){const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return x(a(e),((e,a)=>vt(l(e,ml(fl({},yl),{filepath:"_."+t[a]})))))}));return F({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),fl({totalTables:l,totalRows:a,totalCells:n,totalValues:R(e.getValueIds()),jsonLength:Tt(e.getJson())},t?{detail:{tables:o}}:{})},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));e.createTools=vl},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinybase",
3
- "version": "4.0.0-beta.2",
3
+ "version": "4.0.0-beta.4",
4
4
  "author": "jamesgpearce",
5
5
  "repository": "github:tinyplex/tinybase",
6
6
  "license": "MIT",
@@ -22,8 +22,6 @@
22
22
  "tinybase": "./bin/cli.js"
23
23
  },
24
24
  "exports": {
25
- ".": "./lib/tinybase.js",
26
- "./with-schemas": "./lib/tinybase.js",
27
25
  "./package.json": "./package.json",
28
26
  "./cjs": "./lib/cjs/tinybase.cjs",
29
27
  "./cjs/with-schemas": "./lib/cjs/tinybase.cjs",
@@ -37,10 +35,6 @@
37
35
  "./es6/with-schemas": "./lib/es6/tinybase.js",
38
36
  "./es6/*/with-schemas": "./lib/es6/*.js",
39
37
  "./es6/*": "./lib/es6/*.js",
40
- "./debug": "./lib/debug/tinybase.js",
41
- "./debug/with-schemas": "./lib/debug/tinybase.js",
42
- "./debug/*/with-schemas": "./lib/debug/*.js",
43
- "./debug/*": "./lib/debug/*.js",
44
38
  "./umd": "./lib/umd/tinybase.js",
45
39
  "./umd/with-schemas": "./lib/umd/tinybase.js",
46
40
  "./umd/*/with-schemas": "./lib/umd/*.js",
@@ -53,8 +47,38 @@
53
47
  "./lib/with-schemas": "./lib/tinybase.js",
54
48
  "./lib/*/with-schemas": "./lib/*.js",
55
49
  "./lib/*": "./lib/*.js",
56
- "./*/with-schemas": "./lib/*.js",
57
- "./*": "./lib/*.js"
50
+ "./debug": {
51
+ "types": "./lib/types/tinybase.d.ts",
52
+ "default": "./lib/debug/tinybase.js"
53
+ },
54
+ "./debug/with-schemas": {
55
+ "types": "./lib/types/with-schemas/tinybase.d.ts",
56
+ "default": "./lib/debug/tinybase.js"
57
+ },
58
+ "./debug/*/with-schemas": {
59
+ "types": "./lib/types/with-schemas/*.d.ts",
60
+ "default": "./lib/debug/*.js"
61
+ },
62
+ "./debug/*": {
63
+ "types": "./lib/types/*.d.ts",
64
+ "default": "./lib/debug/*.js"
65
+ },
66
+ ".": {
67
+ "types": "./lib/types/tinybase.d.ts",
68
+ "default": "./lib/tinybase.js"
69
+ },
70
+ "./with-schemas": {
71
+ "types": "./lib/types/with-schemas/tinybase.d.ts",
72
+ "default": "./lib/tinybase.js"
73
+ },
74
+ "./*/with-schemas": {
75
+ "types": "./lib/types/with-schemas/*.d.ts",
76
+ "default": "./lib/*.js"
77
+ },
78
+ "./*": {
79
+ "types": "./lib/types/*.d.ts",
80
+ "default": "./lib/*.js"
81
+ }
58
82
  },
59
83
  "typesVersions": {
60
84
  "*": {
@@ -186,28 +210,30 @@
186
210
  "publishPackage": "gulp publishPackage"
187
211
  },
188
212
  "devDependencies": {
213
+ "@automerge/automerge": "^2.0.3",
189
214
  "@babel/cli": "^7.21.5",
190
- "@babel/core": "^7.21.8",
191
- "@babel/preset-env": "^7.21.5",
192
- "@babel/preset-react": "^7.18.6",
215
+ "@babel/core": "^7.22.1",
216
+ "@babel/preset-env": "^7.22.4",
217
+ "@babel/preset-react": "^7.22.3",
193
218
  "@babel/preset-typescript": "^7.21.5",
194
219
  "@rollup/plugin-replace": "^5.0.2",
195
220
  "@rollup/plugin-terser": "^0.4.3",
196
221
  "@types/asciichart": "^1.5.6",
197
222
  "@types/expect-puppeteer": "^5.0.3",
198
223
  "@types/http-server": "^0.12.1",
199
- "@types/jest": "^29.5.1",
224
+ "@types/jest": "^29.5.2",
200
225
  "@types/jest-environment-puppeteer": "^5.0.3",
201
226
  "@types/less": "^3.0.3",
202
- "@types/node": "^20.1.7",
227
+ "@types/node": "^20.2.5",
203
228
  "@types/puppeteer": "^5.4.7",
204
- "@types/react": "^18.2.6",
229
+ "@types/react": "^18.2.8",
205
230
  "@types/react-dom": "^18.2.4",
206
231
  "@types/react-test-renderer": "^18.0.0",
207
232
  "@types/tmp": "^0.2.3",
208
- "@typescript-eslint/eslint-plugin": "^5.59.6",
209
- "@typescript-eslint/parser": "^5.59.6",
233
+ "@typescript-eslint/eslint-plugin": "^5.59.9",
234
+ "@typescript-eslint/parser": "^5.59.9",
210
235
  "asciichart": "^1.5.25",
236
+ "automerge-repo": "^0.0.54",
211
237
  "babel-eslint": "^10.1.0",
212
238
  "babel-jest": "^29.5.0",
213
239
  "babel-preset-minify": "^0.5.2",
@@ -215,10 +241,10 @@
215
241
  "country-flag-emoji-json": "^2.0.0",
216
242
  "cspell": "^6.31.1",
217
243
  "esbuild": "^0.17.19",
218
- "eslint": "^8.40.0",
244
+ "eslint": "^8.42.0",
219
245
  "eslint-config-prettier": "^8.8.0",
220
246
  "eslint-plugin-jest": "^27.2.1",
221
- "eslint-plugin-jsdoc": "^44.2.4",
247
+ "eslint-plugin-jsdoc": "^46.2.4",
222
248
  "eslint-plugin-react": "^7.32.2",
223
249
  "eslint-plugin-react-hooks": "^4.6.0",
224
250
  "gulp": "^4.0.2",
@@ -227,14 +253,14 @@
227
253
  "jest": "^29.5.0",
228
254
  "jest-environment-jsdom": "^29.5.0",
229
255
  "jest-fetch-mock": "^3.0.3",
230
- "jest-puppeteer": "^8.0.6",
256
+ "jest-puppeteer": "^9.0.0",
231
257
  "less": "^4.1.3",
232
258
  "prettier": "^2.8.8",
233
- "puppeteer": "^20.2.1",
259
+ "puppeteer": "^20.5.0",
234
260
  "react": "^18.2.0",
235
261
  "react-dom": "^18.2.0",
236
262
  "react-test-renderer": "^18.2.0",
237
- "rollup": "^3.22.0",
263
+ "rollup": "^3.23.1",
238
264
  "rollup-plugin-esbuild": "^5.0.0",
239
265
  "rollup-plugin-gzip": "^3.1.0",
240
266
  "rollup-plugin-preserve-shebang": "^1.0.1",
@@ -243,21 +269,25 @@
243
269
  "tinydocs": "^0.1.26",
244
270
  "tmp": "^0.2.1",
245
271
  "ts-unused-exports": "^9.0.4",
246
- "typescript": "5.0.4",
272
+ "typescript": "5.1.3",
247
273
  "yjs": "^13.6.1"
248
274
  },
249
275
  "peerDependencies": {
250
- "prettier": "^2.0.0",
276
+ "automerge-repo": "^0.0.54",
277
+ "prettier": ">=2.0.0",
251
278
  "react": ">=17.0.0",
252
- "yjs": "^13.6.0"
279
+ "yjs": ">=13.6.0"
253
280
  },
254
281
  "peerDependenciesMeta": {
255
- "react": {
282
+ "automerge-repo": {
256
283
  "optional": true
257
284
  },
258
285
  "prettier": {
259
286
  "optional": true
260
287
  },
288
+ "react": {
289
+ "optional": true
290
+ },
261
291
  "yjs": {
262
292
  "optional": true
263
293
  }
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- <section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for <span>local-first apps</span>.</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Why sacrifice store features for bundle size? And why should the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p><em>TinyBase is a smart new way to structure your local app data:</em></p><ul><li>Manage <a href="#start-with-a-simple-key-value-store">key-value data</a> (<em>new!</em>), <a href="#level-up-to-use-tabular-data">tabular data</a> - or both - with optional <a href="#apply-schemas-to-tables-and-values">schematization</a> to model it.</li><li><a href="#register-listeners-at-any-granularity">Flexibly reactive</a> to reconciled updates, so your UI only spends cycles on the data that changes.</li><li><a href="#build-complex-queries-with-tinyql">Powerful query engine</a> to select, join, filter, group, sort and paginate data - reactively.</li><li><a href="#create-indexes-for-fast-lookups">Indexing</a>, <a href="#define-metrics-and-aggregations">metrics</a>, <a href="#configure-relationships-between-tables">relationships</a> - and even an <a href="#use-checkpoints-for-an-easy-undo-stack">undo stack</a> for your app state! - out of the box.</li><li>Easily <a href="#persist-data-to-browser-file-or-server">sync your data</a> to local or remote storage, and use <a href="#call-hooks-to-bind-to-data">idiomatic bindings</a> to your UI.</li><li><a href="#type-definitions-orm-like-apis">Type definitions &amp; ORM-like APIs</a> (<em>new!</em>), based on a schema or inferred from actual data.</li></ul><p><em>Tiny by name, tiny by nature</em>, TinyBase only costs <a href="#did-we-say-tiny">4.5kB - 8.7kB</a> when compressed, and has zero dependencies. And of course it&#x27;s <a href="#well-tested-and-documented">well tested</a>, <a href="https://beta.tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and <a href="https://github.com/tinyplex/tinybase">open source</a>. Other <a href="https://beta.tinybase.org/guides/faq/">FAQs</a>?</p></section><p><a id="new" href="https://beta.tinybase.org/guides/releases/#v3-1"><em>NEW!</em> v3.1 release</a></p><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h3 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h3><p><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img title="arpitBhalla" src="https://github.com/arpitBhalla.png?size=48" width="48" height="48"></a></p></section><section><h3 id="excited-to-be-used-by">Excited to be used by:</h3><p><a href="https://github.com/SuperSonicHub1" target="_blank"><img title="SuperSonicHub1" src="https://github.com/SuperSonicHub1.png?size=48" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img title="brentvatne" src="https://github.com/brentvatne.png?size=48" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img title="circadian-risk" src="https://github.com/circadian-risk.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img title="miking-the-viking" src="https://github.com/miking-the-viking.png?size=48" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img title="cubecull" src="https://github.com/cubecull.png?size=48" width="48" height="48"></a><a href="https://github.com/Apocalypsor" target="_blank"><img title="Apocalypsor" src="https://github.com/Apocalypsor.png?size=48" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img title="uptonking" src="https://github.com/uptonking.png?size=48" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img title="erwinkn" src="https://github.com/erwinkn.png?size=48" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img title="Kayoo-asso" src="https://github.com/Kayoo-asso.png?size=48" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img title="shaneosullivan" src="https://github.com/shaneosullivan.png?size=48" width="48" height="48"></a><a href="https://github.com/generates" target="_blank"><img title="generates" src="https://github.com/generates.png?size=48" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img title="flaming-codes" src="https://github.com/flaming-codes.png?size=48" width="48" height="48"></a><a href="https://github.com/jaysc" target="_blank"><img title="jaysc" src="https://github.com/jaysc.png?size=48" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img title="kotofurumiya" src="https://github.com/kotofurumiya.png?size=48" width="48" height="48"></a></p></section><hr><section><h2 id="start-with-a-simple-key-value-store">Start with a simple key-value store.</h2><p>Creating a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://beta.tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://beta.tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get them back out again.</p><p>Read more about using keyed value data in <a href="https://beta.tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
1
+ <section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for <span>local-first apps</span>.</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Why sacrifice store features for bundle size? And why should the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p><em>TinyBase is a smart new way to structure your local app data:</em></p><ul><li>Manage <a href="#start-with-a-simple-key-value-store">key-value data</a> (<em>new!</em>), <a href="#level-up-to-use-tabular-data">tabular data</a> - or both - with optional <a href="#apply-schemas-to-tables-and-values">schematization</a> to model it.</li><li><a href="#register-listeners-at-any-granularity">Flexibly reactive</a> to reconciled updates, so your UI only spends cycles on the data that changes.</li><li><a href="#build-complex-queries-with-tinyql">Powerful query engine</a> to select, join, filter, group, sort and paginate data - reactively.</li><li><a href="#create-indexes-for-fast-lookups">Indexing</a>, <a href="#define-metrics-and-aggregations">metrics</a>, <a href="#configure-relationships-between-tables">relationships</a> - and even an <a href="#use-checkpoints-for-an-easy-undo-stack">undo stack</a> for your app state! - out of the box.</li><li>Easily <a href="#persist-data-to-storage-or-crdts">sync your data</a> to storage or (<em>new!</em>) CRDTs, and use <a href="#call-hooks-to-bind-to-data">idiomatic bindings</a> to your UI.</li><li><a href="#type-definitions-orm-like-apis">Type definitions &amp; ORM-like APIs</a> (<em>new!</em>), based on a schema or inferred from actual data.</li></ul><p><em>Tiny by name, tiny by nature</em>, TinyBase only costs <a href="#did-we-say-tiny">4.6kB - 8.7kB</a> when compressed, and has zero dependencies. And of course it&#x27;s <a href="#well-tested-and-documented">well tested</a>, <a href="https://beta.tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and <a href="https://github.com/tinyplex/tinybase">open source</a>. Other <a href="https://beta.tinybase.org/guides/faq/">FAQs</a>?</p></section><p><a id="new" href="https://beta.tinybase.org/guides/releases/#v4-0"><em>NEW!</em> v4. release</a></p><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h3 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h3><p><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img title="arpitBhalla" src="https://github.com/arpitBhalla.png?size=48" width="48" height="48"></a></p></section><section><h3 id="excited-to-be-used-by">Excited to be used by:</h3><p><a href="https://github.com/SuperSonicHub1" target="_blank"><img title="SuperSonicHub1" src="https://github.com/SuperSonicHub1.png?size=48" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img title="brentvatne" src="https://github.com/brentvatne.png?size=48" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img title="circadian-risk" src="https://github.com/circadian-risk.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img title="miking-the-viking" src="https://github.com/miking-the-viking.png?size=48" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img title="cubecull" src="https://github.com/cubecull.png?size=48" width="48" height="48"></a><a href="https://github.com/Apocalypsor" target="_blank"><img title="Apocalypsor" src="https://github.com/Apocalypsor.png?size=48" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img title="uptonking" src="https://github.com/uptonking.png?size=48" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img title="erwinkn" src="https://github.com/erwinkn.png?size=48" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img title="Kayoo-asso" src="https://github.com/Kayoo-asso.png?size=48" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img title="shaneosullivan" src="https://github.com/shaneosullivan.png?size=48" width="48" height="48"></a><a href="https://github.com/generates" target="_blank"><img title="generates" src="https://github.com/generates.png?size=48" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img title="flaming-codes" src="https://github.com/flaming-codes.png?size=48" width="48" height="48"></a><a href="https://github.com/jaysc" target="_blank"><img title="jaysc" src="https://github.com/jaysc.png?size=48" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img title="kotofurumiya" src="https://github.com/kotofurumiya.png?size=48" width="48" height="48"></a></p></section><hr><section><h2 id="start-with-a-simple-key-value-store">Start with a simple key-value store.</h2><p>Creating a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://beta.tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://beta.tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get them back out again.</p><p>Read more about using keyed value data in <a href="https://beta.tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
2
2
 
3
3
  ```js
4
4
  const store = createStore()
@@ -100,7 +100,7 @@ console.log(store.getRow('pets', 'felix'));
100
100
  store.delTablesSchema();
101
101
  ```
102
102
 
103
- <section><h2 id="persist-data-to-browser-file-or-server">Persist data to browser, file, or server.</h2><p>You can easily persist a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> between browser page reloads or sessions. You can also synchronize it with a web endpoint, or (if you&#x27;re using TinyBase in an appropriate environment), load and save it to a file.</p><p>Read more about persisters in the <a href="https://beta.tinybase.org/guides/schemas-and-persistence/persisting-data/">Persisting Data</a> guide.</p></section>
103
+ <section><h2 id="persist-data-to-storage-or-crdts">Persist data to storage or CRDTs.</h2><p>You can easily persist a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> between browser page reloads or sessions. You can also synchronize it with a web endpoint, or (if you&#x27;re using TinyBase in an appropriate environment), load and save it to a file. <a href="https://beta.tinybase.org/guides/releases/#v4-0">New in v4.0</a>, you can bind TinyBase to <a href="https://yjs.dev/">Yjs</a> or <a href="https://automerge.org/">Automerge</a> CRDTs.</p><p>Read more about persisters in the <a href="https://beta.tinybase.org/guides/schemas-and-persistence/persisting-data/">Persisting Data</a> guide.</p></section>
104
104
 
105
105
  ```js
106
106
  const persister = createSessionPersister(store, 'demo');
@@ -266,4 +266,4 @@ export const createShop: typeof createShopDecl = () => {
266
266
  };
267
267
  ```
268
268
 
269
- <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://beta.tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>4.5kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>8.7kB</em>.</p><p>The optional <a href="https://beta.tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just another <em>3.4kB</em>, the auxiliary <a href="https://beta.tinybase.org/api/tools/"><code>tools</code></a> module is <em>9.9kB</em>, and everything is super fast. Life&#x27;s easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/store/">store</a></th><td>4.5kB</td><td>10.7kB</td><td>45.6kB</td><td>200.7kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/metrics/">metrics</a></th><td>1.8kB</td><td>3.6kB</td><td>14.9kB</td><td>29.3kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/indexes/">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.7kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/relationships/">relationships</a></th><td>1.8kB</td><td>3.7kB</td><td>16.8kB</td><td>42.2kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/queries/">queries</a></th><td>2.7kB</td><td>5.5kB</td><td>25.0kB</td><td>112.9kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/checkpoints/">checkpoints</a></th><td>1.5kB</td><td>3.1kB</td><td>12.5kB</td><td>33.5kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/persisters/">persisters</a></th><td>0.4kB</td><td>0.8kB</td><td>2.7kB</td><td>24.6kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/common/">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>8.7kB</td><td>21.2kB</td><td>92.0kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,768</td><td>1,768</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,908</td><td>1,908</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>763</td><td>763</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>645</td><td>645</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,712</td></tr><tr><th class="right">Assertions</th><td colspan="3">13,375</td></tr></tbody></table></div><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a>, <a href="https://discord.com/invite/mGz3mevwP8">Discord</a>, and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://github.com/tinyplex/tinybase/discussions">Discussions</a> and <a href="https://github.com/tinyplex/tinybase/issues">issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li><li><a href="https://beta.tinybase.org/guides/releases/">Release notes</a> for each version.</li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/4.0.0-beta.2">NPM</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://hachyderm.io/@jamesgpearce">me</a> in API design, minification, and documentation. It could not have been built without these great <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>
269
+ <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://beta.tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>4.6kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>8.7kB</em>.</p><p>The optional <a href="https://beta.tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just another <em>3.4kB</em>, the auxiliary <a href="https://beta.tinybase.org/api/tools/"><code>tools</code></a> module is <em>10.0kB</em>, and everything is super fast. Life&#x27;s easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/store/">store</a></th><td>4.6kB</td><td>10.8kB</td><td>46.1kB</td><td>202.7kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/metrics/">metrics</a></th><td>1.8kB</td><td>3.6kB</td><td>14.9kB</td><td>29.3kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/indexes/">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.7kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/relationships/">relationships</a></th><td>1.8kB</td><td>3.7kB</td><td>16.8kB</td><td>42.2kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/queries/">queries</a></th><td>2.7kB</td><td>5.5kB</td><td>25.0kB</td><td>112.9kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/checkpoints/">checkpoints</a></th><td>1.5kB</td><td>3.1kB</td><td>12.5kB</td><td>33.5kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/persisters/">persisters</a></th><td>0.4kB</td><td>0.8kB</td><td>2.7kB</td><td>24.6kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/common/">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>8.7kB</td><td>21.3kB</td><td>92.5kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,774</td><td>1,774</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,914</td><td>1,914</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>764</td><td>764</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>653</td><td>653</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,763</td></tr><tr><th class="right">Assertions</th><td colspan="3">13,540</td></tr></tbody></table></div><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a>, <a href="https://discord.com/invite/mGz3mevwP8">Discord</a>, and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://github.com/tinyplex/tinybase/discussions">Discussions</a> and <a href="https://github.com/tinyplex/tinybase/issues">issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li><li><a href="https://beta.tinybase.org/guides/releases/">Release notes</a> for each version.</li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/4.0.0-beta.4">NPM</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://hachyderm.io/@jamesgpearce">me</a> in API design, minification, and documentation. It could not have been built without these great <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>