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,695 +0,0 @@
1
- /**
2
- * The persister-partykit-server module of the TinyBase project contains the
3
- * server portion of the PartyKit integration.
4
- *
5
- * It contains a class which, when run in a PartyKit server environment, lets
6
- * you save and load Store data from a client (that is using the complementary
7
- * persister-partykit-client module) to durable PartyKit cloud storage.
8
- *
9
- * This enables synchronization of the same Store across multiple clients in a
10
- * PartyKit party room.
11
- *
12
- * Note that both the client and server parts of this Persister are currently
13
- * experimental as PartyKit is new and still maturing.
14
- * @see Persistence guides
15
- * @packageDocumentation
16
- * @module persister-partykit-server
17
- * @since v4.3.0
18
- */
19
- import type {Connection, Party, Request, Server} from 'partykit/server';
20
- import type {Id} from '../../../common/with-schemas/index.d.cts';
21
- import type {
22
- Cell,
23
- CellOrUndefined,
24
- Changes,
25
- Content,
26
- NoTablesSchema,
27
- NoValuesSchema,
28
- OptionalSchemas,
29
- Value,
30
- ValueOrUndefined,
31
- } from '../../../store/with-schemas/index.d.cts';
32
-
33
- /**
34
- * The TinyBasePartyKitServerConfig type describes the configuration of a
35
- * PartyKit Persister on the server side.
36
- *
37
- * The defaults (if used on both the server and client) will work fine, but if
38
- * you are building more complex PartyKit apps and you need to configure path
39
- * names, for example, then this is the type to use.
40
- * @example
41
- * When set as the config in a TinyBasePartyKitServer, this
42
- * TinyBasePartyKitServerConfig will expect clients to load and save their JSON
43
- * serialization from and to an end point in the room called `/my_tinybase`.
44
- * Note that this would require you to also add the matching storePath setting
45
- * to the PartyKitPersisterConfig on the client side.
46
- *
47
- * It will also store the data in the durable storage with a prefix of
48
- * 'tinybase_' in case you are worried about colliding with other data stored
49
- * in the room.
50
- *
51
- * ```js
52
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
53
- *
54
- * export class MyServer extends TinyBasePartyKitServer {
55
- * readonly config = {
56
- * storePath: '/my_tinybase',
57
- * storagePrefix: 'tinybase_',
58
- * };
59
- * }
60
- * ```
61
- * @category Configuration
62
- * @since v4.3.9
63
- */
64
- export type TinyBasePartyKitServerConfig = {
65
- /**
66
- * The path used to set and get the whole Store over HTTP(S) on the server.
67
- * This must match the storePath property of the PartyKitPersisterConfig used
68
- * on the client. Both default to '/store'.
69
- * @category Configuration
70
- * @since v4.3.0
71
- */
72
- storePath?: string;
73
-
74
- /**
75
- * The prefix at the beginning of the web socket messages between the client
76
- * and the server when synchronizing the Store. Use this to make sure they do
77
- * not collide with any other message syntax that your room is using. This
78
- * must match the messagePrefix property of the PartyKitPersisterConfig object
79
- * used on the client. Both default to an empty string.
80
- * @category Configuration
81
- * @since v4.3.0
82
- */
83
- messagePrefix?: string;
84
-
85
- /**
86
- * The prefix used before all the keys in the server's durable storage. Use
87
- * this in case you are worried about the Store data colliding with other data
88
- * stored in the room. Defaults to an empty string.
89
- * @category Configuration
90
- * @since v4.3.0
91
- */
92
- storagePrefix?: string;
93
-
94
- /**
95
- * An object containing the extra HTTP(S) headers returned to the client from
96
- * this server. This defaults to the following three headers to allow CORS.
97
- *
98
- * ```
99
- * Access-Control-Allow-Origin: *
100
- * Access-Control-Allow-Methods: *
101
- * Access-Control-Allow-Headers: *
102
- * ```
103
- *
104
- * If you set this field, it will override the default completely. So, for
105
- * example, if you add another header but still want the CORS defaults, you
106
- * will need to explicitly set the Access-Control-Allow headers above again.
107
- * @category Configuration
108
- * @since v4.3.0
109
- */
110
- responseHeaders?: HeadersInit;
111
- };
112
-
113
- /**
114
- * A TinyBasePartyKitServer is the server component for persisting the Store to
115
- * durable PartyKit storage, enabling synchronization of the same Store across
116
- * multiple clients.
117
- *
118
- * This extends the PartyKit Server class, which provides a selection of methods
119
- * you are expected to implement. The TinyBasePartyKitServer implements only two
120
- * of them, the onMessage method and the onRequest method, as well as the
121
- * constructor.
122
- *
123
- * If you wish to use TinyBasePartyKitServer as a general PartyKit server, you
124
- * can implement other methods. But you must remember to call the super
125
- * implementations of those methods to ensure the TinyBase synchronization stays
126
- * supported in addition to your own custom functionality. The same applies to
127
- * the constructor if you choose to implement that.
128
- *
129
- * ```js
130
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
131
- *
132
- * // This is your PartyKit server entry point.
133
- * export class MyServer extends TinyBasePartyKitServer {
134
- * constructor(party) {
135
- * super(party);
136
- * // custom constructor code
137
- * }
138
- *
139
- * async onStart() {
140
- * // no need to call super.onStart()
141
- * console.log('Server started');
142
- * }
143
- *
144
- * async onMessage(message, connection) {
145
- * await super.onMessage(message, connection);
146
- * // custom onMessage code
147
- * }
148
- *
149
- * async onRequest(request) {
150
- * // custom onRequest code, else:
151
- * return await super.onRequest(request);
152
- * }
153
- * }
154
- * ```
155
- *
156
- * See the [PartyKit server API
157
- * documentation](https://docs.partykit.io/reference/partyserver-api/) for
158
- * more details.
159
- * @category Server
160
- * @since v4.3.0
161
- */
162
- export class TinyBasePartyKitServer implements Server {
163
- /**
164
- * The constructor is used to create the server.
165
- * @returns A new instance of the TinyBasePartyKitServer.
166
- * @category Creation
167
- * @since v4.3.9
168
- */
169
- constructor(party: Party);
170
-
171
- /**
172
- * The config property is used to optionally configure the server, using an
173
- * object of the TinyBasePartyKitServerConfig type.
174
- *
175
- * See the documentation for that type for more details.
176
- * @category Configuration
177
- * @since v4.3.9
178
- */
179
- readonly config: TinyBasePartyKitServerConfig;
180
-
181
- /**
182
- * The onRequest method is called when a HTTP request is made to the party
183
- * URL.
184
- *
185
- * If you choose to implement additional functionality in this method, you
186
- * must remember to call the super implementation to ensure the TinyBase
187
- * synchronization stays supported.
188
- *
189
- * ```js
190
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
191
- *
192
- * export class MyServer extends TinyBasePartyKitServer {
193
- * async onRequest(request) {
194
- * // custom onRequest code, else:
195
- * return await super.onRequest(request);
196
- * }
197
- * }
198
- * ```
199
- *
200
- * See the [PartyKit server API
201
- * documentation](https://docs.partykit.io/reference/partyserver-api/) for
202
- * more details.
203
- * @category Connection
204
- * @since v4.3.0
205
- */
206
- onRequest(request: Request): Promise<Response>;
207
-
208
- /**
209
- * The onMessage method is called when the server receives a message from a
210
- * client.
211
- *
212
- * If you choose to implement additional functionality in this method, you
213
- * must remember to call the super implementation to ensure the TinyBase
214
- * synchronization stays supported.
215
- *
216
- * ```js
217
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
218
- *
219
- * export class MyServer extends TinyBasePartyKitServer {
220
- * async onMessage(message, connection) {
221
- * await super.onMessage(message, connection);
222
- * // custom onMessage code
223
- * }
224
- * }
225
- * ```
226
- *
227
- * See the [PartyKit server API
228
- * documentation](https://docs.partykit.io/reference/partyserver-api/) for
229
- * more details.
230
- * @category Connection
231
- * @since v4.3.0
232
- */
233
- onMessage(message: string, connection: Connection): Promise<void>;
234
-
235
- /**
236
- * The canSetTable method lets you allow or disallow any changes to a Table
237
- * stored on the server, as sent from a client.
238
- *
239
- * This is one of the functions use to sanitize the data that is being sent
240
- * from a client. Perhaps you might want to make sure the server-stored data
241
- * adheres to a particular schema, or you might want to make certain data
242
- * read-only. Remember that you cannot trust the client to only send data that
243
- * the server considers valid or safe.
244
- *
245
- * This method is passed the Table Id that the client is trying to change. The
246
- * `initialSave` parameter distinguishes between the first bulk save of the
247
- * Store to the PartyKit room over HTTP (`true`), and subsequent incremental
248
- * updates over a web sockets (`false`).
249
- *
250
- * The `requestOrConnection` parameter will either be the HTTP(S) request or
251
- * the web socket connection, in those two cases respectively. You can, for
252
- * instance, use this to distinguish between different users.
253
- *
254
- * Since v4.3.13, the final parameter is the Cell previously stored on the
255
- * server, if any. Use this to distinguish between the addition of a new Cell
256
- * (in which case it will be undefined) and the updating of an existing one.
257
- *
258
- * Return `false` from this method to disallow changes to this Table on the
259
- * server, or `true` to allow them (subject to subsequent canSetRow method,
260
- * canDelRow method, canSetCell method, and canSetCell method checks). The
261
- * default implementation returns `true` to allow all changes.
262
- * @example
263
- * The following implementation will strip out any attempts by the client to
264
- * update any 'user' tabular data after the initial save:
265
- *
266
- * ```js
267
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
268
- *
269
- * export class MyServer extends TinyBasePartyKitServer {
270
- * canSetTable(tableId, initialSave) {
271
- * return initialSave || tableId != 'user';
272
- * }
273
- * }
274
- * ```
275
- * @category Sanitization
276
- * @since v4.3.12
277
- */
278
- canSetTable(
279
- tableId: Id,
280
- initialSave: boolean,
281
- requestOrConnection: Request | Connection,
282
- ): Promise<boolean>;
283
-
284
- /**
285
- * The canDelTable method lets you allow or disallow deletions of a Table
286
- * stored on the server, as sent from a client.
287
- *
288
- * This is one of the functions use to sanitize the data that is being sent
289
- * from a client. Perhaps you might want to make sure the server-stored data
290
- * adheres to a particular schema, or you might want to make certain data
291
- * read-only. Remember that you cannot trust the client to only send data that
292
- * the server considers valid or safe.
293
- *
294
- * This method is passed the Table Id that the client is trying to delete. The
295
- * `connection` parameter will be the web socket connection of that client.
296
- * You can, for instance, use this to distinguish between different users.
297
- *
298
- * Return `false` from this method to disallow this Table from being deleted
299
- * on the server, or `true` to allow it. The default implementation returns
300
- * `true` to allow deletion.
301
- * @example
302
- * The following implementation will strip out any attempts by the client to
303
- * delete the 'user' Table:
304
- *
305
- * ```js
306
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
307
- *
308
- * export class MyServer extends TinyBasePartyKitServer {
309
- * canDelTable(tableId) {
310
- * return tableId != 'user';
311
- * }
312
- * }
313
- * ```
314
- * @category Sanitization
315
- * @since v4.3.12
316
- */
317
- canDelTable(tableId: Id, connection: Connection): Promise<boolean>;
318
-
319
- /**
320
- * The canSetRow method lets you allow or disallow any changes to a Row stored
321
- * on the server, as sent from a client.
322
- *
323
- * This is one of the functions use to sanitize the data that is being sent
324
- * from a client. Perhaps you might want to make sure the server-stored data
325
- * adheres to a particular schema, or you might want to make certain data
326
- * read-only. Remember that you cannot trust the client to only send data that
327
- * the server considers valid or safe.
328
- *
329
- * This method is passed the Table Id and Row Id that the client is trying to
330
- * change. The `initialSave` parameter distinguishes between the first bulk
331
- * save of the Store to the PartyKit room over HTTP (`true`), and subsequent
332
- * incremental updates over a web sockets (`false`).
333
- *
334
- * The final `requestOrConnection` parameter will either be the HTTP(S)
335
- * request or the web socket connection, in those two cases respectively. You
336
- * can, for instance, use this to distinguish between different users.
337
- *
338
- * Return `false` from this method to disallow changes to this Row on the
339
- * server, or `true` to allow them (subject to subsequent canSetCell method
340
- * and canSetCell method checks). The default implementation returns `true` to
341
- * allow all changes.
342
- * @example
343
- * The following implementation will strip out any attempts by the client to
344
- * update the 'me' Row of the 'user' Table after the initial save:
345
- *
346
- * ```js
347
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
348
- *
349
- * export class MyServer extends TinyBasePartyKitServer {
350
- * canSetRow(tableId, rowId, initialSave) {
351
- * return initialSave || tableId != 'user' || rowId != 'me';
352
- * }
353
- * }
354
- * ```
355
- * @category Sanitization
356
- * @since v4.3.12
357
- */
358
- canSetRow(
359
- tableId: Id,
360
- rowId: Id,
361
- initialSave: boolean,
362
- requestOrConnection: Request | Connection,
363
- ): Promise<boolean>;
364
-
365
- /**
366
- * The canDelRow method lets you allow or disallow deletions of a Row stored
367
- * on the server, as sent from a client.
368
- *
369
- * This is one of the functions use to sanitize the data that is being sent
370
- * from a client. Perhaps you might want to make sure the server-stored data
371
- * adheres to a particular schema, or you might want to make certain data
372
- * read-only. Remember that you cannot trust the client to only send data that
373
- * the server considers valid or safe.
374
- *
375
- * This method is passed the Table Id and Row Id that the client is trying to
376
- * delete. The `connection` parameter will be the web socket connection of
377
- * that client. You can, for instance, use this to distinguish between
378
- * different users.
379
- *
380
- * Return `false` from this method to disallow this Row from being deleted
381
- * on the server, or `true` to allow it. The default implementation returns
382
- * `true` to allow deletion.
383
- * @example
384
- * The following implementation will strip out any attempts by the client to
385
- * delete the 'me' Row of the 'user' Table:
386
- *
387
- * ```js
388
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
389
- *
390
- * export class MyServer extends TinyBasePartyKitServer {
391
- * canDelRow(tableId, rowId) {
392
- * return tableId != 'user' || rowId != 'me';
393
- * }
394
- * }
395
- * ```
396
- * @category Sanitization
397
- * @since v4.3.12
398
- */
399
- canDelRow(tableId: Id, rowId: Id, connection: Connection): Promise<boolean>;
400
-
401
- /**
402
- * The canSetCell method lets you allow or disallow any changes to a Cell
403
- * stored on the server, as sent from a client.
404
- *
405
- * This has schema-based typing. The following is a simplified representation:
406
- *
407
- * ```ts override
408
- * canSetCell(
409
- * tableId: Id,
410
- * rowId: Id,
411
- * cellId: Id,
412
- * cell: Cell,
413
- * initialSave: boolean,
414
- * requestOrConnection: Request | Connection,
415
- * oldCell: CellOrUndefined,
416
- * ): Promise<boolean>;
417
- * ```
418
- *
419
- * This is one of the functions use to sanitize the data that is being sent
420
- * from a client. Perhaps you might want to make sure the server-stored data
421
- * adheres to a particular schema, or you might want to make certain data
422
- * read-only. Remember that you cannot trust the client to only send data that
423
- * the server considers valid or safe.
424
- *
425
- * This method is passed the Table Id, Row Id, and Cell Id that the client is
426
- * trying to change - as well as the Cell value itself. The `initialSave`
427
- * parameter distinguishes between the first bulk save of the Store to the
428
- * PartyKit room over HTTP (`true`), and subsequent incremental updates over a
429
- * web sockets (`false`).
430
- *
431
- * The final `requestOrConnection` parameter will either be the HTTP(S)
432
- * request or the web socket connection, in those two cases respectively. You
433
- * can, for instance, use this to distinguish between different users.
434
- *
435
- * Return `false` from this method to disallow changes to this Cell on the
436
- * server, or `true` to allow them. The default implementation returns `true`
437
- * to allow all changes.
438
- * @example
439
- * The following implementation will strip out any attempts by the client to
440
- * update the 'name' Cell of the 'me' Row of the 'user' Table after the
441
- * initial save:
442
- *
443
- * ```js
444
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
445
- *
446
- * export class MyServer extends TinyBasePartyKitServer {
447
- * canSetCell(tableId, rowId, cellId, cell, initialSave) {
448
- * return (
449
- * initialSave || tableId != 'user' || rowId != 'me' || cellId != 'name'
450
- * );
451
- * }
452
- * }
453
- * ```
454
- * @category Sanitization
455
- * @since v4.3.12
456
- */
457
- canSetCell(
458
- tableId: Id,
459
- rowId: Id,
460
- cellId: Id,
461
- cell: Cell<NoTablesSchema, Id, Id>,
462
- initialSave: boolean,
463
- requestOrConnection: Request | Connection,
464
- oldCell: CellOrUndefined<NoTablesSchema, Id, Id>,
465
- ): Promise<boolean>;
466
-
467
- /**
468
- * The canDelCell method lets you allow or disallow deletions of a Cell stored
469
- * on the server, as sent from a client.
470
- *
471
- * This is one of the functions use to sanitize the data that is being sent
472
- * from a client. Perhaps you might want to make sure the server-stored data
473
- * adheres to a particular schema, or you might want to make certain data
474
- * read-only. Remember that you cannot trust the client to only send data that
475
- * the server considers valid or safe.
476
- *
477
- * This method is passed the Table Id, Row Id, and Cell Id that the client is
478
- * trying to delete. The `connection` parameter will be the web socket
479
- * connection of that client. You can, for instance, use this to distinguish
480
- * between different users.
481
- *
482
- * Return `false` from this method to disallow this Cell from being deleted on
483
- * the server, or `true` to allow it. The default implementation returns
484
- * `true` to allow deletion.
485
- * @example
486
- * The following implementation will strip out any attempts by the client to
487
- * delete the 'name' Cell of the 'me' Row of the 'user' Table:
488
- *
489
- * ```js
490
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
491
- *
492
- * export class MyServer extends TinyBasePartyKitServer {
493
- * canDelCell(tableId, rowId, cellId) {
494
- * return tableId != 'user' || rowId != 'me' || cellId != 'name';
495
- * }
496
- * }
497
- * ```
498
- * @category Sanitization
499
- * @since v4.3.12
500
- */
501
- canDelCell(
502
- tableId: Id,
503
- rowId: Id,
504
- cellId: Id,
505
- connection: Connection,
506
- ): Promise<boolean>;
507
-
508
- /**
509
- * The canSetValue method lets you allow or disallow any changes to a Value
510
- * stored on the server, as sent from a client.
511
- *
512
- * This has schema-based typing. The following is a simplified representation:
513
- *
514
- * ```ts override
515
- * canSetValue(
516
- * valueId: Id,
517
- * value: Value,
518
- * initialSave: boolean,
519
- * requestOrConnection: Request | Connection,
520
- * oldValue: ValueOrUndefined,
521
- * ): Promise<boolean>;
522
- * ```
523
- *
524
- * This is one of the functions use to sanitize the data that is being sent
525
- * from a client. Perhaps you might want to make sure the server-stored data
526
- * adheres to a particular schema, or you might want to make certain data
527
- * read-only. Remember that you cannot trust the client to only send data that
528
- * the server considers valid or safe.
529
- *
530
- * This method is passed the Value Id that the client is trying to change - as
531
- * well as the Value itself. The `initialSave` parameter distinguishes between
532
- * the first bulk save of the Store to the PartyKit room over HTTP (`true`),
533
- * and subsequent incremental updates over a web sockets (`false`).
534
- *
535
- * The `requestOrConnection` parameter will either be the HTTP(S) request or
536
- * the web socket connection, in those two cases respectively. You can, for
537
- * instance, use this to distinguish between different users.
538
- *
539
- * Since v4.3.13, the final parameter is the Value previously stored on the
540
- * server, if any. Use this to distinguish between the addition of a new Value
541
- * (in which case it will be undefined) and the updating of an existing one.
542
- *
543
- * Return `false` from this method to disallow changes to this Value on the
544
- * server, or `true` to allow them. The default implementation returns `true`
545
- * to allow all changes.
546
- * @example
547
- * The following implementation will strip out any attempts by the client to
548
- * update the 'userId' Value after the initial save:
549
- *
550
- * ```js
551
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
552
- *
553
- * export class MyServer extends TinyBasePartyKitServer {
554
- * canSetValue(valueId, value, initialSave) {
555
- * return initialSave || valueId != 'userId';
556
- * }
557
- * }
558
- * ```
559
- * @category Sanitization
560
- * @since v4.3.12
561
- */
562
- canSetValue(
563
- valueId: Id,
564
- value: Value<NoValuesSchema, Id>,
565
- initialSave: boolean,
566
- requestOrConnection: Request | Connection,
567
- oldValue: ValueOrUndefined<NoValuesSchema, Id>,
568
- ): Promise<boolean>;
569
-
570
- /**
571
- * The canDelValue method lets you allow or disallow deletions of a Value
572
- * stored on the server, as sent from a client.
573
- *
574
- * This is one of the functions use to sanitize the data that is being sent
575
- * from a client. Perhaps you might want to make sure the server-stored data
576
- * adheres to a particular schema, or you might want to make certain data
577
- * read-only. Remember that you cannot trust the client to only send data that
578
- * the server considers valid or safe.
579
- *
580
- * This method is passed the Value Id that the client is trying to delete. The
581
- * `connection` parameter will be the web socket connection of that client.
582
- * You can, for instance, use this to distinguish between different users.
583
- *
584
- * Return `false` from this method to disallow this Value from being deleted
585
- * on the server, or `true` to allow it. The default implementation returns
586
- * `true` to allow deletion.
587
- * @example
588
- * The following implementation will strip out any attempts by the client to
589
- * delete the 'userId' Value:
590
- *
591
- * ```js
592
- * import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
593
- *
594
- * export class MyServer extends TinyBasePartyKitServer {
595
- * canDelValue(valueId) {
596
- * return valueId != 'userId';
597
- * }
598
- * }
599
- * ```
600
- * @category Sanitization
601
- * @since v4.3.12
602
- */
603
- canDelValue(valueId: Id, connection: Connection): Promise<boolean>;
604
- }
605
-
606
- /**
607
- * The hasStoreInStorage function returns a boolean indicating whether durable
608
- * PartyKit storage contains a serialized Store.
609
- *
610
- * This is intended for specialist applications that require the ability to
611
- * inspect or load a TinyBase Store from a server's storage outside of the
612
- * normal context of a TinyBasePartyKitServer.
613
- *
614
- * The function is asynchronous, so you should use the `await` keyword or handle
615
- * the result as a promise.
616
- * @param storage A reference to the storage object, as would normally be
617
- * accessible from the `TinyBasePartyKitServer.party` object.
618
- * @param storagePrefix An optional prefix used before all the keys in the
619
- * server's durable storage, to match the equivalent property in the server's
620
- * TinyBasePartyKitServerConfig.
621
- * @returns A promised boolean indicating whether a Store is present in the
622
- * storage.
623
- * @category Storage
624
- * @since v4.4.1
625
- */
626
- export function hasStoreInStorage(
627
- storage: Storage,
628
- storagePrefix?: string,
629
- ): Promise<boolean>;
630
-
631
- /**
632
- * The loadStoreFromStorage function returns the content of a Store from durable
633
- * PartyKit storage.
634
- *
635
- * This has schema-based typing. The following is a simplified representation:
636
- *
637
- * ```ts override
638
- * loadStoreFromStorage(
639
- * storage: Storage,
640
- * storagePrefix?: string,
641
- * ): Promise<Content>;
642
- * ```
643
- *
644
- * This is intended for specialist applications that require the ability to
645
- * inspect or load a TinyBase Store from a server's storage outside of the
646
- * normal context of a TinyBasePartyKitServer.
647
- *
648
- * The function is asynchronous, so you should use the `await` keyword or handle
649
- * the result as a promise.
650
- * @param storage A reference to the storage object, as would normally be
651
- * accessible from the `TinyBasePartyKitServer.party` object.
652
- * @param storagePrefix An optional prefix used before all the keys in the
653
- * server's durable storage, to match the equivalent property in the server's
654
- * TinyBasePartyKitServerConfig.
655
- * @returns A promised array of a Tables object and a Values object.
656
- * @category Storage
657
- * @since v4.4.1
658
- */
659
- export function loadStoreFromStorage<Schemas extends OptionalSchemas>(
660
- storage: Storage,
661
- storagePrefix?: string,
662
- ): Promise<Content<Schemas>>;
663
-
664
- /**
665
- * The broadcastChanges function allows you to broadcast Store
666
- * changes to all the client connections of a TinyBasePartyKitServer.
667
- *
668
- * This has schema-based typing. The following is a simplified representation:
669
- *
670
- * ```ts override
671
- * broadcastChanges(
672
- * server: TinyBasePartyKitServer,
673
- * changes: Changes,
674
- * without?: string[],
675
- * ): Promise<void>;
676
- * ```
677
- *
678
- * This is intended for specialist applications that require the ability to
679
- * update clients of a TinyBasePartyKitServer in their own custom ways.
680
- *
681
- * The function is asynchronous, so you should use the `await` keyword or handle
682
- * its completion as a promise.
683
- * @param server A reference to the TinyBasePartyKitServer object.
684
- * @param changes The Store changes to broadcast to the server's
685
- * clients.
686
- * @param without An optional array of client connection Ids to exclude from the
687
- * broadcast.
688
- * @category Connection
689
- * @since v4.5.1
690
- */
691
- export function broadcastChanges<Schemas extends OptionalSchemas>(
692
- server: TinyBasePartyKitServer,
693
- changes: Changes<Schemas>,
694
- without?: string[],
695
- ): Promise<void>;