tinybase 0.9.2 → 1.0.1
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/LICENSE +1 -1
- package/lib/checkpoints.d.ts +38 -20
- package/lib/common.d.ts +56 -0
- package/lib/common.js +1 -0
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +38 -20
- package/lib/debug/common.d.ts +56 -0
- package/lib/debug/common.js +3 -0
- package/lib/debug/indexes.d.ts +39 -76
- package/lib/debug/indexes.js +17 -9
- package/lib/debug/metrics.d.ts +49 -20
- package/lib/debug/persisters.d.ts +207 -17
- package/lib/debug/relationships.d.ts +48 -23
- package/lib/debug/store.d.ts +184 -102
- package/lib/debug/tinybase.d.ts +1 -2
- package/lib/debug/tinybase.js +16 -8
- package/lib/debug/ui-react.d.ts +271 -163
- package/lib/debug/ui-react.js +24 -15
- package/lib/indexes.d.ts +39 -76
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +49 -20
- package/lib/persisters.d.ts +207 -17
- package/lib/relationships.d.ts +48 -23
- package/lib/store.d.ts +184 -102
- package/lib/tinybase.d.ts +1 -2
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +271 -163
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/common.js +1 -0
- package/lib/umd/common.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +24 -15
- package/readme.md +13 -13
package/lib/ui-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"react";const
|
|
1
|
+
import e,{useContext as o}from"react";const t=e=>typeof e,d=t(""),s=(e,o)=>e.map(o),r=e=>null==e,n=(e,o,t)=>r(e)?t?.():o(e),i=()=>{},{createContext:c,useContext:l}=e,I=c([]),a=(e,o)=>{const t=l(I);return r(e)?t[o]:((e,o)=>n(e,(e=>e[o])))(t[o+1],e)},p=(e,o)=>{const s=a(e,o);return r(e)||(e=>t(e)==d)(e)?s:e},u=e=>a(e,0),b=e=>a(e,2),g=e=>a(e,4),w=e=>a(e,6),C=e=>a(e,8),m=e=>p(e,0),k=e=>p(e,2),R=e=>p(e,4),h=e=>p(e,6),v=e=>p(e,8),{useCallback:y,useEffect:T,useMemo:x,useState:P}=e,L=(e,o,t=[])=>{const d=x((()=>o(e)),[e,...t]);return T((()=>()=>d.destroy()),[d]),d},S=(e,o,t,...d)=>{const s=o?.["get"+e]??(()=>t),r=s(...d),[,n]=P(r);return T((()=>{const t=o?.[`add${e}Listener`]?.(...d,(()=>n(s(...d))),!1);return()=>o?.delListener(t)}),[o,e,n,s,...d]),r},B=(e,o,t,d=[],s,...r)=>{T((()=>{const d=o?.[`add${e}Listener`]?.(...r,t,s);return()=>o?.delListener(d)}),[o,e,...d,s,...r])},f=(e,o,t,d=[],s=i,r=[],...c)=>{const l=m(e);return y((e=>n(l,(d=>n(t(e,d),(e=>s(d["set"+o](...c,e),e)))))),[l,o,...d,...r,...c])},M=(e,o,t=i,d=[],...s)=>{const r=m(e);return y((()=>t(r?.["del"+o](...s))),[r,o,...d,...s])},A=(e,o,t)=>{const d=v(e);return y((()=>d?.[o](t)),[d,o,t])},E=(e,o=[])=>x(e,o),$=e=>S("Tables",m(e),{}),F=e=>S("TableIds",m(e),[]),j=(e,o)=>S("Table",m(o),{},e),q=(e,o)=>S("RowIds",m(o),[],e),z=(e,o,t)=>S("Row",m(t),{},e,o),D=(e,o,t)=>S("CellIds",m(t),[],e,o),G=(e,o,t,d)=>S("Cell",m(d),void 0,e,o,t),H=(e,o,t,d,s)=>f(t,"Tables",e,o,d,s),J=(e,o,t,d,s,r)=>f(d,"Table",o,t,s,r,e),K=(e,o,t,d,s,r,n)=>f(s,"Row",t,d,r,n,e,o),N=(e,o,t=[],d,s=i,r=[])=>{const c=m(d);return y((t=>n(c,(d=>n(o(t,d),(o=>s(d.addRow(e,o),d,o)))))),[c,e,...t,...r])},O=(e,o,t,d,s,r,n)=>f(s,"PartialRow",t,d,r,n,e,o),Q=(e,o,t,d,s,r,n,i)=>f(r,"Cell",d,s,n,i,e,o,t),U=(e,o,t)=>M(e,"Tables",o,t),V=(e,o,t,d)=>M(o,"Table",t,d,e),W=(e,o,t,d,s)=>M(t,"Row",d,s,e,o),X=(e,o,t,d,s,r,n)=>M(s,"Cell",r,n,e,o,t,d),Y=(e,o,t,d)=>B("Tables",m(d),e,o,t),Z=(e,o,t,d)=>B("TableIds",m(d),e,o,t),_=(e,o,t,d,s)=>B("Table",m(s),o,t,d,e),ee=(e,o,t,d,s)=>B("RowIds",m(s),o,t,d,e),oe=(e,o,t,d,s,r)=>B("Row",m(r),t,d,s,e,o),te=(e,o,t,d,s,r)=>B("CellIds",m(r),t,d,s,e,o),de=(e,o,t,d,s,r,n)=>B("Cell",m(n),d,s,r,e,o,t),se=(e,o,t)=>L(e,o,t),re=(e,o)=>S("Metric",k(o),void 0,e),ne=(e,o,t,d)=>B("Metric",k(d),o,t,void 0,e),ie=(e,o,t)=>L(e,o,t),ce=(e,o)=>S("SliceIds",R(o),[],e),le=(e,o,t)=>S("SliceRowIds",R(t),[],e,o),Ie=(e,o,t,d)=>B("SliceIds",R(d),o,t,void 0,e),ae=(e,o,t,d,s)=>B("SliceRowIds",R(s),t,d,void 0,e,o),pe=(e,o,t)=>L(e,o,t),ue=(e,o,t)=>S("RemoteRowId",h(t),void 0,e,o),be=(e,o,t)=>S("LocalRowIds",h(t),[],e,o),ge=(e,o,t)=>S("LinkedRowIds",h(t),[],e,o),we=(e,o,t,d,s)=>B("RemoteRowId",h(s),t,d,void 0,e,o),Ce=(e,o,t,d,s)=>B("LocalRowIds",h(s),t,d,void 0,e,o),me=(e,o,t,d,s)=>B("LinkedRowIds",h(s),t,d,void 0,e,o),ke=(e,o,t)=>L(e,o,t),Re=e=>S("CheckpointIds",v(e),[[],void 0,[]]),he=(e,o)=>S("Checkpoint",v(o),void 0,e),ve=(e=i,o=[],t,d=i,s=[])=>{const r=v(t);return y((o=>n(r,(t=>{const s=e(o);d(t.addCheckpoint(s),t,s)}))),[r,...o,...s])},ye=e=>A(e,"goBackward"),Te=e=>A(e,"goForward"),xe=(e,o=[],t,d=i,s=[])=>{const r=v(t);return y((o=>n(r,(t=>n(e(o),(e=>d(t.goTo(e),e)))))),[r,...o,...s])},Pe=e=>{const o=v(e),[t,d]=Re(o);return[(s=t,!(0==(e=>e.length)(s))),ye(o),d,n(d,(e=>o?.getCheckpoint(e)))??""];var s},Le=e=>{const o=v(e),[,,[t]]=Re(o);return[!r(t),Te(o),t,n(t,(e=>o?.getCheckpoint(e)))??""]},Se=(e,o,t)=>B("CheckpointIds",v(t),e,o),Be=(e,o,t,d)=>B("Checkpoint",v(d),o,t,void 0,e),fe=(e,o,t=[],d,s=[])=>{const[,r]=P(),n=x((()=>o(e)),[e,...t]);return T((()=>((async()=>{await(d?.(n)),r(1)})(),()=>{n.destroy()})),[n,...s]),n},{createElement:Me,useMemo:Ae}=e,Ee=e=>{const o=h(e);return[o,o?.getStore()]},$e=({relationshipId:e,relationships:o,rowComponent:t=Ge,getRowComponentProps:d,separator:r,debugIds:n},i,c)=>{const[l,I]=Ee(o),a=l?.getLocalTableId(e),p=i(e,c,l);return ze(s(p,(e=>Me(t,{...je(d,e),key:e,tableId:a,rowId:e,store:I,debugIds:n}))),r,n,c)},Fe=e=>({checkpoints:o,checkpointComponent:t=We,getCheckpointComponentProps:d,separator:r,debugIds:n})=>{const i=v(o);return ze(s(e(Re(i)),(e=>Me(t,{...je(d,e),key:e,checkpoints:i,checkpointId:e,debugIds:n}))),r)},je=(e,o)=>r(e)?{}:e(o),qe=({store:e,storesById:t,metrics:d,metricsById:s,indexes:r,indexesById:n,relationships:i,relationshipsById:c,checkpoints:l,checkpointsById:a,children:p})=>{const u=o(I);return Me(I.Provider,{value:Ae((()=>[e??u[0],{...u[1],...t},d??u[2],{...u[3],...s},r??u[4],{...u[5],...n},i??u[6],{...u[7],...c},l??u[8],{...u[9],...a}]),[e,t,d,s,r,n,i,c,l,a,u])},p)},ze=(e,o,t,d)=>{const n=r(o)||!Array.isArray(e)?e:s(e,((e,t)=>t>0?[o,e]:e));return t?[d,":{",n,"}"]:n},De=({tableId:e,rowId:o,cellId:t,store:d,debugIds:s})=>ze(""+(G(e,o,t,d)??""),void 0,s,t),Ge=({tableId:e,rowId:o,store:t,cellComponent:d=De,getCellComponentProps:r,separator:n,debugIds:i})=>ze(s(D(e,o,t),(s=>Me(d,{...je(r,s),key:s,tableId:e,rowId:o,cellId:s,store:t,debugIds:i}))),n,i,o),He=({tableId:e,store:o,rowComponent:t=Ge,getRowComponentProps:d,separator:r,debugIds:n})=>ze(s(q(e,o),(s=>Me(t,{...je(d,s),key:s,tableId:e,rowId:s,store:o,debugIds:n}))),r,n,e),Je=({store:e,tableComponent:o=He,getTableComponentProps:t,separator:d,debugIds:r})=>ze(s(F(e),(d=>Me(o,{...je(t,d),key:d,tableId:d,store:e,debugIds:r}))),d),Ke=({metricId:e,metrics:o,debugIds:t})=>ze(re(e,o)??"",void 0,t,e),Ne=({indexId:e,sliceId:o,indexes:t,rowComponent:d=Ge,getRowComponentProps:r,separator:n,debugIds:i})=>{const c=R(t),l=c?.getStore(),I=c?.getTableId(e),a=le(e,o,c);return ze(s(a,(e=>Me(d,{...je(r,e),key:e,tableId:I,rowId:e,store:l,debugIds:i}))),n,i,o)},Oe=({indexId:e,indexes:o,sliceComponent:t=Ne,getSliceComponentProps:d,separator:r,debugIds:n})=>ze(s(ce(e,o),(s=>Me(t,{...je(d,s),key:s,indexId:e,sliceId:s,indexes:o,debugIds:n}))),r,n,e),Qe=({relationshipId:e,localRowId:o,relationships:t,rowComponent:d=Ge,getRowComponentProps:s,debugIds:n})=>{const[i,c]=Ee(t),l=i?.getRemoteTableId(e),I=ue(e,o,i);return ze(r(l)||r(I)?null:Me(d,{...je(s,I),key:I,tableId:l,rowId:I,store:c,debugIds:n}),void 0,n,o)},Ue=e=>$e(e,be,e.remoteRowId),Ve=e=>$e(e,ge,e.firstRowId),We=({checkpoints:e,checkpointId:o,debugIds:t})=>ze(he(o,e)??"",void 0,t,o),Xe=Fe((e=>e[0])),Ye=Fe((e=>r(e[1])?[]:[e[1]])),Ze=Fe((e=>e[2]));export{Xe as BackwardCheckpointsView,De as CellView,We as CheckpointView,Ye as CurrentCheckpointView,Ze as ForwardCheckpointsView,Oe as IndexView,Ve as LinkedRowsView,Ue as LocalRowsView,Ke as MetricView,qe as Provider,Qe as RemoteRowView,Ge as RowView,Ne as SliceView,He as TableView,Je as TablesView,N as useAddRowCallback,G as useCell,D as useCellIds,te as useCellIdsListener,de as useCellListener,he as useCheckpoint,Re as useCheckpointIds,Se as useCheckpointIdsListener,Be as useCheckpointListener,C as useCheckpoints,ke as useCreateCheckpoints,ie as useCreateIndexes,se as useCreateMetrics,fe as useCreatePersister,pe as useCreateRelationships,E as useCreateStore,X as useDelCellCallback,W as useDelRowCallback,V as useDelTableCallback,U as useDelTablesCallback,ye as useGoBackwardCallback,Te as useGoForwardCallback,xe as useGoToCallback,g as useIndexes,ge as useLinkedRowIds,me as useLinkedRowIdsListener,be as useLocalRowIds,Ce as useLocalRowIdsListener,re as useMetric,ne as useMetricListener,b as useMetrics,Le as useRedoInformation,w as useRelationships,ue as useRemoteRowId,we as useRemoteRowIdListener,z as useRow,q as useRowIds,ee as useRowIdsListener,oe as useRowListener,Q as useSetCellCallback,ve as useSetCheckpointCallback,O as useSetPartialRowCallback,K as useSetRowCallback,J as useSetTableCallback,H as useSetTablesCallback,ce as useSliceIds,Ie as useSliceIdsListener,le as useSliceRowIds,ae as useSliceRowIdsListener,u as useStore,j as useTable,F as useTableIds,Z as useTableIdsListener,_ as useTableListener,$ as useTables,Y as useTablesListener,Pe as useUndoInformation};
|
package/lib/ui-react.js.gz
CHANGED
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,o;e=this,o=function(e){"use strict";e.defaultSorter=(e,o)=>e<o?-1:1,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseCommon={});
|
|
Binary file
|
package/lib/umd/indexes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n=t(""),s=(e,t)=>e.every(((n,s)=>0==s||t(e[s-1],n)<=0)),o=(e,t)=>e.sort(t),d=(e,t)=>e.forEach(t),
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,n=t(""),s=(e,t)=>e.every(((n,s)=>0==s||t(e[s-1],n)<=0)),o=(e,t)=>e.sort(t),d=(e,t)=>e.forEach(t),i=e=>e.length,r=e=>0==i(e),l=e=>e.slice(1),c=e=>null==e,a=(e,t,n)=>c(e)?n?.():t(e),f=(e,t)=>e?.has(t)??!1,u=e=>c(e)||0==(e=>e.size)(e),p=e=>e.clear(),g=(e,t)=>e?.forEach(t),I=(e,t)=>e?.delete(t),h=e=>new Map(e),y=e=>[...e?.keys()??[]],b=(e,t)=>e?.get(t),w=(e,t)=>g(e,((e,n)=>t(n,e))),x=(e,t,n)=>c(n)?(I(e,t),e):e?.set(t,n),v=(e,t,n,s)=>(f(e,t)||(s?.(n),e.set(t,n)),b(e,t)),L=e=>new Set(e),S=(e,t)=>e?.add(t),T=(e,s)=>t(e)==n?t=>t(e):e??(()=>s??""),R=(e,t)=>e<t?-1:1,j=(e,t,n)=>i(n)<2?S(r(n)?e:v(e,n[0],L()),t):j(v(e,n[0],h()),t,l(n)),M=e=>{const t=(n,s,...o)=>a(n,(n=>r(o)?e(n,s):d([o[0],null],(e=>t(b(n,e),s,...l(o))))));return t},k=Object.freeze,m=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((e=>{const t=h(),n=h(),[r,l,v,m,z,D,E,O]=((e,t,n)=>{const s=e.hasRow,o=h(),i=h(),r=h(),l=h(),u=h(),I=t=>a(b(u,t),(n=>{g(n,e.delListener),x(u,t)})),v=e=>{x(o,e),x(i,e),x(r,e),x(l,e),I(e)};return[()=>e,()=>y(o),e=>b(o,e),e=>b(i,e),(e,t)=>x(i,e,t),(a,y,v,S,T)=>{const R=h(),j=h();x(o,a,y),f(i,a)||(x(i,a,t()),x(r,a,h()),x(l,a,h()));const M=b(r,a),k=b(l,a),m=t=>{const o=n=>e.getCell(y,t,n),d=b(M,t),i=s(y,t)?n(S(o,t)):void 0;if(d!=i&&x(R,t,[d,i]),!c(T)){const e=b(k,t),n=s(y,t)?T(o,t):void 0;e!=n&&x(j,t,n)}},z=e=>{v((()=>{g(R,(([,e],t)=>x(M,t,e))),g(j,((e,t)=>x(k,t,e)))}),R,j,M,k,e),p(R),p(j)};w(M,m),e.hasTable(y)&&d(e.getRowIds(y),(e=>{f(M,e)||m(e)})),z(!0),I(a),x(u,a,L([e.addRowListener(y,null,((e,t,n)=>m(n))),e.addTableListener(y,(()=>z()))]))},v,()=>w(u,v)]})(e,h,(e=>c(e)?"":e+"")),[_,B,C]=(e=>{let t,n=0;const s=[],o=h();return[(d,i,r=[])=>{t??=e();const l=s.pop()??""+n++;return x(o,l,[d,i,r]),j(i,l,r),l},(e,n=[],...s)=>M(g)(e,(e=>a(b(o,e),(([e])=>e(t,...n,...s)))),...n),e=>a(b(o,e),(([,t,n])=>(M(I)(t,e,...n),x(o,e),i(s)<1e3&&s.push(e),n)),(()=>[])),(e,n,s)=>a(b(o,e),(([e,,o])=>{const r=(...l)=>{const a=i(l);a==i(o)?e(t,...l,...s(l)):c(o[a])?d(n[a](...l),(e=>r(...l,e))):r(...l,o[a])};r()}))]})((()=>P)),P={setIndexDefinition:(e,d,i,r,l,p=R)=>{const y=c(l)?void 0:([e],[t])=>l(e,t);return D(e,d,((d,i,l,v,T,R)=>{let j=0;const M=L(),k=L(),D=m(e);if(g(i,(([e,t],n)=>{c(e)||(S(M,e),a(b(D,e),(t=>{I(t,n),u(t)&&(x(D,e),j=1)}))),c(t)||(S(M,t),f(D,t)||(x(D,t,L()),j=1),S(b(D,t),n),c(r)||S(k,t))})),d(),u(T)||(R?w(D,(e=>S(k,e))):w(l,(e=>a(b(v,e),(e=>S(k,e))))),g(k,(e=>{const t=(t,n)=>p(b(T,t),b(T,n),e),n=[...b(D,e)];s(n,t)||(x(D,e,L(o(n,t))),S(M,e))}))),(j||R)&&!c(y)){const t=[...D];s(t,y)||(z(e,h(o(t,y))),j=1)}j&&B(t,[e]),g(M,(t=>B(n,[e,t])))}),T(i),a(r,T)),P},delIndexDefinition:e=>(E(e),P),getStore:r,getIndexIds:l,getTableId:v,getSliceIds:e=>y(m(e)),getSliceRowIds:(e,t)=>[...b(m(e),t)?.values()??[]],addSliceIdsListener:(e,n)=>_(n,t,[e]),addSliceRowIdsListener:(e,t,s)=>_(s,n,[e,t]),delListener:e=>(C(e),P),destroy:O,getListenerStats:()=>({})};return k(P)}));e.createIndexes=m,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseIndexes={});
|
package/lib/umd/indexes.js.gz
CHANGED
|
Binary file
|
package/lib/umd/tinybase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e,t){"use strict";const s=e=>typeof e,n="",o=s(n),r=s(!0),a=s(0),i=s(s),d="type",l="default",c="utf8",u=(e,t)=>e.includes(t),f=(e,t)=>e.every(((s,n)=>0==n||t(e[n-1],s)<=0)),g=(e,t)=>e.sort(t),h=(e,t)=>e.forEach(t),p=e=>w(e,((e,t)=>e+t),0),L=e=>e.length,v=e=>0==L(e),w=(e,t,s)=>e.reduce(t,s),y=e=>e.slice(1),I=e=>JSON.stringify(e,((e,t)=>m(t,Map)?w([...t],((e,[t,s])=>(e[t]=s,e)),{}):t)),S=JSON.parse,R=Math.max,T=Math.min,b=isFinite,m=(e,t)=>e instanceof t,C=e=>null==e,k=(e,t,s)=>C(e)?s?.():t(e),M=e=>e==o||e==r,x=e=>s(e)==i,A=()=>{},E=e=>e.size,P=(e,t)=>e?.has(t)??!1,D=e=>C(e)||0==E(e),J=e=>[...e?.values()??[]],F=e=>e.clear(),O=(e,t)=>e?.forEach(t),j=(e,t)=>e?.delete(t),z=e=>new Map(e),N=(e=z)=>[e(),e()],B=e=>[...e?.keys()??[]],_=(e,t)=>e?.get(t),q=(e,t)=>O(e,((e,s)=>t(s,e))),H=(e,t,s)=>C(s)?(j(e,t),e):e?.set(t,s),W=(e,t,s,n)=>(P(e,t)||(n?.(s),e.set(t,s)),_(e,t)),G=(e,t)=>{const s={},n=t??(e=>e);return O(e,((e,t)=>s[t]=n(e))),s},K=(e,t)=>{const s=z(),n=t??(e=>e);return O(e,((e,t)=>s.set(t,n(e)))),s},Q=e=>new Set(e),U=(e,t)=>e?.add(t),V=(e,t,s)=>{const n=e.hasRow,o=z(),r=z(),a=z(),i=z(),d=z(),l=t=>k(_(d,t),(s=>{O(s,e.delListener),H(d,t)})),c=e=>{H(o,e),H(r,e),H(a,e),H(i,e),l(e)};return[()=>e,()=>B(o),e=>_(o,e),e=>_(r,e),(e,t)=>H(r,e,t),(c,u,f,g,p)=>{const L=z(),v=z();H(o,c,u),P(r,c)||(H(r,c,t()),H(a,c,z()),H(i,c,z()));const w=_(a,c),y=_(i,c),I=t=>{const o=s=>e.getCell(u,t,s),r=_(w,t),a=n(u,t)?s(g(o,t)):void 0;if(r!=a&&H(L,t,[r,a]),!C(p)){const e=_(y,t),s=n(u,t)?p(o,t):void 0;e!=s&&H(v,t,s)}},S=e=>{f((()=>{O(L,(([,e],t)=>H(w,t,e))),O(v,((e,t)=>H(y,t,e)))}),L,v,w,y,e),F(L),F(v)};q(w,I),e.hasTable(u)&&h(e.getRowIds(u),(e=>{P(w,e)||I(e)})),S(!0),l(c),H(d,c,Q([e.addRowListener(u,null,((e,t,s)=>I(s))),e.addTableListener(u,(()=>S()))]))},c,()=>q(d,c)]},X=(e,t)=>s(e)==o?t=>t(e):e??(()=>t??n),Y=e=>{const t=new WeakMap;return s=>(t.has(s)||t.set(s,e(s)),t.get(s))},Z=(e,t,s)=>L(s)<2?U(v(s)?e:W(e,s[0],Q()),t):Z(W(e,s[0],z()),t,y(s)),$=e=>{const t=(s,n,...o)=>k(s,(s=>v(o)?e(s,n):h([o[0],null],(e=>t(_(s,e),n,...y(o))))));return t},ee=e=>{let t,s=0;const n=[],o=z();return[(r,a,i=[])=>{t??=e();const d=n.pop()??""+s++;return H(o,d,[r,a,i]),Z(a,d,i),d},(e,s=[],...n)=>$(O)(e,(e=>k(_(o,e),(([e])=>e(t,...s,...n)))),...s),e=>k(_(o,e),(([,t,s])=>($(j)(t,e,...s),H(o,e),L(n)<1e3&&n.push(e),s)),(()=>[])),(e,s,n)=>k(_(o,e),(([e,,o])=>{const r=(...a)=>{const i=L(a);i==L(o)?e(t,...a,...n(a)):C(o[i])?h(s[i](...a),(e=>r(...a,e))):r(...a,o[i])};r()}))]},te=Object,se=te.keys,ne=te.isFrozen,oe=te.freeze,re=(e,t)=>!C(((e,t)=>k(e,(e=>e[t])))(e,t)),ae=(e,t)=>delete e[t],ie=(e,t)=>h(te.entries(e),(([e,s])=>t(s,e))),de=Y((e=>{let t,s,n,o=100,r=z(),a=1;const i=Q(),d=z(),[l,c,f]=ee((()=>F)),g=z(),p=z(),w=[],y=[],I=(t,s)=>{a=0,e.transaction((()=>O(_(g,s),((s,n)=>O(s,((s,o)=>O(s,((s,r)=>C(s[t])?e.delCell(n,o,r,!0):e.setCell(n,o,r,s[t]))))))))),a=1},S=e=>{H(g,e),H(p,e),c(d,[e])},R=(e,t)=>h(((e,t)=>e.splice(0,t))(e,t??L(e)),S),T=()=>R(w,L(w)-o),b=e.addCellListener(null,null,null,((e,s,o,i,d,l)=>{if(a){k(t,(()=>{w.push(t),T(),R(y),t=void 0,n=1}));const e=W(r,s,z()),a=W(e,o,z()),c=W(a,i,[void 0,void 0],(e=>e[0]=l));c[1]=d,c[0]===c[1]&&D(H(a,i))&&D(H(e,o))&&D(H(r,s))&&(t=w.pop(),n=1),A()}})),m=(e="")=>(C(t)&&(t=""+s++,H(g,t,r),J(t,e),r=z(),n=1),t),M=()=>{v(w)||(y.unshift(m()),I(0,t),t=w.pop(),n=1)},x=()=>{v(y)||(w.push(t),t=y.shift(),I(1,t),n=1)},A=()=>{n&&(c(i),n=0)},E=e=>{const t=m(e);return A(),t},J=(e,t)=>(P(g,e)&&_(p,e)!==t&&(H(p,e,t),c(d,[e])),F),F={setSize:e=>(o=e,T(),F),addCheckpoint:E,setCheckpoint:J,getStore:()=>e,getCheckpointIds:()=>[[...w],t,[...y]],getCheckpoint:e=>_(p,e),goBackward:()=>(M(),A(),F),goForward:()=>(x(),A(),F),goTo:e=>{const s=u(w,e)?M:u(y,e)?x:null;for(;!C(s)&&e!=t;)s();return A(),F},addCheckpointIdsListener:e=>l(e,i),addCheckpointListener:(e,t)=>l(t,d,[e]),delListener:e=>(f(e),F),clear:()=>(R(w),R(y),C(t)||S(t),t=void 0,s=0,E(),F),destroy:()=>{e.delListener(b)},getListenerStats:()=>({})};return oe(F.clear())})),le=Y((e=>{const t=z(),s=z(),[o,r,a,i,d,l,c,u]=V(e,z,(e=>C(e)?n:e+n)),[h,p,L]=ee((()=>v)),v={setIndexDefinition:(e,n,o,r,a,c=ce)=>{const u=C(a)?void 0:([e],[t])=>a(e,t);return l(e,n,((n,o,a,l,h)=>{let L=0;const v=Q(),w=Q(),y=i(e);if(O(o,(([e,t],s)=>{C(e)||(U(v,e),k(_(y,e),(t=>{j(t,s),D(t)&&(H(y,e),L=1)}))),C(t)||(U(v,t),P(y,t)||(H(y,t,Q()),L=1),U(_(y,t),s),C(r)||U(w,t))})),n(),q(a,(e=>k(_(l,e),(e=>U(w,e))))),D(h)||O(w,(e=>{const t=(t,s)=>c(_(h,t),_(h,s),e),s=[..._(y,e)];f(s,t)||(H(y,e,Q(g(s,t))),U(v,e))})),L){if(!C(u)){const t=[...y];f(t,u)||d(e,z(g(t,u)))}p(t,[e])}O(v,(t=>p(s,[e,t])))}),X(o),k(r,X)),v},delIndexDefinition:e=>(c(e),v),getStore:o,getIndexIds:r,getTableId:a,getSliceIds:e=>B(i(e)),getSliceRowIds:(e,t)=>J(_(i(e),t)),addSliceIdsListener:(e,s)=>h(s,t,[e]),addSliceRowIdsListener:(e,t,n)=>h(n,s,[e,t]),delListener:e=>(L(e),v),destroy:u,getListenerStats:()=>({})};return oe(v)})),ce=(e,t)=>e<t?-1:1,ue=z([["avg",[(e,t)=>p(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>R(...e),(e,t)=>R(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:R(t,e)]],["min",[e=>T(...e),(e,t)=>T(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:T(t,e)]],["sum",[e=>p(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),fe=Y((e=>{const t=z(),[s,o,r,a,i,d,l,c]=V(e,A,(e=>isNaN(e)||C(e)||!0===e||!1===e||e===n?void 0:1*e)),[u,f,g]=ee((()=>h)),h={setMetricDefinition:(e,s,n,o,r,l,c)=>{const u=x(n)?[n,r,l,c]:_(ue,n)??_(ue,"sum");return d(e,s,((s,n,o,r,d,l)=>{let c=a(e),g=E(r);const[h,p,L,v]=u;l=l||C(c),O(n,(([e,t])=>{l||(c=C(e)?p?.(c,t,g++):C(t)?L?.(c,e,g--):v?.(c,t,e,g)),l=l||C(c)})),s(),D(r)?c=void 0:l&&(c=h(J(r),E(r))),b(c)||(c=void 0);const w=a(e);c!=w&&(i(e,c),f(t,[e],c,w))}),X(o,1)),h},delMetricDefinition:e=>(l(e),h),getStore:s,getMetricIds:o,getTableId:r,getMetric:a,addMetricListener:(e,s)=>u(s,t,[e]),delListener:e=>(g(e),h),destroy:c,getListenerStats:()=>({})};return oe(h)})),ge=(e,t,s,n,o)=>{let r,a=0;const i={load:async s=>{if(2!=a){a=1;const n=await t();C(n)||""==n?e.setTables(s):e.setJson(n),a=0}return i},startAutoLoad:async e=>(i.stopAutoLoad(),await i.load(e),n(i.load),i),stopAutoLoad:()=>(o(),i),save:async()=>(1!=a&&(a=2,await s(e.getJson()),a=0),i),startAutoSave:async()=>(await i.stopAutoSave().save(),r=e.addTablesListener((()=>i.save())),i),stopAutoSave:()=>(k(r,e.delListener),i),getStore:()=>e,destroy:()=>i.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return oe(i)},he="storage",pe=globalThis.window,Le=(e,t,s)=>{let n;return ge(e,(async()=>s.getItem(t)),(async e=>s.setItem(t,e)),(e=>{n=n=>{n.storageArea===s&&n.key===t&&e()},pe.addEventListener(he,n)}),(()=>{pe.removeEventListener(he,n),n=void 0}))},ve=e=>e.headers.get("ETag"),we=Y((e=>{const t=z(),s=z(),o=z(),r=z(),[a,i,d,l,c,u,f,g]=V(e,(()=>[z(),z(),z(),z()]),(e=>C(e)?void 0:e+n)),[h,p,L]=ee((()=>I)),v=(e,t,s)=>k(l(e),(([n,,o])=>{if(!P(o,t)){const r=Q();if(d(e)!=y(e))U(r,t);else{let e=t;for(;!C(e)&&!P(r,e);)U(r,e),e=_(n,e)}if(s)return r;H(o,t,r)}return _(o,t)})),w=(e,t)=>k(l(e),(([,,e])=>H(e,t))),y=e=>_(t,e),I={setRelationshipDefinition:(e,n,a,i)=>(H(t,e,a),u(e,n,((t,n)=>{const a=Q(),i=Q(),d=Q(),[c,u]=l(e);O(n,(([t,s],n)=>{C(t)||(U(i,t),k(_(u,t),(e=>{j(e,n),D(e)&&H(u,t)}))),C(s)||(U(i,s),P(u,s)||H(u,s,Q()),U(_(u,s),n)),U(a,n),H(c,n,s),q(_(r,e),(t=>{P(v(e,t),n)&&U(d,t)}))})),t(),O(a,(t=>p(s,[e,t]))),O(i,(t=>p(o,[e,t]))),O(d,(t=>{w(e,t),p(r,[e,t])}))}),X(i)),I),delRelationshipDefinition:e=>(H(t,e),f(e),I),getStore:a,getRelationshipIds:i,getLocalTableId:d,getRemoteTableId:y,getRemoteRowId:(e,t)=>_(l(e)?.[0],t),getLocalRowIds:(e,t)=>J(_(l(e)?.[1],t)),getLinkedRowIds:(e,t)=>C(l(e))?[t]:J(v(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>h(n,s,[e,t]),addLocalRowIdsListener:(e,t,s)=>h(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(v(e,t),h(s,r,[e,t])),delListener:e=>(w(...L(e)),I),destroy:g,getListenerStats:()=>({})};return oe(I)})),ye=(e,t,s,n=H)=>{const o=(r=B(e),a=e=>!re(t,e),r.filter(a));var r,a;return h(se(t),(n=>s(e,n,t[n]))),h(o,(t=>n(e,t))),e},Ie=e=>{const t=s(e);return M(t)||t==a&&b(e)?t:void 0},Se=(e,t)=>!(C(e)||!(e=>m(e,te)&&e.constructor==te)(e)||ne(e)||(ie(e,((s,n)=>{t(s,n)||ae(e,n)})),(e=>v(se(e)))(e))),Re=(e,t,s)=>H(e,t,_(e,t)==-s?void 0:s);e.createCheckpoints=de,e.createCustomPersister=ge,e.createFilePersister=(e,s)=>{let n;return ge(e,(async()=>{try{return await t.promises.readFile(s,c)}catch{}}),(async e=>{try{await t.promises.writeFile(s,e,c)}catch{}}),(e=>{n=t.watch(s,e)}),(()=>{n?.close(),n=void 0}))},e.createIndexes=le,e.createLocalPersister=(e,t)=>Le(e,t,localStorage),e.createMetrics=fe,e.createRelationships=we,e.createRemotePersister=(e,t,s,n)=>{let o,r;return ge(e,(async()=>{const e=await fetch(t);return r=ve(e),e.text()}),(async e=>await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:e})),(e=>{o=setInterval((async()=>{const s=await fetch(t,{method:"HEAD"}),n=ve(s);C(r)||C(n)||n==r||(r=n,e())}),1e3*n)}),(()=>{k(o,clearInterval),o=void 0}))},e.createSessionPersister=(e,t)=>Le(e,t,sessionStorage),e.createStore=()=>{let e,t=0,s=0;const n=z(),o=z(),r=z(),i=z(),c=z(),f=z(),g=z(),p=N(Q),L=N(Q),v=N(),w=N(),y=N(),R=N(),T=N(),[b,m,A,E]=ee((()=>Ee)),J=(t,s)=>(!e||P(c,s))&&Se(t,(e=>j(s,e))),j=(e,t,s)=>Se(s?t:V(t,e),((s,n)=>k(U(e,n,s),(e=>(t[n]=e,!0)),(()=>!1)))),U=(t,s,n)=>e?k(_(_(c,t),s),(e=>Ie(n)!=e.type?e.default:n)):C(Ie(n))?void 0:n,V=(e,t)=>(k(_(f,t),(t=>ie(t,((t,s)=>{re(e,s)||(e[s]=t)})))),e),X=e=>ye(c,e,((e,t,s)=>{const n={};ye(W(c,t,z()),s,((e,t,s)=>{H(e,t,s),k(s.default,(e=>n[t]=e))})),H(f,t,n)}),((e,t)=>{H(c,t),H(f,t)})),Y=e=>ye(g,e,((e,t,s)=>Z(t,s)),((e,t)=>ce(t))),Z=(e,t)=>ye(W(g,e,z(),(()=>ge(e,1))),t,((t,s,n)=>$(e,t,s,n)),((t,s)=>ue(e,t,s))),$=(e,t,s,n,o)=>ye(W(t,s,z(),(()=>he(e,s,1))),n,((t,n,o)=>te(e,s,t,n,o)),((n,r)=>fe(e,t,s,n,r,o))),te=(e,t,s,n,o)=>{P(s,n)||pe(e,t,n,1);const r=_(s,n);o!==r&&(Le(e,t,n,r),H(s,n,o))},se=(e,t,s)=>Ae((()=>$(e,le(e),t,s))),ne=(e,t,s,n,o)=>k(_(t,s),(t=>te(e,s,t,n,o)),(()=>$(e,t,s,V({[n]:o},e)))),de=e=>{const s=""+t++;return P(e,s)?de(e):s},le=e=>_(g,e)??Z(e,{}),ce=e=>Z(e,{}),ue=(e,t,s)=>$(e,t,s,{},!0),fe=(e,t,s,n,o,r)=>{const a=_(f,e)?.[o];if(!C(a)&&!r)return te(e,s,n,o,a);const i=t=>{Le(e,s,t,_(n,t)),pe(e,s,t,-1),H(n,t)};C(a)?i(o):q(n,i),D(n)&&(he(e,s,-1),D(H(t,s))&&(ge(e,-1),H(g,e)))},ge=(e,t)=>Re(n,e,t),he=(e,t,s)=>Re(W(o,e,z()),t,s),pe=(e,t,s,n)=>Re(W(W(r,e,z()),t,z()),s,n),Le=(e,t,s,n)=>W(W(W(i,e,z()),t,z()),s,n),ve=(e,t,s)=>{const n=_(_(i,e),t),o=ke(e,t,s);return P(n,s)?[!0,_(n,s),o]:[!1,o,o]},we=e=>{const t=D(R[e])&&D(w[e])&&D(L[e]),s=D(T[e])&&D(y[e])&&D(v[e])&&D(p[e]);if(t&&s)return;const a=e?[K(n),K(o,K),K(r,(e=>K(e,K))),K(i,(e=>K(e,K)))]:[n,o,r,i];if(t||(O(a[2],((t,s)=>O(t,((t,n)=>{D(t)||m(R[e],[s,n])})))),O(a[1],((t,s)=>{D(t)||m(w[e],[s])})),D(a[0])||m(L[e])),!s){let t;O(a[3],((s,n)=>{let o;O(s,((s,r)=>{let a;O(s,((s,i)=>{const d=ke(n,r,i);d!==s&&(m(T[e],[n,r,i],d,s,ve),t=o=a=1)})),a&&m(y[e],[n,r],ve)})),o&&m(v[e],[n],ve)})),t&&m(p[e],[],ve)}},Te=()=>G(g,(e=>G(e,G))),be=()=>B(g),me=e=>B(_(g,e)),Ce=(e,t)=>B(_(_(g,e),t)),ke=(e,t,s)=>_(_(_(g,e),t),s),Me=e=>((e=>Se(e,J))(e)&&Ae((()=>Y(e))),Ee),xe=()=>(Ae((()=>Y({}))),Ee),Ae=e=>{if(-1==s)return;s++;const t=e();return s--,0==s&&(s=1,we(1),s=-1,we(0),s=0,h([i,n,o,r],F)),t},Ee={getTables:Te,getTableIds:be,getTable:e=>G(_(g,e),G),getRowIds:me,getRow:(e,t)=>G(_(_(g,e),t)),getCellIds:Ce,getCell:ke,hasTable:e=>P(g,e),hasRow:(e,t)=>P(_(g,e),t),hasCell:(e,t,s)=>P(_(_(g,e),t),s),getJson:()=>I(g),getSchemaJson:()=>I(c),setTables:Me,setTable:(e,t)=>(J(t,e)&&Ae((()=>Z(e,t))),Ee),setRow:(e,t,s)=>(j(e,s)&&se(e,t,s),Ee),addRow:(e,t)=>{let s;return j(e,t)&&(s=de(_(g,e)),se(e,s,t)),s},setPartialRow:(e,t,s)=>(j(e,s,1)&&Ae((()=>{const n=le(e);ie(s,((s,o)=>ne(e,n,t,o,s)))})),Ee),setCell:(e,t,s,n)=>(k(U(e,s,x(n)?n(ke(e,t,s)):n),(n=>Ae((()=>ne(e,le(e),t,s,n))))),Ee),setJson:e=>{try{"{}"===e?xe():Me(S(e))}catch{}return Ee},setSchema:t=>{if((e=(e=>Se(e,(e=>Se(e,(e=>{if(!Se(e,((e,t)=>u([d,l],t))))return!1;const t=e.type;return!(!M(t)&&t!=a||(Ie(e.default)!=t&&ae(e,l),0))})))))(t))&&(X(t),!D(g))){const e=Te();xe(),Me(e)}return Ee},delTables:xe,delTable:e=>(P(g,e)&&Ae((()=>ce(e))),Ee),delRow:(e,t)=>(k(_(g,e),(s=>{P(s,t)&&Ae((()=>ue(e,s,t)))})),Ee),delCell:(e,t,s,n)=>(k(_(g,e),(o=>k(_(o,t),(r=>{P(r,s)&&Ae((()=>fe(e,o,t,r,s,n)))})))),Ee),delSchema:()=>(X({}),e=!1,Ee),transaction:Ae,forEachTable:e=>O(g,((t,s)=>e(s,(e=>O(t,((t,s)=>e(s,(e=>q(t,e))))))))),forEachRow:(e,t)=>O(_(g,e),((e,s)=>t(s,(t=>q(e,t))))),forEachCell:(e,t,s)=>q(_(_(g,e),t),s),addTablesListener:(e,t)=>b(e,p[t?1:0]),addTableIdsListener:(e,t)=>b(e,L[t?1:0]),addTableListener:(e,t,s)=>b(t,v[s?1:0],[e]),addRowIdsListener:(e,t,s)=>b(t,w[s?1:0],[e]),addRowListener:(e,t,s,n)=>b(s,y[n?1:0],[e,t]),addCellIdsListener:(e,t,s,n)=>b(s,R[n?1:0],[e,t]),addCellListener:(e,t,s,n,o)=>b(n,T[o?1:0],[e,t,s]),callListener:e=>(E(e,[be,me,Ce],(e=>C(e[2])?[]:[,,].fill(ke(...e)))),Ee),delListener:e=>(A(e),Ee),getListenerStats:()=>({})};return oe(Ee)},e.defaultSorter=ce,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fs")):"function"==typeof define&&define.amd?define(["exports","fs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBase={},e.fs);
|
|
1
|
+
var e,t;e=this,t=function(e,t){"use strict";const s=e=>typeof e,n="",o=s(n),r=s(!0),a=s(0),i=s(s),d="type",l="default",c="utf8",u=(e,t)=>e.includes(t),f=(e,t)=>e.every(((s,n)=>0==n||t(e[n-1],s)<=0)),g=(e,t)=>e.sort(t),h=(e,t)=>e.forEach(t),p=e=>w(e,((e,t)=>e+t),0),L=e=>e.length,v=e=>0==L(e),w=(e,t,s)=>e.reduce(t,s),y=e=>e.slice(1),I=e=>JSON.stringify(e,((e,t)=>m(t,Map)?w([...t],((e,[t,s])=>(e[t]=s,e)),{}):t)),S=JSON.parse,R=Math.max,T=Math.min,b=isFinite,m=(e,t)=>e instanceof t,C=e=>null==e,k=(e,t,s)=>C(e)?s?.():t(e),M=e=>e==o||e==r,x=e=>s(e)==i,A=()=>{},E=e=>e.size,P=(e,t)=>e?.has(t)??!1,D=e=>C(e)||0==E(e),J=e=>[...e?.values()??[]],F=e=>e.clear(),O=(e,t)=>e?.forEach(t),j=(e,t)=>e?.delete(t),z=e=>new Map(e),N=(e=z)=>[e(),e()],B=e=>[...e?.keys()??[]],_=(e,t)=>e?.get(t),q=(e,t)=>O(e,((e,s)=>t(s,e))),H=(e,t,s)=>C(s)?(j(e,t),e):e?.set(t,s),W=(e,t,s,n)=>(P(e,t)||(n?.(s),e.set(t,s)),_(e,t)),G=(e,t)=>{const s={},n=t??(e=>e);return O(e,((e,t)=>s[t]=n(e))),s},K=(e,t)=>{const s=z(),n=t??(e=>e);return O(e,((e,t)=>s.set(t,n(e)))),s},Q=e=>new Set(e),U=(e,t)=>e?.add(t),V=(e,t,s)=>{const n=e.hasRow,o=z(),r=z(),a=z(),i=z(),d=z(),l=t=>k(_(d,t),(s=>{O(s,e.delListener),H(d,t)})),c=e=>{H(o,e),H(r,e),H(a,e),H(i,e),l(e)};return[()=>e,()=>B(o),e=>_(o,e),e=>_(r,e),(e,t)=>H(r,e,t),(c,u,f,g,p)=>{const L=z(),v=z();H(o,c,u),P(r,c)||(H(r,c,t()),H(a,c,z()),H(i,c,z()));const w=_(a,c),y=_(i,c),I=t=>{const o=s=>e.getCell(u,t,s),r=_(w,t),a=n(u,t)?s(g(o,t)):void 0;if(r!=a&&H(L,t,[r,a]),!C(p)){const e=_(y,t),s=n(u,t)?p(o,t):void 0;e!=s&&H(v,t,s)}},S=e=>{f((()=>{O(L,(([,e],t)=>H(w,t,e))),O(v,((e,t)=>H(y,t,e)))}),L,v,w,y,e),F(L),F(v)};q(w,I),e.hasTable(u)&&h(e.getRowIds(u),(e=>{P(w,e)||I(e)})),S(!0),l(c),H(d,c,Q([e.addRowListener(u,null,((e,t,s)=>I(s))),e.addTableListener(u,(()=>S()))]))},c,()=>q(d,c)]},X=(e,t)=>s(e)==o?t=>t(e):e??(()=>t??n),Y=e=>{const t=new WeakMap;return s=>(t.has(s)||t.set(s,e(s)),t.get(s))},Z=(e,t,s)=>L(s)<2?U(v(s)?e:W(e,s[0],Q()),t):Z(W(e,s[0],z()),t,y(s)),$=e=>{const t=(s,n,...o)=>k(s,(s=>v(o)?e(s,n):h([o[0],null],(e=>t(_(s,e),n,...y(o))))));return t},ee=e=>{let t,s=0;const n=[],o=z();return[(r,a,i=[])=>{t??=e();const d=n.pop()??""+s++;return H(o,d,[r,a,i]),Z(a,d,i),d},(e,s=[],...n)=>$(O)(e,(e=>k(_(o,e),(([e])=>e(t,...s,...n)))),...s),e=>k(_(o,e),(([,t,s])=>($(j)(t,e,...s),H(o,e),L(n)<1e3&&n.push(e),s)),(()=>[])),(e,s,n)=>k(_(o,e),(([e,,o])=>{const r=(...a)=>{const i=L(a);i==L(o)?e(t,...a,...n(a)):C(o[i])?h(s[i](...a),(e=>r(...a,e))):r(...a,o[i])};r()}))]},te=Object,se=te.keys,ne=te.isFrozen,oe=te.freeze,re=(e,t)=>!C(((e,t)=>k(e,(e=>e[t])))(e,t)),ae=(e,t)=>delete e[t],ie=(e,t)=>h(te.entries(e),(([e,s])=>t(s,e))),de=Y((e=>{let t,s,n,o=100,r=z(),a=1;const i=Q(),d=z(),[l,c,f]=ee((()=>F)),g=z(),p=z(),w=[],y=[],I=(t,s)=>{a=0,e.transaction((()=>O(_(g,s),((s,n)=>O(s,((s,o)=>O(s,((s,r)=>C(s[t])?e.delCell(n,o,r,!0):e.setCell(n,o,r,s[t]))))))))),a=1},S=e=>{H(g,e),H(p,e),c(d,[e])},R=(e,t)=>h(((e,t)=>e.splice(0,t))(e,t??L(e)),S),T=()=>R(w,L(w)-o),b=e.addCellListener(null,null,null,((e,s,o,i,d,l)=>{if(a){k(t,(()=>{w.push(t),T(),R(y),t=void 0,n=1}));const e=W(r,s,z()),a=W(e,o,z()),c=W(a,i,[void 0,void 0],(e=>e[0]=l));c[1]=d,c[0]===c[1]&&D(H(a,i))&&D(H(e,o))&&D(H(r,s))&&(t=w.pop(),n=1),A()}})),m=(e="")=>(C(t)&&(t=""+s++,H(g,t,r),J(t,e),r=z(),n=1),t),M=()=>{v(w)||(y.unshift(m()),I(0,t),t=w.pop(),n=1)},x=()=>{v(y)||(w.push(t),t=y.shift(),I(1,t),n=1)},A=()=>{n&&(c(i),n=0)},E=e=>{const t=m(e);return A(),t},J=(e,t)=>(P(g,e)&&_(p,e)!==t&&(H(p,e,t),c(d,[e])),F),F={setSize:e=>(o=e,T(),F),addCheckpoint:E,setCheckpoint:J,getStore:()=>e,getCheckpointIds:()=>[[...w],t,[...y]],getCheckpoint:e=>_(p,e),goBackward:()=>(M(),A(),F),goForward:()=>(x(),A(),F),goTo:e=>{const s=u(w,e)?M:u(y,e)?x:null;for(;!C(s)&&e!=t;)s();return A(),F},addCheckpointIdsListener:e=>l(e,i),addCheckpointListener:(e,t)=>l(t,d,[e]),delListener:e=>(f(e),F),clear:()=>(R(w),R(y),C(t)||S(t),t=void 0,s=0,E(),F),destroy:()=>{e.delListener(b)},getListenerStats:()=>({})};return oe(F.clear())})),le=(e,t)=>e<t?-1:1,ce=Y((e=>{const t=z(),s=z(),[o,r,a,i,d,l,c,u]=V(e,z,(e=>C(e)?n:e+n)),[h,p,L]=ee((()=>v)),v={setIndexDefinition:(e,n,o,r,a,c=le)=>{const u=C(a)?void 0:([e],[t])=>a(e,t);return l(e,n,((n,o,a,l,h,L)=>{let v=0;const w=Q(),y=Q(),I=i(e);if(O(o,(([e,t],s)=>{C(e)||(U(w,e),k(_(I,e),(t=>{j(t,s),D(t)&&(H(I,e),v=1)}))),C(t)||(U(w,t),P(I,t)||(H(I,t,Q()),v=1),U(_(I,t),s),C(r)||U(y,t))})),n(),D(h)||(L?q(I,(e=>U(y,e))):q(a,(e=>k(_(l,e),(e=>U(y,e))))),O(y,(e=>{const t=(t,s)=>c(_(h,t),_(h,s),e),s=[..._(I,e)];f(s,t)||(H(I,e,Q(g(s,t))),U(w,e))}))),(v||L)&&!C(u)){const t=[...I];f(t,u)||(d(e,z(g(t,u))),v=1)}v&&p(t,[e]),O(w,(t=>p(s,[e,t])))}),X(o),k(r,X)),v},delIndexDefinition:e=>(c(e),v),getStore:o,getIndexIds:r,getTableId:a,getSliceIds:e=>B(i(e)),getSliceRowIds:(e,t)=>J(_(i(e),t)),addSliceIdsListener:(e,s)=>h(s,t,[e]),addSliceRowIdsListener:(e,t,n)=>h(n,s,[e,t]),delListener:e=>(L(e),v),destroy:u,getListenerStats:()=>({})};return oe(v)})),ue=z([["avg",[(e,t)=>p(e)/t,(e,t,s)=>e+(t-e)/(s+1),(e,t,s)=>e+(e-t)/(s-1),(e,t,s,n)=>e+(t-s)/n]],["max",[e=>R(...e),(e,t)=>R(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:R(t,e)]],["min",[e=>T(...e),(e,t)=>T(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:T(t,e)]],["sum",[e=>p(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),fe=Y((e=>{const t=z(),[s,o,r,a,i,d,l,c]=V(e,A,(e=>isNaN(e)||C(e)||!0===e||!1===e||e===n?void 0:1*e)),[u,f,g]=ee((()=>h)),h={setMetricDefinition:(e,s,n,o,r,l,c)=>{const u=x(n)?[n,r,l,c]:_(ue,n)??_(ue,"sum");return d(e,s,((s,n,o,r,d,l)=>{let c=a(e),g=E(r);const[h,p,L,v]=u;l=l||C(c),O(n,(([e,t])=>{l||(c=C(e)?p?.(c,t,g++):C(t)?L?.(c,e,g--):v?.(c,t,e,g)),l=l||C(c)})),s(),D(r)?c=void 0:l&&(c=h(J(r),E(r))),b(c)||(c=void 0);const w=a(e);c!=w&&(i(e,c),f(t,[e],c,w))}),X(o,1)),h},delMetricDefinition:e=>(l(e),h),getStore:s,getMetricIds:o,getTableId:r,getMetric:a,addMetricListener:(e,s)=>u(s,t,[e]),delListener:e=>(g(e),h),destroy:c,getListenerStats:()=>({})};return oe(h)})),ge=(e,t,s,n,o)=>{let r,a=0;const i={load:async s=>{if(2!=a){a=1;const n=await t();C(n)||""==n?e.setTables(s):e.setJson(n),a=0}return i},startAutoLoad:async e=>(i.stopAutoLoad(),await i.load(e),n(i.load),i),stopAutoLoad:()=>(o(),i),save:async()=>(1!=a&&(a=2,await s(e.getJson()),a=0),i),startAutoSave:async()=>(await i.stopAutoSave().save(),r=e.addTablesListener((()=>i.save())),i),stopAutoSave:()=>(k(r,e.delListener),i),getStore:()=>e,destroy:()=>i.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return oe(i)},he="storage",pe=globalThis.window,Le=(e,t,s)=>{let n;return ge(e,(async()=>s.getItem(t)),(async e=>s.setItem(t,e)),(e=>{n=n=>{n.storageArea===s&&n.key===t&&e()},pe.addEventListener(he,n)}),(()=>{pe.removeEventListener(he,n),n=void 0}))},ve=e=>e.headers.get("ETag"),we=Y((e=>{const t=z(),s=z(),o=z(),r=z(),[a,i,d,l,c,u,f,g]=V(e,(()=>[z(),z(),z(),z()]),(e=>C(e)?void 0:e+n)),[h,p,L]=ee((()=>I)),v=(e,t,s)=>k(l(e),(([n,,o])=>{if(!P(o,t)){const r=Q();if(d(e)!=y(e))U(r,t);else{let e=t;for(;!C(e)&&!P(r,e);)U(r,e),e=_(n,e)}if(s)return r;H(o,t,r)}return _(o,t)})),w=(e,t)=>k(l(e),(([,,e])=>H(e,t))),y=e=>_(t,e),I={setRelationshipDefinition:(e,n,a,i)=>(H(t,e,a),u(e,n,((t,n)=>{const a=Q(),i=Q(),d=Q(),[c,u]=l(e);O(n,(([t,s],n)=>{C(t)||(U(i,t),k(_(u,t),(e=>{j(e,n),D(e)&&H(u,t)}))),C(s)||(U(i,s),P(u,s)||H(u,s,Q()),U(_(u,s),n)),U(a,n),H(c,n,s),q(_(r,e),(t=>{P(v(e,t),n)&&U(d,t)}))})),t(),O(a,(t=>p(s,[e,t]))),O(i,(t=>p(o,[e,t]))),O(d,(t=>{w(e,t),p(r,[e,t])}))}),X(i)),I),delRelationshipDefinition:e=>(H(t,e),f(e),I),getStore:a,getRelationshipIds:i,getLocalTableId:d,getRemoteTableId:y,getRemoteRowId:(e,t)=>_(l(e)?.[0],t),getLocalRowIds:(e,t)=>J(_(l(e)?.[1],t)),getLinkedRowIds:(e,t)=>C(l(e))?[t]:J(v(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>h(n,s,[e,t]),addLocalRowIdsListener:(e,t,s)=>h(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(v(e,t),h(s,r,[e,t])),delListener:e=>(w(...L(e)),I),destroy:g,getListenerStats:()=>({})};return oe(I)})),ye=(e,t,s,n=H)=>{const o=(r=B(e),a=e=>!re(t,e),r.filter(a));var r,a;return h(se(t),(n=>s(e,n,t[n]))),h(o,(t=>n(e,t))),e},Ie=e=>{const t=s(e);return M(t)||t==a&&b(e)?t:void 0},Se=(e,t)=>!(C(e)||!(e=>m(e,te)&&e.constructor==te)(e)||ne(e)||(ie(e,((s,n)=>{t(s,n)||ae(e,n)})),(e=>v(se(e)))(e))),Re=(e,t,s)=>H(e,t,_(e,t)==-s?void 0:s);e.createCheckpoints=de,e.createCustomPersister=ge,e.createFilePersister=(e,s)=>{let n;return ge(e,(async()=>{try{return await t.promises.readFile(s,c)}catch{}}),(async e=>{try{await t.promises.writeFile(s,e,c)}catch{}}),(e=>{n=t.watch(s,e)}),(()=>{n?.close(),n=void 0}))},e.createIndexes=ce,e.createLocalPersister=(e,t)=>Le(e,t,localStorage),e.createMetrics=fe,e.createRelationships=we,e.createRemotePersister=(e,t,s,n)=>{let o,r;return ge(e,(async()=>{const e=await fetch(t);return r=ve(e),e.text()}),(async e=>await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:e})),(e=>{o=setInterval((async()=>{const s=await fetch(t,{method:"HEAD"}),n=ve(s);C(r)||C(n)||n==r||(r=n,e())}),1e3*n)}),(()=>{k(o,clearInterval),o=void 0}))},e.createSessionPersister=(e,t)=>Le(e,t,sessionStorage),e.createStore=()=>{let e,t=0,s=0;const n=z(),o=z(),r=z(),i=z(),c=z(),f=z(),g=z(),p=N(Q),L=N(Q),v=N(),w=N(),y=N(),R=N(),T=N(),[b,m,A,E]=ee((()=>Ee)),J=(t,s)=>(!e||P(c,s))&&Se(t,(e=>j(s,e))),j=(e,t,s)=>Se(s?t:V(t,e),((s,n)=>k(U(e,n,s),(e=>(t[n]=e,!0)),(()=>!1)))),U=(t,s,n)=>e?k(_(_(c,t),s),(e=>Ie(n)!=e.type?e.default:n)):C(Ie(n))?void 0:n,V=(e,t)=>(k(_(f,t),(t=>ie(t,((t,s)=>{re(e,s)||(e[s]=t)})))),e),X=e=>ye(c,e,((e,t,s)=>{const n={};ye(W(c,t,z()),s,((e,t,s)=>{H(e,t,s),k(s.default,(e=>n[t]=e))})),H(f,t,n)}),((e,t)=>{H(c,t),H(f,t)})),Y=e=>ye(g,e,((e,t,s)=>Z(t,s)),((e,t)=>ce(t))),Z=(e,t)=>ye(W(g,e,z(),(()=>ge(e,1))),t,((t,s,n)=>$(e,t,s,n)),((t,s)=>ue(e,t,s))),$=(e,t,s,n,o)=>ye(W(t,s,z(),(()=>he(e,s,1))),n,((t,n,o)=>te(e,s,t,n,o)),((n,r)=>fe(e,t,s,n,r,o))),te=(e,t,s,n,o)=>{P(s,n)||pe(e,t,n,1);const r=_(s,n);o!==r&&(Le(e,t,n,r),H(s,n,o))},se=(e,t,s)=>Ae((()=>$(e,le(e),t,s))),ne=(e,t,s,n,o)=>k(_(t,s),(t=>te(e,s,t,n,o)),(()=>$(e,t,s,V({[n]:o},e)))),de=e=>{const s=""+t++;return P(e,s)?de(e):s},le=e=>_(g,e)??Z(e,{}),ce=e=>Z(e,{}),ue=(e,t,s)=>$(e,t,s,{},!0),fe=(e,t,s,n,o,r)=>{const a=_(f,e)?.[o];if(!C(a)&&!r)return te(e,s,n,o,a);const i=t=>{Le(e,s,t,_(n,t)),pe(e,s,t,-1),H(n,t)};C(a)?i(o):q(n,i),D(n)&&(he(e,s,-1),D(H(t,s))&&(ge(e,-1),H(g,e)))},ge=(e,t)=>Re(n,e,t),he=(e,t,s)=>Re(W(o,e,z()),t,s),pe=(e,t,s,n)=>Re(W(W(r,e,z()),t,z()),s,n),Le=(e,t,s,n)=>W(W(W(i,e,z()),t,z()),s,n),ve=(e,t,s)=>{const n=_(_(i,e),t),o=ke(e,t,s);return P(n,s)?[!0,_(n,s),o]:[!1,o,o]},we=e=>{const t=D(R[e])&&D(w[e])&&D(L[e]),s=D(T[e])&&D(y[e])&&D(v[e])&&D(p[e]);if(t&&s)return;const a=e?[K(n),K(o,K),K(r,(e=>K(e,K))),K(i,(e=>K(e,K)))]:[n,o,r,i];if(t||(O(a[2],((t,s)=>O(t,((t,n)=>{D(t)||m(R[e],[s,n])})))),O(a[1],((t,s)=>{D(t)||m(w[e],[s])})),D(a[0])||m(L[e])),!s){let t;O(a[3],((s,n)=>{let o;O(s,((s,r)=>{let a;O(s,((s,i)=>{const d=ke(n,r,i);d!==s&&(m(T[e],[n,r,i],d,s,ve),t=o=a=1)})),a&&m(y[e],[n,r],ve)})),o&&m(v[e],[n],ve)})),t&&m(p[e],[],ve)}},Te=()=>G(g,(e=>G(e,G))),be=()=>B(g),me=e=>B(_(g,e)),Ce=(e,t)=>B(_(_(g,e),t)),ke=(e,t,s)=>_(_(_(g,e),t),s),Me=e=>((e=>Se(e,J))(e)&&Ae((()=>Y(e))),Ee),xe=()=>(Ae((()=>Y({}))),Ee),Ae=e=>{if(-1==s)return;s++;const t=e();return s--,0==s&&(s=1,we(1),s=-1,we(0),s=0,h([i,n,o,r],F)),t},Ee={getTables:Te,getTableIds:be,getTable:e=>G(_(g,e),G),getRowIds:me,getRow:(e,t)=>G(_(_(g,e),t)),getCellIds:Ce,getCell:ke,hasTable:e=>P(g,e),hasRow:(e,t)=>P(_(g,e),t),hasCell:(e,t,s)=>P(_(_(g,e),t),s),getJson:()=>I(g),getSchemaJson:()=>I(c),setTables:Me,setTable:(e,t)=>(J(t,e)&&Ae((()=>Z(e,t))),Ee),setRow:(e,t,s)=>(j(e,s)&&se(e,t,s),Ee),addRow:(e,t)=>{let s;return j(e,t)&&(s=de(_(g,e)),se(e,s,t)),s},setPartialRow:(e,t,s)=>(j(e,s,1)&&Ae((()=>{const n=le(e);ie(s,((s,o)=>ne(e,n,t,o,s)))})),Ee),setCell:(e,t,s,n)=>(k(U(e,s,x(n)?n(ke(e,t,s)):n),(n=>Ae((()=>ne(e,le(e),t,s,n))))),Ee),setJson:e=>{try{"{}"===e?xe():Me(S(e))}catch{}return Ee},setSchema:t=>{if((e=(e=>Se(e,(e=>Se(e,(e=>{if(!Se(e,((e,t)=>u([d,l],t))))return!1;const t=e.type;return!(!M(t)&&t!=a||(Ie(e.default)!=t&&ae(e,l),0))})))))(t))&&(X(t),!D(g))){const e=Te();xe(),Me(e)}return Ee},delTables:xe,delTable:e=>(P(g,e)&&Ae((()=>ce(e))),Ee),delRow:(e,t)=>(k(_(g,e),(s=>{P(s,t)&&Ae((()=>ue(e,s,t)))})),Ee),delCell:(e,t,s,n)=>(k(_(g,e),(o=>k(_(o,t),(r=>{P(r,s)&&Ae((()=>fe(e,o,t,r,s,n)))})))),Ee),delSchema:()=>(X({}),e=!1,Ee),transaction:Ae,forEachTable:e=>O(g,((t,s)=>e(s,(e=>O(t,((t,s)=>e(s,(e=>q(t,e))))))))),forEachRow:(e,t)=>O(_(g,e),((e,s)=>t(s,(t=>q(e,t))))),forEachCell:(e,t,s)=>q(_(_(g,e),t),s),addTablesListener:(e,t)=>b(e,p[t?1:0]),addTableIdsListener:(e,t)=>b(e,L[t?1:0]),addTableListener:(e,t,s)=>b(t,v[s?1:0],[e]),addRowIdsListener:(e,t,s)=>b(t,w[s?1:0],[e]),addRowListener:(e,t,s,n)=>b(s,y[n?1:0],[e,t]),addCellIdsListener:(e,t,s,n)=>b(s,R[n?1:0],[e,t]),addCellListener:(e,t,s,n,o)=>b(n,T[o?1:0],[e,t,s]),callListener:e=>(E(e,[be,me,Ce],(e=>C(e[2])?[]:[,,].fill(ke(...e)))),Ee),delListener:e=>(A(e),Ee),getListenerStats:()=>({})};return oe(Ee)},e.defaultSorter=le,Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fs")):"function"==typeof define&&define.amd?define(["exports","fs"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBase={},e.fs);
|
package/lib/umd/tinybase.js.gz
CHANGED
|
Binary file
|
package/lib/umd/ui-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,s;e=this,s=function(e,s){"use strict";const o=e=>typeof e,t=o(""),d=(e,s)=>e.map(s),r=e=>null==e,n=(e,s,o)=>r(e)?o?.():s(e),i=()=>{},{createContext:l,useContext:a}=s,c=l([]),u=(e,s)=>{const o=a(c);return r(e)?o[s]:((e,s)=>n(e,(e=>e[s])))(o[s+1],e)},I=(e,s)=>{const d=u(e,s);return r(e)||(e=>o(e)==t)(e)?d:e},p=e=>I(e,0),w=e=>I(e,2),b=e=>I(e,4),C=e=>I(e,6),k=e=>I(e,8),{useCallback:R,useEffect:g,useMemo:h,useState:m}=s,T=(e,s,o=[])=>h((()=>s(e)),[e,...o]),L=(e,s,o,...t)=>{const d=s?.["get"+e]??(()=>o),r=d(...t),[,n]=m(r);return g((()=>{const o=s?.[`add${e}Listener`]?.(...t,(()=>n(d(...t))),!1);return()=>s?.delListener(o)}),[s,e,n,d,...t]),r},y=(e,s,o,t=[],d,...r)=>{g((()=>{const t=s?.[`add${e}Listener`]?.(...r,o,d);return()=>s?.delListener(t)}),[s,e,...t,d,...r])},v=(e,s,o,t=[],d=i,r=[],...l)=>{const a=p(e);return R((e=>n(a,(t=>n(o(e,t),(e=>d(t["set"+s](...l,e),e)))))),[a,s,...t,...r,...l])},S=(e,s,o=i,t=[],...d)=>{const r=p(e);return R((()=>o(r?.["del"+s](...d))),[r,s,...t,...d])},f=(e,s,o)=>{const t=k(e);return R((()=>t?.[s](o)),[t,s,o])},x=e=>L("TableIds",p(e),[]),P=(e,s)=>L("RowIds",p(s),[],e),V=(e,s,o)=>L("CellIds",p(o),[],e,s),M=(e,s,o,t)=>L("Cell",p(t),void 0,e,s,o),B=(e,s)=>L("Metric",w(s),void 0,e),D=(e,s)=>L("SliceIds",b(s),[],e),A=(e,s,o)=>L("SliceRowIds",b(o),[],e,s),F=(e,s,o)=>L("RemoteRowId",C(o),void 0,e,s),G=(e,s,o)=>L("LocalRowIds",C(o),[],e,s),j=(e,s,o)=>L("LinkedRowIds",C(o),[],e,s),E=e=>L("CheckpointIds",k(e),[[],void 0,[]]),U=(e,s)=>L("Checkpoint",k(s),void 0,e),$=e=>f(e,"goBackward"),_=e=>f(e,"goForward"),{createElement:q,useMemo:O}=s,z=e=>{const s=C(e);return[s,s?.getStore()]},H=({relationshipId:e,relationships:s,rowComponent:o=W,getRowComponentProps:t,separator:r,debugIds:n},i,l)=>{const[a,c]=z(s),u=a?.getLocalTableId(e),I=i(e,l,a);return N(d(I,(e=>q(o,{...K(t,e),key:e,tableId:u,rowId:e,store:c,debugIds:n}))),r,n,l)},J=e=>({checkpoints:s,checkpointComponent:o=Z,getCheckpointComponentProps:t,separator:r,debugIds:n})=>{const i=k(s);return N(d(e(E(i)),(e=>q(o,{...K(t,e),key:e,checkpoints:i,checkpointId:e,debugIds:n}))),r)},K=(e,s)=>r(e)?{}:e(s),N=(e,s,o,t)=>{const n=r(s)||!Array.isArray(e)?e:d(e,((e,o)=>o>0?[s,e]:e));return o?[t,":{",n,"}"]:n},Q=({tableId:e,rowId:s,cellId:o,store:t,debugIds:d})=>N(""+(M(e,s,o,t)??""),void 0,d,o),W=({tableId:e,rowId:s,store:o,cellComponent:t=Q,getCellComponentProps:r,separator:n,debugIds:i})=>N(d(V(e,s,o),(d=>q(t,{...K(r,d),key:d,tableId:e,rowId:s,cellId:d,store:o,debugIds:i}))),n,i,s),X=({tableId:e,store:s,rowComponent:o=W,getRowComponentProps:t,separator:r,debugIds:n})=>N(d(P(e,s),(d=>q(o,{...K(t,d),key:d,tableId:e,rowId:d,store:s,debugIds:n}))),r,n,e),Y=({indexId:e,sliceId:s,indexes:o,rowComponent:t=W,getRowComponentProps:r,separator:n,debugIds:i})=>{const l=b(o),a=l?.getStore(),c=l?.getTableId(e),u=A(e,s,l);return N(d(u,(e=>q(t,{...K(r,e),key:e,tableId:c,rowId:e,store:a,debugIds:i}))),n,i,s)},Z=({checkpoints:e,checkpointId:s,debugIds:o})=>N(U(s,e)??"",void 0,o,s),ee=J((e=>e[0])),se=J((e=>r(e[1])?[]:[e[1]])),oe=J((e=>e[2]));e.BackwardCheckpointsView=ee,e.CellView=Q,e.CheckpointView=Z,e.CurrentCheckpointView=se,e.ForwardCheckpointsView=oe,e.IndexView=({indexId:e,indexes:s,sliceComponent:o=Y,getSliceComponentProps:t,separator:r,debugIds:n})=>N(d(D(e,s),(d=>q(o,{...K(t,d),key:d,indexId:e,sliceId:d,indexes:s,debugIds:n}))),r,n,e),e.LinkedRowsView=e=>H(e,j,e.firstRowId),e.LocalRowsView=e=>H(e,G,e.remoteRowId),e.MetricView=({metricId:e,metrics:s,debugIds:o})=>N(B(e,s)??"",void 0,o,e),e.Provider=({store:e,storesById:
|
|
1
|
+
var e,s;e=this,s=function(e,s){"use strict";const o=e=>typeof e,t=o(""),d=(e,s)=>e.map(s),r=e=>null==e,n=(e,s,o)=>r(e)?o?.():s(e),i=()=>{},{createContext:l,useContext:a}=s,c=l([]),u=(e,s)=>{const o=a(c);return r(e)?o[s]:((e,s)=>n(e,(e=>e[s])))(o[s+1],e)},I=(e,s)=>{const d=u(e,s);return r(e)||(e=>o(e)==t)(e)?d:e},p=e=>I(e,0),w=e=>I(e,2),b=e=>I(e,4),C=e=>I(e,6),k=e=>I(e,8),{useCallback:R,useEffect:g,useMemo:h,useState:m}=s,T=(e,s,o=[])=>{const t=h((()=>s(e)),[e,...o]);return g((()=>()=>t.destroy()),[t]),t},L=(e,s,o,...t)=>{const d=s?.["get"+e]??(()=>o),r=d(...t),[,n]=m(r);return g((()=>{const o=s?.[`add${e}Listener`]?.(...t,(()=>n(d(...t))),!1);return()=>s?.delListener(o)}),[s,e,n,d,...t]),r},y=(e,s,o,t=[],d,...r)=>{g((()=>{const t=s?.[`add${e}Listener`]?.(...r,o,d);return()=>s?.delListener(t)}),[s,e,...t,d,...r])},v=(e,s,o,t=[],d=i,r=[],...l)=>{const a=p(e);return R((e=>n(a,(t=>n(o(e,t),(e=>d(t["set"+s](...l,e),e)))))),[a,s,...t,...r,...l])},S=(e,s,o=i,t=[],...d)=>{const r=p(e);return R((()=>o(r?.["del"+s](...d))),[r,s,...t,...d])},f=(e,s,o)=>{const t=k(e);return R((()=>t?.[s](o)),[t,s,o])},x=e=>L("TableIds",p(e),[]),P=(e,s)=>L("RowIds",p(s),[],e),V=(e,s,o)=>L("CellIds",p(o),[],e,s),M=(e,s,o,t)=>L("Cell",p(t),void 0,e,s,o),B=(e,s)=>L("Metric",w(s),void 0,e),D=(e,s)=>L("SliceIds",b(s),[],e),A=(e,s,o)=>L("SliceRowIds",b(o),[],e,s),F=(e,s,o)=>L("RemoteRowId",C(o),void 0,e,s),G=(e,s,o)=>L("LocalRowIds",C(o),[],e,s),j=(e,s,o)=>L("LinkedRowIds",C(o),[],e,s),E=e=>L("CheckpointIds",k(e),[[],void 0,[]]),U=(e,s)=>L("Checkpoint",k(s),void 0,e),$=e=>f(e,"goBackward"),_=e=>f(e,"goForward"),{createElement:q,useMemo:O}=s,z=e=>{const s=C(e);return[s,s?.getStore()]},H=({relationshipId:e,relationships:s,rowComponent:o=W,getRowComponentProps:t,separator:r,debugIds:n},i,l)=>{const[a,c]=z(s),u=a?.getLocalTableId(e),I=i(e,l,a);return N(d(I,(e=>q(o,{...K(t,e),key:e,tableId:u,rowId:e,store:c,debugIds:n}))),r,n,l)},J=e=>({checkpoints:s,checkpointComponent:o=Z,getCheckpointComponentProps:t,separator:r,debugIds:n})=>{const i=k(s);return N(d(e(E(i)),(e=>q(o,{...K(t,e),key:e,checkpoints:i,checkpointId:e,debugIds:n}))),r)},K=(e,s)=>r(e)?{}:e(s),N=(e,s,o,t)=>{const n=r(s)||!Array.isArray(e)?e:d(e,((e,o)=>o>0?[s,e]:e));return o?[t,":{",n,"}"]:n},Q=({tableId:e,rowId:s,cellId:o,store:t,debugIds:d})=>N(""+(M(e,s,o,t)??""),void 0,d,o),W=({tableId:e,rowId:s,store:o,cellComponent:t=Q,getCellComponentProps:r,separator:n,debugIds:i})=>N(d(V(e,s,o),(d=>q(t,{...K(r,d),key:d,tableId:e,rowId:s,cellId:d,store:o,debugIds:i}))),n,i,s),X=({tableId:e,store:s,rowComponent:o=W,getRowComponentProps:t,separator:r,debugIds:n})=>N(d(P(e,s),(d=>q(o,{...K(t,d),key:d,tableId:e,rowId:d,store:s,debugIds:n}))),r,n,e),Y=({indexId:e,sliceId:s,indexes:o,rowComponent:t=W,getRowComponentProps:r,separator:n,debugIds:i})=>{const l=b(o),a=l?.getStore(),c=l?.getTableId(e),u=A(e,s,l);return N(d(u,(e=>q(t,{...K(r,e),key:e,tableId:c,rowId:e,store:a,debugIds:i}))),n,i,s)},Z=({checkpoints:e,checkpointId:s,debugIds:o})=>N(U(s,e)??"",void 0,o,s),ee=J((e=>e[0])),se=J((e=>r(e[1])?[]:[e[1]])),oe=J((e=>e[2]));e.BackwardCheckpointsView=ee,e.CellView=Q,e.CheckpointView=Z,e.CurrentCheckpointView=se,e.ForwardCheckpointsView=oe,e.IndexView=({indexId:e,indexes:s,sliceComponent:o=Y,getSliceComponentProps:t,separator:r,debugIds:n})=>N(d(D(e,s),(d=>q(o,{...K(t,d),key:d,indexId:e,sliceId:d,indexes:s,debugIds:n}))),r,n,e),e.LinkedRowsView=e=>H(e,j,e.firstRowId),e.LocalRowsView=e=>H(e,G,e.remoteRowId),e.MetricView=({metricId:e,metrics:s,debugIds:o})=>N(B(e,s)??"",void 0,o,e),e.Provider=({store:e,storesById:o,metrics:t,metricsById:d,indexes:r,indexesById:n,relationships:i,relationshipsById:l,checkpoints:a,checkpointsById:u,children:I})=>{const p=s.useContext(c);return q(c.Provider,{value:O((()=>[e??p[0],{...p[1],...o},t??p[2],{...p[3],...d},r??p[4],{...p[5],...n},i??p[6],{...p[7],...l},a??p[8],{...p[9],...u}]),[e,o,t,d,r,n,i,l,a,u,p])},I)},e.RemoteRowView=({relationshipId:e,localRowId:s,relationships:o,rowComponent:t=W,getRowComponentProps:d,debugIds:n})=>{const[i,l]=z(o),a=i?.getRemoteTableId(e),c=F(e,s,i);return N(r(a)||r(c)?null:q(t,{...K(d,c),key:c,tableId:a,rowId:c,store:l,debugIds:n}),void 0,n,s)},e.RowView=W,e.SliceView=Y,e.TableView=X,e.TablesView=({store:e,tableComponent:s=X,getTableComponentProps:o,separator:t,debugIds:r})=>N(d(x(e),(t=>q(s,{...K(o,t),key:t,tableId:t,store:e,debugIds:r}))),t),e.useAddRowCallback=(e,s,o=[],t,d=i,r=[])=>{const l=p(t);return R((o=>n(l,(t=>n(s(o,t),(s=>d(t.addRow(e,s),t,s)))))),[l,e,...o,...r])},e.useCell=M,e.useCellIds=V,e.useCellIdsListener=(e,s,o,t,d,r)=>y("CellIds",p(r),o,t,d,e,s),e.useCellListener=(e,s,o,t,d,r,n)=>y("Cell",p(n),t,d,r,e,s,o),e.useCheckpoint=U,e.useCheckpointIds=E,e.useCheckpointIdsListener=(e,s,o)=>y("CheckpointIds",k(o),e,s),e.useCheckpointListener=(e,s,o,t)=>y("Checkpoint",k(t),s,o,void 0,e),e.useCheckpoints=e=>u(e,8),e.useCreateCheckpoints=(e,s,o)=>T(e,s,o),e.useCreateIndexes=(e,s,o)=>T(e,s,o),e.useCreateMetrics=(e,s,o)=>T(e,s,o),e.useCreatePersister=(e,s,o=[],t,d=[])=>{const[,r]=m(),n=h((()=>s(e)),[e,...o]);return g((()=>((async()=>{await(t?.(n)),r(1)})(),()=>{n.destroy()})),[n,...d]),n},e.useCreateRelationships=(e,s,o)=>T(e,s,o),e.useCreateStore=(e,s=[])=>h(e,s),e.useDelCellCallback=(e,s,o,t,d,r,n)=>S(d,"Cell",r,n,e,s,o,t),e.useDelRowCallback=(e,s,o,t,d)=>S(o,"Row",t,d,e,s),e.useDelTableCallback=(e,s,o,t)=>S(s,"Table",o,t,e),e.useDelTablesCallback=(e,s,o)=>S(e,"Tables",s,o),e.useGoBackwardCallback=$,e.useGoForwardCallback=_,e.useGoToCallback=(e,s=[],o,t=i,d=[])=>{const r=k(o);return R((s=>n(r,(o=>n(e(s),(e=>t(o.goTo(e),e)))))),[r,...s,...d])},e.useIndexes=e=>u(e,4),e.useLinkedRowIds=j,e.useLinkedRowIdsListener=(e,s,o,t,d)=>y("LinkedRowIds",C(d),o,t,void 0,e,s),e.useLocalRowIds=G,e.useLocalRowIdsListener=(e,s,o,t,d)=>y("LocalRowIds",C(d),o,t,void 0,e,s),e.useMetric=B,e.useMetricListener=(e,s,o,t)=>y("Metric",w(t),s,o,void 0,e),e.useMetrics=e=>u(e,2),e.useRedoInformation=e=>{const s=k(e),[,,[o]]=E(s);return[!r(o),_(s),o,n(o,(e=>s?.getCheckpoint(e)))??""]},e.useRelationships=e=>u(e,6),e.useRemoteRowId=F,e.useRemoteRowIdListener=(e,s,o,t,d)=>y("RemoteRowId",C(d),o,t,void 0,e,s),e.useRow=(e,s,o)=>L("Row",p(o),{},e,s),e.useRowIds=P,e.useRowIdsListener=(e,s,o,t,d)=>y("RowIds",p(d),s,o,t,e),e.useRowListener=(e,s,o,t,d,r)=>y("Row",p(r),o,t,d,e,s),e.useSetCellCallback=(e,s,o,t,d,r,n,i)=>v(r,"Cell",t,d,n,i,e,s,o),e.useSetCheckpointCallback=(e=i,s=[],o,t=i,d=[])=>{const r=k(o);return R((s=>n(r,(o=>{const d=e(s);t(o.addCheckpoint(d),o,d)}))),[r,...s,...d])},e.useSetPartialRowCallback=(e,s,o,t,d,r,n)=>v(d,"PartialRow",o,t,r,n,e,s),e.useSetRowCallback=(e,s,o,t,d,r,n)=>v(d,"Row",o,t,r,n,e,s),e.useSetTableCallback=(e,s,o,t,d,r)=>v(t,"Table",s,o,d,r,e),e.useSetTablesCallback=(e,s,o,t,d)=>v(o,"Tables",e,s,t,d),e.useSliceIds=D,e.useSliceIdsListener=(e,s,o,t)=>y("SliceIds",b(t),s,o,void 0,e),e.useSliceRowIds=A,e.useSliceRowIdsListener=(e,s,o,t,d)=>y("SliceRowIds",b(d),o,t,void 0,e,s),e.useStore=e=>u(e,0),e.useTable=(e,s)=>L("Table",p(s),{},e),e.useTableIds=x,e.useTableIdsListener=(e,s,o,t)=>y("TableIds",p(t),e,s,o),e.useTableListener=(e,s,o,t,d)=>y("Table",p(d),s,o,t,e),e.useTables=e=>L("Tables",p(e),{}),e.useTablesListener=(e,s,o,t)=>y("Tables",p(t),e,s,o),e.useUndoInformation=e=>{const s=k(e),[o,t]=E(s);return[(d=o,!(0==(e=>e.length)(d))),$(s),t,n(t,(e=>s?.getCheckpoint(e)))??""];var d},Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],s):s((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseUiReact={},e.React);
|
package/lib/umd/ui-react.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://tinybase.org",
|
|
8
8
|
"description": "A tiny, reactive JavaScript library for structured state and tabular data.",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"tiny",
|
|
11
|
+
"reactive",
|
|
12
|
+
"state",
|
|
13
|
+
"data",
|
|
14
|
+
"react"
|
|
15
|
+
],
|
|
9
16
|
"type": "module",
|
|
10
17
|
"files": [
|
|
11
18
|
"lib/**"
|
|
@@ -14,6 +21,7 @@
|
|
|
14
21
|
".": "./lib/tinybase.js",
|
|
15
22
|
"./*": "./lib/*.js"
|
|
16
23
|
},
|
|
24
|
+
"types": "./lib/tinybase.d.ts",
|
|
17
25
|
"browser": {
|
|
18
26
|
"fs": false
|
|
19
27
|
},
|
|
@@ -33,15 +41,16 @@
|
|
|
33
41
|
"compileDocsPagesOnly": "gulp compileDocsPagesOnly",
|
|
34
42
|
"compileDocsAssetsOnly": "gulp compileDocsAssetsOnly",
|
|
35
43
|
"compileDocs": "gulp compileDocs",
|
|
44
|
+
"compileForProdAndDocs": "gulp compileForProdAndDocs",
|
|
36
45
|
"serveDocs": "gulp serveDocs",
|
|
37
46
|
"preCommit": "gulp preCommit",
|
|
38
47
|
"prePublishPackage": "gulp prePublishPackage",
|
|
39
48
|
"publishPackage": "gulp publishPackage"
|
|
40
49
|
},
|
|
41
50
|
"devDependencies": {
|
|
42
|
-
"@babel/cli": "^7.16.
|
|
51
|
+
"@babel/cli": "^7.16.8",
|
|
43
52
|
"@babel/core": "^7.16.7",
|
|
44
|
-
"@babel/preset-env": "^7.16.
|
|
53
|
+
"@babel/preset-env": "^7.16.8",
|
|
45
54
|
"@babel/preset-react": "^7.16.7",
|
|
46
55
|
"@babel/preset-typescript": "^7.16.7",
|
|
47
56
|
"@rollup/plugin-replace": "^3.0.1",
|
|
@@ -56,25 +65,25 @@
|
|
|
56
65
|
"@types/react-dom": "^17.0.11",
|
|
57
66
|
"@types/react-test-renderer": "^17.0.1",
|
|
58
67
|
"@types/tmp": "^0.2.3",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.9.
|
|
60
|
-
"@typescript-eslint/parser": "^5.9.
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
69
|
+
"@typescript-eslint/parser": "^5.9.1",
|
|
61
70
|
"asciichart": "^1.5.25",
|
|
62
71
|
"babel-eslint": "^10.1.0",
|
|
63
|
-
"babel-jest": "^27.4.
|
|
72
|
+
"babel-jest": "^27.4.6",
|
|
64
73
|
"babel-preset-minify": "^0.5.1",
|
|
65
74
|
"country-flag-emoji-json": "^2.0.0",
|
|
66
|
-
"cspell": "^5.
|
|
67
|
-
"esbuild": "^0.14.
|
|
68
|
-
"eslint": "^8.
|
|
75
|
+
"cspell": "^5.15.2",
|
|
76
|
+
"esbuild": "^0.14.11",
|
|
77
|
+
"eslint": "^8.7.0",
|
|
69
78
|
"eslint-config-prettier": "^8.3.0",
|
|
70
|
-
"eslint-plugin-jest": "^25.
|
|
71
|
-
"eslint-plugin-jsdoc": "^37.
|
|
79
|
+
"eslint-plugin-jest": "^25.7.0",
|
|
80
|
+
"eslint-plugin-jsdoc": "^37.6.1",
|
|
72
81
|
"eslint-plugin-react": "^7.28.0",
|
|
73
82
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
74
83
|
"gulp": "^4.0.2",
|
|
75
84
|
"gulp-gzip": "^1.4.2",
|
|
76
|
-
"http-server": "^14.
|
|
77
|
-
"jest": "^27.4.
|
|
85
|
+
"http-server": "^14.1.0",
|
|
86
|
+
"jest": "^27.4.7",
|
|
78
87
|
"jest-fetch-mock": "^3.0.3",
|
|
79
88
|
"jest-puppeteer": "^6.0.3",
|
|
80
89
|
"less": "^4.1.2",
|
|
@@ -83,12 +92,12 @@
|
|
|
83
92
|
"react": "^17.0.2",
|
|
84
93
|
"react-dom": "^17.0.2",
|
|
85
94
|
"react-test-renderer": "^17.0.2",
|
|
86
|
-
"rollup": "^2.
|
|
95
|
+
"rollup": "^2.64.0",
|
|
87
96
|
"rollup-plugin-esbuild": "^4.8.2",
|
|
88
97
|
"rollup-plugin-gzip": "^3.0.0",
|
|
89
98
|
"rollup-plugin-prettier": "^2.2.2",
|
|
90
99
|
"rollup-plugin-terser": "^7.0.2",
|
|
91
|
-
"tinydocs": "^0.1.
|
|
100
|
+
"tinydocs": "^0.1.10",
|
|
92
101
|
"tmp": "^0.2.1",
|
|
93
102
|
"ts-unused-exports": "^7.0.3",
|
|
94
103
|
"typescript": "4.5.4"
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<section id="hero"><h2 id="a-
|
|
1
|
+
<section id="hero"><h2 id="a-javascript-library-for-structured-state">A JavaScript library for <em>structured state</em>.</h2><p>Using plain old JavaScript objects to manage data gets old very quickly. It's error-prone, tricky to track changes efficiently, and easy to mistakenly incur performance costs.</p><p><em>TinyBase is a smarter way to structure your application state:</em></p><ul><li>Familiar concepts of <a href="#set-and-get-tables-rows-and-cells">tables, rows, and cells</a>, and <a href="#apply-schemas-to-tables">schematization</a> to model your data domain.</li><li><a href="#register-listeners-at-any-granularity">Flexibly reactive</a> to reconciled updates, so you only spend cycles on the data that changes.</li><li><a href="#create-indexes-for-fast-lookups">Indexing</a>, <a href="#define-metrics-and-aggregations">metrics</a>, <a href="#configure-relationships-between-tables">relationships</a> - and even an <a href="#use-checkpoints-for-an-easy-undo-stack">undo stack</a> for your app state! - out of the box.</li><li>Easily <a href="#persist-data-to-browser-file-or-server">sync your data</a> to local or remote storage, and use <a href="#call-react-hooks-to-bind-to-data">idiomatic bindings</a> to your React UI.</li></ul><p><em>Tiny by name, tiny by nature</em>, TinyBase only costs <a href="#did-we-say-tiny">2.6kB - 5.5kB</a> when compressed, and has zero dependencies. And of course it's <a href="#well-tested-and-documented">well tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started">fully documented</a>, and <a href="https://github.com/tinyplex/tinybase">open source</a>. Other <a href="https://tinybase.org/guides/faq/">FAQs</a>?</p></section><hr><p><a id="start" href="https://tinybase.org/guides/the-basics/getting-started">Get started</a></p><p><a href="https://tinybase.org/demos">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="set-and-get-tables-rows-and-cells">Set and get tables, rows, and cells.</h2><p>Creating a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a> requires just a simple call to the <a href="https://tinybase.org/api/store/functions/creation/createstore"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>, <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a>, or <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> values by their <a href="https://tinybase.org/api/common/type-aliases/identity/id"><code>Id</code></a>. And of course you can easily get the values back out again.</p><p>Read more about setting and changing data in <a href="https://tinybase.org/guides/the-basics">The Basics</a> guide.</p></section>
|
|
2
2
|
|
|
3
3
|
```js
|
|
4
4
|
const store = createStore()
|
|
@@ -9,7 +9,7 @@ console.log(store.getRow('pets', 'fido'));
|
|
|
9
9
|
// -> {species: 'dog', color: 'brown'}
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
<section><h2 id="register-listeners-at-any-granularity">Register listeners at any granularity.</h2><p>The magic starts to happen when you register listeners on a <a href="https://tinybase.org/api/store/interfaces/
|
|
12
|
+
<section><h2 id="register-listeners-at-any-granularity">Register listeners at any granularity.</h2><p>The magic starts to happen when you register listeners on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>, <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>, <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a>, or <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. They get called when any part of that object changes. You can also use wildcards - useful when you don't know the <a href="https://tinybase.org/api/common/type-aliases/identity/id"><code>Id</code></a> of the objects that might change.</p><p>Read more about listeners in the <a href="https://tinybase.org/guides/the-basics/listening-to-stores">Listening To Stores</a> guide.</p></section>
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
15
|
const listenerId = store.addTableListener('pets', () =>
|
|
@@ -22,7 +22,7 @@ store.setCell('pets', 'fido', 'sold', false);
|
|
|
22
22
|
store.delListener(listenerId);
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
<section><h2 id="call-react-hooks-to-bind-to-data">Call React hooks to bind to data.</h2><p>If you're using React in your application, the optional react module provides hooks to bind to the data in a <a href="https://tinybase.org/api/store/interfaces/
|
|
25
|
+
<section><h2 id="call-react-hooks-to-bind-to-data">Call React hooks to bind to data.</h2><p>If you're using React in your application, the optional <a href="https://tinybase.org/api/ui-react"><code>ui-react</code></a> module provides hooks to bind to the data in a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>More magic! The <a href="https://tinybase.org/api/ui-react/functions/store-hooks/usecell"><code>useCell</code></a> hook in this example fetches the dog's color. But it also registers a listener on that cell that will fire and re-render the component whenever the value changes.</p><p>Basically you simply describe what data you want in your user interface and TinyBase will take care of the whole lifecycle of updating it for you.</p><p>Read more about the using hooks in the <a href="https://tinybase.org/guides/building-uis/using-react-hooks">Using React Hooks</a> guide.</p></section>
|
|
26
26
|
|
|
27
27
|
```jsx
|
|
28
28
|
const App1 = () => {
|
|
@@ -40,10 +40,10 @@ console.log(app.innerHTML);
|
|
|
40
40
|
// -> 'Color: walnut'
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
<section><h2 id="use-components-to-make-reactive-apps">Use components to make reactive apps.</h2><p>The react module provides simple React components with bindings that make it easy to create a fully reactive user interface based on a <a href="https://tinybase.org/api/store/interfaces/
|
|
43
|
+
<section><h2 id="use-components-to-make-reactive-apps">Use components to make reactive apps.</h2><p>The react module provides simple React components with bindings that make it easy to create a fully reactive user interface based on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>In this example, the library's <a href="https://tinybase.org/api/ui-react/functions/store-components/rowview"><code>RowView</code></a> component just needs a reference to the <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>, the <code>tableId</code>, and the <code>rowId</code> in order to render the contents of that row. An optional <code>cellComponent</code> prop lets you override how you want each <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> rendered. Again, all the listeners and updates are taken care of for you.</p><p>The module also includes a context Provider that sets up default for an entire app to use, reducing the need to drill all your props down into your app's hierarchy.</p><p>Most of the demos showcase the use of these React hooks and components. Take a look at <a href="https://tinybase.org/demos/todo-app/todo-app-v1-the-basics">Todo App v1 (the basics)</a> to see these user interface binding patterns in action.</p><p>Read more about the <a href="https://tinybase.org/api/ui-react"><code>ui-react</code></a> module in the <a href="https://tinybase.org/guides/building-uis">Building UIs</a> guides.</p></section>
|
|
44
44
|
|
|
45
45
|
```jsx
|
|
46
|
-
const
|
|
46
|
+
const MyCellView = (props) => (
|
|
47
47
|
<>
|
|
48
48
|
{props.cellId}: <CellView {...props} />
|
|
49
49
|
<hr />
|
|
@@ -55,7 +55,7 @@ const App2 = () => (
|
|
|
55
55
|
store={store}
|
|
56
56
|
tableId="pets"
|
|
57
57
|
rowId="fido"
|
|
58
|
-
cellComponent={
|
|
58
|
+
cellComponent={MyCellView}
|
|
59
59
|
/>
|
|
60
60
|
);
|
|
61
61
|
|
|
@@ -70,7 +70,7 @@ console.log(app.innerHTML);
|
|
|
70
70
|
ReactDOM.unmountComponentAtNode(app);
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
<section><h2 id="apply-schemas-to-tables">Apply schemas to tables.</h2><p>By default, a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> can contain any arbitrary <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. But you can add a schema to a <a href="https://tinybase.org/api/store/interfaces/
|
|
73
|
+
<section><h2 id="apply-schemas-to-tables">Apply schemas to tables.</h2><p>By default, a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> can contain any arbitrary <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. But you can add a schema to a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a> to ensure that the values are always what you expect. For example, you can limit their types, and provide defaults. You can also create mutating listeners that can programmatically enforce a schema.</p><p>In this example, we set a second <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> without the <code>sold</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> in it. The schema ensures it's present with default of <code>false</code>.</p><p>Read more about schemas in the <a href="https://tinybase.org/guides/schemas-and-persistence/using-schemas">Using Schemas</a> guide.</p></section>
|
|
74
74
|
|
|
75
75
|
```js
|
|
76
76
|
store.setSchema({
|
|
@@ -88,7 +88,7 @@ console.log(store.getRow('pets', 'felix'));
|
|
|
88
88
|
store.delSchema();
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
<section><h2 id="persist-data-to-browser-file-or-server">Persist data to browser, file, or server.</h2><p>You can easily persist a <a href="https://tinybase.org/api/store/interfaces/
|
|
91
|
+
<section><h2 id="persist-data-to-browser-file-or-server">Persist data to browser, file, or server.</h2><p>You can easily persist a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a> between browser page reloads or sessions. You can also synchronize it with a web endpoint, or (if you're using TinyBase in an appropriate environment), load and save it to a file.</p><p>Read more about persisters in the <a href="https://tinybase.org/guides/schemas-and-persistence/persisting-data">Persisting Data</a> guide.</p></section>
|
|
92
92
|
|
|
93
93
|
```js
|
|
94
94
|
const persister = createSessionPersister(store, 'demo');
|
|
@@ -101,7 +101,7 @@ persister.destroy();
|
|
|
101
101
|
sessionStorage.clear();
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
<section><h2 id="define-metrics-and-aggregations">Define metrics and aggregations.</h2><p>A <a href="https://tinybase.org/api/metrics/interfaces/
|
|
104
|
+
<section><h2 id="define-metrics-and-aggregations">Define metrics and aggregations.</h2><p>A <a href="https://tinybase.org/api/metrics/interfaces/metrics/metrics"><code>Metrics</code></a> object makes it easy to keep a running aggregation of <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> values in each <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> of a <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>. This is useful for counting rows, but also supports averages, ranges of values, or arbitrary aggregations.</p><p>In this example, we create a new table of the pet species, and keep a track of which is most expensive. When we add horses to our pet store, the listener detects that the highest price has changed.</p><p>Read more about <a href="https://tinybase.org/api/metrics/interfaces/metrics/metrics"><code>Metrics</code></a> in the <a href="https://tinybase.org/guides/metrics-and-indexes/using-metrics">Using Metrics</a> guide.</p></section>
|
|
105
105
|
|
|
106
106
|
```js
|
|
107
107
|
store.setTable('species', {
|
|
@@ -130,7 +130,7 @@ store.setCell('species', 'horse', 'price', 20);
|
|
|
130
130
|
metrics.destroy();
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
<section><h2 id="create-indexes-for-fast-lookups">Create indexes for fast lookups.</h2><p>An <a href="https://tinybase.org/api/indexes/interfaces/
|
|
133
|
+
<section><h2 id="create-indexes-for-fast-lookups">Create indexes for fast lookups.</h2><p>An <a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> object makes it easy to look up all the <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> objects that have a certain value in a <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>.</p><p>In this example, we create an index on the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> values. We can then get the the list of distinct <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> value present for that index (known as 'slices'), and the set of <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> objects that match each value.</p><p><a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> objects are reactive too. So you can set listeners on them just as you do for the data in the underlying <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>Read more about <a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> in the <a href="https://tinybase.org/guides/metrics-and-indexes/using-indexes">Using Indexes</a> guide.</p></section>
|
|
134
134
|
|
|
135
135
|
```js
|
|
136
136
|
const indexes = createIndexes(store);
|
|
@@ -154,7 +154,7 @@ store.setRow('pets', 'lowly', {species: 'worm'});
|
|
|
154
154
|
indexes.destroy();
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
<section><h2 id="model-relationships-between-tables">Model relationships between tables.</h2><p>A <a href="https://tinybase.org/api/relationships/interfaces/
|
|
157
|
+
<section><h2 id="model-relationships-between-tables">Model relationships between tables.</h2><p>A <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> object lets you associate a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> in a local <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a> with the <a href="https://tinybase.org/api/common/type-aliases/identity/id"><code>Id</code></a> of a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> in a remote <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>. You can also reference a table to itself to create linked lists.</p><p>In this example, the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> of the <code>pets</code> <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a> is used to create a relationship to the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>, so that we can access the price of a given pet.</p><p>Like everything else, you can set listeners on <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> too.</p><p>Read more about <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> in the <a href="https://tinybase.org/guides/relationships-and-checkpoints/using-relationships">Using Relationships</a> guide.</p></section>
|
|
158
158
|
|
|
159
159
|
```js
|
|
160
160
|
const relationships = createRelationships(store);
|
|
@@ -177,7 +177,7 @@ console.log(
|
|
|
177
177
|
relationships.destroy();
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
<section><h2 id="set-checkpoints-for-an-undo-stack">Set checkpoints for an undo stack.</h2><p>A <a href="https://tinybase.org/api/checkpoints/interfaces/
|
|
180
|
+
<section><h2 id="set-checkpoints-for-an-undo-stack">Set checkpoints for an undo stack.</h2><p>A <a href="https://tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints"><code>Checkpoints</code></a> object lets you set checkpoints on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>. Move forward and backward through them to create undo and redo functions.</p><p>In this example, we set a checkpoint, then sell one of the pets. Later, the pet is brought back to the shop, and we go back to that checkpoint to revert the store to its previous state.</p><p>Read more about <a href="https://tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints"><code>Checkpoints</code></a> in the <a href="https://tinybase.org/guides/relationships-and-checkpoints/using-checkpoints">Using Checkpoints</a> guide.</p></section>
|
|
181
181
|
|
|
182
182
|
```js
|
|
183
183
|
const checkpoints = createCheckpoints(store);
|
|
@@ -192,4 +192,4 @@ console.log(store.getCell('pets', 'felix', 'sold'));
|
|
|
192
192
|
// -> false
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
<section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store"><code>store</code></a> module alone, you'll only add a gzipped <em>2.6kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>5.5kB</em>. The <code>ui-react</code> adaptor is just another <em>2.
|
|
195
|
+
<section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store"><code>store</code></a> module alone, you'll only add a gzipped <em>2.6kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>5.5kB</em>. The <code>ui-react</code> adaptor is just another <em>2.6kB</em>, and everything is fast.</p><p>Life's easy when you have zero dependencies.</p><p>Read more about how TinyBase is structured in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store">store</a></th><td>2.6kB</td><td>5.8kB</td><td>23.8kB</td><td>86.9kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/indexes">indexes</a></th><td>1.5kB</td><td>2.9kB</td><td>13.0kB</td><td>27.4kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics">metrics</a></th><td>1.5kB</td><td>3.0kB</td><td>12.3kB</td><td>26.6kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/relationships">relationships</a></th><td>1.5kB</td><td>3.1kB</td><td>14.3kB</td><td>39.0kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/checkpoints">checkpoints</a></th><td>1.3kB</td><td>2.4kB</td><td>10.0kB</td><td>30.7kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters">persisters</a></th><td>0.8kB</td><td>1.6kB</td><td>4.9kB</td><td>26.7kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/common">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/tinybase">tinybase</a></th><td>5.5kB</td><td>13.0kB</td><td>53.9kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>933</td><td>933</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,018</td><td>1,018</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>366</td><td>366</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>341</td><td>341</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">1,712</td></tr><tr><th class="right">Assertions</th><td colspan="3">7,959</td></tr></tbody></table></div><hr><p><a id="start" href="https://tinybase.org/guides/the-basics/getting-started">Get started</a></p><p><a href="https://tinybase.org/demos">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a> and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://github.com/tinyplex/tinybase/issues">Issues</a> and <a href="https://github.com/tinyplex/tinybase/releases">release notes</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a></li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/1.0.1">NPM</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was an interesting exercise in API design, minification, and documentation. It's not <a href="https://www.linkedin.com/in/jamespearce">my day job</a>, but I do intend to maintain it, so please provide feedback. I could not have done this without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>
|