tinybase 0.9.3 → 1.0.2

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 (60) hide show
  1. package/LICENSE +1 -1
  2. package/lib/debug/checkpoints.d.ts +3 -0
  3. package/lib/debug/common.d.ts +56 -0
  4. package/lib/debug/indexes.d.ts +7 -58
  5. package/lib/debug/metrics.d.ts +6 -2
  6. package/lib/debug/persisters.d.ts +15 -8
  7. package/lib/debug/relationships.d.ts +3 -1
  8. package/lib/debug/store.d.ts +13 -10
  9. package/lib/debug/tinybase.js +16 -8
  10. package/lib/debug/ui-react.d.ts +29 -2
  11. package/lib/debug/ui-react.js +8 -2
  12. package/package.json +28 -12
  13. package/readme.md +2 -2
  14. package/lib/checkpoints.d.ts +0 -876
  15. package/lib/checkpoints.js +0 -1
  16. package/lib/checkpoints.js.gz +0 -0
  17. package/lib/common.d.ts +0 -59
  18. package/lib/debug/checkpoints.js +0 -326
  19. package/lib/debug/indexes.js +0 -390
  20. package/lib/debug/metrics.js +0 -391
  21. package/lib/debug/persisters.js +0 -191
  22. package/lib/debug/relationships.js +0 -418
  23. package/lib/debug/store.js +0 -725
  24. package/lib/indexes.d.ts +0 -829
  25. package/lib/indexes.js +0 -1
  26. package/lib/indexes.js.gz +0 -0
  27. package/lib/metrics.d.ts +0 -753
  28. package/lib/metrics.js +0 -1
  29. package/lib/metrics.js.gz +0 -0
  30. package/lib/persisters.d.ts +0 -704
  31. package/lib/persisters.js +0 -1
  32. package/lib/persisters.js.gz +0 -0
  33. package/lib/relationships.d.ts +0 -1114
  34. package/lib/relationships.js +0 -1
  35. package/lib/relationships.js.gz +0 -0
  36. package/lib/store.d.ts +0 -2503
  37. package/lib/store.js +0 -1
  38. package/lib/store.js.gz +0 -0
  39. package/lib/tinybase.d.ts +0 -13
  40. package/lib/tinybase.js +0 -1
  41. package/lib/tinybase.js.gz +0 -0
  42. package/lib/ui-react.d.ts +0 -7158
  43. package/lib/ui-react.js +0 -1
  44. package/lib/ui-react.js.gz +0 -0
  45. package/lib/umd/checkpoints.js +0 -1
  46. package/lib/umd/checkpoints.js.gz +0 -0
  47. package/lib/umd/indexes.js +0 -1
  48. package/lib/umd/indexes.js.gz +0 -0
  49. package/lib/umd/metrics.js +0 -1
  50. package/lib/umd/metrics.js.gz +0 -0
  51. package/lib/umd/persisters.js +0 -1
  52. package/lib/umd/persisters.js.gz +0 -0
  53. package/lib/umd/relationships.js +0 -1
  54. package/lib/umd/relationships.js.gz +0 -0
  55. package/lib/umd/store.js +0 -1
  56. package/lib/umd/store.js.gz +0 -0
  57. package/lib/umd/tinybase.js +0 -1
  58. package/lib/umd/tinybase.js.gz +0 -0
  59. package/lib/umd/ui-react.js +0 -1
  60. package/lib/umd/ui-react.js.gz +0 -0
