tinybase 6.1.0-beta.0 → 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 (155) hide show
  1. package/@types/_internal/ui-react/with-schemas/index.d.ts +1 -1
  2. package/@types/common/index.d.ts +4 -4
  3. package/@types/common/with-schemas/index.d.ts +4 -4
  4. package/@types/index.d.ts +1 -1
  5. package/@types/persisters/persister-automerge/index.d.ts +1 -1
  6. package/@types/persisters/persister-automerge/with-schemas/index.d.ts +1 -1
  7. package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +1 -1
  8. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +1 -1
  9. package/@types/persisters/persister-electric-sql/index.d.ts +4 -4
  10. package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +4 -4
  11. package/@types/persisters/persister-expo-sqlite/index.d.ts +1 -1
  12. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +1 -1
  13. package/@types/persisters/persister-libsql/index.d.ts +1 -1
  14. package/@types/persisters/persister-libsql/with-schemas/index.d.ts +1 -1
  15. package/@types/persisters/persister-partykit-client/index.d.ts +1 -1
  16. package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +1 -1
  17. package/@types/persisters/persister-partykit-server/index.d.ts +7 -7
  18. package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +1 -1
  19. package/@types/persisters/persister-pglite/index.d.ts +1 -1
  20. package/@types/persisters/persister-pglite/with-schemas/index.d.ts +1 -1
  21. package/@types/persisters/persister-postgres/index.d.ts +1 -1
  22. package/@types/persisters/persister-postgres/with-schemas/index.d.ts +1 -1
  23. package/@types/persisters/persister-powersync/index.d.ts +1 -1
  24. package/@types/persisters/persister-powersync/with-schemas/index.d.ts +1 -1
  25. package/@types/persisters/persister-sqlite3/index.d.ts +1 -1
  26. package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +1 -1
  27. package/@types/persisters/persister-yjs/index.d.ts +1 -1
  28. package/@types/persisters/persister-yjs/with-schemas/index.d.ts +1 -1
  29. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +1 -1
  30. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +1 -1
  31. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +1 -1
  32. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +1 -1
  33. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +1 -1
  34. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +1 -1
  35. package/@types/ui-react/index.d.ts +3 -3
  36. package/@types/ui-react/with-schemas/index.d.ts +1 -1
  37. package/@types/ui-react-dom/index.d.ts +1 -1
  38. package/@types/ui-react-dom/with-schemas/index.d.ts +1 -1
  39. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  40. package/@types/with-schemas/index.d.ts +1 -1
  41. package/index.js +1579 -1567
  42. package/indexes/index.js +15 -3
  43. package/indexes/with-schemas/index.js +15 -3
  44. package/min/index.js +1 -1
  45. package/min/index.js.gz +0 -0
  46. package/min/indexes/index.js +1 -1
  47. package/min/indexes/index.js.gz +0 -0
  48. package/min/indexes/with-schemas/index.js +1 -1
  49. package/min/indexes/with-schemas/index.js.gz +0 -0
  50. package/min/persisters/index.js +1 -1
  51. package/min/persisters/index.js.gz +0 -0
  52. package/min/persisters/with-schemas/index.js +1 -1
  53. package/min/persisters/with-schemas/index.js.gz +0 -0
  54. package/min/ui-react/index.js +1 -1
  55. package/min/ui-react/index.js.gz +0 -0
  56. package/min/ui-react/with-schemas/index.js +1 -1
  57. package/min/ui-react/with-schemas/index.js.gz +0 -0
  58. package/min/with-schemas/index.js +1 -1
  59. package/min/with-schemas/index.js.gz +0 -0
  60. package/package.json +7 -10
  61. package/persisters/index.js +95 -95
  62. package/persisters/with-schemas/index.js +95 -95
  63. package/readme.md +13 -13
  64. package/releases.md +25 -25
  65. package/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  66. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  67. package/ui-react/index.js +64 -53
  68. package/ui-react/with-schemas/index.js +64 -53
  69. package/ui-react-dom/index.js +3 -3
  70. package/ui-react-dom/with-schemas/index.js +3 -3
  71. package/ui-react-inspector/index.js +4 -4
  72. package/ui-react-inspector/with-schemas/index.js +4 -4
  73. package/with-schemas/index.js +1579 -1567
  74. package/@types/_internal/queries/index.d.cts +0 -0
  75. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  76. package/@types/_internal/store/index.d.cts +0 -3
  77. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  78. package/@types/_internal/ui-react/index.d.cts +0 -0
  79. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  80. package/@types/checkpoints/index.d.cts +0 -1059
  81. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  82. package/@types/common/index.d.cts +0 -158
  83. package/@types/common/with-schemas/index.d.cts +0 -158
  84. package/@types/index.d.cts +0 -17
  85. package/@types/indexes/index.d.cts +0 -1064
  86. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  87. package/@types/mergeable-store/index.d.cts +0 -1139
  88. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  89. package/@types/metrics/index.d.cts +0 -917
  90. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  91. package/@types/persisters/index.d.cts +0 -1877
  92. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  93. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  94. package/@types/persisters/persister-browser/index.d.cts +0 -185
  95. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  96. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  97. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  98. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  99. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  100. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  101. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  102. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  103. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  104. package/@types/persisters/persister-file/index.d.cts +0 -94
  105. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  106. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  107. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  108. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  109. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  110. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  111. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  112. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  113. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  114. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  115. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  116. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  117. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  118. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  119. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  120. package/@types/persisters/persister-remote/index.d.cts +0 -117
  121. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  122. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  123. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  124. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  125. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  126. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  127. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  128. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  129. package/@types/queries/index.d.cts +0 -3695
  130. package/@types/queries/with-schemas/index.d.cts +0 -4016
  131. package/@types/relationships/index.d.cts +0 -1320
  132. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  133. package/@types/store/index.d.cts +0 -7598
  134. package/@types/store/with-schemas/index.d.cts +0 -9278
  135. package/@types/synchronizers/index.d.cts +0 -485
  136. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  137. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  138. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  139. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  140. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  141. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  142. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  143. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  144. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  145. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  146. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  147. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  148. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  149. package/@types/ui-react/index.d.cts +0 -16640
  150. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  151. package/@types/ui-react-dom/index.d.cts +0 -1862
  152. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  153. package/@types/ui-react-inspector/index.d.cts +0 -79
  154. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  155. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,195 +0,0 @@
