tinybase 8.5.0 → 9.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/@types/_internal/queries/with-schemas/index.d.ts +1 -2
  2. package/@types/_internal/ui/with-schemas/index.d.ts +8 -16
  3. package/@types/persisters/index.d.ts +32 -12
  4. package/@types/persisters/persister-durable-object-sql-storage/index.d.ts +9 -8
  5. package/@types/persisters/persister-durable-object-sql-storage/with-schemas/index.d.ts +10 -10
  6. package/@types/persisters/with-schemas/index.d.ts +56 -20
  7. package/@types/queries/index.d.ts +1 -7
  8. package/@types/queries/with-schemas/index.d.ts +5 -15
  9. package/@types/store/index.d.ts +1 -2
  10. package/@types/store/with-schemas/index.d.ts +19 -29
  11. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +9 -3
  12. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +10 -3
  13. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +15 -2
  14. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +17 -2
  15. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +51 -0
  16. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +51 -0
  17. package/@types/ui-react/with-schemas/index.d.ts +3 -6
  18. package/@types/ui-react-dom/index.d.ts +10 -10
  19. package/@types/ui-react-dom/with-schemas/index.d.ts +16 -22
  20. package/@types/ui-react-dom-charts/index.d.ts +7 -7
  21. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +10 -11
  22. package/@types/ui-react-inspector/index.d.ts +1 -1
  23. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  24. package/@types/ui-solid/with-schemas/index.d.ts +4 -8
  25. package/@types/ui-solid-dom/index.d.ts +10 -10
  26. package/@types/ui-solid-dom/with-schemas/index.d.ts +16 -22
  27. package/@types/ui-solid-inspector/index.d.ts +1 -1
  28. package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
  29. package/@types/ui-svelte-dom/index.d.ts +10 -10
  30. package/@types/ui-svelte-dom/with-schemas/index.d.ts +16 -22
  31. package/@types/ui-svelte-inspector/index.d.ts +1 -1
  32. package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
  33. package/index.js +21 -19
  34. package/indexes/index.js +6 -8
  35. package/indexes/with-schemas/index.js +6 -8
  36. package/metrics/index.js +6 -8
  37. package/metrics/with-schemas/index.js +6 -8
  38. package/min/index.js +1 -1
  39. package/min/index.js.gz +0 -0
  40. package/min/omni/index.js +1 -1
  41. package/min/omni/index.js.gz +0 -0
  42. package/min/omni/with-schemas/index.js +1 -1
  43. package/min/omni/with-schemas/index.js.gz +0 -0
  44. package/min/persisters/index.js +1 -1
  45. package/min/persisters/index.js.gz +0 -0
  46. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  47. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  48. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  49. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  50. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  51. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  52. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  53. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  54. package/min/persisters/persister-electric-sql/index.js +1 -1
  55. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  56. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  57. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  58. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  59. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  60. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  61. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  62. package/min/persisters/persister-libsql/index.js +1 -1
  63. package/min/persisters/persister-libsql/index.js.gz +0 -0
  64. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  65. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  66. package/min/persisters/persister-pglite/index.js +1 -1
  67. package/min/persisters/persister-pglite/index.js.gz +0 -0
  68. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  69. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  70. package/min/persisters/persister-postgres/index.js +1 -1
  71. package/min/persisters/persister-postgres/index.js.gz +0 -0
  72. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  73. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  74. package/min/persisters/persister-powersync/index.js +1 -1
  75. package/min/persisters/persister-powersync/index.js.gz +0 -0
  76. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  77. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  78. package/min/persisters/persister-react-native-sqlite/index.js +1 -1
  79. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  80. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  81. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  82. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  83. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  84. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  85. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  86. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  87. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  88. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  89. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  90. package/min/persisters/persister-sqlite3/index.js +1 -1
  91. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  92. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  93. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  94. package/min/persisters/with-schemas/index.js +1 -1
  95. package/min/persisters/with-schemas/index.js.gz +0 -0
  96. package/min/queries/index.js +1 -1
  97. package/min/queries/index.js.gz +0 -0
  98. package/min/queries/with-schemas/index.js +1 -1
  99. package/min/queries/with-schemas/index.js.gz +0 -0
  100. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  101. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  102. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  103. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  104. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  105. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  106. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  107. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  108. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  109. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  110. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  111. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  112. package/min/with-schemas/index.js +1 -1
  113. package/min/with-schemas/index.js.gz +0 -0
  114. package/omni/index.js +311 -141
  115. package/omni/with-schemas/index.js +311 -141
  116. package/package.json +7 -7
  117. package/persisters/index.js +129 -37
  118. package/persisters/persister-cr-sqlite-wasm/index.js +129 -37
  119. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +129 -37
  120. package/persisters/persister-durable-object-sql-storage/index.js +271 -110
  121. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +271 -110
  122. package/persisters/persister-electric-sql/index.js +129 -37
  123. package/persisters/persister-electric-sql/with-schemas/index.js +129 -37
  124. package/persisters/persister-expo-sqlite/index.js +129 -37
  125. package/persisters/persister-expo-sqlite/with-schemas/index.js +129 -37
  126. package/persisters/persister-libsql/index.js +129 -37
  127. package/persisters/persister-libsql/with-schemas/index.js +129 -37
  128. package/persisters/persister-pglite/index.js +130 -37
  129. package/persisters/persister-pglite/with-schemas/index.js +130 -37
  130. package/persisters/persister-postgres/index.js +130 -37
  131. package/persisters/persister-postgres/with-schemas/index.js +130 -37
  132. package/persisters/persister-powersync/index.js +182 -117
  133. package/persisters/persister-powersync/with-schemas/index.js +182 -117
  134. package/persisters/persister-react-native-sqlite/index.js +129 -37
  135. package/persisters/persister-react-native-sqlite/with-schemas/index.js +129 -37
  136. package/persisters/persister-sqlite-bun/index.js +129 -37
  137. package/persisters/persister-sqlite-bun/with-schemas/index.js +129 -37
  138. package/persisters/persister-sqlite-wasm/index.js +129 -37
  139. package/persisters/persister-sqlite-wasm/with-schemas/index.js +129 -37
  140. package/persisters/persister-sqlite3/index.js +129 -37
  141. package/persisters/persister-sqlite3/with-schemas/index.js +129 -37
  142. package/persisters/with-schemas/index.js +129 -37
  143. package/queries/index.js +21 -19
  144. package/queries/with-schemas/index.js +21 -19
  145. package/readme.md +14 -14
  146. package/relationships/index.js +6 -8
  147. package/relationships/with-schemas/index.js +6 -8
  148. package/releases.md +57 -57
  149. package/synchronizers/synchronizer-ws-client/index.js +116 -42
  150. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +116 -42
  151. package/synchronizers/synchronizer-ws-server/index.js +109 -28
  152. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +109 -28
  153. package/synchronizers/synchronizer-ws-server-durable-object/index.js +122 -38
  154. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +122 -38
  155. package/ui-svelte/index.js +1 -1
  156. package/ui-svelte/with-schemas/index.js +1 -1
  157. package/ui-svelte-dom/index.js +2 -2
  158. package/ui-svelte-dom/with-schemas/index.js +2 -2
  159. package/ui-svelte-inspector/index.js +2 -2
  160. package/ui-svelte-inspector/with-schemas/index.js +2 -2
  161. package/with-schemas/index.js +21 -19
