tinybase 1.0.2 → 1.1.0-beta.0
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 +945 -0
- package/lib/checkpoints.js +1 -0
- package/lib/checkpoints.js.gz +0 -0
- package/lib/common.d.ts +115 -0
- package/lib/common.js +1 -0
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +66 -0
- package/lib/debug/checkpoints.js +332 -0
- package/lib/debug/common.js +3 -0
- package/lib/debug/indexes.d.ts +167 -6
- package/lib/debug/indexes.js +431 -0
- package/lib/debug/metrics.d.ts +72 -0
- package/lib/debug/metrics.js +401 -0
- package/lib/debug/persisters.js +191 -0
- package/lib/debug/relationships.d.ts +86 -1
- package/lib/debug/relationships.js +434 -0
- package/lib/debug/store.d.ts +187 -5
- package/lib/debug/store.js +783 -0
- package/lib/debug/tinybase.js +144 -39
- package/lib/indexes.d.ts +939 -0
- package/lib/indexes.js +1 -0
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +829 -0
- package/lib/metrics.js +1 -0
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +711 -0
- package/lib/persisters.js +1 -0
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.d.ts +1201 -0
- package/lib/relationships.js +1 -0
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +2688 -0
- package/lib/store.js +1 -0
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +13 -0
- package/lib/tinybase.js +1 -0
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +7185 -0
- package/lib/ui-react.js +1 -0
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -0
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/common.js +1 -0
- package/lib/umd/common.js.gz +0 -0
- package/lib/umd/indexes.js +1 -0
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -0
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.js +1 -0
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -0
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -0
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -0
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -0
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +14 -14
- package/readme.md +2 -2
package/lib/debug/store.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ export type Row = {[cellId: Id]: Cell};
|
|
|
89
89
|
export type Cell = string | number | boolean;
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* The TableCallback type describes a function that takes a
|
|
92
|
+
* The TableCallback type describes a function that takes a Table's Id and a
|
|
93
93
|
* callback to loop over each Row within it.
|
|
94
94
|
*
|
|
95
95
|
* A TableCallback is provided when using the forEachTable method, so that you
|
|
@@ -332,6 +332,35 @@ export type CellListener = (
|
|
|
332
332
|
getCellChange: GetCellChange | undefined,
|
|
333
333
|
) => void;
|
|
334
334
|
|
|
335
|
+
/**
|
|
336
|
+
* The InvalidCellListener type describes a function that is used to listen to
|
|
337
|
+
* attempts to set invalid data to a Cell.
|
|
338
|
+
*
|
|
339
|
+
* A InvalidCellListener is provided when using the addInvalidCellListener
|
|
340
|
+
* method. See that method for specific examples.
|
|
341
|
+
*
|
|
342
|
+
* When called, a InvalidCellListener is given a reference to the Store, the Id
|
|
343
|
+
* of the Table, the Id of the Row, and the Id of Cell that were being attempted
|
|
344
|
+
* to be changed. It is also given the invalid value of the Cell, which could
|
|
345
|
+
* have been of absolutely any type. Since there could have been multiple failed
|
|
346
|
+
* attempts to set the Cell within a single transaction, this is an array
|
|
347
|
+
* containing each attempt, chronologically.
|
|
348
|
+
*
|
|
349
|
+
* @param store A reference to the Store that was being changed.
|
|
350
|
+
* @param tableId The Id of the Table that was being changed.
|
|
351
|
+
* @param rowId The Id of the Row that was being changed.
|
|
352
|
+
* @param cellId The Id of the Cell that was being changed.
|
|
353
|
+
* @param invalidCells An array of the values of the Cell that were invalid.
|
|
354
|
+
* @category Listener
|
|
355
|
+
*/
|
|
356
|
+
export type InvalidCellListener = (
|
|
357
|
+
store: Store,
|
|
358
|
+
tableId: Id,
|
|
359
|
+
rowId: Id,
|
|
360
|
+
cellId: Id,
|
|
361
|
+
invalidCells: any[],
|
|
362
|
+
) => void;
|
|
363
|
+
|
|
335
364
|
/**
|
|
336
365
|
* The GetCellChange type describes a function that returns information about
|
|
337
366
|
* any Cell's changes during a transaction.
|
|
@@ -545,6 +574,9 @@ export type StoreListenerStats = {
|
|
|
545
574
|
* unique Id. And the setPartialRow method lets you update multiple Cell values
|
|
546
575
|
* in a Row without affecting the others.
|
|
547
576
|
*
|
|
577
|
+
* You can listen to attempts to write invalid data to a Cell with the
|
|
578
|
+
* addInvalidCellListener method.
|
|
579
|
+
*
|
|
548
580
|
* The transaction method is used to wrap multiple changes to the Store so that
|
|
549
581
|
* the relevant listeners only fire once.
|
|
550
582
|
*
|
|
@@ -867,6 +899,26 @@ export interface Store {
|
|
|
867
899
|
*/
|
|
868
900
|
getCell(tableId: Id, rowId: Id, cellId: Id): Cell | undefined;
|
|
869
901
|
|
|
902
|
+
/**
|
|
903
|
+
* The hasTables method returns a boolean indicating whether any Table objects
|
|
904
|
+
* exist in the Store.
|
|
905
|
+
*
|
|
906
|
+
* @returns Whether any Tables exist.
|
|
907
|
+
* @example
|
|
908
|
+
* This example shows simple existence checks.
|
|
909
|
+
*
|
|
910
|
+
* ```js
|
|
911
|
+
* const store = createStore();
|
|
912
|
+
* console.log(store.hasTables());
|
|
913
|
+
* // -> false
|
|
914
|
+
* store.setTables({pets: {fido: {species: 'dog'}}});
|
|
915
|
+
* console.log(store.hasTables());
|
|
916
|
+
* // -> true
|
|
917
|
+
* ```
|
|
918
|
+
* @category Getter
|
|
919
|
+
*/
|
|
920
|
+
hasTables(): boolean;
|
|
921
|
+
|
|
870
922
|
/**
|
|
871
923
|
* The hasTable method returns a boolean indicating whether a given Table
|
|
872
924
|
* exists in the Store.
|
|
@@ -1611,7 +1663,7 @@ export interface Store {
|
|
|
1611
1663
|
*
|
|
1612
1664
|
* This method is useful for iterating over the Table structure of the Store
|
|
1613
1665
|
* in a functional style. The `tableCallback` parameter is a TableCallback
|
|
1614
|
-
* function that will called with the Id of each Table, and with a function
|
|
1666
|
+
* function that will be called with the Id of each Table, and with a function
|
|
1615
1667
|
* that can then be used to iterate over each Row of the Table, should you
|
|
1616
1668
|
* wish.
|
|
1617
1669
|
*
|
|
@@ -1644,9 +1696,10 @@ export interface Store {
|
|
|
1644
1696
|
*
|
|
1645
1697
|
* This method is useful for iterating over the Row structure of the Table in
|
|
1646
1698
|
* a functional style. The `rowCallback` parameter is a RowCallback function
|
|
1647
|
-
* that will called with the Id of each Row, and with a function that can
|
|
1648
|
-
* be used to iterate over each Cell of the Row, should you wish.
|
|
1699
|
+
* that will be called with the Id of each Row, and with a function that can
|
|
1700
|
+
* then be used to iterate over each Cell of the Row, should you wish.
|
|
1649
1701
|
*
|
|
1702
|
+
* @param tableId The Id of the Table to iterate over.
|
|
1650
1703
|
* @param rowCallback The function that should be called for every Row.
|
|
1651
1704
|
* @example
|
|
1652
1705
|
* This example iterates over each Row in a Table, and lists each Cell Id
|
|
@@ -1678,8 +1731,10 @@ export interface Store {
|
|
|
1678
1731
|
*
|
|
1679
1732
|
* This method is useful for iterating over the Cell structure of the Row in a
|
|
1680
1733
|
* functional style. The `cellCallback` parameter is a CellCallback function
|
|
1681
|
-
* that will called with the Id and value of each Cell.
|
|
1734
|
+
* that will be called with the Id and value of each Cell.
|
|
1682
1735
|
*
|
|
1736
|
+
* @param tableId The Id of the Table containing the Row to iterate over.
|
|
1737
|
+
* @param rowId The Id of the Row to iterate over.
|
|
1683
1738
|
* @param cellCallback The function that should be called for every Cell.
|
|
1684
1739
|
* @example
|
|
1685
1740
|
* This example iterates over each Cell in a Row, and lists its value.
|
|
@@ -2348,6 +2403,133 @@ export interface Store {
|
|
|
2348
2403
|
mutator?: boolean,
|
|
2349
2404
|
): Id;
|
|
2350
2405
|
|
|
2406
|
+
/**
|
|
2407
|
+
* The addInvalidCellListener method registers a listener function with the
|
|
2408
|
+
* Store that will be called whenever invalid data was attempted to be written
|
|
2409
|
+
* to a Cell.
|
|
2410
|
+
*
|
|
2411
|
+
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
2412
|
+
* and Cell Id as the method's first three parameters) or invalid attempts to
|
|
2413
|
+
* change any Cell (by providing `null` wildcards).
|
|
2414
|
+
*
|
|
2415
|
+
* All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
|
|
2416
|
+
* be wildcarded with `null`. You can listen to a specific Cell in a specific
|
|
2417
|
+
* Row in a specific Table, any Cell in any Row in any Table, for example - or
|
|
2418
|
+
* every other combination of wildcards.
|
|
2419
|
+
*
|
|
2420
|
+
* The provided listener is an InvalidCellListener function, and will be
|
|
2421
|
+
* called with a reference to the Store, the Id of the Table, the Id of the
|
|
2422
|
+
* Row, and the Id of Cell that were being attempted to be changed. It is also
|
|
2423
|
+
* given the invalid value of the Cell, which could have been of absolutely
|
|
2424
|
+
* any type. Since there could have been multiple failed attempts to set the
|
|
2425
|
+
* Cell within a single transaction, this is an array containing each attempt,
|
|
2426
|
+
* chronologically.
|
|
2427
|
+
*
|
|
2428
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
2429
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
2430
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
2431
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
2432
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
2433
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
2434
|
+
* though they will fire non-mutator listeners.
|
|
2435
|
+
*
|
|
2436
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
2437
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
2438
|
+
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
2439
|
+
* @param listener The function that will be called whenever an attempt to
|
|
2440
|
+
* write invalid data to the matching Cell was made.
|
|
2441
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2442
|
+
* Store data.
|
|
2443
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
2444
|
+
* explicitly, or to remove it.
|
|
2445
|
+
* @example
|
|
2446
|
+
* This example registers a listener that responds to any invalid changes to a
|
|
2447
|
+
* specific Cell.
|
|
2448
|
+
*
|
|
2449
|
+
* ```js
|
|
2450
|
+
* const store = createStore().setTables({
|
|
2451
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
2452
|
+
* });
|
|
2453
|
+
* const listenerId = store.addInvalidCellListener(
|
|
2454
|
+
* 'pets',
|
|
2455
|
+
* 'fido',
|
|
2456
|
+
* 'color',
|
|
2457
|
+
* (store, tableId, rowId, cellId, invalidCells) => {
|
|
2458
|
+
* console.log('Invalid color cell in fido row in pets table');
|
|
2459
|
+
* console.log(invalidCells);
|
|
2460
|
+
* },
|
|
2461
|
+
* );
|
|
2462
|
+
*
|
|
2463
|
+
* store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
|
|
2464
|
+
* // -> 'Invalid color cell in fido row in pets table'
|
|
2465
|
+
* // -> [{r: '96', g: '4B', b: '00'}]
|
|
2466
|
+
*
|
|
2467
|
+
* store.delListener(listenerId);
|
|
2468
|
+
* ```
|
|
2469
|
+
* @example
|
|
2470
|
+
* This example registers a listener that responds to any invalid changes to
|
|
2471
|
+
* any Cell.
|
|
2472
|
+
*
|
|
2473
|
+
* ```js
|
|
2474
|
+
* const store = createStore().setTables({
|
|
2475
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
2476
|
+
* });
|
|
2477
|
+
* const listenerId = store.addInvalidCellListener(
|
|
2478
|
+
* null,
|
|
2479
|
+
* null,
|
|
2480
|
+
* null,
|
|
2481
|
+
* (store, tableId, rowId, cellId) => {
|
|
2482
|
+
* console.log(
|
|
2483
|
+
* `Invalid ${cellId} cell in ${rowId} row in ${tableId} table`,
|
|
2484
|
+
* );
|
|
2485
|
+
* },
|
|
2486
|
+
* );
|
|
2487
|
+
*
|
|
2488
|
+
* store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
|
|
2489
|
+
* // -> 'Invalid color cell in fido row in pets table'
|
|
2490
|
+
* store.setTable('sales', {fido: {date: new Date()}});
|
|
2491
|
+
* // -> 'Invalid date cell in fido row in sales table'
|
|
2492
|
+
*
|
|
2493
|
+
* store.delListener(listenerId);
|
|
2494
|
+
* ```
|
|
2495
|
+
* @example
|
|
2496
|
+
* This example registers a listener that responds to any changes to a
|
|
2497
|
+
* specific Cell, and which also mutates the Store itself.
|
|
2498
|
+
*
|
|
2499
|
+
* ```js
|
|
2500
|
+
* const store = createStore().setTables({
|
|
2501
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
2502
|
+
* });
|
|
2503
|
+
* const listenerId = store.addInvalidCellListener(
|
|
2504
|
+
* 'pets',
|
|
2505
|
+
* 'fido',
|
|
2506
|
+
* 'color',
|
|
2507
|
+
* (store, tableId, rowId, cellId, invalidCells) =>
|
|
2508
|
+
* store.setCell(
|
|
2509
|
+
* 'meta',
|
|
2510
|
+
* 'invalid_updates',
|
|
2511
|
+
* `${tableId}_${rowId}_${cellId}`,
|
|
2512
|
+
* JSON.stringify(invalidCells[0]),
|
|
2513
|
+
* ),
|
|
2514
|
+
* true,
|
|
2515
|
+
* );
|
|
2516
|
+
*
|
|
2517
|
+
* store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
|
|
2518
|
+
* console.log(store.getRow('meta', 'invalid_updates'));
|
|
2519
|
+
* // -> {'pets_fido_color': '{"r":"96","g":"4B","b":"00"}'}
|
|
2520
|
+
*
|
|
2521
|
+
* store.delListener(listenerId);
|
|
2522
|
+
* ```
|
|
2523
|
+
* @category Listener
|
|
2524
|
+
*/
|
|
2525
|
+
addInvalidCellListener(
|
|
2526
|
+
tableId: IdOrNull,
|
|
2527
|
+
rowId: IdOrNull,
|
|
2528
|
+
cellId: IdOrNull,
|
|
2529
|
+
listener: InvalidCellListener,
|
|
2530
|
+
mutator?: boolean,
|
|
2531
|
+
): Id;
|
|
2532
|
+
|
|
2351
2533
|
/**
|
|
2352
2534
|
* The callListener method provides a way for you to manually provoke a
|
|
2353
2535
|
* listener to be called, even if the underlying data hasn't changed.
|