tinybase 1.0.2 → 1.1.0-beta.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/checkpoints.d.ts +945 -0
- package/lib/checkpoints.js +1 -0
- package/lib/checkpoints.js.gz +0 -0
- package/lib/common.d.ts +115 -0
- package/lib/common.js +1 -0
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +66 -0
- package/lib/debug/checkpoints.js +332 -0
- package/lib/debug/common.js +3 -0
- package/lib/debug/indexes.d.ts +167 -6
- package/lib/debug/indexes.js +431 -0
- package/lib/debug/metrics.d.ts +72 -0
- package/lib/debug/metrics.js +401 -0
- package/lib/debug/persisters.js +191 -0
- package/lib/debug/relationships.d.ts +86 -1
- package/lib/debug/relationships.js +434 -0
- package/lib/debug/store.d.ts +187 -5
- package/lib/debug/store.js +783 -0
- package/lib/debug/tinybase.js +144 -39
- package/lib/indexes.d.ts +939 -0
- package/lib/indexes.js +1 -0
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +829 -0
- package/lib/metrics.js +1 -0
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +711 -0
- package/lib/persisters.js +1 -0
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.d.ts +1201 -0
- package/lib/relationships.js +1 -0
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +2688 -0
- package/lib/store.js +1 -0
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +13 -0
- package/lib/tinybase.js +1 -0
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +7185 -0
- package/lib/ui-react.js +1 -0
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -0
- package/lib/umd/checkpoints.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 -0
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -0
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.js +1 -0
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -0
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -0
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -0
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -0
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +14 -14
- package/readme.md +2 -2
package/lib/ui-react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=(e,t)=>e.includes(t),n=(e,t)=>e.forEach(t),o=e=>e.length,s=e=>0==o(e),r=e=>e.slice(1),i=(e,t)=>e.push(t),c=e=>e.pop(),l=e=>null==e,d=(e,t,n)=>l(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,u=e=>l(e)||0==(e=>e.size)(e),p=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),f=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>l(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n,o)=>(a(e,t)||(o?.(n),e.set(t,n)),C(e,t)),v=e=>new Set(e),y=(e,t,n)=>o(n)<2?((e,t)=>e?.add(t))(s(n)?e:k(e,n[0],v()),t):y(k(e,n[0],f()),t,r(n)),L=e=>{const t=(o,i,...c)=>d(o,(o=>s(c)?e(o,i):n([c[0],null],(e=>t(C(o,e),i,...r(c))))));return t},b=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((e=>{let r,w,S,T=100,j=f(),x=1;const z=v(),E=f(),[M,m,B]=(e=>{let t,s=0;const r=[],a=f();return[(n,o,i=[])=>{t??=e();const l=c(r)??""+s++;return g(a,l,[n,o,i]),y(o,l,i),l},(e,n=[],...o)=>L(p)(e,(e=>d(C(a,e),(([e])=>e(t,...n,...o)))),...n),e=>d(C(a,e),(([,t,n])=>(L(h)(t,e,...n),g(a,e),o(r)<1e3&&i(r,e),n)),(()=>[])),(e,s,r)=>d(C(a,e),(([e,,i])=>{const c=(...d)=>{const a=o(d);a==o(i)?e(t,...d,...r(d)):l(i[a])?n(s[a](...d),(e=>c(...d,e))):c(...d,i[a])};c()}))]})((()=>U)),I=f(),O=f(),_=[],F=[],P=(t,n)=>{x=0,e.transaction((()=>p(C(I,n),((n,o)=>p(n,((n,s)=>p(n,((n,r)=>l(n[t])?e.delCell(o,s,r,!0):e.setCell(o,s,r,n[t]))))))))),x=1},W=e=>{g(I,e),g(O,e),m(E,[e])},q=(e,t)=>n(((e,t)=>e.splice(0,t))(e,t??o(e)),W),A=()=>q(_,o(_)-T),D=e.addCellListener(null,null,null,((e,t,n,o,s,l)=>{if(x){d(r,(()=>{i(_,r),A(),q(F),r=void 0,S=1}));const e=k(j,t,f()),a=k(e,n,f()),p=k(a,o,[void 0,void 0],(e=>e[0]=l));p[1]=s,p[0]===p[1]&&u(g(a,o))&&u(g(e,n))&&u(g(j,t))&&(r=c(_),S=1),K()}})),G=(e="")=>(l(r)&&(r=""+w++,g(I,r,j),Q(r,e),j=f(),S=1),r),H=()=>{s(_)||(F.unshift(G()),P(0,r),r=c(_),S=1)},J=()=>{s(F)||(i(_,r),r=F.shift(),P(1,r),S=1)},K=()=>{S&&(m(z),S=0)},N=e=>{const t=G(e);return K(),t},Q=(e,t)=>(R(e)&&C(O,e)!==t&&(g(O,e,t),m(E,[e])),U),R=e=>a(I,e),U={setSize:e=>(T=e,A(),U),addCheckpoint:N,setCheckpoint:Q,getStore:()=>e,getCheckpointIds:()=>[[..._],r,[...F]],forEachCheckpoint:e=>{return t=e,p(O,((e,n)=>t(n,e)));var t},hasCheckpoint:R,getCheckpoint:e=>C(O,e),goBackward:()=>(H(),K(),U),goForward:()=>(J(),K(),U),goTo:e=>{const n=t(_,e)?H:t(F,e)?J:null;for(;!l(n)&&e!=r;)n();return K(),U},addCheckpointIdsListener:e=>M(e,z),addCheckpointListener:(e,t)=>M(t,E,[e]),delListener:e=>(B(e),U),clear:()=>(q(_),q(F),l(r)||W(r),r=void 0,w=0,N(),U),destroy:()=>{e.delListener(D)},getListenerStats:()=>({})};return b(U.clear())}));e.createCheckpoints=w,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).TinyBaseCheckpoints={});
|
|
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
|
|
@@ -0,0 +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),r=e=>e.length,i=e=>0==r(e),c=e=>e.slice(1),l=e=>null==e,a=(e,t,n)=>l(e)?n?.():t(e),f=(e,t)=>e?.has(t)??!1,u=e=>l(e)||0==(e=>e.size)(e),h=e=>e.clear(),p=(e,t)=>e?.forEach(t),I=(e,t)=>e?.delete(t),g=e=>new Map(e),x=e=>[...e?.keys()??[]],y=(e,t)=>e?.get(t),S=(e,t)=>p(e,((e,n)=>t(n,e))),b=(e,t,n)=>l(n)?(I(e,t),e):e?.set(t,n),w=(e,t,n,s)=>(f(e,t)||(s?.(n),e.set(t,n)),y(e,t)),v=e=>new Set(e),L=(e,t)=>e?.add(t),T=(e,s)=>t(e)==n?t=>t(e):e??(()=>s??""),E=(e,t)=>e<t?-1:1,R=(e,t,n)=>r(n)<2?L(i(n)?e:w(e,n[0],v()),t):R(w(e,n[0],g()),t,c(n)),j=e=>{const t=(n,s,...o)=>a(n,(n=>i(o)?e(n,s):d([o[0],null],(e=>t(y(n,e),s,...c(o))))));return t},M=Object.freeze,k=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((e=>{const t=g(),n=g(),[i,c,w,k,m,z,C,D,O,_]=((e,t,n)=>{const s=e.hasRow,o=g(),r=g(),i=g(),c=g(),u=g(),I=t=>a(y(u,t),(n=>{p(n,e.delListener),b(u,t)})),w=e=>{b(o,e),b(r,e),b(i,e),b(c,e),I(e)};return[()=>e,()=>x(o),e=>S(r,e),e=>f(r,e),e=>y(o,e),e=>y(r,e),(e,t)=>b(r,e,t),(a,x,w,L,T)=>{const E=g(),R=g();b(o,a,x),f(r,a)||(b(r,a,t()),b(i,a,g()),b(c,a,g()));const j=y(i,a),M=y(c,a),k=t=>{const o=n=>e.getCell(x,t,n),d=y(j,t),r=s(x,t)?n(L(o,t)):void 0;if(d!=r&&b(E,t,[d,r]),!l(T)){const e=y(M,t),n=s(x,t)?T(o,t):void 0;e!=n&&b(R,t,n)}},m=e=>{w((()=>{p(E,(([,e],t)=>b(j,t,e))),p(R,((e,t)=>b(M,t,e)))}),E,R,j,M,e),h(E),h(R)};S(j,k),e.hasTable(x)&&d(e.getRowIds(x),(e=>{f(j,e)||k(e)})),m(!0),I(a),b(u,a,v([e.addRowListener(x,null,((e,t,n)=>k(n))),e.addTableListener(x,(()=>m()))]))},w,()=>S(u,w)]})(e,g,(e=>l(e)?"":e+"")),[B,P,W]=(e=>{let t,n=0;const s=[],o=g();return[(d,r,i=[])=>{t??=e();const c=s.pop()??""+n++;return b(o,c,[d,r,i]),R(r,c,i),c},(e,n=[],...s)=>j(p)(e,(e=>a(y(o,e),(([e])=>e(t,...n,...s)))),...n),e=>a(y(o,e),(([,t,n])=>(j(I)(t,e,...n),b(o,e),r(s)<1e3&&s.push(e),n)),(()=>[])),(e,n,s)=>a(y(o,e),(([e,,o])=>{const i=(...c)=>{const a=r(c);a==r(o)?e(t,...c,...s(c)):l(o[a])?d(n[a](...c),(e=>i(...c,e))):i(...c,o[a])};i()}))]})((()=>A)),q=(t,n,s)=>{const o=m(t);p(s,((t,s)=>n(s,(n=>p(t,(t=>n(t,(n=>e.forEachCell(o,t,n)))))))))},A={setIndexDefinition:(e,d,r,i,c,h=E)=>{const x=l(c)?void 0:([e],[t])=>c(e,t);return D(e,d,((d,r,c,w,T,E)=>{let R=0;const j=v(),M=v(),k=z(e);if(p(r,(([e,t],n)=>{l(e)||(L(j,e),a(y(k,e),(t=>{I(t,n),u(t)&&(b(k,e),R=1)}))),l(t)||(L(j,t),f(k,t)||(b(k,t,v()),R=1),L(y(k,t),n),l(i)||L(M,t))})),d(),u(T)||(E?S(k,(e=>L(M,e))):S(c,(e=>a(y(w,e),(e=>L(M,e))))),p(M,(e=>{const t=(t,n)=>h(y(T,t),y(T,n),e),n=[...y(k,e)];s(n,t)||(b(k,e,v(o(n,t))),L(j,e))}))),(R||E)&&!l(x)){const t=[...k];s(t,x)||(C(e,g(o(t,x))),R=1)}R&&P(t,[e]),p(j,(t=>P(n,[e,t])))}),T(r),a(i,T)),A},delIndexDefinition:e=>(O(e),A),getStore:i,getIndexIds:c,forEachIndex:e=>w(((t,n)=>e(t,(e=>q(t,e,n))))),forEachSlice:(e,t)=>q(e,t,z(e)),hasIndex:k,hasSlice:(e,t)=>f(z(e),t),getTableId:m,getSliceIds:e=>x(z(e)),getSliceRowIds:(e,t)=>[...y(z(e),t)?.values()??[]],addSliceIdsListener:(e,n)=>B(n,t,[e]),addSliceRowIdsListener:(e,t,s)=>B(s,n,[e,t]),delListener:e=>(W(e),A),destroy:_,getListenerStats:()=>({})};return M(A)}));e.createIndexes=k,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={});
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,s=t(""),n=t(t),i=(e,t)=>e.forEach(t),o=e=>d(e,((e,t)=>e+t),0),r=e=>e.length,c=e=>0==r(e),d=(e,t,s)=>e.reduce(t,s),a=e=>e.slice(1),l=Math.max,u=Math.min,f=isFinite,h=e=>null==e,p=(e,t,s)=>h(e)?s?.():t(e),v=()=>{},M=e=>e.size,g=(e,t)=>e?.has(t)??!1,y=e=>e.clear(),b=(e,t)=>e?.forEach(t),m=(e,t)=>e?.delete(t),w=e=>new Map(e),L=(e,t)=>e?.get(t),T=(e,t)=>b(e,((e,s)=>t(s,e))),x=(e,t,s)=>h(s)?(m(e,t),e):e?.set(t,s),j=(e,t,s,n)=>(g(e,t)||(n?.(s),e.set(t,s)),L(e,t)),E=e=>new Set(e),I=(e,n)=>t(e)==s?t=>t(e):e??(()=>n??""),R=(e,t,s)=>r(s)<2?((e,t)=>e?.add(t))(c(s)?e:j(e,s[0],E()),t):R(j(e,s[0],w()),t,a(s)),S=e=>{const t=(s,n,...o)=>p(s,(s=>c(o)?e(s,n):i([o[0],null],(e=>t(L(s,e),n,...a(o))))));return t},k=Object.freeze,z=w([["avg",[(e,t)=>o(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=>l(...e),(e,t)=>l(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:l(t,e)]],["min",[e=>u(...e),(e,t)=>u(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:u(t,e)]],["sum",[e=>o(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),D=(e=>{const t=new WeakMap;return s=>(t.has(s)||t.set(s,e(s)),t.get(s))})((e=>{const s=w(),[o,c,d,a,l,u,j,D,N,O]=((e,t,s)=>{const n=e.hasRow,o=w(),r=w(),c=w(),d=w(),a=w(),l=t=>p(L(a,t),(s=>{b(s,e.delListener),x(a,t)})),u=e=>{x(o,e),x(r,e),x(c,e),x(d,e),l(e)};return[()=>e,()=>[...o?.keys()??[]],e=>T(r,e),e=>g(r,e),e=>L(o,e),e=>L(r,e),(e,t)=>x(r,e,t),(u,f,p,v,M)=>{const m=w(),j=w();x(o,u,f),g(r,u)||(x(r,u,t()),x(c,u,w()),x(d,u,w()));const I=L(c,u),R=L(d,u),S=t=>{const i=s=>e.getCell(f,t,s),o=L(I,t),r=n(f,t)?s(v(i,t)):void 0;if(o!=r&&x(m,t,[o,r]),!h(M)){const e=L(R,t),s=n(f,t)?M(i,t):void 0;e!=s&&x(j,t,s)}},k=e=>{p((()=>{b(m,(([,e],t)=>x(I,t,e))),b(j,((e,t)=>x(R,t,e)))}),m,j,I,R,e),y(m),y(j)};T(I,S),e.hasTable(f)&&i(e.getRowIds(f),(e=>{g(I,e)||S(e)})),k(!0),l(u),x(a,u,E([e.addRowListener(f,null,((e,t,s)=>S(s))),e.addTableListener(f,(()=>k()))]))},u,()=>T(a,u)]})(e,v,(e=>isNaN(e)||h(e)||!0===e||!1===e||""===e?void 0:1*e)),[_,B,C]=(e=>{let t,s=0;const n=[],o=w();return[(i,r,c=[])=>{t??=e();const d=n.pop()??""+s++;return x(o,d,[i,r,c]),R(r,d,c),d},(e,s=[],...n)=>S(b)(e,(e=>p(L(o,e),(([e])=>e(t,...s,...n)))),...s),e=>p(L(o,e),(([,t,s])=>(S(m)(t,e,...s),x(o,e),r(n)<1e3&&n.push(e),s)),(()=>[])),(e,s,n)=>p(L(o,e),(([e,,o])=>{const c=(...d)=>{const a=r(d);a==r(o)?e(t,...d,...n(d)):h(o[a])?i(s[a](...d),(e=>c(...d,e))):c(...d,o[a])};c()}))]})((()=>F)),F={setMetricDefinition:(e,i,o,r,c,d,a)=>{const l=t(o)==n?[o,c,d,a]:L(z,o)??L(z,"sum");return D(e,i,((t,n,i,o,r,c)=>{let d=u(e),a=M(o);const[p,v,g,y]=l;var m;c=c||h(d),b(n,(([e,t])=>{c||(d=h(e)?v?.(d,t,a++):h(t)?g?.(d,e,a--):y?.(d,t,e,a)),c=c||h(d)})),t(),h(m=o)||0==M(m)?d=void 0:c&&(d=p((e=>[...e?.values()??[]])(o),M(o))),f(d)||(d=void 0);const w=u(e);d!=w&&(j(e,d),B(s,[e],d,w))}),I(r,1)),F},delMetricDefinition:e=>(N(e),F),getStore:o,getMetricIds:c,forEachMetric:d,hasMetric:a,getTableId:l,getMetric:u,addMetricListener:(e,t)=>_(t,s,[e]),delListener:e=>(C(e),F),destroy:O,getListenerStats:()=>({})};return k(F)}));e.createMetrics=D,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).TinyBaseMetrics={});
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t;e=this,t=function(e,t){"use strict";const s="utf8",a=e=>null==e,o=(e,t,s)=>a(e)?s?.():t(e),r=Object.freeze,n=(e,t,s,n,i)=>{let c,d=0;const l={load:async s=>{if(2!=d){d=1;const o=await t();a(o)||""==o?e.setTables(s):e.setJson(o),d=0}return l},startAutoLoad:async e=>(l.stopAutoLoad(),await l.load(e),n(l.load),l),stopAutoLoad:()=>(i(),l),save:async()=>(1!=d&&(d=2,await s(e.getJson()),d=0),l),startAutoSave:async()=>(await l.stopAutoSave().save(),c=e.addTablesListener((()=>l.save())),l),stopAutoSave:()=>(o(c,e.delListener),l),getStore:()=>e,destroy:()=>l.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return r(l)},i="storage",c=globalThis.window,d=(e,t,s)=>{let a;return n(e,(async()=>s.getItem(t)),(async e=>s.setItem(t,e)),(e=>{a=a=>{a.storageArea===s&&a.key===t&&e()},c.addEventListener(i,a)}),(()=>{c.removeEventListener(i,a),a=void 0}))},l=e=>e.headers.get("ETag");e.createCustomPersister=n,e.createFilePersister=(e,a)=>{let o;return n(e,(async()=>{try{return await t.promises.readFile(a,s)}catch{}}),(async e=>{try{await t.promises.writeFile(a,e,s)}catch{}}),(e=>{o=t.watch(a,e)}),(()=>{o?.close(),o=void 0}))},e.createLocalPersister=(e,t)=>d(e,t,localStorage),e.createRemotePersister=(e,t,s,r)=>{let i,c;return n(e,(async()=>{const e=await fetch(t);return c=l(e),e.text()}),(async e=>await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:e})),(e=>{i=setInterval((async()=>{const s=await fetch(t,{method:"HEAD"}),o=l(s);a(c)||a(o)||o==c||(c=o,e())}),1e3*r)}),(()=>{o(i,clearInterval),i=void 0}))},e.createSessionPersister=(e,t)=>d(e,t,sessionStorage),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).TinyBasePersisters={},e.fs);
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,o=t(""),s=(e,t)=>e.forEach(t),n=e=>e.length,i=e=>0==n(e),a=e=>e.slice(1),d=e=>null==e,r=(e,t,o)=>d(e)?o?.():t(e),l=(e,t)=>e?.has(t)??!1,c=e=>[...e?.values()??[]],f=e=>e.clear(),h=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),u=e=>new Map(e),R=(e,t)=>e?.get(t),g=(e,t)=>h(e,((e,o)=>t(o,e))),w=(e,t,o)=>d(o)?(p(e,t),e):e?.set(t,o),L=(e,t,o,s)=>(l(e,t)||(s?.(o),e.set(t,o)),R(e,t)),I=e=>new Set(e),b=(e,t)=>e?.add(t),y=(e,s)=>t(e)==o?t=>t(e):e??(()=>s??""),v=(e,t,o)=>n(o)<2?b(i(o)?e:L(e,o[0],I()),t):v(L(e,o[0],u()),t,a(o)),T=e=>{const t=(o,n,...d)=>r(o,(o=>i(d)?e(o,n):s([d[0],null],(e=>t(R(o,e),n,...a(d))))));return t},m=Object.freeze,k=(e=>{const t=new WeakMap;return o=>(t.has(o)||t.set(o,e(o)),t.get(o))})((e=>{const t=u(),o=u(),i=u(),a=u(),[L,k,E,j,x,M,S,z,D,O]=((e,t,o)=>{const n=e.hasRow,i=u(),a=u(),c=u(),p=u(),L=u(),b=t=>r(R(L,t),(o=>{h(o,e.delListener),w(L,t)})),y=e=>{w(i,e),w(a,e),w(c,e),w(p,e),b(e)};return[()=>e,()=>[...i?.keys()??[]],e=>g(a,e),e=>l(a,e),e=>R(i,e),e=>R(a,e),(e,t)=>w(a,e,t),(r,y,v,T,m)=>{const k=u(),E=u();w(i,r,y),l(a,r)||(w(a,r,t()),w(c,r,u()),w(p,r,u()));const j=R(c,r),x=R(p,r),M=t=>{const s=o=>e.getCell(y,t,o),i=R(j,t),a=n(y,t)?o(T(s,t)):void 0;if(i!=a&&w(k,t,[i,a]),!d(m)){const e=R(x,t),o=n(y,t)?m(s,t):void 0;e!=o&&w(E,t,o)}},S=e=>{v((()=>{h(k,(([,e],t)=>w(j,t,e))),h(E,((e,t)=>w(x,t,e)))}),k,E,j,x,e),f(k),f(E)};g(j,M),e.hasTable(y)&&s(e.getRowIds(y),(e=>{l(j,e)||M(e)})),S(!0),b(r),w(L,r,I([e.addRowListener(y,null,((e,t,o)=>M(o))),e.addTableListener(y,(()=>S()))]))},y,()=>g(L,y)]})(e,(()=>[u(),u(),u(),u()]),(e=>d(e)?void 0:e+"")),[_,B,C]=(e=>{let t,o=0;const i=[],a=u();return[(s,n,d=[])=>{t??=e();const r=i.pop()??""+o++;return w(a,r,[s,n,d]),v(n,r,d),r},(e,o=[],...s)=>T(h)(e,(e=>r(R(a,e),(([e])=>e(t,...o,...s)))),...o),e=>r(R(a,e),(([,t,o])=>(T(p)(t,e,...o),w(a,e),n(i)<1e3&&i.push(e),o)),(()=>[])),(e,o,i)=>r(R(a,e),(([e,,a])=>{const r=(...l)=>{const c=n(l);c==n(a)?e(t,...l,...i(l)):d(a[c])?s(o[c](...l),(e=>r(...l,e))):r(...l,a[c])};r()}))]})((()=>A)),P=(e,t,o)=>r(M(e),(([s,,n])=>{if(!l(n,t)){const i=I();if(x(e)!=q(e))b(i,t);else{let e=t;for(;!d(e)&&!l(i,e);)b(i,e),e=R(s,e)}if(o)return i;w(n,t,i)}return R(n,t)})),W=(e,t)=>r(M(e),(([,,e])=>w(e,t))),q=e=>R(t,e),A={setRelationshipDefinition:(e,s,n,c)=>(w(t,e,n),z(e,s,((t,s)=>{const n=I(),c=I(),f=I(),[u,L]=M(e);h(s,(([t,o],s)=>{d(t)||(b(c,t),r(R(L,t),(e=>{var o;p(e,s),(d(o=e)||0==(e=>e.size)(o))&&w(L,t)}))),d(o)||(b(c,o),l(L,o)||w(L,o,I()),b(R(L,o),s)),b(n,s),w(u,s,o),g(R(a,e),(t=>{l(P(e,t),s)&&b(f,t)}))})),t(),h(n,(t=>B(o,[e,t]))),h(c,(t=>B(i,[e,t]))),h(f,(t=>{W(e,t),B(a,[e,t])}))}),y(c)),A),delRelationshipDefinition:e=>(w(t,e),D(e),A),getStore:L,getRelationshipIds:k,forEachRelationship:t=>E((o=>t(o,(t=>e.forEachRow(x(o),t))))),hasRelationship:j,getLocalTableId:x,getRemoteTableId:q,getRemoteRowId:(e,t)=>R(M(e)?.[0],t),getLocalRowIds:(e,t)=>c(R(M(e)?.[1],t)),getLinkedRowIds:(e,t)=>d(M(e))?[t]:c(P(e,t,!0)),addRemoteRowIdListener:(e,t,s)=>_(s,o,[e,t]),addLocalRowIdsListener:(e,t,o)=>_(o,i,[e,t]),addLinkedRowIdsListener:(e,t,o)=>(P(e,t),_(o,a,[e,t])),delListener:e=>(W(...C(e)),A),destroy:O,getListenerStats:()=>({})};return m(A)}));e.createRelationships=k,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).TinyBaseRelationships={});
|
|
Binary file
|
package/lib/umd/store.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,s=t(""),n=t(!0),r=t(0),l=t(t),o="type",a="default",d=(e,t)=>e.forEach(t),c=e=>e.length,i=e=>0==c(e),u=e=>e.slice(1),f=(e,t)=>e.push(t),h=e=>JSON.stringify(e,((e,t)=>{return T(t,Map)?(s=[...t],n=(e,[t,s])=>(e[t]=s,e),r={},s.reduce(n,r)):t;var s,n,r})),b=JSON.parse,p=isFinite,T=(e,t)=>e instanceof t,g=e=>null==e,y=(e,t,s)=>g(e)?s?.():t(e),w=e=>e==s||e==n,L=(e,t)=>e?.has(t)??!1,R=e=>g(e)||0==(e=>e.size)(e),C=e=>e.clear(),S=(e,t)=>e?.forEach(t),v=(e,t)=>e?.delete(t),I=e=>new Map(e),m=(e=I)=>[e(),e()],E=e=>[...e?.keys()??[]],J=(e,t)=>e?.get(t),O=(e,t)=>S(e,((e,s)=>t(s,e))),j=(e,t,s)=>g(s)?(v(e,t),e):e?.set(t,s),x=(e,t,s,n)=>(L(e,t)||(n?.(s),e.set(t,s)),J(e,t)),z=(e,t)=>{const s={},n=t??(e=>e);return S(e,((e,t)=>s[t]=n(e))),s},M=(e,t)=>{const s=I(),n=t??(e=>e);return S(e,((e,t)=>s.set(t,n(e)))),s},k=Object,F=k.keys,N=k.isFrozen,P=k.freeze,_=(e,t)=>!g(((e,t)=>y(e,(e=>e[t])))(e,t)),B=(e,t)=>delete e[t],q=(e,t)=>d(k.entries(e),(([e,s])=>t(s,e))),A=e=>new Set(e),D=(e,t,s)=>c(s)<2?((e,t)=>e?.add(t))(i(s)?e:x(e,s[0],A()),t):D(x(e,s[0],I()),t,u(s)),G=e=>{const t=(s,n,...r)=>y(s,(s=>i(r)?e(s,n):d([r[0],null],(e=>t(J(s,e),n,...u(r))))));return t},H=(e,t,s,n=j)=>{const r=(l=E(e),o=e=>!_(t,e),l.filter(o));var l,o;return d(F(t),(n=>s(e,n,t[n]))),d(r,(t=>n(e,t))),e},K=e=>{const s=t(e);return w(s)||s==r&&p(e)?s:void 0},Q=(e,t)=>!(g(e)||!(e=>T(e,k)&&e.constructor==k)(e)||N(e)||(q(e,((s,n)=>{t(s,n)||B(e,n)})),(e=>i(F(e)))(e))),U=(e,t,s)=>j(e,t,J(e,t)==-s?void 0:s);e.createStore=()=>{let e,s=0,n=0;const i=I(),u=I(),p=I(),T=I(),k=I(),F=I(),N=I(),V=I(),W=m(A),X=m(A),Y=m(),Z=m(),$=m(),ee=m(),te=m(),se=m(),[ne,re,le,oe]=(e=>{let t,s=0;const n=[],r=I();return[(l,o,a=[])=>{t??=e();const d=n.pop()??""+s++;return j(r,d,[l,o,a]),D(o,d,a),d},(e,s=[],...n)=>G(S)(e,(e=>y(J(r,e),(([e])=>e(t,...s,...n)))),...s),e=>y(J(r,e),(([,t,s])=>(G(v)(t,e,...s),j(r,e),c(n)<1e3&&f(n,e),s)),(()=>[])),(e,s,n)=>y(J(r,e),(([e,,r])=>{const l=(...o)=>{const a=c(o);a==c(r)?e(t,...o,...n(o)):g(r[a])?d(s[a](...o),(e=>l(...o,e))):l(...o,r[a])};l()}))]})((()=>Be)),ae=(t,s)=>(!e||L(F,s))&&Q(t,((e,t)=>de(s,t,e))),de=(e,t,s,n)=>Q(n?s:ie(s,e),((n,r)=>y(ce(e,t,r,n),(e=>(s[r]=e,!0)),(()=>!1)))),ce=(t,s,n,r)=>e?y(J(J(F,t),n),(e=>K(r)!=e.type?Ee(t,s,n,r,e.default):r)):g(K(r))?Ee(t,s,n,r):r,ie=(e,t)=>(y(J(N,t),(t=>q(t,((t,s)=>{_(e,s)||(e[s]=t)})))),e),ue=e=>H(F,e,((e,t,s)=>{const n={};H(x(F,t,I()),s,((e,t,s)=>{j(e,t,s),y(s.default,(e=>n[t]=e))})),j(N,t,n)}),((e,t)=>{j(F,t),j(N,t)})),fe=e=>H(V,e,((e,t,s)=>he(t,s)),((e,t)=>Le(t))),he=(e,t)=>H(x(V,e,I(),(()=>Se(e,1))),t,((t,s,n)=>be(e,t,s,n)),((t,s)=>Re(e,t,s))),be=(e,t,s,n,r)=>H(x(t,s,I(),(()=>ve(e,s,1))),n,((t,n,r)=>pe(e,s,t,n,r)),((n,l)=>Ce(e,t,s,n,l,r))),pe=(e,t,s,n,r)=>{L(s,n)||Ie(e,t,n,1);const l=J(s,n);r!==l&&(me(e,t,n,l),j(s,n,r))},Te=(e,t,s)=>_e((()=>be(e,we(e),t,s))),ge=(e,t,s,n,r)=>y(J(t,s),(t=>pe(e,s,t,n,r)),(()=>be(e,t,s,ie({[n]:r},e)))),ye=e=>{const t=""+s++;return L(e,t)?ye(e):t},we=e=>J(V,e)??he(e,{}),Le=e=>he(e,{}),Re=(e,t,s)=>be(e,t,s,{},!0),Ce=(e,t,s,n,r,l)=>{const o=J(N,e)?.[r];if(!g(o)&&!l)return pe(e,s,n,r,o);const a=t=>{me(e,s,t,J(n,t)),Ie(e,s,t,-1),j(n,t)};g(o)?a(r):O(n,a),R(n)&&(ve(e,s,-1),R(j(t,s))&&(Se(e,-1),j(V,e)))},Se=(e,t)=>U(i,e,t),ve=(e,t,s)=>U(x(u,e,I()),t,s),Ie=(e,t,s,n)=>U(x(x(p,e,I()),t,I()),s,n),me=(e,t,s,n)=>x(x(x(T,e,I()),t,I()),s,n),Ee=(e,t,s,n,r)=>(f(x(x(x(k,e,I()),t,I()),s,[]),n),r),Je=(e,t,s)=>{const n=J(J(T,e),t),r=Fe(e,t,s);return L(n,s)?[!0,J(n,s),r]:[!1,r,r]},Oe=e=>{R(se[e])||S(e?M(k,(e=>M(e,M))):k,((t,s)=>S(t,((t,n)=>S(t,((t,r)=>re(se[e],[s,n,r],t)))))))},je=e=>{const t=R(ee[e])&&R(Z[e])&&R(X[e]),s=R(te[e])&&R($[e])&&R(Y[e])&&R(W[e]);if(t&&s)return;const n=e?[M(i),M(u,M),M(p,(e=>M(e,M))),M(T,(e=>M(e,M)))]:[i,u,p,T];if(t||(S(n[2],((t,s)=>S(t,((t,n)=>{R(t)||re(ee[e],[s,n])})))),S(n[1],((t,s)=>{R(t)||re(Z[e],[s])})),R(n[0])||re(X[e])),!s){let t;S(n[3],((s,n)=>{let r;S(s,((s,l)=>{let o;S(s,((s,a)=>{const d=Fe(n,l,a);d!==s&&(re(te[e],[n,l,a],d,s,Je),t=r=o=1)})),o&&re($[e],[n,l],Je)})),r&&re(Y[e],[n],Je)})),t&&re(W[e],[],Je)}},xe=()=>z(V,(e=>z(e,z))),ze=()=>E(V),Me=e=>E(J(V,e)),ke=(e,t)=>E(J(J(V,e),t)),Fe=(e,t,s)=>J(J(J(V,e),t),s),Ne=e=>((e=>Q(e,ae))(e)?_e((()=>fe(e))):_e(),Be),Pe=()=>(_e((()=>fe({}))),Be),_e=e=>{if(-1==n)return;n++;const t=e?.();return n--,0==n&&(n=1,Oe(1),je(1),n=-1,Oe(0),je(0),n=0,d([T,k,i,u,p],C)),t},Be={getTables:xe,getTableIds:ze,getTable:e=>z(J(V,e),z),getRowIds:Me,getRow:(e,t)=>z(J(J(V,e),t)),getCellIds:ke,getCell:Fe,hasTables:()=>!R(V),hasTable:e=>L(V,e),hasRow:(e,t)=>L(J(V,e),t),hasCell:(e,t,s)=>L(J(J(V,e),t),s),getJson:()=>h(V),getSchemaJson:()=>h(F),setTables:Ne,setTable:(e,t)=>(ae(t,e)?_e((()=>he(e,t))):_e(),Be),setRow:(e,t,s)=>(de(e,t,s)?Te(e,t,s):_e(),Be),addRow:(e,t)=>{let s;return de(e,s,t)?Te(e,s=ye(J(V,e)),t):_e(),s},setPartialRow:(e,t,s)=>(de(e,t,s,1)?_e((()=>{const n=we(e);q(s,((s,r)=>ge(e,n,t,r,s)))})):_e(),Be),setCell:(e,s,n,r)=>(y(ce(e,s,n,t(r)==l?r(Fe(e,s,n)):r),(t=>_e((()=>ge(e,we(e),s,n,t)))),_e),Be),setJson:e=>{try{"{}"===e?Pe():Ne(b(e))}catch{}return Be},setSchema:t=>{if((e=(e=>Q(e,(e=>Q(e,(e=>{if(!Q(e,((e,t)=>[o,a].includes(t))))return!1;const t=e.type;return!(!w(t)&&t!=r||(K(e.default)!=t&&B(e,a),0))})))))(t))&&(ue(t),!R(V))){const e=xe();Pe(),Ne(e)}return Be},delTables:Pe,delTable:e=>(L(V,e)&&_e((()=>Le(e))),Be),delRow:(e,t)=>(y(J(V,e),(s=>{L(s,t)&&_e((()=>Re(e,s,t)))})),Be),delCell:(e,t,s,n)=>(y(J(V,e),(r=>y(J(r,t),(l=>{L(l,s)&&_e((()=>Ce(e,r,t,l,s,n)))})))),Be),delSchema:()=>(ue({}),e=!1,Be),transaction:_e,forEachTable:e=>S(V,((t,s)=>e(s,(e=>S(t,((t,s)=>e(s,(e=>O(t,e))))))))),forEachRow:(e,t)=>S(J(V,e),((e,s)=>t(s,(t=>O(e,t))))),forEachCell:(e,t,s)=>O(J(J(V,e),t),s),addTablesListener:(e,t)=>ne(e,W[t?1:0]),addTableIdsListener:(e,t)=>ne(e,X[t?1:0]),addTableListener:(e,t,s)=>ne(t,Y[s?1:0],[e]),addRowIdsListener:(e,t,s)=>ne(t,Z[s?1:0],[e]),addRowListener:(e,t,s,n)=>ne(s,$[n?1:0],[e,t]),addCellIdsListener:(e,t,s,n)=>ne(s,ee[n?1:0],[e,t]),addCellListener:(e,t,s,n,r)=>ne(n,te[r?1:0],[e,t,s]),addInvalidCellListener:(e,t,s,n,r)=>ne(n,se[r?1:0],[e,t,s]),callListener:e=>(oe(e,[ze,Me,ke],(e=>g(e[2])?[]:[,,].fill(Fe(...e)))),Be),delListener:e=>(le(e),Be),getListenerStats:()=>({})};return P(Be)},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).TinyBaseStore={});
|
|
Binary file
|
|
@@ -0,0 +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)),h=(e,t)=>e.sort(t),g=(e,t)=>e.forEach(t),p=e=>v(e,((e,t)=>e+t),0),L=e=>e.length,w=e=>0==L(e),v=(e,t,s)=>e.reduce(t,s),I=e=>e.slice(1),y=(e,t)=>e.push(t),S=e=>e.pop(),R=e=>JSON.stringify(e,((e,t)=>k(t,Map)?v([...t],((e,[t,s])=>(e[t]=s,e)),{}):t)),T=JSON.parse,b=Math.max,C=Math.min,m=isFinite,k=(e,t)=>e instanceof t,E=e=>null==e,M=(e,t,s)=>E(e)?s?.():t(e),x=e=>e==o||e==r,A=e=>s(e)==i,P=()=>{},D=e=>e.size,J=(e,t)=>e?.has(t)??!1,F=e=>E(e)||0==D(e),O=e=>[...e?.values()??[]],j=e=>e.clear(),z=(e,t)=>e?.forEach(t),N=(e,t)=>e?.delete(t),B=e=>new Map(e),_=(e=B)=>[e(),e()],q=e=>[...e?.keys()??[]],H=(e,t)=>e?.get(t),W=(e,t)=>z(e,((e,s)=>t(s,e))),G=(e,t,s)=>E(s)?(N(e,t),e):e?.set(t,s),K=(e,t,s,n)=>(J(e,t)||(n?.(s),e.set(t,s)),H(e,t)),Q=(e,t)=>{const s={},n=t??(e=>e);return z(e,((e,t)=>s[t]=n(e))),s},U=(e,t)=>{const s=B(),n=t??(e=>e);return z(e,((e,t)=>s.set(t,n(e)))),s},V=e=>new Set(e),X=(e,t)=>e?.add(t),Y=(e,t,s)=>{const n=e.hasRow,o=B(),r=B(),a=B(),i=B(),d=B(),l=t=>M(H(d,t),(s=>{z(s,e.delListener),G(d,t)})),c=e=>{G(o,e),G(r,e),G(a,e),G(i,e),l(e)};return[()=>e,()=>q(o),e=>W(r,e),e=>J(r,e),e=>H(o,e),e=>H(r,e),(e,t)=>G(r,e,t),(c,u,f,h,p)=>{const L=B(),w=B();G(o,c,u),J(r,c)||(G(r,c,t()),G(a,c,B()),G(i,c,B()));const v=H(a,c),I=H(i,c),y=t=>{const o=s=>e.getCell(u,t,s),r=H(v,t),a=n(u,t)?s(h(o,t)):void 0;if(r!=a&&G(L,t,[r,a]),!E(p)){const e=H(I,t),s=n(u,t)?p(o,t):void 0;e!=s&&G(w,t,s)}},S=e=>{f((()=>{z(L,(([,e],t)=>G(v,t,e))),z(w,((e,t)=>G(I,t,e)))}),L,w,v,I,e),j(L),j(w)};W(v,y),e.hasTable(u)&&g(e.getRowIds(u),(e=>{J(v,e)||y(e)})),S(!0),l(c),G(d,c,V([e.addRowListener(u,null,((e,t,s)=>y(s))),e.addTableListener(u,(()=>S()))]))},c,()=>W(d,c)]},Z=(e,t)=>s(e)==o?t=>t(e):e??(()=>t??n),$=e=>{const t=new WeakMap;return s=>(t.has(s)||t.set(s,e(s)),t.get(s))},ee=(e,t,s)=>L(s)<2?X(w(s)?e:K(e,s[0],V()),t):ee(K(e,s[0],B()),t,I(s)),te=e=>{const t=(s,n,...o)=>M(s,(s=>w(o)?e(s,n):g([o[0],null],(e=>t(H(s,e),n,...I(o))))));return t},se=e=>{let t,s=0;const n=[],o=B();return[(r,a,i=[])=>{t??=e();const d=S(n)??""+s++;return G(o,d,[r,a,i]),ee(a,d,i),d},(e,s=[],...n)=>te(z)(e,(e=>M(H(o,e),(([e])=>e(t,...s,...n)))),...s),e=>M(H(o,e),(([,t,s])=>(te(N)(t,e,...s),G(o,e),L(n)<1e3&&y(n,e),s)),(()=>[])),(e,s,n)=>M(H(o,e),(([e,,o])=>{const r=(...a)=>{const i=L(a);i==L(o)?e(t,...a,...n(a)):E(o[i])?g(s[i](...a),(e=>r(...a,e))):r(...a,o[i])};r()}))]},ne=Object,oe=ne.keys,re=ne.isFrozen,ae=ne.freeze,ie=(e,t)=>!E(((e,t)=>M(e,(e=>e[t])))(e,t)),de=(e,t)=>delete e[t],le=(e,t)=>g(ne.entries(e),(([e,s])=>t(s,e))),ce=$((e=>{let t,s,n,o=100,r=B(),a=1;const i=V(),d=B(),[l,c,f]=se((()=>N)),h=B(),p=B(),v=[],I=[],R=(t,s)=>{a=0,e.transaction((()=>z(H(h,s),((s,n)=>z(s,((s,o)=>z(s,((s,r)=>E(s[t])?e.delCell(n,o,r,!0):e.setCell(n,o,r,s[t]))))))))),a=1},T=e=>{G(h,e),G(p,e),c(d,[e])},b=(e,t)=>g(((e,t)=>e.splice(0,t))(e,t??L(e)),T),C=()=>b(v,L(v)-o),m=e.addCellListener(null,null,null,((e,s,o,i,d,l)=>{if(a){M(t,(()=>{y(v,t),C(),b(I),t=void 0,n=1}));const e=K(r,s,B()),a=K(e,o,B()),c=K(a,i,[void 0,void 0],(e=>e[0]=l));c[1]=d,c[0]===c[1]&&F(G(a,i))&&F(G(e,o))&&F(G(r,s))&&(t=S(v),n=1),P()}})),k=(e="")=>(E(t)&&(t=""+s++,G(h,t,r),O(t,e),r=B(),n=1),t),x=()=>{w(v)||(I.unshift(k()),R(0,t),t=S(v),n=1)},A=()=>{w(I)||(y(v,t),t=I.shift(),R(1,t),n=1)},P=()=>{n&&(c(i),n=0)},D=e=>{const t=k(e);return P(),t},O=(e,t)=>(j(e)&&H(p,e)!==t&&(G(p,e,t),c(d,[e])),N),j=e=>J(h,e),N={setSize:e=>(o=e,C(),N),addCheckpoint:D,setCheckpoint:O,getStore:()=>e,getCheckpointIds:()=>[[...v],t,[...I]],forEachCheckpoint:e=>W(p,e),hasCheckpoint:j,getCheckpoint:e=>H(p,e),goBackward:()=>(x(),P(),N),goForward:()=>(A(),P(),N),goTo:e=>{const s=u(v,e)?x:u(I,e)?A:null;for(;!E(s)&&e!=t;)s();return P(),N},addCheckpointIdsListener:e=>l(e,i),addCheckpointListener:(e,t)=>l(t,d,[e]),delListener:e=>(f(e),N),clear:()=>(b(v),b(I),E(t)||T(t),t=void 0,s=0,D(),N),destroy:()=>{e.delListener(m)},getListenerStats:()=>({})};return ae(N.clear())})),ue=(e,t)=>e<t?-1:1,fe=$((e=>{const t=B(),s=B(),[o,r,a,i,d,l,c,u,g,p]=Y(e,B,(e=>E(e)?n:e+n)),[L,w,v]=se((()=>y)),I=(t,s,n)=>{const o=d(t);z(n,((t,n)=>s(n,(s=>z(t,(t=>s(t,(s=>e.forEachCell(o,t,s)))))))))},y={setIndexDefinition:(e,n,o,r,a,i=ue)=>{const d=E(a)?void 0:([e],[t])=>a(e,t);return u(e,n,((n,o,a,u,g,p)=>{let L=0;const v=V(),I=V(),y=l(e);if(z(o,(([e,t],s)=>{E(e)||(X(v,e),M(H(y,e),(t=>{N(t,s),F(t)&&(G(y,e),L=1)}))),E(t)||(X(v,t),J(y,t)||(G(y,t,V()),L=1),X(H(y,t),s),E(r)||X(I,t))})),n(),F(g)||(p?W(y,(e=>X(I,e))):W(a,(e=>M(H(u,e),(e=>X(I,e))))),z(I,(e=>{const t=(t,s)=>i(H(g,t),H(g,s),e),s=[...H(y,e)];f(s,t)||(G(y,e,V(h(s,t))),X(v,e))}))),(L||p)&&!E(d)){const t=[...y];f(t,d)||(c(e,B(h(t,d))),L=1)}L&&w(t,[e]),z(v,(t=>w(s,[e,t])))}),Z(o),M(r,Z)),y},delIndexDefinition:e=>(g(e),y),getStore:o,getIndexIds:r,forEachIndex:e=>a(((t,s)=>e(t,(e=>I(t,e,s))))),forEachSlice:(e,t)=>I(e,t,l(e)),hasIndex:i,hasSlice:(e,t)=>J(l(e),t),getTableId:d,getSliceIds:e=>q(l(e)),getSliceRowIds:(e,t)=>O(H(l(e),t)),addSliceIdsListener:(e,s)=>L(s,t,[e]),addSliceRowIdsListener:(e,t,n)=>L(n,s,[e,t]),delListener:e=>(v(e),y),destroy:p,getListenerStats:()=>({})};return ae(y)})),he=B([["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=>b(...e),(e,t)=>b(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:b(t,e)]],["min",[e=>C(...e),(e,t)=>C(t,e),(e,t)=>t==e?void 0:e,(e,t,s)=>s==e?void 0:C(t,e)]],["sum",[e=>p(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,s)=>e-s+t]]]),ge=$((e=>{const t=B(),[s,o,r,a,i,d,l,c,u,f]=Y(e,P,(e=>isNaN(e)||E(e)||!0===e||!1===e||e===n?void 0:1*e)),[h,g,p]=se((()=>L)),L={setMetricDefinition:(e,s,n,o,r,a,i)=>{const u=A(n)?[n,r,a,i]:H(he,n)??H(he,"sum");return c(e,s,((s,n,o,r,a,i)=>{let c=d(e),f=D(r);const[h,p,L,w]=u;i=i||E(c),z(n,(([e,t])=>{i||(c=E(e)?p?.(c,t,f++):E(t)?L?.(c,e,f--):w?.(c,t,e,f)),i=i||E(c)})),s(),F(r)?c=void 0:i&&(c=h(O(r),D(r))),m(c)||(c=void 0);const v=d(e);c!=v&&(l(e,c),g(t,[e],c,v))}),Z(o,1)),L},delMetricDefinition:e=>(u(e),L),getStore:s,getMetricIds:o,forEachMetric:r,hasMetric:a,getTableId:i,getMetric:d,addMetricListener:(e,s)=>h(s,t,[e]),delListener:e=>(p(e),L),destroy:f,getListenerStats:()=>({})};return ae(L)})),pe=(e,t,s,n,o)=>{let r,a=0;const i={load:async s=>{if(2!=a){a=1;const n=await t();E(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:()=>(M(r,e.delListener),i),getStore:()=>e,destroy:()=>i.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return ae(i)},Le="storage",we=globalThis.window,ve=(e,t,s)=>{let n;return pe(e,(async()=>s.getItem(t)),(async e=>s.setItem(t,e)),(e=>{n=n=>{n.storageArea===s&&n.key===t&&e()},we.addEventListener(Le,n)}),(()=>{we.removeEventListener(Le,n),n=void 0}))},Ie=e=>e.headers.get("ETag"),ye=$((e=>{const t=B(),s=B(),o=B(),r=B(),[a,i,d,l,c,u,f,h,g,p]=Y(e,(()=>[B(),B(),B(),B()]),(e=>E(e)?void 0:e+n)),[L,w,v]=se((()=>R)),I=(e,t,s)=>M(u(e),(([n,,o])=>{if(!J(o,t)){const r=V();if(c(e)!=S(e))X(r,t);else{let e=t;for(;!E(e)&&!J(r,e);)X(r,e),e=H(n,e)}if(s)return r;G(o,t,r)}return H(o,t)})),y=(e,t)=>M(u(e),(([,,e])=>G(e,t))),S=e=>H(t,e),R={setRelationshipDefinition:(e,n,a,i)=>(G(t,e,a),h(e,n,((t,n)=>{const a=V(),i=V(),d=V(),[l,c]=u(e);z(n,(([t,s],n)=>{E(t)||(X(i,t),M(H(c,t),(e=>{N(e,n),F(e)&&G(c,t)}))),E(s)||(X(i,s),J(c,s)||G(c,s,V()),X(H(c,s),n)),X(a,n),G(l,n,s),W(H(r,e),(t=>{J(I(e,t),n)&&X(d,t)}))})),t(),z(a,(t=>w(s,[e,t]))),z(i,(t=>w(o,[e,t]))),z(d,(t=>{y(e,t),w(r,[e,t])}))}),Z(i)),R),delRelationshipDefinition:e=>(G(t,e),g(e),R),getStore:a,getRelationshipIds:i,forEachRelationship:t=>d((s=>t(s,(t=>e.forEachRow(c(s),t))))),hasRelationship:l,getLocalTableId:c,getRemoteTableId:S,getRemoteRowId:(e,t)=>H(u(e)?.[0],t),getLocalRowIds:(e,t)=>O(H(u(e)?.[1],t)),getLinkedRowIds:(e,t)=>E(u(e))?[t]:O(I(e,t,!0)),addRemoteRowIdListener:(e,t,n)=>L(n,s,[e,t]),addLocalRowIdsListener:(e,t,s)=>L(s,o,[e,t]),addLinkedRowIdsListener:(e,t,s)=>(I(e,t),L(s,r,[e,t])),delListener:e=>(y(...v(e)),R),destroy:p,getListenerStats:()=>({})};return ae(R)})),Se=(e,t,s,n=G)=>{const o=(r=q(e),a=e=>!ie(t,e),r.filter(a));var r,a;return g(oe(t),(n=>s(e,n,t[n]))),g(o,(t=>n(e,t))),e},Re=e=>{const t=s(e);return x(t)||t==a&&m(e)?t:void 0},Te=(e,t)=>!(E(e)||!(e=>k(e,ne)&&e.constructor==ne)(e)||re(e)||(le(e,((s,n)=>{t(s,n)||de(e,n)})),(e=>w(oe(e)))(e))),be=(e,t,s)=>G(e,t,H(e,t)==-s?void 0:s);e.createCheckpoints=ce,e.createCustomPersister=pe,e.createFilePersister=(e,s)=>{let n;return pe(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=fe,e.createLocalPersister=(e,t)=>ve(e,t,localStorage),e.createMetrics=ge,e.createRelationships=ye,e.createRemotePersister=(e,t,s,n)=>{let o,r;return pe(e,(async()=>{const e=await fetch(t);return r=Ie(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=Ie(s);E(r)||E(n)||n==r||(r=n,e())}),1e3*n)}),(()=>{M(o,clearInterval),o=void 0}))},e.createSessionPersister=(e,t)=>ve(e,t,sessionStorage),e.createStore=()=>{let e,t=0,s=0;const n=B(),o=B(),r=B(),i=B(),c=B(),f=B(),h=B(),p=B(),L=_(V),w=_(V),v=_(),I=_(),S=_(),b=_(),C=_(),m=_(),[k,P,D,O]=se((()=>Oe)),N=(t,s)=>(!e||J(f,s))&&Te(t,((e,t)=>X(s,t,e))),X=(e,t,s,n)=>Te(n?s:Z(s,e),((n,o)=>M(Y(e,t,o,n),(e=>(s[o]=e,!0)),(()=>!1)))),Y=(t,s,n,o)=>e?M(H(H(f,t),n),(e=>Re(o)!=e.type?ye(t,s,n,o,e.default):o)):E(Re(o))?ye(t,s,n,o):o,Z=(e,t)=>(M(H(h,t),(t=>le(t,((t,s)=>{ie(e,s)||(e[s]=t)})))),e),$=e=>Se(f,e,((e,t,s)=>{const n={};Se(K(f,t,B()),s,((e,t,s)=>{G(e,t,s),M(s.default,(e=>n[t]=e))})),G(h,t,n)}),((e,t)=>{G(f,t),G(h,t)})),ee=e=>Se(p,e,((e,t,s)=>te(t,s)),((e,t)=>he(t))),te=(e,t)=>Se(K(p,e,B(),(()=>Le(e,1))),t,((t,s,n)=>ne(e,t,s,n)),((t,s)=>ge(e,t,s))),ne=(e,t,s,n,o)=>Se(K(t,s,B(),(()=>we(e,s,1))),n,((t,n,o)=>oe(e,s,t,n,o)),((n,r)=>pe(e,t,s,n,r,o))),oe=(e,t,s,n,o)=>{J(s,n)||ve(e,t,n,1);const r=H(s,n);o!==r&&(Ie(e,t,n,r),G(s,n,o))},re=(e,t,s)=>Fe((()=>ne(e,fe(e),t,s))),ce=(e,t,s,n,o)=>M(H(t,s),(t=>oe(e,s,t,n,o)),(()=>ne(e,t,s,Z({[n]:o},e)))),ue=e=>{const s=""+t++;return J(e,s)?ue(e):s},fe=e=>H(p,e)??te(e,{}),he=e=>te(e,{}),ge=(e,t,s)=>ne(e,t,s,{},!0),pe=(e,t,s,n,o,r)=>{const a=H(h,e)?.[o];if(!E(a)&&!r)return oe(e,s,n,o,a);const i=t=>{Ie(e,s,t,H(n,t)),ve(e,s,t,-1),G(n,t)};E(a)?i(o):W(n,i),F(n)&&(we(e,s,-1),F(G(t,s))&&(Le(e,-1),G(p,e)))},Le=(e,t)=>be(n,e,t),we=(e,t,s)=>be(K(o,e,B()),t,s),ve=(e,t,s,n)=>be(K(K(r,e,B()),t,B()),s,n),Ie=(e,t,s,n)=>K(K(K(i,e,B()),t,B()),s,n),ye=(e,t,s,n,o)=>(y(K(K(K(c,e,B()),t,B()),s,[]),n),o),Ce=(e,t,s)=>{const n=H(H(i,e),t),o=Pe(e,t,s);return J(n,s)?[!0,H(n,s),o]:[!1,o,o]},me=e=>{F(m[e])||z(e?U(c,(e=>U(e,U))):c,((t,s)=>z(t,((t,n)=>z(t,((t,o)=>P(m[e],[s,n,o],t)))))))},ke=e=>{const t=F(b[e])&&F(I[e])&&F(w[e]),s=F(C[e])&&F(S[e])&&F(v[e])&&F(L[e]);if(t&&s)return;const a=e?[U(n),U(o,U),U(r,(e=>U(e,U))),U(i,(e=>U(e,U)))]:[n,o,r,i];if(t||(z(a[2],((t,s)=>z(t,((t,n)=>{F(t)||P(b[e],[s,n])})))),z(a[1],((t,s)=>{F(t)||P(I[e],[s])})),F(a[0])||P(w[e])),!s){let t;z(a[3],((s,n)=>{let o;z(s,((s,r)=>{let a;z(s,((s,i)=>{const d=Pe(n,r,i);d!==s&&(P(C[e],[n,r,i],d,s,Ce),t=o=a=1)})),a&&P(S[e],[n,r],Ce)})),o&&P(v[e],[n],Ce)})),t&&P(L[e],[],Ce)}},Ee=()=>Q(p,(e=>Q(e,Q))),Me=()=>q(p),xe=e=>q(H(p,e)),Ae=(e,t)=>q(H(H(p,e),t)),Pe=(e,t,s)=>H(H(H(p,e),t),s),De=e=>((e=>Te(e,N))(e)?Fe((()=>ee(e))):Fe(),Oe),Je=()=>(Fe((()=>ee({}))),Oe),Fe=e=>{if(-1==s)return;s++;const t=e?.();return s--,0==s&&(s=1,me(1),ke(1),s=-1,me(0),ke(0),s=0,g([i,c,n,o,r],j)),t},Oe={getTables:Ee,getTableIds:Me,getTable:e=>Q(H(p,e),Q),getRowIds:xe,getRow:(e,t)=>Q(H(H(p,e),t)),getCellIds:Ae,getCell:Pe,hasTables:()=>!F(p),hasTable:e=>J(p,e),hasRow:(e,t)=>J(H(p,e),t),hasCell:(e,t,s)=>J(H(H(p,e),t),s),getJson:()=>R(p),getSchemaJson:()=>R(f),setTables:De,setTable:(e,t)=>(N(t,e)?Fe((()=>te(e,t))):Fe(),Oe),setRow:(e,t,s)=>(X(e,t,s)?re(e,t,s):Fe(),Oe),addRow:(e,t)=>{let s;return X(e,s,t)?re(e,s=ue(H(p,e)),t):Fe(),s},setPartialRow:(e,t,s)=>(X(e,t,s,1)?Fe((()=>{const n=fe(e);le(s,((s,o)=>ce(e,n,t,o,s)))})):Fe(),Oe),setCell:(e,t,s,n)=>(M(Y(e,t,s,A(n)?n(Pe(e,t,s)):n),(n=>Fe((()=>ce(e,fe(e),t,s,n)))),Fe),Oe),setJson:e=>{try{"{}"===e?Je():De(T(e))}catch{}return Oe},setSchema:t=>{if((e=(e=>Te(e,(e=>Te(e,(e=>{if(!Te(e,((e,t)=>u([d,l],t))))return!1;const t=e.type;return!(!x(t)&&t!=a||(Re(e.default)!=t&&de(e,l),0))})))))(t))&&($(t),!F(p))){const e=Ee();Je(),De(e)}return Oe},delTables:Je,delTable:e=>(J(p,e)&&Fe((()=>he(e))),Oe),delRow:(e,t)=>(M(H(p,e),(s=>{J(s,t)&&Fe((()=>ge(e,s,t)))})),Oe),delCell:(e,t,s,n)=>(M(H(p,e),(o=>M(H(o,t),(r=>{J(r,s)&&Fe((()=>pe(e,o,t,r,s,n)))})))),Oe),delSchema:()=>($({}),e=!1,Oe),transaction:Fe,forEachTable:e=>z(p,((t,s)=>e(s,(e=>z(t,((t,s)=>e(s,(e=>W(t,e))))))))),forEachRow:(e,t)=>z(H(p,e),((e,s)=>t(s,(t=>W(e,t))))),forEachCell:(e,t,s)=>W(H(H(p,e),t),s),addTablesListener:(e,t)=>k(e,L[t?1:0]),addTableIdsListener:(e,t)=>k(e,w[t?1:0]),addTableListener:(e,t,s)=>k(t,v[s?1:0],[e]),addRowIdsListener:(e,t,s)=>k(t,I[s?1:0],[e]),addRowListener:(e,t,s,n)=>k(s,S[n?1:0],[e,t]),addCellIdsListener:(e,t,s,n)=>k(s,b[n?1:0],[e,t]),addCellListener:(e,t,s,n,o)=>k(n,C[o?1:0],[e,t,s]),addInvalidCellListener:(e,t,s,n,o)=>k(n,m[o?1:0],[e,t,s]),callListener:e=>(O(e,[Me,xe,Ae],(e=>E(e[2])?[]:[,,].fill(Pe(...e)))),Oe),delListener:e=>(D(e),Oe),getListenerStats:()=>({})};return ae(Oe)},e.defaultSorter=ue,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);
|
|
Binary file
|
|
@@ -0,0 +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=[])=>{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);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-beta.0",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@babel/cli": "^7.16.8",
|
|
59
|
-
"@babel/core": "^7.16.
|
|
60
|
-
"@babel/preset-env": "^7.16.
|
|
59
|
+
"@babel/core": "^7.16.12",
|
|
60
|
+
"@babel/preset-env": "^7.16.11",
|
|
61
61
|
"@babel/preset-react": "^7.16.7",
|
|
62
62
|
"@babel/preset-typescript": "^7.16.7",
|
|
63
63
|
"@rollup/plugin-replace": "^3.0.1",
|
|
@@ -65,26 +65,26 @@
|
|
|
65
65
|
"@types/expect-puppeteer": "^4.4.7",
|
|
66
66
|
"@types/http-server": "^0.12.1",
|
|
67
67
|
"@types/jest": "^27.4.0",
|
|
68
|
-
"@types/jest-environment-puppeteer": "^
|
|
68
|
+
"@types/jest-environment-puppeteer": "^5.0.0",
|
|
69
69
|
"@types/less": "^3.0.3",
|
|
70
70
|
"@types/puppeteer": "^5.4.4",
|
|
71
71
|
"@types/react": "^17.0.38",
|
|
72
72
|
"@types/react-dom": "^17.0.11",
|
|
73
73
|
"@types/react-test-renderer": "^17.0.1",
|
|
74
74
|
"@types/tmp": "^0.2.3",
|
|
75
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
76
|
-
"@typescript-eslint/parser": "^5.
|
|
75
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
76
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
77
77
|
"asciichart": "^1.5.25",
|
|
78
78
|
"babel-eslint": "^10.1.0",
|
|
79
79
|
"babel-jest": "^27.4.6",
|
|
80
80
|
"babel-preset-minify": "^0.5.1",
|
|
81
81
|
"country-flag-emoji-json": "^2.0.0",
|
|
82
|
-
"cspell": "^5.
|
|
83
|
-
"esbuild": "^0.14.
|
|
84
|
-
"eslint": "^8.
|
|
82
|
+
"cspell": "^5.17.0",
|
|
83
|
+
"esbuild": "^0.14.14",
|
|
84
|
+
"eslint": "^8.8.0",
|
|
85
85
|
"eslint-config-prettier": "^8.3.0",
|
|
86
|
-
"eslint-plugin-jest": "^
|
|
87
|
-
"eslint-plugin-jsdoc": "^37.
|
|
86
|
+
"eslint-plugin-jest": "^26.0.0",
|
|
87
|
+
"eslint-plugin-jsdoc": "^37.7.0",
|
|
88
88
|
"eslint-plugin-react": "^7.28.0",
|
|
89
89
|
"eslint-plugin-react-hooks": "^4.3.0",
|
|
90
90
|
"gulp": "^4.0.2",
|
|
@@ -95,11 +95,11 @@
|
|
|
95
95
|
"jest-puppeteer": "^6.0.3",
|
|
96
96
|
"less": "^4.1.2",
|
|
97
97
|
"prettier": "^2.5.1",
|
|
98
|
-
"puppeteer": "^13.
|
|
98
|
+
"puppeteer": "^13.1.2",
|
|
99
99
|
"react": "^17.0.2",
|
|
100
100
|
"react-dom": "^17.0.2",
|
|
101
101
|
"react-test-renderer": "^17.0.2",
|
|
102
|
-
"rollup": "^2.
|
|
102
|
+
"rollup": "^2.66.1",
|
|
103
103
|
"rollup-plugin-esbuild": "^4.8.2",
|
|
104
104
|
"rollup-plugin-gzip": "^3.0.0",
|
|
105
105
|
"rollup-plugin-prettier": "^2.2.2",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"tinydocs": "^0.1.10",
|
|
108
108
|
"tmp": "^0.2.1",
|
|
109
109
|
"ts-unused-exports": "^7.0.3",
|
|
110
|
-
"typescript": "4.5.
|
|
110
|
+
"typescript": "4.5.5"
|
|
111
111
|
},
|
|
112
112
|
"peerDependencies": {
|
|
113
113
|
"react": "^17.0.2"
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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.
|
|
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.7kB - 5.8kB</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()
|
|
@@ -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.
|
|
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.7kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>5.8kB</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.7kB</td><td>6.2kB</td><td>25.6kB</td><td>93.7kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/indexes">indexes</a></th><td>1.6kB</td><td>3.2kB</td><td>14.1kB</td><td>32.9kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics">metrics</a></th><td>1.5kB</td><td>3.1kB</td><td>12.6kB</td><td>29.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/relationships">relationships</a></th><td>1.6kB</td><td>3.2kB</td><td>14.8kB</td><td>42.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/checkpoints">checkpoints</a></th><td>1.3kB</td><td>2.5kB</td><td>10.4kB</td><td>33.0kB</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.8kB</td><td>13.7kB</td><td>57.3kB</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>971</td><td>971</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,061</td><td>1,061</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>393</td><td>393</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>347</td><td>347</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">1,738</td></tr><tr><th class="right">Assertions</th><td colspan="3">8,379</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.1.0-beta.0">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>
|