tinybase 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/lib/checkpoints.js +1 -1
  2. package/lib/checkpoints.js.gz +0 -0
  3. package/lib/cjs/checkpoints.cjs +1 -1
  4. package/lib/cjs/checkpoints.cjs.gz +0 -0
  5. package/lib/cjs/indexes.cjs +1 -1
  6. package/lib/cjs/indexes.cjs.gz +0 -0
  7. package/lib/cjs/metrics.cjs +1 -1
  8. package/lib/cjs/metrics.cjs.gz +0 -0
  9. package/lib/cjs/relationships.cjs +1 -1
  10. package/lib/cjs/relationships.cjs.gz +0 -0
  11. package/lib/cjs/store.cjs +1 -1
  12. package/lib/cjs/store.cjs.gz +0 -0
  13. package/lib/cjs/tinybase.cjs +1 -1
  14. package/lib/cjs/tinybase.cjs.gz +0 -0
  15. package/lib/cjs/tools.cjs +1 -1
  16. package/lib/cjs/tools.cjs.gz +0 -0
  17. package/lib/cjs/ui-react.cjs +1 -1
  18. package/lib/cjs/ui-react.cjs.gz +0 -0
  19. package/lib/cjs-es6/checkpoints.cjs +1 -1
  20. package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
  21. package/lib/cjs-es6/indexes.cjs +1 -1
  22. package/lib/cjs-es6/indexes.cjs.gz +0 -0
  23. package/lib/cjs-es6/metrics.cjs +1 -1
  24. package/lib/cjs-es6/metrics.cjs.gz +0 -0
  25. package/lib/cjs-es6/relationships.cjs +1 -1
  26. package/lib/cjs-es6/relationships.cjs.gz +0 -0
  27. package/lib/cjs-es6/store.cjs +1 -1
  28. package/lib/cjs-es6/store.cjs.gz +0 -0
  29. package/lib/cjs-es6/tinybase.cjs +1 -1
  30. package/lib/cjs-es6/tinybase.cjs.gz +0 -0
  31. package/lib/cjs-es6/tools.cjs +1 -1
  32. package/lib/cjs-es6/tools.cjs.gz +0 -0
  33. package/lib/cjs-es6/ui-react.cjs +1 -1
  34. package/lib/cjs-es6/ui-react.cjs.gz +0 -0
  35. package/lib/debug/checkpoints.js +2 -2
  36. package/lib/debug/indexes.js +2 -2
  37. package/lib/debug/metrics.js +2 -2
  38. package/lib/debug/relationships.js +2 -2
  39. package/lib/debug/store.js +17 -24
  40. package/lib/debug/tinybase.js +17 -24
  41. package/lib/debug/tools.js +5 -4
  42. package/lib/debug/ui-react.js +3 -2
  43. package/lib/es6/checkpoints.js +1 -1
  44. package/lib/es6/checkpoints.js.gz +0 -0
  45. package/lib/es6/indexes.js +1 -1
  46. package/lib/es6/indexes.js.gz +0 -0
  47. package/lib/es6/metrics.js +1 -1
  48. package/lib/es6/metrics.js.gz +0 -0
  49. package/lib/es6/relationships.js +1 -1
  50. package/lib/es6/relationships.js.gz +0 -0
  51. package/lib/es6/store.js +1 -1
  52. package/lib/es6/store.js.gz +0 -0
  53. package/lib/es6/tinybase.js +1 -1
  54. package/lib/es6/tinybase.js.gz +0 -0
  55. package/lib/es6/tools.js +1 -1
  56. package/lib/es6/tools.js.gz +0 -0
  57. package/lib/es6/ui-react.js +1 -1
  58. package/lib/es6/ui-react.js.gz +0 -0
  59. package/lib/indexes.js +1 -1
  60. package/lib/indexes.js.gz +0 -0
  61. package/lib/metrics.js +1 -1
  62. package/lib/metrics.js.gz +0 -0
  63. package/lib/relationships.js +1 -1
  64. package/lib/relationships.js.gz +0 -0
  65. package/lib/store.js +1 -1
  66. package/lib/store.js.gz +0 -0
  67. package/lib/tinybase.js +1 -1
  68. package/lib/tinybase.js.gz +0 -0
  69. package/lib/tools.js +1 -1
  70. package/lib/tools.js.gz +0 -0
  71. package/lib/types/store.d.ts +22 -12
  72. package/lib/types/ui-react.d.ts +11 -0
  73. package/lib/types/with-schemas/store.d.ts +23 -12
  74. package/lib/types/with-schemas/ui-react.d.ts +12 -0
  75. package/lib/ui-react.js +1 -1
  76. package/lib/ui-react.js.gz +0 -0
  77. package/lib/umd/checkpoints.js +1 -1
  78. package/lib/umd/checkpoints.js.gz +0 -0
  79. package/lib/umd/indexes.js +1 -1
  80. package/lib/umd/indexes.js.gz +0 -0
  81. package/lib/umd/metrics.js +1 -1
  82. package/lib/umd/metrics.js.gz +0 -0
  83. package/lib/umd/relationships.js +1 -1
  84. package/lib/umd/relationships.js.gz +0 -0
  85. package/lib/umd/store.js +1 -1
  86. package/lib/umd/store.js.gz +0 -0
  87. package/lib/umd/tinybase.js +1 -1
  88. package/lib/umd/tinybase.js.gz +0 -0
  89. package/lib/umd/tools.js +1 -1
  90. package/lib/umd/tools.js.gz +0 -0
  91. package/lib/umd/ui-react.js +1 -1
  92. package/lib/umd/ui-react.js.gz +0 -0
  93. package/lib/umd-es6/checkpoints.js +1 -1
  94. package/lib/umd-es6/checkpoints.js.gz +0 -0
  95. package/lib/umd-es6/indexes.js +1 -1
  96. package/lib/umd-es6/indexes.js.gz +0 -0
  97. package/lib/umd-es6/metrics.js +1 -1
  98. package/lib/umd-es6/metrics.js.gz +0 -0
  99. package/lib/umd-es6/relationships.js +1 -1
  100. package/lib/umd-es6/relationships.js.gz +0 -0
  101. package/lib/umd-es6/store.js +1 -1
  102. package/lib/umd-es6/store.js.gz +0 -0
  103. package/lib/umd-es6/tinybase.js +1 -1
  104. package/lib/umd-es6/tinybase.js.gz +0 -0
  105. package/lib/umd-es6/tools.js +1 -1
  106. package/lib/umd-es6/tools.js.gz +0 -0
  107. package/lib/umd-es6/ui-react.js +1 -1
  108. package/lib/umd-es6/ui-react.js.gz +0 -0
  109. package/package.json +9 -9
  110. package/readme.md +1 -1
