tinybase 6.1.0-beta.1 → 6.1.0-beta.3

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 (108) hide show
  1. package/@types/common/index.d.ts +4 -4
  2. package/@types/common/with-schemas/index.d.ts +4 -4
  3. package/@types/mergeable-store/index.d.ts +45 -20
  4. package/@types/mergeable-store/with-schemas/index.d.ts +49 -21
  5. package/@types/persisters/index.d.ts +1 -1
  6. package/@types/persisters/with-schemas/index.d.ts +1 -1
  7. package/index.js +19 -11
  8. package/indexes/index.js +15 -3
  9. package/indexes/with-schemas/index.js +15 -3
  10. package/mergeable-store/index.js +4 -8
  11. package/mergeable-store/with-schemas/index.js +4 -8
  12. package/min/index.js +1 -1
  13. package/min/index.js.gz +0 -0
  14. package/min/indexes/index.js +1 -1
  15. package/min/indexes/index.js.gz +0 -0
  16. package/min/indexes/with-schemas/index.js +1 -1
  17. package/min/indexes/with-schemas/index.js.gz +0 -0
  18. package/min/mergeable-store/index.js +1 -1
  19. package/min/mergeable-store/index.js.gz +0 -0
  20. package/min/mergeable-store/with-schemas/index.js +1 -1
  21. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  22. package/min/with-schemas/index.js +1 -1
  23. package/min/with-schemas/index.js.gz +0 -0
  24. package/package.json +9 -9
  25. package/readme.md +2 -2
  26. package/with-schemas/index.js +19 -11
  27. package/@types/_internal/queries/index.d.cts +0 -0
  28. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  29. package/@types/_internal/store/index.d.cts +0 -3
  30. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  31. package/@types/_internal/ui-react/index.d.cts +0 -0
  32. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  33. package/@types/checkpoints/index.d.cts +0 -1059
  34. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  35. package/@types/common/index.d.cts +0 -158
  36. package/@types/common/with-schemas/index.d.cts +0 -158
  37. package/@types/index.d.cts +0 -17
  38. package/@types/indexes/index.d.cts +0 -1064
  39. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  40. package/@types/mergeable-store/index.d.cts +0 -1139
  41. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  42. package/@types/metrics/index.d.cts +0 -917
  43. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  44. package/@types/persisters/index.d.cts +0 -1877
  45. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  46. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  47. package/@types/persisters/persister-browser/index.d.cts +0 -185
  48. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  49. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  50. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  51. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  52. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  53. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  54. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  55. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  56. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  57. package/@types/persisters/persister-file/index.d.cts +0 -94
  58. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  59. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  60. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  61. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  62. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  63. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  64. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  65. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  66. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  67. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  68. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  69. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  70. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  71. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  72. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  73. package/@types/persisters/persister-remote/index.d.cts +0 -117
  74. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  75. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  76. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  77. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  78. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  79. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  80. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  81. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  82. package/@types/queries/index.d.cts +0 -3695
  83. package/@types/queries/with-schemas/index.d.cts +0 -4016
  84. package/@types/relationships/index.d.cts +0 -1320
  85. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  86. package/@types/store/index.d.cts +0 -7598
  87. package/@types/store/with-schemas/index.d.cts +0 -9278
  88. package/@types/synchronizers/index.d.cts +0 -485
  89. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  90. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  91. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  92. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  93. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  94. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  95. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  96. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  97. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  98. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  99. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  100. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  101. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  102. package/@types/ui-react/index.d.cts +0 -16640
  103. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  104. package/@types/ui-react-dom/index.d.cts +0 -1862
  105. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  106. package/@types/ui-react-inspector/index.d.cts +0 -79
  107. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  108. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,120 +0,0 @@
