tinybase 10.0.0-beta.0 → 10.0.0-beta.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.
- package/@types/common/index.d.ts +1 -0
- package/@types/common/with-schemas/index.d.ts +1 -0
- package/@types/indexes/index.d.ts +4 -3
- package/@types/indexes/with-schemas/index.d.ts +4 -3
- package/@types/metrics/index.d.ts +1 -0
- package/@types/metrics/with-schemas/index.d.ts +1 -0
- package/@types/omni/index.d.ts +1 -0
- package/@types/omni/with-schemas/index.d.ts +1 -0
- package/@types/persisters/index.d.ts +1 -0
- package/@types/persisters/persister-partykit-server/index.d.ts +17 -0
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +17 -0
- package/@types/persisters/persister-tinyjoin/index.d.ts +197 -0
- package/@types/persisters/persister-tinyjoin/with-schemas/index.d.ts +221 -0
- package/@types/persisters/with-schemas/index.d.ts +1 -0
- package/@types/queries/index.d.ts +3 -0
- package/@types/queries/with-schemas/index.d.ts +3 -0
- package/@types/relationships/index.d.ts +1 -0
- package/@types/relationships/with-schemas/index.d.ts +1 -0
- package/@types/store/index.d.ts +4 -0
- package/@types/store/with-schemas/index.d.ts +4 -0
- package/@types/ui-react/index.d.ts +2 -0
- package/@types/ui-react/with-schemas/index.d.ts +1 -0
- package/@types/ui-react-dom-charts/index.d.ts +7 -0
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -0
- package/@types/ui-solid/index.d.ts +2 -0
- package/@types/ui-solid/with-schemas/index.d.ts +1 -0
- package/@types/ui-svelte/index.d.ts +23 -0
- package/@types/ui-svelte/with-schemas/index.d.ts +23 -0
- package/@types/ui-svelte-dom/index.d.ts +10 -0
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -0
- package/@types/ui-svelte-inspector/index.d.ts +1 -0
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -0
- package/checkpoints/index.js +4 -2
- package/checkpoints/with-schemas/index.js +4 -2
- package/index.js +37 -4
- package/metrics/index.js +2 -1
- package/metrics/with-schemas/index.js +2 -1
- package/min/checkpoints/index.js +1 -1
- package/min/checkpoints/index.js.gz +0 -0
- package/min/checkpoints/with-schemas/index.js +1 -1
- package/min/checkpoints/with-schemas/index.js.gz +0 -0
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/metrics/index.js +1 -1
- package/min/metrics/index.js.gz +0 -0
- package/min/metrics/with-schemas/index.js +1 -1
- package/min/metrics/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/persisters/index.js +1 -1
- package/min/persisters/index.js.gz +0 -0
- package/min/persisters/persister-better-sqlite3/index.js +1 -1
- package/min/persisters/persister-better-sqlite3/index.js.gz +0 -0
- package/min/persisters/persister-better-sqlite3/with-schemas/index.js +1 -1
- package/min/persisters/persister-better-sqlite3/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-capacitor-sqlite/index.js +1 -1
- package/min/persisters/persister-capacitor-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-capacitor-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
- package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
- package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/index.js +1 -1
- package/min/persisters/persister-electric-sql/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
- package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-libsql/index.js +1 -1
- package/min/persisters/persister-libsql/index.js.gz +0 -0
- package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
- package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-pg/index.js +1 -1
- package/min/persisters/persister-pg/index.js.gz +0 -0
- package/min/persisters/persister-pg/with-schemas/index.js +1 -1
- package/min/persisters/persister-pg/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-pglite/index.js +1 -1
- package/min/persisters/persister-pglite/index.js.gz +0 -0
- package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
- package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-postgres/index.js +1 -1
- package/min/persisters/persister-postgres/index.js.gz +0 -0
- package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
- package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-powersync/index.js +1 -1
- package/min/persisters/persister-powersync/index.js.gz +0 -0
- package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
- package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-react-native-sqlite/index.js +1 -1
- package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-node/index.js +1 -1
- package/min/persisters/persister-sqlite-node/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-node/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-node/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/index.js +1 -1
- package/min/persisters/persister-sqlite3/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-tinyjoin/index.js +1 -0
- package/min/persisters/persister-tinyjoin/index.js.gz +0 -0
- package/min/persisters/persister-tinyjoin/with-schemas/index.js +1 -0
- package/min/persisters/persister-tinyjoin/with-schemas/index.js.gz +0 -0
- package/min/persisters/with-schemas/index.js +1 -1
- package/min/persisters/with-schemas/index.js.gz +0 -0
- package/min/queries/index.js +1 -1
- package/min/queries/index.js.gz +0 -0
- package/min/queries/with-schemas/index.js +1 -1
- package/min/queries/with-schemas/index.js.gz +0 -0
- package/min/relationships/index.js +1 -1
- package/min/relationships/index.js.gz +0 -0
- package/min/relationships/with-schemas/index.js +1 -1
- package/min/relationships/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/index.js +1 -1
- package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +205 -94
- package/omni/with-schemas/index.js +205 -94
- package/package.json +54 -14
- package/persisters/index.js +28 -13
- package/persisters/persister-better-sqlite3/index.js +70 -55
- package/persisters/persister-better-sqlite3/with-schemas/index.js +70 -55
- package/persisters/persister-capacitor-sqlite/index.js +70 -55
- package/persisters/persister-capacitor-sqlite/with-schemas/index.js +70 -55
- package/persisters/persister-cr-sqlite-wasm/index.js +70 -55
- package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +70 -55
- package/persisters/persister-durable-object-sql-storage/index.js +28 -13
- package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +28 -13
- package/persisters/persister-electric-sql/index.js +70 -55
- package/persisters/persister-electric-sql/with-schemas/index.js +70 -55
- package/persisters/persister-expo-sqlite/index.js +70 -55
- package/persisters/persister-expo-sqlite/with-schemas/index.js +70 -55
- package/persisters/persister-libsql/index.js +91 -78
- package/persisters/persister-libsql/with-schemas/index.js +91 -78
- package/persisters/persister-pg/index.js +77 -62
- package/persisters/persister-pg/with-schemas/index.js +77 -62
- package/persisters/persister-pglite/index.js +28 -13
- package/persisters/persister-pglite/with-schemas/index.js +28 -13
- package/persisters/persister-postgres/index.js +28 -13
- package/persisters/persister-postgres/with-schemas/index.js +28 -13
- package/persisters/persister-powersync/index.js +81 -66
- package/persisters/persister-powersync/with-schemas/index.js +81 -66
- package/persisters/persister-react-native-sqlite/index.js +70 -55
- package/persisters/persister-react-native-sqlite/with-schemas/index.js +70 -55
- package/persisters/persister-sqlite-bun/index.js +70 -55
- package/persisters/persister-sqlite-bun/with-schemas/index.js +70 -55
- package/persisters/persister-sqlite-node/index.js +70 -55
- package/persisters/persister-sqlite-node/with-schemas/index.js +70 -55
- package/persisters/persister-sqlite-wasm/index.js +70 -55
- package/persisters/persister-sqlite-wasm/with-schemas/index.js +70 -55
- package/persisters/persister-sqlite3/index.js +70 -55
- package/persisters/persister-sqlite3/with-schemas/index.js +70 -55
- package/persisters/persister-tinyjoin/index.js +1710 -0
- package/persisters/persister-tinyjoin/with-schemas/index.js +1710 -0
- package/persisters/with-schemas/index.js +28 -13
- package/queries/index.js +2 -1
- package/queries/with-schemas/index.js +2 -1
- package/readme.md +3 -3
- package/relationships/index.js +39 -9
- package/relationships/with-schemas/index.js +39 -9
- package/releases.md +20 -1
- package/synchronizers/synchronizer-local/index.js +1 -1
- package/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
- package/with-schemas/index.js +37 -4
package/@types/common/index.d.ts
CHANGED
|
@@ -121,6 +121,7 @@ export type Sorter = (sortKey1: SortKey, sortKey2: SortKey) => number;
|
|
|
121
121
|
* This is used internally within the mergeable-store module, but is used for
|
|
122
122
|
* the createMergeableStore function's second optional argument to allow
|
|
123
123
|
* applications to override the clock used to generate timestamps.
|
|
124
|
+
* @returns The current time, in milliseconds.
|
|
124
125
|
* @category Stamps
|
|
125
126
|
* @since v6.2.0
|
|
126
127
|
*/
|
|
@@ -134,6 +134,7 @@ export type Sorter = (sortKey1: SortKey, sortKey2: SortKey) => number;
|
|
|
134
134
|
* This is used internally within the mergeable-store module, but is used for
|
|
135
135
|
* the createMergeableStore function's second optional argument to allow
|
|
136
136
|
* applications to override the clock used to generate timestamps.
|
|
137
|
+
* @returns The current time, in milliseconds.
|
|
137
138
|
* @category Stamps
|
|
138
139
|
* @since v6.2.0
|
|
139
140
|
*/
|
|
@@ -553,9 +553,9 @@ export interface Indexes {
|
|
|
553
553
|
* Slice in a specified Index.
|
|
554
554
|
*
|
|
555
555
|
* This method is useful for iterating over the Slice structure of the Index
|
|
556
|
-
* in a functional style. The `
|
|
557
|
-
* function that will be called with the Id
|
|
558
|
-
*
|
|
556
|
+
* in a functional style. The `sliceCallback` parameter is a SliceCallback
|
|
557
|
+
* function that will be called with the Id of each Slice and a function for
|
|
558
|
+
* iterating over its Rows.
|
|
559
559
|
* @param indexId The Id of the Index to iterate over.
|
|
560
560
|
* @param sliceCallback The function that should be called for every Slice.
|
|
561
561
|
* @example
|
|
@@ -828,6 +828,7 @@ export interface Indexes {
|
|
|
828
828
|
* with a reference to the Indexes object.
|
|
829
829
|
* @param listener The function that will be called whenever an Index
|
|
830
830
|
* definition is added or removed.
|
|
831
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
831
832
|
* @example
|
|
832
833
|
* This example creates a Store, an Indexes object, and then registers a
|
|
833
834
|
* listener that responds to the addition and the removal of an Index
|
|
@@ -674,9 +674,9 @@ export interface Indexes<in out Schemas extends OptionalSchemas> {
|
|
|
674
674
|
* ```
|
|
675
675
|
*
|
|
676
676
|
* This method is useful for iterating over the Slice structure of the Index
|
|
677
|
-
* in a functional style. The `
|
|
678
|
-
* function that will be called with the Id
|
|
679
|
-
*
|
|
677
|
+
* in a functional style. The `sliceCallback` parameter is a SliceCallback
|
|
678
|
+
* function that will be called with the Id of each Slice and a function for
|
|
679
|
+
* iterating over its Rows.
|
|
680
680
|
* @param indexId The Id of the Index to iterate over.
|
|
681
681
|
* @param sliceCallback The function that should be called for every Slice.
|
|
682
682
|
* @example
|
|
@@ -882,6 +882,7 @@ export interface Indexes<in out Schemas extends OptionalSchemas> {
|
|
|
882
882
|
* with a reference to the Indexes object.
|
|
883
883
|
* @param listener The function that will be called whenever an Index
|
|
884
884
|
* definition is added or removed.
|
|
885
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
885
886
|
* @example
|
|
886
887
|
* This example creates a Store, an Indexes object, and then registers a
|
|
887
888
|
* listener that responds to the addition and the removal of an Index
|
|
@@ -656,6 +656,7 @@ export interface Metrics {
|
|
|
656
656
|
* with a reference to the Metrics object.
|
|
657
657
|
* @param listener The function that will be called whenever a Metric
|
|
658
658
|
* definition is added or removed.
|
|
659
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
659
660
|
* @example
|
|
660
661
|
* This example creates a Store, a Metrics object, and then registers a
|
|
661
662
|
* listener that responds to the addition and the removal of a Metric
|
|
@@ -724,6 +724,7 @@ export interface Metrics<in out Schemas extends OptionalSchemas> {
|
|
|
724
724
|
* with a reference to the Metrics object.
|
|
725
725
|
* @param listener The function that will be called whenever a Metric
|
|
726
726
|
* definition is added or removed.
|
|
727
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
727
728
|
* @example
|
|
728
729
|
* This example creates a Store, a Metrics object, and then registers a
|
|
729
730
|
* listener that responds to the addition and the removal of a Metric
|
package/@types/omni/index.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export * from '../persisters/persister-sqlite-node/index.d.ts';
|
|
|
47
47
|
export * from '../persisters/persister-sqlite-wasm/index.d.ts';
|
|
48
48
|
export * from '../persisters/persister-sqlite3/index.d.ts';
|
|
49
49
|
export * from '../persisters/persister-supabase/index.d.ts';
|
|
50
|
+
export * from '../persisters/persister-tinyjoin/index.d.ts';
|
|
50
51
|
export * from '../persisters/persister-yjs/index.d.ts';
|
|
51
52
|
export * from '../queries/index.d.ts';
|
|
52
53
|
export * from '../relationships/index.d.ts';
|
|
@@ -46,6 +46,7 @@ export * from '../../persisters/persister-sqlite-node/with-schemas/index.d.ts';
|
|
|
46
46
|
export * from '../../persisters/persister-sqlite-wasm/with-schemas/index.d.ts';
|
|
47
47
|
export * from '../../persisters/persister-sqlite3/with-schemas/index.d.ts';
|
|
48
48
|
export * from '../../persisters/persister-supabase/with-schemas/index.d.ts';
|
|
49
|
+
export * from '../../persisters/persister-tinyjoin/with-schemas/index.d.ts';
|
|
49
50
|
export * from '../../persisters/persister-yjs/with-schemas/index.d.ts';
|
|
50
51
|
export * from '../../persisters/with-schemas/index.d.ts';
|
|
51
52
|
export * from '../../queries/with-schemas/index.d.ts';
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* |ReactNativeSqlitePersister|SQLite in React Native, via [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage)|Yes|Yes*
|
|
28
28
|
* |PostgresPersister|PostgreSQL, via [postgres](https://github.com/porsager/postgres)|Yes|Yes*
|
|
29
29
|
* |PglitePersister|PostgreSQL, via [PGlite](https://github.com/electric-sql/pglite)|Yes|Yes*
|
|
30
|
+
* |TinyJoinPersister|PostgreSQL-shaped SQL in a browser, via [TinyJoin](https://tinyjoin.org)|Yes|Yes*
|
|
30
31
|
* |CrSqliteWasmPersister|SQLite CRDTs, via [cr-sqlite-wasm](https://github.com/vlcn-io/cr-sqlite)|Yes|No
|
|
31
32
|
* |ElectricSqlPersister|Electric SQL, via [electric-sql](https://github.com/electric-sql/electric)|Yes|No
|
|
32
33
|
* |LibSqlPersister|LibSQL for Turso, via [libsql-client](https://github.com/tursodatabase/libsql-client-ts)|Yes|No
|
|
@@ -201,6 +201,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
201
201
|
* See the [PartyKit server API
|
|
202
202
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
203
203
|
* more details.
|
|
204
|
+
* @returns A Promise containing the Response to the request.
|
|
204
205
|
* @category Connection
|
|
205
206
|
* @since v4.3.0
|
|
206
207
|
*/
|
|
@@ -256,6 +257,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
256
257
|
* server, or `true` to allow them (subject to subsequent canSetRow method,
|
|
257
258
|
* canDelRow method, canSetCell method, and canDelCell method checks). The
|
|
258
259
|
* default implementation returns `true` to allow all changes.
|
|
260
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
261
|
+
* Table.
|
|
259
262
|
* @example
|
|
260
263
|
* The following implementation will strip out any attempts by the client to
|
|
261
264
|
* update any 'user' tabular data after the initial save:
|
|
@@ -295,6 +298,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
295
298
|
* Return `false` from this method to disallow this Table from being deleted
|
|
296
299
|
* on the server, or `true` to allow it. The default implementation returns
|
|
297
300
|
* `true` to allow deletion.
|
|
301
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
302
|
+
* Table.
|
|
298
303
|
* @example
|
|
299
304
|
* The following implementation will strip out any attempts by the client to
|
|
300
305
|
* delete the 'user' Table:
|
|
@@ -336,6 +341,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
336
341
|
* server, or `true` to allow them (subject to subsequent canSetCell method
|
|
337
342
|
* and canDelCell method checks). The default implementation returns `true` to
|
|
338
343
|
* allow all changes.
|
|
344
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
345
|
+
* Row.
|
|
339
346
|
* @example
|
|
340
347
|
* The following implementation will strip out any attempts by the client to
|
|
341
348
|
* update the 'me' Row of the 'user' Table after the initial save:
|
|
@@ -377,6 +384,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
377
384
|
* Return `false` from this method to disallow this Row from being deleted
|
|
378
385
|
* on the server, or `true` to allow it. The default implementation returns
|
|
379
386
|
* `true` to allow deletion.
|
|
387
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
388
|
+
* Row.
|
|
380
389
|
* @example
|
|
381
390
|
* The following implementation will strip out any attempts by the client to
|
|
382
391
|
* delete the 'me' Row of the 'user' Table:
|
|
@@ -422,6 +431,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
422
431
|
* Return `false` from this method to disallow changes to this Cell on the
|
|
423
432
|
* server, or `true` to allow them. The default implementation returns `true`
|
|
424
433
|
* to allow all changes.
|
|
434
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
435
|
+
* Cell.
|
|
425
436
|
* @example
|
|
426
437
|
* The following implementation will strip out any attempts by the client to
|
|
427
438
|
* update the 'name' Cell of the 'me' Row of the 'user' Table after the
|
|
@@ -469,6 +480,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
469
480
|
* Return `false` from this method to disallow this Cell from being deleted on
|
|
470
481
|
* the server, or `true` to allow it. The default implementation returns
|
|
471
482
|
* `true` to allow deletion.
|
|
483
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
484
|
+
* Cell.
|
|
472
485
|
* @example
|
|
473
486
|
* The following implementation will strip out any attempts by the client to
|
|
474
487
|
* delete the 'name' Cell of the 'me' Row of the 'user' Table:
|
|
@@ -518,6 +531,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
518
531
|
* Return `false` from this method to disallow changes to this Value on the
|
|
519
532
|
* server, or `true` to allow them. The default implementation returns `true`
|
|
520
533
|
* to allow all changes.
|
|
534
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
535
|
+
* Value.
|
|
521
536
|
* @example
|
|
522
537
|
* The following implementation will strip out any attempts by the client to
|
|
523
538
|
* update the 'userId' Value after the initial save:
|
|
@@ -559,6 +574,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
559
574
|
* Return `false` from this method to disallow this Value from being deleted
|
|
560
575
|
* on the server, or `true` to allow it. The default implementation returns
|
|
561
576
|
* `true` to allow deletion.
|
|
577
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
578
|
+
* Value.
|
|
562
579
|
* @example
|
|
563
580
|
* The following implementation will strip out any attempts by the client to
|
|
564
581
|
* delete the 'userId' Value:
|
|
@@ -201,6 +201,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
201
201
|
* See the [PartyKit server API
|
|
202
202
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
203
203
|
* more details.
|
|
204
|
+
* @returns A Promise containing the Response to the request.
|
|
204
205
|
* @category Connection
|
|
205
206
|
* @since v4.3.0
|
|
206
207
|
*/
|
|
@@ -256,6 +257,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
256
257
|
* server, or `true` to allow them (subject to subsequent canSetRow method,
|
|
257
258
|
* canDelRow method, canSetCell method, and canDelCell method checks). The
|
|
258
259
|
* default implementation returns `true` to allow all changes.
|
|
260
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
261
|
+
* Table.
|
|
259
262
|
* @example
|
|
260
263
|
* The following implementation will strip out any attempts by the client to
|
|
261
264
|
* update any 'user' tabular data after the initial save:
|
|
@@ -295,6 +298,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
295
298
|
* Return `false` from this method to disallow this Table from being deleted
|
|
296
299
|
* on the server, or `true` to allow it. The default implementation returns
|
|
297
300
|
* `true` to allow deletion.
|
|
301
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
302
|
+
* Table.
|
|
298
303
|
* @example
|
|
299
304
|
* The following implementation will strip out any attempts by the client to
|
|
300
305
|
* delete the 'user' Table:
|
|
@@ -336,6 +341,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
336
341
|
* server, or `true` to allow them (subject to subsequent canSetCell method
|
|
337
342
|
* and canDelCell method checks). The default implementation returns `true` to
|
|
338
343
|
* allow all changes.
|
|
344
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
345
|
+
* Row.
|
|
339
346
|
* @example
|
|
340
347
|
* The following implementation will strip out any attempts by the client to
|
|
341
348
|
* update the 'me' Row of the 'user' Table after the initial save:
|
|
@@ -377,6 +384,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
377
384
|
* Return `false` from this method to disallow this Row from being deleted
|
|
378
385
|
* on the server, or `true` to allow it. The default implementation returns
|
|
379
386
|
* `true` to allow deletion.
|
|
387
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
388
|
+
* Row.
|
|
380
389
|
* @example
|
|
381
390
|
* The following implementation will strip out any attempts by the client to
|
|
382
391
|
* delete the 'me' Row of the 'user' Table:
|
|
@@ -436,6 +445,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
436
445
|
* Return `false` from this method to disallow changes to this Cell on the
|
|
437
446
|
* server, or `true` to allow them. The default implementation returns `true`
|
|
438
447
|
* to allow all changes.
|
|
448
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
449
|
+
* Cell.
|
|
439
450
|
* @example
|
|
440
451
|
* The following implementation will strip out any attempts by the client to
|
|
441
452
|
* update the 'name' Cell of the 'me' Row of the 'user' Table after the
|
|
@@ -483,6 +494,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
483
494
|
* Return `false` from this method to disallow this Cell from being deleted on
|
|
484
495
|
* the server, or `true` to allow it. The default implementation returns
|
|
485
496
|
* `true` to allow deletion.
|
|
497
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
498
|
+
* Cell.
|
|
486
499
|
* @example
|
|
487
500
|
* The following implementation will strip out any attempts by the client to
|
|
488
501
|
* delete the 'name' Cell of the 'me' Row of the 'user' Table:
|
|
@@ -544,6 +557,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
544
557
|
* Return `false` from this method to disallow changes to this Value on the
|
|
545
558
|
* server, or `true` to allow them. The default implementation returns `true`
|
|
546
559
|
* to allow all changes.
|
|
560
|
+
* @returns A promised boolean indicating whether to allow the changes to the
|
|
561
|
+
* Value.
|
|
547
562
|
* @example
|
|
548
563
|
* The following implementation will strip out any attempts by the client to
|
|
549
564
|
* update the 'userId' Value after the initial save:
|
|
@@ -585,6 +600,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
585
600
|
* Return `false` from this method to disallow this Value from being deleted
|
|
586
601
|
* on the server, or `true` to allow it. The default implementation returns
|
|
587
602
|
* `true` to allow deletion.
|
|
603
|
+
* @returns A promised boolean indicating whether to allow the deletion of the
|
|
604
|
+
* Value.
|
|
588
605
|
* @example
|
|
589
606
|
* The following implementation will strip out any attempts by the client to
|
|
590
607
|
* delete the 'userId' Value:
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-tinyjoin module of the TinyBase project lets you save and load
|
|
3
|
+
* Store data to and from a TinyJoin database in a browser.
|
|
4
|
+
* @see Database Persistence guide
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module persister-tinyjoin
|
|
7
|
+
* @since 10.0.0
|
|
8
|
+
*/
|
|
9
|
+
import type {Client} from 'tinyjoin';
|
|
10
|
+
import type {MergeableStore} from '../../mergeable-store/index.d.ts';
|
|
11
|
+
import type {Store} from '../../store/index.d.ts';
|
|
12
|
+
import type {
|
|
13
|
+
DatabasePersisterConfig,
|
|
14
|
+
DpcJson,
|
|
15
|
+
Persister,
|
|
16
|
+
Persists,
|
|
17
|
+
} from '../index.d.ts';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The TinyJoinPersister interface represents a Persister that lets you save and
|
|
21
|
+
* load Store data to and from a [TinyJoin](https://tinyjoin.org) database.
|
|
22
|
+
*
|
|
23
|
+
* You should use the createTinyJoinPersister function to create a
|
|
24
|
+
* TinyJoinPersister object.
|
|
25
|
+
*
|
|
26
|
+
* It is a minor extension to the Persister interface and simply provides an
|
|
27
|
+
* extra getTinyJoin method for accessing a reference to the TinyJoin client the
|
|
28
|
+
* Store is being persisted to.
|
|
29
|
+
* @category Persister
|
|
30
|
+
* @since 10.0.0
|
|
31
|
+
*/
|
|
32
|
+
export interface TinyJoinPersister extends Persister<Persists.StoreOrMergeableStore> {
|
|
33
|
+
/**
|
|
34
|
+
* The getTinyJoin method returns a reference to the TinyJoin client the Store
|
|
35
|
+
* is being persisted to.
|
|
36
|
+
* @returns A reference to the TinyJoin client.
|
|
37
|
+
* @example
|
|
38
|
+
* This example creates a Persister object against a newly-created Store and
|
|
39
|
+
* then gets the TinyJoin client back out again.
|
|
40
|
+
*
|
|
41
|
+
* ```js ignore
|
|
42
|
+
* import {createStore} from 'tinybase';
|
|
43
|
+
* import {createTinyJoinPersister} from 'tinybase/persisters/persister-tinyjoin';
|
|
44
|
+
* import {create} from 'tinyjoin';
|
|
45
|
+
*
|
|
46
|
+
* const tinyJoin = await create();
|
|
47
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
48
|
+
* const persister = createTinyJoinPersister(store, tinyJoin, 'my_tinybase');
|
|
49
|
+
*
|
|
50
|
+
* console.log(persister.getTinyJoin() == tinyJoin);
|
|
51
|
+
* // -> true
|
|
52
|
+
*
|
|
53
|
+
* await persister.destroy();
|
|
54
|
+
* await tinyJoin.close();
|
|
55
|
+
* ```
|
|
56
|
+
* @category Getter
|
|
57
|
+
* @since 10.0.0
|
|
58
|
+
*/
|
|
59
|
+
getTinyJoin(): Client;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The createTinyJoinPersister function creates a TinyJoinPersister object that
|
|
64
|
+
* can persist the Store to a [TinyJoin](https://tinyjoin.org) database in a
|
|
65
|
+
* browser.
|
|
66
|
+
*
|
|
67
|
+
* TinyJoin is a tiny, worker-first relational database that runs entirely in
|
|
68
|
+
* the browser, either in memory or - with an `opfs://` data directory - saved
|
|
69
|
+
* across reloads. This Persister therefore gives you a SQL-shaped local
|
|
70
|
+
* database to keep a Store in, without a server or a native dependency. Its
|
|
71
|
+
* `tinyjoin/node` entry point opens an ephemeral in-memory database in a Node
|
|
72
|
+
* worker thread, which makes this Persister testable outside a browser.
|
|
73
|
+
*
|
|
74
|
+
* A TinyJoinPersister supports regular Store objects, and can also be used to
|
|
75
|
+
* persist the metadata of a MergeableStore when using the JSON serialization
|
|
76
|
+
* mode, as described below.
|
|
77
|
+
*
|
|
78
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
79
|
+
* `tinyJoin` parameter which identifies the TinyJoin client that was returned
|
|
80
|
+
* from its own `create` function.
|
|
81
|
+
*
|
|
82
|
+
* A database Persister uses one of two modes: either a JSON serialization of
|
|
83
|
+
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
84
|
+
* mapping of Table Ids to database table names and vice-versa).
|
|
85
|
+
*
|
|
86
|
+
* The third argument is a DatabasePersisterConfig object that configures which
|
|
87
|
+
* of those modes to use, and settings for each. If the third argument is simply
|
|
88
|
+
* a string, it is used as the `storeTableName` property of the JSON
|
|
89
|
+
* serialization.
|
|
90
|
+
*
|
|
91
|
+
* See the documentation for the DpcJson and DpcTabular types for more
|
|
92
|
+
* information on how both of those modes can be configured.
|
|
93
|
+
*
|
|
94
|
+
* Note: When using tabular mode, SQL NULL values are loaded as TinyBase null
|
|
95
|
+
* values, making tables dense (every Row has every Cell). See the Database
|
|
96
|
+
* Persistence guide for details.
|
|
97
|
+
*
|
|
98
|
+
* TinyJoin implements a deliberately bounded SQL dialect, and two of its
|
|
99
|
+
* boundaries are worth knowing about. It has no `ALTER TABLE ... DROP COLUMN`,
|
|
100
|
+
* so the table used for the JSON serialization should not have columns beyond
|
|
101
|
+
* the two it manages, and tabular mode should be left with its default of not
|
|
102
|
+
* deleting empty columns. It also has no SQL transaction
|
|
103
|
+
* statements, and rejects schema changes inside its own callback transactions,
|
|
104
|
+
* so each of the Persister's commands is atomic on its own rather than a save
|
|
105
|
+
* being atomic as a whole.
|
|
106
|
+
* @param store The Store or MergeableStore to persist.
|
|
107
|
+
* @param tinyJoin The TinyJoin client that was returned from `create(...)`.
|
|
108
|
+
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
109
|
+
* persistence mode (or a string to set the `storeTableName` property of the
|
|
110
|
+
* JSON serialization).
|
|
111
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
112
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
113
|
+
* behavior in a development environment.
|
|
114
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
115
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
116
|
+
* debugging persistence issues in a development environment.
|
|
117
|
+
* @returns A reference to the new TinyJoinPersister object.
|
|
118
|
+
* @example
|
|
119
|
+
* This example creates a TinyJoinPersister object and persists the Store to a
|
|
120
|
+
* TinyJoin database as a JSON serialization into the `my_tinybase` table. It
|
|
121
|
+
* makes a change to the database directly and then reloads it back into the
|
|
122
|
+
* Store.
|
|
123
|
+
*
|
|
124
|
+
* ```js ignore
|
|
125
|
+
* import {createStore} from 'tinybase';
|
|
126
|
+
* import {createTinyJoinPersister} from 'tinybase/persisters/persister-tinyjoin';
|
|
127
|
+
* import {create} from 'tinyjoin';
|
|
128
|
+
*
|
|
129
|
+
* const tinyJoin = await create();
|
|
130
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
131
|
+
* const persister = createTinyJoinPersister(store, tinyJoin, 'my_tinybase');
|
|
132
|
+
*
|
|
133
|
+
* await persister.save();
|
|
134
|
+
* // Store will be saved to the database.
|
|
135
|
+
*
|
|
136
|
+
* console.log((await tinyJoin.query('SELECT * FROM my_tinybase')).rows);
|
|
137
|
+
* // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
|
|
138
|
+
*
|
|
139
|
+
* await tinyJoin.query('UPDATE my_tinybase SET store = $1 WHERE _id = $2', [
|
|
140
|
+
* '[{"pets":{"felix":{"species":"cat"}}},{}]',
|
|
141
|
+
* '_',
|
|
142
|
+
* ]);
|
|
143
|
+
*
|
|
144
|
+
* await persister.load();
|
|
145
|
+
* console.log(store.getTables());
|
|
146
|
+
* // -> {pets: {felix: {species: 'cat'}}}
|
|
147
|
+
*
|
|
148
|
+
* await persister.destroy();
|
|
149
|
+
* await tinyJoin.close();
|
|
150
|
+
* ```
|
|
151
|
+
* @example
|
|
152
|
+
* This example creates a TinyJoinPersister object and persists the Store to a
|
|
153
|
+
* TinyJoin database with tabular mapping.
|
|
154
|
+
*
|
|
155
|
+
* ```js ignore
|
|
156
|
+
* import {createStore} from 'tinybase';
|
|
157
|
+
* import {createTinyJoinPersister} from 'tinybase/persisters/persister-tinyjoin';
|
|
158
|
+
* import {create} from 'tinyjoin';
|
|
159
|
+
*
|
|
160
|
+
* const tinyJoin = await create();
|
|
161
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
162
|
+
* const persister = createTinyJoinPersister(store, tinyJoin, {
|
|
163
|
+
* mode: 'tabular',
|
|
164
|
+
* tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
|
|
165
|
+
* });
|
|
166
|
+
*
|
|
167
|
+
* await persister.save();
|
|
168
|
+
* console.log((await tinyJoin.query('SELECT * FROM pets')).rows);
|
|
169
|
+
* // -> [{_id: 'fido', species: '"dog"'}]
|
|
170
|
+
* // Note that Cells and Values are JSON-encoded, as they are in PostgreSQL.
|
|
171
|
+
*
|
|
172
|
+
* await tinyJoin.query('INSERT INTO pets (_id, species) VALUES ($1, $2)', [
|
|
173
|
+
* 'felix',
|
|
174
|
+
* '"cat"',
|
|
175
|
+
* ]);
|
|
176
|
+
* await persister.load();
|
|
177
|
+
* console.log(store.getTables());
|
|
178
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
179
|
+
*
|
|
180
|
+
* await persister.destroy();
|
|
181
|
+
* await tinyJoin.close();
|
|
182
|
+
* ```
|
|
183
|
+
* @category Creation
|
|
184
|
+
* @essential Persisting stores
|
|
185
|
+
* @since 10.0.0
|
|
186
|
+
*/
|
|
187
|
+
export function createTinyJoinPersister<StoreType extends Store>(
|
|
188
|
+
store: StoreType,
|
|
189
|
+
tinyJoin: Client,
|
|
190
|
+
configOrStoreTableName?:
|
|
191
|
+
| (NoInfer<StoreType> extends MergeableStore
|
|
192
|
+
? DpcJson
|
|
193
|
+
: DatabasePersisterConfig)
|
|
194
|
+
| string,
|
|
195
|
+
onSqlCommand?: (sql: string, params?: any[]) => void,
|
|
196
|
+
onIgnoredError?: (error: any) => void,
|
|
197
|
+
): TinyJoinPersister;
|