tinybase 2.0.0-beta.3 → 2.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/checkpoints.d.ts +1 -1
  2. package/lib/checkpoints.js +1 -1
  3. package/lib/checkpoints.js.gz +0 -0
  4. package/lib/debug/checkpoints.d.ts +1 -1
  5. package/lib/debug/checkpoints.js +19 -7
  6. package/lib/debug/indexes.js +18 -7
  7. package/lib/debug/metrics.js +18 -7
  8. package/lib/debug/persisters.d.ts +1 -1
  9. package/lib/debug/queries.d.ts +93 -83
  10. package/lib/debug/queries.js +29 -29
  11. package/lib/debug/relationships.d.ts +1 -1
  12. package/lib/debug/relationships.js +18 -7
  13. package/lib/debug/store.js +42 -22
  14. package/lib/debug/tinybase.js +72 -51
  15. package/lib/debug/ui-react.d.ts +30 -9
  16. package/lib/indexes.js +1 -1
  17. package/lib/indexes.js.gz +0 -0
  18. package/lib/metrics.js +1 -1
  19. package/lib/metrics.js.gz +0 -0
  20. package/lib/persisters.d.ts +1 -1
  21. package/lib/queries.d.ts +93 -83
  22. package/lib/queries.js +1 -1
  23. package/lib/queries.js.gz +0 -0
  24. package/lib/relationships.d.ts +1 -1
  25. package/lib/relationships.js +1 -1
  26. package/lib/relationships.js.gz +0 -0
  27. package/lib/store.js +1 -1
  28. package/lib/store.js.gz +0 -0
  29. package/lib/tinybase.js +1 -1
  30. package/lib/tinybase.js.gz +0 -0
  31. package/lib/ui-react.d.ts +30 -9
  32. package/lib/umd/checkpoints.js +1 -1
  33. package/lib/umd/checkpoints.js.gz +0 -0
  34. package/lib/umd/indexes.js +1 -1
  35. package/lib/umd/indexes.js.gz +0 -0
  36. package/lib/umd/metrics.js +1 -1
  37. package/lib/umd/metrics.js.gz +0 -0
  38. package/lib/umd/queries.js +1 -1
  39. package/lib/umd/queries.js.gz +0 -0
  40. package/lib/umd/relationships.js +1 -1
  41. package/lib/umd/relationships.js.gz +0 -0
  42. package/lib/umd/store.js +1 -1
  43. package/lib/umd/store.js.gz +0 -0
  44. package/lib/umd/tinybase.js +1 -1
  45. package/lib/umd/tinybase.js.gz +0 -0
  46. package/package.json +20 -19
  47. package/readme.md +11 -11
