tinybase 4.3.13 → 4.3.15

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