tinybase 6.1.0-beta.5 → 6.1.1

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 (191) hide show
  1. package/@types/persisters/index.d.ts +82 -0
  2. package/@types/persisters/with-schemas/index.d.ts +91 -0
  3. package/@types/store/index.d.ts +123 -1
  4. package/@types/store/with-schemas/index.d.ts +159 -24
  5. package/@types/ui-react/index.d.ts +575 -7
  6. package/@types/ui-react/with-schemas/index.d.ts +184 -40
  7. package/index.js +73 -53
  8. package/mergeable-store/index.js +73 -53
  9. package/mergeable-store/with-schemas/index.js +73 -53
  10. package/min/index.js +1 -1
  11. package/min/index.js.gz +0 -0
  12. package/min/mergeable-store/index.js +1 -1
  13. package/min/mergeable-store/index.js.gz +0 -0
  14. package/min/mergeable-store/with-schemas/index.js +1 -1
  15. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  16. package/min/persisters/index.js +1 -1
  17. package/min/persisters/index.js.gz +0 -0
  18. package/min/persisters/persister-automerge/index.js +1 -1
  19. package/min/persisters/persister-automerge/index.js.gz +0 -0
  20. package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
  21. package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
  22. package/min/persisters/persister-browser/index.js +1 -1
  23. package/min/persisters/persister-browser/index.js.gz +0 -0
  24. package/min/persisters/persister-browser/with-schemas/index.js +1 -1
  25. package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
  26. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  27. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  28. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  29. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  30. package/min/persisters/persister-durable-object-storage/index.js +1 -1
  31. package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
  32. package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
  33. package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
  34. package/min/persisters/persister-electric-sql/index.js +1 -1
  35. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  36. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  37. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  38. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  39. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  40. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  41. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  42. package/min/persisters/persister-file/index.js +1 -1
  43. package/min/persisters/persister-file/index.js.gz +0 -0
  44. package/min/persisters/persister-file/with-schemas/index.js +1 -1
  45. package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
  46. package/min/persisters/persister-indexed-db/index.js +1 -1
  47. package/min/persisters/persister-indexed-db/index.js.gz +0 -0
  48. package/min/persisters/persister-indexed-db/with-schemas/index.js +1 -1
  49. package/min/persisters/persister-indexed-db/with-schemas/index.js.gz +0 -0
  50. package/min/persisters/persister-libsql/index.js +1 -1
  51. package/min/persisters/persister-libsql/index.js.gz +0 -0
  52. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  53. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  54. package/min/persisters/persister-partykit-client/index.js +1 -1
  55. package/min/persisters/persister-partykit-client/index.js.gz +0 -0
  56. package/min/persisters/persister-partykit-client/with-schemas/index.js +1 -1
  57. package/min/persisters/persister-partykit-client/with-schemas/index.js.gz +0 -0
  58. package/min/persisters/persister-pglite/index.js +1 -1
  59. package/min/persisters/persister-pglite/index.js.gz +0 -0
  60. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  61. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  62. package/min/persisters/persister-postgres/index.js +1 -1
  63. package/min/persisters/persister-postgres/index.js.gz +0 -0
  64. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  65. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  66. package/min/persisters/persister-powersync/index.js +1 -1
  67. package/min/persisters/persister-powersync/index.js.gz +0 -0
  68. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  69. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  70. package/min/persisters/persister-remote/index.js +1 -1
  71. package/min/persisters/persister-remote/index.js.gz +0 -0
  72. package/min/persisters/persister-remote/with-schemas/index.js +1 -1
  73. package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
  74. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  75. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  76. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  77. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  78. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  79. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  80. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  81. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  82. package/min/persisters/persister-sqlite3/index.js +1 -1
  83. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  84. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  85. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  86. package/min/persisters/persister-yjs/index.js +1 -1
  87. package/min/persisters/persister-yjs/index.js.gz +0 -0
  88. package/min/persisters/persister-yjs/with-schemas/index.js +1 -1
  89. package/min/persisters/persister-yjs/with-schemas/index.js.gz +0 -0
  90. package/min/persisters/with-schemas/index.js +1 -1
  91. package/min/persisters/with-schemas/index.js.gz +0 -0
  92. package/min/store/index.js +1 -1
  93. package/min/store/index.js.gz +0 -0
  94. package/min/store/with-schemas/index.js +1 -1
  95. package/min/store/with-schemas/index.js.gz +0 -0
  96. package/min/synchronizers/index.js +1 -1
  97. package/min/synchronizers/index.js.gz +0 -0
  98. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  99. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  100. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  101. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  102. package/min/synchronizers/synchronizer-local/index.js +1 -1
  103. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  104. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  105. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  106. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  107. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  108. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  109. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  110. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  111. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  112. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  113. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  114. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  115. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  116. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  117. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  118. package/min/synchronizers/with-schemas/index.js +1 -1
  119. package/min/synchronizers/with-schemas/index.js.gz +0 -0
  120. package/min/ui-react/index.js +1 -1
  121. package/min/ui-react/index.js.gz +0 -0
  122. package/min/ui-react/with-schemas/index.js +1 -1
  123. package/min/ui-react/with-schemas/index.js.gz +0 -0
  124. package/min/ui-react-inspector/index.js +1 -1
  125. package/min/ui-react-inspector/index.js.gz +0 -0
  126. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  127. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  128. package/min/with-schemas/index.js +1 -1
  129. package/min/with-schemas/index.js.gz +0 -0
  130. package/package.json +6 -6
  131. package/persisters/index.js +33 -8
  132. package/persisters/persister-automerge/index.js +23 -3
  133. package/persisters/persister-automerge/with-schemas/index.js +23 -3
  134. package/persisters/persister-browser/index.js +23 -3
  135. package/persisters/persister-browser/with-schemas/index.js +23 -3
  136. package/persisters/persister-cr-sqlite-wasm/index.js +33 -8
  137. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +33 -8
  138. package/persisters/persister-durable-object-storage/index.js +23 -3
  139. package/persisters/persister-durable-object-storage/with-schemas/index.js +23 -3
  140. package/persisters/persister-electric-sql/index.js +33 -8
  141. package/persisters/persister-electric-sql/with-schemas/index.js +33 -8
  142. package/persisters/persister-expo-sqlite/index.js +33 -8
  143. package/persisters/persister-expo-sqlite/with-schemas/index.js +33 -8
  144. package/persisters/persister-file/index.js +23 -3
  145. package/persisters/persister-file/with-schemas/index.js +23 -3
  146. package/persisters/persister-indexed-db/index.js +23 -3
  147. package/persisters/persister-indexed-db/with-schemas/index.js +23 -3
  148. package/persisters/persister-libsql/index.js +33 -8
  149. package/persisters/persister-libsql/with-schemas/index.js +33 -8
  150. package/persisters/persister-partykit-client/index.js +23 -3
  151. package/persisters/persister-partykit-client/with-schemas/index.js +23 -3
  152. package/persisters/persister-pglite/index.js +33 -8
  153. package/persisters/persister-pglite/with-schemas/index.js +33 -8
  154. package/persisters/persister-postgres/index.js +33 -8
  155. package/persisters/persister-postgres/with-schemas/index.js +33 -8
  156. package/persisters/persister-powersync/index.js +33 -8
  157. package/persisters/persister-powersync/with-schemas/index.js +33 -8
  158. package/persisters/persister-remote/index.js +23 -3
  159. package/persisters/persister-remote/with-schemas/index.js +23 -3
  160. package/persisters/persister-sqlite-bun/index.js +33 -8
  161. package/persisters/persister-sqlite-bun/with-schemas/index.js +33 -8
  162. package/persisters/persister-sqlite-wasm/index.js +33 -8
  163. package/persisters/persister-sqlite-wasm/with-schemas/index.js +33 -8
  164. package/persisters/persister-sqlite3/index.js +33 -8
  165. package/persisters/persister-sqlite3/with-schemas/index.js +33 -8
  166. package/persisters/persister-yjs/index.js +23 -3
  167. package/persisters/persister-yjs/with-schemas/index.js +23 -3
  168. package/persisters/with-schemas/index.js +33 -8
  169. package/readme.md +17 -17
  170. package/releases.md +60 -36
  171. package/store/index.js +73 -53
  172. package/store/with-schemas/index.js +73 -53
  173. package/synchronizers/index.js +27 -9
  174. package/synchronizers/synchronizer-broadcast-channel/index.js +27 -9
  175. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +27 -9
  176. package/synchronizers/synchronizer-local/index.js +27 -9
  177. package/synchronizers/synchronizer-local/with-schemas/index.js +27 -9
  178. package/synchronizers/synchronizer-ws-client/index.js +27 -9
  179. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +27 -9
  180. package/synchronizers/synchronizer-ws-server/index.js +27 -9
  181. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +27 -9
  182. package/synchronizers/synchronizer-ws-server-durable-object/index.js +27 -9
  183. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +27 -9
  184. package/synchronizers/with-schemas/index.js +27 -9
  185. package/ui-react/index.js +84 -20
  186. package/ui-react/with-schemas/index.js +84 -20
  187. package/ui-react-dom/index.js +1 -1
  188. package/ui-react-dom/with-schemas/index.js +1 -1
  189. package/ui-react-inspector/index.js +97 -57
  190. package/ui-react-inspector/with-schemas/index.js +97 -57
  191. package/with-schemas/index.js +73 -53