@@ -159,7 +159,7 @@ export type CheckpointsListenerStats = {
159
159
  * ```
160
160
  * @see Relationships And Checkpoints guides
161
161
  * @see Todo App demos
162
- * @see TinyDraw demo
162
+ * @see Drawing demo
163
163
  * @category Checkpoints
164
164
  */
165
165
  export interface Checkpoints {
@@ -1 +1 @@
1
- const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),o=(e,...t)=>e.push(...t),s=e=>e.pop(),l=e=>null==e,c=(e,t,n)=>l(e)?n?.():t(e),i=(e,t)=>e?.has(t)??!1,a=e=>l(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),u=(e,t)=>e?.delete(t),h=e=>new Map(e),p=(e,t)=>e?.get(t),C=(e,t,n)=>l(n)?(u(e,t),e):e?.set(t,n),g=(e,t,n)=>(i(e,t)||C(e,t,n()),p(e,t)),k=(e,t,r,o,s=0)=>c((r?g:p)(e,t[s],s>n(t)-2?r:h),(l=>{if(s>n(t)-2)return o?.(l)&&C(e,t[s]),l;const c=k(l,t,r,o,s+1);return a(l)&&C(e,t[s]),c})),f=e=>new Set(e),v=e=>{let r,i=0;const g=[],v=h();return[(t,n,o)=>{r??=e();const l=s(g)??""+i++;var c,a;return C(v,l,[t,n,o]),c=k(n,o??[""],f),a=l,c?.add(a),l},(e,s,...l)=>t(((e,r=[""])=>{const s=[],l=(e,c)=>c==n(r)?o(s,e):null===r[c]?d(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(p(e,t),c+1)));return l(e,0),s})(e,s),(e=>d(e,(e=>p(v,e)[0](r,...s??[],...l))))),e=>c(p(v,e),(([,t,r])=>(k(t,r??[""],void 0,(t=>(u(t,e),a(t)?1:0))),C(v,e),n(g)<1e3&&o(g,e),r))),(e,o,s)=>c(p(v,e),(([e,,c=[]])=>{const i=(...a)=>{const d=n(a);d==n(c)?e(r,...a,...s(a)):l(c[d])?t(o[d](...a),(e=>i(...a,e))):i(...a,c[d])};i()}))]},L=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((u=>{let k,f,w,S=100,z=h(),E=1;const I=h(),M=h(),[b,j,x]=v((()=>Q)),y=h(),B=h(),F=[],O=[],T=(e,t)=>{E=0,u.transaction((()=>d(p(y,t),((t,n)=>d(t,((t,r)=>d(t,((t,o)=>((e,t,n,r,o)=>l(o)?e.delCell(t,n,r,!0):e.setCell(t,n,r,o))(u,n,r,o,t[e]))))))))),E=1},W=e=>{C(y,e),C(B,e),j(M,[e])},m=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),W),q=()=>m(F,n(F)-S),A=u.addCellListener(null,null,null,((e,t,n,r,l,i)=>{if(E){c(k,(()=>{o(F,k),q(),m(O),k=void 0,w=1}));const e=g(z,t,h),d=g(e,n,h),u=g(d,r,(()=>[i,void 0]));u[1]=l,u[0]===l&&a(C(d,r))&&a(C(e,n))&&a(C(z,t))&&(k=s(F),w=1),J()}})),D=(e="")=>(l(k)&&(k=""+f++,C(y,k,z),N(k,e),z=h(),w=1),k),G=()=>{r(F)||(O.unshift(D()),T(0,k),k=s(F),w=1)},H=()=>{r(O)||(o(F,k),k=O.shift(),T(1,k),w=1)},J=()=>{w&&(j(I),w=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&p(B,e)!==t&&(C(B,e,t),j(M,[e])),Q),P=e=>i(y,e),Q={setSize:e=>(S=e,q(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>u,getCheckpointIds:()=>[[...F],k,[...O]],forEachCheckpoint:e=>{return t=e,d(B,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>p(B,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(F,t)?G:e(O,t)?H:null;for(;!l(n)&&t!=k;)n();return J(),Q},addCheckpointIdsListener:e=>b(e,I),addCheckpointListener:(e,t)=>b(t,M,[e]),delListener:e=>(x(e),Q),clear:()=>(m(F),m(O),l(k)||W(k),k=void 0,f=0,K(),Q),destroy:()=>{u.delListener(A)},getListenerStats:()=>({})};return L(Q.clear())}));export{w as createCheckpoints};
1
+ const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),o=(e,...t)=>e.push(...t),s=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,i=(e,t,n)=>c(e)?n?.():t(e),d=(e,t)=>e?.has(t)??!1,a=e=>c(e)||0==(e=>e.size)(e),u=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n)=>(d(e,t)||g(e,t,n()),C(e,t)),f=(e,t,r,o,s=0)=>i((r?k:C)(e,t[s],s>n(t)-2?r:p),(l=>{if(s>n(t)-2)return o?.(l)&&g(e,t[s]),l;const c=f(l,t,r,o,s+1);return a(l)&&g(e,t[s]),c})),v=e=>new Set(e),L=/^\d+$/,w=e=>{let r;const[s,d]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&n(e)<1e3&&o(e,t)}]})(),k=p();return[(t,n,o)=>{r??=e();const l=s();var c,i;return g(k,l,[t,n,o]),c=f(n,o??[""],v),i=l,c?.add(i),l},(e,s,...l)=>t(((e,r=[""])=>{const s=[],l=(e,c)=>c==n(r)?o(s,e):null===r[c]?u(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(C(e,t),c+1)));return l(e,0),s})(e,s),(e=>u(e,(e=>C(k,e)[0](r,...s??[],...l))))),e=>i(C(k,e),(([,t,n])=>(f(t,n??[""],void 0,(t=>(h(t,e),a(t)?1:0))),g(k,e),d(e),n))),(e,o,s)=>i(C(k,e),(([e,,l=[]])=>{const i=(...d)=>{const a=n(d);a==n(l)?e(r,...d,...s(d)):c(l[a])?t(o[a](...d),(e=>i(...d,e))):i(...d,l[a])};i()}))]},S=Object.freeze,z=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((h=>{let f,v,L,z=100,E=p(),I=1;const M=p(),b=p(),[j,x,y]=w((()=>Q)),B=p(),F=p(),O=[],T=[],W=(e,t)=>{I=0,h.transaction((()=>u(C(B,t),((t,n)=>u(t,((t,r)=>u(t,((t,o)=>((e,t,n,r,o)=>c(o)?e.delCell(t,n,r,!0):e.setCell(t,n,r,o))(h,n,r,o,t[e]))))))))),I=1},$=e=>{g(B,e),g(F,e),x(b,[e])},m=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),$),q=()=>m(O,n(O)-z),A=h.addCellListener(null,null,null,((e,t,n,r,l,c)=>{if(I){i(f,(()=>{o(O,f),q(),m(T),f=void 0,L=1}));const e=k(E,t,p),d=k(e,n,p),u=k(d,r,(()=>[c,void 0]));u[1]=l,u[0]===l&&a(g(d,r))&&a(g(e,n))&&a(g(E,t))&&(f=s(O),L=1),J()}})),D=(e="")=>(c(f)&&(f=""+v++,g(B,f,E),N(f,e),E=p(),L=1),f),G=()=>{r(O)||(T.unshift(D()),W(0,f),f=s(O),L=1)},H=()=>{r(T)||(o(O,f),f=l(T),W(1,f),L=1)},J=()=>{L&&(x(M),L=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&C(F,e)!==t&&(g(F,e,t),x(b,[e])),Q),P=e=>d(B,e),Q={setSize:e=>(z=e,q(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...O],f,[...T]],forEachCheckpoint:e=>{return t=e,u(F,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>C(F,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(O,t)?G:e(T,t)?H:null;for(;!c(n)&&t!=f;)n();return J(),Q},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,t)=>j(t,b,[e]),delListener:e=>(y(e),Q),clear:()=>(m(O),m(T),c(f)||$(f),f=void 0,v=0,K(),Q),destroy:()=>{h.delListener(A)},getListenerStats:()=>({})};return S(Q.clear())}));export{z as createCheckpoints};
Binary file
@@ -159,7 +159,7 @@ export type CheckpointsListenerStats = {
159
159
  * ```
160
160
  * @see Relationships And Checkpoints guides
161
161
  * @see Todo App demos
162
- * @see TinyDraw demo
162
+ * @see Drawing demo
163
163
  * @category Checkpoints
164
164
  */
165
165
  export interface Checkpoints {
@@ -8,6 +8,7 @@ const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
8
8
  const arrayClear = (array, to) => array.splice(0, to);
9
9
  const arrayPush = (array, ...values) => array.push(...values);
10
10
  const arrayPop = (array) => array.pop();
11
+ const arrayShift = (array) => array.shift();
11
12
 
12
13
  const isUndefined = (thing) => thing == void 0;
13
14
  const ifNotUndefined = (value, then, otherwise) =>
@@ -70,6 +71,20 @@ const getCreateFunction = (getFunction) => {
70
71
  };
71
72
  };
72
73
 
74
+ const INTEGER = /^\d+$/;
75
+ const getPoolFunctions = () => {
76
+ const pool = [];
77
+ let nextId = 0;
78
+ return [
79
+ () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
80
+ (id) => {
81
+ if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
82
+ arrayPush(pool, id);
83
+ }
84
+ },
85
+ ];
86
+ };
87
+
73
88
  const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