@@ -1 +0,0 @@
1
- const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,s=e=>0==n(e),o=e=>e.slice(1),r=e=>null==e,l=(e,t,n)=>r(e)?n?.():t(e),c=(e,t)=>e?.has(t)??!1,i=e=>r(e)||0==(e=>e.size)(e),d=(e,t)=>e?.forEach(t),a=(e,t)=>e?.delete(t),p=e=>new Map(e),u=(e,t)=>e?.get(t),h=(e,t,n)=>r(n)?(a(e,t),e):e?.set(t,n),g=(e,t,n,s)=>(c(e,t)||(s?.(n),e.set(t,n)),u(e,t)),C=e=>new Set(e),k=(e,t,r)=>n(r)<2?((e,t)=>e?.add(t))(s(r)?e:g(e,r[0],C()),t):k(g(e,r[0],p()),t,o(r)),f=e=>{const n=(r,c,...i)=>l(r,(r=>s(i)?e(r,c):t([i[0],null],(e=>n(u(r,e),c,...o(i))))));return n},L=Object.freeze,w=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((o=>{let w,v,S,z=100,E=p(),I=1;const M=C(),b=p(),[j,x,y]=(e=>{let s,o=0;const c=[],i=p();return[(t,n,r=[])=>{s??=e();const l=c.pop()??""+o++;return h(i,l,[t,n,r]),k(n,l,r),l},(e,t=[],...n)=>f(d)(e,(e=>l(u(i,e),(([e])=>e(s,...t,...n)))),...t),e=>l(u(i,e),(([,t,s])=>(f(a)(t,e,...s),h(i,e),n(c)<1e3&&c.push(e),s)),(()=>[])),(e,o,c)=>l(u(i,e),(([e,,l])=>{const i=(...d)=>{const a=n(d);a==n(l)?e(s,...d,...c(d)):r(l[a])?t(o[a](...d),(e=>i(...d,e))):i(...d,l[a])};i()}))]})((()=>Q)),B=p(),F=p(),O=[],T=[],W=(e,t)=>{I=0,o.transaction((()=>d(u(B,t),((t,n)=>d(t,((t,s)=>d(t,((t,l)=>r(t[e])?o.delCell(n,s,l,!0):o.setCell(n,s,l,t[e]))))))))),I=1},m=e=>{h(B,e),h(F,e),x(b,[e])},q=(e,s)=>t(((e,t)=>e.splice(0,t))(e,s??n(e)),m),A=()=>q(O,n(O)-z),D=o.addCellListener(null,null,null,((e,t,n,s,o,r)=>{if(I){l(w,(()=>{O.push(w),A(),q(T),w=void 0,S=1}));const e=g(E,t,p()),c=g(e,n,p()),d=g(c,s,[void 0,void 0],(e=>e[0]=r));d[1]=o,d[0]===d[1]&&i(h(c,s))&&i(h(e,n))&&i(h(E,t))&&(w=O.pop(),S=1),K()}})),G=(e="")=>(r(w)&&(w=""+v++,h(B,w,E),P(w,e),E=p(),S=1),w),H=()=>{s(O)||(T.unshift(G()),W(0,w),w=O.pop(),S=1)},J=()=>{s(T)||(O.push(w),w=T.shift(),W(1,w),S=1)},K=()=>{S&&(x(M),S=0)},N=e=>{const t=G(e);return K(),t},P=(e,t)=>(c(B,e)&&u(F,e)!==t&&(h(F,e,t),x(b,[e])),Q),Q={setSize:e=>(z=e,A(),Q),addCheckpoint:N,setCheckpoint:P,getStore:()=>o,getCheckpointIds:()=>[[...O],w,[...T]],getCheckpoint:e=>u(F,e),goBackward:()=>(H(),K(),Q),goForward:()=>(J(),K(),Q),goTo:t=>{const n=e(O,t)?H:e(T,t)?J:null;for(;!r(n)&&t!=w;)n();return K(),Q},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,t)=>j(t,b,[e]),delListener:e=>(y(e),Q),clear:()=>(q(O),q(T),r(w)||m(w),w=void 0,v=0,N(),Q),destroy:()=>{o.delListener(D)},getListenerStats:()=>({})};return L(Q.clear())}));export{w as createCheckpoints};
Binary file
package/lib/common.d.ts DELETED
@@ -1,59 +0,0 @@
1
- /**
2
- * The common module of the TinyBase project provides a small collection of
3
- * common types used across other modules.
4
- *
5
- * @packageDocumentation
6
- * @module common
7
- */
8
-
9
- /**
10
- * The Json type is a simple alias for a string, but is used to indicate that
11
- * the string should be considered to be a JSON serialization of an object.
12
- *
13
- * @category General
14
- */
15
- export type Json = string;
16
-
17
- /**
18
- * The Ids type is a simple alias for an array of strings, but is used to
19
- * indicate that the strings should be considered to be the keys of objects
20
- * (such as the Row Id strings used in a Table).
21
- *
22
- * @category Identity
23
- */
24
- export type Ids = Id[];
25
-
26
- /**
27
- * The Id type is a simple alias for a string, but is used to indicate that the
28
- * string should be considered to be the key of an object (such as a Row Id
29
- * string used in a Table).
30
- *
31
- * @category Identity
32
- */
33
- export type Id = string;
34
-
35
- /**
36
- * The Id type is a simple alias for the union of a string or `null` value,
37
- * where the string should be considered to be the key of an objects (such as a
38
- * Row Id string used in a Table), and typically `null` indicates a wildcard -
39
- * such as when used in the Store addRowListener method.
40
- *
41
- * @category Identity
42
- */
43
- export type IdOrNull = Id | null;
44
-
45
- /**
46
- * The ParameterizedCallback type represents a generic function that will take
47
- * an optional parameter - such as the handler of a DOM event.
48
- *
49
- * @category Callback
50
- */
51
- export type ParameterizedCallback<Parameter> = (parameter?: Parameter) => void;
52
-
53
- /**
54
- * The Callback type represents a function that is used as a callback and which
55
- * does not take a parameter.
56
- *
57
- * @category Callback
58
- */
59
- export type Callback = () => void;
@@ -1,326 +0,0 @@
1
- const arrayHas = (array, value) => array.includes(value);
2
- const arrayForEach = (array, cb) => array.forEach(cb);
3
- const arrayLength = (array) => array.length;
4
- const arrayIsEmpty = (array) => arrayLength(array) == 0;
5
- const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
6
- const arrayFromSecond = (ids) => ids.slice(1);
7
- const arrayClear = (array, to) => array.splice(0, to);
8
-
9
- const isUndefined = (thing) => thing == void 0;
10
- const ifNotUndefined = (value, then, otherwise) =>
11
- isUndefined(value) ? otherwise?.() : then(value);
12
-
13
- const collSizeN = (collSizer) => (coll) =>
14
- arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
15
- const collSize = (coll) => coll.size;
16
- const collSize2 = collSizeN(collSize);
17
- const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
18
- const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
19
- const collValues = (coll) => [...(coll?.values() ?? [])];
20
- const collForEach = (coll, cb) => coll?.forEach(cb);
21
- const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
22
-
23
- const mapNew = (entries) => new Map(entries);
24
- const mapGet = (map, key) => map?.get(key);
25
- const mapSet = (map, key, value) =>
26
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
27
- const mapEnsure = (map, key, defaultValue, onWillAdd) => {
28
- if (!collHas(map, key)) {
29
- onWillAdd?.(defaultValue);
30
- map.set(key, defaultValue);
31
- }
32
- return mapGet(map, key);
33
- };
34
-
35
- const setNew = (entries) => new Set(entries);
36
- const setAdd = (set, value) => set?.add(value);
37
-
38
- const getCreateFunction = (getFunction) => {
39
- const getFunctionsByStore = /* @__PURE__ */ new WeakMap();
40
- return (store) => {
41
- if (!getFunctionsByStore.has(store)) {
42
- getFunctionsByStore.set(store, getFunction(store));
43
- }
44
- return getFunctionsByStore.get(store);
45
- };
46
- };
47
-
48
- const addDeepSet = (deepSet, value, ids) =>
49
- arrayLength(ids) < 2
50
- ? setAdd(
51
- arrayIsEmpty(ids) ? deepSet : mapEnsure(deepSet, ids[0], setNew()),
52
- value,
53
- )
54
- : addDeepSet(
55
- mapEnsure(deepSet, ids[0], mapNew()),
56
- value,
57
- arrayFromSecond(ids),
58
- );
59
- const forDeepSet = (valueDo) => {
60
- const deep = (deepIdSet, arg, ...ids) =>
61
- ifNotUndefined(deepIdSet, (deepIdSet2) =>
62
- arrayIsEmpty(ids)
63
- ? valueDo(deepIdSet2, arg)
64
- : arrayForEach([ids[0], null], (id) =>
65
- deep(mapGet(deepIdSet2, id), arg, ...arrayFromSecond(ids)),
66
- ),
67
- );
68
- return deep;
69
- };
70
- const getListenerFunctions = (getThing) => {
71
- let thing;
72
- let nextId = 0;
73
- const listenerPool = [];
74
- const allListeners = mapNew();
75
- const addListener = (listener, deepSet, idOrNulls = []) => {
76
- thing ??= getThing();
77
- const id = listenerPool.pop() ?? '' + nextId++;
78
- mapSet(allListeners, id, [listener, deepSet, idOrNulls]);
79
- addDeepSet(deepSet, id, idOrNulls);
80
- return id;
81
- };
82
- const callListeners = (deepSet, ids = [], ...extraArgs) =>
83
- forDeepSet(collForEach)(
84
- deepSet,
85
- (id) =>
86
- ifNotUndefined(mapGet(allListeners, id), ([listener]) =>
87
- listener(thing, ...ids, ...extraArgs),
88
- ),
89
- ...ids,
90
- );
91
- const delListener = (id) =>
92
- ifNotUndefined(
93
- mapGet(allListeners, id),
94
- ([, deepSet, idOrNulls]) => {
95
- forDeepSet(collDel)(deepSet, id, ...idOrNulls);
96
- mapSet(allListeners, id);
97
- if (arrayLength(listenerPool) < 1e3) {
98
- listenerPool.push(id);
99
- }
100
- return idOrNulls;
101
- },
102
- () => [],
103
- );
104
- const callListener = (id, idNullGetters, extraArgsGetter) =>
105
- ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls]) => {
106
- const callWithIds = (...ids) => {
107
- const index = arrayLength(ids);
108
- index == arrayLength(idOrNulls)
109
- ? listener(thing, ...ids, ...extraArgsGetter(ids))
110
- : isUndefined(idOrNulls[index])
111
- ? arrayForEach(idNullGetters[index](...ids), (id2) =>
112
- callWithIds(...ids, id2),
113
- )
114
- : callWithIds(...ids, idOrNulls[index]);
115
- };
116
- callWithIds();
117
- });
118
- return [addListener, callListeners, delListener, callListener];
119
- };
120
-
121
- const object = Object;
122
- const objFreeze = object.freeze;
123
-
124
- const createCheckpoints = getCreateFunction((store) => {
125
- let backwardIdsSize = 100;
126
- let currentId;
127
- let delta = mapNew();
128
- let listening = 1;
129
- let nextCheckpointId;
130
- let checkpointsChanged;
131
- const checkpointIdsListeners = setNew();
132
- const checkpointListeners = mapNew();
133
- const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
134
- () => checkpoints,
135
- );
136
- const deltas = mapNew();
137
- const labels = mapNew();
138
- const backwardIds = [];
139
- const forwardIds = [];
140
- const updateStore = (oldOrNew, checkpointId) => {
141
- listening = 0;
142
- store.transaction(() =>
143
- collForEach(mapGet(deltas, checkpointId), (table, tableId) =>
144
- collForEach(table, (row, rowId) =>
145
- collForEach(row, (oldNew, cellId) =>
146
- isUndefined(oldNew[oldOrNew])
147
- ? store.delCell(tableId, rowId, cellId, true)
148
- : store.setCell(tableId, rowId, cellId, oldNew[oldOrNew]),
149
- ),
150
- ),
151
- ),
152
- );
153
- listening = 1;
154
- };
155
- const clearCheckpointId = (checkpointId) => {
156
- mapSet(deltas, checkpointId);
157
- mapSet(labels, checkpointId);
158
- callListeners(checkpointListeners, [checkpointId]);
159
- };
160
- const clearCheckpointIds = (checkpointIds, to) =>
161
- arrayForEach(
162
- arrayClear(checkpointIds, to ?? arrayLength(checkpointIds)),
163
- clearCheckpointId,
164
- );
165
- const trimBackwardsIds = () =>
166
- clearCheckpointIds(backwardIds, arrayLength(backwardIds) - backwardIdsSize);
167
- const listenerId = store.addCellListener(
168
- null,
169
- null,
170
- null,
171
- (_store, tableId, rowId, cellId, newCell, oldCell) => {
172
- if (listening) {
173
- ifNotUndefined(currentId, () => {
174
- backwardIds.push(currentId);
175
- trimBackwardsIds();
176
- clearCheckpointIds(forwardIds);
177
- currentId = void 0;
178
- checkpointsChanged = 1;
179
- });
180
- const table = mapEnsure(delta, tableId, mapNew());
181
- const row = mapEnsure(table, rowId, mapNew());
182
- const oldNew = mapEnsure(
183
- row,
184
- cellId,
185
- [void 0, void 0],
186
- (addOldNew) => (addOldNew[0] = oldCell),
187
- );
188
- oldNew[1] = newCell;
189
- if (oldNew[0] === oldNew[1]) {
190
- if (collIsEmpty(mapSet(row, cellId))) {
191
- if (collIsEmpty(mapSet(table, rowId))) {
192
- if (collIsEmpty(mapSet(delta, tableId))) {
193
- currentId = backwardIds.pop();
194
- checkpointsChanged = 1;
195
- }
196
- }
197
- }
198
- }
199
- callListenersIfChanged();
200
- }
201
- },
202
- );
203
- const addCheckpointImpl = (label = '') => {
204
- if (isUndefined(currentId)) {
205
- currentId = '' + nextCheckpointId++;
206
- mapSet(deltas, currentId, delta);
207
- setCheckpoint(currentId, label);
208
- delta = mapNew();
209
- checkpointsChanged = 1;
210
- }
211
- return currentId;
212
- };
213
- const goBackwardImpl = () => {
214
- if (!arrayIsEmpty(backwardIds)) {
215
- forwardIds.unshift(addCheckpointImpl());
216
- updateStore(0, currentId);
217
- currentId = backwardIds.pop();
218
- checkpointsChanged = 1;
219
- }
220
- };
221
- const goForwardImpl = () => {
222
- if (!arrayIsEmpty(forwardIds)) {
223
- backwardIds.push(currentId);
224
- currentId = forwardIds.shift();
225
- updateStore(1, currentId);
226
- checkpointsChanged = 1;
227
- }
228
- };
229
- const callListenersIfChanged = () => {
230
- if (checkpointsChanged) {
231
- callListeners(checkpointIdsListeners);
232
- checkpointsChanged = 0;
233
- }
234
- };
235
- const setSize = (size) => {
236
- backwardIdsSize = size;
237
- trimBackwardsIds();
238
- return checkpoints;
239
- };
240
- const addCheckpoint = (label) => {
241
- const id = addCheckpointImpl(label);
242
- callListenersIfChanged();
243
- return id;
244
- };
245
- const setCheckpoint = (checkpointId, label) => {
246
- if (
247
- collHas(deltas, checkpointId) &&
248
- mapGet(labels, checkpointId) !== label
249
- ) {
250
- mapSet(labels, checkpointId, label);
251
- callListeners(checkpointListeners, [checkpointId]);
252
- }
253
- return checkpoints;
254
- };
255
- const getStore = () => store;
256
- const getCheckpointIds = () => [[...backwardIds], currentId, [...forwardIds]];
257
- const getCheckpoint = (checkpointId) => mapGet(labels, checkpointId);
258
- const goBackward = () => {
259
- goBackwardImpl();
260
- callListenersIfChanged();
261
- return checkpoints;
262
- };
263
- const goForward = () => {
264
- goForwardImpl();
265
- callListenersIfChanged();
266
- return checkpoints;
267
- };
268
- const goTo = (checkpointId) => {
269
- const action = arrayHas(backwardIds, checkpointId)
270
- ? goBackwardImpl
271
- : arrayHas(forwardIds, checkpointId)
272
- ? goForwardImpl
273
- : null;
274
- while (!isUndefined(action) && checkpointId != currentId) {
275
- action();
276
- }
277
- callListenersIfChanged();
278
- return checkpoints;
279
- };
280
- const addCheckpointIdsListener = (listener) =>
281
- addListener(listener, checkpointIdsListeners);
282
- const addCheckpointListener = (checkpointId, listener) =>
283
- addListener(listener, checkpointListeners, [checkpointId]);
284
- const delListener = (listenerId2) => {
285
- delListenerImpl(listenerId2);
286
- return checkpoints;
287
- };
288
- const clear = () => {
289
- clearCheckpointIds(backwardIds);
290
- clearCheckpointIds(forwardIds);
291
- if (!isUndefined(currentId)) {
292
- clearCheckpointId(currentId);
293
- }
294
- currentId = void 0;
295
- nextCheckpointId = 0;
296
- addCheckpoint();
297
- return checkpoints;
298
- };
299
- const destroy = () => {
300
- store.delListener(listenerId);
301
- };
302
- const getListenerStats = () => ({
303
- checkpointIds: collSize(checkpointIdsListeners),
304
- checkpoint: collSize2(checkpointListeners),
305
- });
306
- const checkpoints = {
307
- setSize,
308
- addCheckpoint,
309
- setCheckpoint,
310
- getStore,
311
- getCheckpointIds,
312
- getCheckpoint,
313
- goBackward,
314
- goForward,
315
- goTo,
316
- addCheckpointIdsListener,
317
- addCheckpointListener,
318
- delListener,
319
- clear,
320
- destroy,
321
- getListenerStats,
322
- };
323
- return objFreeze(checkpoints.clear());
324
- });
325
-
326
- export {createCheckpoints};