@@ -12,8 +12,7 @@ import type {
12
12
  export type JoinedCellIdOrId<
13
13
  Schema extends OptionalTablesSchema = NoTablesSchema,
14
14
  JoinedTableId extends TableIdFromSchema<Schema> | Id =
15
- | TableIdFromSchema<Schema>
16
- | Id,
15
+ TableIdFromSchema<Schema> | Id,
17
16
  > =
18
17
  JoinedTableId extends TableIdFromSchema<Schema>
19
18
  ? CellIdFromSchema<Schema, JoinedTableId>
@@ -15,33 +15,25 @@ import type {
15
15
  import type {Synchronizer} from '../../../synchronizers/with-schemas/index.d.ts';
16
16
 
17
17
  export type StoreOrStoreId<Schemas extends OptionalSchemas> =
18
- | Store<Schemas>
19
- | Id;
18
+ Store<Schemas> | Id;
20
19
 
21
20
  export type MetricsOrMetricsId<Schemas extends OptionalSchemas> =
22
- | Metrics<Schemas>
23
- | Id;
21
+ Metrics<Schemas> | Id;
24
22
 
25
23
  export type IndexesOrIndexesId<Schemas extends OptionalSchemas> =
26
- | Indexes<Schemas>
27
- | Id;
24
+ Indexes<Schemas> | Id;
28
25
 
29
26
  export type RelationshipsOrRelationshipsId<Schemas extends OptionalSchemas> =
30
- | Relationships<Schemas>
31
- | Id;
27
+ Relationships<Schemas> | Id;
32
28
 
33
29
  export type QueriesOrQueriesId<Schemas extends OptionalSchemas> =
34
- | Queries<Schemas>
35
- | Id;
30
+ Queries<Schemas> | Id;
36
31
 
37
32
  export type CheckpointsOrCheckpointsId<Schemas extends OptionalSchemas> =
38
- | Checkpoints<Schemas>
39
- | Id;
33
+ Checkpoints<Schemas> | Id;
40
34
 
41
35
  export type PersisterOrPersisterId<Schemas extends OptionalSchemas> =
42
- | Persister<Schemas, Persists.StoreOrMergeableStore>
43
- | Id;
36
+ Persister<Schemas, Persists.StoreOrMergeableStore> | Id;
44
37
 
45
38
  export type SynchronizerOrSynchronizerId<Schemas extends OptionalSchemas> =
46
- | Synchronizer<Schemas>
47
- | Id;
39
+ Synchronizer<Schemas> | Id;
@@ -205,10 +205,10 @@ export type PersistedChanges<
205
205
  * neither are present, the content will be loaded using the Persister's load
206
206
  * method. Prior to v5.0, these parameters were callbacks and the overall type
207
207
  * was non-generic.
208
- * @param content If provided, this is a Content object from the Persister
209
- * that will be used to immediately wholesale update the Store.
210
- * @param changes If provided, this is a Changes object from the Persister
211
- * that will be used to immediately incrementally update the Store. This takes
208
+ * @param content If provided, this is a Content object from the Persister that
209
+ * will be used to immediately wholesale update the Store.
210
+ * @param changes If provided, this is a Changes object from the Persister that
211
+ * will be used to immediately incrementally update the Store. This takes
212
212
  * priority over the content argument above if present.
213
213
  * @category Creation
214
214
  * @since v4.0.0
@@ -801,12 +801,15 @@ export type DpcTabularSave = {
801
801
  * Note that both loading and saving of Values from and to the database are
802
802
  * disabled by default.
803
803
  *
804
+ * The `load` and `save` properties can be set to `true` to persist all Values,
805
+ * or to a DpcTabularValuesIn array to persist just a subset of Value Ids.
806
+ *
804
807
  * The 'Dpc' prefix indicates that this type is used within the
805
808
  * DatabasePersisterConfig type.
806
809
  * @example
807
810
  * When applied to a database Persister, this DatabasePersisterConfig will load
808
- * and save the data of a Store's Values into a database
809
- * table called 'my_tinybase_values'.
811
+ * and save the data of two Store Values into a database table called
812
+ * 'my_tinybase_values'.
810
813
  *
811
814
  * ```js
812
815
  * import type {DatabasePersisterConfig} from 'tinybase';
@@ -814,8 +817,8 @@ export type DpcTabularSave = {
814
817
  * export const databasePersisterConfig: DatabasePersisterConfig = {
815
818
  * mode: 'tabular',
816
819
  * values: {
817
- * load: true,
818
- * save: true,
820
+ * load: ['selectedPet', 'open'],
821
+ * save: ['selectedPet', 'open'],
819
822
  * tableName: 'my_tinybase_values',
820
823
  * },
821
824
  * };
@@ -825,17 +828,19 @@ export type DpcTabularSave = {
825
828
  */
826
829
  export type DpcTabularValues = {
827
830
  /**
828
- * Whether Store Values will be loaded from a database table.
831
+ * Whether Store Values will be loaded from a database table, or the subset of
832
+ * Value Ids that will be loaded.
829
833
  * @category Configuration
830
834
  * @since v4.0.0
831
835
  */
832
- load?: boolean;
836
+ load?: boolean | DpcTabularValuesIn;
833
837
  /**
834
- * Whether Store Values will be saved to a database table.
838
+ * Whether Store Values will be saved to a database table, or the subset of
839
+ * Value Ids that will be saved.
835
840
  * @category Configuration
836
841
  * @since v4.0.0
837
842
  */
838
- save?: boolean;
843
+ save?: boolean | DpcTabularValuesIn;
839
844
  /**
840
845
  * The optional name of the database table from and to which the Store Values
841
846
  * should be loaded or saved, defaulting to `tinybase_values`.
@@ -845,6 +850,21 @@ export type DpcTabularValues = {
845
850
  tableName?: string;
846
851
  };
847
852
 
853
+ /**
854
+ * The DpcTabularValuesIn type describes the subset of Store Values that are
855
+ * persisted by the DpcTabularValues type.
856
+ *
857
+ * When used as the DpcTabularValues `load` or `save` property, only the listed
858
+ * Value Ids will be loaded from or saved to the database table. Unlisted
859
+ * database columns are ignored on load and left untouched on save.
860
+ *
861
+ * The 'Dpc' prefix indicates that this type is used within the
862
+ * DatabasePersisterConfig type.
863
+ * @category Configuration
864
+ * @since v9.0.0
865
+ */
866
+ export type DpcTabularValuesIn = Id[];
867
+
848
868
  /**
849
869
  * A Persister object lets you save and load Store data to and from different
850
870
  * locations, or underlying storage types.
@@ -30,10 +30,10 @@ import type {DpcJson, Persister, Persists} from '../index.d.ts';
30
30
  * The DpcFragmented type represents the configuration for fragmented
31
31
  * persistence mode in a DurableObjectSqlStoragePersister.
32
32
  *
33
- * This mode stores each table, row, cell, and value as separate database rows,
34
- * avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON
35
- * mode. While this creates more database writes, it provides better scalability
36
- * for larger datasets.
33
+ * This mode stores each table's metadata, row data, and values as separate
34
+ * database rows, avoiding Cloudflare's 2MB row limit that can be hit with
35
+ * large stores in JSON mode. While this creates more database writes than JSON
36
+ * mode, it provides better scalability for larger datasets.
37
37
  * @example
38
38
  * This example shows how to configure a DurableObjectSqlStoragePersister to use
39
39
  * fragmented mode with a custom storage prefix.
@@ -220,10 +220,11 @@ export interface DurableObjectSqlStoragePersister extends Persister<Persists.Mer
220
220
  * database row. This is efficient for smaller stores but may hit Cloudflare's
221
221
  * 2MB row limit for very large stores and uses fewer database writes.
222
222
  *
223
- * - **Fragmented Mode**: Stores each table, row, cell, and value as separate
224
- * database rows. Use this mode if you're concerned about hitting Cloudflare's
225
- * 2MB row limit with large stores in JSON mode. This mode creates more
226
- * database writes but avoids row size limitations.
223
+ * - **Fragmented Mode**: Stores each table's metadata, row data, and values as
224
+ * separate database rows. Use this mode if you're concerned about hitting
225
+ * Cloudflare's 2MB row limit with large stores in JSON mode. This mode
226
+ * creates more database writes than JSON mode but avoids row size
227
+ * limitations.
227
228
  *
228
229
  * The third argument is a DatabasePersisterConfig object that configures which
229
230
  * of those modes to use, and settings for each. If the third argument is simply
@@ -38,10 +38,10 @@ import type {
38
38
  * The DpcFragmented type represents the configuration for fragmented
39
39
  * persistence mode in a DurableObjectSqlStoragePersister.
40
40
  *
41
- * This mode stores each table, row, cell, and value as separate database rows,
42
- * avoiding Cloudflare's 2MB row limit that can be hit with large stores in JSON
43
- * mode. While this creates more database writes, it provides better scalability
44
- * for larger datasets.
41
+ * This mode stores each table's metadata, row data, and values as separate
42
+ * database rows, avoiding Cloudflare's 2MB row limit that can be hit with
43
+ * large stores in JSON mode. While this creates more database writes than JSON
44
+ * mode, it provides better scalability for larger datasets.
45
45
  * @example
46
46
  * This example shows how to configure a DurableObjectSqlStoragePersister to use
47
47
  * fragmented mode with a custom storage prefix.
@@ -250,10 +250,11 @@ export interface DurableObjectSqlStoragePersister<
250
250
  * database row. This is efficient for smaller stores but may hit Cloudflare's
251
251
  * 2MB row limit for very large stores and uses fewer database writes.
252
252
  *
253
- * - **Fragmented Mode**: Stores each table, row, cell, and value as separate
254
- * database rows. Use this mode if you're concerned about hitting Cloudflare's
255
- * 2MB row limit with large stores in JSON mode. This mode creates more
256
- * database writes but avoids row size limitations.
253
+ * - **Fragmented Mode**: Stores each table's metadata, row data, and values as
254
+ * separate database rows. Use this mode if you're concerned about hitting
255
+ * Cloudflare's 2MB row limit with large stores in JSON mode. This mode
256
+ * creates more database writes than JSON mode but avoids row size
257
+ * limitations.
257
258
  *
258
259
  * The third argument is a DatabasePersisterConfig object that configures which
259
260
  * of those modes to use, and settings for each. If the third argument is simply
@@ -379,8 +380,7 @@ export function createDurableObjectSqlStoragePersister<
379
380
  store: Store<Schemas> | MergeableStore<Schemas>,
380
381
  sqlStorage: SqlStorage,
381
382
  configOrStoreTableName?:
382
- | DurableObjectSqlDatabasePersisterConfig<Schemas>
383
- | string,
383
+ DurableObjectSqlDatabasePersisterConfig<Schemas> | string,
384
384
  onSqlCommand?: (sql: string, params?: any[]) => void,
385
385
  onIgnoredError?: (error: any) => void,
386
386
  ): DurableObjectSqlStoragePersister<Schemas>;
@@ -55,7 +55,10 @@
55
55
  * @module persisters
56
56
  * @since v1.0.0
57
57
  */
58
- import type {TableIdFromSchema} from '../../_internal/store/with-schemas/index.d.ts';
58
+ import type {
59
+ TableIdFromSchema,
60
+ ValueIdFromSchema,
61
+ } from '../../_internal/store/with-schemas/index.d.ts';
59
62
  import type {
60
63
  MergeableChanges,
61
64
  MergeableContent,
@@ -66,6 +69,7 @@ import type {
66
69
  Content,
67
70
  OptionalSchemas,
68
71
  OptionalTablesSchema,
72
+ OptionalValuesSchema,
69
73
  Store,
70
74
  } from '../../store/with-schemas/index.d.ts';
71
75
  import type {Id} from '../../with-schemas/index.d.ts';
@@ -260,10 +264,10 @@ export type PersistedChanges<
260
264
  * neither are present, the content will be loaded using the Persister's load
261
265
  * method. Prior to v5.0, these parameters were callbacks and the overall type
262
266
  * was non-generic.
263
- * @param content If provided, this is a Content object from the Persister
264
- * that will be used to immediately wholesale update the Store.
265
- * @param changes If provided, this is a Changes object from the Persister
266
- * that will be used to immediately incrementally update the Store. This takes
267
+ * @param content If provided, this is a Content object from the Persister that
268
+ * will be used to immediately wholesale update the Store.
269
+ * @param changes If provided, this is a Changes object from the Persister that
270
+ * will be used to immediately incrementally update the Store. This takes
267
271
  * priority over the content argument above if present.
268
272
  * @category Creation
269
273
  * @since v4.0.0
@@ -394,8 +398,7 @@ export type PersisterStats = {
394
398
  * @since v4.0.0
395
399
  */
396
400
  export type DatabasePersisterConfig<Schemas extends OptionalSchemas> =
397
- | DpcJson
398
- | DpcTabular<Schemas[0]>;
401
+ DpcJson | DpcTabular<Schemas[0], Schemas[1]>;
399
402
 
400
403
  /**
401
404
  * The DpcJson type describes the configuration of a database-oriented Persister
@@ -552,7 +555,10 @@ export type DpcJson = {
552
555
  * @category Configuration
553
556
  * @since v4.0.0
554
557
  */
555
- export type DpcTabular<Schema extends OptionalTablesSchema> = {
558
+ export type DpcTabular<
559
+ TablesSchema extends OptionalTablesSchema,
560
+ ValuesSchema extends OptionalValuesSchema = OptionalValuesSchema,
561
+ > = {
556
562
  /**
557
563
  * The mode to be used for persisting the Store to the database, in this case
558
564
  * tabular mapping. See the DpcJson type for the alternative JSON
@@ -573,21 +579,21 @@ export type DpcTabular<Schema extends OptionalTablesSchema> = {
573
579
  * @category Configuration
574
580
  * @since v4.0.0
575
581
  */
576
- load?: DpcTabularLoad<Schema>;
582
+ load?: DpcTabularLoad<TablesSchema>;
577
583
  /**
578
584
  * The settings for how the Store Tables are mapped out to the database
579
585
  * tables when saving.
580
586
  * @category Configuration
581
587
  * @since v4.0.0
582
588
  */
583
- save?: DpcTabularSave<Schema>;
589
+ save?: DpcTabularSave<TablesSchema>;
584
590
  };
585
591
  /**
586
592
  * The settings for how the Store Values are mapped to and from the database.
587
593
  * @category Configuration
588
594
  * @since v4.0.0
589
595
  */
590
- values?: DpcTabularValues;
596
+ values?: DpcTabularValues<ValuesSchema>;
591
597
  /**
592
598
  * How often the Persister should poll the database for any changes made to it
593
599
  * by other clients, defaulting to 1 second.
@@ -876,12 +882,15 @@ export type DpcTabularSave<Schema extends OptionalTablesSchema> = {
876
882
  * Note that both loading and saving of Values from and to the database are
877
883
  * disabled by default.
878
884
  *
885
+ * The `load` and `save` properties can be set to `true` to persist all Values,
886
+ * or to a DpcTabularValuesIn array to persist just a subset of Value Ids.
887
+ *
879
888
  * The 'Dpc' prefix indicates that this type is used within the
880
889
  * DatabasePersisterConfig type.
881
890
  * @example
882
891
  * When applied to a database Persister, this DatabasePersisterConfig will load
883
- * and save the data of a Store's Values into a database
884
- * table called 'my_tinybase_values'.
892
+ * and save the data of two Store Values into a database table called
893
+ * 'my_tinybase_values'.
885
894
  *
886
895
  * ```js
887
896
  * import type {DatabasePersisterConfig} from 'tinybase';
@@ -889,8 +898,8 @@ export type DpcTabularSave<Schema extends OptionalTablesSchema> = {
889
898
  * export const databasePersisterConfig: DatabasePersisterConfig = {
890
899
  * mode: 'tabular',
891
900
  * values: {
892
- * load: true,
893
- * save: true,
901
+ * load: ['selectedPet', 'open'],
902
+ * save: ['selectedPet', 'open'],
894
903
  * tableName: 'my_tinybase_values',
895
904
  * },
896
905
  * };
@@ -898,19 +907,23 @@ export type DpcTabularSave<Schema extends OptionalTablesSchema> = {
898
907
  * @category Configuration
899
908
  * @since v4.0.0
900
909
  */
901
- export type DpcTabularValues = {
910
+ export type DpcTabularValues<
911
+ Schema extends OptionalValuesSchema = OptionalValuesSchema,
912
+ > = {
902
913
  /**
903
- * Whether Store Values will be loaded from a database table.
914
+ * Whether Store Values will be loaded from a database table, or the subset of
915
+ * Value Ids that will be loaded.
904
916
  * @category Configuration
905
917
  * @since v4.0.0
906
918
  */
907
- load?: boolean;
919
+ load?: boolean | DpcTabularValuesIn<Schema>;
908
920
  /**
909
- * Whether Store Values will be saved to a database table.
921
+ * Whether Store Values will be saved to a database table, or the subset of
922
+ * Value Ids that will be saved.
910
923
  * @category Configuration
911
924
  * @since v4.0.0
912
925
  */
913
- save?: boolean;
926
+ save?: boolean | DpcTabularValuesIn<Schema>;
914
927
  /**
915
928
  * The optional name of the database table from and to which the Store Values
916
929
  * should be loaded or saved, defaulting to `tinybase_values`.
@@ -920,6 +933,29 @@ export type DpcTabularValues = {
920
933
  tableName?: string;
921
934
  };
922
935
 
936
+ /**
937
+ * The DpcTabularValuesIn type describes the subset of Store Values that are
938
+ * persisted by the DpcTabularValues type.
939
+ *
940
+ * This has schema-based typing. The following is a simplified representation:
941
+ *
942
+ * ```ts override
943
+ * Id[];
944
+ * ```
945
+ *
946
+ * When used as the DpcTabularValues `load` or `save` property, only the listed
947
+ * Value Ids will be loaded from or saved to the database table. Unlisted
948
+ * database columns are ignored on load and left untouched on save.
949
+ *
950
+ * The 'Dpc' prefix indicates that this type is used within the
951
+ * DatabasePersisterConfig type.
952
+ * @category Configuration
953
+ * @since v9.0.0
954
+ */
955
+ export type DpcTabularValuesIn<
956
+ Schema extends OptionalValuesSchema = OptionalValuesSchema,
957
+ > = ValueIdFromSchema<Schema>[];
958
+
923
959
  /**
924
960
  * A Persister object lets you save and load Store data to and from different
925
961
  * locations, or underlying storage types.
@@ -42,13 +42,7 @@ import type {
42
42
  * @since v7.2.0
43
43
  */
44
44
  export type ParamValue =
45
- | string
46
- | number
47
- | boolean
48
- | null
49
- | string[]
50
- | number[]
51
- | boolean[];
45
+ string | number | boolean | null | string[] | number[] | boolean[];
52
46
 
53
47
  /**
54
48
  * The ParamValues type describes an object of param values, keyed by param Id,
@@ -53,13 +53,7 @@ import type {
53
53
  * @since v7.2.0
54
54
  */
55
55
  export type ParamValue =
56
- | string
57
- | number
58
- | boolean
59
- | null
60
- | string[]
61
- | number[]
62
- | boolean[];
56
+ string | number | boolean | null | string[] | number[] | boolean[];
63
57
 
64
58
  /**
65
59
  * The ParamValues type describes an object of param values, keyed by param Id,
@@ -1482,8 +1476,7 @@ export type Join<
1482
1476
  */
1483
1477
  <
1484
1478
  IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
1485
- | TableIdFromSchema<Schema>
1486
- | Id,
1479
+ TableIdFromSchema<Schema> | Id,
1487
1480
  IntermediateJoinedCellId extends JoinedCellIdOrId<
1488
1481
  Schema,
1489
1482
  IntermediateJoinedTableId
@@ -1511,8 +1504,7 @@ export type Join<
1511
1504
  */
1512
1505
  <
1513
1506
  IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
1514
- | TableIdFromSchema<Schema>
1515
- | Id,
1507
+ TableIdFromSchema<Schema> | Id,
1516
1508
  IntermediateJoinedCellId extends JoinedCellIdOrId<
1517
1509
  Schema,
1518
1510
  IntermediateJoinedTableId
@@ -1542,8 +1534,7 @@ export type Join<
1542
1534
  */
1543
1535
  <
1544
1536
  IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
1545
- | TableIdFromSchema<Schema>
1546
- | Id,
1537
+ TableIdFromSchema<Schema> | Id,
1547
1538
  >(
1548
1539
  joinedTableId: TableIdFromSchema<Schema>,
1549
1540
  fromIntermediateJoinedTableId: IntermediateJoinedTableId,
@@ -1576,8 +1567,7 @@ export type Join<
1576
1567
  */
1577
1568
  <
1578
1569
  IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
1579
- | TableIdFromSchema<Schema>
1580
- | Id,
1570
+ TableIdFromSchema<Schema> | Id,
1581
1571
  >(
1582
1572
  asQuery: true,
1583
1573
  joinedQueryId: Id,
@@ -1521,8 +1521,7 @@ export type InvalidValues = {[valueId: Id]: any[]};
1521
1521
  export type Changes = [
1522
1522
  changedTables: {
1523
1523
  [tableId: Id]:
1524
- | {[rowId: Id]: {[cellId: Id]: CellOrUndefined} | undefined}
1525
- | undefined;
1524
+ {[rowId: Id]: {[cellId: Id]: CellOrUndefined} | undefined} | undefined;
1526
1525
  },
1527
1526
  changedValues: {[valueId: Id]: ValueOrUndefined},
1528
1527
  isChanges: 1,
@@ -711,9 +711,8 @@ export type ValueCallback<
711
711
  Schema extends OptionalValuesSchema,
712
712
  Params extends any[] = ValueIdFromSchema<Schema> extends infer ValueId
713
713
  ? ValueId extends ValueIdFromSchema<Schema>
714
- ?
715
- | [valueId: ValueId, value: Value<Schema, ValueId>]
716
- | [valueId: never, value: never]
714
+ ? | [valueId: ValueId, value: Value<Schema, ValueId>]
715
+ | [valueId: never, value: never]
717
716
  : never
718
717
  : never,
719
718
  Params2 extends any[] = Params | [valueId: never, value: never],
@@ -957,8 +956,7 @@ export type SortedRowIdsArgs<
957
956
  Schema extends OptionalTablesSchema,
958
957
  TableId extends TableIdFromSchema<Schema>,
959
958
  CellIdOrUndefined extends CellIdFromSchema<Schema, TableId> | undefined =
960
- | CellIdFromSchema<Schema, TableId>
961
- | undefined,
959
+ CellIdFromSchema<Schema, TableId> | undefined,
962
960
  > = {
963
961
  /**
964
962
  * The Id of the Table in the Store, required.
@@ -1246,8 +1244,7 @@ export type TableCellIdsListener<
1246
1244
  : never
1247
1245
  : never,
1248
1246
  Params3 extends any[] =
1249
- | Params
1250
- | [store: never, tableId: never, getIdChanges: never],
1247
+ Params | [store: never, tableId: never, getIdChanges: never],
1251
1248
  Params2 extends any[] = Truncate<Params3>,
1252
1249
  // Params1 extends any[] = Truncate<Params2>,
1253
1250
  > = Params extends any
@@ -1314,8 +1311,7 @@ export type HasTableCellListener<
1314
1311
  : never
1315
1312
  : never,
1316
1313
  Params4 extends any[] =
1317
- | Params
1318
- | [store: never, tableId: never, cellId: never, hasTableCell: never],
1314
+ Params | [store: never, tableId: never, cellId: never, hasTableCell: never],
1319
1315
  Params3 extends any[] = Truncate<Params4>,
1320
1316
  // Params2 extends any[] = Truncate<Params3>,
1321
1317
  // Params1 extends any[] = Truncate<Params2>,
@@ -1595,8 +1591,7 @@ export type CellIdsListener<
1595
1591
  : never
1596
1592
  : never,
1597
1593
  Params4 extends any[] =
1598
- | Params
1599
- | [store: never, tableId: never, rowId: never, getIdChanges: never],
1594
+ Params | [store: never, tableId: never, rowId: never, getIdChanges: never],
1600
1595
  Params3 extends any[] = Truncate<Params4>,
1601
1596
  // Params2 extends any[] = Truncate<Params3>,
1602
1597
  // Params1 extends any[] = Truncate<Params2>,
@@ -1783,11 +1778,10 @@ export type CellListener<
1783
1778
  // Params2 extends any[] = Truncate<Params3>,
1784
1779
  // Params1 extends any[] = Truncate<Params2>,
1785
1780
  > = Params extends any
1786
- ?
1787
- | ((...params: Params7) => void)
1788
- | ((...params: Params6) => void)
1789
- | ((...params: Params5) => void)
1790
- | ((...params: Params4) => void)
1781
+ ? | ((...params: Params7) => void)
1782
+ | ((...params: Params6) => void)
1783
+ | ((...params: Params5) => void)
1784
+ | ((...params: Params4) => void)
1791
1785
  : // The unions may no longer be discriminatory with fewer parameters, and
1792
1786
  // TypeScript fails to resolve callback signatures in some cases.
1793
1787
  // | ((...params: Params3) => void)
@@ -2002,11 +1996,10 @@ export type ValueListener<
2002
1996
  Params2 extends any[] = Truncate<Params3>,
2003
1997
  // Params1 extends any[] = Truncate<Params2>,
2004
1998
  > = Params extends any
2005
- ?
2006
- | ((...params: Params5) => void)
2007
- | ((...params: Params4) => void)
2008
- | ((...params: Params3) => void)
2009
- | ((...params: Params2) => void)
1999
+ ? | ((...params: Params5) => void)
2000
+ | ((...params: Params4) => void)
2001
+ | ((...params: Params3) => void)
2002
+ | ((...params: Params2) => void)
2010
2003
  : // | ((...params: Params1) => void)
2011
2004
  never;
2012
2005
 
@@ -2411,8 +2404,7 @@ export type InvalidValues = {[valueId: Id]: any[]};
2411
2404
  * [
2412
2405
  * changedTables: {
2413
2406
  * [tableId: Id]:
2414
- * | {[rowId: Id]: {[cellId: Id]: CellOrUndefined} | undefined}
2415
- * | undefined;
2407
+ * {[rowId: Id]: {[cellId: Id]: CellOrUndefined} | undefined} | undefined;
2416
2408
  * },
2417
2409
  * changedValues: {[valueId: Id]: ValueOrUndefined},
2418
2410
  * isChanges: 1,
@@ -2470,10 +2462,9 @@ export type Changes<Schemas extends OptionalSchemas> = [
2470
2462
  | {
2471
2463
  [rowId: Id]:
2472
2464
  | {
2473
- [CellId in CellIdFromSchema<
2474
- Schemas[0],
2475
- TableId
2476
- >]?: CellOrUndefined<Schemas[0], TableId, CellId>;
2465
+ [
2466
+ CellId in CellIdFromSchema<Schemas[0], TableId>
2467
+ ]?: CellOrUndefined<Schemas[0], TableId, CellId>;
2477
2468
  }
2478
2469
  | undefined;
2479
2470
  }
@@ -4601,8 +4592,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
4601
4592
  rowId: Id,
4602
4593
  cellId: CellId,
4603
4594
  cell:
4604
- | Cell<Schemas[0], TableId, CellId>
4605
- | MapCell<Schemas[0], TableId, CellId>,
4595
+ Cell<Schemas[0], TableId, CellId> | MapCell<Schemas[0], TableId, CellId>,
4606
4596
  ): this;
4607
4597
 
4608
4598
  /**
@@ -79,7 +79,9 @@ export interface WsSynchronizer<
79
79
  * via WebSockets facilitated by a WsServer.
80
80
  *
81
81
  * As well as providing a reference to the MergeableStore to persist, you must
82
- * provide a configured WebSocket to send synchronization messages over.
82
+ * provide a configured WebSocket to send synchronization messages over. The
83
+ * path in the WebSocket URL is used by a WsServer as the path that the client
84
+ * joins. The MergeableStore Id does not select the server path.
83
85
  *
84
86
  * Instead of the raw browser implementation of WebSocket, you may prefer to use
85
87
  * the [Reconnecting
@@ -107,6 +109,9 @@ export interface WsSynchronizer<
107
109
  * @param onIgnoredError An optional handler for the errors that the
108
110
  * Synchronizer would otherwise ignore when trying to synchronize data. This is
109
111
  * suitable for debugging synchronization issues in a development environment.
112
+ * @param fragmentSize An optional maximum size for each WebSocket message
113
+ * fragment. When set, larger synchronization payloads are split into fragments
114
+ * and reassembled by the receiving WsSynchronizer, since v9.0.
110
115
  * @returns A reference to the new WsSynchronizer object.
111
116
  * @example
112
117
  * This example creates two WsSynchronizer objects to synchronize one
@@ -125,11 +130,11 @@ export interface WsSynchronizer<
125
130
  *
126
131
  * const synchronizer1 = await createWsSynchronizer(
127
132
  * store1,
128
- * new WebSocket('ws://localhost:8047'),
133
+ * new WebSocket('ws://localhost:8047/petShop'),
129
134
  * );
130
135
  * const synchronizer2 = await createWsSynchronizer(
131
136
  * store2,
132
- * new WebSocket('ws://localhost:8047'),
137
+ * new WebSocket('ws://localhost:8047/petShop'),
133
138
  * );
134
139
  *
135
140
  * await synchronizer1.startSync();
@@ -159,4 +164,5 @@ export function createWsSynchronizer<WebSocketType extends WebSocketTypes>(
159
164
  onSend?: Send,
160
165
  onReceive?: Receive,
161
166
  onIgnoredError?: (error: any) => void,
167
+ fragmentSize?: number,
162
168
  ): Promise<WsSynchronizer<WebSocketType>>;
@@ -90,11 +90,14 @@ export interface WsSynchronizer<
90
90
  * onSend?: Send,
91
91
  * onReceive?: Receive,
92
92
  * onIgnoredError?: (error: any) => void,
93
+ * fragmentSize?: number,
93
94
  * ): Promise<WsSynchronizer<WebSocketType>>;
94
95
  * ```
95
96
  *
96
97
  * As well as providing a reference to the MergeableStore to persist, you must
97
- * provide a configured WebSocket to send synchronization messages over.
98
+ * provide a configured WebSocket to send synchronization messages over. The
99
+ * path in the WebSocket URL is used by a WsServer as the path that the client
100
+ * joins. The MergeableStore Id does not select the server path.
98
101
  *
99
102
  * Instead of the raw browser implementation of WebSocket, you may prefer to use
100
103
  * the [Reconnecting
@@ -122,6 +125,9 @@ export interface WsSynchronizer<
122
125
  * @param onIgnoredError An optional handler for the errors that the
123
126
  * Synchronizer would otherwise ignore when trying to synchronize data. This is
124
127
  * suitable for debugging synchronization issues in a development environment.
128
+ * @param fragmentSize An optional maximum size for each WebSocket message
129
+ * fragment. When set, larger synchronization payloads are split into fragments
130
+ * and reassembled by the receiving WsSynchronizer, since v9.0.
125
131
  * @returns A reference to the new WsSynchronizer object.
126
132
  * @example
127
133
  * This example creates two WsSynchronizer objects to synchronize one
@@ -140,11 +146,11 @@ export interface WsSynchronizer<
140
146
  *
141
147
  * const synchronizer1 = await createWsSynchronizer(
142
148
  * store1,
143
- * new WebSocket('ws://localhost:8047'),
149
+ * new WebSocket('ws://localhost:8047/petShop'),
144
150
  * );
145
151
  * const synchronizer2 = await createWsSynchronizer(
146
152
  * store2,
147
- * new WebSocket('ws://localhost:8047'),
153
+ * new WebSocket('ws://localhost:8047/petShop'),
148
154
  * );
149
155
  *
150
156
  * await synchronizer1.startSync();
@@ -177,4 +183,5 @@ export function createWsSynchronizer<
177
183
  onSend?: Send,
178
184
  onReceive?: Receive,
179
185
  onIgnoredError?: (error: any) => void,
186
+ fragmentSize?: number,
180
187
  ): Promise<WsSynchronizer<Schemas, WebSocketType>>;