tinybase 4.3.13 → 4.3.14

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 (204) hide show
  1. package/lib/cjs/persisters/persister-automerge.cjs +1 -1
  2. package/lib/cjs/persisters/persister-automerge.cjs.gz +0 -0
  3. package/lib/cjs/persisters/persister-browser.cjs +1 -1
  4. package/lib/cjs/persisters/persister-browser.cjs.gz +0 -0
  5. package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs +1 -1
  6. package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
  7. package/lib/cjs/persisters/persister-expo-sqlite.cjs +1 -1
  8. package/lib/cjs/persisters/persister-expo-sqlite.cjs.gz +0 -0
  9. package/lib/cjs/persisters/persister-file.cjs +1 -1
  10. package/lib/cjs/persisters/persister-file.cjs.gz +0 -0
  11. package/lib/cjs/persisters/persister-indexed-db.cjs +1 -1
  12. package/lib/cjs/persisters/persister-indexed-db.cjs.gz +0 -0
  13. package/lib/cjs/persisters/persister-partykit-client.cjs +1 -1
  14. package/lib/cjs/persisters/persister-partykit-client.cjs.gz +0 -0
  15. package/lib/cjs/persisters/persister-remote.cjs +1 -1
  16. package/lib/cjs/persisters/persister-remote.cjs.gz +0 -0
  17. package/lib/cjs/persisters/persister-sqlite-wasm.cjs +1 -1
  18. package/lib/cjs/persisters/persister-sqlite-wasm.cjs.gz +0 -0
  19. package/lib/cjs/persisters/persister-sqlite3.cjs +1 -1
  20. package/lib/cjs/persisters/persister-sqlite3.cjs.gz +0 -0
  21. package/lib/cjs/persisters/persister-yjs.cjs +1 -1
  22. package/lib/cjs/persisters/persister-yjs.cjs.gz +0 -0
  23. package/lib/cjs/persisters.cjs +1 -1
  24. package/lib/cjs/persisters.cjs.gz +0 -0
  25. package/lib/cjs/tinybase.cjs +1 -1
  26. package/lib/cjs/tinybase.cjs.gz +0 -0
  27. package/lib/cjs/ui-react-dom-debug.cjs +1 -1
  28. package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
  29. package/lib/cjs-es6/persisters/persister-automerge.cjs +1 -1
  30. package/lib/cjs-es6/persisters/persister-automerge.cjs.gz +0 -0
  31. package/lib/cjs-es6/persisters/persister-browser.cjs +1 -1
  32. package/lib/cjs-es6/persisters/persister-browser.cjs.gz +0 -0
  33. package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs +1 -1
  34. package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
  35. package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs +1 -1
  36. package/lib/cjs-es6/persisters/persister-expo-sqlite.cjs.gz +0 -0
  37. package/lib/cjs-es6/persisters/persister-file.cjs +1 -1
  38. package/lib/cjs-es6/persisters/persister-file.cjs.gz +0 -0
  39. package/lib/cjs-es6/persisters/persister-indexed-db.cjs +1 -1
  40. package/lib/cjs-es6/persisters/persister-indexed-db.cjs.gz +0 -0
  41. package/lib/cjs-es6/persisters/persister-partykit-client.cjs +1 -1
  42. package/lib/cjs-es6/persisters/persister-partykit-client.cjs.gz +0 -0
  43. package/lib/cjs-es6/persisters/persister-remote.cjs +1 -1
  44. package/lib/cjs-es6/persisters/persister-remote.cjs.gz +0 -0
  45. package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs +1 -1
  46. package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs.gz +0 -0
  47. package/lib/cjs-es6/persisters/persister-sqlite3.cjs +1 -1
  48. package/lib/cjs-es6/persisters/persister-sqlite3.cjs.gz +0 -0
  49. package/lib/cjs-es6/persisters/persister-yjs.cjs +1 -1
  50. package/lib/cjs-es6/persisters/persister-yjs.cjs.gz +0 -0
  51. package/lib/cjs-es6/persisters.cjs +1 -1
  52. package/lib/cjs-es6/persisters.cjs.gz +0 -0
  53. package/lib/cjs-es6/tinybase.cjs +1 -1
  54. package/lib/cjs-es6/tinybase.cjs.gz +0 -0
  55. package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
  56. package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
  57. package/lib/debug/persisters/persister-automerge.js +5 -0
  58. package/lib/debug/persisters/persister-browser.js +5 -0
  59. package/lib/debug/persisters/persister-cr-sqlite-wasm.js +12 -6
  60. package/lib/debug/persisters/persister-expo-sqlite.js +12 -6
  61. package/lib/debug/persisters/persister-file.js +5 -0
  62. package/lib/debug/persisters/persister-indexed-db.js +5 -0
  63. package/lib/debug/persisters/persister-partykit-client.js +6 -1
  64. package/lib/debug/persisters/persister-remote.js +5 -0
  65. package/lib/debug/persisters/persister-sqlite-wasm.js +12 -6
  66. package/lib/debug/persisters/persister-sqlite3.js +12 -6
  67. package/lib/debug/persisters/persister-yjs.js +5 -0
  68. package/lib/debug/persisters.js +4 -0
  69. package/lib/debug/tinybase.js +4 -0
  70. package/lib/debug/ui-react-dom.js +5 -0
  71. package/lib/es6/persisters/persister-automerge.js +1 -1
  72. package/lib/es6/persisters/persister-automerge.js.gz +0 -0
  73. package/lib/es6/persisters/persister-browser.js +1 -1
  74. package/lib/es6/persisters/persister-browser.js.gz +0 -0
  75. package/lib/es6/persisters/persister-cr-sqlite-wasm.js +1 -1
  76. package/lib/es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
  77. package/lib/es6/persisters/persister-expo-sqlite.js +1 -1
  78. package/lib/es6/persisters/persister-expo-sqlite.js.gz +0 -0
  79. package/lib/es6/persisters/persister-file.js +1 -1
  80. package/lib/es6/persisters/persister-file.js.gz +0 -0
  81. package/lib/es6/persisters/persister-indexed-db.js +1 -1
  82. package/lib/es6/persisters/persister-indexed-db.js.gz +0 -0
  83. package/lib/es6/persisters/persister-partykit-client.js +1 -1
  84. package/lib/es6/persisters/persister-partykit-client.js.gz +0 -0
  85. package/lib/es6/persisters/persister-remote.js +1 -1
  86. package/lib/es6/persisters/persister-remote.js.gz +0 -0
  87. package/lib/es6/persisters/persister-sqlite-wasm.js +1 -1
  88. package/lib/es6/persisters/persister-sqlite-wasm.js.gz +0 -0
  89. package/lib/es6/persisters/persister-sqlite3.js +1 -1
  90. package/lib/es6/persisters/persister-sqlite3.js.gz +0 -0
  91. package/lib/es6/persisters/persister-yjs.js +1 -1
  92. package/lib/es6/persisters/persister-yjs.js.gz +0 -0
  93. package/lib/es6/persisters.js +1 -1
  94. package/lib/es6/persisters.js.gz +0 -0
  95. package/lib/es6/tinybase.js +1 -1
  96. package/lib/es6/tinybase.js.gz +0 -0
  97. package/lib/es6/ui-react-dom-debug.js +1 -1
  98. package/lib/es6/ui-react-dom-debug.js.gz +0 -0
  99. package/lib/persisters/persister-automerge.js +1 -1
  100. package/lib/persisters/persister-automerge.js.gz +0 -0
  101. package/lib/persisters/persister-browser.js +1 -1
  102. package/lib/persisters/persister-browser.js.gz +0 -0
  103. package/lib/persisters/persister-cr-sqlite-wasm.js +1 -1
  104. package/lib/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
  105. package/lib/persisters/persister-expo-sqlite.js +1 -1
  106. package/lib/persisters/persister-expo-sqlite.js.gz +0 -0
  107. package/lib/persisters/persister-file.js +1 -1
  108. package/lib/persisters/persister-file.js.gz +0 -0
  109. package/lib/persisters/persister-indexed-db.js +1 -1
  110. package/lib/persisters/persister-indexed-db.js.gz +0 -0
  111. package/lib/persisters/persister-partykit-client.js +1 -1
  112. package/lib/persisters/persister-partykit-client.js.gz +0 -0
  113. package/lib/persisters/persister-remote.js +1 -1
  114. package/lib/persisters/persister-remote.js.gz +0 -0
  115. package/lib/persisters/persister-sqlite-wasm.js +1 -1
  116. package/lib/persisters/persister-sqlite-wasm.js.gz +0 -0
  117. package/lib/persisters/persister-sqlite3.js +1 -1
  118. package/lib/persisters/persister-sqlite3.js.gz +0 -0
  119. package/lib/persisters/persister-yjs.js +1 -1
  120. package/lib/persisters/persister-yjs.js.gz +0 -0
  121. package/lib/persisters.js +1 -1
  122. package/lib/persisters.js.gz +0 -0
  123. package/lib/tinybase.js +1 -1
  124. package/lib/tinybase.js.gz +0 -0
  125. package/lib/types/persisters/persister-automerge.d.ts +36 -3
  126. package/lib/types/persisters/persister-browser.d.ts +71 -8
  127. package/lib/types/persisters/persister-cr-sqlite-wasm.d.ts +42 -8
  128. package/lib/types/persisters/persister-expo-sqlite.d.ts +40 -7
  129. package/lib/types/persisters/persister-file.d.ts +34 -3
  130. package/lib/types/persisters/persister-indexed-db.d.ts +36 -4
  131. package/lib/types/persisters/persister-partykit-client.d.ts +39 -3
  132. package/lib/types/persisters/persister-remote.d.ts +40 -4
  133. package/lib/types/persisters/persister-sqlite-wasm.d.ts +46 -7
  134. package/lib/types/persisters/persister-sqlite3.d.ts +40 -7
  135. package/lib/types/persisters/persister-yjs.d.ts +37 -5
  136. package/lib/types/with-schemas/persisters/persister-automerge.d.ts +38 -4
  137. package/lib/types/with-schemas/persisters/persister-browser.d.ts +75 -10
  138. package/lib/types/with-schemas/persisters/persister-cr-sqlite-wasm.d.ts +44 -9
  139. package/lib/types/with-schemas/persisters/persister-expo-sqlite.d.ts +42 -8
  140. package/lib/types/with-schemas/persisters/persister-file.d.ts +36 -4
  141. package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +38 -5
  142. package/lib/types/with-schemas/persisters/persister-partykit-client.d.ts +41 -4
  143. package/lib/types/with-schemas/persisters/persister-remote.d.ts +42 -5
  144. package/lib/types/with-schemas/persisters/persister-sqlite-wasm.d.ts +48 -8
  145. package/lib/types/with-schemas/persisters/persister-sqlite3.d.ts +41 -7
  146. package/lib/types/with-schemas/persisters/persister-yjs.d.ts +39 -6
  147. package/lib/umd/persisters/persister-automerge.js +1 -1
  148. package/lib/umd/persisters/persister-automerge.js.gz +0 -0
  149. package/lib/umd/persisters/persister-browser.js +1 -1
  150. package/lib/umd/persisters/persister-browser.js.gz +0 -0
  151. package/lib/umd/persisters/persister-cr-sqlite-wasm.js +1 -1
  152. package/lib/umd/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
  153. package/lib/umd/persisters/persister-expo-sqlite.js +1 -1
  154. package/lib/umd/persisters/persister-expo-sqlite.js.gz +0 -0
  155. package/lib/umd/persisters/persister-file.js +1 -1
  156. package/lib/umd/persisters/persister-file.js.gz +0 -0
  157. package/lib/umd/persisters/persister-indexed-db.js +1 -1
  158. package/lib/umd/persisters/persister-indexed-db.js.gz +0 -0
  159. package/lib/umd/persisters/persister-partykit-client.js +1 -1
  160. package/lib/umd/persisters/persister-partykit-client.js.gz +0 -0
  161. package/lib/umd/persisters/persister-remote.js +1 -1
  162. package/lib/umd/persisters/persister-remote.js.gz +0 -0
  163. package/lib/umd/persisters/persister-sqlite-wasm.js +1 -1
  164. package/lib/umd/persisters/persister-sqlite-wasm.js.gz +0 -0
  165. package/lib/umd/persisters/persister-sqlite3.js +1 -1
  166. package/lib/umd/persisters/persister-sqlite3.js.gz +0 -0
  167. package/lib/umd/persisters/persister-yjs.js +1 -1
  168. package/lib/umd/persisters/persister-yjs.js.gz +0 -0
  169. package/lib/umd/persisters.js +1 -1
  170. package/lib/umd/persisters.js.gz +0 -0
  171. package/lib/umd/tinybase.js +1 -1
  172. package/lib/umd/tinybase.js.gz +0 -0
  173. package/lib/umd/ui-react-dom-debug.js +1 -1
  174. package/lib/umd/ui-react-dom-debug.js.gz +0 -0
  175. package/lib/umd-es6/persisters/persister-automerge.js +1 -1
  176. package/lib/umd-es6/persisters/persister-automerge.js.gz +0 -0
  177. package/lib/umd-es6/persisters/persister-browser.js +1 -1
  178. package/lib/umd-es6/persisters/persister-browser.js.gz +0 -0
  179. package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js +1 -1
  180. package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
  181. package/lib/umd-es6/persisters/persister-expo-sqlite.js +1 -1
  182. package/lib/umd-es6/persisters/persister-expo-sqlite.js.gz +0 -0
  183. package/lib/umd-es6/persisters/persister-file.js +1 -1
  184. package/lib/umd-es6/persisters/persister-file.js.gz +0 -0
  185. package/lib/umd-es6/persisters/persister-indexed-db.js +1 -1
  186. package/lib/umd-es6/persisters/persister-indexed-db.js.gz +0 -0
  187. package/lib/umd-es6/persisters/persister-partykit-client.js +1 -1
  188. package/lib/umd-es6/persisters/persister-partykit-client.js.gz +0 -0
  189. package/lib/umd-es6/persisters/persister-remote.js +1 -1
  190. package/lib/umd-es6/persisters/persister-remote.js.gz +0 -0
  191. package/lib/umd-es6/persisters/persister-sqlite-wasm.js +1 -1
  192. package/lib/umd-es6/persisters/persister-sqlite-wasm.js.gz +0 -0
  193. package/lib/umd-es6/persisters/persister-sqlite3.js +1 -1
  194. package/lib/umd-es6/persisters/persister-sqlite3.js.gz +0 -0
  195. package/lib/umd-es6/persisters/persister-yjs.js +1 -1
  196. package/lib/umd-es6/persisters/persister-yjs.js.gz +0 -0
  197. package/lib/umd-es6/persisters.js +1 -1
  198. package/lib/umd-es6/persisters.js.gz +0 -0
  199. package/lib/umd-es6/tinybase.js +1 -1
  200. package/lib/umd-es6/tinybase.js.gz +0 -0
  201. package/lib/umd-es6/ui-react-dom-debug.js +1 -1
  202. package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
  203. package/package.json +6 -6
  204. package/readme.md +2 -2