package/lib/tools.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",d="default",r="Listener",s="get",I="add",$="Ids",c="Table",i=c+"s",u=c+$,p="Row",b=p+$,C="Sorted"+p+$,h="Cell",g=h+$,m="Value",f=m+"s",w=m+$,y=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),v=(e,t)=>e.forEach(t),V=(e,t)=>e.map(t),x=e=>e.length,R=e=>0==x(e),k=(e,t)=>e.filter(t),S=(e,...t)=>e.push(...t),P=e=>e.pop(),A=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,O=isFinite,N=(e,t)=>e instanceof t,L=e=>null==e,j=e=>e==l||e==a,M=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return j(l)||l==n&&O(t)?l:void 0},z=(e,t)=>e?.has(t)??!1,W=e=>[...e?.values()??[]],B=(e,t)=>e?.forEach(t),F=(e,t)=>e?.delete(t),U=e=>new Map(e),_=(e,t)=>e?.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>V([...e?.entries()??[]],(([e,l])=>t(l,e))),Q=(e,t,l)=>L(l)?(F(e,t),e):e?.set(t,l),q=(e,t,l)=>(z(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te=", and registers a listener so that any changes to that result will cause a re-render",le="Callback",ae="Del",ne="Deps",oe=ne+"?: React.DependencyList",de="doRollback?: DoRollback",re="actions: () => Return, "+de,se="export",Ie="Id",$e="Invalid",ce="Json",ie=X(r),ue="?: ",pe=" | undefined",be="NonNullable",Ce="Partial",he="Props",ge="Provider",me=`Registers a ${ie} that will be called`,fe="Represents",we="rowId: "+Ie,ye="Schema",Te="Set",ve=", descending?: boolean, offset?: number, limit?: number",Ve="[]",xe="the Store",Re="Transaction",ke=X(Re),Se="Execute a "+ke+" to make multiple mutations",Pe="Explicitly starts a "+ke,Ae="Explicitly finishes a "+ke,Ee="the end of the "+ke,De="void",Oe=" => "+De,Ne="WhenSet",Le=" when setting it",je=Y+"string serialization of",Me=" ",Ge="Gets a callback that can ",Je="the ",ze=" the schema for",We=(e=0,l=0)=>`the ${dt[e]}content of`+(l?Me+xe:t),Be=(e=0,l,a=0)=>at[l]+Me+We(e,1)+(a?" when setting it":t),Fe=(e,t=0)=>fe+` a Row when ${t?"s":"g"}etting ${We()} the '${e}' `+c,Ue=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,_e=(e,t)=>`Calls a function for each ${e} in `+t,Ze=e=>"The props passed to a component that renders "+e,He=e=>"A function that takes "+e,Qe=(e,t=0)=>ee+" listening to changes to "+ot[e]+" in "+ot[t],qe=(e,l,a=0)=>me+" whenever "+ot[e]+" in "+ot[l]+" change"+(a?t:"s"),Ke=e=>`the '${e}' `+c,Xe=e=>"the specified Row in "+Ke(e),Ye=(e,t=0)=>at[t]+` ${We()} `+Ke(e),et=(e,t=0)=>at[t]+` ${We()} `+Xe(e),tt=(e,t,l=0)=>at[l]+` the '${t}' Cell for `+Xe(e),lt=(e,t=0)=>at[t]+` the '${e}' Value`,at=["Gets","Checks existence of","Sets","Deletes","Sets part of",fe,"Gets "+je,"Sets "+je,me+" whenever",Ge+"set",Ge+"add",Ge+"set part of",Ge+"delete","Renders","Gets "+je+ze,"Sets"+ze,"Deletes"+ze],nt=[s,"has","set","del","set","forEach",I,t],ot=[xe,i,Je+c+Me+$,Y+c,Je+p+Me+$,Y+p,Je+h+Me+$,Y+h,"invalid Cell changes",f,Je+m+Me+$,Y+m,"invalid Value changes",Je+"sorted "+p+Me+$],dt=[t,"tabular ","keyed value "],rt=e=>new Set(G(e)||L(e)?e:[e]),st=(e,t)=>e?.add(t),It=/[^A-Za-z]+/,$t=/[^A-Za-z0-9]+/,ct=/^( *)\/\*\* *(.*?) *\*\/$/gm,it=(e,t,l)=>e.substring(t,l),ut=e=>e.includes(","),pt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return z(e,n)?pt(e,t,l,a+1):(Q(e,n,l),n)},bt=e=>e.replace(ct,((e,t,l)=>{const a=77-Ct(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Ct=e=>e.length,ht=(e,l=t)=>e.join(l),gt=e=>e.flat(1e3),mt=(e,t=0)=>ht(V(e.split($t),((e,l)=>(l>0||t?K:X)(it(e,0,1))+it(e,1)))),ft=e=>K(ht((e&&!It.test(e[0])?e:" "+e).split($t),"_")),wt=e=>`/** ${e}. */`,yt=(...e)=>ht(k(e,(e=>e)),", "),Tt=(...e)=>"{"+ht(e,"; ")+"}",vt=(...e)=>Tt(...V(e,(e=>"readonly "+e))),Vt=()=>{const e=[U(),U(),U(),U()],l=U(),a=U();return[(...e)=>ht(gt(e),"\n"),(t,l,...a)=>v(a,(a=>v([0,1],(n=>(t??n)==n?st(q(e[n],l,rt),a):0)))),(e,a,n,o=t,d=1)=>pt(l,e,[a,n,o,d]),(e,t,l)=>pt(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:pt(a,e,t),(l=0)=>V([...T(H(e[l],((e,t)=>`import {${ht(T(W(e)),", ")}} from '${t}';`)),((e,t)=>ut(e)!=ut(t)?ut(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l,a,n],o)=>[wt(l),`${n?se+" ":t}type ${o}${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],S(e,P(e)+";"),[`const ${l} = ${E(e)}`,e,t])))]},xt=Object,Rt=xt.keys,kt=xt.freeze,St=e=>N(e,xt)&&e.constructor==xt,Pt=(e,t)=>V(xt.entries(e),(([e,l])=>t(l,e))),At=e=>St(e)&&R(Rt(e)),Et=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Dt=(e,t,l)=>[t=>Pt(e,((e,a)=>t(a,mt(a,1),l(ft(a),`'${a}'`)))),(t,a)=>Pt(e[t],((e,t)=>a(t,e[o],e[d],l(ft(t),`'${t}'`),mt(t,1)))),e=>Pt(t,((t,a)=>e(a,t[o],t[d],l(ft(a),`'${a}'`),mt(a,1))))],Ot=(e,l,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(i,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,l,a)=>`'${e}'${L(a)?"?":t}: ${l}`)))+"}"))),Be(1,5)),I=e(i+Ne,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Be(1,5,1)),$=e(c+Ie,"keyof "+s,"A "+c+" Id in "+xe),m=`<TId extends ${$}>`,f=e(c,be+`<${s}[TId]>`,"A "+c+" in "+xe,m),w=e(c+Ne,be+`<${I}[TId]>`,"A "+c+" in "+xe+Le,m),y=e(p,f+"<TId>[Id]","A "+p+" in a "+c,m),T=e(p+Ne,w+"<TId>[Id]","A "+p+" in a "+c+Le,m),v=e(h+Ie,`Extract<keyof ${y}<TId>, Id>`,"A "+h+" Id in a "+p,m),V=e(h,be+`<${s}[TId]>[Id][CId]`,"A "+h+" in a "+p,`<TId extends ${$}, CId extends ${v}<TId>>`),x=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,h+" Ids and types in a "+p,`<TId extends ${$}, CId = ${v}<TId>>`,0),R=e(h+le,`(...[cellId, cell]: ${x}<TId>)`+Oe,He(Y+h+" Id, and "+h),m),k=e(p+le,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Oe+") "+Oe,He(Y+p+" Id, and a "+h+" iterator"),m),S=e("TableIdForEachRowArray",`TId extends ${$} ? [tableId: TId, forEachRow: (rowCallback: ${k}<TId>)${Oe}] : never`,c+" Ids and callback types",`<TId = ${$}>`,0),P=e(c+le,`(...[tableId, forEachRow]: ${S})`+Oe,He(Y+c+" Id, and a "+p+" iterator"),t),A=e("TableIdRowIdCellIdArray",`TId extends ${$} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${$}>`,0),E=e("GetCellChange",`(...[tableId, rowId, cellId]: ${A}) => CellChange`,ee+" returning information about any Cell's changes during a "+ke),D=e(i+r,`(${d}, getCellChange: ${E}${pe})`+Oe,Qe(1)),O=e(u+r,`(${d})`+Oe,Qe(2)),N=e(c+r,`(${d}, tableId: ${$}, getCellChange: ${E}${pe})`+Oe,Qe(3)),j=e(b+r,`(${d}, tableId: ${$})`+Oe,Qe(4,3)),M=e(C+r,"("+yt(d,"tableId: "+$,"cellId: Id"+pe,"descending: boolean","offset: number","limit: number"+pe,"sortedRowIds: Ids")+")"+Oe,Qe(13,3)),G=e(p+r,"("+yt(""+d,"tableId: "+$,we,`getCellChange: ${E}${pe}`)+")"+Oe,Qe(5,3)),J=e(g+r,"("+yt(""+d,"tableId: "+$,we)+")"+Oe,Qe(6,5)),z=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${we}, cellId: CId, newCell: ${V}<TId, CId> ${pe}, oldCell: ${V}<TId, CId> ${pe}, getCellChange: ${E} ${pe}] : never`,"Cell args for CellListener",`<TId extends ${$}, CId = ${v}<TId>>`,0),W=e("CellListenerArgsArrayOuter",`TId extends ${$} ? `+z+"<TId> : never","Table args for CellListener",`<TId = ${$}>`,0);return[s,I,$,f,w,y,T,v,V,R,k,P,D,O,N,j,M,G,J,e(h+r,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${W})`+Oe,Qe(7,5)),e($e+h+r,`(${d}, tableId: Id, ${we}, cellId: Id, invalidCells: any[])`+Oe,Qe(8))]},(l,a)=>{const o=l+": "+a,d=e(f,Tt(...n(((e,l,a)=>`'${e}'${L(a)?"?":t}: ${l}`))),Be(2,5)),s=e(f+Ne,Tt(...n(((e,t)=>`'${e}'?: ${t}`))),Be(2,5,1)),I=e(m+Ie,"keyof "+d,"A "+m+" Id in "+xe),$=e(m,be+`<${d}[VId]>`,"A "+m+" Id in "+xe,`<VId extends ${I}>`),c=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${$}<VId>] : never`,m+" Ids and types in "+xe,`<VId = ${I}>`,0),i=e(m+le,`(...[valueId, value]: ${c})`+Oe,He(Y+m+" Id, and "+m)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,ee+" returning information about any Value's changes during a "+ke),p=e(f+r,`(${o}, getValueChange: ${u}${pe})`+Oe,Qe(9)),b=e(w+r,`(${o})`+Oe,Qe(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${$}<VId> ${pe}, oldValue: ${$}<VId> ${pe}, getValueChange: ${u} ${pe}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,s,I,$,i,p,b,e(m+r,`(...[${l}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Oe,Qe(11)),e($e+m+r,`(${o}, valueId: Id, invalidValues: any[])`+Oe,Qe(12))]},(t,l)=>e(Re+r,`(${t}: ${l}, cellsTouched: boolean, valuesTouched: boolean)`+Oe,ee+" listening to the completion of a "+ke)],Nt=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),Lt=(e,l=t)=>`fluent(() => ${Nt(e,l)})`,jt=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,Mt=(e,l,n)=>{const[s,y,T,V,x,R,k,P]=Vt(),[E,D,O]=Dt(e,l,x),[N,j,G]=Ot(T,E,D,O),J=U(),z=(e=0)=>H(J,(([l,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${l}): ${a} => ${n},`]:[r+d+`(${l}): ${a};`];return e||A(s,wt(o)),S(s,t),s})),B=(e,l,a,n,o,d=t)=>pt(J,e,[l,a,n,o,d]),F=(e,l,a,n,o,d=t,r=t,s=t)=>B(nt[e]+l+(4==e?Ce:t)+a,d,n,(n==X?Lt:Nt)(nt[e]+(4==e?Ce:t)+a,r,e?void 0:n),o,s),q=(e,l,a,n=t,o=t,d=1,s=t)=>B(I+e+r,(n?n+", ":t)+ie+": "+l+(d?", mutator?: boolean":t),Ie,jt(I+e+r,o,d?"mutator":t),a,s),K=`./${mt(n)}.d`,X=mt(n,1),Y=mt(X),ee=[],te=U();let ae=[],ne=[];if(y(1,K,X,`create${X} as create${X}Decl`),!At(e)){y(0,"tinybase","CellChange"),y(null,"tinybase",$);const[e,l,n,r,s,I,m,f,w,V,R,k,P,A,O,j,G,J,z,B,Z]=N(Y,X),H=U();E(((e,t)=>{const l=`<'${e}'>`,a=[T(t+c,r+l,fe+` the '${e}' `+c),T(t+c+Ne,s+l,fe+` the '${e}' `+c+Le),T(t+p,I+l,Fe(e)),T(t+p+Ne,m+l,Fe(e,1)),T(t+h+Ie,f+l,`A Cell Id for the '${e}' `+c),T(t+h+le,V+l,He(`a Cell Id and value from a Row in the '${e}' `+c)),T(t+p+le,R+l,He(`a Row Id from the '${e}' Table, and a Cell iterator`))];Q(H,e,a),y(1,K,...a)})),y(1,K,e,l,n,f,k,P,A,O,j,G,J,z,B,Z),ae=[e,l,n,f,P,A,O,j,G,J,z,B,H],v([[e],[a],[X,"tables: "+l,"tables"],[X]],(([e,l,a],n)=>F(n,t,i,e,Be(1,n),l,a))),F(0,t,u,n+Ve,Ue(c,xe)),F(5,t,c,De,_e(c,xe),"tableCallback: "+k,"tableCallback as any"),E(((e,l,n)=>{const[o,d,r,s,I,i,u]=_(H,e);v([[o],[a],[X,"table: "+d,", table"],[X]],(([a,o,d=t],r)=>F(r,l,c,a,Ye(e,r),o,n+d))),F(0,l,b,$,Ue(p,Ke(e)),t,n),F(0,l,C,$,Ue(p,Ke(e),1),"cellId?: "+I+ve,n+", cellId, descending, offset, limit"),F(5,l,p,De,_e(p,Ke(e)),"rowCallback: "+u,n+", rowCallback as any"),v([[r],[a],[X,", row: "+s,", row"],[X],[X,", partialRow: "+s,", partialRow"]],(([a,o=t,d=t],r)=>F(r,l,p,a,et(e,r),we+o,n+", rowId"+d))),F(6,l,p,Ie+pe,"Add a new Row to "+Ke(e),"row: "+s,n+", row"),F(0,l,g,I+Ve,Ue(h,Xe(e)),we,n+", rowId"),F(5,l,h,De,_e(h,Xe(e)),we+", cellCallback: "+i,n+", rowId, cellCallback as any"),D(e,((o,d,r,s,I)=>{const $="Map"+mt(d,1);Q(te,d,$);const c=d+(L(r)?pe:t);v([[c],[a],[X,`, cell: ${d} | `+$,", cell as any"],[X]],(([a,d=t,r=t],$)=>F($,l+I,h,a,tt(e,o,$),we+d,n+", rowId, "+s+r)))}))})),F(0,t,i+ce,ce,Be(1,6)),F(2,t,i+ce,X,Be(1,7),"tablesJson: "+ce,"tables"+ce),q(i,P,Be(1,8)+" changes"),q(u,A,qe(2,0,1)),q(c,O,qe(3,0),`tableId: ${n} | null`,"tableId"),q(b,j,qe(4,3,1),`tableId: ${n} | null`,"tableId"),q(C,G,qe(13,3,1),yt("tableId: TId",`cellId: ${f}<TId>`+pe,"descending: boolean","offset: number","limit: number"+pe),yt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),q(p,J,qe(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(g,z,qe(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(h,B,qe(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${ht(E((e=>_(H,e)?.[4]??t))," | ")} | null`,"tableId, rowId, cellId"),q($e+h,Z,me+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),y(1,K,...W(te)),S(ee,".set"+i+ye+"({",gt(E(((e,l,a)=>[`[${a}]: {`,...D(e,((e,l,a,n)=>`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${L(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!At(l)){const[e,l,n,r,s,I,$,c,i]=j(Y,X);y(1,K,e,l,n,s,I,$,c,i),ne=[e,l,n,I,$,c],v([[e],[a],[X,"values: "+l,"values"],[X],[X,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>F(n,t,f,e,Be(2,n),l,a))),F(0,t,w,n+Ve,Ue(m,xe)),F(5,t,m,"void",_e(m,xe),"valueCallback: "+s,"valueCallback as any"),O(((e,l,n,o,d)=>{const r="Map"+mt(l,1);Q(te,l,r),v([[l],[a],[X,`value: ${l} | `+r,", value as any"],[X]],(([l,a,n=t],r)=>F(r,d,m,l,lt(e,r),a,o+n)))})),F(0,t,f+ce,ce,Be(2,6)),F(2,t,f+ce,X,Be(2,7),"valuesJson: "+ce,"values"+ce),q(f,I,Be(2,8)+" changes"),q(w,$,qe(10,0,1)),q(m,c,qe(11,0),`valueId: ${n} | null`,"valueId"),q($e+m,i,me+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),y(1,K,...W(te)),y(0,"tinybase","ValueChange"),S(ee,".set"+f+ye+"({",O(((e,l,a,n)=>[`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${L(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`])),"})")}Z(te,((e,t)=>T(t,`(cell: ${e}${pe}) => `+e,`Takes a ${e} Cell value and returns another`))),y(null,"tinybase","DoRollback",Ie,"IdOrNull",ce,"Store"),F(0,t,ce,ce,Be(0,6)),F(2,t,ce,X,Be(0,7),"tablesAndValuesJson: "+ce,"tablesAndValuesJson"),F(7,t,ke,"Return",Se,re,"actions, doRollback","<Return>"),F(7,t,"start"+Re,X,Pe),F(7,t,"finish"+Re,X,Ae,de,"doRollback");const oe=G(Y,X);return q("WillFinish"+Re,oe,me+" just before "+Ee,t,t,0),q("DidFinish"+Re,oe,me+" just after "+Ee,t,t,0),F(7,t,"call"+r,X,"Manually provoke a listener to be called","listenerId: Id","listenerId"),F(3,t,r,X,"Remove a listener that was previously added to "+xe,"listenerId: Id","listenerId"),B("getStore",t,"Store","store",at[0]+" the underlying Store object"),y(1,"tinybase","createStore"),y(1,K,X,`create${X} as create${X}Decl`,oe),x("store",["createStore()",...ee]),V("fluent","actions: () => Store",["actions();",`return ${Y};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${Y}, ...params)`),x(Y,["{",...z(1),"}"]),[s(...R(0),...k(),se+" interface "+X+" {",...z(0),"}",t,wt(`Creates a ${X} object`),se+" function create"+X+"(): "+X+";"),s(...R(1),se+" const create"+X+": typeof create"+X+"Decl = () => {",...P(),`return Object.freeze(${Y});`,"};"),ae,ne]},Gt=e=>s+e,Jt=e=>yt(Gt(e),Gt(e)+ne),zt="debugIds?: boolean",Wt="debugIds={debugIds}",Bt="then"+oe,Ft="Parameter",Ut=": (parameter: "+Ft+", store: Store) => ",_t="const contextValue = useContext(Context);",Zt=", based on a parameter",Ht=": ",Qt="<"+Ft+",>",qt=Ft+"ized"+le+"<"+Ft+">",Kt="rowId",Xt="rowId={rowId}",Yt=", separator, debugIds",el="separator?: ReactElement | string",tl="then?: (store: Store",ll=yt(tl+")"+Oe,Bt),al="then, then"+ne,nl=Kt+Ht+Ie,ol="View",dl=(e,...t)=>yt(...t,ie+": "+e,ie+oe,"mutator?: boolean"),rl=(...e)=>yt(...e,ie,ie+ne,"mutator"),sl=(e,l,a,n,o)=>{const[d,s,I,y,T,v,V,x]=Vt(),[R,k,P]=Dt(e,l,T),E=`./${mt(a)}.d`,D=`./${mt(a)}-ui-react.d`,O="tinybase/ui-react",N=mt(a,1),j=mt(N),M=N+"Or"+N+Ie,G=j+"Or"+N+Ie,J=j+`={${j}}`,z=U(),W=(e,l,a,n,o,d=t)=>(s(1,D,e+" as "+e+"Decl"),pt(z,e,[l,a,n,o,d])),B=(e,l,a,n,o,d=t)=>W("use"+e,l,a,n,o,d),F=(e,l,a,n,o=t,d=t,r=t,I=t,$=t)=>(s(1,O,`use${l} as use${l}Core`),B(e,yt(o,X,I),a,ne+`(${G}, use${l}Core, [`+(d||t)+($?"], ["+$:t)+"]);",n,r)),Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(z,(([l,a,n,o,d],r)=>{const s=e?[se+` const ${r}: typeof ${r}Decl = ${d}(${l}): ${1==a?"any":a} =>`,n]:[se+` function ${r}${d}(${l}): ${1==a?"ComponentReturnType":a};`];return e||A(s,wt(o)),S(s,t),s}));s(null,"tinybase",Ie,"Store",le,Ft+"ized"+le),s(0,O,"ComponentReturnType"),s(null,O,"ExtraProps"),s(0,E,N);const q=I(M,N+" | "+Ie,`Used when you need to refer to a ${N} in a React hook or component`),K=I(ge+he,vt(j+ue+N,j+`ById?: {[${j}Id: Id]: ${N}}`),`Used with the ${ge} component, so that a `+N+" can be passed into the context of an application");s(0,"react","ReactElement","ComponentType"),s(1,"react","React"),s(1,D,q,K);const X=G+ue+q;T("{createContext, useContext, useMemo}","React"),T("Context",`createContext<[${N}?, {[${j}Id: Id]: ${N}}?]>([])`),B("Create"+N,`create: () => ${N}, create`+oe,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const ee=B(N,"id?: Id",N+pe,["{",_t,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${N} from within a ${ge} component context`),ne=y("useHook",G+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${j} = ${ee}(${G} as Id);`,`return hook(...preParams, ((${G} == null || typeof ${G} == 'string')`,`? ${j} : ${G})?.getStore(), ...postParams)`]),de=y("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),re=y("wrap",yt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),$e=T("NullComponent","() => null");if(!At(e)){const[e,l,a,o,d,m,f,w,T,v,V,x,S]=n;s(null,E,e,l,a,d,m,f,w,T,v,V,x),s(0,E,o),s(1,E,N),s(null,"tinybase",$,"IdOrNull");const P=y("tableView",`{${j}, rowComponent, getRowComponentProps`+Yt+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${re}(rowIds.map((rowId) => (`,"<Row","{..."+de+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",Xt,J,Wt,"/>","))",Yt,", tableId,",");"]),A=y("getDefaultTableComponent","tableId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+$e),O=y("getDefaultCellComponent","tableId: Id, cellId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${ht(k(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+$e} : `)))+$e);F(i,i,e,Be(1,0)+te);const M=F(u,u,a+Ve,Ue(c,xe)+te);F(Te+i+le,Te+i+le,qt,Be(1,9)+Zt,yt(Gt(i)+Ut+l,Gt(i)+oe),Jt(i),Qt,yt(tl,`tables: ${l})`+Oe,Bt),al),F(ae+i+le,ae+i+le,le,Be(1,12),t,t,t,ll,al);const G=I(h+he,vt("tableId?: TId","rowId: Id","cellId?: CId",j+ue+N,zt),Ze(Y+h),`<TId extends ${a}, CId extends ${o}<TId>>`),z=I(p+he,vt("tableId?: TId","rowId: Id",j+ue+N,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${G}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,el,zt),Ze(Y+p),`<TId extends ${a}>`),W=I(c+he,vt("tableId?: TId",j+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+c),`<TId extends ${a}>`),B=I("Sorted"+c+he,vt("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",j+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+"sorted "+c),`<TId extends ${a}>`),U=I(i+he,vt(j+ue+N,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${W}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,el,zt),Ze(We(1,1)));s(1,D,U,W,B,z,G),Z(i+ol,"{"+j+", tableComponents, getTableComponentProps"+Yt+"}: "+U,[re+`(${M}(${j}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+A+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${de}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Wt,"/>;","}), separator)"],Be(1,13)+te),R(((e,l,a)=>{const[n,o,d,r,I]=_(S,e);s(null,E,n,o,d,r,I),F(l+c,c,n,Ye(e)+te,t,a);const i=F(l+b,b,$,Ue(p,Ke(e))+te,t,a),u=F(l+C,C,$,Ue(p,Ke(e),1)+te,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(l+p,p,d,et(e)+te,nl,yt(a,Kt));const m=F(l+g,g,I+Ve,Ue(h,Xe(e))+te,nl,yt(a,Kt));F(Te+l+c+le,Te+c+le,qt,Ye(e,9)+Zt,yt(Gt(c)+Ut+o,Gt(c)+oe),yt(a,Jt(c)),Qt,yt(tl,`table: ${o})`+Oe,Bt),al),F(ae+l+c+le,ae+c+le,le,Ye(e,12),t,a,t,ll,al),F(Te+l+p+le,Te+p+le,qt,et(e,9)+Zt,yt(nl,Gt(p)+Ut+r,Gt(p)+oe),yt(a,Kt,Jt(p)),Qt,yt(tl,`row: ${r})`+Oe,Bt),al),F("Add"+l+p+le,"Add"+p+le,qt,et(e,10)+Zt,yt(Gt(p)+Ut+r,Gt(p)+oe),yt(a,Jt(p)),Qt,"then?: ("+yt(nl+pe,"store: Store","row: "+r+")"+Oe,"then"+oe),al),F(Te+l+Ce+p+le,Te+Ce+p+le,qt,et(e,11)+Zt,yt(nl,Gt(Ce+p)+Ut+r,Gt(Ce+p)+oe),yt(a,Kt,Jt(Ce+p)),Qt,yt(tl,`partialRow: ${r})`+Oe,Bt),al),F(ae+l+p+le,ae+p+le,le,et(e,12),nl,yt(a,Kt),t,ll,al);const f=Z(l+p+ol,"{rowId, "+j+", cellComponents, getCellComponentProps"+Yt+`}: ${z}<'${e}'>`,[re+`(${m}(rowId, ${j}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+O+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${de}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,Xt,"cellId={cellId}",J,Wt,"/>;","})"+Yt+", rowId)"],et(e,13)+te);Z(l+"Sorted"+c+ol,"{cellId, descending, offset, limit, ...props}: "+B+`<'${e}'>`,P+"(props, "+u+`(cellId, descending, offset, limit, props.${j}), ${a}, ${f});`,Ye(e,13)+", sorted"+te),Z(l+c+ol,`props: ${W}<'${e}'>`,P+"(props, "+i+`(props.${j}), ${a}, ${f});`,Ye(e,13)+te),k(e,((n,o,d,r,I)=>{const $="Map"+mt(o,1);s(0,E,$),s(1,E,$);const c=F(l+I+h,h,o+(L(d)?pe:t),tt(e,n)+te,nl,yt(a,Kt,r));F(Te+l+I+h+le,Te+h+le,qt,tt(e,n,9)+Zt,yt(nl,Gt(h)+Ut+o+" | "+$,Gt(h)+oe),yt(a,Kt,r,Jt(h)),Qt,yt(tl,`cell: ${o} | ${$})`+Oe,Bt),al),F(ae+l+I+h+le,ae+h+le,le,tt(e,n,12),yt(nl,"forceDel?: boolean"),yt(a,Kt,r,"forceDel"),t,ll,al),Z(l+I+h+ol,`{rowId, ${j}, debugIds}: `+G+`<'${e}', '${n}'>`,[re+`('' + ${c}(rowId, `+j+`) ?? '', undefined, debugIds, ${r})`],tt(e,n,13)+te)}))}));const H=ht(R((e=>_(S,e)?.[4]??t))," | ");F(i+r,i+r,De,Be(1,8)+" changes",dl(d),rl()),F(u+r,u+r,De,qe(2,0,1),dl(m),rl()),F(c+r,c+r,De,qe(3,0),dl(f,`tableId: ${a} | null`),rl("tableId")),F(b+r,b+r,De,qe(4,3,1),dl(w,`tableId: ${a} | null`),rl("tableId")),F(C+r,C+r,De,qe(13,3,1),dl(T,`tableId: ${a} | null`,"cellId: "+H+pe,"descending: boolean","offset: number","limit: number"+pe),rl("tableId","cellId","descending","offset","limit")),F(p+r,p+r,De,qe(5,3),dl(v,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(g+r,g+r,De,qe(6,5,1),dl(V,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(h+r,h+r,De,qe(7,5),dl(x,`tableId: ${a} | null`,Kt+": IdOrNull",`cellId: ${H} | null`),rl("tableId",Kt,"cellId"))}if(!At(l)){const[e,l,a,n,d,$]=o;s(null,E,...o),s(1,E,N);const c=y("getDefaultValueComponent","valueId: Id",ht(P(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+$e);F(f,f,e,Be(2,0)+te);const i=F(w,w,a+Ve,Ue(m,xe)+te);F(Te+f+le,Te+f+le,qt,Be(2,9)+Zt,yt(Gt(f)+Ut+l,Gt(f)+oe),Jt(f),Qt,yt(tl,`values: ${l})`+Oe,Bt),al),F(Te+Ce+f+le,Te+Ce+f+le,qt,Be(2,11)+Zt,yt(Gt(Ce+f)+Ut+l,Gt(Ce+f)+oe),Jt(Ce+f),Qt,yt(tl,`partialValues: ${l})`+Oe,Bt),al),F(ae+f+le,ae+f+le,le,Be(2,12),t,t,t,ll,al);const u=I(m+he,vt("valueId?: VId",j+ue+N,zt),Ze("a Value"),`<VId extends ${a}>`),p=I(f+he,vt(j+ue+N,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${u}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,el,zt),Ze(We(2,1)));s(1,D,p,u),Z(f+ol,"{"+j+", valueComponents, getValueComponentProps"+Yt+"}: "+p,[re+`(${i}(${j}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+c+"(valueId);","return <Value",`{...${de}(getValueComponentProps, valueId)}`,"key={valueId}",J,Wt,"/>;","}), separator)"],Be(2,13)+te),P(((e,l,a,n,o)=>{const d="Map"+mt(l,1);s(0,E,d),s(1,E,d);const r=F(o+m,m,l,lt(e)+te,t,n);F(Te+o+m+le,Te+m+le,qt,lt(e,9)+Zt,yt(Gt(m)+Ut+l+" | "+d,Gt(m)+oe),yt(n,Jt(m)),Qt,yt(tl,`value: ${l} | ${d})`+Oe,Bt),al),F(ae+o+m+le,ae+m+le,le,lt(e,12),t,n,t,ll,al),Z(o+m+ol,`{${j}, debugIds}: ${u}<'${e}'>`,[re+`('' + ${r}(`+j+`) ?? '', undefined, debugIds, ${n})`],lt(e,13)+te)})),F(f+r,f+r,De,Be(2,8)+" changes",dl(n),rl()),F(w+r,w+r,De,qe(10,0,1),dl(d),rl()),F(m+r,m+r,De,qe(11,0),dl($,`valueId: ${a} | null`),rl("valueId"))}return Z(ge,`{${j}, ${j}ById, children}: `+K+" & {children: React.ReactNode}",["{",_t,"return (","<Context."+ge,"value={useMemo(",`() => [${j} ?? contextValue[0], {...contextValue[1], ...${j}ById}],`,`[${j}, ${j}ById, contextValue],`,")}>","{children}",`</Context.${ge}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...v(0),...V(),...Q(0)),d(...v(1),...x(),...Q(1))]},Il=(e,l,a)=>{if(At(e)&&At(l))return[t,t,t,t];const[n,o,d,r]=Mt(e,l,a);return[n,o,...sl(e,l,a,d,r)]},$l={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},cl=Et((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!At(t)||y(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(y(a,(t=>y(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=q(n,a,(()=>[J(o),U(),[0],0])),[r,s,[I]]=d,$=q(s,o,(()=>0))+1;return $>I&&(d[2]=[$,o]),Q(s,o,$),d[3]++,r==J(o)})))))return t[l]={},B(n,(([e,,[,n],r],s)=>{t[l][s]={[o]:e,...r==x(a)?{[d]:n}:{}}})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return At(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>Il(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(await import("prettier")).format}catch(e){l=e=>e}return V(a(e),((e,a)=>bt(l(e,{...$l,filepath:"_."+t[a]}))))};return kt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:x(e.getValueIds()),jsonLength:Ct(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{cl as createTools};
1
+ const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",d="default",r="Listener",s="get",I="add",$="Ids",c="Table",i=c+"s",u=c+$,p="Row",b=p+$,C="Sorted"+p+$,h="Cell",g=h+$,m="Value",w=m+"s",f=m+$,y=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),v=(e,t)=>e.forEach(t),V=(e,t)=>e.map(t),x=e=>e.length,R=e=>0==x(e),k=(e,t)=>e.filter(t),S=(e,...t)=>e.push(...t),P=e=>e.pop(),A=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,O=isFinite,N=(e,t)=>e instanceof t,L=e=>null==e,j=e=>e==l||e==a,M=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return j(l)||l==n&&O(t)?l:void 0},z=(e,t)=>e?.has(t)??!1,W=e=>[...e?.values()??[]],B=(e,t)=>e?.forEach(t),F=(e,t)=>e?.delete(t),U=e=>new Map(e),_=(e,t)=>e?.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>V([...e?.entries()??[]],(([e,l])=>t(l,e))),Q=(e,t,l)=>L(l)?(F(e,t),e):e?.set(t,l),q=(e,t,l)=>(z(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te=", and registers a listener so that any changes to that result will cause a re-render",le="Callback",ae="Del",ne="Deps",oe=ne+"?: React.DependencyList",de="doRollback?: DoRollback",re="actions: () => Return, "+de,se="export",Ie="Id",$e="Invalid",ce="Json",ie=X(r),ue="?: ",pe=" | undefined",be="NonNullable",Ce="Partial",he="Props",ge="Provider",me=`Registers a ${ie} that will be called`,we="Represents",fe="rowId: "+Ie,ye="Schema",Te="Set",ve=", descending?: boolean, offset?: number, limit?: number",Ve="[]",xe="the Store",Re="Transaction",ke=X(Re),Se="Execute a "+ke+" to make multiple mutations",Pe="Explicitly starts a "+ke,Ae="Explicitly finishes a "+ke,Ee="the end of the "+ke,De="void",Oe=" => "+De,Ne="WhenSet",Le=" when setting it",je=Y+"string serialization of",Me=" ",Ge="Gets a callback that can ",Je="the ",ze=" the schema for",We=(e=0,l=0)=>`the ${dt[e]}content of`+(l?Me+xe:t),Be=(e=0,l,a=0)=>at[l]+Me+We(e,1)+(a?" when setting it":t),Fe=(e,t=0)=>we+` a Row when ${t?"s":"g"}etting ${We()} the '${e}' `+c,Ue=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,_e=(e,t)=>`Calls a function for each ${e} in `+t,Ze=e=>"The props passed to a component that renders "+e,He=e=>"A function that takes "+e,Qe=(e,t=0)=>ee+" listening to changes to "+ot[e]+" in "+ot[t],qe=(e,l,a=0)=>me+" whenever "+ot[e]+" in "+ot[l]+" change"+(a?t:"s"),Ke=e=>`the '${e}' `+c,Xe=e=>"the specified Row in "+Ke(e),Ye=(e,t=0)=>at[t]+` ${We()} `+Ke(e),et=(e,t=0)=>at[t]+` ${We()} `+Xe(e),tt=(e,t,l=0)=>at[l]+` the '${t}' Cell for `+Xe(e),lt=(e,t=0)=>at[t]+` the '${e}' Value`,at=["Gets","Checks existence of","Sets","Deletes","Sets part of",we,"Gets "+je,"Sets "+je,me+" whenever",Ge+"set",Ge+"add",Ge+"set part of",Ge+"delete","Renders","Gets "+je+ze,"Sets"+ze,"Deletes"+ze],nt=[s,"has","set","del","set","forEach",I,t],ot=[xe,i,Je+c+Me+$,Y+c,Je+p+Me+$,Y+p,Je+h+Me+$,Y+h,"invalid Cell changes",w,Je+m+Me+$,Y+m,"invalid Value changes",Je+"sorted "+p+Me+$],dt=[t,"tabular ","keyed value "],rt=e=>new Set(G(e)||L(e)?e:[e]),st=(e,t)=>e?.add(t),It=/[^A-Za-z]+/,$t=/[^A-Za-z0-9]+/,ct=/^( *)\/\*\* *(.*?) *\*\/$/gm,it=(e,t,l)=>e.substring(t,l),ut=e=>e.includes(","),pt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return z(e,n)?pt(e,t,l,a+1):(Q(e,n,l),n)},bt=e=>e.replace(ct,((e,t,l)=>{const a=77-Ct(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Ct=e=>e.length,ht=(e,l=t)=>e.join(l),gt=e=>e.flat(1e3),mt=(e,t=0)=>ht(V(e.split($t),((e,l)=>(l>0||t?K:X)(it(e,0,1))+it(e,1)))),wt=e=>K(ht((e&&!It.test(e[0])?e:" "+e).split($t),"_")),ft=e=>`/** ${e}. */`,yt=(...e)=>ht(k(e,(e=>e)),", "),Tt=(...e)=>"{"+ht(e,"; ")+"}",vt=(...e)=>Tt(...V(e,(e=>"readonly "+e))),Vt=()=>{const e=[U(),U(),U(),U()],l=U(),a=U();return[(...e)=>ht(gt(e),"\n"),(t,l,...a)=>v(a,(a=>v([0,1],(n=>(t??n)==n?st(q(e[n],l,rt),a):0)))),(e,a,n,o=t,d=1)=>pt(l,e,[a,n,o,d]),(e,t,l)=>pt(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:pt(a,e,t),(l=0)=>V([...T(H(e[l],((e,t)=>`import {${ht(T(W(e)),", ")}} from '${t}';`)),((e,t)=>ut(e)!=ut(t)?ut(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l,a,n],o)=>[ft(l),`${n?se+" ":t}type ${o}${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],S(e,P(e)+";"),[`const ${l} = ${E(e)}`,e,t])))]},xt=Object,Rt=xt.keys,kt=xt.freeze,St=e=>N(e,xt)&&e.constructor==xt,Pt=(e,t)=>V(xt.entries(e),(([e,l])=>t(l,e))),At=e=>St(e)&&R(Rt(e)),Et=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Dt=(e,t,l)=>[t=>Pt(e,((e,a)=>t(a,mt(a,1),l(wt(a),`'${a}'`)))),(t,a)=>Pt(e[t],((e,t)=>a(t,e[o],e[d],l(wt(t),`'${t}'`),mt(t,1)))),e=>Pt(t,((t,a)=>e(a,t[o],t[d],l(wt(a),`'${a}'`),mt(a,1))))],Ot=(e,l,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(i,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,l,a)=>`'${e}'${L(a)?"?":t}: ${l}`)))+"}"))),Be(1,5)),I=e(i+Ne,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Be(1,5,1)),$=e(c+Ie,"keyof "+s,"A "+c+" Id in "+xe),m=`<TId extends ${$}>`,w=e(c,be+`<${s}[TId]>`,"A "+c+" in "+xe,m),f=e(c+Ne,be+`<${I}[TId]>`,"A "+c+" in "+xe+Le,m),y=e(p,w+"<TId>[Id]","A "+p+" in a "+c,m),T=e(p+Ne,f+"<TId>[Id]","A "+p+" in a "+c+Le,m),v=e(h+Ie,`Extract<keyof ${y}<TId>, Id>`,"A "+h+" Id in a "+p,m),V=e(h,be+`<${s}[TId]>[Id][CId]`,"A "+h+" in a "+p,`<TId extends ${$}, CId extends ${v}<TId>>`),x=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,h+" Ids and types in a "+p,`<TId extends ${$}, CId = ${v}<TId>>`,0),R=e(h+le,`(...[cellId, cell]: ${x}<TId>)`+Oe,He(Y+h+" Id, and "+h),m),k=e(p+le,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Oe+") "+Oe,He(Y+p+" Id, and a "+h+" iterator"),m),S=e("TableIdForEachRowArray",`TId extends ${$} ? [tableId: TId, forEachRow: (rowCallback: ${k}<TId>)${Oe}] : never`,c+" Ids and callback types",`<TId = ${$}>`,0),P=e(c+le,`(...[tableId, forEachRow]: ${S})`+Oe,He(Y+c+" Id, and a "+p+" iterator"),t),A=e("TableIdRowIdCellIdArray",`TId extends ${$} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${$}>`,0),E=e("GetCellChange",`(...[tableId, rowId, cellId]: ${A}) => CellChange`,ee+" returning information about any Cell's changes during a "+ke),D=e(i+r,`(${d}, getCellChange: ${E}${pe})`+Oe,Qe(1)),O=e(u+r,`(${d})`+Oe,Qe(2)),N=e(c+r,`(${d}, tableId: ${$}, getCellChange: ${E}${pe})`+Oe,Qe(3)),j=e(b+r,`(${d}, tableId: ${$})`+Oe,Qe(4,3)),M=e(C+r,"("+yt(d,"tableId: "+$,"cellId: Id"+pe,"descending: boolean","offset: number","limit: number"+pe,"sortedRowIds: Ids")+")"+Oe,Qe(13,3)),G=e(p+r,"("+yt(""+d,"tableId: "+$,fe,`getCellChange: ${E}${pe}`)+")"+Oe,Qe(5,3)),J=e(g+r,"("+yt(""+d,"tableId: "+$,fe)+")"+Oe,Qe(6,5)),z=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${fe}, cellId: CId, newCell: ${V}<TId, CId> ${pe}, oldCell: ${V}<TId, CId> ${pe}, getCellChange: ${E} ${pe}] : never`,"Cell args for CellListener",`<TId extends ${$}, CId = ${v}<TId>>`,0),W=e("CellListenerArgsArrayOuter",`TId extends ${$} ? `+z+"<TId> : never","Table args for CellListener",`<TId = ${$}>`,0);return[s,I,$,w,f,y,T,v,V,R,k,P,D,O,N,j,M,G,J,e(h+r,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${W})`+Oe,Qe(7,5)),e($e+h+r,`(${d}, tableId: Id, ${fe}, cellId: Id, invalidCells: any[])`+Oe,Qe(8))]},(l,a)=>{const o=l+": "+a,d=e(w,Tt(...n(((e,l,a)=>`'${e}'${L(a)?"?":t}: ${l}`))),Be(2,5)),s=e(w+Ne,Tt(...n(((e,t)=>`'${e}'?: ${t}`))),Be(2,5,1)),I=e(m+Ie,"keyof "+d,"A "+m+" Id in "+xe),$=e(m,be+`<${d}[VId]>`,"A "+m+" Id in "+xe,`<VId extends ${I}>`),c=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${$}<VId>] : never`,m+" Ids and types in "+xe,`<VId = ${I}>`,0),i=e(m+le,`(...[valueId, value]: ${c})`+Oe,He(Y+m+" Id, and "+m)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,ee+" returning information about any Value's changes during a "+ke),p=e(w+r,`(${o}, getValueChange: ${u}${pe})`+Oe,Qe(9)),b=e(f+r,`(${o})`+Oe,Qe(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${$}<VId> ${pe}, oldValue: ${$}<VId> ${pe}, getValueChange: ${u} ${pe}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,s,I,$,i,p,b,e(m+r,`(...[${l}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Oe,Qe(11)),e($e+m+r,`(${o}, valueId: Id, invalidValues: any[])`+Oe,Qe(12))]},(t,l)=>e(Re+r,`(${t}: ${l}, cellsTouched: boolean, valuesTouched: boolean)`+Oe,ee+" listening to the completion of a "+ke)],Nt=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),Lt=(e,l=t)=>`fluent(() => ${Nt(e,l)})`,jt=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,Mt=(e,l,n)=>{const[s,y,T,V,x,R,k,P]=Vt(),[E,D,O]=Dt(e,l,x),[N,j,G]=Ot(T,E,D,O),J=U(),z=(e=0)=>H(J,(([l,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${l}): ${a} => ${n},`]:[r+d+`(${l}): ${a};`];return e||A(s,ft(o)),S(s,t),s})),B=(e,l,a,n,o,d=t)=>pt(J,e,[l,a,n,o,d]),F=(e,l,a,n,o,d=t,r=t,s=t)=>B(nt[e]+l+(4==e?Ce:t)+a,d,n,(n==X?Lt:Nt)(nt[e]+(4==e?Ce:t)+a,r,e?void 0:n),o,s),q=(e,l,a,n=t,o=t,d=1,s=t)=>B(I+e+r,(n?n+", ":t)+ie+": "+l+(d?", mutator?: boolean":t),Ie,jt(I+e+r,o,d?"mutator":t),a,s),K=`./${mt(n)}.d`,X=mt(n,1),Y=mt(X),ee=[],te=U();let ae=[],ne=[];if(y(1,K,X,`create${X} as create${X}Decl`),!At(e)){y(0,"tinybase","CellChange"),y(null,"tinybase",$);const[e,l,n,r,s,I,m,w,f,V,R,k,P,A,O,j,G,J,z,B,Z]=N(Y,X),H=U();E(((e,t)=>{const l=`<'${e}'>`,a=[T(t+c,r+l,we+` the '${e}' `+c),T(t+c+Ne,s+l,we+` the '${e}' `+c+Le),T(t+p,I+l,Fe(e)),T(t+p+Ne,m+l,Fe(e,1)),T(t+h+Ie,w+l,`A Cell Id for the '${e}' `+c),T(t+h+le,V+l,He(`a Cell Id and value from a Row in the '${e}' `+c)),T(t+p+le,R+l,He(`a Row Id from the '${e}' Table, and a Cell iterator`))];Q(H,e,a),y(1,K,...a)})),y(1,K,e,l,n,w,k,P,A,O,j,G,J,z,B,Z),ae=[e,l,n,w,P,A,O,j,G,J,z,B,H],v([[e],[a],[X,"tables: "+l,"tables"],[X]],(([e,l,a],n)=>F(n,t,i,e,Be(1,n),l,a))),F(0,t,u,n+Ve,Ue(c,xe)),F(5,t,c,De,_e(c,xe),"tableCallback: "+k,"tableCallback as any"),E(((e,l,n)=>{const[o,d,r,s,I,i,u]=_(H,e);v([[o],[a],[X,"table: "+d,", table"],[X]],(([a,o,d=t],r)=>F(r,l,c,a,Ye(e,r),o,n+d))),F(0,l,b,$,Ue(p,Ke(e)),t,n),F(0,l,C,$,Ue(p,Ke(e),1),"cellId?: "+I+ve,n+", cellId, descending, offset, limit"),F(5,l,p,De,_e(p,Ke(e)),"rowCallback: "+u,n+", rowCallback as any"),v([[r],[a],[X,", row: "+s,", row"],[X],[X,", partialRow: "+s,", partialRow"]],(([a,o=t,d=t],r)=>F(r,l,p,a,et(e,r),fe+o,n+", rowId"+d))),F(6,l,p,Ie+pe,"Add a new Row to "+Ke(e),"row: "+s+", reuseIds?: boolean",n+", row, reuseIds"),F(0,l,g,I+Ve,Ue(h,Xe(e)),fe,n+", rowId"),F(5,l,h,De,_e(h,Xe(e)),fe+", cellCallback: "+i,n+", rowId, cellCallback as any"),D(e,((o,d,r,s,I)=>{const $="Map"+mt(d,1);Q(te,d,$);const c=d+(L(r)?pe:t);v([[c],[a],[X,`, cell: ${d} | `+$,", cell as any"],[X]],(([a,d=t,r=t],$)=>F($,l+I,h,a,tt(e,o,$),fe+d,n+", rowId, "+s+r)))}))})),F(0,t,i+ce,ce,Be(1,6)),F(2,t,i+ce,X,Be(1,7),"tablesJson: "+ce,"tables"+ce),q(i,P,Be(1,8)+" changes"),q(u,A,qe(2,0,1)),q(c,O,qe(3,0),`tableId: ${n} | null`,"tableId"),q(b,j,qe(4,3,1),`tableId: ${n} | null`,"tableId"),q(C,G,qe(13,3,1),yt("tableId: TId",`cellId: ${w}<TId>`+pe,"descending: boolean","offset: number","limit: number"+pe),yt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),q(p,J,qe(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(g,z,qe(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(h,B,qe(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${ht(E((e=>_(H,e)?.[4]??t))," | ")} | null`,"tableId, rowId, cellId"),q($e+h,Z,me+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),y(1,K,...W(te)),S(ee,".set"+i+ye+"({",gt(E(((e,l,a)=>[`[${a}]: {`,...D(e,((e,l,a,n)=>`[${n}]: {[${x(wt(o),`'${o}'`)}]: ${x(wt(l),`'${l}'`)}${L(a)?t:`, [${x(wt(d),`'${d}'`)}]: `+(M(a)?x(wt(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!At(l)){const[e,l,n,r,s,I,$,c,i]=j(Y,X);y(1,K,e,l,n,s,I,$,c,i),ne=[e,l,n,I,$,c],v([[e],[a],[X,"values: "+l,"values"],[X],[X,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>F(n,t,w,e,Be(2,n),l,a))),F(0,t,f,n+Ve,Ue(m,xe)),F(5,t,m,"void",_e(m,xe),"valueCallback: "+s,"valueCallback as any"),O(((e,l,n,o,d)=>{const r="Map"+mt(l,1);Q(te,l,r),v([[l],[a],[X,`value: ${l} | `+r,", value as any"],[X]],(([l,a,n=t],r)=>F(r,d,m,l,lt(e,r),a,o+n)))})),F(0,t,w+ce,ce,Be(2,6)),F(2,t,w+ce,X,Be(2,7),"valuesJson: "+ce,"values"+ce),q(w,I,Be(2,8)+" changes"),q(f,$,qe(10,0,1)),q(m,c,qe(11,0),`valueId: ${n} | null`,"valueId"),q($e+m,i,me+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),y(1,K,...W(te)),y(0,"tinybase","ValueChange"),S(ee,".set"+w+ye+"({",O(((e,l,a,n)=>[`[${n}]: {[${x(wt(o),`'${o}'`)}]: ${x(wt(l),`'${l}'`)}${L(a)?t:`, [${x(wt(d),`'${d}'`)}]: `+(M(a)?x(wt(a),`'${a}'`):a)}},`])),"})")}Z(te,((e,t)=>T(t,`(cell: ${e}${pe}) => `+e,`Takes a ${e} Cell value and returns another`))),y(null,"tinybase","DoRollback",Ie,"IdOrNull",ce,"Store"),F(0,t,ce,ce,Be(0,6)),F(2,t,ce,X,Be(0,7),"tablesAndValuesJson: "+ce,"tablesAndValuesJson"),F(7,t,ke,"Return",Se,re,"actions, doRollback","<Return>"),F(7,t,"start"+Re,X,Pe),F(7,t,"finish"+Re,X,Ae,de,"doRollback");const oe=G(Y,X);return q("WillFinish"+Re,oe,me+" just before "+Ee,t,t,0),q("DidFinish"+Re,oe,me+" just after "+Ee,t,t,0),F(7,t,"call"+r,X,"Manually provoke a listener to be called","listenerId: Id","listenerId"),F(3,t,r,X,"Remove a listener that was previously added to "+xe,"listenerId: Id","listenerId"),B("getStore",t,"Store","store",at[0]+" the underlying Store object"),y(1,"tinybase","createStore"),y(1,K,X,`create${X} as create${X}Decl`,oe),x("store",["createStore()",...ee]),V("fluent","actions: () => Store",["actions();",`return ${Y};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${Y}, ...params)`),x(Y,["{",...z(1),"}"]),[s(...R(0),...k(),se+" interface "+X+" {",...z(0),"}",t,ft(`Creates a ${X} object`),se+" function create"+X+"(): "+X+";"),s(...R(1),se+" const create"+X+": typeof create"+X+"Decl = () => {",...P(),`return Object.freeze(${Y});`,"};"),ae,ne]},Gt=e=>s+e,Jt=e=>yt(Gt(e),Gt(e)+ne),zt="debugIds?: boolean",Wt="debugIds={debugIds}",Bt="then"+oe,Ft="Parameter",Ut=": (parameter: "+Ft+", store: Store) => ",_t="const contextValue = useContext(Context);",Zt=", based on a parameter",Ht=": ",Qt="<"+Ft+",>",qt=Ft+"ized"+le+"<"+Ft+">",Kt="rowId",Xt="rowId={rowId}",Yt=", separator, debugIds",el="separator?: ReactElement | string",tl="then?: (store: Store",ll=yt(tl+")"+Oe,Bt),al="then, then"+ne,nl=Kt+Ht+Ie,ol="View",dl=(e,...t)=>yt(...t,ie+": "+e,ie+oe,"mutator?: boolean"),rl=(...e)=>yt(...e,ie,ie+ne,"mutator"),sl=(e,l,a,n,o)=>{const[d,s,I,y,T,v,V,x]=Vt(),[R,k,P]=Dt(e,l,T),E=`./${mt(a)}.d`,D=`./${mt(a)}-ui-react.d`,O="tinybase/ui-react",N=mt(a,1),j=mt(N),M=N+"Or"+N+Ie,G=j+"Or"+N+Ie,J=j+`={${j}}`,z=U(),W=(e,l,a,n,o,d=t)=>(s(1,D,e+" as "+e+"Decl"),pt(z,e,[l,a,n,o,d])),B=(e,l,a,n,o,d=t)=>W("use"+e,l,a,n,o,d),F=(e,l,a,n,o=t,d=t,r=t,I=t,$=t)=>(s(1,O,`use${l} as use${l}Core`),B(e,yt(o,X,I),a,ne+`(${G}, use${l}Core, [`+(d||t)+($?"], ["+$:t)+"]);",n,r)),Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(z,(([l,a,n,o,d],r)=>{const s=e?[se+` const ${r}: typeof ${r}Decl = ${d}(${l}): ${1==a?"any":a} =>`,n]:[se+` function ${r}${d}(${l}): ${1==a?"ComponentReturnType":a};`];return e||A(s,ft(o)),S(s,t),s}));s(null,"tinybase",Ie,"Store",le,Ft+"ized"+le),s(0,O,"ComponentReturnType"),s(null,O,"ExtraProps"),s(0,E,N);const q=I(M,N+" | "+Ie,`Used when you need to refer to a ${N} in a React hook or component`),K=I(ge+he,vt(j+ue+N,j+`ById?: {[${j}Id: Id]: ${N}}`),`Used with the ${ge} component, so that a `+N+" can be passed into the context of an application");s(0,"react","ReactElement","ComponentType"),s(1,"react","React"),s(1,D,q,K);const X=G+ue+q;T("{createContext, useContext, useMemo}","React"),T("Context",`createContext<[${N}?, {[${j}Id: Id]: ${N}}?]>([])`),B("Create"+N,`create: () => ${N}, create`+oe,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const ee=B(N,"id?: Id",N+pe,["{",_t,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${N} from within a ${ge} component context`),ne=y("useHook",G+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${j} = ${ee}(${G} as Id);`,`return hook(...preParams, ((${G} == null || typeof ${G} == 'string')`,`? ${j} : ${G})?.getStore(), ...postParams)`]),de=y("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),re=y("wrap",yt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),$e=T("NullComponent","() => null");if(!At(e)){const[e,l,a,o,d,m,w,f,T,v,V,x,S]=n;s(null,E,e,l,a,d,m,w,f,T,v,V,x),s(0,E,o),s(1,E,N),s(null,"tinybase",$,"IdOrNull");const P=y("tableView",`{${j}, rowComponent, getRowComponentProps`+Yt+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${re}(rowIds.map((rowId) => (`,"<Row","{..."+de+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",Xt,J,Wt,"/>","))",Yt,", tableId,",");"]),A=y("getDefaultTableComponent","tableId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+$e),O=y("getDefaultCellComponent","tableId: Id, cellId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${ht(k(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+$e} : `)))+$e);F(i,i,e,Be(1,0)+te);const M=F(u,u,a+Ve,Ue(c,xe)+te);F(Te+i+le,Te+i+le,qt,Be(1,9)+Zt,yt(Gt(i)+Ut+l,Gt(i)+oe),Jt(i),Qt,yt(tl,`tables: ${l})`+Oe,Bt),al),F(ae+i+le,ae+i+le,le,Be(1,12),t,t,t,ll,al);const G=I(h+he,vt("tableId?: TId","rowId: Id","cellId?: CId",j+ue+N,zt),Ze(Y+h),`<TId extends ${a}, CId extends ${o}<TId>>`),z=I(p+he,vt("tableId?: TId","rowId: Id",j+ue+N,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${G}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,el,zt),Ze(Y+p),`<TId extends ${a}>`),W=I(c+he,vt("tableId?: TId",j+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+c),`<TId extends ${a}>`),B=I("Sorted"+c+he,vt("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",j+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+"sorted "+c),`<TId extends ${a}>`),U=I(i+he,vt(j+ue+N,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${W}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,el,zt),Ze(We(1,1)));s(1,D,U,W,B,z,G),Z(i+ol,"{"+j+", tableComponents, getTableComponentProps"+Yt+"}: "+U,[re+`(${M}(${j}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+A+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${de}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Wt,"/>;","}), separator)"],Be(1,13)+te),R(((e,l,a)=>{const[n,o,d,r,I]=_(S,e);s(null,E,n,o,d,r,I),F(l+c,c,n,Ye(e)+te,t,a);const i=F(l+b,b,$,Ue(p,Ke(e))+te,t,a),u=F(l+C,C,$,Ue(p,Ke(e),1)+te,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(l+p,p,d,et(e)+te,nl,yt(a,Kt));const m=F(l+g,g,I+Ve,Ue(h,Xe(e))+te,nl,yt(a,Kt));F(Te+l+c+le,Te+c+le,qt,Ye(e,9)+Zt,yt(Gt(c)+Ut+o,Gt(c)+oe),yt(a,Jt(c)),Qt,yt(tl,`table: ${o})`+Oe,Bt),al),F(ae+l+c+le,ae+c+le,le,Ye(e,12),t,a,t,ll,al),F(Te+l+p+le,Te+p+le,qt,et(e,9)+Zt,yt(nl,Gt(p)+Ut+r,Gt(p)+oe),yt(a,Kt,Jt(p)),Qt,yt(tl,`row: ${r})`+Oe,Bt),al),F("Add"+l+p+le,"Add"+p+le,qt,et(e,10)+Zt,yt(Gt(p)+Ut+r,Gt(p)+oe),yt(a,Jt(p)),Qt,"then?: ("+yt(nl+pe,"store: Store","row: "+r+")"+Oe,"then"+oe)+", reuseRowIds?: boolean",al+", reuseRowIds"),F(Te+l+Ce+p+le,Te+Ce+p+le,qt,et(e,11)+Zt,yt(nl,Gt(Ce+p)+Ut+r,Gt(Ce+p)+oe),yt(a,Kt,Jt(Ce+p)),Qt,yt(tl,`partialRow: ${r})`+Oe,Bt),al),F(ae+l+p+le,ae+p+le,le,et(e,12),nl,yt(a,Kt),t,ll,al);const w=Z(l+p+ol,"{rowId, "+j+", cellComponents, getCellComponentProps"+Yt+`}: ${z}<'${e}'>`,[re+`(${m}(rowId, ${j}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+O+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${de}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,Xt,"cellId={cellId}",J,Wt,"/>;","})"+Yt+", rowId)"],et(e,13)+te);Z(l+"Sorted"+c+ol,"{cellId, descending, offset, limit, ...props}: "+B+`<'${e}'>`,P+"(props, "+u+`(cellId, descending, offset, limit, props.${j}), ${a}, ${w});`,Ye(e,13)+", sorted"+te),Z(l+c+ol,`props: ${W}<'${e}'>`,P+"(props, "+i+`(props.${j}), ${a}, ${w});`,Ye(e,13)+te),k(e,((n,o,d,r,I)=>{const $="Map"+mt(o,1);s(0,E,$),s(1,E,$);const c=F(l+I+h,h,o+(L(d)?pe:t),tt(e,n)+te,nl,yt(a,Kt,r));F(Te+l+I+h+le,Te+h+le,qt,tt(e,n,9)+Zt,yt(nl,Gt(h)+Ut+o+" | "+$,Gt(h)+oe),yt(a,Kt,r,Jt(h)),Qt,yt(tl,`cell: ${o} | ${$})`+Oe,Bt),al),F(ae+l+I+h+le,ae+h+le,le,tt(e,n,12),yt(nl,"forceDel?: boolean"),yt(a,Kt,r,"forceDel"),t,ll,al),Z(l+I+h+ol,`{rowId, ${j}, debugIds}: `+G+`<'${e}', '${n}'>`,[re+`('' + ${c}(rowId, `+j+`) ?? '', undefined, debugIds, ${r})`],tt(e,n,13)+te)}))}));const H=ht(R((e=>_(S,e)?.[4]??t))," | ");F(i+r,i+r,De,Be(1,8)+" changes",dl(d),rl()),F(u+r,u+r,De,qe(2,0,1),dl(m),rl()),F(c+r,c+r,De,qe(3,0),dl(w,`tableId: ${a} | null`),rl("tableId")),F(b+r,b+r,De,qe(4,3,1),dl(f,`tableId: ${a} | null`),rl("tableId")),F(C+r,C+r,De,qe(13,3,1),dl(T,`tableId: ${a} | null`,"cellId: "+H+pe,"descending: boolean","offset: number","limit: number"+pe),rl("tableId","cellId","descending","offset","limit")),F(p+r,p+r,De,qe(5,3),dl(v,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(g+r,g+r,De,qe(6,5,1),dl(V,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(h+r,h+r,De,qe(7,5),dl(x,`tableId: ${a} | null`,Kt+": IdOrNull",`cellId: ${H} | null`),rl("tableId",Kt,"cellId"))}if(!At(l)){const[e,l,a,n,d,$]=o;s(null,E,...o),s(1,E,N);const c=y("getDefaultValueComponent","valueId: Id",ht(P(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+$e);F(w,w,e,Be(2,0)+te);const i=F(f,f,a+Ve,Ue(m,xe)+te);F(Te+w+le,Te+w+le,qt,Be(2,9)+Zt,yt(Gt(w)+Ut+l,Gt(w)+oe),Jt(w),Qt,yt(tl,`values: ${l})`+Oe,Bt),al),F(Te+Ce+w+le,Te+Ce+w+le,qt,Be(2,11)+Zt,yt(Gt(Ce+w)+Ut+l,Gt(Ce+w)+oe),Jt(Ce+w),Qt,yt(tl,`partialValues: ${l})`+Oe,Bt),al),F(ae+w+le,ae+w+le,le,Be(2,12),t,t,t,ll,al);const u=I(m+he,vt("valueId?: VId",j+ue+N,zt),Ze("a Value"),`<VId extends ${a}>`),p=I(w+he,vt(j+ue+N,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${u}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,el,zt),Ze(We(2,1)));s(1,D,p,u),Z(w+ol,"{"+j+", valueComponents, getValueComponentProps"+Yt+"}: "+p,[re+`(${i}(${j}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+c+"(valueId);","return <Value",`{...${de}(getValueComponentProps, valueId)}`,"key={valueId}",J,Wt,"/>;","}), separator)"],Be(2,13)+te),P(((e,l,a,n,o)=>{const d="Map"+mt(l,1);s(0,E,d),s(1,E,d);const r=F(o+m,m,l,lt(e)+te,t,n);F(Te+o+m+le,Te+m+le,qt,lt(e,9)+Zt,yt(Gt(m)+Ut+l+" | "+d,Gt(m)+oe),yt(n,Jt(m)),Qt,yt(tl,`value: ${l} | ${d})`+Oe,Bt),al),F(ae+o+m+le,ae+m+le,le,lt(e,12),t,n,t,ll,al),Z(o+m+ol,`{${j}, debugIds}: ${u}<'${e}'>`,[re+`('' + ${r}(`+j+`) ?? '', undefined, debugIds, ${n})`],lt(e,13)+te)})),F(w+r,w+r,De,Be(2,8)+" changes",dl(n),rl()),F(f+r,f+r,De,qe(10,0,1),dl(d),rl()),F(m+r,m+r,De,qe(11,0),dl($,`valueId: ${a} | null`),rl("valueId"))}return Z(ge,`{${j}, ${j}ById, children}: `+K+" & {children: React.ReactNode}",["{",_t,"return (","<Context."+ge,"value={useMemo(",`() => [${j} ?? contextValue[0], {...contextValue[1], ...${j}ById}],`,`[${j}, ${j}ById, contextValue],`,")}>","{children}",`</Context.${ge}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...v(0),...V(),...Q(0)),d(...v(1),...x(),...Q(1))]},Il=(e,l,a)=>{if(At(e)&&At(l))return[t,t,t,t];const[n,o,d,r]=Mt(e,l,a);return[n,o,...sl(e,l,a,d,r)]},$l={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},cl=Et((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!At(t)||y(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(y(a,(t=>y(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=q(n,a,(()=>[J(o),U(),[0],0])),[r,s,[I]]=d,$=q(s,o,(()=>0))+1;return $>I&&(d[2]=[$,o]),Q(s,o,$),d[3]++,r==J(o)})))))return t[l]={},B(n,(([e,,[,n],r],s)=>{t[l][s]={[o]:e,...r==x(a)?{[d]:n}:{}}})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return At(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>Il(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(await import("prettier")).format}catch(e){l=e=>e}return V(a(e),((e,a)=>bt(l(e,{...$l,filepath:"_."+t[a]}))))};return kt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:x(e.getValueIds()),jsonLength:Ct(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{cl as createTools};
package/lib/tools.js.gz CHANGED
Binary file
@@ -1221,16 +1221,16 @@ export type StoreListenerStats = {
1221
1221
  export interface Store {
1222
1222
  //
1223
1223
  /**
1224
- * The getTables method returns a Tables object containing the entire data of
1225
- * the Store.
1224
+ * The getTables method returns a Tables object containing the entire tabular
1225
+ * data of the Store.
1226
1226
  *
1227
1227
  * Note that this returns a copy of, rather than a reference to the underlying
1228
1228
  * data, so changes made to the returned object are not made to the Store
1229
1229
  * itself.
1230
1230
  *
1231
- * @returns A Tables object containing the entire data of the Store.
1231
+ * @returns A Tables object containing the tabular data of the Store.
1232
1232
  * @example
1233
- * This example retrieves the data in a Store.
1233
+ * This example retrieves the tabular data in a Store.
1234
1234
  *
1235
1235
  * ```js
1236
1236
  * const store = createStore().setTables({
@@ -1569,9 +1569,9 @@ export interface Store {
1569
1569
  * data, so changes made to the returned object are not made to the Store
1570
1570
  * itself.
1571
1571
  *
1572
- * @returns An object containing the entire data of the Values.
1572
+ * @returns An object containing the set of keyed Values in the Store.
1573
1573
  * @example
1574
- * This example retrieves the keyed Values data in a Store.
1574
+ * This example retrieves the set of keyed Values in the Store.
1575
1575
  *
1576
1576
  * ```js
1577
1577
  * const store = createStore().setValues({open: true, employees: 3});
@@ -1579,7 +1579,7 @@ export interface Store {
1579
1579
  * // -> {open: true, employees: 3}
1580
1580
  * ```
1581
1581
  * @example
1582
- * This example retrieves a Values from a Store that has none, returning an
1582
+ * This example retrieves Values from a Store that has none, returning an
1583
1583
  * empty object.
1584
1584
  *
1585
1585
  * ```js
@@ -1964,7 +1964,8 @@ export interface Store {
1964
1964
  getSchemaJson(): Json;
1965
1965
 
1966
1966
  /**
1967
- * The setTables method takes an object and sets the entire data of the Store.
1967
+ * The setTables method takes an object and sets the entire tabular data of
1968
+ * the Store.
1968
1969
  *
1969
1970
  * This method will cause listeners to be called for any Table, Row, Cell, or
1970
1971
  * Id changes resulting from it.
@@ -1982,7 +1983,7 @@ export interface Store {
1982
1983
  *
1983
1984
  * @param tables The data of the Store to be set.
1984
1985
  * @example
1985
- * This example sets the data of a Store.
1986
+ * This example sets the tabular data of a Store.
1986
1987
  *
1987
1988
  * ```js
1988
1989
  * const store = createStore().setTables({
@@ -1993,8 +1994,8 @@ export interface Store {
1993
1994
  * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
1994
1995
  * ```
1995
1996
  * @example
1996
- * This example attempts to set the data of an existing Store with partly
1997
- * invalid, and then completely invalid, Tables objects.
1997
+ * This example attempts to set the tabular data of an existing Store with
1998
+ * partly invalid, and then completely invalid, Tables objects.
1998
1999
  *
1999
2000
  * ```js
2000
2001
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
@@ -2131,8 +2132,17 @@ export interface Store {
2131
2132
  * Row is added to the Table. However it is likely to be a string
2132
2133
  * representation of an increasing integer.
2133
2134
  *
2135
+ * The `reuseRowIds` parameter defaults to `true`, which means that if you
2136
+ * delete a Row and then add another, the Id will be re-used - unless you
2137
+ * delete the entire Table, in which case all Row Ids will reset. Otherwise,
2138
+ * if you specify `reuseRowIds` to be `false`, then the Id will be a
2139
+ * monotonically increasing string representation of an increasing integer,
2140
+ * regardless of any you may have previously deleted.
2141
+ *
2134
2142
  * @param tableId The Id of the Table in the Store.
2135
2143
  * @param row The data of a single Row to be added.
2144
+ * @param reuseRowIds Whether Ids should be recycled from previously deleted
2145
+ * Row objects, defaulting to `true`.
2136
2146
  * @returns A reference to the Store.
2137
2147
  * @example
2138
2148
  * This example adds a single Row.
@@ -2163,7 +2173,7 @@ export interface Store {
2163
2173
  * ```
2164
2174
  * @category Setter
2165
2175
  */
2166
- addRow(tableId: Id, row: Row): Id | undefined;
2176
+ addRow(tableId: Id, row: Row, reuseRowIds?: boolean): Id | undefined;
2167
2177
 
2168
2178
  /**
2169
2179
  * The setPartialRow method takes an object and sets partial data of a single
@@ -1563,6 +1563,13 @@ export function useSetRowCallback<Parameter>(
1563
1563
  * hook's `storeOrStoreId` parameter) is always automatically used as a hook
1564
1564
  * dependency for the callback.
1565
1565
  *
1566
+ * The `reuseRowIds` parameter defaults to `true`, which means that if you
1567
+ * delete a Row and then add another, the Id will be re-used - unless you delete
1568
+ * the entire Table, in which case all Row Ids will reset. Otherwise, if you
1569
+ * specify `reuseRowIds` to be `false`, then the Id will be a monotonically
1570
+ * increasing string representation of an increasing integer, regardless of any
1571
+ * you may have previously deleted.
1572
+ *
1566
1573
  * @param tableId The Id of the Table in the Store.
1567
1574
  * @param getRow A function which returns the Row object that will be used to
1568
1575
  * update the Store, based on the parameter the callback will receive (and which
@@ -1578,6 +1585,9 @@ export function useSetRowCallback<Parameter>(
1578
1585
  * @param thenDeps An optional array of dependencies for the `then` function,
1579
1586
  * which, if any change, result in the regeneration of the callback. This
1580
1587
  * parameter defaults to an empty array.
1588
+ * @param reuseRowIds Whether Ids should be recycled from previously deleted Row
1589
+ * objects, defaulting to `true`.
1590
+ *
1581
1591
  * @returns A parameterized callback for subsequent use.
1582
1592
  * @example
1583
1593
  * This example uses the useAddRowCallback hook to create an event handler which
@@ -1622,6 +1632,7 @@ export function useAddRowCallback<Parameter>(
1622
1632
  storeOrStoreId?: StoreOrStoreId,
1623
1633
  then?: (rowId: Id | undefined, store: Store, row: Row) => void,
1624
1634
  thenDeps?: React.DependencyList,
1635
+ reuseRowIds?: boolean,
1625
1636
  ): ParameterizedCallback<Parameter>;
1626
1637
 
1627
1638
  /**
@@ -1811,8 +1811,8 @@ export type StoreListenerStats = {
1811
1811
  */
1812
1812
  export interface Store<in out Schemas extends OptionalSchemas> {
1813
1813
  /**
1814
- * The getTables method returns a Tables object containing the entire data of
1815
- * the Store.
1814
+ * The getTables method returns a Tables object containing the entire tabular
1815
+ * data of the Store.
1816
1816
  *
1817
1817
  * This has schema-based typing. The following is a simplified representation:
1818
1818
  *
@@ -1824,9 +1824,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
1824
1824
  * data, so changes made to the returned object are not made to the Store
1825
1825
  * itself.
1826
1826
  *
1827
- * @returns A Tables object containing the entire data of the Store.
1827
+ * @returns A Tables object containing the tabular data of the Store.
1828
1828
  * @example
1829
- * This example retrieves the data in a Store.
1829
+ * This example retrieves the tabular data in a Store.
1830
1830
  *
1831
1831
  * ```js
1832
1832
  * const store = createStore().setTables({
@@ -2234,9 +2234,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2234
2234
  * data, so changes made to the returned object are not made to the Store
2235
2235
  * itself.
2236
2236
  *
2237
- * @returns An object containing the entire data of the Values.
2237
+ * @returns An object containing the set of keyed Values in the Store.
2238
2238
  * @example
2239
- * This example retrieves the keyed Values data in a Store.
2239
+ * This example retrieves the set of keyed Values in the Store.
2240
2240
  *
2241
2241
  * ```js
2242
2242
  * const store = createStore().setValues({open: true, employees: 3});
@@ -2244,7 +2244,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2244
2244
  * // -> {open: true, employees: 3}
2245
2245
  * ```
2246
2246
  * @example
2247
- * This example retrieves a Values from a Store that has none, returning an
2247
+ * This example retrieves Values from a Store that has none, returning an
2248
2248
  * empty object.
2249
2249
  *
2250
2250
  * ```js
@@ -2671,7 +2671,8 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2671
2671
  getSchemaJson(): Json;
2672
2672
 
2673
2673
  /**
2674
- * The setTables method takes an object and sets the entire data of the Store.
2674
+ * The setTables method takes an object and sets the entire tabular data of
2675
+ * the Store.
2675
2676
  *
2676
2677
  * This has schema-based typing. The following is a simplified representation:
2677
2678
  *
@@ -2695,7 +2696,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2695
2696
  *
2696
2697
  * @param tables The data of the Store to be set.
2697
2698
  * @example
2698
- * This example sets the data of a Store.
2699
+ * This example sets the tabular data of a Store.
2699
2700
  *
2700
2701
  * ```js
2701
2702
  * const store = createStore().setTables({
@@ -2706,8 +2707,8 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2706
2707
  * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
2707
2708
  * ```
2708
2709
  * @example
2709
- * This example attempts to set the data of an existing Store with partly
2710
- * invalid, and then completely invalid, Tables objects.
2710
+ * This example attempts to set the tabular data of an existing Store with
2711
+ * partly invalid, and then completely invalid, Tables objects.
2711
2712
  *
2712
2713
  * ```js
2713
2714
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
@@ -2851,7 +2852,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2851
2852
  * This has schema-based typing. The following is a simplified representation:
2852
2853
  *
2853
2854
  * ```ts override
2854
- * addRow(tableId: Id, row: Row): Id | undefined;
2855
+ * addRow(tableId: Id, row: Row, reuseRowIds?: boolean): Id | undefined;
2855
2856
  * ```
2856
2857
  *
2857
2858
  * This method will cause listeners to be called for any Table, Row, Cell, or
@@ -2869,8 +2870,17 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2869
2870
  * Row is added to the Table. However it is likely to be a string
2870
2871
  * representation of an increasing integer.
2871
2872
  *
2873
+ * The `reuseRowIds` parameter defaults to `true`, which means that if you
2874
+ * delete a Row and then add another, the Id will be re-used - unless you
2875
+ * delete the entire Table, in which case all Row Ids will reset. Otherwise,
2876
+ * if you specify `reuseRowIds` to be `false`, then the Id will be a
2877
+ * monotonically increasing string representation of an increasing integer,
2878
+ * regardless of any you may have previously deleted.
2879
+ *
2872
2880
  * @param tableId The Id of the Table in the Store.
2873
2881
  * @param row The data of a single Row to be added.
2882
+ * @param reuseRowIds Whether Ids should be recycled from previously deleted
2883
+ * Row objects, defaulting to `true`.
2874
2884
  * @returns A reference to the Store.
2875
2885
  * @example
2876
2886
  * This example adds a single Row.
@@ -2904,6 +2914,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
2904
2914
  addRow<TableId extends TableIdFromSchema<Schemas[0]>>(
2905
2915
  tableId: TableId,
2906
2916
  row: Row<Schemas[0], TableId, true>,
2917
+ reuseRowIds?: boolean,
2907
2918
  ): Id | undefined;
2908
2919
 
2909
2920
  /**
@@ -1809,6 +1809,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
1809
1809
  * storeOrStoreId?: StoreOrStoreId,
1810
1810
  * then?: (rowId: Id | undefined, store: Store, row: Row) => void,
1811
1811
  * thenDeps?: React.DependencyList,
1812
+ * reuseRowIds?: boolean,
1812
1813
  * ): ParameterizedCallback<Parameter>;
1813
1814
  * ```
1814
1815
  *
@@ -1833,6 +1834,13 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
1833
1834
  * hook's `storeOrStoreId` parameter) is always automatically used as a hook
1834
1835
  * dependency for the callback.
1835
1836
  *
1837
+ * The `reuseRowIds` parameter defaults to `true`, which means that if you
1838
+ * delete a Row and then add another, the Id will be re-used - unless you delete
1839
+ * the entire Table, in which case all Row Ids will reset. Otherwise, if you
1840
+ * specify `reuseRowIds` to be `false`, then the Id will be a monotonically
1841
+ * increasing string representation of an increasing integer, regardless of any
1842
+ * you may have previously deleted.
1843
+ *
1836
1844
  * @param tableId The Id of the Table in the Store.
1837
1845
  * @param getRow A function which returns the Row object that will be used to
1838
1846
  * update the Store, based on the parameter the callback will receive (and which
@@ -1848,6 +1856,9 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
1848
1856
  * @param thenDeps An optional array of dependencies for the `then` function,
1849
1857
  * which, if any change, result in the regeneration of the callback. This
1850
1858
  * parameter defaults to an empty array.
1859
+ * @param reuseRowIds Whether Ids should be recycled from previously deleted Row
1860
+ * objects, defaulting to `true`.
1861
+ *
1851
1862
  * @returns A parameterized callback for subsequent use.
1852
1863
  * @example
1853
1864
  * This example uses the useAddRowCallback hook to create an event handler which
@@ -1896,6 +1907,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
1896
1907
  storeOrStoreId?: StoreOrStoreId<Schemas>,
1897
1908
  then?: (rowId: Id | undefined, store: Store<Schemas>, row: AddRow) => void,
1898
1909
  thenDeps?: React.DependencyList,
1910
+ reuseRowIds?: boolean,
1899
1911
  ) => ParameterizedCallback<Parameter>;
1900
1912
 
1901
1913
  /**
package/lib/ui-react.js CHANGED
@@ -1 +1 @@
1
- import e,{useContext as o}from"react";const t=e=>typeof e,s=t(""),d=(e,o)=>e.map(o),r=e=>null==e,n=(e,o,t)=>r(e)?t?.():o(e),l=e=>t(e)==s,I=()=>{},{createContext:u,useContext:a}=e,i=u([]),c=(e,o)=>{const t=a(i);return r(e)?t[o]:l(e)?((e,o)=>n(e,(e=>e[o])))(t[o+1],e):e},p=(e,o)=>{const t=c(e,o);return r(e)||l(e)?t:e},b=e=>c(e,0),g=e=>c(e,2),w=e=>c(e,4),R=e=>c(e,6),C=e=>c(e,8),m=e=>c(e,10),k=e=>p(e,0),y=e=>p(e,2),h=e=>p(e,4),v=e=>p(e,6),T=e=>p(e,8),q=e=>p(e,10),{useCallback:P,useEffect:x,useMemo:S,useRef:V,useState:f}=e,B=(e,o,t=[])=>{const s=S((()=>o(e)),[e,...t]);return x((()=>()=>s.destroy()),[s]),s},L=(e,o,t,s=[],d)=>{const[,n]=f(),l=P((()=>o?.["get"+e]?.(...s)??t),[o,...s]),[I]=f(l),u=V(I);return S((()=>u.current=l()),[l]),M(e,o,((...e)=>{u.current=r(d)?l():e[d],n([])}),[],s),u.current},M=(e,o,t,s=[],d=[],...r)=>x((()=>{const s=o?.["add"+e+"Listener"]?.(...d,t,...r);return()=>o?.delListener(s)}),[o,...d,...s,...r]),A=(e,o,t,s=[],d=I,r=[],...l)=>{const u=k(e);return P((e=>n(u,(s=>n(t(e,s),(e=>d(s["set"+o](...l,e),e)))))),[u,o,...s,...r,...l])},E=(e,o,t=I,s=[],...d)=>{const r=k(e);return P((()=>t(r?.["del"+o](...d))),[r,o,...s,...d])},F=(e,o,t)=>{const s=q(e);return P((()=>s?.[o](t)),[s,o,t])},j=(e,o=[])=>S(e,o),z=e=>L("Tables",k(e),{}),D=e=>L("TableIds",k(e),[],[]),G=(e,o)=>L("Table",k(o),{},[e]),H=(e,o)=>L("RowIds",k(o),[],[e]),J=(e,o,t,s=0,d,r)=>L("SortedRowIds",k(r),[],[e,o,t,s,d],6),K=(e,o,t)=>L("Row",k(t),{},[e,o]),N=(e,o,t)=>L("CellIds",k(t),[],[e,o]),O=(e,o,t,s)=>L("Cell",k(s),void 0,[e,o,t],4),Q=e=>L("Values",k(e),{}),U=e=>L("ValueIds",k(e),[],[]),W=(e,o)=>L("Value",k(o),void 0,[e]),X=(e,o,t,s,d)=>A(t,"Tables",e,o,s,d),Y=(e,o,t,s,d,r)=>A(s,"Table",o,t,d,r,e),Z=(e,o,t,s,d,r,n)=>A(d,"Row",t,s,r,n,e,o),$=(e,o,t=[],s,d=I,r=[])=>{const l=k(s);return P((t=>n(l,(s=>n(o(t,s),(o=>d(s.addRow(e,o),s,o)))))),[l,e,...t,...r])},_=(e,o,t,s,d,r,n)=>A(d,"PartialRow",t,s,r,n,e,o),ee=(e,o,t,s,d,r,n,l)=>A(r,"Cell",s,d,n,l,e,o,t),oe=(e,o,t,s,d)=>A(t,"Values",e,o,s,d),te=(e,o,t,s,d)=>A(t,"PartialValues",e,o,s,d),se=(e,o,t,s,d,r)=>A(s,"Value",o,t,d,r,e),de=(e,o,t)=>E(e,"Tables",o,t),re=(e,o,t,s)=>E(o,"Table",t,s,e),ne=(e,o,t,s,d)=>E(t,"Row",s,d,e,o),le=(e,o,t,s,d,r,n)=>E(d,"Cell",r,n,e,o,t,s),Ie=(e,o,t)=>E(e,"Values",o,t),ue=(e,o,t,s)=>E(o,"Value",t,s,e),ae=(e,o,t,s)=>M("Tables",k(s),e,o,[],t),ie=(e,o,t,s)=>M("TableIds",k(s),e,o,[],t),ce=(e,o,t,s,d)=>M("Table",k(d),o,t,[e],s),pe=(e,o,t,s,d)=>M("RowIds",k(d),o,t,[e],s),be=(e,o,t,s,d,r,n,l,I)=>M("SortedRowIds",k(I),r,n,[e,o,t,s,d],l),ge=(e,o,t,s,d,r)=>M("Row",k(r),t,s,[e,o],d),we=(e,o,t,s,d,r)=>M("CellIds",k(r),t,s,[e,o],d),Re=(e,o,t,s,d,r,n)=>M("Cell",k(n),s,d,[e,o,t],r),Ce=(e,o,t,s)=>M("Values",k(s),e,o,[],t),me=(e,o,t,s)=>M("ValueIds",k(s),e,o,[],t),ke=(e,o,t,s,d)=>M("Value",k(d),o,t,[e],s),ye=(e,o,t)=>B(e,o,t),he=(e,o)=>L("Metric",y(o),void 0,[e]),ve=(e,o,t,s)=>M("Metric",y(s),o,t,[e]),Te=(e,o,t)=>B(e,o,t),qe=(e,o)=>L("SliceIds",h(o),[],[e]),Pe=(e,o,t)=>L("SliceRowIds",h(t),[],[e,o]),xe=(e,o,t,s)=>M("SliceIds",h(s),o,t,[e]),Se=(e,o,t,s,d)=>M("SliceRowIds",h(d),t,s,[e,o]),Ve=(e,o,t)=>B(e,o,t),fe=(e,o,t)=>L("RemoteRowId",v(t),void 0,[e,o]),Be=(e,o,t)=>L("LocalRowIds",v(t),[],[e,o]),Le=(e,o,t)=>L("LinkedRowIds",v(t),[],[e,o]),Me=(e,o,t,s,d)=>M("RemoteRowId",v(d),t,s,[e,o]),Ae=(e,o,t,s,d)=>M("LocalRowIds",v(d),t,s,[e,o]),Ee=(e,o,t,s,d)=>M("LinkedRowIds",v(d),t,s,[e,o]),Fe=(e,o,t)=>B(e,o,t),je=(e,o)=>L("ResultTable",T(o),{},[e]),ze=(e,o)=>L("ResultRowIds",T(o),[],[e]),De=(e,o,t,s=0,d,r)=>L("ResultSortedRowIds",T(r),[],[e,o,t,s,d],6),Ge=(e,o,t)=>L("ResultRow",T(t),{},[e,o]),He=(e,o,t)=>L("ResultCellIds",T(t),[],[e,o]),Je=(e,o,t,s)=>L("ResultCell",T(s),void 0,[e,o,t]),Ke=(e,o,t,s)=>M("ResultTable",T(s),o,t,[e]),Ne=(e,o,t,s)=>M("ResultRowIds",T(s),o,t,[e]),Oe=(e,o,t,s,d,r,n,l)=>M("ResultSortedRowIds",T(l),r,n,[e,o,t,s,d]),Qe=(e,o,t,s,d)=>M("ResultRow",T(d),t,s,[e,o]),Ue=(e,o,t,s,d)=>M("ResultCellIds",T(d),t,s,[e,o]),We=(e,o,t,s,d,r)=>M("ResultCell",T(r),s,d,[e,o,t]),Xe=(e,o,t)=>B(e,o,t),Ye=e=>L("CheckpointIds",q(e),[[],void 0,[]]),Ze=(e,o)=>L("Checkpoint",q(o),void 0,[e]),$e=(e=I,o=[],t,s=I,d=[])=>{const r=q(t);return P((o=>n(r,(t=>{const d=e(o);s(t.addCheckpoint(d),t,d)}))),[r,...o,...d])},_e=e=>F(e,"goBackward"),eo=e=>F(e,"goForward"),oo=(e,o=[],t,s=I,d=[])=>{const r=q(t);return P((o=>n(r,(t=>n(e(o),(e=>s(t.goTo(e),e)))))),[r,...o,...d])},to=e=>{const o=q(e),[t,s]=Ye(o);return[(d=t,!(0==(e=>e.length)(d))),_e(o),s,n(s,(e=>o?.getCheckpoint(e)))??""];var d},so=e=>{const o=q(e),[,,[t]]=Ye(o);return[!r(t),eo(o),t,n(t,(e=>o?.getCheckpoint(e)))??""]},ro=(e,o,t)=>M("CheckpointIds",q(t),e,o),no=(e,o,t,s)=>M("Checkpoint",q(s),o,t,[e]),lo=(e,o,t=[],s,d=[])=>{const[,r]=f(),n=S((()=>o(e)),[e,...t]);return x((()=>((async()=>{await(s?.(n)),r(1)})(),()=>{n.destroy()})),[n,...d]),n},{createElement:Io,useMemo:uo}=e,ao=({tableId:e,store:o,rowComponent:t=mo,getRowComponentProps:s,separator:r,debugIds:n},l)=>Ro(d(l,(d=>Io(t,{...go(s,d),key:d,tableId:e,rowId:d,store:o,debugIds:n}))),r,n,e),io=({queryId:e,queries:o,resultRowComponent:t=Lo,getResultRowComponentProps:s,separator:r,debugIds:n},l)=>Ro(d(l,(d=>Io(t,{...go(s,d),key:d,queryId:e,rowId:d,queries:o,debugIds:n}))),r,n,e),co=e=>{const o=v(e);return[o,o?.getStore()]},po=({relationshipId:e,relationships:o,rowComponent:t=mo,getRowComponentProps:s,separator:r,debugIds:n},l,I)=>{const[u,a]=co(o),i=u?.getLocalTableId(e),c=l(e,I,u);return Ro(d(c,(e=>Io(t,{...go(s,e),key:e,tableId:i,rowId:e,store:a,debugIds:n}))),r,n,I)},bo=e=>({checkpoints:o,checkpointComponent:t=Eo,getCheckpointComponentProps:s,separator:r,debugIds:n})=>{const l=q(o);return Ro(d(e(Ye(l)),(e=>Io(t,{...go(s,e),key:e,checkpoints:l,checkpointId:e,debugIds:n}))),r)},go=(e,o)=>r(e)?{}:e(o),wo=({store:e,storesById:t,metrics:s,metricsById:d,indexes:r,indexesById:n,relationships:l,relationshipsById:I,queries:u,queriesById:a,checkpoints:c,checkpointsById:p,children:b})=>{const g=o(i);return Io(i.Provider,{value:uo((()=>[e??g[0],{...g[1],...t},s??g[2],{...g[3],...d},r??g[4],{...g[5],...n},l??g[6],{...g[7],...I},u??g[8],{...g[9],...a},c??g[10],{...g[11],...p}]),[e,t,s,d,r,n,l,I,u,a,c,p,g])},b)},Ro=(e,o,t,s)=>{const n=r(o)||!Array.isArray(e)?e:d(e,((e,t)=>t>0?[o,e]:e));return t?[s,":{",n,"}"]:n},Co=({tableId:e,rowId:o,cellId:t,store:s,debugIds:d})=>Ro(""+(O(e,o,t,s)??""),void 0,d,t),mo=({tableId:e,rowId:o,store:t,cellComponent:s=Co,getCellComponentProps:r,separator:n,debugIds:l})=>Ro(d(N(e,o,t),(d=>Io(s,{...go(r,d),key:d,tableId:e,rowId:o,cellId:d,store:t,debugIds:l}))),n,l,o),ko=e=>ao(e,H(e.tableId,e.store)),yo=({cellId:e,descending:o,offset:t,limit:s,...d})=>ao(d,J(d.tableId,e,o,t,s,d.store)),ho=({store:e,tableComponent:o=ko,getTableComponentProps:t,separator:s,debugIds:r})=>Ro(d(D(e),(s=>Io(o,{...go(t,s),key:s,tableId:s,store:e,debugIds:r}))),s),vo=({valueId:e,store:o,debugIds:t})=>Ro(""+(W(e,o)??""),void 0,t,e),To=({store:e,valueComponent:o=vo,getValueComponentProps:t,separator:s,debugIds:r})=>Ro(d(U(e),(s=>Io(o,{...go(t,s),key:s,valueId:s,store:e,debugIds:r}))),s),qo=({metricId:e,metrics:o,debugIds:t})=>Ro(he(e,o)??"",void 0,t,e),Po=({indexId:e,sliceId:o,indexes:t,rowComponent:s=mo,getRowComponentProps:r,separator:n,debugIds:l})=>{const I=h(t),u=I?.getStore(),a=I?.getTableId(e),i=Pe(e,o,I);return Ro(d(i,(e=>Io(s,{...go(r,e),key:e,tableId:a,rowId:e,store:u,debugIds:l}))),n,l,o)},xo=({indexId:e,indexes:o,sliceComponent:t=Po,getSliceComponentProps:s,separator:r,debugIds:n})=>Ro(d(qe(e,o),(d=>Io(t,{...go(s,d),key:d,indexId:e,sliceId:d,indexes:o,debugIds:n}))),r,n,e),So=({relationshipId:e,localRowId:o,relationships:t,rowComponent:s=mo,getRowComponentProps:d,debugIds:n})=>{const[l,I]=co(t),u=l?.getRemoteTableId(e),a=fe(e,o,l);return Ro(r(u)||r(a)?null:Io(s,{...go(d,a),key:a,tableId:u,rowId:a,store:I,debugIds:n}),void 0,n,o)},Vo=e=>po(e,Be,e.remoteRowId),fo=e=>po(e,Le,e.firstRowId),Bo=({queryId:e,rowId:o,cellId:t,queries:s,debugIds:d})=>Ro(""+(Je(e,o,t,s)??""),void 0,d,t),Lo=({queryId:e,rowId:o,queries:t,resultCellComponent:s=Bo,getResultCellComponentProps:r,separator:n,debugIds:l})=>Ro(d(He(e,o,t),(d=>Io(s,{...go(r,d),key:d,queryId:e,rowId:o,cellId:d,queries:t,debugIds:l}))),n,l,o),Mo=e=>io(e,ze(e.queryId,e.queries)),Ao=({cellId:e,descending:o,offset:t,limit:s,...d})=>io(d,De(d.queryId,e,o,t,s,d.queries)),Eo=({checkpoints:e,checkpointId:o,debugIds:t})=>Ro(Ze(o,e)??"",void 0,t,o),Fo=bo((e=>e[0])),jo=bo((e=>r(e[1])?[]:[e[1]])),zo=bo((e=>e[2]));export{Fo as BackwardCheckpointsView,Co as CellView,Eo as CheckpointView,jo as CurrentCheckpointView,zo as ForwardCheckpointsView,xo as IndexView,fo as LinkedRowsView,Vo as LocalRowsView,qo as MetricView,wo as Provider,So as RemoteRowView,Bo as ResultCellView,Lo as ResultRowView,Ao as ResultSortedTableView,Mo as ResultTableView,mo as RowView,Po as SliceView,yo as SortedTableView,ko as TableView,ho as TablesView,vo as ValueView,To as ValuesView,ao as tableView,$ as useAddRowCallback,O as useCell,N as useCellIds,we as useCellIdsListener,Re as useCellListener,Ze as useCheckpoint,Ye as useCheckpointIds,ro as useCheckpointIdsListener,no as useCheckpointListener,m as useCheckpoints,Xe as useCreateCheckpoints,Te as useCreateIndexes,ye as useCreateMetrics,lo as useCreatePersister,Fe as useCreateQueries,Ve as useCreateRelationships,j as useCreateStore,le as useDelCellCallback,ne as useDelRowCallback,re as useDelTableCallback,de as useDelTablesCallback,ue as useDelValueCallback,Ie as useDelValuesCallback,_e as useGoBackwardCallback,eo as useGoForwardCallback,oo as useGoToCallback,w as useIndexes,Le as useLinkedRowIds,Ee as useLinkedRowIdsListener,Be as useLocalRowIds,Ae as useLocalRowIdsListener,he as useMetric,ve as useMetricListener,g as useMetrics,C as useQueries,so as useRedoInformation,R as useRelationships,fe as useRemoteRowId,Me as useRemoteRowIdListener,Je as useResultCell,He as useResultCellIds,Ue as useResultCellIdsListener,We as useResultCellListener,Ge as useResultRow,ze as useResultRowIds,Ne as useResultRowIdsListener,Qe as useResultRowListener,De as useResultSortedRowIds,Oe as useResultSortedRowIdsListener,je as useResultTable,Ke as useResultTableListener,K as useRow,H as useRowIds,pe as useRowIdsListener,ge as useRowListener,ee as useSetCellCallback,$e as useSetCheckpointCallback,_ as useSetPartialRowCallback,te as useSetPartialValuesCallback,Z as useSetRowCallback,Y as useSetTableCallback,X as useSetTablesCallback,se as useSetValueCallback,oe as useSetValuesCallback,qe as useSliceIds,xe as useSliceIdsListener,Pe as useSliceRowIds,Se as useSliceRowIdsListener,J as useSortedRowIds,be as useSortedRowIdsListener,b as useStore,G as useTable,D as useTableIds,ie as useTableIdsListener,ce as useTableListener,z as useTables,ae as useTablesListener,to as useUndoInformation,W as useValue,U as useValueIds,me as useValueIdsListener,ke as useValueListener,Q as useValues,Ce as useValuesListener};
1
+ import e,{useContext as o}from"react";const t=e=>typeof e,s=t(""),d=(e,o)=>e.map(o),r=e=>null==e,n=(e,o,t)=>r(e)?t?.():o(e),l=e=>t(e)==s,I=()=>{},{createContext:u,useContext:a}=e,i=u([]),c=(e,o)=>{const t=a(i);return r(e)?t[o]:l(e)?((e,o)=>n(e,(e=>e[o])))(t[o+1],e):e},p=(e,o)=>{const t=c(e,o);return r(e)||l(e)?t:e},b=e=>c(e,0),g=e=>c(e,2),w=e=>c(e,4),R=e=>c(e,6),C=e=>c(e,8),m=e=>c(e,10),k=e=>p(e,0),y=e=>p(e,2),h=e=>p(e,4),v=e=>p(e,6),T=e=>p(e,8),q=e=>p(e,10),{useCallback:P,useEffect:x,useMemo:S,useRef:V,useState:f}=e,B=(e,o,t=[])=>{const s=S((()=>o(e)),[e,...t]);return x((()=>()=>s.destroy()),[s]),s},L=(e,o,t,s=[],d)=>{const[,n]=f(),l=P((()=>o?.["get"+e]?.(...s)??t),[o,...s]),[I]=f(l),u=V(I);return S((()=>u.current=l()),[l]),M(e,o,((...e)=>{u.current=r(d)?l():e[d],n([])}),[],s),u.current},M=(e,o,t,s=[],d=[],...r)=>x((()=>{const s=o?.["add"+e+"Listener"]?.(...d,t,...r);return()=>o?.delListener(s)}),[o,...d,...s,...r]),A=(e,o,t,s=[],d=I,r=[],...l)=>{const u=k(e);return P((e=>n(u,(s=>n(t(e,s),(e=>d(s["set"+o](...l,e),e)))))),[u,o,...s,...r,...l])},E=(e,o,t=I,s=[],...d)=>{const r=k(e);return P((()=>t(r?.["del"+o](...d))),[r,o,...s,...d])},F=(e,o,t)=>{const s=q(e);return P((()=>s?.[o](t)),[s,o,t])},j=(e,o=[])=>S(e,o),z=e=>L("Tables",k(e),{}),D=e=>L("TableIds",k(e),[],[]),G=(e,o)=>L("Table",k(o),{},[e]),H=(e,o)=>L("RowIds",k(o),[],[e]),J=(e,o,t,s=0,d,r)=>L("SortedRowIds",k(r),[],[e,o,t,s,d],6),K=(e,o,t)=>L("Row",k(t),{},[e,o]),N=(e,o,t)=>L("CellIds",k(t),[],[e,o]),O=(e,o,t,s)=>L("Cell",k(s),void 0,[e,o,t],4),Q=e=>L("Values",k(e),{}),U=e=>L("ValueIds",k(e),[],[]),W=(e,o)=>L("Value",k(o),void 0,[e]),X=(e,o,t,s,d)=>A(t,"Tables",e,o,s,d),Y=(e,o,t,s,d,r)=>A(s,"Table",o,t,d,r,e),Z=(e,o,t,s,d,r,n)=>A(d,"Row",t,s,r,n,e,o),$=(e,o,t=[],s,d=I,r=[],l=!0)=>{const u=k(s);return P((t=>n(u,(s=>n(o(t,s),(o=>d(s.addRow(e,o,l),s,o)))))),[u,e,...t,...r,l])},_=(e,o,t,s,d,r,n)=>A(d,"PartialRow",t,s,r,n,e,o),ee=(e,o,t,s,d,r,n,l)=>A(r,"Cell",s,d,n,l,e,o,t),oe=(e,o,t,s,d)=>A(t,"Values",e,o,s,d),te=(e,o,t,s,d)=>A(t,"PartialValues",e,o,s,d),se=(e,o,t,s,d,r)=>A(s,"Value",o,t,d,r,e),de=(e,o,t)=>E(e,"Tables",o,t),re=(e,o,t,s)=>E(o,"Table",t,s,e),ne=(e,o,t,s,d)=>E(t,"Row",s,d,e,o),le=(e,o,t,s,d,r,n)=>E(d,"Cell",r,n,e,o,t,s),Ie=(e,o,t)=>E(e,"Values",o,t),ue=(e,o,t,s)=>E(o,"Value",t,s,e),ae=(e,o,t,s)=>M("Tables",k(s),e,o,[],t),ie=(e,o,t,s)=>M("TableIds",k(s),e,o,[],t),ce=(e,o,t,s,d)=>M("Table",k(d),o,t,[e],s),pe=(e,o,t,s,d)=>M("RowIds",k(d),o,t,[e],s),be=(e,o,t,s,d,r,n,l,I)=>M("SortedRowIds",k(I),r,n,[e,o,t,s,d],l),ge=(e,o,t,s,d,r)=>M("Row",k(r),t,s,[e,o],d),we=(e,o,t,s,d,r)=>M("CellIds",k(r),t,s,[e,o],d),Re=(e,o,t,s,d,r,n)=>M("Cell",k(n),s,d,[e,o,t],r),Ce=(e,o,t,s)=>M("Values",k(s),e,o,[],t),me=(e,o,t,s)=>M("ValueIds",k(s),e,o,[],t),ke=(e,o,t,s,d)=>M("Value",k(d),o,t,[e],s),ye=(e,o,t)=>B(e,o,t),he=(e,o)=>L("Metric",y(o),void 0,[e]),ve=(e,o,t,s)=>M("Metric",y(s),o,t,[e]),Te=(e,o,t)=>B(e,o,t),qe=(e,o)=>L("SliceIds",h(o),[],[e]),Pe=(e,o,t)=>L("SliceRowIds",h(t),[],[e,o]),xe=(e,o,t,s)=>M("SliceIds",h(s),o,t,[e]),Se=(e,o,t,s,d)=>M("SliceRowIds",h(d),t,s,[e,o]),Ve=(e,o,t)=>B(e,o,t),fe=(e,o,t)=>L("RemoteRowId",v(t),void 0,[e,o]),Be=(e,o,t)=>L("LocalRowIds",v(t),[],[e,o]),Le=(e,o,t)=>L("LinkedRowIds",v(t),[],[e,o]),Me=(e,o,t,s,d)=>M("RemoteRowId",v(d),t,s,[e,o]),Ae=(e,o,t,s,d)=>M("LocalRowIds",v(d),t,s,[e,o]),Ee=(e,o,t,s,d)=>M("LinkedRowIds",v(d),t,s,[e,o]),Fe=(e,o,t)=>B(e,o,t),je=(e,o)=>L("ResultTable",T(o),{},[e]),ze=(e,o)=>L("ResultRowIds",T(o),[],[e]),De=(e,o,t,s=0,d,r)=>L("ResultSortedRowIds",T(r),[],[e,o,t,s,d],6),Ge=(e,o,t)=>L("ResultRow",T(t),{},[e,o]),He=(e,o,t)=>L("ResultCellIds",T(t),[],[e,o]),Je=(e,o,t,s)=>L("ResultCell",T(s),void 0,[e,o,t]),Ke=(e,o,t,s)=>M("ResultTable",T(s),o,t,[e]),Ne=(e,o,t,s)=>M("ResultRowIds",T(s),o,t,[e]),Oe=(e,o,t,s,d,r,n,l)=>M("ResultSortedRowIds",T(l),r,n,[e,o,t,s,d]),Qe=(e,o,t,s,d)=>M("ResultRow",T(d),t,s,[e,o]),Ue=(e,o,t,s,d)=>M("ResultCellIds",T(d),t,s,[e,o]),We=(e,o,t,s,d,r)=>M("ResultCell",T(r),s,d,[e,o,t]),Xe=(e,o,t)=>B(e,o,t),Ye=e=>L("CheckpointIds",q(e),[[],void 0,[]]),Ze=(e,o)=>L("Checkpoint",q(o),void 0,[e]),$e=(e=I,o=[],t,s=I,d=[])=>{const r=q(t);return P((o=>n(r,(t=>{const d=e(o);s(t.addCheckpoint(d),t,d)}))),[r,...o,...d])},_e=e=>F(e,"goBackward"),eo=e=>F(e,"goForward"),oo=(e,o=[],t,s=I,d=[])=>{const r=q(t);return P((o=>n(r,(t=>n(e(o),(e=>s(t.goTo(e),e)))))),[r,...o,...d])},to=e=>{const o=q(e),[t,s]=Ye(o);return[(d=t,!(0==(e=>e.length)(d))),_e(o),s,n(s,(e=>o?.getCheckpoint(e)))??""];var d},so=e=>{const o=q(e),[,,[t]]=Ye(o);return[!r(t),eo(o),t,n(t,(e=>o?.getCheckpoint(e)))??""]},ro=(e,o,t)=>M("CheckpointIds",q(t),e,o),no=(e,o,t,s)=>M("Checkpoint",q(s),o,t,[e]),lo=(e,o,t=[],s,d=[])=>{const[,r]=f(),n=S((()=>o(e)),[e,...t]);return x((()=>((async()=>{await(s?.(n)),r(1)})(),()=>{n.destroy()})),[n,...d]),n},{createElement:Io,useMemo:uo}=e,ao=({tableId:e,store:o,rowComponent:t=mo,getRowComponentProps:s,separator:r,debugIds:n},l)=>Ro(d(l,(d=>Io(t,{...go(s,d),key:d,tableId:e,rowId:d,store:o,debugIds:n}))),r,n,e),io=({queryId:e,queries:o,resultRowComponent:t=Lo,getResultRowComponentProps:s,separator:r,debugIds:n},l)=>Ro(d(l,(d=>Io(t,{...go(s,d),key:d,queryId:e,rowId:d,queries:o,debugIds:n}))),r,n,e),co=e=>{const o=v(e);return[o,o?.getStore()]},po=({relationshipId:e,relationships:o,rowComponent:t=mo,getRowComponentProps:s,separator:r,debugIds:n},l,I)=>{const[u,a]=co(o),i=u?.getLocalTableId(e),c=l(e,I,u);return Ro(d(c,(e=>Io(t,{...go(s,e),key:e,tableId:i,rowId:e,store:a,debugIds:n}))),r,n,I)},bo=e=>({checkpoints:o,checkpointComponent:t=Eo,getCheckpointComponentProps:s,separator:r,debugIds:n})=>{const l=q(o);return Ro(d(e(Ye(l)),(e=>Io(t,{...go(s,e),key:e,checkpoints:l,checkpointId:e,debugIds:n}))),r)},go=(e,o)=>r(e)?{}:e(o),wo=({store:e,storesById:t,metrics:s,metricsById:d,indexes:r,indexesById:n,relationships:l,relationshipsById:I,queries:u,queriesById:a,checkpoints:c,checkpointsById:p,children:b})=>{const g=o(i);return Io(i.Provider,{value:uo((()=>[e??g[0],{...g[1],...t},s??g[2],{...g[3],...d},r??g[4],{...g[5],...n},l??g[6],{...g[7],...I},u??g[8],{...g[9],...a},c??g[10],{...g[11],...p}]),[e,t,s,d,r,n,l,I,u,a,c,p,g])},b)},Ro=(e,o,t,s)=>{const n=r(o)||!Array.isArray(e)?e:d(e,((e,t)=>t>0?[o,e]:e));return t?[s,":{",n,"}"]:n},Co=({tableId:e,rowId:o,cellId:t,store:s,debugIds:d})=>Ro(""+(O(e,o,t,s)??""),void 0,d,t),mo=({tableId:e,rowId:o,store:t,cellComponent:s=Co,getCellComponentProps:r,separator:n,debugIds:l})=>Ro(d(N(e,o,t),(d=>Io(s,{...go(r,d),key:d,tableId:e,rowId:o,cellId:d,store:t,debugIds:l}))),n,l,o),ko=e=>ao(e,H(e.tableId,e.store)),yo=({cellId:e,descending:o,offset:t,limit:s,...d})=>ao(d,J(d.tableId,e,o,t,s,d.store)),ho=({store:e,tableComponent:o=ko,getTableComponentProps:t,separator:s,debugIds:r})=>Ro(d(D(e),(s=>Io(o,{...go(t,s),key:s,tableId:s,store:e,debugIds:r}))),s),vo=({valueId:e,store:o,debugIds:t})=>Ro(""+(W(e,o)??""),void 0,t,e),To=({store:e,valueComponent:o=vo,getValueComponentProps:t,separator:s,debugIds:r})=>Ro(d(U(e),(s=>Io(o,{...go(t,s),key:s,valueId:s,store:e,debugIds:r}))),s),qo=({metricId:e,metrics:o,debugIds:t})=>Ro(he(e,o)??"",void 0,t,e),Po=({indexId:e,sliceId:o,indexes:t,rowComponent:s=mo,getRowComponentProps:r,separator:n,debugIds:l})=>{const I=h(t),u=I?.getStore(),a=I?.getTableId(e),i=Pe(e,o,I);return Ro(d(i,(e=>Io(s,{...go(r,e),key:e,tableId:a,rowId:e,store:u,debugIds:l}))),n,l,o)},xo=({indexId:e,indexes:o,sliceComponent:t=Po,getSliceComponentProps:s,separator:r,debugIds:n})=>Ro(d(qe(e,o),(d=>Io(t,{...go(s,d),key:d,indexId:e,sliceId:d,indexes:o,debugIds:n}))),r,n,e),So=({relationshipId:e,localRowId:o,relationships:t,rowComponent:s=mo,getRowComponentProps:d,debugIds:n})=>{const[l,I]=co(t),u=l?.getRemoteTableId(e),a=fe(e,o,l);return Ro(r(u)||r(a)?null:Io(s,{...go(d,a),key:a,tableId:u,rowId:a,store:I,debugIds:n}),void 0,n,o)},Vo=e=>po(e,Be,e.remoteRowId),fo=e=>po(e,Le,e.firstRowId),Bo=({queryId:e,rowId:o,cellId:t,queries:s,debugIds:d})=>Ro(""+(Je(e,o,t,s)??""),void 0,d,t),Lo=({queryId:e,rowId:o,queries:t,resultCellComponent:s=Bo,getResultCellComponentProps:r,separator:n,debugIds:l})=>Ro(d(He(e,o,t),(d=>Io(s,{...go(r,d),key:d,queryId:e,rowId:o,cellId:d,queries:t,debugIds:l}))),n,l,o),Mo=e=>io(e,ze(e.queryId,e.queries)),Ao=({cellId:e,descending:o,offset:t,limit:s,...d})=>io(d,De(d.queryId,e,o,t,s,d.queries)),Eo=({checkpoints:e,checkpointId:o,debugIds:t})=>Ro(Ze(o,e)??"",void 0,t,o),Fo=bo((e=>e[0])),jo=bo((e=>r(e[1])?[]:[e[1]])),zo=bo((e=>e[2]));export{Fo as BackwardCheckpointsView,Co as CellView,Eo as CheckpointView,jo as CurrentCheckpointView,zo as ForwardCheckpointsView,xo as IndexView,fo as LinkedRowsView,Vo as LocalRowsView,qo as MetricView,wo as Provider,So as RemoteRowView,Bo as ResultCellView,Lo as ResultRowView,Ao as ResultSortedTableView,Mo as ResultTableView,mo as RowView,Po as SliceView,yo as SortedTableView,ko as TableView,ho as TablesView,vo as ValueView,To as ValuesView,ao as tableView,$ as useAddRowCallback,O as useCell,N as useCellIds,we as useCellIdsListener,Re as useCellListener,Ze as useCheckpoint,Ye as useCheckpointIds,ro as useCheckpointIdsListener,no as useCheckpointListener,m as useCheckpoints,Xe as useCreateCheckpoints,Te as useCreateIndexes,ye as useCreateMetrics,lo as useCreatePersister,Fe as useCreateQueries,Ve as useCreateRelationships,j as useCreateStore,le as useDelCellCallback,ne as useDelRowCallback,re as useDelTableCallback,de as useDelTablesCallback,ue as useDelValueCallback,Ie as useDelValuesCallback,_e as useGoBackwardCallback,eo as useGoForwardCallback,oo as useGoToCallback,w as useIndexes,Le as useLinkedRowIds,Ee as useLinkedRowIdsListener,Be as useLocalRowIds,Ae as useLocalRowIdsListener,he as useMetric,ve as useMetricListener,g as useMetrics,C as useQueries,so as useRedoInformation,R as useRelationships,fe as useRemoteRowId,Me as useRemoteRowIdListener,Je as useResultCell,He as useResultCellIds,Ue as useResultCellIdsListener,We as useResultCellListener,Ge as useResultRow,ze as useResultRowIds,Ne as useResultRowIdsListener,Qe as useResultRowListener,De as useResultSortedRowIds,Oe as useResultSortedRowIdsListener,je as useResultTable,Ke as useResultTableListener,K as useRow,H as useRowIds,pe as useRowIdsListener,ge as useRowListener,ee as useSetCellCallback,$e as useSetCheckpointCallback,_ as useSetPartialRowCallback,te as useSetPartialValuesCallback,Z as useSetRowCallback,Y as useSetTableCallback,X as useSetTablesCallback,se as useSetValueCallback,oe as useSetValuesCallback,qe as useSliceIds,xe as useSliceIdsListener,Pe as useSliceRowIds,Se as useSliceRowIdsListener,J as useSortedRowIds,be as useSortedRowIdsListener,b as useStore,G as useTable,D as useTableIds,ie as useTableIdsListener,ce as useTableListener,z as useTables,ae as useTablesListener,to as useUndoInformation,W as useValue,U as useValueIds,me as useValueIdsListener,ke as useValueListener,Q as useValues,Ce as useValuesListener};
Binary file
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=(e,t)=>e.includes(t),n=(e,t)=>e.forEach(t),s=e=>e.length,o=e=>0==s(e),r=(e,...t)=>e.push(...t),i=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,d=(e,t,n)=>c(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,u=e=>c(e)||0==(e=>e.size)(e),h=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),f=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(p(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),v=(e,t,n,o,r=0)=>d((n?k:C)(e,t[r],r>s(t)-2?n:f),(i=>{if(r>s(t)-2)return o?.(i)&&g(e,t[r]),i;const l=v(i,t,n,o,r+1);return u(i)&&g(e,t[r]),l})),y=e=>new Set(Array.isArray(e)||c(e)?e:[e]),L=/^\d+$/,w=Object.freeze,b=(e=>{const b=new WeakMap;return e=>(b.has(e)||b.set(e,(e=>{let b,S,T,x=100,z=f(),E=f(),V=1;const j=f(),m=f(),[A,B,I]=(e=>{let t;const[o,i]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&s(e)<1e3&&r(e,t)}]})(),a=f();return[(e,n,s,r=[],i=(()=>[]))=>{t??=_;const l=o();var c;return g(a,l,[e,n,s,r,i]),c=l,v(n,s??[""],y)?.add(c),l},(e,o,...i)=>n(((e,t=[""])=>{const o=[],i=(e,l)=>l==s(t)?r(o,e):null===t[l]?h(e,(e=>i(e,l+1))):n([t[l],null],(t=>i(C(e,t),l+1)));return i(e,0),o})(e,o),(e=>h(e,(e=>C(a,e)[0](t,...o??[],...i))))),e=>d(C(a,e),(([,t,n])=>(v(t,n??[""],void 0,(t=>(p(t,e),u(t)?1:0))),g(a,e),i(e),n))),e=>d(C(a,e),(([e,,o=[],r,i])=>{const l=(...d)=>{const a=s(d);a==s(o)?e(t,...d,...i(d)):c(o[a])?n(r[a]?.(...d)??[],(e=>l(...d,e))):l(...d,o[a])};l()}))]})(),M=f(),F=f(),O=[],W=[],$=(t,n)=>{V=0,e.transaction((()=>{const[s,o]=C(M,n);h(s,((n,s)=>h(n,((n,o)=>h(n,((n,r)=>((e,t,n,s,o)=>c(o)?e.delCell(t,n,s,!0):e.setCell(t,n,s,o))(e,s,o,r,n[t]))))))),h(o,((n,s)=>((e,t,n)=>c(n)?e.delValue(t):e.setValue(t,n))(e,s,n[t])))})),V=1},q=e=>{g(M,e),g(F,e),B(m,[e])},D=(e,t)=>n(((e,t)=>e.splice(0,t))(e,t??s(e)),q),G=()=>D(O,s(O)-x),H=()=>d(b,(()=>{r(O,b),G(),D(W),b=void 0,T=1})),J=()=>{b=i(O),T=1},K=e.addCellListener(null,null,null,((e,t,n,s,o,r)=>{if(V){H();const e=k(z,t,f),i=k(e,n,f),l=k(i,s,(()=>[r,void 0]));l[1]=o,l[0]===o&&u(g(i,s))&&u(g(e,n))&&u(g(z,t))&&J(),U()}})),N=e.addValueListener(null,((e,t,n,s)=>{if(V){H();const e=k(E,t,(()=>[s,void 0]));e[1]=n,e[0]===n&&u(g(E,t))&&J(),U()}})),P=(e="")=>(c(b)&&(b=""+S++,g(M,b,[z,E]),Y(b,e),z=f(),E=f(),T=1),b),Q=()=>{o(O)||(((e,...t)=>{e.unshift(...t)})(W,P()),$(0,b),b=i(O),T=1)},R=()=>{o(W)||(r(O,b),b=l(W),$(1,b),T=1)},U=()=>{T&&(B(j),T=0)},X=e=>{const t=P(e);return U(),t},Y=(e,t)=>(Z(e)&&C(F,e)!==t&&(g(F,e,t),B(m,[e])),_),Z=e=>a(M,e),_={setSize:e=>(x=e,G(),_),addCheckpoint:X,setCheckpoint:Y,getStore:()=>e,getCheckpointIds:()=>[[...O],b,[...W]],forEachCheckpoint:e=>{return t=e,h(F,((e,n)=>t(n,e)));var t},hasCheckpoint:Z,getCheckpoint:e=>C(F,e),goBackward:()=>(Q(),U(),_),goForward:()=>(R(),U(),_),goTo:e=>{const n=t(O,e)?Q:t(W,e)?R:null;for(;!c(n)&&e!=b;)n();return U(),_},addCheckpointIdsListener:e=>A(e,j),addCheckpointListener:(e,t)=>A(t,m,[e]),delListener:e=>(I(e),_),clear:()=>(D(O),D(W),c(b)||q(b),b=void 0,S=0,X(),_),destroy:()=>{e.delListener(K),e.delListener(N)},getListenerStats:()=>({})};return w(_.clear())})(e)),b.get(e))})();e.createCheckpoints=b},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseCheckpoints={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=(e,t)=>e.includes(t),n=(e,t)=>e.forEach(t),s=e=>e.length,o=e=>0==s(e),r=(e,...t)=>e.push(...t),l=e=>e.pop(),i=e=>e.shift(),c=e=>null==e,d=(e,t,n)=>c(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,u=e=>c(e)||0==(e=>e.size)(e),h=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),f=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(p(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),v=(e,t,n,o,r=0)=>d((n?k:C)(e,t[r],r>s(t)-2?n:f),(l=>{if(r>s(t)-2)return o?.(l)&&g(e,t[r]),l;const i=v(l,t,n,o,r+1);return u(l)&&g(e,t[r]),i})),y=e=>new Set(Array.isArray(e)||c(e)?e:[e]),L=/^\d+$/,w=Object.freeze,b=(e=>{const b=new WeakMap;return e=>(b.has(e)||b.set(e,(e=>{let b,S,T,x=100,z=f(),E=f(),V=1;const j=f(),m=f(),[A,B,I]=(e=>{let t;const[o,l]=(()=>{const e=[];let t=0;return[n=>(n?i(e):null)??""+t++,t=>{L.test(t)&&s(e)<1e3&&r(e,t)}]})(),a=f();return[(e,n,s,r=[],l=(()=>[]))=>{t??=_;const i=o(1);var c;return g(a,i,[e,n,s,r,l]),c=i,v(n,s??[""],y)?.add(c),i},(e,o,...l)=>n(((e,t=[""])=>{const o=[],l=(e,i)=>i==s(t)?r(o,e):null===t[i]?h(e,(e=>l(e,i+1))):n([t[i],null],(t=>l(C(e,t),i+1)));return l(e,0),o})(e,o),(e=>h(e,(e=>C(a,e)[0](t,...o??[],...l))))),e=>d(C(a,e),(([,t,n])=>(v(t,n??[""],void 0,(t=>(p(t,e),u(t)?1:0))),g(a,e),l(e),n))),e=>d(C(a,e),(([e,,o=[],r,l])=>{const i=(...d)=>{const a=s(d);a==s(o)?e(t,...d,...l(d)):c(o[a])?n(r[a]?.(...d)??[],(e=>i(...d,e))):i(...d,o[a])};i()}))]})(),M=f(),F=f(),O=[],W=[],$=(t,n)=>{V=0,e.transaction((()=>{const[s,o]=C(M,n);h(s,((n,s)=>h(n,((n,o)=>h(n,((n,r)=>((e,t,n,s,o)=>c(o)?e.delCell(t,n,s,!0):e.setCell(t,n,s,o))(e,s,o,r,n[t]))))))),h(o,((n,s)=>((e,t,n)=>c(n)?e.delValue(t):e.setValue(t,n))(e,s,n[t])))})),V=1},q=e=>{g(M,e),g(F,e),B(m,[e])},D=(e,t)=>n(((e,t)=>e.splice(0,t))(e,t??s(e)),q),G=()=>D(O,s(O)-x),H=()=>d(b,(()=>{r(O,b),G(),D(W),b=void 0,T=1})),J=()=>{b=l(O),T=1},K=e.addCellListener(null,null,null,((e,t,n,s,o,r)=>{if(V){H();const e=k(z,t,f),l=k(e,n,f),i=k(l,s,(()=>[r,void 0]));i[1]=o,i[0]===o&&u(g(l,s))&&u(g(e,n))&&u(g(z,t))&&J(),U()}})),N=e.addValueListener(null,((e,t,n,s)=>{if(V){H();const e=k(E,t,(()=>[s,void 0]));e[1]=n,e[0]===n&&u(g(E,t))&&J(),U()}})),P=(e="")=>(c(b)&&(b=""+S++,g(M,b,[z,E]),Y(b,e),z=f(),E=f(),T=1),b),Q=()=>{o(O)||(((e,...t)=>{e.unshift(...t)})(W,P()),$(0,b),b=l(O),T=1)},R=()=>{o(W)||(r(O,b),b=i(W),$(1,b),T=1)},U=()=>{T&&(B(j),T=0)},X=e=>{const t=P(e);return U(),t},Y=(e,t)=>(Z(e)&&C(F,e)!==t&&(g(F,e,t),B(m,[e])),_),Z=e=>a(M,e),_={setSize:e=>(x=e,G(),_),addCheckpoint:X,setCheckpoint:Y,getStore:()=>e,getCheckpointIds:()=>[[...O],b,[...W]],forEachCheckpoint:e=>{return t=e,h(F,((e,n)=>t(n,e)));var t},hasCheckpoint:Z,getCheckpoint:e=>C(F,e),goBackward:()=>(Q(),U(),_),goForward:()=>(R(),U(),_),goTo:e=>{const n=t(O,e)?Q:t(W,e)?R:null;for(;!c(n)&&e!=b;)n();return U(),_},addCheckpointIdsListener:e=>A(e,j),addCheckpointListener:(e,t)=>A(t,m,[e]),delListener:e=>(I(e),_),clear:()=>(D(O),D(W),c(b)||q(b),b=void 0,S=0,X(),_),destroy:()=>{e.delListener(K),e.delListener(N)},getListenerStats:()=>({})};return w(_.clear())})(e)),b.get(e))})();e.createCheckpoints=b},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseCheckpoints={});
Binary file
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",s=t(n),r=e=>n+e,o=(e,t)=>e.every(t),d=(e,t)=>o(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),c=(e,t)=>e.forEach(t),l=e=>e.length,a=(e,...t)=>e.push(...t),f=e=>null==e,u=(e,t,n)=>f(e)?n?.():t(e),h=e=>Array.isArray(e),I=(e,t)=>e?.has(t)??!1,g=e=>f(e)||0==(e=>e.size)(e),p=e=>[...e?.values()??[]],y=e=>e.clear(),x=(e,t)=>e?.forEach(t),v=(e,t)=>e?.delete(t),S=e=>new Map(e),w=e=>[...e?.keys()??[]],L=(e,t)=>e?.get(t),b=(e,t)=>x(e,((e,n)=>t(n,e))),T=(e,t,n)=>f(n)?(v(e,t),e):e?.set(t,n),E=(e,t,n)=>(I(e,t)||T(e,t,n()),L(e,t)),R=(e,t,n,s,r=0)=>u((n?E:L)(e,t[r],r>l(t)-2?n:S),(o=>{if(r>l(t)-2)return s?.(o)&&T(e,t[r]),o;const d=R(o,t,n,s,r+1);return g(o)&&T(e,t[r]),d})),m=e=>new Set(h(e)||f(e)?e:[e]),j=(e,t)=>e?.add(t),k=(e,r)=>t(e)==s?t=>t(e):e??(()=>r??n),z=(e,t)=>e<t?-1:1,A=/^\d+$/,C=Object.freeze,D=(e=>{const t=new WeakMap;return e=>(t.has(e)||t.set(e,(e=>{const t=S(),s=S(),[D,M,B,O,W,$,q,,F,G,H]=((e,t,n)=>{const s=e.hasRow,r=S(),d=S(),i=S(),a=S(),R=S(),k=(t,n,...s)=>{const r=E(R,t,m);return c(s,(t=>j(r,t)&&n&&e.callListener(t))),s},z=(t,...n)=>u(L(R,t),(s=>{c(0==l(n)?p(s):n,(t=>{e.delListener(t),v(s,t)})),g(s)&&T(R,t)})),A=(e,n)=>{T(r,e,n),I(d,e)||(T(d,e,t()),T(i,e,S()),T(a,e,S()))},C=e=>{T(r,e),T(d,e),T(i,e),T(a,e),z(e)};return[()=>e,()=>w(r),e=>b(d,e),e=>I(d,e),e=>L(r,e),e=>L(d,e),(e,t)=>T(d,e,t),A,(t,r,d,u,g)=>{A(t,r);const p=S(),v=S(),w=L(i,t),E=L(a,t),R=t=>{const d=n=>e.getCell(r,t,n),i=L(w,t),c=s(r,t)?n(u(d,t)):void 0;var a,I;if(i===c||h(i)&&h(c)&&(I=c,l(a=i)===l(I)&&o(a,((e,t)=>I[t]===e)))||T(p,t,[i,c]),!f(g)){const e=L(E,t),n=s(r,t)?g(d,t):void 0;e!=n&&T(v,t,n)}},m=e=>{d((()=>{x(p,(([,e],t)=>T(w,t,e))),x(v,((e,t)=>T(E,t,e)))}),p,v,w,E,e),y(p),y(v)};b(w,R),e.hasTable(r)&&c(e.getRowIds(r),(e=>{I(w,e)||R(e)})),m(!0),z(t),k(t,0,e.addRowListener(r,null,((e,t,n)=>R(n))),e.addTableListener(r,(()=>m())))},C,()=>b(R,C),k,z]})(e,S,(e=>{return f(e)?n:h(e)?(t=r,e.map(t)):r(e);var t})),[J,K,N]=(e=>{let t;const[s,r]=(()=>{const e=[];let t=0;return[()=>e.shift()??n+t++,t=>{A.test(t)&&l(e)<1e3&&a(e,t)}]})(),o=S();return[(e,r,d,i=[],c=(()=>[]))=>{t??=Q;const l=s();return T(o,l,[e,r,d,i,c]),j(R(r,d??[n],m),l),l},(e,s,...r)=>c(((e,t=[n])=>{const s=[],r=(e,n)=>n==l(t)?a(s,e):null===t[n]?x(e,(e=>r(e,n+1))):c([t[n],null],(t=>r(L(e,t),n+1)));return r(e,0),s})(e,s),(e=>x(e,(e=>L(o,e)[0](t,...s??[],...r))))),e=>u(L(o,e),(([,t,s])=>(R(t,s??[n],void 0,(t=>(v(t,e),g(t)?1:0))),T(o,e),r(e),s))),e=>u(L(o,e),(([e,,n=[],s,r])=>{const o=(...d)=>{const i=l(d);i==l(n)?e(t,...d,...r(d)):f(n[i])?c(s[i]?.(...d)??[],(e=>o(...d,e))):o(...d,n[i])};o()}))]})(),P=(t,n,s)=>{const r=W(t);x(s,((t,s)=>n(s,(n=>x(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},Q={setIndexDefinition:(e,n,r,o,c,l=z)=>{const a=f(c)?void 0:([e],[t])=>c(e,t);return F(e,n,((n,r,c,h,p,y)=>{let w=0;const E=m(),R=m(),k=$(e);if(x(r,(([e,t],n)=>{const s=m(e),r=m(t);x(s,(e=>v(r,e)?v(s,e):0)),x(s,(e=>{j(E,e),u(L(k,e),(t=>{v(t,n),g(t)&&(T(k,e),w=1)}))})),x(r,(e=>{j(E,e),I(k,e)||(T(k,e,m()),w=1),j(L(k,e),n),f(o)||j(R,e)}))})),n(),g(p)||(y?b(k,(e=>j(R,e))):b(c,(e=>u(L(h,e),(e=>j(R,e))))),x(R,(e=>{const t=(t,n)=>l(L(p,t),L(p,n),e),n=[...L(k,e)];d(n,t)||(T(k,e,m(i(n,t))),j(E,e))}))),(w||y)&&!f(a)){const t=[...k];d(t,a)||(q(e,S(i(t,a))),w=1)}w&&K(t,[e]),x(E,(t=>K(s,[e,t])))}),k(r),u(o,k)),Q},delIndexDefinition:e=>(G(e),Q),getStore:D,getIndexIds:M,forEachIndex:e=>B(((t,n)=>e(t,(e=>P(t,e,n))))),forEachSlice:(e,t)=>P(e,t,$(e)),hasIndex:O,hasSlice:(e,t)=>I($(e),t),getTableId:W,getSliceIds:e=>w($(e)),getSliceRowIds:(e,t)=>p(L($(e),t)),addSliceIdsListener:(e,n)=>J(n,t,[e]),addSliceRowIdsListener:(e,t,n)=>J(n,s,[e,t]),delListener:e=>(N(e),Q),destroy:H,getListenerStats:()=>({})};return C(Q)})(e)),t.get(e))})();e.createIndexes=D},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseIndexes={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",s=t(n),r=e=>n+e,o=(e,t)=>e.every(t),d=(e,t)=>o(e,((n,s)=>0==s||t(e[s-1],n)<=0)),i=(e,t)=>e.sort(t),l=(e,t)=>e.forEach(t),c=e=>e.length,a=(e,...t)=>e.push(...t),f=e=>null==e,u=(e,t,n)=>f(e)?n?.():t(e),h=e=>Array.isArray(e),I=(e,t)=>e?.has(t)??!1,g=e=>f(e)||0==(e=>e.size)(e),p=e=>[...e?.values()??[]],y=e=>e.clear(),x=(e,t)=>e?.forEach(t),v=(e,t)=>e?.delete(t),S=e=>new Map(e),w=e=>[...e?.keys()??[]],L=(e,t)=>e?.get(t),b=(e,t)=>x(e,((e,n)=>t(n,e))),T=(e,t,n)=>f(n)?(v(e,t),e):e?.set(t,n),E=(e,t,n)=>(I(e,t)||T(e,t,n()),L(e,t)),R=(e,t,n,s,r=0)=>u((n?E:L)(e,t[r],r>c(t)-2?n:S),(o=>{if(r>c(t)-2)return s?.(o)&&T(e,t[r]),o;const d=R(o,t,n,s,r+1);return g(o)&&T(e,t[r]),d})),m=e=>new Set(h(e)||f(e)?e:[e]),j=(e,t)=>e?.add(t),k=(e,r)=>t(e)==s?t=>t(e):e??(()=>r??n),z=(e,t)=>e<t?-1:1,A=/^\d+$/,C=Object.freeze,D=(e=>{const t=new WeakMap;return e=>(t.has(e)||t.set(e,(e=>{const t=S(),s=S(),[D,M,B,O,W,$,q,,F,G,H]=((e,t,n)=>{const s=e.hasRow,r=S(),d=S(),i=S(),a=S(),R=S(),k=(t,n,...s)=>{const r=E(R,t,m);return l(s,(t=>j(r,t)&&n&&e.callListener(t))),s},z=(t,...n)=>u(L(R,t),(s=>{l(0==c(n)?p(s):n,(t=>{e.delListener(t),v(s,t)})),g(s)&&T(R,t)})),A=(e,n)=>{T(r,e,n),I(d,e)||(T(d,e,t()),T(i,e,S()),T(a,e,S()))},C=e=>{T(r,e),T(d,e),T(i,e),T(a,e),z(e)};return[()=>e,()=>w(r),e=>b(d,e),e=>I(d,e),e=>L(r,e),e=>L(d,e),(e,t)=>T(d,e,t),A,(t,r,d,u,g)=>{A(t,r);const p=S(),v=S(),w=L(i,t),E=L(a,t),R=t=>{const d=n=>e.getCell(r,t,n),i=L(w,t),l=s(r,t)?n(u(d,t)):void 0;var a,I;if(i===l||h(i)&&h(l)&&(I=l,c(a=i)===c(I)&&o(a,((e,t)=>I[t]===e)))||T(p,t,[i,l]),!f(g)){const e=L(E,t),n=s(r,t)?g(d,t):void 0;e!=n&&T(v,t,n)}},m=e=>{d((()=>{x(p,(([,e],t)=>T(w,t,e))),x(v,((e,t)=>T(E,t,e)))}),p,v,w,E,e),y(p),y(v)};b(w,R),e.hasTable(r)&&l(e.getRowIds(r),(e=>{I(w,e)||R(e)})),m(!0),z(t),k(t,0,e.addRowListener(r,null,((e,t,n)=>R(n))),e.addTableListener(r,(()=>m())))},C,()=>b(R,C),k,z]})(e,S,(e=>{return f(e)?n:h(e)?(t=r,e.map(t)):r(e);var t})),[J,K,N]=(e=>{let t;const[s,r]=(()=>{const e=[];let t=0;return[s=>(s?e.shift():null)??n+t++,t=>{A.test(t)&&c(e)<1e3&&a(e,t)}]})(),o=S();return[(e,r,d,i=[],l=(()=>[]))=>{t??=Q;const c=s(1);return T(o,c,[e,r,d,i,l]),j(R(r,d??[n],m),c),c},(e,s,...r)=>l(((e,t=[n])=>{const s=[],r=(e,n)=>n==c(t)?a(s,e):null===t[n]?x(e,(e=>r(e,n+1))):l([t[n],null],(t=>r(L(e,t),n+1)));return r(e,0),s})(e,s),(e=>x(e,(e=>L(o,e)[0](t,...s??[],...r))))),e=>u(L(o,e),(([,t,s])=>(R(t,s??[n],void 0,(t=>(v(t,e),g(t)?1:0))),T(o,e),r(e),s))),e=>u(L(o,e),(([e,,n=[],s,r])=>{const o=(...d)=>{const i=c(d);i==c(n)?e(t,...d,...r(d)):f(n[i])?l(s[i]?.(...d)??[],(e=>o(...d,e))):o(...d,n[i])};o()}))]})(),P=(t,n,s)=>{const r=W(t);x(s,((t,s)=>n(s,(n=>x(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},Q={setIndexDefinition:(e,n,r,o,l,c=z)=>{const a=f(l)?void 0:([e],[t])=>l(e,t);return F(e,n,((n,r,l,h,p,y)=>{let w=0;const E=m(),R=m(),k=$(e);if(x(r,(([e,t],n)=>{const s=m(e),r=m(t);x(s,(e=>v(r,e)?v(s,e):0)),x(s,(e=>{j(E,e),u(L(k,e),(t=>{v(t,n),g(t)&&(T(k,e),w=1)}))})),x(r,(e=>{j(E,e),I(k,e)||(T(k,e,m()),w=1),j(L(k,e),n),f(o)||j(R,e)}))})),n(),g(p)||(y?b(k,(e=>j(R,e))):b(l,(e=>u(L(h,e),(e=>j(R,e))))),x(R,(e=>{const t=(t,n)=>c(L(p,t),L(p,n),e),n=[...L(k,e)];d(n,t)||(T(k,e,m(i(n,t))),j(E,e))}))),(w||y)&&!f(a)){const t=[...k];d(t,a)||(q(e,S(i(t,a))),w=1)}w&&K(t,[e]),x(E,(t=>K(s,[e,t])))}),k(r),u(o,k)),Q},delIndexDefinition:e=>(G(e),Q),getStore:D,getIndexIds:M,forEachIndex:e=>B(((t,n)=>e(t,(e=>P(t,e,n))))),forEachSlice:(e,t)=>P(e,t,$(e)),hasIndex:O,hasSlice:(e,t)=>I($(e),t),getTableId:W,getSliceIds:e=>w($(e)),getSliceRowIds:(e,t)=>p(L($(e),t)),addSliceIdsListener:(e,n)=>J(n,t,[e]),addSliceRowIdsListener:(e,t,n)=>J(n,s,[e,t]),delListener:e=>(N(e),Q),destroy:H,getListenerStats:()=>({})};return C(Q)})(e)),t.get(e))})();e.createIndexes=D},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseIndexes={});
Binary file
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",r=t(n),s=t(t),i=(e,t)=>e.forEach(t),o=e=>a(e,((e,t)=>e+t),0),c=e=>e.length,a=(e,t,n)=>e.reduce(t,n),d=(e,...t)=>e.push(...t),l=Math.max,u=Math.min,f=isFinite,h=e=>null==e,v=(e,t,n)=>h(e)?n?.():t(e),g=e=>Array.isArray(e),M=()=>{},p=e=>e.size,y=(e,t)=>e?.has(t)??!1,m=e=>h(e)||0==p(e),b=e=>[...e?.values()??[]],L=e=>e.clear(),w=(e,t)=>e?.forEach(t),T=(e,t)=>e?.delete(t),x=e=>new Map(e),E=(e,t)=>e?.get(t),I=(e,t)=>w(e,((e,n)=>t(n,e))),R=(e,t,n)=>h(n)?(T(e,t),e):e?.set(t,n),S=(e,t,n)=>(y(e,t)||R(e,t,n()),E(e,t)),j=(e,t,n,r,s=0)=>v((n?S:E)(e,t[s],s>c(t)-2?n:x),(i=>{if(s>c(t)-2)return r?.(i)&&R(e,t[s]),i;const o=j(i,t,n,r,s+1);return m(i)&&R(e,t[s]),o})),k=x([["avg",[(e,t)=>o(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,r)=>e+(t-n)/r]],["max",[e=>l(...e),(e,t)=>l(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:l(t,e)]],["min",[e=>u(...e),(e,t)=>u(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:u(t,e)]],["sum",[e=>o(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),z=e=>new Set(g(e)||h(e)?e:[e]),A=(e,t)=>e?.add(t),D=/^\d+$/,N=Object.freeze,B=(e=>{const o=new WeakMap;return e=>(o.has(e)||o.set(e,(e=>{const o=x(),[a,l,u,B,C,F,O,,W,$,q]=((e,t,r)=>{const s=e.hasRow,o=x(),a=x(),d=x(),l=x(),u=x(),f=(t,n,...r)=>{const s=S(u,t,z);return i(r,(t=>A(s,t)&&n&&e.callListener(t))),r},M=(t,...n)=>v(E(u,t),(r=>{i(0==c(n)?b(r):n,(t=>{e.delListener(t),T(r,t)})),m(r)&&R(u,t)})),p=(e,n)=>{R(o,e,n),y(a,e)||(R(a,e,t()),R(d,e,x()),R(l,e,x()))},j=e=>{R(o,e),R(a,e),R(d,e),R(l,e),M(e)};return[()=>e,()=>[...o?.keys()??[]],e=>I(a,e),e=>y(a,e),e=>E(o,e),e=>E(a,e),(e,t)=>R(a,e,t),p,(t,r,o,a,u)=>{p(t,r);const v=x(),m=x(),b=E(d,t),T=E(l,t),S=t=>{const i=n=>e.getCell(r,t,n),o=E(b,t),d=s(r,t)?(l=a(i,t),isNaN(l)||h(l)||!0===l||!1===l||l===n?void 0:1*l):void 0;var l,f,M,p;if(o===d||g(o)&&g(d)&&(M=d,c(f=o)===c(M)&&(p=(e,t)=>M[t]===e,f.every(p)))||R(v,t,[o,d]),!h(u)){const e=E(T,t),n=s(r,t)?u(i,t):void 0;e!=n&&R(m,t,n)}},j=e=>{o((()=>{w(v,(([,e],t)=>R(b,t,e))),w(m,((e,t)=>R(T,t,e)))}),v,m,b,T,e),L(v),L(m)};I(b,S),e.hasTable(r)&&i(e.getRowIds(r),(e=>{y(b,e)||S(e)})),j(!0),M(t),f(t,0,e.addRowListener(r,null,((e,t,n)=>S(n))),e.addTableListener(r,(()=>j())))},j,()=>I(u,j),f,M]})(e,M),[G,H,J]=(e=>{let t;const[r,s]=(()=>{const e=[];let t=0;return[()=>e.shift()??n+t++,t=>{D.test(t)&&c(e)<1e3&&d(e,t)}]})(),o=x();return[(e,s,i,c=[],a=(()=>[]))=>{t??=K;const d=r();return R(o,d,[e,s,i,c,a]),A(j(s,i??[n],z),d),d},(e,r,...s)=>i(((e,t=[n])=>{const r=[],s=(e,n)=>n==c(t)?d(r,e):null===t[n]?w(e,(e=>s(e,n+1))):i([t[n],null],(t=>s(E(e,t),n+1)));return s(e,0),r})(e,r),(e=>w(e,(e=>E(o,e)[0](t,...r??[],...s))))),e=>v(E(o,e),(([,t,r])=>(j(t,r??[n],void 0,(t=>(T(t,e),m(t)?1:0))),R(o,e),s(e),r))),e=>v(E(o,e),(([e,,n=[],r,s])=>{const o=(...a)=>{const d=c(a);d==c(n)?e(t,...a,...s(a)):h(n[d])?i(r[d]?.(...a)??[],(e=>o(...a,e))):o(...a,n[d])};o()}))]})(),K={setMetricDefinition:(e,n,i,c,a,d,l)=>{const u=t(i)==s?[i,a,d,l]:E(k,i)??E(k,"sum");return W(e,n,((t,n,r,s,i,c)=>{const a=F(e),d=p(s);c||=h(a),t();let l=((e,t,n,r,s,i=!1)=>{if(m(n))return;const[o,c,a,d]=s;return i||=h(e),w(r,(([n,r])=>{i||(e=h(n)?c?.(e,r,t++):h(r)?a?.(e,n,t--):d?.(e,r,n,t),i||=h(e))})),i?o(b(n),p(n)):e})(a,d,s,n,u,c);f(l)||(l=void 0),l!=a&&(O(e,l),H(o,[e],l,a))}),(1,t(v=c)==r?e=>e(v):v??(()=>1))),K;var v},delMetricDefinition:e=>($(e),K),getStore:a,getMetricIds:l,forEachMetric:u,hasMetric:B,getTableId:C,getMetric:F,addMetricListener:(e,t)=>G(t,o,[e]),delListener:e=>(J(e),K),destroy:q,getListenerStats:()=>({})};return N(K)})(e)),o.get(e))})();e.createMetrics=B},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseMetrics={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",r=t(n),s=t(t),i=(e,t)=>e.forEach(t),o=e=>a(e,((e,t)=>e+t),0),c=e=>e.length,a=(e,t,n)=>e.reduce(t,n),d=(e,...t)=>e.push(...t),l=Math.max,u=Math.min,f=isFinite,h=e=>null==e,v=(e,t,n)=>h(e)?n?.():t(e),g=e=>Array.isArray(e),M=()=>{},p=e=>e.size,y=(e,t)=>e?.has(t)??!1,m=e=>h(e)||0==p(e),b=e=>[...e?.values()??[]],L=e=>e.clear(),w=(e,t)=>e?.forEach(t),T=(e,t)=>e?.delete(t),x=e=>new Map(e),E=(e,t)=>e?.get(t),I=(e,t)=>w(e,((e,n)=>t(n,e))),R=(e,t,n)=>h(n)?(T(e,t),e):e?.set(t,n),S=(e,t,n)=>(y(e,t)||R(e,t,n()),E(e,t)),j=(e,t,n,r,s=0)=>v((n?S:E)(e,t[s],s>c(t)-2?n:x),(i=>{if(s>c(t)-2)return r?.(i)&&R(e,t[s]),i;const o=j(i,t,n,r,s+1);return m(i)&&R(e,t[s]),o})),k=x([["avg",[(e,t)=>o(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,r)=>e+(t-n)/r]],["max",[e=>l(...e),(e,t)=>l(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:l(t,e)]],["min",[e=>u(...e),(e,t)=>u(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:u(t,e)]],["sum",[e=>o(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),z=e=>new Set(g(e)||h(e)?e:[e]),A=(e,t)=>e?.add(t),D=/^\d+$/,N=Object.freeze,B=(e=>{const o=new WeakMap;return e=>(o.has(e)||o.set(e,(e=>{const o=x(),[a,l,u,B,C,F,O,,W,$,q]=((e,t,r)=>{const s=e.hasRow,o=x(),a=x(),d=x(),l=x(),u=x(),f=(t,n,...r)=>{const s=S(u,t,z);return i(r,(t=>A(s,t)&&n&&e.callListener(t))),r},M=(t,...n)=>v(E(u,t),(r=>{i(0==c(n)?b(r):n,(t=>{e.delListener(t),T(r,t)})),m(r)&&R(u,t)})),p=(e,n)=>{R(o,e,n),y(a,e)||(R(a,e,t()),R(d,e,x()),R(l,e,x()))},j=e=>{R(o,e),R(a,e),R(d,e),R(l,e),M(e)};return[()=>e,()=>[...o?.keys()??[]],e=>I(a,e),e=>y(a,e),e=>E(o,e),e=>E(a,e),(e,t)=>R(a,e,t),p,(t,r,o,a,u)=>{p(t,r);const v=x(),m=x(),b=E(d,t),T=E(l,t),S=t=>{const i=n=>e.getCell(r,t,n),o=E(b,t),d=s(r,t)?(l=a(i,t),isNaN(l)||h(l)||!0===l||!1===l||l===n?void 0:1*l):void 0;var l,f,M,p;if(o===d||g(o)&&g(d)&&(M=d,c(f=o)===c(M)&&(p=(e,t)=>M[t]===e,f.every(p)))||R(v,t,[o,d]),!h(u)){const e=E(T,t),n=s(r,t)?u(i,t):void 0;e!=n&&R(m,t,n)}},j=e=>{o((()=>{w(v,(([,e],t)=>R(b,t,e))),w(m,((e,t)=>R(T,t,e)))}),v,m,b,T,e),L(v),L(m)};I(b,S),e.hasTable(r)&&i(e.getRowIds(r),(e=>{y(b,e)||S(e)})),j(!0),M(t),f(t,0,e.addRowListener(r,null,((e,t,n)=>S(n))),e.addTableListener(r,(()=>j())))},j,()=>I(u,j),f,M]})(e,M),[G,H,J]=(e=>{let t;const[r,s]=(()=>{const e=[];let t=0;return[r=>(r?e.shift():null)??n+t++,t=>{D.test(t)&&c(e)<1e3&&d(e,t)}]})(),o=x();return[(e,s,i,c=[],a=(()=>[]))=>{t??=K;const d=r(1);return R(o,d,[e,s,i,c,a]),A(j(s,i??[n],z),d),d},(e,r,...s)=>i(((e,t=[n])=>{const r=[],s=(e,n)=>n==c(t)?d(r,e):null===t[n]?w(e,(e=>s(e,n+1))):i([t[n],null],(t=>s(E(e,t),n+1)));return s(e,0),r})(e,r),(e=>w(e,(e=>E(o,e)[0](t,...r??[],...s))))),e=>v(E(o,e),(([,t,r])=>(j(t,r??[n],void 0,(t=>(T(t,e),m(t)?1:0))),R(o,e),s(e),r))),e=>v(E(o,e),(([e,,n=[],r,s])=>{const o=(...a)=>{const d=c(a);d==c(n)?e(t,...a,...s(a)):h(n[d])?i(r[d]?.(...a)??[],(e=>o(...a,e))):o(...a,n[d])};o()}))]})(),K={setMetricDefinition:(e,n,i,c,a,d,l)=>{const u=t(i)==s?[i,a,d,l]:E(k,i)??E(k,"sum");return W(e,n,((t,n,r,s,i,c)=>{const a=F(e),d=p(s);c||=h(a),t();let l=((e,t,n,r,s,i=!1)=>{if(m(n))return;const[o,c,a,d]=s;return i||=h(e),w(r,(([n,r])=>{i||(e=h(n)?c?.(e,r,t++):h(r)?a?.(e,n,t--):d?.(e,r,n,t),i||=h(e))})),i?o(b(n),p(n)):e})(a,d,s,n,u,c);f(l)||(l=void 0),l!=a&&(O(e,l),H(o,[e],l,a))}),(1,t(v=c)==r?e=>e(v):v??(()=>1))),K;var v},delMetricDefinition:e=>($(e),K),getStore:a,getMetricIds:l,forEachMetric:u,hasMetric:B,getTableId:C,getMetric:F,addMetricListener:(e,t)=>G(t,o,[e]),delListener:e=>(J(e),K),destroy:q,getListenerStats:()=>({})};return N(K)})(e)),o.get(e))})();e.createMetrics=B},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseMetrics={});
Binary file
@@ -1 +1 @@
1
- var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",s=t(n),o=(e,t)=>e.forEach(t),r=e=>e.length,i=(e,...t)=>e.push(...t),a=e=>null==e,d=(e,t,n)=>a(e)?n?.():t(e),l=e=>Array.isArray(e),c=(e,t)=>e?.has(t)??!1,f=e=>a(e)||0==(e=>e.size)(e),u=e=>[...e?.values()??[]],h=e=>e.clear(),R=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),g=e=>new Map(e),L=(e,t)=>e?.get(t),w=(e,t)=>R(e,((e,n)=>t(n,e))),y=(e,t,n)=>a(n)?(p(e,t),e):e?.set(t,n),I=(e,t,n)=>(c(e,t)||y(e,t,n()),L(e,t)),v=(e,t,n,s,o=0)=>d((n?I:L)(e,t[o],o>r(t)-2?n:g),(i=>{if(o>r(t)-2)return s?.(i)&&y(e,t[o]),i;const a=v(i,t,n,s,o+1);return f(i)&&y(e,t[o]),a})),b=e=>new Set(l(e)||a(e)?e:[e]),T=(e,t)=>e?.add(t),m=/^\d+$/,k=Object.freeze,E=(e=>{const E=new WeakMap;return e=>(E.has(e)||E.set(e,(e=>{const E=g(),x=g(),S=g(),j=g(),[z,A,D,M,B,C,,,O,W,$]=((e,t,s)=>{const i=e.hasRow,v=g(),m=g(),k=g(),E=g(),x=g(),S=(t,n,...s)=>{const r=I(x,t,b);return o(s,(t=>T(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>d(L(x,t),(s=>{o(0==r(n)?u(s):n,(t=>{e.delListener(t),p(s,t)})),f(s)&&y(x,t)})),z=(e,t)=>{y(v,e,t),c(m,e)||(y(m,e,[g(),g(),g(),g()]),y(k,e,g()),y(E,e,g()))},A=e=>{y(v,e),y(m,e),y(k,e),y(E,e),j(e)};return[()=>e,()=>[...v?.keys()??[]],e=>w(m,e),e=>c(m,e),e=>L(v,e),e=>L(m,e),(e,t)=>y(m,e,t),z,(t,s,d,f,u)=>{z(t,s);const p=g(),I=g(),v=L(k,t),b=L(E,t),T=t=>{const o=n=>e.getCell(s,t,n),d=L(v,t),c=i(s,t)?(h=f(o,t),a(h)?void 0:h+n):void 0;var h,R,g,w;if(d===c||l(d)&&l(c)&&(g=c,r(R=d)===r(g)&&(w=(e,t)=>g[t]===e,R.every(w)))||y(p,t,[d,c]),!a(u)){const e=L(b,t),n=i(s,t)?u(o,t):void 0;e!=n&&y(I,t,n)}},m=e=>{d((()=>{R(p,(([,e],t)=>y(v,t,e))),R(I,((e,t)=>y(b,t,e)))}),p,I,v,b,e),h(p),h(I)};w(v,T),e.hasTable(s)&&o(e.getRowIds(s),(e=>{c(v,e)||T(e)})),m(!0),j(t),S(t,0,e.addRowListener(s,null,((e,t,n)=>T(n))),e.addTableListener(s,(()=>m())))},A,()=>w(x,A),S,j]})(e),[q,F,G]=(e=>{let t;const[s,l]=(()=>{const e=[];let t=0;return[()=>e.shift()??n+t++,t=>{m.test(t)&&r(e)<1e3&&i(e,t)}]})(),c=g();return[(e,o,r,i=[],a=(()=>[]))=>{t??=N;const d=s();return y(c,d,[e,o,r,i,a]),T(v(o,r??[n],b),d),d},(e,s,...a)=>o(((e,t=[n])=>{const s=[],a=(e,n)=>n==r(t)?i(s,e):null===t[n]?R(e,(e=>a(e,n+1))):o([t[n],null],(t=>a(L(e,t),n+1)));return a(e,0),s})(e,s),(e=>R(e,(e=>L(c,e)[0](t,...s??[],...a))))),e=>d(L(c,e),(([,t,s])=>(v(t,s??[n],void 0,(t=>(p(t,e),f(t)?1:0))),y(c,e),l(e),s))),e=>d(L(c,e),(([e,,n=[],s,i])=>{const d=(...l)=>{const c=r(l);c==r(n)?e(t,...l,...i(l)):a(n[c])?o(s[c]?.(...l)??[],(e=>d(...l,e))):d(...l,n[c])};d()}))]})(),H=(e,t,n)=>d(C(e),(([s,,o])=>{if(!c(o,t)){const r=b();if(B(e)!=K(e))T(r,t);else{let e=t;for(;!a(e)&&!c(r,e);)T(r,e),e=L(s,e)}if(n)return r;y(o,t,r)}return L(o,t)})),J=(e,t)=>d(C(e),(([,,e])=>y(e,t))),K=e=>L(E,e),N={setRelationshipDefinition:(e,o,r,i)=>{return y(E,e,r),O(e,o,((t,n)=>{const s=b(),o=b(),r=b(),[i,l]=C(e);R(n,(([t,n],u)=>{a(t)||(T(o,t),d(L(l,t),(e=>{p(e,u),f(e)&&y(l,t)}))),a(n)||(T(o,n),c(l,n)||y(l,n,b()),T(L(l,n),u)),T(s,u),y(i,u,n),w(L(j,e),(t=>{c(H(e,t),u)&&T(r,t)}))})),t(),R(s,(t=>F(x,[e,t]))),R(o,(t=>F(S,[e,t]))),R(r,(t=>{J(e,t),F(j,[e,t])}))}),t(l=i)==s?e=>e(l):l??(()=>n)),N;var l},delRelationshipDefinition:e=>(y(E,e),W(e),N),getStore:z,getRelationshipIds:A,forEachRelationship:t=>D((n=>t(n,(t=>e.forEachRow(B(n),t))))),hasRelationship:M,getLocalTableId:B,getRemoteTableId:K,getRemoteRowId:(e,t)=>L(C(e)?.[0],t),getLocalRowIds:(e,t)=>u(L(C(e)?.[1],t)),getLinkedRowIds:(e,t)=>a(C(e))?[t]:u(H(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>q(n,x,[e,t]),addLocalRowIdsListener:(e,t,n)=>q(n,S,[e,t]),addLinkedRowIdsListener:(e,t,n)=>(H(e,t),q(n,j,[e,t])),delListener:e=>(J(...G(e)),N),destroy:$,getListenerStats:()=>({})};return k(N)})(e)),E.get(e))})();e.createRelationships=E},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseRelationships={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n="",s=t(n),o=(e,t)=>e.forEach(t),r=e=>e.length,i=(e,...t)=>e.push(...t),a=e=>null==e,l=(e,t,n)=>a(e)?n?.():t(e),d=e=>Array.isArray(e),c=(e,t)=>e?.has(t)??!1,f=e=>a(e)||0==(e=>e.size)(e),u=e=>[...e?.values()??[]],h=e=>e.clear(),R=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),g=e=>new Map(e),L=(e,t)=>e?.get(t),w=(e,t)=>R(e,((e,n)=>t(n,e))),y=(e,t,n)=>a(n)?(p(e,t),e):e?.set(t,n),I=(e,t,n)=>(c(e,t)||y(e,t,n()),L(e,t)),v=(e,t,n,s,o=0)=>l((n?I:L)(e,t[o],o>r(t)-2?n:g),(i=>{if(o>r(t)-2)return s?.(i)&&y(e,t[o]),i;const a=v(i,t,n,s,o+1);return f(i)&&y(e,t[o]),a})),b=e=>new Set(d(e)||a(e)?e:[e]),T=(e,t)=>e?.add(t),m=/^\d+$/,k=Object.freeze,E=(e=>{const E=new WeakMap;return e=>(E.has(e)||E.set(e,(e=>{const E=g(),x=g(),S=g(),j=g(),[z,A,D,M,B,C,,,O,W,$]=((e,t,s)=>{const i=e.hasRow,v=g(),m=g(),k=g(),E=g(),x=g(),S=(t,n,...s)=>{const r=I(x,t,b);return o(s,(t=>T(r,t)&&n&&e.callListener(t))),s},j=(t,...n)=>l(L(x,t),(s=>{o(0==r(n)?u(s):n,(t=>{e.delListener(t),p(s,t)})),f(s)&&y(x,t)})),z=(e,t)=>{y(v,e,t),c(m,e)||(y(m,e,[g(),g(),g(),g()]),y(k,e,g()),y(E,e,g()))},A=e=>{y(v,e),y(m,e),y(k,e),y(E,e),j(e)};return[()=>e,()=>[...v?.keys()??[]],e=>w(m,e),e=>c(m,e),e=>L(v,e),e=>L(m,e),(e,t)=>y(m,e,t),z,(t,s,l,f,u)=>{z(t,s);const p=g(),I=g(),v=L(k,t),b=L(E,t),T=t=>{const o=n=>e.getCell(s,t,n),l=L(v,t),c=i(s,t)?(h=f(o,t),a(h)?void 0:h+n):void 0;var h,R,g,w;if(l===c||d(l)&&d(c)&&(g=c,r(R=l)===r(g)&&(w=(e,t)=>g[t]===e,R.every(w)))||y(p,t,[l,c]),!a(u)){const e=L(b,t),n=i(s,t)?u(o,t):void 0;e!=n&&y(I,t,n)}},m=e=>{l((()=>{R(p,(([,e],t)=>y(v,t,e))),R(I,((e,t)=>y(b,t,e)))}),p,I,v,b,e),h(p),h(I)};w(v,T),e.hasTable(s)&&o(e.getRowIds(s),(e=>{c(v,e)||T(e)})),m(!0),j(t),S(t,0,e.addRowListener(s,null,((e,t,n)=>T(n))),e.addTableListener(s,(()=>m())))},A,()=>w(x,A),S,j]})(e),[q,F,G]=(e=>{let t;const[s,d]=(()=>{const e=[];let t=0;return[s=>(s?e.shift():null)??n+t++,t=>{m.test(t)&&r(e)<1e3&&i(e,t)}]})(),c=g();return[(e,o,r,i=[],a=(()=>[]))=>{t??=N;const l=s(1);return y(c,l,[e,o,r,i,a]),T(v(o,r??[n],b),l),l},(e,s,...a)=>o(((e,t=[n])=>{const s=[],a=(e,n)=>n==r(t)?i(s,e):null===t[n]?R(e,(e=>a(e,n+1))):o([t[n],null],(t=>a(L(e,t),n+1)));return a(e,0),s})(e,s),(e=>R(e,(e=>L(c,e)[0](t,...s??[],...a))))),e=>l(L(c,e),(([,t,s])=>(v(t,s??[n],void 0,(t=>(p(t,e),f(t)?1:0))),y(c,e),d(e),s))),e=>l(L(c,e),(([e,,n=[],s,i])=>{const l=(...d)=>{const c=r(d);c==r(n)?e(t,...d,...i(d)):a(n[c])?o(s[c]?.(...d)??[],(e=>l(...d,e))):l(...d,n[c])};l()}))]})(),H=(e,t,n)=>l(C(e),(([s,,o])=>{if(!c(o,t)){const r=b();if(B(e)!=K(e))T(r,t);else{let e=t;for(;!a(e)&&!c(r,e);)T(r,e),e=L(s,e)}if(n)return r;y(o,t,r)}return L(o,t)})),J=(e,t)=>l(C(e),(([,,e])=>y(e,t))),K=e=>L(E,e),N={setRelationshipDefinition:(e,o,r,i)=>{return y(E,e,r),O(e,o,((t,n)=>{const s=b(),o=b(),r=b(),[i,d]=C(e);R(n,(([t,n],u)=>{a(t)||(T(o,t),l(L(d,t),(e=>{p(e,u),f(e)&&y(d,t)}))),a(n)||(T(o,n),c(d,n)||y(d,n,b()),T(L(d,n),u)),T(s,u),y(i,u,n),w(L(j,e),(t=>{c(H(e,t),u)&&T(r,t)}))})),t(),R(s,(t=>F(x,[e,t]))),R(o,(t=>F(S,[e,t]))),R(r,(t=>{J(e,t),F(j,[e,t])}))}),t(d=i)==s?e=>e(d):d??(()=>n)),N;var d},delRelationshipDefinition:e=>(y(E,e),W(e),N),getStore:z,getRelationshipIds:A,forEachRelationship:t=>D((n=>t(n,(t=>e.forEachRow(B(n),t))))),hasRelationship:M,getLocalTableId:B,getRemoteTableId:K,getRemoteRowId:(e,t)=>L(C(e)?.[0],t),getLocalRowIds:(e,t)=>u(L(C(e)?.[1],t)),getLinkedRowIds:(e,t)=>a(C(e))?[t]:u(H(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>q(n,x,[e,t]),addLocalRowIdsListener:(e,t,n)=>q(n,S,[e,t]),addLinkedRowIdsListener:(e,t,n)=>(H(e,t),q(n,j,[e,t])),delListener:e=>(J(...G(e)),N),destroy:$,getListenerStats:()=>({})};return k(N)})(e)),E.get(e))})();e.createRelationships=E},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseRelationships={});
Binary file