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,186 +0,0 @@
1
- /**
2
- * The persister-expo-sqlite module of the TinyBase project lets you save and
3
- * load Store data to and from a Expo-SQLite database (in an appropriate React
4
- * Native environment).
5
- *
6
- * As of TinyBase v5.0, this module provides a Persister for the modern version
7
- * of Expo's [SQLite](https://docs.expo.dev/versions/latest/sdk/sqlite) library,
8
- * designated 'next' as of November 2023 and default as v14.0 by June 2024.
9
- *
10
- * Note that TinyBase support for the legacy version of Expo-SQLite is no longer
11
- * available.
12
- * @see Database Persistence guide
13
- * @packageDocumentation
14
- * @module persister-expo-sqlite
15
- * @since v4.5.0
16
- */
17
- import type {SQLiteDatabase} from 'expo-sqlite';
18
- import type {MergeableStore} from '../../mergeable-store/index.d.cts';
19
- import type {Store} from '../../store/index.d.cts';
20
- import type {DatabasePersisterConfig, Persister, Persists} from '../index.d.cts';
21
-
22
- /**
23
- * The ExpoSqlitePersister interface represents a Persister that lets you save
24
- * and load Store data to and from a Expo-SQLite database.
25
- *
26
- * You should use the createExpoSqlitePersister function to create an
27
- * ExpoSqlitePersister object.
28
- *
29
- * It is a minor extension to the Persister interface and simply provides an
30
- * extra getDb method for accessing a reference to the database instance the
31
- * Store is being persisted to.
32
- * @category Persister
33
- * @since v4.5.0
34
- */
35
- export interface ExpoSqlitePersister
36
- extends Persister<Persists.StoreOrMergeableStore> {
37
- /**
38
- * The getDb method returns a reference to the database instance the Store is
39
- * being persisted to.
40
- * @returns A reference to the database instance.
41
- * @example
42
- * This example creates a Persister object against a newly-created Store and
43
- * then gets the database instance back out again.
44
- *
45
- * ```js yolo
46
- * import {openDatabaseSync} from 'expo-sqlite';
47
- * import {createStore} from 'tinybase';
48
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
49
- *
50
- * const db = openDatabaseSync('my.db');
51
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
52
- * const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
53
- *
54
- * console.log(persister.getDb() == db);
55
- * // -> true
56
- *
57
- * persister.destroy();
58
- * ```
59
- * @category Getter
60
- * @since v4.5.0
61
- */
62
- getDb(): SQLiteDatabase;
63
- }
64
-
65
- /**
66
- * The createExpoSqlitePersister function creates an ExpoSqlitePersister object
67
- * that can persist the Store to a local Expo-SQLite database.
68
- *
69
- * An ExpoSqlitePersister supports regular Store objects, and can also be used
70
- * to persist the metadata of a MergeableStore when using the JSON serialization
71
- * mode, as described below.
72
- *
73
- * Note that this Persister is currently experimental as Expo themselves iterate
74
- * on the underlying database library API.
75
- *
76
- * As well as providing a reference to the Store to persist, you must provide a
77
- * `db` parameter which identifies the database instance.
78
- *
79
- * A database Persister uses one of two modes: either a JSON serialization of
80
- * the whole Store stored in a single row of a table (the default), or a tabular
81
- * mapping of Table Ids to database table names and vice-versa).
82
- *
83
- * The third argument is a DatabasePersisterConfig object that configures which
84
- * of those modes to use, and settings for each. If the third argument is simply
85
- * a string, it is used as the `storeTableName` property of the JSON
86
- * serialization.
87
- *
88
- * See the documentation for the DpcJson and DpcTabular types for more
89
- * information on how both of those modes can be configured.
90
- * @param store The Store or MergeableStore to persist.
91
- * @param db The database instance that was returned from
92
- * `SQLite.openDatabase(...)`.
93
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
94
- * persistence mode (or a string to set the `storeTableName` property of the
95
- * JSON serialization).
96
- * @param onSqlCommand An optional handler called every time the Persister
97
- * executes a SQL command or query. This is suitable for logging persistence
98
- * behavior in a development environment.
99
- * @param onIgnoredError An optional handler for the errors that the Persister
100
- * would otherwise ignore when trying to save or load data. This is suitable for
101
- * debugging persistence issues in a development environment.
102
- * @returns A reference to the new ExpoSqlitePersister object.
103
- * @example
104
- * This example creates a ExpoSqlitePersister object and persists the Store
105
- * to a local SQLite database as a JSON serialization into the `my_tinybase`
106
- * table. It makes a change to the database directly and then reloads it back
107
- * into the Store.
108
- *
109
- * ```js yolo
110
- * import {openDatabaseSync} from 'expo-sqlite';
111
- * import {createStore} from 'tinybase';
112
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
113
- *
114
- * const db = openDatabaseSync('my.db');
115
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
116
- * const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
117
- *
118
- * await persister.save();
119
- * // Store will be saved to the database.
120
- *
121
- * console.log(
122
- * await new Promise((resolve) =>
123
- * db.allAsync('SELECT * FROM my_tinybase;').then(resolve),
124
- * ),
125
- * );
126
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
127
- *
128
- * await new Promise((resolve) =>
129
- * db
130
- * .allAsync(
131
- * 'UPDATE my_tinybase SET store = ' +
132
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
133
- * )
134
- * .then(resolve),
135
- * );
136
- * await persister.load();
137
- * console.log(store.getTables());
138
- * // -> {pets: {felix: {species: 'cat'}}}
139
- *
140
- * persister.destroy();
141
- * ```
142
- * @example
143
- * This example creates a ExpoSqlitePersister object and persists the Store
144
- * to a local SQLite database with tabular mapping.
145
- *
146
- * ```js yolo
147
- * import {openDatabaseSync} from 'expo-sqlite';
148
- * import {createStore} from 'tinybase';
149
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
150
- *
151
- * const db = openDatabaseSync('my.db');
152
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
153
- * const persister = createExpoSqlitePersister(store, db, {
154
- * mode: 'tabular',
155
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
156
- * });
157
- *
158
- * await persister.save();
159
- * console.log(
160
- * await new Promise((resolve) =>
161
- * db.allAsync('SELECT * FROM pets;').then(resolve),
162
- * ),
163
- * );
164
- * // -> [{_id: 'fido', species: 'dog'}]
165
- *
166
- * await new Promise((resolve) =>
167
- * db
168
- * .allAsync(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`)
169
- * .then(resolve),
170
- * );
171
- * await persister.load();
172
- * console.log(store.getTables());
173
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
174
- *
175
- * persister.destroy();
176
- * ```
177
- * @category Creation
178
- * @since v4.5.0
179
- */
180
- export function createExpoSqlitePersister(
181
- store: Store | MergeableStore,
182
- db: SQLiteDatabase,
183
- configOrStoreTableName?: DatabasePersisterConfig | string,
184
- onSqlCommand?: (sql: string, params?: any[]) => void,
185
- onIgnoredError?: (error: any) => void,
186
- ): ExpoSqlitePersister;
@@ -1,205 +0,0 @@
1
- /**
2
- * The persister-expo-sqlite module of the TinyBase project lets you save and
3
- * load Store data to and from a Expo-SQLite database (in an appropriate React
4
- * Native environment).
5
- *
6
- * As of TinyBase v5.0, this module provides a Persister for the modern version
7
- * of Expo's [SQLite](https://docs.expo.dev/versions/latest/sdk/sqlite) library,
8
- * designated 'next' as of November 2023 and default as v14.0 by June 2024.
9
- *
10
- * Note that TinyBase support for the legacy version of Expo-SQLite is no longer
11
- * available.
12
- * @see Database Persistence guide
13
- * @packageDocumentation
14
- * @module persister-expo-sqlite
15
- * @since v4.5.0
16
- */
17
- import type {SQLiteDatabase} from 'expo-sqlite';
18
- import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.cts';
19
- import type {
20
- OptionalSchemas,
21
- Store,
22
- } from '../../../store/with-schemas/index.d.cts';
23
- import type {
24
- DatabasePersisterConfig,
25
- Persister,
26
- Persists,
27
- } from '../../with-schemas/index.d.cts';
28
-
29
- /**
30
- * The ExpoSqlitePersister interface represents a Persister that lets you save
31
- * and load Store data to and from a Expo-SQLite database.
32
- *
33
- * You should use the createExpoSqlitePersister function to create an
34
- * ExpoSqlitePersister object.
35
- *
36
- * It is a minor extension to the Persister interface and simply provides an
37
- * extra getDb method for accessing a reference to the database instance the
38
- * Store is being persisted to.
39
- * @category Persister
40
- * @since v4.5.0
41
- */
42
- export interface ExpoSqlitePersister<Schemas extends OptionalSchemas>
43
- extends Persister<Schemas, Persists.StoreOrMergeableStore> {
44
- /**
45
- * The getDb method returns a reference to the database instance the Store is
46
- * being persisted to.
47
- * @returns A reference to the database instance.
48
- * @example
49
- * This example creates a Persister object against a newly-created Store and
50
- * then gets the database instance back out again.
51
- *
52
- * ```js yolo
53
- * import {openDatabaseSync} from 'expo-sqlite';
54
- * import {createStore} from 'tinybase';
55
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
56
- *
57
- * const db = openDatabaseSync('my.db');
58
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
59
- * const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
60
- *
61
- * console.log(persister.getDb() == db);
62
- * // -> true
63
- *
64
- * persister.destroy();
65
- * ```
66
- * @category Getter
67
- * @since v4.5.0
68
- */
69
- getDb(): SQLiteDatabase;
70
- }
71
-
72
- /**
73
- * The createExpoSqlitePersister function creates an ExpoSqlitePersister object
74
- * that can persist the Store to a local Expo-SQLite database.
75
- *
76
- * This has schema-based typing. The following is a simplified representation:
77
- *
78
- * ```ts override
79
- * createExpoSqlitePersister(
80
- * store: Store | MergeableStore,
81
- * db: SQLiteDatabase,
82
- * configOrStoreTableName?: DatabasePersisterConfig | string,
83
- * onSqlCommand?: (sql: string, params?: any[]) => void,
84
- * onIgnoredError?: (error: any) => void,
85
- * ): ExpoSqlitePersister;
86
- * ```
87
- *
88
- * An ExpoSqlitePersister supports regular Store objects, and can also be used
89
- * to persist the metadata of a MergeableStore when using the JSON serialization
90
- * mode, as described below.
91
- *
92
- * Note that this Persister is currently experimental as Expo themselves iterate
93
- * on the underlying database library API.
94
- *
95
- * As well as providing a reference to the Store to persist, you must provide a
96
- * `db` parameter which identifies the database instance.
97
- *
98
- * A database Persister uses one of two modes: either a JSON serialization of
99
- * the whole Store stored in a single row of a table (the default), or a tabular
100
- * mapping of Table Ids to database table names and vice-versa).
101
- *
102
- * The third argument is a DatabasePersisterConfig object that configures which
103
- * of those modes to use, and settings for each. If the third argument is simply
104
- * a string, it is used as the `storeTableName` property of the JSON
105
- * serialization.
106
- *
107
- * See the documentation for the DpcJson and DpcTabular types for more
108
- * information on how both of those modes can be configured.
109
- * @param store The Store or MergeableStore to persist.
110
- * @param db The database instance that was returned from
111
- * `SQLite.openDatabase(...)`.
112
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
113
- * persistence mode (or a string to set the `storeTableName` property of the
114
- * JSON serialization).
115
- * @param onSqlCommand An optional handler called every time the Persister
116
- * executes a SQL command or query. This is suitable for logging persistence
117
- * behavior in a development environment.
118
- * @param onIgnoredError An optional handler for the errors that the Persister
119
- * would otherwise ignore when trying to save or load data. This is suitable for
120
- * debugging persistence issues in a development environment.
121
- * @returns A reference to the new ExpoSqlitePersister object.
122
- * @example
123
- * This example creates a ExpoSqlitePersister object and persists the Store
124
- * to a local SQLite database as a JSON serialization into the `my_tinybase`
125
- * table. It makes a change to the database directly and then reloads it back
126
- * into the Store.
127
- *
128
- * ```js yolo
129
- * import {openDatabaseSync} from 'expo-sqlite';
130
- * import {createStore} from 'tinybase';
131
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
132
- *
133
- * const db = openDatabaseSync('my.db');
134
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
135
- * const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
136
- *
137
- * await persister.save();
138
- * // Store will be saved to the database.
139
- *
140
- * console.log(
141
- * await new Promise((resolve) =>
142
- * db.allAsync('SELECT * FROM my_tinybase;').then(resolve),
143
- * ),
144
- * );
145
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
146
- *
147
- * await new Promise((resolve) =>
148
- * db
149
- * .allAsync(
150
- * 'UPDATE my_tinybase SET store = ' +
151
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
152
- * )
153
- * .then(resolve),
154
- * );
155
- * await persister.load();
156
- * console.log(store.getTables());
157
- * // -> {pets: {felix: {species: 'cat'}}}
158
- *
159
- * persister.destroy();
160
- * ```
161
- * @example
162
- * This example creates a ExpoSqlitePersister object and persists the Store
163
- * to a local SQLite database with tabular mapping.
164
- *
165
- * ```js yolo
166
- * import {openDatabaseSync} from 'expo-sqlite';
167
- * import {createStore} from 'tinybase';
168
- * import {createExpoSqlitePersister} from 'tinybase/persisters/persister-expo-sqlite';
169
- *
170
- * const db = openDatabaseSync('my.db');
171
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
172
- * const persister = createExpoSqlitePersister(store, db, {
173
- * mode: 'tabular',
174
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
175
- * });
176
- *
177
- * await persister.save();
178
- * console.log(
179
- * await new Promise((resolve) =>
180
- * db.allAsync('SELECT * FROM pets;').then(resolve),
181
- * ),
182
- * );
183
- * // -> [{_id: 'fido', species: 'dog'}]
184
- *
185
- * await new Promise((resolve) =>
186
- * db
187
- * .allAsync(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`)
188
- * .then(resolve),
189
- * );
190
- * await persister.load();
191
- * console.log(store.getTables());
192
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
193
- *
194
- * persister.destroy();
195
- * ```
196
- * @category Creation
197
- * @since v4.5.0
198
- */
199
- export function createExpoSqlitePersister<Schemas extends OptionalSchemas>(
200
- store: Store<Schemas> | MergeableStore<Schemas>,
201
- db: SQLiteDatabase,
202
- configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
203
- onSqlCommand?: (sql: string, params?: any[]) => void,
204
- onIgnoredError?: (error: any) => void,
205
- ): ExpoSqlitePersister<Schemas>;
@@ -1,94 +0,0 @@
1
- /**
2
- * The persister-file module of the TinyBase project lets you save and load
3
- * Store data to and from a local file system (in an appropriate environment).
4
- * @see Persistence guides
5
- * @packageDocumentation
6
- * @module persister-file
7
- * @since v1.0.0
8
- */
9
- import type {MergeableStore} from '../../mergeable-store/index.d.cts';
10
- import type {Store} from '../../store/index.d.cts';
11
- import type {Persister, Persists} from '../index.d.cts';
12
-
13
- /**
14
- * The FilePersister interface represents a Persister that lets you save and
15
- * load Store data to and from a local file system.
16
- *
17
- * You should use the createFilePersister function to create a FilePersister
18
- * object.
19
- *
20
- * It is a minor extension to the Persister interface and simply provides an
21
- * extra getFilePath method for accessing the location of the local file the
22
- * Store is being persisted to.
23
- * @category Persister
24
- * @since v4.3.14
25
- */
26
- export interface FilePersister
27
- extends Persister<Persists.StoreOrMergeableStore> {
28
- /**
29
- * The getFilePath method returns the location of the local file the Store is
30
- * being persisted to.
31
- * @returns The location of the local file.
32
- * @example
33
- * This example creates a Persister object against a newly-created Store and
34
- * then gets the file location back out again.
35
- *
36
- * ```js
37
- * import {createStore} from 'tinybase';
38
- * import {createFilePersister} from 'tinybase/persisters/persister-file';
39
- *
40
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
41
- * const persister = createFilePersister(store, '/app/persisted.json');
42
- *
43
- * console.log(persister.getFilePath());
44
- * // -> '/app/persisted.json'
45
- *
46
- * persister.destroy();
47
- * ```
48
- * @category Getter
49
- * @since v4.3.14
50
- */
51
- getFilePath(): string;
52
- }
53
-
54
- /**
55
- * The createFilePersister function creates a FilePersister object that can
56
- * persist the Store to a local file.
57
- *
58
- * A FilePersister supports both regular Store and MergeableStore objects.
59
- *
60
- * As well as providing a reference to the Store to persist, you must provide a
61
- * `filePath` parameter which identifies the file to persist it to.
62
- * @param store The Store or MergeableStore to persist.
63
- * @param filePath The location of the local file to persist the Store to.
64
- * @param onIgnoredError An optional handler for the errors that the Persister
65
- * would otherwise ignore when trying to save or load data. This is suitable for
66
- * debugging persistence issues in a development environment, since v4.0.4.
67
- * @returns A reference to the new FilePersister object.
68
- * @example
69
- * This example creates a FilePersister object and persists the Store to a local
70
- * file.
71
- *
72
- * ```js yolo
73
- * import {createStore} from 'tinybase';
74
- * import {createFilePersister} from 'tinybase/persisters/persister-file';
75
- *
76
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
77
- * const persister = createFilePersister(store, '/app/persisted.json');
78
- *
79
- * await persister.save();
80
- * // Store JSON will be saved to the file.
81
- *
82
- * await persister.load();
83
- * // Store JSON will be loaded from the file.
84
- *
85
- * persister.destroy();
86
- * ```
87
- * @category Creation
88
- * @since v1.0.0
89
- */
90
- export function createFilePersister(
91
- store: Store | MergeableStore,
92
- filePath: string,
93
- onIgnoredError?: (error: any) => void,
94
- ): FilePersister;
@@ -1,107 +0,0 @@
1
- /**
2
- * The persister-file module of the TinyBase project lets you save and load
3
- * Store data to and from a local file system (in an appropriate environment).
4
- * @see Persistence guides
5
- * @packageDocumentation
6
- * @module persister-file
7
- * @since v1.0.0
8
- */
9
- import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.cts';
10
- import type {
11
- OptionalSchemas,
12
- Store,
13
- } from '../../../store/with-schemas/index.d.cts';
14
- import type {Persister, Persists} from '../../with-schemas/index.d.cts';
15
-
16
- /**
17
- * The FilePersister interface represents a Persister that lets you save and
18
- * load Store data to and from a local file system.
19
- *
20
- * You should use the createFilePersister function to create a FilePersister
21
- * object.
22
- *
23
- * It is a minor extension to the Persister interface and simply provides an
24
- * extra getFilePath method for accessing the location of the local file the
25
- * Store is being persisted to.
26
- * @category Persister
27
- * @since v4.3.14
28
- */
29
- export interface FilePersister<Schemas extends OptionalSchemas>
30
- extends Persister<Schemas, Persists.StoreOrMergeableStore> {
31
- /**
32
- * The getFilePath method returns the location of the local file the Store is
33
- * being persisted to.
34
- * @returns The location of the local file.
35
- * @example
36
- * This example creates a Persister object against a newly-created Store and
37
- * then gets the file location back out again.
38
- *
39
- * ```js
40
- * import {createStore} from 'tinybase';
41
- * import {createFilePersister} from 'tinybase/persisters/persister-file';
42
- *
43
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
44
- * const persister = createFilePersister(store, '/app/persisted.json');
45
- *
46
- * console.log(persister.getFilePath());
47
- * // -> '/app/persisted.json'
48
- *
49
- * persister.destroy();
50
- * ```
51
- * @category Getter
52
- * @since v4.3.14
53
- */
54
- getFilePath(): string;
55
- }
56
-
57
- /**
58
- * The createFilePersister function creates a FilePersister object that can
59
- * persist the Store to a local file.
60
- *
61
- * This has schema-based typing. The following is a simplified representation:
62
- *
63
- * ```ts override
64
- * createFilePersister(
65
- * store: Store | MergeableStore,
66
- * filePath: string,
67
- * onIgnoredError?: (error: any) => void,
68
- * ): FilePersister;
69
- * ```
70
- *
71
- * A FilePersister supports both regular Store and MergeableStore objects.
72
- *
73
- * As well as providing a reference to the Store to persist, you must provide a
74
- * `filePath` parameter which identifies the file to persist it to.
75
- * @param store The Store or MergeableStore to persist.
76
- * @param filePath The location of the local file to persist the Store to.
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, since v4.0.4.
80
- * @returns A reference to the new FilePersister object.
81
- * @example
82
- * This example creates a FilePersister object and persists the Store to a local
83
- * file.
84
- *
85
- * ```js yolo
86
- * import {createStore} from 'tinybase';
87
- * import {createFilePersister} from 'tinybase/persisters/persister-file';
88
- *
89
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
90
- * const persister = createFilePersister(store, '/app/persisted.json');
91
- *
92
- * await persister.save();
93
- * // Store JSON will be saved to the file.
94
- *
95
- * await persister.load();
96
- * // Store JSON will be loaded from the file.
97
- *
98
- * persister.destroy();
99
- * ```
100
- * @category Creation
101
- * @since v1.0.0
102
- */
103
- export function createFilePersister<Schemas extends OptionalSchemas>(
104
- store: Store<Schemas> | MergeableStore<Schemas>,
105
- filePath: string,
106
- onIgnoredError?: (error: any) => void,
107
- ): FilePersister<Schemas>;