tinybase 4.0.2 → 4.0.4
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/lib/cjs/persisters/persister-automerge.cjs +1 -1
- package/lib/cjs/persisters/persister-automerge.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-browser.cjs +1 -1
- package/lib/cjs/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-expo-sqlite.cjs +1 -0
- package/lib/cjs/persisters/persister-expo-sqlite.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-file.cjs +1 -1
- package/lib/cjs/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-remote.cjs +1 -1
- package/lib/cjs/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs/persisters.cjs +1 -1
- package/lib/cjs/persisters.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-automerge.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-automerge.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-browser.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs +1 -0
- package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-file.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-remote.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-yjs.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-yjs.cjs.gz +0 -0
- package/lib/cjs-es6/persisters.cjs +1 -1
- package/lib/cjs-es6/persisters.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/debug/persisters/persister-automerge.js +56 -18
- package/lib/debug/persisters/persister-browser.js +55 -22
- package/lib/debug/persisters/persister-cr-sqlite-wasm.js +106 -62
- package/lib/debug/persisters/persister-expo-sqlite.js +813 -0
- package/lib/debug/persisters/persister-file.js +51 -18
- package/lib/debug/persisters/persister-remote.js +51 -17
- package/lib/debug/persisters/persister-sqlite-wasm.js +106 -62
- package/lib/debug/persisters/persister-sqlite3.js +113 -64
- package/lib/debug/persisters/persister-yjs.js +63 -27
- package/lib/debug/persisters.js +49 -17
- package/lib/debug/tinybase.js +35 -17
- package/lib/es6/persisters/persister-automerge.js +1 -1
- package/lib/es6/persisters/persister-automerge.js.gz +0 -0
- package/lib/es6/persisters/persister-browser.js +1 -1
- package/lib/es6/persisters/persister-browser.js.gz +0 -0
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-expo-sqlite.js +1 -0
- package/lib/es6/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/es6/persisters/persister-file.js +1 -1
- package/lib/es6/persisters/persister-file.js.gz +0 -0
- package/lib/es6/persisters/persister-remote.js +1 -1
- package/lib/es6/persisters/persister-remote.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite3.js +1 -1
- package/lib/es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/es6/persisters/persister-yjs.js +1 -1
- package/lib/es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/persisters/persister-automerge.js +1 -1
- package/lib/persisters/persister-automerge.js.gz +0 -0
- package/lib/persisters/persister-browser.js +1 -1
- package/lib/persisters/persister-browser.js.gz +0 -0
- package/lib/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-expo-sqlite.js +1 -0
- package/lib/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/persisters/persister-file.js +1 -1
- package/lib/persisters/persister-file.js.gz +0 -0
- package/lib/persisters/persister-remote.js +1 -1
- package/lib/persisters/persister-remote.js.gz +0 -0
- package/lib/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-sqlite3.js +1 -1
- package/lib/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/persisters/persister-yjs.js +1 -1
- package/lib/persisters/persister-yjs.js.gz +0 -0
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/types/persisters/persister-automerge.d.ts +4 -0
- package/lib/types/persisters/persister-browser.d.ts +8 -0
- package/lib/types/persisters/persister-cr-sqlite-wasm.d.ts +10 -2
- package/lib/types/persisters/persister-expo-sqlite.d.ts +126 -0
- package/lib/types/persisters/persister-file.d.ts +8 -1
- package/lib/types/persisters/persister-remote.d.ts +4 -0
- package/lib/types/persisters/persister-sqlite-wasm.d.ts +8 -0
- package/lib/types/persisters/persister-sqlite3.d.ts +8 -0
- package/lib/types/persisters/persister-yjs.d.ts +4 -0
- package/lib/types/persisters.d.ts +16 -3
- package/lib/types/with-schemas/persisters/persister-automerge.d.ts +5 -0
- package/lib/types/with-schemas/persisters/persister-browser.d.ts +10 -0
- package/lib/types/with-schemas/persisters/persister-cr-sqlite-wasm.d.ts +12 -2
- package/lib/types/with-schemas/persisters/persister-expo-sqlite.d.ts +138 -0
- package/lib/types/with-schemas/persisters/persister-file.d.ts +9 -1
- package/lib/types/with-schemas/persisters/persister-remote.d.ts +5 -0
- package/lib/types/with-schemas/persisters/persister-sqlite-wasm.d.ts +10 -0
- package/lib/types/with-schemas/persisters/persister-sqlite3.d.ts +10 -0
- package/lib/types/with-schemas/persisters/persister-yjs.d.ts +5 -0
- package/lib/types/with-schemas/persisters.d.ts +17 -3
- package/lib/umd/persisters/persister-automerge.js +1 -1
- package/lib/umd/persisters/persister-automerge.js.gz +0 -0
- package/lib/umd/persisters/persister-browser.js +1 -1
- package/lib/umd/persisters/persister-browser.js.gz +0 -0
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-expo-sqlite.js +1 -0
- package/lib/umd/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/umd/persisters/persister-file.js +1 -1
- package/lib/umd/persisters/persister-file.js.gz +0 -0
- package/lib/umd/persisters/persister-remote.js +1 -1
- package/lib/umd/persisters/persister-remote.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite3.js +1 -1
- package/lib/umd/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd/persisters/persister-yjs.js +1 -1
- package/lib/umd/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-automerge.js +1 -1
- package/lib/umd-es6/persisters/persister-automerge.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-browser.js +1 -1
- package/lib/umd-es6/persisters/persister-browser.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-expo-sqlite.js +1 -0
- package/lib/umd-es6/persisters/persister-expo-sqlite.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-file.js +1 -1
- package/lib/umd-es6/persisters/persister-file.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-remote.js +1 -1
- package/lib/umd-es6/persisters/persister-remote.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite3.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-yjs.js +1 -1
- package/lib/umd-es6/persisters/persister-yjs.js.gz +0 -0
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/package.json +6 -5
- package/readme.md +2 -2
|
@@ -26,6 +26,9 @@ import {Store} from '../store';
|
|
|
26
26
|
* that the browser uses to identify the storage location.
|
|
27
27
|
* @param store The Store to persist.
|
|
28
28
|
* @param storageName The unique key to identify the storage location.
|
|
29
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
30
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
31
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
29
32
|
* @returns A reference to the new Persister object.
|
|
30
33
|
* @example
|
|
31
34
|
* This example creates a Persister object and persists the Store to the
|
|
@@ -47,6 +50,7 @@ import {Store} from '../store';
|
|
|
47
50
|
export function createSessionPersister(
|
|
48
51
|
store: Store,
|
|
49
52
|
storageName: string,
|
|
53
|
+
onIgnoredError?: (error: any) => void,
|
|
50
54
|
): Persister;
|
|
51
55
|
|
|
52
56
|
/**
|
|
@@ -58,6 +62,9 @@ export function createSessionPersister(
|
|
|
58
62
|
* that the browser uses to identify the storage location.
|
|
59
63
|
* @param store The Store to persist.
|
|
60
64
|
* @param storageName The unique key to identify the storage location.
|
|
65
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
66
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
67
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
61
68
|
* @returns A reference to the new Persister object.
|
|
62
69
|
* @example
|
|
63
70
|
* This example creates a Persister object and persists the Store to the
|
|
@@ -79,4 +86,5 @@ export function createSessionPersister(
|
|
|
79
86
|
export function createLocalPersister(
|
|
80
87
|
store: Store,
|
|
81
88
|
storageName: string,
|
|
89
|
+
onIgnoredError?: (error: any) => void,
|
|
82
90
|
): Persister;
|
|
@@ -16,8 +16,8 @@ import {Store} from '../store';
|
|
|
16
16
|
* persist the Store to a local CR-SQLite database (in an appropriate
|
|
17
17
|
* environment).
|
|
18
18
|
*
|
|
19
|
-
* As well as providing a reference to the Store to persist, you must provide
|
|
20
|
-
*
|
|
19
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
20
|
+
* `db` parameter which identifies the database instance.
|
|
21
21
|
*
|
|
22
22
|
* A database Persister uses one of two modes: either a JSON serialization of
|
|
23
23
|
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
@@ -35,6 +35,12 @@ import {Store} from '../store';
|
|
|
35
35
|
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
36
36
|
* persistence mode (or a string to set the `storeTableName` property of the
|
|
37
37
|
* JSON serialization).
|
|
38
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
39
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
40
|
+
* behavior in a development environment, since v4.0.4.
|
|
41
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
42
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
43
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
38
44
|
* @returns A reference to the new Persister object.
|
|
39
45
|
* @example
|
|
40
46
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -94,4 +100,6 @@ export function createCrSqliteWasmPersister(
|
|
|
94
100
|
store: Store,
|
|
95
101
|
db: DB,
|
|
96
102
|
configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
103
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
104
|
+
onIgnoredError?: (error: any) => void,
|
|
97
105
|
): Persister;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-expo-sqlite module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from a local Expo-SQLite database (in an appropriate
|
|
4
|
+
* React Native environment).
|
|
5
|
+
*
|
|
6
|
+
* Note that this Persister is currently experimental as Expo themselves iterate
|
|
7
|
+
* on the underlying database library API.
|
|
8
|
+
* @see Persisting Data guide
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
* @module persister-expo-sqlite
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {DatabasePersisterConfig, Persister} from '../persisters';
|
|
14
|
+
import {SQLiteDatabase} from 'expo-sqlite';
|
|
15
|
+
import {Store} from '../store';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The createExpoSqlitePersister function creates a Persister object that can
|
|
19
|
+
* persist the Store to a local Expo-SQLite database (in an appropriate React
|
|
20
|
+
* Native environment).
|
|
21
|
+
*
|
|
22
|
+
* Note that this Persister is currently experimental as Expo themselves iterate
|
|
23
|
+
* on the underlying database library API.
|
|
24
|
+
*
|
|
25
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
26
|
+
* `db` parameter which identifies the database instance.
|
|
27
|
+
*
|
|
28
|
+
* A database Persister uses one of two modes: either a JSON serialization of
|
|
29
|
+
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
30
|
+
* mapping of Table Ids to database table names and vice-versa).
|
|
31
|
+
*
|
|
32
|
+
* The third argument is a DatabasePersisterConfig object that configures which
|
|
33
|
+
* of those modes to use, and settings for each. If the third argument is simply
|
|
34
|
+
* a string, it is used as the `storeTableName` property of the JSON
|
|
35
|
+
* serialization.
|
|
36
|
+
*
|
|
37
|
+
* See the documentation for the DpcJson and DpcTabular types for more
|
|
38
|
+
* information on how both of those modes can be configured.
|
|
39
|
+
* @param store The Store to persist.
|
|
40
|
+
* @param db The database instance that was returned from
|
|
41
|
+
* `SQLite.openDatabase(...)`.
|
|
42
|
+
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
43
|
+
* persistence mode (or a string to set the `storeTableName` property of the
|
|
44
|
+
* JSON serialization).
|
|
45
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
46
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
47
|
+
* behavior in a development environment, since v4.0.4.
|
|
48
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
49
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
50
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
51
|
+
* @returns A reference to the new Persister object.
|
|
52
|
+
* @example
|
|
53
|
+
* This example creates a Persister object and persists the Store to a local
|
|
54
|
+
* SQLite database as a JSON serialization into the `my_tinybase` table. It
|
|
55
|
+
* makes a change to the database directly and then reloads it back into the
|
|
56
|
+
* Store.
|
|
57
|
+
*
|
|
58
|
+
* ```js yolo
|
|
59
|
+
* const db = SQLite.openDatabase('my.db');
|
|
60
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
61
|
+
* const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
|
|
62
|
+
*
|
|
63
|
+
* await persister.save();
|
|
64
|
+
* // Store will be saved to the database.
|
|
65
|
+
*
|
|
66
|
+
* console.log(
|
|
67
|
+
* await new Promise((resolve) =>
|
|
68
|
+
* db.all('SELECT * FROM my_tinybase;', (_, rows) => resolve(rows)),
|
|
69
|
+
* ),
|
|
70
|
+
* );
|
|
71
|
+
* // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
|
|
72
|
+
*
|
|
73
|
+
* await new Promise((resolve) =>
|
|
74
|
+
* db.all(
|
|
75
|
+
* 'UPDATE my_tinybase SET store = ' +
|
|
76
|
+
* `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
|
|
77
|
+
* resolve,
|
|
78
|
+
* ),
|
|
79
|
+
* );
|
|
80
|
+
* await persister.load();
|
|
81
|
+
* console.log(store.getTables());
|
|
82
|
+
* // -> {pets: {felix: {species: 'cat'}}}
|
|
83
|
+
*
|
|
84
|
+
* persister.destroy();
|
|
85
|
+
* ```
|
|
86
|
+
* @example
|
|
87
|
+
* This example creates a Persister object and persists the Store to a local
|
|
88
|
+
* SQLite database with tabular mapping.
|
|
89
|
+
*
|
|
90
|
+
* ```js yolo
|
|
91
|
+
* const db = SQLite.openDatabase('my.db');
|
|
92
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
93
|
+
* const persister = createExpoSqlitePersister(store, db, {
|
|
94
|
+
* mode: 'tabular',
|
|
95
|
+
* tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* await persister.save();
|
|
99
|
+
* console.log(
|
|
100
|
+
* await new Promise((resolve) =>
|
|
101
|
+
* db.all('SELECT * FROM pets;', (_, rows) => resolve(rows)),
|
|
102
|
+
* ),
|
|
103
|
+
* );
|
|
104
|
+
* // -> [{_id: 'fido', species: 'dog'}]
|
|
105
|
+
*
|
|
106
|
+
* await new Promise((resolve) =>
|
|
107
|
+
* db.all(
|
|
108
|
+
* `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
|
|
109
|
+
* resolve,
|
|
110
|
+
* ),
|
|
111
|
+
* );
|
|
112
|
+
* await persister.load();
|
|
113
|
+
* console.log(store.getTables());
|
|
114
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
115
|
+
*
|
|
116
|
+
* persister.destroy();
|
|
117
|
+
* ```
|
|
118
|
+
* @category Creation
|
|
119
|
+
*/
|
|
120
|
+
export function createExpoSqlitePersister(
|
|
121
|
+
store: Store,
|
|
122
|
+
db: SQLiteDatabase,
|
|
123
|
+
configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
124
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
125
|
+
onIgnoredError?: (error: any) => void,
|
|
126
|
+
): Persister;
|
|
@@ -17,6 +17,9 @@ import {Store} from '../store';
|
|
|
17
17
|
* `filePath` parameter which identifies the file to persist it to.
|
|
18
18
|
* @param store The Store to persist.
|
|
19
19
|
* @param filePath The location of the local file to persist the Store to.
|
|
20
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
21
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
22
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
20
23
|
* @returns A reference to the new Persister object.
|
|
21
24
|
* @example
|
|
22
25
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -36,4 +39,8 @@ import {Store} from '../store';
|
|
|
36
39
|
* ```
|
|
37
40
|
* @category Creation
|
|
38
41
|
*/
|
|
39
|
-
export function createFilePersister(
|
|
42
|
+
export function createFilePersister(
|
|
43
|
+
store: Store,
|
|
44
|
+
filePath: string,
|
|
45
|
+
onIgnoredError?: (error: any) => void,
|
|
46
|
+
): Persister;
|
|
@@ -26,6 +26,9 @@ import {Store} from '../store';
|
|
|
26
26
|
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
|
|
27
27
|
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
|
|
28
28
|
* automatically loading changes from the server.
|
|
29
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
30
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
31
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
29
32
|
* @returns A reference to the new Persister object.
|
|
30
33
|
* @example
|
|
31
34
|
* This example creates a Persister object and persists the Store to a remote
|
|
@@ -55,4 +58,5 @@ export function createRemotePersister(
|
|
|
55
58
|
loadUrl: string,
|
|
56
59
|
saveUrl: string,
|
|
57
60
|
autoLoadIntervalSeconds: number,
|
|
61
|
+
onIgnoredError?: (error: any) => void,
|
|
58
62
|
): Persister;
|
|
@@ -36,6 +36,12 @@ import {Store} from '../store';
|
|
|
36
36
|
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
37
37
|
* persistence mode (or a string to set the `storeTableName` property of the
|
|
38
38
|
* JSON serialization).
|
|
39
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
40
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
41
|
+
* behavior in a development environment, since v4.0.4.
|
|
42
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
43
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
44
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
39
45
|
* @returns A reference to the new Persister object.
|
|
40
46
|
* @example
|
|
41
47
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -101,4 +107,6 @@ export function createSqliteWasmPersister(
|
|
|
101
107
|
sqlite3: any,
|
|
102
108
|
db: any,
|
|
103
109
|
configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
110
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
111
|
+
onIgnoredError?: (error: any) => void,
|
|
104
112
|
): Persister;
|
|
@@ -35,6 +35,12 @@ import {Store} from '../store';
|
|
|
35
35
|
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
36
36
|
* persistence mode (or a string to set the `storeTableName` property of the
|
|
37
37
|
* JSON serialization).
|
|
38
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
39
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
40
|
+
* behavior in a development environment, since v4.0.4.
|
|
41
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
42
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
43
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
38
44
|
* @returns A reference to the new Persister object.
|
|
39
45
|
* @example
|
|
40
46
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -108,4 +114,6 @@ export function createSqlite3Persister(
|
|
|
108
114
|
store: Store,
|
|
109
115
|
db: Database,
|
|
110
116
|
configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
117
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
118
|
+
onIgnoredError?: (error: any) => void,
|
|
111
119
|
): Persister;
|
|
@@ -25,6 +25,9 @@ import {Doc as YDoc} from 'yjs';
|
|
|
25
25
|
* @param yDoc The Yjs document to persist the Store to.
|
|
26
26
|
* @param yMapName The name of the Y.Map used inside the Yjs document to sync
|
|
27
27
|
* the Store to (which otherwise will default to 'tinybase').
|
|
28
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
29
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
30
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
28
31
|
* @returns A reference to the new Persister object.
|
|
29
32
|
* @example
|
|
30
33
|
* This example creates a Persister object and persists the Store to a Yjs
|
|
@@ -102,4 +105,5 @@ export function createYjsPersister(
|
|
|
102
105
|
store: Store,
|
|
103
106
|
yDoc: YDoc,
|
|
104
107
|
yMapName?: string,
|
|
108
|
+
onIgnoredError?: (error: any) => void,
|
|
105
109
|
): Persister;
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* |persister-sqlite3|createSqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|
|
|
18
18
|
* |persister-sqlite-wasm|createSqliteWasmPersister|SQLite in a browser, via [sqlite-wasm](https://github.com/tomayac/sqlite-wasm)|
|
|
19
19
|
* |persister-cr-sqlite-wasm|createCrSqliteWasmPersister|SQLite CRDTs, via [cr-sqlite-wasm](https://github.com/vlcn-io/cr-sqlite)|
|
|
20
|
+
* |persister-expo-sqlite|createExpoSqlitePersister|SQLite in React Native, via [expo-sqlite](https://github.com/expo/expo/tree/main/packages/expo-sqlite)|
|
|
20
21
|
* |persister-yjs|createYjsPersister|Yjs CRDTs, via [yjs](https://github.com/yjs/yjs)|
|
|
21
22
|
* |persister-automerge|createSqliteWasmPersister|Automerge CRDTs, via [automerge-repo](https://github.com/automerge/automerge-repo)|
|
|
22
23
|
*
|
|
@@ -569,13 +570,21 @@ export type DpcTabularValues = {
|
|
|
569
570
|
* that changes are constantly synchronized (allowing basic state preservation
|
|
570
571
|
* between browser tabs, for example). The framework has some basic provisions
|
|
571
572
|
* to prevent race conditions - for example it will not attempt to save data if
|
|
572
|
-
* it is currently loading it and vice-versa
|
|
573
|
+
* it is currently loading it and vice-versa - and will sequentially schedule
|
|
574
|
+
* methods that could cause race conditions.
|
|
573
575
|
*
|
|
574
|
-
*
|
|
575
|
-
* synchronization heuristics and you should comprehensively test your
|
|
576
|
+
* That said, be aware that you should always comprehensively test your
|
|
576
577
|
* persistence strategy to understand the opportunity for data loss (in the case
|
|
577
578
|
* of trying to save data to a server under poor network conditions, for
|
|
578
579
|
* example).
|
|
580
|
+
*
|
|
581
|
+
* To help debug such issues, since v4.0.4, the create methods for all Persister
|
|
582
|
+
* objects take an optional `onIgnoredError` argument. This is a handler for the
|
|
583
|
+
* errors that the Persister would otherwise ignore when trying to save or load
|
|
584
|
+
* data (such as when handling corrupted stored data). It's recommended you use
|
|
585
|
+
* this for debugging persistence issues, but only in a development environment.
|
|
586
|
+
* Database-based Persister objects also take an optional `onSqlCommand`
|
|
587
|
+
* argument for logging commands and queries made to the underlying database.
|
|
579
588
|
* @example
|
|
580
589
|
* This example creates a Store, persists it to the browser's session storage as
|
|
581
590
|
* a JSON string, changes the persisted data, updates the Store from it, and
|
|
@@ -1070,6 +1079,9 @@ export interface Persister {
|
|
|
1070
1079
|
* @param delPersisterListener A function that will unregister the listener from
|
|
1071
1080
|
* the underlying changes to the persistence layer. It receives whatever was
|
|
1072
1081
|
* returned from your `addPersisterListener` implementation.
|
|
1082
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
1083
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
1084
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
1073
1085
|
* @returns A reference to the new Persister object.
|
|
1074
1086
|
* @example
|
|
1075
1087
|
* This example creates a custom Persister object and persists the Store to a
|
|
@@ -1117,4 +1129,5 @@ export function createCustomPersister<ListeningHandle>(
|
|
|
1117
1129
|
) => Promise<void>,
|
|
1118
1130
|
addPersisterListener: (listener: PersisterListener) => ListeningHandle,
|
|
1119
1131
|
delPersisterListener: (listeningHandle: ListeningHandle) => void,
|
|
1132
|
+
onIgnoredError?: (error: any) => void,
|
|
1120
1133
|
): Persister;
|
|
@@ -26,6 +26,7 @@ import {Persister} from '../persisters';
|
|
|
26
26
|
* store: Store,
|
|
27
27
|
* docHandle: DocHandle<any>,
|
|
28
28
|
* docMapName?: string,
|
|
29
|
+
* onIgnoredError?: (error: any) => void,
|
|
29
30
|
* ): Persister;
|
|
30
31
|
* ```
|
|
31
32
|
*
|
|
@@ -35,6 +36,9 @@ import {Persister} from '../persisters';
|
|
|
35
36
|
* @param docHandle The Automerge document handler to persist the Store with.
|
|
36
37
|
* @param docMapName The name of the map used inside the Automerge document to
|
|
37
38
|
* sync the Store to (which otherwise will default to 'tinybase').
|
|
39
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
40
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
41
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
38
42
|
* @returns A reference to the new Persister object.
|
|
39
43
|
* @example
|
|
40
44
|
* This example creates a Persister object and persists the Store to an
|
|
@@ -115,4 +119,5 @@ export function createAutomergePersister<Schemas extends OptionalSchemas>(
|
|
|
115
119
|
store: Store<Schemas>,
|
|
116
120
|
docHandle: DocHandle<any>,
|
|
117
121
|
docMapName?: string,
|
|
122
|
+
onIgnoredError?: (error: any) => void,
|
|
118
123
|
): Persister<Schemas>;
|
|
@@ -27,6 +27,7 @@ import {Persister} from '../persisters';
|
|
|
27
27
|
* createSessionPersister(
|
|
28
28
|
* store: Store,
|
|
29
29
|
* storageName: string,
|
|
30
|
+
* onIgnoredError?: (error: any) => void,
|
|
30
31
|
* ): Persister;
|
|
31
32
|
* ```
|
|
32
33
|
*
|
|
@@ -35,6 +36,9 @@ import {Persister} from '../persisters';
|
|
|
35
36
|
* that the browser uses to identify the storage location.
|
|
36
37
|
* @param store The Store to persist.
|
|
37
38
|
* @param storageName The unique key to identify the storage location.
|
|
39
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
40
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
41
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
38
42
|
* @returns A reference to the new Persister object.
|
|
39
43
|
* @example
|
|
40
44
|
* This example creates a Persister object and persists the Store to the
|
|
@@ -56,6 +60,7 @@ import {Persister} from '../persisters';
|
|
|
56
60
|
export function createSessionPersister<Schemas extends OptionalSchemas>(
|
|
57
61
|
store: Store<Schemas>,
|
|
58
62
|
storageName: string,
|
|
63
|
+
onIgnoredError?: (error: any) => void,
|
|
59
64
|
): Persister<Schemas>;
|
|
60
65
|
|
|
61
66
|
/**
|
|
@@ -68,6 +73,7 @@ export function createSessionPersister<Schemas extends OptionalSchemas>(
|
|
|
68
73
|
* createLocalPersister(
|
|
69
74
|
* store: Store,
|
|
70
75
|
* storageName: string,
|
|
76
|
+
* onIgnoredError?: (error: any) => void,
|
|
71
77
|
* ): Persister;
|
|
72
78
|
* ```
|
|
73
79
|
*
|
|
@@ -76,6 +82,9 @@ export function createSessionPersister<Schemas extends OptionalSchemas>(
|
|
|
76
82
|
* that the browser uses to identify the storage location.
|
|
77
83
|
* @param store The Store to persist.
|
|
78
84
|
* @param storageName The unique key to identify the storage location.
|
|
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, since v4.0.4.
|
|
79
88
|
* @returns A reference to the new Persister object.
|
|
80
89
|
* @example
|
|
81
90
|
* This example creates a Persister object and persists the Store to the
|
|
@@ -97,4 +106,5 @@ export function createSessionPersister<Schemas extends OptionalSchemas>(
|
|
|
97
106
|
export function createLocalPersister<Schemas extends OptionalSchemas>(
|
|
98
107
|
store: Store<Schemas>,
|
|
99
108
|
storageName: string,
|
|
109
|
+
onIgnoredError?: (error: any) => void,
|
|
100
110
|
): Persister<Schemas>;
|
|
@@ -23,11 +23,13 @@ import {DB} from '@vlcn.io/crsqlite-wasm';
|
|
|
23
23
|
* store: Store,
|
|
24
24
|
* db: DB,
|
|
25
25
|
* configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
26
|
+
* onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
27
|
+
* onIgnoredError?: (error: any) => void,
|
|
26
28
|
* ): Persister;
|
|
27
29
|
* ```
|
|
28
30
|
*
|
|
29
|
-
* As well as providing a reference to the Store to persist, you must provide
|
|
30
|
-
*
|
|
31
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
32
|
+
* `db` parameter which identifies the database instance.
|
|
31
33
|
*
|
|
32
34
|
* A database Persister uses one of two modes: either a JSON serialization of
|
|
33
35
|
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
@@ -45,6 +47,12 @@ import {DB} from '@vlcn.io/crsqlite-wasm';
|
|
|
45
47
|
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
46
48
|
* persistence mode (or a string to set the `storeTableName` property of the
|
|
47
49
|
* JSON serialization).
|
|
50
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
51
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
52
|
+
* behavior in a development environment, since v4.0.4.
|
|
53
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
54
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
55
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
48
56
|
* @returns A reference to the new Persister object.
|
|
49
57
|
* @example
|
|
50
58
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -104,4 +112,6 @@ export function createCrSqliteWasmPersister<Schemas extends OptionalSchemas>(
|
|
|
104
112
|
store: Store<Schemas>,
|
|
105
113
|
db: DB,
|
|
106
114
|
configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
|
|
115
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
116
|
+
onIgnoredError?: (error: any) => void,
|
|
107
117
|
): Persister<Schemas>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-expo-sqlite module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from a local Expo-SQLite database (in an appropriate
|
|
4
|
+
* React Native environment).
|
|
5
|
+
*
|
|
6
|
+
* Note that this Persister is currently experimental as Expo themselves iterate
|
|
7
|
+
* on the underlying database library API.
|
|
8
|
+
* @see Persisting Data guide
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
* @module persister-expo-sqlite
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {DatabasePersisterConfig, Persister} from '../persisters';
|
|
14
|
+
import {OptionalSchemas, Store} from '../store';
|
|
15
|
+
import {SQLiteDatabase} from 'expo-sqlite';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The createExpoSqlitePersister function creates a Persister object that can
|
|
19
|
+
* persist the Store to a local Expo-SQLite database (in an appropriate React
|
|
20
|
+
* Native environment).
|
|
21
|
+
*
|
|
22
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
23
|
+
*
|
|
24
|
+
* ```ts override
|
|
25
|
+
* createExpoSqlitePersister(
|
|
26
|
+
* store: Store,
|
|
27
|
+
* db: SQLiteDatabase,
|
|
28
|
+
* configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
29
|
+
* onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
30
|
+
* onIgnoredError?: (error: any) => void,
|
|
31
|
+
* ): Persister;
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Note that this Persister is currently experimental as Expo themselves iterate
|
|
35
|
+
* on the underlying database library API.
|
|
36
|
+
*
|
|
37
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
38
|
+
* `db` parameter which identifies the database instance.
|
|
39
|
+
*
|
|
40
|
+
* A database Persister uses one of two modes: either a JSON serialization of
|
|
41
|
+
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
42
|
+
* mapping of Table Ids to database table names and vice-versa).
|
|
43
|
+
*
|
|
44
|
+
* The third argument is a DatabasePersisterConfig object that configures which
|
|
45
|
+
* of those modes to use, and settings for each. If the third argument is simply
|
|
46
|
+
* a string, it is used as the `storeTableName` property of the JSON
|
|
47
|
+
* serialization.
|
|
48
|
+
*
|
|
49
|
+
* See the documentation for the DpcJson and DpcTabular types for more
|
|
50
|
+
* information on how both of those modes can be configured.
|
|
51
|
+
* @param store The Store to persist.
|
|
52
|
+
* @param db The database instance that was returned from
|
|
53
|
+
* `SQLite.openDatabase(...)`.
|
|
54
|
+
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
55
|
+
* persistence mode (or a string to set the `storeTableName` property of the
|
|
56
|
+
* JSON serialization).
|
|
57
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
58
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
59
|
+
* behavior in a development environment, since v4.0.4.
|
|
60
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
61
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
62
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
63
|
+
* @returns A reference to the new Persister object.
|
|
64
|
+
* @example
|
|
65
|
+
* This example creates a Persister object and persists the Store to a local
|
|
66
|
+
* SQLite database as a JSON serialization into the `my_tinybase` table. It
|
|
67
|
+
* makes a change to the database directly and then reloads it back into the
|
|
68
|
+
* Store.
|
|
69
|
+
*
|
|
70
|
+
* ```js yolo
|
|
71
|
+
* const db = SQLite.openDatabase('my.db');
|
|
72
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
73
|
+
* const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
|
|
74
|
+
*
|
|
75
|
+
* await persister.save();
|
|
76
|
+
* // Store will be saved to the database.
|
|
77
|
+
*
|
|
78
|
+
* console.log(
|
|
79
|
+
* await new Promise((resolve) =>
|
|
80
|
+
* db.all('SELECT * FROM my_tinybase;', (_, rows) => resolve(rows)),
|
|
81
|
+
* ),
|
|
82
|
+
* );
|
|
83
|
+
* // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
|
|
84
|
+
*
|
|
85
|
+
* await new Promise((resolve) =>
|
|
86
|
+
* db.all(
|
|
87
|
+
* 'UPDATE my_tinybase SET store = ' +
|
|
88
|
+
* `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
|
|
89
|
+
* resolve,
|
|
90
|
+
* ),
|
|
91
|
+
* );
|
|
92
|
+
* await persister.load();
|
|
93
|
+
* console.log(store.getTables());
|
|
94
|
+
* // -> {pets: {felix: {species: 'cat'}}}
|
|
95
|
+
*
|
|
96
|
+
* persister.destroy();
|
|
97
|
+
* ```
|
|
98
|
+
* @example
|
|
99
|
+
* This example creates a Persister object and persists the Store to a local
|
|
100
|
+
* SQLite database with tabular mapping.
|
|
101
|
+
*
|
|
102
|
+
* ```js yolo
|
|
103
|
+
* const db = SQLite.openDatabase('my.db');
|
|
104
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
105
|
+
* const persister = createExpoSqlitePersister(store, db, {
|
|
106
|
+
* mode: 'tabular',
|
|
107
|
+
* tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* await persister.save();
|
|
111
|
+
* console.log(
|
|
112
|
+
* await new Promise((resolve) =>
|
|
113
|
+
* db.all('SELECT * FROM pets;', (_, rows) => resolve(rows)),
|
|
114
|
+
* ),
|
|
115
|
+
* );
|
|
116
|
+
* // -> [{_id: 'fido', species: 'dog'}]
|
|
117
|
+
*
|
|
118
|
+
* await new Promise((resolve) =>
|
|
119
|
+
* db.all(
|
|
120
|
+
* `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
|
|
121
|
+
* resolve,
|
|
122
|
+
* ),
|
|
123
|
+
* );
|
|
124
|
+
* await persister.load();
|
|
125
|
+
* console.log(store.getTables());
|
|
126
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
127
|
+
*
|
|
128
|
+
* persister.destroy();
|
|
129
|
+
* ```
|
|
130
|
+
* @category Creation
|
|
131
|
+
*/
|
|
132
|
+
export function createExpoSqlitePersister<Schemas extends OptionalSchemas>(
|
|
133
|
+
store: Store<Schemas>,
|
|
134
|
+
db: SQLiteDatabase,
|
|
135
|
+
configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
|
|
136
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
137
|
+
onIgnoredError?: (error: any) => void,
|
|
138
|
+
): Persister<Schemas>;
|
|
@@ -16,13 +16,20 @@ import {Persister} from '../persisters';
|
|
|
16
16
|
* This has schema-based typing. The following is a simplified representation:
|
|
17
17
|
*
|
|
18
18
|
* ```ts override
|
|
19
|
-
* createFilePersister(
|
|
19
|
+
* createFilePersister(
|
|
20
|
+
* store: Store,
|
|
21
|
+
* filePath: string,
|
|
22
|
+
* onIgnoredError?: (error: any) => void,
|
|
23
|
+
* ): Persister;
|
|
20
24
|
* ```
|
|
21
25
|
*
|
|
22
26
|
* As well as providing a reference to the Store to persist, you must provide a
|
|
23
27
|
* `filePath` parameter which identifies the file to persist it to.
|
|
24
28
|
* @param store The Store to persist.
|
|
25
29
|
* @param filePath The location of the local file to persist the Store to.
|
|
30
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
31
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
32
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
26
33
|
* @returns A reference to the new Persister object.
|
|
27
34
|
* @example
|
|
28
35
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -45,4 +52,5 @@ import {Persister} from '../persisters';
|
|
|
45
52
|
export function createFilePersister<Schemas extends OptionalSchemas>(
|
|
46
53
|
store: Store<Schemas>,
|
|
47
54
|
filePath: string,
|
|
55
|
+
onIgnoredError?: (error: any) => void,
|
|
48
56
|
): Persister<Schemas>;
|
|
@@ -21,6 +21,7 @@ import {Persister} from '../persisters';
|
|
|
21
21
|
* loadUrl: string,
|
|
22
22
|
* saveUrl: string,
|
|
23
23
|
* autoLoadIntervalSeconds: number,
|
|
24
|
+
* onIgnoredError?: (error: any) => void,
|
|
24
25
|
* ): Persister;
|
|
25
26
|
* ```
|
|
26
27
|
*
|
|
@@ -37,6 +38,9 @@ import {Persister} from '../persisters';
|
|
|
37
38
|
* @param saveUrl The endpoint that supports a `POST` method to save JSON.
|
|
38
39
|
* @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
|
|
39
40
|
* automatically loading changes from the server.
|
|
41
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
42
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
43
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
40
44
|
* @returns A reference to the new Persister object.
|
|
41
45
|
* @example
|
|
42
46
|
* This example creates a Persister object and persists the Store to a remote
|
|
@@ -66,4 +70,5 @@ export function createRemotePersister<Schemas extends OptionalSchemas>(
|
|
|
66
70
|
loadUrl: string,
|
|
67
71
|
saveUrl: string,
|
|
68
72
|
autoLoadIntervalSeconds: number,
|
|
73
|
+
onIgnoredError?: (error: any) => void,
|
|
69
74
|
): Persister<Schemas>;
|
|
@@ -22,6 +22,8 @@ import {OptionalSchemas, Store} from '../store';
|
|
|
22
22
|
* sqlite3: any,
|
|
23
23
|
* db: any,
|
|
24
24
|
* configOrStoreTableName?: DatabasePersisterConfig | string,
|
|
25
|
+
* onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
26
|
+
* onIgnoredError?: (error: any) => void,
|
|
25
27
|
* ): Persister;
|
|
26
28
|
* ```
|
|
27
29
|
*
|
|
@@ -47,6 +49,12 @@ import {OptionalSchemas, Store} from '../store';
|
|
|
47
49
|
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
48
50
|
* persistence mode (or a string to set the `storeTableName` property of the
|
|
49
51
|
* JSON serialization).
|
|
52
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
53
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
54
|
+
* behavior in a development environment, since v4.0.4.
|
|
55
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
56
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
57
|
+
* debugging persistence issues in a development environment, since v4.0.4.
|
|
50
58
|
* @returns A reference to the new Persister object.
|
|
51
59
|
* @example
|
|
52
60
|
* This example creates a Persister object and persists the Store to a local
|
|
@@ -112,4 +120,6 @@ export function createSqliteWasmPersister<Schemas extends OptionalSchemas>(
|
|
|
112
120
|
sqlite3: any,
|
|
113
121
|
db: any,
|
|
114
122
|
configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
|
|
123
|
+
onSqlCommand?: (sql: string, args?: any[]) => void,
|
|
124
|
+
onIgnoredError?: (error: any) => void,
|
|
115
125
|
): Persister<Schemas>;
|