@@ -12,6 +12,41 @@ import {DatabasePersisterConfig, Persister} from '../persisters';
12
12
  import {OptionalSchemas, Store} from '../store';
13
13
  import {DB} from '@vlcn.io/crsqlite-wasm';
14
14
 
15
+ /**
16
+ * The CrSqliteWasmPersister interface is a minor extension to the Persister
17
+ * interface.
18
+ *
19
+ * It simply provides an extra getDb method for accessing a reference to the
20
+ * database instance the Store is being persisted to.
21
+ * @since v4.3.14
22
+ */
23
+ export interface CrSqliteWasmPersister<Schemas extends OptionalSchemas>
24
+ extends Persister<Schemas> {
25
+ /**
26
+ * The getDb method returns a reference to the database instance the Store is
27
+ * being persisted to.
28
+ * @returns A reference to the database instance.
29
+ * @example
30
+ * This example creates a Persister object against a newly-created Store and
31
+ * then gets the database instance back out again.
32
+ *
33
+ * ```js
34
+ * const crSqlite3 = await initWasm();
35
+ * const db = await crSqlite3.open();
36
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
37
+ * const persister = createCrSqliteWasmPersister(store, db, 'my_tinybase');
38
+ *
39
+ * console.log(persister.getDb() == db);
40
+ * // -> true
41
+ *
42
+ * persister.destroy();
43
+ * ```
44
+ * @category Getter
45
+ * @since v4.3.14
46
+ */
47
+ getDb: () => DB;
48
+ }
49
+
15
50
  /**
16
51
  * The createCrSqliteWasmPersister function creates a Persister object that can
17
52
  * persist the Store to a local CR-SQLite database (in an appropriate
@@ -26,7 +61,7 @@ import {DB} from '@vlcn.io/crsqlite-wasm';
26
61
  * configOrStoreTableName?: DatabasePersisterConfig | string,
27
62
  * onSqlCommand?: (sql: string, args?: any[]) => void,
28
63
  * onIgnoredError?: (error: any) => void,
29
- * ): Persister;
64
+ * ): CrSqliteWasmPersister;
30
65
  * ```
31
66
  *
32
67
  * As well as providing a reference to the Store to persist, you must provide a
@@ -54,12 +89,12 @@ import {DB} from '@vlcn.io/crsqlite-wasm';
54
89
  * @param onIgnoredError An optional handler for the errors that the Persister
55
90
  * would otherwise ignore when trying to save or load data. This is suitable for
56
91
  * debugging persistence issues in a development environment, since v4.0.4.
57
- * @returns A reference to the new Persister object.
92
+ * @returns A reference to the new CrSqliteWasmPersister object.
58
93
  * @example
59
- * This example creates a Persister object and persists the Store to a local
60
- * CR-SQLite database as a JSON serialization into the `my_tinybase` table. It
61
- * makes a change to the database directly and then reloads it back into the
62
- * Store.
94
+ * This example creates a CrSqliteWasmPersister object and persists the Store to
95
+ * a local CR-SQLite database as a JSON serialization into the `my_tinybase`
96
+ * table. It makes a change to the database directly and then reloads it back
97
+ * into the Store.
63
98
  *
64
99
  * ```js
65
100
  * const crSqlite3 = await initWasm();
@@ -84,8 +119,8 @@ import {DB} from '@vlcn.io/crsqlite-wasm';
84
119
  * persister.destroy();
85
120
  * ```
86
121
  * @example
87
- * This example creates a Persister object and persists the Store to a local
88
- * SQLite database with tabular mapping.
122
+ * This example creates a CrSqliteWasmPersister object and persists the Store to
123
+ * a local SQLite database with tabular mapping.
89
124
  *
90
125
  * ```js
91
126
  * const crSqlite3 = await initWasm();
@@ -116,4 +151,4 @@ export function createCrSqliteWasmPersister<Schemas extends OptionalSchemas>(
116
151
  configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
117
152
  onSqlCommand?: (sql: string, args?: any[]) => void,
118
153
  onIgnoredError?: (error: any) => void,
119
- ): Persister<Schemas>;
154
+ ): CrSqliteWasmPersister<Schemas>;
@@ -15,6 +15,40 @@ import {DatabasePersisterConfig, Persister} from '../persisters';
15
15
  import {OptionalSchemas, Store} from '../store';
16
16
  import {SQLiteDatabase} from 'expo-sqlite';
17
17
 
18
+ /**
19
+ * The ExpoSqlitePersister interface is a minor extension to the Persister
20
+ * interface.
21
+ *
22
+ * It simply provides an extra getDb method for accessing a reference to the
23
+ * database instance the Store is being persisted to.
24
+ * @since v4.3.14
25
+ */
26
+ export interface ExpoSqlitePersister<Schemas extends OptionalSchemas>
27
+ extends Persister<Schemas> {
28
+ /**
29
+ * The getDb method returns a reference to the database instance the Store is
30
+ * being persisted to.
31
+ * @returns A reference to the database instance.
32
+ * @example
33
+ * This example creates a Persister object against a newly-created Store and
34
+ * then gets the database instance back out again.
35
+ *
36
+ * ```js yolo
37
+ * const db = SQLite.openDatabase('my.db');
38
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
39
+ * const persister = createExpoSqlitePersister(store, db, 'my_tinybase');
40
+ *
41
+ * console.log(persister.getDb() == db);
42
+ * // -> true
43
+ *
44
+ * persister.destroy();
45
+ * ```
46
+ * @category Getter
47
+ * @since v4.3.14
48
+ */
49
+ getDb: () => SQLiteDatabase;
50
+ }
51
+
18
52
  /**
19
53
  * The createExpoSqlitePersister function creates a Persister object that can
20
54
  * persist the Store to a local Expo-SQLite database (in an appropriate React
@@ -29,7 +63,7 @@ import {SQLiteDatabase} from 'expo-sqlite';
29
63
  * configOrStoreTableName?: DatabasePersisterConfig | string,
30
64
  * onSqlCommand?: (sql: string, args?: any[]) => void,
31
65
  * onIgnoredError?: (error: any) => void,
32
- * ): Persister;
66
+ * ): ExpoSqlitePersister;
33
67
  * ```
34
68
  *
35
69
  * Note that this Persister is currently experimental as Expo themselves iterate
@@ -61,11 +95,11 @@ import {SQLiteDatabase} from 'expo-sqlite';
61
95
  * @param onIgnoredError An optional handler for the errors that the Persister
62
96
  * would otherwise ignore when trying to save or load data. This is suitable for
63
97
  * debugging persistence issues in a development environment, since v4.0.4.
64
- * @returns A reference to the new Persister object.
98
+ * @returns A reference to the new ExpoSqlitePersister object.
65
99
  * @example
66
- * This example creates a Persister object and persists the Store to a local
67
- * SQLite database as a JSON serialization into the `my_tinybase` table. It
68
- * makes a change to the database directly and then reloads it back into the
100
+ * This example creates a ExpoSqlitePersister object and persists the Store to a
101
+ * local SQLite database as a JSON serialization into the `my_tinybase` table.
102
+ * It makes a change to the database directly and then reloads it back into the
69
103
  * Store.
70
104
  *
71
105
  * ```js yolo
@@ -97,8 +131,8 @@ import {SQLiteDatabase} from 'expo-sqlite';
97
131
  * persister.destroy();
98
132
  * ```
99
133
  * @example
100
- * This example creates a Persister object and persists the Store to a local
101
- * SQLite database with tabular mapping.
134
+ * This example creates a ExpoSqlitePersister object and persists the Store to a
135
+ * local SQLite database with tabular mapping.
102
136
  *
103
137
  * ```js yolo
104
138
  * const db = SQLite.openDatabase('my.db');
@@ -137,4 +171,4 @@ export function createExpoSqlitePersister<Schemas extends OptionalSchemas>(
137
171
  configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
138
172
  onSqlCommand?: (sql: string, args?: any[]) => void,
139
173
  onIgnoredError?: (error: any) => void,
140
- ): Persister<Schemas>;
174
+ ): ExpoSqlitePersister<Schemas>;
@@ -9,6 +9,38 @@
9
9
  import {OptionalSchemas, Store} from '../store';
10
10
  import {Persister} from '../persisters';
11
11
 
12
+ /**
13
+ * The FilePersister interface is a minor extension to the Persister interface.
14
+ *
15
+ * It simply provides an extra getFilePath method for accessing the location of
16
+ * the local file the Store is being persisted to.
17
+ * @since v4.3.14
18
+ */
19
+ export interface FilePersister<Schemas extends OptionalSchemas>
20
+ extends Persister<Schemas> {
21
+ /**
22
+ * The getFilePath method returns the location of the local file the Store is
23
+ * being persisted to.
24
+ * @returns The location of the local file.
25
+ * @example
26
+ * This example creates a Persister object against a newly-created Store and
27
+ * then gets the file location back out again.
28
+ *
29
+ * ```js
30
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
31
+ * const persister = createFilePersister(store, '/app/persisted.json');
32
+ *
33
+ * console.log(persister.getFilePath());
34
+ * // -> '/app/persisted.json'
35
+ *
36
+ * persister.destroy();
37
+ * ```
38
+ * @category Getter
39
+ * @since v4.3.14
40
+ */
41
+ getFilePath: () => string;
42
+ }
43
+
12
44
  /**
13
45
  * The createFilePersister function creates a Persister object that can persist
14
46
  * the Store to a local file (in an appropriate environment).
@@ -20,7 +52,7 @@ import {Persister} from '../persisters';
20
52
  * store: Store,
21
53
  * filePath: string,
22
54
  * onIgnoredError?: (error: any) => void,
23
- * ): Persister;
55
+ * ): FilePersister;
24
56
  * ```
25
57
  *
26
58
  * As well as providing a reference to the Store to persist, you must provide a
@@ -30,9 +62,9 @@ import {Persister} from '../persisters';
30
62
  * @param onIgnoredError An optional handler for the errors that the Persister
31
63
  * would otherwise ignore when trying to save or load data. This is suitable for
32
64
  * debugging persistence issues in a development environment, since v4.0.4.
33
- * @returns A reference to the new Persister object.
65
+ * @returns A reference to the new FilePersister object.
34
66
  * @example
35
- * This example creates a Persister object and persists the Store to a local
67
+ * This example creates a FilePersister object and persists the Store to a local
36
68
  * file.
37
69
  *
38
70
  * ```js yolo
@@ -53,4 +85,4 @@ export function createFilePersister<Schemas extends OptionalSchemas>(
53
85
  store: Store<Schemas>,
54
86
  filePath: string,
55
87
  onIgnoredError?: (error: any) => void,
56
- ): Persister<Schemas>;
88
+ ): FilePersister<Schemas>;
@@ -9,6 +9,39 @@
9
9
  import {OptionalSchemas, Store} from '../store';
10
10
  import {Persister} from '../persisters';
11
11
 
12
+ /**
13
+ * The IndexedDbPersister interface is a minor extension to the Persister
14
+ * interface.
15
+ *
16
+ * It simply provides an extra getDbName method for accessing the unique key of
17
+ * the IndexedDB the Store is being persisted to.
18
+ * @since v4.3.14
19
+ */
20
+ export interface IndexedDbPersister<Schemas extends OptionalSchemas>
21
+ extends Persister<Schemas> {
22
+ /**
23
+ * The getDbName method returns the unique key of the IndexedDB the Store is
24
+ * being persisted to.
25
+ * @returns The unique key of the IndexedDB.
26
+ * @example
27
+ * This example creates a Persister object against a newly-created Store and
28
+ * then gets the unique key of the IndexedDB back out again.
29
+ *
30
+ * ```js
31
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
32
+ * const persister = createIndexedDbPersister(store, 'petStore');
33
+ *
34
+ * console.log(persister.getDbName());
35
+ * // -> 'petStore'
36
+ *
37
+ * persister.destroy();
38
+ * ```
39
+ * @category Getter
40
+ * @since v4.3.14
41
+ */
42
+ getDbName: () => string;
43
+ }
44
+
12
45
  /**
13
46
  * The createIndexedDbPersister function creates a Persister object that can
14
47
  * persist the Store to the browser's IndexedDB storage.
@@ -21,7 +54,7 @@ import {Persister} from '../persisters';
21
54
  * dbName: string,
22
55
  * autoLoadIntervalSeconds?: number,
23
56
  * onIgnoredError?: (error: any) => void,
24
- * ): Persister;
57
+ * ): IndexedDbPersister;
25
58
  * ```
26
59
  *
27
60
  * As well as providing a reference to the Store to persist, you must provide a
@@ -45,10 +78,10 @@ import {Persister} from '../persisters';
45
78
  * @param onIgnoredError An optional handler for the errors that the Persister
46
79
  * would otherwise ignore when trying to save or load data. This is suitable for
47
80
  * debugging persistence issues in a development environment.
48
- * @returns A reference to the new Persister object.
81
+ * @returns A reference to the new IndexedDbPersister object.
49
82
  * @example
50
- * This example creates a Persister object and persists the Store to the
51
- * browser's IndexedDB storage.
83
+ * This example creates a IndexedDbPersister object and persists the Store to
84
+ * the browser's IndexedDB storage.
52
85
  *
53
86
  * ```js
54
87
  * const store = createStore()
@@ -82,4 +115,4 @@ export function createIndexedDbPersister<Schemas extends OptionalSchemas>(
82
115
  dbName: string,
83
116
  autoLoadIntervalSeconds?: number,
84
117
  onIgnoredError?: (error: any) => void,
85
- ): Persister<Schemas>;
118
+ ): IndexedDbPersister<Schemas>;
@@ -23,6 +23,43 @@ import {OptionalSchemas, Store} from '../store';
23
23
  import PartySocket from 'partysocket';
24
24
  import {Persister} from '../persisters';
25
25
 
26
+ /**
27
+ * The PartyKitPersister interface is a minor extension to the Persister
28
+ * interface.
29
+ *
30
+ * It simply provides an extra getConnection method for accessing the
31
+ * PartySocket the Store is being persisted to.
32
+ * @since v4.3.14
33
+ */
34
+ export interface PartyKitPersister<Schemas extends OptionalSchemas>
35
+ extends Persister<Schemas> {
36
+ /**
37
+ * The getConnection method returns the PartySocket the Store is being
38
+ * persisted to.
39
+ * @returns The PartySocket.
40
+ * @example
41
+ * This example creates a Persister object against a newly-created Store and
42
+ * then gets the PartySocket back out again.
43
+ *
44
+ * ```js yolo
45
+ * const partySocket = new PartySocket({
46
+ * host: PARTYKIT_HOST,
47
+ * room: 'my_room',
48
+ * });
49
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
50
+ * const persister = createPartyKitPersister(store, partySocket);
51
+ *
52
+ * console.log(persister.getConnection() == partySocket);
53
+ * // -> true
54
+ *
55
+ * persister.destroy();
56
+ * ```
57
+ * @category Getter
58
+ * @since v4.3.14
59
+ */
60
+ getConnection: () => PartySocket;
61
+ }
62
+
26
63
  /**
27
64
  * The PartyKitPersisterConfig type describes the configuration of a PartyKit
28
65
  * Persister on the client side.
@@ -84,7 +121,7 @@ export type PartyKitPersisterConfig = {
84
121
  * connection: PartySocket,
85
122
  * configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
86
123
  * onIgnoredError?: (error: any) => void,
87
- * ): Persister;
124
+ * ): PartyKitPersister;
88
125
  * ```
89
126
  *
90
127
  * As well as providing a reference to the Store to persist, you must provide a
@@ -117,9 +154,9 @@ export type PartyKitPersisterConfig = {
117
154
  * @param onIgnoredError An optional handler for the errors that the Persister
118
155
  * would otherwise ignore when trying to save or load data. This is suitable for
119
156
  * debugging persistence issues in a development environment.
120
- * @returns A reference to the new Persister object.
157
+ * @returns A reference to the new PartyKitPersister object.
121
158
  * @example
122
- * This example creates a Persister object and persists the Store to the
159
+ * This example creates a PartyKitPersister object and persists the Store to the
123
160
  * browser's IndexedDB storage.
124
161
  *
125
162
  * ```js yolo
@@ -146,4 +183,4 @@ export function createPartyKitPersister<Schemas extends OptionalSchemas>(
146
183
  connection: PartySocket,
147
184
  configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
148
185
  onIgnoredError?: (error: any) => void,
149
- ): Persister<Schemas>;
186
+ ): PartyKitPersister<Schemas>;
@@ -9,6 +9,43 @@
9
9
  import {OptionalSchemas, Store} from '../store';
10
10
  import {Persister} from '../persisters';
11
11
 
12
+ /**
13
+ * The RemotePersister interface is a minor extension to the Persister
14
+ * interface.
15
+ *
16
+ * It simply provides an extra getUrls method for accessing the URLs the Store
17
+ * is being persisted to.
18
+ * @since v4.3.14
19
+ */
20
+ export interface RemotePersister<Schemas extends OptionalSchemas>
21
+ extends Persister<Schemas> {
22
+ /**
23
+ * The getUrls method returns the URLs the Store is being persisted to.
24
+ * @returns The load and save URLs as a two-item array.
25
+ * @example
26
+ * This example creates a RemotePersister object against a newly-created Store
27
+ * and then gets the URLs back out again.
28
+ *
29
+ * ```js
30
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
31
+ * const persister = createRemotePersister(
32
+ * store,
33
+ * 'https://example.com/load',
34
+ * 'https://example.com/save',
35
+ * 5,
36
+ * );
37
+ *
38
+ * console.log(persister.getUrls());
39
+ * // -> ['https://example.com/load', 'https://example.com/save']
40
+ *
41
+ * persister.destroy();
42
+ * ```
43
+ * @category Getter
44
+ * @since v4.3.14
45
+ */
46
+ getUrls: () => [string, string];
47
+ }
48
+
12
49
  /**
13
50
  * The createRemotePersister function creates a Persister object that can
14
51
  * persist the Store to a remote server.
@@ -22,7 +59,7 @@ import {Persister} from '../persisters';
22
59
  * saveUrl: string,
23
60
  * autoLoadIntervalSeconds?: number,
24
61
  * onIgnoredError?: (error: any) => void,
25
- * ): Persister;
62
+ * ): RemotePersister;
26
63
  * ```
27
64
  *
28
65
  * As well as providing a reference to the Store to persist, you must provide
@@ -41,10 +78,10 @@ import {Persister} from '../persisters';
41
78
  * @param onIgnoredError An optional handler for the errors that the Persister
42
79
  * would otherwise ignore when trying to save or load data. This is suitable for
43
80
  * debugging persistence issues in a development environment, since v4.0.4.
44
- * @returns A reference to the new Persister object.
81
+ * @returns A reference to the new RemotePersister object.
45
82
  * @example
46
- * This example creates a Persister object and persists the Store to a remote
47
- * server.
83
+ * This example creates a RemotePersister object and persists the Store to a
84
+ * remote server.
48
85
  *
49
86
  * ```js yolo
50
87
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
@@ -71,4 +108,4 @@ export function createRemotePersister<Schemas extends OptionalSchemas>(
71
108
  saveUrl: string,
72
109
  autoLoadIntervalSeconds?: number,
73
110
  onIgnoredError?: (error: any) => void,
74
- ): Persister<Schemas>;
111
+ ): RemotePersister<Schemas>;
@@ -11,6 +11,46 @@
11
11
  import {DatabasePersisterConfig, Persister} from '../persisters';
12
12
  import {OptionalSchemas, Store} from '../store';
13
13
 
14
+ /**
15
+ * The SqliteWasmPersister interface is a minor extension to the Persister
16
+ * interface.
17
+ *
18
+ * It simply provides an extra getDb method for accessing a reference to the
19
+ * database instance the Store is being persisted to.
20
+ * @since v4.3.14
21
+ */
22
+ export interface SqliteWasmPersister<Schemas extends OptionalSchemas>
23
+ extends Persister<Schemas> {
24
+ /**
25
+ * The getDb method returns a reference to the database instance the Store is
26
+ * being persisted to.
27
+ * @returns A reference to the database instance.
28
+ * @example
29
+ * This example creates a Persister object against a newly-created Store and
30
+ * then gets the database instance back out again.
31
+ *
32
+ * ```js
33
+ * const sqlite3 = await sqlite3InitModule();
34
+ * const db = new sqlite3.oo1.DB(':memory:', 'c');
35
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
36
+ * const persister = createSqliteWasmPersister(
37
+ * store,
38
+ * sqlite3,
39
+ * db,
40
+ * 'my_tinybase',
41
+ * );
42
+ *
43
+ * console.log(persister.getDb() == db);
44
+ * // -> true
45
+ *
46
+ * persister.destroy();
47
+ * ```
48
+ * @category Getter
49
+ * @since v4.3.14
50
+ */
51
+ getDb: () => any;
52
+ }
53
+
14
54
  /**
15
55
  * The createSqliteWasmPersister function creates a Persister object that can
16
56
  * persist the Store to a local SQLite database (in an appropriate environment).
@@ -25,7 +65,7 @@ import {OptionalSchemas, Store} from '../store';
25
65
  * configOrStoreTableName?: DatabasePersisterConfig | string,
26
66
  * onSqlCommand?: (sql: string, args?: any[]) => void,
27
67
  * onIgnoredError?: (error: any) => void,
28
- * ): Persister;
68
+ * ): SqliteWasmPersister;
29
69
  * ```
30
70
  *
31
71
  * As well as providing a reference to the Store to persist, you must provide
@@ -56,11 +96,11 @@ import {OptionalSchemas, Store} from '../store';
56
96
  * @param onIgnoredError An optional handler for the errors that the Persister
57
97
  * would otherwise ignore when trying to save or load data. This is suitable for
58
98
  * debugging persistence issues in a development environment, since v4.0.4.
59
- * @returns A reference to the new Persister object.
99
+ * @returns A reference to the new SqliteWasmPersister object.
60
100
  * @example
61
- * This example creates a Persister object and persists the Store to a local
62
- * SQLite database as a JSON serialization into the `my_tinybase` table. It
63
- * makes a change to the database directly and then reloads it back into the
101
+ * This example creates a SqliteWasmPersister object and persists the Store to a
102
+ * local SQLite database as a JSON serialization into the `my_tinybase` table.
103
+ * It makes a change to the database directly and then reloads it back into the
64
104
  * Store.
65
105
  *
66
106
  * ```js
@@ -91,8 +131,8 @@ import {OptionalSchemas, Store} from '../store';
91
131
  * persister.destroy();
92
132
  * ```
93
133
  * @example
94
- * This example creates a Persister object and persists the Store to a local
95
- * SQLite database with tabular mapping.
134
+ * This example creates a SqliteWasmPersister object and persists the Store to a
135
+ * local SQLite database with tabular mapping.
96
136
  *
97
137
  * ```js
98
138
  * const sqlite3 = await sqlite3InitModule();
@@ -124,4 +164,4 @@ export function createSqliteWasmPersister<Schemas extends OptionalSchemas>(
124
164
  configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
125
165
  onSqlCommand?: (sql: string, args?: any[]) => void,
126
166
  onIgnoredError?: (error: any) => void,
127
- ): Persister<Schemas>;
167
+ ): SqliteWasmPersister<Schemas>;
@@ -12,6 +12,40 @@ import {DatabasePersisterConfig, Persister} from '../persisters';
12
12
  import {OptionalSchemas, Store} from '../store';
13
13
  import {Database} from 'sqlite3';
14
14
 
15
+ /**
16
+ * The Sqlite3Persister interface is a minor extension to the Persister
17
+ * interface.
18
+ *
19
+ * It simply provides an extra getDb method for accessing a reference to the
20
+ * database instance the Store is being persisted to.
21
+ * @since v4.3.14
22
+ */
23
+ export interface Sqlite3Persister<Schemas extends OptionalSchemas>
24
+ extends Persister<Schemas> {
25
+ /**
26
+ * The getDb method returns a reference to the database instance the Store is
27
+ * being persisted to.
28
+ * @returns A reference to the database instance.
29
+ * @example
30
+ * This example creates a Persister object against a newly-created Store and
31
+ * then gets the database instance back out again.
32
+ *
33
+ * ```js
34
+ * const db = new sqlite3.Database(':memory:');
35
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
36
+ * const persister = createSqlite3Persister(store, db, 'my_tinybase');
37
+ *
38
+ * console.log(persister.getDb() == db);
39
+ * // -> true
40
+ *
41
+ * persister.destroy();
42
+ * ```
43
+ * @category Getter
44
+ * @since v4.3.14
45
+ */
46
+ getDb: () => Database;
47
+ }
48
+
15
49
  /**
16
50
  * The createSqlite3Persister function creates a Persister object that can
17
51
  * persist the Store to a local SQLite database (in an appropriate environment).
@@ -25,7 +59,7 @@ import {Database} from 'sqlite3';
25
59
  * configOrStoreTableName?: DatabasePersisterConfig | string,
26
60
  * onSqlCommand?: (sql: string, args?: any[]) => void,
27
61
  * onIgnoredError?: (error: any) => void,
28
- * ): Persister;
62
+ * ): Sqlite3Persister;
29
63
  * ```
30
64
  *
31
65
  * As well as providing a reference to the Store to persist, you must provide a
@@ -54,11 +88,11 @@ import {Database} from 'sqlite3';
54
88
  * @param onIgnoredError An optional handler for the errors that the Persister
55
89
  * would otherwise ignore when trying to save or load data. This is suitable for
56
90
  * debugging persistence issues in a development environment, since v4.0.4.
57
- * @returns A reference to the new Persister object.
91
+ * @returns A reference to the new Sqlite3Persister object.
58
92
  * @example
59
- * This example creates a Persister object and persists the Store to a local
60
- * SQLite database as a JSON serialization into the `my_tinybase` table. It
61
- * makes a change to the database directly and then reloads it back into the
93
+ * This example creates a Sqlite3Persister object and persists the Store to a
94
+ * local SQLite database as a JSON serialization into the `my_tinybase` table.
95
+ * It makes a change to the database directly and then reloads it back into the
62
96
  * Store.
63
97
  *
64
98
  * ```js
@@ -90,8 +124,8 @@ import {Database} from 'sqlite3';
90
124
  * persister.destroy();
91
125
  * ```
92
126
  * @example
93
- * This example creates a Persister object and persists the Store to a local
94
- * SQLite database with tabular mapping.
127
+ * This example creates a Sqlite3Persister object and persists the Store to a
128
+ * local SQLite database with tabular mapping.
95
129
  *
96
130
  * ```js
97
131
  * const db = new sqlite3.Database(':memory:');
@@ -15,6 +15,39 @@ import {OptionalSchemas, Store} from '../store.d';
15
15
  import {Persister} from '../persisters.d';
16
16
  import {Doc as YDoc} from 'yjs';
17
17
 
18
+ /**
19
+ * The YjsPersister interface is a minor extension to the Persister interface.
20
+ *
21
+ * It simply provides an extra getYDoc method for accessing the Yjs document the
22
+ * Store is being persisted to.
23
+ * @since v4.3.14
24
+ */
25
+ export interface YjsPersister<Schemas extends OptionalSchemas>
26
+ extends Persister<Schemas> {
27
+ /**
28
+ * The getYDoc method returns the Yjs document the Store is being persisted
29
+ * to.
30
+ * @returns The Yjs document.
31
+ * @example
32
+ * This example creates a Persister object against a newly-created Store and
33
+ * then gets the Yjs document back out again.
34
+ *
35
+ * ```js
36
+ * const doc = new Y.Doc();
37
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
38
+ * const persister = createYjsPersister(store, doc);
39
+ *
40
+ * console.log(persister.getYDoc() == doc);
41
+ * // -> true
42
+ *
43
+ * persister.destroy();
44
+ * ```
45
+ * @category Getter
46
+ * @since v4.3.14
47
+ */
48
+ getYDoc: () => YDoc;
49
+ }
50
+
18
51
  /**
19
52
  * The createYjsPersister function creates a Persister object that can persist
20
53
  * the Store to a Yjs document.
@@ -27,7 +60,7 @@ import {Doc as YDoc} from 'yjs';
27
60
  * yDoc: YDoc,
28
61
  * yMapName?: string,
29
62
  * onIgnoredError?: (error: any) => void,
30
- * ): Persister;
63
+ * ): YjsPersister;
31
64
  * ```
32
65
  *
33
66
  * As well as providing a reference to the Store to persist, you must provide
@@ -39,9 +72,9 @@ import {Doc as YDoc} from 'yjs';
39
72
  * @param onIgnoredError An optional handler for the errors that the Persister
40
73
  * would otherwise ignore when trying to save or load data. This is suitable for
41
74
  * debugging persistence issues in a development environment, since v4.0.4.
42
- * @returns A reference to the new Persister object.
75
+ * @returns A reference to the new YjsPersister object.
43
76
  * @example
44
- * This example creates a Persister object and persists the Store to a Yjs
77
+ * This example creates a YjsPersister object and persists the Store to a Yjs
45
78
  * document.
46
79
  *
47
80
  * ```js
@@ -59,8 +92,8 @@ import {Doc as YDoc} from 'yjs';
59
92
  * ```
60
93
  * @example
61
94
  * This more complex example uses Yjs updates to keep two Store objects (each
62
- * with their own Persister objects and Yjs documents) in sync with each other.
63
- * We use the `await` keyword extensively for the purpose of ensuring
95
+ * with their own YjsPersister objects and Yjs documents) in sync with each
96
+ * other. We use the `await` keyword extensively for the purpose of ensuring
64
97
  * sequentiality in this example.
65
98
  *
66
99
  * Typically, real-world synchronization would happen between two systems via a
@@ -117,4 +150,4 @@ export function createYjsPersister<Schemas extends OptionalSchemas>(
117
150
  yDoc: YDoc,
118
151
  yMapName?: string,
119
152
  onIgnoredError?: (error: any) => void,
120
- ): Persister<Schemas>;
153
+ ): YjsPersister<Schemas>;