1
- /**
2
- * The persister-partykit-client module of the TinyBase project contains the
3
- * client portion of the PartyKit integration.
4
- *
5
- * It contains a Persister which, when run in a PartyKit client environment,
6
- * lets you save and load Store data from the client to the durable PartyKit
7
- * cloud storage of a server (that is using the complementary
8
- * persister-partykit-server module).
9
- *
10
- * This enables synchronization of the same Store across multiple clients in a
11
- * PartyKit party room.
12
- *
13
- * Note that both the client and server parts of this Persister are currently
14
- * experimental as PartyKit is new and still maturing.
15
- * @see Persistence guides
16
- * @packageDocumentation
17
- * @module persister-partykit-client
18
- * @since v4.3.0
19
- */
20
- import type {Store} from '../../store/index.d.cts';
21
- import type {Persister} from '../index.d.cts';
22
- import type {PartySocket} from 'partysocket';
23
-
24
- /**
25
- * The PartyKitPersister interface represents a Persister that lets you save and
26
- * load Store data from the client to the durable PartyKit cloud storage of a
27
- * server.
28
- *
29
- * You should use the createPartyKitPersister function to create a
30
- * PartyKitPersister object.
31
- *
32
- * It is a minor extension to the Persister interface and simply provides an
33
- * extra getConnection method for accessing the PartySocket the Store is being
34
- * persisted to.
35
- * @category Persister
36
- * @since v4.3.14
37
- */
38
- export interface PartyKitPersister extends Persister {
39
- /**
40
- * The getConnection method returns the PartySocket the Store is being
41
- * persisted to.
42
- * @returns The PartySocket.
43
- * @example
44
- * This example creates a Persister object against a newly-created Store and
45
- * then gets the PartySocket back out again.
46
- *
47
- * ```js yolo
48
- * import {PartySocket} from 'partysocket';
49
- * import {createStore} from 'tinybase';
50
- * import {createPartyKitPersister} from 'tinybase/persisters/persister-partykit-client';
51
- *
52
- * const partySocket = new PartySocket({
53
- * host: '127.0.0.1:1999',
54
- * room: 'my_room',
55
- * });
56
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
57
- * const persister = createPartyKitPersister(store, partySocket);
58
- *
59
- * console.log(persister.getConnection() == partySocket);
60
- * // -> true
61
- *
62
- * persister.destroy();
63
- * ```
64
- * @category Getter
65
- * @since v4.3.14
66
- */
67
- getConnection(): PartySocket;
68
- }
69
-
70
- /**
71
- * The PartyKitPersisterConfig type describes the configuration of a PartyKit
72
- * Persister on the client side.
73
- *
74
- * The defaults (if used on both the server and client) will work fine, but if
75
- * you are building more complex PartyKit apps and you need to configure path
76
- * names, for example, then this is the thing to use.
77
- * @example
78
- * When applied to a PartyKit Persister, this PartyKitPersisterConfig will load
79
- * and save a JSON serialization from and to an end point in your room called
80
- * `/my_tinybase`, and use HTTP (rather than the default HTTPS) as the protocol.
81
- *
82
- * Note that this would require you to also add the matching storePath setting
83
- * to the TinyBasePartyKitServerConfig on the server side.
84
- *
85
- * ```js
86
- * export const partyKitPersisterConfig = {
87
- * storeProtocol: 'http',
88
- * storePath: '/my_tinybase',
89
- * };
90
- * ```
91
- * @category Configuration
92
- * @since v4.3.9
93
- */
94
- export type PartyKitPersisterConfig = {
95
- /**
96
- * The HTTP protocol to use (in addition to the websocket channel). This
97
- * defaults to 'https' but you may wish to use 'http' for local PartyKit
98
- * development.
99
- * @category Configuration
100
- * @since v4.3.0
101
- */
102
- storeProtocol?: 'http' | 'https';
103
- /**
104
- * The path used to set and get the whole Store over HTTP(S) on the server.
105
- * This must match the storePath property of the TinyBasePartyKitServerConfig
106
- * object used on the server. Both default to '/store'.
107
- * @category Configuration
108
- * @since v4.3.0
109
- */
110
- storePath?: string;
111
- /**
112
- * The prefix at the beginning of the web socket messages sent between the
113
- * client and the server when synchronizing the Store. Use this to make sure
114
- * they do not collide with any other message syntax that your room is using.
115
- * This must match the messagePrefix property of the
116
- * TinyBasePartyKitServerConfig object used on the server. Both default to an
117
- * empty string.
118
- * @category Configuration
119
- * @since v4.3.0
120
- */
121
- messagePrefix?: string;
122
- };
123
-
124
- /**
125
- * The createPartyKitPersister function creates a PartyKitPersister object that
126
- * can persist the Store to durable PartyKit storage, enabling synchronization
127
- * of the same Store across multiple clients.
128
- *
129
- * A PartyKitPersister only supports regular Store objects, and cannot be used
130
- * to persist the metadata of a MergeableStore.
131
- *
132
- * As well as providing a reference to the Store to persist, you must provide a
133
- * `connection` parameter which is a PartyKit PartySocket that you have already
134
- * instantiated with details of the host and room.
135
- *
136
- * All suitably-equipped TinyBase clients connecting to that room will get to
137
- * share synchronized Store state.
138
- *
139
- * The server room's Store is considered the source of truth. If it is a
140
- * newly-created room, then calling the save method on this Persister will
141
- * initiate it. If, however, there is already a Store present on the server, the
142
- * save method will fail gracefully.
143
- *
144
- * In general, you are strongly recommended to use the auto-save and auto-load
145
- * functionality to stay in sync incrementally with the server, as per the
146
- * example below. This pattern will handle newly-created servers and
147
- * newly-created clients - and the synchronization involved in joining rooms,
148
- * leaving them, or temporarily going offline.
149
- *
150
- * See the [PartyKit client socket API
151
- * documentation](https://docs.partykit.io/reference/partysocket-api/) for more
152
- * details.
153
- * @param store The Store to persist.
154
- * @param connection The PartySocket to use for participating in the PartyKit
155
- * room.
156
- * @param configOrStoreProtocol The PartyKitPersisterConfig configuration for
157
- * the Persister, (or a string to specify a HTTP protocol to use, defaulting to
158
- * 'https').
159
- * @param onIgnoredError An optional handler for the errors that the Persister
160
- * would otherwise ignore when trying to save or load data. This is suitable for
161
- * debugging persistence issues in a development environment.
162
- * @returns A reference to the new PartyKitPersister object.
163
- * @example
164
- * This example creates a PartyKitPersister object and persists the Store to the
165
- * browser's IndexedDB storage.
166
- *
167
- * ```js yolo
168
- * import {PartySocket} from 'partysocket';
169
- * import {createStore} from 'tinybase';
170
- * import {createPartyKitPersister} from 'tinybase/persisters/persister-partykit-client';
171
- *
172
- * const store = createStore()
173
- * .setTable('pets', {fido: {species: 'dog'}})
174
- * .setTable('species', {dog: {price: 5}})
175
- * .setValues({open: true});
176
- * const partySocket = new PartySocket({
177
- * host: '127.0.0.1:1999',
178
- * room: 'my_room',
179
- * });
180
- * const persister = createPartyKitPersister(store, partySocket);
181
- * await persister.startAutoLoad();
182
- * await persister.startAutoSave();
183
- * // Store will now be synchronized with the room.
184
- *
185
- * persister.destroy();
186
- * ```
187
- * @category Creation
188
- * @since v4.3.0
189
- */
190
- export function createPartyKitPersister(
191
- store: Store,
192
- connection: PartySocket,
193
- configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
194
- onIgnoredError?: (error: any) => void,
195
- ): PartyKitPersister;
@@ -1,210 +0,0 @@
1
- /**
2
- * The persister-partykit-client module of the TinyBase project contains the
3
- * client portion of the PartyKit integration.
4
- *
5
- * It contains a Persister which, when run in a PartyKit client environment,
6
- * lets you save and load Store data from the client to the durable PartyKit
7
- * cloud storage of a server (that is using the complementary
8
- * persister-partykit-server module).
9
- *
10
- * This enables synchronization of the same Store across multiple clients in a
11
- * PartyKit party room.
12
- *
13
- * Note that both the client and server parts of this Persister are currently
14
- * experimental as PartyKit is new and still maturing.
15
- * @see Persistence guides
16
- * @packageDocumentation
17
- * @module persister-partykit-client
18
- * @since v4.3.0
19
- */
20
- import type {
21
- OptionalSchemas,
22
- Store,
23
- } from '../../../store/with-schemas/index.d.cts';
24
- import type {Persister} from '../../with-schemas/index.d.cts';
25
- import type {PartySocket} from 'partysocket';
26
-
27
- /**
28
- * The PartyKitPersister interface represents a Persister that lets you save and
29
- * load Store data from the client to the durable PartyKit cloud storage of a
30
- * server.
31
- *
32
- * You should use the createPartyKitPersister function to create a
33
- * PartyKitPersister object.
34
- *
35
- * It is a minor extension to the Persister interface and simply provides an
36
- * extra getConnection method for accessing the PartySocket the Store is being
37
- * persisted to.
38
- * @category Persister
39
- * @since v4.3.14
40
- */
41
- export interface PartyKitPersister<Schemas extends OptionalSchemas>
42
- extends Persister<Schemas> {
43
- /**
44
- * The getConnection method returns the PartySocket the Store is being
45
- * persisted to.
46
- * @returns The PartySocket.
47
- * @example
48
- * This example creates a Persister object against a newly-created Store and
49
- * then gets the PartySocket back out again.
50
- *
51
- * ```js yolo
52
- * import {PartySocket} from 'partysocket';
53
- * import {createStore} from 'tinybase';
54
- * import {createPartyKitPersister} from 'tinybase/persisters/persister-partykit-client';
55
- *
56
- * const partySocket = new PartySocket({
57
- * host: '127.0.0.1:1999',
58
- * room: 'my_room',
59
- * });
60
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
61
- * const persister = createPartyKitPersister(store, partySocket);
62
- *
63
- * console.log(persister.getConnection() == partySocket);
64
- * // -> true
65
- *
66
- * persister.destroy();
67
- * ```
68
- * @category Getter
69
- * @since v4.3.14
70
- */
71
- getConnection(): PartySocket;
72
- }
73
-
74
- /**
75
- * The PartyKitPersisterConfig type describes the configuration of a PartyKit
76
- * Persister on the client side.
77
- *
78
- * The defaults (if used on both the server and client) will work fine, but if
79
- * you are building more complex PartyKit apps and you need to configure path
80
- * names, for example, then this is the thing to use.
81
- * @example
82
- * When applied to a PartyKit Persister, this PartyKitPersisterConfig will load
83
- * and save a JSON serialization from and to an end point in your room called
84
- * `/my_tinybase`, and use HTTP (rather than the default HTTPS) as the protocol.
85
- *
86
- * Note that this would require you to also add the matching storePath setting
87
- * to the TinyBasePartyKitServerConfig on the server side.
88
- *
89
- * ```js
90
- * export const partyKitPersisterConfig = {
91
- * storeProtocol: 'http',
92
- * storePath: '/my_tinybase',
93
- * };
94
- * ```
95
- * @category Configuration
96
- * @since v4.3.9
97
- */
98
- export type PartyKitPersisterConfig = {
99
- /**
100
- * The HTTP protocol to use (in addition to the websocket channel). This
101
- * defaults to 'https' but you may wish to use 'http' for local PartyKit
102
- * development.
103
- * @category Configuration
104
- * @since v4.3.0
105
- */
106
- storeProtocol?: 'http' | 'https';
107
- /**
108
- * The path used to set and get the whole Store over HTTP(S) on the server.
109
- * This must match the storePath property of the TinyBasePartyKitServerConfig
110
- * object used on the server. Both default to '/store'.
111
- * @category Configuration
112
- * @since v4.3.0
113
- */
114
- storePath?: string;
115
- /**
116
- * The prefix at the beginning of the web socket messages sent between the
117
- * client and the server when synchronizing the Store. Use this to make sure
118
- * they do not collide with any other message syntax that your room is using.
119
- * This must match the messagePrefix property of the
120
- * TinyBasePartyKitServerConfig object used on the server. Both default to an
121
- * empty string.
122
- * @category Configuration
123
- * @since v4.3.0
124
- */
125
- messagePrefix?: string;
126
- };
127
-
128
- /**
129
- * The createPartyKitPersister function creates a PartyKitPersister object that
130
- * can persist the Store to durable PartyKit storage, enabling synchronization
131
- * of the same Store across multiple clients.
132
- *
133
- * This has schema-based typing. The following is a simplified representation:
134
- *
135
- * ```ts override
136
- * createPartyKitPersister(
137
- * store: Store,
138
- * connection: PartySocket,
139
- * configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
140
- * onIgnoredError?: (error: any) => void,
141
- * ): PartyKitPersister;
142
- * ```
143
- *
144
- * A PartyKitPersister only supports regular Store objects, and cannot be used
145
- * to persist the metadata of a MergeableStore.
146
- *
147
- * As well as providing a reference to the Store to persist, you must provide a
148
- * `connection` parameter which is a PartyKit PartySocket that you have already
149
- * instantiated with details of the host and room.
150
- *
151
- * All suitably-equipped TinyBase clients connecting to that room will get to
152
- * share synchronized Store state.
153
- *
154
- * The server room's Store is considered the source of truth. If it is a
155
- * newly-created room, then calling the save method on this Persister will
156
- * initiate it. If, however, there is already a Store present on the server, the
157
- * save method will fail gracefully.
158
- *
159
- * In general, you are strongly recommended to use the auto-save and auto-load
160
- * functionality to stay in sync incrementally with the server, as per the
161
- * example below. This pattern will handle newly-created servers and
162
- * newly-created clients - and the synchronization involved in joining rooms,
163
- * leaving them, or temporarily going offline.
164
- *
165
- * See the [PartyKit client socket API
166
- * documentation](https://docs.partykit.io/reference/partysocket-api/) for more
167
- * details.
168
- * @param store The Store to persist.
169
- * @param connection The PartySocket to use for participating in the PartyKit
170
- * room.
171
- * @param configOrStoreProtocol The PartyKitPersisterConfig configuration for
172
- * the Persister, (or a string to specify a HTTP protocol to use, defaulting to
173
- * 'https').
174
- * @param onIgnoredError An optional handler for the errors that the Persister
175
- * would otherwise ignore when trying to save or load data. This is suitable for
176
- * debugging persistence issues in a development environment.
177
- * @returns A reference to the new PartyKitPersister object.
178
- * @example
179
- * This example creates a PartyKitPersister object and persists the Store to the
180
- * browser's IndexedDB storage.
181
- *
182
- * ```js yolo
183
- * import {PartySocket} from 'partysocket';
184
- * import {createStore} from 'tinybase';
185
- * import {createPartyKitPersister} from 'tinybase/persisters/persister-partykit-client';
186
- *
187
- * const store = createStore()
188
- * .setTable('pets', {fido: {species: 'dog'}})
189
- * .setTable('species', {dog: {price: 5}})
190
- * .setValues({open: true});
191
- * const partySocket = new PartySocket({
192
- * host: '127.0.0.1:1999',
193
- * room: 'my_room',
194
- * });
195
- * const persister = createPartyKitPersister(store, partySocket);
196
- * await persister.startAutoLoad();
197
- * await persister.startAutoSave();
198
- * // Store will now be synchronized with the room.
199
- *
200
- * persister.destroy();
201
- * ```
202
- * @category Creation
203
- * @since v4.3.0
204
- */
205
- export function createPartyKitPersister<Schemas extends OptionalSchemas>(
206
- store: Store<Schemas>,
207
- connection: PartySocket,
208
- configOrStoreProtocol?: PartyKitPersisterConfig | 'http' | 'https',
209
- onIgnoredError?: (error: any) => void,
210
- ): PartyKitPersister<Schemas>;