tinybase 6.1.0-beta.1 → 6.1.0-beta.2

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 (98) hide show
  1. package/@types/common/index.d.ts +4 -4
  2. package/@types/common/with-schemas/index.d.ts +4 -4
  3. package/index.js +15 -3
  4. package/indexes/index.js +15 -3
  5. package/indexes/with-schemas/index.js +15 -3
  6. package/min/index.js +1 -1
  7. package/min/index.js.gz +0 -0
  8. package/min/indexes/index.js +1 -1
  9. package/min/indexes/index.js.gz +0 -0
  10. package/min/indexes/with-schemas/index.js +1 -1
  11. package/min/indexes/with-schemas/index.js.gz +0 -0
  12. package/min/with-schemas/index.js +1 -1
  13. package/min/with-schemas/index.js.gz +0 -0
  14. package/package.json +7 -7
  15. package/readme.md +1 -1
  16. package/with-schemas/index.js +15 -3
  17. package/@types/_internal/queries/index.d.cts +0 -0
  18. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  19. package/@types/_internal/store/index.d.cts +0 -3
  20. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  21. package/@types/_internal/ui-react/index.d.cts +0 -0
  22. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  23. package/@types/checkpoints/index.d.cts +0 -1059
  24. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  25. package/@types/common/index.d.cts +0 -158
  26. package/@types/common/with-schemas/index.d.cts +0 -158
  27. package/@types/index.d.cts +0 -17
  28. package/@types/indexes/index.d.cts +0 -1064
  29. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  30. package/@types/mergeable-store/index.d.cts +0 -1139
  31. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  32. package/@types/metrics/index.d.cts +0 -917
  33. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  34. package/@types/persisters/index.d.cts +0 -1877
  35. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  36. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  37. package/@types/persisters/persister-browser/index.d.cts +0 -185
  38. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  39. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  40. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  41. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  42. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  43. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  44. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  45. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  46. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  47. package/@types/persisters/persister-file/index.d.cts +0 -94
  48. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  49. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  50. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  51. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  52. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  53. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  54. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  55. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  56. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  57. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  58. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  59. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  60. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  61. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  62. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  63. package/@types/persisters/persister-remote/index.d.cts +0 -117
  64. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  65. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  66. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  67. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  68. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  69. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  70. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  71. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  72. package/@types/queries/index.d.cts +0 -3695
  73. package/@types/queries/with-schemas/index.d.cts +0 -4016
  74. package/@types/relationships/index.d.cts +0 -1320
  75. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  76. package/@types/store/index.d.cts +0 -7598
  77. package/@types/store/with-schemas/index.d.cts +0 -9278
  78. package/@types/synchronizers/index.d.cts +0 -485
  79. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  80. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  81. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  82. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  83. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  84. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  85. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  86. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  87. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  88. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  89. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  90. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  91. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  92. package/@types/ui-react/index.d.cts +0 -16640
  93. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  94. package/@types/ui-react-dom/index.d.cts +0 -1862
  95. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  96. package/@types/ui-react-inspector/index.d.cts +0 -79
  97. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  98. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,208 +0,0 @@
