tinybase 6.0.3 → 6.0.5

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.
package/index.js CHANGED
@@ -825,7 +825,14 @@ const createIndexes = getCreateFunction((store) => {
825
825
  setDefinitionAndListen(
826
826
  indexId,
827
827
  tableId,
828
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
828
+ (
829
+ change,
830
+ changedSliceIds,
831
+ changedSortKeys,
832
+ sliceIdOrIdsByRowId,
833
+ sortKeys,
834
+ force,
835
+ ) => {
829
836
  let sliceIdsChanged = 0;
830
837
  const changedSlices = setNew();
831
838
  const unsortedSlices = setNew();
@@ -869,8 +876,13 @@ const createIndexes = getCreateFunction((store) => {
869
876
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
870
877
  } else {
871
878
  mapForEach(changedSortKeys, (rowId) =>
872
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
873
- setAdd(unsortedSlices, sliceId),
879
+ ifNotUndefined(
880
+ mapGet(sliceIdOrIdsByRowId, rowId),
881
+ (sliceIdOrIds) =>
882
+ arrayForEach(
883
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
884
+ (sliceId) => setAdd(unsortedSlices, sliceId),
885
+ ),
874
886
  ),
875
887
  );
876
888
  }
package/indexes/index.js CHANGED
@@ -394,7 +394,14 @@ const createIndexes = getCreateFunction((store) => {
394
394
  setDefinitionAndListen(
395
395
  indexId,
396
396
  tableId,
397
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
397
+ (
398
+ change,
399
+ changedSliceIds,
400
+ changedSortKeys,
401
+ sliceIdOrIdsByRowId,
402
+ sortKeys,
403
+ force,
404
+ ) => {
398
405
  let sliceIdsChanged = 0;
399
406
  const changedSlices = setNew();
400
407
  const unsortedSlices = setNew();
@@ -438,8 +445,13 @@ const createIndexes = getCreateFunction((store) => {
438
445
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
439
446
  } else {
440
447
  mapForEach(changedSortKeys, (rowId) =>
441
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
442
- setAdd(unsortedSlices, sliceId),
448
+ ifNotUndefined(
449
+ mapGet(sliceIdOrIdsByRowId, rowId),
450
+ (sliceIdOrIds) =>
451
+ arrayForEach(
452
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
453
+ (sliceId) => setAdd(unsortedSlices, sliceId),
454
+ ),
443
455
  ),
444
456
  );
445
457
  }
@@ -394,7 +394,14 @@ const createIndexes = getCreateFunction((store) => {
394
394
  setDefinitionAndListen(
395
395
  indexId,
396
396
  tableId,
397
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
397
+ (
398
+ change,
399
+ changedSliceIds,
400
+ changedSortKeys,
401
+ sliceIdOrIdsByRowId,
402
+ sortKeys,
403
+ force,
404
+ ) => {
398
405
  let sliceIdsChanged = 0;
399
406
  const changedSlices = setNew();
400
407
  const unsortedSlices = setNew();
@@ -438,8 +445,13 @@ const createIndexes = getCreateFunction((store) => {
438
445
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
439
446
  } else {
440
447
  mapForEach(changedSortKeys, (rowId) =>
441
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
442
- setAdd(unsortedSlices, sliceId),
448
+ ifNotUndefined(
449
+ mapGet(sliceIdOrIdsByRowId, rowId),
450
+ (sliceIdOrIds) =>
451
+ arrayForEach(
452
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
453
+ (sliceId) => setAdd(unsortedSlices, sliceId),
454
+ ),
443
455
  ),
444
456
  );
445
457
  }
package/min/index.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,t="",s=e(t),n=e(!0),o=e(0),l=e(e),r="type",a="default",i="Listener",c="Result",d="add",u="Has",g="Ids",h="Table",f=h+"s",I=h+g,b="Row",w=b+"Count",L=b+g,C="Sorted"+b+g,R="Cell",T=R+g,v="Value",p=v+"s",S=v+g,y=e=>t+e,V=(e,t)=>e.startsWith(t),M=(e,t)=>e.endsWith(t),m=(e,s=t,n)=>e.split(s,n),E=globalThis,k=Math,D=k.max,H=k.min,J=k.floor,x=isFinite,F=e=>null==e,Q=(e,t,s)=>F(e)?s?.():t(e),z=e=>e==s||e==n,N=t=>e(t)==s,O=t=>e(t)==l,W=e=>Array.isArray(e),A=(e,t,s)=>e.slice(t,s),P=e=>e.length,_=()=>{},j=(e,t)=>e.includes(t),B=(e,t)=>e.every(t),U=(e,t)=>P(e)===P(t)&&B(e,((e,s)=>t[s]===e)),q=(e,t)=>B(e,((s,n)=>0==n||t(e[n-1],s)<=0)),G=(e,t)=>e.sort(t),K=(e,t)=>e.forEach(t),X=(e,t)=>e.map(t),Y=e=>$(e,((e,t)=>e+t),0),Z=e=>0==P(e),$=(e,t,s)=>e.reduce(t,s),ee=(e,...t)=>e.push(...t),te=e=>e.pop(),se=e=>e.shift(),ne=t=>{const s=e(t);return z(s)||s==o&&x(t)?s:void 0},oe=e=>F(e)||!F(ne(e)),le=(e,t,s,n,o)=>F(o)?e.delCell(t,s,n,!0):e.setCell(t,s,n,o),re=(e,t,s)=>F(s)?e.delValue(t):e.setValue(t,s),ae=e=>t=>$(fe(t),((t,s)=>t+e(s)),0),ie=e=>e?.size??0,ce=ae(ie),de=ae(ce),ue=ae(de),ge=(e,t)=>e?.has(t)??!1,he=e=>F(e)||0==ie(e),fe=e=>[...e?.values()??[]],Ie=e=>e.clear(),be=(e,t)=>e?.forEach(t),we=(e,t)=>e?.delete(t),Le=Object,Ce=e=>Le.getPrototypeOf(e),Re=Le.entries,Te=Le.isFrozen,ve=e=>!F(e)&&Q(Ce(e),(e=>e==Le.prototype||F(Ce(e))),(()=>!0)),pe=Le.keys,Se=Le.freeze,ye=(e=[])=>Le.fromEntries(e),Ve=(e,t)=>t in e,Me=(e,t)=>(delete e[t],e),me=(e,t)=>K(Re(e),(([e,s])=>t(s,e))),Ee=(e,t)=>ye(((e,t)=>X(Re(e),(([e,s])=>t(s,e))))(e,((e,s)=>[s,t(e,s)]))),ke=e=>ve(e)&&0==(e=>P(pe(e)))(e),De=(e,t,s)=>(Ve(e,t)||(e[t]=s()),e[t]),He=(e,t,s,n=0)=>F(e)||!ve(e)||!n&&ke(e)||Te(e)?(s?.(),!1):(me(e,((s,n)=>{t(s,n)||Me(e,n)})),!!n||!ke(e)),Je=e=>new Map(e),xe=e=>[...e?.keys()??[]],Fe=(e,t)=>e?.get(t),Qe=(e,t)=>be(e,((e,s)=>t(s,e))),ze=(e,t,s)=>F(s)?(we(e,t),e):e?.set(t,s),Ne=(e,t,s,n)=>(ge(e,t)?n?.(Fe(e,t)):ze(e,t,s()),Fe(e,t)),Oe=(e,t,s,n=ze)=>(Ee(t,((t,n)=>s(e,n,t))),Qe(e,(s=>Ve(t,s)?0:n(e,s))),e),We=(e,t,s,n)=>{const o={};return be(e,((e,l)=>{if(!s?.(e,l)){const s=t?t(e,l):e;n?.(s)||(o[l]=s)}})),o},Ae=(e,t,s)=>We(e,(e=>We(e,t,s)),he,ke),Pe=(e,t,s)=>We(e,(e=>Ae(e,t,s)),he,ke),_e=(e,t)=>{const s=Je();return be(e,((e,n)=>s.set(n,t?.(e)??e))),s},je=e=>_e(e,_e),Be=e=>_e(e,je),Ue=(e,t,s,n,o=0)=>Q((s?Ne:Fe)(e,t[o],o>P(t)-2?s:Je),(l=>{if(o>P(t)-2)return n?.(l)&&ze(e,t[o]),l;const r=Ue(l,t,s,n,o+1);return he(l)&&ze(e,t[o]),r})),qe=e=>new Set(W(e)||F(e)?e:[e]),Ge=(e,t)=>e?.add(t),Ke=(e,t,s,n,o)=>{const l=e.hasRow,r=Je(),a=Je(),i=Je(),c=Je(),d=Je(),u=Je(),g=(t,s,...n)=>{const o=Ne(u,t,qe);return K(n,(t=>Ge(o,t)&&s&&e.callListener(t))),n},h=(t,...s)=>Q(Fe(u,t),(n=>{K(Z(s)?fe(n):s,(t=>{e.delListener(t),we(n,t)})),he(n)&&ze(u,t)})),f=(e,s)=>{ze(r,e,s),ge(a,e)||(ze(a,e,t()),ze(c,e,Je()),ze(d,e,Je()),o(i))},I=e=>{ze(r,e),ze(a,e),ze(c,e),ze(d,e),h(e),o(i)};return[()=>e,()=>xe(r),e=>Qe(a,e),e=>ge(a,e),e=>Fe(r,e),e=>Fe(a,e),(e,t)=>ze(a,e,t),f,(t,n,o,r,a)=>{f(t,n);const i=Je(),u=Je(),I=Fe(c,t),b=Fe(d,t),w=t=>{const o=s=>e.getCell(n,t,s),c=Fe(I,t),d=l(n,t)?s(r(o,t)):void 0;if(c===d||W(c)&&W(d)&&U(c,d)||ze(i,t,[c,d]),!F(a)){const e=Fe(b,t),s=l(n,t)?a(o,t):void 0;e!=s&&ze(u,t,s)}},L=e=>{o((()=>{be(i,(([,e],t)=>ze(I,t,e))),be(u,((e,t)=>ze(b,t,e)))}),i,u,I,b,e),Ie(i),Ie(u)};Qe(I,w),e.hasTable(n)&&K(e.getRowIds(n),(e=>{ge(I,e)||w(e)})),L(!0),h(t),g(t,0,e.addRowListener(n,null,((e,t,s)=>w(s))),e.addTableListener(n,(()=>L())))},I,e=>n(e,i),()=>Qe(u,I),g,h]},Xe=(e,s)=>N(e)?t=>t(e):e??(()=>s??t),Ye=(e,t)=>{const s=new WeakMap;return n=>{s.has(n)||s.set(n,e(n));const o=s.get(n);return t?.(o),o}},Ze=/^\d+$/,$e=()=>{const e=[];let s=0;return[n=>(n?se(e):null)??t+s++,t=>{Ze.test(t)&&P(e)<1e3&&ee(e,t)}]},et=e=>{let s;const[n,o]=$e(),l=Je();return[(o,r,a,i=[],c=()=>[])=>{s??=e();const d=n(1);return ze(l,d,[o,r,a,i,c]),Ge(Ue(r,a??[t],qe),d),d},(e,n,...o)=>K(((e,s=[t])=>{const n=[],o=(e,t)=>t==P(s)?ee(n,e):null===s[t]?be(e,(e=>o(e,t+1))):K([s[t],null],(s=>o(Fe(e,s),t+1)));return o(e,0),n})(e,n),(e=>be(e,(e=>Fe(l,e)[0](s,...n??[],...o))))),e=>Q(Fe(l,e),(([,s,n])=>(Ue(s,n??[t],void 0,(t=>(we(t,e),he(t)?1:0))),ze(l,e),o(e),n))),e=>Q(Fe(l,e),(([e,,t=[],n,o])=>{const l=(...r)=>{const a=P(r);a==P(t)?e(s,...r,...o(r)):F(t[a])?K(n[a]?.(...r)??[],(e=>l(...r,e))):l(...r,t[a])};l()}))]},tt=Ye((e=>{let s,n,o,l=100,r=Je(),a=Je(),i=1;const c=Je(),d=Je(),[u,g,h]=et((()=>J)),f=Je(),I=Je(),b=[],w=[],L=(t,s)=>{i=0,e.transaction((()=>{const[n,o]=Fe(f,s);be(n,((s,n)=>be(s,((s,o)=>be(s,((s,l)=>le(e,n,o,l,s[t]))))))),be(o,((s,n)=>re(e,n,s[t])))})),i=1},C=e=>{ze(f,e),ze(I,e),g(d,[e])},R=(e,t)=>K(((e,t)=>e.splice(0,t))(e,t??P(e)),C),T=()=>R(b,P(b)-l),v=()=>Q(s,(()=>{ee(b,s),T(),R(w),s=void 0,o=1})),p=()=>{s=te(b),o=1};let S,y;const V=(e=t)=>(F(s)&&(s=t+n++,ze(f,s,[r,a]),D(s,e),r=Je(),a=Je(),o=1),s),M=()=>{Z(b)||(((e,...t)=>{e.unshift(...t)})(w,V()),L(0,s),s=te(b),o=1)},m=()=>{Z(w)||(ee(b,s),s=se(w),L(1,s),o=1)},E=()=>{o&&(g(c),o=0)},k=e=>{const t=V(e);return E(),t},D=(e,t)=>(H(e)&&Fe(I,e)!==t&&(ze(I,e,t),g(d,[e])),J),H=e=>ge(f,e),J={setSize:e=>(l=e,T(),J),addCheckpoint:k,setCheckpoint:D,getStore:()=>e,getCheckpointIds:()=>[[...b],s,[...w]],forEachCheckpoint:e=>Qe(I,e),hasCheckpoint:H,getCheckpoint:e=>Fe(I,e),goBackward:()=>(M(),E(),J),goForward:()=>(m(),E(),J),goTo:e=>{const t=j(b,e)?M:j(w,e)?m:null;for(;!F(t)&&e!=s;)t();return E(),J},addCheckpointIdsListener:e=>u(e,c),addCheckpointListener:(e,t)=>u(t,d,[e]),delListener:e=>(h(e),J),clear:()=>(R(b),R(w),F(s)||C(s),s=void 0,n=0,k(),J),clearForward:()=>(Z(w)||(R(w),g(c)),J),destroy:()=>{e.delListener(S),e.delListener(y)},getListenerStats:()=>({checkpointIds:ce(c),checkpoint:ce(d)}),_registerListeners:()=>{S=e.addCellListener(null,null,null,((e,t,s,n,o,l)=>{if(i){v();const e=Ne(r,t,Je),a=Ne(e,s,Je),i=Ne(a,n,(()=>[l,void 0]));i[1]=o,i[0]===o&&he(ze(a,n))&&he(ze(e,s))&&he(ze(r,t))&&p(),E()}})),y=e.addValueListener(null,((e,t,s,n)=>{if(i){v();const e=Ne(a,t,(()=>[n,void 0]));e[1]=s,e[0]===s&&he(ze(a,t))&&p(),E()}}))}};return Se(J.clear())}),(e=>e._registerListeners())),st=m("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),nt=Je(X(st,((e,t)=>[e,t]))),ot=e=>st[63&e],lt=(e,t)=>Fe(nt,e[t])??0,rt=E.crypto?e=>E.crypto.getRandomValues(e):e=>X(e,(()=>J(256*k.random()))),at=(e,t)=>(e??0)<(t??0)?-1:1,it=(e=16)=>$(rt(new Uint8Array(e)),((e,t)=>e+ot(t)),""),ct=Ye((e=>{const s=Je(),n=Je(),[o,l,r]=et((()=>C)),[a,i,c,d,u,g,h,,f,I,b,w]=Ke(e,Je,(e=>F(e)?t:W(e)?X(e,y):y(e)),o,l),L=(t,s,n)=>{const o=u(t);be(n,((t,n)=>s(n,(s=>be(t,(t=>s(t,(s=>e.forEachCell(o,t,s)))))))))},C={setIndexDefinition:(e,t,o,r,a,i=at)=>{const c=F(a)?void 0:([e],[t])=>a(e,t);return f(e,t,((t,o,a,d,u,f)=>{let I=0;const b=qe(),w=qe(),L=g(e);if(be(o,(([e,t],s)=>{const n=qe(e),o=qe(t);be(n,(e=>we(o,e)?we(n,e):0)),be(n,(e=>{Ge(b,e),Q(Fe(L,e),(t=>{we(t,s),he(t)&&(ze(L,e),I=1)}))})),be(o,(e=>{Ge(b,e),ge(L,e)||(ze(L,e,qe()),I=1),Ge(Fe(L,e),s),F(r)||Ge(w,e)}))})),t(),he(u)||(f?Qe(L,(e=>Ge(w,e))):Qe(a,(e=>Q(Fe(d,e),(e=>Ge(w,e))))),be(w,(e=>{const t=(t,s)=>i(Fe(u,t),Fe(u,s),e),s=[...Fe(L,e)];q(s,t)||(ze(L,e,qe(G(s,t))),Ge(b,e))}))),(I||f)&&!F(c)){const t=[...L];q(t,c)||(h(e,Je(G(t,c))),I=1)}I&&l(s,[e]),be(b,(t=>l(n,[e,t])))}),Xe(o),Q(r,Xe)),C},delIndexDefinition:e=>(I(e),C),getStore:a,getIndexIds:i,forEachIndex:e=>c(((t,s)=>e(t,(e=>L(t,e,s))))),forEachSlice:(e,t)=>L(e,t,g(e)),hasIndex:d,hasSlice:(e,t)=>ge(g(e),t),getTableId:u,getSliceIds:e=>xe(g(e)),getSliceRowIds:(e,t)=>fe(Fe(g(e),t)),addIndexIdsListener:b,addSliceIdsListener:(e,t)=>o(t,s,[e]),addSliceRowIdsListener:(e,t,s)=>o(s,n,[e,t]),delListener:e=>(r(e),C),destroy:w,getListenerStats:()=>({sliceIds:ce(s),sliceRowIds:de(n)})};return Se(C)})),dt=Je([["avg",[(e,t)=>Y(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>D(...e),(e,t)=>D(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:D(t,e)]],["min",[e=>H(...e),(e,t)=>H(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:H(t,e)]],["sum",[e=>Y(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),ut=(e,t,s,n,o,l=!1)=>{if(he(s))return;const[r,a,i,c]=o;return l||=F(e),be(n,(([s,n])=>{l||(e=F(s)?a?.(e,n,t++):F(n)?i?.(e,s,t--):c?.(e,n,s,t),l||=F(e))})),l?r(fe(s),ie(s)):e},gt=Ye((e=>{const s=Je(),[n,o,l]=et((()=>w)),[r,a,i,c,d,u,g,,h,f,I,b]=Ke(e,_,(e=>isNaN(e)||F(e)||!0===e||!1===e||e===t?void 0:1*e),n,o),w={setMetricDefinition:(e,t,n,l,r,a,i)=>{const c=O(n)?[n,r,a,i]:Fe(dt,n)??Fe(dt,"sum");return h(e,t,((t,n,l,r,a,i)=>{const d=u(e),h=ie(r);i||=F(d),t();let f=ut(d,h,r,n,c,i);x(f)||(f=void 0),f!=d&&(g(e,f),o(s,[e],f,d))}),Xe(l,1)),w},delMetricDefinition:e=>(f(e),w),getStore:r,getMetricIds:a,forEachMetric:i,hasMetric:c,getTableId:d,getMetric:u,addMetricIdsListener:I,addMetricListener:(e,t)=>n(t,s,[e]),delListener:e=>(l(e),w),destroy:b,getListenerStats:()=>({metric:ce(s)})};return Se(w)})),ht=Ye((e=>{const s=e.createStore,n=s(),o=s(),l=Je(),{addListener:r,callListeners:a,delListener:u}=o,[g,f,I,v,p,,,S,,y,V,M,m,E]=Ke(e,(()=>!0),_,r,a),k=(e,t,...s)=>K(s,(s=>Ge(Ne(Ne(l,t,Je),e,qe),s))),D=e=>{Q(Fe(l,e),(e=>{Qe(e,((e,t)=>be(t,(t=>e.delListener(t))))),Ie(e)})),K([o,n],(t=>t.delTable(e)))},H=(e,t,s)=>k(t,e,t.addStartTransactionListener(s.startTransaction),t.addDidFinishTransactionListener((()=>s.finishTransaction()))),J={setQueryDefinition:(s,l,r)=>{S(s,l),D(s);const a=[],i=[[null,[l,null,null,[],Je()]]],c=[],d=[],u=[];r({select:(e,s)=>{const n=O(e)?[P(a)+t,e]:[F(s)?e:s,t=>t(e,s)];return ee(a,n),{as:e=>n[0]=e}},join:(e,t,s)=>{const n=F(s)||O(t)?null:t,o=F(n)?t:s,l=[e,[e,n,O(o)?o:e=>e(o),[],Je()]];return ee(i,l),{as:e=>l[0]=e}},where:(e,t,s)=>ee(c,O(e)?e:F(s)?s=>s(e)===t:n=>n(e,t)===s),group:(e,t,s,n,o)=>{const l=[e,[e,O(t)?[t,s,n,o]:Fe(dt,t)??[(e,t)=>t]]];return ee(d,l),{as:e=>l[0]=e}},having:(e,t)=>ee(u,O(e)?e:s=>s(e)===t)});const g=Je(a);if(he(g))return J;const h=Je(i);Qe(h,((e,[,t])=>Q(Fe(h,t),(({3:t})=>F(e)?0:ee(t,e)))));const f=Je(d);let I=n;if(he(f)&&Z(u))I=o;else{H(s,I,o);const e=Je();Qe(f,((t,[s,n])=>Ge(Ne(e,s,qe),[t,n])));const t=qe();Qe(g,(s=>ge(e,s)?0:Ge(t,s)));const n=Je(),l=(t,n,l,r)=>Q(t,(([a,i,c,d])=>{Qe(n,((t,[s])=>{const n=Ne(a,t,Je),o=Fe(n,l),i=r?void 0:s;if(o!==i){const s=qe([[o,i]]),r=ie(n);ze(n,l,i),be(Fe(e,t),(([e,t])=>{const o=ut(d[e],r,n,s,t);d[e]=F(ne(o))?null:o}))}})),he(i)||!B(u,(e=>e((e=>d[e]))))?o.delRow(s,c):F(c)?t[2]=o.addRow(s,d):o.setRow(s,c,d)}));k(I,s,I.addRowListener(s,null,((o,r,a,i)=>{const c=[],d=[],u=Je(),g=I.hasRow(s,a);let h=!g;be(t,(e=>{const[t,n,o]=i(s,a,e);ee(c,n),ee(d,o),h||=t})),Qe(e,(e=>{const[t,,n]=i(s,a,e);(h||t)&&ze(u,e,[n])})),h&&l(Ue(n,c,void 0,(([,e])=>(we(e,a),he(e)))),u,a,1),g&&l(Ue(n,d,(()=>{const e={};return be(t,(t=>e[t]=I.getCell(s,a,t))),[Je(),qe(),void 0,e]}),(([,e])=>{Ge(e,a)})),u,a)})))}H(s,e,I);const b=(t,n,o,r)=>{const a=t=>e.getCell(n,o,t);K(r,(n=>{const[o,,l,r,i]=Fe(h,n),c=l?.(a,t),[d,u]=Fe(i,t)??[];c!=d&&(F(u)||E(s,u),ze(i,t,F(c)?null:[c,...m(s,1,e.addRowListener(o,c,(()=>b(t,o,c,r))))]))})),(t=>{const n=(s,n)=>e.getCell(...F(n)?[l,t,s]:s===l?[l,t,n]:[Fe(h,s)?.[0],Fe(Fe(h,s)?.[4],t)?.[0],n]);I.transaction((()=>B(c,(e=>e(n)))?Qe(g,((e,o)=>le(I,s,t,e,o(n,t)))):I.delRow(s,t)))})(t)},{3:w}=Fe(h,null);return I.transaction((()=>m(s,1,e.addRowListener(l,null,((t,n,o)=>{e.hasRow(l,o)?b(o,l,o,w):(I.delRow(s,o),be(h,(({4:e})=>Q(Fe(e,o),(([,t])=>{E(s,t),ze(e,o)})))))}))))),J},delQueryDefinition:e=>(D(e),y(e),J),getStore:g,getQueryIds:f,forEachQuery:I,hasQuery:v,getTableId:p,addQueryIdsListener:e=>V((()=>e(J))),delListener:e=>(u(e),J),destroy:M,getListenerStats:()=>{const{tables:e,tableIds:t,transaction:s,...n}=o.getListenerStats();return n}};return Ee({[h]:[1,1],[h+T]:[0,1],[w]:[0,1],[L]:[0,1],[C]:[0,5],[b]:[1,2],[T]:[0,2],[R]:[1,3]},(([e,t],s)=>{K(e?["get","has","forEach"]:["get"],(e=>J[e+c+s]=(...t)=>o[e+s](...t))),J[d+c+s+i]=(...e)=>o[d+s+i](...A(e,0,t),((s,...n)=>e[t](J,...n)),!0)})),Se(J)})),ft=Ye((e=>{const s=Je(),n=Je(),o=Je(),l=Je(),[r,a,i]=et((()=>v)),[c,d,u,g,h,f,,,I,b,w,L]=Ke(e,(()=>[Je(),Je(),Je(),Je()]),(e=>F(e)?void 0:e+t),r,a),C=(e,t,s)=>Q(f(e),(([n,,o])=>{if(!ge(o,t)){const l=qe();if(h(e)!=T(e))Ge(l,t);else{let e=t;for(;!F(e)&&!ge(l,e);)Ge(l,e),e=Fe(n,e)}if(s)return l;ze(o,t,l)}return Fe(o,t)})),R=(e,t)=>Q(f(e),(([,,e])=>ze(e,t))),T=e=>Fe(s,e),v={setRelationshipDefinition:(e,t,r,i)=>(ze(s,e,r),I(e,t,((t,s)=>{const r=qe(),i=qe(),c=qe(),[d,u]=f(e);be(s,(([t,s],n)=>{F(t)||(Ge(i,t),Q(Fe(u,t),(e=>{we(e,n),he(e)&&ze(u,t)}))),F(s)||(Ge(i,s),ge(u,s)||ze(u,s,qe()),Ge(Fe(u,s),n)),Ge(r,n),ze(d,n,s),Qe(Fe(l,e),(t=>{ge(C(e,t),n)&&Ge(c,t)}))})),t(),be(r,(t=>a(n,[e,t]))),be(i,(t=>a(o,[e,t]))),be(c,(t=>{R(e,t),a(l,[e,t])}))}),Xe(i)),v),delRelationshipDefinition:e=>(ze(s,e),b(e),v),getStore:c,getRelationshipIds:d,forEachRelationship:t=>u((s=>t(s,(t=>e.forEachRow(h(s),t))))),hasRelationship:g,getLocalTableId:h,getRemoteTableId:T,getRemoteRowId:(e,t)=>Fe(f(e)?.[0],t),getLocalRowIds:(e,t)=>fe(Fe(f(e)?.[1],t)),getLinkedRowIds:(e,t)=>F(f(e))?[t]:fe(C(e,t,!0)),addRelationshipIdsListener:w,addRemoteRowIdListener:(e,t,s)=>r(s,n,[e,t]),addLocalRowIdsListener:(e,t,s)=>r(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(C(e,t),r(s,l,[e,t])),delListener:e=>(R(...i(e)??[]),v),destroy:L,getListenerStats:()=>({remoteRowId:de(n),localRowIds:de(o),linkedRowIds:de(l)})};return Se(v)})),It=new E.TextEncoder,bt=e=>{let t=2166136261;return K(It.encode(e),(e=>{t^=e,t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)})),t>>>0},wt=2**36,Lt=2**30,Ct=2**24,Rt=2**18,Tt=4096,vt=JSON.stringify,pt=JSON.parse,St=e=>vt(e,((e,t)=>t instanceof Map?Le.fromEntries([...t]):t)),yt=([e,t])=>Mt(e,t),Vt=([e,t,s])=>[e,t,s],Mt=(e,t)=>t?[e,t]:[e],mt=(e,t,s)=>[e,t,s],Et=e=>e[2],kt=(e,t)=>bt(e+":"+t),Dt=(e,t)=>t>e?(e?bt(e):0)^bt(t):0,Ht=(e,t)=>((e??"")>(t??"")?e:t)??"",Jt=(e,t,s)=>{t>e[1]&&(e[1]=t),e[2]=s>>>0},xt=(e=t)=>Mt(ye(),e),Ft=(e=t)=>[Je(),e,0],Qt=([e,t,s],n=Vt)=>[We(e,n),t,s],zt=([e,t],s=yt)=>Mt(We(e,s),t),Nt=(t,s)=>W(t)&&3==P(t)&&N(t[1])&&e(t[2])==o&&x(t[2])&&s(t[0]),Ot=e=>[e,e],Wt=(e,t=ce)=>t(e[0])+t(e[1]),At=()=>[Je(),Je()],Pt=e=>[...e],_t=([e,t])=>e===t,jt=(e,t,s)=>ze(e,t,Fe(e,t)==-s?void 0:s),Bt=()=>{let e,t,s=!1,n=!1,l=0,c=[];const g=Je(),C=Je(),V=Je(),M=Je(),m=Je(),E=Je(),k=Je(),D=Je(),H=Je(),J=Je(),x=Je(),N=Je(),P=Je(),_=Je(),B=qe(),q=Je(),Y=Je(),Z=Je(),$=Je(),te=At(),se=At(),oe=At(),ae=At(),fe=At(),Le=At(),Ce=At(),Re=At(),Te=At(),ve=At(),pe=At(),ye=At(),me=At(),De=At(),Ue=At(),Ke=At(),Xe=At(),Ye=At(),Ze=At(),tt=At(),st=At(),nt=At(),ot=Je(),lt=At(),[rt,it,ct,dt]=et((()=>Os)),ut=e=>{if(!He(e,((e,t)=>j([r,a],t))))return!1;const t=e[r];return!(!z(t)&&t!=o||(ne(e[a])!=t&&Me(e,a),0))},gt=W,ht=(t,s)=>(!e||ge(x,s)||Yt(s))&&He(t,((e,t)=>ft(s,t,e)),(()=>Yt(s))),ft=(e,t,s,n)=>He(n?s:Lt(s,e,t),((n,o)=>Q(It(e,t,o,n),(e=>(s[o]=e,!0)),(()=>!1))),(()=>Yt(e,t))),It=(t,s,n,o)=>e?Q(Fe(Fe(x,t),n),(e=>ne(o)!=e[r]?Yt(t,s,n,o,e[a]):o),(()=>Yt(t,s,n,o))):F(ne(o))?Yt(t,s,n,o):o,bt=(e,t)=>He(t?e:Ct(e),((t,s)=>Q(wt(s,t),(t=>(e[s]=t,!0)),(()=>!1))),(()=>Zt())),wt=(e,s)=>t?Q(Fe(P,e),(t=>ne(s)!=t[r]?Zt(e,s,t[a]):s),(()=>Zt(e,s))):F(ne(s))?Zt(e,s):s,Lt=(e,t,s)=>(Q(Fe(N,t),(([n,o])=>{be(n,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(o,(n=>{Ve(e,n)||Yt(t,s,n)}))})),e),Ct=e=>(t&&(be(_,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(B,(t=>{Ve(e,t)||Zt(t)}))),e),Rt=e=>Oe(x,e,((e,t,s)=>{const n=Je(),o=qe();Oe(Ne(x,t,Je),s,((e,t,s)=>{ze(e,t,s),Q(s[a],(e=>ze(n,t,e)),(()=>Ge(o,t)))})),ze(N,t,[n,o])}),((e,t)=>{ze(x,t),ze(N,t)})),Tt=e=>Oe(P,e,((e,t,s)=>{ze(P,t,s),Q(s[a],(e=>ze(_,t,e)),(()=>Ge(B,t)))}),((e,t)=>{ze(P,t),ze(_,t),we(B,t)})),vt=e=>ke(e)?ks():ys(e),yt=e=>Oe(Z,e,((e,t,s)=>Vt(t,s)),((e,t)=>xt(t))),Vt=(e,t)=>Oe(Ne(Z,e,(()=>(Nt(e,1),ze(q,e,$e()),ze(Y,e,Je()),Je()))),t,((t,s,n)=>Mt(e,t,s,n)),((t,s)=>Ft(e,t,s))),Mt=(e,t,s,n,o)=>Oe(Ne(t,s,(()=>(Ut(e,s,1),Je()))),n,((t,n,o)=>mt(e,s,t,n,o)),((n,l)=>Qt(e,t,s,n,l,o))),mt=(e,t,s,n,o)=>{ge(s,n)||qt(e,t,n,1);const l=Fe(s,n);o!==l&&(Gt(e,t,n,l,o),ze(s,n,o))},Et=(e,t,s,n,o)=>Q(Fe(t,s),(t=>mt(e,s,t,n,o)),(()=>Mt(e,t,s,Lt({[n]:o},e,s)))),kt=e=>ke(e)?Js():Vs(e),Dt=e=>Oe($,e,((e,t,s)=>Ht(t,s)),((e,t)=>zt(t))),Ht=(e,t)=>{ge($,e)||Kt(e,1);const s=Fe($,e);t!==s&&(Xt(e,s,t),ze($,e,t))},Jt=e=>Fe(Z,e)??Vt(e,{}),xt=e=>Vt(e,{}),Ft=(e,t,s)=>{const[,n]=Fe(q,e);n(s),Mt(e,t,s,{},!0)},Qt=(e,t,s,n,o,l)=>{const r=Fe(Fe(N,e)?.[0],o);if(!F(r)&&!l)return mt(e,s,n,o,r);const a=t=>{Gt(e,s,t,Fe(n,t)),qt(e,s,t,-1),ze(n,t)};F(r)?a(o):Qe(n,a),he(n)&&(Ut(e,s,-1),he(ze(t,s))&&(Nt(e,-1),ze(Z,e),ze(q,e),ze(Y,e)))},zt=e=>{const t=Fe(_,e);if(!F(t))return Ht(e,t);Xt(e,Fe($,e)),Kt(e,-1),ze($,e)},Nt=(e,t)=>jt(g,e,t),Ut=(e,t,s)=>jt(Ne(M,e,Je),t,s)&&ze(V,e,Ne(V,e,(()=>0))+s),qt=(e,t,s,n)=>{const o=Fe(Y,e),l=Fe(o,s)??0;(0==l&&1==n||1==l&&-1==n)&&jt(Ne(C,e,Je),s,n),ze(o,s,l!=-n?l+n:null),jt(Ne(Ne(m,e,Je),t,Je),s,n)},Gt=(e,t,s,n,o)=>{Ne(Ne(Ne(E,e,Je),t,Je),s,(()=>[n,0]))[1]=o,c[3]?.(e,t,s,o)},Kt=(e,t)=>jt(k,e,t),Xt=(e,t,s)=>{Ne(D,e,(()=>[t,0]))[1]=s,c[4]?.(e,s)},Yt=(e,t,s,n,o)=>(ee(Ne(Ne(Ne(H,e,Je),t,Je),s,(()=>[])),n),o),Zt=(e,t,s)=>(ee(Ne(J,e,(()=>[])),t),s),$t=(e,t,s)=>Q(Fe(Fe(Fe(E,e),t),s),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(fs(e,t,s))])),es=e=>Q(Fe(D,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(ws(e))])),ts=e=>he(H)||he(Ke[e])?0:be(e?Be(H):H,((t,s)=>be(t,((t,n)=>be(t,((t,o)=>it(Ke[e],[s,n,o],t))))))),ss=e=>he(J)||he(Xe[e])?0:be(e?_e(J):J,((t,s)=>it(Xe[e],[s],t))),ns=(e,t,s,n)=>{if(!he(e))return it(t,n,(()=>We(e))),Qe(e,((e,t)=>it(s,[...n??[],e],1==t))),1},os=e=>{const t=Ls();t!=s&&it(te[e],void 0,t);const n=he(ve[e]),o=he(me[e])&&he(De[e])&&he(Te[e])&&he(pe[e])&&he(Le[e])&&he(Ce[e])&&he(Re[e])&&n&&he(oe[e])&&he(ae[e]),l=he(Ue[e])&&he(ye[e])&&he(fe[e])&&he(se[e]);if(!o||!l){const t=e?[_e(g),je(C),_e(V),je(M),Be(m),Be(E)]:[g,C,V,M,m,E];if(!o){ns(t[0],oe[e],ae[e]),be(t[1],((t,s)=>ns(t,Le[e],Ce[e],[s]))),be(t[2],((t,s)=>{0!=t&&it(Re[e],[s],ds(s))}));const s=qe();be(t[3],((t,o)=>{ns(t,Te[e],pe[e],[o])&&!n&&(it(ve[e],[o,null]),Ge(s,o))})),n||be(t[5],((t,n)=>{if(!ge(s,n)){const s=qe();be(t,(e=>be(e,(([t,n],o)=>n!==t?Ge(s,o):we(e,o))))),be(s,(t=>it(ve[e],[n,t])))}})),be(t[4],((t,s)=>be(t,((t,n)=>ns(t,me[e],De[e],[s,n])))))}if(!l){let s;be(t[5],((t,n)=>{let o;be(t,((t,l)=>{let r;be(t,(([t,a],i)=>{a!==t&&(it(Ue[e],[n,l,i],a,t,$t),s=o=r=1)})),r&&it(ye[e],[n,l],$t)})),o&&it(fe[e],[n],$t)})),s&&it(se[e],void 0,$t)}}},ls=e=>{const t=ps();t!=n&&it(Ye[e],void 0,t);const s=he(tt[e])&&he(st[e]),o=he(nt[e])&&he(Ze[e]);if(!s||!o){const t=e?[_e(k),_e(D)]:[k,D];if(s||ns(t[0],tt[e],st[e]),!o){let s;be(t[1],(([t,n],o)=>{n!==t&&(it(nt[e],[o],n,t,es),s=1)})),s&&it(Ze[e],void 0,es)}}},rs=(e,...t)=>(Qs((()=>e(...X(t,y)))),Os),as=()=>Pe(Z),is=()=>xe(Z),cs=e=>xe(Fe(Y,y(e))),ds=e=>ie(Fe(Z,y(e))),us=e=>xe(Fe(Z,y(e))),gs=(e,t,s,n=0,o)=>{return X(A(G((l=Fe(Z,y(e)),r=(e,s)=>[F(t)?s:Fe(e,y(t)),s],X([...l?.entries()??[]],(([e,t])=>r(t,e)))),(([e],[t])=>at(e,t)*(s?-1:1))),n,F(o)?o:n+o),(([,e])=>e));var l,r},hs=(e,t)=>xe(Fe(Fe(Z,y(e)),y(t))),fs=(e,t,s)=>Fe(Fe(Fe(Z,y(e)),y(t)),y(s)),Is=()=>We($),bs=()=>xe($),ws=e=>Fe($,y(e)),Ls=()=>!he(Z),Cs=e=>ge(Z,y(e)),Rs=(e,t)=>ge(Fe(Y,y(e)),y(t)),Ts=(e,t)=>ge(Fe(Z,y(e)),y(t)),vs=(e,t,s)=>ge(Fe(Fe(Z,y(e)),y(t)),y(s)),ps=()=>!he($),Ss=e=>ge($,y(e)),ys=e=>rs((()=>(e=>He(e,ht,Yt))(e)?yt(e):0)),Vs=e=>rs((()=>bt(e)?Dt(e):0)),Ms=e=>{try{vt(pt(e))}catch{}return Os},ms=t=>rs((()=>{if((e=He(t,(e=>He(e,ut))))&&(Rt(t),!he(Z))){const e=as();ks(),ys(e)}})),Es=e=>rs((()=>{if(t=(e=>He(e,ut))(e)){const s=Is();Fs(),Js(),t=!0,Tt(e),Vs(s)}})),ks=()=>rs((()=>yt({}))),Ds=e=>rs((e=>ge(Z,e)?xt(e):0),e),Hs=(e,t)=>rs(((e,t)=>Q(Fe(Z,e),(s=>ge(s,t)?Ft(e,s,t):0))),e,t),Js=()=>rs((()=>Dt({}))),xs=()=>rs((()=>{Rt({}),e=!1})),Fs=()=>rs((()=>{Tt({}),t=!1})),Qs=(e,t)=>{if(-1!=l){zs();const s=e();return Ns(t),s}},zs=()=>(-1!=l&&l++,1==l&&(c[0]?.(),it(ot)),Os),Ns=e=>(l>0&&(l--,0==l&&(l=1,ts(1),he(E)||os(1),ss(1),he(D)||ls(1),e?.(Os)&&(be(E,((e,t)=>be(e,((e,s)=>be(e,(([e],n)=>le(Os,t,s,n,e))))))),Ie(E),be(D,(([e],t)=>re(Os,t,e))),Ie(D)),it(lt[0],void 0),l=-1,ts(0),he(E)||os(0),ss(0),he(D)||ls(0),c[1]?.(),it(lt[1],void 0),c[2]?.(),l=0,s=Ls(),n=ps(),K([g,C,V,M,m,E,H,k,D,J],Ie))),Os),Os={getContent:()=>[as(),Is()],getTables:as,getTableIds:is,getTable:e=>Ae(Fe(Z,y(e))),getTableCellIds:cs,getRowCount:ds,getRowIds:us,getSortedRowIds:gs,getRow:(e,t)=>We(Fe(Fe(Z,y(e)),y(t))),getCellIds:hs,getCell:fs,getValues:Is,getValueIds:bs,getValue:ws,hasTables:Ls,hasTable:Cs,hasTableCell:Rs,hasRow:Ts,hasCell:vs,hasValues:ps,hasValue:Ss,getTablesJson:()=>St(Z),getValuesJson:()=>St($),getJson:()=>St([Z,$]),getTablesSchemaJson:()=>St(x),getValuesSchemaJson:()=>St(P),getSchemaJson:()=>St([x,P]),hasTablesSchema:()=>e,hasValuesSchema:()=>t,setContent:e=>rs((()=>{const t=O(e)?e():e;gt(t)&&(([e,t])=>{(ke(e)?ks:ys)(e),(ke(t)?Js:Vs)(t)})(t)})),setTables:ys,setTable:(e,t)=>rs((e=>ht(t,e)?Vt(e,t):0),e),setRow:(e,t,s)=>rs(((e,t)=>ft(e,t,s)?Mt(e,Jt(e),t,s):0),e,t),addRow:(e,t,s=!0)=>Qs((()=>{let n;return ft(e,n,t)&&(e=y(e),Mt(e,Jt(e),n=((e,t)=>{const[s]=Fe(q,e);let n;do{n=s(t)}while(ge(Fe(Z,e),n));return n})(e,s?1:0),t)),n})),setPartialRow:(e,t,s)=>rs(((e,t)=>{if(ft(e,t,s,1)){const n=Jt(e);Ee(s,((s,o)=>Et(e,n,t,o,s)))}}),e,t),setCell:(e,t,s,n)=>rs(((e,t,s)=>Q(It(e,t,s,O(n)?n(fs(e,t,s)):n),(n=>Et(e,Jt(e),t,s,n)))),e,t,s),setValues:Vs,setPartialValues:e=>rs((()=>bt(e,1)?Ee(e,((e,t)=>Ht(t,e))):0)),setValue:(e,t)=>rs((e=>Q(wt(e,O(t)?t(ws(e)):t),(t=>Ht(e,t)))),e),applyChanges:e=>rs((()=>{Ee(e[0],((e,t)=>F(e)?Ds(t):Ee(e,((e,s)=>F(e)?Hs(t,s):Ee(e,((e,n)=>le(Os,t,s,n,e))))))),Ee(e[1],((e,t)=>re(Os,t,e)))})),setTablesJson:Ms,setValuesJson:e=>{try{kt(pt(e))}catch{}return Os},setJson:e=>rs((()=>{try{const[t,s]=pt(e);vt(t),kt(s)}catch{Ms(e)}})),setTablesSchema:ms,setValuesSchema:Es,setSchema:(e,t)=>rs((()=>{ms(e),Es(t)})),delTables:ks,delTable:Ds,delRow:Hs,delCell:(e,t,s,n)=>rs(((e,t,s)=>Q(Fe(Z,e),(o=>Q(Fe(o,t),(l=>ge(l,s)?Qt(e,o,t,l,s,n):0))))),e,t,s),delValues:Js,delValue:e=>rs((e=>ge($,e)?zt(e):0),e),delTablesSchema:xs,delValuesSchema:Fs,delSchema:()=>rs((()=>{xs(),Fs()})),transaction:Qs,startTransaction:zs,getTransactionChanges:()=>[We(E,((e,t)=>-1===Fe(g,t)?void 0:We(e,((e,s)=>-1===Fe(Fe(M,t),s)?void 0:We(e,(([,e])=>e),(e=>_t(e)))),he,ke)),he,ke),We(D,(([,e])=>e),(e=>_t(e))),1],getTransactionLog:()=>[!he(E),!he(D),Pe(E,Pt,_t),Pe(H),We(D,Pt,_t),We(J),We(g),Ae(M),Pe(m),We(k)],finishTransaction:Ns,forEachTable:e=>be(Z,((t,s)=>e(s,(e=>be(t,((t,s)=>e(s,(e=>Qe(t,e))))))))),forEachTableCell:(e,t)=>Qe(Fe(Y,y(e)),t),forEachRow:(e,t)=>be(Fe(Z,y(e)),((e,s)=>t(s,(t=>Qe(e,t))))),forEachCell:(e,t,s)=>Qe(Fe(Fe(Z,y(e)),y(t)),s),forEachValue:e=>Qe($,e),addSortedRowIdsListener:(e,t,s,n,o,l,r)=>{let a=gs(e,t,s,n,o);return rt((()=>{const r=gs(e,t,s,n,o);U(r,a)||(a=r,l(Os,e,t,s,n,o,a))}),ve[r?1:0],[e,t],[is])},addStartTransactionListener:e=>rt(e,ot),addWillFinishTransactionListener:e=>rt(e,lt[0]),addDidFinishTransactionListener:e=>rt(e,lt[1]),callListener:e=>(dt(e),Os),delListener:e=>(ct(e),Os),getListenerStats:()=>({hasTables:Wt(te),tables:Wt(se),tableIds:Wt(oe),hasTable:Wt(ae),table:Wt(fe),tableCellIds:Wt(Le),hasTableCell:Wt(Ce,de),rowCount:Wt(Re),rowIds:Wt(Te),sortedRowIds:Wt(ve),hasRow:Wt(pe,de),row:Wt(ye,de),cellIds:Wt(me,de),hasCell:Wt(De,ue),cell:Wt(Ue,ue),invalidCell:Wt(Ke,ue),hasValues:Wt(Ye),values:Wt(Ze),valueIds:Wt(tt),hasValue:Wt(st),value:Wt(nt),invalidValue:Wt(Xe),transaction:ce(ot)+Wt(lt)}),isMergeable:()=>!1,createStore:Bt,addListener:rt,callListeners:it,setInternalListeners:(e,t,s,n,o)=>c=[e,t,s,n,o]};return Ee({[u+f]:[0,te,[],()=>[Ls()]],[f]:[0,se],[I]:[0,oe],[u+h]:[1,ae,[is],e=>[Cs(...e)]],[h]:[1,fe,[is]],[h+T]:[1,Le,[is]],[u+h+R]:[2,Ce,[is,cs],e=>[Rs(...e)]],[w]:[1,Re,[is]],[L]:[1,Te,[is]],[u+b]:[2,pe,[is,us],e=>[Ts(...e)]],[b]:[2,ye,[is,us]],[T]:[2,me,[is,us]],[u+R]:[3,De,[is,us,hs],e=>[vs(...e)]],[R]:[3,Ue,[is,us,hs],e=>Ot(fs(...e))],InvalidCell:[3,Ke],[u+p]:[0,Ye,[],()=>[ps()]],[p]:[0,Ze],[S]:[0,tt],[u+v]:[1,st,[bs],e=>[Ss(...e)]],[v]:[1,nt,[bs],e=>Ot(ws(e[0]))],InvalidValue:[1,Xe]},(([e,t,s,n],o)=>{Os[d+o+i]=(...o)=>rt(o[e],t[o[e+1]?1:0],e>0?A(o,0,e):void 0,s,n)})),Se(Os)},Ut={HasTable:1,Table:1,TableCellIds:1,HasTableCell:2,RowCount:1,RowIds:1,SortedRowIds:5,HasRow:2,Row:2,CellIds:2,HasCell:3,Cell:3,HasValue:1,Value:1,InvalidCell:3,InvalidValue:1},qt=(e=t)=>[Ft(e),Ft(e)],Gt=e=>{let s=1,n=qt(),o=0;const l=Je(),r=qe(),[a,c]=(e=>{let t=0,s=-1;const n=Q(e,(e=>{const t=bt(e);return ot(t/Ct)+ot(t/Rt)+ot(t/Tt)+ot(t/64)+ot(t)}),(()=>it(5))),o=e=>{const n=t,[o,l]=F(e)||""==e?[0,0]:[lt(r=e,0)*wt+lt(r,1)*Lt+lt(r,2)*Ct+lt(r,3)*Rt+lt(r,4)*Tt+64*lt(r,5)+lt(r,6),lt(r,7)*Rt+lt(r,8)*Tt+64*lt(r,9)+lt(r,10)];var r;t=D(n,o,E.HLC_TIME??Date.now()),s=t==n?t==o?D(s,l):s:t==o?l:-1};return[()=>{return o(),l=++s,ot((e=t)/wt)+ot(e/Lt)+ot(e/Ct)+ot(e/Rt)+ot(e/Tt)+ot(e/64)+ot(e)+ot(l/Rt)+ot(l/Tt)+ot(l/64)+ot(l)+n;var e,l},o]})(e),u=Bt(),g=e=>{const t=s;return s=0,e(),s=t,w},h=(e,s=0)=>{const o={},l={},[[r,a=t,i=0],d]=e,[u,g]=n,[h,I,b]=u;let w=s?i:b,L=a;me(r,(([e,n=t,l=0],r)=>{const a=Ne(h,r,Ft),[i,c,d]=a;let u=s?l:d,g=n;me(e,((e,t)=>{const[n,l,a]=f(e,Ne(i,t,Ft),De(De(o,r,ye),t,ye),s);u^=s?0:(l?kt(t,l):0)^kt(t,a),g=Ht(g,n)})),u^=s?0:Dt(c,n),Jt(a,n,u),w^=s?0:(d?kt(r,d):0)^kt(r,a[2]),L=Ht(L,g)})),w^=s?0:Dt(I,a),Jt(u,a,w);const[C]=f(d,g,l,s);return c(Ht(L,C)),[o,l,1]},f=(e,s,n,o)=>{const[l,r=t,a=0]=e,[i,c,d]=s;let u=r,g=o?a:d;return me(l,(([e,s=t,l=0],r)=>{const a=Ne(i,r,(()=>[void 0,t,0])),[,c,d]=a;(!c||s>c)&&(Jt(a,s,o?l:bt(St(e??null)+":"+s)),a[0]=e,n[r]=e,g^=o?0:kt(r,d)^kt(r,a[2]),u=Ht(u,s))})),g^=o?0:Dt(c,r),Jt(s,r,g),[u,d,s[2]]},I=()=>[Qt(n[0],(e=>Qt(e,(e=>Qt(e))))),Qt(n[1])],b=e=>g((()=>u.applyChanges(h(e)))),w={getMergeableContent:I,getMergeableContentHashes:()=>[n[0][2],n[1][2]],getMergeableTableHashes:()=>We(n[0][0],Et),getMergeableTableDiff:e=>{const t=xt(n[0][1]),s={};return Qe(n[0][0],((n,[o,l,r])=>Ve(e,n)?r!=e[n]?s[n]=r:0:t[0][n]=zt([o,l],(e=>zt(e))))),[t,s]},getMergeableRowHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n,,o])=>o!=e?Qe(n,((e,[,,n])=>De(t,s,ye)[e]=n)):0)))),t},getMergeableRowDiff:e=>{const t=xt(n[0][1]),s={};return me(e,((e,o)=>Qe(Fe(n[0][0],o)?.[0],((n,[l,r,a])=>Ve(e,n)?a!==e[n]?De(s,o,ye)[n]=a:0:De(t[0],o,xt)[0][n]=zt([l,r]))))),[t,s]},getMergeableCellHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n])=>me(e,((e,o)=>Q(Fe(n,o),(([n,,l])=>l!==e?Qe(n,((e,[,,n])=>De(De(t,s,ye),o,ye)[e]=n)):0)))))))),t},getMergeableCellDiff:e=>{const[[t,s]]=n,o={};return me(e,((e,s)=>me(e,((e,n)=>Q(Fe(t,s),(([t,l])=>Q(Fe(t,n),(([t,r])=>Qe(t,((t,[a,i,c])=>c!==e[t]?De(De(o,s,(()=>xt(l)))[0],n,(()=>xt(r)))[0][t]=[a,i]:0)))))))))),Mt(o,s)},getMergeableValueHashes:()=>We(n[1][0],Et),getMergeableValueDiff:e=>{const[,[t,s]]=n,o=We(t,yt,(([,,t],s)=>t==e?.[s]));return Mt(o,s)},setMergeableContent:e=>g((()=>(e=>W(e)&&2==P(e)&&Nt(e[0],(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,oe)),void 0,1)))),void 0,1)))),void 0,1)))&&Nt(e[1],(e=>He(e,(e=>Nt(e,oe)),void 0,1))))(e)?u.transaction((()=>{u.delTables().delValues(),n=qt(),u.applyChanges(h(e,1))})):0)),setDefaultContent:e=>(u.transaction((()=>{o=1,u.setContent(e),o=0})),w),getTransactionMergeableChanges:(e=!1)=>{const[[t,s,o],[a,i,c]]=n,d=e?mt:Mt,u={};be(l,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const l={};be(e,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const r={};be(e,(e=>{Q(Fe(t,e),(([t,s,n])=>r[e]=d(t,s,n)))})),l[s]=d(r,n,o)})))),u[s]=d(l,n,o)}))));const g={};return be(r,(e=>Q(Fe(a,e),(([t,s,n])=>g[e]=d(t,s,n))))),[d(u,s,o),d(g,i,c),1]},applyMergeableChanges:b,merge:e=>{const t=I(),s=e.getMergeableContent();return e.applyMergeableChanges(t),b(s)}};return u.setInternalListeners((()=>{}),(()=>{}),(()=>{Ie(l),Ie(r)}),((e,n,r,i)=>{Ge(Ne(Ne(l,e,Je),n,qe),r),s&&h([[{[e]:[{[n]:[{[r]:[i,o?t:a()]}]}]}],[{}],1])}),((e,n)=>{Ge(r,e),s&&h([[{}],[{[e]:[n,o?t:a()]}],1])})),Ee(u,((e,t)=>w[t]=V(t,"set")||V(t,"del")||V(t,"apply")||M(t,"Transaction")||t=="call"+i?(...t)=>(e(...t),w):V(t,d)&&M(t,i)?(...s)=>{const n=Ut[A(t,3,-8)]??0,o=s[n];return s[n]=(e,...t)=>o(w,...t),e(...s)}:"isMergeable"==t?()=>!0:e)),Se(w)};export{tt as createCheckpoints,ct as createIndexes,Gt as createMergeableStore,gt as createMetrics,ht as createQueries,ft as createRelationships,Bt as createStore,at as defaultSorter,it as getUniqueId};
1
+ const e=e=>typeof e,t="",s=e(t),n=e(!0),o=e(0),l=e(e),r="type",a="default",i="Listener",c="Result",d="add",u="Has",g="Ids",h="Table",f=h+"s",I=h+g,b="Row",w=b+"Count",L=b+g,C="Sorted"+b+g,R="Cell",T=R+g,v="Value",p=v+"s",S=v+g,y=e=>t+e,V=(e,t)=>e.startsWith(t),M=(e,t)=>e.endsWith(t),m=(e,s=t,n)=>e.split(s,n),E=globalThis,k=Math,D=k.max,H=k.min,J=k.floor,x=isFinite,F=e=>null==e,Q=(e,t,s)=>F(e)?s?.():t(e),z=e=>e==s||e==n,N=t=>e(t)==s,O=t=>e(t)==l,W=e=>Array.isArray(e),A=(e,t,s)=>e.slice(t,s),P=e=>e.length,_=()=>{},j=(e,t)=>e.includes(t),B=(e,t)=>e.every(t),U=(e,t)=>P(e)===P(t)&&B(e,((e,s)=>t[s]===e)),q=(e,t)=>B(e,((s,n)=>0==n||t(e[n-1],s)<=0)),G=(e,t)=>e.sort(t),K=(e,t)=>e.forEach(t),X=(e,t)=>e.map(t),Y=e=>$(e,((e,t)=>e+t),0),Z=e=>0==P(e),$=(e,t,s)=>e.reduce(t,s),ee=(e,...t)=>e.push(...t),te=e=>e.pop(),se=e=>e.shift(),ne=t=>{const s=e(t);return z(s)||s==o&&x(t)?s:void 0},oe=e=>F(e)||!F(ne(e)),le=(e,t,s,n,o)=>F(o)?e.delCell(t,s,n,!0):e.setCell(t,s,n,o),re=(e,t,s)=>F(s)?e.delValue(t):e.setValue(t,s),ae=e=>t=>$(fe(t),((t,s)=>t+e(s)),0),ie=e=>e?.size??0,ce=ae(ie),de=ae(ce),ue=ae(de),ge=(e,t)=>e?.has(t)??!1,he=e=>F(e)||0==ie(e),fe=e=>[...e?.values()??[]],Ie=e=>e.clear(),be=(e,t)=>e?.forEach(t),we=(e,t)=>e?.delete(t),Le=Object,Ce=e=>Le.getPrototypeOf(e),Re=Le.entries,Te=Le.isFrozen,ve=e=>!F(e)&&Q(Ce(e),(e=>e==Le.prototype||F(Ce(e))),(()=>!0)),pe=Le.keys,Se=Le.freeze,ye=(e=[])=>Le.fromEntries(e),Ve=(e,t)=>t in e,Me=(e,t)=>(delete e[t],e),me=(e,t)=>K(Re(e),(([e,s])=>t(s,e))),Ee=(e,t)=>ye(((e,t)=>X(Re(e),(([e,s])=>t(s,e))))(e,((e,s)=>[s,t(e,s)]))),ke=e=>ve(e)&&0==(e=>P(pe(e)))(e),De=(e,t,s)=>(Ve(e,t)||(e[t]=s()),e[t]),He=(e,t,s,n=0)=>F(e)||!ve(e)||!n&&ke(e)||Te(e)?(s?.(),!1):(me(e,((s,n)=>{t(s,n)||Me(e,n)})),!!n||!ke(e)),Je=e=>new Map(e),xe=e=>[...e?.keys()??[]],Fe=(e,t)=>e?.get(t),Qe=(e,t)=>be(e,((e,s)=>t(s,e))),ze=(e,t,s)=>F(s)?(we(e,t),e):e?.set(t,s),Ne=(e,t,s,n)=>(ge(e,t)?n?.(Fe(e,t)):ze(e,t,s()),Fe(e,t)),Oe=(e,t,s,n=ze)=>(Ee(t,((t,n)=>s(e,n,t))),Qe(e,(s=>Ve(t,s)?0:n(e,s))),e),We=(e,t,s,n)=>{const o={};return be(e,((e,l)=>{if(!s?.(e,l)){const s=t?t(e,l):e;n?.(s)||(o[l]=s)}})),o},Ae=(e,t,s)=>We(e,(e=>We(e,t,s)),he,ke),Pe=(e,t,s)=>We(e,(e=>Ae(e,t,s)),he,ke),_e=(e,t)=>{const s=Je();return be(e,((e,n)=>s.set(n,t?.(e)??e))),s},je=e=>_e(e,_e),Be=e=>_e(e,je),Ue=(e,t,s,n,o=0)=>Q((s?Ne:Fe)(e,t[o],o>P(t)-2?s:Je),(l=>{if(o>P(t)-2)return n?.(l)&&ze(e,t[o]),l;const r=Ue(l,t,s,n,o+1);return he(l)&&ze(e,t[o]),r})),qe=e=>new Set(W(e)||F(e)?e:[e]),Ge=(e,t)=>e?.add(t),Ke=(e,t,s,n,o)=>{const l=e.hasRow,r=Je(),a=Je(),i=Je(),c=Je(),d=Je(),u=Je(),g=(t,s,...n)=>{const o=Ne(u,t,qe);return K(n,(t=>Ge(o,t)&&s&&e.callListener(t))),n},h=(t,...s)=>Q(Fe(u,t),(n=>{K(Z(s)?fe(n):s,(t=>{e.delListener(t),we(n,t)})),he(n)&&ze(u,t)})),f=(e,s)=>{ze(r,e,s),ge(a,e)||(ze(a,e,t()),ze(c,e,Je()),ze(d,e,Je()),o(i))},I=e=>{ze(r,e),ze(a,e),ze(c,e),ze(d,e),h(e),o(i)};return[()=>e,()=>xe(r),e=>Qe(a,e),e=>ge(a,e),e=>Fe(r,e),e=>Fe(a,e),(e,t)=>ze(a,e,t),f,(t,n,o,r,a)=>{f(t,n);const i=Je(),u=Je(),I=Fe(c,t),b=Fe(d,t),w=t=>{const o=s=>e.getCell(n,t,s),c=Fe(I,t),d=l(n,t)?s(r(o,t)):void 0;if(c===d||W(c)&&W(d)&&U(c,d)||ze(i,t,[c,d]),!F(a)){const e=Fe(b,t),s=l(n,t)?a(o,t):void 0;e!=s&&ze(u,t,s)}},L=e=>{o((()=>{be(i,(([,e],t)=>ze(I,t,e))),be(u,((e,t)=>ze(b,t,e)))}),i,u,I,b,e),Ie(i),Ie(u)};Qe(I,w),e.hasTable(n)&&K(e.getRowIds(n),(e=>{ge(I,e)||w(e)})),L(!0),h(t),g(t,0,e.addRowListener(n,null,((e,t,s)=>w(s))),e.addTableListener(n,(()=>L())))},I,e=>n(e,i),()=>Qe(u,I),g,h]},Xe=(e,s)=>N(e)?t=>t(e):e??(()=>s??t),Ye=(e,t)=>{const s=new WeakMap;return n=>{s.has(n)||s.set(n,e(n));const o=s.get(n);return t?.(o),o}},Ze=/^\d+$/,$e=()=>{const e=[];let s=0;return[n=>(n?se(e):null)??t+s++,t=>{Ze.test(t)&&P(e)<1e3&&ee(e,t)}]},et=e=>{let s;const[n,o]=$e(),l=Je();return[(o,r,a,i=[],c=()=>[])=>{s??=e();const d=n(1);return ze(l,d,[o,r,a,i,c]),Ge(Ue(r,a??[t],qe),d),d},(e,n,...o)=>K(((e,s=[t])=>{const n=[],o=(e,t)=>t==P(s)?ee(n,e):null===s[t]?be(e,(e=>o(e,t+1))):K([s[t],null],(s=>o(Fe(e,s),t+1)));return o(e,0),n})(e,n),(e=>be(e,(e=>Fe(l,e)[0](s,...n??[],...o))))),e=>Q(Fe(l,e),(([,s,n])=>(Ue(s,n??[t],void 0,(t=>(we(t,e),he(t)?1:0))),ze(l,e),o(e),n))),e=>Q(Fe(l,e),(([e,,t=[],n,o])=>{const l=(...r)=>{const a=P(r);a==P(t)?e(s,...r,...o(r)):F(t[a])?K(n[a]?.(...r)??[],(e=>l(...r,e))):l(...r,t[a])};l()}))]},tt=Ye((e=>{let s,n,o,l=100,r=Je(),a=Je(),i=1;const c=Je(),d=Je(),[u,g,h]=et((()=>J)),f=Je(),I=Je(),b=[],w=[],L=(t,s)=>{i=0,e.transaction((()=>{const[n,o]=Fe(f,s);be(n,((s,n)=>be(s,((s,o)=>be(s,((s,l)=>le(e,n,o,l,s[t]))))))),be(o,((s,n)=>re(e,n,s[t])))})),i=1},C=e=>{ze(f,e),ze(I,e),g(d,[e])},R=(e,t)=>K(((e,t)=>e.splice(0,t))(e,t??P(e)),C),T=()=>R(b,P(b)-l),v=()=>Q(s,(()=>{ee(b,s),T(),R(w),s=void 0,o=1})),p=()=>{s=te(b),o=1};let S,y;const V=(e=t)=>(F(s)&&(s=t+n++,ze(f,s,[r,a]),D(s,e),r=Je(),a=Je(),o=1),s),M=()=>{Z(b)||(((e,...t)=>{e.unshift(...t)})(w,V()),L(0,s),s=te(b),o=1)},m=()=>{Z(w)||(ee(b,s),s=se(w),L(1,s),o=1)},E=()=>{o&&(g(c),o=0)},k=e=>{const t=V(e);return E(),t},D=(e,t)=>(H(e)&&Fe(I,e)!==t&&(ze(I,e,t),g(d,[e])),J),H=e=>ge(f,e),J={setSize:e=>(l=e,T(),J),addCheckpoint:k,setCheckpoint:D,getStore:()=>e,getCheckpointIds:()=>[[...b],s,[...w]],forEachCheckpoint:e=>Qe(I,e),hasCheckpoint:H,getCheckpoint:e=>Fe(I,e),goBackward:()=>(M(),E(),J),goForward:()=>(m(),E(),J),goTo:e=>{const t=j(b,e)?M:j(w,e)?m:null;for(;!F(t)&&e!=s;)t();return E(),J},addCheckpointIdsListener:e=>u(e,c),addCheckpointListener:(e,t)=>u(t,d,[e]),delListener:e=>(h(e),J),clear:()=>(R(b),R(w),F(s)||C(s),s=void 0,n=0,k(),J),clearForward:()=>(Z(w)||(R(w),g(c)),J),destroy:()=>{e.delListener(S),e.delListener(y)},getListenerStats:()=>({checkpointIds:ce(c),checkpoint:ce(d)}),_registerListeners:()=>{S=e.addCellListener(null,null,null,((e,t,s,n,o,l)=>{if(i){v();const e=Ne(r,t,Je),a=Ne(e,s,Je),i=Ne(a,n,(()=>[l,void 0]));i[1]=o,i[0]===o&&he(ze(a,n))&&he(ze(e,s))&&he(ze(r,t))&&p(),E()}})),y=e.addValueListener(null,((e,t,s,n)=>{if(i){v();const e=Ne(a,t,(()=>[n,void 0]));e[1]=s,e[0]===s&&he(ze(a,t))&&p(),E()}}))}};return Se(J.clear())}),(e=>e._registerListeners())),st=m("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),nt=Je(X(st,((e,t)=>[e,t]))),ot=e=>st[63&e],lt=(e,t)=>Fe(nt,e[t])??0,rt=E.crypto?e=>E.crypto.getRandomValues(e):e=>X(e,(()=>J(256*k.random()))),at=(e,t)=>(e??0)<(t??0)?-1:1,it=(e=16)=>$(rt(new Uint8Array(e)),((e,t)=>e+ot(t)),""),ct=Ye((e=>{const s=Je(),n=Je(),[o,l,r]=et((()=>C)),[a,i,c,d,u,g,h,,f,I,b,w]=Ke(e,Je,(e=>F(e)?t:W(e)?X(e,y):y(e)),o,l),L=(t,s,n)=>{const o=u(t);be(n,((t,n)=>s(n,(s=>be(t,(t=>s(t,(s=>e.forEachCell(o,t,s)))))))))},C={setIndexDefinition:(e,t,o,r,a,i=at)=>{const c=F(a)?void 0:([e],[t])=>a(e,t);return f(e,t,((t,o,a,d,u,f)=>{let I=0;const b=qe(),w=qe(),L=g(e);if(be(o,(([e,t],s)=>{const n=qe(e),o=qe(t);be(n,(e=>we(o,e)?we(n,e):0)),be(n,(e=>{Ge(b,e),Q(Fe(L,e),(t=>{we(t,s),he(t)&&(ze(L,e),I=1)}))})),be(o,(e=>{Ge(b,e),ge(L,e)||(ze(L,e,qe()),I=1),Ge(Fe(L,e),s),F(r)||Ge(w,e)}))})),t(),he(u)||(f?Qe(L,(e=>Ge(w,e))):Qe(a,(e=>Q(Fe(d,e),(e=>K(W(e)?e:[e],(e=>Ge(w,e))))))),be(w,(e=>{const t=(t,s)=>i(Fe(u,t),Fe(u,s),e),s=[...Fe(L,e)];q(s,t)||(ze(L,e,qe(G(s,t))),Ge(b,e))}))),(I||f)&&!F(c)){const t=[...L];q(t,c)||(h(e,Je(G(t,c))),I=1)}I&&l(s,[e]),be(b,(t=>l(n,[e,t])))}),Xe(o),Q(r,Xe)),C},delIndexDefinition:e=>(I(e),C),getStore:a,getIndexIds:i,forEachIndex:e=>c(((t,s)=>e(t,(e=>L(t,e,s))))),forEachSlice:(e,t)=>L(e,t,g(e)),hasIndex:d,hasSlice:(e,t)=>ge(g(e),t),getTableId:u,getSliceIds:e=>xe(g(e)),getSliceRowIds:(e,t)=>fe(Fe(g(e),t)),addIndexIdsListener:b,addSliceIdsListener:(e,t)=>o(t,s,[e]),addSliceRowIdsListener:(e,t,s)=>o(s,n,[e,t]),delListener:e=>(r(e),C),destroy:w,getListenerStats:()=>({sliceIds:ce(s),sliceRowIds:de(n)})};return Se(C)})),dt=Je([["avg",[(e,t)=>Y(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>D(...e),(e,t)=>D(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:D(t,e)]],["min",[e=>H(...e),(e,t)=>H(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:H(t,e)]],["sum",[e=>Y(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),ut=(e,t,s,n,o,l=!1)=>{if(he(s))return;const[r,a,i,c]=o;return l||=F(e),be(n,(([s,n])=>{l||(e=F(s)?a?.(e,n,t++):F(n)?i?.(e,s,t--):c?.(e,n,s,t),l||=F(e))})),l?r(fe(s),ie(s)):e},gt=Ye((e=>{const s=Je(),[n,o,l]=et((()=>w)),[r,a,i,c,d,u,g,,h,f,I,b]=Ke(e,_,(e=>isNaN(e)||F(e)||!0===e||!1===e||e===t?void 0:1*e),n,o),w={setMetricDefinition:(e,t,n,l,r,a,i)=>{const c=O(n)?[n,r,a,i]:Fe(dt,n)??Fe(dt,"sum");return h(e,t,((t,n,l,r,a,i)=>{const d=u(e),h=ie(r);i||=F(d),t();let f=ut(d,h,r,n,c,i);x(f)||(f=void 0),f!=d&&(g(e,f),o(s,[e],f,d))}),Xe(l,1)),w},delMetricDefinition:e=>(f(e),w),getStore:r,getMetricIds:a,forEachMetric:i,hasMetric:c,getTableId:d,getMetric:u,addMetricIdsListener:I,addMetricListener:(e,t)=>n(t,s,[e]),delListener:e=>(l(e),w),destroy:b,getListenerStats:()=>({metric:ce(s)})};return Se(w)})),ht=Ye((e=>{const s=e.createStore,n=s(),o=s(),l=Je(),{addListener:r,callListeners:a,delListener:u}=o,[g,f,I,v,p,,,S,,y,V,M,m,E]=Ke(e,(()=>!0),_,r,a),k=(e,t,...s)=>K(s,(s=>Ge(Ne(Ne(l,t,Je),e,qe),s))),D=e=>{Q(Fe(l,e),(e=>{Qe(e,((e,t)=>be(t,(t=>e.delListener(t))))),Ie(e)})),K([o,n],(t=>t.delTable(e)))},H=(e,t,s)=>k(t,e,t.addStartTransactionListener(s.startTransaction),t.addDidFinishTransactionListener((()=>s.finishTransaction()))),J={setQueryDefinition:(s,l,r)=>{S(s,l),D(s);const a=[],i=[[null,[l,null,null,[],Je()]]],c=[],d=[],u=[];r({select:(e,s)=>{const n=O(e)?[P(a)+t,e]:[F(s)?e:s,t=>t(e,s)];return ee(a,n),{as:e=>n[0]=e}},join:(e,t,s)=>{const n=F(s)||O(t)?null:t,o=F(n)?t:s,l=[e,[e,n,O(o)?o:e=>e(o),[],Je()]];return ee(i,l),{as:e=>l[0]=e}},where:(e,t,s)=>ee(c,O(e)?e:F(s)?s=>s(e)===t:n=>n(e,t)===s),group:(e,t,s,n,o)=>{const l=[e,[e,O(t)?[t,s,n,o]:Fe(dt,t)??[(e,t)=>t]]];return ee(d,l),{as:e=>l[0]=e}},having:(e,t)=>ee(u,O(e)?e:s=>s(e)===t)});const g=Je(a);if(he(g))return J;const h=Je(i);Qe(h,((e,[,t])=>Q(Fe(h,t),(({3:t})=>F(e)?0:ee(t,e)))));const f=Je(d);let I=n;if(he(f)&&Z(u))I=o;else{H(s,I,o);const e=Je();Qe(f,((t,[s,n])=>Ge(Ne(e,s,qe),[t,n])));const t=qe();Qe(g,(s=>ge(e,s)?0:Ge(t,s)));const n=Je(),l=(t,n,l,r)=>Q(t,(([a,i,c,d])=>{Qe(n,((t,[s])=>{const n=Ne(a,t,Je),o=Fe(n,l),i=r?void 0:s;if(o!==i){const s=qe([[o,i]]),r=ie(n);ze(n,l,i),be(Fe(e,t),(([e,t])=>{const o=ut(d[e],r,n,s,t);d[e]=F(ne(o))?null:o}))}})),he(i)||!B(u,(e=>e((e=>d[e]))))?o.delRow(s,c):F(c)?t[2]=o.addRow(s,d):o.setRow(s,c,d)}));k(I,s,I.addRowListener(s,null,((o,r,a,i)=>{const c=[],d=[],u=Je(),g=I.hasRow(s,a);let h=!g;be(t,(e=>{const[t,n,o]=i(s,a,e);ee(c,n),ee(d,o),h||=t})),Qe(e,(e=>{const[t,,n]=i(s,a,e);(h||t)&&ze(u,e,[n])})),h&&l(Ue(n,c,void 0,(([,e])=>(we(e,a),he(e)))),u,a,1),g&&l(Ue(n,d,(()=>{const e={};return be(t,(t=>e[t]=I.getCell(s,a,t))),[Je(),qe(),void 0,e]}),(([,e])=>{Ge(e,a)})),u,a)})))}H(s,e,I);const b=(t,n,o,r)=>{const a=t=>e.getCell(n,o,t);K(r,(n=>{const[o,,l,r,i]=Fe(h,n),c=l?.(a,t),[d,u]=Fe(i,t)??[];c!=d&&(F(u)||E(s,u),ze(i,t,F(c)?null:[c,...m(s,1,e.addRowListener(o,c,(()=>b(t,o,c,r))))]))})),(t=>{const n=(s,n)=>e.getCell(...F(n)?[l,t,s]:s===l?[l,t,n]:[Fe(h,s)?.[0],Fe(Fe(h,s)?.[4],t)?.[0],n]);I.transaction((()=>B(c,(e=>e(n)))?Qe(g,((e,o)=>le(I,s,t,e,o(n,t)))):I.delRow(s,t)))})(t)},{3:w}=Fe(h,null);return I.transaction((()=>m(s,1,e.addRowListener(l,null,((t,n,o)=>{e.hasRow(l,o)?b(o,l,o,w):(I.delRow(s,o),be(h,(({4:e})=>Q(Fe(e,o),(([,t])=>{E(s,t),ze(e,o)})))))}))))),J},delQueryDefinition:e=>(D(e),y(e),J),getStore:g,getQueryIds:f,forEachQuery:I,hasQuery:v,getTableId:p,addQueryIdsListener:e=>V((()=>e(J))),delListener:e=>(u(e),J),destroy:M,getListenerStats:()=>{const{tables:e,tableIds:t,transaction:s,...n}=o.getListenerStats();return n}};return Ee({[h]:[1,1],[h+T]:[0,1],[w]:[0,1],[L]:[0,1],[C]:[0,5],[b]:[1,2],[T]:[0,2],[R]:[1,3]},(([e,t],s)=>{K(e?["get","has","forEach"]:["get"],(e=>J[e+c+s]=(...t)=>o[e+s](...t))),J[d+c+s+i]=(...e)=>o[d+s+i](...A(e,0,t),((s,...n)=>e[t](J,...n)),!0)})),Se(J)})),ft=Ye((e=>{const s=Je(),n=Je(),o=Je(),l=Je(),[r,a,i]=et((()=>v)),[c,d,u,g,h,f,,,I,b,w,L]=Ke(e,(()=>[Je(),Je(),Je(),Je()]),(e=>F(e)?void 0:e+t),r,a),C=(e,t,s)=>Q(f(e),(([n,,o])=>{if(!ge(o,t)){const l=qe();if(h(e)!=T(e))Ge(l,t);else{let e=t;for(;!F(e)&&!ge(l,e);)Ge(l,e),e=Fe(n,e)}if(s)return l;ze(o,t,l)}return Fe(o,t)})),R=(e,t)=>Q(f(e),(([,,e])=>ze(e,t))),T=e=>Fe(s,e),v={setRelationshipDefinition:(e,t,r,i)=>(ze(s,e,r),I(e,t,((t,s)=>{const r=qe(),i=qe(),c=qe(),[d,u]=f(e);be(s,(([t,s],n)=>{F(t)||(Ge(i,t),Q(Fe(u,t),(e=>{we(e,n),he(e)&&ze(u,t)}))),F(s)||(Ge(i,s),ge(u,s)||ze(u,s,qe()),Ge(Fe(u,s),n)),Ge(r,n),ze(d,n,s),Qe(Fe(l,e),(t=>{ge(C(e,t),n)&&Ge(c,t)}))})),t(),be(r,(t=>a(n,[e,t]))),be(i,(t=>a(o,[e,t]))),be(c,(t=>{R(e,t),a(l,[e,t])}))}),Xe(i)),v),delRelationshipDefinition:e=>(ze(s,e),b(e),v),getStore:c,getRelationshipIds:d,forEachRelationship:t=>u((s=>t(s,(t=>e.forEachRow(h(s),t))))),hasRelationship:g,getLocalTableId:h,getRemoteTableId:T,getRemoteRowId:(e,t)=>Fe(f(e)?.[0],t),getLocalRowIds:(e,t)=>fe(Fe(f(e)?.[1],t)),getLinkedRowIds:(e,t)=>F(f(e))?[t]:fe(C(e,t,!0)),addRelationshipIdsListener:w,addRemoteRowIdListener:(e,t,s)=>r(s,n,[e,t]),addLocalRowIdsListener:(e,t,s)=>r(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(C(e,t),r(s,l,[e,t])),delListener:e=>(R(...i(e)??[]),v),destroy:L,getListenerStats:()=>({remoteRowId:de(n),localRowIds:de(o),linkedRowIds:de(l)})};return Se(v)})),It=new E.TextEncoder,bt=e=>{let t=2166136261;return K(It.encode(e),(e=>{t^=e,t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)})),t>>>0},wt=2**36,Lt=2**30,Ct=2**24,Rt=2**18,Tt=4096,vt=JSON.stringify,pt=JSON.parse,St=e=>vt(e,((e,t)=>t instanceof Map?Le.fromEntries([...t]):t)),yt=([e,t])=>Mt(e,t),Vt=([e,t,s])=>[e,t,s],Mt=(e,t)=>t?[e,t]:[e],mt=(e,t,s)=>[e,t,s],Et=e=>e[2],kt=(e,t)=>bt(e+":"+t),Dt=(e,t)=>t>e?(e?bt(e):0)^bt(t):0,Ht=(e,t)=>((e??"")>(t??"")?e:t)??"",Jt=(e,t,s)=>{t>e[1]&&(e[1]=t),e[2]=s>>>0},xt=(e=t)=>Mt(ye(),e),Ft=(e=t)=>[Je(),e,0],Qt=([e,t,s],n=Vt)=>[We(e,n),t,s],zt=([e,t],s=yt)=>Mt(We(e,s),t),Nt=(t,s)=>W(t)&&3==P(t)&&N(t[1])&&e(t[2])==o&&x(t[2])&&s(t[0]),Ot=e=>[e,e],Wt=(e,t=ce)=>t(e[0])+t(e[1]),At=()=>[Je(),Je()],Pt=e=>[...e],_t=([e,t])=>e===t,jt=(e,t,s)=>ze(e,t,Fe(e,t)==-s?void 0:s),Bt=()=>{let e,t,s=!1,n=!1,l=0,c=[];const g=Je(),C=Je(),V=Je(),M=Je(),m=Je(),E=Je(),k=Je(),D=Je(),H=Je(),J=Je(),x=Je(),N=Je(),P=Je(),_=Je(),B=qe(),q=Je(),Y=Je(),Z=Je(),$=Je(),te=At(),se=At(),oe=At(),ae=At(),fe=At(),Le=At(),Ce=At(),Re=At(),Te=At(),ve=At(),pe=At(),ye=At(),me=At(),De=At(),Ue=At(),Ke=At(),Xe=At(),Ye=At(),Ze=At(),tt=At(),st=At(),nt=At(),ot=Je(),lt=At(),[rt,it,ct,dt]=et((()=>Os)),ut=e=>{if(!He(e,((e,t)=>j([r,a],t))))return!1;const t=e[r];return!(!z(t)&&t!=o||(ne(e[a])!=t&&Me(e,a),0))},gt=W,ht=(t,s)=>(!e||ge(x,s)||Yt(s))&&He(t,((e,t)=>ft(s,t,e)),(()=>Yt(s))),ft=(e,t,s,n)=>He(n?s:Lt(s,e,t),((n,o)=>Q(It(e,t,o,n),(e=>(s[o]=e,!0)),(()=>!1))),(()=>Yt(e,t))),It=(t,s,n,o)=>e?Q(Fe(Fe(x,t),n),(e=>ne(o)!=e[r]?Yt(t,s,n,o,e[a]):o),(()=>Yt(t,s,n,o))):F(ne(o))?Yt(t,s,n,o):o,bt=(e,t)=>He(t?e:Ct(e),((t,s)=>Q(wt(s,t),(t=>(e[s]=t,!0)),(()=>!1))),(()=>Zt())),wt=(e,s)=>t?Q(Fe(P,e),(t=>ne(s)!=t[r]?Zt(e,s,t[a]):s),(()=>Zt(e,s))):F(ne(s))?Zt(e,s):s,Lt=(e,t,s)=>(Q(Fe(N,t),(([n,o])=>{be(n,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(o,(n=>{Ve(e,n)||Yt(t,s,n)}))})),e),Ct=e=>(t&&(be(_,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(B,(t=>{Ve(e,t)||Zt(t)}))),e),Rt=e=>Oe(x,e,((e,t,s)=>{const n=Je(),o=qe();Oe(Ne(x,t,Je),s,((e,t,s)=>{ze(e,t,s),Q(s[a],(e=>ze(n,t,e)),(()=>Ge(o,t)))})),ze(N,t,[n,o])}),((e,t)=>{ze(x,t),ze(N,t)})),Tt=e=>Oe(P,e,((e,t,s)=>{ze(P,t,s),Q(s[a],(e=>ze(_,t,e)),(()=>Ge(B,t)))}),((e,t)=>{ze(P,t),ze(_,t),we(B,t)})),vt=e=>ke(e)?ks():ys(e),yt=e=>Oe(Z,e,((e,t,s)=>Vt(t,s)),((e,t)=>xt(t))),Vt=(e,t)=>Oe(Ne(Z,e,(()=>(Nt(e,1),ze(q,e,$e()),ze(Y,e,Je()),Je()))),t,((t,s,n)=>Mt(e,t,s,n)),((t,s)=>Ft(e,t,s))),Mt=(e,t,s,n,o)=>Oe(Ne(t,s,(()=>(Ut(e,s,1),Je()))),n,((t,n,o)=>mt(e,s,t,n,o)),((n,l)=>Qt(e,t,s,n,l,o))),mt=(e,t,s,n,o)=>{ge(s,n)||qt(e,t,n,1);const l=Fe(s,n);o!==l&&(Gt(e,t,n,l,o),ze(s,n,o))},Et=(e,t,s,n,o)=>Q(Fe(t,s),(t=>mt(e,s,t,n,o)),(()=>Mt(e,t,s,Lt({[n]:o},e,s)))),kt=e=>ke(e)?Js():Vs(e),Dt=e=>Oe($,e,((e,t,s)=>Ht(t,s)),((e,t)=>zt(t))),Ht=(e,t)=>{ge($,e)||Kt(e,1);const s=Fe($,e);t!==s&&(Xt(e,s,t),ze($,e,t))},Jt=e=>Fe(Z,e)??Vt(e,{}),xt=e=>Vt(e,{}),Ft=(e,t,s)=>{const[,n]=Fe(q,e);n(s),Mt(e,t,s,{},!0)},Qt=(e,t,s,n,o,l)=>{const r=Fe(Fe(N,e)?.[0],o);if(!F(r)&&!l)return mt(e,s,n,o,r);const a=t=>{Gt(e,s,t,Fe(n,t)),qt(e,s,t,-1),ze(n,t)};F(r)?a(o):Qe(n,a),he(n)&&(Ut(e,s,-1),he(ze(t,s))&&(Nt(e,-1),ze(Z,e),ze(q,e),ze(Y,e)))},zt=e=>{const t=Fe(_,e);if(!F(t))return Ht(e,t);Xt(e,Fe($,e)),Kt(e,-1),ze($,e)},Nt=(e,t)=>jt(g,e,t),Ut=(e,t,s)=>jt(Ne(M,e,Je),t,s)&&ze(V,e,Ne(V,e,(()=>0))+s),qt=(e,t,s,n)=>{const o=Fe(Y,e),l=Fe(o,s)??0;(0==l&&1==n||1==l&&-1==n)&&jt(Ne(C,e,Je),s,n),ze(o,s,l!=-n?l+n:null),jt(Ne(Ne(m,e,Je),t,Je),s,n)},Gt=(e,t,s,n,o)=>{Ne(Ne(Ne(E,e,Je),t,Je),s,(()=>[n,0]))[1]=o,c[3]?.(e,t,s,o)},Kt=(e,t)=>jt(k,e,t),Xt=(e,t,s)=>{Ne(D,e,(()=>[t,0]))[1]=s,c[4]?.(e,s)},Yt=(e,t,s,n,o)=>(ee(Ne(Ne(Ne(H,e,Je),t,Je),s,(()=>[])),n),o),Zt=(e,t,s)=>(ee(Ne(J,e,(()=>[])),t),s),$t=(e,t,s)=>Q(Fe(Fe(Fe(E,e),t),s),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(fs(e,t,s))])),es=e=>Q(Fe(D,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(ws(e))])),ts=e=>he(H)||he(Ke[e])?0:be(e?Be(H):H,((t,s)=>be(t,((t,n)=>be(t,((t,o)=>it(Ke[e],[s,n,o],t))))))),ss=e=>he(J)||he(Xe[e])?0:be(e?_e(J):J,((t,s)=>it(Xe[e],[s],t))),ns=(e,t,s,n)=>{if(!he(e))return it(t,n,(()=>We(e))),Qe(e,((e,t)=>it(s,[...n??[],e],1==t))),1},os=e=>{const t=Ls();t!=s&&it(te[e],void 0,t);const n=he(ve[e]),o=he(me[e])&&he(De[e])&&he(Te[e])&&he(pe[e])&&he(Le[e])&&he(Ce[e])&&he(Re[e])&&n&&he(oe[e])&&he(ae[e]),l=he(Ue[e])&&he(ye[e])&&he(fe[e])&&he(se[e]);if(!o||!l){const t=e?[_e(g),je(C),_e(V),je(M),Be(m),Be(E)]:[g,C,V,M,m,E];if(!o){ns(t[0],oe[e],ae[e]),be(t[1],((t,s)=>ns(t,Le[e],Ce[e],[s]))),be(t[2],((t,s)=>{0!=t&&it(Re[e],[s],ds(s))}));const s=qe();be(t[3],((t,o)=>{ns(t,Te[e],pe[e],[o])&&!n&&(it(ve[e],[o,null]),Ge(s,o))})),n||be(t[5],((t,n)=>{if(!ge(s,n)){const s=qe();be(t,(e=>be(e,(([t,n],o)=>n!==t?Ge(s,o):we(e,o))))),be(s,(t=>it(ve[e],[n,t])))}})),be(t[4],((t,s)=>be(t,((t,n)=>ns(t,me[e],De[e],[s,n])))))}if(!l){let s;be(t[5],((t,n)=>{let o;be(t,((t,l)=>{let r;be(t,(([t,a],i)=>{a!==t&&(it(Ue[e],[n,l,i],a,t,$t),s=o=r=1)})),r&&it(ye[e],[n,l],$t)})),o&&it(fe[e],[n],$t)})),s&&it(se[e],void 0,$t)}}},ls=e=>{const t=ps();t!=n&&it(Ye[e],void 0,t);const s=he(tt[e])&&he(st[e]),o=he(nt[e])&&he(Ze[e]);if(!s||!o){const t=e?[_e(k),_e(D)]:[k,D];if(s||ns(t[0],tt[e],st[e]),!o){let s;be(t[1],(([t,n],o)=>{n!==t&&(it(nt[e],[o],n,t,es),s=1)})),s&&it(Ze[e],void 0,es)}}},rs=(e,...t)=>(Qs((()=>e(...X(t,y)))),Os),as=()=>Pe(Z),is=()=>xe(Z),cs=e=>xe(Fe(Y,y(e))),ds=e=>ie(Fe(Z,y(e))),us=e=>xe(Fe(Z,y(e))),gs=(e,t,s,n=0,o)=>{return X(A(G((l=Fe(Z,y(e)),r=(e,s)=>[F(t)?s:Fe(e,y(t)),s],X([...l?.entries()??[]],(([e,t])=>r(t,e)))),(([e],[t])=>at(e,t)*(s?-1:1))),n,F(o)?o:n+o),(([,e])=>e));var l,r},hs=(e,t)=>xe(Fe(Fe(Z,y(e)),y(t))),fs=(e,t,s)=>Fe(Fe(Fe(Z,y(e)),y(t)),y(s)),Is=()=>We($),bs=()=>xe($),ws=e=>Fe($,y(e)),Ls=()=>!he(Z),Cs=e=>ge(Z,y(e)),Rs=(e,t)=>ge(Fe(Y,y(e)),y(t)),Ts=(e,t)=>ge(Fe(Z,y(e)),y(t)),vs=(e,t,s)=>ge(Fe(Fe(Z,y(e)),y(t)),y(s)),ps=()=>!he($),Ss=e=>ge($,y(e)),ys=e=>rs((()=>(e=>He(e,ht,Yt))(e)?yt(e):0)),Vs=e=>rs((()=>bt(e)?Dt(e):0)),Ms=e=>{try{vt(pt(e))}catch{}return Os},ms=t=>rs((()=>{if((e=He(t,(e=>He(e,ut))))&&(Rt(t),!he(Z))){const e=as();ks(),ys(e)}})),Es=e=>rs((()=>{if(t=(e=>He(e,ut))(e)){const s=Is();Fs(),Js(),t=!0,Tt(e),Vs(s)}})),ks=()=>rs((()=>yt({}))),Ds=e=>rs((e=>ge(Z,e)?xt(e):0),e),Hs=(e,t)=>rs(((e,t)=>Q(Fe(Z,e),(s=>ge(s,t)?Ft(e,s,t):0))),e,t),Js=()=>rs((()=>Dt({}))),xs=()=>rs((()=>{Rt({}),e=!1})),Fs=()=>rs((()=>{Tt({}),t=!1})),Qs=(e,t)=>{if(-1!=l){zs();const s=e();return Ns(t),s}},zs=()=>(-1!=l&&l++,1==l&&(c[0]?.(),it(ot)),Os),Ns=e=>(l>0&&(l--,0==l&&(l=1,ts(1),he(E)||os(1),ss(1),he(D)||ls(1),e?.(Os)&&(be(E,((e,t)=>be(e,((e,s)=>be(e,(([e],n)=>le(Os,t,s,n,e))))))),Ie(E),be(D,(([e],t)=>re(Os,t,e))),Ie(D)),it(lt[0],void 0),l=-1,ts(0),he(E)||os(0),ss(0),he(D)||ls(0),c[1]?.(),it(lt[1],void 0),c[2]?.(),l=0,s=Ls(),n=ps(),K([g,C,V,M,m,E,H,k,D,J],Ie))),Os),Os={getContent:()=>[as(),Is()],getTables:as,getTableIds:is,getTable:e=>Ae(Fe(Z,y(e))),getTableCellIds:cs,getRowCount:ds,getRowIds:us,getSortedRowIds:gs,getRow:(e,t)=>We(Fe(Fe(Z,y(e)),y(t))),getCellIds:hs,getCell:fs,getValues:Is,getValueIds:bs,getValue:ws,hasTables:Ls,hasTable:Cs,hasTableCell:Rs,hasRow:Ts,hasCell:vs,hasValues:ps,hasValue:Ss,getTablesJson:()=>St(Z),getValuesJson:()=>St($),getJson:()=>St([Z,$]),getTablesSchemaJson:()=>St(x),getValuesSchemaJson:()=>St(P),getSchemaJson:()=>St([x,P]),hasTablesSchema:()=>e,hasValuesSchema:()=>t,setContent:e=>rs((()=>{const t=O(e)?e():e;gt(t)&&(([e,t])=>{(ke(e)?ks:ys)(e),(ke(t)?Js:Vs)(t)})(t)})),setTables:ys,setTable:(e,t)=>rs((e=>ht(t,e)?Vt(e,t):0),e),setRow:(e,t,s)=>rs(((e,t)=>ft(e,t,s)?Mt(e,Jt(e),t,s):0),e,t),addRow:(e,t,s=!0)=>Qs((()=>{let n;return ft(e,n,t)&&(e=y(e),Mt(e,Jt(e),n=((e,t)=>{const[s]=Fe(q,e);let n;do{n=s(t)}while(ge(Fe(Z,e),n));return n})(e,s?1:0),t)),n})),setPartialRow:(e,t,s)=>rs(((e,t)=>{if(ft(e,t,s,1)){const n=Jt(e);Ee(s,((s,o)=>Et(e,n,t,o,s)))}}),e,t),setCell:(e,t,s,n)=>rs(((e,t,s)=>Q(It(e,t,s,O(n)?n(fs(e,t,s)):n),(n=>Et(e,Jt(e),t,s,n)))),e,t,s),setValues:Vs,setPartialValues:e=>rs((()=>bt(e,1)?Ee(e,((e,t)=>Ht(t,e))):0)),setValue:(e,t)=>rs((e=>Q(wt(e,O(t)?t(ws(e)):t),(t=>Ht(e,t)))),e),applyChanges:e=>rs((()=>{Ee(e[0],((e,t)=>F(e)?Ds(t):Ee(e,((e,s)=>F(e)?Hs(t,s):Ee(e,((e,n)=>le(Os,t,s,n,e))))))),Ee(e[1],((e,t)=>re(Os,t,e)))})),setTablesJson:Ms,setValuesJson:e=>{try{kt(pt(e))}catch{}return Os},setJson:e=>rs((()=>{try{const[t,s]=pt(e);vt(t),kt(s)}catch{Ms(e)}})),setTablesSchema:ms,setValuesSchema:Es,setSchema:(e,t)=>rs((()=>{ms(e),Es(t)})),delTables:ks,delTable:Ds,delRow:Hs,delCell:(e,t,s,n)=>rs(((e,t,s)=>Q(Fe(Z,e),(o=>Q(Fe(o,t),(l=>ge(l,s)?Qt(e,o,t,l,s,n):0))))),e,t,s),delValues:Js,delValue:e=>rs((e=>ge($,e)?zt(e):0),e),delTablesSchema:xs,delValuesSchema:Fs,delSchema:()=>rs((()=>{xs(),Fs()})),transaction:Qs,startTransaction:zs,getTransactionChanges:()=>[We(E,((e,t)=>-1===Fe(g,t)?void 0:We(e,((e,s)=>-1===Fe(Fe(M,t),s)?void 0:We(e,(([,e])=>e),(e=>_t(e)))),he,ke)),he,ke),We(D,(([,e])=>e),(e=>_t(e))),1],getTransactionLog:()=>[!he(E),!he(D),Pe(E,Pt,_t),Pe(H),We(D,Pt,_t),We(J),We(g),Ae(M),Pe(m),We(k)],finishTransaction:Ns,forEachTable:e=>be(Z,((t,s)=>e(s,(e=>be(t,((t,s)=>e(s,(e=>Qe(t,e))))))))),forEachTableCell:(e,t)=>Qe(Fe(Y,y(e)),t),forEachRow:(e,t)=>be(Fe(Z,y(e)),((e,s)=>t(s,(t=>Qe(e,t))))),forEachCell:(e,t,s)=>Qe(Fe(Fe(Z,y(e)),y(t)),s),forEachValue:e=>Qe($,e),addSortedRowIdsListener:(e,t,s,n,o,l,r)=>{let a=gs(e,t,s,n,o);return rt((()=>{const r=gs(e,t,s,n,o);U(r,a)||(a=r,l(Os,e,t,s,n,o,a))}),ve[r?1:0],[e,t],[is])},addStartTransactionListener:e=>rt(e,ot),addWillFinishTransactionListener:e=>rt(e,lt[0]),addDidFinishTransactionListener:e=>rt(e,lt[1]),callListener:e=>(dt(e),Os),delListener:e=>(ct(e),Os),getListenerStats:()=>({hasTables:Wt(te),tables:Wt(se),tableIds:Wt(oe),hasTable:Wt(ae),table:Wt(fe),tableCellIds:Wt(Le),hasTableCell:Wt(Ce,de),rowCount:Wt(Re),rowIds:Wt(Te),sortedRowIds:Wt(ve),hasRow:Wt(pe,de),row:Wt(ye,de),cellIds:Wt(me,de),hasCell:Wt(De,ue),cell:Wt(Ue,ue),invalidCell:Wt(Ke,ue),hasValues:Wt(Ye),values:Wt(Ze),valueIds:Wt(tt),hasValue:Wt(st),value:Wt(nt),invalidValue:Wt(Xe),transaction:ce(ot)+Wt(lt)}),isMergeable:()=>!1,createStore:Bt,addListener:rt,callListeners:it,setInternalListeners:(e,t,s,n,o)=>c=[e,t,s,n,o]};return Ee({[u+f]:[0,te,[],()=>[Ls()]],[f]:[0,se],[I]:[0,oe],[u+h]:[1,ae,[is],e=>[Cs(...e)]],[h]:[1,fe,[is]],[h+T]:[1,Le,[is]],[u+h+R]:[2,Ce,[is,cs],e=>[Rs(...e)]],[w]:[1,Re,[is]],[L]:[1,Te,[is]],[u+b]:[2,pe,[is,us],e=>[Ts(...e)]],[b]:[2,ye,[is,us]],[T]:[2,me,[is,us]],[u+R]:[3,De,[is,us,hs],e=>[vs(...e)]],[R]:[3,Ue,[is,us,hs],e=>Ot(fs(...e))],InvalidCell:[3,Ke],[u+p]:[0,Ye,[],()=>[ps()]],[p]:[0,Ze],[S]:[0,tt],[u+v]:[1,st,[bs],e=>[Ss(...e)]],[v]:[1,nt,[bs],e=>Ot(ws(e[0]))],InvalidValue:[1,Xe]},(([e,t,s,n],o)=>{Os[d+o+i]=(...o)=>rt(o[e],t[o[e+1]?1:0],e>0?A(o,0,e):void 0,s,n)})),Se(Os)},Ut={HasTable:1,Table:1,TableCellIds:1,HasTableCell:2,RowCount:1,RowIds:1,SortedRowIds:5,HasRow:2,Row:2,CellIds:2,HasCell:3,Cell:3,HasValue:1,Value:1,InvalidCell:3,InvalidValue:1},qt=(e=t)=>[Ft(e),Ft(e)],Gt=e=>{let s=1,n=qt(),o=0;const l=Je(),r=qe(),[a,c]=(e=>{let t=0,s=-1;const n=Q(e,(e=>{const t=bt(e);return ot(t/Ct)+ot(t/Rt)+ot(t/Tt)+ot(t/64)+ot(t)}),(()=>it(5))),o=e=>{const n=t,[o,l]=F(e)||""==e?[0,0]:[lt(r=e,0)*wt+lt(r,1)*Lt+lt(r,2)*Ct+lt(r,3)*Rt+lt(r,4)*Tt+64*lt(r,5)+lt(r,6),lt(r,7)*Rt+lt(r,8)*Tt+64*lt(r,9)+lt(r,10)];var r;t=D(n,o,E.HLC_TIME??Date.now()),s=t==n?t==o?D(s,l):s:t==o?l:-1};return[()=>{return o(),l=++s,ot((e=t)/wt)+ot(e/Lt)+ot(e/Ct)+ot(e/Rt)+ot(e/Tt)+ot(e/64)+ot(e)+ot(l/Rt)+ot(l/Tt)+ot(l/64)+ot(l)+n;var e,l},o]})(e),u=Bt(),g=e=>{const t=s;return s=0,e(),s=t,w},h=(e,s=0)=>{const o={},l={},[[r,a=t,i=0],d]=e,[u,g]=n,[h,I,b]=u;let w=s?i:b,L=a;me(r,(([e,n=t,l=0],r)=>{const a=Ne(h,r,Ft),[i,c,d]=a;let u=s?l:d,g=n;me(e,((e,t)=>{const[n,l,a]=f(e,Ne(i,t,Ft),De(De(o,r,ye),t,ye),s);u^=s?0:(l?kt(t,l):0)^kt(t,a),g=Ht(g,n)})),u^=s?0:Dt(c,n),Jt(a,n,u),w^=s?0:(d?kt(r,d):0)^kt(r,a[2]),L=Ht(L,g)})),w^=s?0:Dt(I,a),Jt(u,a,w);const[C]=f(d,g,l,s);return c(Ht(L,C)),[o,l,1]},f=(e,s,n,o)=>{const[l,r=t,a=0]=e,[i,c,d]=s;let u=r,g=o?a:d;return me(l,(([e,s=t,l=0],r)=>{const a=Ne(i,r,(()=>[void 0,t,0])),[,c,d]=a;(!c||s>c)&&(Jt(a,s,o?l:bt(St(e??null)+":"+s)),a[0]=e,n[r]=e,g^=o?0:kt(r,d)^kt(r,a[2]),u=Ht(u,s))})),g^=o?0:Dt(c,r),Jt(s,r,g),[u,d,s[2]]},I=()=>[Qt(n[0],(e=>Qt(e,(e=>Qt(e))))),Qt(n[1])],b=e=>g((()=>u.applyChanges(h(e)))),w={getMergeableContent:I,getMergeableContentHashes:()=>[n[0][2],n[1][2]],getMergeableTableHashes:()=>We(n[0][0],Et),getMergeableTableDiff:e=>{const t=xt(n[0][1]),s={};return Qe(n[0][0],((n,[o,l,r])=>Ve(e,n)?r!=e[n]?s[n]=r:0:t[0][n]=zt([o,l],(e=>zt(e))))),[t,s]},getMergeableRowHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n,,o])=>o!=e?Qe(n,((e,[,,n])=>De(t,s,ye)[e]=n)):0)))),t},getMergeableRowDiff:e=>{const t=xt(n[0][1]),s={};return me(e,((e,o)=>Qe(Fe(n[0][0],o)?.[0],((n,[l,r,a])=>Ve(e,n)?a!==e[n]?De(s,o,ye)[n]=a:0:De(t[0],o,xt)[0][n]=zt([l,r]))))),[t,s]},getMergeableCellHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n])=>me(e,((e,o)=>Q(Fe(n,o),(([n,,l])=>l!==e?Qe(n,((e,[,,n])=>De(De(t,s,ye),o,ye)[e]=n)):0)))))))),t},getMergeableCellDiff:e=>{const[[t,s]]=n,o={};return me(e,((e,s)=>me(e,((e,n)=>Q(Fe(t,s),(([t,l])=>Q(Fe(t,n),(([t,r])=>Qe(t,((t,[a,i,c])=>c!==e[t]?De(De(o,s,(()=>xt(l)))[0],n,(()=>xt(r)))[0][t]=[a,i]:0)))))))))),Mt(o,s)},getMergeableValueHashes:()=>We(n[1][0],Et),getMergeableValueDiff:e=>{const[,[t,s]]=n,o=We(t,yt,(([,,t],s)=>t==e?.[s]));return Mt(o,s)},setMergeableContent:e=>g((()=>(e=>W(e)&&2==P(e)&&Nt(e[0],(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,oe)),void 0,1)))),void 0,1)))),void 0,1)))&&Nt(e[1],(e=>He(e,(e=>Nt(e,oe)),void 0,1))))(e)?u.transaction((()=>{u.delTables().delValues(),n=qt(),u.applyChanges(h(e,1))})):0)),setDefaultContent:e=>(u.transaction((()=>{o=1,u.setContent(e),o=0})),w),getTransactionMergeableChanges:(e=!1)=>{const[[t,s,o],[a,i,c]]=n,d=e?mt:Mt,u={};be(l,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const l={};be(e,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const r={};be(e,(e=>{Q(Fe(t,e),(([t,s,n])=>r[e]=d(t,s,n)))})),l[s]=d(r,n,o)})))),u[s]=d(l,n,o)}))));const g={};return be(r,(e=>Q(Fe(a,e),(([t,s,n])=>g[e]=d(t,s,n))))),[d(u,s,o),d(g,i,c),1]},applyMergeableChanges:b,merge:e=>{const t=I(),s=e.getMergeableContent();return e.applyMergeableChanges(t),b(s)}};return u.setInternalListeners((()=>{}),(()=>{}),(()=>{Ie(l),Ie(r)}),((e,n,r,i)=>{Ge(Ne(Ne(l,e,Je),n,qe),r),s&&h([[{[e]:[{[n]:[{[r]:[i,o?t:a()]}]}]}],[{}],1])}),((e,n)=>{Ge(r,e),s&&h([[{}],[{[e]:[n,o?t:a()]}],1])})),Ee(u,((e,t)=>w[t]=V(t,"set")||V(t,"del")||V(t,"apply")||M(t,"Transaction")||t=="call"+i?(...t)=>(e(...t),w):V(t,d)&&M(t,i)?(...s)=>{const n=Ut[A(t,3,-8)]??0,o=s[n];return s[n]=(e,...t)=>o(w,...t),e(...s)}:"isMergeable"==t?()=>!0:e)),Se(w)};export{tt as createCheckpoints,ct as createIndexes,Gt as createMergeableStore,gt as createMetrics,ht as createQueries,ft as createRelationships,Bt as createStore,at as defaultSorter,it as getUniqueId};
package/min/index.js.gz CHANGED
Binary file
@@ -1 +1 @@
1
- const e=e=>typeof e,t="",n=e(t),s=e=>t+e,r=e=>null==e,o=(e,t,n)=>r(e)?n?.():t(e),d=e=>Array.isArray(e),c=e=>e.length,l=(e,t)=>e.every(t),a=(e,t)=>l(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),u=(e,t)=>e.forEach(t),I=(e,...t)=>e.push(...t),h=e=>t=>{return n=(t,n)=>t+e(n),S(t).reduce(n,0);var n},f=e=>e?.size??0,g=h(f),v=h(g),w=(e,t)=>e?.has(t)??!1,L=e=>r(e)||0==f(e),S=e=>[...e?.values()??[]],x=e=>e.clear(),p=(e,t)=>e?.forEach(t),y=(e,t)=>e?.delete(t),R=Object.freeze,E=e=>new Map(e),b=e=>[...e?.keys()??[]],T=(e,t)=>e?.get(t),k=(e,t)=>p(e,((e,n)=>t(n,e))),z=(e,t,n)=>r(n)?(y(e,t),e):e?.set(t,n),A=(e,t,n,s)=>(w(e,t)?s?.(T(e,t)):z(e,t,n()),T(e,t)),C=(e,t,n,s,r=0)=>o((n?A:T)(e,t[r],r>c(t)-2?n:E),(o=>{if(r>c(t)-2)return s?.(o)&&z(e,t[r]),o;const d=C(o,t,n,s,r+1);return L(o)&&z(e,t[r]),d})),D=e=>new Set(d(e)||r(e)?e:[e]),M=(e,t)=>e?.add(t),j=(s,r)=>e(s)==n?e=>e(s):s??(()=>r??t),m=(e,t)=>(e??0)<(t??0)?-1:1,O=/^\d+$/,W=(()=>{const e=new WeakMap;return n=>(e.has(n)||e.set(n,(e=>{const n=E(),h=E(),[f,W,$]=(()=>{let e;const[n,s]=(()=>{const e=[];let n=0;return[s=>(s?e.shift():null)??t+n++,t=>{O.test(t)&&c(e)<1e3&&I(e,t)}]})(),d=E();return[(s,r,o,c=[],l=()=>[])=>{e??=X;const a=n(1);return z(d,a,[s,r,o,c,l]),M(C(r,o??[t],D),a),a},(n,s,...r)=>u(((e,n=[t])=>{const s=[],r=(e,t)=>t==c(n)?I(s,e):null===n[t]?p(e,(e=>r(e,t+1))):u([n[t],null],(n=>r(T(e,n),t+1)));return r(e,0),s})(n,s),(t=>p(t,(t=>T(d,t)[0](e,...s??[],...r))))),e=>o(T(d,e),(([,n,r])=>(C(n,r??[t],void 0,(t=>(y(t,e),L(t)?1:0))),z(d,e),s(e),r))),t=>o(T(d,t),(([t,,n=[],s,o])=>{const d=(...l)=>{const a=c(l);a==c(n)?t(e,...l,...o(l)):r(n[a])?u(s[a]?.(...l)??[],(e=>d(...l,e))):d(...l,n[a])};d()}))]})(),[q,B,F,G,H,J,K,,N,P,Q,U]=((e,t,n,s,a)=>{const i=e.hasRow,I=E(),h=E(),f=E(),g=E(),v=E(),R=E(),C=(t,n,...s)=>{const r=A(R,t,D);return u(s,(t=>M(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>o(T(R,t),(s=>{u(0==c(n)?S(s):n,(t=>{e.delListener(t),y(s,t)})),L(s)&&z(R,t)})),m=(e,n)=>{z(I,e,n),w(h,e)||(z(h,e,t()),z(g,e,E()),z(v,e,E()),a(f))},O=e=>{z(I,e),z(h,e),z(g,e),z(v,e),j(e),a(f)};return[()=>e,()=>b(I),e=>k(h,e),e=>w(h,e),e=>T(I,e),e=>T(h,e),(e,t)=>z(h,e,t),m,(t,s,o,a,I)=>{m(t,s);const h=E(),f=E(),L=T(g,t),S=T(v,t),y=t=>{const o=n=>e.getCell(s,t,n),u=T(L,t),g=i(s,t)?n(a(o,t)):void 0;var v,w;if(u===g||d(u)&&d(g)&&(w=g,c(v=u)===c(w)&&l(v,((e,t)=>w[t]===e)))||z(h,t,[u,g]),!r(I)){const e=T(S,t),n=i(s,t)?I(o,t):void 0;e!=n&&z(f,t,n)}},R=e=>{o((()=>{p(h,(([,e],t)=>z(L,t,e))),p(f,((e,t)=>z(S,t,e)))}),h,f,L,S,e),x(h),x(f)};k(L,y),e.hasTable(s)&&u(e.getRowIds(s),(e=>{w(L,e)||y(e)})),R(!0),j(t),C(t,0,e.addRowListener(s,null,((e,t,n)=>y(n))),e.addTableListener(s,(()=>R())))},O,e=>s(e,f),()=>k(R,O),C,j]})(e,E,(e=>{return r(e)?t:d(e)?(n=s,e.map(n)):s(e);var n}),f,W),V=(t,n,s)=>{const r=H(t);p(s,((t,s)=>n(s,(n=>p(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},X={setIndexDefinition:(e,t,s,d,c,l=m)=>{const u=r(c)?void 0:([e],[t])=>c(e,t);return N(e,t,((t,s,c,I,f,g)=>{let v=0;const S=D(),x=D(),R=J(e);if(p(s,(([e,t],n)=>{const s=D(e),c=D(t);p(s,(e=>y(c,e)?y(s,e):0)),p(s,(e=>{M(S,e),o(T(R,e),(t=>{y(t,n),L(t)&&(z(R,e),v=1)}))})),p(c,(e=>{M(S,e),w(R,e)||(z(R,e,D()),v=1),M(T(R,e),n),r(d)||M(x,e)}))})),t(),L(f)||(g?k(R,(e=>M(x,e))):k(c,(e=>o(T(I,e),(e=>M(x,e))))),p(x,(e=>{const t=(t,n)=>l(T(f,t),T(f,n),e),n=[...T(R,e)];a(n,t)||(z(R,e,D(i(n,t))),M(S,e))}))),(v||g)&&!r(u)){const t=[...R];a(t,u)||(K(e,E(i(t,u))),v=1)}v&&W(n,[e]),p(S,(t=>W(h,[e,t])))}),j(s),o(d,j)),X},delIndexDefinition:e=>(P(e),X),getStore:q,getIndexIds:B,forEachIndex:e=>F(((t,n)=>e(t,(e=>V(t,e,n))))),forEachSlice:(e,t)=>V(e,t,J(e)),hasIndex:G,hasSlice:(e,t)=>w(J(e),t),getTableId:H,getSliceIds:e=>b(J(e)),getSliceRowIds:(e,t)=>S(T(J(e),t)),addIndexIdsListener:Q,addSliceIdsListener:(e,t)=>f(t,n,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,h,[e,t]),delListener:e=>($(e),X),destroy:U,getListenerStats:()=>({sliceIds:g(n),sliceRowIds:v(h)})};return R(X)})(n)),e.get(n))})();export{W as createIndexes};
1
+ const e=e=>typeof e,t="",n=e(t),s=e=>t+e,r=e=>null==e,o=(e,t,n)=>r(e)?n?.():t(e),d=e=>Array.isArray(e),c=e=>e.length,l=(e,t)=>e.every(t),a=(e,t)=>l(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),u=(e,t)=>e.forEach(t),I=(e,...t)=>e.push(...t),h=e=>t=>{return n=(t,n)=>t+e(n),S(t).reduce(n,0);var n},f=e=>e?.size??0,g=h(f),v=h(g),w=(e,t)=>e?.has(t)??!1,L=e=>r(e)||0==f(e),S=e=>[...e?.values()??[]],x=e=>e.clear(),p=(e,t)=>e?.forEach(t),y=(e,t)=>e?.delete(t),R=Object.freeze,E=e=>new Map(e),b=e=>[...e?.keys()??[]],T=(e,t)=>e?.get(t),k=(e,t)=>p(e,((e,n)=>t(n,e))),z=(e,t,n)=>r(n)?(y(e,t),e):e?.set(t,n),A=(e,t,n,s)=>(w(e,t)?s?.(T(e,t)):z(e,t,n()),T(e,t)),C=(e,t,n,s,r=0)=>o((n?A:T)(e,t[r],r>c(t)-2?n:E),(o=>{if(r>c(t)-2)return s?.(o)&&z(e,t[r]),o;const d=C(o,t,n,s,r+1);return L(o)&&z(e,t[r]),d})),D=e=>new Set(d(e)||r(e)?e:[e]),M=(e,t)=>e?.add(t),j=(s,r)=>e(s)==n?e=>e(s):s??(()=>r??t),m=(e,t)=>(e??0)<(t??0)?-1:1,O=/^\d+$/,W=(()=>{const e=new WeakMap;return n=>(e.has(n)||e.set(n,(e=>{const n=E(),h=E(),[f,W,$]=(()=>{let e;const[n,s]=(()=>{const e=[];let n=0;return[s=>(s?e.shift():null)??t+n++,t=>{O.test(t)&&c(e)<1e3&&I(e,t)}]})(),d=E();return[(s,r,o,c=[],l=()=>[])=>{e??=X;const a=n(1);return z(d,a,[s,r,o,c,l]),M(C(r,o??[t],D),a),a},(n,s,...r)=>u(((e,n=[t])=>{const s=[],r=(e,t)=>t==c(n)?I(s,e):null===n[t]?p(e,(e=>r(e,t+1))):u([n[t],null],(n=>r(T(e,n),t+1)));return r(e,0),s})(n,s),(t=>p(t,(t=>T(d,t)[0](e,...s??[],...r))))),e=>o(T(d,e),(([,n,r])=>(C(n,r??[t],void 0,(t=>(y(t,e),L(t)?1:0))),z(d,e),s(e),r))),t=>o(T(d,t),(([t,,n=[],s,o])=>{const d=(...l)=>{const a=c(l);a==c(n)?t(e,...l,...o(l)):r(n[a])?u(s[a]?.(...l)??[],(e=>d(...l,e))):d(...l,n[a])};d()}))]})(),[q,B,F,G,H,J,K,,N,P,Q,U]=((e,t,n,s,a)=>{const i=e.hasRow,I=E(),h=E(),f=E(),g=E(),v=E(),R=E(),C=(t,n,...s)=>{const r=A(R,t,D);return u(s,(t=>M(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>o(T(R,t),(s=>{u(0==c(n)?S(s):n,(t=>{e.delListener(t),y(s,t)})),L(s)&&z(R,t)})),m=(e,n)=>{z(I,e,n),w(h,e)||(z(h,e,t()),z(g,e,E()),z(v,e,E()),a(f))},O=e=>{z(I,e),z(h,e),z(g,e),z(v,e),j(e),a(f)};return[()=>e,()=>b(I),e=>k(h,e),e=>w(h,e),e=>T(I,e),e=>T(h,e),(e,t)=>z(h,e,t),m,(t,s,o,a,I)=>{m(t,s);const h=E(),f=E(),L=T(g,t),S=T(v,t),y=t=>{const o=n=>e.getCell(s,t,n),u=T(L,t),g=i(s,t)?n(a(o,t)):void 0;var v,w;if(u===g||d(u)&&d(g)&&(w=g,c(v=u)===c(w)&&l(v,((e,t)=>w[t]===e)))||z(h,t,[u,g]),!r(I)){const e=T(S,t),n=i(s,t)?I(o,t):void 0;e!=n&&z(f,t,n)}},R=e=>{o((()=>{p(h,(([,e],t)=>z(L,t,e))),p(f,((e,t)=>z(S,t,e)))}),h,f,L,S,e),x(h),x(f)};k(L,y),e.hasTable(s)&&u(e.getRowIds(s),(e=>{w(L,e)||y(e)})),R(!0),j(t),C(t,0,e.addRowListener(s,null,((e,t,n)=>y(n))),e.addTableListener(s,(()=>R())))},O,e=>s(e,f),()=>k(R,O),C,j]})(e,E,(e=>{return r(e)?t:d(e)?(n=s,e.map(n)):s(e);var n}),f,W),V=(t,n,s)=>{const r=H(t);p(s,((t,s)=>n(s,(n=>p(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},X={setIndexDefinition:(e,t,s,c,l,I=m)=>{const f=r(l)?void 0:([e],[t])=>l(e,t);return N(e,t,((t,s,l,g,v,S)=>{let x=0;const R=D(),b=D(),A=J(e);if(p(s,(([e,t],n)=>{const s=D(e),d=D(t);p(s,(e=>y(d,e)?y(s,e):0)),p(s,(e=>{M(R,e),o(T(A,e),(t=>{y(t,n),L(t)&&(z(A,e),x=1)}))})),p(d,(e=>{M(R,e),w(A,e)||(z(A,e,D()),x=1),M(T(A,e),n),r(c)||M(b,e)}))})),t(),L(v)||(S?k(A,(e=>M(b,e))):k(l,(e=>o(T(g,e),(e=>u(d(e)?e:[e],(e=>M(b,e))))))),p(b,(e=>{const t=(t,n)=>I(T(v,t),T(v,n),e),n=[...T(A,e)];a(n,t)||(z(A,e,D(i(n,t))),M(R,e))}))),(x||S)&&!r(f)){const t=[...A];a(t,f)||(K(e,E(i(t,f))),x=1)}x&&W(n,[e]),p(R,(t=>W(h,[e,t])))}),j(s),o(c,j)),X},delIndexDefinition:e=>(P(e),X),getStore:q,getIndexIds:B,forEachIndex:e=>F(((t,n)=>e(t,(e=>V(t,e,n))))),forEachSlice:(e,t)=>V(e,t,J(e)),hasIndex:G,hasSlice:(e,t)=>w(J(e),t),getTableId:H,getSliceIds:e=>b(J(e)),getSliceRowIds:(e,t)=>S(T(J(e),t)),addIndexIdsListener:Q,addSliceIdsListener:(e,t)=>f(t,n,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,h,[e,t]),delListener:e=>($(e),X),destroy:U,getListenerStats:()=>({sliceIds:g(n),sliceRowIds:v(h)})};return R(X)})(n)),e.get(n))})();export{W as createIndexes};
Binary file
@@ -1 +1 @@
1
- const e=e=>typeof e,t="",n=e(t),s=e=>t+e,r=e=>null==e,o=(e,t,n)=>r(e)?n?.():t(e),d=e=>Array.isArray(e),c=e=>e.length,l=(e,t)=>e.every(t),a=(e,t)=>l(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),u=(e,t)=>e.forEach(t),I=(e,...t)=>e.push(...t),h=e=>t=>{return n=(t,n)=>t+e(n),S(t).reduce(n,0);var n},f=e=>e?.size??0,g=h(f),v=h(g),w=(e,t)=>e?.has(t)??!1,L=e=>r(e)||0==f(e),S=e=>[...e?.values()??[]],x=e=>e.clear(),p=(e,t)=>e?.forEach(t),y=(e,t)=>e?.delete(t),R=Object.freeze,E=e=>new Map(e),b=e=>[...e?.keys()??[]],T=(e,t)=>e?.get(t),k=(e,t)=>p(e,((e,n)=>t(n,e))),z=(e,t,n)=>r(n)?(y(e,t),e):e?.set(t,n),A=(e,t,n,s)=>(w(e,t)?s?.(T(e,t)):z(e,t,n()),T(e,t)),C=(e,t,n,s,r=0)=>o((n?A:T)(e,t[r],r>c(t)-2?n:E),(o=>{if(r>c(t)-2)return s?.(o)&&z(e,t[r]),o;const d=C(o,t,n,s,r+1);return L(o)&&z(e,t[r]),d})),D=e=>new Set(d(e)||r(e)?e:[e]),M=(e,t)=>e?.add(t),j=(s,r)=>e(s)==n?e=>e(s):s??(()=>r??t),m=(e,t)=>(e??0)<(t??0)?-1:1,O=/^\d+$/,W=(()=>{const e=new WeakMap;return n=>(e.has(n)||e.set(n,(e=>{const n=E(),h=E(),[f,W,$]=(()=>{let e;const[n,s]=(()=>{const e=[];let n=0;return[s=>(s?e.shift():null)??t+n++,t=>{O.test(t)&&c(e)<1e3&&I(e,t)}]})(),d=E();return[(s,r,o,c=[],l=()=>[])=>{e??=X;const a=n(1);return z(d,a,[s,r,o,c,l]),M(C(r,o??[t],D),a),a},(n,s,...r)=>u(((e,n=[t])=>{const s=[],r=(e,t)=>t==c(n)?I(s,e):null===n[t]?p(e,(e=>r(e,t+1))):u([n[t],null],(n=>r(T(e,n),t+1)));return r(e,0),s})(n,s),(t=>p(t,(t=>T(d,t)[0](e,...s??[],...r))))),e=>o(T(d,e),(([,n,r])=>(C(n,r??[t],void 0,(t=>(y(t,e),L(t)?1:0))),z(d,e),s(e),r))),t=>o(T(d,t),(([t,,n=[],s,o])=>{const d=(...l)=>{const a=c(l);a==c(n)?t(e,...l,...o(l)):r(n[a])?u(s[a]?.(...l)??[],(e=>d(...l,e))):d(...l,n[a])};d()}))]})(),[q,B,F,G,H,J,K,,N,P,Q,U]=((e,t,n,s,a)=>{const i=e.hasRow,I=E(),h=E(),f=E(),g=E(),v=E(),R=E(),C=(t,n,...s)=>{const r=A(R,t,D);return u(s,(t=>M(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>o(T(R,t),(s=>{u(0==c(n)?S(s):n,(t=>{e.delListener(t),y(s,t)})),L(s)&&z(R,t)})),m=(e,n)=>{z(I,e,n),w(h,e)||(z(h,e,t()),z(g,e,E()),z(v,e,E()),a(f))},O=e=>{z(I,e),z(h,e),z(g,e),z(v,e),j(e),a(f)};return[()=>e,()=>b(I),e=>k(h,e),e=>w(h,e),e=>T(I,e),e=>T(h,e),(e,t)=>z(h,e,t),m,(t,s,o,a,I)=>{m(t,s);const h=E(),f=E(),L=T(g,t),S=T(v,t),y=t=>{const o=n=>e.getCell(s,t,n),u=T(L,t),g=i(s,t)?n(a(o,t)):void 0;var v,w;if(u===g||d(u)&&d(g)&&(w=g,c(v=u)===c(w)&&l(v,((e,t)=>w[t]===e)))||z(h,t,[u,g]),!r(I)){const e=T(S,t),n=i(s,t)?I(o,t):void 0;e!=n&&z(f,t,n)}},R=e=>{o((()=>{p(h,(([,e],t)=>z(L,t,e))),p(f,((e,t)=>z(S,t,e)))}),h,f,L,S,e),x(h),x(f)};k(L,y),e.hasTable(s)&&u(e.getRowIds(s),(e=>{w(L,e)||y(e)})),R(!0),j(t),C(t,0,e.addRowListener(s,null,((e,t,n)=>y(n))),e.addTableListener(s,(()=>R())))},O,e=>s(e,f),()=>k(R,O),C,j]})(e,E,(e=>{return r(e)?t:d(e)?(n=s,e.map(n)):s(e);var n}),f,W),V=(t,n,s)=>{const r=H(t);p(s,((t,s)=>n(s,(n=>p(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},X={setIndexDefinition:(e,t,s,d,c,l=m)=>{const u=r(c)?void 0:([e],[t])=>c(e,t);return N(e,t,((t,s,c,I,f,g)=>{let v=0;const S=D(),x=D(),R=J(e);if(p(s,(([e,t],n)=>{const s=D(e),c=D(t);p(s,(e=>y(c,e)?y(s,e):0)),p(s,(e=>{M(S,e),o(T(R,e),(t=>{y(t,n),L(t)&&(z(R,e),v=1)}))})),p(c,(e=>{M(S,e),w(R,e)||(z(R,e,D()),v=1),M(T(R,e),n),r(d)||M(x,e)}))})),t(),L(f)||(g?k(R,(e=>M(x,e))):k(c,(e=>o(T(I,e),(e=>M(x,e))))),p(x,(e=>{const t=(t,n)=>l(T(f,t),T(f,n),e),n=[...T(R,e)];a(n,t)||(z(R,e,D(i(n,t))),M(S,e))}))),(v||g)&&!r(u)){const t=[...R];a(t,u)||(K(e,E(i(t,u))),v=1)}v&&W(n,[e]),p(S,(t=>W(h,[e,t])))}),j(s),o(d,j)),X},delIndexDefinition:e=>(P(e),X),getStore:q,getIndexIds:B,forEachIndex:e=>F(((t,n)=>e(t,(e=>V(t,e,n))))),forEachSlice:(e,t)=>V(e,t,J(e)),hasIndex:G,hasSlice:(e,t)=>w(J(e),t),getTableId:H,getSliceIds:e=>b(J(e)),getSliceRowIds:(e,t)=>S(T(J(e),t)),addIndexIdsListener:Q,addSliceIdsListener:(e,t)=>f(t,n,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,h,[e,t]),delListener:e=>($(e),X),destroy:U,getListenerStats:()=>({sliceIds:g(n),sliceRowIds:v(h)})};return R(X)})(n)),e.get(n))})();export{W as createIndexes};
1
+ const e=e=>typeof e,t="",n=e(t),s=e=>t+e,r=e=>null==e,o=(e,t,n)=>r(e)?n?.():t(e),d=e=>Array.isArray(e),c=e=>e.length,l=(e,t)=>e.every(t),a=(e,t)=>l(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),u=(e,t)=>e.forEach(t),I=(e,...t)=>e.push(...t),h=e=>t=>{return n=(t,n)=>t+e(n),S(t).reduce(n,0);var n},f=e=>e?.size??0,g=h(f),v=h(g),w=(e,t)=>e?.has(t)??!1,L=e=>r(e)||0==f(e),S=e=>[...e?.values()??[]],x=e=>e.clear(),p=(e,t)=>e?.forEach(t),y=(e,t)=>e?.delete(t),R=Object.freeze,E=e=>new Map(e),b=e=>[...e?.keys()??[]],T=(e,t)=>e?.get(t),k=(e,t)=>p(e,((e,n)=>t(n,e))),z=(e,t,n)=>r(n)?(y(e,t),e):e?.set(t,n),A=(e,t,n,s)=>(w(e,t)?s?.(T(e,t)):z(e,t,n()),T(e,t)),C=(e,t,n,s,r=0)=>o((n?A:T)(e,t[r],r>c(t)-2?n:E),(o=>{if(r>c(t)-2)return s?.(o)&&z(e,t[r]),o;const d=C(o,t,n,s,r+1);return L(o)&&z(e,t[r]),d})),D=e=>new Set(d(e)||r(e)?e:[e]),M=(e,t)=>e?.add(t),j=(s,r)=>e(s)==n?e=>e(s):s??(()=>r??t),m=(e,t)=>(e??0)<(t??0)?-1:1,O=/^\d+$/,W=(()=>{const e=new WeakMap;return n=>(e.has(n)||e.set(n,(e=>{const n=E(),h=E(),[f,W,$]=(()=>{let e;const[n,s]=(()=>{const e=[];let n=0;return[s=>(s?e.shift():null)??t+n++,t=>{O.test(t)&&c(e)<1e3&&I(e,t)}]})(),d=E();return[(s,r,o,c=[],l=()=>[])=>{e??=X;const a=n(1);return z(d,a,[s,r,o,c,l]),M(C(r,o??[t],D),a),a},(n,s,...r)=>u(((e,n=[t])=>{const s=[],r=(e,t)=>t==c(n)?I(s,e):null===n[t]?p(e,(e=>r(e,t+1))):u([n[t],null],(n=>r(T(e,n),t+1)));return r(e,0),s})(n,s),(t=>p(t,(t=>T(d,t)[0](e,...s??[],...r))))),e=>o(T(d,e),(([,n,r])=>(C(n,r??[t],void 0,(t=>(y(t,e),L(t)?1:0))),z(d,e),s(e),r))),t=>o(T(d,t),(([t,,n=[],s,o])=>{const d=(...l)=>{const a=c(l);a==c(n)?t(e,...l,...o(l)):r(n[a])?u(s[a]?.(...l)??[],(e=>d(...l,e))):d(...l,n[a])};d()}))]})(),[q,B,F,G,H,J,K,,N,P,Q,U]=((e,t,n,s,a)=>{const i=e.hasRow,I=E(),h=E(),f=E(),g=E(),v=E(),R=E(),C=(t,n,...s)=>{const r=A(R,t,D);return u(s,(t=>M(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>o(T(R,t),(s=>{u(0==c(n)?S(s):n,(t=>{e.delListener(t),y(s,t)})),L(s)&&z(R,t)})),m=(e,n)=>{z(I,e,n),w(h,e)||(z(h,e,t()),z(g,e,E()),z(v,e,E()),a(f))},O=e=>{z(I,e),z(h,e),z(g,e),z(v,e),j(e),a(f)};return[()=>e,()=>b(I),e=>k(h,e),e=>w(h,e),e=>T(I,e),e=>T(h,e),(e,t)=>z(h,e,t),m,(t,s,o,a,I)=>{m(t,s);const h=E(),f=E(),L=T(g,t),S=T(v,t),y=t=>{const o=n=>e.getCell(s,t,n),u=T(L,t),g=i(s,t)?n(a(o,t)):void 0;var v,w;if(u===g||d(u)&&d(g)&&(w=g,c(v=u)===c(w)&&l(v,((e,t)=>w[t]===e)))||z(h,t,[u,g]),!r(I)){const e=T(S,t),n=i(s,t)?I(o,t):void 0;e!=n&&z(f,t,n)}},R=e=>{o((()=>{p(h,(([,e],t)=>z(L,t,e))),p(f,((e,t)=>z(S,t,e)))}),h,f,L,S,e),x(h),x(f)};k(L,y),e.hasTable(s)&&u(e.getRowIds(s),(e=>{w(L,e)||y(e)})),R(!0),j(t),C(t,0,e.addRowListener(s,null,((e,t,n)=>y(n))),e.addTableListener(s,(()=>R())))},O,e=>s(e,f),()=>k(R,O),C,j]})(e,E,(e=>{return r(e)?t:d(e)?(n=s,e.map(n)):s(e);var n}),f,W),V=(t,n,s)=>{const r=H(t);p(s,((t,s)=>n(s,(n=>p(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},X={setIndexDefinition:(e,t,s,c,l,I=m)=>{const f=r(l)?void 0:([e],[t])=>l(e,t);return N(e,t,((t,s,l,g,v,S)=>{let x=0;const R=D(),b=D(),A=J(e);if(p(s,(([e,t],n)=>{const s=D(e),d=D(t);p(s,(e=>y(d,e)?y(s,e):0)),p(s,(e=>{M(R,e),o(T(A,e),(t=>{y(t,n),L(t)&&(z(A,e),x=1)}))})),p(d,(e=>{M(R,e),w(A,e)||(z(A,e,D()),x=1),M(T(A,e),n),r(c)||M(b,e)}))})),t(),L(v)||(S?k(A,(e=>M(b,e))):k(l,(e=>o(T(g,e),(e=>u(d(e)?e:[e],(e=>M(b,e))))))),p(b,(e=>{const t=(t,n)=>I(T(v,t),T(v,n),e),n=[...T(A,e)];a(n,t)||(z(A,e,D(i(n,t))),M(R,e))}))),(x||S)&&!r(f)){const t=[...A];a(t,f)||(K(e,E(i(t,f))),x=1)}x&&W(n,[e]),p(R,(t=>W(h,[e,t])))}),j(s),o(c,j)),X},delIndexDefinition:e=>(P(e),X),getStore:q,getIndexIds:B,forEachIndex:e=>F(((t,n)=>e(t,(e=>V(t,e,n))))),forEachSlice:(e,t)=>V(e,t,J(e)),hasIndex:G,hasSlice:(e,t)=>w(J(e),t),getTableId:H,getSliceIds:e=>b(J(e)),getSliceRowIds:(e,t)=>S(T(J(e),t)),addIndexIdsListener:Q,addSliceIdsListener:(e,t)=>f(t,n,[e]),addSliceRowIdsListener:(e,t,n)=>f(n,h,[e,t]),delListener:e=>($(e),X),destroy:U,getListenerStats:()=>({sliceIds:g(n),sliceRowIds:v(h)})};return R(X)})(n)),e.get(n))})();export{W as createIndexes};
@@ -1 +1 @@
1
- const e=e=>typeof e,t="",s=e(t),n=e(!0),o=e(0),l=e(e),r="type",a="default",i="Listener",c="Result",d="add",u="Has",g="Ids",h="Table",f=h+"s",I=h+g,b="Row",w=b+"Count",L=b+g,C="Sorted"+b+g,R="Cell",T=R+g,v="Value",p=v+"s",S=v+g,y=e=>t+e,V=(e,t)=>e.startsWith(t),M=(e,t)=>e.endsWith(t),m=(e,s=t,n)=>e.split(s,n),E=globalThis,k=Math,D=k.max,H=k.min,J=k.floor,x=isFinite,F=e=>null==e,Q=(e,t,s)=>F(e)?s?.():t(e),z=e=>e==s||e==n,N=t=>e(t)==s,O=t=>e(t)==l,W=e=>Array.isArray(e),A=(e,t,s)=>e.slice(t,s),P=e=>e.length,_=()=>{},j=(e,t)=>e.includes(t),B=(e,t)=>e.every(t),U=(e,t)=>P(e)===P(t)&&B(e,((e,s)=>t[s]===e)),q=(e,t)=>B(e,((s,n)=>0==n||t(e[n-1],s)<=0)),G=(e,t)=>e.sort(t),K=(e,t)=>e.forEach(t),X=(e,t)=>e.map(t),Y=e=>$(e,((e,t)=>e+t),0),Z=e=>0==P(e),$=(e,t,s)=>e.reduce(t,s),ee=(e,...t)=>e.push(...t),te=e=>e.pop(),se=e=>e.shift(),ne=t=>{const s=e(t);return z(s)||s==o&&x(t)?s:void 0},oe=e=>F(e)||!F(ne(e)),le=(e,t,s,n,o)=>F(o)?e.delCell(t,s,n,!0):e.setCell(t,s,n,o),re=(e,t,s)=>F(s)?e.delValue(t):e.setValue(t,s),ae=e=>t=>$(fe(t),((t,s)=>t+e(s)),0),ie=e=>e?.size??0,ce=ae(ie),de=ae(ce),ue=ae(de),ge=(e,t)=>e?.has(t)??!1,he=e=>F(e)||0==ie(e),fe=e=>[...e?.values()??[]],Ie=e=>e.clear(),be=(e,t)=>e?.forEach(t),we=(e,t)=>e?.delete(t),Le=Object,Ce=e=>Le.getPrototypeOf(e),Re=Le.entries,Te=Le.isFrozen,ve=e=>!F(e)&&Q(Ce(e),(e=>e==Le.prototype||F(Ce(e))),(()=>!0)),pe=Le.keys,Se=Le.freeze,ye=(e=[])=>Le.fromEntries(e),Ve=(e,t)=>t in e,Me=(e,t)=>(delete e[t],e),me=(e,t)=>K(Re(e),(([e,s])=>t(s,e))),Ee=(e,t)=>ye(((e,t)=>X(Re(e),(([e,s])=>t(s,e))))(e,((e,s)=>[s,t(e,s)]))),ke=e=>ve(e)&&0==(e=>P(pe(e)))(e),De=(e,t,s)=>(Ve(e,t)||(e[t]=s()),e[t]),He=(e,t,s,n=0)=>F(e)||!ve(e)||!n&&ke(e)||Te(e)?(s?.(),!1):(me(e,((s,n)=>{t(s,n)||Me(e,n)})),!!n||!ke(e)),Je=e=>new Map(e),xe=e=>[...e?.keys()??[]],Fe=(e,t)=>e?.get(t),Qe=(e,t)=>be(e,((e,s)=>t(s,e))),ze=(e,t,s)=>F(s)?(we(e,t),e):e?.set(t,s),Ne=(e,t,s,n)=>(ge(e,t)?n?.(Fe(e,t)):ze(e,t,s()),Fe(e,t)),Oe=(e,t,s,n=ze)=>(Ee(t,((t,n)=>s(e,n,t))),Qe(e,(s=>Ve(t,s)?0:n(e,s))),e),We=(e,t,s,n)=>{const o={};return be(e,((e,l)=>{if(!s?.(e,l)){const s=t?t(e,l):e;n?.(s)||(o[l]=s)}})),o},Ae=(e,t,s)=>We(e,(e=>We(e,t,s)),he,ke),Pe=(e,t,s)=>We(e,(e=>Ae(e,t,s)),he,ke),_e=(e,t)=>{const s=Je();return be(e,((e,n)=>s.set(n,t?.(e)??e))),s},je=e=>_e(e,_e),Be=e=>_e(e,je),Ue=(e,t,s,n,o=0)=>Q((s?Ne:Fe)(e,t[o],o>P(t)-2?s:Je),(l=>{if(o>P(t)-2)return n?.(l)&&ze(e,t[o]),l;const r=Ue(l,t,s,n,o+1);return he(l)&&ze(e,t[o]),r})),qe=e=>new Set(W(e)||F(e)?e:[e]),Ge=(e,t)=>e?.add(t),Ke=(e,t,s,n,o)=>{const l=e.hasRow,r=Je(),a=Je(),i=Je(),c=Je(),d=Je(),u=Je(),g=(t,s,...n)=>{const o=Ne(u,t,qe);return K(n,(t=>Ge(o,t)&&s&&e.callListener(t))),n},h=(t,...s)=>Q(Fe(u,t),(n=>{K(Z(s)?fe(n):s,(t=>{e.delListener(t),we(n,t)})),he(n)&&ze(u,t)})),f=(e,s)=>{ze(r,e,s),ge(a,e)||(ze(a,e,t()),ze(c,e,Je()),ze(d,e,Je()),o(i))},I=e=>{ze(r,e),ze(a,e),ze(c,e),ze(d,e),h(e),o(i)};return[()=>e,()=>xe(r),e=>Qe(a,e),e=>ge(a,e),e=>Fe(r,e),e=>Fe(a,e),(e,t)=>ze(a,e,t),f,(t,n,o,r,a)=>{f(t,n);const i=Je(),u=Je(),I=Fe(c,t),b=Fe(d,t),w=t=>{const o=s=>e.getCell(n,t,s),c=Fe(I,t),d=l(n,t)?s(r(o,t)):void 0;if(c===d||W(c)&&W(d)&&U(c,d)||ze(i,t,[c,d]),!F(a)){const e=Fe(b,t),s=l(n,t)?a(o,t):void 0;e!=s&&ze(u,t,s)}},L=e=>{o((()=>{be(i,(([,e],t)=>ze(I,t,e))),be(u,((e,t)=>ze(b,t,e)))}),i,u,I,b,e),Ie(i),Ie(u)};Qe(I,w),e.hasTable(n)&&K(e.getRowIds(n),(e=>{ge(I,e)||w(e)})),L(!0),h(t),g(t,0,e.addRowListener(n,null,((e,t,s)=>w(s))),e.addTableListener(n,(()=>L())))},I,e=>n(e,i),()=>Qe(u,I),g,h]},Xe=(e,s)=>N(e)?t=>t(e):e??(()=>s??t),Ye=(e,t)=>{const s=new WeakMap;return n=>{s.has(n)||s.set(n,e(n));const o=s.get(n);return t?.(o),o}},Ze=/^\d+$/,$e=()=>{const e=[];let s=0;return[n=>(n?se(e):null)??t+s++,t=>{Ze.test(t)&&P(e)<1e3&&ee(e,t)}]},et=e=>{let s;const[n,o]=$e(),l=Je();return[(o,r,a,i=[],c=()=>[])=>{s??=e();const d=n(1);return ze(l,d,[o,r,a,i,c]),Ge(Ue(r,a??[t],qe),d),d},(e,n,...o)=>K(((e,s=[t])=>{const n=[],o=(e,t)=>t==P(s)?ee(n,e):null===s[t]?be(e,(e=>o(e,t+1))):K([s[t],null],(s=>o(Fe(e,s),t+1)));return o(e,0),n})(e,n),(e=>be(e,(e=>Fe(l,e)[0](s,...n??[],...o))))),e=>Q(Fe(l,e),(([,s,n])=>(Ue(s,n??[t],void 0,(t=>(we(t,e),he(t)?1:0))),ze(l,e),o(e),n))),e=>Q(Fe(l,e),(([e,,t=[],n,o])=>{const l=(...r)=>{const a=P(r);a==P(t)?e(s,...r,...o(r)):F(t[a])?K(n[a]?.(...r)??[],(e=>l(...r,e))):l(...r,t[a])};l()}))]},tt=Ye((e=>{let s,n,o,l=100,r=Je(),a=Je(),i=1;const c=Je(),d=Je(),[u,g,h]=et((()=>J)),f=Je(),I=Je(),b=[],w=[],L=(t,s)=>{i=0,e.transaction((()=>{const[n,o]=Fe(f,s);be(n,((s,n)=>be(s,((s,o)=>be(s,((s,l)=>le(e,n,o,l,s[t]))))))),be(o,((s,n)=>re(e,n,s[t])))})),i=1},C=e=>{ze(f,e),ze(I,e),g(d,[e])},R=(e,t)=>K(((e,t)=>e.splice(0,t))(e,t??P(e)),C),T=()=>R(b,P(b)-l),v=()=>Q(s,(()=>{ee(b,s),T(),R(w),s=void 0,o=1})),p=()=>{s=te(b),o=1};let S,y;const V=(e=t)=>(F(s)&&(s=t+n++,ze(f,s,[r,a]),D(s,e),r=Je(),a=Je(),o=1),s),M=()=>{Z(b)||(((e,...t)=>{e.unshift(...t)})(w,V()),L(0,s),s=te(b),o=1)},m=()=>{Z(w)||(ee(b,s),s=se(w),L(1,s),o=1)},E=()=>{o&&(g(c),o=0)},k=e=>{const t=V(e);return E(),t},D=(e,t)=>(H(e)&&Fe(I,e)!==t&&(ze(I,e,t),g(d,[e])),J),H=e=>ge(f,e),J={setSize:e=>(l=e,T(),J),addCheckpoint:k,setCheckpoint:D,getStore:()=>e,getCheckpointIds:()=>[[...b],s,[...w]],forEachCheckpoint:e=>Qe(I,e),hasCheckpoint:H,getCheckpoint:e=>Fe(I,e),goBackward:()=>(M(),E(),J),goForward:()=>(m(),E(),J),goTo:e=>{const t=j(b,e)?M:j(w,e)?m:null;for(;!F(t)&&e!=s;)t();return E(),J},addCheckpointIdsListener:e=>u(e,c),addCheckpointListener:(e,t)=>u(t,d,[e]),delListener:e=>(h(e),J),clear:()=>(R(b),R(w),F(s)||C(s),s=void 0,n=0,k(),J),clearForward:()=>(Z(w)||(R(w),g(c)),J),destroy:()=>{e.delListener(S),e.delListener(y)},getListenerStats:()=>({checkpointIds:ce(c),checkpoint:ce(d)}),_registerListeners:()=>{S=e.addCellListener(null,null,null,((e,t,s,n,o,l)=>{if(i){v();const e=Ne(r,t,Je),a=Ne(e,s,Je),i=Ne(a,n,(()=>[l,void 0]));i[1]=o,i[0]===o&&he(ze(a,n))&&he(ze(e,s))&&he(ze(r,t))&&p(),E()}})),y=e.addValueListener(null,((e,t,s,n)=>{if(i){v();const e=Ne(a,t,(()=>[n,void 0]));e[1]=s,e[0]===s&&he(ze(a,t))&&p(),E()}}))}};return Se(J.clear())}),(e=>e._registerListeners())),st=m("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),nt=Je(X(st,((e,t)=>[e,t]))),ot=e=>st[63&e],lt=(e,t)=>Fe(nt,e[t])??0,rt=E.crypto?e=>E.crypto.getRandomValues(e):e=>X(e,(()=>J(256*k.random()))),at=(e,t)=>(e??0)<(t??0)?-1:1,it=(e=16)=>$(rt(new Uint8Array(e)),((e,t)=>e+ot(t)),""),ct=Ye((e=>{const s=Je(),n=Je(),[o,l,r]=et((()=>C)),[a,i,c,d,u,g,h,,f,I,b,w]=Ke(e,Je,(e=>F(e)?t:W(e)?X(e,y):y(e)),o,l),L=(t,s,n)=>{const o=u(t);be(n,((t,n)=>s(n,(s=>be(t,(t=>s(t,(s=>e.forEachCell(o,t,s)))))))))},C={setIndexDefinition:(e,t,o,r,a,i=at)=>{const c=F(a)?void 0:([e],[t])=>a(e,t);return f(e,t,((t,o,a,d,u,f)=>{let I=0;const b=qe(),w=qe(),L=g(e);if(be(o,(([e,t],s)=>{const n=qe(e),o=qe(t);be(n,(e=>we(o,e)?we(n,e):0)),be(n,(e=>{Ge(b,e),Q(Fe(L,e),(t=>{we(t,s),he(t)&&(ze(L,e),I=1)}))})),be(o,(e=>{Ge(b,e),ge(L,e)||(ze(L,e,qe()),I=1),Ge(Fe(L,e),s),F(r)||Ge(w,e)}))})),t(),he(u)||(f?Qe(L,(e=>Ge(w,e))):Qe(a,(e=>Q(Fe(d,e),(e=>Ge(w,e))))),be(w,(e=>{const t=(t,s)=>i(Fe(u,t),Fe(u,s),e),s=[...Fe(L,e)];q(s,t)||(ze(L,e,qe(G(s,t))),Ge(b,e))}))),(I||f)&&!F(c)){const t=[...L];q(t,c)||(h(e,Je(G(t,c))),I=1)}I&&l(s,[e]),be(b,(t=>l(n,[e,t])))}),Xe(o),Q(r,Xe)),C},delIndexDefinition:e=>(I(e),C),getStore:a,getIndexIds:i,forEachIndex:e=>c(((t,s)=>e(t,(e=>L(t,e,s))))),forEachSlice:(e,t)=>L(e,t,g(e)),hasIndex:d,hasSlice:(e,t)=>ge(g(e),t),getTableId:u,getSliceIds:e=>xe(g(e)),getSliceRowIds:(e,t)=>fe(Fe(g(e),t)),addIndexIdsListener:b,addSliceIdsListener:(e,t)=>o(t,s,[e]),addSliceRowIdsListener:(e,t,s)=>o(s,n,[e,t]),delListener:e=>(r(e),C),destroy:w,getListenerStats:()=>({sliceIds:ce(s),sliceRowIds:de(n)})};return Se(C)})),dt=Je([["avg",[(e,t)=>Y(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>D(...e),(e,t)=>D(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:D(t,e)]],["min",[e=>H(...e),(e,t)=>H(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:H(t,e)]],["sum",[e=>Y(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),ut=(e,t,s,n,o,l=!1)=>{if(he(s))return;const[r,a,i,c]=o;return l||=F(e),be(n,(([s,n])=>{l||(e=F(s)?a?.(e,n,t++):F(n)?i?.(e,s,t--):c?.(e,n,s,t),l||=F(e))})),l?r(fe(s),ie(s)):e},gt=Ye((e=>{const s=Je(),[n,o,l]=et((()=>w)),[r,a,i,c,d,u,g,,h,f,I,b]=Ke(e,_,(e=>isNaN(e)||F(e)||!0===e||!1===e||e===t?void 0:1*e),n,o),w={setMetricDefinition:(e,t,n,l,r,a,i)=>{const c=O(n)?[n,r,a,i]:Fe(dt,n)??Fe(dt,"sum");return h(e,t,((t,n,l,r,a,i)=>{const d=u(e),h=ie(r);i||=F(d),t();let f=ut(d,h,r,n,c,i);x(f)||(f=void 0),f!=d&&(g(e,f),o(s,[e],f,d))}),Xe(l,1)),w},delMetricDefinition:e=>(f(e),w),getStore:r,getMetricIds:a,forEachMetric:i,hasMetric:c,getTableId:d,getMetric:u,addMetricIdsListener:I,addMetricListener:(e,t)=>n(t,s,[e]),delListener:e=>(l(e),w),destroy:b,getListenerStats:()=>({metric:ce(s)})};return Se(w)})),ht=Ye((e=>{const s=e.createStore,n=s(),o=s(),l=Je(),{addListener:r,callListeners:a,delListener:u}=o,[g,f,I,v,p,,,S,,y,V,M,m,E]=Ke(e,(()=>!0),_,r,a),k=(e,t,...s)=>K(s,(s=>Ge(Ne(Ne(l,t,Je),e,qe),s))),D=e=>{Q(Fe(l,e),(e=>{Qe(e,((e,t)=>be(t,(t=>e.delListener(t))))),Ie(e)})),K([o,n],(t=>t.delTable(e)))},H=(e,t,s)=>k(t,e,t.addStartTransactionListener(s.startTransaction),t.addDidFinishTransactionListener((()=>s.finishTransaction()))),J={setQueryDefinition:(s,l,r)=>{S(s,l),D(s);const a=[],i=[[null,[l,null,null,[],Je()]]],c=[],d=[],u=[];r({select:(e,s)=>{const n=O(e)?[P(a)+t,e]:[F(s)?e:s,t=>t(e,s)];return ee(a,n),{as:e=>n[0]=e}},join:(e,t,s)=>{const n=F(s)||O(t)?null:t,o=F(n)?t:s,l=[e,[e,n,O(o)?o:e=>e(o),[],Je()]];return ee(i,l),{as:e=>l[0]=e}},where:(e,t,s)=>ee(c,O(e)?e:F(s)?s=>s(e)===t:n=>n(e,t)===s),group:(e,t,s,n,o)=>{const l=[e,[e,O(t)?[t,s,n,o]:Fe(dt,t)??[(e,t)=>t]]];return ee(d,l),{as:e=>l[0]=e}},having:(e,t)=>ee(u,O(e)?e:s=>s(e)===t)});const g=Je(a);if(he(g))return J;const h=Je(i);Qe(h,((e,[,t])=>Q(Fe(h,t),(({3:t})=>F(e)?0:ee(t,e)))));const f=Je(d);let I=n;if(he(f)&&Z(u))I=o;else{H(s,I,o);const e=Je();Qe(f,((t,[s,n])=>Ge(Ne(e,s,qe),[t,n])));const t=qe();Qe(g,(s=>ge(e,s)?0:Ge(t,s)));const n=Je(),l=(t,n,l,r)=>Q(t,(([a,i,c,d])=>{Qe(n,((t,[s])=>{const n=Ne(a,t,Je),o=Fe(n,l),i=r?void 0:s;if(o!==i){const s=qe([[o,i]]),r=ie(n);ze(n,l,i),be(Fe(e,t),(([e,t])=>{const o=ut(d[e],r,n,s,t);d[e]=F(ne(o))?null:o}))}})),he(i)||!B(u,(e=>e((e=>d[e]))))?o.delRow(s,c):F(c)?t[2]=o.addRow(s,d):o.setRow(s,c,d)}));k(I,s,I.addRowListener(s,null,((o,r,a,i)=>{const c=[],d=[],u=Je(),g=I.hasRow(s,a);let h=!g;be(t,(e=>{const[t,n,o]=i(s,a,e);ee(c,n),ee(d,o),h||=t})),Qe(e,(e=>{const[t,,n]=i(s,a,e);(h||t)&&ze(u,e,[n])})),h&&l(Ue(n,c,void 0,(([,e])=>(we(e,a),he(e)))),u,a,1),g&&l(Ue(n,d,(()=>{const e={};return be(t,(t=>e[t]=I.getCell(s,a,t))),[Je(),qe(),void 0,e]}),(([,e])=>{Ge(e,a)})),u,a)})))}H(s,e,I);const b=(t,n,o,r)=>{const a=t=>e.getCell(n,o,t);K(r,(n=>{const[o,,l,r,i]=Fe(h,n),c=l?.(a,t),[d,u]=Fe(i,t)??[];c!=d&&(F(u)||E(s,u),ze(i,t,F(c)?null:[c,...m(s,1,e.addRowListener(o,c,(()=>b(t,o,c,r))))]))})),(t=>{const n=(s,n)=>e.getCell(...F(n)?[l,t,s]:s===l?[l,t,n]:[Fe(h,s)?.[0],Fe(Fe(h,s)?.[4],t)?.[0],n]);I.transaction((()=>B(c,(e=>e(n)))?Qe(g,((e,o)=>le(I,s,t,e,o(n,t)))):I.delRow(s,t)))})(t)},{3:w}=Fe(h,null);return I.transaction((()=>m(s,1,e.addRowListener(l,null,((t,n,o)=>{e.hasRow(l,o)?b(o,l,o,w):(I.delRow(s,o),be(h,(({4:e})=>Q(Fe(e,o),(([,t])=>{E(s,t),ze(e,o)})))))}))))),J},delQueryDefinition:e=>(D(e),y(e),J),getStore:g,getQueryIds:f,forEachQuery:I,hasQuery:v,getTableId:p,addQueryIdsListener:e=>V((()=>e(J))),delListener:e=>(u(e),J),destroy:M,getListenerStats:()=>{const{tables:e,tableIds:t,transaction:s,...n}=o.getListenerStats();return n}};return Ee({[h]:[1,1],[h+T]:[0,1],[w]:[0,1],[L]:[0,1],[C]:[0,5],[b]:[1,2],[T]:[0,2],[R]:[1,3]},(([e,t],s)=>{K(e?["get","has","forEach"]:["get"],(e=>J[e+c+s]=(...t)=>o[e+s](...t))),J[d+c+s+i]=(...e)=>o[d+s+i](...A(e,0,t),((s,...n)=>e[t](J,...n)),!0)})),Se(J)})),ft=Ye((e=>{const s=Je(),n=Je(),o=Je(),l=Je(),[r,a,i]=et((()=>v)),[c,d,u,g,h,f,,,I,b,w,L]=Ke(e,(()=>[Je(),Je(),Je(),Je()]),(e=>F(e)?void 0:e+t),r,a),C=(e,t,s)=>Q(f(e),(([n,,o])=>{if(!ge(o,t)){const l=qe();if(h(e)!=T(e))Ge(l,t);else{let e=t;for(;!F(e)&&!ge(l,e);)Ge(l,e),e=Fe(n,e)}if(s)return l;ze(o,t,l)}return Fe(o,t)})),R=(e,t)=>Q(f(e),(([,,e])=>ze(e,t))),T=e=>Fe(s,e),v={setRelationshipDefinition:(e,t,r,i)=>(ze(s,e,r),I(e,t,((t,s)=>{const r=qe(),i=qe(),c=qe(),[d,u]=f(e);be(s,(([t,s],n)=>{F(t)||(Ge(i,t),Q(Fe(u,t),(e=>{we(e,n),he(e)&&ze(u,t)}))),F(s)||(Ge(i,s),ge(u,s)||ze(u,s,qe()),Ge(Fe(u,s),n)),Ge(r,n),ze(d,n,s),Qe(Fe(l,e),(t=>{ge(C(e,t),n)&&Ge(c,t)}))})),t(),be(r,(t=>a(n,[e,t]))),be(i,(t=>a(o,[e,t]))),be(c,(t=>{R(e,t),a(l,[e,t])}))}),Xe(i)),v),delRelationshipDefinition:e=>(ze(s,e),b(e),v),getStore:c,getRelationshipIds:d,forEachRelationship:t=>u((s=>t(s,(t=>e.forEachRow(h(s),t))))),hasRelationship:g,getLocalTableId:h,getRemoteTableId:T,getRemoteRowId:(e,t)=>Fe(f(e)?.[0],t),getLocalRowIds:(e,t)=>fe(Fe(f(e)?.[1],t)),getLinkedRowIds:(e,t)=>F(f(e))?[t]:fe(C(e,t,!0)),addRelationshipIdsListener:w,addRemoteRowIdListener:(e,t,s)=>r(s,n,[e,t]),addLocalRowIdsListener:(e,t,s)=>r(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(C(e,t),r(s,l,[e,t])),delListener:e=>(R(...i(e)??[]),v),destroy:L,getListenerStats:()=>({remoteRowId:de(n),localRowIds:de(o),linkedRowIds:de(l)})};return Se(v)})),It=new E.TextEncoder,bt=e=>{let t=2166136261;return K(It.encode(e),(e=>{t^=e,t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)})),t>>>0},wt=2**36,Lt=2**30,Ct=2**24,Rt=2**18,Tt=4096,vt=JSON.stringify,pt=JSON.parse,St=e=>vt(e,((e,t)=>t instanceof Map?Le.fromEntries([...t]):t)),yt=([e,t])=>Mt(e,t),Vt=([e,t,s])=>[e,t,s],Mt=(e,t)=>t?[e,t]:[e],mt=(e,t,s)=>[e,t,s],Et=e=>e[2],kt=(e,t)=>bt(e+":"+t),Dt=(e,t)=>t>e?(e?bt(e):0)^bt(t):0,Ht=(e,t)=>((e??"")>(t??"")?e:t)??"",Jt=(e,t,s)=>{t>e[1]&&(e[1]=t),e[2]=s>>>0},xt=(e=t)=>Mt(ye(),e),Ft=(e=t)=>[Je(),e,0],Qt=([e,t,s],n=Vt)=>[We(e,n),t,s],zt=([e,t],s=yt)=>Mt(We(e,s),t),Nt=(t,s)=>W(t)&&3==P(t)&&N(t[1])&&e(t[2])==o&&x(t[2])&&s(t[0]),Ot=e=>[e,e],Wt=(e,t=ce)=>t(e[0])+t(e[1]),At=()=>[Je(),Je()],Pt=e=>[...e],_t=([e,t])=>e===t,jt=(e,t,s)=>ze(e,t,Fe(e,t)==-s?void 0:s),Bt=()=>{let e,t,s=!1,n=!1,l=0,c=[];const g=Je(),C=Je(),V=Je(),M=Je(),m=Je(),E=Je(),k=Je(),D=Je(),H=Je(),J=Je(),x=Je(),N=Je(),P=Je(),_=Je(),B=qe(),q=Je(),Y=Je(),Z=Je(),$=Je(),te=At(),se=At(),oe=At(),ae=At(),fe=At(),Le=At(),Ce=At(),Re=At(),Te=At(),ve=At(),pe=At(),ye=At(),me=At(),De=At(),Ue=At(),Ke=At(),Xe=At(),Ye=At(),Ze=At(),tt=At(),st=At(),nt=At(),ot=Je(),lt=At(),[rt,it,ct,dt]=et((()=>Os)),ut=e=>{if(!He(e,((e,t)=>j([r,a],t))))return!1;const t=e[r];return!(!z(t)&&t!=o||(ne(e[a])!=t&&Me(e,a),0))},gt=W,ht=(t,s)=>(!e||ge(x,s)||Yt(s))&&He(t,((e,t)=>ft(s,t,e)),(()=>Yt(s))),ft=(e,t,s,n)=>He(n?s:Lt(s,e,t),((n,o)=>Q(It(e,t,o,n),(e=>(s[o]=e,!0)),(()=>!1))),(()=>Yt(e,t))),It=(t,s,n,o)=>e?Q(Fe(Fe(x,t),n),(e=>ne(o)!=e[r]?Yt(t,s,n,o,e[a]):o),(()=>Yt(t,s,n,o))):F(ne(o))?Yt(t,s,n,o):o,bt=(e,t)=>He(t?e:Ct(e),((t,s)=>Q(wt(s,t),(t=>(e[s]=t,!0)),(()=>!1))),(()=>Zt())),wt=(e,s)=>t?Q(Fe(P,e),(t=>ne(s)!=t[r]?Zt(e,s,t[a]):s),(()=>Zt(e,s))):F(ne(s))?Zt(e,s):s,Lt=(e,t,s)=>(Q(Fe(N,t),(([n,o])=>{be(n,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(o,(n=>{Ve(e,n)||Yt(t,s,n)}))})),e),Ct=e=>(t&&(be(_,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(B,(t=>{Ve(e,t)||Zt(t)}))),e),Rt=e=>Oe(x,e,((e,t,s)=>{const n=Je(),o=qe();Oe(Ne(x,t,Je),s,((e,t,s)=>{ze(e,t,s),Q(s[a],(e=>ze(n,t,e)),(()=>Ge(o,t)))})),ze(N,t,[n,o])}),((e,t)=>{ze(x,t),ze(N,t)})),Tt=e=>Oe(P,e,((e,t,s)=>{ze(P,t,s),Q(s[a],(e=>ze(_,t,e)),(()=>Ge(B,t)))}),((e,t)=>{ze(P,t),ze(_,t),we(B,t)})),vt=e=>ke(e)?ks():ys(e),yt=e=>Oe(Z,e,((e,t,s)=>Vt(t,s)),((e,t)=>xt(t))),Vt=(e,t)=>Oe(Ne(Z,e,(()=>(Nt(e,1),ze(q,e,$e()),ze(Y,e,Je()),Je()))),t,((t,s,n)=>Mt(e,t,s,n)),((t,s)=>Ft(e,t,s))),Mt=(e,t,s,n,o)=>Oe(Ne(t,s,(()=>(Ut(e,s,1),Je()))),n,((t,n,o)=>mt(e,s,t,n,o)),((n,l)=>Qt(e,t,s,n,l,o))),mt=(e,t,s,n,o)=>{ge(s,n)||qt(e,t,n,1);const l=Fe(s,n);o!==l&&(Gt(e,t,n,l,o),ze(s,n,o))},Et=(e,t,s,n,o)=>Q(Fe(t,s),(t=>mt(e,s,t,n,o)),(()=>Mt(e,t,s,Lt({[n]:o},e,s)))),kt=e=>ke(e)?Js():Vs(e),Dt=e=>Oe($,e,((e,t,s)=>Ht(t,s)),((e,t)=>zt(t))),Ht=(e,t)=>{ge($,e)||Kt(e,1);const s=Fe($,e);t!==s&&(Xt(e,s,t),ze($,e,t))},Jt=e=>Fe(Z,e)??Vt(e,{}),xt=e=>Vt(e,{}),Ft=(e,t,s)=>{const[,n]=Fe(q,e);n(s),Mt(e,t,s,{},!0)},Qt=(e,t,s,n,o,l)=>{const r=Fe(Fe(N,e)?.[0],o);if(!F(r)&&!l)return mt(e,s,n,o,r);const a=t=>{Gt(e,s,t,Fe(n,t)),qt(e,s,t,-1),ze(n,t)};F(r)?a(o):Qe(n,a),he(n)&&(Ut(e,s,-1),he(ze(t,s))&&(Nt(e,-1),ze(Z,e),ze(q,e),ze(Y,e)))},zt=e=>{const t=Fe(_,e);if(!F(t))return Ht(e,t);Xt(e,Fe($,e)),Kt(e,-1),ze($,e)},Nt=(e,t)=>jt(g,e,t),Ut=(e,t,s)=>jt(Ne(M,e,Je),t,s)&&ze(V,e,Ne(V,e,(()=>0))+s),qt=(e,t,s,n)=>{const o=Fe(Y,e),l=Fe(o,s)??0;(0==l&&1==n||1==l&&-1==n)&&jt(Ne(C,e,Je),s,n),ze(o,s,l!=-n?l+n:null),jt(Ne(Ne(m,e,Je),t,Je),s,n)},Gt=(e,t,s,n,o)=>{Ne(Ne(Ne(E,e,Je),t,Je),s,(()=>[n,0]))[1]=o,c[3]?.(e,t,s,o)},Kt=(e,t)=>jt(k,e,t),Xt=(e,t,s)=>{Ne(D,e,(()=>[t,0]))[1]=s,c[4]?.(e,s)},Yt=(e,t,s,n,o)=>(ee(Ne(Ne(Ne(H,e,Je),t,Je),s,(()=>[])),n),o),Zt=(e,t,s)=>(ee(Ne(J,e,(()=>[])),t),s),$t=(e,t,s)=>Q(Fe(Fe(Fe(E,e),t),s),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(fs(e,t,s))])),es=e=>Q(Fe(D,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(ws(e))])),ts=e=>he(H)||he(Ke[e])?0:be(e?Be(H):H,((t,s)=>be(t,((t,n)=>be(t,((t,o)=>it(Ke[e],[s,n,o],t))))))),ss=e=>he(J)||he(Xe[e])?0:be(e?_e(J):J,((t,s)=>it(Xe[e],[s],t))),ns=(e,t,s,n)=>{if(!he(e))return it(t,n,(()=>We(e))),Qe(e,((e,t)=>it(s,[...n??[],e],1==t))),1},os=e=>{const t=Ls();t!=s&&it(te[e],void 0,t);const n=he(ve[e]),o=he(me[e])&&he(De[e])&&he(Te[e])&&he(pe[e])&&he(Le[e])&&he(Ce[e])&&he(Re[e])&&n&&he(oe[e])&&he(ae[e]),l=he(Ue[e])&&he(ye[e])&&he(fe[e])&&he(se[e]);if(!o||!l){const t=e?[_e(g),je(C),_e(V),je(M),Be(m),Be(E)]:[g,C,V,M,m,E];if(!o){ns(t[0],oe[e],ae[e]),be(t[1],((t,s)=>ns(t,Le[e],Ce[e],[s]))),be(t[2],((t,s)=>{0!=t&&it(Re[e],[s],ds(s))}));const s=qe();be(t[3],((t,o)=>{ns(t,Te[e],pe[e],[o])&&!n&&(it(ve[e],[o,null]),Ge(s,o))})),n||be(t[5],((t,n)=>{if(!ge(s,n)){const s=qe();be(t,(e=>be(e,(([t,n],o)=>n!==t?Ge(s,o):we(e,o))))),be(s,(t=>it(ve[e],[n,t])))}})),be(t[4],((t,s)=>be(t,((t,n)=>ns(t,me[e],De[e],[s,n])))))}if(!l){let s;be(t[5],((t,n)=>{let o;be(t,((t,l)=>{let r;be(t,(([t,a],i)=>{a!==t&&(it(Ue[e],[n,l,i],a,t,$t),s=o=r=1)})),r&&it(ye[e],[n,l],$t)})),o&&it(fe[e],[n],$t)})),s&&it(se[e],void 0,$t)}}},ls=e=>{const t=ps();t!=n&&it(Ye[e],void 0,t);const s=he(tt[e])&&he(st[e]),o=he(nt[e])&&he(Ze[e]);if(!s||!o){const t=e?[_e(k),_e(D)]:[k,D];if(s||ns(t[0],tt[e],st[e]),!o){let s;be(t[1],(([t,n],o)=>{n!==t&&(it(nt[e],[o],n,t,es),s=1)})),s&&it(Ze[e],void 0,es)}}},rs=(e,...t)=>(Qs((()=>e(...X(t,y)))),Os),as=()=>Pe(Z),is=()=>xe(Z),cs=e=>xe(Fe(Y,y(e))),ds=e=>ie(Fe(Z,y(e))),us=e=>xe(Fe(Z,y(e))),gs=(e,t,s,n=0,o)=>{return X(A(G((l=Fe(Z,y(e)),r=(e,s)=>[F(t)?s:Fe(e,y(t)),s],X([...l?.entries()??[]],(([e,t])=>r(t,e)))),(([e],[t])=>at(e,t)*(s?-1:1))),n,F(o)?o:n+o),(([,e])=>e));var l,r},hs=(e,t)=>xe(Fe(Fe(Z,y(e)),y(t))),fs=(e,t,s)=>Fe(Fe(Fe(Z,y(e)),y(t)),y(s)),Is=()=>We($),bs=()=>xe($),ws=e=>Fe($,y(e)),Ls=()=>!he(Z),Cs=e=>ge(Z,y(e)),Rs=(e,t)=>ge(Fe(Y,y(e)),y(t)),Ts=(e,t)=>ge(Fe(Z,y(e)),y(t)),vs=(e,t,s)=>ge(Fe(Fe(Z,y(e)),y(t)),y(s)),ps=()=>!he($),Ss=e=>ge($,y(e)),ys=e=>rs((()=>(e=>He(e,ht,Yt))(e)?yt(e):0)),Vs=e=>rs((()=>bt(e)?Dt(e):0)),Ms=e=>{try{vt(pt(e))}catch{}return Os},ms=t=>rs((()=>{if((e=He(t,(e=>He(e,ut))))&&(Rt(t),!he(Z))){const e=as();ks(),ys(e)}})),Es=e=>rs((()=>{if(t=(e=>He(e,ut))(e)){const s=Is();Fs(),Js(),t=!0,Tt(e),Vs(s)}})),ks=()=>rs((()=>yt({}))),Ds=e=>rs((e=>ge(Z,e)?xt(e):0),e),Hs=(e,t)=>rs(((e,t)=>Q(Fe(Z,e),(s=>ge(s,t)?Ft(e,s,t):0))),e,t),Js=()=>rs((()=>Dt({}))),xs=()=>rs((()=>{Rt({}),e=!1})),Fs=()=>rs((()=>{Tt({}),t=!1})),Qs=(e,t)=>{if(-1!=l){zs();const s=e();return Ns(t),s}},zs=()=>(-1!=l&&l++,1==l&&(c[0]?.(),it(ot)),Os),Ns=e=>(l>0&&(l--,0==l&&(l=1,ts(1),he(E)||os(1),ss(1),he(D)||ls(1),e?.(Os)&&(be(E,((e,t)=>be(e,((e,s)=>be(e,(([e],n)=>le(Os,t,s,n,e))))))),Ie(E),be(D,(([e],t)=>re(Os,t,e))),Ie(D)),it(lt[0],void 0),l=-1,ts(0),he(E)||os(0),ss(0),he(D)||ls(0),c[1]?.(),it(lt[1],void 0),c[2]?.(),l=0,s=Ls(),n=ps(),K([g,C,V,M,m,E,H,k,D,J],Ie))),Os),Os={getContent:()=>[as(),Is()],getTables:as,getTableIds:is,getTable:e=>Ae(Fe(Z,y(e))),getTableCellIds:cs,getRowCount:ds,getRowIds:us,getSortedRowIds:gs,getRow:(e,t)=>We(Fe(Fe(Z,y(e)),y(t))),getCellIds:hs,getCell:fs,getValues:Is,getValueIds:bs,getValue:ws,hasTables:Ls,hasTable:Cs,hasTableCell:Rs,hasRow:Ts,hasCell:vs,hasValues:ps,hasValue:Ss,getTablesJson:()=>St(Z),getValuesJson:()=>St($),getJson:()=>St([Z,$]),getTablesSchemaJson:()=>St(x),getValuesSchemaJson:()=>St(P),getSchemaJson:()=>St([x,P]),hasTablesSchema:()=>e,hasValuesSchema:()=>t,setContent:e=>rs((()=>{const t=O(e)?e():e;gt(t)&&(([e,t])=>{(ke(e)?ks:ys)(e),(ke(t)?Js:Vs)(t)})(t)})),setTables:ys,setTable:(e,t)=>rs((e=>ht(t,e)?Vt(e,t):0),e),setRow:(e,t,s)=>rs(((e,t)=>ft(e,t,s)?Mt(e,Jt(e),t,s):0),e,t),addRow:(e,t,s=!0)=>Qs((()=>{let n;return ft(e,n,t)&&(e=y(e),Mt(e,Jt(e),n=((e,t)=>{const[s]=Fe(q,e);let n;do{n=s(t)}while(ge(Fe(Z,e),n));return n})(e,s?1:0),t)),n})),setPartialRow:(e,t,s)=>rs(((e,t)=>{if(ft(e,t,s,1)){const n=Jt(e);Ee(s,((s,o)=>Et(e,n,t,o,s)))}}),e,t),setCell:(e,t,s,n)=>rs(((e,t,s)=>Q(It(e,t,s,O(n)?n(fs(e,t,s)):n),(n=>Et(e,Jt(e),t,s,n)))),e,t,s),setValues:Vs,setPartialValues:e=>rs((()=>bt(e,1)?Ee(e,((e,t)=>Ht(t,e))):0)),setValue:(e,t)=>rs((e=>Q(wt(e,O(t)?t(ws(e)):t),(t=>Ht(e,t)))),e),applyChanges:e=>rs((()=>{Ee(e[0],((e,t)=>F(e)?Ds(t):Ee(e,((e,s)=>F(e)?Hs(t,s):Ee(e,((e,n)=>le(Os,t,s,n,e))))))),Ee(e[1],((e,t)=>re(Os,t,e)))})),setTablesJson:Ms,setValuesJson:e=>{try{kt(pt(e))}catch{}return Os},setJson:e=>rs((()=>{try{const[t,s]=pt(e);vt(t),kt(s)}catch{Ms(e)}})),setTablesSchema:ms,setValuesSchema:Es,setSchema:(e,t)=>rs((()=>{ms(e),Es(t)})),delTables:ks,delTable:Ds,delRow:Hs,delCell:(e,t,s,n)=>rs(((e,t,s)=>Q(Fe(Z,e),(o=>Q(Fe(o,t),(l=>ge(l,s)?Qt(e,o,t,l,s,n):0))))),e,t,s),delValues:Js,delValue:e=>rs((e=>ge($,e)?zt(e):0),e),delTablesSchema:xs,delValuesSchema:Fs,delSchema:()=>rs((()=>{xs(),Fs()})),transaction:Qs,startTransaction:zs,getTransactionChanges:()=>[We(E,((e,t)=>-1===Fe(g,t)?void 0:We(e,((e,s)=>-1===Fe(Fe(M,t),s)?void 0:We(e,(([,e])=>e),(e=>_t(e)))),he,ke)),he,ke),We(D,(([,e])=>e),(e=>_t(e))),1],getTransactionLog:()=>[!he(E),!he(D),Pe(E,Pt,_t),Pe(H),We(D,Pt,_t),We(J),We(g),Ae(M),Pe(m),We(k)],finishTransaction:Ns,forEachTable:e=>be(Z,((t,s)=>e(s,(e=>be(t,((t,s)=>e(s,(e=>Qe(t,e))))))))),forEachTableCell:(e,t)=>Qe(Fe(Y,y(e)),t),forEachRow:(e,t)=>be(Fe(Z,y(e)),((e,s)=>t(s,(t=>Qe(e,t))))),forEachCell:(e,t,s)=>Qe(Fe(Fe(Z,y(e)),y(t)),s),forEachValue:e=>Qe($,e),addSortedRowIdsListener:(e,t,s,n,o,l,r)=>{let a=gs(e,t,s,n,o);return rt((()=>{const r=gs(e,t,s,n,o);U(r,a)||(a=r,l(Os,e,t,s,n,o,a))}),ve[r?1:0],[e,t],[is])},addStartTransactionListener:e=>rt(e,ot),addWillFinishTransactionListener:e=>rt(e,lt[0]),addDidFinishTransactionListener:e=>rt(e,lt[1]),callListener:e=>(dt(e),Os),delListener:e=>(ct(e),Os),getListenerStats:()=>({hasTables:Wt(te),tables:Wt(se),tableIds:Wt(oe),hasTable:Wt(ae),table:Wt(fe),tableCellIds:Wt(Le),hasTableCell:Wt(Ce,de),rowCount:Wt(Re),rowIds:Wt(Te),sortedRowIds:Wt(ve),hasRow:Wt(pe,de),row:Wt(ye,de),cellIds:Wt(me,de),hasCell:Wt(De,ue),cell:Wt(Ue,ue),invalidCell:Wt(Ke,ue),hasValues:Wt(Ye),values:Wt(Ze),valueIds:Wt(tt),hasValue:Wt(st),value:Wt(nt),invalidValue:Wt(Xe),transaction:ce(ot)+Wt(lt)}),isMergeable:()=>!1,createStore:Bt,addListener:rt,callListeners:it,setInternalListeners:(e,t,s,n,o)=>c=[e,t,s,n,o]};return Ee({[u+f]:[0,te,[],()=>[Ls()]],[f]:[0,se],[I]:[0,oe],[u+h]:[1,ae,[is],e=>[Cs(...e)]],[h]:[1,fe,[is]],[h+T]:[1,Le,[is]],[u+h+R]:[2,Ce,[is,cs],e=>[Rs(...e)]],[w]:[1,Re,[is]],[L]:[1,Te,[is]],[u+b]:[2,pe,[is,us],e=>[Ts(...e)]],[b]:[2,ye,[is,us]],[T]:[2,me,[is,us]],[u+R]:[3,De,[is,us,hs],e=>[vs(...e)]],[R]:[3,Ue,[is,us,hs],e=>Ot(fs(...e))],InvalidCell:[3,Ke],[u+p]:[0,Ye,[],()=>[ps()]],[p]:[0,Ze],[S]:[0,tt],[u+v]:[1,st,[bs],e=>[Ss(...e)]],[v]:[1,nt,[bs],e=>Ot(ws(e[0]))],InvalidValue:[1,Xe]},(([e,t,s,n],o)=>{Os[d+o+i]=(...o)=>rt(o[e],t[o[e+1]?1:0],e>0?A(o,0,e):void 0,s,n)})),Se(Os)},Ut={HasTable:1,Table:1,TableCellIds:1,HasTableCell:2,RowCount:1,RowIds:1,SortedRowIds:5,HasRow:2,Row:2,CellIds:2,HasCell:3,Cell:3,HasValue:1,Value:1,InvalidCell:3,InvalidValue:1},qt=(e=t)=>[Ft(e),Ft(e)],Gt=e=>{let s=1,n=qt(),o=0;const l=Je(),r=qe(),[a,c]=(e=>{let t=0,s=-1;const n=Q(e,(e=>{const t=bt(e);return ot(t/Ct)+ot(t/Rt)+ot(t/Tt)+ot(t/64)+ot(t)}),(()=>it(5))),o=e=>{const n=t,[o,l]=F(e)||""==e?[0,0]:[lt(r=e,0)*wt+lt(r,1)*Lt+lt(r,2)*Ct+lt(r,3)*Rt+lt(r,4)*Tt+64*lt(r,5)+lt(r,6),lt(r,7)*Rt+lt(r,8)*Tt+64*lt(r,9)+lt(r,10)];var r;t=D(n,o,E.HLC_TIME??Date.now()),s=t==n?t==o?D(s,l):s:t==o?l:-1};return[()=>{return o(),l=++s,ot((e=t)/wt)+ot(e/Lt)+ot(e/Ct)+ot(e/Rt)+ot(e/Tt)+ot(e/64)+ot(e)+ot(l/Rt)+ot(l/Tt)+ot(l/64)+ot(l)+n;var e,l},o]})(e),u=Bt(),g=e=>{const t=s;return s=0,e(),s=t,w},h=(e,s=0)=>{const o={},l={},[[r,a=t,i=0],d]=e,[u,g]=n,[h,I,b]=u;let w=s?i:b,L=a;me(r,(([e,n=t,l=0],r)=>{const a=Ne(h,r,Ft),[i,c,d]=a;let u=s?l:d,g=n;me(e,((e,t)=>{const[n,l,a]=f(e,Ne(i,t,Ft),De(De(o,r,ye),t,ye),s);u^=s?0:(l?kt(t,l):0)^kt(t,a),g=Ht(g,n)})),u^=s?0:Dt(c,n),Jt(a,n,u),w^=s?0:(d?kt(r,d):0)^kt(r,a[2]),L=Ht(L,g)})),w^=s?0:Dt(I,a),Jt(u,a,w);const[C]=f(d,g,l,s);return c(Ht(L,C)),[o,l,1]},f=(e,s,n,o)=>{const[l,r=t,a=0]=e,[i,c,d]=s;let u=r,g=o?a:d;return me(l,(([e,s=t,l=0],r)=>{const a=Ne(i,r,(()=>[void 0,t,0])),[,c,d]=a;(!c||s>c)&&(Jt(a,s,o?l:bt(St(e??null)+":"+s)),a[0]=e,n[r]=e,g^=o?0:kt(r,d)^kt(r,a[2]),u=Ht(u,s))})),g^=o?0:Dt(c,r),Jt(s,r,g),[u,d,s[2]]},I=()=>[Qt(n[0],(e=>Qt(e,(e=>Qt(e))))),Qt(n[1])],b=e=>g((()=>u.applyChanges(h(e)))),w={getMergeableContent:I,getMergeableContentHashes:()=>[n[0][2],n[1][2]],getMergeableTableHashes:()=>We(n[0][0],Et),getMergeableTableDiff:e=>{const t=xt(n[0][1]),s={};return Qe(n[0][0],((n,[o,l,r])=>Ve(e,n)?r!=e[n]?s[n]=r:0:t[0][n]=zt([o,l],(e=>zt(e))))),[t,s]},getMergeableRowHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n,,o])=>o!=e?Qe(n,((e,[,,n])=>De(t,s,ye)[e]=n)):0)))),t},getMergeableRowDiff:e=>{const t=xt(n[0][1]),s={};return me(e,((e,o)=>Qe(Fe(n[0][0],o)?.[0],((n,[l,r,a])=>Ve(e,n)?a!==e[n]?De(s,o,ye)[n]=a:0:De(t[0],o,xt)[0][n]=zt([l,r]))))),[t,s]},getMergeableCellHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n])=>me(e,((e,o)=>Q(Fe(n,o),(([n,,l])=>l!==e?Qe(n,((e,[,,n])=>De(De(t,s,ye),o,ye)[e]=n)):0)))))))),t},getMergeableCellDiff:e=>{const[[t,s]]=n,o={};return me(e,((e,s)=>me(e,((e,n)=>Q(Fe(t,s),(([t,l])=>Q(Fe(t,n),(([t,r])=>Qe(t,((t,[a,i,c])=>c!==e[t]?De(De(o,s,(()=>xt(l)))[0],n,(()=>xt(r)))[0][t]=[a,i]:0)))))))))),Mt(o,s)},getMergeableValueHashes:()=>We(n[1][0],Et),getMergeableValueDiff:e=>{const[,[t,s]]=n,o=We(t,yt,(([,,t],s)=>t==e?.[s]));return Mt(o,s)},setMergeableContent:e=>g((()=>(e=>W(e)&&2==P(e)&&Nt(e[0],(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,oe)),void 0,1)))),void 0,1)))),void 0,1)))&&Nt(e[1],(e=>He(e,(e=>Nt(e,oe)),void 0,1))))(e)?u.transaction((()=>{u.delTables().delValues(),n=qt(),u.applyChanges(h(e,1))})):0)),setDefaultContent:e=>(u.transaction((()=>{o=1,u.setContent(e),o=0})),w),getTransactionMergeableChanges:(e=!1)=>{const[[t,s,o],[a,i,c]]=n,d=e?mt:Mt,u={};be(l,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const l={};be(e,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const r={};be(e,(e=>{Q(Fe(t,e),(([t,s,n])=>r[e]=d(t,s,n)))})),l[s]=d(r,n,o)})))),u[s]=d(l,n,o)}))));const g={};return be(r,(e=>Q(Fe(a,e),(([t,s,n])=>g[e]=d(t,s,n))))),[d(u,s,o),d(g,i,c),1]},applyMergeableChanges:b,merge:e=>{const t=I(),s=e.getMergeableContent();return e.applyMergeableChanges(t),b(s)}};return u.setInternalListeners((()=>{}),(()=>{}),(()=>{Ie(l),Ie(r)}),((e,n,r,i)=>{Ge(Ne(Ne(l,e,Je),n,qe),r),s&&h([[{[e]:[{[n]:[{[r]:[i,o?t:a()]}]}]}],[{}],1])}),((e,n)=>{Ge(r,e),s&&h([[{}],[{[e]:[n,o?t:a()]}],1])})),Ee(u,((e,t)=>w[t]=V(t,"set")||V(t,"del")||V(t,"apply")||M(t,"Transaction")||t=="call"+i?(...t)=>(e(...t),w):V(t,d)&&M(t,i)?(...s)=>{const n=Ut[A(t,3,-8)]??0,o=s[n];return s[n]=(e,...t)=>o(w,...t),e(...s)}:"isMergeable"==t?()=>!0:e)),Se(w)};export{tt as createCheckpoints,ct as createIndexes,Gt as createMergeableStore,gt as createMetrics,ht as createQueries,ft as createRelationships,Bt as createStore,at as defaultSorter,it as getUniqueId};
1
+ const e=e=>typeof e,t="",s=e(t),n=e(!0),o=e(0),l=e(e),r="type",a="default",i="Listener",c="Result",d="add",u="Has",g="Ids",h="Table",f=h+"s",I=h+g,b="Row",w=b+"Count",L=b+g,C="Sorted"+b+g,R="Cell",T=R+g,v="Value",p=v+"s",S=v+g,y=e=>t+e,V=(e,t)=>e.startsWith(t),M=(e,t)=>e.endsWith(t),m=(e,s=t,n)=>e.split(s,n),E=globalThis,k=Math,D=k.max,H=k.min,J=k.floor,x=isFinite,F=e=>null==e,Q=(e,t,s)=>F(e)?s?.():t(e),z=e=>e==s||e==n,N=t=>e(t)==s,O=t=>e(t)==l,W=e=>Array.isArray(e),A=(e,t,s)=>e.slice(t,s),P=e=>e.length,_=()=>{},j=(e,t)=>e.includes(t),B=(e,t)=>e.every(t),U=(e,t)=>P(e)===P(t)&&B(e,((e,s)=>t[s]===e)),q=(e,t)=>B(e,((s,n)=>0==n||t(e[n-1],s)<=0)),G=(e,t)=>e.sort(t),K=(e,t)=>e.forEach(t),X=(e,t)=>e.map(t),Y=e=>$(e,((e,t)=>e+t),0),Z=e=>0==P(e),$=(e,t,s)=>e.reduce(t,s),ee=(e,...t)=>e.push(...t),te=e=>e.pop(),se=e=>e.shift(),ne=t=>{const s=e(t);return z(s)||s==o&&x(t)?s:void 0},oe=e=>F(e)||!F(ne(e)),le=(e,t,s,n,o)=>F(o)?e.delCell(t,s,n,!0):e.setCell(t,s,n,o),re=(e,t,s)=>F(s)?e.delValue(t):e.setValue(t,s),ae=e=>t=>$(fe(t),((t,s)=>t+e(s)),0),ie=e=>e?.size??0,ce=ae(ie),de=ae(ce),ue=ae(de),ge=(e,t)=>e?.has(t)??!1,he=e=>F(e)||0==ie(e),fe=e=>[...e?.values()??[]],Ie=e=>e.clear(),be=(e,t)=>e?.forEach(t),we=(e,t)=>e?.delete(t),Le=Object,Ce=e=>Le.getPrototypeOf(e),Re=Le.entries,Te=Le.isFrozen,ve=e=>!F(e)&&Q(Ce(e),(e=>e==Le.prototype||F(Ce(e))),(()=>!0)),pe=Le.keys,Se=Le.freeze,ye=(e=[])=>Le.fromEntries(e),Ve=(e,t)=>t in e,Me=(e,t)=>(delete e[t],e),me=(e,t)=>K(Re(e),(([e,s])=>t(s,e))),Ee=(e,t)=>ye(((e,t)=>X(Re(e),(([e,s])=>t(s,e))))(e,((e,s)=>[s,t(e,s)]))),ke=e=>ve(e)&&0==(e=>P(pe(e)))(e),De=(e,t,s)=>(Ve(e,t)||(e[t]=s()),e[t]),He=(e,t,s,n=0)=>F(e)||!ve(e)||!n&&ke(e)||Te(e)?(s?.(),!1):(me(e,((s,n)=>{t(s,n)||Me(e,n)})),!!n||!ke(e)),Je=e=>new Map(e),xe=e=>[...e?.keys()??[]],Fe=(e,t)=>e?.get(t),Qe=(e,t)=>be(e,((e,s)=>t(s,e))),ze=(e,t,s)=>F(s)?(we(e,t),e):e?.set(t,s),Ne=(e,t,s,n)=>(ge(e,t)?n?.(Fe(e,t)):ze(e,t,s()),Fe(e,t)),Oe=(e,t,s,n=ze)=>(Ee(t,((t,n)=>s(e,n,t))),Qe(e,(s=>Ve(t,s)?0:n(e,s))),e),We=(e,t,s,n)=>{const o={};return be(e,((e,l)=>{if(!s?.(e,l)){const s=t?t(e,l):e;n?.(s)||(o[l]=s)}})),o},Ae=(e,t,s)=>We(e,(e=>We(e,t,s)),he,ke),Pe=(e,t,s)=>We(e,(e=>Ae(e,t,s)),he,ke),_e=(e,t)=>{const s=Je();return be(e,((e,n)=>s.set(n,t?.(e)??e))),s},je=e=>_e(e,_e),Be=e=>_e(e,je),Ue=(e,t,s,n,o=0)=>Q((s?Ne:Fe)(e,t[o],o>P(t)-2?s:Je),(l=>{if(o>P(t)-2)return n?.(l)&&ze(e,t[o]),l;const r=Ue(l,t,s,n,o+1);return he(l)&&ze(e,t[o]),r})),qe=e=>new Set(W(e)||F(e)?e:[e]),Ge=(e,t)=>e?.add(t),Ke=(e,t,s,n,o)=>{const l=e.hasRow,r=Je(),a=Je(),i=Je(),c=Je(),d=Je(),u=Je(),g=(t,s,...n)=>{const o=Ne(u,t,qe);return K(n,(t=>Ge(o,t)&&s&&e.callListener(t))),n},h=(t,...s)=>Q(Fe(u,t),(n=>{K(Z(s)?fe(n):s,(t=>{e.delListener(t),we(n,t)})),he(n)&&ze(u,t)})),f=(e,s)=>{ze(r,e,s),ge(a,e)||(ze(a,e,t()),ze(c,e,Je()),ze(d,e,Je()),o(i))},I=e=>{ze(r,e),ze(a,e),ze(c,e),ze(d,e),h(e),o(i)};return[()=>e,()=>xe(r),e=>Qe(a,e),e=>ge(a,e),e=>Fe(r,e),e=>Fe(a,e),(e,t)=>ze(a,e,t),f,(t,n,o,r,a)=>{f(t,n);const i=Je(),u=Je(),I=Fe(c,t),b=Fe(d,t),w=t=>{const o=s=>e.getCell(n,t,s),c=Fe(I,t),d=l(n,t)?s(r(o,t)):void 0;if(c===d||W(c)&&W(d)&&U(c,d)||ze(i,t,[c,d]),!F(a)){const e=Fe(b,t),s=l(n,t)?a(o,t):void 0;e!=s&&ze(u,t,s)}},L=e=>{o((()=>{be(i,(([,e],t)=>ze(I,t,e))),be(u,((e,t)=>ze(b,t,e)))}),i,u,I,b,e),Ie(i),Ie(u)};Qe(I,w),e.hasTable(n)&&K(e.getRowIds(n),(e=>{ge(I,e)||w(e)})),L(!0),h(t),g(t,0,e.addRowListener(n,null,((e,t,s)=>w(s))),e.addTableListener(n,(()=>L())))},I,e=>n(e,i),()=>Qe(u,I),g,h]},Xe=(e,s)=>N(e)?t=>t(e):e??(()=>s??t),Ye=(e,t)=>{const s=new WeakMap;return n=>{s.has(n)||s.set(n,e(n));const o=s.get(n);return t?.(o),o}},Ze=/^\d+$/,$e=()=>{const e=[];let s=0;return[n=>(n?se(e):null)??t+s++,t=>{Ze.test(t)&&P(e)<1e3&&ee(e,t)}]},et=e=>{let s;const[n,o]=$e(),l=Je();return[(o,r,a,i=[],c=()=>[])=>{s??=e();const d=n(1);return ze(l,d,[o,r,a,i,c]),Ge(Ue(r,a??[t],qe),d),d},(e,n,...o)=>K(((e,s=[t])=>{const n=[],o=(e,t)=>t==P(s)?ee(n,e):null===s[t]?be(e,(e=>o(e,t+1))):K([s[t],null],(s=>o(Fe(e,s),t+1)));return o(e,0),n})(e,n),(e=>be(e,(e=>Fe(l,e)[0](s,...n??[],...o))))),e=>Q(Fe(l,e),(([,s,n])=>(Ue(s,n??[t],void 0,(t=>(we(t,e),he(t)?1:0))),ze(l,e),o(e),n))),e=>Q(Fe(l,e),(([e,,t=[],n,o])=>{const l=(...r)=>{const a=P(r);a==P(t)?e(s,...r,...o(r)):F(t[a])?K(n[a]?.(...r)??[],(e=>l(...r,e))):l(...r,t[a])};l()}))]},tt=Ye((e=>{let s,n,o,l=100,r=Je(),a=Je(),i=1;const c=Je(),d=Je(),[u,g,h]=et((()=>J)),f=Je(),I=Je(),b=[],w=[],L=(t,s)=>{i=0,e.transaction((()=>{const[n,o]=Fe(f,s);be(n,((s,n)=>be(s,((s,o)=>be(s,((s,l)=>le(e,n,o,l,s[t]))))))),be(o,((s,n)=>re(e,n,s[t])))})),i=1},C=e=>{ze(f,e),ze(I,e),g(d,[e])},R=(e,t)=>K(((e,t)=>e.splice(0,t))(e,t??P(e)),C),T=()=>R(b,P(b)-l),v=()=>Q(s,(()=>{ee(b,s),T(),R(w),s=void 0,o=1})),p=()=>{s=te(b),o=1};let S,y;const V=(e=t)=>(F(s)&&(s=t+n++,ze(f,s,[r,a]),D(s,e),r=Je(),a=Je(),o=1),s),M=()=>{Z(b)||(((e,...t)=>{e.unshift(...t)})(w,V()),L(0,s),s=te(b),o=1)},m=()=>{Z(w)||(ee(b,s),s=se(w),L(1,s),o=1)},E=()=>{o&&(g(c),o=0)},k=e=>{const t=V(e);return E(),t},D=(e,t)=>(H(e)&&Fe(I,e)!==t&&(ze(I,e,t),g(d,[e])),J),H=e=>ge(f,e),J={setSize:e=>(l=e,T(),J),addCheckpoint:k,setCheckpoint:D,getStore:()=>e,getCheckpointIds:()=>[[...b],s,[...w]],forEachCheckpoint:e=>Qe(I,e),hasCheckpoint:H,getCheckpoint:e=>Fe(I,e),goBackward:()=>(M(),E(),J),goForward:()=>(m(),E(),J),goTo:e=>{const t=j(b,e)?M:j(w,e)?m:null;for(;!F(t)&&e!=s;)t();return E(),J},addCheckpointIdsListener:e=>u(e,c),addCheckpointListener:(e,t)=>u(t,d,[e]),delListener:e=>(h(e),J),clear:()=>(R(b),R(w),F(s)||C(s),s=void 0,n=0,k(),J),clearForward:()=>(Z(w)||(R(w),g(c)),J),destroy:()=>{e.delListener(S),e.delListener(y)},getListenerStats:()=>({checkpointIds:ce(c),checkpoint:ce(d)}),_registerListeners:()=>{S=e.addCellListener(null,null,null,((e,t,s,n,o,l)=>{if(i){v();const e=Ne(r,t,Je),a=Ne(e,s,Je),i=Ne(a,n,(()=>[l,void 0]));i[1]=o,i[0]===o&&he(ze(a,n))&&he(ze(e,s))&&he(ze(r,t))&&p(),E()}})),y=e.addValueListener(null,((e,t,s,n)=>{if(i){v();const e=Ne(a,t,(()=>[n,void 0]));e[1]=s,e[0]===s&&he(ze(a,t))&&p(),E()}}))}};return Se(J.clear())}),(e=>e._registerListeners())),st=m("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"),nt=Je(X(st,((e,t)=>[e,t]))),ot=e=>st[63&e],lt=(e,t)=>Fe(nt,e[t])??0,rt=E.crypto?e=>E.crypto.getRandomValues(e):e=>X(e,(()=>J(256*k.random()))),at=(e,t)=>(e??0)<(t??0)?-1:1,it=(e=16)=>$(rt(new Uint8Array(e)),((e,t)=>e+ot(t)),""),ct=Ye((e=>{const s=Je(),n=Je(),[o,l,r]=et((()=>C)),[a,i,c,d,u,g,h,,f,I,b,w]=Ke(e,Je,(e=>F(e)?t:W(e)?X(e,y):y(e)),o,l),L=(t,s,n)=>{const o=u(t);be(n,((t,n)=>s(n,(s=>be(t,(t=>s(t,(s=>e.forEachCell(o,t,s)))))))))},C={setIndexDefinition:(e,t,o,r,a,i=at)=>{const c=F(a)?void 0:([e],[t])=>a(e,t);return f(e,t,((t,o,a,d,u,f)=>{let I=0;const b=qe(),w=qe(),L=g(e);if(be(o,(([e,t],s)=>{const n=qe(e),o=qe(t);be(n,(e=>we(o,e)?we(n,e):0)),be(n,(e=>{Ge(b,e),Q(Fe(L,e),(t=>{we(t,s),he(t)&&(ze(L,e),I=1)}))})),be(o,(e=>{Ge(b,e),ge(L,e)||(ze(L,e,qe()),I=1),Ge(Fe(L,e),s),F(r)||Ge(w,e)}))})),t(),he(u)||(f?Qe(L,(e=>Ge(w,e))):Qe(a,(e=>Q(Fe(d,e),(e=>K(W(e)?e:[e],(e=>Ge(w,e))))))),be(w,(e=>{const t=(t,s)=>i(Fe(u,t),Fe(u,s),e),s=[...Fe(L,e)];q(s,t)||(ze(L,e,qe(G(s,t))),Ge(b,e))}))),(I||f)&&!F(c)){const t=[...L];q(t,c)||(h(e,Je(G(t,c))),I=1)}I&&l(s,[e]),be(b,(t=>l(n,[e,t])))}),Xe(o),Q(r,Xe)),C},delIndexDefinition:e=>(I(e),C),getStore:a,getIndexIds:i,forEachIndex:e=>c(((t,s)=>e(t,(e=>L(t,e,s))))),forEachSlice:(e,t)=>L(e,t,g(e)),hasIndex:d,hasSlice:(e,t)=>ge(g(e),t),getTableId:u,getSliceIds:e=>xe(g(e)),getSliceRowIds:(e,t)=>fe(Fe(g(e),t)),addIndexIdsListener:b,addSliceIdsListener:(e,t)=>o(t,s,[e]),addSliceRowIdsListener:(e,t,s)=>o(s,n,[e,t]),delListener:e=>(r(e),C),destroy:w,getListenerStats:()=>({sliceIds:ce(s),sliceRowIds:de(n)})};return Se(C)})),dt=Je([["avg",[(e,t)=>Y(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>D(...e),(e,t)=>D(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:D(t,e)]],["min",[e=>H(...e),(e,t)=>H(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:H(t,e)]],["sum",[e=>Y(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),ut=(e,t,s,n,o,l=!1)=>{if(he(s))return;const[r,a,i,c]=o;return l||=F(e),be(n,(([s,n])=>{l||(e=F(s)?a?.(e,n,t++):F(n)?i?.(e,s,t--):c?.(e,n,s,t),l||=F(e))})),l?r(fe(s),ie(s)):e},gt=Ye((e=>{const s=Je(),[n,o,l]=et((()=>w)),[r,a,i,c,d,u,g,,h,f,I,b]=Ke(e,_,(e=>isNaN(e)||F(e)||!0===e||!1===e||e===t?void 0:1*e),n,o),w={setMetricDefinition:(e,t,n,l,r,a,i)=>{const c=O(n)?[n,r,a,i]:Fe(dt,n)??Fe(dt,"sum");return h(e,t,((t,n,l,r,a,i)=>{const d=u(e),h=ie(r);i||=F(d),t();let f=ut(d,h,r,n,c,i);x(f)||(f=void 0),f!=d&&(g(e,f),o(s,[e],f,d))}),Xe(l,1)),w},delMetricDefinition:e=>(f(e),w),getStore:r,getMetricIds:a,forEachMetric:i,hasMetric:c,getTableId:d,getMetric:u,addMetricIdsListener:I,addMetricListener:(e,t)=>n(t,s,[e]),delListener:e=>(l(e),w),destroy:b,getListenerStats:()=>({metric:ce(s)})};return Se(w)})),ht=Ye((e=>{const s=e.createStore,n=s(),o=s(),l=Je(),{addListener:r,callListeners:a,delListener:u}=o,[g,f,I,v,p,,,S,,y,V,M,m,E]=Ke(e,(()=>!0),_,r,a),k=(e,t,...s)=>K(s,(s=>Ge(Ne(Ne(l,t,Je),e,qe),s))),D=e=>{Q(Fe(l,e),(e=>{Qe(e,((e,t)=>be(t,(t=>e.delListener(t))))),Ie(e)})),K([o,n],(t=>t.delTable(e)))},H=(e,t,s)=>k(t,e,t.addStartTransactionListener(s.startTransaction),t.addDidFinishTransactionListener((()=>s.finishTransaction()))),J={setQueryDefinition:(s,l,r)=>{S(s,l),D(s);const a=[],i=[[null,[l,null,null,[],Je()]]],c=[],d=[],u=[];r({select:(e,s)=>{const n=O(e)?[P(a)+t,e]:[F(s)?e:s,t=>t(e,s)];return ee(a,n),{as:e=>n[0]=e}},join:(e,t,s)=>{const n=F(s)||O(t)?null:t,o=F(n)?t:s,l=[e,[e,n,O(o)?o:e=>e(o),[],Je()]];return ee(i,l),{as:e=>l[0]=e}},where:(e,t,s)=>ee(c,O(e)?e:F(s)?s=>s(e)===t:n=>n(e,t)===s),group:(e,t,s,n,o)=>{const l=[e,[e,O(t)?[t,s,n,o]:Fe(dt,t)??[(e,t)=>t]]];return ee(d,l),{as:e=>l[0]=e}},having:(e,t)=>ee(u,O(e)?e:s=>s(e)===t)});const g=Je(a);if(he(g))return J;const h=Je(i);Qe(h,((e,[,t])=>Q(Fe(h,t),(({3:t})=>F(e)?0:ee(t,e)))));const f=Je(d);let I=n;if(he(f)&&Z(u))I=o;else{H(s,I,o);const e=Je();Qe(f,((t,[s,n])=>Ge(Ne(e,s,qe),[t,n])));const t=qe();Qe(g,(s=>ge(e,s)?0:Ge(t,s)));const n=Je(),l=(t,n,l,r)=>Q(t,(([a,i,c,d])=>{Qe(n,((t,[s])=>{const n=Ne(a,t,Je),o=Fe(n,l),i=r?void 0:s;if(o!==i){const s=qe([[o,i]]),r=ie(n);ze(n,l,i),be(Fe(e,t),(([e,t])=>{const o=ut(d[e],r,n,s,t);d[e]=F(ne(o))?null:o}))}})),he(i)||!B(u,(e=>e((e=>d[e]))))?o.delRow(s,c):F(c)?t[2]=o.addRow(s,d):o.setRow(s,c,d)}));k(I,s,I.addRowListener(s,null,((o,r,a,i)=>{const c=[],d=[],u=Je(),g=I.hasRow(s,a);let h=!g;be(t,(e=>{const[t,n,o]=i(s,a,e);ee(c,n),ee(d,o),h||=t})),Qe(e,(e=>{const[t,,n]=i(s,a,e);(h||t)&&ze(u,e,[n])})),h&&l(Ue(n,c,void 0,(([,e])=>(we(e,a),he(e)))),u,a,1),g&&l(Ue(n,d,(()=>{const e={};return be(t,(t=>e[t]=I.getCell(s,a,t))),[Je(),qe(),void 0,e]}),(([,e])=>{Ge(e,a)})),u,a)})))}H(s,e,I);const b=(t,n,o,r)=>{const a=t=>e.getCell(n,o,t);K(r,(n=>{const[o,,l,r,i]=Fe(h,n),c=l?.(a,t),[d,u]=Fe(i,t)??[];c!=d&&(F(u)||E(s,u),ze(i,t,F(c)?null:[c,...m(s,1,e.addRowListener(o,c,(()=>b(t,o,c,r))))]))})),(t=>{const n=(s,n)=>e.getCell(...F(n)?[l,t,s]:s===l?[l,t,n]:[Fe(h,s)?.[0],Fe(Fe(h,s)?.[4],t)?.[0],n]);I.transaction((()=>B(c,(e=>e(n)))?Qe(g,((e,o)=>le(I,s,t,e,o(n,t)))):I.delRow(s,t)))})(t)},{3:w}=Fe(h,null);return I.transaction((()=>m(s,1,e.addRowListener(l,null,((t,n,o)=>{e.hasRow(l,o)?b(o,l,o,w):(I.delRow(s,o),be(h,(({4:e})=>Q(Fe(e,o),(([,t])=>{E(s,t),ze(e,o)})))))}))))),J},delQueryDefinition:e=>(D(e),y(e),J),getStore:g,getQueryIds:f,forEachQuery:I,hasQuery:v,getTableId:p,addQueryIdsListener:e=>V((()=>e(J))),delListener:e=>(u(e),J),destroy:M,getListenerStats:()=>{const{tables:e,tableIds:t,transaction:s,...n}=o.getListenerStats();return n}};return Ee({[h]:[1,1],[h+T]:[0,1],[w]:[0,1],[L]:[0,1],[C]:[0,5],[b]:[1,2],[T]:[0,2],[R]:[1,3]},(([e,t],s)=>{K(e?["get","has","forEach"]:["get"],(e=>J[e+c+s]=(...t)=>o[e+s](...t))),J[d+c+s+i]=(...e)=>o[d+s+i](...A(e,0,t),((s,...n)=>e[t](J,...n)),!0)})),Se(J)})),ft=Ye((e=>{const s=Je(),n=Je(),o=Je(),l=Je(),[r,a,i]=et((()=>v)),[c,d,u,g,h,f,,,I,b,w,L]=Ke(e,(()=>[Je(),Je(),Je(),Je()]),(e=>F(e)?void 0:e+t),r,a),C=(e,t,s)=>Q(f(e),(([n,,o])=>{if(!ge(o,t)){const l=qe();if(h(e)!=T(e))Ge(l,t);else{let e=t;for(;!F(e)&&!ge(l,e);)Ge(l,e),e=Fe(n,e)}if(s)return l;ze(o,t,l)}return Fe(o,t)})),R=(e,t)=>Q(f(e),(([,,e])=>ze(e,t))),T=e=>Fe(s,e),v={setRelationshipDefinition:(e,t,r,i)=>(ze(s,e,r),I(e,t,((t,s)=>{const r=qe(),i=qe(),c=qe(),[d,u]=f(e);be(s,(([t,s],n)=>{F(t)||(Ge(i,t),Q(Fe(u,t),(e=>{we(e,n),he(e)&&ze(u,t)}))),F(s)||(Ge(i,s),ge(u,s)||ze(u,s,qe()),Ge(Fe(u,s),n)),Ge(r,n),ze(d,n,s),Qe(Fe(l,e),(t=>{ge(C(e,t),n)&&Ge(c,t)}))})),t(),be(r,(t=>a(n,[e,t]))),be(i,(t=>a(o,[e,t]))),be(c,(t=>{R(e,t),a(l,[e,t])}))}),Xe(i)),v),delRelationshipDefinition:e=>(ze(s,e),b(e),v),getStore:c,getRelationshipIds:d,forEachRelationship:t=>u((s=>t(s,(t=>e.forEachRow(h(s),t))))),hasRelationship:g,getLocalTableId:h,getRemoteTableId:T,getRemoteRowId:(e,t)=>Fe(f(e)?.[0],t),getLocalRowIds:(e,t)=>fe(Fe(f(e)?.[1],t)),getLinkedRowIds:(e,t)=>F(f(e))?[t]:fe(C(e,t,!0)),addRelationshipIdsListener:w,addRemoteRowIdListener:(e,t,s)=>r(s,n,[e,t]),addLocalRowIdsListener:(e,t,s)=>r(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(C(e,t),r(s,l,[e,t])),delListener:e=>(R(...i(e)??[]),v),destroy:L,getListenerStats:()=>({remoteRowId:de(n),localRowIds:de(o),linkedRowIds:de(l)})};return Se(v)})),It=new E.TextEncoder,bt=e=>{let t=2166136261;return K(It.encode(e),(e=>{t^=e,t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)})),t>>>0},wt=2**36,Lt=2**30,Ct=2**24,Rt=2**18,Tt=4096,vt=JSON.stringify,pt=JSON.parse,St=e=>vt(e,((e,t)=>t instanceof Map?Le.fromEntries([...t]):t)),yt=([e,t])=>Mt(e,t),Vt=([e,t,s])=>[e,t,s],Mt=(e,t)=>t?[e,t]:[e],mt=(e,t,s)=>[e,t,s],Et=e=>e[2],kt=(e,t)=>bt(e+":"+t),Dt=(e,t)=>t>e?(e?bt(e):0)^bt(t):0,Ht=(e,t)=>((e??"")>(t??"")?e:t)??"",Jt=(e,t,s)=>{t>e[1]&&(e[1]=t),e[2]=s>>>0},xt=(e=t)=>Mt(ye(),e),Ft=(e=t)=>[Je(),e,0],Qt=([e,t,s],n=Vt)=>[We(e,n),t,s],zt=([e,t],s=yt)=>Mt(We(e,s),t),Nt=(t,s)=>W(t)&&3==P(t)&&N(t[1])&&e(t[2])==o&&x(t[2])&&s(t[0]),Ot=e=>[e,e],Wt=(e,t=ce)=>t(e[0])+t(e[1]),At=()=>[Je(),Je()],Pt=e=>[...e],_t=([e,t])=>e===t,jt=(e,t,s)=>ze(e,t,Fe(e,t)==-s?void 0:s),Bt=()=>{let e,t,s=!1,n=!1,l=0,c=[];const g=Je(),C=Je(),V=Je(),M=Je(),m=Je(),E=Je(),k=Je(),D=Je(),H=Je(),J=Je(),x=Je(),N=Je(),P=Je(),_=Je(),B=qe(),q=Je(),Y=Je(),Z=Je(),$=Je(),te=At(),se=At(),oe=At(),ae=At(),fe=At(),Le=At(),Ce=At(),Re=At(),Te=At(),ve=At(),pe=At(),ye=At(),me=At(),De=At(),Ue=At(),Ke=At(),Xe=At(),Ye=At(),Ze=At(),tt=At(),st=At(),nt=At(),ot=Je(),lt=At(),[rt,it,ct,dt]=et((()=>Os)),ut=e=>{if(!He(e,((e,t)=>j([r,a],t))))return!1;const t=e[r];return!(!z(t)&&t!=o||(ne(e[a])!=t&&Me(e,a),0))},gt=W,ht=(t,s)=>(!e||ge(x,s)||Yt(s))&&He(t,((e,t)=>ft(s,t,e)),(()=>Yt(s))),ft=(e,t,s,n)=>He(n?s:Lt(s,e,t),((n,o)=>Q(It(e,t,o,n),(e=>(s[o]=e,!0)),(()=>!1))),(()=>Yt(e,t))),It=(t,s,n,o)=>e?Q(Fe(Fe(x,t),n),(e=>ne(o)!=e[r]?Yt(t,s,n,o,e[a]):o),(()=>Yt(t,s,n,o))):F(ne(o))?Yt(t,s,n,o):o,bt=(e,t)=>He(t?e:Ct(e),((t,s)=>Q(wt(s,t),(t=>(e[s]=t,!0)),(()=>!1))),(()=>Zt())),wt=(e,s)=>t?Q(Fe(P,e),(t=>ne(s)!=t[r]?Zt(e,s,t[a]):s),(()=>Zt(e,s))):F(ne(s))?Zt(e,s):s,Lt=(e,t,s)=>(Q(Fe(N,t),(([n,o])=>{be(n,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(o,(n=>{Ve(e,n)||Yt(t,s,n)}))})),e),Ct=e=>(t&&(be(_,((t,s)=>{Ve(e,s)||(e[s]=t)})),be(B,(t=>{Ve(e,t)||Zt(t)}))),e),Rt=e=>Oe(x,e,((e,t,s)=>{const n=Je(),o=qe();Oe(Ne(x,t,Je),s,((e,t,s)=>{ze(e,t,s),Q(s[a],(e=>ze(n,t,e)),(()=>Ge(o,t)))})),ze(N,t,[n,o])}),((e,t)=>{ze(x,t),ze(N,t)})),Tt=e=>Oe(P,e,((e,t,s)=>{ze(P,t,s),Q(s[a],(e=>ze(_,t,e)),(()=>Ge(B,t)))}),((e,t)=>{ze(P,t),ze(_,t),we(B,t)})),vt=e=>ke(e)?ks():ys(e),yt=e=>Oe(Z,e,((e,t,s)=>Vt(t,s)),((e,t)=>xt(t))),Vt=(e,t)=>Oe(Ne(Z,e,(()=>(Nt(e,1),ze(q,e,$e()),ze(Y,e,Je()),Je()))),t,((t,s,n)=>Mt(e,t,s,n)),((t,s)=>Ft(e,t,s))),Mt=(e,t,s,n,o)=>Oe(Ne(t,s,(()=>(Ut(e,s,1),Je()))),n,((t,n,o)=>mt(e,s,t,n,o)),((n,l)=>Qt(e,t,s,n,l,o))),mt=(e,t,s,n,o)=>{ge(s,n)||qt(e,t,n,1);const l=Fe(s,n);o!==l&&(Gt(e,t,n,l,o),ze(s,n,o))},Et=(e,t,s,n,o)=>Q(Fe(t,s),(t=>mt(e,s,t,n,o)),(()=>Mt(e,t,s,Lt({[n]:o},e,s)))),kt=e=>ke(e)?Js():Vs(e),Dt=e=>Oe($,e,((e,t,s)=>Ht(t,s)),((e,t)=>zt(t))),Ht=(e,t)=>{ge($,e)||Kt(e,1);const s=Fe($,e);t!==s&&(Xt(e,s,t),ze($,e,t))},Jt=e=>Fe(Z,e)??Vt(e,{}),xt=e=>Vt(e,{}),Ft=(e,t,s)=>{const[,n]=Fe(q,e);n(s),Mt(e,t,s,{},!0)},Qt=(e,t,s,n,o,l)=>{const r=Fe(Fe(N,e)?.[0],o);if(!F(r)&&!l)return mt(e,s,n,o,r);const a=t=>{Gt(e,s,t,Fe(n,t)),qt(e,s,t,-1),ze(n,t)};F(r)?a(o):Qe(n,a),he(n)&&(Ut(e,s,-1),he(ze(t,s))&&(Nt(e,-1),ze(Z,e),ze(q,e),ze(Y,e)))},zt=e=>{const t=Fe(_,e);if(!F(t))return Ht(e,t);Xt(e,Fe($,e)),Kt(e,-1),ze($,e)},Nt=(e,t)=>jt(g,e,t),Ut=(e,t,s)=>jt(Ne(M,e,Je),t,s)&&ze(V,e,Ne(V,e,(()=>0))+s),qt=(e,t,s,n)=>{const o=Fe(Y,e),l=Fe(o,s)??0;(0==l&&1==n||1==l&&-1==n)&&jt(Ne(C,e,Je),s,n),ze(o,s,l!=-n?l+n:null),jt(Ne(Ne(m,e,Je),t,Je),s,n)},Gt=(e,t,s,n,o)=>{Ne(Ne(Ne(E,e,Je),t,Je),s,(()=>[n,0]))[1]=o,c[3]?.(e,t,s,o)},Kt=(e,t)=>jt(k,e,t),Xt=(e,t,s)=>{Ne(D,e,(()=>[t,0]))[1]=s,c[4]?.(e,s)},Yt=(e,t,s,n,o)=>(ee(Ne(Ne(Ne(H,e,Je),t,Je),s,(()=>[])),n),o),Zt=(e,t,s)=>(ee(Ne(J,e,(()=>[])),t),s),$t=(e,t,s)=>Q(Fe(Fe(Fe(E,e),t),s),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(fs(e,t,s))])),es=e=>Q(Fe(D,e),(([e,t])=>[!0,e,t]),(()=>[!1,...Ot(ws(e))])),ts=e=>he(H)||he(Ke[e])?0:be(e?Be(H):H,((t,s)=>be(t,((t,n)=>be(t,((t,o)=>it(Ke[e],[s,n,o],t))))))),ss=e=>he(J)||he(Xe[e])?0:be(e?_e(J):J,((t,s)=>it(Xe[e],[s],t))),ns=(e,t,s,n)=>{if(!he(e))return it(t,n,(()=>We(e))),Qe(e,((e,t)=>it(s,[...n??[],e],1==t))),1},os=e=>{const t=Ls();t!=s&&it(te[e],void 0,t);const n=he(ve[e]),o=he(me[e])&&he(De[e])&&he(Te[e])&&he(pe[e])&&he(Le[e])&&he(Ce[e])&&he(Re[e])&&n&&he(oe[e])&&he(ae[e]),l=he(Ue[e])&&he(ye[e])&&he(fe[e])&&he(se[e]);if(!o||!l){const t=e?[_e(g),je(C),_e(V),je(M),Be(m),Be(E)]:[g,C,V,M,m,E];if(!o){ns(t[0],oe[e],ae[e]),be(t[1],((t,s)=>ns(t,Le[e],Ce[e],[s]))),be(t[2],((t,s)=>{0!=t&&it(Re[e],[s],ds(s))}));const s=qe();be(t[3],((t,o)=>{ns(t,Te[e],pe[e],[o])&&!n&&(it(ve[e],[o,null]),Ge(s,o))})),n||be(t[5],((t,n)=>{if(!ge(s,n)){const s=qe();be(t,(e=>be(e,(([t,n],o)=>n!==t?Ge(s,o):we(e,o))))),be(s,(t=>it(ve[e],[n,t])))}})),be(t[4],((t,s)=>be(t,((t,n)=>ns(t,me[e],De[e],[s,n])))))}if(!l){let s;be(t[5],((t,n)=>{let o;be(t,((t,l)=>{let r;be(t,(([t,a],i)=>{a!==t&&(it(Ue[e],[n,l,i],a,t,$t),s=o=r=1)})),r&&it(ye[e],[n,l],$t)})),o&&it(fe[e],[n],$t)})),s&&it(se[e],void 0,$t)}}},ls=e=>{const t=ps();t!=n&&it(Ye[e],void 0,t);const s=he(tt[e])&&he(st[e]),o=he(nt[e])&&he(Ze[e]);if(!s||!o){const t=e?[_e(k),_e(D)]:[k,D];if(s||ns(t[0],tt[e],st[e]),!o){let s;be(t[1],(([t,n],o)=>{n!==t&&(it(nt[e],[o],n,t,es),s=1)})),s&&it(Ze[e],void 0,es)}}},rs=(e,...t)=>(Qs((()=>e(...X(t,y)))),Os),as=()=>Pe(Z),is=()=>xe(Z),cs=e=>xe(Fe(Y,y(e))),ds=e=>ie(Fe(Z,y(e))),us=e=>xe(Fe(Z,y(e))),gs=(e,t,s,n=0,o)=>{return X(A(G((l=Fe(Z,y(e)),r=(e,s)=>[F(t)?s:Fe(e,y(t)),s],X([...l?.entries()??[]],(([e,t])=>r(t,e)))),(([e],[t])=>at(e,t)*(s?-1:1))),n,F(o)?o:n+o),(([,e])=>e));var l,r},hs=(e,t)=>xe(Fe(Fe(Z,y(e)),y(t))),fs=(e,t,s)=>Fe(Fe(Fe(Z,y(e)),y(t)),y(s)),Is=()=>We($),bs=()=>xe($),ws=e=>Fe($,y(e)),Ls=()=>!he(Z),Cs=e=>ge(Z,y(e)),Rs=(e,t)=>ge(Fe(Y,y(e)),y(t)),Ts=(e,t)=>ge(Fe(Z,y(e)),y(t)),vs=(e,t,s)=>ge(Fe(Fe(Z,y(e)),y(t)),y(s)),ps=()=>!he($),Ss=e=>ge($,y(e)),ys=e=>rs((()=>(e=>He(e,ht,Yt))(e)?yt(e):0)),Vs=e=>rs((()=>bt(e)?Dt(e):0)),Ms=e=>{try{vt(pt(e))}catch{}return Os},ms=t=>rs((()=>{if((e=He(t,(e=>He(e,ut))))&&(Rt(t),!he(Z))){const e=as();ks(),ys(e)}})),Es=e=>rs((()=>{if(t=(e=>He(e,ut))(e)){const s=Is();Fs(),Js(),t=!0,Tt(e),Vs(s)}})),ks=()=>rs((()=>yt({}))),Ds=e=>rs((e=>ge(Z,e)?xt(e):0),e),Hs=(e,t)=>rs(((e,t)=>Q(Fe(Z,e),(s=>ge(s,t)?Ft(e,s,t):0))),e,t),Js=()=>rs((()=>Dt({}))),xs=()=>rs((()=>{Rt({}),e=!1})),Fs=()=>rs((()=>{Tt({}),t=!1})),Qs=(e,t)=>{if(-1!=l){zs();const s=e();return Ns(t),s}},zs=()=>(-1!=l&&l++,1==l&&(c[0]?.(),it(ot)),Os),Ns=e=>(l>0&&(l--,0==l&&(l=1,ts(1),he(E)||os(1),ss(1),he(D)||ls(1),e?.(Os)&&(be(E,((e,t)=>be(e,((e,s)=>be(e,(([e],n)=>le(Os,t,s,n,e))))))),Ie(E),be(D,(([e],t)=>re(Os,t,e))),Ie(D)),it(lt[0],void 0),l=-1,ts(0),he(E)||os(0),ss(0),he(D)||ls(0),c[1]?.(),it(lt[1],void 0),c[2]?.(),l=0,s=Ls(),n=ps(),K([g,C,V,M,m,E,H,k,D,J],Ie))),Os),Os={getContent:()=>[as(),Is()],getTables:as,getTableIds:is,getTable:e=>Ae(Fe(Z,y(e))),getTableCellIds:cs,getRowCount:ds,getRowIds:us,getSortedRowIds:gs,getRow:(e,t)=>We(Fe(Fe(Z,y(e)),y(t))),getCellIds:hs,getCell:fs,getValues:Is,getValueIds:bs,getValue:ws,hasTables:Ls,hasTable:Cs,hasTableCell:Rs,hasRow:Ts,hasCell:vs,hasValues:ps,hasValue:Ss,getTablesJson:()=>St(Z),getValuesJson:()=>St($),getJson:()=>St([Z,$]),getTablesSchemaJson:()=>St(x),getValuesSchemaJson:()=>St(P),getSchemaJson:()=>St([x,P]),hasTablesSchema:()=>e,hasValuesSchema:()=>t,setContent:e=>rs((()=>{const t=O(e)?e():e;gt(t)&&(([e,t])=>{(ke(e)?ks:ys)(e),(ke(t)?Js:Vs)(t)})(t)})),setTables:ys,setTable:(e,t)=>rs((e=>ht(t,e)?Vt(e,t):0),e),setRow:(e,t,s)=>rs(((e,t)=>ft(e,t,s)?Mt(e,Jt(e),t,s):0),e,t),addRow:(e,t,s=!0)=>Qs((()=>{let n;return ft(e,n,t)&&(e=y(e),Mt(e,Jt(e),n=((e,t)=>{const[s]=Fe(q,e);let n;do{n=s(t)}while(ge(Fe(Z,e),n));return n})(e,s?1:0),t)),n})),setPartialRow:(e,t,s)=>rs(((e,t)=>{if(ft(e,t,s,1)){const n=Jt(e);Ee(s,((s,o)=>Et(e,n,t,o,s)))}}),e,t),setCell:(e,t,s,n)=>rs(((e,t,s)=>Q(It(e,t,s,O(n)?n(fs(e,t,s)):n),(n=>Et(e,Jt(e),t,s,n)))),e,t,s),setValues:Vs,setPartialValues:e=>rs((()=>bt(e,1)?Ee(e,((e,t)=>Ht(t,e))):0)),setValue:(e,t)=>rs((e=>Q(wt(e,O(t)?t(ws(e)):t),(t=>Ht(e,t)))),e),applyChanges:e=>rs((()=>{Ee(e[0],((e,t)=>F(e)?Ds(t):Ee(e,((e,s)=>F(e)?Hs(t,s):Ee(e,((e,n)=>le(Os,t,s,n,e))))))),Ee(e[1],((e,t)=>re(Os,t,e)))})),setTablesJson:Ms,setValuesJson:e=>{try{kt(pt(e))}catch{}return Os},setJson:e=>rs((()=>{try{const[t,s]=pt(e);vt(t),kt(s)}catch{Ms(e)}})),setTablesSchema:ms,setValuesSchema:Es,setSchema:(e,t)=>rs((()=>{ms(e),Es(t)})),delTables:ks,delTable:Ds,delRow:Hs,delCell:(e,t,s,n)=>rs(((e,t,s)=>Q(Fe(Z,e),(o=>Q(Fe(o,t),(l=>ge(l,s)?Qt(e,o,t,l,s,n):0))))),e,t,s),delValues:Js,delValue:e=>rs((e=>ge($,e)?zt(e):0),e),delTablesSchema:xs,delValuesSchema:Fs,delSchema:()=>rs((()=>{xs(),Fs()})),transaction:Qs,startTransaction:zs,getTransactionChanges:()=>[We(E,((e,t)=>-1===Fe(g,t)?void 0:We(e,((e,s)=>-1===Fe(Fe(M,t),s)?void 0:We(e,(([,e])=>e),(e=>_t(e)))),he,ke)),he,ke),We(D,(([,e])=>e),(e=>_t(e))),1],getTransactionLog:()=>[!he(E),!he(D),Pe(E,Pt,_t),Pe(H),We(D,Pt,_t),We(J),We(g),Ae(M),Pe(m),We(k)],finishTransaction:Ns,forEachTable:e=>be(Z,((t,s)=>e(s,(e=>be(t,((t,s)=>e(s,(e=>Qe(t,e))))))))),forEachTableCell:(e,t)=>Qe(Fe(Y,y(e)),t),forEachRow:(e,t)=>be(Fe(Z,y(e)),((e,s)=>t(s,(t=>Qe(e,t))))),forEachCell:(e,t,s)=>Qe(Fe(Fe(Z,y(e)),y(t)),s),forEachValue:e=>Qe($,e),addSortedRowIdsListener:(e,t,s,n,o,l,r)=>{let a=gs(e,t,s,n,o);return rt((()=>{const r=gs(e,t,s,n,o);U(r,a)||(a=r,l(Os,e,t,s,n,o,a))}),ve[r?1:0],[e,t],[is])},addStartTransactionListener:e=>rt(e,ot),addWillFinishTransactionListener:e=>rt(e,lt[0]),addDidFinishTransactionListener:e=>rt(e,lt[1]),callListener:e=>(dt(e),Os),delListener:e=>(ct(e),Os),getListenerStats:()=>({hasTables:Wt(te),tables:Wt(se),tableIds:Wt(oe),hasTable:Wt(ae),table:Wt(fe),tableCellIds:Wt(Le),hasTableCell:Wt(Ce,de),rowCount:Wt(Re),rowIds:Wt(Te),sortedRowIds:Wt(ve),hasRow:Wt(pe,de),row:Wt(ye,de),cellIds:Wt(me,de),hasCell:Wt(De,ue),cell:Wt(Ue,ue),invalidCell:Wt(Ke,ue),hasValues:Wt(Ye),values:Wt(Ze),valueIds:Wt(tt),hasValue:Wt(st),value:Wt(nt),invalidValue:Wt(Xe),transaction:ce(ot)+Wt(lt)}),isMergeable:()=>!1,createStore:Bt,addListener:rt,callListeners:it,setInternalListeners:(e,t,s,n,o)=>c=[e,t,s,n,o]};return Ee({[u+f]:[0,te,[],()=>[Ls()]],[f]:[0,se],[I]:[0,oe],[u+h]:[1,ae,[is],e=>[Cs(...e)]],[h]:[1,fe,[is]],[h+T]:[1,Le,[is]],[u+h+R]:[2,Ce,[is,cs],e=>[Rs(...e)]],[w]:[1,Re,[is]],[L]:[1,Te,[is]],[u+b]:[2,pe,[is,us],e=>[Ts(...e)]],[b]:[2,ye,[is,us]],[T]:[2,me,[is,us]],[u+R]:[3,De,[is,us,hs],e=>[vs(...e)]],[R]:[3,Ue,[is,us,hs],e=>Ot(fs(...e))],InvalidCell:[3,Ke],[u+p]:[0,Ye,[],()=>[ps()]],[p]:[0,Ze],[S]:[0,tt],[u+v]:[1,st,[bs],e=>[Ss(...e)]],[v]:[1,nt,[bs],e=>Ot(ws(e[0]))],InvalidValue:[1,Xe]},(([e,t,s,n],o)=>{Os[d+o+i]=(...o)=>rt(o[e],t[o[e+1]?1:0],e>0?A(o,0,e):void 0,s,n)})),Se(Os)},Ut={HasTable:1,Table:1,TableCellIds:1,HasTableCell:2,RowCount:1,RowIds:1,SortedRowIds:5,HasRow:2,Row:2,CellIds:2,HasCell:3,Cell:3,HasValue:1,Value:1,InvalidCell:3,InvalidValue:1},qt=(e=t)=>[Ft(e),Ft(e)],Gt=e=>{let s=1,n=qt(),o=0;const l=Je(),r=qe(),[a,c]=(e=>{let t=0,s=-1;const n=Q(e,(e=>{const t=bt(e);return ot(t/Ct)+ot(t/Rt)+ot(t/Tt)+ot(t/64)+ot(t)}),(()=>it(5))),o=e=>{const n=t,[o,l]=F(e)||""==e?[0,0]:[lt(r=e,0)*wt+lt(r,1)*Lt+lt(r,2)*Ct+lt(r,3)*Rt+lt(r,4)*Tt+64*lt(r,5)+lt(r,6),lt(r,7)*Rt+lt(r,8)*Tt+64*lt(r,9)+lt(r,10)];var r;t=D(n,o,E.HLC_TIME??Date.now()),s=t==n?t==o?D(s,l):s:t==o?l:-1};return[()=>{return o(),l=++s,ot((e=t)/wt)+ot(e/Lt)+ot(e/Ct)+ot(e/Rt)+ot(e/Tt)+ot(e/64)+ot(e)+ot(l/Rt)+ot(l/Tt)+ot(l/64)+ot(l)+n;var e,l},o]})(e),u=Bt(),g=e=>{const t=s;return s=0,e(),s=t,w},h=(e,s=0)=>{const o={},l={},[[r,a=t,i=0],d]=e,[u,g]=n,[h,I,b]=u;let w=s?i:b,L=a;me(r,(([e,n=t,l=0],r)=>{const a=Ne(h,r,Ft),[i,c,d]=a;let u=s?l:d,g=n;me(e,((e,t)=>{const[n,l,a]=f(e,Ne(i,t,Ft),De(De(o,r,ye),t,ye),s);u^=s?0:(l?kt(t,l):0)^kt(t,a),g=Ht(g,n)})),u^=s?0:Dt(c,n),Jt(a,n,u),w^=s?0:(d?kt(r,d):0)^kt(r,a[2]),L=Ht(L,g)})),w^=s?0:Dt(I,a),Jt(u,a,w);const[C]=f(d,g,l,s);return c(Ht(L,C)),[o,l,1]},f=(e,s,n,o)=>{const[l,r=t,a=0]=e,[i,c,d]=s;let u=r,g=o?a:d;return me(l,(([e,s=t,l=0],r)=>{const a=Ne(i,r,(()=>[void 0,t,0])),[,c,d]=a;(!c||s>c)&&(Jt(a,s,o?l:bt(St(e??null)+":"+s)),a[0]=e,n[r]=e,g^=o?0:kt(r,d)^kt(r,a[2]),u=Ht(u,s))})),g^=o?0:Dt(c,r),Jt(s,r,g),[u,d,s[2]]},I=()=>[Qt(n[0],(e=>Qt(e,(e=>Qt(e))))),Qt(n[1])],b=e=>g((()=>u.applyChanges(h(e)))),w={getMergeableContent:I,getMergeableContentHashes:()=>[n[0][2],n[1][2]],getMergeableTableHashes:()=>We(n[0][0],Et),getMergeableTableDiff:e=>{const t=xt(n[0][1]),s={};return Qe(n[0][0],((n,[o,l,r])=>Ve(e,n)?r!=e[n]?s[n]=r:0:t[0][n]=zt([o,l],(e=>zt(e))))),[t,s]},getMergeableRowHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n,,o])=>o!=e?Qe(n,((e,[,,n])=>De(t,s,ye)[e]=n)):0)))),t},getMergeableRowDiff:e=>{const t=xt(n[0][1]),s={};return me(e,((e,o)=>Qe(Fe(n[0][0],o)?.[0],((n,[l,r,a])=>Ve(e,n)?a!==e[n]?De(s,o,ye)[n]=a:0:De(t[0],o,xt)[0][n]=zt([l,r]))))),[t,s]},getMergeableCellHashes:e=>{const t={};return me(e,((e,s)=>Q(Fe(n[0][0],s),(([n])=>me(e,((e,o)=>Q(Fe(n,o),(([n,,l])=>l!==e?Qe(n,((e,[,,n])=>De(De(t,s,ye),o,ye)[e]=n)):0)))))))),t},getMergeableCellDiff:e=>{const[[t,s]]=n,o={};return me(e,((e,s)=>me(e,((e,n)=>Q(Fe(t,s),(([t,l])=>Q(Fe(t,n),(([t,r])=>Qe(t,((t,[a,i,c])=>c!==e[t]?De(De(o,s,(()=>xt(l)))[0],n,(()=>xt(r)))[0][t]=[a,i]:0)))))))))),Mt(o,s)},getMergeableValueHashes:()=>We(n[1][0],Et),getMergeableValueDiff:e=>{const[,[t,s]]=n,o=We(t,yt,(([,,t],s)=>t==e?.[s]));return Mt(o,s)},setMergeableContent:e=>g((()=>(e=>W(e)&&2==P(e)&&Nt(e[0],(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,(e=>He(e,(e=>Nt(e,oe)),void 0,1)))),void 0,1)))),void 0,1)))&&Nt(e[1],(e=>He(e,(e=>Nt(e,oe)),void 0,1))))(e)?u.transaction((()=>{u.delTables().delValues(),n=qt(),u.applyChanges(h(e,1))})):0)),setDefaultContent:e=>(u.transaction((()=>{o=1,u.setContent(e),o=0})),w),getTransactionMergeableChanges:(e=!1)=>{const[[t,s,o],[a,i,c]]=n,d=e?mt:Mt,u={};be(l,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const l={};be(e,((e,s)=>Q(Fe(t,s),(([t,n,o])=>{const r={};be(e,(e=>{Q(Fe(t,e),(([t,s,n])=>r[e]=d(t,s,n)))})),l[s]=d(r,n,o)})))),u[s]=d(l,n,o)}))));const g={};return be(r,(e=>Q(Fe(a,e),(([t,s,n])=>g[e]=d(t,s,n))))),[d(u,s,o),d(g,i,c),1]},applyMergeableChanges:b,merge:e=>{const t=I(),s=e.getMergeableContent();return e.applyMergeableChanges(t),b(s)}};return u.setInternalListeners((()=>{}),(()=>{}),(()=>{Ie(l),Ie(r)}),((e,n,r,i)=>{Ge(Ne(Ne(l,e,Je),n,qe),r),s&&h([[{[e]:[{[n]:[{[r]:[i,o?t:a()]}]}]}],[{}],1])}),((e,n)=>{Ge(r,e),s&&h([[{}],[{[e]:[n,o?t:a()]}],1])})),Ee(u,((e,t)=>w[t]=V(t,"set")||V(t,"del")||V(t,"apply")||M(t,"Transaction")||t=="call"+i?(...t)=>(e(...t),w):V(t,d)&&M(t,i)?(...s)=>{const n=Ut[A(t,3,-8)]??0,o=s[n];return s[n]=(e,...t)=>o(w,...t),e(...s)}:"isMergeable"==t?()=>!0:e)),Se(w)};export{tt as createCheckpoints,ct as createIndexes,Gt as createMergeableStore,gt as createMetrics,ht as createQueries,ft as createRelationships,Bt as createStore,at as defaultSorter,it as getUniqueId};
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinybase",
3
- "version": "6.0.3",
3
+ "version": "6.0.5",
4
4
  "author": "jamesgpearce",
5
5
  "repository": "github:tinyplex/tinybase",
6
6
  "license": "MIT",
@@ -22,23 +22,23 @@
22
22
  "sideEffects": false,
23
23
  "peerDependencies": {
24
24
  "@automerge/automerge-repo": "^1.2.1",
25
- "@cloudflare/workers-types": "^4.20250418.0",
25
+ "@cloudflare/workers-types": "^4.20250506.0",
26
26
  "@electric-sql/pglite": "^0.2.17",
27
27
  "@libsql/client": "^0.15.4",
28
- "@powersync/common": "^1.27.1",
28
+ "@powersync/common": "^1.29.0",
29
29
  "@sqlite.org/sqlite-wasm": "^3.49.1-build4",
30
30
  "@vlcn.io/crsqlite-wasm": "^0.16.0",
31
31
  "electric-sql": "^0.12.1",
32
- "expo": "^52.0.4",
33
- "expo-sqlite": "^15.1.4",
32
+ "expo": "^53.0.7",
33
+ "expo-sqlite": "^15.2.9",
34
34
  "partykit": "^0.0.114",
35
35
  "partysocket": "^1.1.3",
36
36
  "postgres": "^3.4.5",
37
37
  "react": "^19.0.0",
38
38
  "react-dom": "^19.0.0",
39
39
  "sqlite3": "^5.1.7",
40
- "ws": "^8.18.1",
41
- "yjs": "^13.6.24"
40
+ "ws": "^8.18.2",
41
+ "yjs": "^13.6.26"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "@automerge/automerge-repo": {
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- <link rel="preload" as="image" href="https://tinybase.org/react.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/indexeddb.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/postgresql.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/pglite.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/sqlite.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/expo.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/cloudflare.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/electric.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/turso.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/powersync.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/partykit.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/yjs.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/crsqlite.png"><link rel="preload" as="image" href="https://tinybase.org/automerge.svg?asImg"><link rel="preload" as="image" href="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=GitHub&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&amp;logo=bluesky&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%230285FF"><link rel="preload" as="image" href="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&amp;logo=x&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%23000"><link rel="preload" as="image" href="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&amp;logo=discord&amp;logoColor=%23fff&amp;label=Discord&amp;labelColor=%233131e8&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Ideas&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Issues&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&amp;logo=jest&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%2387c305"><link rel="preload" as="image" href="https://img.shields.io/npm/v/tinybase?style=for-the-badge&amp;logo=npm&amp;logoColor=%23fff&amp;labelColor=%23bd0005&amp;color=%23333"><link rel="preload" as="image" href="https://tinybase.org/ui-react-dom.webp"><link rel="preload" as="image" href="https://tinybase.org/store-inspector.webp"><link rel="preload" as="image" href="https://github.com/cpojer.png?size=48"><link rel="preload" as="image" href="https://github.com/expo.png?size=48"><link rel="preload" as="image" href="https://github.com/beekeeb.png?size=48"><link rel="preload" as="image" href="https://github.com/cancelself.png?size=48"><link rel="preload" as="image" href="https://github.com/WonderPanda.png?size=48"><link rel="preload" as="image" href="https://github.com/arpitBhalla.png?size=48"><link rel="preload" as="image" href="https://github.com/behrends.png?size=48"><link rel="preload" as="image" href="https://github.com/betomoedano.png?size=48"><link rel="preload" as="image" href="https://github.com/brentvatne.png?size=48"><link rel="preload" as="image" href="https://github.com/byCedric.png?size=48"><link rel="preload" as="image" href="https://github.com/circadian-risk.png?size=48"><link rel="preload" as="image" href="https://github.com/cubecull.png?size=48"><link rel="preload" as="image" href="https://github.com/erwinkn.png?size=48"><link rel="preload" as="image" href="https://github.com/ezra-en.png?size=48"><link rel="preload" as="image" href="https://github.com/feychenie.png?size=48"><link rel="preload" as="image" href="https://github.com/flaming-codes.png?size=48"><link rel="preload" as="image" href="https://github.com/fostertheweb.png?size=48"><link rel="preload" as="image" href="https://github.com/Giulio987.png?size=48"><link rel="preload" as="image" href="https://github.com/hi-ogawa.png?size=48"><link rel="preload" as="image" href="https://github.com/itsdevcoffee.png?size=48"><link rel="preload" as="image" href="https://github.com/jbolda.png?size=48"><link rel="preload" as="image" href="https://github.com/Kayoo-asso.png?size=48"><link rel="preload" as="image" href="https://github.com/kotofurumiya.png?size=48"><link rel="preload" as="image" href="https://github.com/Kudo.png?size=48"><link rel="preload" as="image" href="https://github.com/learn-anything.png?size=48"><link rel="preload" as="image" href="https://github.com/lluc.png?size=48"><link rel="preload" as="image" href="https://github.com/marksteve.png?size=48"><link rel="preload" as="image" href="https://github.com/miking-the-viking.png?size=48"><link rel="preload" as="image" href="https://github.com/mjamesderocher.png?size=48"><link rel="preload" as="image" href="https://github.com/mouktardev.png?size=48"><link rel="preload" as="image" href="https://github.com/nickmessing.png?size=48"><link rel="preload" as="image" href="https://github.com/nikitavoloboev.png?size=48"><link rel="preload" as="image" href="https://github.com/nkzw-tech.png?size=48"><link rel="preload" as="image" href="https://github.com/palerdot.png?size=48"><link rel="preload" as="image" href="https://github.com/PorcoRosso85.png?size=48"><link rel="preload" as="image" href="https://github.com/primodiumxyz.png?size=48"><link rel="preload" as="image" href="https://github.com/shaneosullivan.png?size=48"><link rel="preload" as="image" href="https://github.com/sudo-self.png?size=48"><link rel="preload" as="image" href="https://github.com/SuperSonicHub1.png?size=48"><link rel="preload" as="image" href="https://github.com/threepointone.png?size=48"><link rel="preload" as="image" href="https://github.com/uptonking.png?size=48"><link rel="preload" as="image" href="https://github.com/ViktorZhurbin.png?size=48"><link rel="preload" as="image" href="https://github.com/wilkerlucio.png?size=48"><link rel="preload" as="image" href="https://tinybase.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinywidgets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinytick.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/youtube.webp"><section id="hero"><h2 id="a-reactive-data-store-sync-engine">A <em>reactive</em> data store <span>&amp; <em>sync</em> engine</span>.</h2></section><p><a href="https://tinybase.org/guides/releases/#v6-0"><em>NEW!</em> v6.0 release</a></p><p><span id="one-with">&quot;The One With React 19!&quot;</span></p><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It&#x27;s <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It&#x27;s <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, you can easily <a href="#persist-to-storage-databases-more">persist</a> your data to file, <a href="https://tinybase.org/api/persister-browser">browser storage</a>, <a href="https://tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://tinybase.org/guides/persistence/database-persistence/">SQLite or PostgreSQL databases</a>, and <a href="https://tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It&#x27;s Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it&#x27;s especially great for local-first apps: where data is stored locally on the user&#x27;s device and that can be run offline. It&#x27;s tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.3kB - 11.4kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends.</h2><div><a href="https://tinybase.org/guides/building-uis/getting-started-with-ui-react"><img src="https://tinybase.org/react.svg?asImg" width="48"> React</a></div><div><a href="https://tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img src="https://tinybase.org/indexeddb.svg?asImg" width="48"> IndexedDB</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/postgresql.svg?asImg" width="48"> PostgreSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/pglite.svg?asImg" width="48"> PGlite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/sqlite.svg?asImg" width="48"> SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/expo.svg?asImg" width="48"> Expo SQLite</a></div><div><a href="https://tinybase.org/guides/integrations/cloudflare-durable-objects"><img src="https://tinybase.org/cloudflare.svg?asImg" width="48"> Cloudflare</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/electric.svg?asImg" width="48"> ElectricSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/turso.svg?asImg" width="48"> Turso</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/powersync.svg?asImg" width="48"> PowerSync</a></div><div><a href="https://tinybase.org/api/persister-partykit-client"><img src="https://tinybase.org/partykit.svg?asImg" width="48"> PartyKit</a></div><div><a href="https://tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img src="https://tinybase.org/yjs.svg?asImg" width="48"> YJS</a></div><div><a href="https://tinybase.org/api/persister-cr-sqlite-wasm"><img src="https://tinybase.org/crsqlite.png" width="48"> CR-SQLite</a></div><div><a href="https://tinybase.org/api/persister-automerge"><img src="https://tinybase.org/automerge.svg?asImg" width="48"> Automerge</a></div><p>(Baffled by all these logos? Check out our <a href="https://tinybase.org/guides/the-basics/architectural-options">architectural options</a> guide to make sense of it all!)</p></section><hr><section id="follow"><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=GitHub&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="https://bsky.app/profile/tinybase.bsky.social"><img src="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&amp;logo=bluesky&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%230285FF"> </a><a href="https://x.com/tinybasejs" target="_blank"><img src="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&amp;logo=x&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%23000"> </a><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&amp;logo=discord&amp;logoColor=%23fff&amp;label=Discord&amp;labelColor=%233131e8&amp;color=%23333"></a><br><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Ideas&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Issues&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&amp;logo=jest&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%2387c305"> </a><a href="https://www.npmjs.com/package/tinybase/v/6.0.2" target="_blank"><img src="https://img.shields.io/npm/v/tinybase?style=for-the-badge&amp;logo=npm&amp;logoColor=%23fff&amp;labelColor=%23bd0005&amp;color=%23333"></a></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://tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://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://tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
1
+ <link rel="preload" as="image" href="https://tinybase.org/react.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/indexeddb.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/postgresql.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/pglite.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/sqlite.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/expo.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/cloudflare.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/electric.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/turso.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/powersync.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/partykit.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/yjs.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/crsqlite.png"><link rel="preload" as="image" href="https://tinybase.org/automerge.svg?asImg"><link rel="preload" as="image" href="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=GitHub&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&amp;logo=bluesky&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%230285FF"><link rel="preload" as="image" href="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&amp;logo=x&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%23000"><link rel="preload" as="image" href="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&amp;logo=discord&amp;logoColor=%23fff&amp;label=Discord&amp;labelColor=%233131e8&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Ideas&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Issues&amp;labelColor=%23d81b60&amp;color=%23333"><link rel="preload" as="image" href="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&amp;logo=jest&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%2387c305"><link rel="preload" as="image" href="https://img.shields.io/npm/v/tinybase?style=for-the-badge&amp;logo=npm&amp;logoColor=%23fff&amp;labelColor=%23bd0005&amp;color=%23333"><link rel="preload" as="image" href="https://tinybase.org/ui-react-dom.webp"><link rel="preload" as="image" href="https://tinybase.org/store-inspector.webp"><link rel="preload" as="image" href="https://github.com/cpojer.png?size=48"><link rel="preload" as="image" href="https://github.com/expo.png?size=48"><link rel="preload" as="image" href="https://github.com/beekeeb.png?size=48"><link rel="preload" as="image" href="https://github.com/cancelself.png?size=48"><link rel="preload" as="image" href="https://github.com/WonderPanda.png?size=48"><link rel="preload" as="image" href="https://github.com/arpitBhalla.png?size=48"><link rel="preload" as="image" href="https://github.com/behrends.png?size=48"><link rel="preload" as="image" href="https://github.com/betomoedano.png?size=48"><link rel="preload" as="image" href="https://github.com/brentvatne.png?size=48"><link rel="preload" as="image" href="https://github.com/byCedric.png?size=48"><link rel="preload" as="image" href="https://github.com/circadian-risk.png?size=48"><link rel="preload" as="image" href="https://github.com/cubecull.png?size=48"><link rel="preload" as="image" href="https://github.com/erwinkn.png?size=48"><link rel="preload" as="image" href="https://github.com/ezra-en.png?size=48"><link rel="preload" as="image" href="https://github.com/feychenie.png?size=48"><link rel="preload" as="image" href="https://github.com/flaming-codes.png?size=48"><link rel="preload" as="image" href="https://github.com/fostertheweb.png?size=48"><link rel="preload" as="image" href="https://github.com/Giulio987.png?size=48"><link rel="preload" as="image" href="https://github.com/hi-ogawa.png?size=48"><link rel="preload" as="image" href="https://github.com/itsdevcoffee.png?size=48"><link rel="preload" as="image" href="https://github.com/jbolda.png?size=48"><link rel="preload" as="image" href="https://github.com/Kayoo-asso.png?size=48"><link rel="preload" as="image" href="https://github.com/kotofurumiya.png?size=48"><link rel="preload" as="image" href="https://github.com/Kudo.png?size=48"><link rel="preload" as="image" href="https://github.com/learn-anything.png?size=48"><link rel="preload" as="image" href="https://github.com/lluc.png?size=48"><link rel="preload" as="image" href="https://github.com/marksteve.png?size=48"><link rel="preload" as="image" href="https://github.com/miking-the-viking.png?size=48"><link rel="preload" as="image" href="https://github.com/mjamesderocher.png?size=48"><link rel="preload" as="image" href="https://github.com/mouktardev.png?size=48"><link rel="preload" as="image" href="https://github.com/nickmessing.png?size=48"><link rel="preload" as="image" href="https://github.com/nikitavoloboev.png?size=48"><link rel="preload" as="image" href="https://github.com/nkzw-tech.png?size=48"><link rel="preload" as="image" href="https://github.com/palerdot.png?size=48"><link rel="preload" as="image" href="https://github.com/PorcoRosso85.png?size=48"><link rel="preload" as="image" href="https://github.com/primodiumxyz.png?size=48"><link rel="preload" as="image" href="https://github.com/shaneosullivan.png?size=48"><link rel="preload" as="image" href="https://github.com/sudo-self.png?size=48"><link rel="preload" as="image" href="https://github.com/SuperSonicHub1.png?size=48"><link rel="preload" as="image" href="https://github.com/threepointone.png?size=48"><link rel="preload" as="image" href="https://github.com/uptonking.png?size=48"><link rel="preload" as="image" href="https://github.com/ViktorZhurbin.png?size=48"><link rel="preload" as="image" href="https://github.com/wilkerlucio.png?size=48"><link rel="preload" as="image" href="https://tinybase.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinywidgets.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinytick.org/favicon.svg?asImg"><link rel="preload" as="image" href="https://tinybase.org/youtube.webp"><section id="hero"><h2 id="a-reactive-data-store-sync-engine">A <em>reactive</em> data store <span>&amp; <em>sync</em> engine</span>.</h2></section><p><a href="https://tinybase.org/guides/releases/#v6-0"><em>NEW!</em> v6.0 release</a></p><p><span id="one-with">&quot;The One With React 19!&quot;</span></p><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It&#x27;s <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It&#x27;s <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, you can easily <a href="#persist-to-storage-databases-more">persist</a> your data to file, <a href="https://tinybase.org/api/persister-browser">browser storage</a>, <a href="https://tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://tinybase.org/guides/persistence/database-persistence/">SQLite or PostgreSQL databases</a>, and <a href="https://tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It&#x27;s Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it&#x27;s especially great for local-first apps: where data is stored locally on the user&#x27;s device and that can be run offline. It&#x27;s tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.3kB - 11.5kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends.</h2><div><a href="https://tinybase.org/guides/building-uis/getting-started-with-ui-react"><img src="https://tinybase.org/react.svg?asImg" width="48"> React</a></div><div><a href="https://tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img src="https://tinybase.org/indexeddb.svg?asImg" width="48"> IndexedDB</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/postgresql.svg?asImg" width="48"> PostgreSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/pglite.svg?asImg" width="48"> PGlite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/sqlite.svg?asImg" width="48"> SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/expo.svg?asImg" width="48"> Expo SQLite</a></div><div><a href="https://tinybase.org/guides/integrations/cloudflare-durable-objects"><img src="https://tinybase.org/cloudflare.svg?asImg" width="48"> Cloudflare</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/electric.svg?asImg" width="48"> ElectricSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/turso.svg?asImg" width="48"> Turso</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img src="https://tinybase.org/powersync.svg?asImg" width="48"> PowerSync</a></div><div><a href="https://tinybase.org/api/persister-partykit-client"><img src="https://tinybase.org/partykit.svg?asImg" width="48"> PartyKit</a></div><div><a href="https://tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img src="https://tinybase.org/yjs.svg?asImg" width="48"> YJS</a></div><div><a href="https://tinybase.org/api/persister-cr-sqlite-wasm"><img src="https://tinybase.org/crsqlite.png" width="48"> CR-SQLite</a></div><div><a href="https://tinybase.org/api/persister-automerge"><img src="https://tinybase.org/automerge.svg?asImg" width="48"> Automerge</a></div><p>(Baffled by all these logos? Check out our <a href="https://tinybase.org/guides/the-basics/architectural-options">architectural options</a> guide to make sense of it all!)</p></section><hr><section id="follow"><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=GitHub&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="https://bsky.app/profile/tinybase.bsky.social"><img src="https://img.shields.io/badge/Bluesky-Follow-blue?style=for-the-badge&amp;logo=bluesky&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%230285FF"> </a><a href="https://x.com/tinybasejs" target="_blank"><img src="https://img.shields.io/badge/%2F%20Twitter-Follow-blue?style=for-the-badge&amp;logo=x&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%23000"> </a><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&amp;logo=discord&amp;logoColor=%23fff&amp;label=Discord&amp;labelColor=%233131e8&amp;color=%23333"></a><br><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Ideas&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&amp;logo=GitHub&amp;logoColor=%23fff&amp;label=Issues&amp;labelColor=%23d81b60&amp;color=%23333"> </a><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&amp;logo=jest&amp;logoColor=%23fff&amp;color=%23333&amp;labelColor=%2387c305"> </a><a href="https://www.npmjs.com/package/tinybase/v/6.0.4" target="_blank"><img src="https://img.shields.io/npm/v/tinybase?style=for-the-badge&amp;logo=npm&amp;logoColor=%23fff&amp;labelColor=%23bd0005&amp;color=%23333"></a></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://tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://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://tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
2
2
 
3
3
  ```js
4
4
  import {createStore} from 'tinybase';
@@ -275,4 +275,4 @@ console.log(store.getCell('pets', 'felix', 'sold'));
275
275
  // -> false
276
276
  ```
277
277
 
278
- <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>5.3kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>11.4kB</em>.</p><p>The optional <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just <em>4.9kB</em>, the ui-react-dom components are another <em>2.6kB</em>, and everything is super fast. Life is easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th> </th><th>Minified .js.gz</th><th>Source .js</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">tinybase/store</a> (minimal)</th><td>5.3kB</td><td>52.7kB</td></tr><tr><th class="right">tinybase (complete)</th><td>11.4kB</td><td>119.5kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react/">ui-react</a></th><td>4.9kB</td><td>53.6kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react-dom/">ui-react-dom</a></th><td>2.6kB</td><td>21.1kB</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 for you to get your TinyBase-powered app up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://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>2,289</td><td>2,289</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>2,473</td><td>2,473</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>988</td><td>988</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>854</td><td>854</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">7,066</td></tr><tr><th class="right">Assertions</th><td colspan="3">32,749</td></tr></tbody></table></div><hr><section id="sponsors"><h2 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h2><a href="https://github.com/cpojer" target="_blank"><img src="https://github.com/cpojer.png?size=48" title="cpojer" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img src="https://github.com/expo.png?size=48" title="expo" width="48" height="48"></a><a href="https://github.com/beekeeb" target="_blank"><img src="https://github.com/beekeeb.png?size=48" title="beekeeb" width="48" height="48"></a><a href="https://github.com/cancelself" target="_blank"><img src="https://github.com/cancelself.png?size=48" title="cancelself" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img src="https://github.com/WonderPanda.png?size=48" title="WonderPanda" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img src="https://github.com/arpitBhalla.png?size=48" title="arpitBhalla" width="48" height="48"></a></section><section id="users"><h2 id="excited-to-be-used-by">Excited to be used by:</h2><a href="https://github.com/behrends" target="_blank"><img src="https://github.com/behrends.png?size=48" title="behrends" width="48" height="48"></a><a href="https://github.com/betomoedano" target="_blank"><img src="https://github.com/betomoedano.png?size=48" title="betomoedano" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img src="https://github.com/brentvatne.png?size=48" title="brentvatne" width="48" height="48"></a><a href="https://github.com/byCedric" target="_blank"><img src="https://github.com/byCedric.png?size=48" title="byCedric" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img src="https://github.com/circadian-risk.png?size=48" title="circadian-risk" width="48" height="48"></a><a href="https://github.com/cpojer" target="_blank"><img src="https://github.com/cpojer.png?size=48" title="cpojer" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img src="https://github.com/cubecull.png?size=48" title="cubecull" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img src="https://github.com/erwinkn.png?size=48" title="erwinkn" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img src="https://github.com/expo.png?size=48" title="expo" width="48" height="48"></a><a href="https://github.com/ezra-en" target="_blank"><img src="https://github.com/ezra-en.png?size=48" title="ezra-en" width="48" height="48"></a><a href="https://github.com/feychenie" target="_blank"><img src="https://github.com/feychenie.png?size=48" title="feychenie" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img src="https://github.com/flaming-codes.png?size=48" title="flaming-codes" width="48" height="48"></a><a href="https://github.com/fostertheweb" target="_blank"><img src="https://github.com/fostertheweb.png?size=48" title="fostertheweb" width="48" height="48"></a><a href="https://github.com/Giulio987" target="_blank"><img src="https://github.com/Giulio987.png?size=48" title="Giulio987" width="48" height="48"></a><a href="https://github.com/hi-ogawa" target="_blank"><img src="https://github.com/hi-ogawa.png?size=48" title="hi-ogawa" width="48" height="48"></a><a href="https://github.com/itsdevcoffee" target="_blank"><img src="https://github.com/itsdevcoffee.png?size=48" title="itsdevcoffee" width="48" height="48"></a><a href="https://github.com/jbolda" target="_blank"><img src="https://github.com/jbolda.png?size=48" title="jbolda" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img src="https://github.com/Kayoo-asso.png?size=48" title="Kayoo-asso" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img src="https://github.com/kotofurumiya.png?size=48" title="kotofurumiya" width="48" height="48"></a><a href="https://github.com/Kudo" target="_blank"><img src="https://github.com/Kudo.png?size=48" title="Kudo" width="48" height="48"></a><a href="https://github.com/learn-anything" target="_blank"><img src="https://github.com/learn-anything.png?size=48" title="learn-anything" width="48" height="48"></a><a href="https://github.com/lluc" target="_blank"><img src="https://github.com/lluc.png?size=48" title="lluc" width="48" height="48"></a><a href="https://github.com/marksteve" target="_blank"><img src="https://github.com/marksteve.png?size=48" title="marksteve" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img src="https://github.com/miking-the-viking.png?size=48" title="miking-the-viking" width="48" height="48"></a><a href="https://github.com/mjamesderocher" target="_blank"><img src="https://github.com/mjamesderocher.png?size=48" title="mjamesderocher" width="48" height="48"></a><a href="https://github.com/mouktardev" target="_blank"><img src="https://github.com/mouktardev.png?size=48" title="mouktardev" width="48" height="48"></a><a href="https://github.com/nickmessing" target="_blank"><img src="https://github.com/nickmessing.png?size=48" title="nickmessing" width="48" height="48"></a><a href="https://github.com/nikitavoloboev" target="_blank"><img src="https://github.com/nikitavoloboev.png?size=48" title="nikitavoloboev" width="48" height="48"></a><a href="https://github.com/nkzw-tech" target="_blank"><img src="https://github.com/nkzw-tech.png?size=48" title="nkzw-tech" width="48" height="48"></a><a href="https://github.com/palerdot" target="_blank"><img src="https://github.com/palerdot.png?size=48" title="palerdot" width="48" height="48"></a><a href="https://github.com/PorcoRosso85" target="_blank"><img src="https://github.com/PorcoRosso85.png?size=48" title="PorcoRosso85" width="48" height="48"></a><a href="https://github.com/primodiumxyz" target="_blank"><img src="https://github.com/primodiumxyz.png?size=48" title="primodiumxyz" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img src="https://github.com/shaneosullivan.png?size=48" title="shaneosullivan" width="48" height="48"></a><a href="https://github.com/sudo-self" target="_blank"><img src="https://github.com/sudo-self.png?size=48" title="sudo-self" width="48" height="48"></a><a href="https://github.com/SuperSonicHub1" target="_blank"><img src="https://github.com/SuperSonicHub1.png?size=48" title="SuperSonicHub1" width="48" height="48"></a><a href="https://github.com/threepointone" target="_blank"><img src="https://github.com/threepointone.png?size=48" title="threepointone" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img src="https://github.com/uptonking.png?size=48" title="uptonking" width="48" height="48"></a><a href="https://github.com/ViktorZhurbin" target="_blank"><img src="https://github.com/ViktorZhurbin.png?size=48" title="ViktorZhurbin" width="48" height="48"></a><a href="https://github.com/wilkerlucio" target="_blank"><img src="https://github.com/wilkerlucio.png?size=48" title="wilkerlucio" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img src="https://github.com/WonderPanda.png?size=48" title="WonderPanda" width="48" height="48"></a></section><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section id="family"><h2 id="meet-the-family">Meet the family</h2><p>TinyBase is part of a group of small libraries designed to help make rich client and local-first apps easier to build. Check out the others!</p><p><img src="https://tinybase.org/favicon.svg?asImg" width="48"><br><b>TinyBase</b><br>The reactive data store for local-first apps.</p><p><a href="https://tinywidgets.org" target="_blank"><img src="https://tinywidgets.org/favicon.svg?asImg" width="48"><br><b>TinyWidgets</b></a><br>A collection of tiny, reusable, UI components.</p><p><a href="https://tinytick.org" target="_blank"><img src="https://tinytick.org/favicon.svg?asImg" width="48"><br><b>TinyTick</b></a><br>A tiny but very useful task orchestrator.</p></section><hr><section id="about"><h2 id="about">About</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Or sacrifice features for bundle size? And why does the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://tripleodeon.com">me</a> in API design, minification, and documentation. But now it has taken on a life of its own, and has grown beyond my wildest expectations.</p><p>It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it as much as I do building it!</p></section><section id="story"><h2 id="the-story">The story</h2><a href="https://youtu.be/hXL7OkW-Prk?t=1232" target="_blank"><img src="https://tinybase.org/youtube.webp"></a></section>
278
+ <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>5.3kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>11.5kB</em>.</p><p>The optional <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just <em>4.9kB</em>, the ui-react-dom components are another <em>2.6kB</em>, and everything is super fast. Life is easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th> </th><th>Minified .js.gz</th><th>Source .js</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">tinybase/store</a> (minimal)</th><td>5.3kB</td><td>52.7kB</td></tr><tr><th class="right">tinybase (complete)</th><td>11.5kB</td><td>119.7kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react/">ui-react</a></th><td>4.9kB</td><td>53.6kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react-dom/">ui-react-dom</a></th><td>2.6kB</td><td>21.1kB</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 for you to get your TinyBase-powered app up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://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>2,290</td><td>2,290</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>2,474</td><td>2,474</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>989</td><td>989</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>856</td><td>856</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">7,068</td></tr><tr><th class="right">Assertions</th><td colspan="3">32,755</td></tr></tbody></table></div><hr><section id="sponsors"><h2 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h2><a href="https://github.com/cpojer" target="_blank"><img src="https://github.com/cpojer.png?size=48" title="cpojer" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img src="https://github.com/expo.png?size=48" title="expo" width="48" height="48"></a><a href="https://github.com/beekeeb" target="_blank"><img src="https://github.com/beekeeb.png?size=48" title="beekeeb" width="48" height="48"></a><a href="https://github.com/cancelself" target="_blank"><img src="https://github.com/cancelself.png?size=48" title="cancelself" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img src="https://github.com/WonderPanda.png?size=48" title="WonderPanda" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img src="https://github.com/arpitBhalla.png?size=48" title="arpitBhalla" width="48" height="48"></a></section><section id="users"><h2 id="excited-to-be-used-by">Excited to be used by:</h2><a href="https://github.com/behrends" target="_blank"><img src="https://github.com/behrends.png?size=48" title="behrends" width="48" height="48"></a><a href="https://github.com/betomoedano" target="_blank"><img src="https://github.com/betomoedano.png?size=48" title="betomoedano" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img src="https://github.com/brentvatne.png?size=48" title="brentvatne" width="48" height="48"></a><a href="https://github.com/byCedric" target="_blank"><img src="https://github.com/byCedric.png?size=48" title="byCedric" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img src="https://github.com/circadian-risk.png?size=48" title="circadian-risk" width="48" height="48"></a><a href="https://github.com/cpojer" target="_blank"><img src="https://github.com/cpojer.png?size=48" title="cpojer" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img src="https://github.com/cubecull.png?size=48" title="cubecull" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img src="https://github.com/erwinkn.png?size=48" title="erwinkn" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img src="https://github.com/expo.png?size=48" title="expo" width="48" height="48"></a><a href="https://github.com/ezra-en" target="_blank"><img src="https://github.com/ezra-en.png?size=48" title="ezra-en" width="48" height="48"></a><a href="https://github.com/feychenie" target="_blank"><img src="https://github.com/feychenie.png?size=48" title="feychenie" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img src="https://github.com/flaming-codes.png?size=48" title="flaming-codes" width="48" height="48"></a><a href="https://github.com/fostertheweb" target="_blank"><img src="https://github.com/fostertheweb.png?size=48" title="fostertheweb" width="48" height="48"></a><a href="https://github.com/Giulio987" target="_blank"><img src="https://github.com/Giulio987.png?size=48" title="Giulio987" width="48" height="48"></a><a href="https://github.com/hi-ogawa" target="_blank"><img src="https://github.com/hi-ogawa.png?size=48" title="hi-ogawa" width="48" height="48"></a><a href="https://github.com/itsdevcoffee" target="_blank"><img src="https://github.com/itsdevcoffee.png?size=48" title="itsdevcoffee" width="48" height="48"></a><a href="https://github.com/jbolda" target="_blank"><img src="https://github.com/jbolda.png?size=48" title="jbolda" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img src="https://github.com/Kayoo-asso.png?size=48" title="Kayoo-asso" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img src="https://github.com/kotofurumiya.png?size=48" title="kotofurumiya" width="48" height="48"></a><a href="https://github.com/Kudo" target="_blank"><img src="https://github.com/Kudo.png?size=48" title="Kudo" width="48" height="48"></a><a href="https://github.com/learn-anything" target="_blank"><img src="https://github.com/learn-anything.png?size=48" title="learn-anything" width="48" height="48"></a><a href="https://github.com/lluc" target="_blank"><img src="https://github.com/lluc.png?size=48" title="lluc" width="48" height="48"></a><a href="https://github.com/marksteve" target="_blank"><img src="https://github.com/marksteve.png?size=48" title="marksteve" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img src="https://github.com/miking-the-viking.png?size=48" title="miking-the-viking" width="48" height="48"></a><a href="https://github.com/mjamesderocher" target="_blank"><img src="https://github.com/mjamesderocher.png?size=48" title="mjamesderocher" width="48" height="48"></a><a href="https://github.com/mouktardev" target="_blank"><img src="https://github.com/mouktardev.png?size=48" title="mouktardev" width="48" height="48"></a><a href="https://github.com/nickmessing" target="_blank"><img src="https://github.com/nickmessing.png?size=48" title="nickmessing" width="48" height="48"></a><a href="https://github.com/nikitavoloboev" target="_blank"><img src="https://github.com/nikitavoloboev.png?size=48" title="nikitavoloboev" width="48" height="48"></a><a href="https://github.com/nkzw-tech" target="_blank"><img src="https://github.com/nkzw-tech.png?size=48" title="nkzw-tech" width="48" height="48"></a><a href="https://github.com/palerdot" target="_blank"><img src="https://github.com/palerdot.png?size=48" title="palerdot" width="48" height="48"></a><a href="https://github.com/PorcoRosso85" target="_blank"><img src="https://github.com/PorcoRosso85.png?size=48" title="PorcoRosso85" width="48" height="48"></a><a href="https://github.com/primodiumxyz" target="_blank"><img src="https://github.com/primodiumxyz.png?size=48" title="primodiumxyz" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img src="https://github.com/shaneosullivan.png?size=48" title="shaneosullivan" width="48" height="48"></a><a href="https://github.com/sudo-self" target="_blank"><img src="https://github.com/sudo-self.png?size=48" title="sudo-self" width="48" height="48"></a><a href="https://github.com/SuperSonicHub1" target="_blank"><img src="https://github.com/SuperSonicHub1.png?size=48" title="SuperSonicHub1" width="48" height="48"></a><a href="https://github.com/threepointone" target="_blank"><img src="https://github.com/threepointone.png?size=48" title="threepointone" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img src="https://github.com/uptonking.png?size=48" title="uptonking" width="48" height="48"></a><a href="https://github.com/ViktorZhurbin" target="_blank"><img src="https://github.com/ViktorZhurbin.png?size=48" title="ViktorZhurbin" width="48" height="48"></a><a href="https://github.com/wilkerlucio" target="_blank"><img src="https://github.com/wilkerlucio.png?size=48" title="wilkerlucio" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img src="https://github.com/WonderPanda.png?size=48" title="WonderPanda" width="48" height="48"></a></section><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section id="family"><h2 id="meet-the-family">Meet the family</h2><p>TinyBase is part of a group of small libraries designed to help make rich client and local-first apps easier to build. Check out the others!</p><p><img src="https://tinybase.org/favicon.svg?asImg" width="48"><br><b>TinyBase</b><br>The reactive data store for local-first apps.</p><p><a href="https://tinywidgets.org" target="_blank"><img src="https://tinywidgets.org/favicon.svg?asImg" width="48"><br><b>TinyWidgets</b></a><br>A collection of tiny, reusable, UI components.</p><p><a href="https://tinytick.org" target="_blank"><img src="https://tinytick.org/favicon.svg?asImg" width="48"><br><b>TinyTick</b></a><br>A tiny but very useful task orchestrator.</p></section><hr><section id="about"><h2 id="about">About</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Or sacrifice features for bundle size? And why does the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://tripleodeon.com">me</a> in API design, minification, and documentation. But now it has taken on a life of its own, and has grown beyond my wildest expectations.</p><p>It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it as much as I do building it!</p></section><section id="story"><h2 id="the-story">The story</h2><a href="https://youtu.be/hXL7OkW-Prk?t=1232" target="_blank"><img src="https://tinybase.org/youtube.webp"></a></section>
@@ -825,7 +825,14 @@ const createIndexes = getCreateFunction((store) => {
825
825
  setDefinitionAndListen(
826
826
  indexId,
827
827
  tableId,
828
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
828
+ (
829
+ change,
830
+ changedSliceIds,
831
+ changedSortKeys,
832
+ sliceIdOrIdsByRowId,
833
+ sortKeys,
834
+ force,
835
+ ) => {
829
836
  let sliceIdsChanged = 0;
830
837
  const changedSlices = setNew();
831
838
  const unsortedSlices = setNew();
@@ -869,8 +876,13 @@ const createIndexes = getCreateFunction((store) => {
869
876
  mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
870
877
  } else {
871
878
  mapForEach(changedSortKeys, (rowId) =>
872
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
873
- setAdd(unsortedSlices, sliceId),
879
+ ifNotUndefined(
880
+ mapGet(sliceIdOrIdsByRowId, rowId),
881
+ (sliceIdOrIds) =>
882
+ arrayForEach(
883
+ isArray(sliceIdOrIds) ? sliceIdOrIds : [sliceIdOrIds],
884
+ (sliceId) => setAdd(unsortedSlices, sliceId),
885
+ ),
874
886
  ),
875
887
  );
876
888
  }