tinybase 4.2.0-beta.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/persisters/persister-indexed-db.cjs +1 -0
- package/lib/cjs/persisters/persister-indexed-db.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-remote.cjs +1 -1
- package/lib/cjs/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom.cjs +1 -1
- package/lib/cjs/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-indexed-db.cjs +1 -0
- package/lib/cjs-es6/persisters/persister-indexed-db.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-remote.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/persisters/persister-browser.js +13 -8
- package/lib/debug/persisters/persister-indexed-db.js +272 -0
- package/lib/debug/persisters/persister-remote.js +1 -1
- package/lib/debug/persisters/persister-yjs.js +10 -16
- package/lib/debug/tools.js +21 -5
- package/lib/debug/ui-react-dom.js +187 -126
- package/lib/debug/ui-react.js +4 -3
- package/lib/es6/persisters/persister-indexed-db.js +1 -0
- package/lib/es6/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/es6/persisters/persister-remote.js +1 -1
- package/lib/es6/persisters/persister-remote.js.gz +0 -0
- package/lib/es6/persisters/persister-yjs.js +1 -1
- package/lib/es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react-dom-debug.js +1 -1
- package/lib/es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/es6/ui-react-dom.js +1 -1
- package/lib/es6/ui-react-dom.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/persisters/persister-indexed-db.js +1 -0
- package/lib/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/persisters/persister-remote.js +1 -1
- package/lib/persisters/persister-remote.js.gz +0 -0
- package/lib/persisters/persister-yjs.js +1 -1
- package/lib/persisters/persister-yjs.js.gz +0 -0
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/persisters/persister-indexed-db.d.ts +75 -0
- package/lib/types/persisters/persister-remote.d.ts +2 -2
- package/lib/types/persisters.d.ts +1 -0
- package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +86 -0
- package/lib/types/with-schemas/persisters/persister-remote.d.ts +3 -3
- package/lib/types/with-schemas/persisters.d.ts +1 -0
- package/lib/ui-react-dom.js +1 -1
- package/lib/ui-react-dom.js.gz +0 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/persisters/persister-indexed-db.js +1 -0
- package/lib/umd/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/umd/persisters/persister-remote.js +1 -1
- package/lib/umd/persisters/persister-remote.js.gz +0 -0
- package/lib/umd/persisters/persister-yjs.js +1 -1
- package/lib/umd/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react-dom-debug.js +1 -1
- package/lib/umd/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd/ui-react-dom.js +1 -1
- package/lib/umd/ui-react-dom.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-indexed-db.js +1 -0
- package/lib/umd-es6/persisters/persister-indexed-db.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-remote.js +1 -1
- package/lib/umd-es6/persisters/persister-remote.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-yjs.js +1 -1
- package/lib/umd-es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom-debug.js +1 -1
- package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom.js +1 -1
- package/lib/umd-es6/ui-react-dom.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +29 -27
- package/readme.md +13 -13
package/lib/tools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t="tinybase",l="",a=",",n=e(l),o=e(!0),d=e(0),s="type",r="default",I="Listener",$="get",c="add",u="Ids",i="Table",p=i+"s",b=i+u,C="Row",h=C+u,m="Sorted"+C+u,g="Cell",f=g+u,w="Value",y=w+"s",T=w+u,v=isFinite,V=(e,t)=>e instanceof t,x=e=>null==e,R=e=>e==n||e==o,k=t=>e(t)==n,S=e=>Array.isArray(e),A=t=>{const l=e(t);return R(l)||l==d&&v(t)?l:void 0},P=(e,t)=>e.every(t),E=(e,t)=>e.sort(t),D=(e,t)=>e.forEach(t),O=(e,t=l)=>e.join(t),N=(e,t)=>e.map(t),G=e=>e.length,L=(e,t)=>e.filter(t),j=(e,...t)=>e.push(...t),M=e=>e.pop(),J=(e,...t)=>e.unshift(...t),z=e=>e.shift(),W=Object,B=W.keys,F=W.freeze,U=e=>V(e,W)&&e.constructor==W,_=(e,t)=>N(W.entries(e),(([e,l])=>t(l,e))),Z=e=>G(B(e)),H=e=>U(e)&&0==Z(e),Q=(e,t)=>e?.has(t)??!1,q=e=>[...e?.values()??[]],K=(e,t)=>e?.forEach(t),X=(e,t)=>e?.delete(t),Y=e=>new Map(e),ee=(e,t)=>e?.get(t),te=(e,t)=>K(e,((e,l)=>t(l,e))),le=(e,t)=>N([...e?.entries()??[]],(([e,l])=>t(l,e))),ae=(e,t,l)=>x(l)?(X(e,t),e):e?.set(t,l),ne=(e,t,l)=>(Q(e,t)||ae(e,t,l()),ee(e,t)),oe=e=>e.toUpperCase(),de=e=>e.toLowerCase(),se="a ",re="A function for",Ie=", and registers a listener so that any changes to that result will cause a re-render",$e="Callback",ce="Del",ue="Deps",ie=ue+"?: React.DependencyList",pe="doRollback?: DoRollback",be="actions: () => Return, "+pe,Ce="export",he="Id",me="Invalid",ge="Json",fe=de(I),we="?: ",ye=" | undefined",Te="NonNullable",ve="Partial",Ve="Props",xe="Provider",Re=`Registers a ${fe} that will be called`,ke="Represents",Se="rowId: "+he,Ae="Schema",Pe="Set",Ee=", descending?: boolean, offset?: number, limit?: number",De="[]",Oe="the Store",Ne="Transaction",Ge=Ne+"Changes",Le=de(Ne),je="Execute a "+Le+" to make multiple mutations",Me="Explicitly starts a "+Le,Je="Explicitly finishes a "+Le,ze="the end of the "+Le,We="void",Be=" => "+We,Fe="WhenSet",Ue=" when setting it",_e=se+"string serialization of",Ze=" ",He="Gets a callback that can ",Qe="the ",qe=" the schema for",Ke=(e=0,t=0)=>`the ${bt[e]}content of`+(t?Ze+Oe:l),Xe=(e=0,t,a=0)=>ut[t]+Ze+Ke(e,1)+(a?" when setting it":l),Ye=(e,t=0)=>ke+` a Row when ${t?"s":"g"}etting ${Ke()} the '${e}' `+i,et=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,tt=(e,t)=>`Calls a function for each ${e} in `+t,lt=e=>"The props passed to a component that renders "+e,at=e=>"A function that takes "+e,nt=(e,t=0)=>re+" listening to changes to "+pt[e]+" in "+pt[t],ot=(e,t,a=0)=>Re+" whenever "+pt[e]+" in "+pt[t]+" change"+(a?l:"s"),dt=e=>`the '${e}' `+i,st=e=>"the specified Row in "+dt(e),rt=(e,t=0)=>ut[t]+` ${Ke()} `+dt(e),It=(e,t=0)=>ut[t]+` ${Ke()} `+st(e),$t=(e,t,l=0)=>ut[l]+` the '${t}' Cell for `+st(e),ct=(e,t=0)=>ut[t]+` the '${e}' Value`,ut=["Gets","Checks existence of","Sets","Deletes","Sets part of",ke,"Gets "+_e,"Sets "+_e,Re+" whenever",He+"set",He+"add",He+"set part of",He+"delete","Renders","Gets "+_e+qe,"Sets"+qe,"Deletes"+qe],it=[$,"has","set","del","set","forEach",c,l],pt=[Oe,p,Qe+i+Ze+u,se+i,Qe+C+Ze+u,se+C,Qe+g+Ze+u,se+g,"invalid Cell changes",y,Qe+w+Ze+u,se+w,"invalid Value changes",Qe+"sorted "+C+Ze+u,Qe+g+Ze+u+" anywhere",Qe+"number of Rows"],bt=[l,"tabular ","keyed value "],Ct=e=>new Set(S(e)||x(e)?e:[e]),ht=(e,t)=>e?.add(t),mt=/[^A-Za-z]+/,gt=/[^A-Za-z0-9]+/,ft=/^( *)\/\*\* *(.*?) *\*\/$/gm,wt=(e,t,l)=>e.substring(t,l),yt=e=>e.includes(a),Tt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return Q(e,n)?Tt(e,t,l,a+1):(ae(e,n,l),n)},vt=e=>e.replace(ft,((e,t,l)=>{const a=77-Vt(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Vt=e=>e.length,xt=e=>e.flat(1e3),Rt=(e,t=0)=>O(N(e.split(gt),((e,l)=>(l>0||t?oe:de)(wt(e,0,1))+wt(e,1)))),kt=e=>oe(O((e&&!mt.test(e[0])?e:" "+e).split(gt),"_")),St=e=>`/** ${e}. */`,At=(...e)=>O(L(e,(e=>e)),", "),Pt=(...e)=>"{"+O(e,"; ")+"}",Et=(...e)=>Pt(...N(e,(e=>"readonly "+e))),Dt=()=>{const e=[Y(),Y(),Y(),Y()],t=Y(),a=Y(),n=e=>{const t=e.indexOf(" as ");return-1!=t?e.substring(t+4):e};return[(...e)=>O(xt(e),"\n"),(t,l,...a)=>D(a,(a=>D([0,1],(n=>(t??n)==n?ht(ne(e[n],l,Ct),a):0)))),(e,a,n,o=l,d=1)=>Tt(t,e,[a,n,o,d]),(e,t,l)=>Tt(a,e,S(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>ee(a,e)===t?e:Tt(a,e,t),(t=0)=>N([...E(le(e[t],((e,t)=>`import {${O(E(q(e),((e,t)=>n(e)>n(t)?1:-1)),", ")}} from '${t}';`)),((e,t)=>yt(e)!=yt(t)?yt(e)?-1:1:e>t?1:-1)),l],(e=>e.replace("{React}","React"))),()=>le(t,(([e,t,a,n],o)=>[St(t),`${n?Ce+" ":l}type ${o}${a} = ${e};`,l])),()=>le(a,((e,t)=>(e=S(e)?e:[e],j(e,M(e)+";"),[`const ${t} = ${z(e)}`,e,l])))]},Ot=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Nt=(e,t,l)=>[t=>_(e,((e,a)=>t(a,Rt(a,1),l(kt(a),`'${a}'`)))),(t,a)=>_(e[t],((e,t)=>a(t,e[s],e[r],l(kt(t),`'${t}'`),Rt(t,1)))),e=>_(t,((t,a)=>e(a,t[s],t[r],l(kt(a),`'${a}'`),Rt(a,1))))],Gt=(e,t,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(p,Pt(...t((e=>`'${e}'?: {[rowId: Id]: `+Pt(...a(e,((e,t,a)=>`'${e}'${x(a)?"?":l}: ${t}`)))+"}"))),Xe(1,5)),r=e(p+Fe,Pt(...t((e=>`'${e}'?: {[rowId: Id]: `+Pt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Xe(1,5,1)),$=e(i+he,"keyof "+s,"A "+i+" Id in "+Oe),c=`<TId extends ${$}>`,u=e(i,Te+`<${s}[TId]>`,"A "+i+" in "+Oe,c),w=e(i+Fe,Te+`<${r}[TId]>`,"A "+i+" in "+Oe+Ue,c),y=e(C,u+"<TId>[Id]","A "+C+" in a "+i,c),T=e(C+Fe,w+"<TId>[Id]","A "+C+" in a "+i+Ue,c),v=e(g+he,`Extract<keyof ${y}<TId>, Id>`,"A "+g+" Id in a "+C,c),V=e(g,Te+`<${s}[TId]>[Id][CId]`,"A "+g+" in a "+C,`<TId extends ${$}, CId extends ${v}<TId>>`),R=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,g+" Ids and types in a "+C,`<TId extends ${$}, CId = ${v}<TId>>`,0),k=e(g+$e,`(...[cellId, cell]: ${R}<TId>)`+Be,at(se+g+" Id, and "+g),c),S=e(C+$e,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Be+") "+Be,at(se+C+" Id, and a "+g+" iterator"),c),A=e(i+g+$e,`(cellId: ${v}<TId>, count: number) `+Be,at(se+g+" Id, and count of how many times it appears"),c),P=e("TableIdForEachRowArray",`TId extends ${$} ? [tableId: TId, forEachRow: (rowCallback: ${S}<TId>)${Be}] : never`,i+" Ids and callback types",`<TId = ${$}>`,0),E=e(i+$e,`(...[tableId, forEachRow]: ${P})`+Be,at(se+i+" Id, and a "+C+" iterator"),l),D=e("TableIdRowIdCellIdArray",`TId extends ${$} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${$}>`,0),O=e("GetCellChange",`(...[tableId, rowId, cellId]: ${D}) => CellChange`,re+" returning information about any Cell's changes during a "+Le),N=e(p+I,`(${d}, getCellChange: ${O}${ye})`+Be,nt(1)),G=e(b+I,`(${d})`+Be,nt(2)),L=e(i+I,`(${d}, tableId: ${$}, getCellChange: ${O}${ye})`+Be,nt(3)),j=e(i+f+I,`(${d}, tableId: ${$})`+Be,nt(14,3)),M=e(C+"Count"+I,`(${d}, tableId: ${$})`+Be,nt(15,3)),J=e(h+I,`(${d}, tableId: ${$})`+Be,nt(4,3)),z=e(m+I,"("+At(d,"tableId: "+$,"cellId: Id"+ye,"descending: boolean","offset: number","limit: number"+ye,"sortedRowIds: Ids")+")"+Be,nt(13,3)),W=e(C+I,"("+At(""+d,"tableId: "+$,Se,`getCellChange: ${O}${ye}`)+")"+Be,nt(5,3)),B=e(f+I,"("+At(""+d,"tableId: "+$,Se)+")"+Be,nt(6,5)),F=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${Se}, cellId: CId, newCell: ${V}<TId, CId> ${ye}, oldCell: ${V}<TId, CId> ${ye}, getCellChange: ${O} ${ye}] : never`,"Cell args for CellListener",`<TId extends ${$}, CId = ${v}<TId>>`,0),U=e("CellListenerArgsArrayOuter",`TId extends ${$} ? `+F+"<TId> : never","Table args for CellListener",`<TId = ${$}>`,0);return[s,r,$,u,w,y,T,v,V,k,S,A,E,N,G,L,j,M,J,z,W,B,e(g+I,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U})`+Be,nt(7,5)),e(me+g+I,`(${d}, tableId: Id, ${Se}, cellId: Id, invalidCells: any[])`+Be,nt(8))]},(t,a)=>{const o=t+": "+a,d=e(y,Pt(...n(((e,t,a)=>`'${e}'${x(a)?"?":l}: ${t}`))),Xe(2,5)),s=e(y+Fe,Pt(...n(((e,t)=>`'${e}'?: ${t}`))),Xe(2,5,1)),r=e(w+he,"keyof "+d,"A "+w+" Id in "+Oe),$=e(w,Te+`<${d}[VId]>`,"A "+w+" Id in "+Oe,`<VId extends ${r}>`),c=e("ValueIdValueArray",`VId extends ${r} ? [valueId: VId, value: ${$}<VId>] : never`,w+" Ids and types in "+Oe,`<VId = ${r}>`,0),u=e(w+$e,`(...[valueId, value]: ${c})`+Be,at(se+w+" Id, and "+w)),i=e("GetValueChange",`(valueId: ${r}) => ValueChange`,re+" returning information about any Value's changes during a "+Le),p=e(y+I,`(${o}, getValueChange: ${i}${ye})`+Be,nt(9)),b=e(T+I,`(${o})`+Be,nt(10)),C=e("ValueListenerArgsArray",`VId extends ${r} ? [${o}, valueId: VId, newValue: ${$}<VId> ${ye}, oldValue: ${$}<VId> ${ye}, getValueChange: ${i} ${ye}] : never`,"Value args for ValueListener",`<VId = ${r}>`,0);return[d,s,r,$,u,p,b,e(w+I,`(...[${t}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Be,nt(11)),e(me+w+I,`(${o}, valueId: Id, invalidValues: any[])`+Be,nt(12))]},(t,l)=>e(Ne+I,`(${t}: ${l}, getTransactionChanges: GetTransactionChanges, getTransactionLog: GetTransactionLog)`+Be,re+" listening to the completion of a "+Le)],Lt=(e,t=l,a=l)=>`store.${e}(${t})`+(a?" as "+a:l),jt=(e,t=l)=>`fluent(() => ${Lt(e,t)})`,Mt=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(listener)${a?", "+a:l})`,Jt=(e,a,n)=>{const[d,$,v,V,R,S,A,P]=Dt(),[E,N,G]=Nt(e,a,R),[L,M,z]=Gt(v,E,N,G),W=Y(),B=(e=0)=>le(W,(([t,a,n,o,d],s)=>{const r=e?[s+`: ${d}(${t}): ${a} => ${n},`]:[s+d+`(${t}): ${a};`];return e||J(r,St(o)),j(r,l),r})),F=(e,t,a,n,o,d=l)=>Tt(W,e,[t,a,n,o,d]),U=(e,t,a,n,o,d=l,s=l,r=l)=>F(it[e]+t+(4==e?ve:l)+a,d,n,(n==Q?jt:Lt)(it[e]+(4==e?ve:l)+a,s,e?void 0:n),o,r),_=(e,t,a,n=l,o=l,d=1,s=l)=>F(c+e+I,(n?n+", ":l)+fe+": "+t+(d?", mutator?: boolean":l),he,Mt(c+e+I,o,d?"mutator":l),a,s),Z=`./${Rt(n)}.d`,Q=Rt(n,1),K=Rt(Q),X=[],ne=Y();let oe=[],de=[];if($(1,Z,Q,`create${Q} as create${Q}Decl`),H(e))$(null,t,p);else{$(0,t,"CellChange"),$(null,t,u);const[e,a,n,d,I,c,w,y,T,V,S,A,P,G,M,J,z,W,B,F,H,te,le,de]=L(K,Q),se=Y();E(((e,t)=>{const l=`<'${e}'>`,a=[v(t+i,d+l,ke+` the '${e}' `+i),v(t+i+Fe,I+l,ke+` the '${e}' `+i+Ue),v(t+C,c+l,Ye(e)),v(t+C+Fe,w+l,Ye(e,1)),v(t+g+he,y+l,`A Cell Id for the '${e}' `+i),v(t+g+$e,V+l,at(`a Cell Id and value from a Row in the '${e}' `+i)),v(t+C+$e,S+l,at(`a Row Id from the '${e}' Table, and a Cell iterator`)),v(t+i+g+$e,A+l,at(`a Cell Id from anywhere in the '${e}' Table, and a count of how many times it appears`))];ae(se,e,a),$(1,Z,...a)})),$(1,Z,e,a,n,y,P,G,M,J,z,W,B,F,H,te,le,de),oe=[e,a,n,y,G,M,J,z,W,B,F,H,te,le,se],D([[e],[o],[Q,"tables: "+a,"tables"],[Q]],(([e,t,a],n)=>U(n,l,p,e,Xe(1,n),t,a))),U(0,l,b,n+De,et(i,Oe)),U(5,l,i,We,tt(i,Oe),"tableCallback: "+P,"tableCallback as any"),E(((e,t,a)=>{const[n,d,s,r,I,$,c,p]=ee(se,e);D([[n],[o],[Q,"table: "+d,", table"],[Q]],(([n,o,d=l],s)=>U(s,t,i,n,rt(e,s),o,a+d))),U(0,t,i+f,u,et(g,"the whole of "+dt(e)),l,a),U(5,t,i+g,We,tt(i+g,"the whole of "+dt(e)),"tableCellCallback: "+p,a+", tableCellCallback as any"),U(0,t,C+"Count","number","Gets the number of Rows in the "+dt(e),l,a),U(0,t,h,u,et(C,dt(e)),l,a),U(0,t,m,u,et(C,dt(e),1),"cellId?: "+I+Ee,a+", cellId, descending, offset, limit"),U(5,t,C,We,tt(C,dt(e)),"rowCallback: "+c,a+", rowCallback as any"),D([[s],[o],[Q,", row: "+r,", row"],[Q],[Q,", partialRow: "+r,", partialRow"]],(([n,o=l,d=l],s)=>U(s,t,C,n,It(e,s),Se+o,a+", rowId"+d))),U(6,t,C,he+ye,"Add a new Row to "+dt(e),"row: "+r+", reuseIds?: boolean",a+", row, reuseIds"),U(0,t,f,I+De,et(g,st(e)),Se,a+", rowId"),U(5,t,g,We,tt(g,st(e)),Se+", cellCallback: "+$,a+", rowId, cellCallback as any"),N(e,((n,d,s,r,I)=>{const $="Map"+Rt(d,1);ae(ne,d,$);const c=d+(x(s)?ye:l);D([[c],[o],[Q,`, cell: ${d} | `+$,", cell as any"],[Q]],(([o,d=l,s=l],$)=>U($,t+I,g,o,$t(e,n,$),Se+d,a+", rowId, "+r+s))),U(1,t+I,i+g,o,ut[1]+` the '${n}' Cell anywhere in `+dt(e),l,a+", "+r)}))})),U(0,l,p+ge,ge,Xe(1,6)),U(2,l,p+ge,Q,Xe(1,7),"tablesJson: "+ge,"tables"+ge),_(p,G,Xe(1,8)+" changes"),_(b,M,ot(2,0,1)),_(i,J,ot(3,0),`tableId: ${n} | null`,"tableId"),_(i+f,z,ot(14,3,1),`tableId: ${n} | null`,"tableId"),_(C+"Count",W,ot(15,3),`tableId: ${n} | null`,"tableId"),_(h,B,ot(4,3,1),`tableId: ${n} | null`,"tableId"),_(m,F,ot(13,3,1),At("tableId: TId",`cellId: ${y}<TId>`+ye,"descending: boolean","offset: number","limit: number"+ye),At("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),_(C,H,ot(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),_(f,te,ot(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),_(g,le,ot(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${O(E((e=>ee(se,e)?.[4]??l))," | ")} | null`,"tableId, rowId, cellId"),_(me+g,de,Re+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),$(1,Z,...q(ne)),j(X,".set"+p+Ae+"({",xt(E(((e,t,a)=>[`[${a}]: {`,...N(e,((e,t,a,n)=>`[${n}]: {[${R(kt(s),`'${s}'`)}]: ${R(kt(t),`'${t}'`)}${x(a)?l:`, [${R(kt(r),`'${r}'`)}]: `+(k(a)?R(kt(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(H(a))$(null,t,y);else{const[e,a,n,d,I,c,u,i,p]=M(K,Q);$(1,Z,e,a,n,I,c,u,i,p),de=[e,a,n,c,u,i],D([[e],[o],[Q,"values: "+a,"values"],[Q],[Q,"partialValues: "+a,"partialValues"]],(([e,t,a],n)=>U(n,l,y,e,Xe(2,n),t,a))),U(0,l,T,n+De,et(w,Oe)),U(5,l,w,"void",tt(w,Oe),"valueCallback: "+I,"valueCallback as any"),G(((e,t,a,n,d)=>{const s="Map"+Rt(t,1);ae(ne,t,s),D([[t],[o],[Q,`value: ${t} | `+s,", value as any"],[Q]],(([t,a,o=l],s)=>U(s,d,w,t,ct(e,s),a,n+o)))})),U(0,l,y+ge,ge,Xe(2,6)),U(2,l,y+ge,Q,Xe(2,7),"valuesJson: "+ge,"values"+ge),_(y,c,Xe(2,8)+" changes"),_(T,u,ot(10,0,1)),_(w,i,ot(11,0),`valueId: ${n} | null`,"valueId"),_(me+w,p,Re+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),$(1,Z,...q(ne)),$(0,t,"ValueChange"),j(X,".set"+y+Ae+"({",G(((e,t,a,n)=>[`[${n}]: {[${R(kt(s),`'${s}'`)}]: ${R(kt(t),`'${t}'`)}${x(a)?l:`, [${R(kt(r),`'${r}'`)}]: `+(k(a)?R(kt(a),`'${a}'`):a)}},`])),"})")}U(0,l,"Content",`[${p}, ${y}]`,Xe(0,0)),U(2,l,"Content",Q,Xe(0,2),`[tables, values]: [${p}, ${y}]`,"[tables, values]"),U(2,l,Ge,Q,`Applies a set of ${Ge} to the Store`,"transactionChanges: "+Ge,"transactionChanges"),te(ne,((e,t)=>v(t,`(cell: ${e}${ye}) => `+e,`Takes a ${e} Cell value and returns another`))),$(null,t,"DoRollback",he,"IdOrNull",ge,"Store",Ge),$(0,t,"Get"+Ge,"GetTransactionLog"),U(0,l,ge,ge,Xe(0,6)),U(2,l,ge,Q,Xe(0,7),"tablesAndValuesJson: "+ge,"tablesAndValuesJson"),U(7,l,Le,"Return",je,be,"actions, doRollback","<Return>"),U(7,l,"start"+Ne,Q,Me),U(7,l,"finish"+Ne,Q,Je,pe,"doRollback");const se=z(K,Q);return _("Start"+Ne,se,Re+" just before the start of the "+Le,l,l,0),_("WillFinish"+Ne,se,Re+" just before "+ze,l,l,0),_("DidFinish"+Ne,se,Re+" just after "+ze,l,l,0),U(7,l,"call"+I,Q,"Manually provoke a listener to be called","listenerId: Id","listenerId"),U(3,l,I,Q,"Remove a listener that was previously added to "+Oe,"listenerId: Id","listenerId"),F("getStore",l,"Store","store",ut[0]+" the underlying Store object"),$(1,t,"createStore"),$(1,Z,Q,`create${Q} as create${Q}Decl`,se),R("store",["createStore()",...X]),V("fluent","actions: () => Store",["actions();",`return ${K};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${K}, ...params)`),R(K,["{",...B(1),"}"]),[d(...S(0),...A(),Ce+" interface "+Q+" {",...B(0),"}",l,St(`Creates a ${Q} object`),Ce+" function create"+Q+"(): "+Q+";"),d(...S(1),Ce+" const create"+Q+": typeof create"+Q+"Decl = () => {",...P(),`return Object.freeze(${K});`,"};"),oe,de]},zt=e=>$+e,Wt=e=>At(zt(e),zt(e)+ue),Bt="debugIds?: boolean",Ft="debugIds={debugIds}",Ut="then"+ie,_t="Parameter",Zt=": (parameter: "+_t+", store: Store) => ",Ht="const contextValue = useContext(Context);",Qt=", based on a parameter",qt=": ",Kt="<"+_t+",>",Xt=_t+"ized"+$e+"<"+_t+">",Yt="rowId",el="rowId={rowId}",tl=", separator, debugIds",ll="separator?: ReactElement | string",al="then?: (store: Store",nl=At(al+")"+Be,Ut),ol="then, then"+ue,dl=Yt+qt+he,sl="View",rl=(e,...t)=>At(...t,fe+": "+e,fe+ie,"mutator?: boolean"),Il=(...e)=>At(...e,fe,fe+ue,"mutator"),$l=(e,a,n,o,d)=>{const[s,r,$,c,v,V,R,k]=Dt(),[S,A,P]=Nt(e,a,v),E=`./${Rt(n)}.d`,D=`./${Rt(n)}-ui-react.d`,N="tinybase/ui-react",G=Rt(n,1),L=Rt(G),M=G+"Or"+G+he,z=L+"Or"+G+he,W=L+`={${L}}`,B=Y(),F=(e,t,a,n,o,d=l)=>(r(1,D,e+" as "+e+"Decl"),Tt(B,e,[t,a,n,o,d])),U=(e,t,a,n,o,d=l)=>F("use"+e,t,a,n,o,d),_=(e,t,a,n,o=l,d=l,s=l,I=l,$=l)=>(r(1,N,`use${t} as use${t}Core`),U(e,At(o,X,I),a,ae+`(${z}, use${t}Core, [`+(d||l)+($?"], ["+$:l)+"]);",n,s)),Z=(e,t,l,a)=>F(e,t,1,l,a),Q=(e=0)=>le(B,(([t,a,n,o,d],s)=>{const r=e?[Ce+` const ${s}: typeof ${s}Decl = ${d}(${t}): ${1==a?"any":a} =>`,n]:[Ce+` function ${s}${d}(${t}): ${1==a?"ComponentReturnType":a};`];return e||J(r,St(o)),j(r,l),r}));r(null,t,he,"Store",$e,_t+"ized"+$e),r(0,N,"ComponentReturnType"),r(1,N,"useCellIds"),r(null,N,"ExtraProps"),r(0,E,G);const q=$(M,G+" | "+he,`Used when you need to refer to a ${G} in a React hook or component`),K=$(xe+Ve,Et(L+we+G,L+`ById?: {[${L}Id: Id]: ${G}}`),`Used with the ${xe} component, so that a `+G+" can be passed into the context of an application");r(0,"react","ReactElement","ComponentType"),r(1,"react","React"),r(1,D,q,K);const X=z+we+q;v("{createContext, useContext, useMemo}","React"),v("Context",`createContext<[${G}?, {[${L}Id: Id]: ${G}}?]>([])`),U("Create"+G,`create: () => ${G}, create`+ie,G,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${G} within a React application with convenient memoization`);const te=U(G,"id?: Id",G+ye,["{",Ht,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${G} from within a ${xe} component context`),ae=c("useHook",z+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${L} = ${te}(${z} as Id);`,`return hook(...preParams, ((${z} == null || typeof ${z} == 'string')`,`? ${L} : ${z})?.getStore(), ...postParams)`]),ne=c("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),oe=c("wrap",At("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;"]),de=c("useCustomOrDefaultCellIds",At("customCellIds: Ids | undefined","tableId: Id","rowId: Id",`${z}?: ${q} | undefined`),[`const defaultCellIds = ${ae}(${z}, useCellIds, [tableId, rowId]);`,"return customCellIds ?? defaultCellIds;"]),re=v("NullComponent","() => null");if(!H(e)){const[e,a,n,d,s,w,y,T,v,V,R,k,P,N,j]=o;r(null,E,e,a,n,s,w,y,T,v,V,R,k,P,N),r(0,E,d),r(1,E,G),r(null,t,u,"IdOrNull");const M=c("tableView",`{${L}, rowComponent, getRowComponentProps, customCellIds`+tl+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${oe}(rowIds.map((rowId) => (`,"<Row","{..."+ne+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",el,"customCellIds={customCellIds}",W,Ft,"/>","))",tl,", tableId,",");"]),J=c("getDefaultTableComponent","tableId: Id",O(S(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+re),z=c("getDefaultCellComponent","tableId: Id, cellId: Id",O(S(((e,t,l)=>`tableId == ${l} ? ${O(A(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+re} : `)))+re);_(p,p,e,Xe(1,0)+Ie);const B=_(b,b,n+De,et(i,Oe)+Ie);_(Pe+p+$e,Pe+p+$e,Xt,Xe(1,9)+Qt,At(zt(p)+Zt+a,zt(p)+ie),Wt(p),Kt,At(al,`tables: ${a})`+Be,Ut),ol),_(ce+p+$e,ce+p+$e,$e,Xe(1,12),l,l,l,nl,ol);const F=$(g+Ve,Et("tableId?: TId","rowId: Id","cellId?: CId",L+we+G,Bt),lt(se+g),`<TId extends ${n}, CId extends ${d}<TId>>`),U=$(C+Ve,Et("tableId?: TId","rowId: Id",L+we+G,"cellComponents?: {readonly [CId in "+d+`<TId>]?: ComponentType<${F}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${d}<TId>) => ExtraProps`,`customCellIds?: ${d}<TId>[]`,ll,Bt),lt(se+C),`<TId extends ${n}>`),H=$(i+Ve,Et("tableId?: TId",L+we+G,`rowComponent?: ComponentType<${U}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps","customCellIds?: CellId<TId>[]",ll,Bt),lt(se+i),`<TId extends ${n}>`),Q=$("Sorted"+i+Ve,Et("tableId?: TId","cellId?: "+d+"<TId>","descending?: boolean","offset?: number","limit?: number",L+we+G,`rowComponent?: ComponentType<${U}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps","customCellIds?: CellId<TId>[]",ll,Bt),lt(se+"sorted "+i),`<TId extends ${n}>`),q=$(p+Ve,Et(L+we+G,"tableComponents?: {readonly [TId in "+n+`]?: ComponentType<${H}<TId>>;}`,`getTableComponentProps?: (tableId: ${n}) => ExtraProps`,ll,Bt),lt(Ke(1,1)));r(1,D,q,H,Q,U,F),Z(p+sl,"{"+L+", tableComponents, getTableComponentProps"+tl+"}: "+q,[oe+`(${B}(${L}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+J+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${ne}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",W,Ft,"/>;","}), separator)"],Xe(1,13)+Ie),S(((e,t,a)=>{const[n,o,d,s,I]=ee(j,e);r(null,E,n,o,d,s,I),_(t+i,i,n,rt(e)+Ie,l,a),_(t+i+f,i+f,u,et(g,"the whole of "+dt(e))+Ie,l,a);const $=_(t+h,h,u,et(C,dt(e))+Ie,l,a),c=_(t+m,m,u,et(C,dt(e),1)+Ie,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");_(t+C,C,d,It(e)+Ie,dl,At(a,Yt)),_(t+f,f,I+De,et(g,st(e))+Ie,dl,At(a,Yt)),_(Pe+t+i+$e,Pe+i+$e,Xt,rt(e,9)+Qt,At(zt(i)+Zt+o,zt(i)+ie),At(a,Wt(i)),Kt,At(al,`table: ${o})`+Be,Ut),ol),_(ce+t+i+$e,ce+i+$e,$e,rt(e,12),l,a,l,nl,ol),_(Pe+t+C+$e,Pe+C+$e,Xt,It(e,9)+Qt,At(dl,zt(C)+Zt+s,zt(C)+ie),At(a,Yt,Wt(C)),Kt,At(al,`row: ${s})`+Be,Ut),ol),_("Add"+t+C+$e,"Add"+C+$e,Xt,It(e,10)+Qt,At(zt(C)+Zt+s,zt(C)+ie),At(a,Wt(C)),Kt,"then?: ("+At(dl+ye,"store: Store","row: "+s+")"+Be,"then"+ie)+", reuseRowIds?: boolean",ol+", reuseRowIds"),_(Pe+t+ve+C+$e,Pe+ve+C+$e,Xt,It(e,11)+Qt,At(dl,zt(ve+C)+Zt+s,zt(ve+C)+ie),At(a,Yt,Wt(ve+C)),Kt,At(al,`partialRow: ${s})`+Be,Ut),ol),_(ce+t+C+$e,ce+C+$e,$e,It(e,12),dl,At(a,Yt),l,nl,ol);const p=Z(t+C+sl,"{rowId, "+L+", cellComponents, getCellComponentProps, customCellIds"+tl+`}: ${U}<'${e}'>`,[oe+`(${de}(customCellIds, `+a+`, rowId, ${L}).map((cellId: ${I}) => {`,"const Cell = (cellComponents?.[cellId] ?? "+z+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${ne}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,el,"cellId={cellId}",W,Ft,"/>;","})"+tl+", rowId)"],It(e,13)+Ie);Z(t+"Sorted"+i+sl,"{cellId, descending, offset, limit, ...props}: "+Q+`<'${e}'>`,M+"(props, "+c+`(cellId, descending, offset, limit, props.${L}), ${a}, ${p});`,rt(e,13)+", sorted"+Ie),Z(t+i+sl,`props: ${H}<'${e}'>`,M+"(props, "+$+`(props.${L}), ${a}, ${p});`,rt(e,13)+Ie),A(e,((n,o,d,s,I)=>{const $="Map"+Rt(o,1);r(0,E,$),r(1,E,$);const c=_(t+I+g,g,o+(x(d)?ye:l),$t(e,n)+Ie,dl,At(a,Yt,s));_(Pe+t+I+g+$e,Pe+g+$e,Xt,$t(e,n,9)+Qt,At(dl,zt(g)+Zt+o+" | "+$,zt(g)+ie),At(a,Yt,s,Wt(g)),Kt,At(al,`cell: ${o} | ${$})`+Be,Ut),ol),_(ce+t+I+g+$e,ce+g+$e,$e,$t(e,n,12),At(dl,"forceDel?: boolean"),At(a,Yt,s,"forceDel"),l,nl,ol),Z(t+I+g+sl,`{rowId, ${L}, debugIds}: `+F+`<'${e}', '${n}'>`,[oe+`('' + ${c}(rowId, `+L+`) ?? '', undefined, debugIds, ${s})`],$t(e,n,13)+Ie)}))}));const K=O(S((e=>ee(j,e)?.[4]??l))," | ");_(p+I,p+I,We,Xe(1,8)+" changes",rl(s),Il()),_(b+I,b+I,We,ot(2,0,1),rl(w),Il()),_(i+I,i+I,We,ot(3,0),rl(y,`tableId: ${n} | null`),Il("tableId")),_(i+f+I,i+f+I,We,ot(14,3,1),rl(T,`tableId: ${n} | null`),Il("tableId")),_(h+I,h+I,We,ot(4,3,1),rl(V,`tableId: ${n} | null`),Il("tableId")),_(m+I,m+I,We,ot(13,3,1),rl(R,`tableId: ${n} | null`,"cellId: "+K+ye,"descending: boolean","offset: number","limit: number"+ye),Il("tableId","cellId","descending","offset","limit")),_(C+I,C+I,We,ot(5,3),rl(k,`tableId: ${n} | null`,Yt+": IdOrNull"),Il("tableId",Yt)),_(f+I,f+I,We,ot(6,5,1),rl(P,`tableId: ${n} | null`,Yt+": IdOrNull"),Il("tableId",Yt)),_(g+I,g+I,We,ot(7,5),rl(N,`tableId: ${n} | null`,Yt+": IdOrNull",`cellId: ${K} | null`),Il("tableId",Yt,"cellId"))}if(!H(a)){const[e,t,a,n,o,s]=d;r(null,E,...d),r(1,E,G);const u=c("getDefaultValueComponent","valueId: Id",O(P(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+re);_(y,y,e,Xe(2,0)+Ie);const i=_(T,T,a+De,et(w,Oe)+Ie);_(Pe+y+$e,Pe+y+$e,Xt,Xe(2,9)+Qt,At(zt(y)+Zt+t,zt(y)+ie),Wt(y),Kt,At(al,`values: ${t})`+Be,Ut),ol),_(Pe+ve+y+$e,Pe+ve+y+$e,Xt,Xe(2,11)+Qt,At(zt(ve+y)+Zt+t,zt(ve+y)+ie),Wt(ve+y),Kt,At(al,`partialValues: ${t})`+Be,Ut),ol),_(ce+y+$e,ce+y+$e,$e,Xe(2,12),l,l,l,nl,ol);const p=$(w+Ve,Et("valueId?: VId",L+we+G,Bt),lt("a Value"),`<VId extends ${a}>`),b=$(y+Ve,Et(L+we+G,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${p}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,ll,Bt),lt(Ke(2,1)));r(1,D,b,p),Z(y+sl,"{"+L+", valueComponents, getValueComponentProps"+tl+"}: "+b,[oe+`(${i}(${L}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+u+"(valueId);","return <Value",`{...${ne}(getValueComponentProps, valueId)}`,"key={valueId}",W,Ft,"/>;","}), separator)"],Xe(2,13)+Ie),P(((e,t,a,n,o)=>{const d="Map"+Rt(t,1);r(0,E,d),r(1,E,d);const s=_(o+w,w,t,ct(e)+Ie,l,n);_(Pe+o+w+$e,Pe+w+$e,Xt,ct(e,9)+Qt,At(zt(w)+Zt+t+" | "+d,zt(w)+ie),At(n,Wt(w)),Kt,At(al,`value: ${t} | ${d})`+Be,Ut),ol),_(ce+o+w+$e,ce+w+$e,$e,ct(e,12),l,n,l,nl,ol),Z(o+w+sl,`{${L}, debugIds}: ${p}<'${e}'>`,[oe+`('' + ${s}(`+L+`) ?? '', undefined, debugIds, ${n})`],ct(e,13)+Ie)})),_(y+I,y+I,We,Xe(2,8)+" changes",rl(n),Il()),_(T+I,T+I,We,ot(10,0,1),rl(o),Il()),_(w+I,w+I,We,ot(11,0),rl(s,`valueId: ${a} | null`),Il("valueId"))}return Z(xe,`{${L}, ${L}ById, children}: `+K+" & {children: React.ReactNode}",["{",Ht,"return (","<Context."+xe,"value={useMemo(",`() => [${L} ?? contextValue[0], {...contextValue[1], ...${L}ById}],`,`[${L}, ${L}ById, contextValue],`,")}>","{children}",`</Context.${xe}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[s(...V(0),...R(),...Q(0)),s(...V(1),...k(),...Q(1))]},cl=(e,t,a)=>{if(H(e)&&H(t))return[l,l,l,l];const[n,o,d,s]=Jt(e,t,a);return[n,o,...$l(e,t,a,d,s)]},ul=JSON.parse,il={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},pl=Ot((e=>{const t=()=>{const t=ul(e.getTablesSchemaJson());return!H(t)||P(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=Y();if(P(a,(t=>P(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=ne(n,a,(()=>[A(o),Y(),[0],0])),[s,r,[I]]=d,$=ne(r,o,(()=>0))+1;return $>I&&(d[2]=[$,o]),ae(r,o,$),d[3]++,s==A(o)})))))return t[l]={},K(n,(([e,,[,n],o],d)=>{t[l][d]={[s]:e,...o==G(a)?{[r]:n}:{}}})),1}))?t:{}},l=()=>{const t=ul(e.getValuesSchemaJson());return H(t)&&e.forEachValue(((e,l)=>{t[e]={[s]:A(l)}})),t},a=e=>cl(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 N(a(e),((e,a)=>vt(l(e,{...il,filepath:"_."+t[a]}))))};return F({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let s=0,r=0;const I={};d(((e,l)=>{s++;let a=0;l((()=>a++)),r+=a,t&&(I[e]={rowCells:a})})),a+=s,n+=r,t&&(o[e]={tableRows:s,tableCells:r,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:G(e.getValueIds()),jsonLength:Vt(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{pl as createTools};
|
|
1
|
+
const e=e=>typeof e,t="tinybase",l="",a=",",n=e(l),o=e(!0),d=e(0),s="type",r="default",I="Listener",c="get",$="add",u="Ids",i="Table",p=i+"s",b=i+u,C="Row",h=C+u,m="Sorted"+C+u,g="Cell",f=g+u,w="Value",y=w+"s",T=w+u,v=Promise,V=isFinite,x=(e,t)=>e instanceof t,R=e=>null==e,k=e=>e==n||e==o,S=t=>e(t)==n,P=e=>Array.isArray(e),A=async e=>v.all(e),E=t=>{const l=e(t);return k(l)||l==d&&V(t)?l:void 0},D=(e,t)=>e.every(t),O=(e,t)=>e.sort(t),N=(e,t)=>e.forEach(t),G=(e,t=l)=>e.join(t),L=(e,t)=>e.map(t),j=e=>e.length,M=(e,t)=>e.filter(t),J=(e,...t)=>e.push(...t),z=e=>e.pop(),W=(e,...t)=>e.unshift(...t),B=e=>e.shift(),F=Object,U=F.keys,_=F.freeze,Z=e=>x(e,F)&&e.constructor==F,H=(e,t)=>L(F.entries(e),(([e,l])=>t(l,e))),Q=e=>j(U(e)),q=e=>Z(e)&&0==Q(e),K=(e,t)=>e?.has(t)??!1,X=e=>[...e?.values()??[]],Y=(e,t)=>e?.forEach(t),ee=(e,t)=>e?.delete(t),te=e=>new Map(e),le=(e,t)=>e?.get(t),ae=(e,t)=>Y(e,((e,l)=>t(l,e))),ne=(e,t)=>L([...e?.entries()??[]],(([e,l])=>t(l,e))),oe=(e,t,l)=>R(l)?(ee(e,t),e):e?.set(t,l),de=(e,t,l)=>(K(e,t)||oe(e,t,l()),le(e,t)),se=e=>e.toUpperCase(),re=e=>e.toLowerCase(),Ie="a ",ce="A function for",$e=", and registers a listener so that any changes to that result will cause a re-render",ue="Callback",ie="Del",pe="Deps",be=pe+"?: React.DependencyList",Ce="doRollback?: DoRollback",he="actions: () => Return, "+Ce,me="export",ge="Id",fe="Invalid",we="Json",ye=re(I),Te="?: ",ve=" | undefined",Ve="NonNullable",xe="Partial",Re="Props",ke="Provider",Se=`Registers a ${ye} that will be called`,Pe="Represents",Ae="rowId: "+ge,Ee="Schema",De="Set",Oe=", descending?: boolean, offset?: number, limit?: number",Ne="[]",Ge="the Store",Le="Transaction",je=Le+"Changes",Me=re(Le),Je="Execute a "+Me+" to make multiple mutations",ze="Explicitly starts a "+Me,We="Explicitly finishes a "+Me,Be="the end of the "+Me,Fe="void",Ue=" => "+Fe,_e="WhenSet",Ze=" when setting it",He=Ie+"string serialization of",Qe=" ",qe="Gets a callback that can ",Ke="the ",Xe=" the schema for",Ye=(e=0,t=0)=>`the ${ht[e]}content of`+(t?Qe+Ge:l),et=(e=0,t,a=0)=>pt[t]+Qe+Ye(e,1)+(a?" when setting it":l),tt=(e,t=0)=>Pe+` a Row when ${t?"s":"g"}etting ${Ye()} the '${e}' `+i,lt=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,at=(e,t)=>`Calls a function for each ${e} in `+t,nt=e=>"The props passed to a component that renders "+e,ot=e=>"A function that takes "+e,dt=(e,t=0)=>ce+" listening to changes to "+Ct[e]+" in "+Ct[t],st=(e,t,a=0)=>Se+" whenever "+Ct[e]+" in "+Ct[t]+" change"+(a?l:"s"),rt=e=>`the '${e}' `+i,It=e=>"the specified Row in "+rt(e),ct=(e,t=0)=>pt[t]+` ${Ye()} `+rt(e),$t=(e,t=0)=>pt[t]+` ${Ye()} `+It(e),ut=(e,t,l=0)=>pt[l]+` the '${t}' Cell for `+It(e),it=(e,t=0)=>pt[t]+` the '${e}' Value`,pt=["Gets","Checks existence of","Sets","Deletes","Sets part of",Pe,"Gets "+He,"Sets "+He,Se+" whenever",qe+"set",qe+"add",qe+"set part of",qe+"delete","Renders","Gets "+He+Xe,"Sets"+Xe,"Deletes"+Xe],bt=[c,"has","set","del","set","forEach",$,l],Ct=[Ge,p,Ke+i+Qe+u,Ie+i,Ke+C+Qe+u,Ie+C,Ke+g+Qe+u,Ie+g,"invalid Cell changes",y,Ke+w+Qe+u,Ie+w,"invalid Value changes",Ke+"sorted "+C+Qe+u,Ke+g+Qe+u+" anywhere",Ke+"number of Rows"],ht=[l,"tabular ","keyed value "],mt=e=>new Set(P(e)||R(e)?e:[e]),gt=(e,t)=>e?.add(t),ft=/[^A-Za-z]+/,wt=/[^A-Za-z0-9]+/,yt=/^( *)\/\*\* *(.*?) *\*\/$/gm,Tt=(e,t,l)=>e.substring(t,l),vt=e=>e.includes(a),Vt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return K(e,n)?Vt(e,t,l,a+1):(oe(e,n,l),n)},xt=e=>e.replace(yt,((e,t,l)=>{const a=77-Rt(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Rt=e=>e.length,kt=e=>e.flat(1e3),St=(e,t=0)=>G(L(e.split(wt),((e,l)=>(l>0||t?se:re)(Tt(e,0,1))+Tt(e,1)))),Pt=e=>se(G((e&&!ft.test(e[0])?e:" "+e).split(wt),"_")),At=e=>`/** ${e}. */`,Et=(...e)=>G(M(e,(e=>e)),", "),Dt=(...e)=>"{"+G(e,"; ")+"}",Ot=(...e)=>Dt(...L(e,(e=>"readonly "+e))),Nt=()=>{const e=[te(),te(),te(),te()],t=te(),a=te(),n=e=>{const t=e.indexOf(" as ");return-1!=t?e.substring(t+4):e};return[(...e)=>G(kt(e),"\n"),(t,l,...a)=>N(a,(a=>N([0,1],(n=>(t??n)==n?gt(de(e[n],l,mt),a):0)))),(e,a,n,o=l,d=1)=>Vt(t,e,[a,n,o,d]),(e,t,l)=>Vt(a,e,P(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>le(a,e)===t?e:Vt(a,e,t),(t=0)=>L([...O(ne(e[t],((e,t)=>`import {${G(O(X(e),((e,t)=>n(e)>n(t)?1:-1)),", ")}} from '${t}';`)),((e,t)=>vt(e)!=vt(t)?vt(e)?-1:1:e>t?1:-1)),l],(e=>e.replace("{React}","React"))),()=>ne(t,(([e,t,a,n],o)=>[At(t),`${n?me+" ":l}type ${o}${a} = ${e};`,l])),()=>ne(a,((e,t)=>(e=P(e)?e:[e],J(e,z(e)+";"),[`const ${t} = ${B(e)}`,e,l])))]},Gt=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Lt=(e,t,l)=>[t=>H(e,((e,a)=>t(a,St(a,1),l(Pt(a),`'${a}'`)))),(t,a)=>H(e[t],((e,t)=>a(t,e[s],e[r],l(Pt(t),`'${t}'`),St(t,1)))),e=>H(t,((t,a)=>e(a,t[s],t[r],l(Pt(a),`'${a}'`),St(a,1))))],jt=(e,t,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(p,Dt(...t((e=>`'${e}'?: {[rowId: Id]: `+Dt(...a(e,((e,t,a)=>`'${e}'${R(a)?"?":l}: ${t}`)))+"}"))),et(1,5)),r=e(p+_e,Dt(...t((e=>`'${e}'?: {[rowId: Id]: `+Dt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),et(1,5,1)),c=e(i+ge,"keyof "+s,"A "+i+" Id in "+Ge),$=`<TId extends ${c}>`,u=e(i,Ve+`<${s}[TId]>`,"A "+i+" in "+Ge,$),w=e(i+_e,Ve+`<${r}[TId]>`,"A "+i+" in "+Ge+Ze,$),y=e(C,u+"<TId>[Id]","A "+C+" in a "+i,$),T=e(C+_e,w+"<TId>[Id]","A "+C+" in a "+i+Ze,$),v=e(g+ge,`Extract<keyof ${y}<TId>, Id>`,"A "+g+" Id in a "+C,$),V=e(g,Ve+`<${s}[TId]>[Id][CId]`,"A "+g+" in a "+C,`<TId extends ${c}, CId extends ${v}<TId>>`),x=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,g+" Ids and types in a "+C,`<TId extends ${c}, CId = ${v}<TId>>`,0),k=e(g+ue,`(...[cellId, cell]: ${x}<TId>)`+Ue,ot(Ie+g+" Id, and "+g),$),S=e(C+ue,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Ue+") "+Ue,ot(Ie+C+" Id, and a "+g+" iterator"),$),P=e(i+g+ue,`(cellId: ${v}<TId>, count: number) `+Ue,ot(Ie+g+" Id, and count of how many times it appears"),$),A=e("TableIdForEachRowArray",`TId extends ${c} ? [tableId: TId, forEachRow: (rowCallback: ${S}<TId>)${Ue}] : never`,i+" Ids and callback types",`<TId = ${c}>`,0),E=e(i+ue,`(...[tableId, forEachRow]: ${A})`+Ue,ot(Ie+i+" Id, and a "+C+" iterator"),l),D=e("TableIdRowIdCellIdArray",`TId extends ${c} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${c}>`,0),O=e("GetCellChange",`(...[tableId, rowId, cellId]: ${D}) => CellChange`,ce+" returning information about any Cell's changes during a "+Me),N=e(p+I,`(${d}, getCellChange: ${O}${ve})`+Ue,dt(1)),G=e(b+I,`(${d})`+Ue,dt(2)),L=e(i+I,`(${d}, tableId: ${c}, getCellChange: ${O}${ve})`+Ue,dt(3)),j=e(i+f+I,`(${d}, tableId: ${c})`+Ue,dt(14,3)),M=e(C+"Count"+I,`(${d}, tableId: ${c})`+Ue,dt(15,3)),J=e(h+I,`(${d}, tableId: ${c})`+Ue,dt(4,3)),z=e(m+I,"("+Et(d,"tableId: "+c,"cellId: Id"+ve,"descending: boolean","offset: number","limit: number"+ve,"sortedRowIds: Ids")+")"+Ue,dt(13,3)),W=e(C+I,"("+Et(""+d,"tableId: "+c,Ae,`getCellChange: ${O}${ve}`)+")"+Ue,dt(5,3)),B=e(f+I,"("+Et(""+d,"tableId: "+c,Ae)+")"+Ue,dt(6,5)),F=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${Ae}, cellId: CId, newCell: ${V}<TId, CId> ${ve}, oldCell: ${V}<TId, CId> ${ve}, getCellChange: ${O} ${ve}] : never`,"Cell args for CellListener",`<TId extends ${c}, CId = ${v}<TId>>`,0),U=e("CellListenerArgsArrayOuter",`TId extends ${c} ? `+F+"<TId> : never","Table args for CellListener",`<TId = ${c}>`,0);return[s,r,c,u,w,y,T,v,V,k,S,P,E,N,G,L,j,M,J,z,W,B,e(g+I,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U})`+Ue,dt(7,5)),e(fe+g+I,`(${d}, tableId: Id, ${Ae}, cellId: Id, invalidCells: any[])`+Ue,dt(8))]},(t,a)=>{const o=t+": "+a,d=e(y,Dt(...n(((e,t,a)=>`'${e}'${R(a)?"?":l}: ${t}`))),et(2,5)),s=e(y+_e,Dt(...n(((e,t)=>`'${e}'?: ${t}`))),et(2,5,1)),r=e(w+ge,"keyof "+d,"A "+w+" Id in "+Ge),c=e(w,Ve+`<${d}[VId]>`,"A "+w+" Id in "+Ge,`<VId extends ${r}>`),$=e("ValueIdValueArray",`VId extends ${r} ? [valueId: VId, value: ${c}<VId>] : never`,w+" Ids and types in "+Ge,`<VId = ${r}>`,0),u=e(w+ue,`(...[valueId, value]: ${$})`+Ue,ot(Ie+w+" Id, and "+w)),i=e("GetValueChange",`(valueId: ${r}) => ValueChange`,ce+" returning information about any Value's changes during a "+Me),p=e(y+I,`(${o}, getValueChange: ${i}${ve})`+Ue,dt(9)),b=e(T+I,`(${o})`+Ue,dt(10)),C=e("ValueListenerArgsArray",`VId extends ${r} ? [${o}, valueId: VId, newValue: ${c}<VId> ${ve}, oldValue: ${c}<VId> ${ve}, getValueChange: ${i} ${ve}] : never`,"Value args for ValueListener",`<VId = ${r}>`,0);return[d,s,r,c,u,p,b,e(w+I,`(...[${t}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Ue,dt(11)),e(fe+w+I,`(${o}, valueId: Id, invalidValues: any[])`+Ue,dt(12))]},(t,l)=>e(Le+I,`(${t}: ${l}, getTransactionChanges: GetTransactionChanges, getTransactionLog: GetTransactionLog)`+Ue,ce+" listening to the completion of a "+Me)],Mt=(e,t=l,a=l)=>`store.${e}(${t})`+(a?" as "+a:l),Jt=(e,t=l)=>`fluent(() => ${Mt(e,t)})`,zt=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(listener)${a?", "+a:l})`,Wt=(e,a,n)=>{const[d,c,v,V,x,k,P,A]=Nt(),[E,D,O]=Lt(e,a,x),[L,j,M]=jt(v,E,D,O),z=te(),B=(e=0)=>ne(z,(([t,a,n,o,d],s)=>{const r=e?[s+`: ${d}(${t}): ${a} => ${n},`]:[s+d+`(${t}): ${a};`];return e||W(r,At(o)),J(r,l),r})),F=(e,t,a,n,o,d=l)=>Vt(z,e,[t,a,n,o,d]),U=(e,t,a,n,o,d=l,s=l,r=l)=>F(bt[e]+t+(4==e?xe:l)+a,d,n,(n==H?Jt:Mt)(bt[e]+(4==e?xe:l)+a,s,e?void 0:n),o,r),_=(e,t,a,n=l,o=l,d=1,s=l)=>F($+e+I,(n?n+", ":l)+ye+": "+t+(d?", mutator?: boolean":l),ge,zt($+e+I,o,d?"mutator":l),a,s),Z=`./${St(n)}.d`,H=St(n,1),Q=St(H),K=[],Y=te();let ee=[],de=[];if(c(1,Z,H,`create${H} as create${H}Decl`),q(e))c(null,t,p);else{c(0,t,"CellChange"),c(null,t,u);const[e,a,n,d,I,$,w,y,T,V,k,P,A,O,j,M,z,W,B,F,q,ae,ne,de]=L(Q,H),se=te();E(((e,t)=>{const l=`<'${e}'>`,a=[v(t+i,d+l,Pe+` the '${e}' `+i),v(t+i+_e,I+l,Pe+` the '${e}' `+i+Ze),v(t+C,$+l,tt(e)),v(t+C+_e,w+l,tt(e,1)),v(t+g+ge,y+l,`A Cell Id for the '${e}' `+i),v(t+g+ue,V+l,ot(`a Cell Id and value from a Row in the '${e}' `+i)),v(t+C+ue,k+l,ot(`a Row Id from the '${e}' Table, and a Cell iterator`)),v(t+i+g+ue,P+l,ot(`a Cell Id from anywhere in the '${e}' Table, and a count of how many times it appears`))];oe(se,e,a),c(1,Z,...a)})),c(1,Z,e,a,n,y,A,O,j,M,z,W,B,F,q,ae,ne,de),ee=[e,a,n,y,O,j,M,z,W,B,F,q,ae,ne,se],N([[e],[o],[H,"tables: "+a,"tables"],[H]],(([e,t,a],n)=>U(n,l,p,e,et(1,n),t,a))),U(0,l,b,n+Ne,lt(i,Ge)),U(5,l,i,Fe,at(i,Ge),"tableCallback: "+A,"tableCallback as any"),E(((e,t,a)=>{const[n,d,s,r,I,c,$,p]=le(se,e);N([[n],[o],[H,"table: "+d,", table"],[H]],(([n,o,d=l],s)=>U(s,t,i,n,ct(e,s),o,a+d))),U(0,t,i+f,u,lt(g,"the whole of "+rt(e)),l,a),U(5,t,i+g,Fe,at(i+g,"the whole of "+rt(e)),"tableCellCallback: "+p,a+", tableCellCallback as any"),U(0,t,C+"Count","number","Gets the number of Rows in the "+rt(e),l,a),U(0,t,h,u,lt(C,rt(e)),l,a),U(0,t,m,u,lt(C,rt(e),1),"cellId?: "+I+Oe,a+", cellId, descending, offset, limit"),U(5,t,C,Fe,at(C,rt(e)),"rowCallback: "+$,a+", rowCallback as any"),N([[s],[o],[H,", row: "+r,", row"],[H],[H,", partialRow: "+r,", partialRow"]],(([n,o=l,d=l],s)=>U(s,t,C,n,$t(e,s),Ae+o,a+", rowId"+d))),U(6,t,C,ge+ve,"Add a new Row to "+rt(e),"row: "+r+", reuseIds?: boolean",a+", row, reuseIds"),U(0,t,f,I+Ne,lt(g,It(e)),Ae,a+", rowId"),U(5,t,g,Fe,at(g,It(e)),Ae+", cellCallback: "+c,a+", rowId, cellCallback as any"),D(e,((n,d,s,r,I)=>{const c="Map"+St(d,1);oe(Y,d,c);const $=d+(R(s)?ve:l);N([[$],[o],[H,`, cell: ${d} | `+c,", cell as any"],[H]],(([o,d=l,s=l],c)=>U(c,t+I,g,o,ut(e,n,c),Ae+d,a+", rowId, "+r+s))),U(1,t+I,i+g,o,pt[1]+` the '${n}' Cell anywhere in `+rt(e),l,a+", "+r)}))})),U(0,l,p+we,we,et(1,6)),U(2,l,p+we,H,et(1,7),"tablesJson: "+we,"tables"+we),_(p,O,et(1,8)+" changes"),_(b,j,st(2,0,1)),_(i,M,st(3,0),`tableId: ${n} | null`,"tableId"),_(i+f,z,st(14,3,1),`tableId: ${n} | null`,"tableId"),_(C+"Count",W,st(15,3),`tableId: ${n} | null`,"tableId"),_(h,B,st(4,3,1),`tableId: ${n} | null`,"tableId"),_(m,F,st(13,3,1),Et("tableId: TId",`cellId: ${y}<TId>`+ve,"descending: boolean","offset: number","limit: number"+ve),Et("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),_(C,q,st(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),_(f,ae,st(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),_(g,ne,st(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${G(E((e=>le(se,e)?.[4]??l))," | ")} | null`,"tableId, rowId, cellId"),_(fe+g,de,Se+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),c(1,Z,...X(Y)),J(K,".set"+p+Ee+"({",kt(E(((e,t,a)=>[`[${a}]: {`,...D(e,((e,t,a,n)=>`[${n}]: {[${x(Pt(s),`'${s}'`)}]: ${x(Pt(t),`'${t}'`)}${R(a)?l:`, [${x(Pt(r),`'${r}'`)}]: `+(S(a)?x(Pt(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(q(a))c(null,t,y);else{const[e,a,n,d,I,$,u,i,p]=j(Q,H);c(1,Z,e,a,n,I,$,u,i,p),de=[e,a,n,$,u,i],N([[e],[o],[H,"values: "+a,"values"],[H],[H,"partialValues: "+a,"partialValues"]],(([e,t,a],n)=>U(n,l,y,e,et(2,n),t,a))),U(0,l,T,n+Ne,lt(w,Ge)),U(5,l,w,"void",at(w,Ge),"valueCallback: "+I,"valueCallback as any"),O(((e,t,a,n,d)=>{const s="Map"+St(t,1);oe(Y,t,s),N([[t],[o],[H,`value: ${t} | `+s,", value as any"],[H]],(([t,a,o=l],s)=>U(s,d,w,t,it(e,s),a,n+o)))})),U(0,l,y+we,we,et(2,6)),U(2,l,y+we,H,et(2,7),"valuesJson: "+we,"values"+we),_(y,$,et(2,8)+" changes"),_(T,u,st(10,0,1)),_(w,i,st(11,0),`valueId: ${n} | null`,"valueId"),_(fe+w,p,Se+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),c(1,Z,...X(Y)),c(0,t,"ValueChange"),J(K,".set"+y+Ee+"({",O(((e,t,a,n)=>[`[${n}]: {[${x(Pt(s),`'${s}'`)}]: ${x(Pt(t),`'${t}'`)}${R(a)?l:`, [${x(Pt(r),`'${r}'`)}]: `+(S(a)?x(Pt(a),`'${a}'`):a)}},`])),"})")}U(0,l,"Content",`[${p}, ${y}]`,et(0,0)),U(2,l,"Content",H,et(0,2),`[tables, values]: [${p}, ${y}]`,"[tables, values]"),U(2,l,je,H,`Applies a set of ${je} to the Store`,"transactionChanges: "+je,"transactionChanges"),ae(Y,((e,t)=>v(t,`(cell: ${e}${ve}) => `+e,`Takes a ${e} Cell value and returns another`))),c(null,t,"DoRollback",ge,"IdOrNull",we,"Store",je),c(0,t,"Get"+je,"GetTransactionLog"),U(0,l,we,we,et(0,6)),U(2,l,we,H,et(0,7),"tablesAndValuesJson: "+we,"tablesAndValuesJson"),U(7,l,Me,"Return",Je,he,"actions, doRollback","<Return>"),U(7,l,"start"+Le,H,ze),U(7,l,"finish"+Le,H,We,Ce,"doRollback");const se=M(Q,H);return _("Start"+Le,se,Se+" just before the start of the "+Me,l,l,0),_("WillFinish"+Le,se,Se+" just before "+Be,l,l,0),_("DidFinish"+Le,se,Se+" just after "+Be,l,l,0),U(7,l,"call"+I,H,"Manually provoke a listener to be called","listenerId: Id","listenerId"),U(3,l,I,H,"Remove a listener that was previously added to "+Ge,"listenerId: Id","listenerId"),F("getStore",l,"Store","store",pt[0]+" the underlying Store object"),c(1,t,"createStore"),c(1,Z,H,`create${H} as create${H}Decl`,se),x("store",["createStore()",...K]),V("fluent","actions: () => Store",["actions();",`return ${Q};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${Q}, ...params)`),x(Q,["{",...B(1),"}"]),[d(...k(0),...P(),me+" interface "+H+" {",...B(0),"}",l,At(`Creates a ${H} object`),me+" function create"+H+"(): "+H+";"),d(...k(1),me+" const create"+H+": typeof create"+H+"Decl = () => {",...A(),`return Object.freeze(${Q});`,"};"),ee,de]},Bt=e=>c+e,Ft=e=>Et(Bt(e),Bt(e)+pe),Ut="debugIds?: boolean",_t="debugIds={debugIds}",Zt="then"+be,Ht="Parameter",Qt=": (parameter: "+Ht+", store: Store) => ",qt="const contextValue = useContext(Context);",Kt=", based on a parameter",Xt=": ",Yt="<"+Ht+",>",el=Ht+"ized"+ue+"<"+Ht+">",tl="rowId",ll="rowId={rowId}",al=", separator, debugIds",nl="separator?: ReactElement | string",ol="then?: (store: Store",dl=Et(ol+")"+Ue,Zt),sl="then, then"+pe,rl=tl+Xt+ge,Il="View",cl=(e,...t)=>Et(...t,ye+": "+e,ye+be,"mutator?: boolean"),$l=(...e)=>Et(...e,ye,ye+pe,"mutator"),ul=(e,a,n,o,d)=>{const[s,r,c,$,v,V,x,k]=Nt(),[S,P,A]=Lt(e,a,v),E=`./${St(n)}.d`,D=`./${St(n)}-ui-react.d`,O="tinybase/ui-react",N=St(n,1),L=St(N),j=N+"Or"+N+ge,M=L+"Or"+N+ge,z=L+`={${L}}`,B=te(),F=(e,t,a,n,o,d=l)=>(r(1,D,e+" as "+e+"Decl"),Vt(B,e,[t,a,n,o,d])),U=(e,t,a,n,o,d=l)=>F("use"+e,t,a,n,o,d),_=(e,t,a,n,o=l,d=l,s=l,I=l,c=l)=>(r(1,O,`use${t} as use${t}Core`),U(e,Et(o,X,I),a,ee+`(${M}, use${t}Core, [`+(d||l)+(c?"], ["+c:l)+"]);",n,s)),Z=(e,t,l,a)=>F(e,t,1,l,a),H=(e=0)=>ne(B,(([t,a,n,o,d],s)=>{const r=e?[me+` const ${s}: typeof ${s}Decl = ${d}(${t}): ${1==a?"any":a} =>`,n]:[me+` function ${s}${d}(${t}): ${1==a?"ComponentReturnType":a};`];return e||W(r,At(o)),J(r,l),r}));r(null,t,ge,"Store",ue,Ht+"ized"+ue),r(0,O,"ComponentReturnType"),r(1,O,"useCellIds"),r(null,O,"ExtraProps"),r(0,E,N);const Q=c(j,N+" | "+ge,`Used when you need to refer to a ${N} in a React hook or component`),K=c(ke+Re,Ot(L+Te+N,L+`ById?: {[${L}Id: Id]: ${N}}`),`Used with the ${ke} component, so that a `+N+" can be passed into the context of an application");r(0,"react","ReactElement","ComponentType"),r(1,"react","React"),r(1,D,Q,K);const X=M+Te+Q;v("{createContext, useContext, useMemo}","React"),v("Context",`createContext<[${N}?, {[${L}Id: Id]: ${N}}?]>([])`),U("Create"+N,`create: () => ${N}, create`+be,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const Y=U(N,"id?: Id",N+ve,["{",qt,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${N} from within a ${ke} component context`),ee=$("useHook",M+`: ${Q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${L} = ${Y}(${M} as Id);`,`return hook(...preParams, ((${M} == null || typeof ${M} == 'string')`,`? ${L} : ${M})?.getStore(), ...postParams)`]),ae=$("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),oe=$("wrap",Et("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;"]),de=$("useCustomOrDefaultCellIds",Et("customCellIds: Ids | undefined","tableId: Id","rowId: Id",`${M}?: ${Q} | undefined`),[`const defaultCellIds = ${ee}(${M}, useCellIds, [tableId, rowId]);`,"return customCellIds ?? defaultCellIds;"]),se=v("NullComponent","() => null");if(!q(e)){const[e,a,n,d,s,w,y,T,v,V,x,k,A,O,j]=o;r(null,E,e,a,n,s,w,y,T,v,V,x,k,A,O),r(0,E,d),r(1,E,N),r(null,t,u,"IdOrNull");const M=$("tableView",`{${L}, rowComponent, getRowComponentProps, customCellIds`+al+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${oe}(rowIds.map((rowId) => (`,"<Row","{..."+ae+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",ll,"customCellIds={customCellIds}",z,_t,"/>","))",al,", tableId,",");"]),J=$("getDefaultTableComponent","tableId: Id",G(S(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+se),W=$("getDefaultCellComponent","tableId: Id, cellId: Id",G(S(((e,t,l)=>`tableId == ${l} ? ${G(P(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+se} : `)))+se);_(p,p,e,et(1,0)+$e);const B=_(b,b,n+Ne,lt(i,Ge)+$e);_(De+p+ue,De+p+ue,el,et(1,9)+Kt,Et(Bt(p)+Qt+a,Bt(p)+be),Ft(p),Yt,Et(ol,`tables: ${a})`+Ue,Zt),sl),_(ie+p+ue,ie+p+ue,ue,et(1,12),l,l,l,dl,sl);const F=c(g+Re,Ot("tableId?: TId","rowId: Id","cellId?: CId",L+Te+N,Ut),nt(Ie+g),`<TId extends ${n}, CId extends ${d}<TId>>`),U=c(C+Re,Ot("tableId?: TId","rowId: Id",L+Te+N,"cellComponents?: {readonly [CId in "+d+`<TId>]?: ComponentType<${F}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${d}<TId>) => ExtraProps`,`customCellIds?: ${d}<TId>[]`,nl,Ut),nt(Ie+C),`<TId extends ${n}>`),H=c(i+Re,Ot("tableId?: TId",L+Te+N,`rowComponent?: ComponentType<${U}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps","customCellIds?: CellId<TId>[]",nl,Ut),nt(Ie+i),`<TId extends ${n}>`),Q=c("Sorted"+i+Re,Ot("tableId?: TId","cellId?: "+d+"<TId>","descending?: boolean","offset?: number","limit?: number",L+Te+N,`rowComponent?: ComponentType<${U}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps","customCellIds?: CellId<TId>[]",nl,Ut),nt(Ie+"sorted "+i),`<TId extends ${n}>`),q=c(p+Re,Ot(L+Te+N,"tableComponents?: {readonly [TId in "+n+`]?: ComponentType<${H}<TId>>;}`,`getTableComponentProps?: (tableId: ${n}) => ExtraProps`,nl,Ut),nt(Ye(1,1)));r(1,D,q,H,Q,U,F),Z(p+Il,"{"+L+", tableComponents, getTableComponentProps"+al+"}: "+q,[oe+`(${B}(${L}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+J+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${ae}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",z,_t,"/>;","}), separator)"],et(1,13)+$e),S(((e,t,a)=>{const[n,o,d,s,I]=le(j,e);r(null,E,n,o,d,s,I),_(t+i,i,n,ct(e)+$e,l,a),_(t+i+f,i+f,u,lt(g,"the whole of "+rt(e))+$e,l,a);const c=_(t+h,h,u,lt(C,rt(e))+$e,l,a),$=_(t+m,m,u,lt(C,rt(e),1)+$e,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");_(t+C,C,d,$t(e)+$e,rl,Et(a,tl)),_(t+f,f,I+Ne,lt(g,It(e))+$e,rl,Et(a,tl)),_(De+t+i+ue,De+i+ue,el,ct(e,9)+Kt,Et(Bt(i)+Qt+o,Bt(i)+be),Et(a,Ft(i)),Yt,Et(ol,`table: ${o})`+Ue,Zt),sl),_(ie+t+i+ue,ie+i+ue,ue,ct(e,12),l,a,l,dl,sl),_(De+t+C+ue,De+C+ue,el,$t(e,9)+Kt,Et(rl,Bt(C)+Qt+s,Bt(C)+be),Et(a,tl,Ft(C)),Yt,Et(ol,`row: ${s})`+Ue,Zt),sl),_("Add"+t+C+ue,"Add"+C+ue,el,$t(e,10)+Kt,Et(Bt(C)+Qt+s,Bt(C)+be),Et(a,Ft(C)),Yt,"then?: ("+Et(rl+ve,"store: Store","row: "+s+")"+Ue,"then"+be)+", reuseRowIds?: boolean",sl+", reuseRowIds"),_(De+t+xe+C+ue,De+xe+C+ue,el,$t(e,11)+Kt,Et(rl,Bt(xe+C)+Qt+s,Bt(xe+C)+be),Et(a,tl,Ft(xe+C)),Yt,Et(ol,`partialRow: ${s})`+Ue,Zt),sl),_(ie+t+C+ue,ie+C+ue,ue,$t(e,12),rl,Et(a,tl),l,dl,sl);const p=Z(t+C+Il,"{rowId, "+L+", cellComponents, getCellComponentProps, customCellIds"+al+`}: ${U}<'${e}'>`,[oe+`(${de}(customCellIds, `+a+`, rowId, ${L}).map((cellId: ${I}) => {`,"const Cell = (cellComponents?.[cellId] ?? "+W+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${ae}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,ll,"cellId={cellId}",z,_t,"/>;","})"+al+", rowId)"],$t(e,13)+$e);Z(t+"Sorted"+i+Il,"{cellId, descending, offset, limit, ...props}: "+Q+`<'${e}'>`,M+"(props, "+$+`(cellId, descending, offset, limit, props.${L}), ${a}, ${p});`,ct(e,13)+", sorted"+$e),Z(t+i+Il,`props: ${H}<'${e}'>`,M+"(props, "+c+`(props.${L}), ${a}, ${p});`,ct(e,13)+$e),P(e,((n,o,d,s,I)=>{const c="Map"+St(o,1);r(0,E,c),r(1,E,c);const $=_(t+I+g,g,o+(R(d)?ve:l),ut(e,n)+$e,rl,Et(a,tl,s));_(De+t+I+g+ue,De+g+ue,el,ut(e,n,9)+Kt,Et(rl,Bt(g)+Qt+o+" | "+c,Bt(g)+be),Et(a,tl,s,Ft(g)),Yt,Et(ol,`cell: ${o} | ${c})`+Ue,Zt),sl),_(ie+t+I+g+ue,ie+g+ue,ue,ut(e,n,12),Et(rl,"forceDel?: boolean"),Et(a,tl,s,"forceDel"),l,dl,sl),Z(t+I+g+Il,`{rowId, ${L}, debugIds}: `+F+`<'${e}', '${n}'>`,[oe+`('' + ${$}(rowId, `+L+`) ?? '', undefined, debugIds, ${s})`],ut(e,n,13)+$e)}))}));const K=G(S((e=>le(j,e)?.[4]??l))," | ");_(p+I,p+I,Fe,et(1,8)+" changes",cl(s),$l()),_(b+I,b+I,Fe,st(2,0,1),cl(w),$l()),_(i+I,i+I,Fe,st(3,0),cl(y,`tableId: ${n} | null`),$l("tableId")),_(i+f+I,i+f+I,Fe,st(14,3,1),cl(T,`tableId: ${n} | null`),$l("tableId")),_(h+I,h+I,Fe,st(4,3,1),cl(V,`tableId: ${n} | null`),$l("tableId")),_(m+I,m+I,Fe,st(13,3,1),cl(x,`tableId: ${n} | null`,"cellId: "+K+ve,"descending: boolean","offset: number","limit: number"+ve),$l("tableId","cellId","descending","offset","limit")),_(C+I,C+I,Fe,st(5,3),cl(k,`tableId: ${n} | null`,tl+": IdOrNull"),$l("tableId",tl)),_(f+I,f+I,Fe,st(6,5,1),cl(A,`tableId: ${n} | null`,tl+": IdOrNull"),$l("tableId",tl)),_(g+I,g+I,Fe,st(7,5),cl(O,`tableId: ${n} | null`,tl+": IdOrNull",`cellId: ${K} | null`),$l("tableId",tl,"cellId"))}if(!q(a)){const[e,t,a,n,o,s]=d;r(null,E,...d),r(1,E,N);const u=$("getDefaultValueComponent","valueId: Id",G(A(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+se);_(y,y,e,et(2,0)+$e);const i=_(T,T,a+Ne,lt(w,Ge)+$e);_(De+y+ue,De+y+ue,el,et(2,9)+Kt,Et(Bt(y)+Qt+t,Bt(y)+be),Ft(y),Yt,Et(ol,`values: ${t})`+Ue,Zt),sl),_(De+xe+y+ue,De+xe+y+ue,el,et(2,11)+Kt,Et(Bt(xe+y)+Qt+t,Bt(xe+y)+be),Ft(xe+y),Yt,Et(ol,`partialValues: ${t})`+Ue,Zt),sl),_(ie+y+ue,ie+y+ue,ue,et(2,12),l,l,l,dl,sl);const p=c(w+Re,Ot("valueId?: VId",L+Te+N,Ut),nt("a Value"),`<VId extends ${a}>`),b=c(y+Re,Ot(L+Te+N,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${p}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,nl,Ut),nt(Ye(2,1)));r(1,D,b,p),Z(y+Il,"{"+L+", valueComponents, getValueComponentProps"+al+"}: "+b,[oe+`(${i}(${L}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+u+"(valueId);","return <Value",`{...${ae}(getValueComponentProps, valueId)}`,"key={valueId}",z,_t,"/>;","}), separator)"],et(2,13)+$e),A(((e,t,a,n,o)=>{const d="Map"+St(t,1);r(0,E,d),r(1,E,d);const s=_(o+w,w,t,it(e)+$e,l,n);_(De+o+w+ue,De+w+ue,el,it(e,9)+Kt,Et(Bt(w)+Qt+t+" | "+d,Bt(w)+be),Et(n,Ft(w)),Yt,Et(ol,`value: ${t} | ${d})`+Ue,Zt),sl),_(ie+o+w+ue,ie+w+ue,ue,it(e,12),l,n,l,dl,sl),Z(o+w+Il,`{${L}, debugIds}: ${p}<'${e}'>`,[oe+`('' + ${s}(`+L+`) ?? '', undefined, debugIds, ${n})`],it(e,13)+$e)})),_(y+I,y+I,Fe,et(2,8)+" changes",cl(n),$l()),_(T+I,T+I,Fe,st(10,0,1),cl(o),$l()),_(w+I,w+I,Fe,st(11,0),cl(s,`valueId: ${a} | null`),$l("valueId"))}return Z(ke,`{${L}, ${L}ById, children}: `+K+" & {children: React.ReactNode}",["{",qt,"return (","<Context."+ke,"value={useMemo(",`() => [${L} ?? contextValue[0], {...contextValue[1], ...${L}ById}],`,`[${L}, ${L}ById, contextValue],`,")}>","{children}",`</Context.${ke}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[s(...V(0),...x(),...H(0)),s(...V(1),...k(),...H(1))]},il=(e,t,a)=>{if(q(e)&&q(t))return[l,l,l,l];const[n,o,d,s]=Wt(e,t,a);return[n,o,...ul(e,t,a,d,s)]},pl=JSON.parse,bl="prettier/",Cl=bl+"plugins/",hl={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},ml=Gt((e=>{const t=()=>{const t=pl(e.getTablesSchemaJson());return!q(t)||D(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=te();if(D(a,(t=>D(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=de(n,a,(()=>[E(o),te(),[0],0])),[s,r,[I]]=d,c=de(r,o,(()=>0))+1;return c>I&&(d[2]=[c,o]),oe(r,o,c),d[3]++,s==E(o)})))))return t[l]={},Y(n,(([e,,[,n],o],d)=>{t[l][d]={[s]:e,...o==j(a)?{[r]:n}:{}}})),1}))?t:{}},l=()=>{const t=pl(e.getValuesSchemaJson());return q(t)&&e.forEachValue(((e,l)=>{t[e]={[s]:E(l)}})),t},a=e=>il(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"],l=[];let n;try{n=(await import(bl+"standalone")).format,J(l,await import(Cl+"estree"),await import(Cl+"typescript"))}catch(e){n=async e=>e}return await A(L(a(e),(async(e,a)=>xt(await n(e,{...hl,plugins:l,filepath:"_."+t[a]})))))};return _({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let s=0,r=0;const I={};d(((e,l)=>{s++;let a=0;l((()=>a++)),r+=a,t&&(I[e]={rowCells:a})})),a+=s,n+=r,t&&(o[e]={tableRows:s,tableCells:r,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:j(e.getValueIds()),jsonLength:Rt(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{ml as createTools};
|
package/lib/tools.js.gz
CHANGED
|
Binary file
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-indexed-db module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from browser IndexedDB storage.
|
|
4
|
+
* @see Persisting Data guide
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module persister-indexed-db
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {Persister} from '../persisters';
|
|
10
|
+
import {Store} from '../store';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The createIndexedDbPersister function creates a Persister object that can
|
|
14
|
+
* persist the Store to the browser's IndexedDB storage.
|
|
15
|
+
*
|
|
16
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
17
|
+
* `dbName` parameter which is unique to your application. This is the key used
|
|
18
|
+
* to identify which IndexedDB to use.
|
|
19
|
+
*
|
|
20
|
+
* Within that database, this Persister will create two object stores: one
|
|
21
|
+
* called 't', and one called 'v'. These will contain the Store's tabular and
|
|
22
|
+
* key-value data respectively, using 'k' and 'v' to store the key and value of
|
|
23
|
+
* each entry, as shown in the example.
|
|
24
|
+
*
|
|
25
|
+
* Note that it is not possible to reactively detect changes to a browser's
|
|
26
|
+
* IndexedDB. If you do choose to enable automatic loading for the Persister
|
|
27
|
+
* (with the startAutoLoad method), it needs to poll the database for changes.
|
|
28
|
+
* The `autoLoadIntervalSeconds` method is used to indicate how often to do
|
|
29
|
+
* this.
|
|
30
|
+
* @param store The Store to persist.
|
|
31
|
+
* @param dbName The unique key to identify the IndexedDB to use.
|
|
32
|
+
* @param autoLoadIntervalSeconds How often to poll the database when in
|
|
33
|
+
* 'autoLoad' mode, defaulting to 1.
|
|
34
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
35
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
36
|
+
* debugging persistence issues in a development environment.
|
|
37
|
+
* @returns A reference to the new Persister object.
|
|
38
|
+
* @example
|
|
39
|
+
* This example creates a Persister object and persists the Store to the
|
|
40
|
+
* browser's IndexedDB storage.
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* const store =
|
|
44
|
+
* createStore()
|
|
45
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
46
|
+
* .setTable('species', {dog: {price: 5}})
|
|
47
|
+
* .setValues({open: true});
|
|
48
|
+
* const persister = createIndexedDbPersister(store, 'petStore');
|
|
49
|
+
*
|
|
50
|
+
* await persister.save();
|
|
51
|
+
* // IndexedDB ->
|
|
52
|
+
* // database petStore:
|
|
53
|
+
* // objectStore t:
|
|
54
|
+
* // object 0:
|
|
55
|
+
* // k: "pets"
|
|
56
|
+
* // v: {fido: {species: dog}}
|
|
57
|
+
* // object 1:
|
|
58
|
+
* // k: "species"
|
|
59
|
+
* // v: {dog: {price: 5}}
|
|
60
|
+
* // objectStore v:
|
|
61
|
+
* // object 0:
|
|
62
|
+
* // k: "open"
|
|
63
|
+
* // v: true
|
|
64
|
+
*
|
|
65
|
+
* persister.destroy();
|
|
66
|
+
* ```
|
|
67
|
+
* @category Creation
|
|
68
|
+
* @since v4.2.0
|
|
69
|
+
*/
|
|
70
|
+
export function createIndexedDbPersister(
|
|
71
|
+
store: Store,
|
|
72
|
+
dbName: string,
|
|
73
|
+
autoLoadIntervalSeconds?: number,
|
|
74
|
+
onIgnoredError?: (error: any) => void,
|
|
75
|
+
): Persister;
|
|
@@ -25,7 +25,7 @@ import {Store} from '../store';
|
|
|
25
25
|
* @param loadUrl The endpoint that supports a `GET` method to load JSON.
|
|
26
26
|
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
|
|
27
27
|
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
|
|
28
|
-
* automatically loading changes from the server.
|
|
28
|
+
* automatically loading changes from the server, defaulting to 5.
|
|
29
29
|
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
30
30
|
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
31
31
|
* debugging persistence issues in a development environment, since v4.0.4.
|
|
@@ -57,6 +57,6 @@ export function createRemotePersister(
|
|
|
57
57
|
store: Store,
|
|
58
58
|
loadUrl: string,
|
|
59
59
|
saveUrl: string,
|
|
60
|
-
autoLoadIntervalSeconds
|
|
60
|
+
autoLoadIntervalSeconds?: number,
|
|
61
61
|
onIgnoredError?: (error: any) => void,
|
|
62
62
|
): Persister;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* |-|-|-|
|
|
13
13
|
* |persister-browser|createSessionPersister|Browser session storage|
|
|
14
14
|
* |persister-browser|createLocalPersister|Browser local storage|
|
|
15
|
+
* |persister-indexed-db|createIndexedDbPersister|Browser IndexedDB|
|
|
15
16
|
* |persister-remote|createRemotePersister|Remote server|
|
|
16
17
|
* |persister-file|createFilePersister|Local file (where possible)|
|
|
17
18
|
* |persister-sqlite3|createSqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-indexed-db module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from browser IndexedDB storage.
|
|
4
|
+
* @see Persisting Data guide
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module persister-indexed-db
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {OptionalSchemas, Store} from '../store';
|
|
10
|
+
import {Persister} from '../persisters';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The createIndexedDbPersister function creates a Persister object that can
|
|
14
|
+
* persist the Store to the browser's IndexedDB storage.
|
|
15
|
+
*
|
|
16
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
17
|
+
*
|
|
18
|
+
* ```ts override
|
|
19
|
+
* createIndexedDbPersister(
|
|
20
|
+
* store: Store,
|
|
21
|
+
* dbName: string,
|
|
22
|
+
* autoLoadIntervalSeconds?: number,
|
|
23
|
+
* onIgnoredError?: (error: any) => void,
|
|
24
|
+
* ): Persister;
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
28
|
+
* `dbName` parameter which is unique to your application. This is the key used
|
|
29
|
+
* to identify which IndexedDB to use.
|
|
30
|
+
*
|
|
31
|
+
* Within that database, this Persister will create two object stores: one
|
|
32
|
+
* called 't', and one called 'v'. These will contain the Store's tabular and
|
|
33
|
+
* key-value data respectively, using 'k' and 'v' to store the key and value of
|
|
34
|
+
* each entry, as shown in the example.
|
|
35
|
+
*
|
|
36
|
+
* Note that it is not possible to reactively detect changes to a browser's
|
|
37
|
+
* IndexedDB. If you do choose to enable automatic loading for the Persister
|
|
38
|
+
* (with the startAutoLoad method), it needs to poll the database for changes.
|
|
39
|
+
* The `autoLoadIntervalSeconds` method is used to indicate how often to do
|
|
40
|
+
* this.
|
|
41
|
+
* @param store The Store to persist.
|
|
42
|
+
* @param dbName The unique key to identify the IndexedDB to use.
|
|
43
|
+
* @param autoLoadIntervalSeconds How often to poll the database when in
|
|
44
|
+
* 'autoLoad' mode, defaulting to 1.
|
|
45
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
46
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
47
|
+
* debugging persistence issues in a development environment.
|
|
48
|
+
* @returns A reference to the new Persister object.
|
|
49
|
+
* @example
|
|
50
|
+
* This example creates a Persister object and persists the Store to the
|
|
51
|
+
* browser's IndexedDB storage.
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* const store =
|
|
55
|
+
* createStore()
|
|
56
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
57
|
+
* .setTable('species', {dog: {price: 5}})
|
|
58
|
+
* .setValues({open: true});
|
|
59
|
+
* const persister = createIndexedDbPersister(store, 'petStore');
|
|
60
|
+
*
|
|
61
|
+
* await persister.save();
|
|
62
|
+
* // IndexedDB ->
|
|
63
|
+
* // database petStore:
|
|
64
|
+
* // objectStore t:
|
|
65
|
+
* // object 0:
|
|
66
|
+
* // k: "pets"
|
|
67
|
+
* // v: {fido: {species: dog}}
|
|
68
|
+
* // object 1:
|
|
69
|
+
* // k: "species"
|
|
70
|
+
* // v: {dog: {price: 5}}
|
|
71
|
+
* // objectStore v:
|
|
72
|
+
* // object 0:
|
|
73
|
+
* // k: "open"
|
|
74
|
+
* // v: true
|
|
75
|
+
*
|
|
76
|
+
* persister.destroy();
|
|
77
|
+
* ```
|
|
78
|
+
* @category Creation
|
|
79
|
+
* @since v4.2.0
|
|
80
|
+
*/
|
|
81
|
+
export function createIndexedDbPersister<Schemas extends OptionalSchemas>(
|
|
82
|
+
store: Store<Schemas>,
|
|
83
|
+
dbName: string,
|
|
84
|
+
autoLoadIntervalSeconds?: number,
|
|
85
|
+
onIgnoredError?: (error: any) => void,
|
|
86
|
+
): Persister<Schemas>;
|
|
@@ -20,7 +20,7 @@ import {Persister} from '../persisters';
|
|
|
20
20
|
* store: Store,
|
|
21
21
|
* loadUrl: string,
|
|
22
22
|
* saveUrl: string,
|
|
23
|
-
* autoLoadIntervalSeconds
|
|
23
|
+
* autoLoadIntervalSeconds?: number,
|
|
24
24
|
* onIgnoredError?: (error: any) => void,
|
|
25
25
|
* ): Persister;
|
|
26
26
|
* ```
|
|
@@ -37,7 +37,7 @@ import {Persister} from '../persisters';
|
|
|
37
37
|
* @param loadUrl The endpoint that supports a `GET` method to load JSON.
|
|
38
38
|
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
|
|
39
39
|
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
|
|
40
|
-
* automatically loading changes from the server.
|
|
40
|
+
* automatically loading changes from the server, defaulting to 5.
|
|
41
41
|
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
42
42
|
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
43
43
|
* debugging persistence issues in a development environment, since v4.0.4.
|
|
@@ -69,6 +69,6 @@ export function createRemotePersister<Schemas extends OptionalSchemas>(
|
|
|
69
69
|
store: Store<Schemas>,
|
|
70
70
|
loadUrl: string,
|
|
71
71
|
saveUrl: string,
|
|
72
|
-
autoLoadIntervalSeconds
|
|
72
|
+
autoLoadIntervalSeconds?: number,
|
|
73
73
|
onIgnoredError?: (error: any) => void,
|
|
74
74
|
): Persister<Schemas>;
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* |-|-|-|
|
|
13
13
|
* |persister-browser|createSessionPersister|Browser session storage|
|
|
14
14
|
* |persister-browser|createLocalPersister|Browser local storage|
|
|
15
|
+
* |persister-indexed-db|createIndexedDbPersister|Browser IndexedDB|
|
|
15
16
|
* |persister-remote|createRemotePersister|Remote server|
|
|
16
17
|
* |persister-file|createFilePersister|Local file (where possible)|
|
|
17
18
|
* |persister-sqlite3|createSqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|
|
package/lib/ui-react-dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"react";import{useRowIds as t,useTableCellIds as l,useRowCount as a,useSortedRowIds as n,useValueIds as o,ValueView as r,useIndexesOrIndexesById as i,useSliceRowIds as s,useRelationshipsOrRelationshipsById as d,useResultRowIds as m,useResultTableCellIds as u,useResultRowCount as h,useResultSortedRowIds as c,useCell as g,useSetCellCallback as b,useStoreOrStoreById as p,useValue as f,useSetValueCallback as w,useRemoteRowId as k,CellView as v,ResultCellView as y}from"./ui-react";const C=e=>typeof e,x=C(""),I=C(!0),N=C(0),z="Value"
|
|
1
|
+
import e from"react";import{useRowIds as t,useTableCellIds as l,useRowCount as a,useSortedRowIds as n,useValueIds as o,ValueView as r,useIndexesOrIndexesById as i,useSliceRowIds as s,useRelationshipsOrRelationshipsById as d,useResultRowIds as m,useResultTableCellIds as u,useResultRowCount as h,useResultSortedRowIds as c,useCell as g,useSetCellCallback as b,useStoreOrStoreById as p,useValue as f,useSetValueCallback as w,useRemoteRowId as k,CellView as v,ResultCellView as y}from"./ui-react";const C=e=>typeof e,x=C(""),I=C(!0),N=C(0),z="Value",M="currentTarget",$="value",S=isFinite,T=e=>null==e,{PureComponent:R,Fragment:q,createElement:F,useCallback:P,useLayoutEffect:E,useRef:O,useState:V}=e,j=(e,...t)=>T(e)?{}:e(...t),A=(e,t)=>e.map(t),B=Object,L=(e=[])=>B.fromEntries(e),D=(e,t)=>A(B.entries(e),(([e,l])=>t(l,e))),G="M20 80l5-15l40-40l10 10l-40 40l-15 5m5-15l10 10",H='content:url("',J=H+"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' stroke-width='4' stroke='white' fill='none'>",K='</svg>")',Q=H+"data:image/svg+xml,%3csvg viewBox='0 0 680 680' xmlns='http://www.w3.org/2000/svg' style='width:680px%3bheight:680px'%3e %3cpath stroke='white' stroke-width='80' fill='none' d='M340 617a84 241 90 11.01 0zM131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124zm-12-127a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e %3cpath fill='%23d81b60' d='M131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124z' /%3e %3cpath d='M249 619a94 240 90 00308-128 114 289 70 01-308 128zM119 208a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e%3c/svg%3e\")",U=A([[20,20,20,60],[20,20,60,20],[20,60,60,20],[60,20,20,60],[30,30,40,40]],(([e,t,l,a])=>J+`<rect x='20' y='20' width='60' height='60' fill='grey'/><rect x='${e}' y='${t}' width='${l}' height='${a}' fill='white'/>`+K)),W=J+"<path d='M20 20l60 60M20 80l60-60' />"+K,X=J+`<path d='${G}' />`+K,Y=J+`<path d='${G}M20 20l60 60' />`+K,Z="*::-webkit-scrollbar";((e,t="")=>{e.join(t)})(D({"*":"all:revert","*::before":"all:revert","*::after":"all:revert",[Z]:"width:0.5rem;height:0.5rem;",[Z+"-track"]:"background:#111",[Z+"-thumb"]:"background:#999;border:1px solid #111",[Z+"-thumb:hover"]:"background:#fff",[Z+"-corner"]:"background:#111",img:"width:1rem;height:1rem;background:#111;border:0;vertical-align:text-bottom",">img":"padding:0.25rem;bottom:0;right:0;position:fixed;"+Q,...L(A(["bottom:0;left:0","top:0;right:0"],((e,t)=>[`>img[data-position='${t}']`,e]))),main:"display:flex;flex-direction:column;background:#111d;color:#fff;position:fixed;",...L(A(["bottom:0;left:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:30vh","bottom:0;left:0;width:100vw;height:30vh","top:0;right:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:100vh"],((e,t)=>[`main[data-position='${t}']`,e]))),header:"display:flex;padding:0.25rem;background:#000;align-items:center","header>img:nth-of-type(1)":Q,"header>img:nth-of-type(6)":W,...L(A(U,((e,t)=>[`header>img[data-id='${t}']`,e]))),"header>span":"flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;margin-left:0.25rem",article:"padding:0.25rem 0.25rem 0.25rem 0.5rem;overflow:auto;flex:1",details:"margin-left:0.75rem;width:fit-content;","details img":"display:none","details[open]>summary img":"display:unset;background:none;margin-left:0.25rem","details[open]>summary img.edit":X,"details[open]>summary img.done":Y,summary:"margin-left:-0.75rem;line-height:1.25rem;user-select:none;width:fit-content",table:"border-collapse:collapse;table-layout:fixed;margin-bottom:0.5rem","table input":"background:#111;color:unset;padding:0 0.25rem;border:0;font-size:unset;vertical-align:top;margin:0",'table input[type="number"]':"width:4rem","table tbody button":"font-size:0;background:#fff;border-radius:50%;margin:0 0.125rem 0 0;width:0.85rem;color:#111","table button:first-letter":"font-size:0.75rem",thead:"background:#222","th:nth-of-type(1)":"min-width:2rem;","th.sorted":"background:#000","table caption":"text-align:left;white-space:nowrap;line-height:1.25rem",button:"width:1.5rem;border:none;background:none;color:#fff;padding:0","button[disabled]":"color:#777","button.next":"margin-right:0.5rem","th,td":"overflow:hidden;text-overflow:ellipsis;padding:0.25rem 0.5rem;max-width:12rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#777;text-align:left","span.warn":"margin:0.25rem;color:#d81b60"},((e,t)=>e?`& ${t}{${e}}`:"")));const _=(e,t,l,a)=>e==x?t:e==N?l:a,{useCallback:ee,useMemo:te,useState:le}=e,ae="editable",ne=(e,t)=>A(l(e,t),(t=>e+"."+t)),oe=(e,t,l)=>{const a=ee(e,t);return l?a:void 0},re=(...e)=>te((()=>e),e),ie=(e,t)=>te((()=>({store:e,tableId:t})),[e,t]),se=(e,t)=>te((()=>({queries:e,queryId:t})),[e,t]),de=(e,t=!1,l,a=0,n,o,r,i)=>{const[[s,d,m],u]=le([e,t,a]),h=ee((e=>{u(e),i?.(e)}),[i]),c=oe((e=>h([e,e==s&&!d,m])),[h,s,d,m],l),g=ee((e=>h([s,d,e])),[h,s,d]),b=!0===r?Ie:r;return[[s,d,m],c,te((()=>!1===r?null:F(b,{offset:m,limit:n,total:o,onChange:g})),[r,b,m,n,o,g])]},me=(e,t,l)=>te((()=>{const a=t??e;return L(D(Array.isArray(a)?L(A(a,(e=>[e,e]))):a,((e,t)=>{return[t,{label:t,component:l,...(a=e,C(a)==x?{label:e}:e)}];var a})))}),[t,l,e]),ue=({className:e,headerRow:t,idColumn:l,params:[a,n,o,r,i,s]})=>F("table",{className:e},s?F("caption",null,s):null,!1===t?null:F("thead",null,F("tr",null,!1===l?null:F(he,{sort:r??[],label:"Id",onClick:i}),D(a,(({label:e},t)=>F(he,{key:t,cellId:t,label:e,sort:r??[],onClick:i}))))),F("tbody",null,A(o,(e=>F("tr",{key:e},!1===l?null:F("th",null,e),D(a,(({component:t,getComponentProps:l},a)=>F("td",{key:a},F(t,{...j(l,e,a),...n,rowId:e,cellId:a}))))))))),he=({cellId:e,sort:[t,l],label:a=e??"",onClick:n})=>F("th",{onClick:oe((()=>n?.(e)),[n,e],n),className:T(l)||t!=e?void 0:`sorted ${l?"de":"a"}scending`},T(l)||t!=e?null:(l?"↓":"↑")+" ",a),ce=({localRowId:t,params:[l,a,n,o,r,i,s]})=>{const d=k(r,t,i);return F("tr",null,!1===l?null:F(e.Fragment,null,F("th",null,t),F("th",null,d)),D(a,(({component:e,getComponentProps:l},a)=>{const[r,i]=a.split(".",2),m=r===n?t:r===o?d:null;return T(m)?null:F("td",{key:a},F(e,{...j(l,m,i),store:s,tableId:r,rowId:m,cellId:i}))})))},ge=({thing:e,onThingChange:t,className:l,hasSchema:a})=>{const[n,o]=le(),[r,i]=le(),[s,d]=le(),[m,u]=le(),[h,c]=le();r!==e&&(o((e=>{const t=C(e);return(e=>e==x||e==I)(t)||t==N&&S(e)?t:void 0})(e)),i(e),d(e+""),u(Number(e)||0),c(!!e));const g=ee(((e,l)=>{l(e),i(e),t(e)}),[t]);return F("div",{className:l},F("button",{className:n,onClick:ee((()=>{if(!a?.()){const e=_(n,N,I,x),l=_(e,s,m,h);o(e),i(l),t(l)}}),[a,t,s,m,h,n])},n),_(n,F("input",{key:n,value:s,onChange:ee((e=>g(e[M][$]+"",d)),[g])}),F("input",{key:n,type:"number",value:m,onChange:ee((e=>g(Number(e[M][$]||0),u)),[g])}),F("input",{key:n,type:"checkbox",checked:h,onChange:ee((e=>g(!!e[M].checked,c)),[g])})))},be=({tableId:e,store:a,editable:n,customCells:o,...r})=>F(ue,{...r,params:re(me(l(e,a),o,n?Ce:v),ie(a,e),t(e,a))}),pe=({tableId:e,cellId:t,descending:o,offset:r,limit:i,store:s,editable:d,sortOnClick:m,paginator:u=!1,onChange:h,customCells:c,...g})=>{const[b,p,f]=de(t,o,m,r,i,a(e,s),u,h);return F(ue,{...g,params:re(me(l(e,s),c,d?Ce:v),ie(s,e),n(e,...b,i,s),b,p,f)})},fe=({store:e,editable:t=!1,valueComponent:l=(t?xe:r),getValueComponentProps:a,className:n,headerRow:i,idColumn:s})=>F("table",{className:n},!1===i?null:F("thead",null,F("tr",null,!1===s?null:F("th",null,"Id"),F("th",null,z))),F("tbody",null,A(o(e),(t=>F("tr",{key:t},!1===s?null:F("th",null,t),F("td",null,F(l,{...j(a,t),valueId:t,store:e}))))))),we=({indexId:e,sliceId:t,indexes:a,editable:n,customCells:o,...r})=>{const[d,m,u]=((e,t)=>[e,e?.getStore(),e?.getTableId(t)])(i(a),e);return F(ue,{...r,params:re(me(l(u,m),o,n?Ce:v),ie(m,u),s(e,t,d))})},ke=({relationshipId:l,relationships:a,editable:n,customCells:o,className:r,headerRow:i,idColumn:s=!0})=>{const[m,u,h,c]=((e,t)=>[e,e?.getStore(),e?.getLocalTableId(t),e?.getRemoteTableId(t)])(d(a),l),g=me([...ne(h,u),...ne(c,u)],o,n?Ce:v),b=re(s,g,h,c,l,m,u);return F("table",{className:r},!1===i?null:F("thead",null,F("tr",null,!1===s?null:F(e.Fragment,null,F("th",null,h,".Id"),F("th",null,c,".Id")),D(g,(({label:e},t)=>F("th",{key:t},e))))),F("tbody",null,A(t(h,u),(e=>F(ce,{key:e,localRowId:e,params:b})))))},ve=({queryId:e,queries:t,customCells:l,...a})=>F(ue,{...a,params:re(me(u(e,t),l,y),se(t,e),m(e,t))}),ye=({queryId:e,cellId:t,descending:l,offset:a,limit:n,queries:o,sortOnClick:r,paginator:i=!1,customCells:s,onChange:d,...m})=>{const[g,b,p]=de(t,l,r,a,n,h(e,o),i,d);return F(ue,{...m,params:re(me(u(e,o),s,y),se(o,e),c(e,...g,n,o),g,b,p)})},Ce=({tableId:e,rowId:t,cellId:l,store:a,className:n})=>F(ge,{thing:g(e,t,l,a),onThingChange:b(e,t,l,(e=>e),[],a),className:n??ae+"Cell",hasSchema:p(a)?.hasTablesSchema}),xe=({valueId:e,store:t,className:l})=>F(ge,{thing:f(e,t),onThingChange:w(e,(e=>e),[],t),className:l??ae+z,hasSchema:p(t)?.hasValuesSchema}),Ie=({onChange:t,total:l,offset:a=0,limit:n=l,singular:o="row",plural:r=o+"s"})=>{(a>l||a<0)&&(a=0,t(0));const i=oe((()=>t(a-n)),[t,a,n],a>0),s=oe((()=>t(a+n)),[t,a,n],a+n<l);return F(e.Fragment,null,l>n&&F(e.Fragment,null,F("button",{className:"previous",disabled:0==a,onClick:i},"←"),F("button",{className:"next",disabled:a+n>=l,onClick:s},"→"),a+1," to ",Math.min(l,a+n)," of "),l," ",1!=l?r:o)},Ne=e=>new Map(e);Ne(),Ne();const ze=e=>null;export{Ce as EditableCellView,xe as EditableValueView,ke as RelationshipInHtmlTable,ye as ResultSortedTableInHtmlTable,ve as ResultTableInHtmlTable,we as SliceInHtmlTable,pe as SortedTableInHtmlTable,Ie as SortedTablePaginator,ze as StoreInspector,be as TableInHtmlTable,fe as ValuesInHtmlTable};
|
package/lib/ui-react-dom.js.gz
CHANGED
|
Binary file
|
package/lib/ui-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useContext as t}from"react";const o=e=>typeof e,s="",r=o(s),d="Result",n="Ids",I="Table",u=I+"s",l=I+n,i="Row",c=i+"Count",a=i+n,p="Sorted"+i+n,g="Cell",b=g+n,C="Value",m=C+"s",k=C+n,y=e=>null==e,w=(e,t,o)=>y(e)?o?.():t(e),h=e=>o(e)==r,R=()=>{},v=(e,t)=>e.map(t),q=Object.keys,{createContext:P,useContext:f}=e,x=P([]),S=(e,t)=>{const o=f(x);return y(e)?o[t]:h(e)?((e,t)=>w(e,(e=>e[t])))(o[t+1],e):e},L=(e,t)=>{const o=S(e,t);return y(e)||h(e)?o:e},B=e=>q(f(x)[e]),T=e=>S(e,0),M=e=>L(e,0),E=e=>S(e,2),V=e=>L(e,2),A=e=>S(e,4),F=e=>L(e,4),j=e=>S(e,6),O=e=>L(e,6),Q=e=>S(e,8),z=e=>L(e,8),D=e=>S(e,10),G=e=>L(e,10),{useCallback:H,useEffect:J,useMemo:K,useRef:N,useState:U}=e,W=(e,t,o=[])=>{const s=K((()=>t(e)),[e,...o]);return J((()=>()=>s.destroy()),[s]),s},X=(e,t,o,s=[],r)=>{const[,d]=U(),n=H((()=>t?.["get"+e]?.(...s)??o),[t,...s]),[I]=U(n),u=N(I);return K((()=>u.current=n()),[n]),Y(e,t,((...e)=>{u.current=y(r)?n():e[r],d([])}),[],s),u.current},Y=(e,t,o,s=[],r=[],...d)=>J((()=>{const s=t?.["add"+e+"Listener"]?.(...r,o,...d);return()=>t?.delListener(s)}),[t,...r,...s,...d]),Z=(e,t,o,s=[],r=R,d=[],...n)=>{const I=M(e);return H((e=>w(I,(s=>w(o(e,s),(e=>r(s["set"+t](...n,e),e)))))),[I,t,...s,...d,...n])},$=(e,t,o=R,s=[],...r)=>{const d=M(e);return H((()=>o(d?.["del"+t](...r))),[d,t,...s,...r])},_=(e,t,o)=>{const s=G(e);return H((()=>s?.[t](o)),[s,t,o])},ee=(e,t=[])=>K(e,t),te=()=>B(1),oe=e=>X(u,M(e),{}),se=e=>X(l,M(e),[],[]),re=(e,t)=>X(I,M(t),{},[e]),de=(e,t)=>X(I+b,M(t),[],[e]),ne=(e,t)=>X(c,M(t),[],[e]),Ie=(e,t)=>X(a,M(t),[],[e]),ue=(e,t,o,s=0,r,d)=>X(p,M(d),[],[e,t,o,s,r],6),le=(e,t,o)=>X(i,M(o),{},[e,t]),ie=(e,t,o)=>X(b,M(o),[],[e,t]),ce=(e,t,o,s)=>X(g,M(s),void 0,[e,t,o],4),ae=e=>X(m,M(e),{}),pe=e=>X(k,M(e),[],[]),ge=(e,t)=>X(C,M(t),void 0,[e]),be=(e,t,o,s,r)=>Z(o,u,e,t,s,r),Ce=(e,t,o,s,r,d)=>Z(s,I,t,o,r,d,e),me=(e,t,o,s,r,d,n)=>Z(r,i,o,s,d,n,e,t),ke=(e,t,o=[],s,r=R,d=[],n=!0)=>{const I=M(s);return H((o=>w(I,(s=>w(t(o,s),(t=>r(s.addRow(e,t,n),s,t)))))),[I,e,...o,...d,n])},ye=(e,t,o,s,r,d,n)=>Z(r,"PartialRow",o,s,d,n,e,t),we=(e,t,o,s,r,d,n,I)=>Z(d,g,s,r,n,I,e,t,o),he=(e,t,o,s,r)=>Z(o,m,e,t,s,r),Re=(e,t,o,s,r)=>Z(o,"PartialValues",e,t,s,r),ve=(e,t,o,s,r,d)=>Z(s,C,t,o,r,d,e),qe=(e,t,o)=>$(e,u,t,o),Pe=(e,t,o,s)=>$(t,I,o,s,e),fe=(e,t,o,s,r)=>$(o,i,s,r,e,t),xe=(e,t,o,s,r,d,n)=>$(r,g,d,n,e,t,o,s),Se=(e,t,o)=>$(e,m,t,o),Le=(e,t,o,s)=>$(t,C,o,s,e),Be=(e,t,o,s)=>Y(u,M(s),e,t,[],o),Te=(e,t,o,s)=>Y(l,M(s),e,t,[],o),Me=(e,t,o,s,r)=>Y(I,M(r),t,o,[e],s),Ee=(e,t,o,s,r)=>Y(I+b,M(r),t,o,[e],s),Ve=(e,t,o,s,r)=>Y(c,M(r),t,o,[e],s),Ae=(e,t,o,s,r)=>Y(a,M(r),t,o,[e],s),Fe=(e,t,o,s,r,d,n,I,u)=>Y(p,M(u),d,n,[e,t,o,s,r],I),je=(e,t,o,s,r,d)=>Y(i,M(d),o,s,[e,t],r),Oe=(e,t,o,s,r,d)=>Y(b,M(d),o,s,[e,t],r),Qe=(e,t,o,s,r,d,n)=>Y(g,M(n),s,r,[e,t,o],d),ze=(e,t,o,s)=>Y(m,M(s),e,t,[],o),De=(e,t,o,s)=>Y(k,M(s),e,t,[],o),Ge=(e,t,o,s,r)=>Y(C,M(r),t,o,[e],s),He=(e,t,o)=>W(e,t,o),Je=()=>B(3),Ke=e=>X("MetricIds",V(e),[]),Ne=(e,t)=>X("Metric",V(t),void 0,[e]),Ue=(e,t,o,s)=>Y("Metric",V(s),t,o,[e]),We=(e,t,o)=>W(e,t,o),Xe=()=>B(5),Ye=(e,t)=>X("SliceIds",F(t),[],[e]),Ze=e=>X("IndexIds",F(e),[]),$e=(e,t,o)=>X("Slice"+a,F(o),[],[e,t]),_e=(e,t,o,s)=>Y("SliceIds",F(s),t,o,[e]),et=(e,t,o,s,r)=>Y("Slice"+a,F(r),o,s,[e,t]),tt=(e,t,o)=>W(e,t,o),ot=()=>B(7),st=e=>X("RelationshipIds",O(e),[]),rt=(e,t,o)=>X("RemoteRowId",O(o),void 0,[e,t]),dt=(e,t,o)=>X("Local"+a,O(o),[],[e,t]),nt=(e,t,o)=>X("Linked"+a,O(o),[],[e,t]),It=(e,t,o,s,r)=>Y("RemoteRowId",O(r),o,s,[e,t]),ut=(e,t,o,s,r)=>Y("Local"+a,O(r),o,s,[e,t]),lt=(e,t,o,s,r)=>Y("Linked"+a,O(r),o,s,[e,t]),it=(e,t,o)=>W(e,t,o),ct=()=>B(9),at=e=>X("QueryIds",z(e),[]),pt=(e,t)=>X(d+I,z(t),{},[e]),gt=(e,t)=>X(d+I+b,z(t),[],[e]),bt=(e,t)=>X(d+c,z(t),[],[e]),Ct=(e,t)=>X(d+a,z(t),[],[e]),mt=(e,t,o,s=0,r,n)=>X(d+p,z(n),[],[e,t,o,s,r],6),kt=(e,t,o)=>X(d+i,z(o),{},[e,t]),yt=(e,t,o)=>X(d+b,z(o),[],[e,t]),wt=(e,t,o,s)=>X(d+g,z(s),void 0,[e,t,o]),ht=(e,t,o,s)=>Y(d+I,z(s),t,o,[e]),Rt=(e,t,o,s)=>Y(d+I+b,z(s),t,o,[e]),vt=(e,t,o,s)=>Y(d+c,z(s),t,o,[e]),qt=(e,t,o,s)=>Y(d+a,z(s),t,o,[e]),Pt=(e,t,o,s,r,n,I,u)=>Y(d+p,z(u),n,I,[e,t,o,s,r]),ft=(e,t,o,s,r)=>Y(d+i,z(r),o,s,[e,t]),xt=(e,t,o,s,r)=>Y(d+b,z(r),o,s,[e,t]),St=(e,t,o,s,r,n)=>Y(d+g,z(n),s,r,[e,t,o]),Lt=(e,t,o)=>W(e,t,o),Bt=()=>B(11),Tt=e=>X("CheckpointIds",G(e),[[],void 0,[]]),Mt=(e,t)=>X("Checkpoint",G(t),void 0,[e]),Et=(e=R,t=[],o,s=R,r=[])=>{const d=G(o);return H((t=>w(d,(o=>{const r=e(t);s(o.addCheckpoint(r),o,r)}))),[d,...t,...r])},Vt=e=>_(e,"goBackward"),At=e=>_(e,"goForward"),Ft=(e,t=[],o,s=R,r=[])=>{const d=G(o);return H((t=>w(d,(o=>w(e(t),(e=>s(o.goTo(e),e)))))),[d,...t,...r])},jt=e=>{const t=G(e),[o,r]=Tt(t);return[(d=o,!(0==(e=>e.length)(d))),Vt(t),r,w(r,(e=>t?.getCheckpoint(e)))??s];var d},Ot=e=>{const t=G(e),[,,[o]]=Tt(t);return[!y(o),At(t),o,w(o,(e=>t?.getCheckpoint(e)))??s]},Qt=(e,t,o)=>Y("CheckpointIds",G(o),e,t),zt=(e,t,o,s)=>Y("Checkpoint",G(s),t,o,[e]),Dt=(e,t,o=[],s,r=[])=>{const[,d]=U(),n=K((()=>t(e)),[e,...o]);return J((()=>((async()=>{await(s?.(n)),d(1)})(),()=>{n.destroy()})),[n,...r]),n},{createElement:Gt,Fragment:Ht,useCallback:Jt,useLayoutEffect:Kt,useRef:Nt,useState:Ut}=e,Wt=(e,...t)=>y(e)?{}:e(...t),Xt=(e,t)=>[e,e?.getStore(),e?.getLocalTableId(t),e?.getRemoteTableId(t)],{useMemo:Yt}=e,Zt=({tableId:e,store:t,rowComponent:o=ro,getRowComponentProps:s,customCellIds:r,separator:d,debugIds:n},I)=>oo(v(I,(d=>Gt(o,{...Wt(s,d),key:d,tableId:e,rowId:d,customCellIds:r,store:t,debugIds:n}))),d,n,e),$t=({queryId:e,queries:t,resultRowComponent:o=ko,getResultRowComponentProps:s,separator:r,debugIds:d},n)=>oo(v(n,(r=>Gt(o,{...Wt(s,r),key:r,queryId:e,rowId:r,queries:t,debugIds:d}))),r,d,e),_t=({relationshipId:e,relationships:t,rowComponent:o=ro,getRowComponentProps:s,separator:r,debugIds:d},n,I)=>{const[u,l,i]=Xt(O(t),e),c=n(e,I,u);return oo(v(c,(e=>Gt(o,{...Wt(s,e),key:e,tableId:i,rowId:e,store:l,debugIds:d}))),r,d,I)},eo=e=>({checkpoints:t,checkpointComponent:o=ho,getCheckpointComponentProps:s,separator:r,debugIds:d})=>{const n=G(t);return oo(v(e(Tt(n)),(e=>Gt(o,{...Wt(s,e),key:e,checkpoints:n,checkpointId:e,debugIds:d}))),r)},to=({store:e,storesById:o,metrics:s,metricsById:r,indexes:d,indexesById:n,relationships:I,relationshipsById:u,queries:l,queriesById:i,checkpoints:c,checkpointsById:a,children:p})=>{const g=t(x);return Gt(x.Provider,{value:Yt((()=>[e??g[0],{...g[1],...o},s??g[2],{...g[3],...r},d??g[4],{...g[5],...n},I??g[6],{...g[7],...u},l??g[8],{...g[9],...i},c??g[10],{...g[11],...a}]),[e,o,s,r,d,n,I,u,l,i,c,a,g])},p)},oo=(e,t,o,s)=>{const r=y(t)||!Array.isArray(e)?e:v(e,((e,o)=>o>0?[t,e]:e));return o?[s,":{",r,"}"]:r},so=({tableId:e,rowId:t,cellId:o,store:r,debugIds:d})=>oo(s+(ce(e,t,o,r)??s),void 0,d,o),ro=({tableId:e,rowId:t,store:o,cellComponent:s=so,getCellComponentProps:r,customCellIds:d,separator:n,debugIds:I})=>oo(v(((e,t,o,s)=>{const r=ie(t,o,s);return e??r})(d,e,t,o),(d=>Gt(s,{...Wt(r,d),key:d,tableId:e,rowId:t,cellId:d,store:o,debugIds:I}))),n,I,t),no=e=>Zt(e,Ie(e.tableId,e.store)),Io=({cellId:e,descending:t,offset:o,limit:s,...r})=>Zt(r,ue(r.tableId,e,t,o,s,r.store)),uo=({store:e,tableComponent:t=no,getTableComponentProps:o,separator:s,debugIds:r})=>oo(v(se(e),(s=>Gt(t,{...Wt(o,s),key:s,tableId:s,store:e,debugIds:r}))),s),lo=({valueId:e,store:t,debugIds:o})=>oo(s+(ge(e,t)??s),void 0,o,e),io=({store:e,valueComponent:t=lo,getValueComponentProps:o,separator:s,debugIds:r})=>oo(v(pe(e),(s=>Gt(t,{...Wt(o,s),key:s,valueId:s,store:e,debugIds:r}))),s),co=({metricId:e,metrics:t,debugIds:o})=>oo(Ne(e,t)??s,void 0,o,e),ao=({indexId:e,sliceId:t,indexes:o,rowComponent:s=ro,getRowComponentProps:r,separator:d,debugIds:n})=>{const[I,u,l]=((e,t)=>[e,e?.getStore(),e?.getTableId(t)])(F(o),e),i=$e(e,t,I);return oo(v(i,(e=>Gt(s,{...Wt(r,e),key:e,tableId:l,rowId:e,store:u,debugIds:n}))),d,n,t)},po=({indexId:e,indexes:t,sliceComponent:o=ao,getSliceComponentProps:s,separator:r,debugIds:d})=>oo(v(Ye(e,t),(r=>Gt(o,{...Wt(s,r),key:r,indexId:e,sliceId:r,indexes:t,debugIds:d}))),r,d,e),go=({relationshipId:e,localRowId:t,relationships:o,rowComponent:s=ro,getRowComponentProps:r,debugIds:d})=>{const[n,I,,u]=Xt(O(o),e),l=rt(e,t,n);return oo(y(u)||y(l)?null:Gt(s,{...Wt(r,l),key:l,tableId:u,rowId:l,store:I,debugIds:d}),void 0,d,t)},bo=e=>_t(e,dt,e.remoteRowId),Co=e=>_t(e,nt,e.firstRowId),mo=({queryId:e,rowId:t,cellId:o,queries:r,debugIds:d})=>oo(s+(wt(e,t,o,r)??s),void 0,d,o),ko=({queryId:e,rowId:t,queries:o,resultCellComponent:s=mo,getResultCellComponentProps:r,separator:d,debugIds:n})=>oo(v(yt(e,t,o),(d=>Gt(s,{...Wt(r,d),key:d,queryId:e,rowId:t,cellId:d,queries:o,debugIds:n}))),d,n,t),yo=e=>$t(e,Ct(e.queryId,e.queries)),wo=({cellId:e,descending:t,offset:o,limit:s,...r})=>$t(r,mt(r.queryId,e,t,o,s,r.queries)),ho=({checkpoints:e,checkpointId:t,debugIds:o})=>oo(Mt(t,e)??s,void 0,o,t),Ro=eo((e=>e[0])),vo=eo((e=>y(e[1])?[]:[e[1]])),qo=eo((e=>e[2]));export{Ro as BackwardCheckpointsView,so as CellView,ho as CheckpointView,vo as CurrentCheckpointView,qo as ForwardCheckpointsView,po as IndexView,Co as LinkedRowsView,bo as LocalRowsView,co as MetricView,to as Provider,go as RemoteRowView,mo as ResultCellView,ko as ResultRowView,wo as ResultSortedTableView,yo as ResultTableView,ro as RowView,ao as SliceView,Io as SortedTableView,no as TableView,uo as TablesView,lo as ValueView,io as ValuesView,ke as useAddRowCallback,ce as useCell,ie as useCellIds,Oe as useCellIdsListener,Qe as useCellListener,Mt as useCheckpoint,Tt as useCheckpointIds,Qt as useCheckpointIdsListener,zt as useCheckpointListener,D as useCheckpoints,Bt as useCheckpointsIds,G as useCheckpointsOrCheckpointsById,Lt as useCreateCheckpoints,We as useCreateIndexes,He as useCreateMetrics,Dt as useCreatePersister,it as useCreateQueries,tt as useCreateRelationships,ee as useCreateStore,xe as useDelCellCallback,fe as useDelRowCallback,Pe as useDelTableCallback,qe as useDelTablesCallback,Le as useDelValueCallback,Se as useDelValuesCallback,Vt as useGoBackwardCallback,At as useGoForwardCallback,Ft as useGoToCallback,Ze as useIndexIds,A as useIndexes,Xe as useIndexesIds,F as useIndexesOrIndexesById,nt as useLinkedRowIds,lt as useLinkedRowIdsListener,dt as useLocalRowIds,ut as useLocalRowIdsListener,Ne as useMetric,Ke as useMetricIds,Ue as useMetricListener,E as useMetrics,Je as useMetricsIds,V as useMetricsOrMetricsById,Q as useQueries,ct as useQueriesIds,z as useQueriesOrQueriesById,at as useQueryIds,Ot as useRedoInformation,st as useRelationshipIds,j as useRelationships,ot as useRelationshipsIds,O as useRelationshipsOrRelationshipsById,rt as useRemoteRowId,It as useRemoteRowIdListener,wt as useResultCell,yt as useResultCellIds,xt as useResultCellIdsListener,St as useResultCellListener,kt as useResultRow,bt as useResultRowCount,vt as useResultRowCountListener,Ct as useResultRowIds,qt as useResultRowIdsListener,ft as useResultRowListener,mt as useResultSortedRowIds,Pt as useResultSortedRowIdsListener,pt as useResultTable,gt as useResultTableCellIds,Rt as useResultTableCellIdsListener,ht as useResultTableListener,le as useRow,ne as useRowCount,Ve as useRowCountListener,Ie as useRowIds,Ae as useRowIdsListener,je as useRowListener,we as useSetCellCallback,Et as useSetCheckpointCallback,ye as useSetPartialRowCallback,Re as useSetPartialValuesCallback,me as useSetRowCallback,Ce as useSetTableCallback,be as useSetTablesCallback,ve as useSetValueCallback,he as useSetValuesCallback,Ye as useSliceIds,_e as useSliceIdsListener,$e as useSliceRowIds,et as useSliceRowIdsListener,ue as useSortedRowIds,Fe as useSortedRowIdsListener,T as useStore,te as useStoreIds,M as useStoreOrStoreById,re as useTable,de as useTableCellIds,Ee as useTableCellIdsListener,se as useTableIds,Te as useTableIdsListener,Me as useTableListener,oe as useTables,Be as useTablesListener,jt as useUndoInformation,ge as useValue,pe as useValueIds,De as useValueIdsListener,Ge as useValueListener,ae as useValues,ze as useValuesListener};
|
|
1
|
+
import e,{useContext as t}from"react";const o=e=>typeof e,s="",r=o(s),d="Result",n="Ids",I="Table",u=I+"s",l=I+n,i="Row",c=i+"Count",a=i+n,p="Sorted"+i+n,g="Cell",b=g+n,C="Value",m=C+"s",k=C+n,y=e=>null==e,w=(e,t,o)=>y(e)?o?.():t(e),h=e=>o(e)==r,R=()=>{},v=(e,t)=>e.map(t),q=Object.keys,{createContext:P,useContext:f}=e,x=P([]),S=(e,t)=>{const o=f(x);return y(e)?o[t]:h(e)?((e,t)=>w(e,(e=>e[t])))(o[t+1]??{},e):e},L=(e,t)=>{const o=S(e,t);return y(e)||h(e)?o:e},B=e=>q(f(x)[e]??{}),T=e=>S(e,0),M=e=>L(e,0),E=e=>S(e,2),V=e=>L(e,2),A=e=>S(e,4),F=e=>L(e,4),j=e=>S(e,6),O=e=>L(e,6),Q=e=>S(e,8),z=e=>L(e,8),D=e=>S(e,10),G=e=>L(e,10),{useCallback:H,useEffect:J,useMemo:K,useRef:N,useState:U}=e,W=(e,t,o=[])=>{const s=K((()=>t(e)),[e,...o]);return J((()=>()=>s.destroy()),[s]),s},X=(e,t,o,s=[],r)=>{const[,d]=U(),n=H((()=>t?.["get"+e]?.(...s)??o),[t,...s]),[I]=U(n),u=N(I);return K((()=>u.current=n()),[n]),Y(e,t,((...e)=>{u.current=y(r)?n():e[r],d([])}),[],s),u.current},Y=(e,t,o,s=[],r=[],...d)=>J((()=>{const s=t?.["add"+e+"Listener"]?.(...r,o,...d);return()=>t?.delListener(s)}),[t,...r,...s,...d]),Z=(e,t,o,s=[],r=R,d=[],...n)=>{const I=M(e);return H((e=>w(I,(s=>w(o(e,s),(e=>r(s["set"+t](...n,e),e)))))),[I,t,...s,...d,...n])},$=(e,t,o=R,s=[],...r)=>{const d=M(e);return H((()=>o(d?.["del"+t](...r))),[d,t,...s,...r])},_=(e,t,o)=>{const s=G(e);return H((()=>s?.[t](o)),[s,t,o])},ee=(e,t=[])=>K(e,t),te=()=>B(1),oe=e=>X(u,M(e),{}),se=e=>X(l,M(e),[],[]),re=(e,t)=>X(I,M(t),{},[e]),de=(e,t)=>X(I+b,M(t),[],[e]),ne=(e,t)=>X(c,M(t),[],[e]),Ie=(e,t)=>X(a,M(t),[],[e]),ue=(e,t,o,s=0,r,d)=>X(p,M(d),[],[e,t,o,s,r],6),le=(e,t,o)=>X(i,M(o),{},[e,t]),ie=(e,t,o)=>X(b,M(o),[],[e,t]),ce=(e,t,o,s)=>X(g,M(s),void 0,[e,t,o],4),ae=e=>X(m,M(e),{}),pe=e=>X(k,M(e),[],[]),ge=(e,t)=>X(C,M(t),void 0,[e]),be=(e,t,o,s,r)=>Z(o,u,e,t,s,r),Ce=(e,t,o,s,r,d)=>Z(s,I,t,o,r,d,e),me=(e,t,o,s,r,d,n)=>Z(r,i,o,s,d,n,e,t),ke=(e,t,o=[],s,r=R,d=[],n=!0)=>{const I=M(s);return H((o=>w(I,(s=>w(t(o,s),(t=>r(s.addRow(e,t,n),s,t)))))),[I,e,...o,...d,n])},ye=(e,t,o,s,r,d,n)=>Z(r,"PartialRow",o,s,d,n,e,t),we=(e,t,o,s,r,d,n,I)=>Z(d,g,s,r,n,I,e,t,o),he=(e,t,o,s,r)=>Z(o,m,e,t,s,r),Re=(e,t,o,s,r)=>Z(o,"PartialValues",e,t,s,r),ve=(e,t,o,s,r,d)=>Z(s,C,t,o,r,d,e),qe=(e,t,o)=>$(e,u,t,o),Pe=(e,t,o,s)=>$(t,I,o,s,e),fe=(e,t,o,s,r)=>$(o,i,s,r,e,t),xe=(e,t,o,s,r,d,n)=>$(r,g,d,n,e,t,o,s),Se=(e,t,o)=>$(e,m,t,o),Le=(e,t,o,s)=>$(t,C,o,s,e),Be=(e,t,o,s)=>Y(u,M(s),e,t,[],o),Te=(e,t,o,s)=>Y(l,M(s),e,t,[],o),Me=(e,t,o,s,r)=>Y(I,M(r),t,o,[e],s),Ee=(e,t,o,s,r)=>Y(I+b,M(r),t,o,[e],s),Ve=(e,t,o,s,r)=>Y(c,M(r),t,o,[e],s),Ae=(e,t,o,s,r)=>Y(a,M(r),t,o,[e],s),Fe=(e,t,o,s,r,d,n,I,u)=>Y(p,M(u),d,n,[e,t,o,s,r],I),je=(e,t,o,s,r,d)=>Y(i,M(d),o,s,[e,t],r),Oe=(e,t,o,s,r,d)=>Y(b,M(d),o,s,[e,t],r),Qe=(e,t,o,s,r,d,n)=>Y(g,M(n),s,r,[e,t,o],d),ze=(e,t,o,s)=>Y(m,M(s),e,t,[],o),De=(e,t,o,s)=>Y(k,M(s),e,t,[],o),Ge=(e,t,o,s,r)=>Y(C,M(r),t,o,[e],s),He=(e,t,o)=>W(e,t,o),Je=()=>B(3),Ke=e=>X("MetricIds",V(e),[]),Ne=(e,t)=>X("Metric",V(t),void 0,[e]),Ue=(e,t,o,s)=>Y("Metric",V(s),t,o,[e]),We=(e,t,o)=>W(e,t,o),Xe=()=>B(5),Ye=(e,t)=>X("SliceIds",F(t),[],[e]),Ze=e=>X("IndexIds",F(e),[]),$e=(e,t,o)=>X("Slice"+a,F(o),[],[e,t]),_e=(e,t,o,s)=>Y("SliceIds",F(s),t,o,[e]),et=(e,t,o,s,r)=>Y("Slice"+a,F(r),o,s,[e,t]),tt=(e,t,o)=>W(e,t,o),ot=()=>B(7),st=e=>X("RelationshipIds",O(e),[]),rt=(e,t,o)=>X("RemoteRowId",O(o),void 0,[e,t]),dt=(e,t,o)=>X("Local"+a,O(o),[],[e,t]),nt=(e,t,o)=>X("Linked"+a,O(o),[],[e,t]),It=(e,t,o,s,r)=>Y("RemoteRowId",O(r),o,s,[e,t]),ut=(e,t,o,s,r)=>Y("Local"+a,O(r),o,s,[e,t]),lt=(e,t,o,s,r)=>Y("Linked"+a,O(r),o,s,[e,t]),it=(e,t,o)=>W(e,t,o),ct=()=>B(9),at=e=>X("QueryIds",z(e),[]),pt=(e,t)=>X(d+I,z(t),{},[e]),gt=(e,t)=>X(d+I+b,z(t),[],[e]),bt=(e,t)=>X(d+c,z(t),[],[e]),Ct=(e,t)=>X(d+a,z(t),[],[e]),mt=(e,t,o,s=0,r,n)=>X(d+p,z(n),[],[e,t,o,s,r],6),kt=(e,t,o)=>X(d+i,z(o),{},[e,t]),yt=(e,t,o)=>X(d+b,z(o),[],[e,t]),wt=(e,t,o,s)=>X(d+g,z(s),void 0,[e,t,o]),ht=(e,t,o,s)=>Y(d+I,z(s),t,o,[e]),Rt=(e,t,o,s)=>Y(d+I+b,z(s),t,o,[e]),vt=(e,t,o,s)=>Y(d+c,z(s),t,o,[e]),qt=(e,t,o,s)=>Y(d+a,z(s),t,o,[e]),Pt=(e,t,o,s,r,n,I,u)=>Y(d+p,z(u),n,I,[e,t,o,s,r]),ft=(e,t,o,s,r)=>Y(d+i,z(r),o,s,[e,t]),xt=(e,t,o,s,r)=>Y(d+b,z(r),o,s,[e,t]),St=(e,t,o,s,r,n)=>Y(d+g,z(n),s,r,[e,t,o]),Lt=(e,t,o)=>W(e,t,o),Bt=()=>B(11),Tt=e=>X("CheckpointIds",G(e),[[],void 0,[]]),Mt=(e,t)=>X("Checkpoint",G(t),void 0,[e]),Et=(e=R,t=[],o,s=R,r=[])=>{const d=G(o);return H((t=>w(d,(o=>{const r=e(t);s(o.addCheckpoint(r),o,r)}))),[d,...t,...r])},Vt=e=>_(e,"goBackward"),At=e=>_(e,"goForward"),Ft=(e,t=[],o,s=R,r=[])=>{const d=G(o);return H((t=>w(d,(o=>w(e(t),(e=>s(o.goTo(e),e)))))),[d,...t,...r])},jt=e=>{const t=G(e),[o,r]=Tt(t);return[(d=o,!(0==(e=>e.length)(d))),Vt(t),r,w(r,(e=>t?.getCheckpoint(e)))??s];var d},Ot=e=>{const t=G(e),[,,[o]]=Tt(t);return[!y(o),At(t),o,w(o,(e=>t?.getCheckpoint(e)))??s]},Qt=(e,t,o)=>Y("CheckpointIds",G(o),e,t),zt=(e,t,o,s)=>Y("Checkpoint",G(s),t,o,[e]),Dt=(e,t,o=[],s,r=[])=>{const[,d]=U(),n=K((()=>t(e)),[e,...o]);return J((()=>((async()=>{await(s?.(n)),d(1)})(),()=>{n.destroy()})),[n,...r]),n},{PureComponent:Gt,Fragment:Ht,createElement:Jt,useCallback:Kt,useLayoutEffect:Nt,useRef:Ut,useState:Wt}=e,Xt=(e,...t)=>y(e)?{}:e(...t),Yt=(e,t)=>[e,e?.getStore(),e?.getLocalTableId(t),e?.getRemoteTableId(t)],{useMemo:Zt}=e,$t=({tableId:e,store:t,rowComponent:o=no,getRowComponentProps:s,customCellIds:r,separator:d,debugIds:n},I)=>so(v(I,(d=>Jt(o,{...Xt(s,d),key:d,tableId:e,rowId:d,customCellIds:r,store:t,debugIds:n}))),d,n,e),_t=({queryId:e,queries:t,resultRowComponent:o=yo,getResultRowComponentProps:s,separator:r,debugIds:d},n)=>so(v(n,(r=>Jt(o,{...Xt(s,r),key:r,queryId:e,rowId:r,queries:t,debugIds:d}))),r,d,e),eo=({relationshipId:e,relationships:t,rowComponent:o=no,getRowComponentProps:s,separator:r,debugIds:d},n,I)=>{const[u,l,i]=Yt(O(t),e),c=n(e,I,u);return so(v(c,(e=>Jt(o,{...Xt(s,e),key:e,tableId:i,rowId:e,store:l,debugIds:d}))),r,d,I)},to=e=>({checkpoints:t,checkpointComponent:o=Ro,getCheckpointComponentProps:s,separator:r,debugIds:d})=>{const n=G(t);return so(v(e(Tt(n)),(e=>Jt(o,{...Xt(s,e),key:e,checkpoints:n,checkpointId:e,debugIds:d}))),r)},oo=({store:e,storesById:o,metrics:s,metricsById:r,indexes:d,indexesById:n,relationships:I,relationshipsById:u,queries:l,queriesById:i,checkpoints:c,checkpointsById:a,children:p})=>{const g=t(x);return Jt(x.Provider,{value:Zt((()=>[e??g[0],{...g[1],...o},s??g[2],{...g[3],...r},d??g[4],{...g[5],...n},I??g[6],{...g[7],...u},l??g[8],{...g[9],...i},c??g[10],{...g[11],...a}]),[e,o,s,r,d,n,I,u,l,i,c,a,g])},p)},so=(e,t,o,s)=>{const r=y(t)||!Array.isArray(e)?e:v(e,((e,o)=>o>0?[t,e]:e));return o?[s,":{",r,"}"]:r},ro=({tableId:e,rowId:t,cellId:o,store:r,debugIds:d})=>so(s+(ce(e,t,o,r)??s),void 0,d,o),no=({tableId:e,rowId:t,store:o,cellComponent:s=ro,getCellComponentProps:r,customCellIds:d,separator:n,debugIds:I})=>so(v(((e,t,o,s)=>{const r=ie(t,o,s);return e??r})(d,e,t,o),(d=>Jt(s,{...Xt(r,d),key:d,tableId:e,rowId:t,cellId:d,store:o,debugIds:I}))),n,I,t),Io=e=>$t(e,Ie(e.tableId,e.store)),uo=({cellId:e,descending:t,offset:o,limit:s,...r})=>$t(r,ue(r.tableId,e,t,o,s,r.store)),lo=({store:e,tableComponent:t=Io,getTableComponentProps:o,separator:s,debugIds:r})=>so(v(se(e),(s=>Jt(t,{...Xt(o,s),key:s,tableId:s,store:e,debugIds:r}))),s),io=({valueId:e,store:t,debugIds:o})=>so(s+(ge(e,t)??s),void 0,o,e),co=({store:e,valueComponent:t=io,getValueComponentProps:o,separator:s,debugIds:r})=>so(v(pe(e),(s=>Jt(t,{...Xt(o,s),key:s,valueId:s,store:e,debugIds:r}))),s),ao=({metricId:e,metrics:t,debugIds:o})=>so(Ne(e,t)??s,void 0,o,e),po=({indexId:e,sliceId:t,indexes:o,rowComponent:s=no,getRowComponentProps:r,separator:d,debugIds:n})=>{const[I,u,l]=((e,t)=>[e,e?.getStore(),e?.getTableId(t)])(F(o),e),i=$e(e,t,I);return so(v(i,(e=>Jt(s,{...Xt(r,e),key:e,tableId:l,rowId:e,store:u,debugIds:n}))),d,n,t)},go=({indexId:e,indexes:t,sliceComponent:o=po,getSliceComponentProps:s,separator:r,debugIds:d})=>so(v(Ye(e,t),(r=>Jt(o,{...Xt(s,r),key:r,indexId:e,sliceId:r,indexes:t,debugIds:d}))),r,d,e),bo=({relationshipId:e,localRowId:t,relationships:o,rowComponent:s=no,getRowComponentProps:r,debugIds:d})=>{const[n,I,,u]=Yt(O(o),e),l=rt(e,t,n);return so(y(u)||y(l)?null:Jt(s,{...Xt(r,l),key:l,tableId:u,rowId:l,store:I,debugIds:d}),void 0,d,t)},Co=e=>eo(e,dt,e.remoteRowId),mo=e=>eo(e,nt,e.firstRowId),ko=({queryId:e,rowId:t,cellId:o,queries:r,debugIds:d})=>so(s+(wt(e,t,o,r)??s),void 0,d,o),yo=({queryId:e,rowId:t,queries:o,resultCellComponent:s=ko,getResultCellComponentProps:r,separator:d,debugIds:n})=>so(v(yt(e,t,o),(d=>Jt(s,{...Xt(r,d),key:d,queryId:e,rowId:t,cellId:d,queries:o,debugIds:n}))),d,n,t),wo=e=>_t(e,Ct(e.queryId,e.queries)),ho=({cellId:e,descending:t,offset:o,limit:s,...r})=>_t(r,mt(r.queryId,e,t,o,s,r.queries)),Ro=({checkpoints:e,checkpointId:t,debugIds:o})=>so(Mt(t,e)??s,void 0,o,t),vo=to((e=>e[0])),qo=to((e=>y(e[1])?[]:[e[1]])),Po=to((e=>e[2]));export{vo as BackwardCheckpointsView,ro as CellView,Ro as CheckpointView,qo as CurrentCheckpointView,Po as ForwardCheckpointsView,go as IndexView,mo as LinkedRowsView,Co as LocalRowsView,ao as MetricView,oo as Provider,bo as RemoteRowView,ko as ResultCellView,yo as ResultRowView,ho as ResultSortedTableView,wo as ResultTableView,no as RowView,po as SliceView,uo as SortedTableView,Io as TableView,lo as TablesView,io as ValueView,co as ValuesView,ke as useAddRowCallback,ce as useCell,ie as useCellIds,Oe as useCellIdsListener,Qe as useCellListener,Mt as useCheckpoint,Tt as useCheckpointIds,Qt as useCheckpointIdsListener,zt as useCheckpointListener,D as useCheckpoints,Bt as useCheckpointsIds,G as useCheckpointsOrCheckpointsById,Lt as useCreateCheckpoints,We as useCreateIndexes,He as useCreateMetrics,Dt as useCreatePersister,it as useCreateQueries,tt as useCreateRelationships,ee as useCreateStore,xe as useDelCellCallback,fe as useDelRowCallback,Pe as useDelTableCallback,qe as useDelTablesCallback,Le as useDelValueCallback,Se as useDelValuesCallback,Vt as useGoBackwardCallback,At as useGoForwardCallback,Ft as useGoToCallback,Ze as useIndexIds,A as useIndexes,Xe as useIndexesIds,F as useIndexesOrIndexesById,nt as useLinkedRowIds,lt as useLinkedRowIdsListener,dt as useLocalRowIds,ut as useLocalRowIdsListener,Ne as useMetric,Ke as useMetricIds,Ue as useMetricListener,E as useMetrics,Je as useMetricsIds,V as useMetricsOrMetricsById,Q as useQueries,ct as useQueriesIds,z as useQueriesOrQueriesById,at as useQueryIds,Ot as useRedoInformation,st as useRelationshipIds,j as useRelationships,ot as useRelationshipsIds,O as useRelationshipsOrRelationshipsById,rt as useRemoteRowId,It as useRemoteRowIdListener,wt as useResultCell,yt as useResultCellIds,xt as useResultCellIdsListener,St as useResultCellListener,kt as useResultRow,bt as useResultRowCount,vt as useResultRowCountListener,Ct as useResultRowIds,qt as useResultRowIdsListener,ft as useResultRowListener,mt as useResultSortedRowIds,Pt as useResultSortedRowIdsListener,pt as useResultTable,gt as useResultTableCellIds,Rt as useResultTableCellIdsListener,ht as useResultTableListener,le as useRow,ne as useRowCount,Ve as useRowCountListener,Ie as useRowIds,Ae as useRowIdsListener,je as useRowListener,we as useSetCellCallback,Et as useSetCheckpointCallback,ye as useSetPartialRowCallback,Re as useSetPartialValuesCallback,me as useSetRowCallback,Ce as useSetTableCallback,be as useSetTablesCallback,ve as useSetValueCallback,he as useSetValuesCallback,Ye as useSliceIds,_e as useSliceIdsListener,$e as useSliceRowIds,et as useSliceRowIdsListener,ue as useSortedRowIds,Fe as useSortedRowIdsListener,T as useStore,te as useStoreIds,M as useStoreOrStoreById,re as useTable,de as useTableCellIds,Ee as useTableCellIdsListener,se as useTableIds,Te as useTableIdsListener,Me as useTableListener,oe as useTables,Be as useTablesListener,jt as useUndoInformation,ge as useValue,pe as useValueIds,De as useValueIdsListener,Ge as useValueListener,ae as useValues,ze as useValuesListener};
|
package/lib/ui-react.js.gz
CHANGED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t,e;t=this,e=function(t){"use strict";const e=(t,e)=>t.map(e),a=(t,...e)=>t.push(...e),s=Promise,n=setInterval,o=clearInterval,r=t=>null==t,c=(t,e,a)=>r(t)?a?.():e(t),i=t=>new s(t),d=async t=>s.all(t),y=Object,l=y.keys,u=y.freeze,w=t=>(t=>t instanceof y&&t.constructor==y)(t)&&0==(t=>l(t).length)(t),h=t=>new Map(t),p=(t,e)=>t?.get(e),f=(t,e,a)=>{return r(a)?(s=t,n=e,s?.delete(n),t):t?.set(e,a);var s,n},v=(t,e,a)=>{var s,n;return s=t,n=e,s?.has(n)||f(t,e,a()),p(t,e)},g=h(),b=h(),A=globalThis.window,S=["t","v"],x={keyPath:"k"},j=async(t,s)=>{const n=((a,s)=>e(y.entries(a),(([e,a])=>L(t,"put",{k:e,v:a}))))(s);e(await L(t,"getAllKeys"),(e=>((t,e)=>!r(((t,e)=>c(t,(t=>t[e])))(t,e)))(s,e)?0:a(n,L(t,"delete",e)))),await d(n)},L=async(t,e,a)=>i(((s,n)=>{const o=t[e](a);o.onsuccess=()=>s(o.result),o.onerror=()=>n(`objectStore.${e} error`)}));t.createIndexedDbPersister=(t,s,l=1,h)=>{const T=async(t,a=[],n=0)=>i(((o,r)=>{const c=A.indexedDB.open(s,1);c.onupgradeneeded=()=>n&&e(S,(t=>c.result.createObjectStore(t,x))),c.onsuccess=async()=>{try{const s=c.result.transaction(S,"readwrite"),n=await d(e(S,(async(e,n)=>await t(s.objectStore(e),a[n]))));c.result.close(),o(n)}catch(t){r(t)}},c.onerror=()=>r("indexedDB.open error")}));return((t,e,s,n,o,i,d=[])=>{let y,l,h,A=0,S=0;v(g,d,(()=>0)),v(b,d,(()=>[]));const x=async t=>(2!=A&&(A=1,await j.schedule((async()=>{await t(),A=0}))),j),j={load:async(a,s)=>await x((async()=>{try{t.setContent(await e())}catch{t.setContent([a,s])}})),startAutoLoad:async(a={},s={})=>(j.stopAutoLoad(),await j.load(a,s),S=1,h=n((async(a,s)=>{if(s){const e=s();await x((async()=>t.setTransactionChanges(e)))}else await x((async()=>{try{t.setContent(a?.()??await e())}catch(t){i?.(t)}}))})),j),stopAutoLoad:()=>(S&&(o(h),h=void 0,S=0),j),save:async e=>(1!=A&&(A=2,await j.schedule((async()=>{try{await s(t.getContent,e)}catch(t){i?.(t)}A=0}))),j),startAutoSave:async()=>(await j.stopAutoSave().save(),y=t.addDidFinishTransactionListener(((t,e)=>{const[a,s]=e();w(a)&&w(s)||j.save((()=>[a,s]))})),j),stopAutoSave:()=>(c(y,t.delListener),j),schedule:async(...t)=>(a(p(b,d),...t),await(async()=>{if(!p(g,d)){for(f(g,d,1);!r((t=p(b,d),l=t.shift()));)try{await l()}catch(t){i?.(t)}f(g,d,0)}var t})(),j),getStore:()=>t,destroy:()=>j.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return u(j)})(t,(async()=>await T((async t=>((t=[])=>y.fromEntries(t))(e(await L(t,"getAll"),(({k:t,v:e})=>[t,e])))))),(async t=>await T((async(t,e)=>await j(t,e)),t(),1)),(t=>n(t,1e3*l)),(t=>o(t)),h)},t.objectStoreMatch=j},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterIndexedDb={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e;t=this,e=function(t){"use strict";const e=setInterval,a=clearInterval,s=(t,e)=>t instanceof e,n=t=>null==t,o=Object,r=o.keys,c=o.freeze,i=t=>(t=>s(t,o)&&t.constructor==o)(t)&&0==(t=>r(t).length)(t),d=JSON.parse,y=t=>new Map(t),u=(t,e)=>t?.get(e),f=(t,e,a)=>{return n(a)?(s=t,o=e,s?.delete(o),t):t?.set(e,a);var s,o},h=(t,e,a)=>{var s,n;return s=t,n=e,s?.has(n)||f(t,e,a()),u(t,e)},l=y(),p=y(),w=t=>t.headers.get("ETag");t.createRemotePersister=(t,r,y,v,g)=>{let A;return((t,e,a,s,o,r,d=[])=>{let y,w,v,g=0,A=0;h(l,d,(()=>0)),h(p,d,(()=>[]));const S=async t=>(2!=g&&(g=1,await T.schedule((async()=>{await t(),g=0}))),T),T={load:async(a,s)=>await S((async()=>{try{t.setContent(await e())}catch{t.setContent([a,s])}})),startAutoLoad:async(a={},n={})=>(T.stopAutoLoad(),await T.load(a,n),A=1,v=s((async(a,s)=>{if(s){const e=s();await S((async()=>t.setTransactionChanges(e)))}else await S((async()=>{try{t.setContent(a?.()??await e())}catch(t){r?.(t)}}))})),T),stopAutoLoad:()=>(A&&(o(v),v=void 0,A=0),T),save:async e=>(1!=g&&(g=2,await T.schedule((async()=>{try{await a(t.getContent,e)}catch(t){r?.(t)}g=0}))),T),startAutoSave:async()=>(await T.stopAutoSave().save(),y=t.addDidFinishTransactionListener(((t,e)=>{const[a,s]=e();i(a)&&i(s)||T.save((()=>[a,s]))})),T),stopAutoSave:()=>{var e,a;return e=y,a=t.delListener,n(e)||a(e),T},schedule:async(...t)=>(((t,...e)=>{t.push(...e)})(u(p,d),...t),await(async()=>{if(!u(l,d)){for(f(l,d,1);!n((t=u(p,d),w=t.shift()));)try{await w()}catch(t){r?.(t)}f(l,d,0)}var t})(),T),getStore:()=>t,destroy:()=>T.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return c(T)})(t,(async()=>{const t=await fetch(r);return A=w(t),d(await t.text())}),(async t=>{return await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:(e=t(),JSON.stringify(e,((t,e)=>s(e,Map)?o.fromEntries([...e]):e)))});var e}),(t=>e((async()=>{const e=await fetch(r,{method:"HEAD"}),a=w(e);n(A)||n(a)||a==A||(A=a,t())}),1e3*v)),(t=>a(t)),g)}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterRemote={});
|
|
1
|
+
var t,e;t=this,e=function(t){"use strict";const e=setInterval,a=clearInterval,s=(t,e)=>t instanceof e,n=t=>null==t,o=Object,r=o.keys,c=o.freeze,i=t=>(t=>s(t,o)&&t.constructor==o)(t)&&0==(t=>r(t).length)(t),d=JSON.parse,y=t=>new Map(t),u=(t,e)=>t?.get(e),f=(t,e,a)=>{return n(a)?(s=t,o=e,s?.delete(o),t):t?.set(e,a);var s,o},h=(t,e,a)=>{var s,n;return s=t,n=e,s?.has(n)||f(t,e,a()),u(t,e)},l=y(),p=y(),w=t=>t.headers.get("ETag");t.createRemotePersister=(t,r,y,v=5,g)=>{let A;return((t,e,a,s,o,r,d=[])=>{let y,w,v,g=0,A=0;h(l,d,(()=>0)),h(p,d,(()=>[]));const S=async t=>(2!=g&&(g=1,await T.schedule((async()=>{await t(),g=0}))),T),T={load:async(a,s)=>await S((async()=>{try{t.setContent(await e())}catch{t.setContent([a,s])}})),startAutoLoad:async(a={},n={})=>(T.stopAutoLoad(),await T.load(a,n),A=1,v=s((async(a,s)=>{if(s){const e=s();await S((async()=>t.setTransactionChanges(e)))}else await S((async()=>{try{t.setContent(a?.()??await e())}catch(t){r?.(t)}}))})),T),stopAutoLoad:()=>(A&&(o(v),v=void 0,A=0),T),save:async e=>(1!=g&&(g=2,await T.schedule((async()=>{try{await a(t.getContent,e)}catch(t){r?.(t)}g=0}))),T),startAutoSave:async()=>(await T.stopAutoSave().save(),y=t.addDidFinishTransactionListener(((t,e)=>{const[a,s]=e();i(a)&&i(s)||T.save((()=>[a,s]))})),T),stopAutoSave:()=>{var e,a;return e=y,a=t.delListener,n(e)||a(e),T},schedule:async(...t)=>(((t,...e)=>{t.push(...e)})(u(p,d),...t),await(async()=>{if(!u(l,d)){for(f(l,d,1);!n((t=u(p,d),w=t.shift()));)try{await w()}catch(t){r?.(t)}f(l,d,0)}var t})(),T),getStore:()=>t,destroy:()=>T.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return c(T)})(t,(async()=>{const t=await fetch(r);return A=w(t),d(await t.text())}),(async t=>{return await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:(e=t(),JSON.stringify(e,((t,e)=>s(e,Map)?o.fromEntries([...e]):e)))});var e}),(t=>e((async()=>{const e=await fetch(r,{method:"HEAD"}),a=w(e);n(A)||n(a)||a==A||(A=a,t())}),1e3*v)),(t=>a(t)),g)}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterRemote={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t,e;t=this,e=function(t,e){"use strict";const s=t=>t.length,
|
|
1
|
+
var t,e;t=this,e=function(t,e){"use strict";const s="t",a="v",n=t=>t.length,o=t=>t.shift(),c=t=>null==t,r=(t,e,s)=>c(t)?s?.():e(t),i=Object,d=i.keys,l=i.freeze,u=(t=[])=>i.fromEntries(t),y=(t,e)=>!c(((t,e)=>r(t,(t=>t[e])))(t,e)),g=(t,e)=>((t,e)=>t.map(e))(i.entries(t),(([t,s])=>e(s,t))),f=t=>(t=>t instanceof i&&t.constructor==i)(t)&&0==(t=>n(d(t)))(t),p=(t,e,s)=>(y(t,e)||(t[e]=s()),t[e]),h=t=>new Map(t),v=(t,e)=>t?.get(e),w=(t,e)=>((t,e)=>t?.forEach(e))(t,((t,s)=>e(s,t))),S=(t,e,s)=>{return c(s)?(a=t,n=e,a?.delete(n),t):t?.set(e,s);var a,n},A=(t,e,s)=>{var a,n;return a=t,n=e,a?.has(n)||S(t,e,s()),v(t,e)},b=h(),j=h(),O="delete",J=t=>[t.get(s),t.get(a)],L=(t,s,a,n)=>{const o=c(s)?t:t.get(s)??t.set(s,new e.Map);let r;return g(a,((t,e)=>{n(o,e,t)&&(r=1)})),o.forEach(((t,e)=>{y(a,e)||(o.delete(e),r=1)})),c(s)||o.size||t.delete(s),r};t.createYjsPersister=(t,i,d="tinybase",y)=>{const h=i.getMap(d);return((t,e,s,a,n,i,d=[])=>{let u,y,g,p=0,h=0;A(b,d,(()=>0)),A(j,d,(()=>[]));const w=async t=>(2!=p&&(p=1,await O.schedule((async()=>{await t(),p=0}))),O),O={load:async(s,a)=>await w((async()=>{try{t.setContent(await e())}catch{t.setContent([s,a])}})),startAutoLoad:async(s={},n={})=>(O.stopAutoLoad(),await O.load(s,n),h=1,g=a((async(s,a)=>{if(a){const e=a();await w((async()=>t.setTransactionChanges(e)))}else await w((async()=>{try{t.setContent(s?.()??await e())}catch(t){i?.(t)}}))})),O),stopAutoLoad:()=>(h&&(n(g),g=void 0,h=0),O),save:async e=>(1!=p&&(p=2,await O.schedule((async()=>{try{await s(t.getContent,e)}catch(t){i?.(t)}p=0}))),O),startAutoSave:async()=>(await O.stopAutoSave().save(),u=t.addDidFinishTransactionListener(((t,e)=>{const[s,a]=e();f(s)&&f(a)||O.save((()=>[s,a]))})),O),stopAutoSave:()=>(r(u,t.delListener),O),schedule:async(...t)=>(((t,...e)=>{t.push(...e)})(v(j,d),...t),await(async()=>{if(!v(b,d)){for(S(b,d,1);!c(y=o(v(j,d)));)try{await y()}catch(t){i?.(t)}S(b,d,0)}})(),O),getStore:()=>t,destroy:()=>O.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return l(O)})(t,(async()=>h.size?[h.get(s).toJSON(),h.get(a).toJSON()]:void 0),(async(t,n)=>i.transact((()=>((t,n,o)=>{t.size||(t.set(s,new e.Map),t.set(a,new e.Map));const[i,d]=J(t),l=()=>{u=1};let u=1;if(r(o?.(),(([t,e])=>{u=0,g(t,((t,e)=>u?0:c(t)?i.delete(e):r(i.get(e),(e=>g(t,((t,s)=>u?0:c(t)?e.delete(s):r(e.get(s),(e=>g(t,((t,s)=>c(t)?e.delete(s):e.set(s,t)))),l)))),l))),g(e,((t,e)=>u?0:c(t)?d.delete(e):d.set(e,t)))})),u){const[t,e]=n();L(i,void 0,t,((t,e,s)=>L(i,e,s,((t,e,s)=>L(t,e,s,((t,e,s)=>{if(t.get(e)!==s)return t.set(e,s),1})))))),L(d,void 0,e,((t,e,s)=>{d.get(e)!==s&&d.set(e,s)}))}})(h,t,n)))),(t=>{const e=e=>t(void 0,(()=>((t,e)=>{if(1==n(e)&&(c=e[0].path,0==n(c)))return[t.get(s).toJSON(),t.get(a).toJSON()];var c;const[i,d]=J(t),l={},y={};return((t,e)=>{t.forEach((({path:t,changes:{keys:e}})=>o(t)==s?r(o(t),(s=>{const a=p(l,s,u),n=i.get(s);r(o(t),(t=>{const s=p(a,t,u),o=n.get(t);w(e,((t,{action:e})=>s[t]=e==O?null:o.get(t)))}),(()=>w(e,((t,{action:e})=>a[t]=e==O?null:n.get(t)?.toJSON()))))}),(()=>w(e,((t,{action:e})=>l[t]=e==O?null:i.get(t)?.toJSON())))):w(e,((t,{action:e})=>y[t]=e==O?null:d.get(t)))))})(e),[l,y]})(h,e)));return h.observeDeep(e),e}),(t=>{h.unobserveDeep(t)}),y)}},"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("yjs")):"function"==typeof define&&define.amd?define(["exports","yjs"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterYjs={},t.yjs);
|
|
Binary file
|