tinybase 5.1.3 → 5.1.4
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/cjs/es6/min/persisters/persister-automerge/index.cjs +1 -1
- package/cjs/es6/min/persisters/persister-automerge/index.cjs.gz +0 -0
- package/cjs/es6/min/persisters/persister-automerge/with-schemas/index.cjs +1 -1
- package/cjs/es6/min/persisters/persister-automerge/with-schemas/index.cjs.gz +0 -0
- package/cjs/es6/persisters/persister-automerge/index.cjs +2 -1
- package/cjs/es6/persisters/persister-automerge/with-schemas/index.cjs +2 -1
- package/cjs/min/persisters/persister-automerge/index.cjs +1 -1
- package/cjs/min/persisters/persister-automerge/index.cjs.gz +0 -0
- package/cjs/min/persisters/persister-automerge/with-schemas/index.cjs +1 -1
- package/cjs/min/persisters/persister-automerge/with-schemas/index.cjs.gz +0 -0
- package/cjs/persisters/persister-automerge/index.cjs +2 -1
- package/cjs/persisters/persister-automerge/with-schemas/index.cjs +2 -1
- package/es6/min/persisters/persister-automerge/index.js +1 -1
- package/es6/min/persisters/persister-automerge/index.js.gz +0 -0
- package/es6/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/es6/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/es6/persisters/persister-automerge/index.js +2 -1
- package/es6/persisters/persister-automerge/with-schemas/index.js +2 -1
- package/min/persisters/persister-automerge/index.js +1 -1
- package/min/persisters/persister-automerge/index.js.gz +0 -0
- package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/package.json +2 -2
- package/persisters/persister-automerge/index.js +2 -1
- package/persisters/persister-automerge/with-schemas/index.js +2 -1
- package/readme.md +2 -2
- package/umd/es6/min/persisters/persister-automerge/index.js +1 -1
- package/umd/es6/min/persisters/persister-automerge/index.js.gz +0 -0
- package/umd/es6/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/umd/es6/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/umd/es6/persisters/persister-automerge/index.js +2 -1
- package/umd/es6/persisters/persister-automerge/with-schemas/index.js +2 -1
- package/umd/min/persisters/persister-automerge/index.js +1 -1
- package/umd/min/persisters/persister-automerge/index.js.gz +0 -0
- package/umd/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/umd/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/umd/persisters/persister-automerge/index.js +2 -1
- package/umd/persisters/persister-automerge/with-schemas/index.js +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e,n)=>t(e,(e=>e[n])),
|
|
1
|
+
"use strict";const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e=[])=>r.fromEntries(e),c=(e,n)=>t(e,(e=>e[n])),d=(e,t)=>t in e,v=(e,t)=>(delete e[t],e),y=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,n])=>t(n,e))),p=e=>a(e).length,h=n=>(n=>!e(n)&&t(l(n),(t=>t==r.prototype||e(l(t))),(()=>!0)))(n)&&0==p(n),g=(e,t,n)=>(d(e,t)||(e[t]=n()),e[t]),f=e=>new Map(e),b=(e,t)=>null==e?void 0:e.get(t),m=(t,n,o)=>{return e(o)?(l=n,null==(r=t)||r.delete(l),t):null==t?void 0:t.set(n,o);var r,l},C=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||m(e,t,n()),b(e,t)};var A=Object.defineProperty,P=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,S=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,L=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const M=f(),j=f();var x=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(t,n,o,r)=>{const l=e(n)?t:g(t,n,(()=>({})));let i;return y(o,((e,t)=>{r(l,t,e)&&(i=1)})),y(l,((e,t)=>{d(o,t)||(v(l,t),i=1)})),!e(n)&&h(l)&&v(t,n),i};exports.createAutomergePersister=(r,l,i="tinybase",a)=>(l.change((e=>g(e,i,s))),((r,l,i,a,s,c,d,v={},y=[])=>{let p,g,f,A=0,x=0,D=0;C(M,y,(()=>0)),C(j,y,(()=>[]));const[E,T,k,z,F]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:o("Store type not supported by this Persister"))(d,r),H=e=>{(E&&n(null==e?void 0:e[0])?1===(null==e?void 0:e[2])?r.applyMergeableChanges:r.setMergeableContent:1===(null==e?void 0:e[2])?r.applyChanges:r.setContent)(e)},I=e=>L(void 0,null,(function*(){return 2!=A&&(A=1,x++,yield J((()=>L(void 0,null,(function*(){try{const e=yield l();n(e)?H(e):o("Content is not an array "+e)}catch(t){null==c||c(t),e&&F(e)}A=0}))))),K})),q=()=>(g&&(s(g),g=void 0),K),B=e=>L(void 0,null,(function*(){return 1!=A&&(A=2,D++,yield J((()=>L(void 0,null,(function*(){try{yield i(T,e)}catch(e){null==c||c(e)}A=0}))))),K})),G=()=>(t(f,r.delListener),f=void 0,K),J=(...t)=>L(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(b(j,y),...t),yield L(void 0,null,(function*(){if(!b(M,y)){for(m(M,y,1);!e((t=b(j,y),p=t.shift()));)try{yield p()}catch(e){null==c||c(e)}m(M,y,0)}var t})),K})),K=((e,t)=>{for(var n in t||(t={}))w.call(t,n)&&S(e,n,t[n]);if(P)for(var n of P(t))O.call(t,n)&&S(e,n,t[n]);return e})({load:I,startAutoLoad:e=>L(void 0,null,(function*(){yield q().load(e);try{g=a(((e,t)=>L(void 0,null,(function*(){t||e?2!=A&&(A=1,x++,H(null!=t?t:e),A=0):yield I()}))))}catch(e){null==c||c(e)}return K})),stopAutoLoad:q,isAutoLoading:()=>!e(g),save:B,startAutoSave:()=>L(void 0,null,(function*(){return yield G().save(),f=r.addDidFinishTransactionListener((()=>{const e=k();z(e)&&B(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!e(f),schedule:J,getStore:()=>r,destroy:()=>(b(j,y).splice(0,void 0),q().stopAutoSave()),getStats:()=>({loads:x,saves:D})},v);return u(K)})(r,(()=>x(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((n,o)=>x(void 0,null,(function*(){return l.change((r=>((n,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(n,o);const[i,a]=D(n,o),u=()=>{s=1};let s=1;if(t(l,(([n,o])=>{s=0,y(n,((n,o)=>s?0:e(n)?v(i,o):t(i[o],(o=>y(n,((n,r)=>s?0:e(n)?v(o,r):t(c(o,r),(t=>y(n,((n,o)=>e(n)?v(t,o):t[o]=n))),u)))),u))),y(o,((t,n)=>s?0:e(t)?v(a,n):a[n]=t))})),s){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,n,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}));
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e,n)=>t(e,(e=>e[n])),
|
|
1
|
+
"use strict";const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e=[])=>r.fromEntries(e),c=(e,n)=>t(e,(e=>e[n])),d=(e,t)=>t in e,v=(e,t)=>(delete e[t],e),y=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,n])=>t(n,e))),p=e=>a(e).length,h=n=>(n=>!e(n)&&t(l(n),(t=>t==r.prototype||e(l(t))),(()=>!0)))(n)&&0==p(n),g=(e,t,n)=>(d(e,t)||(e[t]=n()),e[t]),f=e=>new Map(e),b=(e,t)=>null==e?void 0:e.get(t),m=(t,n,o)=>{return e(o)?(l=n,null==(r=t)||r.delete(l),t):null==t?void 0:t.set(n,o);var r,l},C=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||m(e,t,n()),b(e,t)};var A=Object.defineProperty,P=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,S=(e,t,n)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,L=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const M=f(),j=f();var x=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(t,n,o,r)=>{const l=e(n)?t:g(t,n,(()=>({})));let i;return y(o,((e,t)=>{r(l,t,e)&&(i=1)})),y(l,((e,t)=>{d(o,t)||(v(l,t),i=1)})),!e(n)&&h(l)&&v(t,n),i};exports.createAutomergePersister=(r,l,i="tinybase",a)=>(l.change((e=>g(e,i,s))),((r,l,i,a,s,c,d,v={},y=[])=>{let p,g,f,A=0,x=0,D=0;C(M,y,(()=>0)),C(j,y,(()=>[]));const[E,T,k,z,F]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:o("Store type not supported by this Persister"))(d,r),H=e=>{(E&&n(null==e?void 0:e[0])?1===(null==e?void 0:e[2])?r.applyMergeableChanges:r.setMergeableContent:1===(null==e?void 0:e[2])?r.applyChanges:r.setContent)(e)},I=e=>L(void 0,null,(function*(){return 2!=A&&(A=1,x++,yield J((()=>L(void 0,null,(function*(){try{const e=yield l();n(e)?H(e):o("Content is not an array "+e)}catch(t){null==c||c(t),e&&F(e)}A=0}))))),K})),q=()=>(g&&(s(g),g=void 0),K),B=e=>L(void 0,null,(function*(){return 1!=A&&(A=2,D++,yield J((()=>L(void 0,null,(function*(){try{yield i(T,e)}catch(e){null==c||c(e)}A=0}))))),K})),G=()=>(t(f,r.delListener),f=void 0,K),J=(...t)=>L(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(b(j,y),...t),yield L(void 0,null,(function*(){if(!b(M,y)){for(m(M,y,1);!e((t=b(j,y),p=t.shift()));)try{yield p()}catch(e){null==c||c(e)}m(M,y,0)}var t})),K})),K=((e,t)=>{for(var n in t||(t={}))w.call(t,n)&&S(e,n,t[n]);if(P)for(var n of P(t))O.call(t,n)&&S(e,n,t[n]);return e})({load:I,startAutoLoad:e=>L(void 0,null,(function*(){yield q().load(e);try{g=a(((e,t)=>L(void 0,null,(function*(){t||e?2!=A&&(A=1,x++,H(null!=t?t:e),A=0):yield I()}))))}catch(e){null==c||c(e)}return K})),stopAutoLoad:q,isAutoLoading:()=>!e(g),save:B,startAutoSave:()=>L(void 0,null,(function*(){return yield G().save(),f=r.addDidFinishTransactionListener((()=>{const e=k();z(e)&&B(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!e(f),schedule:J,getStore:()=>r,destroy:()=>(b(j,y).splice(0,void 0),q().stopAutoSave()),getStats:()=>({loads:x,saves:D})},v);return u(K)})(r,(()=>x(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((n,o)=>x(void 0,null,(function*(){return l.change((r=>((n,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(n,o);const[i,a]=D(n,o),u=()=>{s=1};let s=1;if(t(l,(([n,o])=>{s=0,y(n,((n,o)=>s?0:e(n)?v(i,o):t(i[o],(o=>y(n,((n,r)=>s?0:e(n)?v(o,r):t(c(o,r),(t=>y(n,((n,o)=>e(n)?v(t,o):t[o]=n))),u)))),u))),y(o,((t,n)=>s?0:e(t)?v(a,n):a[n]=t))})),s){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,n,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}));
|
|
Binary file
|
|
@@ -32,6 +32,7 @@ const isObject = (obj) =>
|
|
|
32
32
|
);
|
|
33
33
|
const objIds = object.keys;
|
|
34
34
|
const objFreeze = object.freeze;
|
|
35
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
35
36
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
36
37
|
const objHas = (obj, id) => id in obj;
|
|
37
38
|
const objDel = (obj, id) => {
|
|
@@ -445,7 +446,7 @@ const createAutomergePersister = (
|
|
|
445
446
|
docObjName = TINYBASE,
|
|
446
447
|
onIgnoredError,
|
|
447
448
|
) => {
|
|
448
|
-
docHandle.change((doc) => (doc
|
|
449
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
449
450
|
const getPersisted = () =>
|
|
450
451
|
__async(void 0, null, function* () {
|
|
451
452
|
const doc = yield docHandle.doc();
|
|
@@ -32,6 +32,7 @@ const isObject = (obj) =>
|
|
|
32
32
|
);
|
|
33
33
|
const objIds = object.keys;
|
|
34
34
|
const objFreeze = object.freeze;
|
|
35
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
35
36
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
36
37
|
const objHas = (obj, id) => id in obj;
|
|
37
38
|
const objDel = (obj, id) => {
|
|
@@ -445,7 +446,7 @@ const createAutomergePersister = (
|
|
|
445
446
|
docObjName = TINYBASE,
|
|
446
447
|
onIgnoredError,
|
|
447
448
|
) => {
|
|
448
|
-
docHandle.change((doc) => (doc
|
|
449
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
449
450
|
const getPersisted = () =>
|
|
450
451
|
__async(void 0, null, function* () {
|
|
451
452
|
const doc = yield docHandle.doc();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,r=t=>s.getPrototypeOf(t),o=s.entries,i=s.keys,c=s.freeze,y=(t,a)=>e(t,(t=>t[a])),
|
|
1
|
+
"use strict";const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,r=t=>s.getPrototypeOf(t),o=s.entries,i=s.keys,c=s.freeze,y=(t=[])=>s.fromEntries(t),g=(t,a)=>e(t,(t=>t[a])),d=(t,e)=>e in t,l=(t,e)=>(delete t[e],t),u=(t,e)=>((t,e)=>t.map(e))(o(t),(([t,a])=>e(a,t))),h=t=>i(t).length,v=a=>(a=>!t(a)&&e(r(a),(e=>e==s.prototype||t(r(e))),(()=>!0)))(a)&&0==h(a),p=(t,e,a)=>(d(t,e)||(t[e]=a()),t[e]),w=t=>new Map(t),C=(t,e)=>t?.get(e),A=(e,a,n)=>{return t(n)?(s=e,r=a,s?.delete(r),e):e?.set(a,n);var s,r},f=(t,e,a,n)=>{var s,r;return s=t,r=e,s?.has(r)||A(t,e,a()),C(t,e)},b=w(),S=w(),L=(t,e)=>[t[e].t,t[e].v],M=(e,a,n,s)=>{const r=t(a)?e:p(e,a,(()=>({})));let o;return u(n,((t,e)=>{s(r,e,t)&&(o=1)})),u(r,((t,e)=>{d(n,e)||(l(r,e),o=1)})),!t(a)&&v(r)&&l(e,a),o};exports.createAutomergePersister=(s,r,o="tinybase",i)=>(r.change((t=>p(t,o,y))),((s,r,o,i,y,g,d,l={},u=[])=>{let h,p,w,L=0,M=0,m=0;f(b,u,(()=>0)),f(S,u,(()=>[]));const[D,P,T,E,O]=((t=1,e)=>1!=t&&e.isMergeable()?[1,e.getMergeableContent,e.getTransactionMergeableChanges,([[t],[e]])=>!v(t)||!v(e),e.setDefaultContent]:2!=t?[0,e.getContent,e.getTransactionChanges,([t,e])=>!v(t)||!v(e),e.setContent]:n("Store type not supported by this Persister"))(d,s),j=t=>{(D&&a(t?.[0])?1===t?.[2]?s.applyMergeableChanges:s.setMergeableContent:1===t?.[2]?s.applyChanges:s.setContent)(t)},k=async t=>(2!=L&&(L=1,M++,await H((async()=>{try{const t=await r();a(t)?j(t):n("Content is not an array "+t)}catch(e){g?.(e),t&&O(t)}L=0}))),q),x=()=>(p&&(y(p),p=void 0),q),z=async t=>(1!=L&&(L=2,m++,await H((async()=>{try{await o(P,t)}catch(t){g?.(t)}L=0}))),q),F=()=>(e(w,s.delListener),w=void 0,q),H=async(...e)=>(((t,...e)=>{t.push(...e)})(C(S,u),...e),await(async()=>{if(!C(b,u)){for(A(b,u,1);!t((e=C(S,u),h=e.shift()));)try{await h()}catch(t){g?.(t)}A(b,u,0)}var e})(),q),q={load:k,startAutoLoad:async t=>{await x().load(t);try{p=i((async(t,e)=>{e||t?2!=L&&(L=1,M++,j(e??t),L=0):await k()}))}catch(t){g?.(t)}return q},stopAutoLoad:x,isAutoLoading:()=>!t(p),save:z,startAutoSave:async()=>(await F().save(),w=s.addDidFinishTransactionListener((()=>{const t=T();E(t)&&z(t)})),q),stopAutoSave:F,isAutoSaving:()=>!t(w),schedule:H,getStore:()=>s,destroy:()=>(C(S,u).splice(0,void 0),x().stopAutoSave()),getStats:()=>({loads:M,saves:m}),...l};return c(q)})(s,(async()=>{const t=await r.doc();return 2==h(t?.[o])?L(t,o):void 0}),(async(a,n)=>r.change((s=>((a,n,s,r)=>{((t,e)=>{v(t[e])&&(t[e]={t:{},v:{}})})(a,n);const[o,i]=L(a,n),c=()=>{y=1};let y=1;if(e(r,(([a,n])=>{y=0,u(a,((a,n)=>y?0:t(a)?l(o,n):e(o[n],(n=>u(a,((a,s)=>y?0:t(a)?l(n,s):e(g(n,s),(e=>u(a,((a,n)=>t(a)?l(e,n):e[n]=a))),c)))),c))),u(n,((e,a)=>y?0:t(e)?l(i,a):i[a]=e))})),y){const[t,e]=s();M(o,void 0,t,((t,e,a)=>M(o,e,a,((t,e,a)=>M(t,e,a,((t,e,a)=>{if(g(t,e)!==a)return t[e]=a,1})))))),M(i,void 0,e,((t,e,a)=>{g(i,e)!==a&&(i[e]=a)}))}})(s,o,a,n)))),(t=>{const e=({doc:e})=>t(L(e,o));return r.on("change",e),e}),(t=>{r.removeListener("change",t)}),i,1,{getDocHandle:()=>r}));
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,r=t=>s.getPrototypeOf(t),o=s.entries,i=s.keys,c=s.freeze,y=(t,a)=>e(t,(t=>t[a])),
|
|
1
|
+
"use strict";const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,r=t=>s.getPrototypeOf(t),o=s.entries,i=s.keys,c=s.freeze,y=(t=[])=>s.fromEntries(t),g=(t,a)=>e(t,(t=>t[a])),d=(t,e)=>e in t,l=(t,e)=>(delete t[e],t),u=(t,e)=>((t,e)=>t.map(e))(o(t),(([t,a])=>e(a,t))),h=t=>i(t).length,v=a=>(a=>!t(a)&&e(r(a),(e=>e==s.prototype||t(r(e))),(()=>!0)))(a)&&0==h(a),p=(t,e,a)=>(d(t,e)||(t[e]=a()),t[e]),w=t=>new Map(t),C=(t,e)=>t?.get(e),A=(e,a,n)=>{return t(n)?(s=e,r=a,s?.delete(r),e):e?.set(a,n);var s,r},f=(t,e,a,n)=>{var s,r;return s=t,r=e,s?.has(r)||A(t,e,a()),C(t,e)},b=w(),S=w(),L=(t,e)=>[t[e].t,t[e].v],M=(e,a,n,s)=>{const r=t(a)?e:p(e,a,(()=>({})));let o;return u(n,((t,e)=>{s(r,e,t)&&(o=1)})),u(r,((t,e)=>{d(n,e)||(l(r,e),o=1)})),!t(a)&&v(r)&&l(e,a),o};exports.createAutomergePersister=(s,r,o="tinybase",i)=>(r.change((t=>p(t,o,y))),((s,r,o,i,y,g,d,l={},u=[])=>{let h,p,w,L=0,M=0,m=0;f(b,u,(()=>0)),f(S,u,(()=>[]));const[D,P,T,E,O]=((t=1,e)=>1!=t&&e.isMergeable()?[1,e.getMergeableContent,e.getTransactionMergeableChanges,([[t],[e]])=>!v(t)||!v(e),e.setDefaultContent]:2!=t?[0,e.getContent,e.getTransactionChanges,([t,e])=>!v(t)||!v(e),e.setContent]:n("Store type not supported by this Persister"))(d,s),j=t=>{(D&&a(t?.[0])?1===t?.[2]?s.applyMergeableChanges:s.setMergeableContent:1===t?.[2]?s.applyChanges:s.setContent)(t)},k=async t=>(2!=L&&(L=1,M++,await H((async()=>{try{const t=await r();a(t)?j(t):n("Content is not an array "+t)}catch(e){g?.(e),t&&O(t)}L=0}))),q),x=()=>(p&&(y(p),p=void 0),q),z=async t=>(1!=L&&(L=2,m++,await H((async()=>{try{await o(P,t)}catch(t){g?.(t)}L=0}))),q),F=()=>(e(w,s.delListener),w=void 0,q),H=async(...e)=>(((t,...e)=>{t.push(...e)})(C(S,u),...e),await(async()=>{if(!C(b,u)){for(A(b,u,1);!t((e=C(S,u),h=e.shift()));)try{await h()}catch(t){g?.(t)}A(b,u,0)}var e})(),q),q={load:k,startAutoLoad:async t=>{await x().load(t);try{p=i((async(t,e)=>{e||t?2!=L&&(L=1,M++,j(e??t),L=0):await k()}))}catch(t){g?.(t)}return q},stopAutoLoad:x,isAutoLoading:()=>!t(p),save:z,startAutoSave:async()=>(await F().save(),w=s.addDidFinishTransactionListener((()=>{const t=T();E(t)&&z(t)})),q),stopAutoSave:F,isAutoSaving:()=>!t(w),schedule:H,getStore:()=>s,destroy:()=>(C(S,u).splice(0,void 0),x().stopAutoSave()),getStats:()=>({loads:M,saves:m}),...l};return c(q)})(s,(async()=>{const t=await r.doc();return 2==h(t?.[o])?L(t,o):void 0}),(async(a,n)=>r.change((s=>((a,n,s,r)=>{((t,e)=>{v(t[e])&&(t[e]={t:{},v:{}})})(a,n);const[o,i]=L(a,n),c=()=>{y=1};let y=1;if(e(r,(([a,n])=>{y=0,u(a,((a,n)=>y?0:t(a)?l(o,n):e(o[n],(n=>u(a,((a,s)=>y?0:t(a)?l(n,s):e(g(n,s),(e=>u(a,((a,n)=>t(a)?l(e,n):e[n]=a))),c)))),c))),u(n,((e,a)=>y?0:t(e)?l(i,a):i[a]=e))})),y){const[t,e]=s();M(o,void 0,t,((t,e,a)=>M(o,e,a,((t,e,a)=>M(t,e,a,((t,e,a)=>{if(g(t,e)!==a)return t[e]=a,1})))))),M(i,void 0,e,((t,e,a)=>{g(i,e)!==a&&(i[e]=a)}))}})(s,o,a,n)))),(t=>{const e=({doc:e})=>t(L(e,o));return r.on("change",e),e}),(t=>{r.removeListener("change",t)}),i,1,{getDocHandle:()=>r}));
|
|
Binary file
|
|
@@ -32,6 +32,7 @@ const isObject = (obj) =>
|
|
|
32
32
|
);
|
|
33
33
|
const objIds = object.keys;
|
|
34
34
|
const objFreeze = object.freeze;
|
|
35
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
35
36
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
36
37
|
const objHas = (obj, id) => id in obj;
|
|
37
38
|
const objDel = (obj, id) => {
|
|
@@ -350,7 +351,7 @@ const createAutomergePersister = (
|
|
|
350
351
|
docObjName = TINYBASE,
|
|
351
352
|
onIgnoredError,
|
|
352
353
|
) => {
|
|
353
|
-
docHandle.change((doc) => (doc
|
|
354
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
354
355
|
const getPersisted = async () => {
|
|
355
356
|
const doc = await docHandle.doc();
|
|
356
357
|
return objSize(doc?.[docObjName]) == 2
|
|
@@ -32,6 +32,7 @@ const isObject = (obj) =>
|
|
|
32
32
|
);
|
|
33
33
|
const objIds = object.keys;
|
|
34
34
|
const objFreeze = object.freeze;
|
|
35
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
35
36
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
36
37
|
const objHas = (obj, id) => id in obj;
|
|
37
38
|
const objDel = (obj, id) => {
|
|
@@ -350,7 +351,7 @@ const createAutomergePersister = (
|
|
|
350
351
|
docObjName = TINYBASE,
|
|
351
352
|
onIgnoredError,
|
|
352
353
|
) => {
|
|
353
|
-
docHandle.change((doc) => (doc
|
|
354
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
354
355
|
const getPersisted = async () => {
|
|
355
356
|
const doc = await docHandle.doc();
|
|
356
357
|
return objSize(doc?.[docObjName]) == 2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e,n)=>t(e,(e=>e[n])),
|
|
1
|
+
const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e=[])=>r.fromEntries(e),c=(e,n)=>t(e,(e=>e[n])),d=(e,t)=>t in e,v=(e,t)=>(delete e[t],e),y=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,n])=>t(n,e))),p=e=>a(e).length,h=n=>(n=>!e(n)&&t(l(n),(t=>t==r.prototype||e(l(t))),(()=>!0)))(n)&&0==p(n),g=(e,t,n)=>(d(e,t)||(e[t]=n()),e[t]),f=e=>new Map(e),b=(e,t)=>null==e?void 0:e.get(t),C=(t,n,o)=>{return e(o)?(l=n,null==(r=t)||r.delete(l),t):null==t?void 0:t.set(n,o);var r,l},m=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||C(e,t,n()),b(e,t)};var w=Object.defineProperty,A=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,S=(e,t,n)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,L=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const M=f(),j=f();var x=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(t,n,o,r)=>{const l=e(n)?t:g(t,n,(()=>({})));let i;return y(o,((e,t)=>{r(l,t,e)&&(i=1)})),y(l,((e,t)=>{d(o,t)||(v(l,t),i=1)})),!e(n)&&h(l)&&v(t,n),i},T=(r,l,i="tinybase",a)=>(l.change((e=>g(e,i,s))),((r,l,i,a,s,c,d,v={},y=[])=>{let p,g,f,w=0,x=0,D=0;m(M,y,(()=>0)),m(j,y,(()=>[]));const[E,T,k,z,F]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:o("Store type not supported by this Persister"))(d,r),H=e=>{(E&&n(null==e?void 0:e[0])?1===(null==e?void 0:e[2])?r.applyMergeableChanges:r.setMergeableContent:1===(null==e?void 0:e[2])?r.applyChanges:r.setContent)(e)},I=e=>L(void 0,null,(function*(){return 2!=w&&(w=1,x++,yield J((()=>L(void 0,null,(function*(){try{const e=yield l();n(e)?H(e):o("Content is not an array "+e)}catch(t){null==c||c(t),e&&F(e)}w=0}))))),K})),q=()=>(g&&(s(g),g=void 0),K),B=e=>L(void 0,null,(function*(){return 1!=w&&(w=2,D++,yield J((()=>L(void 0,null,(function*(){try{yield i(T,e)}catch(e){null==c||c(e)}w=0}))))),K})),G=()=>(t(f,r.delListener),f=void 0,K),J=(...t)=>L(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(b(j,y),...t),yield L(void 0,null,(function*(){if(!b(M,y)){for(C(M,y,1);!e((t=b(j,y),p=t.shift()));)try{yield p()}catch(e){null==c||c(e)}C(M,y,0)}var t})),K})),K=((e,t)=>{for(var n in t||(t={}))P.call(t,n)&&S(e,n,t[n]);if(A)for(var n of A(t))O.call(t,n)&&S(e,n,t[n]);return e})({load:I,startAutoLoad:e=>L(void 0,null,(function*(){yield q().load(e);try{g=a(((e,t)=>L(void 0,null,(function*(){t||e?2!=w&&(w=1,x++,H(null!=t?t:e),w=0):yield I()}))))}catch(e){null==c||c(e)}return K})),stopAutoLoad:q,isAutoLoading:()=>!e(g),save:B,startAutoSave:()=>L(void 0,null,(function*(){return yield G().save(),f=r.addDidFinishTransactionListener((()=>{const e=k();z(e)&&B(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!e(f),schedule:J,getStore:()=>r,destroy:()=>(b(j,y).splice(0,void 0),q().stopAutoSave()),getStats:()=>({loads:x,saves:D})},v);return u(K)})(r,(()=>x(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((n,o)=>x(void 0,null,(function*(){return l.change((r=>((n,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(n,o);const[i,a]=D(n,o),u=()=>{s=1};let s=1;if(t(l,(([n,o])=>{s=0,y(n,((n,o)=>s?0:e(n)?v(i,o):t(i[o],(o=>y(n,((n,r)=>s?0:e(n)?v(o,r):t(c(o,r),(t=>y(n,((n,o)=>e(n)?v(t,o):t[o]=n))),u)))),u))),y(o,((t,n)=>s?0:e(t)?v(a,n):a[n]=t))})),s){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,n,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}));export{T as createAutomergePersister};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e,n)=>t(e,(e=>e[n])),
|
|
1
|
+
const e=e=>null==e,t=(t,n,o)=>e(t)?null==o?void 0:o():n(t),n=e=>Array.isArray(e),o=e=>{throw Error(e)},r=Object,l=e=>r.getPrototypeOf(e),i=r.entries,a=r.keys,u=r.freeze,s=(e=[])=>r.fromEntries(e),c=(e,n)=>t(e,(e=>e[n])),d=(e,t)=>t in e,v=(e,t)=>(delete e[t],e),y=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,n])=>t(n,e))),p=e=>a(e).length,h=n=>(n=>!e(n)&&t(l(n),(t=>t==r.prototype||e(l(t))),(()=>!0)))(n)&&0==p(n),g=(e,t,n)=>(d(e,t)||(e[t]=n()),e[t]),f=e=>new Map(e),b=(e,t)=>null==e?void 0:e.get(t),C=(t,n,o)=>{return e(o)?(l=n,null==(r=t)||r.delete(l),t):null==t?void 0:t.set(n,o);var r,l},m=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||C(e,t,n()),b(e,t)};var w=Object.defineProperty,A=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,S=(e,t,n)=>t in e?w(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,L=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const M=f(),j=f();var x=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(t,n,o,r)=>{const l=e(n)?t:g(t,n,(()=>({})));let i;return y(o,((e,t)=>{r(l,t,e)&&(i=1)})),y(l,((e,t)=>{d(o,t)||(v(l,t),i=1)})),!e(n)&&h(l)&&v(t,n),i},T=(r,l,i="tinybase",a)=>(l.change((e=>g(e,i,s))),((r,l,i,a,s,c,d,v={},y=[])=>{let p,g,f,w=0,x=0,D=0;m(M,y,(()=>0)),m(j,y,(()=>[]));const[E,T,k,z,F]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:o("Store type not supported by this Persister"))(d,r),H=e=>{(E&&n(null==e?void 0:e[0])?1===(null==e?void 0:e[2])?r.applyMergeableChanges:r.setMergeableContent:1===(null==e?void 0:e[2])?r.applyChanges:r.setContent)(e)},I=e=>L(void 0,null,(function*(){return 2!=w&&(w=1,x++,yield J((()=>L(void 0,null,(function*(){try{const e=yield l();n(e)?H(e):o("Content is not an array "+e)}catch(t){null==c||c(t),e&&F(e)}w=0}))))),K})),q=()=>(g&&(s(g),g=void 0),K),B=e=>L(void 0,null,(function*(){return 1!=w&&(w=2,D++,yield J((()=>L(void 0,null,(function*(){try{yield i(T,e)}catch(e){null==c||c(e)}w=0}))))),K})),G=()=>(t(f,r.delListener),f=void 0,K),J=(...t)=>L(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(b(j,y),...t),yield L(void 0,null,(function*(){if(!b(M,y)){for(C(M,y,1);!e((t=b(j,y),p=t.shift()));)try{yield p()}catch(e){null==c||c(e)}C(M,y,0)}var t})),K})),K=((e,t)=>{for(var n in t||(t={}))P.call(t,n)&&S(e,n,t[n]);if(A)for(var n of A(t))O.call(t,n)&&S(e,n,t[n]);return e})({load:I,startAutoLoad:e=>L(void 0,null,(function*(){yield q().load(e);try{g=a(((e,t)=>L(void 0,null,(function*(){t||e?2!=w&&(w=1,x++,H(null!=t?t:e),w=0):yield I()}))))}catch(e){null==c||c(e)}return K})),stopAutoLoad:q,isAutoLoading:()=>!e(g),save:B,startAutoSave:()=>L(void 0,null,(function*(){return yield G().save(),f=r.addDidFinishTransactionListener((()=>{const e=k();z(e)&&B(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!e(f),schedule:J,getStore:()=>r,destroy:()=>(b(j,y).splice(0,void 0),q().stopAutoSave()),getStats:()=>({loads:x,saves:D})},v);return u(K)})(r,(()=>x(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((n,o)=>x(void 0,null,(function*(){return l.change((r=>((n,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(n,o);const[i,a]=D(n,o),u=()=>{s=1};let s=1;if(t(l,(([n,o])=>{s=0,y(n,((n,o)=>s?0:e(n)?v(i,o):t(i[o],(o=>y(n,((n,r)=>s?0:e(n)?v(o,r):t(c(o,r),(t=>y(n,((n,o)=>e(n)?v(t,o):t[o]=n))),u)))),u))),y(o,((t,n)=>s?0:e(t)?v(a,n):a[n]=t))})),s){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,n,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}));export{T as createAutomergePersister};
|
|
Binary file
|
|
@@ -30,6 +30,7 @@ const isObject = (obj) =>
|
|
|
30
30
|
);
|
|
31
31
|
const objIds = object.keys;
|
|
32
32
|
const objFreeze = object.freeze;
|
|
33
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
33
34
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
34
35
|
const objHas = (obj, id) => id in obj;
|
|
35
36
|
const objDel = (obj, id) => {
|
|
@@ -443,7 +444,7 @@ const createAutomergePersister = (
|
|
|
443
444
|
docObjName = TINYBASE,
|
|
444
445
|
onIgnoredError,
|
|
445
446
|
) => {
|
|
446
|
-
docHandle.change((doc) => (doc
|
|
447
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
447
448
|
const getPersisted = () =>
|
|
448
449
|
__async(void 0, null, function* () {
|
|
449
450
|
const doc = yield docHandle.doc();
|
|
@@ -30,6 +30,7 @@ const isObject = (obj) =>
|
|
|
30
30
|
);
|
|
31
31
|
const objIds = object.keys;
|
|
32
32
|
const objFreeze = object.freeze;
|
|
33
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
33
34
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
34
35
|
const objHas = (obj, id) => id in obj;
|
|
35
36
|
const objDel = (obj, id) => {
|
|
@@ -443,7 +444,7 @@ const createAutomergePersister = (
|
|
|
443
444
|
docObjName = TINYBASE,
|
|
444
445
|
onIgnoredError,
|
|
445
446
|
) => {
|
|
446
|
-
docHandle.change((doc) => (doc
|
|
447
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
447
448
|
const getPersisted = () =>
|
|
448
449
|
__async(void 0, null, function* () {
|
|
449
450
|
const doc = yield docHandle.doc();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,o=t=>s.getPrototypeOf(t),r=s.entries,i=s.keys,c=s.freeze,y=(t,a)=>e(t,(t=>t[a])),
|
|
1
|
+
const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,o=t=>s.getPrototypeOf(t),r=s.entries,i=s.keys,c=s.freeze,y=(t=[])=>s.fromEntries(t),g=(t,a)=>e(t,(t=>t[a])),d=(t,e)=>e in t,l=(t,e)=>(delete t[e],t),h=(t,e)=>((t,e)=>t.map(e))(r(t),(([t,a])=>e(a,t))),u=t=>i(t).length,v=a=>(a=>!t(a)&&e(o(a),(e=>e==s.prototype||t(o(e))),(()=>!0)))(a)&&0==u(a),p=(t,e,a)=>(d(t,e)||(t[e]=a()),t[e]),w=t=>new Map(t),C=(t,e)=>t?.get(e),f=(e,a,n)=>{return t(n)?(s=e,o=a,s?.delete(o),e):e?.set(a,n);var s,o},A=(t,e,a,n)=>{var s,o;return s=t,o=e,s?.has(o)||f(t,e,a()),C(t,e)},b=w(),S=w(),L=(t,e)=>[t[e].t,t[e].v],M=(e,a,n,s)=>{const o=t(a)?e:p(e,a,(()=>({})));let r;return h(n,((t,e)=>{s(o,e,t)&&(r=1)})),h(o,((t,e)=>{d(n,e)||(l(o,e),r=1)})),!t(a)&&v(o)&&l(e,a),r},m=(s,o,r="tinybase",i)=>(o.change((t=>p(t,r,y))),((s,o,r,i,y,g,d,l={},h=[])=>{let u,p,w,L=0,M=0,m=0;A(b,h,(()=>0)),A(S,h,(()=>[]));const[D,T,E,O,P]=((t=1,e)=>1!=t&&e.isMergeable()?[1,e.getMergeableContent,e.getTransactionMergeableChanges,([[t],[e]])=>!v(t)||!v(e),e.setDefaultContent]:2!=t?[0,e.getContent,e.getTransactionChanges,([t,e])=>!v(t)||!v(e),e.setContent]:n("Store type not supported by this Persister"))(d,s),j=t=>{(D&&a(t?.[0])?1===t?.[2]?s.applyMergeableChanges:s.setMergeableContent:1===t?.[2]?s.applyChanges:s.setContent)(t)},k=async t=>(2!=L&&(L=1,M++,await H((async()=>{try{const t=await o();a(t)?j(t):n("Content is not an array "+t)}catch(e){g?.(e),t&&P(t)}L=0}))),q),x=()=>(p&&(y(p),p=void 0),q),z=async t=>(1!=L&&(L=2,m++,await H((async()=>{try{await r(T,t)}catch(t){g?.(t)}L=0}))),q),F=()=>(e(w,s.delListener),w=void 0,q),H=async(...e)=>(((t,...e)=>{t.push(...e)})(C(S,h),...e),await(async()=>{if(!C(b,h)){for(f(b,h,1);!t((e=C(S,h),u=e.shift()));)try{await u()}catch(t){g?.(t)}f(b,h,0)}var e})(),q),q={load:k,startAutoLoad:async t=>{await x().load(t);try{p=i((async(t,e)=>{e||t?2!=L&&(L=1,M++,j(e??t),L=0):await k()}))}catch(t){g?.(t)}return q},stopAutoLoad:x,isAutoLoading:()=>!t(p),save:z,startAutoSave:async()=>(await F().save(),w=s.addDidFinishTransactionListener((()=>{const t=E();O(t)&&z(t)})),q),stopAutoSave:F,isAutoSaving:()=>!t(w),schedule:H,getStore:()=>s,destroy:()=>(C(S,h).splice(0,void 0),x().stopAutoSave()),getStats:()=>({loads:M,saves:m}),...l};return c(q)})(s,(async()=>{const t=await o.doc();return 2==u(t?.[r])?L(t,r):void 0}),(async(a,n)=>o.change((s=>((a,n,s,o)=>{((t,e)=>{v(t[e])&&(t[e]={t:{},v:{}})})(a,n);const[r,i]=L(a,n),c=()=>{y=1};let y=1;if(e(o,(([a,n])=>{y=0,h(a,((a,n)=>y?0:t(a)?l(r,n):e(r[n],(n=>h(a,((a,s)=>y?0:t(a)?l(n,s):e(g(n,s),(e=>h(a,((a,n)=>t(a)?l(e,n):e[n]=a))),c)))),c))),h(n,((e,a)=>y?0:t(e)?l(i,a):i[a]=e))})),y){const[t,e]=s();M(r,void 0,t,((t,e,a)=>M(r,e,a,((t,e,a)=>M(t,e,a,((t,e,a)=>{if(g(t,e)!==a)return t[e]=a,1})))))),M(i,void 0,e,((t,e,a)=>{g(i,e)!==a&&(i[e]=a)}))}})(s,r,a,n)))),(t=>{const e=({doc:e})=>t(L(e,r));return o.on("change",e),e}),(t=>{o.removeListener("change",t)}),i,1,{getDocHandle:()=>o}));export{m as createAutomergePersister};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,o=t=>s.getPrototypeOf(t),r=s.entries,i=s.keys,c=s.freeze,y=(t,a)=>e(t,(t=>t[a])),
|
|
1
|
+
const t=t=>null==t,e=(e,a,n)=>t(e)?n?.():a(e),a=t=>Array.isArray(t),n=t=>{throw Error(t)},s=Object,o=t=>s.getPrototypeOf(t),r=s.entries,i=s.keys,c=s.freeze,y=(t=[])=>s.fromEntries(t),g=(t,a)=>e(t,(t=>t[a])),d=(t,e)=>e in t,l=(t,e)=>(delete t[e],t),h=(t,e)=>((t,e)=>t.map(e))(r(t),(([t,a])=>e(a,t))),u=t=>i(t).length,v=a=>(a=>!t(a)&&e(o(a),(e=>e==s.prototype||t(o(e))),(()=>!0)))(a)&&0==u(a),p=(t,e,a)=>(d(t,e)||(t[e]=a()),t[e]),w=t=>new Map(t),C=(t,e)=>t?.get(e),f=(e,a,n)=>{return t(n)?(s=e,o=a,s?.delete(o),e):e?.set(a,n);var s,o},A=(t,e,a,n)=>{var s,o;return s=t,o=e,s?.has(o)||f(t,e,a()),C(t,e)},b=w(),S=w(),L=(t,e)=>[t[e].t,t[e].v],M=(e,a,n,s)=>{const o=t(a)?e:p(e,a,(()=>({})));let r;return h(n,((t,e)=>{s(o,e,t)&&(r=1)})),h(o,((t,e)=>{d(n,e)||(l(o,e),r=1)})),!t(a)&&v(o)&&l(e,a),r},m=(s,o,r="tinybase",i)=>(o.change((t=>p(t,r,y))),((s,o,r,i,y,g,d,l={},h=[])=>{let u,p,w,L=0,M=0,m=0;A(b,h,(()=>0)),A(S,h,(()=>[]));const[D,T,E,O,P]=((t=1,e)=>1!=t&&e.isMergeable()?[1,e.getMergeableContent,e.getTransactionMergeableChanges,([[t],[e]])=>!v(t)||!v(e),e.setDefaultContent]:2!=t?[0,e.getContent,e.getTransactionChanges,([t,e])=>!v(t)||!v(e),e.setContent]:n("Store type not supported by this Persister"))(d,s),j=t=>{(D&&a(t?.[0])?1===t?.[2]?s.applyMergeableChanges:s.setMergeableContent:1===t?.[2]?s.applyChanges:s.setContent)(t)},k=async t=>(2!=L&&(L=1,M++,await H((async()=>{try{const t=await o();a(t)?j(t):n("Content is not an array "+t)}catch(e){g?.(e),t&&P(t)}L=0}))),q),x=()=>(p&&(y(p),p=void 0),q),z=async t=>(1!=L&&(L=2,m++,await H((async()=>{try{await r(T,t)}catch(t){g?.(t)}L=0}))),q),F=()=>(e(w,s.delListener),w=void 0,q),H=async(...e)=>(((t,...e)=>{t.push(...e)})(C(S,h),...e),await(async()=>{if(!C(b,h)){for(f(b,h,1);!t((e=C(S,h),u=e.shift()));)try{await u()}catch(t){g?.(t)}f(b,h,0)}var e})(),q),q={load:k,startAutoLoad:async t=>{await x().load(t);try{p=i((async(t,e)=>{e||t?2!=L&&(L=1,M++,j(e??t),L=0):await k()}))}catch(t){g?.(t)}return q},stopAutoLoad:x,isAutoLoading:()=>!t(p),save:z,startAutoSave:async()=>(await F().save(),w=s.addDidFinishTransactionListener((()=>{const t=E();O(t)&&z(t)})),q),stopAutoSave:F,isAutoSaving:()=>!t(w),schedule:H,getStore:()=>s,destroy:()=>(C(S,h).splice(0,void 0),x().stopAutoSave()),getStats:()=>({loads:M,saves:m}),...l};return c(q)})(s,(async()=>{const t=await o.doc();return 2==u(t?.[r])?L(t,r):void 0}),(async(a,n)=>o.change((s=>((a,n,s,o)=>{((t,e)=>{v(t[e])&&(t[e]={t:{},v:{}})})(a,n);const[r,i]=L(a,n),c=()=>{y=1};let y=1;if(e(o,(([a,n])=>{y=0,h(a,((a,n)=>y?0:t(a)?l(r,n):e(r[n],(n=>h(a,((a,s)=>y?0:t(a)?l(n,s):e(g(n,s),(e=>h(a,((a,n)=>t(a)?l(e,n):e[n]=a))),c)))),c))),h(n,((e,a)=>y?0:t(e)?l(i,a):i[a]=e))})),y){const[t,e]=s();M(r,void 0,t,((t,e,a)=>M(r,e,a,((t,e,a)=>M(t,e,a,((t,e,a)=>{if(g(t,e)!==a)return t[e]=a,1})))))),M(i,void 0,e,((t,e,a)=>{g(i,e)!==a&&(i[e]=a)}))}})(s,r,a,n)))),(t=>{const e=({doc:e})=>t(L(e,r));return o.on("change",e),e}),(t=>{o.removeListener("change",t)}),i,1,{getDocHandle:()=>o}));export{m as createAutomergePersister};
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.4",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@automerge/automerge-repo": "^1.2.0",
|
|
24
24
|
"@powersync/common": "^1.16.0",
|
|
25
|
-
"@libsql/client": "^0.
|
|
25
|
+
"@libsql/client": "^0.9.0",
|
|
26
26
|
"@sqlite.org/sqlite-wasm": "^3.46.0-build2",
|
|
27
27
|
"@vlcn.io/crsqlite-wasm": "^0.16.0",
|
|
28
28
|
"electric-sql": "^0.12.1",
|
|
@@ -30,6 +30,7 @@ const isObject = (obj) =>
|
|
|
30
30
|
);
|
|
31
31
|
const objIds = object.keys;
|
|
32
32
|
const objFreeze = object.freeze;
|
|
33
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
33
34
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
34
35
|
const objHas = (obj, id) => id in obj;
|
|
35
36
|
const objDel = (obj, id) => {
|
|
@@ -348,7 +349,7 @@ const createAutomergePersister = (
|
|
|
348
349
|
docObjName = TINYBASE,
|
|
349
350
|
onIgnoredError,
|
|
350
351
|
) => {
|
|
351
|
-
docHandle.change((doc) => (doc
|
|
352
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
352
353
|
const getPersisted = async () => {
|
|
353
354
|
const doc = await docHandle.doc();
|
|
354
355
|
return objSize(doc?.[docObjName]) == 2
|
|
@@ -30,6 +30,7 @@ const isObject = (obj) =>
|
|
|
30
30
|
);
|
|
31
31
|
const objIds = object.keys;
|
|
32
32
|
const objFreeze = object.freeze;
|
|
33
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
33
34
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
34
35
|
const objHas = (obj, id) => id in obj;
|
|
35
36
|
const objDel = (obj, id) => {
|
|
@@ -348,7 +349,7 @@ const createAutomergePersister = (
|
|
|
348
349
|
docObjName = TINYBASE,
|
|
349
350
|
onIgnoredError,
|
|
350
351
|
) => {
|
|
351
|
-
docHandle.change((doc) => (doc
|
|
352
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
352
353
|
const getPersisted = async () => {
|
|
353
354
|
const doc = await docHandle.doc();
|
|
354
355
|
return objSize(doc?.[docObjName]) == 2
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for <span>local-first apps</span>.</h2></section><p><a href="https://tinybase.org/guides/releases/#v5-1"><em>NEW!</em> v5.1 release</a></p><p><span id="one-with">"The One You Can Sync... with a server!"</span></p><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It's <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It's <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, but you can easily <a href="#persist-to-storage-sqlite-more">persist</a> your data to file, <a href="https://tinybase.org/api/persister-browser">browser storage</a>, <a href="https://tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://tinybase.org/guides/persistence/database-persistence/">SQLite databases</a>, and <a href="https://tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It's Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it's especially great for local-first apps: where data is stored locally on the user's device and that can be run offline. It's tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.3kB - 12.7kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends!</h2><div><a href="https://tinybase.org/guides/building-uis/getting-started-with-ui-react"><img width="48" src="https://tinybase.org/react.svg"> React</a></div><div><a href="https://tinybase.org/api/persister-partykit-client"><img width="48" src="https://tinybase.org/partykit.svg"> PartyKit</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/expo.svg">Expo SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/electric.svg">ElectricSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/sqlite.svg"> SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/turso.svg">Turso</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/powersync.svg">PowerSync</a></div><div><a href="https://tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img width="48" src="https://tinybase.org/indexeddb.svg"> IndexedDB</a></div><div><a href="https://tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img width="48" src="https://tinybase.org/yjs.svg"> YJS</a></div><div><a href="https://tinybase.org/api/persister-cr-sqlite-wasm"><img width="48" src="https://tinybase.org/crsqlite.png"> CR-SQLite</a></div><div><a href="https://tinybase.org/api/persister-automerge"><img width="48" src="https://tinybase.org/automerge.svg"> Automerge</a></div></section><hr><section id="follow"><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"> </a><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"> </a><a href="https://twitter.com/tinybasejs" target="_blank"><img src="https://img.shields.io/twitter/follow/tinybasejs?style=for-the-badge&logo=x&logoColor=%23fff&label=Twitter&labelColor=%23333&color=%23333"></a><br><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"> </a><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"> </a><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=jest&logoColor=%23fff&color=%23333&labelColor=%2387c305"> </a><a href="https://www.npmjs.com/package/tinybase/v/5.1.
|
|
1
|
+
<section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for <span>local-first apps</span>.</h2></section><p><a href="https://tinybase.org/guides/releases/#v5-1"><em>NEW!</em> v5.1 release</a></p><p><span id="one-with">"The One You Can Sync... with a server!"</span></p><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="it-s-reactive">It's <em>Reactive</em></h2><p>TinyBase lets you <a href="#register-granular-listeners">listen to changes</a> made to any part of your data. This means your app will be fast, since you only spend rendering cycles on things that change. The optional <a href="#call-hooks-to-bind-to-data">bindings to React</a> and <a href="#pre-built-reactive-components">pre-built components</a> let you easily build fully reactive UIs on top of TinyBase. You even get a built-in <a href="#set-checkpoints-for-an-undo-stack">undo stack</a>, and <a href="#an-inspector-for-your-data">developer tools</a>!</p></section><section><h2 id="it-s-database-like">It's <em>Database-Like</em></h2><p>Consumer app? Enterprise app? Or even a game? Model <a href="#start-with-a-simple-key-value-store">key-value data</a> and <a href="#level-up-to-use-tabular-data">tabular data</a> with optional typed <a href="#apply-schemas-to-tables-values">schematization</a>, whatever its data structures. There are built-in <a href="#create-indexes-for-fast-lookups">indexing</a>, <a href="#define-metrics-and-aggregations">metric aggregation</a>, and tabular <a href="#model-table-relationships">relationships</a> APIs - and a powerful <a href="#build-complex-queries-with-tinyql">query engine</a> to select, join, filter, and group data (reactively!) without SQL.</p></section><section><h2 id="it-synchronizes">It <em>Synchronizes</em></h2><p>TinyBase has <a href="#synchronize-between-devices">native CRDT</a> support, meaning that you can deterministically <a href="https://tinybase.org/guides/synchronization/">synchronize</a> and merge data across multiple sources, clients, and servers. And although TinyBase is an in-memory data store, but you can easily <a href="#persist-to-storage-sqlite-more">persist</a> your data to file, <a href="https://tinybase.org/api/persister-browser">browser storage</a>, <a href="https://tinybase.org/api/persister-indexed-db">IndexedDB</a>, <a href="https://tinybase.org/guides/persistence/database-persistence/">SQLite databases</a>, and <a href="https://tinybase.org/guides/persistence/third-party-crdt-persistence/">more</a>.</p></section><section><h2 id="it-s-built-for-a-local-first-world">It's Built For A <em>Local-First</em> World</h2><p>TinyBase works anywhere that JavaScript does, but it's especially great for local-first apps: where data is stored locally on the user's device and that can be run offline. It's tiny by name, tiny by nature: just <a href="#did-we-say-tiny">5.3kB - 12.7kB</a> and with no dependencies - yet <a href="#well-tested-and-documented">100% tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and of course, <a href="https://github.com/tinyplex/tinybase">open source</a>!</p></section><hr><section id="friends"><h2 id="tinybase-works-great-on-its-own-but-also-plays-well-with-friends">TinyBase works great on its own, but also plays well with friends!</h2><div><a href="https://tinybase.org/guides/building-uis/getting-started-with-ui-react"><img width="48" src="https://tinybase.org/react.svg"> React</a></div><div><a href="https://tinybase.org/api/persister-partykit-client"><img width="48" src="https://tinybase.org/partykit.svg"> PartyKit</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/expo.svg">Expo SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/electric.svg">ElectricSQL</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/sqlite.svg"> SQLite</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/turso.svg">Turso</a></div><div><a href="https://tinybase.org/guides/schemas-and-persistence/database-persistence"><img width="48" src="https://tinybase.org/powersync.svg">PowerSync</a></div><div><a href="https://tinybase.org/api/persister-indexed-db/functions/creation/createindexeddbpersister"><img width="48" src="https://tinybase.org/indexeddb.svg"> IndexedDB</a></div><div><a href="https://tinybase.org/api/persister-yjs/functions/creation/createyjspersister"><img width="48" src="https://tinybase.org/yjs.svg"> YJS</a></div><div><a href="https://tinybase.org/api/persister-cr-sqlite-wasm"><img width="48" src="https://tinybase.org/crsqlite.png"> CR-SQLite</a></div><div><a href="https://tinybase.org/api/persister-automerge"><img width="48" src="https://tinybase.org/automerge.svg"> Automerge</a></div></section><hr><section id="follow"><a href="https://github.com/tinyplex/tinybase" target="_blank"><img src="https://img.shields.io/github/stars/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=GitHub&labelColor=%23d81b60&color=%23333"> </a><a href="https://discord.com/invite/mGz3mevwP8" target="_blank"><img src="https://img.shields.io/discord/1027918215323590676?style=for-the-badge&logo=discord&logoColor=%23fff&label=Discord&labelColor=%233131e8&color=%23333"> </a><a href="https://twitter.com/tinybasejs" target="_blank"><img src="https://img.shields.io/twitter/follow/tinybasejs?style=for-the-badge&logo=x&logoColor=%23fff&label=Twitter&labelColor=%23333&color=%23333"></a><br><a href="https://github.com/tinyplex/tinybase/discussions" target="_blank"><img src="https://img.shields.io/github/discussions/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Ideas&labelColor=%23d81b60&color=%23333"> </a><a href="https://github.com/tinyplex/tinybase/issues" target="_blank"><img src="https://img.shields.io/github/issues/tinyplex/tinybase?style=for-the-badge&logo=GitHub&logoColor=%23fff&label=Issues&labelColor=%23d81b60&color=%23333"> </a><a href="#well-tested-and-documented"><img src="https://img.shields.io/badge/Tests-100%25-green?style=for-the-badge&logo=jest&logoColor=%23fff&color=%23333&labelColor=%2387c305"> </a><a href="https://www.npmjs.com/package/tinybase/v/5.1.3" target="_blank"><img src="https://img.shields.io/npm/v/tinybase?style=for-the-badge&logo=npm&logoColor=%23fff&labelColor=%23bd0005&color=%23333"></a></section><hr><section><h2 id="start-with-a-simple-key-value-store">Start with a simple key-value store.</h2><p>Creating a <a href="https://tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://tinybase.org/api/store/type-aliases/store/values/"><code>Values</code></a> in it by unique <a href="https://tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get them back out again.</p><p>Read more about using keyed value data in <a href="https://tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
|
|
2
2
|
|
|
3
3
|
```js
|
|
4
4
|
import {createStore} from 'tinybase';
|
|
@@ -292,4 +292,4 @@ export const createShop: typeof createShopDecl = () => {
|
|
|
292
292
|
};
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
<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>5.3kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>12.7kB</em>.</p><p>The optional <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just <em>4.6kB</em>, the ui-react-dom components are another <em>2.5kB</em>, and everything is super fast. Life's easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th> </th><th>Minified .js.gz</th><th>Source .js</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">tinybase/store</a> (minimal)</th><td>5.3kB</td><td>52.5kB</td></tr><tr><th class="right">tinybase (complete)</th><td>12.7kB</td><td>130.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react/">ui-react</a></th><td>4.6kB</td><td>48.3kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react-dom/">ui-react-dom</a></th><td>2.5kB</td><td>20.4kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible for you to get your TinyBase-powered app up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>2,380</td><td>2,380</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>2,567</td><td>2,567</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>1,006</td><td>1,006</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>951</td><td>951</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">6,851</td></tr><tr><th class="right">Assertions</th><td colspan="3">32,075</td></tr></tbody></table></div><hr><section id="sponsors"><h2 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h2><a href="https://github.com/cpojer" target="_blank"><img title="cpojer" src="https://github.com/cpojer.png?size=48" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/beekeeb" target="_blank"><img title="beekeeb" src="https://github.com/beekeeb.png?size=48" width="48" height="48"></a><a href="https://github.com/cancelself" target="_blank"><img title="cancelself" src="https://github.com/cancelself.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img title="arpitBhalla" src="https://github.com/arpitBhalla.png?size=48" width="48" height="48"></a></section><section id="users"><h2 id="excited-to-be-used-by">Excited to be used by:</h2><a href="https://github.com/Apocalypsor" target="_blank"><img title="Apocalypsor" src="https://github.com/Apocalypsor.png?size=48" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img title="brentvatne" src="https://github.com/brentvatne.png?size=48" width="48" height="48"></a><a href="https://github.com/byCedric" target="_blank"><img title="byCedric" src="https://github.com/byCedric.png?size=48" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img title="circadian-risk" src="https://github.com/circadian-risk.png?size=48" width="48" height="48"></a><a href="https://github.com/cpojer" target="_blank"><img title="cpojer" src="https://github.com/cpojer.png?size=48" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img title="cubecull" src="https://github.com/cubecull.png?size=48" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img title="erwinkn" src="https://github.com/erwinkn.png?size=48" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/ezra-en" target="_blank"><img title="ezra-en" src="https://github.com/ezra-en.png?size=48" width="48" height="48"></a><a href="https://github.com/fdfontes" target="_blank"><img title="fdfontes" src="https://github.com/fdfontes.png?size=48" width="48" height="48"></a><a href="https://github.com/feychenie" target="_blank"><img title="feychenie" src="https://github.com/feychenie.png?size=48" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img title="flaming-codes" src="https://github.com/flaming-codes.png?size=48" width="48" height="48"></a><a href="https://github.com/fostertheweb" target="_blank"><img title="fostertheweb" src="https://github.com/fostertheweb.png?size=48" width="48" height="48"></a><a href="https://github.com/generates" target="_blank"><img title="generates" src="https://github.com/generates.png?size=48" width="48" height="48"></a><a href="https://github.com/Giulio987" target="_blank"><img title="Giulio987" src="https://github.com/Giulio987.png?size=48" width="48" height="48"></a><a href="https://github.com/itsdevcoffee" target="_blank"><img title="itsdevcoffee" src="https://github.com/itsdevcoffee.png?size=48" width="48" height="48"></a><a href="https://github.com/jaysc" target="_blank"><img title="jaysc" src="https://github.com/jaysc.png?size=48" width="48" height="48"></a><a href="https://github.com/jbolda" target="_blank"><img title="jbolda" src="https://github.com/jbolda.png?size=48" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img title="Kayoo-asso" src="https://github.com/Kayoo-asso.png?size=48" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img title="kotofurumiya" src="https://github.com/kotofurumiya.png?size=48" width="48" height="48"></a><a href="https://github.com/Kudo" target="_blank"><img title="Kudo" src="https://github.com/Kudo.png?size=48" width="48" height="48"></a><a href="https://github.com/learn-anything" target="_blank"><img title="learn-anything" src="https://github.com/learn-anything.png?size=48" width="48" height="48"></a><a href="https://github.com/lluc" target="_blank"><img title="lluc" src="https://github.com/lluc.png?size=48" width="48" height="48"></a><a href="https://github.com/marksteve" target="_blank"><img title="marksteve" src="https://github.com/marksteve.png?size=48" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img title="miking-the-viking" src="https://github.com/miking-the-viking.png?size=48" width="48" height="48"></a><a href="https://github.com/mjamesderocher" target="_blank"><img title="mjamesderocher" src="https://github.com/mjamesderocher.png?size=48" width="48" height="48"></a><a href="https://github.com/mouktardev" target="_blank"><img title="mouktardev" src="https://github.com/mouktardev.png?size=48" width="48" height="48"></a><a href="https://github.com/nickmessing" target="_blank"><img title="nickmessing" src="https://github.com/nickmessing.png?size=48" width="48" height="48"></a><a href="https://github.com/nikitavoloboev" target="_blank"><img title="nikitavoloboev" src="https://github.com/nikitavoloboev.png?size=48" width="48" height="48"></a><a href="https://github.com/nkzw-tech" target="_blank"><img title="nkzw-tech" src="https://github.com/nkzw-tech.png?size=48" width="48" height="48"></a><a href="https://github.com/palerdot" target="_blank"><img title="palerdot" src="https://github.com/palerdot.png?size=48" width="48" height="48"></a><a href="https://github.com/PorcoRosso85" target="_blank"><img title="PorcoRosso85" src="https://github.com/PorcoRosso85.png?size=48" width="48" height="48"></a><a href="https://github.com/primodiumxyz" target="_blank"><img title="primodiumxyz" src="https://github.com/primodiumxyz.png?size=48" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img title="shaneosullivan" src="https://github.com/shaneosullivan.png?size=48" width="48" height="48"></a><a href="https://github.com/sudo-self" target="_blank"><img title="sudo-self" src="https://github.com/sudo-self.png?size=48" width="48" height="48"></a><a href="https://github.com/SuperSonicHub1" target="_blank"><img title="SuperSonicHub1" src="https://github.com/SuperSonicHub1.png?size=48" width="48" height="48"></a><a href="https://github.com/threepointone" target="_blank"><img title="threepointone" src="https://github.com/threepointone.png?size=48" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img title="uptonking" src="https://github.com/uptonking.png?size=48" width="48" height="48"></a><a href="https://github.com/ViktorZhurbin" target="_blank"><img title="ViktorZhurbin" src="https://github.com/ViktorZhurbin.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a></section><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section id="about"><h2 id="about">About</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Or sacrifice features for bundle size? And why does the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://tripleodeon.com">me</a> in API design, minification, and documentation. But now it has taken on a life of its own, and has grown beyond my wildest expectations.</p><p>It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it as much as I do building it!</p></section><section id="story"><h2 id="the-story">The story</h2><a href="https://youtu.be/hXL7OkW-Prk?t=1232" target="_blank"><img src="https://tinybase.org/youtube.webp"></a></section>
|
|
295
|
+
<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>5.3kB</em> to your app. Incrementally add the other modules as you need more functionality, or get it all for <em>12.7kB</em>.</p><p>The optional <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just <em>4.6kB</em>, the ui-react-dom components are another <em>2.5kB</em>, and everything is super fast. Life's easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured and packaged in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th> </th><th>Minified .js.gz</th><th>Source .js</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">tinybase/store</a> (minimal)</th><td>5.3kB</td><td>52.5kB</td></tr><tr><th class="right">tinybase (complete)</th><td>12.7kB</td><td>130.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react/">ui-react</a></th><td>4.6kB</td><td>48.3kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/ui-react-dom/">ui-react-dom</a></th><td>2.5kB</td><td>20.4kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible for you to get your TinyBase-powered app up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>2,380</td><td>2,380</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>2,567</td><td>2,567</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>1,006</td><td>1,006</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>951</td><td>951</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">6,851</td></tr><tr><th class="right">Assertions</th><td colspan="3">32,074</td></tr></tbody></table></div><hr><section id="sponsors"><h2 id="proud-to-be-sponsored-by">Proud to be sponsored by:</h2><a href="https://github.com/cpojer" target="_blank"><img title="cpojer" src="https://github.com/cpojer.png?size=48" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/beekeeb" target="_blank"><img title="beekeeb" src="https://github.com/beekeeb.png?size=48" width="48" height="48"></a><a href="https://github.com/cancelself" target="_blank"><img title="cancelself" src="https://github.com/cancelself.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a><a href="https://github.com/arpitBhalla" target="_blank"><img title="arpitBhalla" src="https://github.com/arpitBhalla.png?size=48" width="48" height="48"></a></section><section id="users"><h2 id="excited-to-be-used-by">Excited to be used by:</h2><a href="https://github.com/Apocalypsor" target="_blank"><img title="Apocalypsor" src="https://github.com/Apocalypsor.png?size=48" width="48" height="48"></a><a href="https://github.com/brentvatne" target="_blank"><img title="brentvatne" src="https://github.com/brentvatne.png?size=48" width="48" height="48"></a><a href="https://github.com/byCedric" target="_blank"><img title="byCedric" src="https://github.com/byCedric.png?size=48" width="48" height="48"></a><a href="https://github.com/circadian-risk" target="_blank"><img title="circadian-risk" src="https://github.com/circadian-risk.png?size=48" width="48" height="48"></a><a href="https://github.com/cpojer" target="_blank"><img title="cpojer" src="https://github.com/cpojer.png?size=48" width="48" height="48"></a><a href="https://github.com/cubecull" target="_blank"><img title="cubecull" src="https://github.com/cubecull.png?size=48" width="48" height="48"></a><a href="https://github.com/erwinkn" target="_blank"><img title="erwinkn" src="https://github.com/erwinkn.png?size=48" width="48" height="48"></a><a href="https://github.com/expo" target="_blank"><img title="expo" src="https://github.com/expo.png?size=48" width="48" height="48"></a><a href="https://github.com/ezra-en" target="_blank"><img title="ezra-en" src="https://github.com/ezra-en.png?size=48" width="48" height="48"></a><a href="https://github.com/fdfontes" target="_blank"><img title="fdfontes" src="https://github.com/fdfontes.png?size=48" width="48" height="48"></a><a href="https://github.com/feychenie" target="_blank"><img title="feychenie" src="https://github.com/feychenie.png?size=48" width="48" height="48"></a><a href="https://github.com/flaming-codes" target="_blank"><img title="flaming-codes" src="https://github.com/flaming-codes.png?size=48" width="48" height="48"></a><a href="https://github.com/fostertheweb" target="_blank"><img title="fostertheweb" src="https://github.com/fostertheweb.png?size=48" width="48" height="48"></a><a href="https://github.com/generates" target="_blank"><img title="generates" src="https://github.com/generates.png?size=48" width="48" height="48"></a><a href="https://github.com/Giulio987" target="_blank"><img title="Giulio987" src="https://github.com/Giulio987.png?size=48" width="48" height="48"></a><a href="https://github.com/itsdevcoffee" target="_blank"><img title="itsdevcoffee" src="https://github.com/itsdevcoffee.png?size=48" width="48" height="48"></a><a href="https://github.com/jaysc" target="_blank"><img title="jaysc" src="https://github.com/jaysc.png?size=48" width="48" height="48"></a><a href="https://github.com/jbolda" target="_blank"><img title="jbolda" src="https://github.com/jbolda.png?size=48" width="48" height="48"></a><a href="https://github.com/Kayoo-asso" target="_blank"><img title="Kayoo-asso" src="https://github.com/Kayoo-asso.png?size=48" width="48" height="48"></a><a href="https://github.com/kotofurumiya" target="_blank"><img title="kotofurumiya" src="https://github.com/kotofurumiya.png?size=48" width="48" height="48"></a><a href="https://github.com/Kudo" target="_blank"><img title="Kudo" src="https://github.com/Kudo.png?size=48" width="48" height="48"></a><a href="https://github.com/learn-anything" target="_blank"><img title="learn-anything" src="https://github.com/learn-anything.png?size=48" width="48" height="48"></a><a href="https://github.com/lluc" target="_blank"><img title="lluc" src="https://github.com/lluc.png?size=48" width="48" height="48"></a><a href="https://github.com/marksteve" target="_blank"><img title="marksteve" src="https://github.com/marksteve.png?size=48" width="48" height="48"></a><a href="https://github.com/miking-the-viking" target="_blank"><img title="miking-the-viking" src="https://github.com/miking-the-viking.png?size=48" width="48" height="48"></a><a href="https://github.com/mjamesderocher" target="_blank"><img title="mjamesderocher" src="https://github.com/mjamesderocher.png?size=48" width="48" height="48"></a><a href="https://github.com/mouktardev" target="_blank"><img title="mouktardev" src="https://github.com/mouktardev.png?size=48" width="48" height="48"></a><a href="https://github.com/nickmessing" target="_blank"><img title="nickmessing" src="https://github.com/nickmessing.png?size=48" width="48" height="48"></a><a href="https://github.com/nikitavoloboev" target="_blank"><img title="nikitavoloboev" src="https://github.com/nikitavoloboev.png?size=48" width="48" height="48"></a><a href="https://github.com/nkzw-tech" target="_blank"><img title="nkzw-tech" src="https://github.com/nkzw-tech.png?size=48" width="48" height="48"></a><a href="https://github.com/palerdot" target="_blank"><img title="palerdot" src="https://github.com/palerdot.png?size=48" width="48" height="48"></a><a href="https://github.com/PorcoRosso85" target="_blank"><img title="PorcoRosso85" src="https://github.com/PorcoRosso85.png?size=48" width="48" height="48"></a><a href="https://github.com/primodiumxyz" target="_blank"><img title="primodiumxyz" src="https://github.com/primodiumxyz.png?size=48" width="48" height="48"></a><a href="https://github.com/shaneosullivan" target="_blank"><img title="shaneosullivan" src="https://github.com/shaneosullivan.png?size=48" width="48" height="48"></a><a href="https://github.com/sudo-self" target="_blank"><img title="sudo-self" src="https://github.com/sudo-self.png?size=48" width="48" height="48"></a><a href="https://github.com/SuperSonicHub1" target="_blank"><img title="SuperSonicHub1" src="https://github.com/SuperSonicHub1.png?size=48" width="48" height="48"></a><a href="https://github.com/threepointone" target="_blank"><img title="threepointone" src="https://github.com/threepointone.png?size=48" width="48" height="48"></a><a href="https://github.com/uptonking" target="_blank"><img title="uptonking" src="https://github.com/uptonking.png?size=48" width="48" height="48"></a><a href="https://github.com/ViktorZhurbin" target="_blank"><img title="ViktorZhurbin" src="https://github.com/ViktorZhurbin.png?size=48" width="48" height="48"></a><a href="https://github.com/WonderPanda" target="_blank"><img title="WonderPanda" src="https://github.com/WonderPanda.png?size=48" width="48" height="48"></a></section><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section id="about"><h2 id="about">About</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Or sacrifice features for bundle size? And why does the cloud do all the work <a href="https://localfirstweb.dev/" target="_blank">anyway</a>?</p><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://tripleodeon.com">me</a> in API design, minification, and documentation. But now it has taken on a life of its own, and has grown beyond my wildest expectations.</p><p>It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it as much as I do building it!</p></section><section id="story"><h2 id="the-story">The story</h2><a href="https://youtu.be/hXL7OkW-Prk?t=1232" target="_blank"><img src="https://tinybase.org/youtube.webp"></a></section>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,n=(e,n,o)=>t(e)?null==o?void 0:o():n(e),o=e=>Array.isArray(e),r=e=>{throw Error(e)},l=Object,i=e=>l.getPrototypeOf(e),a=l.entries,s=l.keys,u=l.freeze,d=(e,t)=>n(e,(e=>e[t])),
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,n=(e,n,o)=>t(e)?null==o?void 0:o():n(e),o=e=>Array.isArray(e),r=e=>{throw Error(e)},l=Object,i=e=>l.getPrototypeOf(e),a=l.entries,s=l.keys,u=l.freeze,d=(e=[])=>l.fromEntries(e),c=(e,t)=>n(e,(e=>e[t])),v=(e,t)=>t in e,y=(e,t)=>(delete e[t],e),f=(e,t)=>((e,t)=>e.map(t))(a(e),(([e,n])=>t(n,e))),p=e=>s(e).length,h=e=>(e=>!t(e)&&n(i(e),(e=>e==l.prototype||t(i(e))),(()=>!0)))(e)&&0==p(e),g=(e,t,n)=>(v(e,t)||(e[t]=n()),e[t]),b=e=>new Map(e),m=(e,t)=>null==e?void 0:e.get(t),A=(e,n,o)=>{return t(o)?(l=n,null==(r=e)||r.delete(l),e):null==e?void 0:e.set(n,o);var r,l},C=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||A(e,t,n()),m(e,t)};var P=Object.defineProperty,w=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,x=(e,t,n)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const L=b(),M=b();var T=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(e,n,o,r)=>{const l=t(n)?e:g(e,n,(()=>({})));let i;return f(o,((e,t)=>{r(l,t,e)&&(i=1)})),f(l,((e,t)=>{v(o,t)||(y(l,t),i=1)})),!t(n)&&h(l)&&y(e,n),i};e.createAutomergePersister=(e,l,i="tinybase",a)=>(l.change((e=>g(e,i,d))),((e,l,i,a,s,d,c,v={},y=[])=>{let f,p,g,b=0,P=0,T=0;C(L,y,(()=>0)),C(M,y,(()=>[]));const[D,E,k,z,B]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:r("Store type not supported by this Persister"))(c,e),F=t=>{(D&&o(null==t?void 0:t[0])?1===(null==t?void 0:t[2])?e.applyMergeableChanges:e.setMergeableContent:1===(null==t?void 0:t[2])?e.applyChanges:e.setContent)(t)},H=e=>j(void 0,null,(function*(){return 2!=b&&(b=1,P++,yield J((()=>j(void 0,null,(function*(){try{const e=yield l();o(e)?F(e):r("Content is not an array "+e)}catch(t){null==d||d(t),e&&B(e)}b=0}))))),K})),I=()=>(p&&(s(p),p=void 0),K),q=e=>j(void 0,null,(function*(){return 1!=b&&(b=2,T++,yield J((()=>j(void 0,null,(function*(){try{yield i(E,e)}catch(e){null==d||d(e)}b=0}))))),K})),G=()=>(n(g,e.delListener),g=void 0,K),J=(...e)=>j(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(m(M,y),...e),yield j(void 0,null,(function*(){if(!m(L,y)){for(A(L,y,1);!t((e=m(M,y),f=e.shift()));)try{yield f()}catch(e){null==d||d(e)}A(L,y,0)}var e})),K})),K=((e,t)=>{for(var n in t||(t={}))O.call(t,n)&&x(e,n,t[n]);if(w)for(var n of w(t))S.call(t,n)&&x(e,n,t[n]);return e})({load:H,startAutoLoad:e=>j(void 0,null,(function*(){yield I().load(e);try{p=a(((e,t)=>j(void 0,null,(function*(){t||e?2!=b&&(b=1,P++,F(null!=t?t:e),b=0):yield H()}))))}catch(e){null==d||d(e)}return K})),stopAutoLoad:I,isAutoLoading:()=>!t(p),save:q,startAutoSave:()=>j(void 0,null,(function*(){return yield G().save(),g=e.addDidFinishTransactionListener((()=>{const e=k();z(e)&&q(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!t(g),schedule:J,getStore:()=>e,destroy:()=>(m(M,y).splice(0,void 0),I().stopAutoSave()),getStats:()=>({loads:P,saves:T})},v);return u(K)})(e,(()=>T(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((e,o)=>T(void 0,null,(function*(){return l.change((r=>((e,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(e,o);const[i,a]=D(e,o),s=()=>{u=1};let u=1;if(n(l,(([e,o])=>{u=0,f(e,((e,o)=>u?0:t(e)?y(i,o):n(i[o],(o=>f(e,((e,r)=>u?0:t(e)?y(o,r):n(c(o,r),(n=>f(e,((e,o)=>t(e)?y(n,o):n[o]=e))),s)))),s))),f(o,((e,n)=>u?0:t(e)?y(a,n):a[n]=e))})),u){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,e,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}))},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterAutomerge={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,n=(e,n,o)=>t(e)?null==o?void 0:o():n(e),o=e=>Array.isArray(e),r=e=>{throw Error(e)},l=Object,i=e=>l.getPrototypeOf(e),a=l.entries,s=l.keys,u=l.freeze,d=(e,t)=>n(e,(e=>e[t])),
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,n=(e,n,o)=>t(e)?null==o?void 0:o():n(e),o=e=>Array.isArray(e),r=e=>{throw Error(e)},l=Object,i=e=>l.getPrototypeOf(e),a=l.entries,s=l.keys,u=l.freeze,d=(e=[])=>l.fromEntries(e),c=(e,t)=>n(e,(e=>e[t])),v=(e,t)=>t in e,y=(e,t)=>(delete e[t],e),f=(e,t)=>((e,t)=>e.map(t))(a(e),(([e,n])=>t(n,e))),p=e=>s(e).length,h=e=>(e=>!t(e)&&n(i(e),(e=>e==l.prototype||t(i(e))),(()=>!0)))(e)&&0==p(e),g=(e,t,n)=>(v(e,t)||(e[t]=n()),e[t]),b=e=>new Map(e),m=(e,t)=>null==e?void 0:e.get(t),A=(e,n,o)=>{return t(o)?(l=n,null==(r=e)||r.delete(l),e):null==e?void 0:e.set(n,o);var r,l},C=(e,t,n,o)=>{var r,l,i;return l=t,null!=(i=null==(r=e)?void 0:r.has(l))&&i||A(e,t,n()),m(e,t)};var P=Object.defineProperty,w=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,x=(e,t,n)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,j=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const L=b(),M=b();var T=(e,t,n)=>new Promise(((o,r)=>{var l=e=>{try{a(n.next(e))}catch(e){r(e)}},i=e=>{try{a(n.throw(e))}catch(e){r(e)}},a=e=>e.done?o(e.value):Promise.resolve(e.value).then(l,i);a((n=n.apply(e,t)).next())}));const D=(e,t)=>[e[t].t,e[t].v],E=(e,n,o,r)=>{const l=t(n)?e:g(e,n,(()=>({})));let i;return f(o,((e,t)=>{r(l,t,e)&&(i=1)})),f(l,((e,t)=>{v(o,t)||(y(l,t),i=1)})),!t(n)&&h(l)&&y(e,n),i};e.createAutomergePersister=(e,l,i="tinybase",a)=>(l.change((e=>g(e,i,d))),((e,l,i,a,s,d,c,v={},y=[])=>{let f,p,g,b=0,P=0,T=0;C(L,y,(()=>0)),C(M,y,(()=>[]));const[D,E,k,z,B]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!h(e)||!h(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!h(e)||!h(t),t.setContent]:r("Store type not supported by this Persister"))(c,e),F=t=>{(D&&o(null==t?void 0:t[0])?1===(null==t?void 0:t[2])?e.applyMergeableChanges:e.setMergeableContent:1===(null==t?void 0:t[2])?e.applyChanges:e.setContent)(t)},H=e=>j(void 0,null,(function*(){return 2!=b&&(b=1,P++,yield J((()=>j(void 0,null,(function*(){try{const e=yield l();o(e)?F(e):r("Content is not an array "+e)}catch(t){null==d||d(t),e&&B(e)}b=0}))))),K})),I=()=>(p&&(s(p),p=void 0),K),q=e=>j(void 0,null,(function*(){return 1!=b&&(b=2,T++,yield J((()=>j(void 0,null,(function*(){try{yield i(E,e)}catch(e){null==d||d(e)}b=0}))))),K})),G=()=>(n(g,e.delListener),g=void 0,K),J=(...e)=>j(void 0,null,(function*(){return((e,...t)=>{e.push(...t)})(m(M,y),...e),yield j(void 0,null,(function*(){if(!m(L,y)){for(A(L,y,1);!t((e=m(M,y),f=e.shift()));)try{yield f()}catch(e){null==d||d(e)}A(L,y,0)}var e})),K})),K=((e,t)=>{for(var n in t||(t={}))O.call(t,n)&&x(e,n,t[n]);if(w)for(var n of w(t))S.call(t,n)&&x(e,n,t[n]);return e})({load:H,startAutoLoad:e=>j(void 0,null,(function*(){yield I().load(e);try{p=a(((e,t)=>j(void 0,null,(function*(){t||e?2!=b&&(b=1,P++,F(null!=t?t:e),b=0):yield H()}))))}catch(e){null==d||d(e)}return K})),stopAutoLoad:I,isAutoLoading:()=>!t(p),save:q,startAutoSave:()=>j(void 0,null,(function*(){return yield G().save(),g=e.addDidFinishTransactionListener((()=>{const e=k();z(e)&&q(e)})),K})),stopAutoSave:G,isAutoSaving:()=>!t(g),schedule:J,getStore:()=>e,destroy:()=>(m(M,y).splice(0,void 0),I().stopAutoSave()),getStats:()=>({loads:P,saves:T})},v);return u(K)})(e,(()=>T(void 0,null,(function*(){const e=yield l.doc();return 2==p(null==e?void 0:e[i])?D(e,i):void 0}))),((e,o)=>T(void 0,null,(function*(){return l.change((r=>((e,o,r,l)=>{((e,t)=>{h(e[t])&&(e[t]={t:{},v:{}})})(e,o);const[i,a]=D(e,o),s=()=>{u=1};let u=1;if(n(l,(([e,o])=>{u=0,f(e,((e,o)=>u?0:t(e)?y(i,o):n(i[o],(o=>f(e,((e,r)=>u?0:t(e)?y(o,r):n(c(o,r),(n=>f(e,((e,o)=>t(e)?y(n,o):n[o]=e))),s)))),s))),f(o,((e,n)=>u?0:t(e)?y(a,n):a[n]=e))})),u){const[e,t]=r();E(i,void 0,e,((e,t,n)=>E(i,t,n,((e,t,n)=>E(e,t,n,((e,t,n)=>{if(c(e,t)!==n)return e[t]=n,1})))))),E(a,void 0,t,((e,t,n)=>{c(a,t)!==n&&(a[t]=n)}))}})(r,i,e,o)))}))),(e=>{const t=({doc:t})=>e(D(t,i));return l.on("change",t),t}),(e=>{l.removeListener("change",e)}),a,1,{getDocHandle:()=>l}))},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterAutomerge={});
|
|
Binary file
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
);
|
|
46
46
|
const objIds = object.keys;
|
|
47
47
|
const objFreeze = object.freeze;
|
|
48
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
48
49
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
49
50
|
const objHas = (obj, id) => id in obj;
|
|
50
51
|
const objDel = (obj, id) => {
|
|
@@ -458,7 +459,7 @@
|
|
|
458
459
|
docObjName = TINYBASE,
|
|
459
460
|
onIgnoredError,
|
|
460
461
|
) => {
|
|
461
|
-
docHandle.change((doc) => (doc
|
|
462
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
462
463
|
const getPersisted = () =>
|
|
463
464
|
__async(void 0, null, function* () {
|
|
464
465
|
const doc = yield docHandle.doc();
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
);
|
|
46
46
|
const objIds = object.keys;
|
|
47
47
|
const objFreeze = object.freeze;
|
|
48
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
48
49
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
49
50
|
const objHas = (obj, id) => id in obj;
|
|
50
51
|
const objDel = (obj, id) => {
|
|
@@ -458,7 +459,7 @@
|
|
|
458
459
|
docObjName = TINYBASE,
|
|
459
460
|
onIgnoredError,
|
|
460
461
|
) => {
|
|
461
|
-
docHandle.change((doc) => (doc
|
|
462
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
462
463
|
const getPersisted = () =>
|
|
463
464
|
__async(void 0, null, function* () {
|
|
464
465
|
const doc = yield docHandle.doc();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,a=(e,a,n)=>t(e)?n?.():a(e),n=e=>Array.isArray(e),s=e=>{throw Error(e)},o=Object,r=e=>o.getPrototypeOf(e),i=o.entries,c=o.keys,d=o.freeze,y=(e,t)=>a(e,(e=>e[t])),
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,a=(e,a,n)=>t(e)?n?.():a(e),n=e=>Array.isArray(e),s=e=>{throw Error(e)},o=Object,r=e=>o.getPrototypeOf(e),i=o.entries,c=o.keys,d=o.freeze,y=(e=[])=>o.fromEntries(e),g=(e,t)=>a(e,(e=>e[t])),l=(e,t)=>t in e,u=(e,t)=>(delete e[t],e),p=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,a])=>t(a,e))),h=e=>c(e).length,f=e=>(e=>!t(e)&&a(r(e),(e=>e==o.prototype||t(r(e))),(()=>!0)))(e)&&0==h(e),v=(e,t,a)=>(l(e,t)||(e[t]=a()),e[t]),w=e=>new Map(e),b=(e,t)=>e?.get(t),A=(e,a,n)=>{return t(n)?(s=e,o=a,s?.delete(o),e):e?.set(a,n);var s,o},C=(e,t,a,n)=>{var s,o;return s=e,o=t,s?.has(o)||A(e,t,a()),b(e,t)},m=w(),S=w(),L=(e,t)=>[e[t].t,e[t].v],M=(e,a,n,s)=>{const o=t(a)?e:v(e,a,(()=>({})));let r;return p(n,((e,t)=>{s(o,t,e)&&(r=1)})),p(o,((e,t)=>{l(n,t)||(u(o,t),r=1)})),!t(a)&&f(o)&&u(e,a),r};e.createAutomergePersister=(e,o,r="tinybase",i)=>(o.change((e=>v(e,r,y))),((e,o,r,i,c,y,g,l={},u=[])=>{let p,h,v,w=0,L=0,M=0;C(m,u,(()=>0)),C(S,u,(()=>[]));const[T,P,x,D,j]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!f(e)||!f(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!f(e)||!f(t),t.setContent]:s("Store type not supported by this Persister"))(g,e),E=t=>{(T&&n(t?.[0])?1===t?.[2]?e.applyMergeableChanges:e.setMergeableContent:1===t?.[2]?e.applyChanges:e.setContent)(t)},O=async e=>(2!=w&&(w=1,L++,await F((async()=>{try{const e=await o();n(e)?E(e):s("Content is not an array "+e)}catch(t){y?.(t),e&&j(e)}w=0}))),H),k=()=>(h&&(c(h),h=void 0),H),z=async e=>(1!=w&&(w=2,M++,await F((async()=>{try{await r(P,e)}catch(e){y?.(e)}w=0}))),H),B=()=>(a(v,e.delListener),v=void 0,H),F=async(...e)=>(((e,...t)=>{e.push(...t)})(b(S,u),...e),await(async()=>{if(!b(m,u)){for(A(m,u,1);!t((e=b(S,u),p=e.shift()));)try{await p()}catch(e){y?.(e)}A(m,u,0)}var e})(),H),H={load:O,startAutoLoad:async e=>{await k().load(e);try{h=i((async(e,t)=>{t||e?2!=w&&(w=1,L++,E(t??e),w=0):await O()}))}catch(e){y?.(e)}return H},stopAutoLoad:k,isAutoLoading:()=>!t(h),save:z,startAutoSave:async()=>(await B().save(),v=e.addDidFinishTransactionListener((()=>{const e=x();D(e)&&z(e)})),H),stopAutoSave:B,isAutoSaving:()=>!t(v),schedule:F,getStore:()=>e,destroy:()=>(b(S,u).splice(0,void 0),k().stopAutoSave()),getStats:()=>({loads:L,saves:M}),...l};return d(H)})(e,(async()=>{const e=await o.doc();return 2==h(e?.[r])?L(e,r):void 0}),(async(e,n)=>o.change((s=>((e,n,s,o)=>{((e,t)=>{f(e[t])&&(e[t]={t:{},v:{}})})(e,n);const[r,i]=L(e,n),c=()=>{d=1};let d=1;if(a(o,(([e,n])=>{d=0,p(e,((e,n)=>d?0:t(e)?u(r,n):a(r[n],(n=>p(e,((e,s)=>d?0:t(e)?u(n,s):a(g(n,s),(a=>p(e,((e,n)=>t(e)?u(a,n):a[n]=e))),c)))),c))),p(n,((e,a)=>d?0:t(e)?u(i,a):i[a]=e))})),d){const[e,t]=s();M(r,void 0,e,((e,t,a)=>M(r,t,a,((e,t,a)=>M(e,t,a,((e,t,a)=>{if(g(e,t)!==a)return e[t]=a,1})))))),M(i,void 0,t,((e,t,a)=>{g(i,t)!==a&&(i[t]=a)}))}})(s,r,e,n)))),(e=>{const t=({doc:t})=>e(L(t,r));return o.on("change",t),t}),(e=>{o.removeListener("change",e)}),i,1,{getDocHandle:()=>o}))},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterAutomerge={});
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,a=(e,a,n)=>t(e)?n?.():a(e),n=e=>Array.isArray(e),s=e=>{throw Error(e)},o=Object,r=e=>o.getPrototypeOf(e),i=o.entries,c=o.keys,d=o.freeze,y=(e,t)=>a(e,(e=>e[t])),
|
|
1
|
+
var e,t;e=this,t=function(e){"use strict";const t=e=>null==e,a=(e,a,n)=>t(e)?n?.():a(e),n=e=>Array.isArray(e),s=e=>{throw Error(e)},o=Object,r=e=>o.getPrototypeOf(e),i=o.entries,c=o.keys,d=o.freeze,y=(e=[])=>o.fromEntries(e),g=(e,t)=>a(e,(e=>e[t])),l=(e,t)=>t in e,u=(e,t)=>(delete e[t],e),p=(e,t)=>((e,t)=>e.map(t))(i(e),(([e,a])=>t(a,e))),h=e=>c(e).length,f=e=>(e=>!t(e)&&a(r(e),(e=>e==o.prototype||t(r(e))),(()=>!0)))(e)&&0==h(e),v=(e,t,a)=>(l(e,t)||(e[t]=a()),e[t]),w=e=>new Map(e),b=(e,t)=>e?.get(t),A=(e,a,n)=>{return t(n)?(s=e,o=a,s?.delete(o),e):e?.set(a,n);var s,o},C=(e,t,a,n)=>{var s,o;return s=e,o=t,s?.has(o)||A(e,t,a()),b(e,t)},m=w(),S=w(),L=(e,t)=>[e[t].t,e[t].v],M=(e,a,n,s)=>{const o=t(a)?e:v(e,a,(()=>({})));let r;return p(n,((e,t)=>{s(o,t,e)&&(r=1)})),p(o,((e,t)=>{l(n,t)||(u(o,t),r=1)})),!t(a)&&f(o)&&u(e,a),r};e.createAutomergePersister=(e,o,r="tinybase",i)=>(o.change((e=>v(e,r,y))),((e,o,r,i,c,y,g,l={},u=[])=>{let p,h,v,w=0,L=0,M=0;C(m,u,(()=>0)),C(S,u,(()=>[]));const[T,P,x,D,j]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!f(e)||!f(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!f(e)||!f(t),t.setContent]:s("Store type not supported by this Persister"))(g,e),E=t=>{(T&&n(t?.[0])?1===t?.[2]?e.applyMergeableChanges:e.setMergeableContent:1===t?.[2]?e.applyChanges:e.setContent)(t)},O=async e=>(2!=w&&(w=1,L++,await F((async()=>{try{const e=await o();n(e)?E(e):s("Content is not an array "+e)}catch(t){y?.(t),e&&j(e)}w=0}))),H),k=()=>(h&&(c(h),h=void 0),H),z=async e=>(1!=w&&(w=2,M++,await F((async()=>{try{await r(P,e)}catch(e){y?.(e)}w=0}))),H),B=()=>(a(v,e.delListener),v=void 0,H),F=async(...e)=>(((e,...t)=>{e.push(...t)})(b(S,u),...e),await(async()=>{if(!b(m,u)){for(A(m,u,1);!t((e=b(S,u),p=e.shift()));)try{await p()}catch(e){y?.(e)}A(m,u,0)}var e})(),H),H={load:O,startAutoLoad:async e=>{await k().load(e);try{h=i((async(e,t)=>{t||e?2!=w&&(w=1,L++,E(t??e),w=0):await O()}))}catch(e){y?.(e)}return H},stopAutoLoad:k,isAutoLoading:()=>!t(h),save:z,startAutoSave:async()=>(await B().save(),v=e.addDidFinishTransactionListener((()=>{const e=x();D(e)&&z(e)})),H),stopAutoSave:B,isAutoSaving:()=>!t(v),schedule:F,getStore:()=>e,destroy:()=>(b(S,u).splice(0,void 0),k().stopAutoSave()),getStats:()=>({loads:L,saves:M}),...l};return d(H)})(e,(async()=>{const e=await o.doc();return 2==h(e?.[r])?L(e,r):void 0}),(async(e,n)=>o.change((s=>((e,n,s,o)=>{((e,t)=>{f(e[t])&&(e[t]={t:{},v:{}})})(e,n);const[r,i]=L(e,n),c=()=>{d=1};let d=1;if(a(o,(([e,n])=>{d=0,p(e,((e,n)=>d?0:t(e)?u(r,n):a(r[n],(n=>p(e,((e,s)=>d?0:t(e)?u(n,s):a(g(n,s),(a=>p(e,((e,n)=>t(e)?u(a,n):a[n]=e))),c)))),c))),p(n,((e,a)=>d?0:t(e)?u(i,a):i[a]=e))})),d){const[e,t]=s();M(r,void 0,e,((e,t,a)=>M(r,t,a,((e,t,a)=>M(e,t,a,((e,t,a)=>{if(g(e,t)!==a)return e[t]=a,1})))))),M(i,void 0,t,((e,t,a)=>{g(i,t)!==a&&(i[t]=a)}))}})(s,r,e,n)))),(e=>{const t=({doc:t})=>e(L(t,r));return o.on("change",t),t}),(e=>{o.removeListener("change",e)}),i,1,{getDocHandle:()=>o}))},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterAutomerge={});
|
|
Binary file
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
);
|
|
42
42
|
const objIds = object.keys;
|
|
43
43
|
const objFreeze = object.freeze;
|
|
44
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
44
45
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
45
46
|
const objHas = (obj, id) => id in obj;
|
|
46
47
|
const objDel = (obj, id) => {
|
|
@@ -361,7 +362,7 @@
|
|
|
361
362
|
docObjName = TINYBASE,
|
|
362
363
|
onIgnoredError,
|
|
363
364
|
) => {
|
|
364
|
-
docHandle.change((doc) => (doc
|
|
365
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
365
366
|
const getPersisted = async () => {
|
|
366
367
|
const doc = await docHandle.doc();
|
|
367
368
|
return objSize(doc?.[docObjName]) == 2
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
);
|
|
42
42
|
const objIds = object.keys;
|
|
43
43
|
const objFreeze = object.freeze;
|
|
44
|
+
const objNew = (entries = []) => object.fromEntries(entries);
|
|
44
45
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
45
46
|
const objHas = (obj, id) => id in obj;
|
|
46
47
|
const objDel = (obj, id) => {
|
|
@@ -361,7 +362,7 @@
|
|
|
361
362
|
docObjName = TINYBASE,
|
|
362
363
|
onIgnoredError,
|
|
363
364
|
) => {
|
|
364
|
-
docHandle.change((doc) => (doc
|
|
365
|
+
docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
|
|
365
366
|
const getPersisted = async () => {
|
|
366
367
|
const doc = await docHandle.doc();
|
|
367
368
|
return objSize(doc?.[docObjName]) == 2
|