tinybase 4.3.10 → 4.3.12
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.
- package/lib/cjs/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom.cjs +1 -1
- package/lib/cjs/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom.cjs.gz +0 -0
- package/lib/debug/persisters/persister-partykit-client.js +29 -19
- package/lib/debug/persisters/persister-partykit-server.js +155 -64
- package/lib/debug/ui-react-dom.js +45 -30
- package/lib/es6/persisters/persister-partykit-client.js +1 -1
- package/lib/es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/es6/persisters/persister-partykit-server.js +1 -1
- package/lib/es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/es6/ui-react-dom-debug.js +1 -1
- package/lib/es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/es6/ui-react-dom.js +1 -1
- package/lib/es6/ui-react-dom.js.gz +0 -0
- package/lib/persisters/persister-partykit-client.js +1 -1
- package/lib/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/persisters/persister-partykit-server.js +1 -1
- package/lib/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/types/persisters/persister-indexed-db.d.ts +4 -5
- package/lib/types/persisters/persister-partykit-client.d.ts +18 -7
- package/lib/types/persisters/persister-partykit-server.d.ts +335 -7
- package/lib/types/tools.d.ts +4 -6
- package/lib/types/ui-react-dom.d.ts +13 -2
- package/lib/types/ui-react.d.ts +4 -4
- package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +4 -5
- package/lib/types/with-schemas/persisters/persister-partykit-client.d.ts +18 -7
- package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +359 -7
- package/lib/types/with-schemas/tools.d.ts +4 -6
- package/lib/types/with-schemas/ui-react-dom.d.ts +21 -4
- package/lib/types/with-schemas/ui-react.d.ts +4 -4
- package/lib/ui-react-dom.js +1 -1
- package/lib/ui-react-dom.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-client.js +1 -1
- package/lib/umd/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-server.js +1 -1
- package/lib/umd/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd/ui-react-dom-debug.js +1 -1
- package/lib/umd/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd/ui-react-dom.js +1 -1
- package/lib/umd/ui-react-dom.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-client.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-server.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom-debug.js +1 -1
- package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom.js +1 -1
- package/lib/umd-es6/ui-react-dom.js.gz +0 -0
- package/package.json +10 -10
- package/readme.md +2 -2
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* @since 4.3.0
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import {Cell, Value} from '../store';
|
|
21
22
|
import {Connection, Party, Request, Server} from 'partykit/server';
|
|
23
|
+
import {Id} from '../common';
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* The TinyBasePartyKitServerConfig type describes the configuration of a
|
|
@@ -38,13 +40,13 @@ import {Connection, Party, Request, Server} from 'partykit/server';
|
|
|
38
40
|
* 'tinybase_' in case you are worried about colliding with other data stored
|
|
39
41
|
* in the room.
|
|
40
42
|
*
|
|
41
|
-
* ```js
|
|
42
|
-
*
|
|
43
|
+
* ```js
|
|
44
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
43
45
|
* readonly config: TinyBasePartyKitServerConfig = {
|
|
44
46
|
* storePath: '/my_tinybase',
|
|
45
47
|
* storagePrefix: 'tinybase_',
|
|
46
48
|
* };
|
|
47
|
-
* }
|
|
49
|
+
* }
|
|
48
50
|
* ```
|
|
49
51
|
* @category Configuration
|
|
50
52
|
* @since v4.3.9
|
|
@@ -56,6 +58,14 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
56
58
|
* on the client. Both default to '/store'.
|
|
57
59
|
*/
|
|
58
60
|
storePath?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The prefix at the beginning of the web socket messages between the client
|
|
63
|
+
* and the server when synchronizing the Store. Use this to make sure they do
|
|
64
|
+
* not collide with any other message syntax that your room is using. This
|
|
65
|
+
* must match the messagePrefix property of the PartyKitPersisterConfig object
|
|
66
|
+
* used on the client. Both default to an empty string.
|
|
67
|
+
*/
|
|
68
|
+
messagePrefix?: string;
|
|
59
69
|
/**
|
|
60
70
|
* The prefix used before all the keys in the server's durable storage. Use
|
|
61
71
|
* this in case you are worried about the Store data colliding with other data
|
|
@@ -98,7 +108,7 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
98
108
|
* ```js
|
|
99
109
|
* // This is your PartyKit server entry point.
|
|
100
110
|
*
|
|
101
|
-
*
|
|
111
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
102
112
|
* constructor(party) {
|
|
103
113
|
* super(party);
|
|
104
114
|
* // custom constructor code
|
|
@@ -124,6 +134,8 @@ export type TinyBasePartyKitServerConfig = {
|
|
|
124
134
|
* See the [PartyKit server API
|
|
125
135
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
126
136
|
* more details.
|
|
137
|
+
* @category Creation
|
|
138
|
+
* @since v4.3.0
|
|
127
139
|
*/
|
|
128
140
|
export class TinyBasePartyKitServer implements Server {
|
|
129
141
|
constructor(party: Party);
|
|
@@ -132,6 +144,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
132
144
|
* object of the TinyBasePartyKitServerConfig type.
|
|
133
145
|
*
|
|
134
146
|
* See the documentation for that type for more details.
|
|
147
|
+
* @category Configuration
|
|
148
|
+
* @since v4.3.9
|
|
135
149
|
*/
|
|
136
150
|
readonly config: TinyBasePartyKitServerConfig;
|
|
137
151
|
/**
|
|
@@ -143,7 +157,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
143
157
|
* synchronization stays supported:
|
|
144
158
|
*
|
|
145
159
|
* ```js
|
|
146
|
-
*
|
|
160
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
147
161
|
* async onRequest(request) {
|
|
148
162
|
* // custom onRequest code, else:
|
|
149
163
|
* return await super.onRequest(request);
|
|
@@ -154,6 +168,8 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
154
168
|
* See the [PartyKit server API
|
|
155
169
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
156
170
|
* more details.
|
|
171
|
+
* @category Connection
|
|
172
|
+
* @since v4.3.0
|
|
157
173
|
*/
|
|
158
174
|
onRequest(request: Request): Promise<Response>;
|
|
159
175
|
/**
|
|
@@ -165,7 +181,7 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
165
181
|
* synchronization stays supported:
|
|
166
182
|
*
|
|
167
183
|
* ```js
|
|
168
|
-
*
|
|
184
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
169
185
|
* async onMessage(message, client) {
|
|
170
186
|
* await super.onMessage(message, client);
|
|
171
187
|
* // custom onMessage code
|
|
@@ -176,6 +192,318 @@ export class TinyBasePartyKitServer implements Server {
|
|
|
176
192
|
* See the [PartyKit server API
|
|
177
193
|
* documentation](https://docs.partykit.io/reference/partyserver-api/) for
|
|
178
194
|
* more details.
|
|
195
|
+
* @category Connection
|
|
196
|
+
* @since v4.3.0
|
|
197
|
+
*/
|
|
198
|
+
onMessage(message: string, client: Connection): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* The canSetTable method lets you allow or disallow any changes to a Table
|
|
201
|
+
* stored on the server, as sent from a client.
|
|
202
|
+
*
|
|
203
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
204
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
205
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
206
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
207
|
+
* the server considers valid or safe.
|
|
208
|
+
*
|
|
209
|
+
* This method is passed the Table Id that the client is trying to change. The
|
|
210
|
+
* `initialSave` parameter distinguishes between the first bulk save of the
|
|
211
|
+
* Store to the PartyKit room over HTTP (`true`), and subsequent incremental
|
|
212
|
+
* updates over a web sockets (`false`).
|
|
213
|
+
*
|
|
214
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
215
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
216
|
+
* can, for instance, use this to distinguish between different users.
|
|
217
|
+
*
|
|
218
|
+
* Return `false` from this method to disallow changes to this Table on the
|
|
219
|
+
* server, or `true` to allow them (subject to subsequent canSetRow method,
|
|
220
|
+
* canDelRow method, canSetCell method, and canSetCell method checks). The
|
|
221
|
+
* default implementation returns `true` to allow all changes.
|
|
222
|
+
* @example
|
|
223
|
+
* The following implementation will strip out any attempts by the client to
|
|
224
|
+
* update any 'user' tabular data after the initial save:
|
|
225
|
+
*
|
|
226
|
+
* ```js
|
|
227
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
228
|
+
* canSetTable(tableId, initialSave) {
|
|
229
|
+
* return initialSave || tableId != 'user';
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
* @category Sanitization
|
|
234
|
+
* @since v4.3.12
|
|
235
|
+
*/
|
|
236
|
+
canSetTable(
|
|
237
|
+
tableId: Id,
|
|
238
|
+
initialSave: boolean,
|
|
239
|
+
requestOrConnection: Request | Connection,
|
|
240
|
+
): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* The canDelTable method lets you allow or disallow deletions of a Table
|
|
243
|
+
* stored on the server, as sent from a client.
|
|
244
|
+
*
|
|
245
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
246
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
247
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
248
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
249
|
+
* the server considers valid or safe.
|
|
250
|
+
*
|
|
251
|
+
* This method is passed the Table Id that the client is trying to delete. The
|
|
252
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
253
|
+
* You can, for instance, use this to distinguish between different users.
|
|
254
|
+
*
|
|
255
|
+
* Return `false` from this method to disallow this Table from being deleted
|
|
256
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
257
|
+
* `true` to allow deletion.
|
|
258
|
+
* @example
|
|
259
|
+
* The following implementation will strip out any attempts by the client to
|
|
260
|
+
* delete the 'user' Table:
|
|
261
|
+
*
|
|
262
|
+
* ```js
|
|
263
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
264
|
+
* canDelTable(tableId) {
|
|
265
|
+
* return tableId != 'user';
|
|
266
|
+
* }
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
* @category Sanitization
|
|
270
|
+
* @since v4.3.12
|
|
271
|
+
*/
|
|
272
|
+
canDelTable(tableId: Id, connection: Connection): boolean;
|
|
273
|
+
/**
|
|
274
|
+
* The canSetRow method lets you allow or disallow any changes to a Row stored
|
|
275
|
+
* on the server, as sent from a client.
|
|
276
|
+
*
|
|
277
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
278
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
279
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
280
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
281
|
+
* the server considers valid or safe.
|
|
282
|
+
*
|
|
283
|
+
* This method is passed the Table Id and Row Id that the client is trying to
|
|
284
|
+
* change. The `initialSave` parameter distinguishes between the first bulk
|
|
285
|
+
* save of the Store to the PartyKit room over HTTP (`true`), and subsequent
|
|
286
|
+
* incremental updates over a web sockets (`false`).
|
|
287
|
+
*
|
|
288
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
289
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
290
|
+
* can, for instance, use this to distinguish between different users.
|
|
291
|
+
*
|
|
292
|
+
* Return `false` from this method to disallow changes to this Row on the
|
|
293
|
+
* server, or `true` to allow them (subject to subsequent canSetCell method
|
|
294
|
+
* and canSetCell method checks). The default implementation returns `true` to
|
|
295
|
+
* allow all changes.
|
|
296
|
+
* @example
|
|
297
|
+
* The following implementation will strip out any attempts by the client to
|
|
298
|
+
* update the 'me' Row of the 'user' Table after the initial save:
|
|
299
|
+
*
|
|
300
|
+
* ```js
|
|
301
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
302
|
+
* canSetRow(tableId, rowId, initialSave) {
|
|
303
|
+
* return initialSave || tableId != 'user' || rowId != 'me';
|
|
304
|
+
* }
|
|
305
|
+
* }
|
|
306
|
+
* ```
|
|
307
|
+
* @category Sanitization
|
|
308
|
+
* @since v4.3.12
|
|
309
|
+
*/
|
|
310
|
+
canSetRow(
|
|
311
|
+
tableId: Id,
|
|
312
|
+
rowId: Id,
|
|
313
|
+
initialSave: boolean,
|
|
314
|
+
requestOrConnection: Request | Connection,
|
|
315
|
+
): boolean;
|
|
316
|
+
/**
|
|
317
|
+
* The canDelRow method lets you allow or disallow deletions of a Row stored
|
|
318
|
+
* on the server, as sent from a client.
|
|
319
|
+
*
|
|
320
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
321
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
322
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
323
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
324
|
+
* the server considers valid or safe.
|
|
325
|
+
*
|
|
326
|
+
* This method is passed the Table Id and Row Id that the client is trying to
|
|
327
|
+
* delete. The `connection` parameter will be the web socket connection of
|
|
328
|
+
* that client. You can, for instance, use this to distinguish between
|
|
329
|
+
* different users.
|
|
330
|
+
*
|
|
331
|
+
* Return `false` from this method to disallow this Row from being deleted
|
|
332
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
333
|
+
* `true` to allow deletion.
|
|
334
|
+
* @example
|
|
335
|
+
* The following implementation will strip out any attempts by the client to
|
|
336
|
+
* delete the 'me' Row of the 'user' Table:
|
|
337
|
+
*
|
|
338
|
+
* ```js
|
|
339
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
340
|
+
* canDelRow(tableId, rowId) {
|
|
341
|
+
* return tableId != 'user' || rowId != 'me';
|
|
342
|
+
* }
|
|
343
|
+
* }
|
|
344
|
+
* ```
|
|
345
|
+
* @category Sanitization
|
|
346
|
+
* @since v4.3.12
|
|
347
|
+
*/
|
|
348
|
+
canDelRow(tableId: Id, rowId: Id, connection: Connection): boolean;
|
|
349
|
+
/**
|
|
350
|
+
* The canSetCell method lets you allow or disallow any changes to a Cell
|
|
351
|
+
* stored on the server, as sent from a client.
|
|
352
|
+
*
|
|
353
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
354
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
355
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
356
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
357
|
+
* the server considers valid or safe.
|
|
358
|
+
*
|
|
359
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
360
|
+
* trying to change - as well as the Cell value itself. The `initialSave`
|
|
361
|
+
* parameter distinguishes between the first bulk save of the Store to the
|
|
362
|
+
* PartyKit room over HTTP (`true`), and subsequent incremental updates over a
|
|
363
|
+
* web sockets (`false`).
|
|
364
|
+
*
|
|
365
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
366
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
367
|
+
* can, for instance, use this to distinguish between different users.
|
|
368
|
+
*
|
|
369
|
+
* Return `false` from this method to disallow changes to this Cell on the
|
|
370
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
371
|
+
* to allow all changes.
|
|
372
|
+
* @example
|
|
373
|
+
* The following implementation will strip out any attempts by the client to
|
|
374
|
+
* update the 'name' Cell of the 'me' Row of the 'user' Table after the
|
|
375
|
+
* initial save:
|
|
376
|
+
*
|
|
377
|
+
* ```js
|
|
378
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
379
|
+
* canSetCell(tableId, rowId, cellId, cell, initialSave) {
|
|
380
|
+
* return (
|
|
381
|
+
* initialSave || tableId != 'user' || rowId != 'me' || cellId != 'name'
|
|
382
|
+
* );
|
|
383
|
+
* }
|
|
384
|
+
* }
|
|
385
|
+
* ```
|
|
386
|
+
* @category Sanitization
|
|
387
|
+
* @since v4.3.12
|
|
388
|
+
*/
|
|
389
|
+
canSetCell(
|
|
390
|
+
tableId: Id,
|
|
391
|
+
rowId: Id,
|
|
392
|
+
cellId: Id,
|
|
393
|
+
cell: Cell,
|
|
394
|
+
initialSave: boolean,
|
|
395
|
+
requestOrConnection: Request | Connection,
|
|
396
|
+
): boolean;
|
|
397
|
+
/**
|
|
398
|
+
* The canDelCell method lets you allow or disallow deletions of a Cell stored
|
|
399
|
+
* on the server, as sent from a client.
|
|
400
|
+
*
|
|
401
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
402
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
403
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
404
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
405
|
+
* the server considers valid or safe.
|
|
406
|
+
*
|
|
407
|
+
* This method is passed the Table Id, Row Id, and Cell Id that the client is
|
|
408
|
+
* trying to delete. The `connection` parameter will be the web socket
|
|
409
|
+
* connection of that client. You can, for instance, use this to distinguish
|
|
410
|
+
* between different users.
|
|
411
|
+
*
|
|
412
|
+
* Return `false` from this method to disallow this Cell from being deleted on
|
|
413
|
+
* the server, or `true` to allow it. The default implementation returns
|
|
414
|
+
* `true` to allow deletion.
|
|
415
|
+
* @example
|
|
416
|
+
* The following implementation will strip out any attempts by the client to
|
|
417
|
+
* delete the 'name' Cell of the 'me' Row of the 'user' Table:
|
|
418
|
+
*
|
|
419
|
+
* ```js
|
|
420
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
421
|
+
* canDelCell(tableId, rowId, cellId) {
|
|
422
|
+
* return tableId != 'user' || rowId != 'me' || cellId != 'name';
|
|
423
|
+
* }
|
|
424
|
+
* }
|
|
425
|
+
* ```
|
|
426
|
+
* @category Sanitization
|
|
427
|
+
* @since v4.3.12
|
|
428
|
+
*/
|
|
429
|
+
canDelCell(
|
|
430
|
+
tableId: Id,
|
|
431
|
+
rowId: Id,
|
|
432
|
+
cellId: Id,
|
|
433
|
+
connection: Connection,
|
|
434
|
+
): boolean;
|
|
435
|
+
/**
|
|
436
|
+
* The canSetValue method lets you allow or disallow any changes to a Value
|
|
437
|
+
* stored on the server, as sent from a client.
|
|
438
|
+
*
|
|
439
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
440
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
441
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
442
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
443
|
+
* the server considers valid or safe.
|
|
444
|
+
*
|
|
445
|
+
* This method is passed the Value Id that the client is trying to change - as
|
|
446
|
+
* well as the Value itself. The `initialSave` parameter distinguishes between
|
|
447
|
+
* the first bulk save of the Store to the PartyKit room over HTTP (`true`),
|
|
448
|
+
* and subsequent incremental updates over a web sockets (`false`).
|
|
449
|
+
*
|
|
450
|
+
* The final `requestOrConnection` parameter will either be the HTTP(S)
|
|
451
|
+
* request or the web socket connection, in those two cases respectively. You
|
|
452
|
+
* can, for instance, use this to distinguish between different users.
|
|
453
|
+
*
|
|
454
|
+
* Return `false` from this method to disallow changes to this Value on the
|
|
455
|
+
* server, or `true` to allow them. The default implementation returns `true`
|
|
456
|
+
* to allow all changes.
|
|
457
|
+
* @example
|
|
458
|
+
* The following implementation will strip out any attempts by the client to
|
|
459
|
+
* update the 'userId' Value after the initial save:
|
|
460
|
+
*
|
|
461
|
+
* ```js
|
|
462
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
463
|
+
* canSetValue(valueId, value, initialSave) {
|
|
464
|
+
* return initialSave || userId != 'userId';
|
|
465
|
+
* }
|
|
466
|
+
* }
|
|
467
|
+
* ```
|
|
468
|
+
* @category Sanitization
|
|
469
|
+
* @since v4.3.12
|
|
470
|
+
*/
|
|
471
|
+
canSetValue(
|
|
472
|
+
valueId: Id,
|
|
473
|
+
value: Value,
|
|
474
|
+
initialSave: boolean,
|
|
475
|
+
requestOrConnection: Request | Connection,
|
|
476
|
+
): boolean;
|
|
477
|
+
/**
|
|
478
|
+
* The canDelValue method lets you allow or disallow deletions of a Value
|
|
479
|
+
* stored on the server, as sent from a client.
|
|
480
|
+
*
|
|
481
|
+
* This is one of the functions use to sanitize the data that is being sent
|
|
482
|
+
* from a client. Perhaps you might want to make sure the server-stored data
|
|
483
|
+
* adheres to a particular schema, or you might want to make certain data
|
|
484
|
+
* read-only. Remember that you cannot trust the client to only send data that
|
|
485
|
+
* the server considers valid or safe.
|
|
486
|
+
*
|
|
487
|
+
* This method is passed the Value Id that the client is trying to delete. The
|
|
488
|
+
* `connection` parameter will be the web socket connection of that client.
|
|
489
|
+
* You can, for instance, use this to distinguish between different users.
|
|
490
|
+
*
|
|
491
|
+
* Return `false` from this method to disallow this Value from being deleted
|
|
492
|
+
* on the server, or `true` to allow it. The default implementation returns
|
|
493
|
+
* `true` to allow deletion.
|
|
494
|
+
* @example
|
|
495
|
+
* The following implementation will strip out any attempts by the client to
|
|
496
|
+
* delete the 'userId' Value:
|
|
497
|
+
*
|
|
498
|
+
* ```js
|
|
499
|
+
* class MyServer extends TinyBasePartyKitServer {
|
|
500
|
+
* canDelValue(valueId) {
|
|
501
|
+
* return valueId != 'userId';
|
|
502
|
+
* }
|
|
503
|
+
* }
|
|
504
|
+
* ```
|
|
505
|
+
* @category Sanitization
|
|
506
|
+
* @since v4.3.12
|
|
179
507
|
*/
|
|
180
|
-
|
|
508
|
+
canDelValue(valueId: Id, connection: Connection): boolean;
|
|
181
509
|
}
|
package/lib/types/tools.d.ts
CHANGED
|
@@ -413,9 +413,8 @@ export interface Tools {
|
|
|
413
413
|
* },
|
|
414
414
|
* });
|
|
415
415
|
* const tools = createTools(store);
|
|
416
|
-
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
417
|
-
* store
|
|
418
|
-
* ).getPrettyStoreApi('shop');
|
|
416
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
417
|
+
* await createTools(store).getPrettyStoreApi('shop');
|
|
419
418
|
*
|
|
420
419
|
* const dTsLines = dTs.split('\n');
|
|
421
420
|
* console.log(dTsLines[17]);
|
|
@@ -434,9 +433,8 @@ export interface Tools {
|
|
|
434
433
|
* felix: {price: 4},
|
|
435
434
|
* });
|
|
436
435
|
* const tools = createTools(store);
|
|
437
|
-
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
438
|
-
* store
|
|
439
|
-
* ).getPrettyStoreApi('shop');
|
|
436
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
437
|
+
* await createTools(store).getPrettyStoreApi('shop');
|
|
440
438
|
*
|
|
441
439
|
* const dTsLines = dTs.split('\n');
|
|
442
440
|
* console.log(dTsLines[17]);
|
|
@@ -1476,6 +1476,10 @@ export function ResultSortedTableInHtmlTable(
|
|
|
1476
1476
|
* A Cell contains a string, number, or boolean, so the value is rendered in an
|
|
1477
1477
|
* appropriate <input> tag and a button lets the user change type, if possible.
|
|
1478
1478
|
*
|
|
1479
|
+
* Set the `showType` prop to false to remove the ability for the user to see or
|
|
1480
|
+
* change the Cell type. They will also not be able to change the type if there
|
|
1481
|
+
* is a TablesSchema applied to the Store.
|
|
1482
|
+
*
|
|
1479
1483
|
* This component uses the useCell hook under the covers, which means that any
|
|
1480
1484
|
* changes to the specified Cell outside of this component will cause a
|
|
1481
1485
|
* re-render.
|
|
@@ -1516,7 +1520,7 @@ export function ResultSortedTableInHtmlTable(
|
|
|
1516
1520
|
* @since v4.1.0
|
|
1517
1521
|
*/
|
|
1518
1522
|
export function EditableCellView(
|
|
1519
|
-
props: CellProps & {readonly className?: string},
|
|
1523
|
+
props: CellProps & {readonly className?: string; readonly showType?: boolean},
|
|
1520
1524
|
): ComponentReturnType;
|
|
1521
1525
|
|
|
1522
1526
|
/**
|
|
@@ -1533,6 +1537,10 @@ export function EditableCellView(
|
|
|
1533
1537
|
* A Value contains a string, number, or boolean, so the value is rendered in an
|
|
1534
1538
|
* appropriate <input> tag and a button lets the user change type, if possible.
|
|
1535
1539
|
*
|
|
1540
|
+
* Set the `showType` prop to false to remove the ability for the user to see or
|
|
1541
|
+
* change the Value type. They will also not be able to change the type if there
|
|
1542
|
+
* is a ValuesSchema applied to the Store.
|
|
1543
|
+
*
|
|
1536
1544
|
* This component uses the useValue hook under the covers, which means that any
|
|
1537
1545
|
* changes to the specified Value outside of this component will cause a
|
|
1538
1546
|
* re-render.
|
|
@@ -1571,7 +1579,10 @@ export function EditableCellView(
|
|
|
1571
1579
|
* @since v4.1.0
|
|
1572
1580
|
*/
|
|
1573
1581
|
export function EditableValueView(
|
|
1574
|
-
props: ValueProps & {
|
|
1582
|
+
props: ValueProps & {
|
|
1583
|
+
readonly className?: string;
|
|
1584
|
+
readonly showType?: boolean;
|
|
1585
|
+
},
|
|
1575
1586
|
): ComponentReturnType;
|
|
1576
1587
|
|
|
1577
1588
|
/**
|
package/lib/types/ui-react.d.ts
CHANGED
|
@@ -3708,8 +3708,8 @@ export function useStartTransactionListener(
|
|
|
3708
3708
|
* </Provider>
|
|
3709
3709
|
* );
|
|
3710
3710
|
* const Pane = () => {
|
|
3711
|
-
* useWillFinishTransactionListener(
|
|
3712
|
-
*
|
|
3711
|
+
* useWillFinishTransactionListener(() =>
|
|
3712
|
+
* console.log('Will finish transaction'),
|
|
3713
3713
|
* );
|
|
3714
3714
|
* return <span>App</span>;
|
|
3715
3715
|
* };
|
|
@@ -3767,8 +3767,8 @@ export function useWillFinishTransactionListener(
|
|
|
3767
3767
|
* </Provider>
|
|
3768
3768
|
* );
|
|
3769
3769
|
* const Pane = () => {
|
|
3770
|
-
* useDidFinishTransactionListener(
|
|
3771
|
-
*
|
|
3770
|
+
* useDidFinishTransactionListener(() =>
|
|
3771
|
+
* console.log('Did finish transaction'),
|
|
3772
3772
|
* );
|
|
3773
3773
|
* return <span>App</span>;
|
|
3774
3774
|
* };
|
|
@@ -51,11 +51,10 @@ import {Persister} from '../persisters';
|
|
|
51
51
|
* browser's IndexedDB storage.
|
|
52
52
|
*
|
|
53
53
|
* ```js
|
|
54
|
-
* const store =
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* .setValues({open: true});
|
|
54
|
+
* const store = createStore()
|
|
55
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
56
|
+
* .setTable('species', {dog: {price: 5}})
|
|
57
|
+
* .setValues({open: true});
|
|
59
58
|
* const persister = createIndexedDbPersister(store, 'petStore');
|
|
60
59
|
*
|
|
61
60
|
* await persister.save();
|
|
@@ -57,9 +57,18 @@ export type PartyKitPersisterConfig = {
|
|
|
57
57
|
/**
|
|
58
58
|
* The path used to set and get the whole Store over HTTP(S) on the server.
|
|
59
59
|
* This must match the storePath property of the TinyBasePartyKitServerConfig
|
|
60
|
-
* object on the server. Both default to '/store'.
|
|
60
|
+
* object used on the server. Both default to '/store'.
|
|
61
61
|
*/
|
|
62
62
|
storePath?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The prefix at the beginning of the web socket messages sent between the
|
|
65
|
+
* client and the server when synchronizing the Store. Use this to make sure
|
|
66
|
+
* they do not collide with any other message syntax that your room is using.
|
|
67
|
+
* This must match the messagePrefix property of the
|
|
68
|
+
* TinyBasePartyKitServerConfig object used on the server. Both default to an
|
|
69
|
+
* empty string.
|
|
70
|
+
*/
|
|
71
|
+
messagePrefix?: string;
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
/**
|
|
@@ -114,12 +123,14 @@ export type PartyKitPersisterConfig = {
|
|
|
114
123
|
* browser's IndexedDB storage.
|
|
115
124
|
*
|
|
116
125
|
* ```js yolo
|
|
117
|
-
* const store =
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
126
|
+
* const store = createStore()
|
|
127
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
128
|
+
* .setTable('species', {dog: {price: 5}})
|
|
129
|
+
* .setValues({open: true});
|
|
130
|
+
* const partySocket = new PartySocket({
|
|
131
|
+
* host: PARTYKIT_HOST,
|
|
132
|
+
* room: 'my_room',
|
|
133
|
+
* });
|
|
123
134
|
* const persister = createPartyKitPersister(store, partySocket);
|
|
124
135
|
* await persister.startAutoLoad();
|
|
125
136
|
* await persister.startAutoSave();
|