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.
- package/lib/checkpoints.d.ts +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +1 -1
- package/lib/debug/checkpoints.js +19 -7
- package/lib/debug/indexes.js +18 -7
- package/lib/debug/metrics.js +18 -7
- package/lib/debug/persisters.d.ts +1 -1
- package/lib/debug/queries.d.ts +93 -83
- package/lib/debug/queries.js +29 -29
- package/lib/debug/relationships.d.ts +1 -1
- package/lib/debug/relationships.js +18 -7
- package/lib/debug/store.js +42 -22
- package/lib/debug/tinybase.js +72 -51
- package/lib/debug/ui-react.d.ts +30 -9
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +1 -1
- package/lib/queries.d.ts +93 -83
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +1 -1
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +30 -9
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/package.json +20 -19
- package/readme.md +11 -11
package/lib/checkpoints.d.ts
CHANGED
package/lib/checkpoints.js
CHANGED
|
@@ -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,
|
|
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};
|
package/lib/checkpoints.js.gz
CHANGED
|
Binary file
|
package/lib/debug/checkpoints.js
CHANGED
|
@@ -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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
244
|
+
currentId = arrayShift(forwardIds);
|
|
233
245
|
updateStore(1, currentId);
|
|
234
246
|
checkpointsChanged = 1;
|
|
235
247
|
}
|
package/lib/debug/indexes.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
264
|
-
arrayPush(listenerPool, id);
|
|
265
|
-
}
|
|
276
|
+
releaseId(id);
|
|
266
277
|
return idOrNulls;
|
|
267
278
|
});
|
|
268
279
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
package/lib/debug/metrics.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
334
|
-
arrayPush(listenerPool, id);
|
|
335
|
-
}
|
|
346
|
+
releaseId(id);
|
|
336
347
|
return idOrNulls;
|
|
337
348
|
});
|
|
338
349
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|