@@ -1307,6 +1307,88 @@ export interface Persister<Persist extends Persists = Persists.StoreOnly> {
1307
1307
  */
1308
1308
  isAutoSaving(): boolean;
1309
1309
 
1310
+ /**
1311
+ * The startAutoPersist method is a convenience method that starts both
1312
+ * automatic loading and saving of the Store data.
1313
+ *
1314
+ * This simply runs the startAutoLoad and startAutoSave methods in sequence,
1315
+ * and returns a Promise that resolves when both have completed.
1316
+ *
1317
+ * This method can take `initialContent` to pass to the startAutoLoad method.
1318
+ * See its documentation for more details.
1319
+ *
1320
+ * If for some reason you want to start saving _before_ you start loading,
1321
+ * pass true as the second parameter.
1322
+ * @param initialContent An optional Content object used when the underlying
1323
+ * storage has not previously been populated.
1324
+ * @param startSaveFirst Whether to start saving before loading, defaulting to
1325
+ * false.
1326
+ * @returns A Promise containing a reference to the Persister object.
1327
+ * @example This example creates a Persister and starts automatically loading
1328
+ * and saving.
1329
+ *
1330
+ * ```js
1331
+ * import {createStore} from 'tinybase';
1332
+ * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
1333
+ *
1334
+ * const persister = createSessionPersister(createStore(), 'pets');
1335
+ *
1336
+ * await persister.startAutoPersisting();
1337
+ * console.log(persister.isAutoSaving());
1338
+ * // -> true
1339
+ * console.log(persister.isAutoLoading());
1340
+ * // -> true
1341
+ *
1342
+ * persister.destroy();
1343
+ * ```
1344
+ * @category Lifecycle
1345
+ * @since v6.1.0
1346
+ */
1347
+ startAutoPersisting(
1348
+ initialContent?: Content | (() => Content),
1349
+ startSaveFirst?: boolean,
1350
+ ): Promise<this>;
1351
+
1352
+ /**
1353
+ * The stopAutoPersist method is a convenience method that stops both
1354
+ * automatic loading and saving of the Store data.
1355
+ *
1356
+ * This simply runs the stopAutoLoad and stopAutoSave methods in sequence, and
1357
+ * returns a Promise that resolves when both have completed.
1358
+ *
1359
+ * If for some reason you want to stop saving _before_ you stop loading, pass
1360
+ * true as the second parameter.
1361
+ * @param stopSaveFirst Whether to stop saving before loading, defaulting to
1362
+ * false.
1363
+ * @returns A Promise containing a reference to the Persister object.
1364
+ * @example This example creates a Persister and starts, then stops,
1365
+ * automatically loading and saving.
1366
+ *
1367
+ * ```js
1368
+ * import {createStore} from 'tinybase';
1369
+ * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
1370
+ *
1371
+ * const persister = createSessionPersister(createStore(), 'pets');
1372
+ *
1373
+ * await persister.startAutoPersisting();
1374
+ * console.log(persister.isAutoSaving());
1375
+ * // -> true
1376
+ * console.log(persister.isAutoLoading());
1377
+ * // -> true
1378
+ *
1379
+ * await persister.stopAutoPersisting();
1380
+ * console.log(persister.isAutoSaving());
1381
+ * // -> false
1382
+ * console.log(persister.isAutoLoading());
1383
+ * // -> false
1384
+ *
1385
+ * persister.destroy();
1386
+ * ```
1387
+ * @category Lifecycle
1388
+ * @since v6.1.0
1389
+ */
1390
+ stopAutoPersisting(stopSaveFirst?: boolean): Promise<this>;
1391
+
1310
1392
  /**
1311
1393
  * The getStatus method lets you find out if the Persister is currently in the
1312
1394
  * process of loading or saving content.
@@ -1400,6 +1400,97 @@ export interface Persister<
1400
1400
  */
1401
1401
  isAutoSaving(): boolean;
1402
1402
 
1403
+ /**
1404
+ * The startAutoPersist method is a convenience method that starts both
1405
+ * automatic loading and saving of the Store data.
1406
+ *
1407
+ * This has schema-based typing. The following is a simplified representation:
1408
+ *
1409
+ * ```ts override
1410
+ * startAutoPersisting(
1411
+ * initialContent?: Content | (() => Content),
1412
+ * startSaveFirst?: boolean,
1413
+ * ): Promise<this>;
1414
+ * ```
1415
+ *
1416
+ * This simply runs the startAutoLoad and startAutoSave methods in sequence,
1417
+ * and returns a Promise that resolves when both have completed.
1418
+ *
1419
+ * This method can take `initialContent` to pass to the startAutoLoad method.
1420
+ * See its documentation for more details.
1421
+ *
1422
+ * If for some reason you want to start saving _before_ you start loading,
1423
+ * pass true as the second parameter.
1424
+ * @param initialContent An optional Content object used when the underlying
1425
+ * storage has not previously been populated.
1426
+ * @param startSaveFirst Whether to start saving before loading, defaulting to
1427
+ * false.
1428
+ * @returns A Promise containing a reference to the Persister object.
1429
+ * @example This example creates a Persister and starts automatically loading
1430
+ * and saving.
1431
+ *
1432
+ * ```js
1433
+ * import {createStore} from 'tinybase';
1434
+ * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
1435
+ *
1436
+ * const persister = createSessionPersister(createStore(), 'pets');
1437
+ *
1438
+ * await persister.startAutoPersisting();
1439
+ * console.log(persister.isAutoSaving());
1440
+ * // -> true
1441
+ * console.log(persister.isAutoLoading());
1442
+ * // -> true
1443
+ *
1444
+ * persister.destroy();
1445
+ * ```
1446
+ * @category Lifecycle
1447
+ * @since v6.1.0
1448
+ */
1449
+ startAutoPersisting(
1450
+ initialContent?: Content<Schemas, true> | (() => Content<Schemas, true>),
1451
+ startSaveFirst?: boolean,
1452
+ ): Promise<this>;
1453
+
1454
+ /**
1455
+ * The stopAutoPersist method is a convenience method that stops both
1456
+ * automatic loading and saving of the Store data.
1457
+ *
1458
+ * This simply runs the stopAutoLoad and stopAutoSave methods in sequence, and
1459
+ * returns a Promise that resolves when both have completed.
1460
+ *
1461
+ * If for some reason you want to stop saving _before_ you stop loading, pass
1462
+ * true as the second parameter.
1463
+ * @param stopSaveFirst Whether to stop saving before loading, defaulting to
1464
+ * false.
1465
+ * @returns A Promise containing a reference to the Persister object.
1466
+ * @example This example creates a Persister and starts, then stops,
1467
+ * automatically loading and saving.
1468
+ *
1469
+ * ```js
1470
+ * import {createStore} from 'tinybase';
1471
+ * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
1472
+ *
1473
+ * const persister = createSessionPersister(createStore(), 'pets');
1474
+ *
1475
+ * await persister.startAutoPersisting();
1476
+ * console.log(persister.isAutoSaving());
1477
+ * // -> true
1478
+ * console.log(persister.isAutoLoading());
1479
+ * // -> true
1480
+ *
1481
+ * await persister.stopAutoPersisting();
1482
+ * console.log(persister.isAutoSaving());
1483
+ * // -> false
1484
+ * console.log(persister.isAutoLoading());
1485
+ * // -> false
1486
+ *
1487
+ * persister.destroy();
1488
+ * ```
1489
+ * @category Lifecycle
1490
+ * @since v6.1.0
1491
+ */
1492
+ stopAutoPersisting(stopSaveFirst?: boolean): Promise<this>;
1493
+
1403
1494
  /**
1404
1495
  * The getStatus method lets you find out if the Persister is currently in the
1405
1496
  * process of loading or saving content.
@@ -576,6 +576,50 @@ export type ChangedValueIds = {[valueId: Id]: IdAddedOrRemoved};
576
576
  */
577
577
  export type DoRollback = (store: Store) => boolean;
578
578
 
579
+ /**
580
+ * The SortedRowIdsArgs type describes the arguments used to sort Row Ids using
581
+ * the getSortedRowIds method.
582
+ *
583
+ * It's an object containing the Id of the Table in the Store, and optional
584
+ * `cellId`, `descending`, `offset`, and `limit` parameters. See the
585
+ * getSortedRowIds method for specific examples.
586
+ * @category Store
587
+ * @since v6.1.0
588
+ */
589
+ export type SortedRowIdsArgs = {
590
+ /**
591
+ * The Id of the Table in the Store, required.
592
+ * @category Argument
593
+ * @since v6.1.0
594
+ */
595
+ tableId: Id;
596
+ /**
597
+ * The optional Id of the Cell whose values are used for the sorting, defaults
598
+ * to sorting by the Row Id itself.
599
+ * @category Argument
600
+ * @since v6.1.0
601
+ */
602
+ cellId?: Id;
603
+ /**
604
+ * Whether the sorting should be in descending order, defaulting to false.
605
+ * @category Argument
606
+ * @since v6.1.0
607
+ */
608
+ descending?: boolean;
609
+ /**
610
+ * The number of Row Ids to skip for pagination purposes, defaulting to 0.
611
+ * @category Argument
612
+ * @since v6.1.0
613
+ */
614
+ offset?: number;
615
+ /**
616
+ * The maximum number of Row Ids to return, defaulting to all.
617
+ * @category Argument
618
+ * @since v6.1.0
619
+ */
620
+ limit?: number;
621
+ };
622
+
579
623
  /**
580
624
  * The TransactionListener type describes a function that is used to listen to
581
625
  * the completion of a transaction for the Store.
@@ -2120,7 +2164,7 @@ export interface Store {
2120
2164
  * any.
2121
2165
  * @param limit The maximum number of Row Ids to return, or `undefined` for
2122
2166
  * all.
2123
- * @returns An array of the sorted Ids of every Row in the Table.
2167
+ * @returns An array of the sorted Ids of appropriate Rows in the Table.
2124
2168
  * @example
2125
2169
  * This example retrieves sorted Row Ids in a Table.
2126
2170
  *
@@ -2212,6 +2256,34 @@ export interface Store {
2212
2256
  limit?: number,
2213
2257
  ): Ids;
2214
2258
 
2259
+ /**
2260
+ * When called with one object argument, the getSortedRowIds method
2261
+ * destructures it to make it easier to skip optional parameters.
2262
+ * @param args A SortedRowIdsArgs object containing the Id of the Table in the
2263
+ * Store, and optional `cellId`, `descending`, `offset`, and `limit`
2264
+ * parameters.
2265
+ * @returns An array of the sorted Ids of appropriate Rows in the Table.
2266
+ * @example
2267
+ * This example retrieves the first sorted Row Id in a Table.
2268
+ *
2269
+ * ```js
2270
+ * import {createStore} from 'tinybase';
2271
+ *
2272
+ * const store = createStore().setTables({
2273
+ * pets: {
2274
+ * fido: {species: 'dog'},
2275
+ * felix: {species: 'cat'},
2276
+ * cujo: {species: 'wolf'},
2277
+ * },
2278
+ * });
2279
+ * console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
2280
+ * // -> ['cujo']
2281
+ * ```
2282
+ * @category Getter
2283
+ * @since v6.1.0
2284
+ */
2285
+ getSortedRowIds(args: SortedRowIdsArgs): Ids;
2286
+
2215
2287
  /**
2216
2288
  * The getRow method returns an object containing the entire data of a single
2217
2289
  * Row in a given Table.
@@ -5673,6 +5745,56 @@ export interface Store {
5673
5745
  mutator?: boolean,
5674
5746
  ): Id;
5675
5747
 
5748
+ /**
5749
+ * When called with an object as the first argument, the
5750
+ * addSortedRowIdsListener method destructures it to make it easier to skip
5751
+ * optional parameters.
5752
+ * @param args A SortedRowIdsArgs object containing the Id of the Table in the
5753
+ * Store, and optional `cellId`, `descending`, `offset`, and `limit`
5754
+ * parameters.
5755
+ * @param listener The function that will be called whenever the sorted Row
5756
+ * Ids in the Table change.
5757
+ * @param mutator An optional boolean that indicates that the listener mutates
5758
+ * Store data.
5759
+ * @returns A unique Id for the listener that can later be used to call it
5760
+ * explicitly, or to remove it.
5761
+ * @example
5762
+ * This example registers a listener that responds to any change to the first
5763
+ * of the sorted Row Ids of a specific Table.
5764
+ *
5765
+ * ```js
5766
+ * import {createStore} from 'tinybase';
5767
+ *
5768
+ * const store = createStore().setTables({
5769
+ * pets: {fido: {price: 6}, felix: {price: 5}},
5770
+ * });
5771
+ *
5772
+ * const listenerId = store.addSortedRowIdsListener(
5773
+ * {tableId: 'pets', limit: 1},
5774
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
5775
+ * console.log(`First sorted Row Id for ${tableId} table changed`);
5776
+ * console.log(sortedRowIds);
5777
+ * // ^ cheaper than calling getSortedRowIds again
5778
+ * },
5779
+ * );
5780
+ * console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
5781
+ * // -> ['felix']
5782
+ *
5783
+ * store.setRow('pets', 'carnaby', {price: 4.5});
5784
+ * // -> 'First sorted Row Id for pets table changed'
5785
+ * // -> ['carnaby']
5786
+ *
5787
+ * store.delListener(listenerId);
5788
+ * ```
5789
+ * @category Listener
5790
+ * @since v6.1.0
5791
+ */
5792
+ addSortedRowIdsListener(
5793
+ args: SortedRowIdsArgs,
5794
+ listener: SortedRowIdsListener<this>,
5795
+ mutator?: boolean,
5796
+ ): Id;
5797
+
5676
5798
  /**
5677
5799
  * The addHasRowListener method registers a listener function with the Store
5678
5800
  * that will be called when a Row is added to or removed from the Store.
@@ -896,6 +896,56 @@ export type DoRollback<Schemas extends OptionalSchemas> = (
896
896
  store: Store<Schemas>,
897
897
  ) => boolean;
898
898
 
899
+ /**
900
+ * The SortedRowIdsArgs type describes the arguments used to sort Row Ids using
901
+ * the getSortedRowIds method.
902
+ *
903
+ * It's an object containing the Id of the Table in the Store, and optional
904
+ * `cellId`, `descending`, `offset`, and `limit` parameters. See the
905
+ * getSortedRowIds method for specific examples.
906
+ * @category Store
907
+ * @since v6.1.0
908
+ */
909
+ export type SortedRowIdsArgs<
910
+ Schema extends OptionalTablesSchema,
911
+ TableId extends TableIdFromSchema<Schema>,
912
+ CellIdOrUndefined extends CellIdFromSchema<Schema, TableId> | undefined =
913
+ | CellIdFromSchema<Schema, TableId>
914
+ | undefined,
915
+ > = {
916
+ /**
917
+ * The Id of the Table in the Store, required.
918
+ * @category Argument
919
+ * @since v6.1.0
920
+ */
921
+ tableId: TableId;
922
+ /**
923
+ * The optional Id of the Cell whose values are used for the sorting, defaults
924
+ * to sorting by the Row Id itself.
925
+ * @category Argument
926
+ * @since v6.1.0
927
+ */
928
+ cellId?: CellIdOrUndefined;
929
+ /**
930
+ * Whether the sorting should be in descending order, defaulting to false.
931
+ * @category Argument
932
+ * @since v6.1.0
933
+ */
934
+ descending?: boolean;
935
+ /**
936
+ * The number of Row Ids to skip for pagination purposes, defaulting to 0.
937
+ * @category Argument
938
+ * @since v6.1.0
939
+ */
940
+ offset?: number;
941
+ /**
942
+ * The maximum number of Row Ids to return, defaulting to all.
943
+ * @category Argument
944
+ * @since v6.1.0
945
+ */
946
+ limit?: number;
947
+ };
948
+
899
949
  /**
900
950
  * The TransactionListener type describes a function that is used to listen to
901
951
  * the completion of a transaction for the Store.
@@ -1346,18 +1396,15 @@ export type RowIdsListener<
1346
1396
  export type SortedRowIdsListener<
1347
1397
  Schemas extends OptionalSchemas,
1348
1398
  TableId extends TableIdFromSchema<Schemas[0]>,
1349
- CellId extends CellIdFromSchema<Schemas[0], TableId> | undefined,
1350
- Descending extends boolean,
1351
- Offset extends number,
1352
- Limit extends number | undefined,
1399
+ CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
1353
1400
  Store extends StoreAlias<Schemas> = StoreAlias<Schemas>,
1354
1401
  > = (
1355
1402
  store: Store,
1356
1403
  tableId: TableId,
1357
- cellId: CellId,
1358
- descending: Descending,
1359
- offset: Offset,
1360
- limit: Limit,
1404
+ cellId: CellIdOrUndefined,
1405
+ descending: boolean,
1406
+ offset: number,
1407
+ limit: number | undefined,
1361
1408
  sortedRowIds: Ids,
1362
1409
  ) => void;
1363
1410
 
@@ -3145,7 +3192,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
3145
3192
  * any.
3146
3193
  * @param limit The maximum number of Row Ids to return, or `undefined` for
3147
3194
  * all.
3148
- * @returns An array of the sorted Ids of every Row in the Table.
3195
+ * @returns An array of the sorted Ids of appropriate Rows in the Table.
3149
3196
  * @example
3150
3197
  * This example retrieves sorted Row Ids in a Table.
3151
3198
  *
@@ -3237,6 +3284,42 @@ export interface Store<in out Schemas extends OptionalSchemas> {
3237
3284
  limit?: number,
3238
3285
  ): Ids;
3239
3286
 
3287
+ /**
3288
+ * When called with one object argument, the getSortedRowIds method
3289
+ * destructures it to make it easier to skip optional parameters.
3290
+ * @param args A SortedRowIdsArgs object containing the Id of the Table in the
3291
+ * Store, and optional `cellId`, `descending`, `offset`, and `limit`
3292
+ * parameters.
3293
+ * @returns An array of the sorted Ids of appropriate Rows in the Table.
3294
+ * @example
3295
+ * This example retrieves the first sorted Row Id in a Table.
3296
+ *
3297
+ * This has schema-based typing. The following is a simplified representation:
3298
+ *
3299
+ * ```ts override
3300
+ * getSortedRowIds(args: SortedRowIdsArgs): Ids;
3301
+ * ```
3302
+ *
3303
+ * ```js
3304
+ * import {createStore} from 'tinybase';
3305
+ *
3306
+ * const store = createStore().setTables({
3307
+ * pets: {
3308
+ * fido: {species: 'dog'},
3309
+ * felix: {species: 'cat'},
3310
+ * cujo: {species: 'wolf'},
3311
+ * },
3312
+ * });
3313
+ * console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
3314
+ * // -> ['cujo']
3315
+ * ```
3316
+ * @category Getter
3317
+ * @since v6.1.0
3318
+ */
3319
+ getSortedRowIds<TableId extends TableIdFromSchema<Schemas[0]>>(
3320
+ args: SortedRowIdsArgs<Schemas[0], TableId>,
3321
+ ): Ids;
3322
+
3240
3323
  /**
3241
3324
  * The getRow method returns an object containing the entire data of a single
3242
3325
  * Row in a given Table.
@@ -7140,24 +7223,76 @@ export interface Store<in out Schemas extends OptionalSchemas> {
7140
7223
  addSortedRowIdsListener<
7141
7224
  TableId extends TableIdFromSchema<Schemas[0]>,
7142
7225
  CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
7143
- Descending extends boolean,
7144
- Offset extends number,
7145
- Limit extends number | undefined,
7146
7226
  >(
7147
7227
  tableId: TableId,
7148
7228
  cellId: CellIdOrUndefined,
7149
- descending: Descending,
7150
- offset: Offset,
7151
- limit: Limit,
7152
- listener: SortedRowIdsListener<
7153
- Schemas,
7154
- TableId,
7155
- CellIdOrUndefined,
7156
- Descending,
7157
- Offset,
7158
- Limit,
7159
- this
7160
- >,
7229
+ descending: boolean,
7230
+ offset: number,
7231
+ limit: number | undefined,
7232
+ listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined, this>,
7233
+ mutator?: boolean,
7234
+ ): Id;
7235
+
7236
+ /**
7237
+ * When called with an object as the first argument, the
7238
+ * addSortedRowIdsListener method destructures it to make it easier to skip
7239
+ * optional parameters.
7240
+ * @param args A SortedRowIdsArgs object containing the Id of the Table in the
7241
+ * Store, and optional `cellId`, `descending`, `offset`, and `limit`
7242
+ * parameters.
7243
+ * @param listener The function that will be called whenever the sorted Row
7244
+ * Ids in the Table change.
7245
+ * @param mutator An optional boolean that indicates that the listener mutates
7246
+ * Store data.
7247
+ * @returns A unique Id for the listener that can later be used to call it
7248
+ * explicitly, or to remove it.
7249
+ * @example
7250
+ * This example registers a listener that responds to any change to the first
7251
+ * of the sorted Row Ids of a specific Table.
7252
+ *
7253
+ * This has schema-based typing. The following is a simplified representation:
7254
+ *
7255
+ * ```ts override
7256
+ * addSortedRowIdsListener(
7257
+ * args: SortedRowIdsArgs,
7258
+ * listener: SortedRowIdsListener<this>,
7259
+ * mutator?: boolean,
7260
+ * ): Id;
7261
+ * ```
7262
+ *
7263
+ * ```js
7264
+ * import {createStore} from 'tinybase';
7265
+ *
7266
+ * const store = createStore().setTables({
7267
+ * pets: {fido: {price: 6}, felix: {price: 5}},
7268
+ * });
7269
+ *
7270
+ * const listenerId = store.addSortedRowIdsListener(
7271
+ * {tableId: 'pets', limit: 1},
7272
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
7273
+ * console.log(`First sorted Row Id for ${tableId} table changed`);
7274
+ * console.log(sortedRowIds);
7275
+ * // ^ cheaper than calling getSortedRowIds again
7276
+ * },
7277
+ * );
7278
+ * console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
7279
+ * // -> ['felix']
7280
+ *
7281
+ * store.setRow('pets', 'carnaby', {price: 4.5});
7282
+ * // -> 'First sorted Row Id for pets table changed'
7283
+ * // -> ['carnaby']
7284
+ *
7285
+ * store.delListener(listenerId);
7286
+ * ```
7287
+ * @category Listener
7288
+ * @since v6.1.0
7289
+ */
7290
+ addSortedRowIdsListener<
7291
+ TableId extends TableIdFromSchema<Schemas[0]>,
7292
+ CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
7293
+ >(
7294
+ args: SortedRowIdsArgs<Schemas[0], TableId, CellIdOrUndefined>,
7295
+ listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined, this>,
7161
7296
  mutator?: boolean,
7162
7297
  ): Id;
7163
7298