tinybase 4.4.0 → 4.4.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 (50) hide show
  1. package/lib/cjs/persisters/persister-partykit-server.cjs +1 -1
  2. package/lib/cjs/persisters/persister-partykit-server.cjs.gz +0 -0
  3. package/lib/cjs/ui-react.cjs +1 -1
  4. package/lib/cjs/ui-react.cjs.gz +0 -0
  5. package/lib/cjs-es6/persisters/persister-partykit-server.cjs +1 -1
  6. package/lib/cjs-es6/persisters/persister-partykit-server.cjs.gz +0 -0
  7. package/lib/cjs-es6/ui-react.cjs +1 -1
  8. package/lib/cjs-es6/ui-react.cjs.gz +0 -0
  9. package/lib/debug/checkpoints.js +8 -8
  10. package/lib/debug/indexes.js +8 -8
  11. package/lib/debug/metrics.js +8 -8
  12. package/lib/debug/persisters/persister-automerge.js +23 -23
  13. package/lib/debug/persisters/persister-partykit-server.js +35 -21
  14. package/lib/debug/persisters/persister-yjs.js +23 -23
  15. package/lib/debug/queries.js +10 -10
  16. package/lib/debug/relationships.js +6 -6
  17. package/lib/debug/store.js +10 -10
  18. package/lib/debug/tinybase.js +24 -24
  19. package/lib/debug/tools.js +2 -2
  20. package/lib/debug/ui-react-dom.js +12 -12
  21. package/lib/debug/ui-react.js +56 -22
  22. package/lib/es6/persisters/persister-partykit-server.js +1 -1
  23. package/lib/es6/persisters/persister-partykit-server.js.gz +0 -0
  24. package/lib/es6/ui-react.js +1 -1
  25. package/lib/es6/ui-react.js.gz +0 -0
  26. package/lib/persisters/persister-partykit-server.js +1 -1
  27. package/lib/persisters/persister-partykit-server.js.gz +0 -0
  28. package/lib/types/metrics.d.ts +2 -2
  29. package/lib/types/persisters/persister-partykit-server.d.ts +58 -2
  30. package/lib/types/persisters/persister-remote.d.ts +6 -1
  31. package/lib/types/queries.d.ts +2 -45
  32. package/lib/types/ui-react.d.ts +53 -0
  33. package/lib/types/with-schemas/metrics.d.ts +2 -2
  34. package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +61 -0
  35. package/lib/types/with-schemas/persisters/persister-remote.d.ts +6 -1
  36. package/lib/types/with-schemas/queries.d.ts +2 -45
  37. package/lib/types/with-schemas/store.d.ts +8 -8
  38. package/lib/types/with-schemas/ui-react.d.ts +59 -0
  39. package/lib/ui-react.js +1 -1
  40. package/lib/ui-react.js.gz +0 -0
  41. package/lib/umd/persisters/persister-partykit-server.js +1 -1
  42. package/lib/umd/persisters/persister-partykit-server.js.gz +0 -0
  43. package/lib/umd/ui-react.js +1 -1
  44. package/lib/umd/ui-react.js.gz +0 -0
  45. package/lib/umd-es6/persisters/persister-partykit-server.js +1 -1
  46. package/lib/umd-es6/persisters/persister-partykit-server.js.gz +0 -0
  47. package/lib/umd-es6/ui-react.js +1 -1
  48. package/lib/umd-es6/ui-react.js.gz +0 -0
  49. package/package.json +19 -19
  50. package/readme.md +2 -2
@@ -18,8 +18,15 @@
18
18
  * @since 4.3.0
19
19
  */
20
20
 
21
- import {Cell, CellOrUndefined, Value, ValueOrUndefined} from '../store';
22
- import {Connection, Party, Request, Server} from 'partykit/server';
21
+ import {
22
+ Cell,
23
+ CellOrUndefined,
24
+ Tables,
25
+ Value,
26
+ ValueOrUndefined,
27
+ Values,
28
+ } from '../store';
29
+ import {Connection, Party, Request, Server, Storage} from 'partykit/server';
23
30
  import {Id} from '../common';
24
31
 
25
32
  /**
@@ -517,3 +524,52 @@ export class TinyBasePartyKitServer implements Server {
517
524
  */
518
525
  canDelValue(valueId: Id, connection: Connection): boolean;
519
526
  }
527
+
528
+ /**
529
+ * The hasStoreInStorage function returns a boolean indicating whether durable
530
+ * PartyKit storage contains a serialized Store.
531
+ *
532
+ * This is intended for specialist applications that require the ability to
533
+ * inspect or load a TinyBase Store from a server's storage outside of the
534
+ * normal context of a TinyBasePartyKitServer.
535
+ *
536
+ * The function is asynchronous, so you should use the `await` keyword or handle
537
+ * the result as a promise.
538
+ * @param storage A reference to the storage object, as would normally be
539
+ * accessible from the `TinyBasePartyKitServer.party` object.
540
+ * @param storagePrefix An optional prefix used before all the keys in the
541
+ * server's durable storage, to match the equivalent property in the server's
542
+ * TinyBasePartyKitServerConfig.
543
+ * @returns A promised boolean indicating whether a Store is present in the
544
+ * storage.
545
+ * @category Storage
546
+ * @since v4.4.1
547
+ */
548
+ export function hasStoreInStorage(
549
+ storage: Storage,
550
+ storagePrefix?: string,
551
+ ): Promise<boolean>;
552
+
553
+ /**
554
+ * The loadStoreFromStorage function returns the content of a Store from durable
555
+ * PartyKit storage.
556
+ *
557
+ * This is intended for specialist applications that require the ability to
558
+ * inspect or load a TinyBase Store from a server's storage outside of the
559
+ * normal context of a TinyBasePartyKitServer.
560
+ *
561
+ * The function is asynchronous, so you should use the `await` keyword or handle
562
+ * the result as a promise.
563
+ * @param storage A reference to the storage object, as would normally be
564
+ * accessible from the `TinyBasePartyKitServer.party` object.
565
+ * @param storagePrefix An optional prefix used before all the keys in the
566
+ * server's durable storage, to match the equivalent property in the server's
567
+ * TinyBasePartyKitServerConfig.
568
+ * @returns A promised array of a Tables object and a Values object.
569
+ * @category Storage
570
+ * @since v4.4.1
571
+ */
572
+ export function loadStoreFromStorage(
573
+ storage: Storage,
574
+ storagePrefix?: string,
575
+ ): Promise<[Tables, Values]>;
@@ -55,8 +55,13 @@ export interface RemotePersister extends Persister {
55
55
  * the `POST` method (to send the Store JSON to save) respectively.
56
56
  *
57
57
  * For when you choose to enable automatic loading for the Persister (with the
58
- * startAutoLoad method), it will poll the loadUrl for changes. The
58
+ * startAutoLoad method), it will poll the loadUrl for changes, using the
59
+ * `ETag` HTTP header to identify if things have changed. The
59
60
  * `autoLoadIntervalSeconds` method is used to indicate how often to do this.
61
+ *
62
+ * If you are implementing the server portion of this functionality yourself,
63
+ * remember to ensure that the `ETag` header changes every time the server's
64
+ * Store content does - otherwise changes will not be detected by the client.
60
65
  * @param store The Store to persist.
61
66
  * @param loadUrl The endpoint that supports a `GET` method to load JSON.
62
67
  * @param saveUrl The endpoint that supports a `POST` method to save JSON.
@@ -1313,49 +1313,6 @@ export type Where = {
1313
1313
  * ```js
1314
1314
  * const store = createStore()
1315
1315
  * .setTable('pets', {
1316
- * fido: {species: 'dog', color: 'brown', owner: 'alice'},
1317
- * felix: {species: 'cat', color: 'black', owner: 'bob'},
1318
- * cujo: {species: 'dog', color: 'black', owner: 'bob'},
1319
- * lowly: {species: 'worm', color: 'brown', owner: 'alice'},
1320
- * carnaby: {species: 'parrot', color: 'black', owner: 'bob'},
1321
- * polly: {species: 'parrot', color: 'red', owner: 'alice'},
1322
- * })
1323
- * .setTable('species', {
1324
- * dog: {price: 5, legs: 4},
1325
- * cat: {price: 4, legs: 4},
1326
- * parrot: {price: 3, legs: 2},
1327
- * worm: {price: 1, legs: 0},
1328
- * });
1329
- *
1330
- * const queries = createQueries(store);
1331
- * queries.setQueryDefinition('query', 'pets', ({select, join, group}) => {
1332
- * select('pets', 'color'); // group by
1333
- * select('pets', 'owner'); // group by
1334
- * select('species', 'price'); // grouped
1335
- * select('species', 'legs'); // grouped
1336
- * // from pets
1337
- * join('species', 'species');
1338
- * group('price', 'avg').as('avgPrice');
1339
- * group('legs', 'sum').as('sumLegs');
1340
- * });
1341
- *
1342
- * queries.forEachResultRow('query', (rowId) => {
1343
- * console.log({[rowId]: queries.getResultRow('query', rowId)});
1344
- * });
1345
- * // -> {0: {color: 'brown', owner: 'alice', avgPrice: 3, sumLegs: 4}}
1346
- * // -> {1: {color: 'black', owner: 'bob', avgPrice: 4, sumLegs: 10}}
1347
- * // -> {2: {color: 'red', owner: 'alice', avgPrice: 3, sumLegs: 2}}
1348
- * ```
1349
- * @example
1350
- * This example shows a query that calculates the a custom aggregate of one
1351
- * Cell's values, grouped by another. Note how `aggregateAdd`,
1352
- * `aggregateRemove`, and `aggregateReplace` parameters are provided to make the
1353
- * custom aggregation more efficient as individual values are added, removed, or
1354
- * replaced during the lifecycle of the Table.
1355
- *
1356
- * ```js
1357
- * const store = createStore()
1358
- * .setTable('pets', {
1359
1316
  * fido: {species: 'dog', owner: 'alice'},
1360
1317
  * felix: {species: 'cat', owner: 'bob'},
1361
1318
  * cujo: {species: 'dog', owner: 'bob'},
@@ -1385,8 +1342,8 @@ export type Where = {
1385
1342
  * remove == current
1386
1343
  * ? undefined
1387
1344
  * : add > 2
1388
- * ? Math.min(current, add)
1389
- * : current,
1345
+ * ? Math.min(current, add)
1346
+ * : current,
1390
1347
  * ).as('lowestPriceOver2');
1391
1348
  * });
1392
1349
  *
@@ -427,6 +427,59 @@ export function useStoreOrStoreById(
427
427
  storeOrStoreId?: StoreOrStoreId,
428
428
  ): Store | undefined;
429
429
 
430
+ /**
431
+ * The useProvideStore hook is used to add a Store object by Id to a Provider
432
+ * component, but imperatively from a component within it.
433
+ *
434
+ * Normally you will register a Store by Id in a context by using the
435
+ * `storesById` prop of the top-level Provider component. This hook, however,
436
+ * lets you dynamically add a new Store to the context, from within a descendent
437
+ * component. This is useful for applications where the set of Stores is not
438
+ * known at the time of the first render of the root Provider.
439
+ *
440
+ * A Store added to the Provider context in this way will be available to other
441
+ * components within the context (using the useStore hook and so on). If you use
442
+ * the same Id as an existing Store registration, the new one will take priority
443
+ * over one provided by the `storesById` prop.
444
+ *
445
+ * Note that other components that consume a Store registered like this should
446
+ * defend against it being undefined at first. On the first render, the other
447
+ * component will likely not yet have completed the registration. In the example
448
+ * below, we use the null-safe `useStore('petStore')?.getTableIds()` to do this.
449
+ * @param storeId The Id of the Store object to be registered with the Provider.
450
+ * @param store The Store object to be registered.
451
+ * @example
452
+ * This example creates a Provider context. A child component registers a Store
453
+ * into it which is then consumable by a peer child component.
454
+ * ```jsx
455
+ * const App = () => (
456
+ * <Provider>
457
+ * <RegisterStore />
458
+ * <ConsumeStore />
459
+ * </Provider>
460
+ * );
461
+ * const RegisterStore = () => {
462
+ * const store = useCreateStore(() =>
463
+ * createStore().setCell('pets', 'fido', 'color', 'brown'),
464
+ * );
465
+ * useProvideStore('petStore', store);
466
+ * return null;
467
+ * };
468
+ * const ConsumeStore = () => (
469
+ * <span>{JSON.stringify(useStore('petStore')?.getTableIds())}</span>
470
+ * );
471
+ *
472
+ * const app = document.createElement('div');
473
+ * const root = ReactDOMClient.createRoot(app);
474
+ * root.render(<App />); // !act
475
+ * console.log(app.innerHTML);
476
+ * // -> '<span>["pets"]</span>'
477
+ * ```
478
+ * @category Store hooks
479
+ * @since v4.4.2
480
+ */
481
+ export function useProvideStore(storeId: Id, store: Store): void;
482
+
430
483
  /**
431
484
  * The useHasTables hook returns a boolean indicating whether any Table objects
432
485
  * exist in the Store, and registers a listener so that any changes to that
@@ -413,8 +413,8 @@ export interface Metrics<in out Schemas extends OptionalSchemas> {
413
413
  * remove == metric
414
414
  * ? undefined
415
415
  * : add > 2
416
- * ? Math.min(metric, add)
417
- * : metric,
416
+ * ? Math.min(metric, add)
417
+ * : metric,
418
418
  * );
419
419
  *
420
420
  * console.log(metrics.getMetric('lowestPriceOver2'));
@@ -23,8 +23,11 @@ import {
23
23
  CellOrUndefined,
24
24
  NoTablesSchema,
25
25
  NoValuesSchema,
26
+ OptionalSchemas,
27
+ Tables,
26
28
  Value,
27
29
  ValueOrUndefined,
30
+ Values,
28
31
  } from '../store';
29
32
  import {Connection, Party, Request, Server} from 'partykit/server';
30
33
  import {Id} from '../common';
@@ -550,3 +553,61 @@ export class TinyBasePartyKitServer implements Server {
550
553
  */
551
554
  canDelValue(valueId: Id, connection: Connection): boolean;
552
555
  }
556
+
557
+ /**
558
+ * The hasStoreInStorage function returns a boolean indicating whether durable
559
+ * PartyKit storage contains a serialized Store.
560
+ *
561
+ * This is intended for specialist applications that require the ability to
562
+ * inspect or load a TinyBase Store from a server's storage outside of the
563
+ * normal context of a TinyBasePartyKitServer.
564
+ *
565
+ * The function is asynchronous, so you should use the `await` keyword or handle
566
+ * the result as a promise.
567
+ * @param storage A reference to the storage object, as would normally be
568
+ * accessible from the `TinyBasePartyKitServer.party` object.
569
+ * @param storagePrefix An optional prefix used before all the keys in the
570
+ * server's durable storage, to match the equivalent property in the server's
571
+ * TinyBasePartyKitServerConfig.
572
+ * @returns A promised boolean indicating whether a Store is present in the
573
+ * storage.
574
+ * @category Storage
575
+ * @since v4.4.1
576
+ */
577
+ export function hasStoreInStorage(
578
+ storage: Storage,
579
+ storagePrefix?: string,
580
+ ): Promise<boolean>;
581
+
582
+ /**
583
+ * The loadStoreFromStorage function returns the content of a Store from durable
584
+ * PartyKit storage.
585
+ *
586
+ * This has schema-based typing. The following is a simplified representation:
587
+ *
588
+ * ```ts override
589
+ * loadStoreFromStorage(
590
+ * storage: Storage,
591
+ * storagePrefix?: string,
592
+ * ): Promise<[Tables, Values]>;
593
+ * ```
594
+ *
595
+ * This is intended for specialist applications that require the ability to
596
+ * inspect or load a TinyBase Store from a server's storage outside of the
597
+ * normal context of a TinyBasePartyKitServer.
598
+ *
599
+ * The function is asynchronous, so you should use the `await` keyword or handle
600
+ * the result as a promise.
601
+ * @param storage A reference to the storage object, as would normally be
602
+ * accessible from the `TinyBasePartyKitServer.party` object.
603
+ * @param storagePrefix An optional prefix used before all the keys in the
604
+ * server's durable storage, to match the equivalent property in the server's
605
+ * TinyBasePartyKitServerConfig.
606
+ * @returns A promised array of a Tables object and a Values object.
607
+ * @category Storage
608
+ * @since v4.4.1
609
+ */
610
+ export function loadStoreFromStorage<Schemas extends OptionalSchemas>(
611
+ storage: Storage,
612
+ storagePrefix?: string,
613
+ ): Promise<[Tables<Schemas[0]>, Values<Schemas[1]>]>;
@@ -68,8 +68,13 @@ export interface RemotePersister<Schemas extends OptionalSchemas>
68
68
  * the `POST` method (to send the Store JSON to save) respectively.
69
69
  *
70
70
  * For when you choose to enable automatic loading for the Persister (with the
71
- * startAutoLoad method), it will poll the loadUrl for changes. The
71
+ * startAutoLoad method), it will poll the loadUrl for changes, using the
72
+ * `ETag` HTTP header to identify if things have changed. The
72
73
  * `autoLoadIntervalSeconds` method is used to indicate how often to do this.
74
+ *
75
+ * If you are implementing the server portion of this functionality yourself,
76
+ * remember to ensure that the `ETag` header changes every time the server's
77
+ * Store content does - otherwise changes will not be detected by the client.
73
78
  * @param store The Store to persist.
74
79
  * @param loadUrl The endpoint that supports a `GET` method to load JSON.
75
80
  * @param saveUrl The endpoint that supports a `POST` method to save JSON.
@@ -1500,49 +1500,6 @@ export type Where<
1500
1500
  * ```js
1501
1501
  * const store = createStore()
1502
1502
  * .setTable('pets', {
1503
- * fido: {species: 'dog', color: 'brown', owner: 'alice'},
1504
- * felix: {species: 'cat', color: 'black', owner: 'bob'},
1505
- * cujo: {species: 'dog', color: 'black', owner: 'bob'},
1506
- * lowly: {species: 'worm', color: 'brown', owner: 'alice'},
1507
- * carnaby: {species: 'parrot', color: 'black', owner: 'bob'},
1508
- * polly: {species: 'parrot', color: 'red', owner: 'alice'},
1509
- * })
1510
- * .setTable('species', {
1511
- * dog: {price: 5, legs: 4},
1512
- * cat: {price: 4, legs: 4},
1513
- * parrot: {price: 3, legs: 2},
1514
- * worm: {price: 1, legs: 0},
1515
- * });
1516
- *
1517
- * const queries = createQueries(store);
1518
- * queries.setQueryDefinition('query', 'pets', ({select, join, group}) => {
1519
- * select('pets', 'color'); // group by
1520
- * select('pets', 'owner'); // group by
1521
- * select('species', 'price'); // grouped
1522
- * select('species', 'legs'); // grouped
1523
- * // from pets
1524
- * join('species', 'species');
1525
- * group('price', 'avg').as('avgPrice');
1526
- * group('legs', 'sum').as('sumLegs');
1527
- * });
1528
- *
1529
- * queries.forEachResultRow('query', (rowId) => {
1530
- * console.log({[rowId]: queries.getResultRow('query', rowId)});
1531
- * });
1532
- * // -> {0: {color: 'brown', owner: 'alice', avgPrice: 3, sumLegs: 4}}
1533
- * // -> {1: {color: 'black', owner: 'bob', avgPrice: 4, sumLegs: 10}}
1534
- * // -> {2: {color: 'red', owner: 'alice', avgPrice: 3, sumLegs: 2}}
1535
- * ```
1536
- * @example
1537
- * This example shows a query that calculates the a custom aggregate of one
1538
- * Cell's values, grouped by another. Note how `aggregateAdd`,
1539
- * `aggregateRemove`, and `aggregateReplace` parameters are provided to make the
1540
- * custom aggregation more efficient as individual values are added, removed, or
1541
- * replaced during the lifecycle of the Table.
1542
- *
1543
- * ```js
1544
- * const store = createStore()
1545
- * .setTable('pets', {
1546
1503
  * fido: {species: 'dog', owner: 'alice'},
1547
1504
  * felix: {species: 'cat', owner: 'bob'},
1548
1505
  * cujo: {species: 'dog', owner: 'bob'},
@@ -1572,8 +1529,8 @@ export type Where<
1572
1529
  * remove == current
1573
1530
  * ? undefined
1574
1531
  * : add > 2
1575
- * ? Math.min(current, add)
1576
- * : current,
1532
+ * ? Math.min(current, add)
1533
+ * : current,
1577
1534
  * ).as('lowestPriceOver2');
1578
1535
  * });
