tinybase 1.0.0 → 1.0.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/LICENSE +1 -1
- package/lib/checkpoints.d.ts +22 -0
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +22 -0
- package/lib/debug/checkpoints.js +3 -4
- package/lib/debug/indexes.d.ts +53 -5
- package/lib/debug/indexes.js +6 -0
- package/lib/debug/metrics.d.ts +26 -0
- package/lib/debug/metrics.js +4 -0
- package/lib/debug/relationships.d.ts +23 -0
- package/lib/debug/relationships.js +4 -0
- package/lib/debug/store.d.ts +20 -0
- package/lib/debug/store.js +2 -0
- package/lib/debug/tinybase.js +15 -4
- package/lib/indexes.d.ts +53 -5
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +26 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/relationships.d.ts +23 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +20 -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/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/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 +15 -6
- package/readme.md +2 -2
package/LICENSE
CHANGED
package/lib/checkpoints.d.ts
CHANGED
|
@@ -353,6 +353,28 @@ export interface Checkpoints {
|
|
|
353
353
|
*/
|
|
354
354
|
getCheckpointIds(): CheckpointIds;
|
|
355
355
|
|
|
356
|
+
/**
|
|
357
|
+
* The hasCheckpoint method returns a boolean indicating whether a given
|
|
358
|
+
* Checkpoint exists in the Checkpoints object.
|
|
359
|
+
*
|
|
360
|
+
* @param checkpointId The Id of a possible Checkpoint in the Checkpoints
|
|
361
|
+
* object.
|
|
362
|
+
* @returns Whether a Checkpoint with that Id exists.
|
|
363
|
+
* @example
|
|
364
|
+
* This example shows two simple Checkpoint existence checks.
|
|
365
|
+
*
|
|
366
|
+
* ```js
|
|
367
|
+
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
368
|
+
* const checkpoints = createCheckpoints(store);
|
|
369
|
+
* console.log(checkpoints.hasCheckpoint('0'));
|
|
370
|
+
* // -> true
|
|
371
|
+
* console.log(checkpoints.hasCheckpoint('1'));
|
|
372
|
+
* // -> false
|
|
373
|
+
* ```
|
|
374
|
+
* @category Getter
|
|
375
|
+
*/
|
|
376
|
+
hasCheckpoint(checkpointId: Id): boolean;
|
|
377
|
+
|
|
356
378
|
/**
|
|
357
379
|
* The getCheckpoint method fetches the label for a checkpoint, if it had been
|
|
358
380
|
* provided at the time of the addCheckpoint method or set subsequently with
|
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,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),
|
|
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),h=(e,t)=>e?.get(t),u=(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)),h(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(h(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 u(i,l,[t,n,r]),k(n,l,r),l},(e,t=[],...n)=>f(d)(e,(e=>l(h(i,e),(([e])=>e(s,...t,...n)))),...t),e=>l(h(i,e),(([,t,s])=>(f(a)(t,e,...s),u(i,e),n(c)<1e3&&c.push(e),s)),(()=>[])),(e,o,c)=>l(h(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()}))]})((()=>R)),B=p(),F=p(),O=[],T=[],W=(e,t)=>{I=0,o.transaction((()=>d(h(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=>{u(B,e),u(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(u(c,s))&&i(u(e,n))&&i(u(E,t))&&(w=O.pop(),S=1),K()}})),G=(e="")=>(r(w)&&(w=""+v++,u(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)=>(Q(e)&&h(F,e)!==t&&(u(F,e,t),x(b,[e])),R),Q=e=>c(B,e),R={setSize:e=>(z=e,A(),R),addCheckpoint:N,setCheckpoint:P,getStore:()=>o,getCheckpointIds:()=>[[...O],w,[...T]],hasCheckpoint:Q,getCheckpoint:e=>h(F,e),goBackward:()=>(H(),K(),R),goForward:()=>(J(),K(),R),goTo:t=>{const n=e(O,t)?H:e(T,t)?J:null;for(;!r(n)&&t!=w;)n();return K(),R},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,t)=>j(t,b,[e]),delListener:e=>(y(e),R),clear:()=>(q(O),q(T),r(w)||m(w),w=void 0,v=0,N(),R),destroy:()=>{o.delListener(D)},getListenerStats:()=>({})};return L(R.clear())}));export{w as createCheckpoints};
|
package/lib/checkpoints.js.gz
CHANGED
|
Binary file
|
|
@@ -353,6 +353,28 @@ export interface Checkpoints {
|
|
|
353
353
|
*/
|
|
354
354
|
getCheckpointIds(): CheckpointIds;
|
|
355
355
|
|
|
356
|
+
/**
|
|
357
|
+
* The hasCheckpoint method returns a boolean indicating whether a given
|
|
358
|
+
* Checkpoint exists in the Checkpoints object.
|
|
359
|
+
*
|
|
360
|
+
* @param checkpointId The Id of a possible Checkpoint in the Checkpoints
|
|
361
|
+
* object.
|
|
362
|
+
* @returns Whether a Checkpoint with that Id exists.
|
|
363
|
+
* @example
|
|
364
|
+
* This example shows two simple Checkpoint existence checks.
|
|
365
|
+
*
|
|
366
|
+
* ```js
|
|
367
|
+
* const store = createStore().setTables({pets: {fido: {sold: false}}});
|
|
368
|
+
* const checkpoints = createCheckpoints(store);
|
|
369
|
+
* console.log(checkpoints.hasCheckpoint('0'));
|
|
370
|
+
* // -> true
|
|
371
|
+
* console.log(checkpoints.hasCheckpoint('1'));
|
|
372
|
+
* // -> false
|
|
373
|
+
* ```
|
|
374
|
+
* @category Getter
|
|
375
|
+
*/
|
|
376
|
+
hasCheckpoint(checkpointId: Id): boolean;
|
|
377
|
+
|
|
356
378
|
/**
|
|
357
379
|
* The getCheckpoint method fetches the label for a checkpoint, if it had been
|
|
358
380
|
* provided at the time of the addCheckpoint method or set subsequently with
|
package/lib/debug/checkpoints.js
CHANGED
|
@@ -243,10 +243,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
243
243
|
return id;
|
|
244
244
|
};
|
|
245
245
|
const setCheckpoint = (checkpointId, label) => {
|
|
246
|
-
if (
|
|
247
|
-
collHas(deltas, checkpointId) &&
|
|
248
|
-
mapGet(labels, checkpointId) !== label
|
|
249
|
-
) {
|
|
246
|
+
if (hasCheckpoint(checkpointId) && mapGet(labels, checkpointId) !== label) {
|
|
250
247
|
mapSet(labels, checkpointId, label);
|
|
251
248
|
callListeners(checkpointListeners, [checkpointId]);
|
|
252
249
|
}
|
|
@@ -254,6 +251,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
254
251
|
};
|
|
255
252
|
const getStore = () => store;
|
|
256
253
|
const getCheckpointIds = () => [[...backwardIds], currentId, [...forwardIds]];
|
|
254
|
+
const hasCheckpoint = (checkpointId) => collHas(deltas, checkpointId);
|
|
257
255
|
const getCheckpoint = (checkpointId) => mapGet(labels, checkpointId);
|
|
258
256
|
const goBackward = () => {
|
|
259
257
|
goBackwardImpl();
|
|
@@ -309,6 +307,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
309
307
|
setCheckpoint,
|
|
310
308
|
getStore,
|
|
311
309
|
getCheckpointIds,
|
|
310
|
+
hasCheckpoint,
|
|
312
311
|
getCheckpoint,
|
|
313
312
|
goBackward,
|
|
314
313
|
goForward,
|
package/lib/debug/indexes.d.ts
CHANGED
|
@@ -362,6 +362,54 @@ export interface Indexes {
|
|
|
362
362
|
*/
|
|
363
363
|
getIndexIds(): Ids;
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* The hasIndex method returns a boolean indicating whether a given Index
|
|
367
|
+
* exists in the Indexes object.
|
|
368
|
+
*
|
|
369
|
+
* @param indexId The Id of a possible Index in the Indexes object.
|
|
370
|
+
* @returns Whether an Index with that Id exists.
|
|
371
|
+
* @example
|
|
372
|
+
* This example shows two simple Index existence checks.
|
|
373
|
+
*
|
|
374
|
+
* ```js
|
|
375
|
+
* const indexes = createIndexes(createStore());
|
|
376
|
+
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
377
|
+
* console.log(indexes.hasIndex('bySpecies'));
|
|
378
|
+
* // -> true
|
|
379
|
+
* console.log(indexes.hasIndex('byColor'));
|
|
380
|
+
* // -> false
|
|
381
|
+
* ```
|
|
382
|
+
* @category Getter
|
|
383
|
+
*/
|
|
384
|
+
hasIndex(indexId: Id): boolean;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The hasSlice method returns a boolean indicating whether a given Slice
|
|
388
|
+
* exists in the Indexes object.
|
|
389
|
+
*
|
|
390
|
+
* @param indexId The Id of a possible Index in the Indexes object.
|
|
391
|
+
* @param sliceId The Id of a possible Slice in the Index.
|
|
392
|
+
* @returns Whether a Slice with that Id exists.
|
|
393
|
+
* @example
|
|
394
|
+
* This example shows two simple Index existence checks.
|
|
395
|
+
*
|
|
396
|
+
* ```js
|
|
397
|
+
* const store = createStore().setTable('pets', {
|
|
398
|
+
* fido: {species: 'dog'},
|
|
399
|
+
* felix: {species: 'cat'},
|
|
400
|
+
* cujo: {species: 'dog'},
|
|
401
|
+
* });
|
|
402
|
+
* const indexes = createIndexes(store);
|
|
403
|
+
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
404
|
+
* console.log(indexes.hasSlice('bySpecies', 'dog'));
|
|
405
|
+
* // -> true
|
|
406
|
+
* console.log(indexes.hasSlice('bySpecies', 'worm'));
|
|
407
|
+
* // -> false
|
|
408
|
+
* ```
|
|
409
|
+
* @category Getter
|
|
410
|
+
*/
|
|
411
|
+
hasSlice(indexId: Id, sliceId: Id): boolean;
|
|
412
|
+
|
|
365
413
|
/**
|
|
366
414
|
* The getTableId method returns the Id of the underlying Table that is
|
|
367
415
|
* backing an Index.
|
|
@@ -473,7 +521,7 @@ export interface Indexes {
|
|
|
473
521
|
* the Index change.
|
|
474
522
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
475
523
|
* @example
|
|
476
|
-
* This example creates a Store,
|
|
524
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
477
525
|
* listener that responds to any changes to a specific Index.
|
|
478
526
|
*
|
|
479
527
|
* ```js
|
|
@@ -501,7 +549,7 @@ export interface Indexes {
|
|
|
501
549
|
* indexes.delListener(listenerId);
|
|
502
550
|
* ```
|
|
503
551
|
* @example
|
|
504
|
-
* This example creates a Store,
|
|
552
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
505
553
|
* listener that responds to any changes to any Index.
|
|
506
554
|
*
|
|
507
555
|
* ```js
|
|
@@ -558,7 +606,7 @@ export interface Indexes {
|
|
|
558
606
|
* the Slice change.
|
|
559
607
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
560
608
|
* @example
|
|
561
|
-
* This example creates a Store,
|
|
609
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
562
610
|
* listener that responds to any changes to a specific Slice.
|
|
563
611
|
*
|
|
564
612
|
* ```js
|
|
@@ -587,7 +635,7 @@ export interface Indexes {
|
|
|
587
635
|
* indexes.delListener(listenerId);
|
|
588
636
|
* ```
|
|
589
637
|
* @example
|
|
590
|
-
* This example creates a Store,
|
|
638
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
591
639
|
* listener that responds to any changes to any Slice.
|
|
592
640
|
*
|
|
593
641
|
* ```js
|
|
@@ -639,7 +687,7 @@ export interface Indexes {
|
|
|
639
687
|
* @param listenerId The Id of the listener to remove.
|
|
640
688
|
* @returns A reference to the Indexes object.
|
|
641
689
|
* @example
|
|
642
|
-
* This example creates a Store,
|
|
690
|
+
* This example creates a Store, an Indexes object, registers a listener, and
|
|
643
691
|
* then removes it.
|
|
644
692
|
*
|
|
645
693
|
* ```js
|
package/lib/debug/indexes.js
CHANGED
|
@@ -57,6 +57,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
57
57
|
const storeListenerIds = mapNew();
|
|
58
58
|
const getStore = () => store;
|
|
59
59
|
const getThingIds = () => mapKeys(tableIds);
|
|
60
|
+
const hasThing = (id) => collHas(things, id);
|
|
60
61
|
const getTableId = (id) => mapGet(tableIds, id);
|
|
61
62
|
const getThing = (id) => mapGet(things, id);
|
|
62
63
|
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
@@ -146,6 +147,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
146
147
|
return [
|
|
147
148
|
getStore,
|
|
148
149
|
getThingIds,
|
|
150
|
+
hasThing,
|
|
149
151
|
getTableId,
|
|
150
152
|
getThing,
|
|
151
153
|
setThing,
|
|
@@ -252,6 +254,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
252
254
|
const [
|
|
253
255
|
getStore,
|
|
254
256
|
getIndexIds,
|
|
257
|
+
hasIndex,
|
|
255
258
|
getTableId,
|
|
256
259
|
getIndex,
|
|
257
260
|
setIndex,
|
|
@@ -264,6 +267,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
264
267
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
265
268
|
() => indexes,
|
|
266
269
|
);
|
|
270
|
+
const hasSlice = (indexId, sliceId) => collHas(getIndex(indexId), sliceId);
|
|
267
271
|
const setIndexDefinition = (
|
|
268
272
|
indexId,
|
|
269
273
|
tableId,
|
|
@@ -383,6 +387,8 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
383
387
|
delIndexDefinition,
|
|
384
388
|
getStore,
|
|
385
389
|
getIndexIds,
|
|
390
|
+
hasIndex,
|
|
391
|
+
hasSlice,
|
|
386
392
|
getTableId,
|
|
387
393
|
getSliceIds,
|
|
388
394
|
getSliceRowIds,
|
package/lib/debug/metrics.d.ts
CHANGED
|
@@ -478,6 +478,32 @@ export interface Metrics {
|
|
|
478
478
|
*/
|
|
479
479
|
getMetricIds(): Ids;
|
|
480
480
|
|
|
481
|
+
/**
|
|
482
|
+
* The hasMetric method returns a boolean indicating whether a given Metric
|
|
483
|
+
* exists in the Metrics object, and has a value.
|
|
484
|
+
*
|
|
485
|
+
* @param metricId The Id of a possible Metric in the Metrics object.
|
|
486
|
+
* @returns Whether a Metric with that Id exists.
|
|
487
|
+
* @example
|
|
488
|
+
* This example shows two simple Metric existence checks.
|
|
489
|
+
*
|
|
490
|
+
* ```js
|
|
491
|
+
* const store = createStore();
|
|
492
|
+
* const metrics = createMetrics(store);
|
|
493
|
+
* metrics.setMetricDefinition('highestPrice', 'species', 'max', 'price');
|
|
494
|
+
*
|
|
495
|
+
* console.log(metrics.hasMetric('lowestPrice'));
|
|
496
|
+
* // -> false
|
|
497
|
+
* console.log(metrics.hasMetric('highestPrice'));
|
|
498
|
+
* // -> false
|
|
499
|
+
* store.setTable('species', {dog: {price: 5}, cat: {price: 4}});
|
|
500
|
+
* console.log(metrics.hasMetric('highestPrice'));
|
|
501
|
+
* // -> true
|
|
502
|
+
* ```
|
|
503
|
+
* @category Getter
|
|
504
|
+
*/
|
|
505
|
+
hasMetric(metricId: Id): boolean;
|
|
506
|
+
|
|
481
507
|
/**
|
|
482
508
|
* The getTableId method returns the Id of the underlying Table that is
|
|
483
509
|
* backing a Metric.
|
package/lib/debug/metrics.js
CHANGED
|
@@ -62,6 +62,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
62
62
|
const storeListenerIds = mapNew();
|
|
63
63
|
const getStore = () => store;
|
|
64
64
|
const getThingIds = () => mapKeys(tableIds);
|
|
65
|
+
const hasThing = (id) => collHas(things, id);
|
|
65
66
|
const getTableId = (id) => mapGet(tableIds, id);
|
|
66
67
|
const getThing = (id) => mapGet(things, id);
|
|
67
68
|
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
@@ -151,6 +152,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
151
152
|
return [
|
|
152
153
|
getStore,
|
|
153
154
|
getThingIds,
|
|
155
|
+
hasThing,
|
|
154
156
|
getTableId,
|
|
155
157
|
getThing,
|
|
156
158
|
setThing,
|
|
@@ -294,6 +296,7 @@ const createMetrics = getCreateFunction((store) => {
|
|
|
294
296
|
const [
|
|
295
297
|
getStore,
|
|
296
298
|
getMetricIds,
|
|
299
|
+
hasMetric,
|
|
297
300
|
getTableId,
|
|
298
301
|
getMetric,
|
|
299
302
|
setMetric,
|
|
@@ -378,6 +381,7 @@ const createMetrics = getCreateFunction((store) => {
|
|
|
378
381
|
delMetricDefinition,
|
|
379
382
|
getStore,
|
|
380
383
|
getMetricIds,
|
|
384
|
+
hasMetric,
|
|
381
385
|
getTableId,
|
|
382
386
|
getMetric,
|
|
383
387
|
addMetricListener,
|
|
@@ -405,6 +405,29 @@ export interface Relationships {
|
|
|
405
405
|
*/
|
|
406
406
|
getRelationshipIds(): Ids;
|
|
407
407
|
|
|
408
|
+
/**
|
|
409
|
+
* The hasRelationship method returns a boolean indicating whether a given
|
|
410
|
+
* Relationship exists in the Relationships object.
|
|
411
|
+
*
|
|
412
|
+
* @param relationshipId The Id of a possible Relationship in the
|
|
413
|
+
* Relationships object.
|
|
414
|
+
* @returns Whether a Relationship with that Id exists.
|
|
415
|
+
* @example
|
|
416
|
+
* This example shows two simple Relationship existence checks.
|
|
417
|
+
*
|
|
418
|
+
* ```js
|
|
419
|
+
* const relationships = createRelationships(
|
|
420
|
+
* createStore(),
|
|
421
|
+
* ).setRelationshipDefinition('petSpecies', 'pets', 'species', 'species');
|
|
422
|
+
* console.log(relationships.hasRelationship('petSpecies'));
|
|
423
|
+
* // -> true
|
|
424
|
+
* console.log(relationships.hasRelationship('petColor'));
|
|
425
|
+
* // -> false
|
|
426
|
+
* ```
|
|
427
|
+
* @category Getter
|
|
428
|
+
*/
|
|
429
|
+
hasRelationship(indexId: Id): boolean;
|
|
430
|
+
|
|
408
431
|
/**
|
|
409
432
|
* The getLocalTableId method returns the Id of the underlying local Table
|
|
410
433
|
* that is used in the Relationship.
|
|
@@ -52,6 +52,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
52
52
|
const storeListenerIds = mapNew();
|
|
53
53
|
const getStore = () => store;
|
|
54
54
|
const getThingIds = () => mapKeys(tableIds);
|
|
55
|
+
const hasThing = (id) => collHas(things, id);
|
|
55
56
|
const getTableId = (id) => mapGet(tableIds, id);
|
|
56
57
|
const getThing = (id) => mapGet(things, id);
|
|
57
58
|
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
@@ -141,6 +142,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
141
142
|
return [
|
|
142
143
|
getStore,
|
|
143
144
|
getThingIds,
|
|
145
|
+
hasThing,
|
|
144
146
|
getTableId,
|
|
145
147
|
getThing,
|
|
146
148
|
setThing,
|
|
@@ -247,6 +249,7 @@ const createRelationships = getCreateFunction((store) => {
|
|
|
247
249
|
const [
|
|
248
250
|
getStore,
|
|
249
251
|
getRelationshipIds,
|
|
252
|
+
hasRelationship,
|
|
250
253
|
getLocalTableId,
|
|
251
254
|
getRelationship,
|
|
252
255
|
_setRelationship,
|
|
@@ -400,6 +403,7 @@ const createRelationships = getCreateFunction((store) => {
|
|
|
400
403
|
delRelationshipDefinition,
|
|
401
404
|
getStore,
|
|
402
405
|
getRelationshipIds,
|
|
406
|
+
hasRelationship,
|
|
403
407
|
getLocalTableId,
|
|
404
408
|
getRemoteTableId,
|
|
405
409
|
getRemoteRowId,
|
package/lib/debug/store.d.ts
CHANGED
|
@@ -867,6 +867,26 @@ export interface Store {
|
|
|
867
867
|
*/
|
|
868
868
|
getCell(tableId: Id, rowId: Id, cellId: Id): Cell | undefined;
|
|
869
869
|
|
|
870
|
+
/**
|
|
871
|
+
* The hasTables method returns a boolean indicating whether any Table objects
|
|
872
|
+
* exist in the Store.
|
|
873
|
+
*
|
|
874
|
+
* @returns Whether any Tables exist.
|
|
875
|
+
* @example
|
|
876
|
+
* This example shows simple existence checks.
|
|
877
|
+
*
|
|
878
|
+
* ```js
|
|
879
|
+
* const store = createStore();
|
|
880
|
+
* console.log(store.hasTables());
|
|
881
|
+
* // -> false
|
|
882
|
+
* store.setTables({pets: {fido: {species: 'dog'}}});
|
|
883
|
+
* console.log(store.hasTables());
|
|
884
|
+
* // -> true
|
|
885
|
+
* ```
|
|
886
|
+
* @category Getter
|
|
887
|
+
*/
|
|
888
|
+
hasTables(): boolean;
|
|
889
|
+
|
|
870
890
|
/**
|
|
871
891
|
* The hasTable method returns a boolean indicating whether a given Table
|
|
872
892
|
* exists in the Store.
|
package/lib/debug/store.js
CHANGED
|
@@ -490,6 +490,7 @@ const createStore = () => {
|
|
|
490
490
|
mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
|
|
491
491
|
const getCell = (tableId, rowId, cellId) =>
|
|
492
492
|
mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
|
|
493
|
+
const hasTables = () => !collIsEmpty(tablesMap);
|
|
493
494
|
const hasTable = (tableId) => collHas(tablesMap, tableId);
|
|
494
495
|
const hasRow = (tableId, rowId) => collHas(mapGet(tablesMap, tableId), rowId);
|
|
495
496
|
const hasCell = (tableId, rowId, cellId) =>
|
|
@@ -686,6 +687,7 @@ const createStore = () => {
|
|
|
686
687
|
getRow,
|
|
687
688
|
getCellIds,
|
|
688
689
|
getCell,
|
|
690
|
+
hasTables,
|
|
689
691
|
hasTable,
|
|
690
692
|
hasRow,
|
|
691
693
|
hasCell,
|
package/lib/debug/tinybase.js
CHANGED
|
@@ -110,6 +110,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
110
110
|
const storeListenerIds = mapNew();
|
|
111
111
|
const getStore = () => store;
|
|
112
112
|
const getThingIds = () => mapKeys(tableIds);
|
|
113
|
+
const hasThing = (id) => collHas(things, id);
|
|
113
114
|
const getTableId = (id) => mapGet(tableIds, id);
|
|
114
115
|
const getThing = (id) => mapGet(things, id);
|
|
115
116
|
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
@@ -199,6 +200,7 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
|
199
200
|
return [
|
|
200
201
|
getStore,
|
|
201
202
|
getThingIds,
|
|
203
|
+
hasThing,
|
|
202
204
|
getTableId,
|
|
203
205
|
getThing,
|
|
204
206
|
setThing,
|
|
@@ -429,10 +431,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
429
431
|
return id;
|
|
430
432
|
};
|
|
431
433
|
const setCheckpoint = (checkpointId, label) => {
|
|
432
|
-
if (
|
|
433
|
-
collHas(deltas, checkpointId) &&
|
|
434
|
-
mapGet(labels, checkpointId) !== label
|
|
435
|
-
) {
|
|
434
|
+
if (hasCheckpoint(checkpointId) && mapGet(labels, checkpointId) !== label) {
|
|
436
435
|
mapSet(labels, checkpointId, label);
|
|
437
436
|
callListeners(checkpointListeners, [checkpointId]);
|
|
438
437
|
}
|
|
@@ -440,6 +439,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
440
439
|
};
|
|
441
440
|
const getStore = () => store;
|
|
442
441
|
const getCheckpointIds = () => [[...backwardIds], currentId, [...forwardIds]];
|
|
442
|
+
const hasCheckpoint = (checkpointId) => collHas(deltas, checkpointId);
|
|
443
443
|
const getCheckpoint = (checkpointId) => mapGet(labels, checkpointId);
|
|
444
444
|
const goBackward = () => {
|
|
445
445
|
goBackwardImpl();
|
|
@@ -495,6 +495,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
495
495
|
setCheckpoint,
|
|
496
496
|
getStore,
|
|
497
497
|
getCheckpointIds,
|
|
498
|
+
hasCheckpoint,
|
|
498
499
|
getCheckpoint,
|
|
499
500
|
goBackward,
|
|
500
501
|
goForward,
|
|
@@ -517,6 +518,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
517
518
|
const [
|
|
518
519
|
getStore,
|
|
519
520
|
getIndexIds,
|
|
521
|
+
hasIndex,
|
|
520
522
|
getTableId,
|
|
521
523
|
getIndex,
|
|
522
524
|
setIndex,
|
|
@@ -529,6 +531,7 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
529
531
|
const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
|
|
530
532
|
() => indexes,
|
|
531
533
|
);
|
|
534
|
+
const hasSlice = (indexId, sliceId) => collHas(getIndex(indexId), sliceId);
|
|
532
535
|
const setIndexDefinition = (
|
|
533
536
|
indexId,
|
|
534
537
|
tableId,
|
|
@@ -648,6 +651,8 @@ const createIndexes = getCreateFunction((store) => {
|
|
|
648
651
|
delIndexDefinition,
|
|
649
652
|
getStore,
|
|
650
653
|
getIndexIds,
|
|
654
|
+
hasIndex,
|
|
655
|
+
hasSlice,
|
|
651
656
|
getTableId,
|
|
652
657
|
getSliceIds,
|
|
653
658
|
getSliceRowIds,
|
|
@@ -705,6 +710,7 @@ const createMetrics = getCreateFunction((store) => {
|
|
|
705
710
|
const [
|
|
706
711
|
getStore,
|
|
707
712
|
getMetricIds,
|
|
713
|
+
hasMetric,
|
|
708
714
|
getTableId,
|
|
709
715
|
getMetric,
|
|
710
716
|
setMetric,
|
|
@@ -789,6 +795,7 @@ const createMetrics = getCreateFunction((store) => {
|
|
|
789
795
|
delMetricDefinition,
|
|
790
796
|
getStore,
|
|
791
797
|
getMetricIds,
|
|
798
|
+
hasMetric,
|
|
792
799
|
getTableId,
|
|
793
800
|
getMetric,
|
|
794
801
|
addMetricListener,
|
|
@@ -980,6 +987,7 @@ const createRelationships = getCreateFunction((store) => {
|
|
|
980
987
|
const [
|
|
981
988
|
getStore,
|
|
982
989
|
getRelationshipIds,
|
|
990
|
+
hasRelationship,
|
|
983
991
|
getLocalTableId,
|
|
984
992
|
getRelationship,
|
|
985
993
|
_setRelationship,
|
|
@@ -1133,6 +1141,7 @@ const createRelationships = getCreateFunction((store) => {
|
|
|
1133
1141
|
delRelationshipDefinition,
|
|
1134
1142
|
getStore,
|
|
1135
1143
|
getRelationshipIds,
|
|
1144
|
+
hasRelationship,
|
|
1136
1145
|
getLocalTableId,
|
|
1137
1146
|
getRemoteTableId,
|
|
1138
1147
|
getRemoteRowId,
|
|
@@ -1469,6 +1478,7 @@ const createStore = () => {
|
|
|
1469
1478
|
mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
|
|
1470
1479
|
const getCell = (tableId, rowId, cellId) =>
|
|
1471
1480
|
mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
|
|
1481
|
+
const hasTables = () => !collIsEmpty(tablesMap);
|
|
1472
1482
|
const hasTable = (tableId) => collHas(tablesMap, tableId);
|
|
1473
1483
|
const hasRow = (tableId, rowId) => collHas(mapGet(tablesMap, tableId), rowId);
|
|
1474
1484
|
const hasCell = (tableId, rowId, cellId) =>
|
|
@@ -1665,6 +1675,7 @@ const createStore = () => {
|
|
|
1665
1675
|
getRow,
|
|
1666
1676
|
getCellIds,
|
|
1667
1677
|
getCell,
|
|
1678
|
+
hasTables,
|
|
1668
1679
|
hasTable,
|
|
1669
1680
|
hasRow,
|
|
1670
1681
|
hasCell,
|
package/lib/indexes.d.ts
CHANGED
|
@@ -362,6 +362,54 @@ export interface Indexes {
|
|
|
362
362
|
*/
|
|
363
363
|
getIndexIds(): Ids;
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* The hasIndex method returns a boolean indicating whether a given Index
|
|
367
|
+
* exists in the Indexes object.
|
|
368
|
+
*
|
|
369
|
+
* @param indexId The Id of a possible Index in the Indexes object.
|
|
370
|
+
* @returns Whether an Index with that Id exists.
|
|
371
|
+
* @example
|
|
372
|
+
* This example shows two simple Index existence checks.
|
|
373
|
+
*
|
|
374
|
+
* ```js
|
|
375
|
+
* const indexes = createIndexes(createStore());
|
|
376
|
+
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
377
|
+
* console.log(indexes.hasIndex('bySpecies'));
|
|
378
|
+
* // -> true
|
|
379
|
+
* console.log(indexes.hasIndex('byColor'));
|
|
380
|
+
* // -> false
|
|
381
|
+
* ```
|
|
382
|
+
* @category Getter
|
|
383
|
+
*/
|
|
384
|
+
hasIndex(indexId: Id): boolean;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The hasSlice method returns a boolean indicating whether a given Slice
|
|
388
|
+
* exists in the Indexes object.
|
|
389
|
+
*
|
|
390
|
+
* @param indexId The Id of a possible Index in the Indexes object.
|
|
391
|
+
* @param sliceId The Id of a possible Slice in the Index.
|
|
392
|
+
* @returns Whether a Slice with that Id exists.
|
|
393
|
+
* @example
|
|
394
|
+
* This example shows two simple Index existence checks.
|
|
395
|
+
*
|
|
396
|
+
* ```js
|
|
397
|
+
* const store = createStore().setTable('pets', {
|
|
398
|
+
* fido: {species: 'dog'},
|
|
399
|
+
* felix: {species: 'cat'},
|
|
400
|
+
* cujo: {species: 'dog'},
|
|
401
|
+
* });
|
|
402
|
+
* const indexes = createIndexes(store);
|
|
403
|
+
* indexes.setIndexDefinition('bySpecies', 'pets', 'species');
|
|
404
|
+
* console.log(indexes.hasSlice('bySpecies', 'dog'));
|
|
405
|
+
* // -> true
|
|
406
|
+
* console.log(indexes.hasSlice('bySpecies', 'worm'));
|
|
407
|
+
* // -> false
|
|
408
|
+
* ```
|
|
409
|
+
* @category Getter
|
|
410
|
+
*/
|
|
411
|
+
hasSlice(indexId: Id, sliceId: Id): boolean;
|
|
412
|
+
|
|
365
413
|
/**
|
|
366
414
|
* The getTableId method returns the Id of the underlying Table that is
|
|
367
415
|
* backing an Index.
|
|
@@ -473,7 +521,7 @@ export interface Indexes {
|
|
|
473
521
|
* the Index change.
|
|
474
522
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
475
523
|
* @example
|
|
476
|
-
* This example creates a Store,
|
|
524
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
477
525
|
* listener that responds to any changes to a specific Index.
|
|
478
526
|
*
|
|
479
527
|
* ```js
|
|
@@ -501,7 +549,7 @@ export interface Indexes {
|
|
|
501
549
|
* indexes.delListener(listenerId);
|
|
502
550
|
* ```
|
|
503
551
|
* @example
|
|
504
|
-
* This example creates a Store,
|
|
552
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
505
553
|
* listener that responds to any changes to any Index.
|
|
506
554
|
*
|
|
507
555
|
* ```js
|
|
@@ -558,7 +606,7 @@ export interface Indexes {
|
|
|
558
606
|
* the Slice change.
|
|
559
607
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
560
608
|
* @example
|
|
561
|
-
* This example creates a Store,
|
|
609
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
562
610
|
* listener that responds to any changes to a specific Slice.
|
|
563
611
|
*
|
|
564
612
|
* ```js
|
|
@@ -587,7 +635,7 @@ export interface Indexes {
|
|
|
587
635
|
* indexes.delListener(listenerId);
|
|
588
636
|
* ```
|
|
589
637
|
* @example
|
|
590
|
-
* This example creates a Store,
|
|
638
|
+
* This example creates a Store, an Indexes object, and then registers a
|
|
591
639
|
* listener that responds to any changes to any Slice.
|
|
592
640
|
*
|
|
593
641
|
* ```js
|
|
@@ -639,7 +687,7 @@ export interface Indexes {
|
|
|
639
687
|
* @param listenerId The Id of the listener to remove.
|
|
640
688
|
* @returns A reference to the Indexes object.
|
|
641
689
|
* @example
|
|
642
|
-
* This example creates a Store,
|
|
690
|
+
* This example creates a Store, an Indexes object, registers a listener, and
|
|
643
691
|
* then removes it.
|
|
644
692
|
*
|
|
645
693
|
* ```js
|
package/lib/indexes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t=e(""),s=(e,t)=>e.every(((s,n)=>0==n||t(e[n-1],s)<=0)),n=(e,t)=>e.sort(t),o=(e,t)=>e.forEach(t),r=e=>e.length,d=e=>0==r(e),c=e=>e.slice(1),l=e=>null==e,i=(e,t,s)=>l(e)?s?.():t(e),a=(e,t)=>e?.has(t)??!1,u=e=>l(e)||0==(e=>e.size)(e),g=e=>e.clear(),I=(e,t)=>e?.forEach(t),
|
|
1
|
+
const e=e=>typeof e,t=e(""),s=(e,t)=>e.every(((s,n)=>0==n||t(e[n-1],s)<=0)),n=(e,t)=>e.sort(t),o=(e,t)=>e.forEach(t),r=e=>e.length,d=e=>0==r(e),c=e=>e.slice(1),l=e=>null==e,i=(e,t,s)=>l(e)?s?.():t(e),a=(e,t)=>e?.has(t)??!1,u=e=>l(e)||0==(e=>e.size)(e),g=e=>e.clear(),I=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),f=e=>new Map(e),w=e=>[...e?.keys()??[]],S=(e,t)=>e?.get(t),p=(e,t)=>I(e,((e,s)=>t(s,e))),L=(e,t,s)=>l(s)?(h(e,t),e):e?.set(t,s),v=(e,t,s,n)=>(a(e,t)||(n?.(s),e.set(t,s)),S(e,t)),x=e=>new Set(e),R=(e,t)=>e?.add(t),b=(s,n)=>e(s)==t?e=>e(s):s??(()=>n??""),y=(e,t)=>e<t?-1:1,T=(e,t,s)=>r(s)<2?R(d(s)?e:v(e,s[0],x()),t):T(v(e,s[0],f()),t,c(s)),k=e=>{const t=(s,n,...r)=>i(s,(s=>d(r)?e(s,n):o([r[0],null],(e=>t(S(s,e),n,...c(r))))));return t},z=Object.freeze,D=(e=>{const t=new WeakMap;return s=>(t.has(s)||t.set(s,e(s)),t.get(s))})((e=>{const t=f(),d=f(),[c,v,D,E,M,j,C,O,W]=((e,t,s)=>{const n=e.hasRow,r=f(),d=f(),c=f(),u=f(),h=f(),v=t=>i(S(h,t),(s=>{I(s,e.delListener),L(h,t)})),R=e=>{L(r,e),L(d,e),L(c,e),L(u,e),v(e)};return[()=>e,()=>w(r),e=>a(d,e),e=>S(r,e),e=>S(d,e),(e,t)=>L(d,e,t),(i,w,R,b,y)=>{const T=f(),k=f();L(r,i,w),a(d,i)||(L(d,i,t()),L(c,i,f()),L(u,i,f()));const z=S(c,i),D=S(u,i),E=t=>{const o=s=>e.getCell(w,t,s),r=S(z,t),d=n(w,t)?s(b(o,t)):void 0;if(r!=d&&L(T,t,[r,d]),!l(y)){const e=S(D,t),s=n(w,t)?y(o,t):void 0;e!=s&&L(k,t,s)}},M=e=>{R((()=>{I(T,(([,e],t)=>L(z,t,e))),I(k,((e,t)=>L(D,t,e)))}),T,k,z,D,e),g(T),g(k)};p(z,E),e.hasTable(w)&&o(e.getRowIds(w),(e=>{a(z,e)||E(e)})),M(!0),v(i),L(h,i,x([e.addRowListener(w,null,((e,t,s)=>E(s))),e.addTableListener(w,(()=>M()))]))},R,()=>p(h,R)]})(e,f,(e=>l(e)?"":e+"")),[m,q,A]=(e=>{let t,s=0;const n=[],d=f();return[(o,r,c=[])=>{t??=e();const l=n.pop()??""+s++;return L(d,l,[o,r,c]),T(r,l,c),l},(e,s=[],...n)=>k(I)(e,(e=>i(S(d,e),(([e])=>e(t,...s,...n)))),...s),e=>i(S(d,e),(([,t,s])=>(k(h)(t,e,...s),L(d,e),r(n)<1e3&&n.push(e),s)),(()=>[])),(e,s,n)=>i(S(d,e),(([e,,d])=>{const c=(...i)=>{const a=r(i);a==r(d)?e(t,...i,...n(i)):l(d[a])?o(s[a](...i),(e=>c(...i,e))):c(...i,d[a])};c()}))]})((()=>B)),B={setIndexDefinition:(e,o,r,c,g,w=y)=>{const v=l(g)?void 0:([e],[t])=>g(e,t);return C(e,o,((o,r,g,b,y,T)=>{let k=0;const z=x(),D=x(),E=M(e);if(I(r,(([e,t],s)=>{l(e)||(R(z,e),i(S(E,e),(t=>{h(t,s),u(t)&&(L(E,e),k=1)}))),l(t)||(R(z,t),a(E,t)||(L(E,t,x()),k=1),R(S(E,t),s),l(c)||R(D,t))})),o(),u(y)||(T?p(E,(e=>R(D,e))):p(g,(e=>i(S(b,e),(e=>R(D,e))))),I(D,(e=>{const t=(t,s)=>w(S(y,t),S(y,s),e),o=[...S(E,e)];s(o,t)||(L(E,e,x(n(o,t))),R(z,e))}))),(k||T)&&!l(v)){const t=[...E];s(t,v)||(j(e,f(n(t,v))),k=1)}k&&q(t,[e]),I(z,(t=>q(d,[e,t])))}),b(r),i(c,b)),B},delIndexDefinition:e=>(O(e),B),getStore:c,getIndexIds:v,hasIndex:D,hasSlice:(e,t)=>a(M(e),t),getTableId:E,getSliceIds:e=>w(M(e)),getSliceRowIds:(e,t)=>[...S(M(e),t)?.values()??[]],addSliceIdsListener:(e,s)=>m(s,t,[e]),addSliceRowIdsListener:(e,t,s)=>m(s,d,[e,t]),delListener:e=>(A(e),B),destroy:W,getListenerStats:()=>({})};return z(B)}));export{D as createIndexes};
|
package/lib/indexes.js.gz
CHANGED
|
Binary file
|