1
- /**
2
- * The persister-browser module of the TinyBase project lets you save and load
3
- * Store data to and from browser storage.
4
- *
5
- * Two entry points are provided, each of which returns a new Persister object
6
- * that can load and save a Store:
7
- *
8
- * - The createSessionPersister function returns a Persister that uses the
9
- * browser's session storage.
10
- * - The createLocalPersister function returns a Persister that uses the
11
- * browser's local storage.
12
- * @see Persistence guides
13
- * @packageDocumentation
14
- * @module persister-browser
15
- * @since v1.0.0
16
- */
17
- import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.cts';
18
- import type {
19
- OptionalSchemas,
20
- Store,
21
- } from '../../../store/with-schemas/index.d.cts';
22
- import type {Persister, Persists} from '../../with-schemas/index.d.cts';
23
-
24
- /**
25
- * The SessionPersister interface represents a Persister that lets you save and
26
- * load Store data to and from the browser's session storage.
27
- *
28
- * You should use the createSessionPersister function to create a
29
- * SessionPersister object.
30
- *
31
- * It is a minor extension to the Persister interface and simply provides an
32
- * extra getStorageName method for accessing the unique key of the storage
33
- * location the Store is being persisted to.
34
- * @category Persister
35
- * @since v4.3.14
36
- */
37
- export interface SessionPersister<Schemas extends OptionalSchemas>
38
- extends Persister<Schemas, Persists.StoreOrMergeableStore> {
39
- /**
40
- * The getStorageName method returns the unique key of the storage location
41
- * the Store is being persisted to.
42
- * @returns The unique key of the storage location.
43
- * @example
44
- * This example creates a Persister object against a newly-created Store and
45
- * then gets the unique key of the storage location back out again.
46
- *
47
- * ```js
48
- * import {createStore} from 'tinybase';
49
- * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
50
- *
51
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
52
- * const persister = createSessionPersister(store, 'pets');
53
- *
54
- * console.log(persister.getStorageName());
55
- * // -> 'pets'
56
- *
57
- * persister.destroy();
58
- * ```
59
- * @category Getter
60
- * @since v4.3.14
61
- */
62
- getStorageName(): string;
63
- }
64
-
65
- /**
66
- * The LocalPersister interface represents a Persister that lets you save and
67
- * load Store data to and from the browser's local storage.
68
- *
69
- * It is a minor extension to the Persister interface and simply provides an
70
- * extra getStorageName method for accessing the unique key of the storage
71
- * location the Store is being persisted to.
72
- *
73
- * You should use the createLocalPersister function to create a LocalPersister
74
- * object.
75
- * @category Persister
76
- * @since v4.3.14
77
- */
78
- export interface LocalPersister<Schemas extends OptionalSchemas>
79
- extends Persister<Schemas, Persists.StoreOrMergeableStore> {
80
- /**
81
- * The getStorageName method returns the unique key of the storage location
82
- * the Store is being persisted to.
83
- * @returns The unique key of the storage location.
84
- * @example
85
- * This example creates a Persister object against a newly-created Store and
86
- * then gets the unique key of the storage location back out again.
87
- *
88
- * ```js
89
- * import {createStore} from 'tinybase';
90
- * import {createLocalPersister} from 'tinybase/persisters/persister-browser';
91
- *
92
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
93
- * const persister = createLocalPersister(store, 'pets');
94
- *
95
- * console.log(persister.getStorageName());
96
- * // -> 'pets'
97
- *
98
- * persister.destroy();
99
- * ```
100
- * @category Getter
101
- * @since v4.3.14
102
- */
103
- getStorageName(): string;
104
- }
105
-
106
- /**
107
- * The createSessionPersister function creates a SessionPersister object that
108
- * can persist the Store to the browser's session storage.
109
- *
110
- * This has schema-based typing. The following is a simplified representation:
111
- *
112
- * ```ts override
113
- * createSessionPersister(
114
- * store: Store | MergeableStore,
115
- * storageName: string,
116
- * onIgnoredError?: (error: any) => void,
117
- * ): SessionPersister;
118
- * ```
119
- *
120
- * A SessionPersister supports both regular Store and MergeableStore objects.
121
- *
122
- * As well as providing a reference to the Store to persist, you must provide a
123
- * `storageName` parameter which is unique to your application. This is the key
124
- * that the browser uses to identify the storage location.
125
- * @param store The Store or MergeableStore to persist.
126
- * @param storageName The unique key to identify the storage location.
127
- * @param onIgnoredError An optional handler for the errors that the Persister
128
- * would otherwise ignore when trying to save or load data. This is suitable for
129
- * debugging persistence issues in a development environment, since v4.0.4.
130
- * @returns A reference to the new SessionPersister object.
131
- * @example
132
- * This example creates a SessionPersister object and persists the Store to the
133
- * browser's session storage.
134
- *
135
- * ```js
136
- * import {createStore} from 'tinybase';
137
- * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
138
- *
139
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
140
- * const persister = createSessionPersister(store, 'pets');
141
- *
142
- * await persister.save();
143
- * console.log(sessionStorage.getItem('pets'));
144
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
145
- *
146
- * persister.destroy();
147
- * sessionStorage.clear();
148
- * ```
149
- * @category Creation
150
- * @since v1.0.0
151
- */
152
- export function createSessionPersister<Schemas extends OptionalSchemas>(
153
- store: Store<Schemas> | MergeableStore<Schemas>,
154
- storageName: string,
155
- onIgnoredError?: (error: any) => void,
156
- ): SessionPersister<Schemas>;
157
-
158
- /**
159
- * The createLocalPersister function creates a LocalPersister object that can
160
- * persist the Store to the browser's local storage.
161
- *
162
- * This has schema-based typing. The following is a simplified representation:
163
- *
164
- * ```ts override
165
- * createLocalPersister(
166
- * store: Store | MergeableStore,
167
- * storageName: string,
168
- * onIgnoredError?: (error: any) => void,
169
- * ): LocalPersister;
170
- * ```
171
- *
172
- * A LocalPersister supports both regular Store and MergeableStore objects.
173
- *
174
- * As well as providing a reference to the Store to persist, you must provide a
175
- * `storageName` parameter which is unique to your application. This is the key
176
- * that the browser uses to identify the storage location.
177
- * @param store The Store or MergeableStore to persist.
178
- * @param storageName The unique key to identify the storage location.
179
- * @param onIgnoredError An optional handler for the errors that the Persister
180
- * would otherwise ignore when trying to save or load data. This is suitable for
181
- * debugging persistence issues in a development environment, since v4.0.4.
182
- * @returns A reference to the new LocalPersister object.
183
- * @example
184
- * This example creates a LocalPersister object and persists the Store to the
185
- * browser's local storage.
186
- *
187
- * ```js
188
- * import {createStore} from 'tinybase';
189
- * import {createLocalPersister} from 'tinybase/persisters/persister-browser';
190
- *
191
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
192
- * const persister = createLocalPersister(store, 'pets');
193
- *
194
- * await persister.save();
195
- * console.log(localStorage.getItem('pets'));
196
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
197
- *
198
- * persister.destroy();
199
- * localStorage.clear();
200
- * ```
201
- * @category Creation
202
- * @since v1.0.0
203
- */
204
- export function createLocalPersister<Schemas extends OptionalSchemas>(
205
- store: Store<Schemas> | MergeableStore<Schemas>,
206
- storageName: string,
207
- onIgnoredError?: (error: any) => void,
208
- ): LocalPersister<Schemas>;
@@ -1,159 +0,0 @@
1
- /**
2
- * The persister-cr-sqlite-wasm module of the TinyBase project lets you save and
3
- * load Store data to and from a local CR-SQLite database (in an appropriate
4
- * environment).
5
- * @see Database Persistence guide
6
- * @packageDocumentation
7
- * @module persister-cr-sqlite-wasm
8
- * @since v4.0.0
9
- */
10
- import type {DB} from '@vlcn.io/crsqlite-wasm';
11
- import type {Store} from '../../store/index.d.cts';
12
- import type {DatabasePersisterConfig, Persister} from '../index.d.cts';
13
-
14
- /**
15
- * The CrSqliteWasmPersister interface represents a Persister that lets you save
16
- * and load Store data to and from a local CR-SQLite database.
17
- *
18
- * You should use the createCrSqliteWasmPersister function to create a
19
- * CrSqliteWasmPersister object.
20
- *
21
- * It is a minor extension to the Persister interface and simply provides an
22
- * extra getDb method for accessing a reference to the database instance the
23
- * Store is being persisted to.
24
- * @category Persister
25
- * @since v4.3.14
26
- */
27
- export interface CrSqliteWasmPersister extends Persister {
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
37
- * import initWasm from '@vlcn.io/crsqlite-wasm';
38
- * import {createStore} from 'tinybase';
39
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
40
- *
41
- * const crSqlite3 = await initWasm();
42
- * const db = await crSqlite3.open();
43
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
44
- * const persister = createCrSqliteWasmPersister(store, db, 'my_tinybase');
45
- *
46
- * console.log(persister.getDb() == db);
47
- * // -> true
48
- *
49
- * persister.destroy();
50
- * ```
51
- * @category Getter
52
- * @since v4.3.14
53
- */
54
- getDb(): DB;
55
- }
56
-
57
- /**
58
- * The createCrSqliteWasmPersister function creates a CrSqliteWasmPersister
59
- * object that can persist the Store to a local CR-SQLite database.
60
- *
61
- * A CrSqliteWasmPersister only supports regular Store objects, and cannot be
62
- * used to persist the metadata of a MergeableStore.
63
- *
64
- * As well as providing a reference to the Store to persist, you must provide a
65
- * `db` parameter which identifies the database instance.
66
- *
67
- * A database Persister uses one of two modes: either a JSON serialization of
68
- * the whole Store stored in a single row of a table (the default), or a tabular
69
- * mapping of Table Ids to database table names and vice-versa).
70
- *
71
- * The third argument is a DatabasePersisterConfig object that configures which
72
- * of those modes to use, and settings for each. If the third argument is simply
73
- * a string, it is used as the `storeTableName` property of the JSON
74
- * serialization.
75
- *
76
- * See the documentation for the DpcJson and DpcTabular types for more
77
- * information on how both of those modes can be configured.
78
- * @param store The Store to persist.
79
- * @param db The database instance that was returned from `crSqlite3.open(...)`.
80
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
81
- * persistence mode (or a string to set the `storeTableName` property of the
82
- * JSON serialization).
83
- * @param onSqlCommand An optional handler called every time the Persister
84
- * executes a SQL command or query. This is suitable for logging persistence
85
- * behavior in a development environment, since v4.0.4.
86
- * @param onIgnoredError An optional handler for the errors that the Persister
87
- * would otherwise ignore when trying to save or load data. This is suitable for
88
- * debugging persistence issues in a development environment, since v4.0.4.
89
- * @returns A reference to the new CrSqliteWasmPersister object.
90
- * @example
91
- * This example creates a CrSqliteWasmPersister object and persists the Store to
92
- * a local CR-SQLite database as a JSON serialization into the `my_tinybase`
93
- * table. It makes a change to the database directly and then reloads it back
94
- * into the Store.
95
- *
96
- * ```js
97
- * import initWasm from '@vlcn.io/crsqlite-wasm';
98
- * import {createStore} from 'tinybase';
99
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
100
- *
101
- * const crSqlite3 = await initWasm();
102
- * const db = await crSqlite3.open();
103
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
104
- * const persister = createCrSqliteWasmPersister(store, db, 'my_tinybase');
105
- *
106
- * await persister.save();
107
- * // Store will be saved to the database.
108
- *
109
- * console.log(await db.execO('SELECT * FROM my_tinybase;'));
110
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
111
- *
112
- * await db.exec(
113
- * 'UPDATE my_tinybase SET store = ' +
114
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
115
- * );
116
- * await persister.load();
117
- * console.log(store.getTables());
118
- * // -> {pets: {felix: {species: 'cat'}}}
119
- *
120
- * persister.destroy();
121
- * ```
122
- * @example
123
- * This example creates a CrSqliteWasmPersister object and persists the Store to
124
- * a local SQLite database with tabular mapping.
125
- *
126
- * ```js
127
- * import initWasm from '@vlcn.io/crsqlite-wasm';
128
- * import {createStore} from 'tinybase';
129
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
130
- *
131
- * const crSqlite3 = await initWasm();
132
- * const db = await crSqlite3.open();
133
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
134
- * const persister = createCrSqliteWasmPersister(store, db, {
135
- * mode: 'tabular',
136
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
137
- * });
138
- *
139
- * await persister.save();
140
- * console.log(await db.execO('SELECT * FROM pets;'));
141
- * // -> [{_id: 'fido', species: 'dog'}]
142
- *
143
- * await db.exec(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`);
144
- * await persister.load();
145
- * console.log(store.getTables());
146
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
147
- *
148
- * persister.destroy();
149
- * ```
150
- * @category Creation
151
- * @since v4.0.0
152
- */
153
- export function createCrSqliteWasmPersister(
154
- store: Store,
155
- db: DB,
156
- configOrStoreTableName?: DatabasePersisterConfig | string,
157
- onSqlCommand?: (sql: string, params?: any[]) => void,
158
- onIgnoredError?: (error: any) => void,
159
- ): CrSqliteWasmPersister;
@@ -1,178 +0,0 @@
1
- /**
2
- * The persister-cr-sqlite-wasm module of the TinyBase project lets you save and
3
- * load Store data to and from a local CR-SQLite database (in an appropriate
4
- * environment).
5
- * @see Database Persistence guide
6
- * @packageDocumentation
7
- * @module persister-cr-sqlite-wasm
8
- * @since v4.0.0
9
- */
10
- import type {DB} from '@vlcn.io/crsqlite-wasm';
11
- import type {
12
- OptionalSchemas,
13
- Store,
14
- } from '../../../store/with-schemas/index.d.cts';
15
- import type {
16
- DatabasePersisterConfig,
17
- Persister,
18
- } from '../../with-schemas/index.d.cts';
19
-
20
- /**
21
- * The CrSqliteWasmPersister interface represents a Persister that lets you save
22
- * and load Store data to and from a local CR-SQLite database.
23
- *
24
- * You should use the createCrSqliteWasmPersister function to create a
25
- * CrSqliteWasmPersister object.
26
- *
27
- * It is a minor extension to the Persister interface and simply provides an
28
- * extra getDb method for accessing a reference to the database instance the
29
- * Store is being persisted to.
30
- * @category Persister
31
- * @since v4.3.14
32
- */
33
- export interface CrSqliteWasmPersister<Schemas extends OptionalSchemas>
34
- extends Persister<Schemas> {
35
- /**
36
- * The getDb method returns a reference to the database instance the Store is
37
- * being persisted to.
38
- * @returns A reference to the database instance.
39
- * @example
40
- * This example creates a Persister object against a newly-created Store and
41
- * then gets the database instance back out again.
42
- *
43
- * ```js
44
- * import initWasm from '@vlcn.io/crsqlite-wasm';
45
- * import {createStore} from 'tinybase';
46
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
47
- *
48
- * const crSqlite3 = await initWasm();
49
- * const db = await crSqlite3.open();
50
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
51
- * const persister = createCrSqliteWasmPersister(store, db, 'my_tinybase');
52
- *
53
- * console.log(persister.getDb() == db);
54
- * // -> true
55
- *
56
- * persister.destroy();
57
- * ```
58
- * @category Getter
59
- * @since v4.3.14
60
- */
61
- getDb(): DB;
62
- }
63
-
64
- /**
65
- * The createCrSqliteWasmPersister function creates a CrSqliteWasmPersister
66
- * object that can persist the Store to a local CR-SQLite database.
67
- *
68
- * This has schema-based typing. The following is a simplified representation:
69
- *
70
- * ```ts override
71
- * createCrSqliteWasmPersister(
72
- * store: Store,
73
- * db: DB,
74
- * configOrStoreTableName?: DatabasePersisterConfig | string,
75
- * onSqlCommand?: (sql: string, params?: any[]) => void,
76
- * onIgnoredError?: (error: any) => void,
77
- * ): CrSqliteWasmPersister;
78
- * ```
79
- *
80
- * A CrSqliteWasmPersister only supports regular Store objects, and cannot be
81
- * used to persist the metadata of a MergeableStore.
82
- *
83
- * As well as providing a reference to the Store to persist, you must provide a
84
- * `db` parameter which identifies the database instance.
85
- *
86
- * A database Persister uses one of two modes: either a JSON serialization of
87
- * the whole Store stored in a single row of a table (the default), or a tabular
88
- * mapping of Table Ids to database table names and vice-versa).
89
- *
90
- * The third argument is a DatabasePersisterConfig object that configures which
91
- * of those modes to use, and settings for each. If the third argument is simply
92
- * a string, it is used as the `storeTableName` property of the JSON
93
- * serialization.
94
- *
95
- * See the documentation for the DpcJson and DpcTabular types for more
96
- * information on how both of those modes can be configured.
97
- * @param store The Store to persist.
98
- * @param db The database instance that was returned from `crSqlite3.open(...)`.
99
- * @param configOrStoreTableName A DatabasePersisterConfig to configure the
100
- * persistence mode (or a string to set the `storeTableName` property of the
101
- * JSON serialization).
102
- * @param onSqlCommand An optional handler called every time the Persister
103
- * executes a SQL command or query. This is suitable for logging persistence
104
- * behavior in a development environment, since v4.0.4.
105
- * @param onIgnoredError An optional handler for the errors that the Persister
106
- * would otherwise ignore when trying to save or load data. This is suitable for
107
- * debugging persistence issues in a development environment, since v4.0.4.
108
- * @returns A reference to the new CrSqliteWasmPersister object.
109
- * @example
110
- * This example creates a CrSqliteWasmPersister object and persists the Store to
111
- * a local CR-SQLite database as a JSON serialization into the `my_tinybase`
112
- * table. It makes a change to the database directly and then reloads it back
113
- * into the Store.
114
- *
115
- * ```js
116
- * import initWasm from '@vlcn.io/crsqlite-wasm';
117
- * import {createStore} from 'tinybase';
118
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
119
- *
120
- * const crSqlite3 = await initWasm();
121
- * const db = await crSqlite3.open();
122
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
123
- * const persister = createCrSqliteWasmPersister(store, db, 'my_tinybase');
124
- *
125
- * await persister.save();
126
- * // Store will be saved to the database.
127
- *
128
- * console.log(await db.execO('SELECT * FROM my_tinybase;'));
129
- * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
130
- *
131
- * await db.exec(
132
- * 'UPDATE my_tinybase SET store = ' +
133
- * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
134
- * );
135
- * await persister.load();
136
- * console.log(store.getTables());
137
- * // -> {pets: {felix: {species: 'cat'}}}
138
- *
139
- * persister.destroy();
140
- * ```
141
- * @example
142
- * This example creates a CrSqliteWasmPersister object and persists the Store to
143
- * a local SQLite database with tabular mapping.
144
- *
145
- * ```js
146
- * import initWasm from '@vlcn.io/crsqlite-wasm';
147
- * import {createStore} from 'tinybase';
148
- * import {createCrSqliteWasmPersister} from 'tinybase/persisters/persister-cr-sqlite-wasm';
149
- *
150
- * const crSqlite3 = await initWasm();
151
- * const db = await crSqlite3.open();
152
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
153
- * const persister = createCrSqliteWasmPersister(store, db, {
154
- * mode: 'tabular',
155
- * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
156
- * });
157
- *
158
- * await persister.save();
159
- * console.log(await db.execO('SELECT * FROM pets;'));
160
- * // -> [{_id: 'fido', species: 'dog'}]
161
- *
162
- * await db.exec(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`);
163
- * await persister.load();
164
- * console.log(store.getTables());
165
- * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
166
- *
167
- * persister.destroy();
168
- * ```
169
- * @category Creation
170
- * @since v4.0.0
171
- */
172
- export function createCrSqliteWasmPersister<Schemas extends OptionalSchemas>(
173
- store: Store<Schemas>,
174
- db: DB,
175
- configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
176
- onSqlCommand?: (sql: string, params?: any[]) => void,
177
- onIgnoredError?: (error: any) => void,
178
- ): CrSqliteWasmPersister<Schemas>;
@@ -1,122 +0,0 @@
1
- /**
2
- * The persister-durable-object-storage module of the TinyBase project lets you
3
- * save and load Store data to and from Cloudflare Durable Object storage (in an
4
- * appropriate environment).
5
- * @see Cloudflare Durable Objects guide
6
- * @see Persistence guides
7
- * @packageDocumentation
8
- * @module persister-durable-object-storage
9
- * @since v5.4.0
10
- */
11
- import type {MergeableStore} from '../../mergeable-store/index.d.cts';
12
- import type {Persister, Persists} from '../index.d.cts';
13
-
14
- /**
15
- * The DurableObjectStoragePersister interface represents a Persister that lets
16
- * you save and load Store data to and from Cloudflare Durable Object storage.
17
- *
18
- * You should use the createDurableObjectStoragePersister function to create a
19
- * DurableObjectStoragePersister object, most likely within the createPersister
20
- * method of a WsServerDurableObject.
21
- *
22
- * It is a minor extension to the Persister interface and simply provides an
23
- * extra getStorage method for accessing a reference to the storage that the
24
- * Store is being persisted to.
25
- * @category Persister
26
- * @since v5.4.0
27
- */
28
- export interface DurableObjectStoragePersister
29
- extends Persister<Persists.MergeableStoreOnly> {
30
- /**
31
- * The getStorage method returns a reference to the storage that the Store is
32
- * being persisted to.
33
- * @returns The reference to the storage.
34
- * @example
35
- * This example creates a Persister object against a newly-created Store
36
- * (within the createPersister method of a WsServerDurableObject instance) and
37
- * then gets the storage reference back out again.
38
- *
39
- * ```js yolo
40
- * import {createMergeableStore} from 'tinybase';
41
- * import {createDurableObjectStoragePersister} from 'tinybase/persisters/persister-durable-object-storage';
42
- * import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
43
- *
44
- * export class MyDurableObject extends WsServerDurableObject {
45
- * createPersister() {
46
- * const store = createMergeableStore();
47
- * const persister = createDurableObjectStoragePersister(
48
- * store,
49
- * this.ctx.storage,
50
- * );
51
- * console.log(persister.getStorage() == this.ctx.storage);
52
- * // -> true
53
- *
54
- * return persister;
55
- * }
56
- * }
57
- * ```
58
- * @category Getter
59
- * @since v5.4.0
60
- */
61
- getStorage(): DurableObjectStorage;
62
- }
63
-
64
- /**
65
- * The createDurableObjectStoragePersister function creates a
66
- * DurableObjectStoragePersister object that can persist the Store to and from
67
- * Cloudflare Durable Object storage.
68
- *
69
- * You will mostly use this within the createPersister method of a
70
- * WsServerDurableObject.
71
- *
72
- * A DurableObjectStoragePersister only supports MergeableStore objects, and
73
- * cannot be used to persist a regular Store.
74
- *
75
- * Durable Objects have limitations on the data that can be stored in each key
76
- * of their key-value structure. The DurableObjectStoragePersister uses one key
77
- * per TinyBase Value, one key per Cell, one key per Row, and one key per Table.
78
- * Mostly this is CRDT metadata, but the main caution is to ensure that each
79
- * individual TinyBase Cell and Value data does not exceed the (128 KiB) limit.
80
- *
81
- * As well as providing a reference to the MergeableStore to persist, you must
82
- * provide a `storage` parameter which identifies the Durable Object storage to
83
- * persist it to.
84
- * @param store The MergeableStore to persist.
85
- * @param storage The Durable Object storage to persist the Store to.
86
- * @param storagePrefix An optional prefix to use on the keys in storage, which
87
- * is useful if you want to ensure the Persister will not affect unrelated
88
- * Durable Object storage. Defaults to an empty string.
89
- * @param onIgnoredError An optional handler for the errors that the Persister
90
- * would otherwise ignore when trying to save or load data. This is suitable for
91
- * debugging persistence issues in a development environment.
92
- * @returns A reference to the new DurableObjectStoragePersister object.
93
- * @example
94
- * This example creates a Persister object against a newly-created
95
- * MergeableStore (within the createPersister method of a WsServerDurableObject
96
- * instance) and then gets the storage reference back out again.
97
- *
98
- * ```js yolo
99
- * import {createMergeableStore} from 'tinybase';
100
- * import {createDurableObjectStoragePersister} from 'tinybase/persisters/persister-durable-object-storage';
101
- * import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
102
- *
103
- * export class MyDurableObject extends WsServerDurableObject {
104
- * createPersister() {
105
- * const store = createMergeableStore();
106
- * const persister = createDurableObjectStoragePersister(
107
- * store,
108
- * this.ctx.storage,
109
- * );
110
- * return persister;
111
- * }
112
- * }
113
- * ```
114
- * @category Creation
115
- * @since v5.4.0
116
- */
117
- export function createDurableObjectStoragePersister(
118
- store: MergeableStore,
119
- storage: DurableObjectStorage,
120
- storagePrefix?: string,
121
- onIgnoredError?: (error: any) => void,
122
- ): DurableObjectStoragePersister;