1579
1536
  *
@@ -304,10 +304,10 @@ export type Cell<
304
304
  > = CellType extends 'string'
305
305
  ? string
306
306
  : CellType extends 'number'
307
- ? number
308
- : CellType extends 'boolean'
309
- ? boolean
310
- : string | number | boolean;
307
+ ? number
308
+ : CellType extends 'boolean'
309
+ ? boolean
310
+ : string | number | boolean;
311
311
 
312
312
  /**
313
313
  * The CellOrUndefined type is a data structure representing the data in a
@@ -400,10 +400,10 @@ export type Value<
400
400
  > = ValueType extends 'string'
401
401
  ? string
402
402
  : ValueType extends 'number'
403
- ? number
404
- : ValueType extends 'boolean'
405
- ? boolean
406
- : string | number | boolean;
403
+ ? number
404
+ : ValueType extends 'boolean'
405
+ ? boolean
406
+ : string | number | boolean;
407
407
 
408
408
  /**
409
409
  * The ValueOrUndefined type is a data structure representing the data in a
@@ -531,6 +531,65 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
531
531
  storeOrStoreId?: StoreOrStoreId<Schemas>,
532
532
  ) => Store<Schemas> | undefined;
533
533
 
534
+ /**
535
+ * The useProvideStore hook is used to add a Store object by Id to a Provider
536
+ * component, but imperatively from a component within it.
537
+ *
538
+ * This has schema-based typing. The following is a simplified representation:
539
+ *
540
+ * ```ts override
541
+ * useProvideStore(storeId: Id, store: Store): void;
542
+ * ```
543
+ *
544
+ * Normally you will register a Store by Id in a context by using the
545
+ * `storesById` prop of the top-level Provider component. This hook, however,
546
+ * lets you dynamically add a new Store to the context, from within a descendent
547
+ * component. This is useful for applications where the set of Stores is not
548
+ * known at the time of the first render of the root Provider.
549
+ *
550
+ * A Store added to the Provider context in this way will be available to other
551
+ * components within the context (using the useStore hook and so on). If you use
552
+ * the same Id as an existing Store registration, the new one will take priority
553
+ * over one provided by the `storesById` prop.
554
+ *
555
+ * Note that other components that consume a Store registered like this should
556
+ * defend against it being undefined at first. On the first render, the other
557
+ * component will likely not yet have completed the registration. In the example
558
+ * below, we use the null-safe `useStore('petStore')?.getTableIds()` to do this.
559
+ * @param storeId The Id of the Store object to be registered with the Provider.
560
+ * @param store The Store object to be registered.
561
+ * @example
562
+ * This example creates a Provider context. A child component registers a Store
563
+ * into it which is then consumable by a peer child component.
564
+ * ```jsx
565
+ * const App = () => (
566
+ * <Provider>
567
+ * <RegisterStore />
568
+ * <ConsumeStore />
569
+ * </Provider>
570
+ * );
571
+ * const RegisterStore = () => {
572
+ * const store = useCreateStore(() =>
573
+ * createStore().setCell('pets', 'fido', 'color', 'brown'),
574
+ * );
575
+ * useProvideStore('petStore', store);
576
+ * return null;
577
+ * };
578
+ * const ConsumeStore = () => (
579
+ * <span>{JSON.stringify(useStore('petStore')?.getTableIds())}</span>
580
+ * );
581
+ *
582
+ * const app = document.createElement('div');
583
+ * const root = ReactDOMClient.createRoot(app);
584
+ * root.render(<App />); // !act
585
+ * console.log(app.innerHTML);
586
+ * // -> '<span>["pets"]</span>'
587
+ * ```
588
+ * @category Store hooks
589
+ * @since v4.4.2
590
+ */
591
+ useProvideStore: (storeId: Id, store: Store<Schemas>) => void;
592
+
534
593
  /**
535
594
  * The useHasTables hook returns a boolean indicating whether any Table objects
536
595
  * exist in the Store, and registers a listener so that any changes to that
package/lib/ui-react.js CHANGED
@@ -1 +1 @@
1
- import e,{useContext as t}from"react";const o=e=>typeof e,s="",r=o(s),d="Listener",n="Result",u="Has",I="has",i="Ids",c="Table",l=c+"s",a=c+i,p="Row",g=p+"Count",b=p+i,C="Sorted"+p+i,m="Cell",y=m+i,k="Value",w=k+"s",h=k+i,R=e=>null==e,v=(e,t,o)=>R(e)?o?.():t(e),q=e=>o(e)==r,f=()=>{},P=(e,t)=>e.map(t),x=Object.keys,{createContext:S,useContext:L}=e,B=S([]),T=(e,t)=>{const o=L(B);return R(e)?o[t]:q(e)?((e,t)=>v(e,(e=>e[t])))(o[t+1]??{},e):e},M=(e,t)=>{const o=T(e,t);return R(e)||q(e)?o:e},E=e=>x(L(B)[e]??{}),F=e=>T(e,0),V=e=>M(e,0),A=e=>T(e,2),j=e=>M(e,2),D=e=>T(e,4),H=e=>M(e,4),O=e=>T(e,6),Q=e=>M(e,6),W=e=>T(e,8),z=e=>M(e,8),G=e=>T(e,10),J=e=>M(e,10),K=e=>e.toLowerCase();K(d);const N="Transaction";K(N);const{useCallback:U,useEffect:X,useMemo:Y,useLayoutEffect:Z,useRef:$,useState:_}=e,ee=[],te={},oe=[[],void 0,[]],se=(e,t,o=ee)=>{const s=Y((()=>t(e)),[e,...o]);return X((()=>()=>s.destroy()),[s]),s},re=(e,t,o,s=ee,r,d="get",n="")=>{const[,u]=_(),I=U((()=>t?.[d+e]?.(...s)??o),[t,e,...s,o]),i=$();return Y((()=>i.current=I()),[I]),de(n+e,t,((...e)=>{i.current=R(r)?I():e[r],u([])}),[I,r],s),i.current},de=(e,t,o,s=ee,r=ee,...n)=>Z((()=>{const s=t?.["add"+e+d]?.(...r,o,...n);return()=>t?.delListener(s)}),[t,e,...r,...s,...n]),ne=(e,t,o,s=ee,r=f,d=ee,...n)=>{const u=V(e);return U((e=>v(u,(s=>v(o(e,s),(e=>r(s["set"+t](...n,e),e)))))),[u,t,...s,...d,...n])},ue=(e,t,o=f,s=ee,...r)=>{const d=V(e);return U((()=>o(d?.["del"+t](...r))),[d,t,...s,...r])},Ie=(e,t,o)=>{const s=J(e);return U((()=>s?.[t](o)),[s,t,o])},ie=(e,t=ee)=>Y(e,t),ce=()=>E(1),le=e=>re(l,V(e),!1,[],1,I,u),ae=e=>re(l,V(e),te),pe=e=>re(a,V(e),ee),ge=(e,t)=>re(c,V(t),!1,[e],2,I,u),be=(e,t)=>re(c,V(t),te,[e]),Ce=(e,t)=>re(c+y,V(t),ee,[e]),me=(e,t,o)=>re(c+m,V(o),!1,[e,t],3,I,u),ye=(e,t)=>re(g,V(t),0,[e]),ke=(e,t)=>re(b,V(t),ee,[e]),we=(e,t,o,s=0,r,d)=>re(C,V(d),ee,[e,t,o,s,r],6),he=(e,t,o)=>re(p,V(o),!1,[e,t],3,I,u),Re=(e,t,o)=>re(p,V(o),te,[e,t]),ve=(e,t,o)=>re(y,V(o),ee,[e,t]),qe=(e,t,o,s)=>re(m,V(s),!1,[e,t,o],4,I,u),fe=(e,t,o,s)=>re(m,V(s),void 0,[e,t,o],4),Pe=e=>re(w,V(e),!1,[],1,I,u),xe=e=>re(w,V(e),te),Se=e=>re(h,V(e),ee),Le=(e,t)=>re(k,V(t),!1,[e],2,I,u),Be=(e,t)=>re(k,V(t),void 0,[e]),Te=(e,t,o,s,r)=>ne(o,l,e,t,s,r),Me=(e,t,o,s,r,d)=>ne(s,c,t,o,r,d,e),Ee=(e,t,o,s,r,d,n)=>ne(r,p,o,s,d,n,e,t),Fe=(e,t,o=ee,s,r=f,d=ee,n=!0)=>{const u=V(s);return U((o=>v(u,(s=>v(t(o,s),(t=>r(s.addRow(e,t,n),s,t)))))),[u,e,...o,...d,n])},Ve=(e,t,o,s,r,d,n)=>ne(r,"PartialRow",o,s,d,n,e,t),Ae=(e,t,o,s,r,d,n,u)=>ne(d,m,s,r,n,u,e,t,o),je=(e,t,o,s,r)=>ne(o,w,e,t,s,r),De=(e,t,o,s,r)=>ne(o,"PartialValues",e,t,s,r),He=(e,t,o,s,r,d)=>ne(s,k,t,o,r,d,e),Oe=(e,t,o)=>ue(e,l,t,o),Qe=(e,t,o,s)=>ue(t,c,o,s,e),We=(e,t,o,s,r)=>ue(o,p,s,r,e,t),ze=(e,t,o,s,r,d,n)=>ue(r,m,d,n,e,t,o,s),Ge=(e,t,o)=>ue(e,w,t,o),Je=(e,t,o,s)=>ue(t,k,o,s,e),Ke=(e,t,o,s)=>de(u+l,V(s),e,t,[],o),Ne=(e,t,o,s)=>de(l,V(s),e,t,ee,o),Ue=(e,t,o,s)=>de(a,V(s),e,t,ee,o),Xe=(e,t,o,s,r)=>de(u+c,V(r),t,o,[e],s),Ye=(e,t,o,s,r)=>de(c,V(r),t,o,[e],s),Ze=(e,t,o,s,r)=>de(c+y,V(r),t,o,[e],s),$e=(e,t,o,s,r,d)=>de(u+c+m,V(d),o,s,[e,t],r),_e=(e,t,o,s,r)=>de(g,V(r),t,o,[e],s),et=(e,t,o,s,r)=>de(b,V(r),t,o,[e],s),tt=(e,t,o,s,r,d,n,u,I)=>de(C,V(I),d,n,[e,t,o,s,r],u),ot=(e,t,o,s,r,d)=>de(u+p,V(d),o,s,[e,t],r),st=(e,t,o,s,r,d)=>de(p,V(d),o,s,[e,t],r),rt=(e,t,o,s,r,d)=>de(y,V(d),o,s,[e,t],r),dt=(e,t,o,s,r,d,n)=>de(u+m,V(n),s,r,[e,t,o],d),nt=(e,t,o,s,r,d,n)=>de(m,V(n),s,r,[e,t,o],d),ut=(e,t,o,s)=>de(u+w,V(s),e,t,[],o),It=(e,t,o,s)=>de(w,V(s),e,t,ee,o),it=(e,t,o,s)=>de(h,V(s),e,t,ee,o),ct=(e,t,o,s,r)=>de(u+k,V(r),t,o,[e],s),lt=(e,t,o,s,r)=>de(k,V(r),t,o,[e],s),at=(e,t,o)=>de("Start"+N,V(o),e,t),pt=(e,t,o)=>de("WillFinish"+N,V(o),e,t),gt=(e,t,o)=>de("DidFinish"+N,V(o),e,t),bt=(e,t,o)=>se(e,t,o),Ct=()=>E(3),mt=e=>re("MetricIds",j(e),ee),yt=(e,t)=>re("Metric",j(t),void 0,[e]),kt=(e,t,o,s)=>de("Metric",j(s),t,o,[e]),wt=(e,t,o)=>se(e,t,o),ht=()=>E(5),Rt=(e,t)=>re("SliceIds",H(t),ee,[e]),vt=e=>re("IndexIds",H(e),ee),qt=(e,t,o)=>re("Slice"+b,H(o),ee,[e,t]),ft=(e,t,o,s)=>de("SliceIds",H(s),t,o,[e]),Pt=(e,t,o,s,r)=>de("Slice"+b,H(r),o,s,[e,t]),xt=(e,t,o)=>se(e,t,o),St=()=>E(7),Lt=e=>re("RelationshipIds",Q(e),ee),Bt=(e,t,o)=>re("RemoteRowId",Q(o),void 0,[e,t]),Tt=(e,t,o)=>re("Local"+b,Q(o),ee,[e,t]),Mt=(e,t,o)=>re("Linked"+b,Q(o),ee,[e,t]),Et=(e,t,o,s,r)=>de("RemoteRowId",Q(r),o,s,[e,t]),Ft=(e,t,o,s,r)=>de("Local"+b,Q(r),o,s,[e,t]),Vt=(e,t,o,s,r)=>de("Linked"+b,Q(r),o,s,[e,t]),At=(e,t,o)=>se(e,t,o),jt=()=>E(9),Dt=e=>re("QueryIds",z(e),ee),Ht=(e,t)=>re(n+c,z(t),te,[e]),Ot=(e,t)=>re(n+c+y,z(t),ee,[e]),Qt=(e,t)=>re(n+g,z(t),0,[e]),Wt=(e,t)=>re(n+b,z(t),ee,[e]),zt=(e,t,o,s=0,r,d)=>re(n+C,z(d),ee,[e,t,o,s,r],6),Gt=(e,t,o)=>re(n+p,z(o),te,[e,t]),Jt=(e,t,o)=>re(n+y,z(o),ee,[e,t]),Kt=(e,t,o,s)=>re(n+m,z(s),void 0,[e,t,o]),Nt=(e,t,o,s)=>de(n+c,z(s),t,o,[e]),Ut=(e,t,o,s)=>de(n+c+y,z(s),t,o,[e]),Xt=(e,t,o,s)=>de(n+g,z(s),t,o,[e]),Yt=(e,t,o,s)=>de(n+b,z(s),t,o,[e]),Zt=(e,t,o,s,r,d,u,I)=>de(n+C,z(I),d,u,[e,t,o,s,r]),$t=(e,t,o,s,r)=>de(n+p,z(r),o,s,[e,t]),_t=(e,t,o,s,r)=>de(n+y,z(r),o,s,[e,t]),eo=(e,t,o,s,r,d)=>de(n+m,z(d),s,r,[e,t,o]),to=(e,t,o)=>se(e,t,o),oo=()=>E(11),so=e=>re("CheckpointIds",J(e),oe),ro=(e,t)=>re("Checkpoint",J(t),void 0,[e]),no=(e=f,t=ee,o,s=f,r=ee)=>{const d=J(o);return U((t=>v(d,(o=>{const r=e(t);s(o.addCheckpoint(r),o,r)}))),[d,...t,...r])},uo=e=>Ie(e,"goBackward"),Io=e=>Ie(e,"goForward"),io=(e,t=ee,o,s=f,r=ee)=>{const d=J(o);return U((t=>v(d,(o=>v(e(t),(e=>s(o.goTo(e),e)))))),[d,...t,...r])},co=e=>{const t=J(e),[o,r]=so(t);return[(d=o,!(0==d.length)),uo(t),r,v(r,(e=>t?.getCheckpoint(e)))??s];var d},lo=e=>{const t=J(e),[,,[o]]=so(t);return[!R(o),Io(t),o,v(o,(e=>t?.getCheckpoint(e)))??s]},ao=(e,t,o)=>de("CheckpointIds",J(o),e,t),po=(e,t,o,s)=>de("Checkpoint",J(s),t,o,[e]),go=(e,t,o=ee,s,r=ee,d,n=ee)=>{const[,u]=_(),I=Y((()=>t(e)),[e,...o]);return X((()=>((async()=>{s&&(await s(I),u([]))})(),()=>{I?.destroy(),d?.(I)})),[I,...r,...n]),I},{PureComponent:bo,Fragment:Co,createElement:mo,useCallback:yo,useLayoutEffect:ko,useRef:wo,useState:ho}=e,Ro=(e,...t)=>R(e)?{}:e(...t),vo=(e,t)=>[e,e?.getStore(),e?.getLocalTableId(t),e?.getRemoteTableId(t)],{useMemo:qo}=e,fo=({tableId:e,store:t,rowComponent:o=Mo,getRowComponentProps:s,customCellIds:r,separator:d,debugIds:n},u)=>Bo(P(u,(d=>mo(o,{...Ro(s,d),key:d,tableId:e,rowId:d,customCellIds:r,store:t,debugIds:n}))),d,n,e),Po=({queryId:e,queries:t,resultRowComponent:o=Jo,getResultRowComponentProps:s,separator:r,debugIds:d},n)=>Bo(P(n,(r=>mo(o,{...Ro(s,r),key:r,queryId:e,rowId:r,queries:t,debugIds:d}))),r,d,e),xo=({relationshipId:e,relationships:t,rowComponent:o=Mo,getRowComponentProps:s,separator:r,debugIds:d},n,u)=>{const[I,i,c]=vo(Q(t),e),l=n(e,u,I);return Bo(P(l,(e=>mo(o,{...Ro(s,e),key:e,tableId:c,rowId:e,store:i,debugIds:d}))),r,d,u)},So=e=>({checkpoints:t,checkpointComponent:o=Uo,getCheckpointComponentProps:s,separator:r,debugIds:d})=>{const n=J(t);return Bo(P(e(so(n)),(e=>mo(o,{...Ro(s,e),key:e,checkpoints:n,checkpointId:e,debugIds:d}))),r)},Lo=({store:e,storesById:o,metrics:s,metricsById:r,indexes:d,indexesById:n,relationships:u,relationshipsById:I,queries:i,queriesById:c,checkpoints:l,checkpointsById:a,children:p})=>{const g=t(B);return mo(B.Provider,{value:qo((()=>[e??g[0],{...g[1],...o},s??g[2],{...g[3],...r},d??g[4],{...g[5],...n},u??g[6],{...g[7],...I},i??g[8],{...g[9],...c},l??g[10],{...g[11],...a}]),[e,o,s,r,d,n,u,I,i,c,l,a,g])},p)},Bo=(e,t,o,s)=>{const r=R(t)||!Array.isArray(e)?e:P(e,((e,o)=>o>0?[t,e]:e));return o?[s,":{",r,"}"]:r},To=({tableId:e,rowId:t,cellId:o,store:r,debugIds:d})=>Bo(s+(fe(e,t,o,r)??s),void 0,d,o),Mo=({tableId:e,rowId:t,store:o,cellComponent:s=To,getCellComponentProps:r,customCellIds:d,separator:n,debugIds:u})=>Bo(P(((e,t,o,s)=>{const r=ve(t,o,s);return e??r})(d,e,t,o),(d=>mo(s,{...Ro(r,d),key:d,tableId:e,rowId:t,cellId:d,store:o,debugIds:u}))),n,u,t),Eo=e=>fo(e,ke(e.tableId,e.store)),Fo=({cellId:e,descending:t,offset:o,limit:s,...r})=>fo(r,we(r.tableId,e,t,o,s,r.store)),Vo=({store:e,tableComponent:t=Eo,getTableComponentProps:o,separator:s,debugIds:r})=>Bo(P(pe(e),(s=>mo(t,{...Ro(o,s),key:s,tableId:s,store:e,debugIds:r}))),s),Ao=({valueId:e,store:t,debugIds:o})=>Bo(s+(Be(e,t)??s),void 0,o,e),jo=({store:e,valueComponent:t=Ao,getValueComponentProps:o,separator:s,debugIds:r})=>Bo(P(Se(e),(s=>mo(t,{...Ro(o,s),key:s,valueId:s,store:e,debugIds:r}))),s),Do=({metricId:e,metrics:t,debugIds:o})=>Bo(yt(e,t)??s,void 0,o,e),Ho=({indexId:e,sliceId:t,indexes:o,rowComponent:s=Mo,getRowComponentProps:r,separator:d,debugIds:n})=>{const[u,I,i]=((e,t)=>[e,e?.getStore(),e?.getTableId(t)])(H(o),e),c=qt(e,t,u);return Bo(P(c,(e=>mo(s,{...Ro(r,e),key:e,tableId:i,rowId:e,store:I,debugIds:n}))),d,n,t)},Oo=({indexId:e,indexes:t,sliceComponent:o=Ho,getSliceComponentProps:s,separator:r,debugIds:d})=>Bo(P(Rt(e,t),(r=>mo(o,{...Ro(s,r),key:r,indexId:e,sliceId:r,indexes:t,debugIds:d}))),r,d,e),Qo=({relationshipId:e,localRowId:t,relationships:o,rowComponent:s=Mo,getRowComponentProps:r,debugIds:d})=>{const[n,u,,I]=vo(Q(o),e),i=Bt(e,t,n);return Bo(R(I)||R(i)?null:mo(s,{...Ro(r,i),key:i,tableId:I,rowId:i,store:u,debugIds:d}),void 0,d,t)},Wo=e=>xo(e,Tt,e.remoteRowId),zo=e=>xo(e,Mt,e.firstRowId),Go=({queryId:e,rowId:t,cellId:o,queries:r,debugIds:d})=>Bo(s+(Kt(e,t,o,r)??s),void 0,d,o),Jo=({queryId:e,rowId:t,queries:o,resultCellComponent:s=Go,getResultCellComponentProps:r,separator:d,debugIds:n})=>Bo(P(Jt(e,t,o),(d=>mo(s,{...Ro(r,d),key:d,queryId:e,rowId:t,cellId:d,queries:o,debugIds:n}))),d,n,t),Ko=e=>Po(e,Wt(e.queryId,e.queries)),No=({cellId:e,descending:t,offset:o,limit:s,...r})=>Po(r,zt(r.queryId,e,t,o,s,r.queries)),Uo=({checkpoints:e,checkpointId:t,debugIds:o})=>Bo(ro(t,e)??s,void 0,o,t),Xo=So((e=>e[0])),Yo=So((e=>R(e[1])?[]:[e[1]])),Zo=So((e=>e[2]));export{Xo as BackwardCheckpointsView,To as CellView,Uo as CheckpointView,Yo as CurrentCheckpointView,Zo as ForwardCheckpointsView,Oo as IndexView,zo as LinkedRowsView,Wo as LocalRowsView,Do as MetricView,Lo as Provider,Qo as RemoteRowView,Go as ResultCellView,Jo as ResultRowView,No as ResultSortedTableView,Ko as ResultTableView,Mo as RowView,Ho as SliceView,Fo as SortedTableView,Eo as TableView,Vo as TablesView,Ao as ValueView,jo as ValuesView,Fe as useAddRowCallback,fe as useCell,ve as useCellIds,rt as useCellIdsListener,nt as useCellListener,ro as useCheckpoint,so as useCheckpointIds,ao as useCheckpointIdsListener,po as useCheckpointListener,G as useCheckpoints,oo as useCheckpointsIds,J as useCheckpointsOrCheckpointsById,to as useCreateCheckpoints,wt as useCreateIndexes,bt as useCreateMetrics,go as useCreatePersister,At as useCreateQueries,xt as useCreateRelationships,ie as useCreateStore,ze as useDelCellCallback,We as useDelRowCallback,Qe as useDelTableCallback,Oe as useDelTablesCallback,Je as useDelValueCallback,Ge as useDelValuesCallback,gt as useDidFinishTransactionListener,uo as useGoBackwardCallback,Io as useGoForwardCallback,io as useGoToCallback,qe as useHasCell,dt as useHasCellListener,he as useHasRow,ot as useHasRowListener,ge as useHasTable,me as useHasTableCell,$e as useHasTableCellListener,Xe as useHasTableListener,le as useHasTables,Ke as useHasTablesListener,Le as useHasValue,ct as useHasValueListener,Pe as useHasValues,ut as useHasValuesListener,vt as useIndexIds,D as useIndexes,ht as useIndexesIds,H as useIndexesOrIndexesById,Mt as useLinkedRowIds,Vt as useLinkedRowIdsListener,Tt as useLocalRowIds,Ft as useLocalRowIdsListener,yt as useMetric,mt as useMetricIds,kt as useMetricListener,A as useMetrics,Ct as useMetricsIds,j as useMetricsOrMetricsById,W as useQueries,jt as useQueriesIds,z as useQueriesOrQueriesById,Dt as useQueryIds,lo as useRedoInformation,Lt as useRelationshipIds,O as useRelationships,St as useRelationshipsIds,Q as useRelationshipsOrRelationshipsById,Bt as useRemoteRowId,Et as useRemoteRowIdListener,Kt as useResultCell,Jt as useResultCellIds,_t as useResultCellIdsListener,eo as useResultCellListener,Gt as useResultRow,Qt as useResultRowCount,Xt as useResultRowCountListener,Wt as useResultRowIds,Yt as useResultRowIdsListener,$t as useResultRowListener,zt as useResultSortedRowIds,Zt as useResultSortedRowIdsListener,Ht as useResultTable,Ot as useResultTableCellIds,Ut as useResultTableCellIdsListener,Nt as useResultTableListener,Re as useRow,ye as useRowCount,_e as useRowCountListener,ke as useRowIds,et as useRowIdsListener,st as useRowListener,Ae as useSetCellCallback,no as useSetCheckpointCallback,Ve as useSetPartialRowCallback,De as useSetPartialValuesCallback,Ee as useSetRowCallback,Me as useSetTableCallback,Te as useSetTablesCallback,He as useSetValueCallback,je as useSetValuesCallback,Rt as useSliceIds,ft as useSliceIdsListener,qt as useSliceRowIds,Pt as useSliceRowIdsListener,we as useSortedRowIds,tt as useSortedRowIdsListener,at as useStartTransactionListener,F as useStore,ce as useStoreIds,V as useStoreOrStoreById,be as useTable,Ce as useTableCellIds,Ze as useTableCellIdsListener,pe as useTableIds,Ue as useTableIdsListener,Ye as useTableListener,ae as useTables,Ne as useTablesListener,co as useUndoInformation,Be as useValue,Se as useValueIds,it as useValueIdsListener,lt as useValueListener,xe as useValues,It as useValuesListener,pt as useWillFinishTransactionListener};
1
+ import e from"react";const t=e=>typeof e,o="",s=t(o),r="Listener",d="Result",n="Has",u="has",I="Ids",i="Table",c=i+"s",l=i+I,a="Row",p=a+"Count",g=a+I,b="Sorted"+a+I,C="Cell",m=C+I,k="Value",y=k+"s",w=k+I,h=e=>null==e,R=(e,t,o)=>h(e)?o?.():t(e),v=e=>t(e)==s,f=()=>{},q=(e,t)=>e.map(t),P=Object.keys,x=(e,t)=>R(e,(e=>e[t])),S=(e,t)=>(delete e[t],e),{createContext:L,useContext:B,useEffect:T}=e,E=L([]),M=(e,t)=>{const o=B(E);return h(e)?o[t]:v(e)?x(o[t+1]??{},e):e},F=(e,t)=>{const o=M(e,t);return h(e)||v(e)?o:e},V=e=>P(B(E)[e]??{}),A=e=>M(e,0),j=e=>F(e,0),D=(e,t)=>{const{12:o,13:s}=B(E);T((()=>(o?.(e,t),()=>s?.(e))),[o,e,t,s])},H=e=>M(e,2),O=e=>F(e,2),Q=e=>M(e,4),W=e=>F(e,4),z=e=>M(e,6),G=e=>F(e,6),J=e=>M(e,8),K=e=>F(e,8),N=e=>M(e,10),U=e=>F(e,10),X=e=>e.toLowerCase();X(r);const Y="Transaction";X(Y);const{useCallback:Z,useEffect:$,useMemo:_,useLayoutEffect:ee,useRef:te,useState:oe}=e,se=[],re={},de=[[],void 0,[]],ne=(e,t,o=se)=>{const s=_((()=>t(e)),[e,...o]);return $((()=>()=>s.destroy()),[s]),s},ue=(e,t,o,s=se,r,d="get",n="")=>{const[,u]=oe(),I=Z((()=>t?.[d+e]?.(...s)??o),[t,e,...s,o]),i=te();return _((()=>i.current=I()),[I]),Ie(n+e,t,((...e)=>{i.current=h(r)?I():e[r],u([])}),[I,r],s),i.current},Ie=(e,t,o,s=se,d=se,...n)=>ee((()=>{const s=t?.["add"+e+r]?.(...d,o,...n);return()=>t?.delListener(s)}),[t,e,...d,...s,...n]),ie=(e,t,o,s=se,r=f,d=se,...n)=>{const u=j(e);return Z((e=>R(u,(s=>R(o(e,s),(e=>r(s["set"+t](...n,e),e)))))),[u,t,...s,...d,...n])},ce=(e,t,o=f,s=se,...r)=>{const d=j(e);return Z((()=>o(d?.["del"+t](...r))),[d,t,...s,...r])},le=(e,t,o)=>{const s=U(e);return Z((()=>s?.[t](o)),[s,t,o])},ae=(e,t=se)=>_(e,t),pe=()=>V(1),ge=e=>ue(c,j(e),!1,[],1,u,n),be=e=>ue(c,j(e),re),Ce=e=>ue(l,j(e),se),me=(e,t)=>ue(i,j(t),!1,[e],2,u,n),ke=(e,t)=>ue(i,j(t),re,[e]),ye=(e,t)=>ue(i+m,j(t),se,[e]),we=(e,t,o)=>ue(i+C,j(o),!1,[e,t],3,u,n),he=(e,t)=>ue(p,j(t),0,[e]),Re=(e,t)=>ue(g,j(t),se,[e]),ve=(e,t,o,s=0,r,d)=>ue(b,j(d),se,[e,t,o,s,r],6),fe=(e,t,o)=>ue(a,j(o),!1,[e,t],3,u,n),qe=(e,t,o)=>ue(a,j(o),re,[e,t]),Pe=(e,t,o)=>ue(m,j(o),se,[e,t]),xe=(e,t,o,s)=>ue(C,j(s),!1,[e,t,o],4,u,n),Se=(e,t,o,s)=>ue(C,j(s),void 0,[e,t,o],4),Le=e=>ue(y,j(e),!1,[],1,u,n),Be=e=>ue(y,j(e),re),Te=e=>ue(w,j(e),se),Ee=(e,t)=>ue(k,j(t),!1,[e],2,u,n),Me=(e,t)=>ue(k,j(t),void 0,[e]),Fe=(e,t,o,s,r)=>ie(o,c,e,t,s,r),Ve=(e,t,o,s,r,d)=>ie(s,i,t,o,r,d,e),Ae=(e,t,o,s,r,d,n)=>ie(r,a,o,s,d,n,e,t),je=(e,t,o=se,s,r=f,d=se,n=!0)=>{const u=j(s);return Z((o=>R(u,(s=>R(t(o,s),(t=>r(s.addRow(e,t,n),s,t)))))),[u,e,...o,...d,n])},De=(e,t,o,s,r,d,n)=>ie(r,"PartialRow",o,s,d,n,e,t),He=(e,t,o,s,r,d,n,u)=>ie(d,C,s,r,n,u,e,t,o),Oe=(e,t,o,s,r)=>ie(o,y,e,t,s,r),Qe=(e,t,o,s,r)=>ie(o,"PartialValues",e,t,s,r),We=(e,t,o,s,r,d)=>ie(s,k,t,o,r,d,e),ze=(e,t,o)=>ce(e,c,t,o),Ge=(e,t,o,s)=>ce(t,i,o,s,e),Je=(e,t,o,s,r)=>ce(o,a,s,r,e,t),Ke=(e,t,o,s,r,d,n)=>ce(r,C,d,n,e,t,o,s),Ne=(e,t,o)=>ce(e,y,t,o),Ue=(e,t,o,s)=>ce(t,k,o,s,e),Xe=(e,t,o,s)=>Ie(n+c,j(s),e,t,[],o),Ye=(e,t,o,s)=>Ie(c,j(s),e,t,se,o),Ze=(e,t,o,s)=>Ie(l,j(s),e,t,se,o),$e=(e,t,o,s,r)=>Ie(n+i,j(r),t,o,[e],s),_e=(e,t,o,s,r)=>Ie(i,j(r),t,o,[e],s),et=(e,t,o,s,r)=>Ie(i+m,j(r),t,o,[e],s),tt=(e,t,o,s,r,d)=>Ie(n+i+C,j(d),o,s,[e,t],r),ot=(e,t,o,s,r)=>Ie(p,j(r),t,o,[e],s),st=(e,t,o,s,r)=>Ie(g,j(r),t,o,[e],s),rt=(e,t,o,s,r,d,n,u,I)=>Ie(b,j(I),d,n,[e,t,o,s,r],u),dt=(e,t,o,s,r,d)=>Ie(n+a,j(d),o,s,[e,t],r),nt=(e,t,o,s,r,d)=>Ie(a,j(d),o,s,[e,t],r),ut=(e,t,o,s,r,d)=>Ie(m,j(d),o,s,[e,t],r),It=(e,t,o,s,r,d,u)=>Ie(n+C,j(u),s,r,[e,t,o],d),it=(e,t,o,s,r,d,n)=>Ie(C,j(n),s,r,[e,t,o],d),ct=(e,t,o,s)=>Ie(n+y,j(s),e,t,[],o),lt=(e,t,o,s)=>Ie(y,j(s),e,t,se,o),at=(e,t,o,s)=>Ie(w,j(s),e,t,se,o),pt=(e,t,o,s,r)=>Ie(n+k,j(r),t,o,[e],s),gt=(e,t,o,s,r)=>Ie(k,j(r),t,o,[e],s),bt=(e,t,o)=>Ie("Start"+Y,j(o),e,t),Ct=(e,t,o)=>Ie("WillFinish"+Y,j(o),e,t),mt=(e,t,o)=>Ie("DidFinish"+Y,j(o),e,t),kt=(e,t,o)=>ne(e,t,o),yt=()=>V(3),wt=e=>ue("MetricIds",O(e),se),ht=(e,t)=>ue("Metric",O(t),void 0,[e]),Rt=(e,t,o,s)=>Ie("Metric",O(s),t,o,[e]),vt=(e,t,o)=>ne(e,t,o),ft=()=>V(5),qt=(e,t)=>ue("SliceIds",W(t),se,[e]),Pt=e=>ue("IndexIds",W(e),se),xt=(e,t,o)=>ue("Slice"+g,W(o),se,[e,t]),St=(e,t,o,s)=>Ie("SliceIds",W(s),t,o,[e]),Lt=(e,t,o,s,r)=>Ie("Slice"+g,W(r),o,s,[e,t]),Bt=(e,t,o)=>ne(e,t,o),Tt=()=>V(7),Et=e=>ue("RelationshipIds",G(e),se),Mt=(e,t,o)=>ue("RemoteRowId",G(o),void 0,[e,t]),Ft=(e,t,o)=>ue("Local"+g,G(o),se,[e,t]),Vt=(e,t,o)=>ue("Linked"+g,G(o),se,[e,t]),At=(e,t,o,s,r)=>Ie("RemoteRowId",G(r),o,s,[e,t]),jt=(e,t,o,s,r)=>Ie("Local"+g,G(r),o,s,[e,t]),Dt=(e,t,o,s,r)=>Ie("Linked"+g,G(r),o,s,[e,t]),Ht=(e,t,o)=>ne(e,t,o),Ot=()=>V(9),Qt=e=>ue("QueryIds",K(e),se),Wt=(e,t)=>ue(d+i,K(t),re,[e]),zt=(e,t)=>ue(d+i+m,K(t),se,[e]),Gt=(e,t)=>ue(d+p,K(t),0,[e]),Jt=(e,t)=>ue(d+g,K(t),se,[e]),Kt=(e,t,o,s=0,r,n)=>ue(d+b,K(n),se,[e,t,o,s,r],6),Nt=(e,t,o)=>ue(d+a,K(o),re,[e,t]),Ut=(e,t,o)=>ue(d+m,K(o),se,[e,t]),Xt=(e,t,o,s)=>ue(d+C,K(s),void 0,[e,t,o]),Yt=(e,t,o,s)=>Ie(d+i,K(s),t,o,[e]),Zt=(e,t,o,s)=>Ie(d+i+m,K(s),t,o,[e]),$t=(e,t,o,s)=>Ie(d+p,K(s),t,o,[e]),_t=(e,t,o,s)=>Ie(d+g,K(s),t,o,[e]),eo=(e,t,o,s,r,n,u,I)=>Ie(d+b,K(I),n,u,[e,t,o,s,r]),to=(e,t,o,s,r)=>Ie(d+a,K(r),o,s,[e,t]),oo=(e,t,o,s,r)=>Ie(d+m,K(r),o,s,[e,t]),so=(e,t,o,s,r,n)=>Ie(d+C,K(n),s,r,[e,t,o]),ro=(e,t,o)=>ne(e,t,o),no=()=>V(11),uo=e=>ue("CheckpointIds",U(e),de),Io=(e,t)=>ue("Checkpoint",U(t),void 0,[e]),io=(e=f,t=se,o,s=f,r=se)=>{const d=U(o);return Z((t=>R(d,(o=>{const r=e(t);s(o.addCheckpoint(r),o,r)}))),[d,...t,...r])},co=e=>le(e,"goBackward"),lo=e=>le(e,"goForward"),ao=(e,t=se,o,s=f,r=se)=>{const d=U(o);return Z((t=>R(d,(o=>R(e(t),(e=>s(o.goTo(e),e)))))),[d,...t,...r])},po=e=>{const t=U(e),[s,r]=uo(t);return[(d=s,!(0==d.length)),co(t),r,R(r,(e=>t?.getCheckpoint(e)))??o];var d},go=e=>{const t=U(e),[,,[s]]=uo(t);return[!h(s),lo(t),s,R(s,(e=>t?.getCheckpoint(e)))??o]},bo=(e,t,o)=>Ie("CheckpointIds",U(o),e,t),Co=(e,t,o,s)=>Ie("Checkpoint",U(s),t,o,[e]),mo=(e,t,o=se,s,r=se,d,n=se)=>{const[,u]=oe(),I=_((()=>t(e)),[e,...o]);return $((()=>((async()=>{s&&(await s(I),u([]))})(),()=>{I?.destroy(),d?.(I)})),[I,...r,...n]),I},{PureComponent:ko,Fragment:yo,createElement:wo,useCallback:ho,useLayoutEffect:Ro,useRef:vo,useState:fo}=e,qo=(e,...t)=>h(e)?{}:e(...t),Po=(e,t)=>[e,e?.getStore(),e?.getLocalTableId(t),e?.getRemoteTableId(t)],{useCallback:xo,useContext:So,useMemo:Lo,useState:Bo}=e,To=({tableId:e,store:t,rowComponent:o=Do,getRowComponentProps:s,customCellIds:r,separator:d,debugIds:n},u)=>Ao(q(u,(d=>wo(o,{...qo(s,d),key:d,tableId:e,rowId:d,customCellIds:r,store:t,debugIds:n}))),d,n,e),Eo=({queryId:e,queries:t,resultRowComponent:o=Zo,getResultRowComponentProps:s,separator:r,debugIds:d},n)=>Ao(q(n,(r=>wo(o,{...qo(s,r),key:r,queryId:e,rowId:r,queries:t,debugIds:d}))),r,d,e),Mo=({relationshipId:e,relationships:t,rowComponent:o=Do,getRowComponentProps:s,separator:r,debugIds:d},n,u)=>{const[I,i,c]=Po(G(t),e),l=n(e,u,I);return Ao(q(l,(e=>wo(o,{...qo(s,e),key:e,tableId:c,rowId:e,store:i,debugIds:d}))),r,d,u)},Fo=e=>({checkpoints:t,checkpointComponent:o=es,getCheckpointComponentProps:s,separator:r,debugIds:d})=>{const n=U(t);return Ao(q(e(uo(n)),(e=>wo(o,{...qo(s,e),key:e,checkpoints:n,checkpointId:e,debugIds:d}))),r)},Vo=({store:e,storesById:t,metrics:o,metricsById:s,indexes:r,indexesById:d,relationships:n,relationshipsById:u,queries:I,queriesById:i,checkpoints:c,checkpointsById:l,children:a})=>{const p=So(E),[g,b]=Bo({}),C=xo(((e,t)=>b((o=>x(o,e)==t?o:{...o,[e]:t}))),[]),m=xo((e=>b((t=>({...S(t,e)})))),[]);return wo(E.Provider,{value:Lo((()=>[e??p[0],{...p[1],...t,...g},o??p[2],{...p[3],...s},r??p[4],{...p[5],...d},n??p[6],{...p[7],...u},I??p[8],{...p[9],...i},c??p[10],{...p[11],...l},C,m]),[e,t,g,o,s,r,d,n,u,I,i,c,l,p,C,m])},a)},Ao=(e,t,o,s)=>{const r=h(t)||!Array.isArray(e)?e:q(e,((e,o)=>o>0?[t,e]:e));return o?[s,":{",r,"}"]:r},jo=({tableId:e,rowId:t,cellId:s,store:r,debugIds:d})=>Ao(o+(Se(e,t,s,r)??o),void 0,d,s),Do=({tableId:e,rowId:t,store:o,cellComponent:s=jo,getCellComponentProps:r,customCellIds:d,separator:n,debugIds:u})=>Ao(q(((e,t,o,s)=>{const r=Pe(t,o,s);return e??r})(d,e,t,o),(d=>wo(s,{...qo(r,d),key:d,tableId:e,rowId:t,cellId:d,store:o,debugIds:u}))),n,u,t),Ho=e=>To(e,Re(e.tableId,e.store)),Oo=({cellId:e,descending:t,offset:o,limit:s,...r})=>To(r,ve(r.tableId,e,t,o,s,r.store)),Qo=({store:e,tableComponent:t=Ho,getTableComponentProps:o,separator:s,debugIds:r})=>Ao(q(Ce(e),(s=>wo(t,{...qo(o,s),key:s,tableId:s,store:e,debugIds:r}))),s),Wo=({valueId:e,store:t,debugIds:s})=>Ao(o+(Me(e,t)??o),void 0,s,e),zo=({store:e,valueComponent:t=Wo,getValueComponentProps:o,separator:s,debugIds:r})=>Ao(q(Te(e),(s=>wo(t,{...qo(o,s),key:s,valueId:s,store:e,debugIds:r}))),s),Go=({metricId:e,metrics:t,debugIds:s})=>Ao(ht(e,t)??o,void 0,s,e),Jo=({indexId:e,sliceId:t,indexes:o,rowComponent:s=Do,getRowComponentProps:r,separator:d,debugIds:n})=>{const[u,I,i]=((e,t)=>[e,e?.getStore(),e?.getTableId(t)])(W(o),e),c=xt(e,t,u);return Ao(q(c,(e=>wo(s,{...qo(r,e),key:e,tableId:i,rowId:e,store:I,debugIds:n}))),d,n,t)},Ko=({indexId:e,indexes:t,sliceComponent:o=Jo,getSliceComponentProps:s,separator:r,debugIds:d})=>Ao(q(qt(e,t),(r=>wo(o,{...qo(s,r),key:r,indexId:e,sliceId:r,indexes:t,debugIds:d}))),r,d,e),No=({relationshipId:e,localRowId:t,relationships:o,rowComponent:s=Do,getRowComponentProps:r,debugIds:d})=>{const[n,u,,I]=Po(G(o),e),i=Mt(e,t,n);return Ao(h(I)||h(i)?null:wo(s,{...qo(r,i),key:i,tableId:I,rowId:i,store:u,debugIds:d}),void 0,d,t)},Uo=e=>Mo(e,Ft,e.remoteRowId),Xo=e=>Mo(e,Vt,e.firstRowId),Yo=({queryId:e,rowId:t,cellId:s,queries:r,debugIds:d})=>Ao(o+(Xt(e,t,s,r)??o),void 0,d,s),Zo=({queryId:e,rowId:t,queries:o,resultCellComponent:s=Yo,getResultCellComponentProps:r,separator:d,debugIds:n})=>Ao(q(Ut(e,t,o),(d=>wo(s,{...qo(r,d),key:d,queryId:e,rowId:t,cellId:d,queries:o,debugIds:n}))),d,n,t),$o=e=>Eo(e,Jt(e.queryId,e.queries)),_o=({cellId:e,descending:t,offset:o,limit:s,...r})=>Eo(r,Kt(r.queryId,e,t,o,s,r.queries)),es=({checkpoints:e,checkpointId:t,debugIds:s})=>Ao(Io(t,e)??o,void 0,s,t),ts=Fo((e=>e[0])),os=Fo((e=>h(e[1])?[]:[e[1]])),ss=Fo((e=>e[2]));export{ts as BackwardCheckpointsView,jo as CellView,es as CheckpointView,os as CurrentCheckpointView,ss as ForwardCheckpointsView,Ko as IndexView,Xo as LinkedRowsView,Uo as LocalRowsView,Go as MetricView,Vo as Provider,No as RemoteRowView,Yo as ResultCellView,Zo as ResultRowView,_o as ResultSortedTableView,$o as ResultTableView,Do as RowView,Jo as SliceView,Oo as SortedTableView,Ho as TableView,Qo as TablesView,Wo as ValueView,zo as ValuesView,je as useAddRowCallback,Se as useCell,Pe as useCellIds,ut as useCellIdsListener,it as useCellListener,Io as useCheckpoint,uo as useCheckpointIds,bo as useCheckpointIdsListener,Co as useCheckpointListener,N as useCheckpoints,no as useCheckpointsIds,U as useCheckpointsOrCheckpointsById,ro as useCreateCheckpoints,vt as useCreateIndexes,kt as useCreateMetrics,mo as useCreatePersister,Ht as useCreateQueries,Bt as useCreateRelationships,ae as useCreateStore,Ke as useDelCellCallback,Je as useDelRowCallback,Ge as useDelTableCallback,ze as useDelTablesCallback,Ue as useDelValueCallback,Ne as useDelValuesCallback,mt as useDidFinishTransactionListener,co as useGoBackwardCallback,lo as useGoForwardCallback,ao as useGoToCallback,xe as useHasCell,It as useHasCellListener,fe as useHasRow,dt as useHasRowListener,me as useHasTable,we as useHasTableCell,tt as useHasTableCellListener,$e as useHasTableListener,ge as useHasTables,Xe as useHasTablesListener,Ee as useHasValue,pt as useHasValueListener,Le as useHasValues,ct as useHasValuesListener,Pt as useIndexIds,Q as useIndexes,ft as useIndexesIds,W as useIndexesOrIndexesById,Vt as useLinkedRowIds,Dt as useLinkedRowIdsListener,Ft as useLocalRowIds,jt as useLocalRowIdsListener,ht as useMetric,wt as useMetricIds,Rt as useMetricListener,H as useMetrics,yt as useMetricsIds,O as useMetricsOrMetricsById,D as useProvideStore,J as useQueries,Ot as useQueriesIds,K as useQueriesOrQueriesById,Qt as useQueryIds,go as useRedoInformation,Et as useRelationshipIds,z as useRelationships,Tt as useRelationshipsIds,G as useRelationshipsOrRelationshipsById,Mt as useRemoteRowId,At as useRemoteRowIdListener,Xt as useResultCell,Ut as useResultCellIds,oo as useResultCellIdsListener,so as useResultCellListener,Nt as useResultRow,Gt as useResultRowCount,$t as useResultRowCountListener,Jt as useResultRowIds,_t as useResultRowIdsListener,to as useResultRowListener,Kt as useResultSortedRowIds,eo as useResultSortedRowIdsListener,Wt as useResultTable,zt as useResultTableCellIds,Zt as useResultTableCellIdsListener,Yt as useResultTableListener,qe as useRow,he as useRowCount,ot as useRowCountListener,Re as useRowIds,st as useRowIdsListener,nt as useRowListener,He as useSetCellCallback,io as useSetCheckpointCallback,De as useSetPartialRowCallback,Qe as useSetPartialValuesCallback,Ae as useSetRowCallback,Ve as useSetTableCallback,Fe as useSetTablesCallback,We as useSetValueCallback,Oe as useSetValuesCallback,qt as useSliceIds,St as useSliceIdsListener,xt as useSliceRowIds,Lt as useSliceRowIdsListener,ve as useSortedRowIds,rt as useSortedRowIdsListener,bt as useStartTransactionListener,A as useStore,pe as useStoreIds,j as useStoreOrStoreById,ke as useTable,ye as useTableCellIds,et as useTableCellIdsListener,Ce as useTableIds,Ze as useTableIdsListener,_e as useTableListener,be as useTables,Ye as useTablesListener,po as useUndoInformation,Me as useValue,Te as useValueIds,at as useValueIdsListener,gt as useValueListener,Be as useValues,lt as useValuesListener,Ct as useWillFinishTransactionListener};
Binary file
@@ -1 +1 @@
1
- var t,e;t=this,e=function(t){"use strict";const e=t=>typeof t,a="",s=e(a),n="t",i=(t,e)=>t.startsWith(e),r=Promise,o=t=>null==t,c=(t,e,a)=>o(t)?a?.():e(t),l=(t,e,a)=>t.slice(e,a),f=t=>t.length,u=async t=>r.all(t),h=(t,e)=>t.map(e),y=(t,...e)=>t.push(...e),w=Object,g=(t=[])=>w.fromEntries(t),p=(t,e)=>h(w.entries(t),(([t,a])=>e(a,t))),d=(t,e,a)=>(((t,e)=>!o(((t,e)=>c(t,(t=>t[e])))(t,e)))(t,e)||(t[e]=a()),t[e]),S=t=>JSON.stringify(t,((t,e)=>e instanceof Map?w.fromEntries([...e]):e)),P=JSON.parse,b=(t,a,n)=>t+a+(e(n)==s?n:S(n)),m=(t,e,a)=>{const s=f(t);return i(e,t)?[e[s],(a?P:String)(l(e,s+1))]:void 0},T=(t,e)=>((t,e)=>t?.forEach(e))(t,((t,a)=>e(a,t))),x="hasStore",D=g(h(["Origin","Methods","Headers"],(t=>["Access-Control-Allow-"+t,"*"]))),v=async t=>await t.party.storage.get((t.config.storagePrefix??a)+x),R=async(t,e,s,r)=>{const c=t.party.storage,l=t.config.storagePrefix??a,h={[l+x]:1},w=[],g=[];await u(p(e[0],(async(e,a)=>o(e)?!s&&t.canDelTable(a,r)&&((t,...e)=>t.unshift(...e))(g,C(l,n,a)):t.canSetTable(a,s,r)&&await u(p(e,(async(e,i)=>o(e)?!s&&t.canDelRow(a,i,r)&&y(g,C(l,n,a,i)):t.canSetRow(a,i,s,r)&&await u(p(e,(async(e,f)=>{const u=[a,i,f],g=C(l,n,...u);o(e)?!s&&t.canDelCell(...u,r)&&y(w,g):t.canSetCell(...u,e,s,r,await c.get(g))&&(h[g]=e)}))))))))),await u(p(e[1],(async(e,a)=>{const n=l+"v"+a;o(e)?!s&&t.canDelValue(a,r)&&y(w,n):t.canSetValue(a,e,s,r,await c.get(n))&&(h[n]=e)}))),0!=f(g)&&T(await c.list(),(t=>g.every((e=>!i(t,e)||y(w,t)&&0)))),await c.delete(w),await c.put(h)},C=(t,e,...a)=>b(t,e,l(S(a),1,-1)),O=async(t,e,a=null)=>new Response(a,{status:e,headers:t.config.responseHeaders??D});t.TinyBasePartyKitServer=class{constructor(t){this.party=t,this.config={}}async onRequest(t){const e=this.config.storePath??"/store";if(new URL(t.url).pathname.endsWith(e)){const e=await v(this),s=await t.text();return"PUT"==t.method?e?O(this,205):(await R(this,P(s),!0,t),O(this,201)):O(this,200,e?S(await(async t=>{const e={},s={},i=t.config.storagePrefix??a;return T(await t.party.storage.list(),((t,a)=>c(m(i,t),(([t,i])=>{if(t==n){const[t,s,n]=P("["+i+"]");d(d(e,t,g),s,g)[n]=a}else"v"==t&&(s[i]=a)})))),[e,s]})(this)):a)}return O(this,404)}async onMessage(t,e){const s=this.config.messagePrefix??a;await c(m(s,t,1),(async([t,a])=>{"s"==t&&await v(this)&&(await R(this,a,!1,e),this.party.broadcast(b(s,"s",a)))}))}canSetTable(t,e,a){return!0}canDelTable(t,e){return!0}canSetRow(t,e,a,s){return!0}canDelRow(t,e,a){return!0}canSetCell(t,e,a,s,n,i,r){return!0}canDelCell(t,e,a,s){return!0}canSetValue(t,e,a,s,n){return!0}canDelValue(t,e){return!0}}},"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TinyBasePersisterPartyKitServer={});
1
+ var e,t;e=this,t=function(e){"use strict";const t=e=>typeof e,a=t(""),s="t",n=(e,t)=>e.startsWith(t),r=Promise,i=e=>null==e,o=(e,t,a)=>i(e)?a?.():t(e),c=(e,t,a)=>e.slice(t,a),l=e=>e.length,f=async e=>r.all(e),h=(e,t)=>e.map(t),u=(e,...t)=>e.push(...t),g=Object,y=(e=[])=>g.fromEntries(e),w=(e,t)=>h(g.entries(e),(([e,a])=>t(a,e))),d=(e,t,a)=>(((e,t)=>!i(((e,t)=>o(e,(e=>e[t])))(e,t)))(e,t)||(e[t]=a()),e[t]),p=e=>JSON.stringify(e,((e,t)=>t instanceof Map?g.fromEntries([...t]):t)),S=JSON.parse,P=(e,s,n)=>e+s+(t(n)==a?n:p(n)),m=(e,t,a)=>{const s=l(e);return n(t,e)?[t[s],(a?S:String)(c(t,s+1))]:void 0},x=(e,t)=>((e,t)=>e?.forEach(t))(e,((e,a)=>t(a,e))),b="hasStore",T=y(h(["Origin","Methods","Headers"],(e=>["Access-Control-Allow-"+e,"*"]))),D=async(e,t="")=>!!await e.get(t+b),v=async(e,t="")=>{const a={},n={};return x(await e.list(),((e,r)=>o(m(t,e),(([e,t])=>{if(e==s){const[e,s,n]=S("["+t+"]");d(d(a,e,y),s,y)[n]=r}else"v"==e&&(n[t]=r)})))),[a,n]},R=async(e,t,a,r)=>{const o=e.party.storage,c=e.config.storagePrefix,h={[c+b]:1},g=[],y=[];await f(w(t[0],(async(t,n)=>i(t)?!a&&e.canDelTable(n,r)&&((e,...t)=>e.unshift(...t))(y,C(c,s,n)):e.canSetTable(n,a,r)&&await f(w(t,(async(t,l)=>i(t)?!a&&e.canDelRow(n,l,r)&&u(y,C(c,s,n,l)):e.canSetRow(n,l,a,r)&&await f(w(t,(async(t,f)=>{const y=[n,l,f],w=C(c,s,...y);i(t)?!a&&e.canDelCell(...y,r)&&u(g,w):e.canSetCell(...y,t,a,r,await o.get(w))&&(h[w]=t)}))))))))),await f(w(t[1],(async(t,s)=>{const n=c+"v"+s;i(t)?!a&&e.canDelValue(s,r)&&u(g,n):e.canSetValue(s,t,a,r,await o.get(n))&&(h[n]=t)}))),0!=l(y)&&x(await o.list(),(e=>y.every((t=>!n(e,t)||u(g,e)&&0)))),await o.delete(g),await o.put(h)},C=(e,t,...a)=>P(e,t,c(p(a),1,-1)),O=async(e,t,a=null)=>new Response(a,{status:t,headers:e.config.responseHeaders});e.TinyBasePartyKitServer=class{constructor(e){this.party=e,this.config={},this.config.storePath??="/store",this.config.messagePrefix??="",this.config.storagePrefix??="",this.config.responseHeaders??=T}async onRequest(e){const{party:{storage:t},config:{storePath:a,storagePrefix:s}}=this;if(new URL(e.url).pathname.endsWith(a)){const a=await D(t,s),n=await e.text();return"PUT"==e.method?a?O(this,205):(await R(this,S(n),!0,e),O(this,201)):O(this,200,a?p(await v(t,s)):"")}return O(this,404)}async onMessage(e,t){const{party:{storage:a,broadcast:s},config:{messagePrefix:n,storagePrefix:r}}=this;await o(m(n,e,1),(async([e,i])=>{"s"==e&&await D(a,r)&&(await R(this,i,!1,t),s(P(n,"s",i),[t.id]))}))}canSetTable(e,t,a){return!0}canDelTable(e,t){return!0}canSetRow(e,t,a,s){return!0}canDelRow(e,t,a){return!0}canSetCell(e,t,a,s,n,r,i){return!0}canDelCell(e,t,a,s){return!0}canSetValue(e,t,a,s,n){return!0}canDelValue(e,t){return!0}},e.hasStoreInStorage=D,e.loadStoreFromStorage=v},"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBasePersisterPartyKitServer={});
@@ -1 +1 @@
1
- var e,s;e=this,s=function(e,s){"use strict";const t=e=>typeof e,o="",u=t(o),r="Listener",l="Result",d="Has",n="has",i="Ids",a="Table",c=a+"s",I=a+i,C="Row",b=C+"Count",p=C+i,w="Sorted"+C+i,R="Cell",k=R+i,g="Value",L=g+"s",h=g+i,m=e=>null==e,y=(e,s,t)=>m(e)?t?.():s(e),T=e=>t(e)==u,V=()=>{},S=(e,s)=>e.map(s),f=Object.keys,{createContext:x,useContext:v}=s,P=x([]),q=(e,s)=>{const t=v(P);return m(e)?t[s]:T(e)?((e,s)=>y(e,(e=>e[s])))(t[s+1]??{},e):e},B=(e,s)=>{const t=q(e,s);return m(e)||T(e)?t:e},H=e=>f(v(P)[e]??{}),M=e=>B(e,0),D=e=>B(e,2),F=e=>B(e,4),O=e=>B(e,6),Q=e=>B(e,8),E=e=>B(e,10),A=e=>e.toLowerCase();A(r);const G="Transaction";A(G);const{useCallback:j,useEffect:U,useMemo:W,useLayoutEffect:z,useRef:J,useState:K}=s,N=[],X={},Y=[[],void 0,[]],Z=(e,s,t=N)=>{const o=W((()=>s(e)),[e,...t]);return U((()=>()=>o.destroy()),[o]),o},$=(e,s,t,o=N,u,r="get",l="")=>{const[,d]=K(),n=j((()=>s?.[r+e]?.(...o)??t),[s,e,...o,t]),i=J();return W((()=>i.current=n()),[n]),_(l+e,s,((...e)=>{i.current=m(u)?n():e[u],d([])}),[n,u],o),i.current},_=(e,s,t,o=N,u=N,...l)=>z((()=>{const o=s?.["add"+e+r]?.(...u,t,...l);return()=>s?.delListener(o)}),[s,e,...u,...o,...l]),ee=(e,s,t,o=N,u=V,r=N,...l)=>{const d=M(e);return j((e=>y(d,(o=>y(t(e,o),(e=>u(o["set"+s](...l,e),e)))))),[d,s,...o,...r,...l])},se=(e,s,t=V,o=N,...u)=>{const r=M(e);return j((()=>t(r?.["del"+s](...u))),[r,s,...o,...u])},te=(e,s,t)=>{const o=E(e);return j((()=>o?.[s](t)),[o,s,t])},oe=e=>$(I,M(e),N),ue=(e,s)=>$(p,M(s),N,[e]),re=(e,s,t,o=0,u,r)=>$(w,M(r),N,[e,s,t,o,u],6),le=(e,s,t)=>$(k,M(t),N,[e,s]),de=(e,s,t,o)=>$(R,M(o),void 0,[e,s,t],4),ne=e=>$(h,M(e),N),ie=(e,s)=>$(g,M(s),void 0,[e]),ae=(e,s)=>$("Metric",D(s),void 0,[e]),ce=(e,s)=>$("SliceIds",F(s),N,[e]),Ie=(e,s,t)=>$("Slice"+p,F(t),N,[e,s]),Ce=(e,s,t)=>$("RemoteRowId",O(t),void 0,[e,s]),be=(e,s,t)=>$("Local"+p,O(t),N,[e,s]),pe=(e,s,t)=>$("Linked"+p,O(t),N,[e,s]),we=(e,s)=>$(l+p,Q(s),N,[e]),Re=(e,s,t,o=0,u,r)=>$(l+w,Q(r),N,[e,s,t,o,u],6),ke=(e,s,t)=>$(l+k,Q(t),N,[e,s]),ge=(e,s,t,o)=>$(l+R,Q(o),void 0,[e,s,t]),Le=e=>$("CheckpointIds",E(e),Y),he=(e,s)=>$("Checkpoint",E(s),void 0,[e]),me=e=>te(e,"goBackward"),ye=e=>te(e,"goForward"),{PureComponent:Te,Fragment:Ve,createElement:Se,useCallback:fe,useLayoutEffect:xe,useRef:ve,useState:Pe}=s,qe=(e,...s)=>m(e)?{}:e(...s),Be=(e,s)=>[e,e?.getStore(),e?.getLocalTableId(s),e?.getRemoteTableId(s)],{useMemo:He}=s,Me=({tableId:e,store:s,rowComponent:t=Ae,getRowComponentProps:o,customCellIds:u,separator:r,debugIds:l},d)=>Qe(S(d,(r=>Se(t,{...qe(o,r),key:r,tableId:e,rowId:r,customCellIds:u,store:s,debugIds:l}))),r,l,e),De=({queryId:e,queries:s,resultRowComponent:t=ze,getResultRowComponentProps:o,separator:u,debugIds:r},l)=>Qe(S(l,(u=>Se(t,{...qe(o,u),key:u,queryId:e,rowId:u,queries:s,debugIds:r}))),u,r,e),Fe=({relationshipId:e,relationships:s,rowComponent:t=Ae,getRowComponentProps:o,separator:u,debugIds:r},l,d)=>{const[n,i,a]=Be(O(s),e),c=l(e,d,n);return Qe(S(c,(e=>Se(t,{...qe(o,e),key:e,tableId:a,rowId:e,store:i,debugIds:r}))),u,r,d)},Oe=e=>({checkpoints:s,checkpointComponent:t=Je,getCheckpointComponentProps:o,separator:u,debugIds:r})=>{const l=E(s);return Qe(S(e(Le(l)),(e=>Se(t,{...qe(o,e),key:e,checkpoints:l,checkpointId:e,debugIds:r}))),u)},Qe=(e,s,t,o)=>{const u=m(s)||!Array.isArray(e)?e:S(e,((e,t)=>t>0?[s,e]:e));return t?[o,":{",u,"}"]:u},Ee=({tableId:e,rowId:s,cellId:t,store:u,debugIds:r})=>Qe(o+(de(e,s,t,u)??o),void 0,r,t),Ae=({tableId:e,rowId:s,store:t,cellComponent:o=Ee,getCellComponentProps:u,customCellIds:r,separator:l,debugIds:d})=>Qe(S(((e,s,t,o)=>{const u=le(s,t,o);return e??u})(r,e,s,t),(r=>Se(o,{...qe(u,r),key:r,tableId:e,rowId:s,cellId:r,store:t,debugIds:d}))),l,d,s),Ge=e=>Me(e,ue(e.tableId,e.store)),je=({valueId:e,store:s,debugIds:t})=>Qe(o+(ie(e,s)??o),void 0,t,e),Ue=({indexId:e,sliceId:s,indexes:t,rowComponent:o=Ae,getRowComponentProps:u,separator:r,debugIds:l})=>{const[d,n,i]=((e,s)=>[e,e?.getStore(),e?.getTableId(s)])(F(t),e),a=Ie(e,s,d);return Qe(S(a,(e=>Se(o,{...qe(u,e),key:e,tableId:i,rowId:e,store:n,debugIds:l}))),r,l,s)},We=({queryId:e,rowId:s,cellId:t,queries:u,debugIds:r})=>Qe(o+(ge(e,s,t,u)??o),void 0,r,t),ze=({queryId:e,rowId:s,queries:t,resultCellComponent:o=We,getResultCellComponentProps:u,separator:r,debugIds:l})=>Qe(S(ke(e,s,t),(r=>Se(o,{...qe(u,r),key:r,queryId:e,rowId:s,cellId:r,queries:t,debugIds:l}))),r,l,s),Je=({checkpoints:e,checkpointId:s,debugIds:t})=>Qe(he(s,e)??o,void 0,t,s),Ke=Oe((e=>e[0])),Ne=Oe((e=>m(e[1])?[]:[e[1]])),Xe=Oe((e=>e[2]));e.BackwardCheckpointsView=Ke,e.CellView=Ee,e.CheckpointView=Je,e.CurrentCheckpointView=Ne,e.ForwardCheckpointsView=Xe,e.IndexView=({indexId:e,indexes:s,sliceComponent:t=Ue,getSliceComponentProps:o,separator:u,debugIds:r})=>Qe(S(ce(e,s),(u=>Se(t,{...qe(o,u),key:u,indexId:e,sliceId:u,indexes:s,debugIds:r}))),u,r,e),e.LinkedRowsView=e=>Fe(e,pe,e.firstRowId),e.LocalRowsView=e=>Fe(e,be,e.remoteRowId),e.MetricView=({metricId:e,metrics:s,debugIds:t})=>Qe(ae(e,s)??o,void 0,t,e),e.Provider=({store:e,storesById:t,metrics:o,metricsById:u,indexes:r,indexesById:l,relationships:d,relationshipsById:n,queries:i,queriesById:a,checkpoints:c,checkpointsById:I,children:C})=>{const b=s.useContext(P);return Se(P.Provider,{value:He((()=>[e??b[0],{...b[1],...t},o??b[2],{...b[3],...u},r??b[4],{...b[5],...l},d??b[6],{...b[7],...n},i??b[8],{...b[9],...a},c??b[10],{...b[11],...I}]),[e,t,o,u,r,l,d,n,i,a,c,I,b])},C)},e.RemoteRowView=({relationshipId:e,localRowId:s,relationships:t,rowComponent:o=Ae,getRowComponentProps:u,debugIds:r})=>{const[l,d,,n]=Be(O(t),e),i=Ce(e,s,l);return Qe(m(n)||m(i)?null:Se(o,{...qe(u,i),key:i,tableId:n,rowId:i,store:d,debugIds:r}),void 0,r,s)},e.ResultCellView=We,e.ResultRowView=ze,e.ResultSortedTableView=({cellId:e,descending:s,offset:t,limit:o,...u})=>De(u,Re(u.queryId,e,s,t,o,u.queries)),e.ResultTableView=e=>De(e,we(e.queryId,e.queries)),e.RowView=Ae,e.SliceView=Ue,e.SortedTableView=({cellId:e,descending:s,offset:t,limit:o,...u})=>Me(u,re(u.tableId,e,s,t,o,u.store)),e.TableView=Ge,e.TablesView=({store:e,tableComponent:s=Ge,getTableComponentProps:t,separator:o,debugIds:u})=>Qe(S(oe(e),(o=>Se(s,{...qe(t,o),key:o,tableId:o,store:e,debugIds:u}))),o),e.ValueView=je,e.ValuesView=({store:e,valueComponent:s=je,getValueComponentProps:t,separator:o,debugIds:u})=>Qe(S(ne(e),(o=>Se(s,{...qe(t,o),key:o,valueId:o,store:e,debugIds:u}))),o),e.useAddRowCallback=(e,s,t=N,o,u=V,r=N,l=!0)=>{const d=M(o);return j((t=>y(d,(o=>y(s(t,o),(s=>u(o.addRow(e,s,l),o,s)))))),[d,e,...t,...r,l])},e.useCell=de,e.useCellIds=le,e.useCellIdsListener=(e,s,t,o,u,r)=>_(k,M(r),t,o,[e,s],u),e.useCellListener=(e,s,t,o,u,r,l)=>_(R,M(l),o,u,[e,s,t],r),e.useCheckpoint=he,e.useCheckpointIds=Le,e.useCheckpointIdsListener=(e,s,t)=>_("CheckpointIds",E(t),e,s),e.useCheckpointListener=(e,s,t,o)=>_("Checkpoint",E(o),s,t,[e]),e.useCheckpoints=e=>q(e,10),e.useCheckpointsIds=()=>H(11),e.useCheckpointsOrCheckpointsById=E,e.useCreateCheckpoints=(e,s,t)=>Z(e,s,t),e.useCreateIndexes=(e,s,t)=>Z(e,s,t),e.useCreateMetrics=(e,s,t)=>Z(e,s,t),e.useCreatePersister=(e,s,t=N,o,u=N,r,l=N)=>{const[,d]=K(),n=W((()=>s(e)),[e,...t]);return U((()=>((async()=>{o&&(await o(n),d([]))})(),()=>{n?.destroy(),r?.(n)})),[n,...u,...l]),n},e.useCreateQueries=(e,s,t)=>Z(e,s,t),e.useCreateRelationships=(e,s,t)=>Z(e,s,t),e.useCreateStore=(e,s=N)=>W(e,s),e.useDelCellCallback=(e,s,t,o,u,r,l)=>se(u,R,r,l,e,s,t,o),e.useDelRowCallback=(e,s,t,o,u)=>se(t,C,o,u,e,s),e.useDelTableCallback=(e,s,t,o)=>se(s,a,t,o,e),e.useDelTablesCallback=(e,s,t)=>se(e,c,s,t),e.useDelValueCallback=(e,s,t,o)=>se(s,g,t,o,e),e.useDelValuesCallback=(e,s,t)=>se(e,L,s,t),e.useDidFinishTransactionListener=(e,s,t)=>_("DidFinish"+G,M(t),e,s),e.useGoBackwardCallback=me,e.useGoForwardCallback=ye,e.useGoToCallback=(e,s=N,t,o=V,u=N)=>{const r=E(t);return j((s=>y(r,(t=>y(e(s),(e=>o(t.goTo(e),e)))))),[r,...s,...u])},e.useHasCell=(e,s,t,o)=>$(R,M(o),!1,[e,s,t],4,n,d),e.useHasCellListener=(e,s,t,o,u,r,l)=>_(d+R,M(l),o,u,[e,s,t],r),e.useHasRow=(e,s,t)=>$(C,M(t),!1,[e,s],3,n,d),e.useHasRowListener=(e,s,t,o,u,r)=>_(d+C,M(r),t,o,[e,s],u),e.useHasTable=(e,s)=>$(a,M(s),!1,[e],2,n,d),e.useHasTableCell=(e,s,t)=>$(a+R,M(t),!1,[e,s],3,n,d),e.useHasTableCellListener=(e,s,t,o,u,r)=>_(d+a+R,M(r),t,o,[e,s],u),e.useHasTableListener=(e,s,t,o,u)=>_(d+a,M(u),s,t,[e],o),e.useHasTables=e=>$(c,M(e),!1,[],1,n,d),e.useHasTablesListener=(e,s,t,o)=>_(d+c,M(o),e,s,[],t),e.useHasValue=(e,s)=>$(g,M(s),!1,[e],2,n,d),e.useHasValueListener=(e,s,t,o,u)=>_(d+g,M(u),s,t,[e],o),e.useHasValues=e=>$(L,M(e),!1,[],1,n,d),e.useHasValuesListener=(e,s,t,o)=>_(d+L,M(o),e,s,[],t),e.useIndexIds=e=>$("IndexIds",F(e),N),e.useIndexes=e=>q(e,4),e.useIndexesIds=()=>H(5),e.useIndexesOrIndexesById=F,e.useLinkedRowIds=pe,e.useLinkedRowIdsListener=(e,s,t,o,u)=>_("Linked"+p,O(u),t,o,[e,s]),e.useLocalRowIds=be,e.useLocalRowIdsListener=(e,s,t,o,u)=>_("Local"+p,O(u),t,o,[e,s]),e.useMetric=ae,e.useMetricIds=e=>$("MetricIds",D(e),N),e.useMetricListener=(e,s,t,o)=>_("Metric",D(o),s,t,[e]),e.useMetrics=e=>q(e,2),e.useMetricsIds=()=>H(3),e.useMetricsOrMetricsById=D,e.useQueries=e=>q(e,8),e.useQueriesIds=()=>H(9),e.useQueriesOrQueriesById=Q,e.useQueryIds=e=>$("QueryIds",Q(e),N),e.useRedoInformation=e=>{const s=E(e),[,,[t]]=Le(s);return[!m(t),ye(s),t,y(t,(e=>s?.getCheckpoint(e)))??o]},e.useRelationshipIds=e=>$("RelationshipIds",O(e),N),e.useRelationships=e=>q(e,6),e.useRelationshipsIds=()=>H(7),e.useRelationshipsOrRelationshipsById=O,e.useRemoteRowId=Ce,e.useRemoteRowIdListener=(e,s,t,o,u)=>_("RemoteRowId",O(u),t,o,[e,s]),e.useResultCell=ge,e.useResultCellIds=ke,e.useResultCellIdsListener=(e,s,t,o,u)=>_(l+k,Q(u),t,o,[e,s]),e.useResultCellListener=(e,s,t,o,u,r)=>_(l+R,Q(r),o,u,[e,s,t]),e.useResultRow=(e,s,t)=>$(l+C,Q(t),X,[e,s]),e.useResultRowCount=(e,s)=>$(l+b,Q(s),0,[e]),e.useResultRowCountListener=(e,s,t,o)=>_(l+b,Q(o),s,t,[e]),e.useResultRowIds=we,e.useResultRowIdsListener=(e,s,t,o)=>_(l+p,Q(o),s,t,[e]),e.useResultRowListener=(e,s,t,o,u)=>_(l+C,Q(u),t,o,[e,s]),e.useResultSortedRowIds=Re,e.useResultSortedRowIdsListener=(e,s,t,o,u,r,d,n)=>_(l+w,Q(n),r,d,[e,s,t,o,u]),e.useResultTable=(e,s)=>$(l+a,Q(s),X,[e]),e.useResultTableCellIds=(e,s)=>$(l+a+k,Q(s),N,[e]),e.useResultTableCellIdsListener=(e,s,t,o)=>_(l+a+k,Q(o),s,t,[e]),e.useResultTableListener=(e,s,t,o)=>_(l+a,Q(o),s,t,[e]),e.useRow=(e,s,t)=>$(C,M(t),X,[e,s]),e.useRowCount=(e,s)=>$(b,M(s),0,[e]),e.useRowCountListener=(e,s,t,o,u)=>_(b,M(u),s,t,[e],o),e.useRowIds=ue,e.useRowIdsListener=(e,s,t,o,u)=>_(p,M(u),s,t,[e],o),e.useRowListener=(e,s,t,o,u,r)=>_(C,M(r),t,o,[e,s],u),e.useSetCellCallback=(e,s,t,o,u,r,l,d)=>ee(r,R,o,u,l,d,e,s,t),e.useSetCheckpointCallback=(e=V,s=N,t,o=V,u=N)=>{const r=E(t);return j((s=>y(r,(t=>{const u=e(s);o(t.addCheckpoint(u),t,u)}))),[r,...s,...u])},e.useSetPartialRowCallback=(e,s,t,o,u,r,l)=>ee(u,"PartialRow",t,o,r,l,e,s),e.useSetPartialValuesCallback=(e,s,t,o,u)=>ee(t,"PartialValues",e,s,o,u),e.useSetRowCallback=(e,s,t,o,u,r,l)=>ee(u,C,t,o,r,l,e,s),e.useSetTableCallback=(e,s,t,o,u,r)=>ee(o,a,s,t,u,r,e),e.useSetTablesCallback=(e,s,t,o,u)=>ee(t,c,e,s,o,u),e.useSetValueCallback=(e,s,t,o,u,r)=>ee(o,g,s,t,u,r,e),e.useSetValuesCallback=(e,s,t,o,u)=>ee(t,L,e,s,o,u),e.useSliceIds=ce,e.useSliceIdsListener=(e,s,t,o)=>_("SliceIds",F(o),s,t,[e]),e.useSliceRowIds=Ie,e.useSliceRowIdsListener=(e,s,t,o,u)=>_("Slice"+p,F(u),t,o,[e,s]),e.useSortedRowIds=re,e.useSortedRowIdsListener=(e,s,t,o,u,r,l,d,n)=>_(w,M(n),r,l,[e,s,t,o,u],d),e.useStartTransactionListener=(e,s,t)=>_("Start"+G,M(t),e,s),e.useStore=e=>q(e,0),e.useStoreIds=()=>H(1),e.useStoreOrStoreById=M,e.useTable=(e,s)=>$(a,M(s),X,[e]),e.useTableCellIds=(e,s)=>$(a+k,M(s),N,[e]),e.useTableCellIdsListener=(e,s,t,o,u)=>_(a+k,M(u),s,t,[e],o),e.useTableIds=oe,e.useTableIdsListener=(e,s,t,o)=>_(I,M(o),e,s,N,t),e.useTableListener=(e,s,t,o,u)=>_(a,M(u),s,t,[e],o),e.useTables=e=>$(c,M(e),X),e.useTablesListener=(e,s,t,o)=>_(c,M(o),e,s,N,t),e.useUndoInformation=e=>{const s=E(e),[t,u]=Le(s);return[(r=t,!(0==r.length)),me(s),u,y(u,(e=>s?.getCheckpoint(e)))??o];var r},e.useValue=ie,e.useValueIds=ne,e.useValueIdsListener=(e,s,t,o)=>_(h,M(o),e,s,N,t),e.useValueListener=(e,s,t,o,u)=>_(g,M(u),s,t,[e],o),e.useValues=e=>$(L,M(e),X),e.useValuesListener=(e,s,t,o)=>_(L,M(o),e,s,N,t),e.useWillFinishTransactionListener=(e,s,t)=>_("WillFinish"+G,M(t),e,s)},"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],s):s((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseUiReact={},e.React);
1
+ var e,s;e=this,s=function(e,s){"use strict";const t=e=>typeof e,o="",u=t(o),r="Listener",l="Result",d="Has",n="has",i="Ids",a="Table",c=a+"s",I=a+i,C="Row",b=C+"Count",p=C+i,w="Sorted"+C+i,R="Cell",k=R+i,g="Value",L=g+"s",h=g+i,m=e=>null==e,y=(e,s,t)=>m(e)?t?.():s(e),T=e=>t(e)==u,V=()=>{},S=(e,s)=>e.map(s),f=Object.keys,v=(e,s)=>y(e,(e=>e[s])),x=(e,s)=>(delete e[s],e),{createContext:P,useContext:q,useEffect:B}=s,H=P([]),M=(e,s)=>{const t=q(H);return m(e)?t[s]:T(e)?v(t[s+1]??{},e):e},D=(e,s)=>{const t=M(e,s);return m(e)||T(e)?t:e},F=e=>f(q(H)[e]??{}),O=e=>D(e,0),Q=e=>D(e,2),E=e=>D(e,4),A=e=>D(e,6),G=e=>D(e,8),j=e=>D(e,10),U=e=>e.toLowerCase();U(r);const W="Transaction";U(W);const{useCallback:z,useEffect:J,useMemo:K,useLayoutEffect:N,useRef:X,useState:Y}=s,Z=[],$={},_=[[],void 0,[]],ee=(e,s,t=Z)=>{const o=K((()=>s(e)),[e,...t]);return J((()=>()=>o.destroy()),[o]),o},se=(e,s,t,o=Z,u,r="get",l="")=>{const[,d]=Y(),n=z((()=>s?.[r+e]?.(...o)??t),[s,e,...o,t]),i=X();return K((()=>i.current=n()),[n]),te(l+e,s,((...e)=>{i.current=m(u)?n():e[u],d([])}),[n,u],o),i.current},te=(e,s,t,o=Z,u=Z,...l)=>N((()=>{const o=s?.["add"+e+r]?.(...u,t,...l);return()=>s?.delListener(o)}),[s,e,...u,...o,...l]),oe=(e,s,t,o=Z,u=V,r=Z,...l)=>{const d=O(e);return z((e=>y(d,(o=>y(t(e,o),(e=>u(o["set"+s](...l,e),e)))))),[d,s,...o,...r,...l])},ue=(e,s,t=V,o=Z,...u)=>{const r=O(e);return z((()=>t(r?.["del"+s](...u))),[r,s,...o,...u])},re=(e,s,t)=>{const o=j(e);return z((()=>o?.[s](t)),[o,s,t])},le=e=>se(I,O(e),Z),de=(e,s)=>se(p,O(s),Z,[e]),ne=(e,s,t,o=0,u,r)=>se(w,O(r),Z,[e,s,t,o,u],6),ie=(e,s,t)=>se(k,O(t),Z,[e,s]),ae=(e,s,t,o)=>se(R,O(o),void 0,[e,s,t],4),ce=e=>se(h,O(e),Z),Ie=(e,s)=>se(g,O(s),void 0,[e]),Ce=(e,s)=>se("Metric",Q(s),void 0,[e]),be=(e,s)=>se("SliceIds",E(s),Z,[e]),pe=(e,s,t)=>se("Slice"+p,E(t),Z,[e,s]),we=(e,s,t)=>se("RemoteRowId",A(t),void 0,[e,s]),Re=(e,s,t)=>se("Local"+p,A(t),Z,[e,s]),ke=(e,s,t)=>se("Linked"+p,A(t),Z,[e,s]),ge=(e,s)=>se(l+p,G(s),Z,[e]),Le=(e,s,t,o=0,u,r)=>se(l+w,G(r),Z,[e,s,t,o,u],6),he=(e,s,t)=>se(l+k,G(t),Z,[e,s]),me=(e,s,t,o)=>se(l+R,G(o),void 0,[e,s,t]),ye=e=>se("CheckpointIds",j(e),_),Te=(e,s)=>se("Checkpoint",j(s),void 0,[e]),Ve=e=>re(e,"goBackward"),Se=e=>re(e,"goForward"),{PureComponent:fe,Fragment:ve,createElement:xe,useCallback:Pe,useLayoutEffect:qe,useRef:Be,useState:He}=s,Me=(e,...s)=>m(e)?{}:e(...s),De=(e,s)=>[e,e?.getStore(),e?.getLocalTableId(s),e?.getRemoteTableId(s)],{useCallback:Fe,useContext:Oe,useMemo:Qe,useState:Ee}=s,Ae=({tableId:e,store:s,rowComponent:t=Je,getRowComponentProps:o,customCellIds:u,separator:r,debugIds:l},d)=>We(S(d,(r=>xe(t,{...Me(o,r),key:r,tableId:e,rowId:r,customCellIds:u,store:s,debugIds:l}))),r,l,e),Ge=({queryId:e,queries:s,resultRowComponent:t=Ze,getResultRowComponentProps:o,separator:u,debugIds:r},l)=>We(S(l,(u=>xe(t,{...Me(o,u),key:u,queryId:e,rowId:u,queries:s,debugIds:r}))),u,r,e),je=({relationshipId:e,relationships:s,rowComponent:t=Je,getRowComponentProps:o,separator:u,debugIds:r},l,d)=>{const[n,i,a]=De(A(s),e),c=l(e,d,n);return We(S(c,(e=>xe(t,{...Me(o,e),key:e,tableId:a,rowId:e,store:i,debugIds:r}))),u,r,d)},Ue=e=>({checkpoints:s,checkpointComponent:t=$e,getCheckpointComponentProps:o,separator:u,debugIds:r})=>{const l=j(s);return We(S(e(ye(l)),(e=>xe(t,{...Me(o,e),key:e,checkpoints:l,checkpointId:e,debugIds:r}))),u)},We=(e,s,t,o)=>{const u=m(s)||!Array.isArray(e)?e:S(e,((e,t)=>t>0?[s,e]:e));return t?[o,":{",u,"}"]:u},ze=({tableId:e,rowId:s,cellId:t,store:u,debugIds:r})=>We(o+(ae(e,s,t,u)??o),void 0,r,t),Je=({tableId:e,rowId:s,store:t,cellComponent:o=ze,getCellComponentProps:u,customCellIds:r,separator:l,debugIds:d})=>We(S(((e,s,t,o)=>{const u=ie(s,t,o);return e??u})(r,e,s,t),(r=>xe(o,{...Me(u,r),key:r,tableId:e,rowId:s,cellId:r,store:t,debugIds:d}))),l,d,s),Ke=e=>Ae(e,de(e.tableId,e.store)),Ne=({valueId:e,store:s,debugIds:t})=>We(o+(Ie(e,s)??o),void 0,t,e),Xe=({indexId:e,sliceId:s,indexes:t,rowComponent:o=Je,getRowComponentProps:u,separator:r,debugIds:l})=>{const[d,n,i]=((e,s)=>[e,e?.getStore(),e?.getTableId(s)])(E(t),e),a=pe(e,s,d);return We(S(a,(e=>xe(o,{...Me(u,e),key:e,tableId:i,rowId:e,store:n,debugIds:l}))),r,l,s)},Ye=({queryId:e,rowId:s,cellId:t,queries:u,debugIds:r})=>We(o+(me(e,s,t,u)??o),void 0,r,t),Ze=({queryId:e,rowId:s,queries:t,resultCellComponent:o=Ye,getResultCellComponentProps:u,separator:r,debugIds:l})=>We(S(he(e,s,t),(r=>xe(o,{...Me(u,r),key:r,queryId:e,rowId:s,cellId:r,queries:t,debugIds:l}))),r,l,s),$e=({checkpoints:e,checkpointId:s,debugIds:t})=>We(Te(s,e)??o,void 0,t,s),_e=Ue((e=>e[0])),es=Ue((e=>m(e[1])?[]:[e[1]])),ss=Ue((e=>e[2]));e.BackwardCheckpointsView=_e,e.CellView=ze,e.CheckpointView=$e,e.CurrentCheckpointView=es,e.ForwardCheckpointsView=ss,e.IndexView=({indexId:e,indexes:s,sliceComponent:t=Xe,getSliceComponentProps:o,separator:u,debugIds:r})=>We(S(be(e,s),(u=>xe(t,{...Me(o,u),key:u,indexId:e,sliceId:u,indexes:s,debugIds:r}))),u,r,e),e.LinkedRowsView=e=>je(e,ke,e.firstRowId),e.LocalRowsView=e=>je(e,Re,e.remoteRowId),e.MetricView=({metricId:e,metrics:s,debugIds:t})=>We(Ce(e,s)??o,void 0,t,e),e.Provider=({store:e,storesById:s,metrics:t,metricsById:o,indexes:u,indexesById:r,relationships:l,relationshipsById:d,queries:n,queriesById:i,checkpoints:a,checkpointsById:c,children:I})=>{const C=Oe(H),[b,p]=Ee({}),w=Fe(((e,s)=>p((t=>v(t,e)==s?t:{...t,[e]:s}))),[]),R=Fe((e=>p((s=>({...x(s,e)})))),[]);return xe(H.Provider,{value:Qe((()=>[e??C[0],{...C[1],...s,...b},t??C[2],{...C[3],...o},u??C[4],{...C[5],...r},l??C[6],{...C[7],...d},n??C[8],{...C[9],...i},a??C[10],{...C[11],...c},w,R]),[e,s,b,t,o,u,r,l,d,n,i,a,c,C,w,R])},I)},e.RemoteRowView=({relationshipId:e,localRowId:s,relationships:t,rowComponent:o=Je,getRowComponentProps:u,debugIds:r})=>{const[l,d,,n]=De(A(t),e),i=we(e,s,l);return We(m(n)||m(i)?null:xe(o,{...Me(u,i),key:i,tableId:n,rowId:i,store:d,debugIds:r}),void 0,r,s)},e.ResultCellView=Ye,e.ResultRowView=Ze,e.ResultSortedTableView=({cellId:e,descending:s,offset:t,limit:o,...u})=>Ge(u,Le(u.queryId,e,s,t,o,u.queries)),e.ResultTableView=e=>Ge(e,ge(e.queryId,e.queries)),e.RowView=Je,e.SliceView=Xe,e.SortedTableView=({cellId:e,descending:s,offset:t,limit:o,...u})=>Ae(u,ne(u.tableId,e,s,t,o,u.store)),e.TableView=Ke,e.TablesView=({store:e,tableComponent:s=Ke,getTableComponentProps:t,separator:o,debugIds:u})=>We(S(le(e),(o=>xe(s,{...Me(t,o),key:o,tableId:o,store:e,debugIds:u}))),o),e.ValueView=Ne,e.ValuesView=({store:e,valueComponent:s=Ne,getValueComponentProps:t,separator:o,debugIds:u})=>We(S(ce(e),(o=>xe(s,{...Me(t,o),key:o,valueId:o,store:e,debugIds:u}))),o),e.useAddRowCallback=(e,s,t=Z,o,u=V,r=Z,l=!0)=>{const d=O(o);return z((t=>y(d,(o=>y(s(t,o),(s=>u(o.addRow(e,s,l),o,s)))))),[d,e,...t,...r,l])},e.useCell=ae,e.useCellIds=ie,e.useCellIdsListener=(e,s,t,o,u,r)=>te(k,O(r),t,o,[e,s],u),e.useCellListener=(e,s,t,o,u,r,l)=>te(R,O(l),o,u,[e,s,t],r),e.useCheckpoint=Te,e.useCheckpointIds=ye,e.useCheckpointIdsListener=(e,s,t)=>te("CheckpointIds",j(t),e,s),e.useCheckpointListener=(e,s,t,o)=>te("Checkpoint",j(o),s,t,[e]),e.useCheckpoints=e=>M(e,10),e.useCheckpointsIds=()=>F(11),e.useCheckpointsOrCheckpointsById=j,e.useCreateCheckpoints=(e,s,t)=>ee(e,s,t),e.useCreateIndexes=(e,s,t)=>ee(e,s,t),e.useCreateMetrics=(e,s,t)=>ee(e,s,t),e.useCreatePersister=(e,s,t=Z,o,u=Z,r,l=Z)=>{const[,d]=Y(),n=K((()=>s(e)),[e,...t]);return J((()=>((async()=>{o&&(await o(n),d([]))})(),()=>{n?.destroy(),r?.(n)})),[n,...u,...l]),n},e.useCreateQueries=(e,s,t)=>ee(e,s,t),e.useCreateRelationships=(e,s,t)=>ee(e,s,t),e.useCreateStore=(e,s=Z)=>K(e,s),e.useDelCellCallback=(e,s,t,o,u,r,l)=>ue(u,R,r,l,e,s,t,o),e.useDelRowCallback=(e,s,t,o,u)=>ue(t,C,o,u,e,s),e.useDelTableCallback=(e,s,t,o)=>ue(s,a,t,o,e),e.useDelTablesCallback=(e,s,t)=>ue(e,c,s,t),e.useDelValueCallback=(e,s,t,o)=>ue(s,g,t,o,e),e.useDelValuesCallback=(e,s,t)=>ue(e,L,s,t),e.useDidFinishTransactionListener=(e,s,t)=>te("DidFinish"+W,O(t),e,s),e.useGoBackwardCallback=Ve,e.useGoForwardCallback=Se,e.useGoToCallback=(e,s=Z,t,o=V,u=Z)=>{const r=j(t);return z((s=>y(r,(t=>y(e(s),(e=>o(t.goTo(e),e)))))),[r,...s,...u])},e.useHasCell=(e,s,t,o)=>se(R,O(o),!1,[e,s,t],4,n,d),e.useHasCellListener=(e,s,t,o,u,r,l)=>te(d+R,O(l),o,u,[e,s,t],r),e.useHasRow=(e,s,t)=>se(C,O(t),!1,[e,s],3,n,d),e.useHasRowListener=(e,s,t,o,u,r)=>te(d+C,O(r),t,o,[e,s],u),e.useHasTable=(e,s)=>se(a,O(s),!1,[e],2,n,d),e.useHasTableCell=(e,s,t)=>se(a+R,O(t),!1,[e,s],3,n,d),e.useHasTableCellListener=(e,s,t,o,u,r)=>te(d+a+R,O(r),t,o,[e,s],u),e.useHasTableListener=(e,s,t,o,u)=>te(d+a,O(u),s,t,[e],o),e.useHasTables=e=>se(c,O(e),!1,[],1,n,d),e.useHasTablesListener=(e,s,t,o)=>te(d+c,O(o),e,s,[],t),e.useHasValue=(e,s)=>se(g,O(s),!1,[e],2,n,d),e.useHasValueListener=(e,s,t,o,u)=>te(d+g,O(u),s,t,[e],o),e.useHasValues=e=>se(L,O(e),!1,[],1,n,d),e.useHasValuesListener=(e,s,t,o)=>te(d+L,O(o),e,s,[],t),e.useIndexIds=e=>se("IndexIds",E(e),Z),e.useIndexes=e=>M(e,4),e.useIndexesIds=()=>F(5),e.useIndexesOrIndexesById=E,e.useLinkedRowIds=ke,e.useLinkedRowIdsListener=(e,s,t,o,u)=>te("Linked"+p,A(u),t,o,[e,s]),e.useLocalRowIds=Re,e.useLocalRowIdsListener=(e,s,t,o,u)=>te("Local"+p,A(u),t,o,[e,s]),e.useMetric=Ce,e.useMetricIds=e=>se("MetricIds",Q(e),Z),e.useMetricListener=(e,s,t,o)=>te("Metric",Q(o),s,t,[e]),e.useMetrics=e=>M(e,2),e.useMetricsIds=()=>F(3),e.useMetricsOrMetricsById=Q,e.useProvideStore=(e,s)=>{const{12:t,13:o}=q(H);B((()=>(t?.(e,s),()=>o?.(e))),[t,e,s,o])},e.useQueries=e=>M(e,8),e.useQueriesIds=()=>F(9),e.useQueriesOrQueriesById=G,e.useQueryIds=e=>se("QueryIds",G(e),Z),e.useRedoInformation=e=>{const s=j(e),[,,[t]]=ye(s);return[!m(t),Se(s),t,y(t,(e=>s?.getCheckpoint(e)))??o]},e.useRelationshipIds=e=>se("RelationshipIds",A(e),Z),e.useRelationships=e=>M(e,6),e.useRelationshipsIds=()=>F(7),e.useRelationshipsOrRelationshipsById=A,e.useRemoteRowId=we,e.useRemoteRowIdListener=(e,s,t,o,u)=>te("RemoteRowId",A(u),t,o,[e,s]),e.useResultCell=me,e.useResultCellIds=he,e.useResultCellIdsListener=(e,s,t,o,u)=>te(l+k,G(u),t,o,[e,s]),e.useResultCellListener=(e,s,t,o,u,r)=>te(l+R,G(r),o,u,[e,s,t]),e.useResultRow=(e,s,t)=>se(l+C,G(t),$,[e,s]),e.useResultRowCount=(e,s)=>se(l+b,G(s),0,[e]),e.useResultRowCountListener=(e,s,t,o)=>te(l+b,G(o),s,t,[e]),e.useResultRowIds=ge,e.useResultRowIdsListener=(e,s,t,o)=>te(l+p,G(o),s,t,[e]),e.useResultRowListener=(e,s,t,o,u)=>te(l+C,G(u),t,o,[e,s]),e.useResultSortedRowIds=Le,e.useResultSortedRowIdsListener=(e,s,t,o,u,r,d,n)=>te(l+w,G(n),r,d,[e,s,t,o,u]),e.useResultTable=(e,s)=>se(l+a,G(s),$,[e]),e.useResultTableCellIds=(e,s)=>se(l+a+k,G(s),Z,[e]),e.useResultTableCellIdsListener=(e,s,t,o)=>te(l+a+k,G(o),s,t,[e]),e.useResultTableListener=(e,s,t,o)=>te(l+a,G(o),s,t,[e]),e.useRow=(e,s,t)=>se(C,O(t),$,[e,s]),e.useRowCount=(e,s)=>se(b,O(s),0,[e]),e.useRowCountListener=(e,s,t,o,u)=>te(b,O(u),s,t,[e],o),e.useRowIds=de,e.useRowIdsListener=(e,s,t,o,u)=>te(p,O(u),s,t,[e],o),e.useRowListener=(e,s,t,o,u,r)=>te(C,O(r),t,o,[e,s],u),e.useSetCellCallback=(e,s,t,o,u,r,l,d)=>oe(r,R,o,u,l,d,e,s,t),e.useSetCheckpointCallback=(e=V,s=Z,t,o=V,u=Z)=>{const r=j(t);return z((s=>y(r,(t=>{const u=e(s);o(t.addCheckpoint(u),t,u)}))),[r,...s,...u])},e.useSetPartialRowCallback=(e,s,t,o,u,r,l)=>oe(u,"PartialRow",t,o,r,l,e,s),e.useSetPartialValuesCallback=(e,s,t,o,u)=>oe(t,"PartialValues",e,s,o,u),e.useSetRowCallback=(e,s,t,o,u,r,l)=>oe(u,C,t,o,r,l,e,s),e.useSetTableCallback=(e,s,t,o,u,r)=>oe(o,a,s,t,u,r,e),e.useSetTablesCallback=(e,s,t,o,u)=>oe(t,c,e,s,o,u),e.useSetValueCallback=(e,s,t,o,u,r)=>oe(o,g,s,t,u,r,e),e.useSetValuesCallback=(e,s,t,o,u)=>oe(t,L,e,s,o,u),e.useSliceIds=be,e.useSliceIdsListener=(e,s,t,o)=>te("SliceIds",E(o),s,t,[e]),e.useSliceRowIds=pe,e.useSliceRowIdsListener=(e,s,t,o,u)=>te("Slice"+p,E(u),t,o,[e,s]),e.useSortedRowIds=ne,e.useSortedRowIdsListener=(e,s,t,o,u,r,l,d,n)=>te(w,O(n),r,l,[e,s,t,o,u],d),e.useStartTransactionListener=(e,s,t)=>te("Start"+W,O(t),e,s),e.useStore=e=>M(e,0),e.useStoreIds=()=>F(1),e.useStoreOrStoreById=O,e.useTable=(e,s)=>se(a,O(s),$,[e]),e.useTableCellIds=(e,s)=>se(a+k,O(s),Z,[e]),e.useTableCellIdsListener=(e,s,t,o,u)=>te(a+k,O(u),s,t,[e],o),e.useTableIds=le,e.useTableIdsListener=(e,s,t,o)=>te(I,O(o),e,s,Z,t),e.useTableListener=(e,s,t,o,u)=>te(a,O(u),s,t,[e],o),e.useTables=e=>se(c,O(e),$),e.useTablesListener=(e,s,t,o)=>te(c,O(o),e,s,Z,t),e.useUndoInformation=e=>{const s=j(e),[t,u]=ye(s);return[(r=t,!(0==r.length)),Ve(s),u,y(u,(e=>s?.getCheckpoint(e)))??o];var r},e.useValue=Ie,e.useValueIds=ce,e.useValueIdsListener=(e,s,t,o)=>te(h,O(o),e,s,Z,t),e.useValueListener=(e,s,t,o,u)=>te(g,O(u),s,t,[e],o),e.useValues=e=>se(L,O(e),$),e.useValuesListener=(e,s,t,o)=>te(L,O(o),e,s,Z,t),e.useWillFinishTransactionListener=(e,s,t)=>te("WillFinish"+W,O(t),e,s)},"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],s):s((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseUiReact={},e.React);
Binary file