1
- /**
2
- * The persister-indexed-db module of the TinyBase project lets you save and
3
- * load Store data to and from browser IndexedDB storage.
4
- * @see Persistence guides
5
- * @packageDocumentation
6
- * @module persister-indexed-db
7
- * @since v4.2.0
8
- */
9
- import type {Store} from '../../store/index.d.cts';
10
- import type {Persister} from '../index.d.cts';
11
-
12
- /**
13
- * The IndexedDbPersister interface represents a Persister that lets you save
14
- * and load Store data to and from browser IndexedDB storage.
15
- *
16
- * You should use the createIndexedDbPersister function to create an
17
- * IndexedDbPersister object.
18
- *
19
- * It is a minor extension to the Persister interface and simply provides an
20
- * extra getDbName method for accessing the unique key of the IndexedDB the
21
- * Store is being persisted to.
22
- * @category Persister
23
- * @since v4.3.14
24
- */
25
- export interface IndexedDbPersister extends Persister {
26
- /**
27
- * The getDbName method returns the unique key of the IndexedDB the Store is
28
- * being persisted to.
29
- * @returns The unique key of the IndexedDB.
30
- * @example
31
- * This example creates a Persister object against a newly-created Store and
32
- * then gets the unique key of the IndexedDB back out again.
33
- *
34
- * ```js
35
- * import {createStore} from 'tinybase';
36
- * import {createIndexedDbPersister} from 'tinybase/persisters/persister-indexed-db';
37
- *
38
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
39
- * const persister = createIndexedDbPersister(store, 'petStore');
40
- *
41
- * console.log(persister.getDbName());
42
- * // -> 'petStore'
43
- *
44
- * persister.destroy();
45
- * ```
46
- * @category Getter
47
- * @since v4.3.14
48
- */
49
- getDbName(): string;
50
- }
51
-
52
- /**
53
- * The createIndexedDbPersister function creates an IndexedDbPersister object
54
- * that can persist a Store to the browser's IndexedDB storage.
55
- *
56
- * An IndexedDbPersister only supports regular Store objects, and cannot be used
57
- * to persist the metadata of a MergeableStore.
58
- *
59
- * As well as providing a reference to the Store to persist, you must provide a
60
- * `dbName` parameter which is unique to your application. This is the key used
61
- * to identify which IndexedDB to use.
62
- *
63
- * Within that database, this Persister will create two object stores: one
64
- * called 't', and one called 'v'. These will contain the Store's tabular and
65
- * key-value data respectively, using 'k' and 'v' to store the key and value of
66
- * each entry, as shown in the example.
67
- *
68
- * Note that it is not possible to reactively detect changes to a browser's
69
- * IndexedDB. If you do choose to enable automatic loading for the Persister
70
- * (with the startAutoLoad method), it needs to poll the database for changes.
71
- * The `autoLoadIntervalSeconds` method is used to indicate how often to do
72
- * this.
73
- * @param store The Store to persist.
74
- * @param dbName The unique key to identify the IndexedDB to use.
75
- * @param autoLoadIntervalSeconds How often to poll the database when in
76
- * 'autoLoad' mode, defaulting to 1.
77
- * @param onIgnoredError An optional handler for the errors that the Persister
78
- * would otherwise ignore when trying to save or load data. This is suitable for
79
- * debugging persistence issues in a development environment.
80
- * @returns A reference to the new IndexedDbPersister object.
81
- * @example
82
- * This example creates a IndexedDbPersister object and persists the Store to
83
- * the browser's IndexedDB storage.
84
- *
85
- * ```js
86
- * import {createStore} from 'tinybase';
87
- * import {createIndexedDbPersister} from 'tinybase/persisters/persister-indexed-db';
88
- *
89
- * const store = createStore()
90
- * .setTable('pets', {fido: {species: 'dog'}})
91
- * .setTable('species', {dog: {price: 5}})
92
- * .setValues({open: true});
93
- * const persister = createIndexedDbPersister(store, 'petStore');
94
- *
95
- * await persister.save();
96
- * // IndexedDB ->
97
- * // database petStore:
98
- * // objectStore t:
99
- * // object 0:
100
- * // k: "pets"
101
- * // v: {fido: {species: dog}}
102
- * // object 1:
103
- * // k: "species"
104
- * // v: {dog: {price: 5}}
105
- * // objectStore v:
106
- * // object 0:
107
- * // k: "open"
108
- * // v: true
109
- *
110
- * persister.destroy();
111
- * ```
112
- * @category Creation
113
- * @since v4.2.0
114
- */
115
- export function createIndexedDbPersister(
116
- store: Store,
117
- dbName: string,
118
- autoLoadIntervalSeconds?: number,
119
- onIgnoredError?: (error: any) => void,
120
- ): IndexedDbPersister;
@@ -1,135 +0,0 @@
1
- /**
2
- * The persister-indexed-db module of the TinyBase project lets you save and
3
- * load Store data to and from browser IndexedDB storage.
4
- * @see Persistence guides
5
- * @packageDocumentation
6
- * @module persister-indexed-db
7
- * @since v4.2.0
8
- */
9
- import type {
10
- OptionalSchemas,
11
- Store,
12
- } from '../../../store/with-schemas/index.d.cts';
13
- import type {Persister} from '../../with-schemas/index.d.cts';
14
-
15
- /**
16
- * The IndexedDbPersister interface represents a Persister that lets you save
17
- * and load Store data to and from browser IndexedDB storage.
18
- *
19
- * You should use the createIndexedDbPersister function to create an
20
- * IndexedDbPersister object.
21
- *
22
- * It is a minor extension to the Persister interface and simply provides an
23
- * extra getDbName method for accessing the unique key of the IndexedDB the
24
- * Store is being persisted to.
25
- * @category Persister
26
- * @since v4.3.14
27
- */
28
- export interface IndexedDbPersister<Schemas extends OptionalSchemas>
29
- extends Persister<Schemas> {
30
- /**
31
- * The getDbName method returns the unique key of the IndexedDB the Store is
32
- * being persisted to.
33
- * @returns The unique key of the IndexedDB.
34
- * @example
35
- * This example creates a Persister object against a newly-created Store and
36
- * then gets the unique key of the IndexedDB back out again.
37
- *
38
- * ```js
39
- * import {createStore} from 'tinybase';
40
- * import {createIndexedDbPersister} from 'tinybase/persisters/persister-indexed-db';
41
- *
42
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
43
- * const persister = createIndexedDbPersister(store, 'petStore');
44
- *
45
- * console.log(persister.getDbName());
46
- * // -> 'petStore'
47
- *
48
- * persister.destroy();
49
- * ```
50
- * @category Getter
51
- * @since v4.3.14
52
- */
53
- getDbName(): string;
54
- }
55
-
56
- /**
57
- * The createIndexedDbPersister function creates an IndexedDbPersister object
58
- * that can persist a Store to the browser's IndexedDB storage.
59
- *
60
- * This has schema-based typing. The following is a simplified representation:
61
- *
62
- * ```ts override
63
- * createIndexedDbPersister(
64
- * store: Store,
65
- * dbName: string,
66
- * autoLoadIntervalSeconds?: number,
67
- * onIgnoredError?: (error: any) => void,
68
- * ): IndexedDbPersister;
69
- * ```
70
- *
71
- * An IndexedDbPersister only supports regular Store objects, and cannot be used
72
- * to persist the metadata of a MergeableStore.
73
- *
74
- * As well as providing a reference to the Store to persist, you must provide a
75
- * `dbName` parameter which is unique to your application. This is the key used
76
- * to identify which IndexedDB to use.
77
- *
78
- * Within that database, this Persister will create two object stores: one
79
- * called 't', and one called 'v'. These will contain the Store's tabular and
80
- * key-value data respectively, using 'k' and 'v' to store the key and value of
81
- * each entry, as shown in the example.
82
- *
83
- * Note that it is not possible to reactively detect changes to a browser's
84
- * IndexedDB. If you do choose to enable automatic loading for the Persister
85
- * (with the startAutoLoad method), it needs to poll the database for changes.
86
- * The `autoLoadIntervalSeconds` method is used to indicate how often to do
87
- * this.
88
- * @param store The Store to persist.
89
- * @param dbName The unique key to identify the IndexedDB to use.
90
- * @param autoLoadIntervalSeconds How often to poll the database when in
91
- * 'autoLoad' mode, defaulting to 1.
92
- * @param onIgnoredError An optional handler for the errors that the Persister
93
- * would otherwise ignore when trying to save or load data. This is suitable for
94
- * debugging persistence issues in a development environment.
95
- * @returns A reference to the new IndexedDbPersister object.
96
- * @example
97
- * This example creates a IndexedDbPersister object and persists the Store to
98
- * the browser's IndexedDB storage.
99
- *
100
- * ```js
101
- * import {createStore} from 'tinybase';
102
- * import {createIndexedDbPersister} from 'tinybase/persisters/persister-indexed-db';
103
- *
104
- * const store = createStore()
105
- * .setTable('pets', {fido: {species: 'dog'}})
106
- * .setTable('species', {dog: {price: 5}})
107
- * .setValues({open: true});
108
- * const persister = createIndexedDbPersister(store, 'petStore');
109
- *
110
- * await persister.save();
111
- * // IndexedDB ->
112
- * // database petStore:
113
- * // objectStore t:
114
- * // object 0:
115
- * // k: "pets"
116
- * // v: {fido: {species: dog}}
117
- * // object 1:
118
- * // k: "species"
119
- * // v: {dog: {price: 5}}
120
- * // objectStore v:
121
- * // object 0:
122
- * // k: "open"
123
- * // v: true
124
- *
125
- * persister.destroy();
126
- * ```
127
- * @category Creation
128
- * @since v4.2.0
129
- */
130
- export function createIndexedDbPersister<Schemas extends OptionalSchemas>(
131
- store: Store<Schemas>,
132
- dbName: string,
133
- autoLoadIntervalSeconds?: number,
134
- onIgnoredError?: (error: any) => void,
135
- ): IndexedDbPersister<Schemas>;
@@ -1,158 +0,0 @@
1
- /**
2
- * The persister-libsql module of the TinyBase project lets you save and load
3
- * Store data to and from a local LibSQL database (in an appropriate
4
- * environment).
5
- * @see Database Persistence guide
6
- * @packageDocumentation
7
- * @module persister-libsql
8
- * @since v4.7.0
9
- */
10
- import type {Client} from '@libsql/client';
11
- import type {Store} from '../../store/index.d.cts';
12
- import type {DatabasePersisterConfig, Persister} from '../index.d.cts';
13
-
14
- /**
15
- * The LibSqlPersister interface represents a Persister that lets you save and
16
- * load Store data to and from a local LibSQL database.
17
- *
18
- * You should use the createLibSqlPersister function to create a LibSqlPersister
19
- * object.
20
- *
21
- * It is a minor extension to the Persister interface and simply provides an
22
- * extra getClient method for accessing a reference to the database client the
23
- * Store is being persisted to.
24
- * @category Persister
25
- * @since v4.7.0
26
- */
27
- export interface LibSqlPersister extends Persister {
28
- /**
29
- * The getClient method returns a reference to the database client the Store
30
- * is being persisted to.
31
- * @returns A reference to the database client.
32
- * @example
33
- * This example creates a Persister object against a newly-created Store and
34
- * then gets the database client back out again.
35
- *
36
- * ```js yolo
37
- * import {createClient} from '@libsql/client';
38
- * import {createStore} from 'tinybase';
39
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
40
- *
41
- * const client = createClient({url: 'file:my.db'});
42
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
43
- * const persister = createLibSqlPersister(store, client, 'my_tinybase');
44
- *
45
- * console.log(persister.getClient() == client);
46
- * // -> true
47
- *
48
- * persister.destroy();
49
- * ```
50
- * @category Getter
51
- * @since v4.7.0
52
- */
53
- getClient(): Client;
54
- }
55
-
56
- /**
57
- * The createLibSqlPersister function creates a LibSqlPersister object that can
58
- * persist a Store to a local LibSQL database.
59
- *
60
- * A LibSqlPersister only supports regular Store objects, and cannot be used to
61
- * persist the metadata of a MergeableStore.
62
- *
63
- * As well as providing a reference to the Store to persist, you must provide a
64
- * `client` parameter which identifies the database client.
65
- *
66
- * A database Persister uses one of two modes: either a JSON serialization of
67
- * the whole Store stored in a single row of a table (the default), or a tabular
68
- * mapping of Table Ids to database table names and vice-versa).
69
- *
70
- * The third argument is a DatabasePersisterConfig object that configures which
71
- * of those modes to use, and settings for each. If the third argument is simply
72
- * a string, it is used as the `storeTableName` property of the JSON
73
- * serialization.
74
- *
75
- * See the documentation for the DpcJson and DpcTabular types for more
76
- * information on how both of those modes can be configured.
77
- * @param store The Store to persist.
78
- * @param client The database client that was returned from `createClient(...)`.
79
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
80
- * persistence mode (or a string to set the `storeTableName` property of the
81
- * JSON serialization).
82
- * @param onSqlCommand An optional handler called every time the Persister
83
- * executes a SQL command or query. This is suitable for logging persistence
84
- * behavior in a development environment.
85
- * @param onIgnoredError An optional handler for the errors that the Persister
86
- * would otherwise ignore when trying to save or load data. This is suitable for
87
- * debugging persistence issues in a development environment.
88
- * @returns A reference to the new LibSqlPersister object.
89
- * @example
90
- * This example creates a LibSqlPersister object and persists the Store to a
91
- * local SQLite database as a JSON serialization into the `my_tinybase` table.
92
- * It makes a change to the database directly and then reloads it back into the
93
- * Store.
94
- *
95
- * ```js yolo
96
- * import {createClient} from '@libsql/client';
97
- * import {createStore} from 'tinybase';
98
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
99
- *
100
- * const client = createClient({url: 'file:my.db'});
101
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
102
- * const persister = createLibSqlPersister(store, client, 'my_tinybase');
103
- *
104
- * await persister.save();
105
- * // Store will be saved to the database.
106
- *
107
- * console.log((await client.execute('SELECT * FROM my_tinybase;')).rows);
108
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
109
- *
110
- * await client.execute(
111
- * 'UPDATE my_tinybase SET store = ' +
112
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
113
- * );
114
- * await persister.load();
115
- * console.log(store.getTables());
116
- * // -> {pets: {felix: {species: 'cat'}}}
117
- *
118
- * persister.destroy();
119
- * ```
120
- * @example
121
- * This example creates a LibSqlPersister object and persists the Store to a
122
- * local SQLite database with tabular mapping.
123
- *
124
- * ```js yolo
125
- * import {createClient} from '@libsql/client';
126
- * import {createStore} from 'tinybase';
127
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
128
- *
129
- * const client = createClient({url: 'file:my.db'});
130
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
131
- * const persister = createLibSqlPersister(store, client, {
132
- * mode: 'tabular',
133
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
134
- * });
135
- *
136
- * await persister.save();
137
- * console.log((await client.execute('SELECT * FROM pets;')).rows);
138
- * // -> [{_id: 'fido', species: 'dog'}]
139
- *
140
- * await client.execute(
141
- * `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
142
- * );
143
- * await persister.load();
144
- * console.log(store.getTables());
145
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
146
- *
147
- * persister.destroy();
148
- * ```
149
- * @category Creation
150
- * @since v4.7.0
151
- */
152
- export function createLibSqlPersister(
153
- store: Store,
154
- client: Client,
155
- configOrStoreTableName?: DatabasePersisterConfig | string,
156
- onSqlCommand?: (sql: string, params?: any[]) => void,
157
- onIgnoredError?: (error: any) => void,
158
- ): LibSqlPersister;
@@ -1,177 +0,0 @@
1
- /**
2
- * The persister-libsql module of the TinyBase project lets you save and load
3
- * Store data to and from a local LibSQL database (in an appropriate
4
- * environment).
5
- * @see Database Persistence guide
6
- * @packageDocumentation
7
- * @module persister-libsql
8
- * @since v4.7.0
9
- */
10
- import type {Client} from '@libsql/client';
11
- import type {
12
- OptionalSchemas,
13
- Store,
14
- } from '../../../store/with-schemas/index.d.cts';
15
- import type {
16
- DatabasePersisterConfig,
17
- Persister,
18
- } from '../../with-schemas/index.d.cts';
19
-
20
- /**
21
- * The LibSqlPersister interface represents a Persister that lets you save and
22
- * load Store data to and from a local LibSQL database.
23
- *
24
- * You should use the createLibSqlPersister function to create a LibSqlPersister
25
- * object.
26
- *
27
- * It is a minor extension to the Persister interface and simply provides an
28
- * extra getClient method for accessing a reference to the database client the
29
- * Store is being persisted to.
30
- * @category Persister
31
- * @since v4.7.0
32
- */
33
- export interface LibSqlPersister<Schemas extends OptionalSchemas>
34
- extends Persister<Schemas> {
35
- /**
36
- * The getClient method returns a reference to the database client the Store
37
- * is being persisted to.
38
- * @returns A reference to the database client.
39
- * @example
40
- * This example creates a Persister object against a newly-created Store and
41
- * then gets the database client back out again.
42
- *
43
- * ```js yolo
44
- * import {createClient} from '@libsql/client';
45
- * import {createStore} from 'tinybase';
46
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
47
- *
48
- * const client = createClient({url: 'file:my.db'});
49
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
50
- * const persister = createLibSqlPersister(store, client, 'my_tinybase');
51
- *
52
- * console.log(persister.getClient() == client);
53
- * // -> true
54
- *
55
- * persister.destroy();
56
- * ```
57
- * @category Getter
58
- * @since v4.7.0
59
- */
60
- getClient(): Client;
61
- }
62
-
63
- /**
64
- * The createLibSqlPersister function creates a LibSqlPersister object that can
65
- * persist a Store to a local LibSQL database.
66
- *
67
- * This has schema-based typing. The following is a simplified representation:
68
- *
69
- * ```ts override
70
- * createLibSqlPersister(
71
- * store: Store,
72
- * client: Client,
73
- * configOrStoreTableName?: DatabasePersisterConfig | string,
74
- * onSqlCommand?: (sql: string, params?: any[]) => void,
75
- * onIgnoredError?: (error: any) => void,
76
- * ): LibSqlPersister;
77
- * ```
78
- *
79
- * A LibSqlPersister only supports regular Store objects, and cannot be used to
80
- * persist the metadata of a MergeableStore.
81
- *
82
- * As well as providing a reference to the Store to persist, you must provide a
83
- * `client` parameter which identifies the database client.
84
- *
85
- * A database Persister uses one of two modes: either a JSON serialization of
86
- * the whole Store stored in a single row of a table (the default), or a tabular
87
- * mapping of Table Ids to database table names and vice-versa).
88
- *
89
- * The third argument is a DatabasePersisterConfig object that configures which
90
- * of those modes to use, and settings for each. If the third argument is simply
91
- * a string, it is used as the `storeTableName` property of the JSON
92
- * serialization.
93
- *
94
- * See the documentation for the DpcJson and DpcTabular types for more
95
- * information on how both of those modes can be configured.
96
- * @param store The Store to persist.
97
- * @param client The database client that was returned from `createClient(...)`.
98
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
99
- * persistence mode (or a string to set the `storeTableName` property of the
100
- * JSON serialization).
101
- * @param onSqlCommand An optional handler called every time the Persister
102
- * executes a SQL command or query. This is suitable for logging persistence
103
- * behavior in a development environment.
104
- * @param onIgnoredError An optional handler for the errors that the Persister
105
- * would otherwise ignore when trying to save or load data. This is suitable for
106
- * debugging persistence issues in a development environment.
107
- * @returns A reference to the new LibSqlPersister object.
108
- * @example
109
- * This example creates a LibSqlPersister object and persists the Store to a
110
- * local SQLite database as a JSON serialization into the `my_tinybase` table.
111
- * It makes a change to the database directly and then reloads it back into the
112
- * Store.
113
- *
114
- * ```js yolo
115
- * import {createClient} from '@libsql/client';
116
- * import {createStore} from 'tinybase';
117
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
118
- *
119
- * const client = createClient({url: 'file:my.db'});
120
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
121
- * const persister = createLibSqlPersister(store, client, 'my_tinybase');
122
- *
123
- * await persister.save();
124
- * // Store will be saved to the database.
125
- *
126
- * console.log((await client.execute('SELECT * FROM my_tinybase;')).rows);
127
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
128
- *
129
- * await client.execute(
130
- * 'UPDATE my_tinybase SET store = ' +
131
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
132
- * );
133
- * await persister.load();
134
- * console.log(store.getTables());
135
- * // -> {pets: {felix: {species: 'cat'}}}
136
- *
137
- * persister.destroy();
138
- * ```
139
- * @example
140
- * This example creates a LibSqlPersister object and persists the Store to a
141
- * local SQLite database with tabular mapping.
142
- *
143
- * ```js yolo
144
- * import {createClient} from '@libsql/client';
145
- * import {createStore} from 'tinybase';
146
- * import {createLibSqlPersister} from 'tinybase/persisters/persister-libsql';
147
- *
148
- * const client = createClient({url: 'file:my.db'});
149
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
150
- * const persister = createLibSqlPersister(store, client, {
151
- * mode: 'tabular',
152
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
153
- * });
154
- *
155
- * await persister.save();
156
- * console.log((await client.execute('SELECT * FROM pets;')).rows);
157
- * // -> [{_id: 'fido', species: 'dog'}]
158
- *
159
- * await client.execute(
160
- * `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
161
- * );
162
- * await persister.load();
163
- * console.log(store.getTables());
164
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
165
- *
166
- * persister.destroy();
167
- * ```
168
- * @category Creation
169
- * @since v4.7.0
170
- */
171
- export function createLibSqlPersister<Schemas extends OptionalSchemas>(
172
- store: Store<Schemas>,
173
- client: Client,
174
- configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
175
- onSqlCommand?: (sql: string, params?: any[]) => void,
176
- onIgnoredError?: (error: any) => void,
177
- ): LibSqlPersister<Schemas>;