74
89
  const leaves = [];
75
90
  const deep = (node, p) =>
@@ -83,12 +98,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
83
98
  };
84
99
  const getListenerFunctions = (getThing) => {
85
100
  let thing;
86
- let nextId = 0;
87
- const listenerPool = [];
101
+ const [getId, releaseId] = getPoolFunctions();
88
102
  const allListeners = mapNew();
89
103
  const addListener = (listener, idSetNode, path) => {
90
104
  thing ??= getThing();
91
- const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
105
+ const id = getId();
92
106
  mapSet(allListeners, id, [listener, idSetNode, path]);
93
107
  setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
94
108
  return id;
@@ -106,9 +120,7 @@ const getListenerFunctions = (getThing) => {
106
120
  return collIsEmpty(idSet) ? 1 : 0;
107
121
  });
108
122
  mapSet(allListeners, id);
109
- if (arrayLength(listenerPool) < 1e3) {
110
- arrayPush(listenerPool, id);
111
- }
123
+ releaseId(id);
112
124
  return idOrNulls;
113
125
  });
114
126
  const callListener = (id, idNullGetters, extraArgsGetter) =>
@@ -229,7 +241,7 @@ const createCheckpoints = getCreateFunction((store) => {
229
241
  const goForwardImpl = () => {
230
242
  if (!arrayIsEmpty(forwardIds)) {
231
243
  arrayPush(backwardIds, currentId);
232
- currentId = forwardIds.shift();
244
+ currentId = arrayShift(forwardIds);
233
245
  updateStore(1, currentId);
234
246
  checkpointsChanged = 1;
235
247
  }
@@ -14,7 +14,7 @@ const arrayLength = (array) => array.length;
14
14
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
15
15
  const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
16
16
  const arrayPush = (array, ...values) => array.push(...values);
17
- const arrayPop = (array) => array.pop();
17
+ const arrayShift = (array) => array.shift();
18
18
 
19
19
  const isUndefined = (thing) => thing == void 0;
20
20
  const ifNotUndefined = (value, then, otherwise) =>
@@ -224,6 +224,20 @@ const getCreateFunction = (getFunction) => {
224
224
 
225
225
  const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
226
226
 
227
+ const INTEGER = /^\d+$/;
228
+ const getPoolFunctions = () => {
229
+ const pool = [];
230
+ let nextId = 0;
231
+ return [
232
+ () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
233
+ (id) => {
234
+ if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
235
+ arrayPush(pool, id);
236
+ }
237
+ },
238
+ ];
239
+ };
240
+
227
241
  const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
228
242
  const leaves = [];
229
243
  const deep = (node, p) =>
@@ -237,12 +251,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
237
251
  };
238
252
  const getListenerFunctions = (getThing) => {
239
253
  let thing;
240
- let nextId = 0;
241
- const listenerPool = [];
254
+ const [getId, releaseId] = getPoolFunctions();
242
255
  const allListeners = mapNew();
243
256
  const addListener = (listener, idSetNode, path) => {
244
257
  thing ??= getThing();
245
- const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
258
+ const id = getId();
246
259
  mapSet(allListeners, id, [listener, idSetNode, path]);
247
260
  setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
248
261
  return id;
@@ -260,9 +273,7 @@ const getListenerFunctions = (getThing) => {
260
273
  return collIsEmpty(idSet) ? 1 : 0;
261
274
  });
262
275
  mapSet(allListeners, id);
263
- if (arrayLength(listenerPool) < 1e3) {
264
- arrayPush(listenerPool, id);
265
- }
276
+ releaseId(id);
266
277
  return idOrNulls;
267
278
  });
268
279
  const callListener = (id, idNullGetters, extraArgsGetter) =>
@@ -13,7 +13,7 @@ const arrayLength = (array) => array.length;
13
13
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
14
14
  const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
15
15
  const arrayPush = (array, ...values) => array.push(...values);
16
- const arrayPop = (array) => array.pop();
16
+ const arrayShift = (array) => array.shift();
17
17
 
18
18
  const mathMax = Math.max;
19
19
  const mathMin = Math.min;
@@ -294,6 +294,20 @@ const getCreateFunction = (getFunction) => {
294
294
  };
295
295
  };
296
296
 
297
+ const INTEGER = /^\d+$/;
298
+ const getPoolFunctions = () => {
299
+ const pool = [];
300
+ let nextId = 0;
301
+ return [
302
+ () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
303
+ (id) => {
304
+ if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
305
+ arrayPush(pool, id);
306
+ }
307
+ },
308
+ ];
309
+ };
310
+
297
311
  const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
298
312
  const leaves = [];
299
313
  const deep = (node, p) =>
@@ -307,12 +321,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
307
321
  };
308
322
  const getListenerFunctions = (getThing) => {
309
323
  let thing;
310
- let nextId = 0;
311
- const listenerPool = [];
324
+ const [getId, releaseId] = getPoolFunctions();
312
325
  const allListeners = mapNew();
313
326
  const addListener = (listener, idSetNode, path) => {
314
327
  thing ??= getThing();
315
- const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
328
+ const id = getId();
316
329
  mapSet(allListeners, id, [listener, idSetNode, path]);
317
330
  setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
318
331
  return id;
@@ -330,9 +343,7 @@ const getListenerFunctions = (getThing) => {
330
343
  return collIsEmpty(idSet) ? 1 : 0;
331
344
  });
332
345
  mapSet(allListeners, id);
333
- if (arrayLength(listenerPool) < 1e3) {
334
- arrayPush(listenerPool, id);
335
- }
346
+ releaseId(id);
336
347
  return idOrNulls;
337
348
  });
338
349
  const callListener = (id, idNullGetters, extraArgsGetter) =>
@@ -22,7 +22,7 @@
22
22
  * @see Persisting Data guide
23
23
  * @see Countries demo
24
24
  * @see Todo App demos
25
- * @see TinyDraw demo
25
+ * @see Drawing demo
26
26
  * @packageDocumentation
27
27
  * @module persisters
28
28
  */